Skip to content

Keypair (Class)

A cryptographic keypair containing private and public keys.

Provides convenient access to all key forms needed for signing and address generation.

private_key property

private_key: str

The private key as hex.

public_key property

public_key: str

The full public key as hex.

xonly_public_key property

xonly_public_key: str

The x-only public key as hex.

__new__

__new__(secret_key: str, public_key: str, xonly_public_key: str) -> Keypair

Create a keypair from hex string representations.

PARAMETER DESCRIPTION
secret_key

The secret key as hex.

TYPE: str

public_key

The public key as hex.

TYPE: str

xonly_public_key

The x-only public key as hex.

TYPE: str

RETURNS DESCRIPTION
Keypair

A new Keypair instance.

TYPE: Keypair

RAISES DESCRIPTION
Exception

If any key format is invalid.

from_private_key staticmethod

from_private_key(private_key: PrivateKey) -> Keypair

Create a keypair from a private key.

PARAMETER DESCRIPTION
private_key

The private key to derive from.

TYPE: PrivateKey

RETURNS DESCRIPTION
Keypair

A new Keypair with derived public keys.

TYPE: Keypair

RAISES DESCRIPTION
Exception

If derivation fails.

random staticmethod

random() -> Keypair

Generate a random keypair.

RETURNS DESCRIPTION
Keypair

A new random Keypair.

TYPE: Keypair

to_address

to_address(network: str | NetworkType) -> Address

Derive a Schnorr address from this keypair.

PARAMETER DESCRIPTION
network

The network type for address encoding.

TYPE: str | NetworkType

RETURNS DESCRIPTION
Address

The derived Schnorr address.

TYPE: Address

to_address_ecdsa

to_address_ecdsa(network: str | NetworkType) -> Address

Derive an ECDSA address from this keypair.

PARAMETER DESCRIPTION
network

The network type for address encoding.

TYPE: str | NetworkType

RETURNS DESCRIPTION
Address

The derived ECDSA address.

TYPE: Address