mirror of
https://github.com/Discreetly/server.git
synced 2026-01-08 20:18:08 -05:00
Merge branch 'main' into session-ids
This commit is contained in:
@@ -77,4 +77,4 @@
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.1.6"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ export function createMessageInRoom(roomId: string, message: MessageI): Promise<
|
||||
create: {
|
||||
message: message.message ? String(message.message) : '',
|
||||
messageId: message.messageId ? message.messageId.toString() : '',
|
||||
messageType: message.messageType,
|
||||
messageType: message.messageType!,
|
||||
proof: JSON.stringify(message.proof),
|
||||
roomId: roomId
|
||||
}
|
||||
|
||||
@@ -177,6 +177,10 @@ export async function addIdentityToIdentityListRooms(
|
||||
}
|
||||
}
|
||||
});
|
||||
console.debug(
|
||||
`Successfully created and added user to Identity List room ${room.roomId}`
|
||||
);
|
||||
addedRooms.push(roomId);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createMessageInRoom, findRoomWithMessageId, removeIdentityFromRoom } from './db/';
|
||||
import { createMessageInRoom, findRoomWithMessageId } from './db/';
|
||||
import { MessageI, RoomI } from 'discreetly-interfaces';
|
||||
import { shamirRecovery, getIdentityCommitmentFromSecret } from '../crypto/shamirRecovery';
|
||||
import { shamirRecovery } from '../crypto/shamirRecovery';
|
||||
import { RLNFullProof } from 'rlnjs';
|
||||
import { verifyProof } from '../crypto/';
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ import type { Request, Response } from 'express';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { limiter } from '../middleware';
|
||||
import asyncHandler from 'express-async-handler';
|
||||
import { SNARKProof } from '../../types';
|
||||
import { verifyTheWordProof } from '../../gateways/theWord/verifier';
|
||||
import { addIdentityToIdentityListRooms } from '../../data/db';
|
||||
import { RoomI } from 'discreetly-interfaces';
|
||||
import { SNARKProof } from 'idc-nullifier';
|
||||
|
||||
const router = express.Router();
|
||||
const prisma = new PrismaClient();
|
||||
@@ -23,25 +23,24 @@ router.post(
|
||||
'/join',
|
||||
limiter,
|
||||
asyncHandler(async (req: Request, res: Response) => {
|
||||
const { proof, idc } = req.body as { proof: SNARKProof; idc: string };
|
||||
|
||||
const { proof, idc } = req.body as { proof: SNARKProof, idc: string };
|
||||
const isValid = await verifyTheWordProof(proof);
|
||||
if (isValid) {
|
||||
const room = (await prisma.rooms.findUnique({
|
||||
const room = await prisma.rooms.findUnique({
|
||||
where: {
|
||||
roomId: '007' + process.env.THEWORD_ITERATION
|
||||
}
|
||||
})) as RoomI;
|
||||
}) as RoomI;
|
||||
const addedRoom = await addIdentityToIdentityListRooms([room], idc);
|
||||
if (addedRoom.length === 0) {
|
||||
res.status(500).json({
|
||||
status: 'already-added',
|
||||
message: 'Identity already added to room'
|
||||
roomIds: []
|
||||
});
|
||||
} else {
|
||||
res.status(200).json({
|
||||
status: 'valid',
|
||||
roomId: room.roomId
|
||||
roomIds: [room.roomId]
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import express from 'express';
|
||||
import type { Request, Response } from 'express';
|
||||
import { limiter } from '../middleware';
|
||||
import asyncHandler from 'express-async-handler';
|
||||
// import asyncHandler from 'express-async-handler';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { verifyIdentityProof } from '../../crypto/idcVerifier/verifier';
|
||||
// import { verifyIdentityProof } from '../../crypto/idcVerifier/verifier';
|
||||
import { pp } from '../../utils';
|
||||
import { IDCProof } from 'idc-nullifier/dist/types/types';
|
||||
// import { IDCProof } from 'idc-nullifier/dist/types/types';
|
||||
import { addRoomData } from '../../types';
|
||||
import {
|
||||
findRoomById,
|
||||
findRoomsByIdentity,
|
||||
// findRoomsByIdentity,
|
||||
createRoom,
|
||||
removeRoom,
|
||||
removeMessage
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { SNARKProof } from '../../types';
|
||||
import { groth16 } from 'snarkjs';
|
||||
import vkey from './vkey';
|
||||
import { SNARKProof } from 'idc-nullifier';
|
||||
|
||||
|
||||
export async function verifyTheWordProof(proof: SNARKProof): Promise<boolean> {
|
||||
|
||||
|
||||
const isValid = groth16.verify(vkey, proof.publicSignals, proof.proof);
|
||||
|
||||
return isValid;
|
||||
|
||||
Reference in New Issue
Block a user