Ed25519PublicKey

class cometa.cryptography.ed25519_public_key.Ed25519PublicKey(ptr)[source]

Bases: object

Represents an Ed25519 public key within the Cardano ecosystem.

Ed25519 public keys are 32 bytes and are used for signature verification, address generation, and identifying stake pool operators and DReps.

Example

>>> pub_key = Ed25519PublicKey.from_hex("00" * 32)
>>> key_hash = pub_key.to_hash()
__init__(ptr)[source]
Return type:

None

__enter__()[source]
Return type:

Ed25519PublicKey

__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 an Ed25519 public key from raw bytes.

Parameters:

data (bytes | bytearray) – The public key as raw bytes (32 bytes).

Returns:

A new Ed25519PublicKey instance.

Raises:

CardanoError – If creation fails.

Return type:

Ed25519PublicKey

Example

>>> pub_key = Ed25519PublicKey.from_bytes(bytes(32))
classmethod from_hex(hex_string)[source]

Creates an Ed25519 public key from a hexadecimal string.

Parameters:

hex_string (str) – The public key as a hexadecimal string (64 characters).

Returns:

A new Ed25519PublicKey instance.

Raises:

CardanoError – If creation fails or hex is invalid.

Return type:

Ed25519PublicKey

Example

>>> pub_key = Ed25519PublicKey.from_hex("00" * 32)
to_bytes()[source]

Returns the public key as raw bytes.

Returns:

The 32-byte public key.

Return type:

bytes

to_hex()[source]

Returns the public key as a hexadecimal string.

Returns:

The public key as a 64-character hex string.

Return type:

str

to_hash()[source]

Computes the Blake2b-224 hash of this public key.

This hash is commonly used as a key hash for credentials in addresses and governance operations.

Returns:

The Blake2b-224 hash of the public key.

Raises:

CardanoError – If hashing fails.

Return type:

Blake2bHash

verify(signature, message)[source]

Verifies a signature against a message using this public key.

Parameters:
  • signature (Ed25519Signature) – The Ed25519 signature to verify.

  • message (bytes | bytearray) – The message that was signed.

Returns:

True if the signature is valid, False otherwise.

Return type:

bool

Example

>>> pub_key = Ed25519PublicKey.from_hex("...")
>>> sig = Ed25519Signature.from_hex("...")
>>> pub_key.verify(sig, b"Hello, world!")
True
__eq__(other)[source]

Checks equality with another Ed25519PublicKey.

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