diff --git a/package-lock.json b/package-lock.json index 367e671..85d0f4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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.25", "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.25", + "resolved": "https://registry.npmjs.org/discreetly-interfaces/-/discreetly-interfaces-0.1.25.tgz", + "integrity": "sha512-yWKAycHE6mwJbROT+9rQNE5fwYrYmL+VH9ZJfHl2nqt3L++31djQjVgV2xG5/rYBTrkUPnEbFXpzRF1i2pqO7g==", "dependencies": { "poseidon-lite": "^0.2.0", "rlnjs": "^3.1.4" diff --git a/package.json b/package.json index 62d550d..6c69be6 100644 --- a/package.json +++ b/package.json @@ -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.25", "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" } -} +} \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 4eebff6..5254f70 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -16,6 +16,12 @@ enum RoomMembershipType { BANDADA } +enum RoomType { + PUBLIC + PRIVATE + PIXEL +} + model Rooms { id String @id @default(auto()) @map("_id") @db.ObjectId roomId String @unique @@ -31,6 +37,7 @@ model Rooms { messages Messages[] claimCodes ClaimCodes[] @relation(fields: [claimCodeIds], references: [id]) claimCodeIds String[] @default([]) @db.ObjectId + type RoomType @default(PUBLIC) } model ClaimCodes { diff --git a/src/crypto/verifier.ts b/src/crypto/verifier.ts index e8b5352..1da92b3 100644 --- a/src/crypto/verifier.ts +++ b/src/crypto/verifier.ts @@ -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 diff --git a/src/data/db.ts b/src/data/db.ts index 61eb7bc..cb6055a 100644 --- a/src/data/db.ts +++ b/src/data/db.ts @@ -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'; @@ -29,7 +30,11 @@ export function getRoomByID(id: string): Promise { name: true, identities: true, rateLimit: true, - userMessageLimit: true + userMessageLimit: true, + membershipType: true, + contractAddress: true, + bandadaAddress: true, + type: true } }) .then((room) => { @@ -82,23 +87,25 @@ export function updateClaimCode(code: string): Promise { } export function updateRoomIdentities(idc: string, roomIds: string[]): Promise { - 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 {