import type { SessionTypes } from '@walletconnect/types'; import type { Network, ConnectorResult, WalletConnectProvider, Namespace } from '@meshconnect/uwc-types'; import type { WalletConnectClient } from './walletconnect-client'; /** * Service for handling WalletConnect connections */ export declare class ConnectionService { private walletConnectClient; private currentSession; private connectionUri; private activeNetwork; private activeAddress; private pendingPairing; /** * In-flight mint promise. Concurrent `beginPairing` calls (parallel React * effects / double renders) share this single mint instead of each racing to * open its own relay subscription + proposal before `pendingPairing` is set. */ private pendingPairingMint; /** * Bumped by `disconnect()` to invalidate any in-flight mint. A `beginPairing` * warm-up that was still awaiting when the connection was reset must not * repopulate `pendingPairing` after the fact (and be adopted by a later * `connect()`); `mintPairing` checks this before publishing. */ private pairingGeneration; /** * True for the full duration of `connect()`. A warm-up mint that resolves while * a connect is in progress (including before `connect()` has set `connectionUri` * in `finalizePairing`) must not publish a pending pairing, or it would leave an * orphan for a later `connect()` to adopt. */ private isConnecting; /** * Conservative TTL for a pre-generated pairing. WalletConnect proposals expire * at ~5 min; stay under that so an adopted pairing is never already-dead. */ private static readonly PENDING_PAIRING_TTL_MS; constructor(walletConnectClient: WalletConnectClient); /** * Generate a WalletConnect pairing (URI) WITHOUT waiting for wallet approval. * Creating the pairing topic opens the relay socket (warming a cold client), * and the returned URI can be deep-linked before `connect()` is called. The * approval function is retained (uncalled) for `connect()` to adopt. * * Idempotent within the TTL: if a still-valid pending pairing already exists, * its URI is returned as-is rather than minting a second one. Every mint opens * a relay subscription and publishes a proposal that would otherwise leak until * the SDK's ~5-min expiry, so a consumer that warms on every picker view (or a * re-render) does not accumulate abandoned pairings. An expired pending pairing * falls through to a fresh mint. * * Does NOT set `connectionUri`: the URI is returned to the caller directly, and * `connectionUri` is reserved for an in-flight `connect()` (set by * `finalizePairing`) so a late-resolving `beginPairing` can never overwrite the * URI a concurrent `connect()` is polling on. * * Concurrent calls are deduped: parallel invocations share one in-flight mint * rather than each opening its own relay subscription + proposal. Errors are * normalized through `parseError`, so a direct `WalletConnectConnector` * consumer sees the same `WalletConnectorError` surface as `connect()`. * * `provider.supportedNetworkIds` should be the UNION of the session's * WalletConnect wallets' networks, so the single pairing's `optionalNamespaces` * work for whichever wallet the user later selects (optionalNamespaces let a * wallet approve only the subset it supports). `provider` is only consulted when * a fresh pairing is minted; a call that reuses a still-valid pending pairing * returns its existing URI and ignores the argument (the sole caller, * `UniversalWalletConnector.beginPairing`, always passes the same union). */ beginPairing(provider: Pick): Promise; /** * Mint a fresh pairing: open the relay socket + generate the URI, and store it * as the pending pairing. If a disconnect/connect/session supersedes the warm-up * while it is awaiting, it throws WITHOUT publishing rather than returning a URI * that no later `connect()` can adopt. Errors are wrapped with `parseError` for a * consistent `WalletConnectorError` surface (matching `connect()`). */ private mintPairing; /** Take the pending pairing iff still valid (not expired); clears it either way. */ private takeValidPendingPairing; /** * Second half of a connection: await the wallet's approval on an existing * pairing, then derive the session/addresses for the selected network + wallet. * Shared by the fresh-connect path and the adopt-pending-pairing path. Sets * `connectionUri` to the pairing URI while awaiting (so `getConnectionURI` can * surface it for the QR/deeplink) and clears it once resolved or failed. */ private finalizePairing; /** * Connect to a wallet via WalletConnect * This will store the URI and wait for approval */ connect(network: Network, provider: WalletConnectProvider): Promise; /** * Get the current connection URI */ getConnectionURI(): string | null; /** * Build WalletConnect namespaces from provider's supported network IDs */ private buildNamespacesFromProvider; /** * Extract addresses from a WalletConnect session */ private extractAddresses; /** * Re-read the live account list for a namespace from the current SignClient * session — used to sync a wallet-side account switch (`accountsChanged`) * without repeating `extractAddresses`'s primary-address/requested-network * selection, which doesn't apply to a live update (there is no "requested * network" for an in-session switch). */ getAccountsForNamespace(namespace: Namespace): string[]; /** * Get current session */ getSession(): SessionTypes.Struct | null; /** * Set session (for restoration) */ setSession(session: SessionTypes.Struct): void; /** * Get active network */ getActiveNetwork(): Network | null; /** * Set active network (for network switching) */ setActiveNetwork(network: Network): void; /** * Get active address */ getActiveAddress(): string | null; /** * Set active address (for network/address switching) */ setActiveAddress(address: string): void; /** * Disconnect current session */ disconnect(): Promise; /** Forget local state when SignClient has already removed the session. */ clearSession(): void; } //# sourceMappingURL=connection-service.d.ts.map