Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/hashing.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable jsdoc/require-jsdoc */

import { blake2b } from '@noble/hashes/blake2.js'
import { blake512 } from '@noble/hashes/blake1.js'
import type { Point } from '@zk-kit/baby-jubjub'
import { leBigIntToBuffer, leBufferToBigInt } from '@zk-kit/utils'
import { poseidon5 } from 'poseidon-lite'

type HashFn = (m: Uint8Array) => Uint8Array
// TODO: to modularize this hasher, we can add more hash functions here
function blake2BWrapper (m: Uint8Array) {
return blake2b(m, { dkLen: 64 })
function blake512Wrapper (m: Uint8Array) {
return blake512(m)
}

/**
Expand All @@ -29,7 +29,7 @@ class RFC9591Hasher {
*/
constructor (contextString: string, order: bigint, hashFn?: HashFn) {
this.contextString = contextString
this.hashFn = hashFn ?? blake2BWrapper
this.hashFn = hashFn ?? blake512Wrapper
this.order = order
}

Expand Down
26 changes: 13 additions & 13 deletions test/hashes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ function toHex(buffer: Uint8Array) {
const INPUT_HEX = '103056215bc7e90f9bbf1a4b4371b4484649a8ef98098c3326f9cb582673068a'
const INPUT = hexToBytes(INPUT_HEX)

// Expected vectors from the prompt
// BLAKE-512 (BLAKE-1 / SHA-3 finalist) vectors for the 32-byte input above
const VECTORS = {
'H1': {
rawHex: '517822754585151647635ec2224ab27d6a83e6629ebf3d36b1ad419eb400b9e50352423edec008d7e08fe9fddc571f592ff82da660a02a2c3d5dbac8426a079d',
modDec: 1011714033864805916802867513617709433878078050615495686330311857274316592610n,
modHex: '0x23c9c1f2be6312c1cf47ab103220a6d50059f50020dbda92a158e5266eb15e2'
rawHex: 'db60748bfe364a66d8a534c9aae75ed21681ee98b2646e28a2348b851d4e1f0e6954f75d5146d5d99ae79f8a1c4a6af4ba056df0c4eee0032db0e67b42bf277b',
modDec: 1678949461854840229640339098254152788517688981803963206851042767735562726141n,
modHex: '0x3b64070b4bfe54a871407503712f1918062d4a26284774df303393d973c6afd'
},
'H3': {
rawHex: 'bcdd17d7d0d207a7fb860509ee09546dfca51454b0b591c547626e565272a1f60c0b37e46b18794793318ebd49c430349b2e467c0862d5bc9ebf4a868069f35f',
modDec: 2247655552097648134964227634858129138190003209803194921068384139971060600961n,
modHex: '0x4f820c1fc138c5e2dc3c7a16230acb75f8d13da98b23f952f561d3715489081'
rawHex: '5bbb9d21a860ca973b78cef0056a4c57c354ea0705e28136f447a736a75dd72b7f9e504a3f359a5840f3ace159ecc012d95a18f9ee94f0799462221675d22ff1',
modDec: 1213950929864348775292835996094940120861297402490820397600529732903868101565n,
modHex: '0x2af12668e8e162c9b3aa0ab3acea87d9542420ee5f0e5420671392dcd64f3bd'
},
'H4': {
rawHex: '39c1201c3014ba6032db564c77835ecc98a5e8f55ce10b904edba4293a00ad2fd792e0ed2b54e2621e7ed71c79e16a4e0d41e427f3240759b88e2a2f04df196e',
modDec: 2658467010355774823620755361084890962955677056727848814744952892684839397019n,
modHex: '0x5e0a395dcb3661341ee884396c6ce17c33f63a7c6ccf95e8849429da84ba69b'
rawHex: '2316e8d9a9db62b6c37b1d8d77a354b0335561c2a893ac5b2c7b08af4a5d978c761a64400ccf50bb9349baec2c29904da4e0dda54c564ff98cecb03da9bcb323',
modDec: 1252599766121406257733049228675028233963257259286401030830052074095697611857n,
modHex: '0x2c4f243918758686fd1a27d4572d6cb888aaadb0914a1ebac92f9c326064c51'
},
'H5': {
rawHex: '6146fffab891f131e3062a315b15f1973c549d98a56f9670c8912699aa5f177cca177e364308d02a298c15401f4bbe7f6ed0263be81b6597856f13ae89509d9a',
modDec: 1548104687198327700120789144102730872945653177570532681524096721970790712817n,
modHex: '0x36c323a46d1ebb644d126e0ae5f6ca61ad35252b8c7b8707fe6ae2df344c5f1'
rawHex: '53626e59d4f3f1aed62ead01bc0205e9c039b98fe1d30dabae22c37e8250e6a433d652c6c2958aa68bf7de931af787887a8d1c65fdb48cc10a3ffc53c760b9af',
modDec: 2053056783151336678290556986299662488575879129835563357194705989096511257949n,
modHex: '0x489fd2c7a4e21b7ae996096535f467ae251a13ab1cde88781ae06fe1ac23d5d'
}
} as const

Expand Down