Open
Conversation
Verify endpoint: send {paymentHeader, resource, maxAmount} instead of
{paymentRequirements}, read `valid` not `isValid` from response.
Settle endpoint: send {paymentHeader, merchantWallet, amount, asset}
instead of {paymentRequirements}, read `txHash` not `transaction`.
Add X-API-Key header support (required by facilitator auth middleware).
Update example facilitator URL to x402.kamiyo.ai.
Author
|
The verify and settle functions don't match the KAMIYO facilitator API contract. The requests will fail as-is. I pushed fixes to Verify endpoint (
Settle endpoint (
Auth
Other
Commit: kamiyo-ai/ShadowWire@62fd190 |
Fix inverted content-type check in safeParseBody. Restrict findCompatibleRequirement to shadowwire-only schemes. Add retry backoff on 5xx after payment. Add Vary: X-Payment header to prevent cache poisoning. Reject proof resource mismatch before calling facilitator. Improve abort detection for non-DOM runtimes. Remove unadvertised 'exact' scheme from discovery document.
- Add X402InvalidSchemeError, X402HeaderTooLargeError, X402FacilitatorError - Replace generic error strings with typed errors in x402.ts - Add JSDoc to public x402 exports - Add vitest with 35 test cases covering encode/decode, request flow, middleware, verify/settle, and discovery document - Fix Unicode-unsafe browser base64 (btoa/atob → TextEncoder path) - Add x402Version validation in decodePaymentHeader - Use URL API for facilitator endpoint composition - Wrap onPayment callback in try/catch to prevent post-settlement crashes - Split x402-payment.ts into focused x402-server.ts and x402-client.ts
Make facilitatorUrl optional in X402MiddlewareConfig with a built-in default so SDK consumers don't need to specify it explicitly.
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
Adds x402 (HTTP 402 Payment Required) support to ShadowWire, enabling privacy-preserving API monetization with Bulletproof-shielded payments.
X402Clientclass that detects 402 responses, pays via ShadowWire transfer, and retries with anX-Paymentheaderx402Paywall()Express middleware that gates routes behind payment, delegating verification and settlement to an external facilitatorcreateDiscoveryDocument()for.well-known/x402endpoint generationNew exports
X402Clientx402PaywallcreatePaymentRequiredverifyPaymentsettlePaymentcreateDiscoveryDocumentPayment flow
New
shadowwireschemeThe x402
acceptsarray includes ashadowwirescheme alongside the standardexactscheme, advertising Bulletproof-based private payments with amount hiding.Test plan
npm run buildpasses cleanX402Client.request()handles non-402, 402 with payment, and 402 rejection flowspay()rejects non-shadowwire schemes before initiating transferX-Paymentpresentreq.x402encodePaymentHeader/decodePaymentHeaderround-trip correctlyBuffer