@turnkey/core
Version:
A core JavaScript web and React Native package for interfacing with Turnkey's infrastructure.
111 lines • 4.66 kB
TypeScript
import type { CoreTypes, ProposalTypes, SessionTypes } from "@walletconnect/types";
/**
* WalletConnectClient is a low-level wrapper around the WalletConnect SignClient.
*
* - Used internally by `WalletConnectWallet` to manage connections and sessions.
* - Handles pairing, approval, session tracking, RPC requests, and disconnects.
* - Exposes a minimal API for lifecycle control; higher-level logic lives in `WalletConnectWallet`.
*/
export declare class WalletConnectClient {
private client;
private pendingApproval;
private sessionUpdateHandlers;
private sessionEventHandlers;
private sessionDeleteHandlers;
/**
* Registers a callback for WalletConnect `session_delete`.
*
* - Fired from the underlying SignClient when a session is terminated.
* - Useful for clearing UI state or internal session data after a disconnect.
*
* @param fn - Callback to invoke when the session is deleted.
*/
onSessionDelete(fn: () => void): void;
/**
* Registers a callback for WalletConnect `session_update`.
*
* - Triggered when the wallet updates the session namespaces
* (e.g., accounts/chains/permissions). Use this to refresh providers.
* - Returns an unsubscribe function to remove the listener.
*
* @param fn - Callback invoked when a `session_update` occurs.
* @returns A function that unsubscribes this listener.
*/
onSessionUpdate(fn: () => void): () => void;
/**
* Registers a callback for WalletConnect `session_event`.
*
* - Emits ephemeral wallet events such as `chainChanged` or `accountsChanged`.
* - The raw event payload is forwarded so callers can inspect `{ event, chainId, topic }`.
* - Returns an unsubscribe function to remove the listener.
*
* @param fn - Callback receiving the raw session event args.
* @returns A function that unsubscribes this listener.
*/
onSessionEvent(fn: (args: any) => void): () => void;
/**
* Initializes the WalletConnect SignClient with your project credentials.
*
* - Must be called before `pair()`, `approve()`, or `request()`.
* - Configures app metadata and an optional custom relay server.
*
* @param opts.projectId - WalletConnect project ID.
* @param opts.appMetadata - Metadata about your app (name, URL, icons).
* @param opts.relayUrl - (Optional) custom relay server URL.
* @returns A promise that resolves once the client is initialized.
*/
init(opts: {
projectId: string;
appMetadata: CoreTypes.Metadata;
relayUrl?: string;
}): Promise<void>;
/**
* Initiates a pairing request and returns a URI to be scanned or deep-linked.
*
* - Requires `init()` to have been called.
* - Must be followed by `approve()` after the wallet approves.
* - Throws if a pairing is already in progress.
*
* @param namespaces - Optional namespaces requesting capabilities.
* @returns A WalletConnect URI for the wallet to connect with.
* @throws {Error} If a pairing is already in progress or no URI is returned.
*/
pair(namespaces: ProposalTypes.OptionalNamespaces): Promise<string>;
/**
* Completes the pairing approval process after the wallet approves the request.
*
* - Requires `init()` and a pending pairing started via `pair()`.
*
* @returns A promise that resolves to the established session.
* @throws {Error} If called before `pair()` or if approval fails.
*/
approve(): Promise<SessionTypes.Struct>;
/**
* Retrieves the most recent active WalletConnect session.
*
* @returns The most recent session, or `null` if none are active.
*/
getSession(): SessionTypes.Struct | null;
/**
* Sends a JSON-RPC request over the active WalletConnect session.
*
* - Requires `init()` and an active session.
*
* @param chainId - Target chain ID (e.g. `eip155:1`).
* @param method - RPC method name.
* @param params - Parameters for the RPC method.
* @returns A promise that resolves with the RPC response.
* @throws {Error} If no active session exists.
*/
request(chainId: string, method: string, params: any[] | Record<string, any>): Promise<any>;
/**
* Disconnects the active session, if one exists.
*
* - Sends a disconnect signal to the wallet.
* - Does nothing if no session is currently active.
*
* @returns A promise that resolves once disconnection is complete.
*/
disconnect(): Promise<void>;
}
//# sourceMappingURL=client.d.ts.map