@@ -11,7 +11,7 @@ use crate::abi::prebuild::erc721::Erc721;
11
11
use crate :: abi:: prebuild:: ExecuteArgs ;
12
12
use crate :: address:: { Address , EvmAddress } ;
13
13
use crate :: evm_context:: EvmContext ;
14
- use crate :: modules :: authorization_signer :: AuthorizationSigner ;
14
+ use crate :: message :: { to_signing , EthMessage } ;
15
15
use crate :: transaction:: access_list:: { Access , AccessList } ;
16
16
use crate :: transaction:: authorization_list:: {
17
17
Authorization , AuthorizationList , SignedAuthorization ,
@@ -29,6 +29,7 @@ use tw_encoding::hex::DecodeHex;
29
29
use tw_hash:: H256 ;
30
30
use tw_keypair:: ecdsa:: secp256k1;
31
31
use tw_keypair:: ecdsa:: secp256k1:: Signature ;
32
+ use tw_keypair:: traits:: SigningKeyTrait ;
32
33
use tw_keypair:: KeyPairError ;
33
34
use tw_memory:: Data ;
34
35
use tw_number:: U256 ;
@@ -657,7 +658,7 @@ impl<Context: EvmContext> TxBuilder<Context> {
657
658
. into_tw ( )
658
659
. context ( "Invalid authority address" ) ?;
659
660
660
- let signed_authorization =
661
+ let ( authorization , signature ) =
661
662
if let Some ( other_auth_fields) = & eip7702_authorization. custom_signature {
662
663
// If field `custom_signature` is provided, it means that the authorization is already signed.
663
664
let chain_id = U256 :: from_big_endian_slice ( & other_auth_fields. chain_id )
@@ -676,16 +677,14 @@ impl<Context: EvmContext> TxBuilder<Context> {
676
677
. tw_err ( SigningErrorType :: Error_invalid_params )
677
678
. context ( "Invalid signature" ) ?;
678
679
679
- SignedAuthorization {
680
- authorization : Authorization {
680
+ (
681
+ Authorization {
681
682
chain_id,
682
683
address,
683
684
nonce,
684
685
} ,
685
- y_parity : signature. v ( ) ,
686
- r : U256 :: from_big_endian ( signature. r ( ) ) ,
687
- s : U256 :: from_big_endian ( signature. s ( ) ) ,
688
- }
686
+ signature,
687
+ )
689
688
} else {
690
689
// If field `custom_signature` is not provided, the authorization will be signed with the provided private key, nonce and chainId
691
690
let signer_key = secp256k1:: PrivateKey :: try_from ( input. private_key . as_ref ( ) )
@@ -707,17 +706,26 @@ impl<Context: EvmContext> TxBuilder<Context> {
707
706
. into_tw ( )
708
707
. context ( "Invalid nonce" ) ?;
709
708
710
- AuthorizationSigner :: sign (
711
- & signer_key,
712
- Authorization {
713
- chain_id,
714
- address,
715
- // `authorization.nonce` must be incremented by 1 over `transaction.nonce`.
716
- nonce : nonce + 1 ,
717
- } ,
718
- ) ?
709
+ let authorization = Authorization {
710
+ chain_id,
711
+ address,
712
+ // `authorization.nonce` must be incremented by 1 over `transaction.nonce`.
713
+ nonce : nonce + 1 ,
714
+ } ;
715
+
716
+ let pre_hash = authorization. hash ( ) . map_err ( to_signing) ?;
717
+ let signature = signer_key. sign ( pre_hash) ?;
718
+
719
+ ( authorization, signature)
719
720
} ;
720
721
722
+ let signed_authorization = SignedAuthorization {
723
+ authorization,
724
+ y_parity : signature. v ( ) ,
725
+ r : U256 :: from_big_endian ( signature. r ( ) ) ,
726
+ s : U256 :: from_big_endian ( signature. s ( ) ) ,
727
+ } ;
728
+
721
729
Ok ( AuthorizationList :: from ( vec ! [ signed_authorization] ) )
722
730
}
723
731
}
0 commit comments