Derivation

class hdwallet.derivations.Derivation(path: Optional[str] = None, semantic: str = 'p2pkh')

Hierarchical Deterministic Wallet Derivation’s

Parameters
  • path (str) – Derivation path.

  • semantic (str) – Extended semantic, defaults to P2PKH.

Returns

Derivation – Derivation instance.

>>> from hdwallet.derivations import Derivation
>>> Derivation()
<hdwallet.derivations.Derivation object at 0x000001EBC58E9F70>
>>> str(Derivation())
""
>>> str(Derivation(path="m/44'/0'/0'/0/0", semantic="p2pkh"))
"m/44'/0'/0'/0/0"

Note

Do not forget all derivation paths are start swith ‘m/’ prefix.

classmethod from_path(path: str)hdwallet.derivations.Derivation

Derivation from path.

Parameters

path (str, Derivation) – Derivation path.

Returns

Derivation – Derivation instance.

>>> from hdwallet.derivations import Derivation
>>> derivation = Derivation()
>>> derivation.from_path(path="m/44'/0'/'0/0/0")
<hdwallet.derivation.Derivation object at 0x000001E8BFB98D60>
from_index(index: int, hardened: bool = False)hdwallet.derivations.Derivation

Derivation from path.

Parameters
  • index (int) – Derivation index.

  • hardened (bool) – Hardened address, default to False.

Returns

Derivation – Derivation instance.

>>> from hdwallet.derivations import Derivation
>>> derivation = Derivation()
>>> derivation.from_index(index=44, hardened=True)
>>> derivation.from_index(index=0, hardened=True)
>>> derivation.from_index(index=0, hardened=True)
>>> derivation.from_index(index=0)
>>> derivation.from_index(index=0)
<hdwallet.derivation.Derivation object at 0x000001E8BFB98D60>
clean_derivation()hdwallet.derivations.Derivation

Clean derivation path or indexes.

Returns

Derivation – Derivation instance.

>>> from hdwallet.derivations import Derivation
>>> derivation = Derivation()
>>> derivation.from_path(path="m/44'/0'/'0/0/0")
>>> str(derivation)
"m/44'/0'/'0/0/0"
>>> derivation.clean_derivation()
<hdwallet.wallet.HDWallet object at 0x000001E8BFB98D60>
>>> str(derivation)
""

BIP32Derivation

class hdwallet.derivations.BIP32Derivation(cryptocurrency: Optional[Any] = None, purpose: Union[int, Tuple[int, bool]] = 0, coin_type: Union[int, Tuple[int, bool]] = 0, account: Union[int, Tuple[int, bool]] = 0, change: bool = False, address: Union[int, Tuple[int, bool]] = 0)

Hierarchical Deterministic Wallet BIP32 Derivation

Parameters
  • cryptocurrency (Cryptocurrency) – Cryptocurrency instance, default to None.

  • purpose (int, tuple) – Purpose index, default to 0.

  • coin_type (int, tuple) – Coin type, default to 0.

  • account (int, tuple) – Account index, default to 0.

  • change (bool) – Change addresses, default to False.

  • address (int, tuple) – Address index, default to 0.

Returns

BIP32Derivation – BIP32Derivation instance.

>>> from hdwallet.derivations import BIP32Derivation
>>> from hdwallet.cryptocurrencies import BitcoinMainnet
>>> BIP32Derivation(cryptocurrency=BitcoinMainnet)
<hdwallet.derivations.Derivation object at 0x000001EBC58E9F70>
>>> str(BIP32Derivation(cryptocurrency=BitcoinMainnet))
"m/0'/0'/0'/0/0"
from_purpose(purpose: int, hardened: bool = True)hdwallet.derivations.BIP32Derivation

Derivation from purpose index.

Parameters
  • purpose (int) – Purpose index.

  • hardened (bool) – Hardened, default to True.

Returns

BIP32Derivation – BIP32Derivation instance.

>>> from hdwallet.derivations import BIP32Derivation
>>> bip32_derivation = BIP32Derivation()
>>> bip32_derivation.from_purpose(purpose=0, hardened=True)
<hdwallet.derivation.BIP32Derivation object at 0x000001E8BFB98D60>
from_coin_type(coin_type: int, hardened: bool = True)hdwallet.derivations.BIP32Derivation

