Function: decodePaymentHeader()
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
accepted: object & object = X402PaymentRequirementsEnvelopeSchema;Type Declaration
amount
amount: string = nonEmptyString;asset
asset: string = nonEmptyString;maxTimeoutSeconds
maxTimeoutSeconds: number = positiveSeconds;network
network: string = nonEmptyString;payTo
payTo: string = nonEmptyString;scheme
scheme: string = nonEmptyString;extensions?
extensions?:
| {
[key: string]: unknown;
}
| null;payload
payload: object = CantonPaymentInnerSchema;payload.assetTransferMethod
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?
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
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
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
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?
resource?: object & object | null;x402Version
x402Version: 2;