Skip to content

PublicKey (Class)

A public key for verifying signatures and deriving addresses.

Can be created from a private key or parsed from a hex string.

__new__

__new__(key: str) -> PublicKey

Create a public key from a hex string.

PARAMETER DESCRIPTION
key

A hex-encoded public key string.

TYPE: str

RETURNS DESCRIPTION
PublicKey

A new PublicKey instance.

TYPE: PublicKey

RAISES DESCRIPTION
Exception

If the hex string is invalid.

fingerprint

fingerprint() -> Optional[str]

Get the key fingerprint (first 4 bytes of hash).

RETURNS DESCRIPTION
Optional[str]

str | None: The fingerprint as hex, or None if unavailable.

to_address

to_address(network: str | NetworkType) -> Address

Derive a Schnorr address from this public 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 address derivation fails.

to_address_ecdsa

to_address_ecdsa(network: str | NetworkType) -> Address

Derive an ECDSA address from this public 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 address derivation fails.

to_string

to_string() -> str

Convert to hex string representation.

RETURNS DESCRIPTION
str

The public key as a hex string.

TYPE: str

to_x_only_public_key

to_x_only_public_key() -> XOnlyPublicKey

Get the x-only public key (32 bytes, no parity byte).

RETURNS DESCRIPTION
XOnlyPublicKey

The x-only representation.

TYPE: XOnlyPublicKey