libcrypto.addresses¶
Multi-chain address generation from secp256k1 public keys.
class AddressGenerator¶
AddressGenerator.from_public_key(public_key, address_type, network) -> str¶
Generate an address from a compressed or uncompressed public key.
public_key: 33-byte compressed, 65-byte uncompressed, or (for EVM/TRON) 64-byte raw point bytes.address_type: coin-specific type (see table below). Case-insensitive.network: coin name. Case-insensitive.
Raises AddressError for unsupported types and NotImplementedError for
networks that do not use secp256k1 derivation (solana, ton, cardano).
from libcrypto import PrivateKey, AddressGenerator
pub = PrivateKey(1).get_public_key(compressed=True).bytes
AddressGenerator.from_public_key(pub, "p2wpkh", "bitcoin")
Address types per network¶
| Network family | Address types |
|---|---|
| Bitcoin, Litecoin, DigiByte, testnet | p2pkh, p2sh-p2wpkh, p2wpkh, p2tr (where supported by HRP) |
| Dogecoin, Dash, Namecoin | p2pkh |
| Bitcoin Cash | p2pkh, cashaddr |
| Ethereum & EVM chains | EIP-55 checksummed hex (use default) |
| TRON | Base58Check (default), hex 0x41 form (hex) |
| Ripple / XRP | classic account address (default) |
Aliases accepted by address_type: legacy→p2pkh,
nested-segwit/p2sh_p2wpkh→p2sh-p2wpkh, segwit/bech32→p2wpkh,
taproot/taproot-bip86→p2tr, hash/hash_address→TRON hex.
Encoders¶
Two helper classes back the generator and are available for advanced use:
class Bech32¶
Bech32 / Bech32m encoding and decoding for SegWit-style addresses.
| Method | Description |
|---|---|
encode_witness(hrp, witness_version, witness_program) -> str |
Encode a witness program (v0 → Bech32, v1..16 → Bech32m). |
decode(address) -> (hrp, data, spec) |
Decode and verify a Bech32/Bech32m string. |
decode_witness(address) -> (hrp, witness_version, program) |
Decode a SegWit address with full witness-program validation. |
convert_bits(data, frombits, tobits, pad=True) |
Base conversion helper. |
class CashAddr¶
Bitcoin Cash CashAddr encoder for 20-byte P2PKH/P2SH hashes.
| Method | Description |
|---|---|
encode(prefix, payload, kind="p2pkh") -> str |
Encode a CashAddr address. |
Taproot (BIP86)¶
p2tr addresses are single-key BIP86 outputs: the internal key is the x-only
public key, tweaked by TapTweak(internal_key) per BIP341, and encoded as a
witness-v1 Bech32m program.