import { PX402ConfigError } from "./wallet.js"; /** * The HKDF info a seed signature is turned into a seed under: the only seed * derivation there is. * * Not in `kdf.ts`'s `INFO`: that table is byte-exact with the Rust core's, * and the issuer never computes this. Distinct from every string in it. */ export declare const SEED_FROM_SIGNATURE_INFO: Uint8Array; /** The EIP-712 domain's `version`, and the message's. A new version is a new wallet. */ export declare const SEED_TYPED_DATA_VERSION = "1"; /** The seed message's primary type. */ export declare const SEED_TYPED_DATA_TYPE = "Px402WalletSeed"; /** * What a wallet app shows the user when it is asked for the seed signature: * what it is for, and that nothing else should ever ask for it. */ export declare const SEED_TYPED_DATA_PURPOSE: string; /** * The EIP-712 request an account signs for its seed, in the shape viem's * `signTypedData` takes (`EIP712Domain` is derived from `domain`). */ export interface SeedTypedData { readonly domain: { readonly name: "px402"; readonly version: string; readonly chainId: number; }; readonly types: { readonly Px402WalletSeed: readonly { readonly name: string; readonly type: string; }[]; }; readonly primaryType: "Px402WalletSeed"; readonly message: { readonly purpose: string; readonly chainId: bigint; }; } /** The seed message for `chainId`: fixed, versioned, px402's, naming the chain. */ export declare function seedTypedData(chainId: number): SeedTypedData; /** * The 32-byte EIP-712 digest of {@link seedTypedData}: what a local key signs * for it, `keccak256(0x1901 ‖ domainSeparator ‖ structHash)`. */ export declare function seedTypedDataDigest(chainId: number): Uint8Array; /** * The EIP-1559 transaction an account is asked to sign when the drop-in * deposits for it, in the shape viem's `signTransaction` takes. */ export interface AccountTransaction { readonly type: "eip1559"; readonly chainId: number; readonly nonce: number; readonly to: `0x${string}`; readonly data: `0x${string}`; readonly value: bigint; readonly gas: bigint; readonly maxFeePerGas: bigint; readonly maxPriorityFeePerGas: bigint; } /** * The account the drop-in surface pays from, as x402's own client takes one: * a viem local account fits it as it is (`viem.test.ts` checks that against * viem's own types). * * - `privateKey`, when the account exposes it (ethers' `Wallet` does): the * seed message is signed here with it, and the drop-in signs deposits * itself. * - `signTypedData`, otherwise: the account signs the seed message, twice * (see the module docs). The seed is the same either way for the same key. * It also signs a gasless deposit's USDC authorization (`gasless.ts`), so * an account that signs typed data and no transactions still funds the * wallet from its USDC. * - `signTransaction`: lets the drop-in fund the wallet from this address * with deposits of its own, paying the gas. */ export interface PaymentAccount { /** The account's address, `0x`-prefixed. */ readonly address: string; /** The account's secp256k1 key, `0x`-prefixed hex, when it exposes one. */ readonly privateKey?: string; signTypedData?(typedData: SeedTypedData): Promise; signTransaction?(transaction: AccountTransaction): Promise; } /** * An account that signed the seed message twice and got two different * signatures: a seed derived from it would change on every start. Pass * `seed` explicitly (32 random bytes, kept like a key) instead. */ export declare class PX402NondeterministicSignerError extends PX402ConfigError { /** The account that was asked. */ readonly address: string; constructor(address: string); } /** * A `0x`-prefixed 32-byte hex private key, as bytes, checked to be a valid * secp256k1 scalar. Never echoes the input: a malformed key is still mostly a * key, and error messages get logged. */ export declare function parsePrivateKey(key: string, what?: string): Uint8Array; /** Whether `value` reads as a private key: 32 bytes of hex, `0x`-prefixed or not. */ export declare function looksLikePrivateKey(value: string): boolean; /** The `0x` lowercase address of a secp256k1 private key. */ export declare function addressOfKey(key: Uint8Array): string; /** * A private key's signature over {@link seedTypedData} for `chainId`: 65 * bytes, `r ‖ s ‖ v` with `v` in {27, 28}, as an Ethereum wallet returns it. * RFC 6979 with no extra entropy, low-`s` (`@noble/curves`' defaults, said * out loud): the same key and chain always sign to the same bytes, which * are what viem's `privateKeyToAccount(key).signTypedData` returns for the * same message. Secret: whoever holds it holds the seed. */ export declare function signSeedTypedData(key: string | Uint8Array, chainId: number): Uint8Array; /** * The wallet seed for a private key on `chainId` (see the module docs): the * key signs the seed message here, once, and the seed is HKDF of that * signature -- the seed {@link seedFromAccount} derives for any account that * signs with this key, viem's and ethers' included. */ export declare function seedFromPrivateKey(key: string | Uint8Array, chainId: number): Uint8Array; /** * The bytes of a signature as the seed hashes them. A 65-byte ECDSA * signature is `r ‖ s` with `s` folded to the low half and `v` dropped: `v` * is recoverable from the rest, its encoding (0/1 or 27/28) varies between * libraries, and the high-`s` twin of a signature is the same signature. So * a library upgrade cannot move the seed. Any other length is taken as it is. */ export declare function canonicalSignature(signature: string): Uint8Array; /** * The wallet seed for an account on `chainId`: its signature over * {@link seedTypedData} -- made here, once, when the account exposes its key; * else asked of the account twice, and the two must agree. Either way the * seed {@link seedFromPrivateKey} gives the account's key. * * @throws PX402NondeterministicSignerError when the two signatures differ. * @throws PX402ConfigError when the account neither exposes a key nor signs * typed data, or exposes a key that is not its address's. */ export declare function seedFromAccount(account: PaymentAccount, chainId: number): Promise;