From cd34a058ded776fdfa76ec04dc429e2930188011 Mon Sep 17 00:00:00 2001 From: AtHeartEngineer <1675654+AtHeartEngineer@users.noreply.github.com> Date: Wed, 23 Aug 2023 11:27:23 -0400 Subject: [PATCH] added SemaphoreIdentities and rateLimitHasher --- package.json | 2 +- src/index.ts | 3 ++- src/utils.ts | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5bb8316..c9ac129 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discreetly-interfaces", - "version": "0.1.34", + "version": "0.1.35", "description": "Common interfaces and utilities for discreetly", "author": "AtHeartEngineer", "homepage": "https://github.com/Discreetly", diff --git a/src/index.ts b/src/index.ts index 665f8ac..d9c573f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import type { RLNFullProof } from 'rlnjs'; -export { str2BigInt, genId, randomBigInt } from './utils'; +export * from './utils'; export type IdentityCommitmentT = bigint | string; export interface MessageI { @@ -27,6 +27,7 @@ export interface RoomI { userMessageLimit?: number; // default number of messages per epoch per user membershipType?: string; identities?: IdentityCommitmentT[]; + semaphoreIdentities?: IdentityCommitmentT[]; contractAddress?: string; // RLN_CONTRACT as "chainID:0xADDRESS" bandadaAddress?: string; // Bandada root url address bandadaGroupId?: string; // Bandada group id diff --git a/src/utils.ts b/src/utils.ts index 0d486ce..02e07a8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -8,6 +8,12 @@ export function str2BigInt(str: string) { return BigInt(num); } +/** + * @description Generates a room ID from a server ID and room name + * @param serverID : bigint | string | number + * @param roomName : bigint | string | number + * @returns roomId : bigint + */ export function genId(serverID: string | bigint | number, roomName: string | bigint | number) { if (typeof roomName === 'string') { return poseidon2([BigInt(serverID), str2BigInt(roomName)]); @@ -23,3 +29,16 @@ export function randomBigInt(bits: number = 253) { } return BigInt('0x' + hexString); } + +/** + * @description Hashes the identity commitment and user message limit into the rate commitment + * @param identityCommitment Semaphore Identity Commitment + * @param userMessageLimit Number of messages a user can send per RLN epoch + * @returns rlnRateCommitment + */ +export function getRateCommitmentHash( + identityCommitment: bigint, + userMessageLimit: number | bigint +): bigint { + return poseidon2([identityCommitment, userMessageLimit]); +}