From f118c32383783eb73754fa701697ad3a6ae000f5 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sat, 9 Aug 2025 00:22:55 -0700 Subject: [PATCH] Simplify BIP-39 seed gen by deriving bits directly. --- src/lib/crypto/bip39.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) 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) -- 2.47.3