Derivations¶
- class hdwallet.derivations.DERIVATIONS¶
A class that manages a dictionary of derivation classes.
This class provides methods to retrieve names and classes of various derivation implementations, as well as methods to validate and access specific derivation classes by name.
Here are available entropy names and classes:
Name
Class
BIP44
BIP49
BIP84
BIP86
CIP1852
Custom
Electrum
Monero
HDW
- classmethod names() List[str]¶
Get the list of derivation class names.
- Returns:
A list of derivation class names.
- Return type:
List[str]
- classmethod classes() List[Type[IDerivation]]¶
Get the list of derivation classes.
- Returns:
A list of derivation classes.
- Return type:
List[Type[IDerivation]]
- classmethod derivation(name: str) Type[IDerivation]¶
Retrieve an derivation class by its name.
- Parameters:
name (str) – The name of the derivation class.
- Returns:
The derivation class corresponding to the given name.
- Return type:
Type[IDerivation]
- classmethod is_derivation(name: str) bool¶
Check if a given name is a valid derivation name.
- Parameters:
name (str) – The name to check.
- Returns:
True if the name is valid, False otherwise.
- Return type:
bool
>>> from hdwallet.derivations import DERIVATIONS
>>> DERIVATIONS.names()
['BIP44', 'BIP49', 'BIP84', 'BIP86', 'CIP1852', 'Custom', 'Electrum', 'Monero']
>>> DERIVATIONS.classes()
[<class 'hdwallet.derivations.bip44.BIP44Derivation'>, <class 'hdwallet.derivations.bip49.BIP49Derivation'>, <class 'hdwallet.derivations.bip84.BIP84Derivation'>, <class 'hdwallet.derivations.bip86.BIP86Derivation'>, <class 'hdwallet.derivations.cip1852.CIP1852Derivation'>, <class 'hdwallet.derivations.custom.CustomDerivation'>, <class 'hdwallet.derivations.electrum.ElectrumDerivation'>, <class 'hdwallet.derivations.monero.MoneroDerivation'>]
>>> DERIVATIONS.derivation(name="BIP44")
<class 'hdwallet.derivations.bip44.BIP44Derivation'>
>>> DERIVATIONS.is_derivation(name="BIP44")
True
- class hdwallet.derivations.iderivation.IDerivation(path: str | None = None, indexes: List[int] | None = None, **kwargs)¶
- classmethod name() str¶
Get the name of the derivation class.
- Returns:
The name of the derivation class.
- Return type:
str
- clean() IDerivation¶
Reset the object’s attributes to their initial states or defaults.
- Returns:
The updated IDerivation object itself after cleaning.
- Return type:
- path() str¶
Retrieves the path associated with the current instance.
- Returns:
The derivation as a string.
- Return type:
str
- indexes() List[int]¶
Retrieve the list of indexes in the derivation path.
- Returns:
A list of integer indexes used in the derivation path.
- Return type:
List[int]
- derivations() List[Tuple[int, bool]]¶
Retrieve the list of derivations in the derivation path.
- Returns:
A list of tuples where each tuple contains an index and a boolean indicating whether the index is hardened.
- Return type:
List[Tuple[int, bool]]
- depth() int¶
Retrieve the depth of the derivation path.
- Returns:
The number of derivation levels in the path.
- Return type:
int
- purpose() int¶
Retrieve the purpose value from the object’s _purpose attribute.
This method returns the first element of the _purpose attribute, which is assumed to be a list or similar iterable containing integers.
- Returns:
The purpose value stored as the first element of _purpose.
- Return type:
int
- coin_type() int¶
Retrieve the coin type value from the object’s _coin_type attribute.
This method returns the value of the _coin_type attribute, which is expected to be an integer representing the type of coin.
- Returns:
The coin type value stored in _coin_type.
- Return type:
int
- account() int¶
Retrieve the account value from the object’s _account attribute.
This method returns the value of the _account attribute, which is expected to be an integer representing the account identifier.
- Returns:
The account value stored in _account.
- Return type:
int
- change() int | str¶
Retrieve the change value from the object’s _change attribute.
This method returns the value of the _change attribute, which can be an integer or a string, representing the change status or type.
- Returns:
The change value stored in _change.
- Return type:
Union[int, str]
- role() str¶
Retrieve the role value from the object’s _role attribute.
This method returns the value of the _role attribute, which is expected to be a string representing the role of the object.
- Returns:
The role value stored in _role.
- Return type:
str
- address() int¶
Retrieve the address value from the object’s _address attribute.
This method returns the value of the _address attribute, which is expected to be an integer representing the address.
- Returns:
The address value stored in _address.
- Return type:
int
- minor() int¶
Retrieve the minor version value from the object’s _minor attribute.
This method returns the value of the _minor attribute, which is expected to be an integer representing the minor version number.
- Returns:
The minor version value stored in _minor.
- Return type:
int
- major() int¶
Retrieve the major version value from the object’s _major attribute.
This method returns the value of the _major attribute, which is expected to be an integer representing the major version number.
- Returns:
The major version value stored in _major.
- Return type:
int
- class hdwallet.derivations.bip44.BIP44Derivation(coin_type: str | int = 0, account: str | int | Tuple[int, int] = 0, change: str | int = 'external-chain', address: str | int | Tuple[int, int] = 0)¶
This class implements the BIP44 standard for hierarchical deterministic wallets. BIP44 defines a specific path structure for deriving keys from a master seed.
Note
This class inherits from the
IDerivationclass, thereby ensuring that all functions are accessible.Name
Value
EXTERNAL_CHAIN
external-chain
INTERNAL_CHAIN
internal-chain
- classmethod name() str¶
Get the name of the derivation class.
- Returns:
The name of the derivation class.
- Return type:
str
- from_coin_type(coin_type: str | int) BIP44Derivation¶
Set the object’s _coin_type attribute to the specified coin type index or tuple, updating _path, _indexes, and _derivations accordingly.
- Parameters:
coin_type (Union[str, int]) – The coin type index or tuple to set. Can be a string or integer.
- Returns:
The updated BIP44Derivation object itself after setting the coin type.
- Return type:
- from_account(account: str | int | Tuple[int, int]) BIP44Derivation¶
Set the object’s _account attribute to the specified account index or tuple, updating _path, _indexes, and _derivations accordingly.
- Parameters:
account (Union[str, int, Tuple[int, int]]) – The account index or tuple to set. Can be a string, integer, or tuple of two integers.
- Returns:
The updated BIP44Derivation object itself after setting the account.
- Return type:
- from_change(change: str | int) BIP44Derivation¶
Set the object’s _change attribute to the specified change index or key, updating _path, _indexes, and _derivations accordingly.
- Parameters:
change (Union[str, int]) – The change index or key to set. Can be a string, integer, or one of the predefined keys.
- Returns:
The updated BIP44Derivation object itself after setting the change.
- Return type:
- from_address(address: str | int | Tuple[int, int]) BIP44Derivation¶
Set the object’s _address attribute to the specified address index or tuple of indexes, updating _path, _indexes, and _derivations accordingly.
- Parameters:
address (Union[str, int, Tuple[int, int]]) – The address index or tuple of indexes to set. Should be non-hardened.
- Returns:
The updated BIP44Derivation object itself after setting the address.
- Return type:
- clean() BIP44Derivation¶
Reset the object’s attributes related to BIP-44 derivation to their initial states or defaults.
- Returns:
The updated BIP44Derivation object itself after cleaning.
- Return type:
- purpose() int¶
Retrieve the purpose value from the object’s _purpose attribute.
Returns the first element of _purpose.
- Returns:
The purpose value stored in _purpose.
- Return type:
int
- coin_type() int¶
Retrieve the coin type value from the object’s _coin_type attribute.
Returns the first element of _coin_type.
- Returns:
The coin type value stored in _coin_type.
- Return type:
int
- account() int¶
Retrieve the account from the object.
- Returns:
The account value.
- Return type:
int
- change(name_only: bool = True) str¶
Get the change value.
- Parameters:
name_only (bool) – Return the change name if True, or its index if False.
- Returns:
Change name or index.
- Return type:
str
- address() int¶
Retrieve the address from the object.
- Returns:
The address value.
- Return type:
int
>>> from hdwallet.derivations.bip44 import BIP44Derivation, CHANGES
>>> BIP44Derivation.name()
'BIP44'
>>> bip44_derivation: BIP44Derivation = BIP44Derivation()
>>> bip44_derivation.path()
"m/44'/0'/0'/0/0"
>>> bip44_derivation.from_coin_type(coin_type=11)
<hdwallet.derivations.bip44.BIP44Derivation object at 0x000001EF69834D00>
>>> bip44_derivation.from_account(account=1)
<hdwallet.derivations.bip44.BIP44Derivation object at 0x000001EF69834D00>
>>> bip44_derivation.from_change(change="external-chain")
<hdwallet.derivations.bip44.BIP44Derivation object at 0x000001EF69834D00>
>>> bip44_derivation.from_address(address=10)
<hdwallet.derivations.bip44.BIP44Derivation object at 0x000001EF69834D00>
>>> bip44_derivation.from_coin_type(coin_type=11)
<hdwallet.derivations.bip44.BIP44Derivation object at 0x000001EF69834D00>
>>> bip44_derivation.path()
"m/44'/11'/1'/0/10"
>>> bip44_derivation.indexes()
[2147483692, 2147483659, 2147483649, 0, 10]
>>> bip44_derivation: BIP44Derivation = BIP44Derivation(coin_type=11, account=1, change=CHANGES.EXTERNAL_CHAIN, address=10)
>>> bip44_derivation.purpose()
44
>>> bip44_derivation.coin_type()
11
>>> bip44_derivation.account()
1
>>> bip44_derivation.change()
'external-chain'
>>> bip44_derivation.address()
10
- class hdwallet.derivations.bip49.BIP49Derivation(coin_type: str | int = 0, account: str | int | Tuple[int, int] = 0, change: str | int = 'external-chain', address: str | int | Tuple[int, int] = 0)¶
This class implements the BIP49 standard for hierarchical deterministic wallets. BIP49 defines a specific path structure for deriving keys from a master seed.
Note
This class inherits from the
BIP44Derivationclass, thereby ensuring that all functions are accessible.- classmethod name() str¶
Get the name of the derivation class.
- Returns:
The name of the derivation class.
- Return type:
str
>>> from hdwallet.derivations import CHANGES
>>> from hdwallet.derivations.bip49 import BIP49Derivation
>>> BIP49Derivation.name()
'BIP49'
>>> bip49_derivation: BIP49Derivation = BIP49Derivation()
>>> bip49_derivation.path()
"m/49'/0'/0'/0/0"
>>> bip49_derivation.from_coin_type(coin_type=11)
<hdwallet.derivations.bip49.BIP49Derivation object at 0x000001A0CC9F75B0>
>>> bip49_derivation.from_account(account=1)
<hdwallet.derivations.bip49.BIP49Derivation object at 0x000001A0CC9F75B0>
>>> bip49_derivation.from_change(change="external-chain")
<hdwallet.derivations.bip49.BIP49Derivation object at 0x000001A0CC9F75B0>
>>> bip49_derivation.from_address(address=10)
<hdwallet.derivations.bip49.BIP49Derivation object at 0x000001A0CC9F75B0>
>>> bip49_derivation.from_coin_type(coin_type=11)
<hdwallet.derivations.bip49.BIP49Derivation object at 0x000001A0CC9F75B0>
>>> bip49_derivation.path()
"m/49'/11'/1'/0/10"
>>> bip49_derivation.indexes()
[2147483697, 2147483659, 2147483649, 0, 10]
>>> bip49_derivation: BIP49Derivation = BIP49Derivation(coin_type=11, account=1, change=CHANGES.EXTERNAL_CHAIN, address=10)
>>> bip49_derivation.purpose()
49
>>> bip49_derivation.coin_type()
11
>>> bip49_derivation.account()
1
>>> bip49_derivation.change()
'external-chain'
>>> bip49_derivation.address()
10
- class hdwallet.derivations.bip84.BIP84Derivation(coin_type: str | int = 0, account: str | int | Tuple[int, int] = 0, change: str | int = 'external-chain', address: str | int | Tuple[int, int] = 0)¶
This class implements the BIP84 standard for hierarchical deterministic wallets. BIP84 defines a specific path structure for deriving keys from a master seed.
Note
This class inherits from the
BIP44Derivationclass, thereby ensuring that all functions are accessible.- classmethod name() str¶
Get the name of the derivation class.
- Returns:
The name of the derivation class.
- Return type:
str
>>> from hdwallet.derivations import CHANGES
>>> from hdwallet.derivations.bip84 import BIP84Derivation
>>> BIP84Derivation.name()
'BIP84'
>>> bip84_derivation: BIP84Derivation = BIP84Derivation()
>>> bip84_derivation.path()
"m/84'/0'/0'/0/0"
>>> bip84_derivation.from_coin_type(coin_type=11)
<hdwallet.derivations.bip84.BIP84Derivation object at 0x000001E9949B75B0>
>>> bip84_derivation.from_account(account=1)
<hdwallet.derivations.bip84.BIP84Derivation object at 0x000001E9949B75B0>
>>> bip84_derivation.from_change(change="external-chain")
<hdwallet.derivations.bip84.BIP84Derivation object at 0x000001E9949B75B0>
>>> bip84_derivation.from_address(address=10)
<hdwallet.derivations.bip84.BIP84Derivation object at 0x000001E9949B75B0>
>>> bip84_derivation.from_coin_type(coin_type=11)
<hdwallet.derivations.bip84.BIP84Derivation object at 0x000001E9949B75B0>
>>> bip84_derivation.path()
"m/84'/11'/1'/0/10"
>>> bip84_derivation.indexes()
[2147483732, 2147483659, 2147483649, 0, 10]
>>> bip84_derivation: BIP84Derivation = BIP84Derivation(coin_type=11, account=1, change=CHANGES.EXTERNAL_CHAIN, address=10)
>>> bip84_derivation.purpose()
84
>>> bip84_derivation.coin_type()
11
>>> bip84_derivation.account()
1
>>> bip84_derivation.change()
'external-chain'
>>> bip84_derivation.address()
10
- class hdwallet.derivations.bip86.BIP86Derivation(coin_type: str | int = 0, account: str | int | Tuple[int, int] = 0, change: str | int = 'external-chain', address: str | int | Tuple[int, int] = 0)¶
This class implements the BIP86 standard for hierarchical deterministic wallets. BIP86 defines a specific path structure for deriving keys from a master seed.
Note
This class inherits from the
BIP44Derivationclass, thereby ensuring that all functions are accessible.- classmethod name() str¶
Get the name of the derivation class.
- Returns:
The name of the derivation class.
- Return type:
str
>>> from hdwallet.derivations import CHANGES
>>> from hdwallet.derivations.bip86 import BIP86Derivation
>>> BIP86Derivation.name()
'BIP86'
>>> bip86_derivation: BIP86Derivation = BIP86Derivation()
>>> bip86_derivation.path()
"m/86'/0'/0'/0/0"
>>> bip86_derivation.from_coin_type(coin_type=11)
<hdwallet.derivations.bip86.BIP86Derivation object at 0x000001E9949B6920>
>>> bip86_derivation.from_account(account=1)
<hdwallet.derivations.bip86.BIP86Derivation object at 0x000001E9949B6920>
>>> bip86_derivation.from_change(change="external-chain")
<hdwallet.derivations.bip86.BIP86Derivation object at 0x000001E9949B6920>
>>> bip86_derivation.from_address(address=10)
<hdwallet.derivations.bip86.BIP86Derivation object at 0x000001E9949B6920>
>>> bip86_derivation.from_coin_type(coin_type=11)
<hdwallet.derivations.bip86.BIP86Derivation object at 0x000001E9949B6920>
>>> bip86_derivation.path()
"m/86'/11'/1'/0/10"
>>> bip86_derivation.indexes()
[2147483734, 2147483659, 2147483649, 0, 10]
>>> bip86_derivation: BIP86Derivation = BIP86Derivation(coin_type=11, account=1, change=CHANGES.EXTERNAL_CHAIN, address=10)
>>> bip86_derivation.purpose()
86
>>> bip86_derivation.coin_type()
11
>>> bip86_derivation.account()
1
>>> bip86_derivation.change()
'external-chain'
>>> bip86_derivation.address()
10
- class hdwallet.derivations.cip1852.CIP1852Derivation(coin_type: str | int = 1815, account: str | int | Tuple[int, int] = 0, role: str | int = 'external-chain', address: str | int | Tuple[int, int] = 0)¶
This class implements the CIP1852 standard for hierarchical deterministic wallets. CIP1852 defines a specific path structure for deriving keys from a master seed.
Note
This class inherits from the
IDerivationclass, thereby ensuring that all functions are accessible.Name
Value
EXTERNAL_CHAIN
external-chain
INTERNAL_CHAIN
internal-chain
STAKING_KEY
staking-key
- classmethod name() str¶
Get the name of the derivation class.
- Returns:
The name of the derivation class.
- Return type:
str
- from_coin_type(coin_type: str | int) CIP1852Derivation¶
Sets the derivation path based on the provided coin type index.
- Parameters:
coin_type (Union[str, int]) – The index for the coin type derivation.
- Returns:
The updated instance with the new derivation path based on the coin type index.
- Return type:
- from_account(account: str | int | Tuple[int, int]) CIP1852Derivation¶
Sets the derivation path based on the provided account index.
- Parameters:
account (Union[str, int, Tuple[int, int]]) – The index for the account derivation.
- Returns:
The updated instance with the new derivation path based on the account index.
- Return type:
- from_role(role: str | int) CIP1852Derivation¶
Sets the derivation path based on the provided role index.
- Parameters:
role (Union[str, int]) – The index for the role derivation.
- Returns:
The updated instance with the new derivation path based on the role index.
- Return type:
- from_address(address: str | int | Tuple[int, int]) CIP1852Derivation¶
Sets the derivation path based on the provided address index.
- Parameters:
address (Union[str, int, Tuple[int, int]]) – The index or tuple of indices for the address derivation.
- Returns:
The updated instance with the new derivation path based on the address index.
- Return type:
- clean() CIP1852Derivation¶
Resets the derivation state to default values for a clean derivation path.
- Returns:
The updated instance with a clean derivation path.
- Return type:
- purpose() int¶
Retrieves the purpose value associated with the current instance.
- Returns:
The purpose value as an integer.
- Return type:
int
- coin_type() int¶
Retrieves the coin type associated with the current instance.
- Returns:
The coin type integer.
- Return type:
int
- account() int¶
Retrieves the account associated with the current instance.
- Returns:
The account integer.
- Return type:
int
- role(name_only: bool = True) str¶
Retrieves the role associated with the current instance.
- Parameters:
name_only (bool) – Return the role name if True, or its index if False.
- Returns:
The role string.
- Return type:
str
- address() int¶
Retrieves the address index from the internal _address attribute.
- Returns:
The address index.
- Return type:
int
>>> from hdwallet.derivations.cip1852 import CIP1852Derivation, ROLES
>>> CIP1852Derivation.name()
'CIP1852'
>>> cip1852_derivation: CIP1852Derivation = CIP1852Derivation()
>>> cip1852_derivation.path()
"m/1852'/1815'/0'/0/0"
>>> cip1852_derivation.from_account(account=1)
<hdwallet.derivations.cip1852.CIP1852Derivation object at 0x000002601E4E4D00>
>>> cip1852_derivation.from_role(role="external-chain")
<hdwallet.derivations.cip1852.CIP1852Derivation object at 0x000002601E4E4D00>
>>> cip1852_derivation.from_address(address=10)
<hdwallet.derivations.cip1852.CIP1852Derivation object at 0x000002601E4E4D00>
>>> cip1852_derivation.path()
"m/1852'/1815'/1'/0/10"
>>> cip1852_derivation.indexes()
[2147485500, 2147485463, 2147483649, 0, 10]
>>> cip1852_derivation: CIP1852Derivation = CIP1852Derivation(account=1, role=ROLES.EXTERNAL_CHAIN, address=10)
>>> cip1852_derivation.purpose()
1852
>>> cip1852_derivation.coin_type()
1815
>>> cip1852_derivation.account()
1
>>> cip1852_derivation.role()
'external-chain'
>>> cip1852_derivation.address()
10
- class hdwallet.derivations.custom.CustomDerivation(path: str | None = None, indexes: List[int] | None = None)¶
This class implements the Custom standard for hierarchical deterministic wallets. Custom defines a specific path structure for deriving keys from a master seed.
Note
This class inherits from the
IDerivationclass, thereby ensuring that all functions are accessible.- classmethod name() str¶
Get the name of the derivation class.
- Returns:
The name of the derivation class.
- Return type:
str
- from_path(path: str) CustomDerivation¶
Sets the derivation path and indexes list from a given path string.
- Parameters:
path (str) – The path string to set the derivation path and indexes list. It should be in the format like “m/0’/0”.
- Returns:
The instance of CustomDerivation after setting the derivation path and indexes list.
- Return type:
- from_indexes(indexes: List[int]) CustomDerivation¶
Sets the derivation path and indexes list from a list of indexes.
- Parameters:
indexes (List[int]) – The list of indexes to set the derivation path and indexes list.
- Returns:
The instance of CustomDerivation after setting the derivation path and indexes list.
- Return type:
- from_index(index: int, hardened: bool = False) CustomDerivation¶
Appends an index to the derivation path and indexes list based on whether it’s hardened.
- Parameters:
index (int) – The index to append to the derivation path and indexes list.
hardened (bool) – Indicates if the index is hardened (True) or not (False), defaults to False.
- Returns:
The instance of CustomDerivation after appending the index.
- Return type:
- clean() CustomDerivation¶
Resets the derivation path, indexes, and derivations to their default values.
- Returns:
The instance of CustomDerivation after cleaning.
- Return type:
>>> from hdwallet.derivations.custom import CustomDerivation
>>> CustomDerivation.name()
'Custom'
>>> custom_derivation: CustomDerivation = CustomDerivation("m/84'/0'/1'/0/7")
>>> custom_derivation.path()
"m/84'/0'/1'/0/7"
>>> custom_derivation.indexes()
[2147483732, 2147483648, 2147483649, 0, 7]
- class hdwallet.derivations.electrum.ElectrumDerivation(change: str | int | Tuple[int, int] = 0, address: str | int | Tuple[int, int] = 0)¶
This class implements the Electrum standard for hierarchical deterministic wallets. Electrum defines a specific path structure for deriving keys from a master seed.
Note
This class inherits from the
IDerivationclass, thereby ensuring that all functions are accessible.- classmethod name() str¶
Get the name of the derivation class.
- Returns:
The name of the derivation class.
- Return type:
str
- from_change(change: str | int | Tuple[int, int]) ElectrumDerivation¶
Sets the change index and updates the derivation path accordingly.
- Parameters:
change (Union[str, int, Tuple[int, int]]) – The change index to set. It can be a string, integer, or tuple representing the index.
- Returns:
The instance of ElectrumDerivation with the updated change index.
- Return type:
- from_address(address: str | int | Tuple[int, int]) ElectrumDerivation¶
Sets the address index and updates the derivation path accordingly.
- Parameters:
address (Union[str, int, Tuple[int, int]]) – The address index to set. It can be a string, integer, or tuple representing the index.
- Returns:
The instance of ElectrumDerivation with the updated address index.
- Return type:
- clean() ElectrumDerivation¶
Resets the derivation to the default state with change and address indices set to 0.
- Returns:
The instance of ElectrumDerivation after resetting to default state.
- Return type:
- change() int¶
Retrieves the change index from the internal _change attribute.
- Returns:
The change index.
- Return type:
int
- address() int¶
Retrieves the address index from the internal _address attribute.
- Returns:
The address index.
- Return type:
int
>>> from hdwallet.derivations.electrum import ElectrumDerivation
>>> ElectrumDerivation.name()
'Electrum'
>>> electrum_derivation: ElectrumDerivation = ElectrumDerivation()
>>> electrum_derivation.path()
'm/0/0'
>>> electrum_derivation.from_change(change=0)
<hdwallet.derivations.electrum.ElectrumDerivation object at 0x00000206B9C36E30>
>>> electrum_derivation.from_address(address=10)
<hdwallet.derivations.electrum.ElectrumDerivation object at 0x00000206B9C36E30>
>>> electrum_derivation.path()
'm/0/10'
>>> electrum_derivation.indexes()
[0, 10]
>>> electrum_derivation.change()
0
>>> electrum_derivation.address()
10
- class hdwallet.derivations.monero.MoneroDerivation(minor: str | int | Tuple[int, int] = 1, major: str | int | Tuple[int, int] = 0)¶
This class implements the Monero standard for hierarchical deterministic wallets. Monero defines a specific path structure for deriving keys from a master seed.
Note
This class inherits from the
IDerivationclass, thereby ensuring that all functions are accessible.- classmethod name() str¶
Get the name of the derivation class.
- Returns:
The name of the derivation class.
- Return type:
str
- from_minor(minor: str | int | Tuple[int, int]) MoneroDerivation¶
Sets the minor index for Monero derivation and updates the derivation path accordingly.
This method accepts a minor index, normalizes it, and updates the derivation path to reflect the new minor index value.
- Parameters:
minor (Union[str, int, Tuple[int, int]]) – The minor index to set. Can be a string, integer, or tuple of integers.
- Returns:
The instance of MoneroDerivation with the updated minor index.
- Return type:
- from_major(major: str | int | Tuple[int, int]) MoneroDerivation¶
Sets the major index for Monero derivation and updates the derivation path accordingly.
This method accepts a major index, normalizes it, and updates the derivation path to reflect the new major index value.
- Parameters:
major (Union[str, int, Tuple[int, int]]) – The major index to set. Can be a string, integer, or tuple of integers.
- Returns:
The instance of MoneroDerivation with the updated major index.
- Return type:
- clean() MoneroDerivation¶
Resets the derivation path to default values for Monero derivation.
This method sets the minor index to 1 and the major index to 0, and updates the derivation path accordingly.
- Returns:
The instance of MoneroDerivation with the reset derivation path.
- Return type:
- minor() int¶
Retrieves the minor index from the internal _minor attribute.
- Returns:
The minor index.
- Return type:
int
- major() int¶
Retrieves the major index from the internal _major attribute.
- Returns:
The major index.
- Return type:
int
>>> from hdwallet.derivations.monero import MoneroDerivation
>>> MoneroDerivation.name()
'Monero'
>>> monero_derivation: MoneroDerivation = MoneroDerivation()
>>> monero_derivation.from_major(11)
<hdwallet.derivations.monero.MoneroDerivation object at 0x0000027391CC4D00>
>>> monero_derivation.from_minor(2)
<hdwallet.derivations.monero.MoneroDerivation object at 0x0000027391CC4D00>
>>> monero_derivation: MoneroDerivation = MoneroDerivation(minor=11,major=2)
>>> monero_derivation.path()
'm/11/2'
>>> monero_derivation.indexes()
[11, 2]
>>> monero_derivation.minor()
11
>>> monero_derivation.major()
2
- class hdwallet.derivations.hdw.HDWDerivation(account: str | int | ~typing.Tuple[int, int] = 0, ecc: str | int | ~typing.Type[~hdwallet.eccs.iecc.IEllipticCurveCryptography] | None = <class 'hdwallet.eccs.slip10.secp256k1.SLIP10Secp256k1ECCCoincurve'>, address: str | int | ~typing.Tuple[int, int] = 0)¶
This class implements the HDW standard for hierarchical deterministic wallets. HDW defines a specific path structure for deriving keys from a master seed.
Note
This class inherits from the
IDerivationclass, thereby ensuring that all functions are accessible.- classmethod name() str¶
Get the name of the derivation class.
- Returns:
The name of the derivation class.
- Return type:
str
- from_account(account: str | int | Tuple[int, int]) HDWDerivation¶
Set the object’s _account attribute to the specified account index or tuple, updating _path, _indexes, and _derivations accordingly.
- Parameters:
account (Union[str, int, Tuple[int, int]]) – The account index or tuple to set. Can be a string, integer, or tuple of two integers.
- Returns:
The updated HDWDerivation object itself after setting the account.
- Return type:
- from_ecc(ecc: str | int | Type[IEllipticCurveCryptography]) HDWDerivation¶
Set the object’s _ecc attribute to the specified ecc index or key, updating _path, _indexes, and _derivations accordingly.
- Parameters:
ecc (Union[str, int, Type[IEllipticCurveCryptography]]) – The ecc index or key to set. Can be a string, integer, or one of the predefined keys.
- Returns:
The updated HDWDerivation object itself after setting the ecc.
- Return type:
- from_address(address: str | int | Tuple[int, int]) HDWDerivation¶
Set the object’s _address attribute to the specified address index or tuple of indexes, updating _path, _indexes, and _derivations accordingly.
- Parameters:
address (Union[str, int, Tuple[int, int]]) – The address index or tuple of indexes to set. Should be non-hardened.
- Returns:
The updated HDWDerivation object itself after setting the address.
- Return type:
- clean() HDWDerivation¶
Reset the object’s attributes related to HDW derivation to their initial states or defaults.
- Returns:
The updated HDWDerivation object itself after cleaning.
- Return type:
- account() int¶
Retrieve the account value from the object’s _account attribute.
Checks the length of _account. If it equals 3, returns the second element; otherwise, returns the first element.
- Returns:
The account value stored in _account.
- Return type:
int
- ecc(name_only: bool = True) str¶
Retrieve the ecc value from the object’s eccs dictionary.
Iterates through the eccs dictionary, and if a value matches the first element of _ecc, sets the corresponding key as the ecc value.
- Parameters:
name_only (bool) – Return the ECC name if True, or its index if False.
- Returns:
The key from the eccs dictionary that corresponds to the _ecc value, or None if not found.
- Return type:
str
- address() int¶
Retrieve the address from the object.
- Returns:
The address value.
- Return type:
int
>>> from hdwallet.derivations.hdw import HDWDerivation
>>> HDWDerivation.name()
'HDW'
>>> hdw_derivation: HDWDerivation = HDWDerivation()
>>> hdw_derivation.from_account(11)
<hdwallet.derivations.hdw.HDWDerivation object at 0x000002060AFB2130>
>>> hdw_derivation.from_address(2)
<hdwallet.derivations.hdw.HDWDerivation object at 0x000002060AFB2130>
>>> hdw_derivation: HDWDerivation = HDWDerivation(ecc='SLIP10-Ed25519-Monero')
>>> hdw_derivation.path()
"m/0'/5/0"
>>> hdw_derivation.indexes()
[2147483648, 5, 0]
>>> hdw_derivation.account()
0
>>> hdw_derivation.ecc()
'SLIP10-Ed25519-Monero'
>>> hdw_derivation.address()
0