Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make auth mandatory in recovered auth #1047

Merged
merged 2 commits into from
Jul 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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