mnemonic_utils
Module containing common utility classes for mnemonic.
- class MnemonicUtils
Bases:
object
Class container for mnemonic utility functions.
- static BytesChunkToWords(bytes_chunk: bytes, words_list: MnemonicWordsList, endianness: typing_extensions.Literal[little, big]) List[str]
Get words from a bytes chunk.
- Parameters:
bytes_chunk (bytes) – Bytes chunk
words_list (MnemonicWordsList object) – Mnemonic list
endianness ("big" or "little") – Bytes endianness
- Returns:
3 word indexes
- Return type:
list[str]
- static WordsToBytesChunk(word1: str, word2: str, word3: str, words_list: MnemonicWordsList, endianness: typing_extensions.Literal[little, big]) bytes
Get bytes chunk from words.
- Parameters:
word1 (str) – Word 1
word2 (str) – Word 2
word3 (str) – Word 3
words_list (MnemonicWordsList object) – Mnemonic list
endianness ("big" or "little") – Bytes endianness
- Returns:
Bytes chunk
- Return type:
bytes
- class MnemonicWordsList(words_list: List[str])
Bases:
object
Mnemonic words list class.
- m_idx_to_words: List[str]
- m_words_to_idx: Dict[str, int]
- Length() int
Get the length of the words list.
- Returns:
Words list length
- Return type:
int
- GetWordIdx(word: str) int
Get the index of the specified word.
- Parameters:
word (str) – Word to be searched
- Returns:
Word index
- Return type:
int
- Raises:
ValueError – If the word is not found
- GetWordAtIdx(word_idx: int) str
Get the word at the specified index.
- Parameters:
word_idx (int) – Word index
- Returns:
Word at the specified index
- Return type:
str
- class MnemonicWordsListFileReader
Bases:
object
Mnemonic words list file reader class. It reads the words list from a file.
- static LoadFile(file_path: str, words_num: int) MnemonicWordsList
Load words list file correspondent to the specified language.
- Parameters:
file_path (str) – File name
words_num (int) – Number of expected words
- Returns:
MnemonicWordsList object
- Return type:
- Raises:
ValueError – If loaded words list is not valid
- class MnemonicWordsListGetterBase
Bases:
ABC
Mnemonic words list getter base class.
- m_words_lists: Dict[MnemonicLanguages, MnemonicWordsList]
- abstract GetByLanguage(lang: MnemonicLanguages) MnemonicWordsList
Get words list by language. Words list of a specific language are loaded from file only the first time they are requested.
- Parameters:
lang (MnemonicLanguages) – Language
- Returns:
MnemonicWordsList object
- Return type:
MnemonicWordsList object
- Raises:
TypeError – If the language is not of the correct enumerative
ValueError – If loaded words list is not valid
- classmethod Instance() MnemonicWordsListGetterBase
Get the global class instance.
- Returns:
MnemonicWordsListGetterBase object
- Return type:
MnemonicWordsListGetterBase object
- class MnemonicWordsListFinderBase
Bases:
ABC
Mnemonic words list finder base class. It automatically finds the correct words list from a mnemonic.
- abstract classmethod FindLanguage(mnemonic: Mnemonic) Tuple[MnemonicWordsList, MnemonicLanguages]
Automatically find the language of the specified mnemonic and get the correct MnemonicWordsList class for it.
- Parameters:
mnemonic (Mnemonic object) – Mnemonic object
- Returns:
MnemonicWordsList object (index 0), mnemonic language (index 1)
- Return type:
tuple[MnemonicWordsList, MnemonicLanguages]
- Raises:
ValueError – If the mnemonic language cannot be found