@@ -5,14 +5,15 @@ use alloy::{
55 hex:: FromHex ,
66 primitives:: { Address , B256 , Bytes , hex, keccak256} ,
77 sol,
8- sol_types:: { SolCall , SolStruct , SolValue , eip712_domain} ,
8+ sol_types:: { SolCall , SolValue , decode_revert_reason , eip712_domain} ,
99} ;
1010use engine_core:: {
1111 chain:: Chain ,
1212 credentials:: SigningCredential ,
1313 error:: EngineError ,
14- signer:: { AccountSigner , EoaSigner , EoaSigningOptions , SmartAccountSigningOptions } ,
14+ signer:: { AccountSigner , EoaSigner , EoaSigningOptions , Erc4337SigningOptions } ,
1515} ;
16+ use serde:: Serialize ;
1617use vault_types:: enclave:: encrypted:: eoa:: MessageFormat ;
1718
1819use crate :: {
3536}
3637
3738sol ! {
39+ #[ derive( Serialize ) ]
3840 struct AccountMessage {
3941 bytes message;
4042 }
@@ -48,15 +50,15 @@ const ERC6492_MAGIC_SUFFIX: [u8; 32] =
4850pub struct SmartAccountSignerBuilder < C : Chain > {
4951 eoa_signer : Arc < EoaSigner > ,
5052 credentials : SigningCredential ,
51- options : SmartAccountSigningOptions ,
53+ options : Erc4337SigningOptions ,
5254 chain : C ,
5355}
5456
5557impl < C : Chain + Clone > SmartAccountSignerBuilder < C > {
5658 pub fn new (
5759 eoa_signer : Arc < EoaSigner > ,
5860 credentials : SigningCredential ,
59- options : SmartAccountSigningOptions ,
61+ options : Erc4337SigningOptions ,
6062 chain : C ,
6163 ) -> Self {
6264 Self {
@@ -141,7 +143,7 @@ impl<C: Chain + Clone> SmartAccountSignerBuilder<C> {
141143/// Smart Account signer with pre-computed address and factory pattern support
142144#[ derive( Clone ) ]
143145pub struct SmartAccountSigner < C : Chain > {
144- options : SmartAccountSigningOptions ,
146+ options : Erc4337SigningOptions ,
145147 credentials : SigningCredential ,
146148 chain : C ,
147149 eoa_signer : Arc < EoaSigner > ,
@@ -242,17 +244,16 @@ impl<C: Chain + Clone> SmartAccountSigner<C> {
242244 } ;
243245
244246 // Get the EIP712 signing hash using alloy's native functionality
245- let signing_hash = account_message . eip712_signing_hash ( & domain) ;
247+ let typed_data = TypedData :: from_struct ( & account_message , Some ( domain) ) ;
246248
247249 // Sign the hash directly with EOA
248250 self . eoa_signer
249- . sign_message (
251+ . sign_typed_data (
250252 EoaSigningOptions {
251253 chain_id : Some ( self . chain . chain_id ( ) ) ,
252254 from : self . options . signer_address ,
253255 } ,
254- & format ! ( "0x{}" , hex:: encode( signing_hash) ) ,
255- MessageFormat :: Hex ,
256+ & typed_data,
256257 self . credentials . clone ( ) ,
257258 )
258259 . await
@@ -268,16 +269,25 @@ impl<C: Chain + Clone> SmartAccountSigner<C> {
268269 let contract =
269270 ERC1271Contract :: new ( self . smart_account . address , self . chain . provider ( ) . clone ( ) ) ;
270271
272+ dbg ! ( self . options. signer_address) ;
273+ dbg ! ( hash) ;
274+ dbg ! ( signature) ;
275+
271276 match contract
272277 . isValidSignature ( hash, signature_bytes. into ( ) )
273278 . call ( )
274279 . await
275280 {
276281 Ok ( response) => {
282+ dbg ! ( response) ;
277283 let expected_magic = ERC1271Contract :: isValidSignatureCall:: SELECTOR ;
278284 Ok ( response. as_slice ( ) == expected_magic)
279285 }
280- Err ( _) => Ok ( false ) ,
286+ Err ( e) => {
287+ let data = e. as_revert_data ( ) . unwrap ( ) ;
288+ dbg ! ( decode_revert_reason( data. as_ref( ) ) ) ;
289+ Ok ( false )
290+ }
281291 }
282292 }
283293
0 commit comments