XPub (Class)¶
An extended public key (BIP-32).
Allows hierarchical deterministic address generation without access to private keys. Useful for watch-only wallets.
__new__
¶
__new__(xpub: str) -> XPub
Create an XPub from a serialized xpub string.
| PARAMETER | DESCRIPTION |
|---|---|
xpub
|
A Base58-encoded extended public key string.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
XPub
|
A new XPub instance.
TYPE:
|
| 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:
|
hardened
|
Whether to use hardened derivation (default: False).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
XPub
|
The derived child XPub.
TYPE:
|
| 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:
|
| RETURNS | DESCRIPTION |
|---|---|
XPub
|
The derived XPub at that path.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
Exception
|
If derivation fails. |
into_string
¶
Serialize to string with custom prefix.
| PARAMETER | DESCRIPTION |
|---|---|
prefix
|
The key prefix (e.g., "kpub", "xpub").
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The serialized extended public key.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
Exception
|
If serialization fails. |