SDK reference · Rails
@provenanceauth/rails/x402
@provenanceauth/rails/x402 in the Rails: 12 methods. X402 (HTTP 402 agent payments) mapping + merchant verification.
Methods
encodeX402Header
encodeX402Header(obj: X402PaymentRequired | X402PaymentPayload): stringEncode an x402 object as a header value (base64 of its JSON).
decodePaymentRequired
decodePaymentRequired(headerValue: string | null | undefined): X402PaymentRequired | nullDecode + shape-check a PAYMENT-REQUIRED value.
decodePaymentPayload
decodePaymentPayload(headerValue: string | null | undefined): X402PaymentPayload | nullDecode + shape-check a PAYMENT-SIGNATURE value.
intentExtension
intentExtension(opts?: { required?: boolean; profile?: DiscoveryBlock }): X402ExtensionThe extension entry a merchant advertises.
withIntentExtension
withIntentExtension(paymentRequired: X402PaymentRequired, opts?: { required?: boolean; profile?: DiscoveryBlock }): X402PaymentRequiredAdd the extension to a PaymentRequired your x402 server already builds (returns a new object; other extensions are kept).
x402Challenge
x402Challenge(opts: { resource: X402ResourceInfo | string; accepts: X402PaymentRequirements[]; error?: string; required?: boolean; extensions?: Record<string, X402Extension>; /** #110: the business's discovery block (`discoveryFields(profile).x402.profile`). */ profile?: DiscoveryBlock; }): { status: 402; headers: Record<string, string>; body: X402PaymentRequired }Build the 402 a merchant returns: the PaymentRequired with the extension, its base64 PAYMENT-REQUIRED header, and the same object as an informational JSON body.
x402ProfileOf
x402ProfileOf(paymentRequired: Pick<X402PaymentRequired, "extensions"> | null | undefined): DiscoveryBlock | nullAgent side: the business's discovery block in a 402's extension, or null (older merchants send none).
x402BindingPayload
x402BindingPayload(resource: X402ResourceInfo | string, requirements: Pick<X402PaymentRequirements, "scheme" | "network" | "amount" | "asset" | "payTo">): X402BindingThe exact object to pass as action_payload to POST /v1/mandate/intents, so the token's payload_hash binds this resource and these payment requirements.
x402BindingHash
x402BindingHash(b: X402Binding): Promise<string>Sha256(canonical JSON) of the binding, the value a bound token carries as payload_hash.
withIntentToken
withIntentToken(payment: X402PaymentPayload, extension: X402Extension, token: string, opts?: { jwksUrl?: string }): X402PaymentPayloadAppend the intent token to a PaymentPayload's extensions, echoing the merchant's entry unchanged (x402 v2: clients may append info but never delete or overwrite it).
intentPaymentFetch
intentPaymentFetch(fetchImpl: typeof fetch, getToken: (challenge: X402IntentChallenge) => Promise<string | null> | string | null, opts: IntentPaymentFetchOptions): typeof fetchClient middleware: wrap a fetch so a 402 that asks for a Provenance intent is retried once with a PAYMENT-SIGNATURE carrying the payment and the token.
verifyX402Payment
verifyX402Payment(paymentSignature: string | null | undefined, opts: X402VerifyOptions): Promise<X402VerifyResult>Merchant side: verify the intent token in a PAYMENT-SIGNATURE header before you settle.