Skip to content

Commit 468d2a0

Browse files
Update tmp_plan to rust-bitcoin 0.30.0
1 parent b8ac16d commit 468d2a0

File tree

4 files changed

+52
-32
lines changed

4 files changed

+52
-32
lines changed

nursery/tmp_plan/src/lib.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
//! witness/script_sig for the input.
1717
use bdk_chain::{bitcoin, collections::*, miniscript};
1818
use bitcoin::{
19-
blockdata::{locktime::LockTime, transaction::Sequence},
19+
absolute,
20+
address::WitnessVersion,
21+
bip32::{DerivationPath, Fingerprint, KeySource},
22+
blockdata::transaction::Sequence,
23+
ecdsa,
2024
hashes::{hash160, ripemd160, sha256},
2125
secp256k1::Secp256k1,
22-
util::{
23-
address::WitnessVersion,
24-
bip32::{DerivationPath, Fingerprint, KeySource},
25-
taproot::{LeafVersion, TapBranchHash, TapLeafHash},
26-
},
27-
EcdsaSig, SchnorrSig, Script, TxIn, Witness,
26+
taproot::{self, LeafVersion, TapLeafHash},
27+
ScriptBuf, TxIn, Witness,
2828
};
2929
use miniscript::{
3030
descriptor::{InnerXKey, Tr},
@@ -46,7 +46,7 @@ use template::TemplateItem;
4646
enum TrSpend {
4747
KeySpend,
4848
LeafSpend {
49-
script: Script,
49+
script: ScriptBuf,
5050
leaf_version: LeafVersion,
5151
},
5252
}
@@ -55,7 +55,7 @@ enum TrSpend {
5555
enum Target {
5656
Legacy,
5757
Segwitv0 {
58-
script_code: Script,
58+
script_code: ScriptBuf,
5959
},
6060
Segwitv1 {
6161
tr: Tr<DefiniteDescriptorKey>,
@@ -72,7 +72,7 @@ impl Target {}
7272
pub struct Plan<AK> {
7373
template: Vec<TemplateItem<AK>>,
7474
target: Target,
75-
set_locktime: Option<LockTime>,
75+
set_locktime: Option<absolute::LockTime>,
7676
set_sequence: Option<Sequence>,
7777
}
7878

@@ -86,9 +86,9 @@ impl Default for Target {
8686
/// Signatures and hash pre-images that can be used to complete a plan.
8787
pub struct SatisfactionMaterial {
8888
/// Schnorr signautres under their keys
89-
pub schnorr_sigs: BTreeMap<DefiniteDescriptorKey, SchnorrSig>,
89+
pub schnorr_sigs: BTreeMap<DefiniteDescriptorKey, taproot::Signature>,
9090
/// ECDSA signatures under their keys
91-
pub ecdsa_sigs: BTreeMap<DefiniteDescriptorKey, EcdsaSig>,
91+
pub ecdsa_sigs: BTreeMap<DefiniteDescriptorKey, ecdsa::Signature>,
9292
/// SHA256 pre-images under their images
9393
pub sha256_preimages: BTreeMap<sha256::Hash, Vec<u8>>,
9494
/// hash160 pre-images under their images
@@ -201,7 +201,7 @@ where
201201
..
202202
} => PlanState::Complete {
203203
final_script_sig: None,
204-
final_script_witness: Some(Witness::from_vec(witness)),
204+
final_script_witness: Some(Witness::from(witness)),
205205
},
206206
Target::Segwitv1 {
207207
tr,
@@ -220,7 +220,7 @@ where
220220

221221
PlanState::Complete {
222222
final_script_sig: None,
223-
final_script_witness: Some(Witness::from_vec(witness)),
223+
final_script_witness: Some(Witness::from(witness)),
224224
}
225225
}
226226
}
@@ -306,7 +306,7 @@ where
306306
}
307307

308308
/// The minimum required locktime height or time on the transaction using the plan.
309-
pub fn required_locktime(&self) -> Option<LockTime> {
309+
pub fn required_locktime(&self) -> Option<absolute::LockTime> {
310310
self.set_locktime.clone()
311311
}
312312

@@ -330,7 +330,7 @@ pub enum PlanState<Ak> {
330330
/// The plan is complete
331331
Complete {
332332
/// The script sig that should be set on the input
333-
final_script_sig: Option<Script>,
333+
final_script_sig: Option<ScriptBuf>,
334334
/// The witness that should be set on the input
335335
final_script_witness: Option<Witness>,
336336
},
@@ -341,7 +341,7 @@ pub enum PlanState<Ak> {
341341
pub struct Assets<K> {
342342
pub keys: Vec<K>,
343343
pub txo_age: Option<Sequence>,
344-
pub max_locktime: Option<LockTime>,
344+
pub max_locktime: Option<absolute::LockTime>,
345345
pub sha256: Vec<sha256::Hash>,
346346
pub hash256: Vec<hash256::Hash>,
347347
pub ripemd160: Vec<ripemd160::Hash>,
@@ -380,6 +380,11 @@ impl CanDerive for KeySource {
380380

381381
path_to_child(self, &origin, Some(&dxk.derivation_path))
382382
}
383+
DescriptorPublicKey::MultiXPub(_) => {
384+
// This crate will be replaced by
385+
// https://github.com/rust-bitcoin/rust-miniscript/pull/481 anyways
386+
todo!();
387+
}
383388
}
384389
}
385390
}

nursery/tmp_plan/src/plan_impls.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bdk_chain::{bitcoin, miniscript};
2-
use bitcoin::locktime::{Height, Time};
2+
use bitcoin::locktime::absolute;
33
use miniscript::Terminal;
44

55
use super::*;
@@ -154,7 +154,7 @@ where
154154

155155
#[derive(Debug)]
156156
struct TermPlan<Ak> {
157-
pub min_locktime: Option<LockTime>,
157+
pub min_locktime: Option<absolute::LockTime>,
158158
pub min_sequence: Option<Sequence>,
159159
pub template: Vec<TemplateItem<Ak>>,
160160
}
@@ -216,10 +216,12 @@ fn plan_steps<Ak: Clone + CanDerive, Ctx: ScriptContext>(
216216
}
217217
Terminal::After(locktime) => {
218218
let max_locktime = assets.max_locktime?;
219-
let locktime = LockTime::from(locktime);
219+
let locktime = absolute::LockTime::from(*locktime);
220220
let (height, time) = match max_locktime {
221-
LockTime::Blocks(height) => (height, Time::from_consensus(0).unwrap()),
222-
LockTime::Seconds(seconds) => (Height::from_consensus(0).unwrap(), seconds),
221+
absolute::LockTime::Blocks(height) => {
222+
(height, absolute::Time::from_consensus(0).unwrap())
223+
}
224+
absolute::LockTime::Seconds(seconds) => (absolute::Height::ZERO, seconds),
223225
};
224226
if max_locktime.is_satisfied_by(height, time) {
225227
Some(TermPlan {

nursery/tmp_plan/src/requirements.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ use bdk_chain::{bitcoin, collections::*, miniscript};
22
use core::ops::Deref;
33

44
use bitcoin::{
5+
bip32,
56
hashes::{hash160, ripemd160, sha256},
7+
key::XOnlyPublicKey,
68
psbt::Prevouts,
79
secp256k1::{KeyPair, Message, PublicKey, Signing, Verification},
8-
util::{bip32, sighash, sighash::SighashCache, taproot},
9-
EcdsaSighashType, SchnorrSighashType, Transaction, TxOut, XOnlyPublicKey,
10+
sighash,
11+
sighash::{EcdsaSighashType, SighashCache, TapSighashType},
12+
taproot, Transaction, TxOut,
1013
};
1114

1215
use super::*;
@@ -72,7 +75,7 @@ pub enum RequiredSignatures<Ak> {
7275
/// the internal key
7376
plan_key: PlanKey<Ak>,
7477
/// The merkle root of the taproot output
75-
merkle_root: Option<TapBranchHash>,
78+
merkle_root: Option<taproot::TapNodeHash>,
7679
},
7780
/// Taproot script path signatures are required
7881
TapScript {
@@ -114,12 +117,12 @@ impl From<bip32::Error> for SigningError {
114117
impl std::error::Error for SigningError {}
115118

116119
impl RequiredSignatures<DescriptorPublicKey> {
117-
pub fn sign_with_keymap<T: Deref<Target = Transaction>>(
120+
pub fn sign_with_keymap<T: core::borrow::Borrow<Transaction>>(
118121
&self,
119122
input_index: usize,
120123
keymap: &KeyMap,
121124
prevouts: &Prevouts<'_, impl core::borrow::Borrow<TxOut>>,
122-
schnorr_sighashty: Option<SchnorrSighashType>,
125+
schnorr_sighashty: Option<TapSighashType>,
123126
_ecdsa_sighashty: Option<EcdsaSighashType>,
124127
sighash_cache: &mut SighashCache<T>,
125128
auth_data: &mut SatisfactionMaterial,
@@ -131,7 +134,7 @@ impl RequiredSignatures<DescriptorPublicKey> {
131134
plan_key,
132135
merkle_root,
133136
} => {
134-
let schnorr_sighashty = schnorr_sighashty.unwrap_or(SchnorrSighashType::Default);
137+
let schnorr_sighashty = schnorr_sighashty.unwrap_or(TapSighashType::Default);
135138
let sighash = sighash_cache.taproot_key_spend_signature_hash(
136139
input_index,
137140
prevouts,
@@ -148,6 +151,11 @@ impl RequiredSignatures<DescriptorPublicKey> {
148151
.derive_priv(&secp, &plan_key.derivation_hint)?
149152
.private_key
150153
}
154+
DescriptorSecretKey::MultiXPrv(_) => {
155+
// This crate will be replaced by
156+
// https://github.com/rust-bitcoin/rust-miniscript/pull/481 anyways
157+
todo!();
158+
}
151159
};
152160

153161
let pubkey = PublicKey::from_secret_key(&secp, &secret_key);
@@ -162,7 +170,7 @@ impl RequiredSignatures<DescriptorPublicKey> {
162170
let msg = Message::from_slice(sighash.as_ref()).expect("Sighashes are 32 bytes");
163171
let sig = secp.sign_schnorr_no_aux_rand(&msg, &keypair);
164172

165-
let bitcoin_sig = SchnorrSig {
173+
let bitcoin_sig = taproot::Signature {
166174
sig,
167175
hash_ty: schnorr_sighashty,
168176
};
@@ -176,7 +184,7 @@ impl RequiredSignatures<DescriptorPublicKey> {
176184
leaf_hash,
177185
plan_keys,
178186
} => {
179-
let sighash_type = schnorr_sighashty.unwrap_or(SchnorrSighashType::Default);
187+
let sighash_type = schnorr_sighashty.unwrap_or(TapSighashType::Default);
180188
let sighash = sighash_cache.taproot_script_spend_signature_hash(
181189
input_index,
182190
prevouts,
@@ -195,12 +203,17 @@ impl RequiredSignatures<DescriptorPublicKey> {
195203
.derive_priv(&secp, &plan_key.derivation_hint)?
196204
.private_key
197205
}
206+
DescriptorSecretKey::MultiXPrv(_) => {
207+
// This crate will be replaced by
208+
// https://github.com/rust-bitcoin/rust-miniscript/pull/481 anyways
209+
todo!();
210+
}
198211
};
199212
let keypair = KeyPair::from_secret_key(&secp, &secret_key.clone());
200213
let msg =
201214
Message::from_slice(sighash.as_ref()).expect("Sighashes are 32 bytes");
202215
let sig = secp.sign_schnorr_no_aux_rand(&msg, &keypair);
203-
let bitcoin_sig = SchnorrSig {
216+
let bitcoin_sig = taproot::Signature {
204217
sig,
205218
hash_ty: sighash_type,
206219
};

nursery/tmp_plan/src/template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bdk_chain::{bitcoin, miniscript};
22
use bitcoin::{
3+
bip32::DerivationPath,
34
hashes::{hash160, ripemd160, sha256},
4-
util::bip32::DerivationPath,
55
};
66

77
use super::*;

0 commit comments

Comments
 (0)