import { AnnotatedKey, AnnotatedKeyDigestType, PasswordKeyAnnotation } from "./AnnotatedKey"; /** * PBKDF2 derivation parameters */ export interface DerivationParams { digest: AnnotatedKeyDigestType; salt: Uint8Array; rounds: number; fullLength: number; } /** * Generates keys for same passwords and cache generated arrays. One password may require * generation of different keys and maybe with different generation parameters, so we catch it * inside. * * Use [[generateKeys]] to get the keys. Do not instantiate this class manually. */ export declare class PasswordKeyGenerator { private readonly password; private readonly results; private constructor(); private derive; /** * Generate one or more keys from this password. If such a key is already generated or is being generated, * it will be automatically reused. Creates AnnotatedKeys that could be later restored from the password using * parameters saved inside their instances (see [[PasswordKeyAnnotation]]). * * Not that the cryptographically independent ID for annotation is also derived from the password and could be * safely disclosed to distinguish _keys_ but not disclosing info of the _password_ used. * * @param count number of keys to generated * @param salt PBKDF2 salt * @param rounds PBKDF2 rounds * @param idLength size of id that is also derived from the password. * @param digest hash algorithm used in PBKDF2 */ generateKeys(count: number, salt: Uint8Array | string, rounds: number, idLength?: number, digest?: AnnotatedKeyDigestType): Promise; private restoreKey; /** * Caching password keys generator. Generates one or more keys for a given password and generation parameters * reusing matching keys being generated (it is performed in a worker) or already generated. Use [[clear()]] * to drop the cache for security reasons. * @param password * @param count * @param salt * @param rounds * @param idLength * @param digest */ static generateKeys(password: string, count: number, salt: Uint8Array | string, rounds: number, digest?: AnnotatedKeyDigestType, idLength?: number): Promise; static recyclableGenerator(password: string): PasswordKeyGenerator; /** * Forget everything about generated keys. New keys will be re-derived on first request. * It is safe to call clear immediately after [[generateKeys]]. */ static clear(): void; /** * Try to restore the key for a given password and annotation, which contains all necessary derivation * parameters. Note that derivation contains also id, so we can check that derived key is what is expected, * and return undefined if the password does not match. * @param password to derive from * @param annotation * @return promise with derived key if the password is ok otherwise undefined. */ static restoreKey(password: string, annotation: PasswordKeyAnnotation): Promise; }