Skip to content

PublicKeyGenerator (Class)

Generator for deriving public keys and addresses from an extended public key.

Useful for creating watch-only wallets that can generate addresses without access to private keys.

change_address

change_address(network_type: str | NetworkType, index: int) -> Address

Derive a change address at the given index.

PARAMETER DESCRIPTION
network_type

The network type for address encoding.

TYPE: str | NetworkType

index

The address index.

TYPE: int

RETURNS DESCRIPTION
Address

The derived address.

TYPE: Address

RAISES DESCRIPTION
Exception

If derivation fails.

change_address_as_string

change_address_as_string(network_type: str | NetworkType, index: int) -> str

Derive a change address as string.

PARAMETER DESCRIPTION
network_type

The network type for address encoding.

TYPE: str | NetworkType

index

The address index.

TYPE: int

RETURNS DESCRIPTION
str

The derived address string.

TYPE: str

RAISES DESCRIPTION
Exception

If derivation fails.

change_addresses

change_addresses(network_type: str | NetworkType, start: int, end: int) -> list[Address]

Derive a range of change addresses.

PARAMETER DESCRIPTION
network_type

The network type for address encoding.

TYPE: str | NetworkType

start

Start index (inclusive).

TYPE: int

end

End index (exclusive).

TYPE: int

RETURNS DESCRIPTION
list[Address]

list[Address]: The derived addresses.

RAISES DESCRIPTION
Exception

If derivation fails.

change_addresses_as_strings

change_addresses_as_strings(network_type: str | NetworkType, start: int, end: int) -> list[str]

Derive a range of change addresses as strings.

PARAMETER DESCRIPTION
network_type

The network type for address encoding.

TYPE: str | NetworkType

start

Start index (inclusive).

TYPE: int

end

End index (exclusive).

TYPE: int

RETURNS DESCRIPTION
list[str]

list[str]: The derived addresses as strings.

RAISES DESCRIPTION
Exception

If derivation fails.

change_pubkey

change_pubkey(index: int) -> PublicKey

Derive a change (internal) public key at the given index.

PARAMETER DESCRIPTION
index

The address index.

TYPE: int

RETURNS DESCRIPTION
PublicKey

The derived public key.

TYPE: PublicKey

RAISES DESCRIPTION
Exception

If derivation fails.

change_pubkey_as_string

change_pubkey_as_string(index: int) -> str

Derive a change public key as hex string.

PARAMETER DESCRIPTION
index

The address index.

TYPE: int

RETURNS DESCRIPTION
str

The public key as hex.

TYPE: str

RAISES DESCRIPTION
Exception

If derivation fails.

change_pubkeys

change_pubkeys(start: int, end: int) -> list[PublicKey]

Derive a range of change (internal) public keys.

PARAMETER DESCRIPTION
start

Start index (inclusive).

TYPE: int

end

End index (exclusive).

TYPE: int

RETURNS DESCRIPTION
list[PublicKey]

list[PublicKey]: The derived public keys.

RAISES DESCRIPTION
Exception

If derivation fails.

change_pubkeys_as_strings

change_pubkeys_as_strings(start: int, end: int) -> list[str]

Derive a range of change public keys as hex strings.

PARAMETER DESCRIPTION
start

Start index (inclusive).

TYPE: int

end

End index (exclusive).

TYPE: int

RETURNS DESCRIPTION
list[str]

list[str]: The derived public keys as hex.

RAISES DESCRIPTION
Exception

If derivation fails.

from_master_xprv staticmethod

from_master_xprv(xprv: str | XPrv, is_multisig: bool, account_index: int, cosigner_index: Optional[int] = None) -> PublicKeyGenerator

Create a generator from a master extended private key.

Derives the account-level public key and creates a generator.

PARAMETER DESCRIPTION
xprv

The master extended private key, as a string or XPrv instance.

TYPE: str | XPrv

is_multisig

Whether this is for a multisig wallet.

TYPE: bool

account_index

The account index to derive.

TYPE: int

cosigner_index

Optional cosigner index for multisig.

TYPE: Optional[int] DEFAULT: None

RETURNS DESCRIPTION
PublicKeyGenerator

