//! 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},
enum TrSpend {
KeySpend,
LeafSpend {
- script: Script,
+ script: ScriptBuf,
leaf_version: LeafVersion,
},
}
enum Target {
Legacy,
Segwitv0 {
- script_code: Script,
+ script_code: ScriptBuf,
},
Segwitv1 {
tr: Tr<DefiniteDescriptorKey>,
pub struct Plan<AK> {
template: Vec<TemplateItem<AK>>,
target: Target,
- set_locktime: Option<LockTime>,
+ set_locktime: Option<absolute::LockTime>,
set_sequence: Option<Sequence>,
}
/// 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
..
} => PlanState::Complete {
final_script_sig: None,
- final_script_witness: Some(Witness::from_vec(witness)),
+ final_script_witness: Some(Witness::from(witness)),
},
Target::Segwitv1 {
tr,
PlanState::Complete {
final_script_sig: None,
- final_script_witness: Some(Witness::from_vec(witness)),
+ final_script_witness: Some(Witness::from(witness)),
}
}
}
}
/// 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()
}
/// 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>,
},
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>,
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!();
+ }
}
}
}
use bdk_chain::{bitcoin, miniscript};
-use bitcoin::locktime::{Height, Time};
+use bitcoin::locktime::absolute;
use miniscript::Terminal;
use super::*;
#[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>>,
}
}
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 {
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::*;
/// 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 {
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,
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,
.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);
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,
};
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,
.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,
};
use bdk_chain::{bitcoin, miniscript};
use bitcoin::{
+ bip32::DerivationPath,
hashes::{hash160, ripemd160, sha256},
- util::bip32::DerivationPath,
};
use super::*;