From 5cad5a53f3cd2584b0e0a4e64275762bb07a594c Mon Sep 17 00:00:00 2001 From: yougotwill Date: Wed, 7 Aug 2024 11:33:34 +1000 Subject: [PATCH] fix: have a too many words error when decoding a recovery passwrd --- .../registration/stages/RestoreAccount.tsx | 5 ++++- ts/session/crypto/mnemonic.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ts/components/registration/stages/RestoreAccount.tsx b/ts/components/registration/stages/RestoreAccount.tsx index 777efd254..43672277b 100644 --- a/ts/components/registration/stages/RestoreAccount.tsx +++ b/ts/components/registration/stages/RestoreAccount.tsx @@ -183,9 +183,12 @@ export const RestoreAccount = () => { try { const validName = await ProfileManager.updateOurProfileDisplayName(displayName, true); + const trimmedPassword = recoveryPassword.trim(); + setRecoveryPassword(trimmedPassword); + await signInWithNewDisplayName({ displayName: validName, - recoveryPassword, + recoveryPassword: trimmedPassword, dispatch, }); } catch (err) { diff --git a/ts/session/crypto/mnemonic.ts b/ts/session/crypto/mnemonic.ts index d4fd26198..4649a06c9 100644 --- a/ts/session/crypto/mnemonic.ts +++ b/ts/session/crypto/mnemonic.ts @@ -20,6 +20,15 @@ export class NotEnoughWordsError extends MnemonicError { } } +/** NOTE 2024-08-07 (Will) Maximum number of words is 13 */ +export class TooManyWordsError extends MnemonicError { + constructor(message = "You've entered too many words, please try again") { + super(message); + // restore prototype chain + Object.setPrototypeOf(this, TooManyWordsError.prototype); + } +} + export class InvalidWordsError extends MnemonicError { constructor(message = "You've entered too few words, please try again") { super(message); @@ -103,6 +112,10 @@ export function mnDecode(str: string, wordsetName: string = MN_DEFAULT_WORDSET): if (wlist.length < 12) { throw new NotEnoughWordsError(); } + if (wlist.length > 13) { + throw new TooManyWordsError(); + } + if ( (wordset.prefixLen === 0 && wlist.length % 3 !== 0) || (wordset.prefixLen > 0 && wlist.length % 3 === 2)