Skip to content

Commit a76940b

Browse files
Merge pull request #543 from LedgerHQ/fix/apa/client_non_legacy_recover_transaction
Fix recover_transaction function in Ragger client
2 parents 4277465 + 682354c commit a76940b

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

client/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
### Fixed
1515

1616
- Increased the delay between `autonext` callback calls for EIP-712 on Stax
17+
- `recover_transaction` util function for non-legacy transactions
1718

1819
## [0.2.1] - 2023-12-01
1920

client/src/ledger_app_clients/ethereum/utils.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,22 @@ def recover_message(msg, vrs: tuple) -> bytes:
1717
return bytes.fromhex(addr[2:])
1818

1919

20-
# TODO: Figure out why it doesn't work for non-legacy transactions
2120
def recover_transaction(tx_params, vrs: tuple) -> bytes:
2221
raw_tx = Account.create().sign_transaction(tx_params).rawTransaction
2322
prefix = bytes()
2423
if raw_tx[0] in [0x01, 0x02]:
2524
prefix = raw_tx[:1]
2625
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])
3836
decoded = rlp.decode(raw_tx)
3937
reencoded = rlp.encode(decoded[:-3] + list(vrs))
4038
addr = Account.recover_transaction(prefix + reencoded)

0 commit comments

Comments
 (0)