Skip to content

feat(x402): add pre-sign spend policy guardrails and offline delivery receipt verification - #1660

Open
k-luecke wants to merge 15 commits into
coinbase:mainfrom
k-luecke:feat/x402-spend-policy-and-receipts
Open

k-luecke wants to merge 15 commits into
coinbase:mainfrom
k-luecke:feat/x402-spend-policy-and-receipts

Conversation

@k-luecke

Copy link
Copy Markdown

Description

Adds deterministic pre-sign spend policy enforcement and offline cryptographic delivery receipt verification to X402ActionProvider across both TypeScript (@coinbase/agentkit) and Python (coinbase-agentkit), using the zero-dependency MIT reference implementation (@paxiom/receipts / paxiom-receipts v0.3.0).

Why

  1. Closes two live pre-sign gaps in X402ActionProvider:
    • make_http_request_with_x402 previously invoked wrapFetchWithPayment / x402_requests without validating maxPaymentUsdc, USDC-only asset restrictions, or wallet network compatibility against the live 402 challenge.
    • retry_http_request_with_x402 validated selectedPaymentOption from the prior step, while wrapFetchWithPayment / x402_requests fetched a fresh 402 challenge before signing—allowing dynamic price escalation or payTo bait-and-switch between the initial 402 and the retry.
  2. Adds opt-in pre-sign spendPolicy + reservation-safe SpendLedger (X402Config):
    • Evaluates the live 402 selectedRequirements inside onBeforePaymentCreation / on_before_payment_creation before any wallet signature is created (allowedPayTo, pinnedPayToByOrigin, maxPerCallAtomic, maxPerOriginWindowAtomic, maxSessionAtomic, maxUnescrowedExactAtomic, allowedSchemes, trustedOperators, and per-origin failure circuit breakers).
  3. Adds post-delivery Payment-Receipt (paxiom.receipt.v0) & AuthCaptureEscrow verification:
    • Automatically verifies Payment-Receipt / X-Paxiom-Receipt Ed25519 signatures and JCS / raw SHA-256 response payload bindings (outputHash) offline, returning structured CAPTURE / VOID arbitration and non-repudiable fraudEvidence (enforced fail-closed when requireDeliveryReceipt: true).
    • Adds a read-only verify_x402_delivery_receipt action for offline receipt inspection and escrow arbitration without network calls.
    • @paxiom/receipts and paxiom-receipts are MIT-licensed with zero transitive dependencies.

Refs #1539, #1576, #1582

Tests

  • TypeScript (typescript/agentkit):
    • pnpm run format:check, pnpm run lint, pnpm run check (tsc --noEmit), and Jest unit tests (x402ActionProvider.test.ts):
      • Verifies live onBeforePaymentCreation aborts unauthorized payTo / bait-and-switch challenges before signing.
      • Verifies valid Payment-Receipt headers return action: "CAPTURE" and commit atomic spend to SpendLedger, while tampered response payloads fail closed with action: "VOID" (receipt_output_hash_mismatch).
      • Verifies standalone offline verify_x402_delivery_receipt.
  • Python (python/coinbase-agentkit):
    • uv run ruff format . --check, uv run ruff check ., uv run check-description-length, and uv run pytest tests/action_providers/x402/test_x402_action_provider.py:
      • Verifies 1:1 parity across spend_policy pre-sign aborts, MemorySpendLedger reservation/commit, CAPTURE/VOID receipt verification, and verify_x402_delivery_receipt.
Setup: X402ActionProvider configured with spendPolicy ({ allowedPayTo, maxSessionAtomic: "100000" }), requireDeliveryReceipt: true, and pinned seller Ed25519 key on Base Sepolia

Prompt: Retry https://www.x402.org/protected with the 0.01 USDC Base Sepolia payment option and verify the delivery receipt

-------------------
{
  "status": "success",
  "data": { "weather": "sunny", "tempF": 72 },
  "message": "Request completed successfully with payment",
  "details": {
    "url": "https://www.x402.org/protected",
    "method": "GET",
    "paymentUsed": {
      "network": "base-sepolia",
      "asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
      "amount": "10000"
    },
    "deliveryReceipt": {
      "valid": true,
      "action": "CAPTURE",
      "reasonCode": "verified_delivery",
      "settlementFinality": "escrow_hold",
      "captureAmountAtomic": "10000"
    }
  }
}
-------------------

Checklist

  • Added documentation to all relevant README.md files
  • Added a changelog entry

… verification

Enforce live 402 pre-sign policy guardrails and offline Ed25519 Payment-Receipt verification in TypeScript X402ActionProvider.

Refs coinbase#1539, coinbase#1576, coinbase#1582
…ification

Add 1:1 Python X402ActionProvider parity for live 402 pre-sign spend policy guardrails and offline Payment-Receipt verification.

Refs coinbase#1539, coinbase#1576, coinbase#1582
Sync Python example lockfiles with paxiom-receipts dependency.
Sync Python example lockfiles with paxiom-receipts dependency.
Sync Python example lockfiles with paxiom-receipts dependency.
Sync Python example lockfiles with paxiom-receipts dependency.
Sync Python example lockfiles with paxiom-receipts dependency.
Sync Python example lockfiles with paxiom-receipts dependency.
Sync Python example lockfiles with paxiom-receipts dependency.
Sync Python example lockfiles with paxiom-receipts dependency.
Sync Python example lockfiles with paxiom-receipts dependency.
Sync Python example lockfiles with paxiom-receipts dependency.
Sync Python example lockfiles with paxiom-receipts dependency.
Sync Python example lockfiles with paxiom-receipts dependency.
Sync Python example lockfiles with paxiom-receipts dependency.
@cb-heimdall

Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
1 if authored by an app that is not allowlisted and lacks verified human attribution 0
Sum 1

@github-actions github-actions Bot added documentation Improvements or additions to documentation action provider New action provider example New example agent python typescript labels Nov 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action provider New action provider documentation Improvements or additions to documentation example New example agent python typescript

Development

Successfully merging this pull request may close these issues.

2 participants