Skip to content

Commit

Permalink
Derive Hash on a bunch of types
Browse files Browse the repository at this point in the history
In preparation for being able to derive `Hash` on all types in
`miniscript`, derive `Hash` on all of the required types.
  • Loading branch information
tcharding committed May 6, 2022
1 parent 23fe753 commit c4f9419
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/blockdata/transaction.rs
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/util/bip32.rs
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/util/ecdsa.rs
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/util/key.rs
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/util/psbt/map/input.rs
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/util/psbt/map/output.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/util/psbt/mod.rs
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/util/schnorr.rs
Expand Up @@ -138,7 +138,7 @@ impl TapTweak for UntweakedKeyPair {
/// # Returns
/// The tweaked key and its parity.
fn tap_tweak<C: Verification>(mut self, secp: &Secp256k1<C>, merkle_root: Option<TapBranchHash>) -> 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)
Expand Down Expand Up @@ -212,7 +212,7 @@ impl From<TweakedKeyPair> 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
Expand Down

0 comments on commit c4f9419

Please sign in to comment.