feat(x402): payment middleware pipeline and two-phase approval flow#87
Open
zhongeric wants to merge 1 commit intoConway-Research:mainfrom
Open
feat(x402): payment middleware pipeline and two-phase approval flow#87zhongeric wants to merge 1 commit intoConway-Research:mainfrom
zhongeric wants to merge 1 commit intoConway-Research:mainfrom
Conversation
x402Fetch previously auto-signed any 402 payment without agent evaluation. This introduces a middleware pipeline and a two-phase tool flow so the agent reasons about each payment before committing funds: - Phase 1 (discover): x402_fetch returns payment details without signing - Phase 2 (pay): x402_fetch with approve_payment: true runs middleware, signs, and logs the transaction Also adds PaymentMiddleware/PaymentContext types, x402_payment transaction type, 11 new tests, and README documentation. Co-Authored-By: Claude Opus 4.6 <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
x402_fetchtool: Phase 1 discovers payment details (amount, recipient, network, wallet balance) without signing. Phase 2 (approve_payment: true) runs the middleware chain, signs the USDC payment, and logs the transaction — giving the agent a reasoning turn before committing funds.PaymentMiddleware[]runs before every signing attempt. Phase 1 uses a blocking middleware to force the early return. Phase 2 runs with an empty chain, open for future additions (balance checks, rate limits, allowlists) without changingx402Fetch.x402_paymenttransactions with amount and description, following the existingtransfer_creditspattern.Changes
src/types.ts"x402_payment"toTransactionTypeunionsrc/conway/x402.tsPaymentRequirement/X402PaymentResult; addedPaymentContext,PaymentMiddleware,X402FetchOptionstypes; refactoredx402Fetchwith middleware pipeline and backward-compatible signaturesrc/agent/tools.tsx402_fetchtool withapprove_paymentparameter, two-phase handler, and transaction loggingsrc/__tests__/x402.test.tsREADME.mdTest plan
pnpm build— clean compilationpnpm test— 21/21 tests pass (11 new x402 tests + 10 existing)x402_fetchagainst an x402-gated URL, confirm Phase 1 returns payment details without signingx402_fetchwithapprove_payment: true, confirm payment is signed and response is returned🤖 Generated with Claude Code