Skip to content

Commit

Permalink
Merge pull request #13 from Discreetly/verifier
Browse files Browse the repository at this point in the history
chore: linting fixes, github actions tests, and remove completed todos
  • Loading branch information
AtHeartEngineer authored Jul 26, 2023
2 parents dd22266 + b79bc40 commit 7a49d88
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
18 changes: 18 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-env node */
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ["@typescript-eslint"],
overrides: [
{
files: ['*.ts', '*.tsx'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],

parserOptions: {
project: ['./tsconfig.json'], // Specify it only for TypeScript files
},
},
],
}
2 changes: 1 addition & 1 deletion src/config/rooms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MembershipI, RoomGroupI, ServerI } from 'discreetly-interfaces';
import type { RoomGroupI, ServerI } from 'discreetly-interfaces';
import { genId } from 'discreetly-interfaces';
import 'dotenv/config';

Expand Down
4 changes: 2 additions & 2 deletions src/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export default function Mock(io: SocketIOServer) {
this.weightSums = [];
let sum = 0;

for (let weight of weights) {
for (const weight of weights) {
sum += weight;
this.weightSums.push(sum);
}
}

pick() {
const rand = Math.random() * this.weightSums[this.weightSums.length - 1];
let index = this.weightSums.findIndex((sum) => rand < sum);
const index = this.weightSums.findIndex((sum) => rand < sum);
return this.values[index]();
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function initRedisVariables(redisClient: RedisClientType): Promise<
loadedRooms = JSON.parse(_CachedRooms) as unknown as RoomGroupI[];
} else {
console.log('Using default rooms');
loadedRooms = defaultRooms as RoomGroupI[];
loadedRooms = defaultRooms ;
redisClient.set('rooms', JSON.stringify(loadedRooms));
}

Expand Down Expand Up @@ -49,7 +49,7 @@ export async function initRedisVariables(redisClient: RedisClientType): Promise<
}

export function initSockets(io: SocketIOServer, loadedRooms: RoomGroupI[]) {
let userCount: userCountI = {};
const userCount: userCountI = {};
io.on('connection', (socket: Socket) => {
pp('SocketIO: a user connected', 'debug');

Expand Down Expand Up @@ -115,12 +115,12 @@ export function initExpressEndpoints(
const result: ClaimCodeStatus = ccm.claimCode(code);
const groupID = result.groupID;
if (result.status === 'CLAIMED') {
let claimedRooms: any[] = [];
let alreadyAddedRooms: any[] = [];
const claimedRooms: any[] = [];
const alreadyAddedRooms: any[] = [];
loadedRooms.forEach((group) => {
if (group.id == groupID) {
group.rooms.forEach((room: RoomI) => {
let { status, roomGroups } = addIdentityToRoom(
const { status, roomGroups } = addIdentityToRoom(
BigInt(room.id),
BigInt(idc),
loadedRooms
Expand All @@ -135,7 +135,7 @@ export function initExpressEndpoints(
});
}
});
let r = [...claimedRooms, ...alreadyAddedRooms];
const r = [...claimedRooms, ...alreadyAddedRooms];

if (claimedRooms.length > 0) {
res.status(200).json({ status: 'valid', rooms: r });
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function findRoomById(
return undefined;
}

export function findGroupById(roomGroups: RoomGroupI[], groupId: BigInt): RoomGroupI {
export function findGroupById(roomGroups: RoomGroupI[], groupId: bigint): RoomGroupI {
const group = roomGroups.find((group) => group.id === groupId);
console.log(roomGroups, groupId);
if (!group) {
Expand All @@ -36,7 +36,7 @@ export function addIdentityToRoom(
roomID: bigint,
identityCommitment: bigint,
roomGroups: RoomGroupI[]
): { status: Boolean; roomGroups: RoomGroupI[] } {
): { status: boolean; roomGroups: RoomGroupI[] } {
let added = false;
const r = findRoomById(roomGroups, roomID);

Expand Down
9 changes: 1 addition & 8 deletions src/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@ import type { MessageI, RoomGroupI } from 'discreetly-interfaces';
import { str2BigInt } from 'discreetly-interfaces';
import { RLNVerifier } from 'rlnjs';
import vkey from './verification_key.js';
import { poseidon1 } from 'poseidon-lite/poseidon1';
import { findRoomById } from './utils.js';
import { Group } from '@semaphore-protocol/group';

const v = new RLNVerifier(vkey);

async function verifyProof(msg: MessageI, roomGroups: RoomGroupI[]): Promise<boolean> {
// FIXME NEED TO VALIDATE THE FOLLOWING (IN THIS ORDER):
// TODO EPOCH FALLS WITHIN RANGE FOR ROOM
// TODO INTERNAL NULLIFIER
// TODO MESSAGE HASH IS CORRECT
// TODO VERIFY MERKLE ROOT
// TODO VERIFY PROOF LAST
const { room } = findRoomById(roomGroups, msg.room);
if (!room) {
console.warn('Room not found');
Expand All @@ -34,7 +27,7 @@ async function verifyProof(msg: MessageI, roomGroups: RoomGroupI[]): Promise<boo
}

// Check that the internal nullifier doesn't have collisions
// TODO RLNjs cache
// TODO! INTERNAL NULLIFIER (RLNjs cache)

// Check that the message hash is correct
if (msgHash !== msg.proof.snarkProof.publicSignals.x) {
Expand Down
5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
"module": "ES2022",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
"files": [
"./src/server.ts"
]
}
}

0 comments on commit 7a49d88

Please sign in to comment.