Derivation from Coin Type index.

Parameters
  • coin_type (int) – Coin type index.

  • hardened (bool) – Hardened, default to True.

Returns

BIP32Derivation – BIP32Derivation instance.

>>> from hdwallet.derivations import BIP32Derivation
>>> bip32_derivation = BIP32Derivation()
>>> bip32_derivation.from_coin_type(coin_type=56, hardened=True)
<hdwallet.derivation.BIP32Derivation object at 0x000001E8BFB98D60>
from_account(account: int, hardened: bool = True)hdwallet.derivations.BIP32Derivation

Derivation from Account index.

Parameters
  • account (int) – Coin type index.

  • hardened (bool) – Hardened, default to True.

Returns

BIP32Derivation – BIP32Derivation instance.

>>> from hdwallet.derivations import BIP32Derivation
>>> bip32_derivation = BIP32Derivation()
>>> bip32_derivation.from_account(account=1, hardened=True)
<hdwallet.derivation.BIP32Derivation object at 0x000001E8BFB98D60>
from_change(change: bool)hdwallet.derivations.BIP32Derivation

Derivation from external Change.

Parameters

change (bool) – External chnage.

Returns

BIP32Derivation – BIP32Derivation instance.

>>> from hdwallet.derivations import BIP32Derivation
>>> bip32_derivation = BIP32Derivation()
>>> bip32_derivation.from_account(change=True)
<hdwallet.derivation.BIP32Derivation object at 0x000001E8BFB98D60>
from_address(address: int, hardened: bool = False)hdwallet.derivations.BIP32Derivation

Derivation from Address index.

Parameters
  • address (int) – Address index.

  • hardened (bool) – Hardened, default to True.

Returns

BIP32Derivation – BIP32Derivation instance.

>>> from hdwallet.derivations import BIP32Derivation
>>> bip32_derivation = BIP32Derivation()
>>> bip32_derivation.from_address(address=1, hardened=True)
<hdwallet.derivation.BIP32Derivation object at 0x000001E8BFB98D60>
clean_derivation()hdwallet.derivations.BIP32Derivation

Clean derivation path or indexes.

Returns

Derivation – Derivation instance.

>>> from hdwallet.derivations import Derivation
>>> derivation = Derivation()
>>> derivation.from_path(path="m/44'/0'/'0/0/0")
>>> str(derivation)
"m/44'/0'/'0/0/0"
>>> derivation.clean_derivation()
<hdwallet.wallet.HDWallet object at 0x000001E8BFB98D60>
>>> str(derivation)
""
purpose()str

Gey Purpose index.

Returns

str – Purpose index.

>>> from hdwallet.derivations import BIP32Derivation
>>> bip32_derivation = BIP32Derivation()
>>> bip32_derivation.from_purpose(purpose=0, hardened=True)
>>> bip32_derivation.purpose()
"0'"
coin_type()str

Gey Coin Type index.

Returns

str – Coin Type index.

>>> from hdwallet.derivations import BIP32Derivation
>>> bip32_derivation = BIP32Derivation()
>>> bip32_derivation.coin_type(coin_type=15, hardened=True)
>>> bip32_derivation.coin_type()
"15'"
account()str

Gey Account index.

Returns

str – Account index.

>>> from hdwallet.derivations import BIP32Derivation
>>> bip32_derivation = BIP32Derivation()
>>> bip32_derivation.from_account(account=1, hardened=True)
>>> bip32_derivation.account()
"1'"
change(number: bool = False)Union[str, bool]

Gey external Change.

Parameters

number (bool) – Return type, default to False.

Returns

str – External change index.

>>> from hdwallet.derivations import BIP32Derivation
>>> bip32_derivation = BIP32Derivation()
>>> bip32_derivation.from_change(change=True)
>>> bip32_derivation.change(number=True)
"1"
>>> bip32_derivation.change(number=False)
True
address()str

Gey Address index.

Returns

str – Address index.

