Skip to main content

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.

Release files for pyhdwallet 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyhdwallet 1.0.0
File Size Uploaded
pyhdwallet-1.0.0.tar.gz 18.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyhdwallet 1.0.0
File Interpreter ABI Platform
pyhdwallet-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 38.2 kB

Release files / pyhdwallet-1.0.0.tar.gz

Download URL pyhdwallet-1.0.0.tar.gz
Size 18.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c1d8b268064e9e3e4ce5fad4fae328af58364ba1ac55ee7e537db43a7becefcd
BLAKE2b-256 checksum
How to use checksums
e698f67a7c611a1265166440a77d939e2bb41eee46fb65d7812ca96057d8ead0
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pyhdwallet-1.0.0-py3-none-any.whl

Download URL pyhdwallet-1.0.0-py3-none-any.whl
Size 20.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
84f2f3b2c804bc9596f8d0e256dd631b7abc9cc938a34e712c954df893ab533e
BLAKE2b-256 checksum
How to use checksums
17330c70ccfc895365d8af705393de9edb19eafcb3c69df07d803b6374ecc487
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page