import { type FetchLike } from "./client.js"; import { type PaymentAccount } from "./keyseed.js"; /** An RLP item: a byte string, or a list of items. */ export type RlpItem = Uint8Array | readonly RlpItem[]; /** Recursive-length-prefix encoding (the Ethereum yellow paper, appendix B). */ export declare function rlpEncode(item: RlpItem): Uint8Array; /** An unsigned integer as RLP takes it: big-endian, no leading zeros, zero as the empty string. */ export declare function quantity(value: bigint): Uint8Array; /** An EIP-1559 (type 2) transaction with no access list. */ export interface Eip1559Transaction { readonly chainId: number; readonly nonce: bigint; readonly maxPriorityFeePerGas: bigint; readonly maxFeePerGas: bigint; readonly gas: bigint; /** `0x`-prefixed 20-byte address. */ readonly to: string; readonly value: bigint; /** `0x`-prefixed calldata. */ readonly data: string; } /** * Sign an EIP-1559 transaction with a secp256k1 key: `keccak256(0x02 ‖ * rlp(payload))`, signed low-`s` (RFC 6979, so the same transaction signs to * the same bytes), returned as the `0x02 ‖ rlp(payload ‖ yParity ‖ r ‖ s)` * hex `eth_sendRawTransaction` takes. */ export declare function signEip1559(tx: Eip1559Transaction, privateKey: Uint8Array): string; /** Whoever signs the drop-in's deposits: the key it was given, or the account that holds it. */ export interface TransactionSigner { /** The signing address, `0x` lowercase: where the USDC and the gas come from. */ readonly address: string; /** The signed transaction, as `eth_sendRawTransaction` takes it. */ sign(tx: Eip1559Transaction): Promise; } /** A signer over a private key the SDK holds. */ export declare function keySigner(privateKey: Uint8Array): TransactionSigner; /** * A signer over an account's own `signTransaction` (viem's local accounts * have one), which never shows the SDK its key. */ export declare function accountSigner(account: PaymentAccount): TransactionSigner; /** A mined transaction, as much of its receipt as the drop-in reads. */ export interface MinedReceipt { readonly transactionHash: string; /** `true` when `status` is 1; a reverted transaction is mined and `false`. */ readonly success: boolean; readonly blockNumber: bigint; /** What it used, when the node says. */ readonly gasUsed?: bigint; /** Its logs, when the node gives them: what a gasless deposit's `Deposit` is read from. */ readonly logs?: readonly ReceiptLog[]; } /** One log of a receipt: the contract that emitted it, its topics, its data (all `0x` hex). */ export interface ReceiptLog { readonly address: string; readonly topics: readonly string[]; readonly data: string; } /** How many times a read at the floor is asked again of a node that has not reached it. */ export declare const RPC_LAG_RETRIES = 8; /** The first wait before asking again; it doubles, up to {@link RPC_LAG_BACKOFF_MAX_MS}. */ export declare const RPC_LAG_BACKOFF_MS = 250; /** The longest wait between two asks: a Base block is two seconds. */ export declare const RPC_LAG_BACKOFF_MAX_MS = 2000; /** Where an {@link EvmRpc} sends its calls. */ export interface EvmRpcOptions { /** A JSON-RPC endpoint. Never echoed into an error: it may carry an API key. */ readonly rpcUrl: string; /** Defaults to the global `fetch`. */ readonly fetch?: FetchLike; /** Per call. Defaults to `DEFAULT_RPC_TIMEOUT_MS`. */ readonly timeoutMs?: number; /** How a read waits for a lagging node. Defaults to a timer. */ readonly sleep?: (ms: number) => Promise; /** Defaults to {@link RPC_LAG_RETRIES}. */ readonly lagRetries?: number; } /** The 4-byte selector of a function signature, as hex without `0x`. */ export declare function selectorOf(signature: string): string; /** A signed transaction's hash: `keccak256` of its raw bytes, typed envelope included. */ export declare function transactionHashOf(raw: string): string; /** * The calls a deposit needs, over plain JSON-RPC: the reads that decide it * (balances, allowance, the reserve's balance, the nonce, an estimate), each * at the floor (see the module docs), the write (`eth_sendRawTransaction`), * and the receipt, which raises the floor to the block it was mined in. */ export declare class EvmRpc { private readonly options; private readonly fetchImpl; private readonly sleep; private floorBlock; constructor(options: EvmRpcOptions); /** * The newest block this client has seen: its own transactions' blocks, and * every head it read. Every read that decides a deposit is made at it. * `undefined` until something has been seen; reads are then at `latest`. */ get floor(): bigint | undefined; /** Raise the floor to `block`; never lowers it. */ observe(block: bigint): void; /** The block tag every pinned read names: the floor, or `latest` before there is one. */ private tag; /** One JSON-RPC request; its `result`, or a typed failure naming the method. */ request(method: string, params: readonly unknown[]): Promise; /** * A read at the floor. A node that has not reached the floor -- an error * saying so, or no result -- is asked again after a short backoff, up to * {@link RPC_LAG_RETRIES} times; then the read fails as a * {@link PX402TransportError}, retryable. Before any floor the read is at * `latest`, and asked once. */ private pinned; /** `eth_call` at the floor, returning the raw hex. */ call(to: string, data: string): Promise; /** The `index`-th 32-byte word of an `eth_call` at the floor, as an unsigned integer. */ callWord(to: string, data: string, index?: number): Promise; /** `token.balanceOf(owner)`. */ tokenBalance(token: string, owner: string): Promise; /** `token.allowance(owner, spender)`. */ allowance(token: string, owner: string, spender: string): Promise; /** `reserves(reserveAddr).balance` on the reserve contract: what it can still withdraw. */ reserveBalance(reserveContract: string, reserveAddr: string): Promise; /** `reserves(reserveAddr).nonce`: the reserve's next withdraw nonce. */ reserveNonce(reserveContract: string, reserveAddr: string): Promise; /** The address's native balance at the floor, in wei. */ balance(address: string): Promise; /** How many transactions `address` has had mined, at the floor: every one of ours seen mined counts. */ nonce(address: string): Promise; /** * The next nonce counting transactions still in a node's pool. Whichever * node answers may be behind, so this is only ever a lower bound: the * caller takes the larger of it, {@link nonce}, and its own count. */ pendingNonce(address: string): Promise; /** `eth_estimateGas` for a call from `from`, against the state at the floor. */ estimateGas(call: { readonly from: string; readonly to: string; readonly data: string; }): Promise; /** * The newest head a node will give, and the floor raised to it: the reads * after this one see every block that node had, ours included. */ syncHead(): Promise; /** * EIP-1559 fees: the node's suggested tip, and a cap of twice the latest * base fee plus that tip, which outlasts six full blocks of base-fee rise. * A node without `eth_maxPriorityFeePerGas` or a base fee is priced from * `eth_gasPrice`. The head it reads raises the floor. */ fees(): Promise<{ readonly maxFeePerGas: bigint; readonly maxPriorityFeePerGas: bigint; }>; /** * `eth_sendRawTransaction`: the transaction's hash. A node that already * holds these exact bytes ("already known") has accepted them: their hash * is returned, computed here. */ sendRawTransaction(raw: string): Promise; /** * The receipt of a mined transaction, or `undefined` while it is pending -- * or while whichever node answered has not reached its block. A receipt * raises the floor to its block. */ receipt(hash: string): Promise; /** * The latest block's timestamp, in seconds, raising the floor to it; * `undefined` when the node's block carries none. What a gasless * authorization's `validBefore` is set from: the chain's clock, not this * host's. */ headTimestamp(): Promise; /** A `string`-returning view (`name()`, `version()`), at the floor, ABI-decoded. */ callString(to: string, signature: string): Promise; /** `token.authorizationState(authorizer, nonce)` at the floor: the EIP-3009 nonce is used (or cancelled). */ authorizationState(token: string, authorizer: string, nonce: Uint8Array): Promise; }