libcrypto.wallet¶
High-level facade around a single secp256k1 private key. Wallet caches both
the compressed and uncompressed public keys and dispatches address generation
per coin.
class Wallet¶
Wallet(private_key)¶
private_key may be:
- a
PrivateKeyinstance, - a 64-character hex string,
- a WIF string,
- raw 32
bytes, - an
intin[1, N-1].
from libcrypto import Wallet, PrivateKey
Wallet("0000...0001") # hex
Wallet(PrivateKey.generate()) # from a PrivateKey
Wallet(1) # int
Wallet.generate() -> Wallet¶
Create a wallet backed by a freshly generated secure private key.
get_address(coin, address_type="p2pkh") -> str¶
Return one address for coin. Address-type aliases are normalized
(segwit/bech32 → p2wpkh, taproot → p2tr, hash → hex). Account-based
coins (Ethereum, EVM chains, TRON, Ripple) ignore Bitcoin-style address types
and use their canonical format.
wallet.get_address("bitcoin", "p2wpkh")
wallet.get_address("ethereum")
wallet.get_address("tron", "hex")
Raises ValueError for unsupported coins or address types.
get_all_addresses(coin) -> dict[str, str]¶
Return every configured address format for a coin. Any per-format failure is
captured as an "Error: ..." string value rather than raising, so the mapping
always contains one entry per configured type.
wallet.get_all_addresses("bitcoin")
# {'p2pkh': '1...', 'p2sh-p2wpkh': '3...', 'p2wpkh': 'bc1q...', 'p2tr': 'bc1p...'}
Attributes¶
| Attribute | Description |
|---|---|
private_key |
The underlying PrivateKey. |
_public_key_compressed |
Cached compressed PublicKey. |
_public_key_uncompressed |
Cached uncompressed PublicKey. |
Supported coins¶
Bitcoin-style: bitcoin, testnet, litecoin, dogecoin, dash,
bitcoin_cash, digibyte, namecoin, bitcoin_gold, ravencoin, qtum,
monacoin, vertcoin, zcash.
EVM-compatible: ethereum, ethereum_classic, bsc,
binance_smart_chain, polygon, polygon_zkevm, avalanche, arbitrum,
optimism, base, fantom, cronos, gnosis, celo, moonbeam,
moonriver, harmony, aurora, metis, kava, mantle, linea, scroll,
blast, opbnb, zksync, sonic.
Account-based: tron, ripple.
See Supported Coins & Networks for version bytes and per-coin
examples, and addresses for the exact address types available
per coin.