wif
Module for WIF encoding/decoding.
- class WifConst
Bases:
object
Class container for WIF constants.
- COMPR_PUB_KEY_SUFFIX: bytes = b'\x01'
- class WifEncoder
Bases:
object
WIF encoder class. It provides methods for encoding to WIF format.
- static Encode(priv_key: Union[bytes, IPrivateKey], net_ver: bytes = b'\x80', pub_key_mode: P2PKHPubKeyModes = P2PKHPubKeyModes.COMPRESSED) str
Encode key bytes into a WIF string.
- Parameters:
priv_key (bytes or IPrivateKey) – Private key bytes or object
net_ver (bytes, optional) – Net version (Bitcoin main net by default)
pub_key_mode (WifPubKeyModes, optional) – Specify if the private key corresponds to a compressed public key
- Returns:
WIF encoded string
- Return type:
str
- Raises:
TypeError – If pub_key_mode is not a WifPubKeyModes enum or the private key is not a valid Secp256k1PrivateKey
ValueError – If the key is not valid
- class WifDecoder
Bases:
object
WIF encoder class. It provides methods for encoding to WIF format.
- static Decode(wif_str: str, net_ver: bytes = b'\x80') Tuple[bytes, P2PKHPubKeyModes]
Decode key bytes from a WIF string.
- Parameters:
wif_str (str) – WIF string
net_ver (bytes, optional) – Net version (Bitcoin main net by default)
- Returns:
Key bytes (index 0), public key mode (index 1)
- Return type:
tuple[bytes, WifPubKeyModes]
- Raises:
Base58ChecksumError – If the base58 checksum is not valid
ValueError – If the resulting key is not valid