]> git.codecow.com Git - libnemo.git/commitdiff
Type check entropy and checksum concatenation. Ensure mnemonic phrase is lowercase...
authorChris Duncan <chris@zoso.dev>
Mon, 4 Aug 2025 13:57:32 +0000 (06:57 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 4 Aug 2025 13:57:32 +0000 (06:57 -0700)
src/lib/bip39-mnemonic.ts

index 1305a39dffefd9a666850d2922dd19029f5f77fe..d3fc40904d29d4e4f58e4f16842b6217c25ced53 100644 (file)
@@ -48,7 +48,7 @@ export class Bip39Mnemonic {
                        e = e << 8n | BigInt(entropy[i])\r
                }\r
 \r
-               let concatenation = (e << BigInt(entropy.byteLength) / 4n) | checksum\r
+               let concatenation: bigint = (e << BigInt(entropy.byteLength) / 4n) | checksum\r
                const words: string[] = []\r
                for (let i = 0; i < phraseLength; i++) {\r
                        const wordBits = concatenation & 2047n\r
@@ -74,7 +74,7 @@ export class Bip39Mnemonic {
                const self = new this()\r
                const isValid = await this.validate(phrase)\r
                if (isValid) {\r
-                       self.#phrase = phrase.normalize('NFKD').split(' ')\r
+                       self.#phrase = phrase.normalize('NFKD').toLowerCase().split(' ')\r
                        return self\r
                } else {\r
                        throw new Error('Invalid mnemonic phrase.')\r