Skip to content

Commit

Permalink
Depend on crate-smashing branch
Browse files Browse the repository at this point in the history
Depend on the `crate-smashing` branch, which introduces the new
`primitives`, `bip32`, and `psbt-v0` crates.

The point of this patch is to try to show we have all the re-exports
correct in `rust-bitcoin` after introducing the new crates.

Apart from the manifest changes this patch changes a single line, BOOM!
  • Loading branch information
tcharding committed Jun 21, 2024
1 parent 5d342eb commit 80cf6c1
Show file tree
Hide file tree
Showing 44 changed files with 785 additions and 658 deletions.
58 changes: 46 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "miniscript"
version = "12.0.0"
version = "13.0.0"
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>, Sanket Kanjalkar <sanket1729@gmail.com>"]
license = "CC0-1.0"
homepage = "https://github.com/rust-bitcoin/rust-miniscript/"
Expand All @@ -12,25 +12,29 @@ edition = "2018"

[features]
default = ["std"]
std = ["bitcoin/std", "bitcoin/secp-recovery", "bech32/std"]
std = ["bech32/std", "bip32/std", "bitcoin-primitives/crypto-std", "psbt-v0/std", "secp256k1/std", "secp256k1/recovery"]
no-std = ["bech32/alloc"]
compiler = []
trace = []

serde = ["actual-serde", "bitcoin/serde"]
rand = ["bitcoin/rand"]
base64 = ["bitcoin/base64"]
serde = ["actual-serde", "bip32/serde", "bitcoin-primitives/crypto-serde", "psbt-v0/serde", "secp256k1/serde"]
rand = ["secp256k1/rand"]
base64 = ["psbt-v0/base64"]

[dependencies]
bech32 = { version = "0.11.0", default-features = false }
bitcoin = { version = "0.32.0-rc1", default-features = false }
bip32 = { version = "0.1.0", default-features = false }
bitcoin-primitives = { version = "0.1.0", default-features = false, features = ["crypto"] }
psbt-v0 = { version = "0.1.0", default-features = false, features = [] }
secp256k1 = { version = "0.29.0", default-features = false, features = ["hashes", "alloc"] }

# Do NOT use this as a feature! Use the `serde` feature instead.
actual-serde = { package = "serde", version = "1.0.103", optional = true }

[dev-dependencies]
serde_test = "1.0.147"
bitcoin = { version = "0.32.0-rc1", features = ["base64"] }
bitcoin-primitives = { version = "0.1.0", features = ["crypto-std"] }
psbt-v0 = { version = "0.1.0", features = ["base64"] }
secp256k1 = {version = "0.29.0", features = ["rand-std"]}

[[example]]
Expand Down Expand Up @@ -69,17 +73,47 @@ required-features = ["std", "base64", "compiler"]
members = ["fuzz"]
exclude = ["embedded"]

[patch.crates-io.base58ck]
path = "/home/tobin/build/github.com/tcharding/rust-bitcoin/crate-smashing/base58"
# git = "https://github.com/tcharding/rust-bitcoin"
# branch = "crate-smashing"

[patch.crates-io.bip32]
path = "/home/tobin/build/github.com/tcharding/rust-bitcoin/crate-smashing/bip32"
# git = "https://github.com/tcharding/rust-bitcoin"
# branch = "crate-smashing"

[patch.crates-io.bitcoin]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
path = "/home/tobin/build/github.com/tcharding/rust-bitcoin/crate-smashing/bitcoin"
# git = "https://github.com/tcharding/rust-bitcoin"
# branch = "crate-smashing"

[patch.crates-io.bitcoin_hashes]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
path = "/home/tobin/build/github.com/tcharding/rust-bitcoin/crate-smashing/hashes"
# git = "https://github.com/tcharding/rust-bitcoin"
# branch = "crate-smashing"

[patch.crates-io.bitcoin-internals]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
path = "/home/tobin/build/github.com/tcharding/rust-bitcoin/crate-smashing/internals"
# git = "https://github.com/tcharding/rust-bitcoin"
# branch = "crate-smashing"

