From 7bd14a28873e9d02715ec1bc76d5fd3ba053cbf0 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 4 Aug 2025 06:48:42 -0700 Subject: [PATCH] Validate mnemonic input type and format. --- src/lib/bip39-mnemonic.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/bip39-mnemonic.ts b/src/lib/bip39-mnemonic.ts index 7265c02..1305a39 100644 --- a/src/lib/bip39-mnemonic.ts +++ b/src/lib/bip39-mnemonic.ts @@ -87,7 +87,14 @@ export class Bip39Mnemonic { * @param {string} mnemonic - Mnemonic phrase to validate * @returns {boolean} True if the mnemonic phrase is valid */ - static async validate (mnemonic: string): Promise { + static async validate (mnemonic: string): Promise + static async validate (mnemonic: unknown): Promise { + if (typeof mnemonic !== 'string') { + return false + } + if (!/^(?:[a-z]{3,8} ){11,23}[a-z]{3,8}$/i.test(mnemonic)) { + return false + } const words = mnemonic.normalize('NFKD').split(' ') if (words.length % 3 !== 0) { return false -- 2.47.3