Update tmp_plan to rust-bitcoin 0.30.0
This commit is contained in:
parent
b8ac16d03c
commit
468d2a0a3b
@ -16,15 +16,15 @@
|
||||
//! witness/script_sig for the input.
|
||||
use bdk_chain::{bitcoin, collections::*, miniscript};
|
||||
use bitcoin::{
|
||||
blockdata::{locktime::LockTime, transaction::Sequence},
|
||||
absolute,
|
||||
address::WitnessVersion,
|
||||
bip32::{DerivationPath, Fingerprint, KeySource},
|
||||
blockdata::transaction::Sequence,
|
||||
ecdsa,
|
||||
hashes::{hash160, ripemd160, sha256},
|
||||
secp256k1::Secp256k1,
|
||||
util::{
|
||||
address::WitnessVersion,
|
||||
bip32::{DerivationPath, Fingerprint, KeySource},
|
||||
taproot::{LeafVersion, TapBranchHash, TapLeafHash},
|
||||
},
|
||||
EcdsaSig, SchnorrSig, Script, TxIn, Witness,
|
||||
taproot::{self, LeafVersion, TapLeafHash},
|
||||
ScriptBuf, TxIn, Witness,
|
||||
};
|
||||
use miniscript::{
|
||||
descriptor::{InnerXKey, Tr},
|
||||
@ -46,7 +46,7 @@ use template::TemplateItem;
|
||||
enum TrSpend {
|
||||
KeySpend,
|
||||
LeafSpend {
|
||||
script: Script,
|
||||
script: ScriptBuf,
|
||||
leaf_version: LeafVersion,
|
||||
},
|
||||
}
|
||||
@ -55,7 +55,7 @@ enum TrSpend {
|
||||
enum Target {
|
||||
Legacy,
|
||||
Segwitv0 {
|
||||
script_code: Script,
|
||||
script_code: ScriptBuf,
|
||||
},
|
||||
Segwitv1 {
|
||||
tr: Tr<DefiniteDescriptorKey>,
|
||||
@ -72,7 +72,7 @@ impl Target {}
|
||||
pub struct Plan<AK> {
|
||||
template: Vec<TemplateItem<AK>>,
|
||||
target: Target,
|
||||
set_locktime: Option<LockTime>,
|
||||
set_locktime: Option<absolute::LockTime>,
|
||||
set_sequence: Option<Sequence>,
|
||||
}
|
||||
|
||||
@ -86,9 +86,9 @@ impl Default for Target {
|
||||
/// Signatures and hash pre-images that can be used to complete a plan.
|
||||
pub struct SatisfactionMaterial {
|
||||
/// Schnorr signautres under their keys
|
||||
pub schnorr_sigs: BTreeMap<DefiniteDescriptorKey, SchnorrSig>,
|
||||
pub schnorr_sigs: BTreeMap<DefiniteDescriptorKey, taproot::Signature>,
|
||||
/// ECDSA signatures under their keys
|
||||
pub ecdsa_sigs: BTreeMap<DefiniteDescriptorKey, EcdsaSig>,
|
||||
pub ecdsa_sigs: BTreeMap<DefiniteDescriptorKey, ecdsa::Signature>,
|
||||
/// SHA256 pre-images under their images
|
||||
pub sha256_preimages: BTreeMap<sha256::Hash, Vec<u8>>,
|
||||
/// hash160 pre-images under their images
|
||||
@ -201,7 +201,7 @@ where
|
||||
..
|
||||
} => PlanState::Complete {
|
||||
final_script_sig: None,
|
||||
final_script_witness: Some(Witness::from_vec(witness)),
|
||||
final_script_witness: Some(Witness::from(witness)),
|
||||
},
|
||||
Target::Segwitv1 {
|
||||
tr,
|
||||
@ -220,7 +220,7 @@ where
|
||||
|
||||
PlanState::Complete {
|
||||
final_script_sig: None,
|
||||
final_script_witness: Some(Witness::from_vec(witness)),
|
||||
final_script_witness: Some(Witness::from(witness)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -306,7 +306,7 @@ where
|
||||
}
|
||||
|
||||
/// The minimum required locktime height or time on the transaction using the plan.
|
||||
pub fn required_locktime(&self) -> Option<LockTime> {
|
||||
pub fn required_locktime(&self) -> Option<absolute::LockTime> {
|
||||
self.set_locktime.clone()
|
||||
}
|
||||
|
||||
@ -330,7 +330,7 @@ pub enum PlanState<Ak> {
|
||||
/// The plan is complete
|
||||
Complete {
|
||||
/// The script sig that should be set on the input
|
||||
final_script_sig: Option<Script>,
|
||||
final_script_sig: Option<ScriptBuf>,
|
||||
/// The witness that should be set on the input
|
||||
final_script_witness: Option<Witness>,
|
||||
},
|
||||
@ -341,7 +341,7 @@ pub enum PlanState<Ak> {
|
||||
pub struct Assets<K> {
|
||||
pub keys: Vec<K>,
|
||||
pub txo_age: Option<Sequence>,
|
||||
pub max_locktime: Option<LockTime>,
|
||||
pub max_locktime: Option<absolute::LockTime>,
|
||||
pub sha256: Vec<sha256::Hash>,
|
||||
pub hash256: Vec<hash256::Hash>,
|
||||
pub ripemd160: Vec<ripemd160::Hash>,
|
||||
@ -380,6 +380,11 @@ impl CanDerive for KeySource {
|
||||
|
||||
path_to_child(self, &origin, Some(&dxk.derivation_path))
|
||||
}
|
||||
DescriptorPublicKey::MultiXPub(_) => {
|
||||
// This crate will be replaced by
|
||||
// https://github.com/rust-bitcoin/rust-miniscript/pull/481 anyways
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use bdk_chain::{bitcoin, miniscript};
|
||||
use bitcoin::locktime::{Height, Time};
|
||||
use bitcoin::locktime::absolute;
|
||||
use miniscript::Terminal;
|
||||
|
||||
use super::*;
|
||||
@ -154,7 +154,7 @@ where
|
||||
|
||||
#[derive(Debug)]
|
||||
struct TermPlan<Ak> {
|
||||
pub min_locktime: Option<LockTime>,
|
||||
pub min_locktime: Option<absolute::LockTime>,
|
||||
pub min_sequence: Option<Sequence>,
|
||||
pub template: Vec<TemplateItem<Ak>>,
|
||||
}
|
||||
@ -216,10 +216,12 @@ fn plan_steps<Ak: Clone + CanDerive, Ctx: ScriptContext>(
|
||||
}
|
||||
Terminal::After(locktime) => {
|
||||
let max_locktime = assets.max_locktime?;
|
||||
let locktime = LockTime::from(locktime);
|
||||
let locktime = absolute::LockTime::from(*locktime);
|
||||
let (height, time) = match max_locktime {
|
||||
LockTime::Blocks(height) => (height, Time::from_consensus(0).unwrap()),
|
||||
LockTime::Seconds(seconds) => (Height::from_consensus(0).unwrap(), seconds),
|
||||
absolute::LockTime::Blocks(height) => {
|
||||
(height, absolute::Time::from_consensus(0).unwrap())
|
||||
}
|
||||
absolute::LockTime::Seconds(seconds) => (absolute::Height::ZERO, seconds),
|
||||
};
|
||||
if max_locktime.is_satisfied_by(height, time) {
|
||||
Some(TermPlan {
|
||||
|
@ -2,11 +2,14 @@ use bdk_chain::{bitcoin, collections::*, miniscript};
|
||||
use core::ops::Deref;
|
||||
|
||||
use bitcoin::{
|
||||
bip32,
|
||||
hashes::{hash160, ripemd160, sha256},
|
||||
key::XOnlyPublicKey,
|
||||
psbt::Prevouts,
|
||||
secp256k1::{KeyPair, Message, PublicKey, Signing, Verification},
|
||||
util::{bip32, sighash, sighash::SighashCache, taproot},
|
||||
EcdsaSighashType, SchnorrSighashType, Transaction, TxOut, XOnlyPublicKey,
|
||||
sighash,
|
||||
sighash::{EcdsaSighashType, SighashCache, TapSighashType},
|
||||
taproot, Transaction, TxOut,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
@ -72,7 +75,7 @@ pub enum RequiredSignatures<Ak> {
|
||||
/// the internal key
|
||||
plan_key: PlanKey<Ak>,
|
||||
/// The merkle root of the taproot output
|
||||
merkle_root: Option<TapBranchHash>,
|
||||
merkle_root: Option<taproot::TapNodeHash>,
|
||||
},
|
||||
/// Taproot script path signatures are required
|
||||
TapScript {
|
||||
@ -114,12 +117,12 @@ impl From<bip32::Error> for SigningError {
|
||||
impl std::error::Error for SigningError {}
|
||||
|
||||
impl RequiredSignatures<DescriptorPublicKey> {
|
||||
pub fn sign_with_keymap<T: Deref<Target = Transaction>>(
|
||||
pub fn sign_with_keymap<T: core::borrow::Borrow<Transaction>>(
|
||||
&self,
|
||||
input_index: usize,
|
||||
keymap: &KeyMap,
|
||||
prevouts: &Prevouts<'_, impl core::borrow::Borrow<TxOut>>,
|
||||
schnorr_sighashty: Option<SchnorrSighashType>,
|
||||
schnorr_sighashty: Option<TapSighashType>,
|
||||
_ecdsa_sighashty: Option<EcdsaSighashType>,
|
||||
sighash_cache: &mut SighashCache<T>,
|
||||
auth_data: &mut SatisfactionMaterial,
|
||||
@ -131,7 +134,7 @@ impl RequiredSignatures<DescriptorPublicKey> {
|
||||
plan_key,
|
||||
merkle_root,
|
||||
} => {
|
||||
let schnorr_sighashty = schnorr_sighashty.unwrap_or(SchnorrSighashType::Default);
|
||||
let schnorr_sighashty = schnorr_sighashty.unwrap_or(TapSighashType::Default);
|
||||
let sighash = sighash_cache.taproot_key_spend_signature_hash(
|
||||
input_index,
|
||||
prevouts,
|
||||
@ -148,6 +151,11 @@ impl RequiredSignatures<DescriptorPublicKey> {
|
||||
.derive_priv(&secp, &plan_key.derivation_hint)?
|
||||
.private_key
|
||||
}
|
||||
DescriptorSecretKey::MultiXPrv(_) => {
|
||||
// This crate will be replaced by
|
||||
// https://github.com/rust-bitcoin/rust-miniscript/pull/481 anyways
|
||||
todo!();
|
||||
}
|
||||
};
|
||||
|
||||
let pubkey = PublicKey::from_secret_key(&secp, &secret_key);
|
||||
@ -162,7 +170,7 @@ impl RequiredSignatures<DescriptorPublicKey> {
|
||||
let msg = Message::from_slice(sighash.as_ref()).expect("Sighashes are 32 bytes");
|
||||
let sig = secp.sign_schnorr_no_aux_rand(&msg, &keypair);
|
||||
|
||||
let bitcoin_sig = SchnorrSig {
|
||||
let bitcoin_sig = taproot::Signature {
|
||||
sig,
|
||||
hash_ty: schnorr_sighashty,
|
||||
};
|
||||
@ -176,7 +184,7 @@ impl RequiredSignatures<DescriptorPublicKey> {
|
||||
leaf_hash,
|
||||
plan_keys,
|
||||
} => {
|
||||
let sighash_type = schnorr_sighashty.unwrap_or(SchnorrSighashType::Default);
|
||||
let sighash_type = schnorr_sighashty.unwrap_or(TapSighashType::Default);
|
||||
let sighash = sighash_cache.taproot_script_spend_signature_hash(
|
||||
input_index,
|
||||
prevouts,
|
||||
@ -195,12 +203,17 @@ impl RequiredSignatures<DescriptorPublicKey> {
|
||||
.derive_priv(&secp, &plan_key.derivation_hint)?
|
||||
.private_key
|
||||
}
|
||||
DescriptorSecretKey::MultiXPrv(_) => {
|
||||
// This crate will be replaced by
|
||||
// https://github.com/rust-bitcoin/rust-miniscript/pull/481 anyways
|
||||
todo!();
|
||||
}
|
||||
};
|
||||
let keypair = KeyPair::from_secret_key(&secp, &secret_key.clone());
|
||||
let msg =
|
||||
Message::from_slice(sighash.as_ref()).expect("Sighashes are 32 bytes");
|
||||
let sig = secp.sign_schnorr_no_aux_rand(&msg, &keypair);
|
||||
let bitcoin_sig = SchnorrSig {
|
||||
let bitcoin_sig = taproot::Signature {
|
||||
sig,
|
||||
hash_ty: sighash_type,
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
use bdk_chain::{bitcoin, miniscript};
|
||||
use bitcoin::{
|
||||
bip32::DerivationPath,
|
||||
hashes::{hash160, ripemd160, sha256},
|
||||
util::bip32::DerivationPath,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
Loading…
x
Reference in New Issue
Block a user