A new generator instance.

TYPE: PublicKeyGenerator

RAISES DESCRIPTION
Exception

If derivation fails.

from_xpub staticmethod

from_xpub(kpub: str, cosigner_index: Optional[int] = None) -> PublicKeyGenerator

Create a generator from an extended public key string.

PARAMETER DESCRIPTION
kpub

The extended public key (xpub/kpub format).

TYPE: str

cosigner_index

Optional cosigner index for multisig.

TYPE: Optional[int] DEFAULT: None

RETURNS DESCRIPTION
PublicKeyGenerator

A new generator instance.

TYPE: PublicKeyGenerator

RAISES DESCRIPTION
Exception

If parsing fails.

receive_address

receive_address(network_type: str | NetworkType, index: int) -> Address

Derive a receive address at the given index.

PARAMETER DESCRIPTION
network_type

The network type for address encoding.

TYPE: str | NetworkType

index

The address index.

TYPE: int

RETURNS DESCRIPTION
Address

The derived address.

TYPE: Address

RAISES DESCRIPTION
Exception

If derivation fails.

receive_address_as_string

receive_address_as_string(network_type: str | NetworkType, index: int) -> str

Derive a receive address as string.

PARAMETER DESCRIPTION
network_type

The network type for address encoding.

TYPE: str | NetworkType

index

The address index.

TYPE: int

RETURNS DESCRIPTION
str

The derived address string.

TYPE: str

RAISES DESCRIPTION
Exception

If derivation fails.

receive_addresses

receive_addresses(network_type: str | NetworkType, start: int, end: int) -> list[Address]

Derive a range of receive addresses.

PARAMETER DESCRIPTION
network_type

The network type for address encoding.

TYPE: str | NetworkType

start

Start index (inclusive).

TYPE: int

end

End index (exclusive).

TYPE: int

RETURNS DESCRIPTION
list[Address]

list[Address]: The derived addresses.

RAISES DESCRIPTION
Exception

If derivation fails.

receive_addresses_as_strings

receive_addresses_as_strings(network_type: str | NetworkType, start: int, end: int) -> list[str]

Derive a range of receive addresses as strings.

PARAMETER DESCRIPTION
network_type

The network type for address encoding.

TYPE: str | NetworkType

start

Start index (inclusive).

TYPE: int

end

End index (exclusive).

TYPE: int

RETURNS DESCRIPTION
list[str]

list[str]: The derived addresses as strings.

RAISES DESCRIPTION
Exception

If derivation fails.

receive_pubkey

receive_pubkey(index: int) -> PublicKey

Derive a receive (external) public key at the given index.

PARAMETER DESCRIPTION
index

The address index.

TYPE: int

RETURNS DESCRIPTION
PublicKey

The derived public key.

TYPE: PublicKey

RAISES DESCRIPTION
Exception

If derivation fails.

receive_pubkey_as_string

receive_pubkey_as_string(index: int) -> str

Derive a receive public key as hex string.

PARAMETER DESCRIPTION
index

The address index.

TYPE: int

RETURNS DESCRIPTION
str

The public key as hex.

TYPE: str

RAISES DESCRIPTION
Exception

If derivation fails.

receive_pubkeys

receive_pubkeys(start: int, end: int) -> list[PublicKey]

Derive a range of receive (external) public keys.

PARAMETER DESCRIPTION
start

Start index (inclusive).

TYPE: int

end

End index (exclusive).

TYPE: int

RETURNS DESCRIPTION
list[PublicKey]

list[PublicKey]: The derived public keys.

RAISES DESCRIPTION
Exception

If derivation fails.

receive_pubkeys_as_strings

receive_pubkeys_as_strings(start: int, end: int) -> list[str]

Derive a range of receive public keys as hex strings.

PARAMETER DESCRIPTION
start

Start index (inclusive).

TYPE: int

end

End index (exclusive).

TYPE: int

RETURNS DESCRIPTION
list[str]

list[str]: The derived public keys as hex.

RAISES DESCRIPTION
Exception

If derivation fails.

to_string

to_string() -> str

Get the string representation of this generator.

RETURNS DESCRIPTION
str

The generator info string.

TYPE: str