feat(payment): buildX402AcceptsFor402 + probe extra.name fix (1.3.2)#10
Merged
vvillait88 merged 1 commit intomainfrom May 5, 2026
Merged
Conversation
…ect extra.name (1.3.2)
Mirrors the python-commerce 1.3.4 cleanup. Two parallel goals:
1. Lift up the boilerplate every Node merchant inlined for emitting x402
challenges (`x402Server.buildPaymentRequirements({...} as never)` + push
the result) so the EIP-712-domain-mismatch trap can't recur.
2. Fix the discovery probe + tests + examples that hardcoded
`extra: { name: 'USDC' }` regardless of network — wrong on Base mainnet
(USDC contract returns `name() = "USD Coin"`), correct on sepolia
(`name() = "USDC"`).
New public API:
buildX402AcceptsFor402(server, { network, price, payTo, scheme?, maxTimeoutSeconds?, extensions? })
Wraps `server.buildPaymentRequirements(...)`, returns the result as a list
of plain wire-shape objects ready for the 402 body's `accepts[]`. The x402
scheme registered on the server fills in `extra` from contract metadata —
sepolia → `name: 'USDC'`, mainnet → `name: 'USD Coin'`.
Probe / examples / tests:
- src/discovery/probe.ts: sample accept for `eip155:8453` now emits
`extra: { name: 'USD Coin', version: '2' }`; sepolia stays `'USDC'`.
- examples/multi-rail-merchant.ts: refactored to use
`buildX402AcceptsFor402(x402Server, ...)` instead of the hand-rolled accept.
- examples/api-provider.ts: keeps inline (smallest possible example) with
a comment pointing at the helper as the production pattern.
- tests/discovery/probe.test.ts: assertions updated.
- tests/payment/x402_server.test.ts: 3 new tests for the helper.
669 tests pass. Lint + typecheck clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Mirrors the python-commerce 1.3.4 cleanup. Two parallel goals:
x402Server.buildPaymentRequirements({...} as never)+ push the result) so the EIP-712 domain-mismatch trap can't recur.extra: { name: 'USDC' }regardless of network — wrong on Base mainnet (the actual USDC contract returnsname() = "USD Coin"), correct on sepolia (name() = "USDC").New public API
Wraps
server.buildPaymentRequirements(...), returns the result as a list of plain wire-shape objects ready for the 402 body'saccepts[]. The x402 scheme registered on the server fills inextrafrom contract metadata: sepolia →name: 'USDC', mainnet →name: 'USD Coin'.Probe / examples / tests
src/discovery/probe.ts: sample accept foreip155:8453now emitsextra: { name: 'USD Coin', version: '2' }; sepolia stays'USDC'.examples/multi-rail-merchant.ts: refactored to usebuildX402AcceptsFor402(x402Server, ...)instead of the hand-rolled accept.examples/api-provider.ts: keeps inline (smallest possible example) with a comment pointing at the helper as the production pattern.tests/discovery/probe.test.ts: assertions updated.tests/payment/x402_server.test.ts: 3 new tests for the helper (passes resource-config, honours scheme/maxTimeoutSeconds/extensions, returns[]on non-array fallback).Tests
669 passed, 4 skipped. Lint + typecheck clean.
Doc updates
README.md+CLAUDE.mdgain abuildX402AcceptsFor402snippet.core/docs/integrations/node-commerce.mdx(Mintlify) updated in the companion core PR (#237).Test plan
v1.3.2, push tag → npm publish.martin-estate/src/routes/purchase.tsto use the new helper (currently callsx402Server.buildPaymentRequirements(...)directly with anas nevercast — works, but the helper drops the cast and tightens the type story).🤖 Generated with Claude Code