import type { FetchLike } from "./client.js"; /** The refusal message of a reply that is one of {@link KEPT_FOR_KEYS}, if it is. */ export declare function keptForKeys(body: unknown): string | undefined; /** How many times a rate-limited request is repeated before it is reported. */ export declare const RATE_LIMIT_RETRIES = 7; /** The longest `Retry-After` waited out; a provider asking for longer is reported at once. */ export declare const MAX_RETRY_AFTER_MS = 60000; /** * Requests in flight to one RPC URL at most. Public endpoints take a handful * of concurrent requests from one client and refuse the rest (Base's public * mainnet endpoint: five), so the wallet's parallel reads queue here instead of * bursting into the limit and retrying into it again. A rate limit lowers it * further for a while (`AdaptiveLimit`). */ export declare const MAX_IN_FLIGHT_PER_RPC = 4; /** What came back: the HTTP status and the parsed body, or `undefined` when it was not JSON. */ export interface JsonRpcReply { readonly status: number; readonly body: unknown; } /** Whether a reply is the provider asking for time. */ export declare function rateLimited(status: number, body: unknown): boolean; /** * A `Retry-After` header in milliseconds: delay-seconds or an HTTP date. * `undefined` when absent or unreadable; never negative. */ export declare function retryAfterMs(header: string | null, nowMs?: number): number | undefined; /** An RPC URL's host, for an error that must say which RPC refused without carrying its key. */ export declare function rpcHost(url: string): string; /** * A concurrency limit that backs off on rate limits and grows back slowly: * halved (never below one) when a call is rate-limited, and raised by one, up * to its maximum, after as many answers in a row as the limit itself. Callers * wait for a slot in the order they asked. */ export declare class AdaptiveLimit { readonly max: number; private current; private inFlight; private streak; private readonly waiting; constructor(max: number); /** How many calls may be in flight now. */ get limit(): number; /** Run `task` once a slot is free. */ run(task: () => Promise): Promise; /** A call was rate-limited: half as many at once from now on. */ backOff(): void; /** A call was answered: after a full window of these, one more at once. */ succeeded(): void; } /** The concurrency limit calls to `url` share. For tests; not exported from the package. */ export declare function rpcLimit(url: string): AdaptiveLimit; /** Forget every RPC URL's limit and pause. For tests; not exported from the package. */ export declare function forgetRpcEndpoints(): void; /** * POST one JSON-RPC request to `url`, repeating it while the provider rate * limits. Throws `PX402TransportError` when the request cannot be sent, and * when the provider still refuses after {@link RATE_LIMIT_RETRIES} repeats (or * asks to be left for longer than {@link MAX_RETRY_AFTER_MS}); * `PX402RpcUnsupportedError` when it keeps the request for clients with a key. * The URL is never named in an error: it often carries an API key. Its host is. */ export declare function postJsonRpc(fetchImpl: FetchLike, url: string, method: string, params: readonly unknown[], timeoutMs: number, sleep?: (ms: number) => Promise): Promise;