From c4f9419a2fd5769cd69517f8dbe8e147715bf007 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 6 May 2022 13:37:24 +1000 Subject: [PATCH] Derive Hash on a bunch of types In preparation for being able to derive `Hash` on all types in `miniscript`, derive `Hash` on all of the required types. --- src/blockdata/transaction.rs | 2 +- src/util/bip32.rs | 2 +- src/util/ecdsa.rs | 2 +- src/util/key.rs | 2 +- src/util/psbt/map/input.rs | 2 +- src/util/psbt/map/output.rs | 4 ++-- src/util/psbt/mod.rs | 2 +- src/util/schnorr.rs | 4 ++-- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index 47e5623414..1e24ce156a 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -743,7 +743,7 @@ pub type SigHashType = EcdsaSighashType; /// /// Fixed values so they can be cast as integer types for encoding (see also /// [`SchnorrSighashType`]). -#[derive(PartialEq, Eq, Debug, Copy, Clone)] +#[derive(PartialEq, Eq, Debug, Copy, Clone, Hash)] pub enum EcdsaSighashType { /// 0x1: Sign all outputs. All = 0x01, diff --git a/src/util/bip32.rs b/src/util/bip32.rs index 611ee005ae..d2203d351c 100644 --- a/src/util/bip32.rs +++ b/src/util/bip32.rs @@ -46,7 +46,7 @@ impl_array_newtype!(Fingerprint, u8, 4); impl_bytes_newtype!(Fingerprint, 4); /// Extended private key -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "std", derive(Debug))] pub struct ExtendedPrivKey { /// The network this key is to be used on diff --git a/src/util/ecdsa.rs b/src/util/ecdsa.rs index 431b368af5..193fdcfb8d 100644 --- a/src/util/ecdsa.rs +++ b/src/util/ecdsa.rs @@ -25,7 +25,7 @@ use secp256k1; use EcdsaSighashType; /// An ECDSA signature with the corresponding hash type. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct EcdsaSig { /// The underlying ECDSA Signature diff --git a/src/util/key.rs b/src/util/key.rs index e8c202533b..b6e73b1e46 100644 --- a/src/util/key.rs +++ b/src/util/key.rs @@ -234,7 +234,7 @@ impl FromStr for PublicKey { } /// A Bitcoin ECDSA private key -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "std", derive(Debug))] pub struct PrivateKey { /// Whether this private key should be serialized as compressed diff --git a/src/util/psbt/map/input.rs b/src/util/psbt/map/input.rs index 113f06268a..3adca69e4a 100644 --- a/src/util/psbt/map/input.rs +++ b/src/util/psbt/map/input.rs @@ -79,7 +79,7 @@ const PSBT_IN_PROPRIETARY: u8 = 0xFC; /// A key-value map for an input of the corresponding index in the unsigned /// transaction. -#[derive(Clone, Default, Debug, PartialEq, Eq)] +#[derive(Clone, Default, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Input { /// The non-witness transaction this input spends from. Should only be diff --git a/src/util/psbt/map/output.rs b/src/util/psbt/map/output.rs index 2545497df4..dbef6da383 100644 --- a/src/util/psbt/map/output.rs +++ b/src/util/psbt/map/output.rs @@ -47,7 +47,7 @@ const PSBT_OUT_PROPRIETARY: u8 = 0xFC; /// A key-value map for an output of the corresponding index in the unsigned /// transaction. -#[derive(Clone, Default, Debug, PartialEq, Eq)] +#[derive(Clone, Default, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Output { /// The redeem script for this output. @@ -113,7 +113,7 @@ impl core::fmt::Display for IncompleteTapTree { impl ::std::error::Error for IncompleteTapTree {} /// Taproot Tree representing a finalized [`TaprootBuilder`] (a complete binary tree). -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct TapTree(pub(crate) TaprootBuilder); diff --git a/src/util/psbt/mod.rs b/src/util/psbt/mod.rs index a067a2a4e5..f79bf36338 100644 --- a/src/util/psbt/mod.rs +++ b/src/util/psbt/mod.rs @@ -50,7 +50,7 @@ use util::bip32::{ExtendedPubKey, KeySource}; pub type Psbt = PartiallySignedTransaction; /// A Partially Signed Transaction. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct PartiallySignedTransaction { /// The unsigned transaction, scriptSigs and witnesses for each input must be diff --git a/src/util/schnorr.rs b/src/util/schnorr.rs index 4c2fca7326..afe1fb6aec 100644 --- a/src/util/schnorr.rs +++ b/src/util/schnorr.rs @@ -138,7 +138,7 @@ impl TapTweak for UntweakedKeyPair { /// # Returns /// The tweaked key and its parity. fn tap_tweak(mut self, secp: &Secp256k1, merkle_root: Option) -> TweakedKeyPair { - let pubkey = ::XOnlyPublicKey::from_keypair(&self); + let (pubkey, _parity) = ::XOnlyPublicKey::from_keypair(&self); let tweak_value = TapTweakHash::from_key_and_tweak(pubkey, merkle_root).into_inner(); self.tweak_add_assign(&secp, &tweak_value).expect("Tap tweak failed"); TweakedKeyPair(self) @@ -212,7 +212,7 @@ impl From for ::KeyPair { } /// A BIP340-341 serialized schnorr signature with the corresponding hash type. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct SchnorrSig { /// The underlying schnorr signature