mirror of
https://github.com/Discreetly/interfaces.git
synced 2026-01-10 05:18:04 -05:00
added message types for different types of rooms & signalhashing
This commit is contained in:
7
package-lock.json
generated
7
package-lock.json
generated
@@ -1,14 +1,17 @@
|
||||
{
|
||||
"name": "discreetly-interfaces",
|
||||
"version": "0.1.14",
|
||||
"version": "0.1.38",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "discreetly-interfaces",
|
||||
"version": "0.1.14",
|
||||
"version": "0.1.38",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@ethersproject/bytes": "^5.7.0",
|
||||
"@ethersproject/keccak256": "^5.7.0",
|
||||
"@ethersproject/strings": "^5.7.0",
|
||||
"poseidon-lite": "^0.2.0",
|
||||
"rlnjs": "^3.1.4"
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "discreetly-interfaces",
|
||||
"version": "0.1.37",
|
||||
"version": "0.1.38",
|
||||
"description": "Common interfaces and utilities for discreetly",
|
||||
"author": "AtHeartEngineer",
|
||||
"homepage": "https://github.com/Discreetly",
|
||||
@@ -45,6 +45,9 @@
|
||||
"README.md"
|
||||
],
|
||||
"dependencies": {
|
||||
"@ethersproject/bytes": "^5.7.0",
|
||||
"@ethersproject/keccak256": "^5.7.0",
|
||||
"@ethersproject/strings": "^5.7.0",
|
||||
"poseidon-lite": "^0.2.0",
|
||||
"rlnjs": "^3.1.4"
|
||||
},
|
||||
|
||||
12
src/index.ts
12
src/index.ts
@@ -1,12 +1,17 @@
|
||||
import type { RLNFullProof } from 'rlnjs';
|
||||
import { MessageType, MessageInterfaces } from './messageTypes';
|
||||
export * from './utils';
|
||||
export * from './messageTypes';
|
||||
export type IdentityCommitmentT = bigint | string;
|
||||
export type RoomType = 'PUBLIC' | 'PRIVATE';
|
||||
export type MembershipType = 'IDENTITY_LIST' | 'BANDADA_GROUP';
|
||||
|
||||
export interface MessageI {
|
||||
id?: string; // database ID
|
||||
messageId?: string; // internal nullifier as string
|
||||
roomId?: RLNFullProof['rlnIdentifier'] | string;
|
||||
message: string;
|
||||
messageType?: MessageType;
|
||||
message: MessageInterfaces | string; // TODO remove string once we have a migrationinterface
|
||||
proof?: RLNFullProof | string;
|
||||
epoch?: number | bigint;
|
||||
timeStamp?: string | Date | number; // unix epoch time in ms as string
|
||||
@@ -25,16 +30,17 @@ export interface RoomI {
|
||||
rateLimit?: number; // Milliseconds between epochs
|
||||
banRateLimit?: number; // starting number of epochs banned for
|
||||
userMessageLimit?: number; // default number of messages per epoch per user
|
||||
membershipType?: string;
|
||||
membershipType?: MembershipType | string; // TODO remove string once we have a migration
|
||||
identities?: IdentityCommitmentT[];
|
||||
semaphoreIdentities?: IdentityCommitmentT[];
|
||||
adminIdentities?: IdentityCommitmentT[];
|
||||
contractAddress?: string; // RLN_CONTRACT as "chainID:0xADDRESS"
|
||||
bandadaAddress?: string; // Bandada root url address
|
||||
bandadaGroupId?: string; // Bandada group id
|
||||
epochs?: any[]; // this is for use in the db, not for the client
|
||||
messages?: MessageI[]; // this is a list of messages DATABASE REFERENCES to messages
|
||||
claimCodes?: string[]; // this is a list of claim codes for the room
|
||||
type?: string; // Public or private, if undefinied, assume public
|
||||
type?: RoomType | string; // Room Type // TODO remove string once we have a migration
|
||||
}
|
||||
|
||||
export interface ServerI {
|
||||
|
||||
20
src/messageTypes.ts
Normal file
20
src/messageTypes.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export type MessageType = 'TEXT' | 'PIXEL' | 'BBS' | 'POLL';
|
||||
export type MessageInterfaces = string | PixelMessage | BBSMessage | PollMessage;
|
||||
|
||||
export type HexColor = `#${string}`;
|
||||
|
||||
export interface PixelMessage {
|
||||
x: number;
|
||||
y: number;
|
||||
color: HexColor;
|
||||
}
|
||||
|
||||
export interface BBSMessage {
|
||||
title: string;
|
||||
body: string;
|
||||
}
|
||||
|
||||
export interface PollMessage {
|
||||
title: string;
|
||||
options: string[];
|
||||
}
|
||||
13
src/utils.ts
13
src/utils.ts
@@ -1,4 +1,7 @@
|
||||
import { poseidon2 } from 'poseidon-lite/poseidon2';
|
||||
import { hexlify } from '@ethersproject/bytes';
|
||||
import { toUtf8Bytes } from '@ethersproject/strings';
|
||||
import { keccak256 } from '@ethersproject/keccak256';
|
||||
|
||||
export function str2BigInt(str: string) {
|
||||
let num = '';
|
||||
@@ -42,3 +45,13 @@ export function getRateCommitmentHash(
|
||||
): bigint {
|
||||
return poseidon2([identityCommitment, userMessageLimit]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hashes a signal string with Keccak256.
|
||||
* @param signal The RLN signal.
|
||||
* @returns The signal hash.
|
||||
*/
|
||||
export function calculateSignalHash(signal: string): bigint {
|
||||
const converted = hexlify(toUtf8Bytes(signal));
|
||||
return BigInt(keccak256(converted)) >> BigInt(8);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user