Parse a mnemonic without checksum check

In some situations, a user can come with mnemonic words himself. In
this case a mnemonic will fail the checksum check.

This pr implements a function to be able to parse a mnemonic without
checksum check
This commit is contained in:
Ayrat Badykov 2023-02-25 12:53:46 +02:00
parent 266b715897
commit 38f81b87d7
No known key found for this signature in database
GPG Key ID: A5F96CDE59FA6215
1 changed files with 22 additions and 0 deletions

View File

@ -434,6 +434,28 @@ impl Mnemonic {
})
}
/// Parse a mnemonic in normalized UTF8 in the given language without checksum check.
pub fn parse_without_checksum_check(language: Language, s: &str) -> Result<Mnemonic, Error> {
let nb_words = s.split_whitespace().count();
if is_invalid_word_count(nb_words) {
return Err(Error::BadWordCount(nb_words));
}
// Here we will store the eventual words.
let mut words = [EOF; MAX_NB_WORDS];
for (i, word) in s.split_whitespace().enumerate() {
let idx = language.find_word(word).ok_or(Error::UnknownWord(i))?;
words[i] = idx;
}
Ok(Mnemonic {
lang: language,
words: words,
})
}
/// Parse a mnemonic in normalized UTF8.
pub fn parse_normalized(s: &str) -> Result<Mnemonic, Error> {
let lang = Mnemonic::language_of(s)?;