Mnemonic#

This is a class with which you can generate and check mnemonic seed’s

Example#

>>> from defichain import Mnemonic
>>> mnemonic = Mnemonic(language="english")
>>> seed = mnemonic.generate(256)
"shoulder unusual practice sight apart course eager true diesel rescue diagram denial oppose total fun rocket spend chapter spider paddle benefit empower type purse"
>>> Mnemonic.detect_language(seed)
"english"
>>> mnemonic.check(seed)
True
class defichain.mnemonic.Mnemonic(language: str = 'english')#

Creates a mnemonic instance

Parameters:

language (str) – (optional) language of the mnemonic seed: english, chinese_simplified, chinese_traditional, french, italian, japanese, korean, spanish

Returns:

Mnemonic – Mnemonic instance.

Example:

>>> from defichain import Mnemonic
>>> Mnemonic(language="english")
classmethod list_languages() List[str]#

List all languages for mnemonic seed

Returns:

(array) languages

Example:

>>> from defichain import Mnemonic
>>> Mnemonic.list_languages()
['korean', 'japanese', 'chinese_simplified', 'english', 'french', 'italian', 'chinese_traditional', 'spanish']
classmethod detect_language(mnemonic: str) str#

Scan the Mnemonic until the language becomes unambiguous

Parameters:

mnemonic (str) – (required) the mnemonic seed

Returns:

(string) language of the mnemonic seed

Example:

>>> from defichain import Mnemonic
>>> mnemonic = Mnemonic(language="english").generate()
>>> Mnemonic.detect_language(mnemonic)
"english"
generate(strength: int = 256) str#

Create a new mnemonic using a random generated number as entropy.

As defined in BIP39, the entropy must be a multiple of 32 bits, and its size must be between 128 and 256 bits. Therefore the possible values for strength are 128, 160, 192, 224 and 256.

If not provided, the default entropy length will be set to 128 bits.

The return is a list of words that encodes the generated entropy.

Parameters:

strength (int) – (optional) Number of bytes used as entropy

Returns:

(string) A randomly generated mnemonic

Example:

>>> from defichain import Mnemonic
>>> mnemonic = Mnemonic(language="english")
>>> mnemonic.generate()
"shoulder unusual practice sight apart course eager true diesel rescue diagram denial oppose total fun rocket spend chapter spider paddle benefit empower type purse"
check(mnemonic: str) bool#

Checks if the mnemonic seed is valid

Parameters:

mnemonic (str) – (required) mnemonic seed

Returns:

bool

Example:

>>> from defichain import Mnemonic
>>> mn = Mnemonic(language="english")
>>> seed = mn.generate()
>>> mn.check(seed)
True