UNPKG

@provablehq/sdk

Version:

A Software Development Kit (SDK) for Zero-Knowledge Transactions

61 lines (60 loc) 2.92 kB
import { FunctionKeyPair } from "../../models/keyPair.js"; import { KeyFingerprint } from "../verifier/interface.js"; import { KeyLocator, KeyStore, ProvingKeyLocator, VerifyingKeyLocator } from "./interface.js"; import { ProvingKey, VerifyingKey } from "../../wasm.js"; /** * Browser-compatible {@link KeyStore} backed by IndexedDB. * * This is the browser counterpart to {@link LocalFileKeyStore} (which requires Node.js `fs`). * It persists proving and verifying keys across page reloads and browser sessions using the * IndexedDB API available in all modern browsers and Web Workers. * * **Environment**: Browser / Web Worker only. Instantiating this class is safe in any * environment, but the first IndexedDB operation will reject with a clear error when * `globalThis.indexedDB` is not available (e.g., Node.js, SSR contexts). Guard your * imports accordingly if you bundle for server-side rendering. * * **Security**: Keys are stored as plaintext `Uint8Array` in IndexedDB. Any script * running on the same origin — including scripts injected via XSS — can read the stored * proving and verifying keys. Do **not** use this keystore for data that must remain * confidential under an XSS-capable adversary; encrypt sensitive material at the * application layer before persisting, or use an in-memory store. * * @example * ```ts * import { IndexedDBKeyStore, ProgramManager } from "@provablehq/sdk"; * * const keyStore = new IndexedDBKeyStore(); * const pm = new ProgramManager(); * pm.setKeyStore(keyStore); * // Keys synthesized during execution are now cached in IndexedDB * // and reloaded automatically on subsequent runs. * ``` */ export declare class IndexedDBKeyStore implements KeyStore { private readonly dbName; private readonly storeName; private readonly keyVerifier; private dbPromise; /** * @param dbName IndexedDB database name. Defaults to `"aleo-keystore"`. */ constructor(dbName?: string); /** Opens (or creates) the database, returning a cached promise. */ private openDB; /** Runs a single read-write transaction and returns the request result. */ private tx; private validateComponent; private validateNonNegative; private serializeLocator; private checksumToFingerprint; getKeyBytes(locator: KeyLocator): Promise<Uint8Array | null>; getProvingKey(locator: ProvingKeyLocator): Promise<ProvingKey | null>; getVerifyingKey(locator: VerifyingKeyLocator): Promise<VerifyingKey | null>; setKeys(proverLocator: ProvingKeyLocator, verifierLocator: VerifyingKeyLocator, keys: FunctionKeyPair): Promise<void>; setKeyBytes(keyBytes: Uint8Array, locator: KeyLocator): Promise<void>; getKeyMetadata(locator: KeyLocator): Promise<KeyFingerprint | null>; has(locator: KeyLocator): Promise<boolean>; delete(locator: KeyLocator): Promise<void>; clear(): Promise<void>; }