Skip to content

Commit

Permalink
feat: add hash for 7702 (#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jul 11, 2024
1 parent 5d8dce4 commit 678617e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions crates/eips/src/eip7702/auth_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use alloy_rlp::{
length_of_length, BufMut, Decodable, Encodable, Header, Result as RlpResult, RlpDecodable,
RlpEncodable,
};
use core::hash::{Hash, Hasher};

/// An unsigned EIP-7702 authorization.
#[derive(Debug, Clone, RlpEncodable, RlpDecodable, Eq, PartialEq)]
#[derive(Debug, Clone, Hash, RlpEncodable, RlpDecodable, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct Authorization {
Expand Down Expand Up @@ -108,6 +109,15 @@ impl SignedAuthorization {
}
}

impl Hash for SignedAuthorization {
fn hash<H: Hasher>(&self, state: &mut H) {
self.inner.hash(state);
self.signature.r().hash(state);
self.signature.s().hash(state);
self.signature.v().to_u64().hash(state);
}
}

impl Decodable for SignedAuthorization {
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
let header = Header::decode(buf)?;
Expand Down Expand Up @@ -161,7 +171,7 @@ impl Deref for SignedAuthorization {
}

/// A recovered authorization.
#[derive(Debug, Clone, Eq, PartialEq)]
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RecoveredAuthorization {
#[cfg_attr(feature = "serde", serde(flatten))]
Expand Down Expand Up @@ -197,7 +207,7 @@ impl Deref for RecoveredAuthorization {
/// nonce was specified (i.e. `None`). If there is 1 item, this is the same as `Some`.
///
/// The wrapper type is used for RLP encoding and decoding.
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
#[derive(Default, Debug, Copy, Clone, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct OptionalNonce(Option<u64>);

Expand Down

0 comments on commit 678617e

Please sign in to comment.