From c96a2e4089ea5084901febbe86b185f5d4fe9ac4 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 4 Aug 2025 06:57:32 -0700 Subject: [PATCH] Type check entropy and checksum concatenation. Ensure mnemonic phrase is lowercase when imported. --- src/lib/bip39-mnemonic.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/bip39-mnemonic.ts b/src/lib/bip39-mnemonic.ts index 1305a39..d3fc409 100644 --- a/src/lib/bip39-mnemonic.ts +++ b/src/lib/bip39-mnemonic.ts @@ -48,7 +48,7 @@ export class Bip39Mnemonic { e = e << 8n | BigInt(entropy[i]) } - let concatenation = (e << BigInt(entropy.byteLength) / 4n) | checksum + let concatenation: bigint = (e << BigInt(entropy.byteLength) / 4n) | checksum const words: string[] = [] for (let i = 0; i < phraseLength; i++) { const wordBits = concatenation & 2047n @@ -74,7 +74,7 @@ export class Bip39Mnemonic { const self = new this() const isValid = await this.validate(phrase) if (isValid) { - self.#phrase = phrase.normalize('NFKD').split(' ') + self.#phrase = phrase.normalize('NFKD').toLowerCase().split(' ') return self } else { throw new Error('Invalid mnemonic phrase.') -- 2.47.3