Skip to content

Commit

Permalink
feat: add RecoveredAuthorization
Browse files Browse the repository at this point in the history
  • Loading branch information
onbjerg committed Jun 24, 2024
1 parent 3172967 commit b091519
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions crates/eips/src/eip7702/auth_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ impl SignedAuthorization<alloy_primitives::Signature> {
pub fn recover_authority(&self) -> Result<Address, alloy_primitives::SignatureError> {
self.signature.recover_address_from_prehash(&self.inner.signature_hash())
}

/// Recover the authority and transform the signed authorization into a
/// [`RecoveredAuthorization`].
pub fn into_recovered(self) -> RecoveredAuthorization {
RecoveredAuthorization { inner: self.inner, authority: self.recover_authority().ok() }
}
}

impl<S> Deref for SignedAuthorization<S> {
Expand All @@ -104,6 +110,30 @@ impl<S> Deref for SignedAuthorization<S> {
}
}

/// A recovered authorization.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct RecoveredAuthorization {
inner: Authorization,
authority: Option<Address>,
}

impl RecoveredAuthorization {
/// Get the `authority` for the authorization.
///
/// If this is `None`, then the authority could not be recovered.
pub const fn authority(&self) -> Option<Address> {
self.authority
}
}

impl Deref for RecoveredAuthorization {
type Target = Authorization;

fn deref(&self) -> &Self::Target {
&self.inner
}
}

/// An internal wrapper around an `Option<u64>` for optional nonces.
///
/// In EIP-7702 the nonce is encoded as a list of either 0 or 1 items, where 0 items means that no
Expand Down

0 comments on commit b091519

Please sign in to comment.