@@ -17,24 +17,22 @@ def recover_message(msg, vrs: tuple) -> bytes:
17
17
return bytes .fromhex (addr [2 :])
18
18
19
19
20
- # TODO: Figure out why it doesn't work for non-legacy transactions
21
20
def recover_transaction (tx_params , vrs : tuple ) -> bytes :
22
21
raw_tx = Account .create ().sign_transaction (tx_params ).rawTransaction
23
22
prefix = bytes ()
24
23
if raw_tx [0 ] in [0x01 , 0x02 ]:
25
24
prefix = raw_tx [:1 ]
26
25
raw_tx = raw_tx [len (prefix ):]
27
- if prefix == bytes ():
28
- # v is returned on one byte only so it might have overflowed
29
- # in that case, we will reconstruct it to its full value
30
- if "chainId" in tx_params :
31
- trunc_chain_id = tx_params ["chainId" ]
32
- while trunc_chain_id .bit_length () > 32 :
33
- trunc_chain_id >>= 8
34
- target = tx_params ["chainId" ] * 2 + 35
35
- trunc_target = trunc_chain_id * 2 + 35
36
- diff = vrs [0 ][0 ] - (trunc_target & 0xff )
37
- vrs = (target + diff , vrs [1 ], vrs [2 ])
26
+ # v is returned on one byte only so it might have overflowed
27
+ # in that case, we will reconstruct it to its full value
28
+ if "chainId" in tx_params :
29
+ trunc_chain_id = tx_params ["chainId" ]
30
+ while trunc_chain_id .bit_length () > 32 :
31
+ trunc_chain_id >>= 8
32
+ target = tx_params ["chainId" ] * 2 + 35
33
+ trunc_target = trunc_chain_id * 2 + 35
34
+ diff = vrs [0 ][0 ] - (trunc_target & 0xff )
35
+ vrs = (target + diff , vrs [1 ], vrs [2 ])
38
36
decoded = rlp .decode (raw_tx )
39
37
reencoded = rlp .encode (decoded [:- 3 ] + list (vrs ))
40
38
addr = Account .recover_transaction (prefix + reencoded )
0 commit comments