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

fix: change authorization tuple use hexstirng #972

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions crates/rpc/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub(crate) use v0_7::{
RpcUserOperationOptionalGas as RpcUserOperationOptionalGasV0_7,
};

mod rpc_authorization;

/// API namespace
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, strum::EnumString)]
#[strum(serialize_all = "lowercase", ascii_case_insensitive)]
Expand Down
47 changes: 47 additions & 0 deletions crates/rpc/src/types/rpc_authorization.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use alloy_primitives::{Address, U256, U64, U8};
use rundler_types::authorization::Authorization;
use serde::{Deserialize, Serialize};

/// authorization tuple for 7702 txn support
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub(crate) struct RpcAuthorization {
/// The chain ID of the authorization.
pub chain_id: U64,
/// The address of the authorization.
pub address: Address,
/// The nonce for the authorization.
pub nonce: U64,
/// signed authorizzation tuple.
pub y_parity: U8,
/// signed authorizzation tuple.
pub r: U256,
/// signed authorizzation tuple.
pub s: U256,
}

impl From<RpcAuthorization> for Authorization {
fn from(val: RpcAuthorization) -> Self {
andysim3d marked this conversation as resolved.
Show resolved Hide resolved
Authorization {
chain_id: val.chain_id.to(),
address: val.address,
nonce: val.nonce.to(),
y_parity: val.y_parity.to(),
r: val.r,
s: val.s,
}
}
}

impl From<Authorization> for RpcAuthorization {
fn from(value: Authorization) -> Self {
Self {
chain_id: U64::from(value.chain_id),
address: value.address,
nonce: U64::from(value.nonce),
y_parity: U8::from(value.y_parity),
r: value.r,
s: value.s,
}
}
}
10 changes: 4 additions & 6 deletions crates/rpc/src/types/v0_6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use alloy_primitives::{Address, Bytes, U128, U256};
use rundler_types::{
authorization::Authorization,
chain::ChainSpec,
v0_6::{
ExtendedUserOperation, UserOperation, UserOperationBuilder, UserOperationOptionalGas,
Expand All @@ -23,8 +22,7 @@ use rundler_types::{
};
use serde::{Deserialize, Serialize};

use super::{FromRpc, RpcAddress};

use super::{rpc_authorization::RpcAuthorization, FromRpc, RpcAddress};
/// User operation definition for RPC
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
Expand All @@ -40,7 +38,7 @@ pub(crate) struct RpcUserOperation {
max_priority_fee_per_gas: U128,
paymaster_and_data: Bytes,
signature: Bytes,
authorization_tuple: Option<Authorization>,
authorization_tuple: Option<RpcAuthorization>,
}

impl From<UserOperation> for RpcUserOperation {
Expand All @@ -57,7 +55,7 @@ impl From<UserOperation> for RpcUserOperation {
max_priority_fee_per_gas: U128::from(op.max_priority_fee_per_gas),
paymaster_and_data: op.paymaster_and_data,
signature: op.signature,
authorization_tuple: op.authorization_tuple,
authorization_tuple: op.authorization_tuple.map(|a| a.into()),
}
}
}
Expand All @@ -80,7 +78,7 @@ impl FromRpc<RpcUserOperation> for UserOperation {
signature: def.signature,
},
ExtendedUserOperation {
authorization_tuple: def.authorization_tuple,
authorization_tuple: def.authorization_tuple.map(|a| a.into()),
},
)
.build()
Expand Down
9 changes: 4 additions & 5 deletions crates/rpc/src/types/v0_7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use alloy_primitives::{Address, Bytes, B256, U128, U256};
use rundler_types::{
authorization::Authorization,
chain::ChainSpec,
v0_7::{
UserOperation, UserOperationBuilder, UserOperationOptionalGas, UserOperationRequiredFields,
Expand All @@ -22,7 +21,7 @@ use rundler_types::{
};
use serde::{Deserialize, Serialize};

use super::{FromRpc, RpcAddress};
use super::{rpc_authorization::RpcAuthorization, FromRpc, RpcAddress};

/// User operation definition for RPC inputs
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
Expand Down Expand Up @@ -50,7 +49,7 @@ pub(crate) struct RpcUserOperation {
paymaster_data: Option<Bytes>,
signature: Bytes,
#[serde(skip_serializing_if = "Option::is_none")]
authorization_tuple: Option<Authorization>,
authorization_tuple: Option<RpcAuthorization>,
}

impl From<UserOperation> for RpcUserOperation {
Expand Down Expand Up @@ -88,7 +87,7 @@ impl From<UserOperation> for RpcUserOperation {
paymaster_post_op_gas_limit: paymaster_post_op_gas_limit.map(|x| U128::from(x)),
paymaster_data,
signature: op.signature,
authorization_tuple: op.authorization_tuple,
authorization_tuple: op.authorization_tuple.map(|a| a.into()),
}
}
}
Expand Down Expand Up @@ -125,7 +124,7 @@ impl FromRpc<RpcUserOperation> for UserOperation {
builder = builder.factory(def.factory.unwrap(), def.factory_data.unwrap_or_default());
}
if def.authorization_tuple.is_some() {
builder = builder.authorization_tuple(def.authorization_tuple);
builder = builder.authorization_tuple(def.authorization_tuple.map(|a| a.into()));
}
builder.build()
}
Expand Down
Loading