[auth] Improve error message for invalid recovery input

This commit is contained in:
Neeraj Gupta
2024-08-17 06:46:53 +05:30
parent 191e32463f
commit eace1150f5

View File

@@ -285,9 +285,20 @@ class Configuration {
Future<void> recover(String recoveryKey) async {
// check if user has entered mnemonic code
if (recoveryKey.contains(' ')) {
if (recoveryKey.split(' ').length != mnemonicKeyWordCount) {
final split = recoveryKey.split(' ');
if (split.length != mnemonicKeyWordCount) {
String wordThatIsFollowedByEmptySpaceInSplit = '';
for (int i = 1; i < split.length; i++) {
String word = split[i];
if (word.isEmpty) {
wordThatIsFollowedByEmptySpaceInSplit =
'\n\nExtra space after word "${split[i - 1]}"';
break;
}
}
throw AssertionError(
'recovery code should have $mnemonicKeyWordCount words',
'\nRecovery code should have $mnemonicKeyWordCount words, '
'found ${split.length} words instead.$wordThatIsFollowedByEmptySpaceInSplit',
);
}
recoveryKey = bip39.mnemonicToEntropy(recoveryKey);