Skip to content

PrivateKey (Class)

A private key for signing transactions and messages.

Private keys should be kept secret and never shared.

__new__

__new__(key: str) -> PrivateKey

Create a private key from a hex string.

PARAMETER DESCRIPTION
key

A 64-character hex string representing the secret key.

TYPE: str

RETURNS DESCRIPTION
PrivateKey

A new PrivateKey instance.

TYPE: PrivateKey

RAISES DESCRIPTION
Exception

If the hex string is invalid.

to_address

to_address(network: str | NetworkType) -> Address

Derive a Schnorr address from this private key.

PARAMETER DESCRIPTION
network

The network type for address encoding.

TYPE: str | NetworkType

RETURNS DESCRIPTION
Address

The derived Schnorr address.

TYPE: Address

RAISES DESCRIPTION
Exception

If derivation fails.

to_address_ecdsa

to_address_ecdsa(network: str | NetworkType) -> Address

Derive an ECDSA address from this private key.

PARAMETER DESCRIPTION
network

The network type for address encoding.

TYPE: str | NetworkType

RETURNS DESCRIPTION
Address

The derived ECDSA address.

TYPE: Address

RAISES DESCRIPTION
Exception

If derivation fails.

to_keypair

to_keypair() -> Keypair

Create a Keypair from this private key.

RETURNS DESCRIPTION
Keypair

A keypair containing this private key and derived public keys.

TYPE: Keypair

RAISES DESCRIPTION
Exception

If keypair creation fails.

to_public_key

to_public_key() -> PublicKey

Derive the corresponding public key.

RETURNS DESCRIPTION
PublicKey

The derived public key.

TYPE: PublicKey

RAISES DESCRIPTION
Exception

If derivation fails.

to_string

to_string() -> str

Convert to hex string representation.

RETURNS DESCRIPTION
str

The private key as a hex string.

TYPE: str