Add helper for recovering authority (#750)

For EIP-7702 SetCode transaction, it is necessary to identify the
authority issuing an authorization. Its account's code is set to
proxy to the authorization address if successful.
This commit is contained in:
Etan Kissling 2024-10-15 16:44:10 +02:00 committed by GitHub
parent b736906dc7
commit 171531fbf1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 0 deletions

View File

@ -305,6 +305,23 @@ proc readTxEip4844(rlp: var Rlp, tx: var Transaction) {.raises: [RlpError].} =
rlp.read(tx.R) rlp.read(tx.R)
rlp.read(tx.S) rlp.read(tx.S)
func rlpEncodeEip7702(auth: Authorization): seq[byte] =
var w = initRlpWriter()
w.append(0x05'u8)
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].} = proc read*(rlp: var Rlp, T: type Authorization): T {.raises: [RlpError].} =
rlp.tryEnterList() rlp.tryEnterList()
result.chainId = rlp.read(uint64).ChainId result.chainId = rlp.read(uint64).ChainId