added SemaphoreIdentities and rateLimitHasher

This commit is contained in:
AtHeartEngineer
2023-08-23 11:27:23 -04:00
parent a22b800f81
commit cd34a058de
3 changed files with 22 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "discreetly-interfaces", "name": "discreetly-interfaces",
"version": "0.1.34", "version": "0.1.35",
"description": "Common interfaces and utilities for discreetly", "description": "Common interfaces and utilities for discreetly",
"author": "AtHeartEngineer", "author": "AtHeartEngineer",
"homepage": "https://github.com/Discreetly", "homepage": "https://github.com/Discreetly",

View File

@@ -1,5 +1,5 @@
import type { RLNFullProof } from 'rlnjs'; import type { RLNFullProof } from 'rlnjs';
export { str2BigInt, genId, randomBigInt } from './utils'; export * from './utils';
export type IdentityCommitmentT = bigint | string; export type IdentityCommitmentT = bigint | string;
export interface MessageI { export interface MessageI {
@@ -27,6 +27,7 @@ export interface RoomI {
userMessageLimit?: number; // default number of messages per epoch per user userMessageLimit?: number; // default number of messages per epoch per user
membershipType?: string; membershipType?: string;
identities?: IdentityCommitmentT[]; identities?: IdentityCommitmentT[];
semaphoreIdentities?: IdentityCommitmentT[];
contractAddress?: string; // RLN_CONTRACT as "chainID:0xADDRESS" contractAddress?: string; // RLN_CONTRACT as "chainID:0xADDRESS"
bandadaAddress?: string; // Bandada root url address bandadaAddress?: string; // Bandada root url address
bandadaGroupId?: string; // Bandada group id bandadaGroupId?: string; // Bandada group id

View File

@@ -8,6 +8,12 @@ export function str2BigInt(str: string) {
return BigInt(num); 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) { export function genId(serverID: string | bigint | number, roomName: string | bigint | number) {
if (typeof roomName === 'string') { if (typeof roomName === 'string') {
return poseidon2([BigInt(serverID), str2BigInt(roomName)]); return poseidon2([BigInt(serverID), str2BigInt(roomName)]);
@@ -23,3 +29,16 @@ export function randomBigInt(bits: number = 253) {
} }
return BigInt('0x' + hexString); 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]);
}