Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(x402): add TypeScript pre-sign spend policy and delivery receipt…
… verification

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

Refs #1539, #1576, #1582
  • Loading branch information
k-luecke authored Nov 18, 2026
commit 3bda50d1fb51c000be3923092ee2f8bcbc28fe5c
5 changes: 5 additions & 0 deletions typescript/.changeset/add-x402-spend-policy-and-receipts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@coinbase/agentkit": patch
---

Added live pre-sign spend policy enforcement (`spendPolicy` + rolling `SpendLedger`) and offline Ed25519 delivery receipt verification (`Payment-Receipt` / `paxiom.receipt.v0` + `AuthCaptureEscrow` `CAPTURE`/`VOID` arbitration) to `X402ActionProvider`, closing live `maxPaymentUsdc` and `payTo` bait-and-switch gaps across `make_http_request_with_x402` and `retry_http_request_with_x402`.
1 change: 1 addition & 0 deletions typescript/agentkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@dtelecom/x402-client": "^0.1.3",
"@ensofinance/sdk": "^2.0.6",
"@jup-ag/api": "^6.0.39",
"@paxiom/receipts": "^0.3.0",
"@privy-io/public-api": "2.18.5",
"@privy-io/server-auth": "1.18.4",
"@solana/kit": "^2.1.1",
Expand Down
21 changes: 18 additions & 3 deletions typescript/agentkit/src/action-providers/x402/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,29 @@ const config: X402Config = {

// Maximum payment per request in USDC
// Default: 1.0 (or X402_MAX_PAYMENT_USDC env var)
maxPaymentUsdc: 0.5
maxPaymentUsdc: 0.5,

// Optional deterministic pre-sign buyer firewall policy (evaluated against live 402 challenges)
spendPolicy: {
allowedPayTo: ["0x209693Bc6afc0C5328bA36FaF03C514EF312287C"],
maxPerCallAtomic: "500000",
maxSessionAtomic: "2000000",
},

// Optional: require cryptographically valid Ed25519 Payment-Receipt headers on paid responses
requireDeliveryReceipt: false,
expectedIssuerPublicKeys: {
"https://api.example.com": ["<seller-ed25519-pubkey-base64>"],
},
};

const provider = x402ActionProvider(config);
```

- **Service Whitelisting**: Only registered service URLs can be called
- **USDC-Only Payments**: All payments are restricted to USDC assets only
- **Payment Limits**: Enforces maximum payment amount per request (default: 1.0 USDC)
- **USDC-Only Payments**: All payments are restricted to USDC assets only (enforced against live 402 challenges)
- **Payment Limits & Pre-Sign Spend Policy**: Enforces `maxPaymentUsdc`, bait-and-switch protection, and optional rolling `SpendLedger` / `payTo` pinning before signing
- **Delivery Receipt & Escrow Verification**: Automatically verifies `Payment-Receipt` (`paxiom.receipt.v0`) headers and computes `AuthCaptureEscrow` `CAPTURE`/`VOID` verdicts offline
- **Dynamic Registration Control**: Optional runtime service registration via agent

## Actions
Expand All @@ -67,6 +81,7 @@ const provider = x402ActionProvider(config);

- `make_http_request_with_x402`: Direct payment-enabled requests (skips confirmation flow)
- `discover_x402_services`: Discover available x402 services (filter by price, keyword, etc.)
- `verify_x402_delivery_receipt`: Offline verification of an Ed25519 `Payment-Receipt` header or JSON receipt against delivered response output

## Overview

Expand Down
2 changes: 1 addition & 1 deletion typescript/agentkit/src/action-providers/x402/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./x402ActionProvider";
export type { X402Config } from "./schemas";
export type { BuyerFirewallPolicy, SpendLedger, X402Config } from "./schemas";
56 changes: 55 additions & 1 deletion typescript/agentkit/src/action-providers/x402/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { z } from "zod";
import type { BuyerFirewallPolicy, SpendLedger } from "@paxiom/receipts/guard";
import { DEFAULT_FACILITATOR } from "./constants";

export type { BuyerFirewallPolicy, SpendLedger };

/**
* Schema for listing registered services/facilitators (no parameters required).
*/
export const EmptySchema = z.object({}).describe("No parameters required");

/**
* Configuration options for X402ActionProvider.

*/
export interface X402Config {
/** Service URLs the agent can call. Only these services will be allowed for HTTP requests. */
Expand All @@ -32,6 +34,31 @@ export interface X402Config {
* Default: 1.0 (or X402_MAX_PAYMENT_USDC env var)
*/
maxPaymentUsdc?: number;

/**
* Optional deterministic pre-sign buyer firewall policy evaluated against the live 402
* challenge before any wallet signature is created (payTo allowlists/pinning, rolling
* per-origin and session atomic caps, allowed schemes/networks/assets, and escrow terms).
*/
spendPolicy?: BuyerFirewallPolicy;

/**
* Optional reservation-safe spend and circuit-breaker ledger shared across calls.
* Automatically initialized in memory when `spendPolicy` is configured.
*/
spendLedger?: SpendLedger;

/**
* Require paid x402 responses to carry a cryptographically valid `Payment-Receipt`
* (`paxiom.receipt.v0`) bound to the delivered response payload. Default: false.
*/
requireDeliveryReceipt?: boolean;

/**
* Optional pinned Ed25519 seller public keys (base64) for `Payment-Receipt` verification,
* specified either as a global list or mapped by lowercase service origin.
*/
expectedIssuerPublicKeys?: string[] | Record<string, string[]>;
}

/**
Expand Down Expand Up @@ -204,3 +231,30 @@ export const DirectX402RequestSchema = z
.describe(
"Instructions for making an HTTP request with automatic x402 payment handling. WARNING: This bypasses user confirmation - only use when explicitly told to skip confirmation!",
);

/**
* Schema for verifying an Ed25519-signed x402 delivery receipt offline.
*/
export const VerifyDeliveryReceiptSchema = z
.object({
receiptOrHeader: z
.string()
.describe(
"Base64url Payment-Receipt / X-Paxiom-Receipt header value or serialized JSON receipt object",
),
responseBody: z
.any()
.nullable()
.describe(
"Optional delivered response body (JSON object or raw string) to verify outputHash payload binding",
),
expectedPayTo: z
.string()
.nullable()
.describe("Optional expected recipient wallet address to verify payTo authorization"),
expectedIssuerPublicKeys: z
.array(z.string())
.nullable()
.describe("Optional allowed Ed25519 seller public keys (base64)"),
})
.describe("Parameters for offline verification of an x402 delivery receipt");
Loading