Bip32PublicKey
- class cometa.cryptography.bip32_public_key.Bip32PublicKey(ptr)[source]
Bases:
objectRepresents a BIP32 hierarchical deterministic (HD) public key.
BIP32 public keys enable the derivation of child public keys following a hierarchical tree structure. This allows for generating wallet addresses without access to the private key, enabling watch-only wallets.
Example
>>> # Derive public key from a BIP32 private key >>> pub_key = priv_key.get_public_key() >>> child = pub_key.derive([0, 1])
- classmethod from_bytes(data)[source]
Creates a BIP32 public key from raw bytes.
- Parameters:
data (bytes | bytearray) – The public key as raw bytes (64 bytes).
- Returns:
A new Bip32PublicKey instance.
- Raises:
CardanoError – If creation fails.
- Return type:
Example
>>> pub_key = Bip32PublicKey.from_bytes(key_bytes)
- classmethod from_hex(hex_string)[source]
Creates a BIP32 public key from a hexadecimal string.
- Parameters:
hex_string (str) – The public key as a hexadecimal string (128 characters).
- Returns:
A new Bip32PublicKey instance.
- Raises:
CardanoError – If creation fails or hex is invalid.
- Return type:
Example
>>> pub_key = Bip32PublicKey.from_hex(hex_string)
- derive(indices)[source]
Derives a child public key using the specified derivation path.
Note: Only non-hardened derivation is possible with public keys. Hardened indices (>= 2^31) will fail.
- Parameters:
indices (List[int]) – List of derivation indices.
- Returns:
The derived child Bip32PublicKey.
- Raises:
CardanoError – If derivation fails.
- Return type:
Example
>>> child = pub_key.derive([0, 1, 2])
- to_ed25519_key()[source]
Converts this BIP32 public key to an Ed25519 public key.
- Returns:
The Ed25519 public key extracted from this BIP32 key.
- Raises:
CardanoError – If conversion fails.
- Return type:
- to_hash()[source]
Computes the Blake2b-224 hash of this public key.
- Returns:
The Blake2b-224 hash of the public key.
- Raises:
CardanoError – If hashing fails.
- Return type:
- to_bytes()[source]
Returns the public key as raw bytes.
- Returns:
The 64-byte public key.
- Return type:
bytes
- to_hex()[source]
Returns the public key as a hexadecimal string.
- Returns:
The public key as a 128-character hex string.
- Return type:
str