/** * x402 Protocol Helpers * Native implementations of x402 protocol types and helpers. * No external x402 SDK dependency — all logic is self-contained. */ /** * CAIP-2 Network identifier for Stacks */ export type NetworkV2 = `stacks:${string}`; /** * Information about the protected resource */ export interface ResourceInfo { /** URL of the protected resource */ url: string; /** Human-readable description of the resource */ description?: string; /** MIME type of the expected response */ mimeType?: string; } /** * Payment requirements for x402 v2 protocol */ export interface PaymentRequirementsV2 { /** Payment scheme identifier (e.g., "exact") */ scheme: string; /** Network identifier in CAIP-2 format (e.g., "stacks:1") */ network: NetworkV2; /** Required payment amount in atomic units (microSTX, satoshis, etc.) */ amount: string; /** Asset identifier ("STX" or contract identifier like "SP...address.contract-name") */ asset: string; /** Recipient address */ payTo: string; /** Maximum time allowed for payment completion */ maxTimeoutSeconds: number; /** Scheme-specific additional information */ extra?: Record; } /** * Payment required response for x402 v2 protocol */ export interface PaymentRequiredV2 { /** Protocol version (must be 2) */ x402Version: 2; /** Human-readable error message */ error?: string; /** Information about the protected resource */ resource: ResourceInfo; /** Array of acceptable payment methods */ accepts: PaymentRequirementsV2[]; /** Protocol extensions data */ extensions?: Record; } /** * Stacks-specific payment payload (transaction data) */ export interface StacksPayloadV2 { /** Signed transaction hex */ transaction: string; } /** * Payment payload for x402 v2 protocol */ export interface PaymentPayloadV2 { /** Protocol version (must be 2) */ x402Version: 2; /** Information about the resource being accessed */ resource?: ResourceInfo; /** The payment method chosen by the client */ accepted: PaymentRequirementsV2; /** Scheme-specific payment data (signed transaction for Stacks) */ payload: StacksPayloadV2; /** Protocol extensions data */ extensions?: Record; } /** * Settlement response for x402 v2 protocol */ export interface SettlementResponseV2 { /** Whether the payment settlement was successful */ success: boolean; /** Error reason if settlement failed */ errorReason?: string; /** Address of the payer's wallet */ payer?: string; /** Blockchain transaction hash */ transaction: string; /** Network identifier in CAIP-2 format */ network: NetworkV2; } /** * x402 HTTP header names (V2 protocol) */ export declare const X402_HEADERS: { /** Header containing payment required info (base64 encoded) */ readonly PAYMENT_REQUIRED: "payment-required"; /** Header containing payment signature/payload (base64 encoded) */ readonly PAYMENT_SIGNATURE: "payment-signature"; /** Header containing settlement response (base64 encoded) */ readonly PAYMENT_RESPONSE: "payment-response"; }; export declare function decodePaymentRequired(header: string | null | undefined): PaymentRequiredV2 | null; export declare function encodePaymentPayload(payload: PaymentPayloadV2): string; export declare function decodePaymentPayload(encoded: string | null | undefined): PaymentPayloadV2 | null; export declare function decodePaymentResponse(header: string | null | undefined): SettlementResponseV2 | null; /** * Typed shape of the payment-identifier extension for PaymentPayloadV2.extensions. * Wire format: { "payment-identifier": { info: { id: "pay_<32-hex-chars>" } } } * * Validation rules enforced by the x402-sponsor-relay: * - id: 16-128 chars, pattern [a-zA-Z0-9_-]+ * - Same id + same payload = cached response (idempotent retry) * - Same id + different payload = 409 Conflict */ export interface PaymentIdentifierExtension { [key: string]: unknown; "payment-identifier": { info: { id: string; }; }; } /** * Generate a stable, unique payment identifier for use as an idempotency key. * Format: "pay_<32 lowercase hex chars>" (36 chars total). * Uses Node.js built-in crypto.randomUUID() with dashes stripped. */ export declare function generatePaymentId(): string; export declare function buildPaymentIdentifierExtension(id: string): PaymentIdentifierExtension; //# sourceMappingURL=x402-protocol.d.ts.map