Bip39

cometa.bip39.entropy_to_mnemonic(entropy)[source]

Converts entropy into a BIP-39 mnemonic word sequence.

Takes entropy bytes and converts them into a corresponding BIP-39 mnemonic phrase using the English wordlist.

Parameters:

entropy (bytes | bytearray) – The entropy bytes. Supported sizes are: - 16 bytes (128 bits) -> 12 words - 20 bytes (160 bits) -> 15 words - 24 bytes (192 bits) -> 18 words - 28 bytes (224 bits) -> 21 words - 32 bytes (256 bits) -> 24 words

Returns:

List of mnemonic words from the English BIP-39 wordlist.

Raises:

CardanoError – If the entropy size is invalid.

Return type:

List[str]

Example

>>> entropy = bytes(16)
>>> words = entropy_to_mnemonic(entropy)
>>> len(words)
12

cometa.bip39.mnemonic_to_entropy(words)[source]

Converts a BIP-39 mnemonic word sequence back into entropy.

Takes a mnemonic phrase and converts it back into the original entropy bytes. The words must be valid English BIP-39 words with a correct checksum.

Parameters:

words (List[str]) – List of BIP-39 English mnemonic words. Supported lengths are: - 12 words -> 16 bytes (128-bit entropy) - 15 words -> 20 bytes (160-bit entropy) - 18 words -> 24 bytes (192-bit entropy) - 21 words -> 28 bytes (224-bit entropy) - 24 words -> 32 bytes (256-bit entropy)

Returns:

The entropy bytes corresponding to the mnemonic.

Raises:

CardanoError – If the word count is invalid, words are not in the wordlist, or the checksum is incorrect.

Return type:

bytes

Example

>>> words = ["abandon"] * 11 + ["about"]
>>> entropy = mnemonic_to_entropy(words)
>>> len(entropy)
16