Skip to content

Commit

Permalink
chore: make auth mandatory in recovered auth (#1047)
Browse files Browse the repository at this point in the history
* chore: make auth mandatory in recovered auth

* features
  • Loading branch information
mattsse authored Jul 14, 2024
1 parent e35703d commit ea6a447
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions crates/eips/src/eip7702/auth_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RecoveredAuthorization, alloy_primitives::SignatureError> {
let authority = self.recover_authority()?;
Ok(RecoveredAuthorization { inner: self.inner, authority })
}
}

Expand Down Expand Up @@ -197,23 +199,35 @@ impl<'a> arbitrary::Arbitrary<'a> for SignedAuthorization {
pub struct RecoveredAuthorization {
#[cfg_attr(feature = "serde", serde(flatten))]
inner: Authorization,
authority: Option<Address>,
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<Address> {
pub const fn authority(&self) -> Address {
self.authority
}

/// Splits the authorization into parts.
pub const fn into_parts(self) -> (Authorization, Option<Address>) {
pub const fn into_parts(self) -> (Authorization, Address) {
(self.inner, self.authority)
}
}

#[cfg(feature = "k256")]
impl TryFrom<SignedAuthorization> for RecoveredAuthorization {
type Error = alloy_primitives::SignatureError;

fn try_from(value: SignedAuthorization) -> Result<Self, Self::Error> {
value.try_into_recovered()
}
}

impl Deref for RecoveredAuthorization {
type Target = Authorization;

Expand Down

0 comments on commit ea6a447

Please sign in to comment.