import { type FetchLike } from "./client.js"; import { PX402Error } from "./errors.js"; import { type TokenDomain } from "./bridge.js"; /** `PX402GaslessDepositor.GASLESS_DEPOSIT_TYPEHASH`'s preimage: the tag the nonce is derived under. */ export declare const GASLESS_DEPOSIT_TYPE = "PX402GaslessDeposit(uint256 chainId,address depositor,address reserveAddr,uint256 fee,bytes32 salt)"; /** EIP-3009's `ReceiveWithAuthorization` type, as USDC hashes it. */ export declare const RECEIVE_WITH_AUTHORIZATION_TYPE = "ReceiveWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)"; /** * The EIP-3009 nonce of a gasless deposit of `fee` into `reserveAddr` under * `salt`, on `chainId`, through `depositor`: exactly what * `PX402GaslessDepositor.gaslessDepositNonce` computes. */ export declare function gaslessDepositNonce(chainId: number | bigint, depositor: string, reserveAddr: string, fee: bigint, salt: Uint8Array): Uint8Array; export { tokenDomainSeparator, type TokenDomain } from "./bridge.js"; /** One `ReceiveWithAuthorization`: `from` lets `to` (the depositor) pull `value` once. */ export interface ReceiveAuthorization { readonly from: string; readonly to: string; readonly value: bigint; readonly validAfter: bigint; readonly validBefore: bigint; /** {@link gaslessDepositNonce}. */ readonly nonce: Uint8Array; } /** The EIP-712 digest USDC verifies `auth`'s signature against, under `domainSeparator`. */ export declare function receiveAuthorizationDigest(domainSeparator: Uint8Array, auth: ReceiveAuthorization): Uint8Array; /** The typed data an account's `signTypedData` takes for `auth` (viem's shape; `EIP712Domain` is derived from `domain`). */ export interface ReceiveAuthorizationTypedData { readonly domain: { readonly name: string; readonly version: string; readonly chainId: number; readonly verifyingContract: `0x${string}`; }; readonly types: { readonly ReceiveWithAuthorization: readonly { readonly name: string; readonly type: string; }[]; }; readonly primaryType: "ReceiveWithAuthorization"; readonly message: { readonly from: `0x${string}`; readonly to: `0x${string}`; readonly value: bigint; readonly validAfter: bigint; readonly validBefore: bigint; readonly nonce: `0x${string}`; }; } /** {@link ReceiveAuthorizationTypedData} for `auth` under `domain`. */ export declare function receiveAuthorizationTypedData(domain: TokenDomain, auth: ReceiveAuthorization): ReceiveAuthorizationTypedData; /** Whoever signs the agent's authorization: the key it was given, or the account that holds it. */ export interface AuthorizationSigner { /** The address the USDC comes from, `0x` lowercase. */ readonly address: string; /** The signature over `typed` (whose EIP-712 digest is `digest`), as USDC takes it. */ sign(typed: ReceiveAuthorizationTypedData, digest: Uint8Array): Promise; } /** A signer over a private key the SDK holds: `r ‖ s ‖ v`, `v` 27 or 28, low-`s`. */ export declare function keyAuthorizationSigner(privateKey: Uint8Array, address: string): AuthorizationSigner; /** * A signer over an account's own `signTypedData` (viem's accounts have one), * which never shows the SDK a key. The account must sign any EIP-712 message * it is given, as viem's and every wallet library's do. A smart-contract * account's signature is passed on as it is: USDC checks it through ERC-1271. */ export declare function accountAuthorizationSigner(account: { readonly address: string; signTypedData?(typedData: never): Promise; }): AuthorizationSigner | undefined; /** What the facilitator's `/supported` says a depositor's sponsorship costs. */ export interface SponsorOffer { readonly depositor: string; /** The least fee a sponsoring relayer takes, USDC base units. */ readonly minFee: bigint; /** The most one sponsored deposit may move. */ readonly maxValue: bigint; } /** * Why a gasless deposit did not happen. * * - `unavailable`: no relayer behind the facilitator sponsors this * depositor right now (or it would not say). * - `fee`: the fee asked is above `maxSponsorFee`. * - `refused`: a relayer refused the authorization before sending anything * ({@link sponsorCode} says why: `SPONSOR_INSUFFICIENT_BALANCE`, ...). * - `unreachable`: the facilitator did not answer. * - `failed`: the authorization was submitted and did not land before it * expired. */ export type SponsorRefusal = "unavailable" | "fee" | "refused" | "unreachable" | "failed"; /** * A gasless deposit that did not happen. Nothing left the address unless * {@link reason} is `failed`, and then nothing did either: the authorization * expired unused. */ export declare class PX402SponsorError extends PX402Error { readonly facilitator: string; readonly reason: SponsorRefusal; /** The relayer's or the facilitator's code, when it named one. */ readonly sponsorCode: string | undefined; constructor(detail: { facilitator: string; reason: SponsorRefusal; detail: string; sponsorCode?: string; httpStatus?: number; }); } /** * The facilitator's offer for `depositor`, from its `/supported` * (`kinds[].extra.sponsor`), or `undefined` when it lists none. The * depositor is matched, never taken. */ export declare function readSponsorOffer(fetchImpl: FetchLike, facilitator: string, depositor: string): Promise; /** `POST /deposit/sponsor`'s body, on px402's wire. */ export interface SponsorRequestWire { readonly depositor: string; readonly from: string; readonly reserve_addr: string; readonly value: string; readonly fee: string; readonly valid_after: string; readonly valid_before: string; readonly salt: string; readonly signature: string; } /** What a sponsoring relayer answered. */ export interface SponsorAnswer { /** Its `depositWithAuthorization` transaction. */ readonly transaction: string; /** `submitted`, or `used` once the token shows the authorization used. */ readonly state: string; } /** * Posts `request` to `facilitator`'s `/deposit/sponsor`. * * @throws PX402SponsorError: `unreachable` when nothing answered, `refused` * with the code otherwise (`SPONSOR_AUTHORIZATION_USED` among them, which * the caller reads as "landed already" after asking the chain). */ export declare function postSponsor(fetchImpl: FetchLike, facilitator: string, request: SponsorRequestWire): Promise; /** `0x`-prefixed lowercase hex. */ export declare function hex0x(bytes: Uint8Array): string;