A Python implementation of BIP46: Address Scheme for Timelocked Fidelity Bonds
Project description
BIP46 - Address Scheme for Timelocked Fidelity Bonds
Python implementation of BIP46: Address Scheme for Timelocked Fidelity Bonds.
Example
Create a redeem script from a mnemonic
from datetime import UTC, datetime
from bip46 import (
create_redeemscript,
hdkey_derive,
hdkey_from_mnemonic,
hdkey_to_pubkey,
lockdate_to_derivation_path,
redeemscript_address,
redeemscript_pubkey,
)
network = "mainnet"
lock_date = datetime(2042, 6, 1, tzinfo=UTC)
lock_path = lockdate_to_derivation_path(lock_date, network=network)
hdkey = hdkey_from_mnemonic(
"abandon abandon abandon abandon abandon abandon"
" abandon abandon abandon abandon abandon about",
network=network,
)
redeem_key = hdkey_derive(hdkey, lock_path)
redeem_pub_key = hdkey_to_pubkey(redeem_key)
redeem_script = create_redeemscript(lock_date, redeem_pub_key)
script_pubkey = redeemscript_pubkey(redeem_script)
script_address = redeemscript_address(script_pubkey, network=network)
Create addresses from an xpub
BIP46 paths include hardened account components: m/84'/coin_type'/0'/2/index.
A public key cannot derive those hardened components, so pass an account-level xpub
for m/84'/coin_type'/0'. The library will derive the public BIP46 suffix
2/index from that account xpub.
from datetime import UTC, datetime
from bip46 import (
create_redeemscript,
hdkey_derive,
hdkey_from_xpub,
hdkey_to_pubkey,
lockdate_to_derivation_path,
redeemscript_address,
redeemscript_pubkey,
)
network = "mainnet"
lock_date = datetime(2042, 6, 1, tzinfo=UTC)
lock_path = lockdate_to_derivation_path(lock_date, network=network)
hdkey = hdkey_from_xpub("xpub...")
redeem_key = hdkey_derive(hdkey, lock_path)
redeem_pub_key = hdkey_to_pubkey(redeem_key)
redeem_script = create_redeemscript(lock_date, redeem_pub_key)
script_pubkey = redeemscript_pubkey(redeem_script)
script_address = redeemscript_address(script_pubkey, network=network)
The CLI also accepts an account xpub:
XPUB="xpub..." uv run bip46 create-timelock 2042 6 mainnet
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 bip46-1.0.0.tar.gz.
File metadata
- Download URL: bip46-1.0.0.tar.gz
- Upload date:
- Size: 34.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f85f2c3702c2e95741db625869b884866b6115d2c2413fe65018cedd38b7458a
|
|
| MD5 |
4434246809235dbca96c13bbaf37c7cf
|
|
| BLAKE2b-256 |
f26f20127a1b497b85606bb67a6b2431e61e1c1189abb9833bd78beb1f32209f
|
File details
Details for the file bip46-1.0.0-py3-none-any.whl.
File metadata
- Download URL: bip46-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb6e70f179b6afb136969b56536809f728699f327d84a102c2d6481d309cd088
|
|
| MD5 |
4f5deb07c081919346d0b74f5ab60c5e
|
|
| BLAKE2b-256 |
99d078eac6e6b3893a8df1d4ed98c06e2bf3f7c2812b52b3f5eebda8833d5cc9
|