Last active
March 21, 2022 21:08
-
-
Save v0l/e3ef35760628e315299b3d39cdd5928b to your computer and use it in GitHub Desktop.
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 std::str::FromStr; | |
use bitcoin::util::bip32::ExtendedPubKey; | |
use bitcoin::util::bip32::DerivationPath; | |
use bitcoin::secp256k1::Secp256k1; | |
use bitcoin::secp256k1::ffi::types::AlignedType; | |
use slip132::FromSlip132; | |
fn main() { | |
let network = bitcoin::Network::Bitcoin; | |
// zprvAWgYBBk7JR8GmC7Jc5iG3LcxY8B93PG88L9N7emTEGnrtkVTxCPGLBisPQ5gbxeXtrZZHAGsUm9ojGYAN5gkvpvkNJNsxYb2C4PbAbS5oq4 | |
// globe motor iron eye glide own flag disagree satisfy slim control pride | |
let k1 = ExtendedPubKey::from_slip132_str("Zpub75FRZYofsUD31eBn35Yw3PnSXhfrhCSrxJciEnjWj8x25MxWRWwCYWNh4V8ShR1otGKghpDoJ4GG3LzjBoyqHoGAArdTzdhcGpZRdW1y619").unwrap(); | |
// zprvAWgYBBk7JR8GjXC6efnu7VbGDJGsQRJojViLw22rmkCcKNLdQsSxTEiuFJfGaPYsNAiAXZ6FoCb2qqNcdLHPJZ5R9Ai4G7F5MzosomRv7xr | |
// trust arena helmet squirrel pottery runway merge target brick kick concert decrease | |
let k2 = ExtendedPubKey::from_slip132_str("Zpub74pvmbyguyWMP5QbohasDZwtUu24N5sAg6AcZvNeq5wzF7WLL3tZBDihvT9DF1h8MzhMFXZvr15NuGygzYRU5Zfw1rTW8mYohmQ6EKwziM2").unwrap(); | |
let dp = DerivationPath::from_str("m/0/0").unwrap(); | |
let mut buf: Vec<AlignedType> = Vec::new(); | |
buf.resize(Secp256k1::preallocate_size(), AlignedType::zeroed()); | |
let secp = Secp256k1::preallocated_new(buf.as_mut_slice()).unwrap(); | |
let a0k1 = k1.derive_pub(&secp, &dp).unwrap(); | |
let a0k2 = k2.derive_pub(&secp, &dp).unwrap(); | |
println!("PK-0: {}", a0k1.public_key); | |
println!("PK-1: {}", a0k2.public_key); | |
let s0 = bitcoin::Script::from_str("5221023f3f6c33b522aa2178230e9a1b374f91bc59f4413da59a285fecfc1e7f72e67a2103e62f96cbb76f277b3c37913602baa4815f05ef6f7d14ade430efce0caf33fe3652ae").unwrap(); | |
// OP_PUSHNUM_2 | |
// OP_PUSHBYTES_33 023f3f6c33b522aa2178230e9a1b374f91bc59f4413da59a285fecfc1e7f72e67a | |
// OP_PUSHBYTES_33 03e62f96cbb76f277b3c37913602baa4815f05ef6f7d14ade430efce0caf33fe36 | |
// OP_PUSHNUM_2 | |
// OP_CHECKMULTISIG | |
let script = bitcoin::blockdata::script::Builder::new() | |
.push_int(2) | |
.push_key(&a0k2.public_key) | |
.push_key(&a0k1.public_key) | |
.push_int(2) | |
.push_opcode(bitcoin::blockdata::opcodes::all::OP_CHECKMULTISIG) | |
.into_script(); | |
println!("Ref: {}", s0); | |
println!("New: {}", script); | |
let script = bitcoin::Script::new_v0_wsh(&script.wscript_hash()); | |
let addr = bitcoin::Address::from_script(&script, network).unwrap(); | |
println!("Addr: {}", addr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment