A Python lib for working with BIP32 (Hierarchical Deterministic Wallets)
Project description
pyhdwallet
A Python lib for working with BIP32 (Hierarchical Deterministic Wallets)
This project aims to provide an API similar to bitcoincashjs2-lib concerning HD utilities.
Don't trust. Verify.
Sample Usage
>>> from binascii import unhexlify
>>> from pyhdwallet import ECPair, HDNode
>>> from pyhdwallet.hashutils import sha256
>>> from pyhdwallet.networks import BITCOIN_TESTNET
>>>
>>>
>>> SEED = b'5636fa7760cca11a5ef1212c56fe0f5e576004e371b88a53780994ece7b6fe8f6923bd5ba3ab0688b0dbb865dbfef37894a39bf2ce9b11315c5413d510a1eee1'
>>> seed_buffer = unhexlify(SEED)
>>>
>>> hdnode = HDNode.from_seed(seed_buffer)
>>> print("xprv:", hdnode.to_base58())
xprv: xprv9s21ZrQH143K2KoRMrztFLQfsKWMADqGKYXSoPRpLapf13Q4cMcFWJeNangQ2XRucXfkoQscg4dk7w3vtfStFZNM1z4DnxfRh4XYJkT1gAg
>>> print("xpub:", hdnode.neutered().to_base58())
xpub: xpub661MyMwAqRbcEostTtXtcUMQRMLqZgZ7gmT3bmqRtvMdsqjD9tvW46xrS53Se68UQLRAYGjSkpm5Cje9We12dE3CAK1p4W3xFauG5aX1Z8u
>>> print("address:", hdnode.get_address())
address: 17avao5dfvwuq1ugvo5wN7sUSNUjMa93BX
>>>
>>> hdnode_testnet = HDNode.from_seed(seed_buffer, network=BITCOIN_TESTNET)
>>> print("tprv (testnet):", hdnode_testnet.to_base58())
tprv (testnet): tprv8ZgxMBicQKsPd92x2RrPQz2fBSvZPjsGf6SZforGpZK8ne99bix1241pVxr42tpDyyCXoWVNqRDYanbg1snq4cdwYdGXTKPUcAGxkXczrnh
>>>
>>> hdnode2 = HDNode.from_base58("xprv9s21ZrQH143K2KoRMrztFLQfsKWMADqGKYXSoPRpLapf13Q4cMcFWJeNangQ2XRucXfkoQscg4dk7w3vtfStFZNM1z4DnxfRh4XYJkT1gAg")
>>>
>>> child = hdnode.derive_path("m/0/1'/1")
>>> print("address child:", child.get_address())
address child: 14fW6kaeFiPees7FWNkvNFxewqhX7zSj2r
>>> print("child hdnode: ", child)
child hdnode: HDNode (keyPair=ECPair (privKey=85992014414924097038377675237145575004969559361289161063865857372311461164262, pubKey=b'\x02E\x8aEg\xc9\x03\xaf@\x12\xe1\xa4a"}\xfa1)\xfcM\x1e.\x05\xe6\x11\xcc\xac\x17\xdf\xc2\x02\xb12', compressed=True, network=Bitcoin Mainnet), chainCode=b'\xe9>(\x84\xb2\x83"\x80c8)\xdb\xbf\x1d\xe8\xa9*1\x15\x10s\xc5x\xb1E\xfc)ONuC>',depth=3, index=1,parentFingerprint=1079081844)
>>>
>>> ecpair = child.get_keypair()
>>> print("public key:", ecpair.pubkey_buffer)
public key: b'\x02E\x8aEg\xc9\x03\xaf@\x12\xe1\xa4a"}\xfa1)\xfcM\x1e.\x05\xe6\x11\xcc\xac\x17\xdf\xc2\x02\xb12'
>>> print("wif:", ecpair.to_wif())
wif: L3bGjEiQ6TynvKskm567Kh2rKrrs2JmgACV81Zb6MFFx9JyMnJNV
>>> ecpair2 = ECPair.from_wif("L1HZ6Vo7RJtXBzx75o2N2AhpXFVVuXVatqu6Xsy4iWNtmPphhJiz")
>>> print("wif2:", ecpair2.to_wif())
wif2: L1HZ6Vo7RJtXBzx75o2N2AhpXFVVuXVatqu6Xsy4iWNtmPphhJiz
>>>
>>> signature = ecpair.sign(sha256(b"Message"))
>>> print("signature valid:", ecpair.verify(sha256(b"Message"), signature))
signature valid: True
Documentation
See the documentation for more info.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyhdwallet-1.0.0.tar.gz.
File metadata
- Download URL: pyhdwallet-1.0.0.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1d8b268064e9e3e4ce5fad4fae328af58364ba1ac55ee7e537db43a7becefcd
|
|
| MD5 |
79b6d135b3378458835cda70868a958f
|
|
| BLAKE2b-256 |
e698f67a7c611a1265166440a77d939e2bb41eee46fb65d7812ca96057d8ead0
|
File details
Details for the file pyhdwallet-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pyhdwallet-1.0.0-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84f2f3b2c804bc9596f8d0e256dd631b7abc9cc938a34e712c954df893ab533e
|
|
| MD5 |
45225c1112141320845b87a9356990a2
|
|
| BLAKE2b-256 |
17330c70ccfc895365d8af705393de9edb19eafcb3c69df07d803b6374ecc487
|