From e67420aa277798ff9a05a8f4ea01d57b36037ca1 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 13 Jul 2024 07:56:19 +0200 Subject: [PATCH 1/2] chore: make auth mandatory in recovered auth --- crates/eips/src/eip7702/auth_list.rs | 29 ++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/eips/src/eip7702/auth_list.rs b/crates/eips/src/eip7702/auth_list.rs index 2633fd91dd3..887fea238e7 100644 --- a/crates/eips/src/eip7702/auth_list.rs +++ b/crates/eips/src/eip7702/auth_list.rs @@ -157,9 +157,11 @@ impl SignedAuthorization { /// Recover the authority and transform the signed authorization into a /// [`RecoveredAuthorization`]. - pub fn into_recovered(self) -> RecoveredAuthorization { - let authority = self.recover_authority().ok(); - RecoveredAuthorization { inner: self.inner, authority } + pub fn try_into_recovered( + self, + ) -> Result { + let authority = self.recover_authority()?; + Ok(RecoveredAuthorization { inner: self.inner, authority }) } } @@ -197,23 +199,34 @@ impl<'a> arbitrary::Arbitrary<'a> for SignedAuthorization { pub struct RecoveredAuthorization { #[cfg_attr(feature = "serde", serde(flatten))] inner: Authorization, - authority: Option
, + authority: Address, } impl RecoveredAuthorization { + /// Instantiate without performing recovery. This should be used carefully. + pub const fn new_unchecked(inner: Authorization, authority: Address) -> Self { + Self { inner, authority } + } + /// Get the `authority` for the authorization. - /// - /// If this is `None`, then the authority could not be recovered. - pub const fn authority(&self) -> Option
{ + pub const fn authority(&self) -> Address { self.authority } /// Splits the authorization into parts. - pub const fn into_parts(self) -> (Authorization, Option
) { + pub const fn into_parts(self) -> (Authorization, Address) { (self.inner, self.authority) } } +impl TryFrom for RecoveredAuthorization { + type Error = alloy_primitives::SignatureError; + + fn try_from(value: SignedAuthorization) -> Result { + value.try_into_recovered() + } +} + impl Deref for RecoveredAuthorization { type Target = Authorization; From 1a3b981a6f9e46ba7827535d38ebbb4acd50a877 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 13 Jul 2024 08:00:06 +0200 Subject: [PATCH 2/2] features --- crates/eips/src/eip7702/auth_list.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/eips/src/eip7702/auth_list.rs b/crates/eips/src/eip7702/auth_list.rs index 887fea238e7..e8247202f5f 100644 --- a/crates/eips/src/eip7702/auth_list.rs +++ b/crates/eips/src/eip7702/auth_list.rs @@ -219,6 +219,7 @@ impl RecoveredAuthorization { } } +#[cfg(feature = "k256")] impl TryFrom for RecoveredAuthorization { type Error = alloy_primitives::SignatureError;