diff --git a/Cargo.toml b/Cargo.toml index 5431b5ab..30890edf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,9 @@ base64 = ["bitcoin/base64"] [dependencies] bitcoin = "0.30.0" -elements = "0.22.0" +elements = "0.23.0" bitcoin-miniscript = { package = "miniscript", version = "10.0" } -simplicity = { git = "https://github.com/BlockstreamResearch/rust-simplicity", rev = "8ed4d4e0caf550148f1e17784af7665bad74b384" } +simplicity = { git = "https://github.com/BlockstreamResearch/rust-simplicity", rev = "d5c0d65320816bfdf36411feed4bdff0708b5b12" } # Do NOT use this as a feature! Use the `serde` feature instead. actual-serde = { package = "serde", version = "1.0", optional = true } diff --git a/bitcoind-tests/tests/test_arith.rs b/bitcoind-tests/tests/test_arith.rs index 3d2660de..a9a9e792 100644 --- a/bitcoind-tests/tests/test_arith.rs +++ b/bitcoind-tests/tests/test_arith.rs @@ -4,7 +4,7 @@ //! use elements::pset::PartiallySignedTransaction as Psbt; -use elements::sighash::SigHashCache; +use elements::sighash::SighashCache; use elements::taproot::TapLeafHash; use elements::{ confidential, pset as psbt, secp256k1_zkp as secp256k1, sighash, OutPoint, Script, Sequence, @@ -97,10 +97,10 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec // Get all the pubkeys and the corresponding secret keys let unsigned_tx = &psbt.extract_tx().unwrap(); - let mut sighash_cache = SigHashCache::new(unsigned_tx); + let mut sighash_cache = SighashCache::new(unsigned_tx); match derived_desc { Descriptor::TrExt(ref tr) => { - let hash_ty = sighash::SchnorrSigHashType::Default; + let hash_ty = sighash::SchnorrSighashType::Default; let prevouts = [witness_utxo]; let prevouts = sighash::Prevouts::All(&prevouts); diff --git a/bitcoind-tests/tests/test_cpp.rs b/bitcoind-tests/tests/test_cpp.rs index 180e757a..0b24e8c6 100644 --- a/bitcoind-tests/tests/test_cpp.rs +++ b/bitcoind-tests/tests/test_cpp.rs @@ -142,8 +142,8 @@ pub fn test_from_cpp_ms(cl: &ElementsD, testdata: &TestData) { // Get the required sighash message let amt = confidential::Value::Explicit(100_000_000); let unsigned_tx = psbts[i].extract_tx().unwrap(); - let mut sighash_cache = elements::sighash::SigHashCache::new(&unsigned_tx); - let sighash_ty = elements::EcdsaSigHashType::All; + let mut sighash_cache = elements::sighash::SighashCache::new(&unsigned_tx); + let sighash_ty = elements::EcdsaSighashType::All; let sighash = sighash_cache.segwitv0_sighash(0, &ms.encode(), amt, sighash_ty); // requires both signing and verification because we check the tx diff --git a/bitcoind-tests/tests/test_csfs.rs b/bitcoind-tests/tests/test_csfs.rs index ffa26bdd..f10e6a0d 100644 --- a/bitcoind-tests/tests/test_csfs.rs +++ b/bitcoind-tests/tests/test_csfs.rs @@ -4,7 +4,7 @@ //! use elements::pset::PartiallySignedTransaction as Psbt; -use elements::sighash::SigHashCache; +use elements::sighash::SighashCache; use elements::taproot::TapLeafHash; use elements::{ confidential, pset as psbt, secp256k1_zkp as secp256k1, sighash, OutPoint, Script, Sequence, @@ -98,10 +98,10 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec // Get all the pubkeys and the corresponding secret keys let unsigned_tx = &psbt.extract_tx().unwrap(); - let mut sighash_cache = SigHashCache::new(unsigned_tx); + let mut sighash_cache = SighashCache::new(unsigned_tx); match derived_desc { Descriptor::TrExt(ref tr) => { - let hash_ty = sighash::SchnorrSigHashType::Default; + let hash_ty = sighash::SchnorrSighashType::Default; let prevouts = [witness_utxo]; let prevouts = sighash::Prevouts::All(&prevouts); diff --git a/bitcoind-tests/tests/test_desc.rs b/bitcoind-tests/tests/test_desc.rs index e7f4b95f..34c808f9 100644 --- a/bitcoind-tests/tests/test_desc.rs +++ b/bitcoind-tests/tests/test_desc.rs @@ -8,7 +8,7 @@ use std::{error, fmt}; use elements::hashes::{sha256d, Hash}; use elements::pset::PartiallySignedTransaction as Psbt; -use elements::sighash::SigHashCache; +use elements::sighash::SighashCache; use elements::taproot::TapLeafHash; use elements::{ confidential, pset as psbt, secp256k1_zkp as secp256k1, sighash, OutPoint, SchnorrSig, Script, @@ -133,11 +133,11 @@ pub fn test_desc_satisfy( // Get all the pubkeys and the corresponding secret keys let unsigned_tx = &psbt.extract_tx().unwrap(); - let mut sighash_cache = SigHashCache::new(unsigned_tx); + let mut sighash_cache = SighashCache::new(unsigned_tx); match derived_desc { Descriptor::Tr(ref tr) => { // Fixme: take a parameter - let hash_ty = sighash::SchnorrSigHashType::Default; + let hash_ty = sighash::SchnorrSighashType::Default; let internal_key_present = x_only_pks .iter() @@ -251,7 +251,7 @@ pub fn test_desc_satisfy( .to_secp_msg(); // Fixme: Take a parameter - let hash_ty = elements::EcdsaSigHashType::All; + let hash_ty = elements::EcdsaSighashType::All; // Finally construct the signature and add to psbt for sk in sks_reqd { diff --git a/bitcoind-tests/tests/test_introspect.rs b/bitcoind-tests/tests/test_introspect.rs index 811da104..86fb26fa 100644 --- a/bitcoind-tests/tests/test_introspect.rs +++ b/bitcoind-tests/tests/test_introspect.rs @@ -4,7 +4,7 @@ //! use elements::pset::PartiallySignedTransaction as Psbt; -use elements::sighash::SigHashCache; +use elements::sighash::SighashCache; use elements::taproot::TapLeafHash; use elements::{ confidential, pset as psbt, secp256k1_zkp as secp256k1, sighash, OutPoint, Script, Sequence, @@ -97,10 +97,10 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec // Get all the pubkeys and the corresponding secret keys let unsigned_tx = &psbt.extract_tx().unwrap(); - let mut sighash_cache = SigHashCache::new(unsigned_tx); + let mut sighash_cache = SighashCache::new(unsigned_tx); match derived_desc { Descriptor::TrExt(ref tr) => { - let hash_ty = sighash::SchnorrSigHashType::Default; + let hash_ty = sighash::SchnorrSighashType::Default; let prevouts = [witness_utxo]; let prevouts = sighash::Prevouts::All(&prevouts); diff --git a/examples/psbt_sign_finalize.rs b/examples/psbt_sign_finalize.rs index 1d5a8a4b..616f068f 100644 --- a/examples/psbt_sign_finalize.rs +++ b/examples/psbt_sign_finalize.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use elements::bitcoin::PrivateKey; use elements::encode::{serialize, serialize_hex}; use elements::hashes::Hash; -use elements::sighash::SigHashCache; +use elements::sighash::SighashCache; use elements::{confidential, AssetId, LockTime, TxOutWitness}; use miniscript::elements::pset::PartiallySignedTransaction as Psbt; use miniscript::elements::{ @@ -135,7 +135,7 @@ fn main() { psbt.inputs_mut()[0].witness_utxo = Some(witness_utxo); let tx = &psbt.extract_tx().unwrap(); - let mut sighash_cache = SigHashCache::new(tx); + let mut sighash_cache = SighashCache::new(tx); // genesis hash is not used at all for sighash calculation let genesis_hash = elements::BlockHash::all_zeros(); @@ -145,7 +145,7 @@ fn main() { .to_secp_msg(); // Fixme: Take a parameter - let hash_ty = elements::EcdsaSigHashType::All; + let hash_ty = elements::EcdsaSighashType::All; let sk1 = backup1_private.inner; let sk2 = backup2_private.inner; diff --git a/examples/sign_multisig.rs b/examples/sign_multisig.rs index 6da5d93b..2f046906 100644 --- a/examples/sign_multisig.rs +++ b/examples/sign_multisig.rs @@ -75,7 +75,7 @@ fn main() { 531d75c136272f127a5dc14acc0722301cbddc222262934151f140da345af177", ) .unwrap(), - elements::EcdsaSigHashType::All, + elements::EcdsaSighashType::All, ); let descriptor_str = format!( diff --git a/examples/verify_tx.rs b/examples/verify_tx.rs index 751025ee..d8c6e83b 100644 --- a/examples/verify_tx.rs +++ b/examples/verify_tx.rs @@ -133,7 +133,7 @@ fn main() { let iter = interpreter.iter_custom( Box::new(|key_sig: &KeySigPair| { let (pk, ecdsa_sig) = key_sig.as_ecdsa().expect("Ecdsa Sig"); - ecdsa_sig.1 == elements::EcdsaSigHashType::All + ecdsa_sig.1 == elements::EcdsaSighashType::All && secp.verify_ecdsa(&message, &ecdsa_sig.0, &pk.inner).is_ok() }), None, // txenv diff --git a/src/descriptor/csfs_cov/mod.rs b/src/descriptor/csfs_cov/mod.rs index 8b01647e..0ef29c89 100644 --- a/src/descriptor/csfs_cov/mod.rs +++ b/src/descriptor/csfs_cov/mod.rs @@ -64,7 +64,7 @@ mod tests { use elements::secp256k1_zkp::ZERO_TWEAK; use elements::{ self, confidential, opcodes, script, secp256k1_zkp, AssetId, AssetIssuance, - EcdsaSigHashType, LockTime, OutPoint, Script, Sequence, Transaction, TxIn, TxInWitness, + EcdsaSighashType, LockTime, OutPoint, Script, Sequence, Transaction, TxIn, TxInWitness, TxOut, Txid, }; @@ -225,7 +225,7 @@ mod tests { 0, confidential::Value::Explicit(200_000), &script_code, - EcdsaSigHashType::All, + EcdsaSighashType::All, ); // Create a signature to sign the input @@ -236,7 +236,7 @@ mod tests { &secp256k1_zkp::Message::from_slice(&sighash_u256[..]).unwrap(), &cov_sk, ); - let el_sig = (sig, EcdsaSigHashType::All); + let el_sig = (sig, EcdsaSighashType::All); // For satisfying the Pk part of the covenant struct SimpleSat { @@ -284,7 +284,7 @@ mod tests { assert_eq!( constraints.last().unwrap(), &SatisfiedConstraint::PublicKey { - key_sig: interpreter::KeySigPair::Ecdsa(desc.pk, (sig, EcdsaSigHashType::All)) + key_sig: interpreter::KeySigPair::Ecdsa(desc.pk, (sig, EcdsaSighashType::All)) } ); Ok(()) @@ -429,7 +429,7 @@ mod tests { 0, confidential::Value::Explicit(200_000), &script_code, - EcdsaSigHashType::All, + EcdsaSighashType::All, ); // Create a signature to sign the input @@ -440,7 +440,7 @@ mod tests { &secp256k1_zkp::Message::from_slice(&sighash_u256[..]).unwrap(), &sks[0], ); - let sig = (sig, EcdsaSigHashType::All); + let sig = (sig, EcdsaSighashType::All); // For satisfying the Pk part of the covenant struct SimpleSat { diff --git a/src/descriptor/csfs_cov/satisfy.rs b/src/descriptor/csfs_cov/satisfy.rs index 6490c73e..d65077ef 100644 --- a/src/descriptor/csfs_cov/satisfy.rs +++ b/src/descriptor/csfs_cov/satisfy.rs @@ -16,8 +16,8 @@ use elements::encode::Encodable; use elements::hashes::{sha256d, Hash}; -use elements::sighash::SigHashCache; -use elements::{self, confidential, EcdsaSigHashType, OutPoint, Script, SigHash, Transaction}; +use elements::sighash::SighashCache; +use elements::{self, confidential, EcdsaSighashType, OutPoint, Script, Sighash, Transaction}; use super::CovError; use crate::{MiniscriptKey, Satisfier, ToPublicKey}; @@ -36,7 +36,7 @@ pub struct LegacyCovSatisfier<'tx, 'ptx> { /// The input index being spent idx: u32, /// The sighash type - hash_type: EcdsaSigHashType, + hash_type: EcdsaSighashType, // Segwitv0 /// The script code required for segwit sighash @@ -53,7 +53,7 @@ impl<'tx, 'ptx> LegacyCovSatisfier<'tx, 'ptx> { idx: u32, value: confidential::Value, script_code: &'ptx Script, - hash_type: EcdsaSigHashType, + hash_type: EcdsaSighashType, ) -> Self { assert!((idx as usize) < tx.input.len()); Self { @@ -70,8 +70,8 @@ impl<'tx, 'ptx> LegacyCovSatisfier<'tx, 'ptx> { /// Note that this does not do any caching, so it /// will be slightly inefficient as compared to /// using sighash - pub fn segwit_sighash(&self) -> Result { - let mut cache = SigHashCache::new(self.tx); + pub fn segwit_sighash(&self) -> Result { + let mut cache = SighashCache::new(self.tx); // TODO: error types let script_code = self.script_code.ok_or(CovError::MissingScriptCode)?; let value = self.value.ok_or(CovError::MissingValue)?; diff --git a/src/descriptor/mod.rs b/src/descriptor/mod.rs index d29324ad..9a164562 100644 --- a/src/descriptor/mod.rs +++ b/src/descriptor/mod.rs @@ -1579,7 +1579,7 @@ mod tests { impl Satisfier for SimpleSat { fn lookup_ecdsa_sig(&self, pk: &bitcoin::PublicKey) -> Option { if *pk == self.pk { - Some((self.sig, elements::EcdsaSigHashType::All)) + Some((self.sig, elements::EcdsaSighashType::All)) } else { None } @@ -1808,8 +1808,8 @@ mod tests { let satisfier = { let mut satisfier = HashMap::with_capacity(2); - satisfier.insert(a, (sig_a, ::elements::EcdsaSigHashType::All)); - satisfier.insert(b, (sig_b, ::elements::EcdsaSigHashType::All)); + satisfier.insert(a, (sig_a, ::elements::EcdsaSighashType::All)); + satisfier.insert(b, (sig_b, ::elements::EcdsaSighashType::All)); satisfier }; diff --git a/src/interpreter/error.rs b/src/interpreter/error.rs index 49e9448b..636ab593 100644 --- a/src/interpreter/error.rs +++ b/src/interpreter/error.rs @@ -46,13 +46,13 @@ pub enum Error { /// MultiSig missing at least `1` witness elements out of `k + 1` required InsufficientSignaturesMultiSig, /// Invalid Sighash type - InvalidSchnorrSigHashType(Vec), + InvalidSchnorrSighashType(Vec), /// ecdsa Signature failed to verify InvalidEcdsaSignature(bitcoin::PublicKey), /// Signature failed to verify InvalidSchnorrSignature(bitcoin::key::XOnlyPublicKey), /// Last byte of this signature isn't a standard sighash type - NonStandardSigHash(Vec), + NonStandardSighash(Vec), /// Miniscript error Miniscript(crate::Error), /// MultiSig requires 1 extra zero element apart from the `k` signatures @@ -154,14 +154,14 @@ impl fmt::Display for Error { } Error::IncorrectWScriptHash => f.write_str("witness script did not match scriptpubkey"), Error::InsufficientSignaturesMultiSig => f.write_str("Insufficient signatures for CMS"), - Error::InvalidSchnorrSigHashType(ref sig) => write!( + Error::InvalidSchnorrSighashType(ref sig) => write!( f, "Invalid sighash type for schnorr signature '{}'", sig.to_hex() ), Error::InvalidEcdsaSignature(pk) => write!(f, "bad ecdsa signature with pk {}", pk), Error::InvalidSchnorrSignature(pk) => write!(f, "bad schnorr signature with pk {}", pk), - Error::NonStandardSigHash(ref sig) => write!( + Error::NonStandardSighash(ref sig) => write!( f, "Non standard sighash type for signature '{}'", sig.to_hex() @@ -233,8 +233,8 @@ impl error::Error for Error { | InsufficientSignaturesMultiSig | InvalidEcdsaSignature(_) | InvalidSchnorrSignature(_) - | InvalidSchnorrSigHashType(_) - | NonStandardSigHash(_) + | InvalidSchnorrSighashType(_) + | NonStandardSighash(_) | MissingExtraZeroMultiSig | MultiSigEvaluationError | NonEmptyWitness diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 5a393100..848264be 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -14,7 +14,7 @@ use std::str::FromStr; use bitcoin; use elements::hashes::{hash160, ripemd160, sha256, Hash, HashEngine}; -use elements::{self, secp256k1_zkp, sighash, EcdsaSigHashType, LockTime, Sequence, SigHash}; +use elements::{self, secp256k1_zkp, sighash, EcdsaSighashType, LockTime, Sequence, Sighash}; use crate::extensions::{CovExtArgs, ParseableExt, TxEnv}; use crate::miniscript::context::{NoChecks, SigType}; @@ -259,7 +259,7 @@ where sighash::Prevouts::All(prevouts) => prevouts.get(input_index), } } - let mut cache = elements::sighash::SigHashCache::new(tx); + let mut cache = elements::sighash::SighashCache::new(tx); match sig { KeySigPair::Ecdsa(key, ecdsa_sig) => { let script_pubkey = self.script_code.as_ref().expect("Legacy have script code"); @@ -1101,7 +1101,7 @@ where { let sighash_bytes = self.stack[1].as_push().expect("Push checked above"); let sighash_u32 = util::slice_to_u32_le(sighash_bytes); - let sighash_ty = EcdsaSigHashType::from_u32(sighash_u32); + let sighash_ty = EcdsaSighashType::from_u32(sighash_u32); let sig_vec = self.stack[0].as_push().expect("Size checked above"); ser_sig.extend(sig_vec); ser_sig.push(sighash_ty as u8); @@ -1117,9 +1117,9 @@ where .rev() .flat_map(|x| Vec::from(x.as_push().expect("Push checked above"))) .collect(); - let mut eng = SigHash::engine(); + let mut eng = Sighash::engine(); eng.input(&sighash_msg); - let sighash_u256 = SigHash::from_engine(eng); + let sighash_u256 = Sighash::from_engine(eng); let msg = elements::secp256k1_zkp::Message::from_slice(&sighash_u256[..]).unwrap(); // Legacy Cov scripts only operate on Ecdsa key sig pairs @@ -1242,7 +1242,7 @@ mod tests { compressed: true, }; let sig = secp.sign_ecdsa(&msg, &sk); - ecdsa_sigs.push((sig, elements::EcdsaSigHashType::All)); + ecdsa_sigs.push((sig, elements::EcdsaSighashType::All)); let mut sigser = sig.serialize_der().to_vec(); sigser.push(0x01); // sighash_all pks.push(pk); @@ -1254,7 +1254,7 @@ mod tests { let schnorr_sig = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &[0u8; 32]); let schnorr_sig = elements::SchnorrSig { sig: schnorr_sig, - hash_ty: elements::SchnorrSigHashType::Default, + hash_ty: elements::SchnorrSighashType::Default, }; ser_schnorr_sigs.push(schnorr_sig.to_vec()); schnorr_sigs.push(schnorr_sig); diff --git a/src/miniscript/mod.rs b/src/miniscript/mod.rs index cf367e49..59ef2a92 100644 --- a/src/miniscript/mod.rs +++ b/src/miniscript/mod.rs @@ -1180,7 +1180,7 @@ mod tests { ) -> Option { Some(elements::SchnorrSig { sig: self.0, - hash_ty: elements::SchnorrSigHashType::Default, + hash_ty: elements::SchnorrSighashType::Default, }) } } diff --git a/src/miniscript/satisfy.rs b/src/miniscript/satisfy.rs index 80b82e69..7261e12d 100644 --- a/src/miniscript/satisfy.rs +++ b/src/miniscript/satisfy.rs @@ -24,7 +24,7 @@ use crate::util::witness_size; use crate::{Miniscript, MiniscriptKey, ScriptContext, Terminal, ToPublicKey}; /// Type alias for a signature/hashtype pair -pub type ElementsSig = (secp256k1_zkp::ecdsa::Signature, elements::EcdsaSigHashType); +pub type ElementsSig = (secp256k1_zkp::ecdsa::Signature, elements::EcdsaSighashType); /// Type alias for 32 byte Preimage. pub type Preimage32 = [u8; 32]; @@ -41,7 +41,7 @@ pub fn elementssig_to_rawsig(sig: &ElementsSig) -> Vec { /// Returns underlying secp if the Signature is not of correct format pub fn elementssig_from_rawsig(rawsig: &[u8]) -> Result { let (flag, sig) = rawsig.split_last().unwrap(); - let flag = elements::EcdsaSigHashType::from_u32(*flag as u32); + let flag = elements::EcdsaSighashType::from_u32(*flag as u32); let sig = secp256k1_zkp::ecdsa::Signature::from_der(sig)?; Ok((sig, flag)) } diff --git a/src/policy/compiler.rs b/src/policy/compiler.rs index d567da2c..f2846d1e 100644 --- a/src/policy/compiler.rs +++ b/src/policy/compiler.rs @@ -1403,7 +1403,7 @@ mod tests { assert_eq!(abs.n_keys(), 5); assert_eq!(abs.minimum_n_keys(), Some(3)); - let elements_sig = (sig, elements::EcdsaSigHashType::All); + let elements_sig = (sig, elements::EcdsaSighashType::All); let mut sigvec = elements_sig.0.serialize_der().to_vec(); sigvec.push(elements_sig.1 as u8); diff --git a/src/psbt/finalizer.rs b/src/psbt/finalizer.rs index 01866149..7bc1e2b3 100644 --- a/src/psbt/finalizer.rs +++ b/src/psbt/finalizer.rs @@ -360,10 +360,10 @@ fn input_sanity_checks(psbt: &Psbt, index: usize) -> Result<(), super::Error> { )); } let (flag, sig) = rawsig.split_last().unwrap(); - let flag = elements::EcdsaSigHashType::from_u32(*flag as u32); + let flag = elements::EcdsaSighashType::from_u32(*flag as u32); if target != flag { return Err(Error::InputError( - InputError::WrongSigHashFlag { + InputError::WrongSighashFlag { required: target, got: flag, pubkey: *key, diff --git a/src/psbt/mod.rs b/src/psbt/mod.rs index 7544d8ad..97803d51 100644 --- a/src/psbt/mod.rs +++ b/src/psbt/mod.rs @@ -17,10 +17,10 @@ use bitcoin::bip32; use elements::hashes::{hash160, sha256d, Hash}; use elements::pset::PartiallySignedTransaction as Psbt; use elements::secp256k1_zkp::{self as secp256k1, Secp256k1, VerifyOnly}; -use elements::sighash::SigHashCache; +use elements::sighash::SighashCache; use elements::taproot::{self, ControlBlock, LeafVersion, TapLeafHash}; use elements::{ - self, pset as psbt, EcdsaSigHashType, LockTime, SchnorrSigHashType, Script, Sequence, + self, pset as psbt, EcdsaSighashType, LockTime, SchnorrSighashType, Script, Sequence, }; use crate::extensions::{CovExtArgs, CovenantExt, ParseableExt}; @@ -149,11 +149,11 @@ pub enum InputError { /// Non standard sighash type NonStandardSighashType, /// Sighash did not match - WrongSigHashFlag { + WrongSighashFlag { /// required sighash type - required: EcdsaSigHashType, + required: EcdsaSighashType, /// the sighash type we got - got: EcdsaSigHashType, + got: EcdsaSighashType, /// the corresponding publickey pubkey: bitcoin::PublicKey, }, @@ -176,7 +176,7 @@ impl error::Error for InputError { | NonEmptyWitnessScript | NonEmptyRedeemScript | NonStandardSighashType - | WrongSigHashFlag { .. } => None, + | WrongSighashFlag { .. } => None, SecpErr(e) => Some(e), KeyErr(e) => Some(e), Interpreter(e) => Some(e), @@ -226,7 +226,7 @@ impl fmt::Display for InputError { InputError::NonEmptyWitnessScript => { write!(f, "PSET has non-empty witness script at for legacy input") } - InputError::WrongSigHashFlag { + InputError::WrongSighashFlag { required, got, pubkey, @@ -612,10 +612,10 @@ pub trait PsbtExt { /// Get the sighash message(data to sign) at input index `idx` based on the sighash /// flag specified in the [`Psbt`] sighash field. If the input sighash flag psbt field is `None` - /// the [`SchnorrSigHashType::Default`](elements::sighash::SchnorrSigHashType::Default) is chosen - /// for for taproot spends, otherwise [`EcdsaSignatureHashType::All`](elements::EcdsaSigHashType::All) is chosen. - /// If the utxo at `idx` is a taproot output, returns a [`PsbtSigHashMsg::TapSigHash`] variant. - /// If the utxo at `idx` is a pre-taproot output, returns a [`PsbtSigHashMsg::EcdsaSigHash`] variant. + /// the [`SchnorrSighashType::Default`](elements::sighash::SchnorrSighashType::Default) is chosen + /// for for taproot spends, otherwise [`EcdsaSignatureHashType::All`](elements::EcdsaSighashType::All) is chosen. + /// If the utxo at `idx` is a taproot output, returns a [`PsbtSighashMsg::TapSighash`] variant. + /// If the utxo at `idx` is a pre-taproot output, returns a [`PsbtSighashMsg::EcdsaSighash`] variant. /// The `tapleaf_hash` parameter can be used to specify which tapleaf script hash has to be computed. If /// `tapleaf_hash` is [`None`], and the output is taproot output, the key spend hash is computed. This parameter must be /// set to [`None`] while computing sighash for pre-taproot outputs. @@ -631,10 +631,10 @@ pub trait PsbtExt { fn sighash_msg>( &self, idx: usize, - cache: &mut SigHashCache, + cache: &mut SighashCache, tapleaf_hash: Option, genesis_hash: elements::BlockHash, - ) -> Result; + ) -> Result; } impl PsbtExt for Psbt { @@ -877,10 +877,10 @@ impl PsbtExt for Psbt { fn sighash_msg>( &self, idx: usize, - cache: &mut SigHashCache, + cache: &mut SighashCache, tapleaf_hash: Option, genesis_hash: elements::BlockHash, - ) -> Result { + ) -> Result { // Infer a descriptor at idx if idx >= self.inputs().len() { return Err(SighashError::IndexOutOfBounds(idx, self.inputs().len())); @@ -888,7 +888,7 @@ impl PsbtExt for Psbt { let inp = &self.inputs()[idx]; let prevouts = finalizer::prevouts(self).map_err(|_e| SighashError::MissingSpendUtxos)?; // Note that as per Psbt spec we should have access to spent_utxos for the transaction - // Even if the transaction does not require SigHashAll, we create `Prevouts::All` for code simplicity + // Even if the transaction does not require SighashAll, we create `Prevouts::All` for code simplicity let prevouts = elements::sighash::Prevouts::All(&prevouts); let inp_spk = finalizer::get_scriptpubkey(self, idx).map_err(|_e| SighashError::MissingInputUtxo)?; @@ -896,8 +896,8 @@ impl PsbtExt for Psbt { let hash_ty = inp .sighash_type .map(|h| h.schnorr_hash_ty()) - .unwrap_or(Some(SchnorrSigHashType::Default)) - .ok_or(SighashError::InvalidSigHashType)?; + .unwrap_or(Some(SchnorrSighashType::Default)) + .ok_or(SighashError::InvalidSighashType)?; match tapleaf_hash { Some(leaf_hash) => { let tap_sighash_msg = cache.taproot_script_spend_signature_hash( @@ -907,7 +907,7 @@ impl PsbtExt for Psbt { hash_ty, genesis_hash, )?; - Ok(PsbtSigHashMsg::TapSigHash(tap_sighash_msg)) + Ok(PsbtSighashMsg::TapSighash(tap_sighash_msg)) } None => { let tap_sighash_msg = cache.taproot_key_spend_signature_hash( @@ -916,15 +916,15 @@ impl PsbtExt for Psbt { hash_ty, genesis_hash, )?; - Ok(PsbtSigHashMsg::TapSigHash(tap_sighash_msg)) + Ok(PsbtSighashMsg::TapSighash(tap_sighash_msg)) } } } else { let hash_ty = inp .sighash_type .map(|h| h.ecdsa_hash_ty()) - .unwrap_or(Some(EcdsaSigHashType::All)) - .ok_or(SighashError::InvalidSigHashType)?; + .unwrap_or(Some(EcdsaSighashType::All)) + .ok_or(SighashError::InvalidSighashType)?; let amt = finalizer::get_utxo(self, idx) .map_err(|_e| SighashError::MissingInputUtxo)? .value; @@ -959,7 +959,7 @@ impl PsbtExt for Psbt { .ok_or(SighashError::MissingWitnessScript)?; cache.segwitv0_sighash(idx, script_code, amt, hash_ty) }; - Ok(PsbtSigHashMsg::EcdsaSigHash(msg)) + Ok(PsbtSighashMsg::EcdsaSighash(msg)) } else { // legacy sighash case let script_code = if inp_spk.is_p2sh() { @@ -970,7 +970,7 @@ impl PsbtExt for Psbt { inp_spk }; let msg = cache.legacy_sighash(idx, script_code, hash_ty); - Ok(PsbtSigHashMsg::EcdsaSigHash(msg)) + Ok(PsbtSighashMsg::EcdsaSighash(msg)) } } } @@ -1456,11 +1456,11 @@ pub enum SighashError { /// Missing Prevouts MissingSpendUtxos, /// Invalid Sighash type - InvalidSigHashType, + InvalidSighashType, /// Sighash computation error /// Only happens when single does not have corresponding output as psbts /// already have information to compute the sighash - SigHashComputationError(elements::sighash::Error), + SighashComputationError(elements::sighash::Error), /// Missing Witness script MissingWitnessScript, /// Missing Redeem script, @@ -1475,8 +1475,8 @@ impl fmt::Display for SighashError { } SighashError::MissingInputUtxo => write!(f, "Missing input utxo in pbst"), SighashError::MissingSpendUtxos => write!(f, "Missing Psbt spend utxos"), - SighashError::InvalidSigHashType => write!(f, "Invalid Sighash type"), - SighashError::SigHashComputationError(e) => { + SighashError::InvalidSighashType => write!(f, "Invalid Sighash type"), + SighashError::SighashComputationError(e) => { write!(f, "Sighash computation error : {}", e) } SighashError::MissingWitnessScript => write!(f, "Missing Witness Script"), @@ -1487,7 +1487,7 @@ impl fmt::Display for SighashError { impl From for SighashError { fn from(e: elements::sighash::Error) -> Self { - SighashError::SigHashComputationError(e) + SighashError::SighashComputationError(e) } } @@ -1499,32 +1499,32 @@ impl error::Error for SighashError { IndexOutOfBounds(_, _) | MissingInputUtxo | MissingSpendUtxos - | InvalidSigHashType + | InvalidSighashType | MissingWitnessScript | MissingRedeemScript => None, - SigHashComputationError(e) => Some(e), + SighashComputationError(e) => Some(e), } } } /// Sighash message(signing data) for a given psbt transaction input. #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)] -pub enum PsbtSigHashMsg { +pub enum PsbtSighashMsg { /// Taproot Signature hash - TapSigHash(taproot::TapSighashHash), - /// Ecdsa SigHash message (includes sighash for legacy/p2sh/segwitv0 outputs) - EcdsaSigHash(elements::SigHash), + TapSighash(taproot::TapSighashHash), + /// Ecdsa Sighash message (includes sighash for legacy/p2sh/segwitv0 outputs) + EcdsaSighash(elements::Sighash), } -impl PsbtSigHashMsg { +impl PsbtSighashMsg { /// Convert the message to a [`secp256k1::Message`]. pub fn to_secp_msg(&self) -> secp256k1::Message { match *self { - PsbtSigHashMsg::TapSigHash(msg) => { - secp256k1::Message::from_slice(msg.as_ref()).expect("SigHashes are 32 bytes") + PsbtSighashMsg::TapSighash(msg) => { + secp256k1::Message::from_slice(msg.as_ref()).expect("Sighashes are 32 bytes") } - PsbtSigHashMsg::EcdsaSigHash(msg) => { - secp256k1::Message::from_slice(msg.as_ref()).expect("SigHashes are 32 bytes") + PsbtSighashMsg::EcdsaSighash(msg) => { + secp256k1::Message::from_slice(msg.as_ref()).expect("Sighashes are 32 bytes") } } }