import { CommunicationClient, WCStorage } from '@ecadlabs/beacon-core'; import Client from '@walletconnect/sign-client'; import { SessionTypes, SignClientTypes } from '@walletconnect/types'; import { ExtendedWalletConnectPairingRequest, ExtendedWalletConnectPairingResponse, NetworkType, OperationRequest, PermissionRequest, SignPayloadRequest } from '@ecadlabs/beacon-types'; export interface PermissionScopeParam { networks: NetworkType[]; methods: PermissionScopeMethods[]; events?: PermissionScopeEvents[]; } export declare enum PermissionScopeMethods { GET_ACCOUNTS = "tezos_getAccounts", OPERATION_REQUEST = "tezos_send", SIGN = "tezos_sign" } export declare enum PermissionScopeEvents { CHAIN_CHANGED = "chainChanged", ACCOUNTS_CHANGED = "accountsChanged", REQUEST_ACKNOWLEDGED = "requestAcknowledged" } export declare class WalletConnectCommunicationClient extends CommunicationClient { private readonly wcOptions; private readonly isLeader; protected readonly activeListeners: Map void>; protected readonly channelOpeningListeners: Map void>; private static instance; signClient: Client | undefined; private signClientPromise; private pairingRequestPromise; storage: WCStorage; private session; private activeAccountOrPbk; private activeNetwork; readonly disconnectionEvents: Set; private pingInterval; /** * this queue stores each active message id * [0] newest message * [length - 1] oldest message */ private messageIds; /** * Tracks the last time session extension was attempted (Unix timestamp in seconds) * Used to prevent duplicate re-extension attempts that can cause relay conflicts */ private lastExtensionAttempt; constructor(wcOptions: { network: NetworkType; opts: SignClientTypes.Options; }, isLeader: Function); static getInstance(wcOptions: { network: NetworkType; opts: SignClientTypes.Options; }, isLeader: Function): WalletConnectCommunicationClient; private getTopicFromSession; listenForEncryptedMessage(senderPublicKey: string, messageCallback: (message: string) => void): Promise; listenForChannelOpening(messageCallback: (pairingResponse: ExtendedWalletConnectPairingResponse) => void): Promise; /** * WC Sign client doesn't sync between intances, meaning that a dApp signClient instance state may * differ from a wallet state */ private refreshState; private clearEvents; private onStorageMessageHandler; private onStorageErrorHandler; unsubscribeFromEncryptedMessages(): Promise; unsubscribeFromEncryptedMessage(_senderPublicKey: string): Promise; closeSignClient(): Promise; private ping; private checkWalletReadiness; sendMessage(_message: string, _peer?: any): Promise; private fetchAccounts; private notifyListenersWithPermissionResponse; requestPermissions(message: PermissionRequest): Promise; /** * @description Once the session is establish, send payload to be approved and signed by the wallet. * @error MissingRequiredScope is thrown if permission to sign payload was not granted */ signPayload(signPayloadRequest: SignPayloadRequest): Promise; /** * @description Once the session is established, send Tezos operations to be approved, signed and inject by the wallet. * @error MissingRequiredScope is thrown if permission to send operation was not granted */ sendOperations(operationRequest: OperationRequest): Promise; private isMobileSesion; /** * Function used to fix appSwitching with web wallets when pairing through 'Other wallet flow' * @param session the newly created session */ private updateStorageWallet; init(forceNewConnection?: boolean): Promise<{ uri: string; topic: string; } | undefined>; close(): Promise; private subscribeToSessionEvents; private acknowledgeRequest; private updateActiveAccount; private disconnect; private onSessionClosed; getPairingRequestInfo(): Promise; private createPairingRequestInfo; private closePairings; private closeSessions; private openSession; private getRequiredPermissionScopeParams; private getOptionalPermissionScopeParams; private permissionScopeParamsToNamespaces; private validateReceivedNamespace; private validateMethods; private validateEvents; private validateAccounts; closeActiveSession(account: string, notify?: boolean): Promise; private validateNetworkAndAccount; /** * @description Access the active network * @error ActiveNetworkUnspecified thorwn when there are multiple Tezos networks in the session and none is set as the active one */ getActiveNetwork(): string; private setDefaultAccountAndNetwork; /** * @description Return all connected accounts from the active session * @error NotConnected if no active session */ getAccounts(): string[]; /** * @description Return all networks from the namespace of the active session * @error NotConnected if no active session */ getNetworks(): string[]; private getTezosNamespace; private getPermittedMethods; private getPermittedNetwork; private getTezosRequiredNamespace; private notifyListeners; currentSession(): SessionTypes.Struct | undefined; private tryConnectToRelayer; private initSignClientWithTimeout; private getSignClient; private createSignClient; private getSession; /** * @description Access the public key hash (or public key) of the active account * @error ActiveAccountUnspecified thrown when there are multiple Tezos account in the session and none is set as the active one */ getAccountOrPK(): Promise; private clearState; /** * @description Checks if session is close to expiry and extends it if needed * Extends session by 7 days if it will expire within 24 hours * Uses defensive error handling to prevent relay message conflicts (TrustWallet issue) */ private checkAndExtendSession; /** * @description Validates if a restored session is still valid and usable * @param session The session to validate * @returns true if session is valid, false if stale/expired */ private isSessionValid; /** * @description Cleans up a stale session by disconnecting and removing it * @param session The stale session to cleanup */ private cleanupStaleSession; private withTimeout; }