@@ -3,15 +3,30 @@ use alloy::{
33 primitives:: { keccak256, Address , ChainId , Bytes , U256 , B256 } ,
44 rpc:: types:: { PackedUserOperation , UserOperation } ,
55} ;
6+ use serde:: { Deserialize , Serialize } ;
7+
8+ /// UserOp version enum
9+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
10+ #[ serde( untagged) ]
11+ pub enum VersionedUserOp {
12+ V0_6 ( UserOperation ) ,
13+ V0_7 ( PackedUserOperation ) ,
14+ }
615
7- use super :: IAWError ;
16+ /// Error type for UserOp operations
17+ #[ derive( Debug , Clone , thiserror:: Error , serde:: Serialize , serde:: Deserialize , schemars:: JsonSchema , utoipa:: ToSchema ) ]
18+ #[ serde( tag = "type" , rename_all = "SCREAMING_SNAKE_CASE" ) ]
19+ pub enum UserOpError {
20+ #[ error( "Unexpected error: {0}" ) ]
21+ UnexpectedError ( String ) ,
22+ }
823
924/// Compute UserOperation v0.6 hash
1025pub fn compute_user_op_v06_hash (
1126 op : & UserOperation ,
1227 entrypoint : Address ,
1328 chain_id : ChainId ,
14- ) -> Result < B256 , IAWError > {
29+ ) -> Result < B256 , UserOpError > {
1530 // Hash the byte fields first
1631 let init_code_hash = keccak256 ( & op. init_code ) ;
1732 let call_data_hash = keccak256 ( & op. call_data ) ;
@@ -49,7 +64,7 @@ pub fn compute_user_op_v07_hash(
4964 op : & PackedUserOperation ,
5065 entrypoint : Address ,
5166 chain_id : ChainId ,
52- ) -> Result < B256 , IAWError > {
67+ ) -> Result < B256 , UserOpError > {
5368 // Construct initCode from factory and factoryData
5469 let init_code: Bytes = if let Some ( factory) = op. factory {
5570 if factory != Address :: ZERO {
@@ -63,10 +78,10 @@ pub fn compute_user_op_v07_hash(
6378
6479 // Construct accountGasLimits
6580 let vgl_u128: u128 = op. verification_gas_limit . try_into ( ) . map_err ( |_| {
66- IAWError :: UnexpectedError ( "verification_gas_limit too large" . to_string ( ) )
81+ UserOpError :: UnexpectedError ( "verification_gas_limit too large" . to_string ( ) )
6782 } ) ?;
6883 let cgl_u128: u128 = op. call_gas_limit . try_into ( ) . map_err ( |_| {
69- IAWError :: UnexpectedError ( "call_gas_limit too large" . to_string ( ) )
84+ UserOpError :: UnexpectedError ( "call_gas_limit too large" . to_string ( ) )
7085 } ) ?;
7186
7287 let mut account_gas_limits_bytes = [ 0u8 ; 32 ] ;
@@ -76,10 +91,10 @@ pub fn compute_user_op_v07_hash(
7691
7792 // Construct gasFees
7893 let mpfpg_u128: u128 = op. max_priority_fee_per_gas . try_into ( ) . map_err ( |_| {
79- IAWError :: UnexpectedError ( "max_priority_fee_per_gas too large" . to_string ( ) )
94+ UserOpError :: UnexpectedError ( "max_priority_fee_per_gas too large" . to_string ( ) )
8095 } ) ?;
8196 let mfpg_u128: u128 = op. max_fee_per_gas . try_into ( ) . map_err ( |_| {
82- IAWError :: UnexpectedError ( "max_fee_per_gas too large" . to_string ( ) )
97+ UserOpError :: UnexpectedError ( "max_fee_per_gas too large" . to_string ( ) )
8398 } ) ?;
8499
85100 let mut gas_fees_bytes = [ 0u8 ; 32 ] ;
@@ -91,10 +106,10 @@ pub fn compute_user_op_v07_hash(
91106 let paymaster_and_data: Bytes = if let Some ( paymaster) = op. paymaster {
92107 if paymaster != Address :: ZERO {
93108 let pm_vgl_u128: u128 = op. paymaster_verification_gas_limit . unwrap_or_default ( ) . try_into ( ) . map_err ( |_| {
94- IAWError :: UnexpectedError ( "paymaster_verification_gas_limit too large" . to_string ( ) )
109+ UserOpError :: UnexpectedError ( "paymaster_verification_gas_limit too large" . to_string ( ) )
95110 } ) ?;
96111 let pm_pogl_u128: u128 = op. paymaster_post_op_gas_limit . unwrap_or_default ( ) . try_into ( ) . map_err ( |_| {
97- IAWError :: UnexpectedError ( "paymaster_post_op_gas_limit too large" . to_string ( ) )
112+ UserOpError :: UnexpectedError ( "paymaster_post_op_gas_limit too large" . to_string ( ) )
98113 } ) ?;
99114 [
100115 & paymaster[ ..] ,
@@ -139,4 +154,4 @@ pub fn compute_user_op_v07_hash(
139154 let outer_encoded = outer_tuple. abi_encode ( ) ;
140155 let final_hash = keccak256 ( & outer_encoded) ;
141156 Ok ( final_hash)
142- }
157+ }
0 commit comments