electrum_v2_mnemonic_generator

Module for Electrum v2 mnemonic generation.

class ElectrumV2MnemonicGeneratorConst

Bases: object

Class container for Electrum v2 mnemonic generator constants.

WORDS_NUM_TO_ENTROPY_LEN: Dict[ElectrumV2WordsNum, ElectrumV2EntropyBitLen] = {ElectrumV2WordsNum.WORDS_NUM_12: ElectrumV2EntropyBitLen.BIT_LEN_132, ElectrumV2WordsNum.WORDS_NUM_24: ElectrumV2EntropyBitLen.BIT_LEN_264}
MAX_ATTEMPTS: int = 1000000
class ElectrumV2MnemonicGenerator(mnemonic_type: ElectrumV2MnemonicTypes, lang: ElectrumV2Languages = ElectrumV2Languages.ENGLISH)

Bases: object

Electrum v2 mnemonic generator class. It generates 12 or 24-words mnemonic in according to Electrum wallets.

m_mnemonic_encoder: ElectrumV2MnemonicEncoder
FromWordsNumber(words_num: Union[int, ElectrumV2WordsNum]) Mnemonic

Generate mnemonic with the specified words number and type from random entropy.

Parameters:

words_num (int or ElectrumV2WordsNum) – Number of words (12)

Returns:

Generated mnemonic

Return type:

Mnemonic object

Raises:

ValueError – If words number is not valid

FromEntropy(entropy_bytes: bytes) Mnemonic

Generate mnemonic from the specified entropy bytes. Because of the mnemonic encoding algorithm used by Electrum, the specified entropy will only be a starting point to find a suitable one. Therefore, it’s very likely that the actual entropy bytes will be different. To get the actual entropy bytes, just decode the generated mnemonic. Please note that, to successfully generate a mnemonic, the bits of the big endian integer encoded entropy shall be at least 121 (for 12 words) or 253 (for 24 words). Otherwise, a mnemonic generation is not possible and a ValueError exception will be raised.

Parameters:

entropy_bytes (bytes) – Entropy bytes

Returns:

Generated mnemonic

Return type:

Mnemonic object

Raises:

ValueError – If entropy byte length is not valid or a mnemonic cannot be generated