Created
July 16, 2021 14:45
-
-
Save grunch/6ec7db634b0285c09be841e674561107 to your computer and use it in GitHub Desktop.
miniscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use miniscript::DescriptorTrait; | |
use std::str::FromStr; | |
use bitcoin::{Network, PrivateKey, PublicKey}; | |
use bitcoin::secp256k1; | |
use bdk::Error; | |
#[derive(Debug)] | |
pub struct WifAndHexPub { | |
wif: String, | |
hex_pub: String, | |
} | |
fn main() { | |
let alice_key = generate_keys().unwrap(); | |
let bob_key = generate_keys().unwrap(); | |
let descriptor_string = format!( | |
"wsh(or_d(pk({}),and_v(v:pk({}),older(25920))))", | |
alice_key.hex_pub, | |
bob_key.hex_pub, | |
); | |
let descriptor = miniscript::Descriptor::<bitcoin::PublicKey>::from_str(&descriptor_string).unwrap(); | |
println!("{:?}", descriptor.address(Network::Testnet).unwrap()); | |
} | |
fn generate_keys() -> Result<WifAndHexPub, Error> { | |
let key = secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng()); | |
let sk = PrivateKey { | |
compressed: true, | |
network: Network::Testnet, | |
key, | |
}; | |
let secp = secp256k1::Secp256k1::signing_only(); | |
let key = PublicKey::from_private_key(&secp, &sk); | |
Ok(WifAndHexPub { | |
wif: sk.to_wif(), | |
hex_pub: key.to_string(), | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment