import { EIP6963ProviderDetail } from "mipd"; import { Address, ChainID, EIP1193Provider, WrappedRequestFunction } from "../types"; /** What the registry needs from the SDK that owns it. */ export interface EvmProviderRegistryDeps { /** The provider the SDK currently attributes activity to. */ activeProvider(): EIP1193Provider | undefined; /** The active provider's chain, per central state. */ activeChainId(): ChainID | undefined; /** The wallet already known for EVM, if any. */ knownEvmAddress(): Address | undefined; /** * A provider reported a chain. * * The registry records it per provider; whether central state should follow * is the SDK's decision, not the registry's, because it depends on which * namespace is active. */ onChainObserved(provider: EIP1193Provider, chainId: number): void; } /** * Which EVM wallets exist, and what is known about each. * * Split out of `FormoAnalytics` so "the provider registry" is one thing with * one owner. It deliberately holds no event logic: registering listeners and * reacting to them stays with the SDK for now, and moves next. * * Three provider sets, which are not the same thing: * - `details` is every EIP-6963 provider discovered, with its metadata. * - `tracked` is the subset that has listeners wired up. * - `seen` guards `details` against duplicates. */ export declare class EvmProviderRegistry { private readonly deps; private details; private tracked; private seen; /** Last chain heard from each provider, whoever is active. */ private chainIds; /** * Bumped on every chain observation, PER PROVIDER, so a stale answer that * arrives late cannot overwrite a newer one. */ private chainGenerations; /** Listeners this SDK attached, so teardown can remove exactly those. */ private listeners; /** The window-injected provider, once detected, so it is not re-wrapped. */ private injectedDetail?; /** * Attribution supplied by the integration layer for a provider that was * never announced: the wagmi fallback wrap names a connector's provider * after the CONNECTOR, so request-derived events carry the same wallet * name as the hook-driven events from the same connection. Without it * the name came from flag sniffing, and a custom or embedded connector * whose provider exposes no recognised flag split one wallet's activity * between "Injected Provider" and the connector's name. * * A RESOLVER, read at each `infoFor`, not a value: the name is live for * the connector the integration layer bound it to (a WalletConnect * session that resolves or changes its peer renames without a re-wrap), * and the integration layer names events on its hook path with the same * function, so the two paths cannot disagree. Which connector a * provider is bound to is the integration layer's decision; it is not * necessarily the connector that is current when the request runs. */ private attributions; constructor(deps: EvmProviderRegistryDeps); get all(): readonly EIP6963ProviderDetail[]; isTracked(provider: EIP1193Provider): boolean; markTracked(provider: EIP1193Provider): void; forgetTracked(provider: EIP1193Provider): void; trackedProviders(): EIP1193Provider[]; isSeen(provider: EIP1193Provider): boolean; get injected(): EIP6963ProviderDetail | undefined; set injected(detail: EIP6963ProviderDetail | undefined); /** Counts for the public debug helpers. */ get counts(): { totalProviders: number; trackedProviders: number; seenProviders: number; }; /** Add a discovered provider once. Returns false if already present. */ add(detail: EIP6963ProviderDetail): boolean; /** * Record (or, with `undefined`, forget) the integration layer's own * attribution resolver for a provider. See `attributions`. */ rememberAttribution(provider: EIP1193Provider | undefined, resolve: (() => { name: string; rdns?: string; } | undefined) | undefined): void; /** The supplied attribution for a provider, if any resolves right now. */ private suppliedAttributionFor; /** * A provider's display name and rdns. * * EIP-6963 metadata is authoritative when we have it. A supplied * attribution (the connector a wagmi app connected through) comes next: * it describes the SESSION, which is what the hook-driven events report. * Otherwise fall back to sniffing the injected provider, which is all a * pre-6963 wallet offers; a supplied name without an rdns keeps the * sniffed rdns. */ infoFor(provider: EIP1193Provider): { name: string; rdns: string; }; addListener(provider: EIP1193Provider, event: string, listener: (...args: unknown[]) => void): void; /** Remove only the listeners this SDK attached, never the host app's. */ removeListeners(provider: EIP1193Provider): void; /** Events still attached to a provider after a failed teardown. */ attachedEvents(provider: EIP1193Provider): string[]; /** * Whether this provider's `request` is already our wrapper. * * Checks the wrapper's own marker AND that the provider still points at * that exact function, so a wallet that replaced `request` after we wrapped * it is re-wrapped rather than left uninstrumented. */ isWrapped(provider: EIP1193Provider, currentRequest: WrappedRequestFunction | undefined): boolean; chainIdOf(provider: EIP1193Provider): number | undefined; /** Advance and return this provider's chain-observation generation. */ bumpChainGeneration(provider: EIP1193Provider): number; chainGeneration(provider: EIP1193Provider): number; /** * Record a provider's chain. Fed by `chainChanged` and `connect`, and by * the one-off probe at tracking time, never from inside a user request. */ rememberChain(provider: EIP1193Provider | undefined, chainId: number | undefined): void; /** * Resolve the chain an autocaptured request actually ran on. * * Central chain state is maintained by `chainChanged` from whichever * provider is currently active. When a request arrives from a DIFFERENT * tracked provider, which happens whenever a visitor has two wallets * installed, that cached value describes the wrong wallet, and tagging the * event with it silently mis-attributes the chain. * * Answered entirely from a per-provider snapshot. Deliberately SYNCHRONOUS * and never issues an RPC. * * An earlier version called `eth_chainId` on the signing provider and * time-boxed it with `Promise.race`. That is not safe: the race abandons * the SDK's promise but cannot cancel the provider's request. On a * transport that serialises (WalletConnect's relay socket, the very case * this path exists to serve) an abandoned lookup stays at the head of the * wallet's queue, and every later RPC the dapp makes queues behind it until * reload. Mislabelling a chain is a reporting defect; wedging the user's * wallet is not an acceptable way to avoid one. * * When nothing is known this reports 0 ("unknown") rather than guessing * with the active provider's chain, which is known-wrong for another wallet. */ resolveChainId(provider?: EIP1193Provider): number; /** * The wallet's first account, or null. * * Prefers what the SDK already knows, so an EVM context never returns a * Solana address and no RPC is issued when the answer is already in hand. */ addressOf(provider?: EIP1193Provider): Promise
; /** Every checksummed account a provider reports, or null. */ accountsOf(provider?: EIP1193Provider): Promise; } //# sourceMappingURL=EvmProviderRegistry.d.ts.map