Skip to content

Function: decodePaymentRequiredHeader() ​

ts
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 ​

ts
accepts: object[];

error? ​

ts
error?: string;

extensions? ​

ts
extensions?: 
  | {
[key: string]: unknown;
}
  | null;

resource ​

ts
resource: object & object = ResourceInfoSchema;

Type Declaration ​

description? ​
ts
description?: string | null;
iconUrl? ​
ts
iconUrl?: string | null;
mimeType? ​
ts
mimeType?: string | null;
serviceName? ​
ts
serviceName?: string | null;
tags? ​
ts
tags?: string[] | null;
url ​
ts
url: string;

x402Version ​

ts
x402Version: 2;