Skip to content

XPub (Class)

An extended public key (BIP-32).

Allows hierarchical deterministic address generation without access to private keys. Useful for watch-only wallets.

chain_code property

chain_code: str

The chain code as hex.

child_number property

child_number: int

The child number used to derive this key.

depth property

depth: int

The derivation depth (0 for master key).

parent_fingerprint property

parent_fingerprint: str

The parent key's fingerprint as hex.

xpub property

xpub: str

The serialized extended public key string.

__new__

__new__(xpub: str) -> XPub

Create an XPub from a serialized xpub string.

PARAMETER DESCRIPTION
xpub

A Base58-encoded extended public key string.

TYPE: str

RETURNS DESCRIPTION
XPub

A new XPub instance.

TYPE: XPub

RAISES DESCRIPTION
Exception

If the xpub string is invalid.

derive_child

derive_child(child_number: int, hardened: Optional[bool] = None) -> XPub

Derive a child key at the given index.

Note: Extended public keys can only derive non-hardened children.

PARAMETER DESCRIPTION
child_number

The child index.

TYPE: int

hardened

Whether to use hardened derivation (default: False).

TYPE: Optional[bool] DEFAULT: None

RETURNS DESCRIPTION
XPub

The derived child XPub.

TYPE: XPub

RAISES DESCRIPTION
Exception

If derivation fails (e.g., hardened from xpub).

derive_path

derive_path(path: str) -> XPub

Derive a key at the given derivation path.

PARAMETER DESCRIPTION
path

A derivation path string (non-hardened only).

TYPE: str

RETURNS DESCRIPTION
XPub

The derived XPub at that path.

TYPE: XPub

RAISES DESCRIPTION
Exception

If derivation fails.

into_string

into_string(prefix: str) -> str

Serialize to string with custom prefix.

PARAMETER DESCRIPTION
prefix

The key prefix (e.g., "kpub", "xpub").

TYPE: str

RETURNS DESCRIPTION
str

The serialized extended public key.

TYPE: str

RAISES DESCRIPTION
Exception

If serialization fails.

to_public_key

to_public_key() -> PublicKey

Get the public key at this derivation level.

RETURNS DESCRIPTION
PublicKey

The public key.

TYPE: PublicKey