>>> from hdwallet.derivations import BIP32Derivation
>>> bip32_derivation = BIP32Derivation()
>>> bip32_derivation.from_address(address=1, hardened=True)
>>> bip32_derivation.address()
"1"

BIP44Derivation

class hdwallet.derivations.BIP44Derivation(cryptocurrency: Any, account: Union[int, Tuple[int, bool]] = 0, change: bool = False, address: Union[int, Tuple[int, bool]] = 0)

Hierarchical Deterministic Wallet BIP44 Derivation

Parameters
  • cryptocurrency (Cryptocurrency) – Cryptocurrency instance.

  • account (int, tuple) – Account index, default to 0.

  • change (bool) – Change addresses, default to False.

  • address (int, tuple) – Address index, default to 0.

Returns

BIP44Derivation – BIP44Derivation instance.

>>> from hdwallet.derivations import BIP44Derivation
>>> from hdwallet.cryptocurrencies import BitcoinMainnet
>>> BIP44Derivation(cryptocurrency=BitcoinMainnet)
<hdwallet.derivations.Derivation object at 0x000001EBC58E9F70>
>>> str(BIP44Derivation(cryptocurrency=BitcoinMainnet))
"m/44'/0'/0'/0/0"

BIP49Derivation

class hdwallet.derivations.BIP49Derivation(cryptocurrency: Any, account: Union[int, Tuple[int, bool]] = 0, change: bool = False, address: Union[int, Tuple[int, bool]] = 0)

Hierarchical Deterministic Wallet BIP49 Derivation

Parameters
  • cryptocurrency (Cryptocurrency) – Cryptocurrency instance.

  • account (int, tuple) – Account index, default to 0.

  • change (bool) – Change addresses, default to False.

  • address (int, tuple) – Address index, default to 0.

Returns

BIP49Derivation – BIP49Derivation instance.

>>> from hdwallet.derivations import BIP49Derivation
>>> from hdwallet.cryptocurrencies import BitcoinMainnet
>>> BIP49Derivation(cryptocurrency=BitcoinMainnet)
<hdwallet.derivations.Derivation object at 0x000001EBC58E9F70>
>>> str(BIP49Derivation(cryptocurrency=BitcoinMainnet))
"m/49'/0'/0'/0/0"

BIP84Derivation

class hdwallet.derivations.BIP84Derivation(cryptocurrency: Any, account: Union[int, Tuple[int, bool]] = 0, change: bool = False, address: Union[int, Tuple[int, bool]] = 0)

Hierarchical Deterministic Wallet BIP84 Derivation

Parameters
  • cryptocurrency (Cryptocurrency) – Cryptocurrency instance.

  • account (int, tuple) – Account index, default to 0.

  • change (bool) – Change addresses, default to False.

  • address (int, tuple) – Address index, default to 0.

Returns

BIP84Derivation – BIP84Derivation instance.

>>> from hdwallet.derivations import BIP84Derivation
>>> from hdwallet.cryptocurrencies import BitcoinMainnet
>>> BIP84Derivation(cryptocurrency=BitcoinMainnet)
<hdwallet.derivations.Derivation object at 0x000001EBC58E9F70>
>>> str(BIP84Derivation(cryptocurrency=BitcoinMainnet))
"m/84'/0'/0'/0/0"

BIP141Derivation

class hdwallet.derivations.BIP141Derivation(cryptocurrency: Any, path: Optional[Union[str, hdwallet.derivations.Derivation]] = None, semantic: str = 'p2wpkh')

Hierarchical Deterministic Wallet BIP141 Derivation

Parameters
  • path (str) – Derivation path, default to None.

  • semantic (str) – Extended semantic, defaults to P2WPKH.

Returns

BIP141Derivation – BIP141Derivation instance.

>>> from hdwallet.derivations import BIP141Derivation
>>> from hdwallet.cryptocurrencies import BitcoinMainnet
>>> BIP141Derivation(cryptocurrency=BitcoinMainnet)
<hdwallet.derivations.Derivation object at 0x000001EBC58E9F70>
>>> str(BIP141Derivation(cryptocurrency=BitcoinMainnet))
"m/44'/0'/0'/0/0"