aiobitcoin.tools.key package¶
aiobitcoin.tools.key.BIP32Node module¶
A BIP0032-style hierarchical wallet.
Implement a BIP0032-style hierarchical wallet which can create public or private wallet keys. Each key can create many child nodes. Each node has a wallet key and a corresponding private & public key, which can be used to generate Bitcoin addresses or WIF private keys.
At any stage, the private information can be stripped away, after which descendants can only produce public keys.
Private keys can also generate “hardened” children, which cannot be generated by the corresponding public keys. This is useful for generating “change” addresses, for example, which there is no need to share with people you give public keys to.
-
class
aiobitcoin.tools.key.BIP32Node.
BIP32Node
(netcode, chain_code, depth=0, parent_fingerprint=b'x00x00x00x00', child_index=0, secret_exponent=None, public_pair=None)[source]¶ Bases:
aiobitcoin.tools.key.Key.Key
This is a deterministic wallet that complies with BIP0032 https://en.bitcoin.it/wiki/BIP_0032
-
as_text
(as_private=False)¶ Yield a 111-byte string corresponding to this node.
-
classmethod
from_hwif
(b58_str, allow_subkey_suffix=True)[source]¶ Generate a Wallet from a base58 string in a standard way.
-
classmethod
from_master_secret
(master_secret, netcode='BTC')[source]¶ Generate a Wallet from a master password.
-
classmethod
from_wallet_key
(b58_str, allow_subkey_suffix=True)¶ Generate a Wallet from a base58 string in a standard way.
-
subkey
(i=0, is_hardened=False, as_private=None)[source]¶ Yield a child node for this node.
i: the index for this node. is_hardened: use “hardened key derivation”. That is, the public version
of this node cannot calculate this child.as_private: set to True to get a private subkey.
-
subkey_for_path
(path)[source]¶ - path: a path of subkeys denoted by numbers and slashes. Use H or p
- for private key derivation. End with .pub to force the key public.
- Examples: 1H/5/2/1 would call subkey(i=1, is_hardened=True)
- .subkey(i=5).subkey(i=2).subkey(i=1) and then yield the private key 0/0/458.pub would call subkey(i=0).subkey(i=0) .subkey(i=458) and then yield the public key
You should choose one of the H or p convention for private key derivation and stick with it.
-
wallet_key
(as_private=False)¶ Yield a 111-byte string corresponding to this node.
-
aiobitcoin.tools.key.Key module¶
-
class
aiobitcoin.tools.key.Key.
Key
(secret_exponent=None, public_pair=None, hash160=None, prefer_uncompressed=None, is_compressed=None, is_pay_to_script=False, netcode=None)[source]¶ Bases:
object
-
address
(use_uncompressed=None)[source]¶ Return the public address representation of this key, if available. If use_uncompressed is not set, the preferred representation is returned.
-
bitcoin_address
(use_uncompressed=None)¶ Return the public address representation of this key, if available. If use_uncompressed is not set, the preferred representation is returned.
-
classmethod
from_sec
(sec, netcode=None)[source]¶ Create a key from an sec bytestream (which is an encoding of a public pair).
-
classmethod
from_text
(text, is_compressed=False)[source]¶ This function will accept a BIP0032 wallet string, a WIF, or a bitcoin address.
The “is_compressed” parameter is ignored unless a public address is passed in.
-
hash160
(use_uncompressed=None)[source]¶ Return the hash160 representation of this key, if available. If use_uncompressed is not set, the preferred representation is returned.
-
sec
(use_uncompressed=None)[source]¶ Return the SEC representation of this key, if available. If use_uncompressed is not set, the preferred representation is returned.
-
sec_as_hex
(use_uncompressed=None)[source]¶ Return the SEC representation of this key as hex text. If use_uncompressed is not set, the preferred representation is returned.
-
sign
(h)[source]¶ Return a der-encoded signature for a hash h. Will throw a RuntimeError if this key is not a private key
-