import { EIP1193Provider, KeyPair } from '@walletcast/types'; type WalletId = 'metamask' | 'trust' | 'coinbase' | 'phantom' | 'okx'; interface WalletInfo { name: string; /** Generate universal link (https://...) for this wallet */ universal: (connectorUrl: string) => string; /** Generate native deep link (protocol://...) for this wallet */ native: (connectorUrl: string) => string; } interface DeepLinkConfig { /** URL where the connector page is hosted */ connectorUrl: string; /** Public RPC endpoint for read methods. If omitted, all requests go through the wallet. */ rpcUrl?: string; /** Target chain ID. If omitted, detected from the wallet on connect. */ chainId?: number; /** Nostr relay WebSocket URLs (defaults to well-known public relays) */ nostrRelays?: string[]; /** Fallback URL to fetch a fresh relay list if hardcoded relays are down */ relayListUrl?: string; } interface DeepLinkResult { /** EIP-1193 provider for the dapp to use */ provider: EIP1193Provider; /** Deep link URLs per wallet */ links: Record; /** Full connector URL with connection params */ connectorUrl: string; /** Dapp's public key (hex) */ pubkey: string; /** Dapp's keypair (for session persistence) */ keypair: KeyPair; /** Nostr relay URLs used (for session persistence) */ relays: string[]; /** Resolves with accounts when the wallet connects */ approval: Promise; } /** Messages exchanged over encrypted Nostr events */ type NostrRpcMessage = { type: 'session'; accounts: string[]; chainId: string; } | { type: 'request'; id: number; method: string; params: unknown[]; } | { type: 'response'; id: number; result?: unknown; error?: { code: number; message: string; }; } | { type: 'event'; name: string; data: unknown; } | { type: 'ping'; } | { type: 'pong'; } | { type: 'disconnect'; }; /** * Encrypted Nostr RPC transport. * * Uses the same ECDH + AES-256-GCM encryption as the existing signaling * layer, but carries JSON-RPC messages instead of WebRTC SDP payloads. * Messages are published as ephemeral Nostr events (kind 21059). */ declare class NostrRpc { private relayPool; private keypair; private pubKeyHex; constructor(relayUrls: string[], keypair: KeyPair); /** Get our x-only public key hex (for sharing with the connector). */ get publicKey(): string; /** * Send an encrypted RPC message to a recipient. */ send(recipientPubKey: string, message: NostrRpcMessage): Promise; /** * Subscribe to encrypted RPC messages addressed to our public key. * Returns an unsubscribe function. */ subscribe(onMessage: (msg: NostrRpcMessage, senderPubKey: string) => void): Promise<() => void>; /** Close all relay connections. */ destroy(): Promise; } interface RestoredSessionState { remotePubKey: string; accounts: string[]; chainId: string; } /** * EIP-1193 provider that communicates with a wallet via encrypted Nostr messages. * * Read methods (eth_call, eth_getBalance, etc.) go to a public RPC endpoint. * Signing methods (eth_sendTransaction, personal_sign, etc.) are forwarded to * the wallet's connector page over Nostr relays. */ declare class DeepLinkProvider implements EIP1193Provider { private nostrRpc; private rpcRouter; private emitter; private remotePubKey; private accounts; private chainId; private connected; private nextId; private pending; private unsubscribe; private heartbeatInterval; private lastPong; private sessionResolve; private sessionReject; /** Called when the remote side sends a disconnect message. */ onSessionCleared: (() => void) | null; constructor(rpcUrl: string | undefined, chainId: number | undefined, nostrRpc: NostrRpc, restoredState?: RestoredSessionState); /** * Start listening for the connector's session message. * Returns a promise that resolves with accounts when the wallet connects. */ waitForSession(timeout?: number): Promise; /** * Attempt to restore a previous session by sending ping and waiting for pong. * Requires constructor to have been called with restoredState. * Throws if no pong received within timeout. */ restoreSession(timeout?: number): Promise; request(args: { method: string; params?: unknown[]; }): Promise; on(event: string, listener: (...args: unknown[]) => void): void; removeListener(event: string, listener: (...args: unknown[]) => void): void; get isConnected(): boolean; /** The wallet's current chain ID (hex string, e.g. "0x1"). Updated from session/events. */ get currentChainId(): string; disconnect(): Promise; private handleMessage; private sendToWallet; private startHeartbeat; private stopHeartbeat; private rejectAllPending; } /** * Dapp-side session persistence. * * Saves the ephemeral keypair, relay list, and wallet state so that a page * reload can silently reconnect via ping/pong instead of showing a new QR. */ interface DappSession { version: 1; /** Dapp's private key (64-char hex) */ privateKeyHex: string; /** Dapp's x-only public key (64-char hex) */ publicKeyHex: string; /** Connector's x-only public key (64-char hex) */ remotePubKey: string; /** Nostr relay URLs */ relays: string[]; /** Connected wallet accounts */ accounts: string[]; /** Hex chain ID (e.g. "0x1") */ chainId: string; /** Public RPC endpoint */ rpcUrl: string; /** Connector page base URL */ connectorUrl: string; /** Unix ms when session was created */ createdAt: number; } declare class SessionManager { private storageKey; private ttlMs; constructor(storageKey?: string, ttlMs?: number); save(session: DappSession): void; load(): DappSession | null; clear(): void; } declare const WALLET_REGISTRY: Record; /** * Build the full connector URL with connection params in the hash fragment. * Format: {baseUrl}#/c/{pubkey_base64url}/{relay1}/{relay2}/... * Example: https://walletcast.net/#/c/7xKp8y.../relay.damus.io/nos.lol * * The hash fragment is never sent to the server, so pubkeys and relay * addresses stay private (no Cloudflare/nginx log leakage). */ declare function generateConnectorUrl(baseUrl: string, pubkey: string, relays: string[]): string; /** * Generate deep link URLs for a specific wallet to open the connector page. */ declare function generateDeepLink(walletId: WalletId, connectorUrl: string): { universal: string; native: string; }; /** * Generate deep links for all supported wallets. */ declare function generateAllDeepLinks(connectorUrl: string): Record; export { type DappSession, type DeepLinkConfig, DeepLinkProvider, type DeepLinkResult, NostrRpc, type NostrRpcMessage, type RestoredSessionState, SessionManager, WALLET_REGISTRY, type WalletId, type WalletInfo, generateAllDeepLinks, generateConnectorUrl, generateDeepLink };