Skip to content

Commit 4fc621a

Browse files
committed
Remove secp context
1 parent f8a7c62 commit 4fc621a

File tree

16 files changed

+152
-288
lines changed

16 files changed

+152
-288
lines changed

examples/big.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use miniscript::{
2020
translate_hash_fail, DefiniteDescriptorKey, Descriptor, DescriptorPublicKey, MiniscriptKey,
2121
Translator,
2222
};
23-
use secp256k1::Secp256k1;
23+
2424
fn main() {
2525
let empty = "".to_string();
2626
let mut args = std::env::args().collect::<Vec<_>>();
@@ -39,8 +39,7 @@ fn main() {
3939
.unwrap();
4040
println!("{}", a);
4141

42-
let secp = Secp256k1::new();
43-
let (d, m) = Descriptor::parse_descriptor(&secp, &i).unwrap();
42+
let (d, m) = Descriptor::parse_descriptor(&i).unwrap();
4443
use_descriptor(d);
4544
println!("{:?}", m);
4645

@@ -52,7 +51,7 @@ fn main() {
5251
println!("{:?}", h.address(bitcoin::Network::Bitcoin));
5352

5453
let psbt: bitcoin::Psbt = i.parse().unwrap();
55-
let psbt = psbt.finalize(&secp).unwrap();
54+
let psbt = psbt.finalize().unwrap();
5655
let mut tx = psbt.extract_tx().unwrap();
5756
println!("{:?}", tx);
5857

examples/psbt_sign_finalize.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ use miniscript::psbt::{PsbtExt, PsbtInputExt};
1818
use miniscript::Descriptor;
1919

2020
fn main() {
21-
let secp256k1 = secp256k1::Secp256k1::new();
22-
2321
let s = "wsh(t:or_c(pk(027a3565454fe1b749bccaef22aff72843a9c3efefd7b16ac54537a0c23f0ec0de),v:thresh(1,pkh(032d672a1a91cc39d154d366cd231983661b0785c7f27bc338447565844f4a6813),a:pkh(03417129311ed34c242c012cd0a3e0b9bca0065f742d0dfb63c78083ea6a02d4d9),a:pkh(025a687659658baeabdfc415164528065be7bcaade19342241941e556557f01e28))))#7hut9ukn";
2422
let bridge_descriptor = Descriptor::from_str(s).unwrap();
2523
//let bridge_descriptor = Descriptor::<bitcoin::PublicKey>::from_str(&s).expect("parse descriptor string");
@@ -142,7 +140,7 @@ fn main() {
142140
println!("{:#?}", psbt);
143141
println!("{}", psbt);
144142

145-
psbt.finalize_mut(&secp256k1).unwrap();
143+
psbt.finalize_mut().unwrap();
146144
println!("{:#?}", psbt);
147145

148146
let tx = psbt.extract_tx().expect("failed to extract tx");

examples/taptree_of_horror/helper_fns.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use bitcoin::bip32::{DerivationPath, Xpriv};
44
use bitcoin::hashes::{ripemd160, sha256};
55
use miniscript::descriptor::DescriptorSecretKey;
66
use miniscript::ToPublicKey;
7-
use secp256k1::Secp256k1;
87

98
use crate::KEYS_PER_PERSONA;
109

@@ -28,7 +27,6 @@ pub fn produce_kelly_hash(secret: &str) -> (sha256::Hash, sha256::Hash) {
2827

2928
pub fn produce_key_pairs(
3029
desc: DescriptorSecretKey,
31-
secp: &Secp256k1<secp256k1::All>,
3230
derivation_without_index: &str,
3331
_alias: &str,
3432
) -> (Vec<bitcoin::PublicKey>, Vec<Xpriv>) {
@@ -42,7 +40,7 @@ pub fn produce_key_pairs(
4240

4341
for i in 0..KEYS_PER_PERSONA {
4442
let pk = desc
45-
.to_public(secp)
43+
.to_public()
4644
.unwrap()
4745
.at_derivation_index(i.try_into().unwrap())
4846
.unwrap()

examples/taptree_of_horror/taptree_of_horror.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ mod helper_fns;
1515
pub const KEYS_PER_PERSONA: usize = 9;
1616

1717
fn main() {
18-
let secp: &secp256k1::Secp256k1<secp256k1::All> = &secp256k1::Secp256k1::new();
19-
2018
// ====== 1. Setup Hardcoded Values for all of the Personas ======
2119

2220
// Define derivation paths that will be used
@@ -59,7 +57,7 @@ fn main() {
5957
// ====== 2. Derive Keys, Preimages, Hashes, and Timelocks for Policy and Signing ======
6058

6159
let internal_xpub: miniscript::DescriptorPublicKey =
62-
internal_desc_secret.to_public(secp).unwrap();
60+
internal_desc_secret.to_public().unwrap();
6361

6462
// example of how defining the internal xpriv that can be used for signing.
6563
// let internal_xpriv: DescriptorXKey<bitcoin::bip32::Xpriv> = match internal_desc_secret {
@@ -68,20 +66,20 @@ fn main() {
6866
// }
6967
// .unwrap();
7068

71-
let (a_pks, a_prvs) = produce_key_pairs(a_descriptor_desc_secret, secp, normal_path, "alice");
72-
let (b_pks, b_prvs) = produce_key_pairs(b_descriptor_desc_secret, secp, normal_path, "bob");
73-
let (c_pks, c_prvs) = produce_key_pairs(c_descriptor_desc_secret, secp, normal_path, "charlie");
74-
let (d_pks, d_prvs) = produce_key_pairs(d_descriptor_desc_secret, secp, weird_path, "dave");
75-
let (e_pks, e_prvs) = produce_key_pairs(e_descriptor_desc_secret, secp, normal_path, "eve");
76-
let (f_pks, f_prvs) = produce_key_pairs(f_descriptor_desc_secret, secp, normal_path, "frank");
77-
let (h_pks, h_prvs) = produce_key_pairs(h_descriptor_desc_secret, secp, normal_path, "heather");
78-
let (i_pks, i_prvs) = produce_key_pairs(i_descriptor_desc_secret, secp, unhardened_path, "ian");
79-
let (j_pks, j_prvs) = produce_key_pairs(j_descriptor_desc_secret, secp, normal_path, "judy");
80-
let (l_pks, l_prvs) = produce_key_pairs(l_descriptor_desc_secret, secp, normal_path, "liam");
69+
let (a_pks, a_prvs) = produce_key_pairs(a_descriptor_desc_secret, normal_path, "alice");
70+
let (b_pks, b_prvs) = produce_key_pairs(b_descriptor_desc_secret, normal_path, "bob");
71+
let (c_pks, c_prvs) = produce_key_pairs(c_descriptor_desc_secret, normal_path, "charlie");
72+
let (d_pks, d_prvs) = produce_key_pairs(d_descriptor_desc_secret, weird_path, "dave");
73+
let (e_pks, e_prvs) = produce_key_pairs(e_descriptor_desc_secret, normal_path, "eve");
74+
let (f_pks, f_prvs) = produce_key_pairs(f_descriptor_desc_secret, normal_path, "frank");
75+
let (h_pks, h_prvs) = produce_key_pairs(h_descriptor_desc_secret, normal_path, "heather");
76+
let (i_pks, i_prvs) = produce_key_pairs(i_descriptor_desc_secret, unhardened_path, "ian");
77+
let (j_pks, j_prvs) = produce_key_pairs(j_descriptor_desc_secret, normal_path, "judy");
78+
let (l_pks, l_prvs) = produce_key_pairs(l_descriptor_desc_secret, normal_path, "liam");
8179
let (s_pks, _s_prvs) =
82-
produce_key_pairs(s_descriptor_desc_secret, secp, normal_path, "s_backup1");
80+
produce_key_pairs(s_descriptor_desc_secret, normal_path, "s_backup1");
8381
let (x_pks, _x_prvs) =
84-
produce_key_pairs(x_descriptor_desc_secret, secp, normal_path, "x_backup2");
82+
produce_key_pairs(x_descriptor_desc_secret, normal_path, "x_backup2");
8583

8684
// For this example we are grabbing the 9 keys for each persona
8785
let [a0, a1, a2, a3, a4, a5, a6, a7, a8]: [PublicKey; KEYS_PER_PERSONA] =
@@ -201,8 +199,6 @@ fn main() {
201199

202200
// ====== 4. Construct an Unsigned Transaction from the Tapscript ======
203201

204-
let secp: &secp256k1::Secp256k1<secp256k1::All> = &secp256k1::Secp256k1::new();
205-
206202
let tx_in = TxIn {
207203
previous_output: bitcoin::OutPoint {
208204
txid: "8888888899999999aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffff"
@@ -273,7 +269,7 @@ fn main() {
273269
.insert(grim.1, grim.0.to_byte_array().to_vec());
274270

275271
// Finalize PSBT now that we have all the required signatures and hash preimages.
276-
psbt.finalize_mut(secp).unwrap();
272+
psbt.finalize_mut().unwrap();
277273

278274
// Now extract the tx
279275
let signed_tx = psbt.extract_tx().unwrap();

examples/verify_tx.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::str::FromStr;
66

77
use miniscript::bitcoin::consensus::Decodable;
88
use miniscript::bitcoin::script::ScriptPubKeyBuf;
9-
use miniscript::bitcoin::secp256k1::Secp256k1;
109
use miniscript::bitcoin::{absolute, sighash, Sequence};
1110
use miniscript::interpreter::KeySigPair;
1211

@@ -64,13 +63,12 @@ fn main() {
6463
// as having participated in the script
6564

6665
println!("\n\nExample two:\n");
67-
let secp = Secp256k1::new();
6866

6967
// We can set prevouts to be empty list because this is a legacy transaction
7068
// and this information is not required for sighash computation.
7169
let prevouts = sighash::Prevouts::All::<bitcoin::TxOut>(&[]);
7270

73-
for elem in interpreter.iter(&secp, &tx, 0, &prevouts) {
71+
for elem in interpreter.iter(&tx, 0, &prevouts) {
7472
if let miniscript::interpreter::SatisfiedConstraint::PublicKey { key_sig } =
7573
elem.expect("no evaluation error")
7674
{

examples/xpub_descriptors.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,29 @@
44
55
use std::str::FromStr;
66

7-
use miniscript::bitcoin::secp256k1::{Secp256k1, Verification};
87
use miniscript::bitcoin::{Address, Network};
98
use miniscript::{DefiniteDescriptorKey, Descriptor, DescriptorPublicKey};
109

1110
const XPUB_1: &str = "xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB";
1211
const XPUB_2: &str = "xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH";
1312

1413
fn main() {
15-
// For deriving from descriptors, we need to provide a secp context.
16-
let secp = Secp256k1::verification_only();
17-
1814
// P2WSH and single xpubs.
19-
let _ = p2wsh(&secp);
15+
let _ = p2wsh();
2016

2117
// P2WSH-P2SH and ranged xpubs.
22-
let _ = p2sh_p2wsh(&secp);
18+
let _ = p2sh_p2wsh();
2319
}
2420

2521
/// Parses a P2WSH descriptor, returns the associated address.
26-
fn p2wsh<C: Verification>(secp: &Secp256k1<C>) -> Address {
22+
fn p2wsh() -> Address {
2723
// It does not matter what order the two xpubs go in, the same address will be generated.
2824
let s = format!("wsh(sortedmulti(1,{},{}))", XPUB_1, XPUB_2);
2925
// let s = format!("wsh(sortedmulti(1,{},{}))", XPUB_2, XPUB_1);
3026

3127
let address = Descriptor::<DefiniteDescriptorKey>::from_str(&s)
3228
.unwrap()
33-
.derived_descriptor(secp)
29+
.derived_descriptor()
3430
.address(Network::Bitcoin)
3531
.unwrap();
3632

@@ -45,14 +41,14 @@ fn p2wsh<C: Verification>(secp: &Secp256k1<C>) -> Address {
4541
}
4642

4743
/// Parses a P2SH-P2WSH descriptor, returns the associated address.
48-
fn p2sh_p2wsh<C: Verification>(secp: &Secp256k1<C>) -> Address {
44+
fn p2sh_p2wsh() -> Address {
4945
// It does not matter what order the two xpubs go in, the same address will be generated.
5046
let s = format!("sh(wsh(sortedmulti(1,{}/1/0/*,{}/0/0/*)))", XPUB_1, XPUB_2);
5147
// let s = format!("sh(wsh(sortedmulti(1,{}/1/0/*,{}/0/0/*)))", XPUB_2, XPUB_1);
5248

5349
let address = Descriptor::<DescriptorPublicKey>::from_str(&s)
5450
.unwrap()
55-
.derived_descriptor(secp, 5)
51+
.derived_descriptor(5)
5652
.unwrap()
5753
.address(Network::Bitcoin)
5854
.unwrap();

0 commit comments

Comments
 (0)