From b877e2661564ff863404cc40e8e5f379682483d9 Mon Sep 17 00:00:00 2001 From: "Pengfei(Andy) Zhang" Date: Thu, 9 Jan 2025 11:08:46 -0500 Subject: [PATCH] fix: change authorization tuple use hexstirng --- crates/rpc/src/types/mod.rs | 2 + crates/rpc/src/types/rpc_authorization.rs | 47 +++++++++++++++++++++++ crates/rpc/src/types/v0_6.rs | 10 ++--- crates/rpc/src/types/v0_7.rs | 9 ++--- 4 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 crates/rpc/src/types/rpc_authorization.rs diff --git a/crates/rpc/src/types/mod.rs b/crates/rpc/src/types/mod.rs index ac6472361..97e737237 100644 --- a/crates/rpc/src/types/mod.rs +++ b/crates/rpc/src/types/mod.rs @@ -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)] diff --git a/crates/rpc/src/types/rpc_authorization.rs b/crates/rpc/src/types/rpc_authorization.rs new file mode 100644 index 000000000..5035e4e86 --- /dev/null +++ b/crates/rpc/src/types/rpc_authorization.rs @@ -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 for Authorization { + fn from(val: RpcAuthorization) -> Self { + 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 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, + } + } +} diff --git a/crates/rpc/src/types/v0_6.rs b/crates/rpc/src/types/v0_6.rs index 99f6d22fc..e7b0c6f79 100644 --- a/crates/rpc/src/types/v0_6.rs +++ b/crates/rpc/src/types/v0_6.rs @@ -13,7 +13,6 @@ use alloy_primitives::{Address, Bytes, U128, U256}; use rundler_types::{ - authorization::Authorization, chain::ChainSpec, v0_6::{ ExtendedUserOperation, UserOperation, UserOperationBuilder, UserOperationOptionalGas, @@ -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")] @@ -40,7 +38,7 @@ pub(crate) struct RpcUserOperation { max_priority_fee_per_gas: U128, paymaster_and_data: Bytes, signature: Bytes, - authorization_tuple: Option, + authorization_tuple: Option, } impl From for RpcUserOperation { @@ -57,7 +55,7 @@ impl From 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()), } } } @@ -80,7 +78,7 @@ impl FromRpc for UserOperation { signature: def.signature, }, ExtendedUserOperation { - authorization_tuple: def.authorization_tuple, + authorization_tuple: def.authorization_tuple.map(|a| a.into()), }, ) .build() diff --git a/crates/rpc/src/types/v0_7.rs b/crates/rpc/src/types/v0_7.rs index fab0dde71..683e7d34b 100644 --- a/crates/rpc/src/types/v0_7.rs +++ b/crates/rpc/src/types/v0_7.rs @@ -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, @@ -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)] @@ -50,7 +49,7 @@ pub(crate) struct RpcUserOperation { paymaster_data: Option, signature: Bytes, #[serde(skip_serializing_if = "Option::is_none")] - authorization_tuple: Option, + authorization_tuple: Option, } impl From for RpcUserOperation { @@ -88,7 +87,7 @@ impl From 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()), } } } @@ -125,7 +124,7 @@ impl FromRpc 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() }