-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
188a989
commit 967eb83
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { hashMessageHash } from './hashMessageHash' | ||
import { test, expect } from 'vitest' | ||
|
||
test('returns correct source hash', async () => { | ||
const hash = | ||
'0xB1C3824DEF40047847145E069BF467AA67E906611B9F5EF31515338DB0AABFA2' | ||
// checked result of same method in OP SDK | ||
expect(hashMessageHash(hash)).toEqual( | ||
'0x4a932049252365b3eedbc5190e18949f2ec11f39d3bef2d259764799a1b27d99', | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Hex, encodeAbiParameters, keccak256, parseAbiParameters } from 'viem' | ||
|
||
// from https://github.com/ethereum-optimism/optimism/blob/develop/packages/sdk/src/utils/message-utils.ts#L42 | ||
// adapted to viem | ||
|
||
/** | ||
* Utility for hashing a message hash. This computes the storage slot | ||
* where the message hash will be stored in state. HashZero is used | ||
* because the first mapping in the contract is used. | ||
* | ||
* @param messageHash Message hash to hash. | ||
* @returns Hash of the given message hash. | ||
*/ | ||
export const hashMessageHash = (messageHash: Hex): string => { | ||
const data = encodeAbiParameters(parseAbiParameters(['bytes32, uint256']), [ | ||
messageHash, | ||
0n, | ||
]) | ||
return keccak256(data) | ||
} |