@bsv/wallet-toolbox
Version:
BRC100 conforming wallet, wallet storage and wallet signer components
89 lines • 3.04 kB
TypeScript
/**
* EntropyCollector
*
* Collects entropy from user interactions (mouse movements) and mixes it with
* cryptographically secure random numbers to generate high-quality random seeds
* for key generation.
*
* This provides defense-in-depth: even if the system's CSPRNG is compromised,
* the user-provided entropy adds unpredictability. Conversely, if the user's
* mouse movements are predictable, the CSPRNG ensures security.
*/
export interface EntropyCollectorConfig {
/** Target number of mouse samples to collect (default: 256) */
targetSamples?: number;
/** Minimum time between samples in ms (default: 10) */
minSampleInterval?: number;
}
export interface EntropyProgress {
/** Number of samples collected so far */
collected: number;
/** Target number of samples */
target: number;
/** Percentage complete (0-100) */
percent: number;
}
/**
* Callback type for entropy collection progress updates
*/
export type EntropyProgressCallback = (progress: EntropyProgress) => void;
export declare class EntropyCollector {
private config;
private rawEntropy;
private lastSampleTime;
constructor(config?: EntropyCollectorConfig);
/**
* Reset collected entropy data
*/
reset(): void;
/**
* Add a mouse movement sample
* Call this from a mousemove event handler
*
* @returns Progress information, or null if sample was rejected (too soon)
*/
addMouseSample(x: number, y: number): EntropyProgress | null;
/**
* Get current collection progress
*/
getProgress(): EntropyProgress;
/**
* Check if enough entropy has been collected
*/
isComplete(): boolean;
/**
* Extract entropy bytes from collected mouse data
* Uses SHA-256 to compress and whiten the data
*/
private extractRawEntropy;
/**
* Mix user entropy with system CSPRNG for defense-in-depth
*
* @returns 32 bytes of high-quality random data suitable for key generation
*/
mixWithCSPRNG(): Uint8Array;
/**
* Generate entropy with automatic CSPRNG fallback
*
* If not enough user entropy has been collected, supplements with CSPRNG.
* Always mixes with CSPRNG regardless.
*
* @returns 32 bytes suitable for private key generation
*/
generateEntropy(): Uint8Array;
/**
* Convenience method for browser environments.
* Creates event listeners and resolves when enough entropy is collected.
*
* @param element The HTML element to listen on (default: document)
* @param onProgress Optional callback for progress updates
* @returns Promise that resolves with 32 bytes of entropy
*/
collectFromBrowser(element?: EventTarget, onProgress?: EntropyProgressCallback): Promise<Uint8Array>;
/**
* Estimate the quality of collected entropy in bits
* This is a rough heuristic, not a cryptographic guarantee
*/
estimateEntropyBits(): number;
}
//# sourceMappingURL=EntropyCollector.d.ts.map