Skip to content

Function: decodePaymentHeader() ​

ts
function decodePaymentHeader(headerValue): object;

Defined in: packages/x402-core/src/payment-header.ts:194

Parse a PAYMENT-SIGNATURE (or X-PAYMENT) header value into the payment it carries. Throws on bad base64 / JSON, or when the value is not a well-formed x402 v2 payment envelope, including the pre-spec { payment, requirements } wrapper, a payment with no accepted, and one whose accepted is not a whole PaymentRequirements (a field every scheme's requirements share, missing or empty).

Validation here is envelope-level and scheme-agnostic (x402 v2, an accepted with the fields every scheme's requirements share, a payload object) — deliberately not the concrete per-scheme inner, or the rest of accepted. Concrete validation is the verifier's job: the facilitator (or a local createCantonExactVerifier) checks the scheme-specific inner + asset and the signature before the payment is trusted. This keeps the codec one scheme-agnostic seam and avoids duplicating per-scheme knowledge here.

The result is typed as the canton-exact payload for caller convenience; that's optimistic — a caller MUST verify before relying on scheme-specific fields, and narrow accepted before reading more than the fields every scheme shares.

Parameters ​

headerValue ​

string

Returns ​

object

accepted ​

ts
accepted: object & object = X402PaymentRequirementsEnvelopeSchema;

Type Declaration ​

amount ​
ts
amount: string = nonEmptyString;
asset ​
ts
asset: string = nonEmptyString;
maxTimeoutSeconds ​
ts
maxTimeoutSeconds: number = positiveSeconds;
network ​
ts
network: string = nonEmptyString;
payTo ​
ts
payTo: string = nonEmptyString;
scheme ​
ts
scheme: string = nonEmptyString;

extensions? ​

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

payload ​

ts
payload: object = CantonPaymentInnerSchema;

payload.assetTransferMethod ​

ts
assetTransferMethod: "transfer-factory";

MUST be transfer-factory, the same literal as the requirements' extra.assetTransferMethod: the spec requires it in both places. Any other value fails the shape check.

payload.hashingSchemeVersion? ​

ts
hashingSchemeVersion?: string;

Canton interactive-submission hashing scheme the payload was prepared with. The signature is bound to a hash computed with this version, so the facilitator's execute must use the same one. Optional: the spec reads an absent value as HashingSchemeVersion.V2. Validated as a string (the HashingSchemeVersion open union is a type-level nicety).

payload.preparedTransaction ​

ts
preparedTransaction: string;

The prepared transaction from /v2/interactive-submission/prepare, as base64 of exactly one gzip member (gzipPreparedTransaction): at most 8 KiB compressed and 72 KiB decompressed.

payload.preparedTxHash ​

ts
preparedTxHash: string;

The hash the payer signed: 32 bytes as lower-case hex, no multihash prefix. Non-empty here; the verifier checks the encoding itself.

payload.signature ​

ts
signature: string;

The payer's Ed25519 signature over preparedTxHash: 64 bytes as canonical standard base64. Base64, not hex — the spec's encoding, and the one the ledger's partySignatures takes, so the facilitator relays it unchanged. Non-empty here; the verifier checks the encoding itself. Nothing here names the payer: it is the signed transfer's sender (spec Rule 8).

resource? ​

ts
resource?: object & object | null;

x402Version ​

ts
x402Version: 2;