feat: settle in requirePayment + x402 v2 upgrade + unit/identity fixes#151
Merged
feat: settle in requirePayment + x402 v2 upgrade + unit/identity fixes#151
Conversation
…sign) Settlement now happens inside requirePayment() instead of the Express middleware. This is the correct design because: 1. requirePayment has the pricing context (amount, options, destination) needed to regenerate protocol-specific settlement data 2. For X402, the server regenerates paymentRequirements from its own config (standard X402 pattern — no state from previous request needed) 3. The middleware's only job is detection + context storage Flow: - Middleware: detectProtocol() → setDetectedCredential() in ATXP context - requirePayment: getDetectedCredential() → settle with pricing context → charge from credited ledger Changes: - atxpContext: DetectedCredential type, get/setDetectedCredential helpers - requirePayment: settleDetectedCredential() with full pricing context - X402: fetches destination sources, builds requirements, passes to settle - ATXP: passes sourceAccountToken + options - MPP: passes credential (self-contained) - atxpExpress: simplified — detect + store credential, no settlement logic - protocol.ts: X402PaymentOption adds asset field, buildRequestBody extracts first accept from X402PaymentRequirements for auth schema compatibility - omniChallenge: includes asset + mimeType in X402 accepts Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Settlement failure throws McpError(-32000) instead of swallowing error and falling through to confusing insufficient_balance + new challenge - 3 new tests: settlement success, settlement failure (McpError), no credential - Removed unused X402PaymentRequirements import - Documented: testnet asset/network mismatch, per-request ProtocolSettlement, first-accept extraction rationale Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…r cleanup - Express middleware tests updated: verify credential stored in context, handler proceeds (no settle/402 from middleware) - Fix payeeName null handling inconsistency - Remove temp cli-base-temp.ts Co-Authored-By: Claude Opus 4.6 (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
Moves settlement from Express middleware to
requirePayment()(stateless design), upgrades x402 to v2 packages, and fixes unit/identity mismatches.Architecture: settle in requirePayment
requirePayment()settles with full pricing context (regenerates X402 requirements from server config)x402 v2 upgrade
@x402/core+@x402/evmreplacex402v1 packageamount(notmaxAmountRequired), CAIP-2 networks, x402Version 2PAYMENT-SIGNATUREheader (v2) detected alongsideX-PAYMENT(v1 fallback)Unit/identity fixes
E2E Verified
Full X402 payment on Base mainnet via CDP facilitator:
0x23f9260e913ca98d04c4496aaf4f2eff65dce2ef8446bbc5216e4e281b79b169Test plan
🤖 Generated with Claude Code