Expand description
§rustywallet-taproot
Full Taproot support implementing BIP340 (Schnorr), BIP341 (Taproot), and BIP342 (Tapscript).
§Features
- Schnorr signatures (BIP340)
- X-only public keys
- Key tweaking for Taproot
- Tap tree (MAST) construction
- Control block generation
- P2TR address generation
- BIP341 signature hash
§Example
use rustywallet_taproot::{XOnlyPublicKey, TaprootOutput, Network};
use secp256k1::{Secp256k1, SecretKey};
// Generate a key pair
let secp = Secp256k1::new();
let secret = [1u8; 32];
let sk = SecretKey::from_slice(&secret).unwrap();
let pk = sk.public_key(&secp);
let (xonly, _) = pk.x_only_public_key();
let internal_key = XOnlyPublicKey::from_inner(xonly);
// Create a key-path only Taproot output
let output = TaprootOutput::key_path_only(internal_key).unwrap();
// Get the P2TR address
let address = output.address(Network::Mainnet).unwrap();
assert!(address.starts_with("bc1p"));§Script Path Example
use rustywallet_taproot::{XOnlyPublicKey, TaprootOutput, TapTreeBuilder, Network};
use secp256k1::{Secp256k1, SecretKey};
let secp = Secp256k1::new();
let secret = [1u8; 32];
let sk = SecretKey::from_slice(&secret).unwrap();
let pk = sk.public_key(&secp);
let (xonly, _) = pk.x_only_public_key();
let internal_key = XOnlyPublicKey::from_inner(xonly);
// Build a tap tree with two scripts
let tree = TapTreeBuilder::new()
.add_leaf(1, vec![0x51]) // OP_1
.add_leaf(1, vec![0x52]) // OP_2
.build()
.unwrap();
// Create output with script tree
let output = TaprootOutput::with_script_tree(internal_key, &tree).unwrap();
let address = output.address(Network::Mainnet).unwrap();Re-exports§
pub use control_block::ControlBlock;pub use error::TaprootError;pub use schnorr::SchnorrSignature;pub use sighash::taproot_key_path_sighash;pub use sighash::taproot_script_path_sighash;pub use sighash::TaprootSighashType;pub use tagged_hash::tagged_hash;pub use tagged_hash::TapLeafHash;pub use tagged_hash::TapNodeHash;pub use tagged_hash::TapTweakHash;pub use taproot::create_address;pub use taproot::is_p2tr_address;pub use taproot::parse_address;pub use taproot::Network;pub use taproot::TaprootOutput;pub use taptree::LeafVersion;pub use taptree::TapLeaf;pub use taptree::TapNode;pub use taptree::TapTree;pub use taptree::TapTreeBuilder;pub use tweak::compute_output_key;pub use tweak::compute_tweak;pub use tweak::tweak_private_key;pub use tweak::tweak_public_key;pub use xonly::Parity;pub use xonly::XOnlyPublicKey;
Modules§
- control_
block - Control block for Taproot script path spending
- error
- Taproot error types
- prelude
- Prelude module for convenient imports
- schnorr
- Schnorr signatures (BIP340)
- sighash
- BIP341 Taproot signature hash
- tagged_
hash - Tagged hashes for BIP340/341
- taproot
- Taproot output and address generation
- taptree
- Tap tree (MAST) construction
- tweak
- Key tweaking for Taproot
- xonly
- X-only public keys (BIP340)