/** * Statement store driver — manages statement RPC through either a smoldot * chain connection, a shared runtime-owned chain service, or a direct browser * WebSocket to a full node. * * Custom pallet RPC methods (statement_submit, statement_subscribeStatement, * etc.) cannot be forwarded by smoldot, so hosts either provide a shared * runtime-owned chain service or the `websocket` transport opens a direct * connection to a full-node endpoint instead. * * @example smoldot transport * ```ts * import { SmoldotDriver, StatementStoreDriver } from "@polkadot-apps/host-sdk"; * * const store = new StatementStoreDriver( * { kind: "smoldot", driver, chainName: "PaseoAssetHub" }, * sdk.chainClient, * sdk.raw.statement, * ); * store.subscribe((stmt) => console.log("new statement:", stmt)); * await store.submit(encodedHex); * ``` * * @example websocket transport * ```ts * import { StatementStoreDriver } from "@polkadot-apps/host-sdk"; * * const store = new StatementStoreDriver( * { kind: "websocket", endpoints: ["wss://pop3-testnet.parity-lab.parity.io/people"] }, * sdk.chainClient, * sdk.raw.statement, * ); * store.subscribe((stmt) => console.log("new statement:", stmt)); * await store.submit(encodedHex); * ``` * * @example shared runtime transport * ```ts * import { StatementStoreDriver, mountHostRuntimeFrame } from "@polkadot-apps/host-sdk"; * * const runtimeFrame = await mountHostRuntimeFrame({ * runtimeUrl: "https://host.dot.li/runtime-frame.html", * runtimeOrigin: "https://host.dot.li", * }); * * const store = new StatementStoreDriver( * { kind: "runtime", chainService: runtimeFrame.chainService!, chainName: "PaseoAssetHub" }, * sdk.chainClient, * sdk.raw.statement, * ); * ``` */ import type { SmoldotDriver, WasmChainClientHandle } from "./chain.js"; import type { DecodedStatement } from "./types.js"; export type StatementCallback = (statement: DecodedStatement) => void; /** * WASM StatementHandle interface (pure encoding — no I/O). * Matches the real StatementHandle exported from host-wasm. */ export interface WasmStatementHandle { hexDecode(hex: string): Uint8Array; hexEncode(bytes: Uint8Array): string; decodeStatement(bytes: Uint8Array): DecodedStatement; buildSigningPayload(nowSecs: number, decryptionKey: Uint8Array | null, channel: Uint8Array | null, priority: number, topicsFlat: Uint8Array, data: Uint8Array): Uint8Array; assembleStatement(signingPayloadWithHeader: Uint8Array, sr25519Pubkey: Uint8Array, signature: Uint8Array): Uint8Array; blake2b256(data: Uint8Array): Uint8Array; } /** * Discriminated union selecting the JSON-RPC transport for StatementStoreDriver. * * - `smoldot`: route requests through an existing SmoldotDriver chain connection. * - `runtime`: route requests through a shared HostRuntime-owned chain service. * - `websocket`: open a direct browser WebSocket to a full-node endpoint list. * The driver cycles through `endpoints` on failure and reconnects automatically. */ export type StatementTransport = { kind: "smoldot"; driver: SmoldotDriver; chainName: string; } | { kind: "runtime"; chainService: RuntimeStatementChainService; chainName: string; } | { kind: "websocket"; endpoints: string[]; }; type RuntimeStatementSubscriptionStop = () => void | Promise; export interface RuntimeStatementChainService { sendRpc(chainName: string, method: string, paramsJson: string): Promise; startSubscription(chainName: string, method: string, paramsJson: string, onMessage: (jsonRpc: string) => void, onAbort: (reason: string) => void): RuntimeStatementSubscriptionStop | Promise; } /** * Manages statement store operations over either a smoldot chain connection, * a shared runtime-owned chain service, or a direct WebSocket to a full node. * * Lifecycle: * 1. Create with a transport, chain handle, and WASM statement handle * 2. Call `subscribe(cb)` to receive incoming statements * 3. Call `submit(encodedHex)` to submit statements * 4. Call `destroy()` to clean up */ export declare class StatementStoreDriver { private transport; private chainHandle; private statementHandle; private nextId; private subId; private subRequestId; private callback; private pendingRequests; private seen; private destroyed; private ws; private wsEndpointIndex; private wsReconnectTimer; private runtimeSubscriptionState; private runtimeSubscriptionStop; constructor(transport: StatementTransport, chainHandle: WasmChainClientHandle, statementHandle: WasmStatementHandle); /** Submit a hex-encoded statement. Rejects if the node rejects the statement. */ submit(encodedHex: string): Promise; /** Fetch current broadcast statements matching the given topic hex strings. */ fetchBroadcasts(topicHexes: string[]): Promise; /** Subscribe to incoming statement notifications. */ subscribe(cb: StatementCallback): void; /** Unsubscribe from statement notifications. */ unsubscribe(): void; /** Clean up: unsubscribe and remove the response interceptor / close the WebSocket. */ destroy(): void; private getParaChain; /** * Response interceptor called by SmoldotDriver for each JSON-RPC response. * Returns true if the message was consumed (statement-related), false otherwise. */ private handleResponse; /** Open a WebSocket to the next available endpoint. */ private wsConnect; private wsOnOpen; private wsOnMessage; private wsOnError; private wsOnClose; /** * Send a JSON-RPC message over the WebSocket. * If the socket is not open, immediately rejects the pending request and removes it. */ private wsSend; /** Send the statement_subscribeStatement request. */ private wsSendSubscribe; /** * Extract statement hex strings from a subscription notification. * Mirrors the three JSON pointer paths the native implementation checks: * /params/result/data/statements * /params/result/newStatements/statements * /params/result/statements */ private extractStatementHexes; /** Resolve a submit promise, translating node rejection objects into errors. */ private resolveSubmit; private processStatements; private decodeBroadcastsResult; private handleRuntimeSubscriptionMessage; private parseRuntimeRpcMessage; private parseRuntimeRpcResult; } export {}; //# sourceMappingURL=statement-store.d.ts.map