/** * Types for the window.host bridge adapter pattern. * * The bridge sits between a host runtime (which implements HostBridgeAdapter) * and a guest web app (which uses HostBridge). It translates between the * low-level binary adapter API and the string-oriented API that apps expect. */ import type { HostStoreStatus } from "../types.js"; import type { BridgeMetadata, BridgeMetadataOptions } from "./contract.js"; /** A decoded statement as delivered by the adapter's subscribe callback. */ export interface BridgeStatement { proofPubkey: Uint8Array | undefined; channel: Uint8Array | undefined; topics: Uint8Array[]; data: Uint8Array; priority: number; timestampMs?: number; } /** Cancels an adapter subscription when called. */ export type BridgeUnsubscribe = () => void; /** The host runtime must implement this interface to back a HostBridge. */ export interface HostBridgeAdapter { statements: { subscribe(topics: Uint8Array[], onStatement: (stmt: BridgeStatement) => void): BridgeUnsubscribe; submit(encodedStatement: Uint8Array): Promise; status(): Promise; }; storage: { get(key: string): Promise; set(key: string, value: string): Promise; remove(key: string): Promise; }; getAddress(): Promise; sign(payload: Uint8Array): Promise<{ publicKey: Uint8Array; signature: Uint8Array; }>; /** Optional: resolve a username to an account ID on the People chain. */ resolveUsername?(username: string): Promise; } export type { HostStoreStatus } from "../types.js"; export type { StatementEventPayload } from "../events.js"; /** Pure encoding helpers required by the bridge - no I/O, no side effects. */ export interface BridgeEncodingUtils { /** Hash a string into a 32-byte topic (blake2b-256). */ stringToTopic(s: string): Uint8Array; /** Build the signing payload for a statement (step 1 of 2). */ buildSigningPayload(nowSecs: number, decryptionKey: Uint8Array | null, channel: Uint8Array | null, priority: number, topicsFlat: Uint8Array, data: Uint8Array): Uint8Array; /** Assemble a complete statement from payload + signature (step 2 of 2). */ assembleStatement(signingPayloadWithHeader: Uint8Array, sr25519Pubkey: Uint8Array, signature: Uint8Array): Uint8Array; /** Hex-encode bytes with 0x prefix. */ hexEncode(bytes: Uint8Array): string; } /** Options for createWindowHostBridge. */ export interface CreateWindowHostBridgeOptions { adapter: HostBridgeAdapter; encoding: BridgeEncodingUtils; /** Optional prefix prepended to all storage keys (e.g. "voxchat:"). */ storagePrefix?: string; /** Optional metadata describing the host profile and extension capabilities. */ metadata?: BridgeMetadataOptions; } /** The bridge object exposed to the app (assigned to window.host or similar). */ export interface HostBridge { /** Immutable bridge metadata for version/profile/capability feature detection. */ readonly __bridge: BridgeMetadata; statements: { /** Register interest in a channel. Topics are accumulated across calls. */ subscribe(channel: string): Promise; /** Sign and submit data to a channel. Data must be base64-encoded. */ write(channel: string, data: string): Promise; /** Query the health of the underlying statement store. */ status(): Promise; }; storage: { get(key: string): Promise; set(key: string, value: string): Promise; remove(key: string): Promise; }; identity: { /** Resolve a username to a hex account ID. Throws if not supported. */ resolveUsername(username: string): Promise; }; /** Return the hex-encoded address of the current account. */ getAddress(): Promise; /** Register an event listener. */ on(event: string, callback: (data: unknown) => void): void; /** Remove an event listener. */ off(event: string, callback: (data: unknown) => void): void; /** Tear down the bridge: unsubscribe from adapter, clear state. */ destroy(): void; } //# sourceMappingURL=types.d.ts.map