Skip to content

feat(payment): buildX402AcceptsFor402 + probe extra.name fix (1.3.2)#10

Merged
vvillait88 merged 1 commit intomainfrom
feat/x402-build-accepts-helper-and-probe-fix
May 5, 2026
Merged

feat(payment): buildX402AcceptsFor402 + probe extra.name fix (1.3.2)#10
vvillait88 merged 1 commit intomainfrom
feat/x402-build-accepts-helper-and-probe-fix

Conversation

@vvillait88
Copy link
Copy Markdown
Contributor

Summary

Mirrors the python-commerce 1.3.4 cleanup. Two parallel goals:

  1. Lift up the boilerplate every Node merchant inlines 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 (the actual USDC contract returns name() = "USD Coin"), correct on sepolia (name() = "USDC").

New public API

import { buildX402AcceptsFor402 } from '@agent-score/commerce/payment';

const accepts = await buildX402AcceptsFor402(x402Server, {
  network: X402_BASE,
  price: `$${totalUsd}`,
  payTo: process.env.TREASURY_BASE_RECIPIENT!,
  maxTimeoutSeconds: 300,
});

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 (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.md gain a buildX402AcceptsFor402 snippet.
  • core/docs/integrations/node-commerce.mdx (Mintlify) updated in the companion core PR (#237).

Test plan

  • CI green.
  • Tag v1.3.2, push tag → npm publish.
  • Follow-up: refactor martin-estate/src/routes/purchase.ts to use the new helper (currently calls x402Server.buildPaymentRequirements(...) directly with an as never cast — works, but the helper drops the cast and tightens the type story).

🤖 Generated with Claude Code

…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>
@vvillait88 vvillait88 merged commit b22e668 into main May 5, 2026
6 checks passed
@vvillait88 vvillait88 deleted the feat/x402-build-accepts-helper-and-probe-fix branch May 5, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant