/** * Web Worker wrapper for browser-based key derivation. * * Usage in React/browser: * ```typescript * import { createWorker, deriveInWorker } from 'brainvault/worker'; * * const worker = createWorker(); * * const result = await deriveInWorker(worker, { * identity: 'user@example.com', * password: new Uint8Array([...]), * profile: 'standard', * generation: 0, * factor: 3, * outputMode: 'pq', * }, (current, total) => { * console.log(`Progress: ${current}/${total}`); * }); * * worker.terminate(); * ``` */ import type { Profile } from '../core/profiles.js'; import type { OutputMode } from '../core/constants.js'; export interface WorkerDerivationConfig { identity: string; password: Uint8Array; profile: Profile | 'portable' | 'standard' | 'bunker'; generation: number; factor: number; outputMode: OutputMode | 'pq' | 'legacy' | 'both'; } export interface WorkerMessage { type: 'derive' | 'progress' | 'result' | 'error'; id: string; payload?: unknown; } export interface DeriveMessage extends WorkerMessage { type: 'derive'; payload: WorkerDerivationConfig; } export interface ProgressMessage extends WorkerMessage { type: 'progress'; payload: { current: number; total: number; }; } export interface ResultMessage extends WorkerMessage { type: 'result'; payload: SerializedDerivationResult; } export interface ErrorMessage extends WorkerMessage { type: 'error'; payload: { message: string; }; } /** * Serialized result that can be sent via postMessage. * Uint8Array is transferred, functions are omitted. */ export interface SerializedDerivationResult { fingerprint: string; algo: string; totalShards: number; penaltyShards: number; baseShards: number; outputMode: string; passwordStrength: { guessesLog10: number; entropyBits: number; effectiveBits: number; reason: string; securityTier: string; }; pq?: { secretKey: { pem: string; raw: Uint8Array; }; publicKey: { pem: string; raw: Uint8Array; }; keypair: { secretKey: Uint8Array; publicKey: Uint8Array; }; }; legacy?: { mnemonic: string; appPassword: string; }; } /** * Get the inline worker script. * * This returns the worker code as a blob URL, avoiding the need * for a separate worker file. */ export declare function getWorkerScript(): string; /** * Create a worker instance for key derivation. * * Note: In bundled applications, you may need to configure your bundler * to handle the worker properly. For Vite/Rollup, use: * * ```typescript * const worker = new Worker(new URL('./brainvault.worker.ts', import.meta.url), { type: 'module' }); * ``` * * For simpler cases, use the inline script: * ```typescript * const worker = new Worker(getWorkerScript(), { type: 'module' }); * ``` */ export declare function createWorker(): Worker; /** * Derive keys in a Web Worker. * * @param worker - Worker instance from createWorker() * @param config - Derivation configuration * @param onProgress - Optional progress callback * @returns Promise resolving to derivation result */ export declare function deriveInWorker(worker: Worker, config: WorkerDerivationConfig, onProgress?: (current: number, total: number) => void): Promise; /** * React hook for key derivation (if using React). * * Example: * ```tsx * function DeriveComponent() { * const { derive, progress, result, error, isLoading } = useBrainVault(); * * const handleDerive = async () => { * await derive({ * identity: 'user@example.com', * password: new TextEncoder().encode('my-password'), * profile: 'standard', * generation: 0, * factor: 3, * outputMode: 'pq', * }); * }; * * return ( *
* * {result &&
{JSON.stringify(result, null, 2)}
} * {error &&
{error.message}
} *
* ); * } * ``` */ export interface UseBrainVaultResult { derive: (config: WorkerDerivationConfig) => Promise; progress: number; result: SerializedDerivationResult | null; error: Error | null; isLoading: boolean; } //# sourceMappingURL=index.d.ts.map