MCPcopy Create free account
hub / github.com/DeepNotesApp/DeepNotes / derivePasswordValues

Function derivePasswordValues

apps/app-server/src/utils/crypto.ts:17–41  ·  view source on GitHub ↗
(input: {
  password: Uint8Array;
  salt?: Uint8Array;
})

Source from the content-addressed store, hash-verified

15import { pack, unpack } from 'msgpackr';
16
17export function derivePasswordValues(input: {
18 password: Uint8Array;
19 salt?: Uint8Array;
20}) {
21 mainLogger.info('Started hashing password');
22
23 input.salt ??= sodium.randombytes_buf(sodium.crypto_pwhash_SALTBYTES);
24
25 const derivedKey = sodium.crypto_pwhash(
26 32 + 64,
27 input.password,
28 input.salt,
29 2,
30 32 * 1048576,
31 sodium.crypto_pwhash_ALG_ARGON2ID13,
32 );
33
34 mainLogger.info('Finished hashing password');
35
36 return {
37 key: wrapSymmetricKey(derivedKey.slice(0, 32)),
38 hash: derivedKey.slice(32),
39 salt: input.salt,
40 };
41}
42
43export type PasswordValues = ReturnType<typeof derivePasswordValues>;
44

Callers 9

rotateKeysStep1Function · 0.90
rotateKeysStep2Function · 0.90
changePasswordStep1Function · 0.90
changePasswordStep2Function · 0.90
changeEmailStep1Function · 0.90
changeEmailStep2Function · 0.90
registerFunction · 0.90
loginFunction · 0.90

Calls 1

wrapSymmetricKeyFunction · 0.90

Tested by

no test coverage detected