mirror of
https://github.com/Discreetly/server.git
synced 2026-01-10 13:08:07 -05:00
Merge branch 'main' of github.com:Discreetly/server into main
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@@ -14,7 +14,7 @@
|
||||
"body-parser": "^1.20.2",
|
||||
"cors": "^2.8.5",
|
||||
"discreetly-claimcodes": "^1.1.3",
|
||||
"discreetly-interfaces": "^0.1.23",
|
||||
"discreetly-interfaces": "^0.1.29",
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.18.2",
|
||||
"express-basic-auth": "^1.2.1",
|
||||
@@ -3470,9 +3470,9 @@
|
||||
"integrity": "sha512-2QnlhYUPIGLl11XgxIxl6ZKIJZoS2T1ABIHbqjBbec0YYQ2qfWZ7JWH53OZm0mqeO8Dbjon5zK3YNoGiuYJ1Gg=="
|
||||
},
|
||||
"node_modules/discreetly-interfaces": {
|
||||
"version": "0.1.23",
|
||||
"resolved": "https://registry.npmjs.org/discreetly-interfaces/-/discreetly-interfaces-0.1.23.tgz",
|
||||
"integrity": "sha512-C1mqzLZY52aW83XHUBr3lxe8F7HFagx4V+MzigxPf5GTjDGhelIbnmihhV3RUtWb1uddo1Gm1CImD+meygf1bg==",
|
||||
"version": "0.1.29",
|
||||
"resolved": "https://registry.npmjs.org/discreetly-interfaces/-/discreetly-interfaces-0.1.29.tgz",
|
||||
"integrity": "sha512-3R63KkmB+wFKFFzD9DixX3VDoLCYkDuMQZucAItmXbjE+0tFgmrK683a1/WBI9VkBhARip6HsVNrjzaGqdR1Aw==",
|
||||
"dependencies": {
|
||||
"poseidon-lite": "^0.2.0",
|
||||
"rlnjs": "^3.1.4"
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
"body-parser": "^1.20.2",
|
||||
"cors": "^2.8.5",
|
||||
"discreetly-claimcodes": "^1.1.3",
|
||||
"discreetly-interfaces": "^0.1.23",
|
||||
"discreetly-interfaces": "^0.1.29",
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.18.2",
|
||||
"express-basic-auth": "^1.2.1",
|
||||
@@ -64,4 +64,4 @@
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.1.6"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,6 @@ datasource db {
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
enum RoomMembershipType {
|
||||
IDENTITY_LIST
|
||||
RLN_CONTRACT
|
||||
BANDADA
|
||||
}
|
||||
|
||||
model Rooms {
|
||||
id String @id @default(auto()) @map("_id") @db.ObjectId
|
||||
@@ -23,7 +18,7 @@ model Rooms {
|
||||
rateLimit Int @default(1000) // epoch length in ms
|
||||
banRateLimit Int @default(1000000) // starting number of epochs banned for
|
||||
userMessageLimit Int @default(1) // per epoch
|
||||
membershipType RoomMembershipType @default(IDENTITY_LIST)
|
||||
membershipType String @default("IDENTITY_LIST")
|
||||
identities String[] @default([])
|
||||
contractAddress String? // RLN_CONTRACT as "chainID:0xADDRESS"
|
||||
bandadaAddress String? // BANDADA as "url:groupID"
|
||||
@@ -31,6 +26,7 @@ model Rooms {
|
||||
messages Messages[]
|
||||
claimCodes ClaimCodes[] @relation(fields: [claimCodeIds], references: [id])
|
||||
claimCodeIds String[] @default([]) @db.ObjectId
|
||||
type String
|
||||
}
|
||||
|
||||
model ClaimCodes {
|
||||
|
||||
@@ -40,9 +40,11 @@ async function verifyProof(msg: MessageI, room: RoomI, epochErrorRange = 5): Pro
|
||||
}
|
||||
|
||||
// Check that the merkle root is correct
|
||||
const group = new Group(room.id, 20, room.membership?.identityCommitments);
|
||||
if (group.root !== msg.proof.snarkProof.publicSignals.root) {
|
||||
return false;
|
||||
if (room.identities && Array.isArray(room.identities)) {
|
||||
const group = new Group(room.id, 20, room.identities as bigint[] | undefined);
|
||||
if (group.root !== msg.proof.snarkProof.publicSignals.root) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check that the proof is correct
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { RoomI, genId } from 'discreetly-interfaces';
|
||||
import { genId } from 'discreetly-interfaces';
|
||||
import type { RoomI } from 'discreetly-interfaces';
|
||||
import { serverConfig } from '../config/serverConfig';
|
||||
import { genMockUsers, genClaimCodeArray, pp } from '../utils';
|
||||
|
||||
@@ -17,8 +18,8 @@ interface RoomsFromClaimCode {
|
||||
roomIds: string[];
|
||||
}
|
||||
|
||||
export function getRoomByID(id: string): Promise<RoomI | null> {
|
||||
return prisma.rooms
|
||||
export async function getRoomByID(id: string): Promise<RoomI | null> {
|
||||
const room = await prisma.rooms
|
||||
.findUnique({
|
||||
where: {
|
||||
roomId: id
|
||||
@@ -29,7 +30,11 @@ export function getRoomByID(id: string): Promise<RoomI | null> {
|
||||
name: true,
|
||||
identities: true,
|
||||
rateLimit: true,
|
||||
userMessageLimit: true
|
||||
userMessageLimit: true,
|
||||
membershipType: true,
|
||||
contractAddress: true,
|
||||
bandadaAddress: true,
|
||||
type: true
|
||||
}
|
||||
})
|
||||
.then((room) => {
|
||||
@@ -39,6 +44,12 @@ export function getRoomByID(id: string): Promise<RoomI | null> {
|
||||
console.error(err);
|
||||
throw err; // Add this line to throw the error
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
if (room) {
|
||||
resolve(room as RoomI);
|
||||
}
|
||||
reject('Room not found');
|
||||
});
|
||||
}
|
||||
|
||||
export async function getRoomsByIdentity(identity: string): Promise<string[]> {
|
||||
@@ -82,29 +93,37 @@ export function updateClaimCode(code: string): Promise<RoomsFromClaimCode> {
|
||||
}
|
||||
|
||||
export function updateRoomIdentities(idc: string, roomIds: string[]): Promise<any> {
|
||||
return prisma.rooms.findMany({
|
||||
where: { id: { in: roomIds } },
|
||||
})
|
||||
.then((rooms) => {
|
||||
const roomsToUpdate = rooms
|
||||
.filter(room => !room.identities.includes(idc))
|
||||
.map(room => room.id);
|
||||
return prisma.rooms
|
||||
.findMany({
|
||||
where: { id: { in: roomIds } }
|
||||
})
|
||||
.then((rooms) => {
|
||||
const roomsToUpdate = rooms
|
||||
.filter((room) => !room.identities.includes(idc))
|
||||
.map((room) => room.id);
|
||||
|
||||
if (roomsToUpdate) {
|
||||
return prisma.rooms.updateMany({
|
||||
where: { id: { in: roomsToUpdate } },
|
||||
data: { identities: { push: idc } }
|
||||
});
|
||||
}
|
||||
}).catch(err => {
|
||||
pp(err, 'error')
|
||||
})
|
||||
if (roomsToUpdate) {
|
||||
return prisma.rooms.updateMany({
|
||||
where: { id: { in: roomsToUpdate } },
|
||||
data: { identities: { push: idc } }
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
pp(err, 'error');
|
||||
});
|
||||
}
|
||||
|
||||
export function findUpdatedRooms(roomIds: string[]): Promise<RoomI[]> {
|
||||
return prisma.rooms.findMany({
|
||||
export async function findUpdatedRooms(roomIds: string[]): Promise<RoomI[]> {
|
||||
const rooms = await prisma.rooms.findMany({
|
||||
where: { id: { in: roomIds } }
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
if (rooms) {
|
||||
resolve(rooms as RoomI[]);
|
||||
}
|
||||
reject('No rooms found');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,7 +70,11 @@ if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
|
||||
initEndpoints(app, adminAuth);
|
||||
_app = initAppListeners(PORT);
|
||||
listEndpoints(app);
|
||||
io = new SocketIOServer(_app, {});
|
||||
io = new SocketIOServer(_app, {
|
||||
cors: {
|
||||
origin: '*'
|
||||
}
|
||||
});
|
||||
initWebsockets(io);
|
||||
mock(io);
|
||||
} else {
|
||||
@@ -78,7 +82,11 @@ if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
|
||||
serverConfigStartup.port = PORT;
|
||||
initEndpoints(app, adminAuth);
|
||||
_app = initAppListeners(PORT);
|
||||
io = new SocketIOServer(_app, {});
|
||||
io = new SocketIOServer(_app, {
|
||||
cors: {
|
||||
origin: '*'
|
||||
}
|
||||
});
|
||||
initWebsockets(io);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { faker } from '@faker-js/faker';
|
||||
|
||||
export function randBigint(): bigint {
|
||||
return faker.number.bigInt();
|
||||
const min = 1000000000000000000000000000000000000000000000000000000000000000000000000000n;
|
||||
const max = 9999999999999999999999999999999999999999999999999999999999999999999999999999n;
|
||||
return faker.number.bigInt({ min: min, max: max });
|
||||
}
|
||||
|
||||
export function randomRoomName(min = 5, max = 20): string {
|
||||
|
||||
Reference in New Issue
Block a user