mirror of
https://github.com/kayleegeorge/zk-chat.git
synced 2026-01-09 14:18:03 -05:00
rlnjs
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,6 @@
|
||||
# dependencies
|
||||
/node_modules
|
||||
/dist
|
||||
# /dist
|
||||
.env
|
||||
/rlnjs
|
||||
/rln-circuits
|
||||
|
||||
20
dist/types/ChatApp.d.ts
vendored
Normal file
20
dist/types/ChatApp.d.ts
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Web3Provider } from '@ethersproject/providers';
|
||||
import ChatRoom from './ChatRoom';
|
||||
import { RoomType } from './types/ChatRoomOptions';
|
||||
import { Connection } from './Connection';
|
||||
import { Contract } from 'ethers';
|
||||
import User from './User';
|
||||
import RLN from './RLN';
|
||||
export default class ChatApp {
|
||||
appName: string;
|
||||
chatRoomStore: Map<string, ChatRoom>;
|
||||
rln: RLN;
|
||||
provider: Web3Provider | undefined;
|
||||
connection: Connection;
|
||||
onChain: Contract | undefined;
|
||||
constructor(appName: string, onChain?: Contract, provider?: Web3Provider, existingIdentity?: string, rlnIdentifier?: bigint);
|
||||
registerUserOnChain(): Promise<import("@semaphore-protocol/identity").Identity>;
|
||||
createChatRoom(name: string, roomType: RoomType, chatMembers?: User[]): ChatRoom;
|
||||
fetchChatRoomMsgs(contentTopic: string): Promise<void | undefined>;
|
||||
fetchChatRoomsNames(): string[];
|
||||
}
|
||||
18
dist/types/ChatRoom.d.ts
vendored
Normal file
18
dist/types/ChatRoom.d.ts
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Web3Provider } from '@ethersproject/providers';
|
||||
import { RoomType } from './types/ChatRoomOptions';
|
||||
import { Connection } from './Connection';
|
||||
import RLN from './RLN';
|
||||
import User from './User';
|
||||
export default class ChatRoom {
|
||||
roomType: RoomType;
|
||||
chatRoomName: string;
|
||||
rlnInstance: RLN;
|
||||
provider: Web3Provider | undefined;
|
||||
connection: Connection;
|
||||
private chatMembers;
|
||||
constructor(chatRoomName: string, roomType: RoomType, chatMembers: User[], rlnInstance: RLN, connection: Connection, provider?: Web3Provider);
|
||||
retrieveMessageStore(): Promise<void>;
|
||||
sendMessage(text: string, alias: string): Promise<void>;
|
||||
addChatMember(member: User): Promise<User>;
|
||||
getChatMembers(): User[];
|
||||
}
|
||||
19
dist/types/Connection.d.ts
vendored
Normal file
19
dist/types/Connection.d.ts
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import RLN from './RLN';
|
||||
declare enum ConnectionStatus {
|
||||
ready = "ready",
|
||||
connecting = "connecting",
|
||||
disconnected = "disconnected"
|
||||
}
|
||||
export declare class Connection {
|
||||
connectionStatus: ConnectionStatus;
|
||||
private connectionInstance;
|
||||
private rlnInstance;
|
||||
constructor(rlnInstance: RLN);
|
||||
connect(): void;
|
||||
disconnect(): void;
|
||||
subscribeToRoom(contentTopic: string): void;
|
||||
unsubscribeFromRoom(contentTopic: string): void;
|
||||
sendMessage(text: string, alias: string, roomName: string): Promise<void>;
|
||||
retrieveMessageStore(contentTopic: string): Promise<void>;
|
||||
}
|
||||
export {};
|
||||
34
dist/types/RLN.d.ts
vendored
Normal file
34
dist/types/RLN.d.ts
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Registry, RLN as RLNjs, RLNFullProof, Cache } from 'rlnjs';
|
||||
import { Contract } from 'ethers';
|
||||
import { Web3Provider } from '@ethersproject/providers';
|
||||
export default class RLN {
|
||||
registry: Registry;
|
||||
identityCommitments: bigint[];
|
||||
contract: Contract | undefined;
|
||||
rlnjs: RLNjs;
|
||||
cache: Cache;
|
||||
rlnIdentifier: bigint;
|
||||
identityCommitment: bigint;
|
||||
constructor(onChain?: Contract, existingIdentity?: string, rlnIdentifier?: bigint);
|
||||
initOnChain(): Promise<void>;
|
||||
generateRLNProof(msg: string, epoch: bigint): Promise<RLNFullProof>;
|
||||
verifyProof(rlnProof: RLNFullProof): Promise<boolean>;
|
||||
constructRLNMemberTree(): Promise<void>;
|
||||
registerUserOnRLNContract(provider: Web3Provider): Promise<void>;
|
||||
addProofToCache(proof: RLNFullProof): void;
|
||||
getIdentityAsString(): string;
|
||||
generateRLNcredentials(appName: string): {
|
||||
application: string;
|
||||
appIdentifier: bigint;
|
||||
credentials: {
|
||||
key: bigint;
|
||||
commitment: bigint;
|
||||
membershipGroups: {
|
||||
chainId: number;
|
||||
contract: Contract | undefined;
|
||||
treeIndex: number;
|
||||
}[];
|
||||
}[];
|
||||
version: number;
|
||||
};
|
||||
}
|
||||
6
dist/types/User.d.ts
vendored
Normal file
6
dist/types/User.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export default class User {
|
||||
address: string | undefined;
|
||||
alias: string | undefined;
|
||||
identityCommitment: bigint;
|
||||
constructor(identityCommitment: bigint, alias?: string, address?: string);
|
||||
}
|
||||
4
dist/types/index.d.ts
vendored
Normal file
4
dist/types/index.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import ChatApp from './ChatApp';
|
||||
import ChatRoom from './ChatRoom';
|
||||
import RLN from './RLN';
|
||||
export { ChatApp, ChatRoom, RLN };
|
||||
13
dist/types/proto/ChatMessage.d.ts
vendored
Normal file
13
dist/types/proto/ChatMessage.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { Codec } from 'protons-runtime';
|
||||
import type { Uint8ArrayList } from 'uint8arraylist';
|
||||
export interface ChatMessage {
|
||||
message: Uint8Array;
|
||||
epoch: bigint;
|
||||
rlnProof?: Uint8Array;
|
||||
alias?: string;
|
||||
}
|
||||
export declare namespace ChatMessage {
|
||||
const codec: () => Codec<ChatMessage>;
|
||||
const encode: (obj: ChatMessage) => Uint8Array;
|
||||
const decode: (buf: Uint8Array | Uint8ArrayList) => ChatMessage;
|
||||
}
|
||||
22
dist/types/types/ChatMessage.d.ts
vendored
Normal file
22
dist/types/types/ChatMessage.d.ts
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import * as protoType from '../proto/ChatMessage';
|
||||
import { MessageV0 } from 'js-waku/lib/waku_message/version_0';
|
||||
export declare class ChatMessage {
|
||||
proto: protoType.ChatMessage;
|
||||
constructor(proto: protoType.ChatMessage);
|
||||
static fromUtf8String(text: string, epoch: bigint, rlnProof?: Uint8Array, alias?: string): ChatMessage;
|
||||
static decodeWakuMessage(wakuMsg: MessageV0): ChatMessage | undefined;
|
||||
/**
|
||||
* Decode a protobuf payload to a ChatMessage.
|
||||
* @param bytes The payload to decode.
|
||||
*/
|
||||
static decode(bytes: Uint8Array): ChatMessage;
|
||||
/**
|
||||
* Encode this ChatMessage to a byte array, to be used as a protobuf payload.
|
||||
* @returns The encoded payload.
|
||||
*/
|
||||
encode(): Uint8Array;
|
||||
get epoch(): bigint;
|
||||
get message(): string;
|
||||
get rlnProof(): Uint8Array | undefined;
|
||||
get alias(): string | undefined;
|
||||
}
|
||||
4
dist/types/types/ChatRoomOptions.d.ts
vendored
Normal file
4
dist/types/types/ChatRoomOptions.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export declare enum RoomType {
|
||||
PubGroup = "Public",
|
||||
PrivGroup = "Private"
|
||||
}
|
||||
4
dist/types/utils/checkChain.d.ts
vendored
Normal file
4
dist/types/utils/checkChain.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { Network } from '@ethersproject/providers';
|
||||
export declare const GOERLI = 5;
|
||||
export declare const OPTIMISM = 10;
|
||||
export declare function checkChain(network: Network): Promise<void>;
|
||||
2
dist/types/utils/createWakuNode.d.ts
vendored
Normal file
2
dist/types/utils/createWakuNode.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { WakuLight } from 'js-waku/lib/interfaces';
|
||||
export declare function createWakuNode(): Promise<WakuLight | undefined>;
|
||||
5
dist/types/utils/formatting.d.ts
vendored
Normal file
5
dist/types/utils/formatting.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare function arrayify(key: string): Uint8Array;
|
||||
export declare function stringify(arr: Uint8Array): string;
|
||||
export declare function dateToEpoch(timestamp: Date): bigint;
|
||||
export declare function strToArr(s: string): Uint8Array;
|
||||
export declare function arrToStr(b: Uint8Array): string;
|
||||
1
dist/types/utils/generateAppId.d.ts
vendored
Normal file
1
dist/types/utils/generateAppId.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export default function (appName: string): bigint;
|
||||
10
dist/types/utils/getDates.d.ts
vendored
Normal file
10
dist/types/utils/getDates.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
export declare enum TimePeriod {
|
||||
Hour = "hour",
|
||||
Day = "day",
|
||||
Week = "week",
|
||||
Month = "month"
|
||||
}
|
||||
export declare function getDates(timePeriod: TimePeriod): {
|
||||
startTime: Date;
|
||||
endTime: Date;
|
||||
};
|
||||
14
package-lock.json
generated
14
package-lock.json
generated
@@ -27,7 +27,7 @@
|
||||
"protons-runtime": "^5.0.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"rlnjs": "^2.0.5",
|
||||
"rlnjs": "^2.0.6",
|
||||
"uint8arrays": "^4.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -22504,9 +22504,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/rlnjs": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/rlnjs/-/rlnjs-2.0.5.tgz",
|
||||
"integrity": "sha512-gBEfZ8g9yupdco5eDmx2IufUGeNT2q9cpceQAyyqRO1oTHyzt2CY2xxQeZIVOV+h8bCSChu0+XPuruzKnpDILA==",
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/rlnjs/-/rlnjs-2.0.6.tgz",
|
||||
"integrity": "sha512-fh+GNx5eCtonPrDWuVIncNz82kdVpr+LEBuxFZ0Nna+Umkkc9wEOdmtQIdU+XxC23shHIjAEfMIbDOQmep52zw==",
|
||||
"dependencies": {
|
||||
"@ethersproject/bytes": "^5.6.1",
|
||||
"@ethersproject/solidity": "^5.6.1",
|
||||
@@ -45058,9 +45058,9 @@
|
||||
}
|
||||
},
|
||||
"rlnjs": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/rlnjs/-/rlnjs-2.0.5.tgz",
|
||||
"integrity": "sha512-gBEfZ8g9yupdco5eDmx2IufUGeNT2q9cpceQAyyqRO1oTHyzt2CY2xxQeZIVOV+h8bCSChu0+XPuruzKnpDILA==",
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/rlnjs/-/rlnjs-2.0.6.tgz",
|
||||
"integrity": "sha512-fh+GNx5eCtonPrDWuVIncNz82kdVpr+LEBuxFZ0Nna+Umkkc9wEOdmtQIdU+XxC23shHIjAEfMIbDOQmep52zw==",
|
||||
"requires": {
|
||||
"@ethersproject/bytes": "^5.6.1",
|
||||
"@ethersproject/solidity": "^5.6.1",
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
"protons-runtime": "^5.0.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"rlnjs": "^2.0.5",
|
||||
"rlnjs": "^2.0.6",
|
||||
"uint8arrays": "^4.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
12
src/RLN.ts
12
src/RLN.ts
@@ -1,5 +1,5 @@
|
||||
import { GOERLI } from './utils/checkChain'
|
||||
import { genExternalNullifier, Registry, RLN as RLNjs, RLNFullProof, Cache } from 'rlnjs'
|
||||
import { Registry, RLN as RLNjs, RLNFullProof, Cache } from 'rlnjs'
|
||||
import { Contract } from 'ethers'
|
||||
import { Web3Provider } from '@ethersproject/providers'
|
||||
import * as path from 'path'
|
||||
@@ -12,7 +12,7 @@ const wasmFilePath = path.join('./zkeyFiles', 'rln', 'rln.wasm')
|
||||
const finalZkeyPath = path.join('./zkeyFiles', 'rln', 'rln_final.zkey')
|
||||
|
||||
export default class RLN {
|
||||
public registry: Registry
|
||||
registry: Registry
|
||||
|
||||
public identityCommitments: bigint[]
|
||||
|
||||
@@ -50,15 +50,15 @@ export default class RLN {
|
||||
|
||||
/* generate RLN Proof */
|
||||
public async generateRLNProof(msg: string, epoch: bigint) {
|
||||
const epochNullifier = genExternalNullifier(epoch.toString())
|
||||
const merkleProof = await this.registry.generateMerkleProof(this.identityCommitment)
|
||||
const proof = this.rlnjs.generateProof(msg, merkleProof, epochNullifier)
|
||||
// const epochNullifier = genExternalNullifier(epoch.toString())
|
||||
const merkleProof = this.registry.generateMerkleProof(this.identityCommitment)
|
||||
const proof = this.rlnjs.generateProof(msg, merkleProof)
|
||||
return proof
|
||||
}
|
||||
|
||||
/* RLN proof verification */
|
||||
public async verifyProof(rlnProof: RLNFullProof) {
|
||||
return RLNjs.verifyProof(vkey, rlnProof)
|
||||
return RLNjs.verifySNARKProof(rlnProof)
|
||||
}
|
||||
|
||||
/* construct RLN member tree locally */
|
||||
|
||||
@@ -11424,10 +11424,10 @@
|
||||
"hash-base" "^3.0.0"
|
||||
"inherits" "^2.0.1"
|
||||
|
||||
"rlnjs@^2.0.5":
|
||||
"integrity" "sha512-gBEfZ8g9yupdco5eDmx2IufUGeNT2q9cpceQAyyqRO1oTHyzt2CY2xxQeZIVOV+h8bCSChu0+XPuruzKnpDILA=="
|
||||
"resolved" "https://registry.npmjs.org/rlnjs/-/rlnjs-2.0.5.tgz"
|
||||
"version" "2.0.5"
|
||||
"rlnjs@^2.0.6":
|
||||
"integrity" "sha512-fh+GNx5eCtonPrDWuVIncNz82kdVpr+LEBuxFZ0Nna+Umkkc9wEOdmtQIdU+XxC23shHIjAEfMIbDOQmep52zw=="
|
||||
"resolved" "https://registry.npmjs.org/rlnjs/-/rlnjs-2.0.6.tgz"
|
||||
"version" "2.0.6"
|
||||
dependencies:
|
||||
"@ethersproject/bytes" "^5.6.1"
|
||||
"@ethersproject/solidity" "^5.6.1"
|
||||
|
||||
Reference in New Issue
Block a user