bip44_base
Module with BIP44 base class.
- class Bip44Changes(value)
Bases:
IntEnum
Enumerative for BIP44 changes.
- CHAIN_EXT = 0
- CHAIN_INT = 1
- class Bip44Levels(value)
Bases:
IntEnum
Enumerative for BIP44 levels.
- MASTER = 0
- PURPOSE = 1
- COIN = 2
- ACCOUNT = 3
- CHANGE = 4
- ADDRESS_INDEX = 5
- class Bip44Base(bip32_obj: Bip32Base, coin_conf: BipCoinConf)
Bases:
ABC
BIP44 base class. It allows coin, account, chain and address keys generation in according to BIP44 or its extensions. The class is meant to be derived by classes implementing BIP44 or its extensions.
- m_coin_conf: BipCoinConf
- PublicKey() Bip44PublicKey
Return the public key.
- Returns:
Bip44PublicKey object
- Return type:
Bip44PublicKey object
- PrivateKey() Bip44PrivateKey
Return the private key.
- Returns:
Bip44PrivateKey object
- Return type:
Bip44PrivateKey object
- Raises:
Bip32KeyError – If the Bip32 object is public-only
- Bip32Object() Bip32Base
Return the BIP32 object.
- Returns:
Bip32Base object
- Return type:
Bip32Base object
- CoinConf() BipCoinConf
Get coin configuration.
- Returns:
BipCoinConf object
- Return type:
BipCoinConf object
- IsPublicOnly() bool
Get if it’s public-only.
- Returns:
True if public-only, false otherwise
- Return type:
bool
- Level() Bip44Levels
Return the current level.
- Returns:
Current level
- Return type:
- IsLevel(level: Bip44Levels) bool
Return if the current level is the specified one.
- Parameters:
level (Bip44Levels) – Level to be checked
- Returns:
True if it’s the specified level, false otherwise
- Return type:
bool
- Raises:
TypeError – If the level index is not a Bip44Levels enum
- DeriveDefaultPath() Bip44Base
Derive the default coin path and return a new Bip44Base object.
- Returns:
Bip44Base object
- Return type:
Bip44Base object
- Raises:
Bip44DepthError – If the current depth is not suitable for deriving keys
Bip32KeyError – If the derivation results in an invalid key
- abstract classmethod FromSeed(seed_bytes: bytes, coin_type: BipCoins) Bip44Base
Create a Bip44Base object from the specified seed (e.g. BIP39 seed). The test net flag is automatically set when the coin is derived. However, if you want to get the correct master or purpose keys, you have to specify here if it’s a test net.
- Parameters:
seed_bytes (bytes) – Seed bytes
coin_type (BipCoins) – Coin type (the type depends on the specific child class)
- Returns:
Bip44Base object
- Return type:
Bip44Base object
- Raises:
TypeError – If coin type is not of the correct type
ValueError – If the seed is too short
Bip32KeyError – If the seed is not suitable for master key generation
- abstract classmethod FromExtendedKey(ex_key_str: str, coin_type: BipCoins) Bip44Base
Create a Bip44Base object from the specified extended key.
- Parameters:
ex_key_str (str) – Extended key string
coin_type (BipCoins) – Coin type (the type depends on the specific child class)
- Returns:
Bip44Base object
- Return type:
Bip44Base object
- Raises:
TypeError – If coin type is not of the correct type
Bip32KeyError – If the extended key is not valid
- abstract classmethod FromPrivateKey(priv_key: Union[bytes, IPrivateKey], coin_type: BipCoins, key_data: Bip32KeyData) Bip44Base
Create a Bip44Base object from the specified private key and derivation data. If only the private key bytes are specified, the key will be considered a master key with the chain code set to zero, since there is no way to recover the key derivation data.
- Parameters:
priv_key (bytes or IPrivateKey) – Private key
coin_type (BipCoins) – Coin type, shall be a Bip44Coins enum
key_data (Bip32KeyData object) – Key data
- Returns:
Bip44Base object
- Return type:
Bip44Base object
- Raises:
TypeError – If coin type is not a Bip44Coins enum
Bip32KeyError – If the key is not valid
- abstract classmethod FromPublicKey(pub_key: Union[bytes, IPublicKey], coin_type: BipCoins, key_data: Bip32KeyData) Bip44Base
Create a Bip44Base object from the specified public key and derivation data. If only the public key bytes are specified, the key will be considered an account key with the chain code set to zero, since there is no way to recover the key derivation data.
- Parameters:
pub_key (bytes or IPublicKey) – Public key
coin_type (BipCoins) – Coin type, shall be a Bip44Coins enum
key_data (Bip32KeyData object) – Key data
- Returns:
Bip44Base object
- Return type:
Bip44Base object
- Raises:
TypeError – If coin type is not a Bip44Coins enum
Bip32KeyError – If the key is not valid
- abstract Purpose() Bip44Base
Derive a child key from the purpose and return a new Bip44Base object.
- Returns:
Bip44Base object
- Return type:
Bip44Base object
- Raises:
Bip44DepthError – If current depth is not suitable for deriving keys
Bip32KeyError – If the derivation results in an invalid key
- abstract Coin() Bip44Base
Derive a child key from the coin type specified at construction and return a new Bip44Base object.
- Returns:
Bip44Base object
- Return type:
Bip44Base object
- Raises:
Bip44DepthError – If current depth is not suitable for deriving keys
Bip32KeyError – If the derivation results in an invalid key
- abstract Account(acc_idx: int) Bip44Base
Derive a child key from the specified account index and return a new Bip44Base object.
- Parameters:
acc_idx (int) – Account index
- Returns:
Bip44Base object
- Return type:
Bip44Base object
- Raises:
Bip44DepthError – If current depth is not suitable for deriving keys
Bip32KeyError – If the derivation results in an invalid key
- abstract Change(change_type: Bip44Changes) Bip44Base
Derive a child key from the specified change type and return a new Bip44Base object.
- Parameters:
change_type (Bip44Changes) – Change type, must a Bip44Changes enum
- Returns:
Bip44Base object
- Return type:
Bip44Base object
- Raises:
TypeError – If change type is not a Bip44Changes enum
Bip44DepthError – If current depth is not suitable for deriving keys
Bip32KeyError – If the derivation results in an invalid key
- abstract AddressIndex(addr_idx: int) Bip44Base
Derive a child key from the specified address index and return a new Bip44Base object.
- Parameters:
addr_idx (int) – Address index
- Returns:
Bip44Base object
- Return type:
Bip44Base object
- Raises:
Bip44DepthError – If current depth is not suitable for deriving keys
Bip32KeyError – If the derivation results in an invalid key
- abstract static SpecName() str
Get specification name.
- Returns:
Specification name
- Return type:
str