Files
kestrove-core/crates/kv-wasm/js/client.d.ts
T
samiandClaude Opus 5.5 2e2c8cd26f kv-wasm: onboarding (setup codes, enrollment tickets, scan-to-join) for the web vault
Mirrors kv-ffi's docs/10 §5 API in WebCore and binds it under the names the web app codes
against: setupPayloadForKit, addDevicePayload, revokeEnrollmentTicket, loginWithSetup,
joinStart/joinPoll/joinCancel, joinApprove, joinSend, and the free function parseSetupPayload
(also callable through the worker client).

Unlike kv-ffi, the Secret Key is not persisted: every unlock on the web takes it, so it is
kept zeroized in the unlocked state and dropped on lock. loginWithSetup refuses a code for a
different server than the configured origin (the browser only talks to its own origin).

Tests: ticket enrollment and scan-to-join in both roles against kv-ffi via the kv-sync test
server, a swapped-approver rejection, a Chrome test (IndexedDB never holds the Secret Key,
JS shapes, error codes) and a Node smoke check of the built package.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-18 06:58:13 +09:00

44 lines
1.4 KiB
TypeScript

import type {
VaultCore,
CoreError,
CoreErrorCode,
generatePassword,
totpCode,
matchUrl,
coreVersion,
parseSetupPayload,
} from "./kv_wasm.js";
export * from "./kv_wasm.js";
type Async<F> = F extends (...args: infer A) => infer R ? (...args: A) => Promise<Awaited<R>> : never;
type CoreMethods = {
[K in keyof VaultCore as K extends "free" | typeof Symbol.dispose ? never : K]: Async<VaultCore[K]>;
};
/** `VaultCore` running in a Web Worker: same methods, all async, plus the free functions. */
export type RemoteVault = CoreMethods & {
generatePassword: Async<typeof generatePassword>;
totpCode: Async<typeof totpCode>;
matchUrl: Async<typeof matchUrl>;
coreVersion: Async<typeof coreVersion>;
parseSetupPayload: Async<typeof parseSetupPayload>;
/** Frees the core (zeroizing keys), releases the tab lock and terminates the worker. */
close(): Promise<void>;
};
/** `"InUse"`: another tab already has this vault open (one tab per vault). */
export type ClientErrorCode = CoreErrorCode | "InUse";
export interface ConnectOptions {
/** IndexedDB database name. Default "kestrove". */
dbName?: string;
/** Persist nothing (previews, tests). */
inMemory?: boolean;
/** Bring your own worker (e.g. a bundler's `new Worker(new URL(...))`). It must run worker.js. */
worker?: Worker;
}
export function connectVault(options?: ConnectOptions): Promise<RemoteVault>;