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