/** * The Solidity typehash string for `ContractTerms`, character for character * identical to the constant embedded in `PX402Reserve.sol` and to * `terms.rs`'s `CONTRACT_TERMS_TYPEHASH_STRING`. One stray space or a * reordered field changes the typehash and therefore every digest below. */ export declare const CONTRACT_TERMS_TYPEHASH_STRING = "ContractTerms(uint32 px402Version,uint32 x402Version,bytes32 acceptedHash,bytes32 resourceUrlHash,address payTo,uint256 amount,bytes32 nonce,uint64 validUntil)"; /** * Fields of the `ContractTerms` struct hashed by {@link contractTermsHash}, * in Solidity declaration order. * * `amount` and `validUntil` are `bigint` rather than `number`: a `uint256` * amount and a `uint64` timestamp both exceed `Number.MAX_SAFE_INTEGER`, and * a silently-rounded amount is a payment for the wrong sum. The two version * numbers are `uint32`, which is exactly representable, so they stay * `number`. */ export interface ContractTerms { readonly px402Version: number; readonly x402Version: number; /** `keccak256(termsSalt ‖ JCS(accepted))` -- see {@link acceptedHash}. */ readonly acceptedHash: Uint8Array; /** `keccak256(termsSalt ‖ resourceUrl)` -- see {@link resourceUrlHash}. */ readonly resourceUrlHash: Uint8Array; /** The merchant's 20-byte EVM address. */ readonly payTo: Uint8Array; readonly amount: bigint; readonly nonce: Uint8Array; readonly validUntil: bigint; } /** * `keccak256(data)` -- Ethereum/Solidity Keccak (the original NIST-submission * padding), **not** SHA3-256. See the module docs for why the distinction is * load-bearing rather than pedantic. */ export declare function keccak256(data: Uint8Array): Uint8Array; /** `keccak256` of {@link CONTRACT_TERMS_TYPEHASH_STRING}. */ export declare function contractTermsTypehash(): Uint8Array; /** * Width of the per-payment terms salt (§6.3, §11): 32 random bytes the wallet * draws at payment time and carries to the facilitator as `termsSalt`. */ export declare const TERMS_SALT_LEN = 32; /** `ContractTerms.resourceUrlHash = keccak256(termsSalt ‖ resourceUrl)` (§6.3). */ export declare function resourceUrlHash(salt: Uint8Array, resourceUrl: string): Uint8Array; /** * `ContractTerms.acceptedHash = keccak256(termsSalt ‖ JCS(accepted))` (§6.3), * where `acceptedJcs` is the RFC 8785 serialization of the chosen * `PaymentRequirements` exactly as the merchant served it. */ export declare function acceptedHash(salt: Uint8Array, acceptedJcs: string): Uint8Array; /** * `abi.encode(CONTRACT_TERMS_TYPEHASH, ...fields)` -- nine 32-byte words, * head-only, in declaration order. * * Head-only because the struct has no dynamic member: every field is a value * type or a `bytes32`, and EIP-712 pre-hashes strings before they get here * (`acceptedHash`, `resourceUrlHash`). A length other than `9 * 32` means a * field was packed (`abi.encodePacked`) or dropped, and Solidity would then * compute a different hash from the same terms. */ export declare function abiEncoded(t: ContractTerms): Uint8Array; /** * The bare struct hash: `keccak256(abiEncoded(t))`. * * See the module docs -- this value carries no authority alone and must not * be signed directly. */ export declare function contractTermsHash(t: ContractTerms): Uint8Array; /** Domain tag of {@link payoutNonce}: raw bytes, no length prefix. */ export declare const PAYOUT_NONCE_TAG = "px402/v3/payout-nonce"; /** * The EIP-3009 nonce a relayer signs this payment's payout under (v3 spec * §19.1): `keccak256("px402/v3/payout-nonce" ‖ abiEncoded(t))`. Mirrors * `px402_core::terms::payout_nonce`; pinned by `vectors/terms.json`'s * `payout_nonce_hex`. * * A payout counts only as USDC's `AuthorizationUsed(relayer, payoutNonce)` * followed, in the same call, by the `Transfer` to `payTo`: the nonce names * the payment, so one transfer can never answer for two payments. It is * derived from the salted preimage, not from the public `H(contractTerms)`, * so only a party holding the preimage -- the merchant, the facilitator, * the relayer, the issuer on a dispute, and the wallet that built it -- can * compute it. */ export declare function payoutNonce(t: ContractTerms): Uint8Array; /** * `ContractTerms` as the services take it in a JSON body -- the * `contract_terms` of a facilitator's `/refund` and `/bridge/lookup`, the * issuer's `/disputes` and the registry's `/bridge/cancel-request` (v3 §26.7, * §26.8): `TermsPreimage` in `crates/px402-issuer/src/dispute.rs`, field for * field. * * Spellings follow §6.14: the two salted hashes and the nonce are opaque * protocol digests, so **bare** lowercase hex; `pay_to` maps to an EVM word, * so `0x`-prefixed; `amount` and `valid_until` are `u64`s, so decimal * strings. The services refuse the wrong convention rather than accept both. * * This is the payment's **preimage**: whoever holds it can compute * `payoutNonce` and open the payment in a dispute (§26.7), which is why it is * sent only to the services that already hold it or are asked to judge it, * and never travels with the public terms hash. */ export interface ContractTermsWire { readonly px402_version: number; readonly x402_version: number; readonly accepted_hash: string; readonly resource_url_hash: string; readonly pay_to: string; readonly amount: string; readonly nonce: string; readonly valid_until: string; } /** {@link ContractTerms} in its {@link ContractTermsWire} spelling. */ export declare function contractTermsToWire(t: ContractTerms): ContractTermsWire; /** * The inverse of {@link contractTermsToWire}, strict about every spelling. * * @throws RangeError naming the first field that is not in its §6.14 form. */ export declare function contractTermsFromWire(json: unknown): ContractTerms;