rustywallet-descriptor
Output descriptors (BIP380-386) for Bitcoin wallet development.
Features
- Descriptor Parsing: Parse pk, pkh, wpkh, sh, wsh, tr, multi, sortedmulti descriptors
- BIP380 Checksum: Compute and verify descriptor checksums
- Key Expressions: Support for raw pubkeys, xpub/xprv with derivation paths, key origins
- Script Generation: Generate scriptPubKey for all descriptor types
- Address Derivation: Derive addresses from descriptors with network support
- Wildcard Support: Range derivation for HD wallet descriptors
Installation
[]
= "0.1"
Usage
Parse and Derive Address
use ;
use Network;
// Parse a wpkh descriptor
let desc = parse.unwrap;
// Derive address
let address = derive_address.unwrap;
println!; // bc1q...
Checksum Operations
use ;
// Add checksum to descriptor
let desc = "wpkh(02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5)";
let with_checksum = add_checksum;
println!; // wpkh(...)#xxxxxxxx
// Verify checksum
verify_checksum.unwrap;
HD Wallet Descriptors
use ;
use Network;
// Parse xpub descriptor with wildcard
let desc = parse.unwrap;
// Derive multiple addresses
let addresses = derive_addresses.unwrap;
for in addresses.iter.enumerate
Nested Descriptors
use Descriptor;
// P2SH-wrapped P2WPKH
let desc = parse.unwrap;
Multisig Descriptors
use Descriptor;
// 2-of-3 multisig
let desc = parse.unwrap;
Supported Descriptor Types
| Type | Description | Example |
|---|---|---|
pk(KEY) |
Pay-to-PubKey | pk(02...) |
pkh(KEY) |
Pay-to-PubKey-Hash | pkh(02...) |
wpkh(KEY) |
Pay-to-Witness-PubKey-Hash | wpkh(02...) |
sh(SCRIPT) |
Pay-to-Script-Hash | sh(wpkh(...)) |
wsh(SCRIPT) |
Pay-to-Witness-Script-Hash | wsh(multi(...)) |
tr(KEY) |
Pay-to-Taproot | tr(02...) |
multi(k,KEY,...) |
k-of-n Multisig | multi(2,02...,03...) |
sortedmulti(k,KEY,...) |
Sorted k-of-n Multisig | sortedmulti(2,02...,03...) |
Key Expression Formats
- Raw hex pubkey:
02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 - Extended public key:
xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8 - With derivation path:
xpub.../0/1 - With wildcard:
xpub.../0/*orxpub.../0/*' - With key origin:
[fingerprint/path]xpub...
License
MIT