/** * x402 + A2A in-band integration utilities (x402 v2 A2A transport). * * Port of the Python SDK's `payments_py/x402/a2a.py` `X402A2AUtils`. These * helpers bridge the x402 payment protocol with the A2A (Agent-to-Agent) * protocol, signalling payment state *in band* through A2A Task / Message * metadata instead of HTTP status codes and headers. * * The A2A transport equivalent of the MCP transport's `_meta["x402/payment"]` * keys is the A2A **task / message metadata** under the spec-defined * `x402.payment.*` keys (see {@link X402A2AMetadata}). The wire shapes are * defined by: * - Coinbase x402 v2 A2A transport: specs/transports-v2/a2a.md * - A2A x402 extension: https://github.com/google-agentic-commerce/a2a-x402 * * These constants/keys are part of the specification and MUST NOT be changed. */ import type { Message, Task } from '@a2a-js/sdk'; import type { SettlePermissionsResult, X402PaymentRequired } from '../x402/facilitator-api.js'; /** * Protocol-defined payment states for the A2A x402 flow. * * Tracked in the `x402.payment.status` metadata field. Values are part of the * A2A x402 specification (Section 6: State Management) and must not be changed. */ export declare enum PaymentStatus { /** Payment requirements sent to client (task state `input-required`). */ PAYMENT_REQUIRED = "payment-required", /** Payment payload received by server. */ PAYMENT_SUBMITTED = "payment-submitted", /** Payment payload verified by the facilitator. */ PAYMENT_VERIFIED = "payment-verified", /** Payment requirements rejected by the client. */ PAYMENT_REJECTED = "payment-rejected", /** Payment settled on-chain successfully (task state `completed`). */ PAYMENT_COMPLETED = "payment-completed", /** Payment verification or settlement failed (task state `failed`). */ PAYMENT_FAILED = "payment-failed" } /** * Spec-defined A2A task / message metadata keys for the x402 protocol. * * As defined in the A2A x402 specification (Section 6: State Management). These * keys are part of the specification and must not be changed. Note these are * NOT the MCP `_meta["x402/payment"]` keys — A2A signals payment state through * Task / Message `metadata` instead. */ export declare const X402A2AMetadata: { /** Current payment flow stage. */ readonly STATUS_KEY: "x402.payment.status"; /** X402PaymentRequired object. */ readonly REQUIRED_KEY: "x402.payment.required"; /** PaymentPayload object (client → server). */ readonly PAYLOAD_KEY: "x402.payment.payload"; /** Array of SettleResponse receipts (server → client). */ readonly RECEIPTS_KEY: "x402.payment.receipts"; /** Error code on failure. */ readonly ERROR_KEY: "x402.payment.error"; }; /** * Nevermined-specific (non-core-spec) marker set alongside `payment-verified` * when on-chain settlement is **deferred** to a batch process this handler does * not confirm. Lets a client distinguish "verified, will be charged out-of-band" * from a plain verify; spec-only clients ignore the unknown key. Value: `'deferred'`. */ export declare const X402_SETTLEMENT_DEFERRED_KEY = "x402.payment.settlement"; /** * Utilities for managing x402 payment state in A2A messages and tasks. * * Provides methods to extract payment status / requirements / payload from * incoming A2A messages and tasks, and to stamp payment-required, verified, * completed and failed state onto outgoing tasks — all via the spec-defined * `x402.payment.*` metadata keys. */ export declare class X402A2AUtils { static readonly STATUS_KEY: "x402.payment.status"; static readonly REQUIRED_KEY: "x402.payment.required"; static readonly PAYLOAD_KEY: "x402.payment.payload"; static readonly RECEIPTS_KEY: "x402.payment.receipts"; static readonly ERROR_KEY: "x402.payment.error"; /** Extract the payment status from a Message's metadata, or `undefined`. */ getPaymentStatusFromMessage(message?: Message | null): string | undefined; /** Extract the payment status from a Task's status message metadata, or `undefined`. */ getPaymentStatus(task?: Task | null): string | undefined; /** * Extract the X402PaymentRequired object from a Message's metadata. * * Returns the raw object (already spec-shaped JSON). Returns `undefined` when * absent or not a plain object. */ getPaymentRequirementsFromMessage(message?: Message | null): X402PaymentRequired | undefined; /** Extract the X402PaymentRequired object from a Task's status message metadata. */ getPaymentRequirements(task?: Task | null): X402PaymentRequired | undefined; /** * Extract the in-band PaymentPayload object from a Message's metadata. * * The payload is untrusted client input that the server re-encodes into an * access token, so this rejects null, arrays and oversized payloads * (defense-in-depth, parity with the MCP `readPaymentPayload`). * * @returns The PaymentPayload object, or `undefined` when absent/invalid. */ getPaymentPayloadFromMessage(message?: Message | null): Record | undefined; /** Extract the in-band PaymentPayload object from a Task's status message metadata. */ getPaymentPayload(task?: Task | null): Record | undefined; /** * Set a Task to the payment-required state (`input-required`) with the * X402PaymentRequired object in `x402.payment.required` metadata. * * Mutates and returns `task` (in place), per the x402 v2 A2A transport. */ createPaymentRequiredTask(task: Task, paymentRequired: X402PaymentRequired): Task; /** * Record payment verification on a Task: sets the `x402.payment.status` * metadata to `payment-verified`. Task state is left to the caller (the spec * keeps it `working`). */ recordPaymentVerified(task: Task): Task; /** * Record a deferred (batch) settlement on a Task: the payload was verified but * on-chain settlement is deferred out-of-band (the handler never confirms it). * Sets `payment-verified` PLUS the Nevermined `x402.payment.settlement: 'deferred'` * marker, so a client can tell it will be charged out-of-band — distinct from a * plain verify where nothing is owed. */ recordPaymentDeferred(task: Task): Task; /** * Record a successful settlement on a Task: sets the `x402.payment.status` * metadata to `payment-completed` and stores the SettleResponse receipt under * `x402.payment.receipts` (an array, per the spec). */ recordPaymentSuccess(task: Task, settleResponse?: SettlePermissionsResult): Task; /** * Record a payment failure on a Task: `x402.payment.status = payment-failed`, * the error code under `x402.payment.error`, and (when available) the failed * SettleResponse under `x402.payment.receipts`. */ recordPaymentFailure(task: Task, errorCode: string, errorResponse?: SettlePermissionsResult): Task; } /** Shared singleton, matching the Python `X402A2AUtils()` usage pattern. */ export declare const x402A2AUtils: X402A2AUtils; //# sourceMappingURL=x402-a2a.d.ts.map