fix: have a too many words error when decoding a recovery passwrd

pull/3138/head
yougotwill 8 months ago
parent 8b5978e347
commit 5cad5a53f3

@ -183,9 +183,12 @@ export const RestoreAccount = () => {
try { try {
const validName = await ProfileManager.updateOurProfileDisplayName(displayName, true); const validName = await ProfileManager.updateOurProfileDisplayName(displayName, true);
const trimmedPassword = recoveryPassword.trim();
setRecoveryPassword(trimmedPassword);
await signInWithNewDisplayName({ await signInWithNewDisplayName({
displayName: validName, displayName: validName,
recoveryPassword, recoveryPassword: trimmedPassword,
dispatch, dispatch,
}); });
} catch (err) { } catch (err) {

@ -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 { export class InvalidWordsError extends MnemonicError {
constructor(message = "You've entered too few words, please try again") { constructor(message = "You've entered too few words, please try again") {
super(message); super(message);
@ -103,6 +112,10 @@ export function mnDecode(str: string, wordsetName: string = MN_DEFAULT_WORDSET):
if (wlist.length < 12) { if (wlist.length < 12) {
throw new NotEnoughWordsError(); throw new NotEnoughWordsError();
} }
if (wlist.length > 13) {
throw new TooManyWordsError();
}
if ( if (
(wordset.prefixLen === 0 && wlist.length % 3 !== 0) || (wordset.prefixLen === 0 && wlist.length % 3 !== 0) ||
(wordset.prefixLen > 0 && wlist.length % 3 === 2) (wordset.prefixLen > 0 && wlist.length % 3 === 2)

Loading…
Cancel
Save