import type { Network, NetworkId, Namespace } from './networks'; import type { ConnectionMode } from './connection-mode'; import type { AvailableAddress } from './session'; import type { DetectedEIP6963WalletInfo, DetectedSolanaWalletInfo, DetectedTronWalletInfo, DetectedTonWalletInfo, DetectedBitcoinWalletInfo, ExtensionInjectedProvider, IntegratedBrowserInjectedProvider, WalletConnectProvider, TonConnectWalletProvider, WalletMetadata } from './UWC-state'; import type { EVMCapabilities, TransactionRequest, TransactionResult } from './transactions'; import type { SignatureResult, EIP712TypedData } from './signature'; /** * A post-connect wallet lifecycle change observed from the live provider. * * PII-safe by construction: there is NO address field. For `accountChanged` we * signal only THAT the account/list changed (the new address is dropped at the * connector boundary). `chainChanged` carries the new CAIP-2 id (non-PII) when * resolvable. */ export type WalletLifecycleEvent = { type: 'accountChanged'; } | { type: 'chainChanged'; chainId?: NetworkId; } | { type: 'disconnect'; } | { type: 'sessionExpired'; }; /** * Names the session a lifecycle subscription is being attached FOR. The caller * (core) resolves it from the active session and passes it explicitly — a * connector must never infer it from its own ambient state, which can be * ambiguous (a secondary-namespace gather leaves more than one internal * service holding a live provider surface). */ export interface WalletLifecycleContext { /** Transport of the session being observed. */ connectionMode: ConnectionMode; /** ACTIVE namespace of the session — the surface the connector must observe. */ namespace?: Namespace; walletId?: string; } /** * Result interface for connect operations */ export interface ConnectorResult { networkId: NetworkId; address: string; availableAddresses: AvailableAddress[]; publicKey?: string; } /** * Result interface for network switch operations */ export interface SwitchNetworkResult { networkId: NetworkId; address: string; availableAddresses?: AvailableAddress[]; } /** * Per-attempt options for {@link Connector.connect}. * * Deliberately per-CONNECT rather than connector construction config: the * caller's constraint can differ between attempts (a verify flow pins a * different address than the transfer flow that preceded it), so config read * once at construction would go stale. */ export interface ConnectorConnectOptions { /** * Addresses the caller will accept for this connection, case-insensitive. * * When set, a connector must not report an already-authorized account that * falls outside the list as an existing connection — it should re-prompt so * the user can authorize a matching one — and should prefer a matching * account over positional order when the wallet returns several. * * Currently honoured by the bip122 (Bitcoin) namespace, where Wallet * Standard `wallet.accounts` is the PER-ORIGIN authorized set rather than * the wallet's live UI selection. Other namespaces ignore it today; an empty * or omitted list means no constraint. */ requiredAddresses?: readonly string[]; } /** * Common interface for all wallet connectors */ export interface Connector { /** * Connect to a wallet on the specified network * @param network The network to connect to * @param provider The transport-specific provider for this connector * @param options Per-attempt constraints; see {@link ConnectorConnectOptions} * @returns A promise that resolves to a ConnectorResult containing the network ID, wallet address, and available addresses */ connect(network: Network, provider?: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider | WalletConnectProvider | TonConnectWalletProvider, options?: ConnectorConnectOptions): Promise; /** * Get the connection URI for the wallet, if applicable * This is typically used for WalletConnect or similar protocols * to allow the user to scan a QR code or open a link * to initiate the connection. * @return A string representing the connection URI, or undefined if not applicable * @remarks This method is optional and may not be implemented by all connectors. */ getConnectionURI?(): string; /** * Pre-generate a connection pairing (URI) ahead of wallet selection, WITHOUT * waiting for approval. Warms the transport (e.g. opens the WalletConnect relay * socket on a cold client) and returns a URI the caller can deep-link inside a * user gesture; a subsequent `connect()` adopts the same pairing so the URI the * user approves matches the one opened. Optional — only connectors with a * pairing step (WalletConnect) implement it. * @param provider Only `supportedNetworkIds` is required (pass the UNION of the * session's WalletConnect wallets' networks so one pairing serves any wallet). * @returns The pairing URI. */ beginPairing?(provider: Pick): Promise; /** * Disconnect from the wallet * This method is optional and may not be implemented by all connectors. * @returns A promise that resolves when the disconnection is complete */ disconnect?(): Promise; /** * Switch to a different network * @param network The network to switch to * @param args Additional arguments specific to the connector type * @returns A promise that resolves to a SwitchNetworkResult containing the network ID and new wallet address */ switchNetwork(network: Network, provider?: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider | WalletConnectProvider | TonConnectWalletProvider): Promise; /** * Get available wallets for a specific namespace * This method is optional and may not be implemented by all connectors. * @param namespace The namespace to check for available wallets (e.g., 'eip155', 'solana') * @param expectedWallets The expected wallets to check for * @returns A promise that resolves to an array of detected wallets, or undefined if not supported */ getAvailableWallets?(namespace: Namespace, expectedWallets?: WalletMetadata[]): Promise; /** * Sign a message with the connected wallet * @param message The message to sign * @param provider The wallet provider (required for injected connector) * @returns A promise that resolves to a {@link SignatureResult} carrying both * the signature and the EXACT address it was signed with. Consumers verifying * ownership MUST claim `result.address` (the live signer) rather than a * possibly-stale session address, which can diverge after an account switch. */ signMessage?(message: string, provider?: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider | WalletConnectProvider | TonConnectWalletProvider): Promise; /** * Sign EIP-712 typed structured data (eth_signTypedData_v4). * Required for ERC-3009 (Transfer With Authorization) and EIP-2612 (Permit) relay flows. * EVM-only (eip155); connectors that don't support it leave this undefined. * @returns A promise that resolves to the 65-byte hex signature (0x-prefixed) */ signTypedData?(typedData: EIP712TypedData, provider?: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider | WalletConnectProvider): Promise; /** * Send a transaction with the connected wallet * @param request The transaction request parameters * @param provider The wallet provider (required for injected connector) * @returns A promise that resolves to the transaction result */ sendTransaction?(request: TransactionRequest, provider?: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider | WalletConnectProvider | TonConnectWalletProvider): Promise; getWalletCapabilities?(from: string, networks: Network[]): Promise>; /** * Sign a Solana tx without broadcasting — raw bytes in/out (no @solana/web3.js * for callers). Fee-payer relay flows: the wallet adds only the user's * signature, the relay broadcasts. Optional; not all connectors support it. */ signSolanaTransactionBytes?(serializedTx: Uint8Array): Promise; /** * Subscribe to post-connect wallet lifecycle changes from the live provider * (account/chain switched in the wallet, disconnect, session expiry). For * OBSERVABILITY only — it never changes connection behaviour. * * Implementations MUST NOT include an address in the emitted event (the PII * boundary stays in core). The caller passes a `WalletLifecycleContext` * naming the session being observed (active namespace / transport / wallet); * implementations route by it rather than inferring from internal state. * Returns an unsubscribe function, or `undefined` when this connector/session * can't be observed (no live `.on`, unsupported namespace) — the core then * emits `lifecycleTelemetryUnavailable`. Optional: a connector that never * observes lifecycle leaves it undefined entirely. */ onLifecycleEvent?(listener: (event: WalletLifecycleEvent) => void, context: WalletLifecycleContext): (() => void) | undefined; /** * Subscribe to the live provider's REAL account list for the active * session — used only to keep UWC's own session state (activeAddress / * availableAddresses) in sync with the wallet. This is a distinct concern * from `onLifecycleEvent`: that stream is PII-safe telemetry and must * never carry an address; this one exists specifically to carry it. * * An empty array signals the wallet-side logout/lock condition — the * caller (core) treats it as a full disconnect. Returns an unsubscribe * function, or `undefined` when this connector/session can't be observed * (no live `.on`, unsupported namespace). Optional: a connector that * never observes real account changes leaves it undefined entirely. */ onAccountsChanged?(listener: (accounts: string[]) => void, context: WalletLifecycleContext): (() => void) | undefined; /** * Read the wallet's LIVE current address for a given namespace, re-read at * call time (not the connect-time cache), so it reflects an in-wallet account * switch. Optional: only connectors backed by a live provider/adapter per * namespace implement it (injected, tron). Returns null when the namespace * isn't connected or no address is available. Must never throw. */ getLiveAccount?(namespace: Namespace): Promise; } //# sourceMappingURL=connector.d.ts.map