From 9640cfd5ba6eb2e7b35bea9257cf469dee1aa5bd Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Fri, 13 Sep 2024 11:00:38 +0200 Subject: [PATCH] ADd doc --- src/crypto-api/key-passphrase.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/crypto-api/key-passphrase.ts b/src/crypto-api/key-passphrase.ts index e8cae0c385..1650a418a7 100644 --- a/src/crypto-api/key-passphrase.ts +++ b/src/crypto-api/key-passphrase.ts @@ -34,6 +34,11 @@ interface IKey { iterations: number; } +/** + * Derive a key from a passphrase using the salt and iterations from the auth data. + * @param authData + * @param password + */ export function keyFromAuthData(authData: IAuthData, password: string): Promise { if (!authData.private_key_salt || !authData.private_key_iterations) { throw new Error("Salt and/or iterations not found: " + "this backup cannot be restored with a passphrase"); @@ -47,6 +52,10 @@ export function keyFromAuthData(authData: IAuthData, password: string): Promise< ); } +/** + * Derive a key from a passphrase. + * @param password + */ export async function keyFromPassphrase(password: string): Promise { const salt = randomString(32); @@ -55,6 +64,13 @@ export async function keyFromPassphrase(password: string): Promise { return { key, salt, iterations: DEFAULT_ITERATIONS }; } +/** + * Derive a key from a passphrase using PBKDF2. + * @param password + * @param salt + * @param iterations + * @param numBits + */ export async function deriveKey( password: string, salt: string,