Skip to content

Commit

Permalink
Add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Sep 13, 2024
1 parent d82ccc7 commit c542099
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/crypto-api/key-passphrase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uint8Array> {
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");
Expand All @@ -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<IKey> {
const salt = randomString(32);

Expand All @@ -55,6 +64,13 @@ export async function keyFromPassphrase(password: string): Promise<IKey> {
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,
Expand Down

0 comments on commit c542099

Please sign in to comment.