[patch.crates-io.bitcoin-io]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
path = "/home/tobin/build/github.com/tcharding/rust-bitcoin/crate-smashing/io"
# git = "https://github.com/tcharding/rust-bitcoin"
# branch = "crate-smashing"

[patch.crates-io.bitcoin-primitives]
path = "/home/tobin/build/github.com/tcharding/rust-bitcoin/crate-smashing/primitives"
# git = "https://github.com/tcharding/rust-bitcoin"
# branch = "crate-smashing"

[patch.crates-io.psbt-v0]
path = "/home/tobin/build/github.com/tcharding/rust-bitcoin/crate-smashing/psbt"
# git = "https://github.com/tcharding/rust-bitcoin"
# branch = "crate-smashing"

[patch.crates-io.bitcoin-units]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
path = "/home/tobin/build/github.com/tcharding/rust-bitcoin/crate-smashing/units"
# git = "https://github.com/tcharding/rust-bitcoin"
# branch = "crate-smashing"
4 changes: 2 additions & 2 deletions embedded/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ fn main() -> ! {
)))";
hprintln!("descriptor {}", descriptor).unwrap();
let desc =
miniscript::Descriptor::<miniscript::bitcoin::PublicKey>::from_str(descriptor).unwrap();
miniscript::Descriptor::<miniscript::bitcoin_primitives::PublicKey>::from_str(descriptor).unwrap();

// Derive the P2SH address
let p2sh_addr = desc
.address(miniscript::bitcoin::Network::Bitcoin)
.address(miniscript::bitcoin_primitives::Network::Bitcoin)
.unwrap()
.to_string();
hprintln!("p2sh address {}", p2sh_addr).unwrap();
Expand Down
20 changes: 11 additions & 9 deletions examples/big.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use std::collections::HashMap;
use std::str::FromStr;

