Bip32PublicKey

class cometa.cryptography.bip32_public_key.Bip32PublicKey(ptr)[source]

Bases: object

Represents 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])
__init__(ptr)[source]
Return type:

None

__enter__()[source]
Return type:

Bip32PublicKey

__exit__(exc_type, exc_val, exc_tb)[source]
Return type:

None

__repr__()[source]

Return repr(self).

Return type:

str

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:

Bip32PublicKey

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:

Bip32PublicKey

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:

Bip32PublicKey

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:

Ed25519PublicKey

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:

Blake2bHash

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

__eq__(other)[source]

Checks equality with another Bip32PublicKey.

Parameters:

other (object)

Return type:

bool

__hash__()[source]

Returns a Python hash for use in sets and dicts.

Return type:

int

__str__()[source]

Returns the hexadecimal representation.

Return type:

str