Skip to content

fix(x402): align PaymentRequirement with x402 v1 spec#83

Open
zhongeric wants to merge 1 commit intoConway-Research:mainfrom
zhongeric:fix/x402-payment-requirement-v1-spec
Open

fix(x402): align PaymentRequirement with x402 v1 spec#83
zhongeric wants to merge 1 commit intoConway-Research:mainfrom
zhongeric:fix/x402-payment-requirement-v1-spec

Conversation

@zhongeric
Copy link

Summary

  • Renames local PaymentRequirement fields to match the x402 v1 spec: usdcAddressasset, payToAddresspayTo, requiredDeadlineSecondsmaxTimeoutSeconds
  • Adds the extra field ({ name, version }) from the spec, which carries the EIP-712 domain parameters needed for TransferWithAuthorization signing
  • signPayment now reads extra.name / extra.version from the server's payment requirement instead of hardcoding "USD Coin" / "2", enabling valid signatures for non-USDC EIP-3009 tokens (e.g. EURC)
  • Falls back to USDC defaults (name: "USD Coin", version: "2", USDC contract address) when the server omits extra or asset
  • Preserves backwards-compatible fallbacks for the old non-standard field names (payToAddress, usdcAddress, requiredDeadlineSeconds), marked @deprecated

Test plan

  • Verify pnpm build passes cleanly (confirmed locally)
  • Test against a server sending standard v1 fields (payTo, asset, maxTimeoutSeconds, extra)
  • Test against a server sending old non-standard fields (payToAddress, usdcAddress, requiredDeadlineSeconds) to confirm backwards compat
  • Test with a server omitting extra to confirm USDC fallback defaults apply
  • Test with a non-USDC token (e.g. EURC) that provides extra: { name: "EURC", version: "1" } to confirm correct EIP-712 signature

🤖 Generated with Claude Code

The local PaymentRequirement interface used non-standard field names
(usdcAddress, payToAddress, requiredDeadlineSeconds) and hardcoded
the EIP-712 domain to USDC, making it impossible to sign valid payments
for other EIP-3009 tokens (e.g. EURC).

- Rename fields to match x402 v1 spec: asset, payTo, maxTimeoutSeconds
- Add `extra` field (name, version) for EIP-712 domain parameters
- Use `extra` in signPayment instead of hardcoded "USD Coin" / "2"
- Fall back to USDC defaults when server omits `extra` or `asset`
- Preserve deprecated fallbacks for old non-standard field names

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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