mirror of
https://github.com/Discreetly/interfaces.git
synced 2026-01-08 20:38:04 -05:00
added SemaphoreIdentities and rateLimitHasher
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
19
src/utils.ts
19
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]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user