bip32_base
Module with BIP32 base class.
- class Bip32Base(priv_key: Optional[Union[bytes, IPrivateKey]], pub_key: Optional[Union[bytes, IPoint, IPublicKey]], key_data: Bip32KeyData, key_net_ver: Bip32KeyNetVersions)
Bases:
ABC
BIP32 base class. It allows master key generation and children keys derivation in according to BIP-0032/SLIP-0010. It shall be derived to implement derivation for a specific elliptic curve.
- classmethod FromSeed(seed_bytes: bytes, key_net_ver: Optional[Bip32KeyNetVersions] = None) Bip32Base
Create a Bip32 object from the specified seed (e.g. BIP39 seed).
- Parameters:
seed_bytes (bytes) – Seed bytes
key_net_ver (Bip32KeyNetVersions object, optional) – Bip32KeyNetVersions object (default: specific class key net version)
- Returns:
Bip32Base object
- Return type:
Bip32Base object
- Raises:
ValueError – If the seed is too short
Bip32KeyError – If the seed is not suitable for master key generation
- classmethod FromSeedAndPath(seed_bytes: bytes, path: Union[str, Bip32Path], key_net_ver: Optional[Bip32KeyNetVersions] = None) Bip32Base
Create a Bip32 object from the specified seed (e.g. BIP39 seed) and path.
- Parameters:
seed_bytes (bytes) – Seed bytes
path (str or Bip32Path object) – Path
key_net_ver (Bip32KeyNetVersions object, optional) – Bip32KeyNetVersions object (default: specific class key net version)
- Returns:
Bip32Base object
- Return type:
Bip32Base object
- Raises:
ValueError – If the seed length is too short
Bip32PathError – If the path is not valid
Bip32KeyError – If the seed is not suitable for master key generation
- classmethod FromExtendedKey(ex_key_str: str, key_net_ver: Optional[Bip32KeyNetVersions] = None) Bip32Base
Create a Bip32 object from the specified extended key.
- Parameters:
ex_key_str (str) – Extended key string
key_net_ver (Bip32KeyNetVersions object, optional) – Bip32KeyNetVersions object (default: specific class key net version)
- Returns:
Bip32Base object
- Return type:
Bip32Base object
- Raises:
Bip32KeyError – If the key is not valid
- classmethod FromPrivateKey(priv_key: ~typing.Union[bytes, ~bip_utils.ecc.common.ikeys.IPrivateKey], key_data: ~bip_utils.bip.bip32.bip32_key_data.Bip32KeyData = <bip_utils.bip.bip32.bip32_key_data.Bip32KeyData object>, key_net_ver: ~typing.Optional[~bip_utils.bip.bip32.bip32_key_net_ver.Bip32KeyNetVersions] = None) Bip32Base
Create a Bip32 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
key_data (Bip32KeyData object, optional) – Key data (default: all zeros)
key_net_ver (Bip32KeyNetVersions object, optional) – Bip32KeyNetVersions object (default: specific class key net version)
- Returns:
Bip32Base object
- Return type:
Bip32Base object
- Raises:
Bip32KeyError – If the key is not valid
- classmethod FromPublicKey(pub_key: ~typing.Union[bytes, ~bip_utils.ecc.common.ipoint.IPoint, ~bip_utils.ecc.common.ikeys.IPublicKey], key_data: ~bip_utils.bip.bip32.bip32_key_data.Bip32KeyData = <bip_utils.bip.bip32.bip32_key_data.Bip32KeyData object>, key_net_ver: ~typing.Optional[~bip_utils.bip.bip32.bip32_key_net_ver.Bip32KeyNetVersions] = None) Bip32Base
Create a Bip32 object from the specified public key and derivation data. If only the public 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:
pub_key (bytes, IPoint or IPublicKey) – Public key
key_data (Bip32KeyData object, optional) – Key data (default: all zeros)
key_net_ver (Bip32KeyNetVersions object, optional) – Bip32KeyNetVersions object (default: specific class key net version)
- Returns:
Bip32Base object
- Return type:
Bip32Base object
- Raises:
Bip32KeyError – If the key is not valid
- m_priv_key: Optional[Bip32PrivateKey]
- m_pub_key: Bip32PublicKey
- ChildKey(index: Union[int, Bip32KeyIndex]) Bip32Base
Create and return a child key of the current one with the specified index. The index shall be hardened using HardenIndex method to use the private derivation algorithm.
- Parameters:
index (int or Bip32KeyIndex object) – Index
- Returns:
Bip32Base object
- Return type:
Bip32Base object
- Raises:
Bip32KeyError – If the index results in an invalid key
- DerivePath(path: Union[str, Bip32Path]) Bip32Base
Derive children keys from the specified path.
- Parameters:
path (str or Bip32Path object) – Path
- Returns:
Bip32Base object
- Return type:
Bip32Base object
- Raises:
Bip32KeyError – If the index results in an invalid key
Bip32PathError – If the path is not valid
ValueError – If the path is a master path and the key is a child key
- ConvertToPublic() None
Convert the object into a public one.
- IsPublicOnly() bool
Get if it’s public-only.
- Returns:
True if public-only, false otherwise
- Return type:
bool
- PrivateKey() Bip32PrivateKey
Return private key object.
- Returns:
Bip32PrivateKey object
- Return type:
Bip32PrivateKey object
- Raises:
Bip32KeyError – If internal key is public-only
- PublicKey() Bip32PublicKey
Return public key object.
- Returns:
Bip32PublicKey object
- Return type:
Bip32PublicKey object
- KeyNetVersions() Bip32KeyNetVersions
Get key net versions.
- Returns:
Bip32KeyNetVersions object
- Return type:
Bip32KeyNetVersions object
- Depth() Bip32Depth
Get current depth.
- Returns:
Current depth
- Return type:
Bip32Depth object
- Index() Bip32KeyIndex
Get current index.
- Returns:
Current index
- Return type:
Bip32KeyIndex object
- ChainCode() Bip32ChainCode
Get chain code.
- Returns:
Chain code
- Return type:
- FingerPrint() Bip32FingerPrint
Get public key fingerprint.
- Returns:
Public key fingerprint bytes
- Return type:
Bip32FingerPrint object
- ParentFingerPrint() Bip32FingerPrint
Get parent fingerprint.
- Returns:
Parent fingerprint bytes
- Return type:
Bip32FingerPrint object
- classmethod Curve() EllipticCurve
Return the elliptic curve.
- Returns:
EllipticCurve object
- Return type:
EllipticCurve object
- classmethod IsPublicDerivationSupported() bool
Get if public derivation is supported.
- Returns:
True if supported, false otherwise.
- Return type:
bool
- abstract static CurveType() EllipticCurveTypes
Return the elliptic curve type.
- Returns:
Curve type
- Return type: