import SignClient from '@walletconnect/sign-client'; import type { WalletConnectConfig } from '@meshconnect/uwc-types'; /** * Cap on distinct relay-error messages remembered for dedup. Dedup is a storm * guard, not a permanent ledger — bounding it keeps memory flat on a long-lived * session even if messages are high-cardinality (timestamps / urls). */ export declare const MAX_RELAY_ERROR_DEDUP_KEYS = 100; export declare const MAX_REPORTED_RELAY_ERRORS = 100; /** * Cap on relay transport-lifecycle emissions PER EVENT TYPE (disconnect and * reconnect budgeted independently) per client. A flapping socket IS the signal * we want, but bounding emissions keeps a pathological relay from flooding * telemetry on a long-lived session. Independent budgets so a drop-heavy flap * that exhausts the disconnect cap can never silently swallow the paired * reconnect — otherwise telemetry would show drops with no recovery for a socket * that did recover. */ export declare const MAX_REPORTED_RELAY_LIFECYCLE = 50; /** * Optional telemetry sinks for the WalletConnect client. Covers both the relay * transport (error / disconnect / reconnect) AND `SignClient.init` failures. * Every field is opt-in — an empty observer leaves behaviour unchanged. All * sinks are telemetry-only: they never alter connection behaviour, and a * throwing sink is swallowed so it can't break the SDK's relayer dispatch (or, * for `onInitError`, mask the always-rethrown init rejection). */ export interface WalletConnectTelemetryObserver { /** * Relay-socket failure: the relayer re-emits an abnormal WebSocket close under * `RELAYER_EVENTS.error` (e.g. code 3000 JWT validation error on clock skew), * detached from the connect() promise. Deduped by a stable error-family key. */ onRelayError?: (error: unknown) => void; /** Relay-error telemetry reached its per-client emission budget. */ onRelayErrorCapped?: () => void; /** * `SignClient.init` failure (storage/crypto, NOT relay). Telemetry-only — the * init rejection is always rethrown so `getClient()` callers see it unchanged. */ onInitError?: (error: unknown) => void; /** * Relay transport socket dropped (relayer `disconnect`), emitted once per * outage. The lifecycle FACT — distinct from `onRelayError` (a close WITH an * error). This is the CARE-263 signal a suspended WebView produces silently. */ onRelayDisconnect?: () => void; /** * Relay socket recovered (relayer `connect` after a drop). Pair with * `onRelayDisconnect` to measure the dead window. */ onRelayReconnect?: () => void; } /** * Normalize the telemetry constructor slots into a `WalletConnectTelemetryObserver`. * * BACKWARD COMPATIBILITY: the published 0.8.x signature was positional — * `(…, onRelayError?, onInitError?)`. This PR moved to a single observer object; * the positional form is retained so external JS/TS consumers on 0.8.x don't * break at runtime. Disambiguate on the first telemetry slot: a FUNCTION is the * legacy `onRelayError` (the new form always passes an object). The legacy form * predates `onRelayDisconnect`/`onRelayReconnect`, so those are simply absent. */ export declare function toTelemetryObserver(observerOrOnRelayError?: WalletConnectTelemetryObserver | ((error: unknown) => void), onInitError?: (error: unknown) => void): WalletConnectTelemetryObserver; /** * Service for managing WalletConnect client instance */ export declare class WalletConnectClient { private client; private initPromise; /** Dedupe relay-error reports so a reconnect storm surfaces once, not per tick. */ private readonly relayErrorDedup; /** Hard limit for relay-error telemetry when messages are high-cardinality. */ private relayErrorCount; /** Ensures the telemetry-cap signal is emitted once per client. */ private relayErrorCapped; /** Independent bounded counters so drop/recover telemetry can never starve each other. */ private relayDisconnectCount; private relayReconnectCount; /** True once the socket has dropped — gates `relayReconnected` to real recoveries. */ private relayHasDisconnected; private readonly config; private readonly telemetryObserver; /** * @param telemetryObserver - optional telemetry sinks (see * `WalletConnectTelemetryObserver`). Every field is opt-in; an empty/omitted * observer leaves behaviour unchanged. */ constructor(config: WalletConnectConfig, telemetryObserver?: WalletConnectTelemetryObserver); /** * @deprecated Pass a {@link WalletConnectTelemetryObserver}. The positional * `(onRelayError, onInitError)` form is retained for backward compatibility * with the published 0.8.x signature and will be removed in a future major. */ constructor(config: WalletConnectConfig, onRelayError?: (error: unknown) => void, onInitError?: (error: unknown) => void); /** * Initialize or get the WalletConnect client */ getClient(): Promise; /** * Initialize the WalletConnect client */ private initClient; /** * Surface relay-socket failures as telemetry. The relay JsonRpcProvider re-emits * an abnormal WebSocket close under `RELAYER_EVENTS.error` — e.g. close code 3000 * "JWT Token is not yet valid" when the device clock is skewed past the relay's * 120s leeway. That error is otherwise detached from the connect() promise, so it * escapes the connect handoff and lands as an unhandled error. Forward it (deduped * per message) so it becomes a classified signal instead. This listener handles the * relayer ERROR stream only; the socket's clean up/down lifecycle is captured * separately by `attachRelayLifecycleListeners` (CARE-263 — a suspended WebView * drops the socket without emitting an `error`). Telemetry-only; never changes behaviour. */ private attachRelayErrorListener; /** * Surface the relay transport socket's up/down lifecycle as telemetry. This is * the signal `attachRelayErrorListener` misses: when iOS suspends the WebView * during a wallet deep-link the socket drops with no `error` event, WC core only * reconnects on its slow internal heartbeat, and any in-flight sign/connect * response strands in the meantime (CARE-263). Emitting `disconnect` + the * subsequent `connect` lets us see the drop and measure the dead window. * * Emitted at most once per outage: WC core re-emits `disconnect` on every failed * reconnect attempt, so a transition flag gates the emit to keep drop/recover 1:1 * (and bounds emissions); a counter cap backstops many distinct outages. Both * sinks are guarded so a throwing observer can never break the SDK's relayer * dispatch. Telemetry-only; it never changes connection behaviour. */ private attachRelayLifecycleListeners; /** * The initialized client if `connect()` already ran, else null. Synchronous — * lets callers attach lifecycle listeners post-connect without forcing a * re-init or awaiting. */ getExistingClient(): SignClient | null; /** * Disconnect all sessions */ disconnectAll(): Promise; /** * Disconnect a specific session */ disconnect(topic: string): Promise; } //# sourceMappingURL=walletconnect-client.d.ts.map