-
Notifications
You must be signed in to change notification settings - Fork 231
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
Showing
7 changed files
with
49 additions
and
13 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
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,16 @@ | ||
import { BigNumber } from "@ethersproject/bignumber" | ||
import { BytesLike, Hexable, zeroPad } from "@ethersproject/bytes" | ||
import { keccak256 } from "@ethersproject/keccak256" | ||
import { NumericString } from "@zk-kit/groth16" | ||
|
||
/** | ||
* Creates a keccak256 hash of a message compatible with the SNARK scalar modulus. | ||
* @param message The message to be hashed. | ||
* @returns The message digest. | ||
*/ | ||
export default function hash(message: BytesLike | Hexable | number | bigint): NumericString { | ||
message = BigNumber.from(message).toTwos(256).toHexString() | ||
message = zeroPad(message, 32) | ||
|
||
return (BigInt(keccak256(message)) >> BigInt(8)).toString() as NumericString | ||
} |
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
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