(input: {
password: Uint8Array;
salt?: Uint8Array;
})
| 15 | import { pack, unpack } from 'msgpackr'; |
| 16 | |
| 17 | export 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 | |
| 43 | export type PasswordValues = ReturnType<typeof derivePasswordValues>; |
| 44 |
no test coverage detected