Entropies¶
- class hdwallet.entropies.ENTROPIES¶
A class that manages a dictionary of entropy classes.
This class provides methods to retrieve names and classes of various entropy implementations, as well as methods to validate and access specific entropy classes by name.
Here are available entropy names and classes:
Name
Class
Algorand
BIP39
Electrum-V1
Electrum-V2
Monero
- classmethod names() List[str]¶
Get the list of entropy class names.
- Returns:
A list of entropy class names.
- Return type:
List[str]
- classmethod classes() List[Type[IEntropy]]¶
Get the list of entropy classes.
- Returns:
A list of entropy classes.
- Return type:
List[Type[IEntropy]]
- classmethod entropy(name: str) Type[IEntropy]¶
Retrieve an entropy class by its name.
- Parameters:
name (str) – The name of the entropy class.
- Returns:
The entropy class corresponding to the given name.
- Return type:
Type[IEntropy]
- classmethod is_entropy(name: str) bool¶
Check if a given name is a valid entropy name.
- Parameters:
name (str) – The name to check.
- Returns:
True if the name is valid, False otherwise.
- Return type:
bool
>>> from hdwallet.entropies import ENTROPIES
>>> ENTROPIES.names()
['Algorand', 'BIP39', 'Electrum-V1', 'Electrum-V2', 'Monero']
>>> ENTROPIES.classes()
[<class 'hdwallet.entropies.algorand.AlgorandEntropy'>, <class 'hdwallet.entropies.bip39.BIP39Entropy'>, <class 'hdwallet.entropies.electrum.v1.ElectrumV1Entropy'>, <class 'hdwallet.entropies.electrum.v2.ElectrumV2Entropy'>, <class 'hdwallet.entropies.monero.MoneroEntropy'>]
>>> from hdwallet.entropies import BIP39Entropy
>>> ENTROPIES.entropy(name="BIP39")
<class 'hdwallet.entropies.bip39.BIP39Entropy'>
>>> ENTROPIES.entropy(name="BIP39") == BIP39Entropy
True
>>> ENTROPIES.is_entropy(name="Electrum-V2")
True
- class hdwallet.entropies.ientropy.IEntropy(entropy: bytes | str)¶
- classmethod name() str¶
Get the name of the entropy class.
- Returns:
The name of the entropy class.
- Return type:
str
- entropy() str¶
Get entropy hex string.
- Returns:
The entropy value.
- Return type:
str
- strength() int¶
- Returns:
The strength of the entropy in bits.
- Return type:
int
- classmethod generate(strength: int) str¶
Generates a new entropy hex string with the given strength.
- Parameters:
strength (int) – The entropy value.
- Returns:
The generated entropy hex string.
- Return type:
str
- classmethod is_valid(entropy: str) bool¶
Checks if the given entropy is valid.
- Parameters:
entropy (str) – Hex string representing entropy
- Returns:
True if is valid, False otherwise.
- Return type:
bool
- classmethod is_valid_strength(strength: int) bool¶
Checks if the given strength is valid.
- Parameters:
strength (int) – The strength to check.
- Returns:
True if the strength is valid, False otherwise.
- Return type:
bool
- classmethod is_valid_bytes_strength(bytes_strength: int) bool¶
Checks if the given byte strength is valid.
- Parameters:
bytes_strength (int) – The byte strength to check.
- Returns:
True if the strength is valid, False otherwise.
- Return type:
bool
- are_entropy_bits_enough(entropy: bytes | int) bool¶
Checks if the entropy bits are enough.
- Parameters:
entropy (Union[bytes, int]) – The entropy value.
- Returns:
True if the strength is valid, False otherwise.
- Return type:
bool
- class hdwallet.entropies.algorand.AlgorandEntropy(entropy: bytes | str)¶
Uses entropy to generate a mnemonic phrase specific to Algorand, ensuring secure account creation with a unique checksum for address verification.
Note
This class inherits from the
IEntropyclass, thereby ensuring that all functions are accessible.Here are available
ALGORAND_ENTROPY_STRENGTHS:Name
Value
TWO_HUNDRED_FIFTY_SIX
256
- classmethod name() str¶
Get the name of the entropy class.
- Returns:
The name of the entropy class.
- Return type:
str
>>> from hdwallet.entropies.algorand import AlgorandEntropy, ALGORAND_ENTROPY_STRENGTHS
>>> entropy: str = AlgorandEntropy.generate(
... strength=ALGORAND_ENTROPY_STRENGTHS.TWO_HUNDRED_FIFTY_SIX
... )
>>> entropy
'5e4d59d4c056b9f0dc9871e8f30194a6b67de1742df9a3f23dc4b9ee8f73b51e'
>>> algorand_entropy: AlgorandEntropy = AlgorandEntropy(entropy=entropy)
>>> algorand_entropy.name()
'Algorand'
>>> algorand_entropy.entropy()
'5e4d59d4c056b9f0dc9871e8f30194a6b67de1742df9a3f23dc4b9ee8f73b51e'
>>> algorand_entropy.strength()
256
- class hdwallet.entropies.bip39.BIP39Entropy(entropy: bytes | str)¶
Converts entropy into a mnemonic phrase (12, 15, 18, 21, or 24 words). This phrase is used to derive a seed, which creates deterministic keys for various cryptocurrencies.
Note
This class inherits from the
IEntropyclass, thereby ensuring that all functions are accessible.Here are available
BIP39_ENTROPY_STRENGTHS:Name
Value
ONE_HUNDRED_TWENTY_EIGHT
128
ONE_HUNDRED_SIXTY
160
ONE_HUNDRED_NINETY_TWO
192
TWO_HUNDRED_TWENTY_FOUR
224
TWO_HUNDRED_FIFTY_SIX
256
- classmethod name() str¶
Get the name of the entropy class.
- Returns:
The name of the entropy class.
- Return type:
str
>>> from hdwallet.entropies.bip39 import BIP39Entropy, BIP39_ENTROPY_STRENGTHS
>>> entropy: str = BIP39Entropy.generate(
strength=BIP39_ENTROPY_STRENGTHS.ONE_HUNDRED_TWENTY_EIGHT
)
>>> entropy
"89f89c8d5445f37dde5d70212bf3f6b4"
>>> bip39_entropy: BIP39Entropy = BIP39Entropy(entropy=entropy)
>>> bip39_entropy.name()
"BIP39"
>>> bip39_entropy.entropy()
"89f89c8d5445f37dde5d70212bf3f6b4"
>>> bip39_entropy.strength()
128
- class hdwallet.entropies.electrum.v1.ElectrumV1Entropy(entropy: bytes | str)¶
Relied on user input and simple entropy to generate a seed. It did not use a standardized mnemonic, leading to less secure key generation.
Note
This class inherits from the
IEntropyclass, thereby ensuring that all functions are accessible.Here are available
ELECTRUM_V1_ENTROPY_STRENGTHS:Name
Value
ONE_HUNDRED_TWENTY_EIGHT
128
- classmethod name() str¶
Get the name of the entropy class.
- Returns:
The name of the entropy class.
- Return type:
str
>>> from hdwallet.entropies.electrum.v1 import ElectrumV1Entropy, ELECTRUM_V1_ENTROPY_STRENGTHS
>>> entropy: str = ElectrumV1Entropy.generate(
... strength=ELECTRUM_V1_ENTROPY_STRENGTHS.ONE_HUNDRED_TWENTY_EIGHT
... )
>>> entropy
'9b96654fbbd35cb4d4e7c6c118cf6a5e'
>>> ev1_entropy: ElectrumV1Entropy = ElectrumV1Entropy(entropy=entropy)
>>> ev1_entropy.name()
'Electrum-V1'
>>> ev1_entropy.entropy()
'9b96654fbbd35cb4d4e7c6c118cf6a5e'
>>> ev1_entropy.strength()
128
- class hdwallet.entropies.electrum.v2.ElectrumV2Entropy(entropy: bytes | str)¶
Improved security with a BIP32-compatible seed and unique wordlist for mnemonic generation, providing better entropy and hierarchical deterministic key derivation.
Note
This class inherits from the
IEntropyclass, thereby ensuring that all functions are accessible.Here are available
ELECTRUM_V2_ENTROPY_STRENGTHS:Name
Value
ONE_HUNDRED_THIRTY_TWO
132
TWO_HUNDRED_SIXTY_FOUR
264
- classmethod name() str¶
Get the name of the entropy class.
- Returns:
The name of the entropy class.
- Return type:
str
- classmethod generate(strength: int) str¶
Generates a new entropy value with the given strength.
- Parameters:
strength (int) – The entropy value.
- Returns:
The generated entropy value for Electrum-V2.
- Return type:
str
- classmethod is_valid(entropy: str) bool¶
Checks if the given entropy is valid.
- Parameters:
entropy (str) – Hex string representing entropy
- Returns:
True if is valid, False otherwise.
- Return type:
bool
- classmethod is_valid_strength(strength: int) bool¶
Check if the provided strength is valid.
- Parameters:
strength (int) – The entropy strength to validate.
- Returns:
True if the strength is valid, False otherwise.
- Return type:
bool
- classmethod are_entropy_bits_enough(entropy: bytes | int) bool¶
Check if the provided entropy has enough bits.
- Parameters:
entropy (Union[bytes, int]) – The entropy value to check.
- Returns:
True if the strength is valid, False otherwise.
- Return type:
bool
>>> from hdwallet.entropies.electrum.v2 import ElectrumV2Entropy, ELECTRUM_V2_ENTROPY_STRENGTHS
>>> entropy: str = ElectrumV2Entropy.generate(
... strength=ELECTRUM_V2_ENTROPY_STRENGTHS.TWO_HUNDRED_SIXTY_FOUR
... )
>>> entropy
'997cf5c9ab01f11e0d61a43a8abdb4740903043f7c1befbba1e356212c82fcac4f'
>>> ev2_entropy: ElectrumV2Entropy = ElectrumV2Entropy(entropy=entropy)
>>> ev2_entropy.name()
'Electrum-V2'
>>> ev2_entropy.entropy()
'997cf5c9ab01f11e0d61a43a8abdb4740903043f7c1befbba1e356212c82fcac4f'
>>> ev2_entropy.strength()
264
>>> ElectrumV2Entropy.generate(strength=ELECTRUM_V2_ENTROPY_STRENGTHS.TWO_HUNDRED_SIXTY_FOUR)
'c7902e83f0343317faa44df15df60688d2c5a1ca5c496c3efb77d4650ccc834383'
>>> ElectrumV2Entropy.is_valid_strength(strength=ELECTRUM_V2_ENTROPY_STRENGTHS.TWO_HUNDRED_SIXTY_FOUR)
True
- class hdwallet.entropies.monero.MoneroEntropy(entropy: bytes | str)¶
Uses high entropy to generate a 25-word mnemonic seed, with the last word acting as a checksum. This ensures secure generation of private spend and view keys.
Note
This class inherits from the
IEntropyclass, thereby ensuring that all functions are accessible.Here are available
MONERO_ENTROPY_STRENGTHS:Name
Value
ONE_HUNDRED_TWENTY_EIGHT
128
TWO_HUNDRED_FIFTY_SIX
256
- classmethod name() str¶
Get the name of the entropy class.
- Returns:
The name of the entropy class.
- Return type:
str
>>> from hdwallet.entropies.monero import MoneroEntropy, MONERO_ENTROPY_STRENGTHS
>>> entropy: str = MoneroEntropy.generate(
... strength=MONERO_ENTROPY_STRENGTHS.TWO_HUNDRED_FIFTY_SIX
... )
>>> entropy
'9718cfa416a1c6dfc7126759b88c545130b8fe36f30e0365d9e48f1bf3ca906e'
>>> monero_entropy: MoneroEntropy = MoneroEntropy(entropy=entropy)
>>> monero_entropy.name()
'Monero'
>>> monero_entropy.entropy()
'9718cfa416a1c6dfc7126759b88c545130b8fe36f30e0365d9e48f1bf3ca906e'
>>> monero_entropy.strength()
256