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