import { Address, Hex } from 'viem'; /** * EIP-712 domain name for Circle Gateway batched payments. * Used in the `extra.name` field of PaymentRequirements to identify Circle batching options. */ declare const CIRCLE_BATCHING_NAME = "GatewayWalletBatched"; /** * EIP-712 domain version for Circle Gateway batched payments. * Used in the `extra.version` field of PaymentRequirements. */ declare const CIRCLE_BATCHING_VERSION = "1"; /** * The payment scheme used for Circle batching (same as standard x402 exact scheme). */ declare const CIRCLE_BATCHING_SCHEME = "exact"; /** * Authorization validity window the SDK should publish and sign with. */ declare const GATEWAY_AUTH_VALIDITY_WINDOW_SECONDS: number; /** * Extra fields specific to Circle Gateway batching in PaymentRequirements. */ interface BatchExtra { /** EIP-712 domain name - must be "GatewayWalletBatched" */ name: typeof CIRCLE_BATCHING_NAME; /** EIP-712 domain version - must be "1" */ version: typeof CIRCLE_BATCHING_VERSION; /** The GatewayWallet contract address used as verifyingContract in EIP-712 */ verifyingContract: Address; } /** * Configuration for BatchFacilitatorClient. */ interface BatchFacilitatorConfig { /** Base URL of Circle Gateway. Defaults to "https://gateway-api.circle.com" */ url?: string; /** * Additional headers merged into every outbound Gateway API request. * These take precedence over auth headers from `createAuthHeaders` on collision. */ headers?: Record; /** Optional function to create auth headers for requests */ createAuthHeaders?: () => Promise<{ verify: Record; settle: Record; supported: Record; }>; } /** * EIP-3009 TransferWithAuthorization message structure. */ interface TransferWithAuthorizationMessage { from: Address; to: Address; value: bigint; validAfter: bigint; validBefore: bigint; nonce: Hex; } /** * EVM signer interface for creating payment payloads. */ interface BatchEvmSigner { /** The signer's address */ address: Address; /** Sign EIP-712 typed data */ signTypedData: (params: { domain: { name: string; version: string; chainId: number; verifyingContract: Address; }; types: Record>; primaryType: string; message: Record; }) => Promise; } /** * Payload structure for batching payments. */ interface BatchPayload { signature: Hex; authorization: { from: Address; to: Address; value: string; validAfter: string; validBefore: string; nonce: Hex; }; } /** * Lifecycle hook types for the Circle Gateway batching SDK. * * These mirror the lifecycle hooks defined in the standard `@x402/core` SDK. * See https://docs.x402.org/advanced-concepts/lifecycle-hooks for the full * reference. The semantics implemented here match that documentation: hooks * receive a read-only context, drive control flow via `abort` / `skip` / * `recovered` return values, and a thrown hook is logged but does not break * the surrounding payment flow (the next hook still runs). */ /** * Minimal `PaymentPayload` shape (subset used by hook contexts). */ interface HookPaymentPayload { x402Version: number; payload: Record; resource?: { url: string; description: string; mimeType: string; }; accepted?: Record; extensions?: Record; } /** * Minimal `PaymentRequirements` shape (subset used by hook contexts). */ interface HookPaymentRequirements { scheme: string; network: string; asset: string; amount: string; payTo: string; maxTimeoutSeconds: number; extra?: Record; } /** * Minimal `VerifyResponse` shape (subset used by hook contexts). */ interface HookVerifyResponse { isValid: boolean; invalidReason?: string; payer?: string; } /** * Minimal `SettleResponse` shape (subset used by hook contexts). */ interface HookSettleResponse { success: boolean; errorReason?: string; payer?: string; transaction: string; network: string; } interface VerifyContext { paymentPayload: HookPaymentPayload; requirements: HookPaymentRequirements; } interface VerifyResultContext extends VerifyContext { result: HookVerifyResponse; } interface VerifyFailureContext extends VerifyContext { error: Error; } interface SettleContext { paymentPayload: HookPaymentPayload; requirements: HookPaymentRequirements; } interface SettleResultContext extends SettleContext { result: HookSettleResponse; } interface SettleFailureContext extends SettleContext { error: Error; } /** * Reason a verified payment never reached settlement. `handler_threw` matches * the standard SDK's reason for "the protected handler errored". */ type VerifiedPaymentCancellationReason = 'handler_threw' | 'handler_failed'; interface VerifiedPaymentCanceledContext extends SettleContext { reason: VerifiedPaymentCancellationReason; error?: unknown; responseStatus?: number; } type BeforeVerifyHook = (context: VerifyContext) => Promise; type AfterVerifyHook = (context: VerifyResultContext) => Promise; type OnVerifyFailureHook = (context: VerifyFailureContext) => Promise; type BeforeSettleHook = (context: SettleContext) => Promise; type AfterSettleHook = (context: SettleResultContext) => Promise; type OnSettleFailureHook = (context: SettleFailureContext) => Promise; type OnVerifiedPaymentCanceledHook = (context: VerifiedPaymentCanceledContext) => Promise; type FacilitatorBeforeVerifyHook = (context: VerifyContext) => Promise; type FacilitatorAfterVerifyHook = (context: VerifyResultContext) => Promise; type FacilitatorOnVerifyFailureHook = (context: VerifyFailureContext) => Promise; type FacilitatorBeforeSettleHook = (context: SettleContext) => Promise; type FacilitatorAfterSettleHook = (context: SettleResultContext) => Promise; type FacilitatorOnSettleFailureHook = (context: SettleFailureContext) => Promise; /** * Minimal HTTP request descriptor passed to `onProtectedRequest`. Mirrors the * shape standard x402 uses, but reduced to the bits the gateway middleware * actually has access to. */ interface ProtectedRequestContext { /** The HTTP method (uppercase, e.g. "GET"). */ method: string; /** The request path (no query string). */ path: string; /** Full URL as advertised in the 402 response (may equal `path`). */ url: string; /** * Case-insensitive header lookup. Returns `undefined` for unknown headers. */ getHeader(name: string): string | undefined; } interface ProtectedRouteConfig { /** Price string passed to `gateway.require(...)`. */ price: string; } type ProtectedRequestHook = (context: ProtectedRequestContext, routeConfig: ProtectedRouteConfig) => Promise; /** * Minimal `PaymentRequired` shape passed to client hook contexts. */ interface HookPaymentRequired { x402Version: number; resource?: { url: string; description: string; mimeType: string; }; accepts: HookPaymentRequirements[]; extensions?: Record; error?: string; } interface PaymentCreationContext { paymentRequired: HookPaymentRequired; selectedRequirements: HookPaymentRequirements; } interface PaymentCreatedContext extends PaymentCreationContext { paymentPayload: HookPaymentPayload; } interface PaymentCreationFailureContext extends PaymentCreationContext { error: Error; } interface PaymentResponseContext { paymentPayload: HookPaymentPayload; requirements: HookPaymentRequirements; settleResponse?: HookSettleResponse; paymentRequired?: HookPaymentRequired; error?: Error; } type BeforePaymentCreationHook = (context: PaymentCreationContext) => Promise; type AfterPaymentCreationHook = (context: PaymentCreatedContext) => Promise; type OnPaymentCreationFailureHook = (context: PaymentCreationFailureContext) => Promise; type OnPaymentResponseHook = (context: PaymentResponseContext) => Promise; export { type AfterVerifyHook as A, type BatchFacilitatorConfig as B, CIRCLE_BATCHING_NAME as C, type SettleResultContext as D, type SettleFailureContext as E, type FacilitatorBeforeVerifyHook as F, GATEWAY_AUTH_VALIDITY_WINDOW_SECONDS as G, type HookPaymentPayload as H, type VerifiedPaymentCanceledContext as I, type VerifiedPaymentCancellationReason as J, type ProtectedRequestContext as K, type ProtectedRouteConfig as L, type PaymentCreationContext as M, type PaymentCreatedContext as N, type OnVerifyFailureHook as O, type ProtectedRequestHook as P, type PaymentCreationFailureContext as Q, type SettleContext as S, type TransferWithAuthorizationMessage as T, type VerifyContext as V, type FacilitatorAfterVerifyHook as a, type FacilitatorOnVerifyFailureHook as b, type FacilitatorBeforeSettleHook as c, type FacilitatorAfterSettleHook as d, type FacilitatorOnSettleFailureHook as e, type BeforeVerifyHook as f, type BeforeSettleHook as g, type AfterSettleHook as h, type OnSettleFailureHook as i, type OnVerifiedPaymentCanceledHook as j, type BatchPayload as k, type BatchEvmSigner as l, type BeforePaymentCreationHook as m, type AfterPaymentCreationHook as n, type OnPaymentCreationFailureHook as o, type OnPaymentResponseHook as p, type PaymentResponseContext as q, CIRCLE_BATCHING_VERSION as r, CIRCLE_BATCHING_SCHEME as s, type BatchExtra as t, type HookPaymentRequirements as u, type HookPaymentRequired as v, type HookVerifyResponse as w, type HookSettleResponse as x, type VerifyResultContext as y, type VerifyFailureContext as z };