feat(payments): add USDC payment verification for Hedera#5
Merged
Conversation
Add `verifyUsdcPayment` and `waitForUsdcPayment` as convenience wrappers
over the HTS verification engine, with 6-decimal amount parsing, an
optional token-id override, and a verified USDC token registry.
- `verifyUsdcPayment` / `waitForUsdcPayment`: required `network`, forced
6-decimal parsing, optional `tokenId` override for dev/mock tokens;
result `asset` tagged `{ tokenId, decimals: 6, symbol: "USDC" }`.
- USDC registry: `USDC_TOKEN_IDS`, `getUsdcTokenId`, `USDC_DECIMALS`,
`isUsdcPaymentResult`. Token ids verified against the live Mirror Node
and Circle's official docs: mainnet 0.0.456858, testnet 0.0.429274;
previewnet has none and throws.
- core: add `UnsupportedAssetError` (thrown for networks without a
verified USDC token id).
- `PaymentAsset` gains an additive optional `symbol?` (non-breaking).
- Tests: 22 unit cases plus an opt-in, read-only live smoke test gated by
`HBARKIT_LIVE=1`.
- Docs/example/llms: new "Verify a USDC payment" guide, README sections,
`verify:usdc` example script, and llms.txt/llms-full.txt updates.
Changeset: payments minor, core minor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds production-ready USDC payment verification to
@hbar-kit/paymentsas a focused extension of the existing read-only, non-custodial HTS verification layer. USDC on Hedera is an HTS token, so this is a thin convenience path over the genericverifyHtsPaymentengine — no custody, no Circle API, no fiat conversion, no wallet/UI.What's new
verifyUsdcPayment(params)/waitForUsdcPayment(params)— wrappers oververifyHtsPayment/waitForHtsPaymentthat resolve the verified USDC token id for the network, force 6-decimal amount parsing, and tag the resultassetas{ tokenId, decimals: 6, symbol: "USDC" }. All existing payment semantics (confirmed/pending/underpaid/overpaid/duplicate/mismatch/expired/failed) are preserved.USDC_TOKEN_IDS,getUsdcTokenId(network),USDC_DECIMALS(= 6),isUsdcPaymentResult(result).UnsupportedAssetErroradded to@hbar-kit/core— thrown for networks without a verified USDC token id.PaymentAssetgains an additive optionalsymbol?— non-breaking.Network safety
networkis required for the USDC helper — USDC token ids and HashScan URLs are network-specific, so there is no implicit default. Previewnet has no Circle-issued USDC and throws rather than silently falling back. A customtokenIdoverride is supported (dev/mock tokens) and format-validated, but is always parsed at 6 decimals.Verified token ids
Triple-checked before hardcoding (source comments cite the evidence):
0.0.4568580.0.429274UnsupportedAssetErrorTests
22 unit cases covering exact / underpaid / overpaid (exact vs
atLeast) / wrong memo / missing memo / wrong receiver / wrong token / duplicate / failed-excluded / custom token id / unsupported network />6decimal precision / missing network / malformed token id / explorer-url network correctness / wait→confirmed / wait→expired. Plus an opt-in, read-only live smoke test gated byHBARKIT_LIVE=1(no keys, no funds) that confirms the registry ids still resolve to real USDC on-chain.Docs / example
New "Verify a USDC payment" guide (wired into the sidebar) + cross-links, root and package README sections, reference-doc updates, a
verify:usdcexample script with.env, andllms.txt/llms-full.txtupdates. Positioning unchanged — USDC does not dominate over HBAR/HTS.Validation
pnpm lint,typecheck,build,test,coverage, andcheck:publishall pass; VitePress docs build clean with no dead links.usdc.tshas 100% statement/function/line coverage. Backwards compatible —verifyHbar/HtsPayment,waitForHbar/HtsPayment, andPaymentResultare unchanged.Release
Changeset included:
@hbar-kit/paymentsminor,@hbar-kit/coreminor. Merging tomainalso triggers the Docs deploy so the new guide goes live on GitHub Pages.