Ed25519PrivateKey

class cometa.cryptography.ed25519_private_key.Ed25519PrivateKey(ptr)[source]

Bases: object

Represents an Ed25519 private key within the Cardano ecosystem.

Ed25519 private keys are used for signing transactions and messages. This class supports both “normal” (32-byte seed) and “extended” (64-byte) private key formats.

Warning

Private keys should be handled with extreme care. Never expose them in logs, error messages, or user interfaces.

Example

>>> priv_key = Ed25519PrivateKey.from_normal_hex("00" * 32)
>>> pub_key = priv_key.get_public_key()
__init__(ptr)[source]
Return type:

None

__enter__()[source]
Return type:

Ed25519PrivateKey

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

None

__repr__()[source]

Return repr(self).

Return type:

str

classmethod from_normal_bytes(data)[source]

Creates an Ed25519 private key from a 32-byte seed.

Parameters:

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

Returns:

A new Ed25519PrivateKey instance.

Raises:

CardanoError – If creation fails.

Return type:

Ed25519PrivateKey

Example

>>> priv_key = Ed25519PrivateKey.from_normal_bytes(bytes(32))
classmethod from_extended_bytes(data)[source]

Creates an extended Ed25519 private key from 64 bytes.

The extended format includes both the 32-byte private scalar and a 32-byte chain code or initialization vector.

Parameters:

data (bytes | bytearray) – The extended private key as raw bytes (64 bytes).

Returns:

A new Ed25519PrivateKey instance.

Raises:

CardanoError – If creation fails.

Return type:

Ed25519PrivateKey

Example

>>> priv_key = Ed25519PrivateKey.from_extended_bytes(bytes(64))
classmethod from_normal_hex(hex_string)[source]

Creates an Ed25519 private key from a hexadecimal seed string.

Parameters:

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

Returns:

A new Ed25519PrivateKey instance.

Raises:

CardanoError – If creation fails or hex is invalid.

Return type:

Ed25519PrivateKey

Example

>>> priv_key = Ed25519PrivateKey.from_normal_hex("00" * 32)
classmethod from_extended_hex(hex_string)[source]

Creates an extended Ed25519 private key from a hexadecimal string.

Parameters:

hex_string (str) – The extended private key as a hexadecimal string (128 characters).

Returns:

A new Ed25519PrivateKey instance.

Raises:

CardanoError – If creation fails or hex is invalid.

Return type:

Ed25519PrivateKey

Example

>>> priv_key = Ed25519PrivateKey.from_extended_hex("00" * 64)
get_public_key()[source]

Derives the corresponding public key from this private key.

Returns:

The Ed25519 public key derived from this private key.

Raises:

CardanoError – If derivation fails.

Return type:

Ed25519PublicKey

sign(message)[source]

Signs a message using this private key.

Parameters:

message (bytes | bytearray) – The message to sign.

Returns:

The Ed25519 signature of the message.

Raises:

CardanoError – If signing fails.

Return type:

Ed25519Signature

Example

>>> priv_key = Ed25519PrivateKey.from_normal_hex("...")
>>> sig = priv_key.sign(b"Hello, world!")
to_bytes()[source]

Returns the private key as raw bytes.

Warning

Handle the returned bytes with care as they contain sensitive key material.

Returns:

The private key bytes (32 or 64 bytes depending on format).

Return type:

bytes

to_hex()[source]

Returns the private key as a hexadecimal string.

Warning

Handle the returned string with care as it contains sensitive key material.

Returns:

The private key as a hex string.

Return type:

str

__eq__(other)[source]

Checks equality with another Ed25519PrivateKey.

Parameters:

other (object)

Return type:

bool

__hash__()[source]

Returns a Python hash for use in sets and dicts.

Return type:

int

__str__()[source]

Returns a safe string representation (does not expose key material).

Return type:

str