From: Chris Duncan Date: Sat, 9 Aug 2025 07:22:55 +0000 (-0700) Subject: Simplify BIP-39 seed gen by deriving bits directly. X-Git-Tag: v0.10.5~41^2~152 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=f118c32383783eb73754fa701697ad3a6ae000f5;p=libnemo.git Simplify BIP-39 seed gen by deriving bits directly. --- diff --git a/src/lib/crypto/bip39.ts b/src/lib/crypto/bip39.ts index f30120b..bd94034 100644 --- a/src/lib/crypto/bip39.ts +++ b/src/lib/crypto/bip39.ts @@ -199,21 +199,14 @@ export class Bip39 { : passphrase const keyData = utf8.toBytes(this.phrase) const phraseKey = await crypto.subtle.importKey('raw', keyData, 'PBKDF2', false, ['deriveBits', 'deriveKey']) - const derivedKeyType: HmacImportParams = { - name: 'HMAC', - hash: 'SHA-512', - length: 512 - } - const algorithm: Pbkdf2Params = { name: 'PBKDF2', hash: 'SHA-512', salt: utf8.toBytes(`mnemonic${salt.normalize('NFKD')}`), iterations: BIP39_ITERATIONS } - const seedKey = await crypto.subtle.deriveKey(algorithm, phraseKey, derivedKeyType, true, ['sign']) - const seedBuffer = await crypto.subtle.exportKey('raw', seedKey) - this.#bip39Seed = new Uint8Array(seedBuffer) + const seed = await crypto.subtle.deriveBits(algorithm, phraseKey, 512) + this.#bip39Seed = new Uint8Array(seed) } return format === 'hex' ? bytes.toHex(this.#bip39Seed)