UNPKG

@lightninglabs/lnc-web

Version:

Lightning Node Connect npm module for web

97 lines 3.02 kB
/** * Plain data object passed to WasmManager.connect() with everything needed * to establish a connection. */ export interface ConnectionParams { pairingPhrase: string; serverHost: string; localKey?: string; remoteKey?: string; } /** * Callback interface that WasmManager invokes during the WASM handshake. * Each entrypoint provides its own callbacks to write keys back to the * appropriate store. */ export interface ConnectionCallbacks { onLocalKeyCreated(keyHex: string): void; onRemoteKeyReceived(keyHex: string): void; } /** * A reference to the global object that is extended with proper typing for the LNC * functions that are injected by the WASM client and the Go object. This eliminates the * need for casting `globalThis` to `any`. */ export declare const lncGlobal: typeof globalThis & { Go: new () => GoInstance; } & { [key: string]: unknown; }; /** * Manages WebAssembly client lifecycle, connection, and RPC communication. * Handles all WASM-specific operations and state management. */ export declare class WasmManager { private _wasmClientCode; private _namespace; private _preloadPromise?; private _callbacks; private go; private result?; constructor(namespace: string, wasmClientCode: string, callbacks: ConnectionCallbacks); /** * Get the WASM global object */ private get wasm(); /** * Set the WASM global object */ private set wasm(value); get isReady(): boolean; get isConnected(): boolean; get status(): string; get expiry(): Date; get isReadOnly(): boolean; hasPerms(permission: string): boolean; /** * Downloads the WASM client binary */ preload(): Promise<void>; /** * Initializes the WASM namespace, registers callbacks, and starts the * WASM client binary. */ run(): Promise<void>; /** * Waits until the WASM client is ready */ waitTilReady(): Promise<void>; /** * Connects to the LNC proxy server using plain connection parameters. */ connect(params: ConnectionParams): Promise<void>; /** * Disconnects from the proxy server */ disconnect(): void; /** * Emulates a GRPC request but uses the WASM client instead */ request<TRes>(method: string, request?: object): Promise<TRes>; /** * Subscribes to a GRPC server-streaming endpoint */ subscribe<TRes>(method: string, request?: object, onMessage?: (res: TRes) => void, onError?: (res: Error) => void): void; /** * Set up WASM callback functions using the stored ConnectionCallbacks. * Guarded so that a re-entrant run() via connect() does not overwrite * callbacks that are already wired up. */ private setupWasmCallbacks; /** * Wait for connection to be established. No post-connect cleanup — each * entrypoint handles its own credential lifecycle. */ private waitForConnection; } //# sourceMappingURL=wasmManager.d.ts.map