mirror of
https://github.com/Discreetly/server.git
synced 2026-01-09 12:37:58 -05:00
fix signal hash
This commit is contained in:
3
package-lock.json
generated
3
package-lock.json
generated
@@ -9,6 +9,9 @@
|
||||
"version": "0.1.2",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@ethersproject/bytes": "^5.7.0",
|
||||
"@ethersproject/keccak256": "^5.7.0",
|
||||
"@ethersproject/strings": "^5.7.0",
|
||||
"@faker-js/faker": "^8.0.2",
|
||||
"@prisma/client": "^5.0.0",
|
||||
"body-parser": "^1.20.2",
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@ethersproject/bytes": "^5.7.0",
|
||||
"@ethersproject/keccak256": "^5.7.0",
|
||||
"@ethersproject/strings": "^5.7.0",
|
||||
"@faker-js/faker": "^8.0.2",
|
||||
"@prisma/client": "^5.0.0",
|
||||
"body-parser": "^1.20.2",
|
||||
|
||||
13
src/crypto/signalHash.ts
Normal file
13
src/crypto/signalHash.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { hexlify } from '@ethersproject/bytes';
|
||||
import { toUtf8Bytes } from '@ethersproject/strings';
|
||||
import { keccak256 } from '@ethersproject/keccak256';
|
||||
|
||||
/**
|
||||
* Hashes a signal string with Keccak256.
|
||||
* @param signal The RLN signal.
|
||||
* @returns The signal hash.
|
||||
*/
|
||||
export function calculateSignalHash(signal: string): bigint {
|
||||
const converted = hexlify(toUtf8Bytes(signal));
|
||||
return BigInt(keccak256(converted)) >> BigInt(8);
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { MessageI, RoomI } from 'discreetly-interfaces';
|
||||
import { str2BigInt } from 'discreetly-interfaces';
|
||||
import { RLNFullProof, RLNVerifier } from 'rlnjs';
|
||||
import vkey from './verification_key';
|
||||
import { Group } from '@semaphore-protocol/group';
|
||||
import { calculateSignalHash } from './signalHash';
|
||||
|
||||
const v = new RLNVerifier(vkey);
|
||||
|
||||
@@ -16,7 +16,7 @@ async function verifyProof(msg: MessageI, room: RoomI, epochErrorRange = 5): Pro
|
||||
const rateLimit = room.rateLimit ? room.rateLimit : 1000;
|
||||
const currentEpoch = Math.floor(timestamp / rateLimit);
|
||||
const rlnIdentifier = BigInt(msg.roomId);
|
||||
const msgHash = str2BigInt(msg.message);
|
||||
const msgHash = calculateSignalHash(msg.message);
|
||||
let proof: RLNFullProof | undefined;
|
||||
// Check that the epoch falls within the range for the room
|
||||
const epoch = BigInt(msg.epoch);
|
||||
|
||||
Reference in New Issue
Block a user