rustywallet-psbt
PSBT (Partially Signed Bitcoin Transaction) implementation for Bitcoin wallet development.
Features
- BIP174 (PSBT v0) - Full support for standard PSBT format
- BIP370 (PSBT v2) - Support for improved PSBT format
- All BIP174 Roles - Creator, Updater, Signer, Combiner, Finalizer, Extractor
- Multiple Input Types - P2PKH, P2WPKH, P2SH, P2WSH, P2TR
- Hardware Wallet Compatible - Interoperable with Ledger, Trezor, Coldcard
Installation
[]
= "0.1"
Quick Start
Parse PSBT
use Psbt;
// From base64
let psbt = from_base64?;
// From bytes
let psbt = from_bytes?;
println!;
println!;
Create PSBT
use Psbt;
// Create from unsigned transaction
let unsigned_tx = vec!;
let psbt = from_unsigned_tx?;
// Or create PSBT v2
let psbt = new_v2; // 2 inputs, 2 outputs
Update PSBT
use ;
let mut psbt = from_base64?;
// Add witness UTXO
psbt.update_input_with_utxo?;
// Add BIP32 derivation
psbt.update_input_with_bip32?;
Sign PSBT
use Psbt;
use PrivateKey;
let mut psbt = from_base64?;
let private_key = from_wif?;
// Sign all inputs that match this key
let signed_count = psbt.sign?;
println!;
Combine PSBTs
use Psbt;
let psbt1 = from_base64?; // Signed by party 1
let psbt2 = from_base64?; // Signed by party 2
// Combine signatures
let combined = combine?;
Finalize and Extract
use Psbt;
let mut psbt = from_base64?;
// Finalize all inputs
psbt.finalize?;
// Check if finalized
if psbt.is_finalized
BIP174 Roles
| Role | Description | Methods |
|---|---|---|
| Creator | Create PSBT from unsigned tx | from_unsigned_tx(), new_v2() |
| Updater | Add UTXO info, scripts, paths | update_input_with_*() |
| Signer | Add partial signatures | sign(), sign_input() |
| Combiner | Merge PSBTs | combine(), merge() |
| Finalizer | Build final scriptSig/witness | finalize(), finalize_input() |
| Extractor | Extract signed transaction | extract_tx() |
Supported Input Types
| Type | Description | Support |
|---|---|---|
| P2PKH | Legacy pay-to-pubkey-hash | ✅ |
| P2WPKH | Native SegWit | ✅ |
| P2SH-P2WPKH | Wrapped SegWit | ✅ |
| P2SH | Pay-to-script-hash | ✅ |
| P2WSH | Native SegWit script | ✅ |
| P2SH-P2WSH | Wrapped SegWit script | ✅ |
| P2TR | Taproot key path | ✅ |
Serialization
// To bytes
let bytes = psbt.to_bytes;
// To base64
let base64 = psbt.to_base64;
// Display (base64)
println!;
// Parse from string
let psbt: Psbt = "cHNidP8BAH...".parse?;
Error Handling
use ;
match from_base64
License
MIT License - see LICENSE for details.
Related Crates
- rustywallet-tx - Transaction building
- rustywallet-keys - Key management
- rustywallet-multisig - Multi-signature wallets