-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support custom node hash in SimpleMerkleTree (#39)
Co-authored-by: ernestognw <[email protected]>
- Loading branch information
1 parent
6ab2cfb
commit 29f611e
Showing
9 changed files
with
399 additions
and
99 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
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,14 @@ | ||
import { defaultAbiCoder } from '@ethersproject/abi'; | ||
import { keccak256 } from '@ethersproject/keccak256'; | ||
import { BytesLike, HexString, concat, compare } from './bytes'; | ||
|
||
export type LeafHash<T> = (leaf: T) => HexString; | ||
export type NodeHash = (left: BytesLike, right: BytesLike) => HexString; | ||
|
||
export function standardLeafHash<T extends any[]>(types: string[], value: T): HexString { | ||
return keccak256(keccak256(defaultAbiCoder.encode(types, value))); | ||
} | ||
|
||
export function standardNodeHash(a: BytesLike, b: BytesLike): HexString { | ||
return keccak256(concat([a, b].sort(compare))); | ||
} |
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
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
Oops, something went wrong.