Function: decodePaymentRequiredHeader()
function decodePaymentRequiredHeader(headerValue): object;Defined in: packages/x402-core/src/payment-header.ts:85
Parse a PAYMENT-REQUIRED header value into the PaymentRequired it carries.
The counterpart of encodePaymentRequiredHeader, and the way a client should read a 402: the HTTP transport makes the header the canonical location and calls the response body a server implementation concern, so a merchant may well answer {} — every registered Canton merchant does.
Throws on bad base64 / JSON, on nesting past 64 levels, or when the value is not an x402 v2 PaymentRequired (version 2, a resource with a url, and an accepts[] whose entries carry the fields every scheme's requirements share).
Validation is envelope-level and scheme-agnostic, as decodePaymentHeader's is: a 402 may offer canton-exact beside another scheme, and reading each entry as canton-exact would throw out an offer over an entry this reader was never going to pay. Typed as canton-exact for caller convenience, which is optimistic — a caller picking an entry must still check its own scheme can pay it.
Parameters
headerValue
string
Returns
object
accepts
accepts: object[];error?
error?: string;extensions?
extensions?:
| {
[key: string]: unknown;
}
| null;resource
resource: object & object = ResourceInfoSchema;Type Declaration
description?
description?: string | null;iconUrl?
iconUrl?: string | null;mimeType?
mimeType?: string | null;serviceName?
serviceName?: string | null;tags?
tags?: string[] | null;url
url: string;x402Version
x402Version: 2;