use bitcoin::{ecdsa, XOnlyPublicKey};
use bitcoin_primitives::{ecdsa, XOnlyPublicKey};
use miniscript::descriptor::Wsh;
use miniscript::policy::{Concrete, Liftable};
use miniscript::psbt::PsbtExt;
Expand All @@ -29,13 +29,13 @@ fn main() {
let d = Descriptor::<DescriptorPublicKey>::from_str(&i).unwrap();
use_descriptor(d.clone());
use_descriptor(Descriptor::<DefiniteDescriptorKey>::from_str(&i).unwrap());
use_descriptor(Descriptor::<bitcoin::PublicKey>::from_str(&i).unwrap());
use_descriptor(Descriptor::<bitcoin_primitives::PublicKey>::from_str(&i).unwrap());
use_descriptor(Descriptor::<String>::from_str(&i).unwrap());

let a = d
.at_derivation_index(0)
.unwrap()
.address(bitcoin::Network::Bitcoin)
.address(bitcoin_primitives::Network::Bitcoin)
.unwrap();
println!("{}", a);

Expand All @@ -44,20 +44,20 @@ fn main() {
use_descriptor(d);
println!("{:?}", m);

let p = Concrete::<bitcoin::PublicKey>::from_str(&i).unwrap();
let p = Concrete::<bitcoin_primitives::PublicKey>::from_str(&i).unwrap();
let h = Wsh::new(p.compile().unwrap()).unwrap();
println!("{}", h);
println!("{:?}", h.lift());
println!("{:?}", h.script_pubkey());
println!("{:?}", h.address(bitcoin::Network::Bitcoin));
println!("{:?}", h.address(bitcoin_primitives::Network::Bitcoin));

let psbt: bitcoin::Psbt = i.parse().unwrap();
let psbt: psbt_v0::Psbt = i.parse().unwrap();
let psbt = psbt.finalize(&secp).unwrap();
let mut tx = psbt.extract_tx().unwrap();
println!("{:?}", tx);

let d = miniscript::Descriptor::<bitcoin::PublicKey>::from_str(&i).unwrap();
let sigs = HashMap::<bitcoin::PublicKey, ecdsa::Signature>::new();
let d = miniscript::Descriptor::<bitcoin_primitives::PublicKey>::from_str(&i).unwrap();
let sigs = HashMap::<bitcoin_primitives::PublicKey, ecdsa::Signature>::new();
d.satisfy(&mut tx.input[0], &sigs).unwrap();

let pol = Concrete::<String>::from_str(&i).unwrap();
Expand All @@ -67,7 +67,9 @@ fn main() {
let mut t = StrPkTranslator { pk_map };
let real_desc = desc.translate_pk(&mut t).unwrap();
println!("{}", real_desc);
let addr = real_desc.address(bitcoin::Network::Bitcoin).unwrap();
let addr = real_desc
.address(bitcoin_primitives::Network::Bitcoin)
.unwrap();
println!("{}", addr);
}

Expand Down
4 changes: 2 additions & 2 deletions examples/htlc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

use std::str::FromStr;

use miniscript::bitcoin::Network;
use miniscript::bitcoin_primitives::Network;
use miniscript::descriptor::Wsh;
use miniscript::policy::{Concrete, Liftable};

fn main() {
// HTLC policy with 10:1 odds for happy (co-operative) case compared to uncooperative case.
let htlc_policy = Concrete::<bitcoin::PublicKey>::from_str(&format!("or(10@and(sha256({secret_hash}),pk({redeem_identity})),1@and(older({expiry}),pk({refund_identity})))",
let htlc_policy = Concrete::<bitcoin_primitives::PublicKey>::from_str(&format!("or(10@and(sha256({secret_hash}),pk({redeem_identity})),1@and(older({expiry}),pk({refund_identity})))",
secret_hash = "1111111111111111111111111111111111111111111111111111111111111111",
redeem_identity = "022222222222222222222222222222222222222222222222222222222222222222",
refund_identity = "020202020202020202020202020202020202020202020202020202020202020202",
Expand Down
4 changes: 2 additions & 2 deletions examples/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use miniscript::descriptor::DescriptorType;
use miniscript::Descriptor;

fn main() {
let desc = miniscript::Descriptor::<bitcoin::PublicKey>::from_str(
let desc = miniscript::Descriptor::<bitcoin_primitives::PublicKey>::from_str(
"wsh(c:pk_k(020202020202020202020202020202020202020202020202020202020202020202))",
)
.unwrap();
Expand Down Expand Up @@ -48,7 +48,7 @@ fn main() {
);

// In a similar fashion we can parse a wrapped segwit script.
let desc = miniscript::Descriptor::<bitcoin::PublicKey>::from_str(
let desc = miniscript::Descriptor::<bitcoin_primitives::PublicKey>::from_str(
"sh(wsh(c:pk_k(020202020202020202020202020202020202020202020202020202020202020202)))",
)
.unwrap();
Expand Down
31 changes: 16 additions & 15 deletions examples/psbt_sign_finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
use std::collections::BTreeMap;
use std::str::FromStr;

use miniscript::bitcoin::consensus::encode::deserialize;
use miniscript::bitcoin::hashes::hex::FromHex;
use miniscript::bitcoin::psbt::{self, Psbt};
use miniscript::bitcoin::sighash::SighashCache;
//use miniscript::bitcoin::secp256k1; // https://github.com/rust-lang/rust/issues/121684
use miniscript::bitcoin::{
use miniscript::bitcoin_primitives::consensus::encode::deserialize;
use miniscript::bitcoin_primitives::hex::FromHex;
use miniscript::bitcoin_primitives::sighash::SighashCache;
//use miniscript::secp256k1; // https://github.com/rust-lang/rust/issues/121684
use miniscript::bitcoin_primitives::{
transaction, Address, Amount, Network, OutPoint, PrivateKey, Script, Sequence, Transaction,
TxIn, TxOut,
};
use miniscript::psbt::{PsbtExt, PsbtInputExt};
use miniscript::psbt_v0::{self, Psbt};
use miniscript::Descriptor;

fn main() {
let secp256k1 = secp256k1::Secp256k1::new();

let s = "wsh(t:or_c(pk(027a3565454fe1b749bccaef22aff72843a9c3efefd7b16ac54537a0c23f0ec0de),v:thresh(1,pkh(032d672a1a91cc39d154d366cd231983661b0785c7f27bc338447565844f4a6813),a:pkh(03417129311ed34c242c012cd0a3e0b9bca0065f742d0dfb63c78083ea6a02d4d9),a:pkh(025a687659658baeabdfc415164528065be7bcaade19342241941e556557f01e28))))#7hut9ukn";
let bridge_descriptor = Descriptor::from_str(s).unwrap();
//let bridge_descriptor = Descriptor::<bitcoin::PublicKey>::from_str(&s).expect("parse descriptor string");
//let bridge_descriptor = Descriptor::<bitcoin_primitives::PublicKey>::from_str(&s).expect("parse descriptor string");
assert!(bridge_descriptor.sanity_check().is_ok());
println!("Bridge pubkey script: {}", bridge_descriptor.script_pubkey());
println!("Bridge address: {}", bridge_descriptor.address(Network::Regtest).unwrap());
Expand Down Expand Up @@ -54,7 +54,7 @@ fn main() {

let spend_tx = Transaction {
version: transaction::Version::TWO,
lock_time: bitcoin::absolute::LockTime::from_consensus(5000),
lock_time: bitcoin_primitives::absolute::LockTime::from_consensus(5000),
input: vec![],
output: vec![],
};
Expand Down Expand Up @@ -100,14 +100,14 @@ fn main() {

// Generating signatures & witness data

let mut input = psbt::Input::default();
let mut input = psbt_v0::Input::default();
input
.update_with_descriptor_unchecked(&bridge_descriptor)
.unwrap();

input.witness_utxo = Some(witness_utxo.clone());
psbt.inputs.push(input);
psbt.outputs.push(psbt::Output::default());
psbt.outputs.push(psbt_v0::Output::default());

let mut sighash_cache = SighashCache::new(&psbt.unsigned_tx);

Expand All @@ -117,7 +117,7 @@ fn main() {
.to_secp_msg();

// Fixme: Take a parameter
let hash_ty = bitcoin::sighash::EcdsaSighashType::All;
let hash_ty = bitcoin_primitives::sighash::EcdsaSighashType::All;

let sk1 = backup1_private.inner;
let sk2 = backup2_private.inner;
Expand All @@ -132,9 +132,10 @@ fn main() {
let pk2 = backup2_private.public_key(&secp256k1);
assert!(secp256k1.verify_ecdsa(&msg, &sig2, &pk2.inner).is_ok());

psbt.inputs[0]
.partial_sigs
.insert(pk1, bitcoin::ecdsa::Signature { signature: sig1, sighash_type: hash_ty });
psbt.inputs[0].partial_sigs.insert(
pk1,
bitcoin_primitives::ecdsa::Signature { signature: sig1, sighash_type: hash_ty },
);

println!("{:#?}", psbt);
println!("{}", psbt);
Expand All @@ -143,7 +144,7 @@ fn main() {
println!("{:#?}", psbt);

let tx = psbt.extract_tx().expect("failed to extract tx");
println!("{}", bitcoin::consensus::encode::serialize_hex(&tx));
println!("{}", bitcoin_primitives::consensus::encode::serialize_hex(&tx));
}

// Find the Outpoint by spk
Expand Down
32 changes: 16 additions & 16 deletions examples/sign_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use std::collections::HashMap;
use std::str::FromStr;

use bitcoin::witness::Witness;
use bitcoin::{absolute, ecdsa, transaction, Amount, Sequence};
use bitcoin_primitives::witness::Witness;
use bitcoin_primitives::{absolute, ecdsa, transaction, Amount, Sequence};

fn main() {
let mut tx = spending_transaction();
Expand All @@ -15,15 +15,15 @@ fn main() {

// Descriptor for the output being spent.
let s = format!("wsh(multi(2,{},{},{}))", pks[0], pks[1], pks[2],);
let descriptor = miniscript::Descriptor::<bitcoin::PublicKey>::from_str(&s).unwrap();
let descriptor = miniscript::Descriptor::<bitcoin_primitives::PublicKey>::from_str(&s).unwrap();

// Check weight for witness satisfaction cost ahead of time.
// 106 (serialized witnessScript)
// + 73*2 (signature length + signatures + sighash bytes) + 1 (dummy byte) = 253
assert_eq!(descriptor.max_weight_to_satisfy().unwrap().to_wu(), 253);

// Sometimes it is necessary to have additional information to get the
// `bitcoin::PublicKey` from the `MiniscriptKey` which can be supplied by
// `bitcoin_primitives::PublicKey` from the `MiniscriptKey` which can be supplied by
// the `to_pk_ctx` parameter. For example, when calculating the script
// pubkey of a descriptor with xpubs, the secp context and child information
// maybe required.
Expand Down Expand Up @@ -51,7 +51,7 @@ fn main() {
// Attempt to satisfy at age 0, height 0.
let original_txin = tx.input[0].clone();

let mut sigs = HashMap::<bitcoin::PublicKey, ecdsa::Signature>::new();
let mut sigs = HashMap::<bitcoin_primitives::PublicKey, ecdsa::Signature>::new();

// Doesn't work with no signatures.
assert!(descriptor.satisfy(&mut tx.input[0], &sigs).is_err());
Expand All @@ -76,35 +76,35 @@ fn main() {
}

// Transaction which spends some output.
fn spending_transaction() -> bitcoin::Transaction {
bitcoin::Transaction {
fn spending_transaction() -> bitcoin_primitives::Transaction {
bitcoin_primitives::Transaction {
version: transaction::Version::TWO,
lock_time: absolute::LockTime::ZERO,
input: vec![bitcoin::TxIn {
input: vec![bitcoin_primitives::TxIn {
previous_output: Default::default(),
script_sig: bitcoin::ScriptBuf::new(),
script_sig: bitcoin_primitives::ScriptBuf::new(),
sequence: Sequence::MAX,
witness: Witness::default(),
}],
output: vec![bitcoin::TxOut {
script_pubkey: bitcoin::ScriptBuf::new(),
output: vec![bitcoin_primitives::TxOut {
script_pubkey: bitcoin_primitives::ScriptBuf::new(),
value: Amount::from_sat(100_000_000),
}],
}
}

#[rustfmt::skip]
fn list_of_three_arbitrary_public_keys() -> Vec<bitcoin::PublicKey> {
fn list_of_three_arbitrary_public_keys() -> Vec<bitcoin_primitives::PublicKey> {
vec![
bitcoin::PublicKey::from_slice(&[2; 33]).expect("key 1"),
bitcoin::PublicKey::from_slice(&[
bitcoin_primitives::PublicKey::from_slice(&[2; 33]).expect("key 1"),
bitcoin_primitives::PublicKey::from_slice(&[
0x02,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]).expect("key 2"),
bitcoin::PublicKey::from_slice(&[
bitcoin_primitives::PublicKey::from_slice(&[
0x03,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
Expand All @@ -126,6 +126,6 @@ fn random_signature_from_the_blockchain() -> ecdsa::Signature {
531d75c136272f127a5dc14acc0722301cbddc222262934151f140da345af177",
)
.unwrap(),
sighash_type: bitcoin::sighash::EcdsaSighashType::All,
sighash_type: bitcoin_primitives::sighash::EcdsaSighashType::All,
}
}
Loading

0 comments on commit 80cf6c1

Please sign in to comment.