Skip to content

XPrv (Class)

An extended private key (BIP-32).

Allows hierarchical deterministic key derivation from a seed. All keys in an HD wallet can be derived from a single XPrv.

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.

private_key property

private_key: str

The private key as a hex string.

xprv property

xprv: str

The serialized extended private key string.

__new__

__new__(seed: str) -> XPrv

Create an XPrv from a seed hex string.

PARAMETER DESCRIPTION
seed

A hex-encoded seed (typically from Mnemonic.to_seed()).

TYPE: str

RETURNS DESCRIPTION
XPrv

A new XPrv instance.

TYPE: XPrv

RAISES DESCRIPTION
Exception

If the seed is invalid.

derive_child

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

Derive a child key at the given index.

PARAMETER DESCRIPTION
child_number

The child index.

TYPE: int

hardened

Whether to use hardened derivation (default: False).

TYPE: Optional[bool] DEFAULT: None

RETURNS DESCRIPTION
XPrv

The derived child XPrv.

TYPE: XPrv

RAISES DESCRIPTION
Exception

If derivation fails.

derive_path

derive_path(path: Any) -> XPrv

Derive a key at the given derivation path.

PARAMETER DESCRIPTION
path

A derivation path string (e.g., "m/44'/111111'/0'") or DerivationPath.

TYPE: Any

RETURNS DESCRIPTION
XPrv

The derived XPrv at that path.

TYPE: XPrv

RAISES DESCRIPTION
Exception

If derivation fails.

from_xprv staticmethod

from_xprv(xprv: str) -> XPrv

Create an XPrv from a serialized xprv string.

PARAMETER DESCRIPTION
xprv

A Base58-encoded extended private key string.

TYPE: str

RETURNS DESCRIPTION
XPrv

A new XPrv instance.

TYPE: XPrv

RAISES DESCRIPTION
Exception

If the xprv string is invalid.

into_string

into_string(prefix: str) -> str

Serialize to string with custom prefix.

PARAMETER DESCRIPTION
prefix

The key prefix (e.g., "kprv", "xprv").

TYPE: str

RETURNS DESCRIPTION
str

The serialized extended private key.

TYPE: str

RAISES DESCRIPTION
Exception

If serialization fails.

to_private_key

to_private_key() -> PrivateKey

Get the private key at this derivation level.

RETURNS DESCRIPTION
PrivateKey

The private key.

TYPE: PrivateKey

to_string

to_string() -> str

Serialize to string with default "kprv" prefix.

RETURNS DESCRIPTION
str

The serialized extended private key.

TYPE: str

RAISES DESCRIPTION
Exception

If serialization fails.

to_xpub

to_xpub() -> XPub

Get the corresponding extended public key.

RETURNS DESCRIPTION
XPub

The derived extended public key.

TYPE: XPub