Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper for recovering authority #750

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions eth/common/transactions_rlp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,23 @@ proc readTxEip4844(rlp: var Rlp, tx: var Transaction) {.raises: [RlpError].} =
rlp.read(tx.R)
rlp.read(tx.S)

func rlpEncodeEip7702(auth: Authorization): seq[byte] =
var w = initRlpWriter()
w.append(0x05'u8)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works :) cross-checked against https://github.com/ethereum/EIPs/blob/e0d0c814bb8b240d4dc44fefc48bc7aa00792504/assets/eip-6404/convert_tests.py#L96 I got the same authorities with this nim-eth code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you port the tests to nim-eth then?

w.startList(3)
w.append(auth.chainId.uint64)
w.append(auth.address)
w.append(auth.nonce)
w.finish()

func encodeForSigning*(auth: Authorization): seq[byte] =
## Encode authorization data in preparation for signing or signature checking.
auth.rlpEncodeEip7702

func rlpHashForSigning*(auth: Authorization): Hash32 =
# Hash authorization without signature
keccak256(encodeForSigning(auth))

proc read*(rlp: var Rlp, T: type Authorization): T {.raises: [RlpError].} =
rlp.tryEnterList()
result.chainId = rlp.read(uint64).ChainId
Expand Down