@waku/rln 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -21
- package/bundle/index.js +24163 -44584
- package/dist/.tsbuildinfo +1 -1
- package/dist/codec.d.ts +24 -10
- package/dist/codec.js +16 -6
- package/dist/codec.js.map +1 -1
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +14 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/message.d.ts +9 -7
- package/dist/message.js +9 -5
- package/dist/message.js.map +1 -1
- package/dist/rln.d.ts +9 -8
- package/dist/rln.js +13 -2
- package/dist/rln.js.map +1 -1
- package/dist/rln_contract.d.ts +24 -0
- package/dist/rln_contract.js +50 -0
- package/dist/rln_contract.js.map +1 -0
- package/package.json +9 -3
- package/src/codec.ts +63 -26
- package/src/constants.ts +14 -0
- package/src/index.ts +13 -2
- package/src/message.ts +23 -10
- package/src/rln.ts +24 -9
- package/src/rln_contract.ts +104 -0
package/dist/rln.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rln.js","sourceRoot":"","sources":["../src/rln.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"rln.js","sourceRoot":"","sources":["../src/rln.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,EAAE,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,eAAe,MAAM,iCAAiC,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAG9C;;;;GAIG;AACH,SAAS,WAAW,CAAC,GAAG,KAAmB;IACzC,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,KAAK,MAAM,GAAG,I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} from "ethers";
|
2
|
+
import { RLNInstance } from "./rln.js";
|
3
|
+
declare type Member = {
|
4
|
+
pubkey: string;
|
5
|
+
index: number;
|
6
|
+
};
|
7
|
+
declare type ContractOptions = {
|
8
|
+
address: string;
|
9
|
+
provider: ethers.Signer | ethers.providers.Provider;
|
10
|
+
};
|
11
|
+
export declare class RLNContract {
|
12
|
+
private _contract;
|
13
|
+
private membersFilter;
|
14
|
+
private _members;
|
15
|
+
static init(rlnInstance: RLNInstance, options: ContractOptions): Promise<RLNContract>;
|
16
|
+
constructor({ address, provider }: ContractOptions);
|
17
|
+
get contract(): ethers.Contract;
|
18
|
+
get members(): Member[];
|
19
|
+
fetchMembers(rlnInstance: RLNInstance, fromBlock?: number): Promise<void>;
|
20
|
+
subscribeToMembers(rlnInstance: RLNInstance): void;
|
21
|
+
private addMemberFromEvent;
|
22
|
+
registerMember(rlnInstance: RLNInstance, signature: string): Promise<ethers.Event | undefined>;
|
23
|
+
}
|
24
|
+
export {};
|
@@ -0,0 +1,50 @@
|
|
1
|
+
import { ethers } from "ethers";
|
2
|
+
import { RLN_ABI } from "./constants.js";
|
3
|
+
export class RLNContract {
|
4
|
+
constructor({ address, provider }) {
|
5
|
+
this._members = [];
|
6
|
+
this._contract = new ethers.Contract(address, RLN_ABI, provider);
|
7
|
+
this.membersFilter = this.contract.filters.MemberRegistered();
|
8
|
+
}
|
9
|
+
static async init(rlnInstance, options) {
|
10
|
+
const rlnContract = new RLNContract(options);
|
11
|
+
await rlnContract.fetchMembers(rlnInstance);
|
12
|
+
rlnContract.subscribeToMembers(rlnInstance);
|
13
|
+
return rlnContract;
|
14
|
+
}
|
15
|
+
get contract() {
|
16
|
+
return this._contract;
|
17
|
+
}
|
18
|
+
get members() {
|
19
|
+
return this._members;
|
20
|
+
}
|
21
|
+
async fetchMembers(rlnInstance, fromBlock) {
|
22
|
+
const registeredMemberEvents = await this.contract.queryFilter(this.membersFilter, fromBlock);
|
23
|
+
for (const event of registeredMemberEvents) {
|
24
|
+
this.addMemberFromEvent(rlnInstance, event);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
subscribeToMembers(rlnInstance) {
|
28
|
+
this.contract.on(this.membersFilter, (_pubkey, _index, event) => this.addMemberFromEvent(rlnInstance, event));
|
29
|
+
}
|
30
|
+
addMemberFromEvent(rlnInstance, event) {
|
31
|
+
if (!event.args) {
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
const pubkey = event.args.pubkey;
|
35
|
+
const index = event.args.index;
|
36
|
+
this.members.push({ index, pubkey });
|
37
|
+
const idCommitment = ethers.utils.zeroPad(ethers.utils.arrayify(pubkey), 32);
|
38
|
+
rlnInstance.insertMember(idCommitment);
|
39
|
+
}
|
40
|
+
async registerMember(rlnInstance, signature) {
|
41
|
+
const membershipKey = await rlnInstance.generateSeededMembershipKey(signature);
|
42
|
+
const depositValue = await this.contract.MEMBERSHIP_DEPOSIT();
|
43
|
+
const txRegisterResponse = await this.contract.register(membershipKey.IDCommitmentBigInt, {
|
44
|
+
value: depositValue,
|
45
|
+
});
|
46
|
+
const txRegisterReceipt = await txRegisterResponse.wait();
|
47
|
+
return txRegisterReceipt?.events?.[0];
|
48
|
+
}
|
49
|
+
}
|
50
|
+
//# sourceMappingURL=rln_contract.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rln_contract.js","sourceRoot":"","sources":["../src/rln_contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAazC,MAAM,OAAO,WAAW;IAkBtB,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAmB;QAd1C,aAAQ,GAAa,EAAE,CAAC;QAe9B,IAAI,CAAC,SAAS,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QACjE,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,QAAQ,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E,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAErC,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CACvC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAC7B,EAAE,CACH,CAAC;QACF,WAAW,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;IACzC,CAAC;IAEM,KAAK,CAAC,cAAc,CACzB,WAAwB,EACxB,SAAiB;QAEjB,MAAM,aAAa,GAAG,MAAM,WAAW,CAAC,2BAA2B,CACjE,SAAS,CACV,CAAC;QACF,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC;QAE9D,MAAM,kBAAkB,GACtB,MAAM,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,kBAAkB,EAAE;YAC7D,KAAK,EAAE,YAAY;SACpB,CAAC,CAAC;QACL,MAAM,iBAAiB,GAAG,MAAM,kBAAkB,CAAC,IAAI,EAAE,CAAC;QAE1D,OAAO,iBAAiB,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;CACF"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@waku/rln",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.14",
|
4
4
|
"description": "Rate Limit Nullifier for js-waku",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"module": "./dist/index.js",
|
@@ -59,6 +59,7 @@
|
|
59
59
|
"@size-limit/preset-big-lib": "^8.0.0",
|
60
60
|
"@types/app-root-path": "^1.2.4",
|
61
61
|
"@types/chai": "^4.2.15",
|
62
|
+
"@types/chai-spies": "^1.0.3",
|
62
63
|
"@types/debug": "^4.1.7",
|
63
64
|
"@types/mocha": "^9.1.0",
|
64
65
|
"@types/node": "^17.0.6",
|
@@ -69,6 +70,7 @@
|
|
69
70
|
"@web/rollup-plugin-import-meta-assets": "^1.0.7",
|
70
71
|
"app-root-path": "^3.0.0",
|
71
72
|
"chai": "^4.3.4",
|
73
|
+
"chai-spies": "^1.0.0",
|
72
74
|
"cspell": "^5.14.0",
|
73
75
|
"eslint": "^8.6.0",
|
74
76
|
"eslint-config-prettier": "^8.3.0",
|
@@ -81,7 +83,9 @@
|
|
81
83
|
"husky": "^7.0.4",
|
82
84
|
"ignore-loader": "^0.1.2",
|
83
85
|
"isomorphic-fetch": "^3.0.0",
|
84
|
-
"
|
86
|
+
"@waku/interfaces": "^0.0.11",
|
87
|
+
"@waku/message-encryption": "^0.0.14",
|
88
|
+
"@waku/core": "^0.0.16",
|
85
89
|
"jsdom": "^19.0.0",
|
86
90
|
"jsdom-global": "^3.0.2",
|
87
91
|
"karma": "^6.3.12",
|
@@ -125,6 +129,8 @@
|
|
125
129
|
]
|
126
130
|
},
|
127
131
|
"dependencies": {
|
128
|
-
"@waku/
|
132
|
+
"@waku/utils": "^0.0.4",
|
133
|
+
"@waku/zerokit-rln-wasm": "^0.0.5",
|
134
|
+
"ethers": "^5.7.2"
|
129
135
|
}
|
130
136
|
}
|
package/src/codec.ts
CHANGED
@@ -1,55 +1,49 @@
|
|
1
|
+
import type {
|
2
|
+
IDecodedMessage,
|
3
|
+
IDecoder,
|
4
|
+
IEncoder,
|
5
|
+
IMessage,
|
6
|
+
IProtoMessage,
|
7
|
+
IRateLimitProof,
|
8
|
+
} from "@waku/interfaces";
|
1
9
|
import debug from "debug";
|
2
|
-
import {
|
3
|
-
Decoder,
|
4
|
-
Encoder,
|
5
|
-
Message,
|
6
|
-
ProtoMessage,
|
7
|
-
RateLimitProof,
|
8
|
-
} from "js-waku/lib/interfaces";
|
9
10
|
|
10
11
|
import { RlnMessage, toRLNSignal } from "./message.js";
|
11
12
|
import { MembershipKey, RLNInstance } from "./rln.js";
|
12
13
|
|
13
14
|
const log = debug("waku:rln:encoder");
|
14
15
|
|
15
|
-
export class RLNEncoder implements
|
16
|
-
public contentTopic: string;
|
16
|
+
export class RLNEncoder implements IEncoder {
|
17
17
|
private readonly idKey: Uint8Array;
|
18
18
|
|
19
19
|
constructor(
|
20
|
-
private encoder:
|
20
|
+
private encoder: IEncoder,
|
21
21
|
private rlnInstance: RLNInstance,
|
22
22
|
private index: number,
|
23
23
|
membershipKey: MembershipKey
|
24
24
|
) {
|
25
25
|
if (index < 0) throw "invalid membership index";
|
26
26
|
this.idKey = membershipKey.IDKey;
|
27
|
-
this.contentTopic = encoder.contentTopic;
|
28
27
|
}
|
29
28
|
|
30
|
-
async toWire(message:
|
31
|
-
message.contentTopic = this.contentTopic;
|
29
|
+
async toWire(message: IMessage): Promise<Uint8Array | undefined> {
|
32
30
|
message.rateLimitProof = await this.generateProof(message);
|
33
31
|
log("Proof generated", message.rateLimitProof);
|
34
32
|
return this.encoder.toWire(message);
|
35
33
|
}
|
36
34
|
|
37
|
-
async toProtoObj(
|
38
|
-
message: Partial<Message>
|
39
|
-
): Promise<ProtoMessage | undefined> {
|
40
|
-
message.contentTopic = this.contentTopic;
|
35
|
+
async toProtoObj(message: IMessage): Promise<IProtoMessage | undefined> {
|
41
36
|
const protoMessage = await this.encoder.toProtoObj(message);
|
42
37
|
if (!protoMessage) return;
|
43
38
|
|
39
|
+
protoMessage.contentTopic = this.contentTopic;
|
44
40
|
protoMessage.rateLimitProof = await this.generateProof(message);
|
45
41
|
log("Proof generated", protoMessage.rateLimitProof);
|
46
42
|
return protoMessage;
|
47
43
|
}
|
48
44
|
|
49
|
-
private async generateProof(
|
50
|
-
message
|
51
|
-
): Promise<RateLimitProof> {
|
52
|
-
const signal = toRLNSignal(message);
|
45
|
+
private async generateProof(message: IMessage): Promise<IRateLimitProof> {
|
46
|
+
const signal = toRLNSignal(this.contentTopic, message);
|
53
47
|
|
54
48
|
console.time("proof_gen_timer");
|
55
49
|
const proof = await this.rlnInstance.generateRLNProof(
|
@@ -61,24 +55,67 @@ export class RLNEncoder implements Encoder {
|
|
61
55
|
console.timeEnd("proof_gen_timer");
|
62
56
|
return proof;
|
63
57
|
}
|
58
|
+
|
59
|
+
get contentTopic(): string {
|
60
|
+
return this.encoder.contentTopic;
|
61
|
+
}
|
62
|
+
|
63
|
+
get ephemeral(): boolean {
|
64
|
+
return this.encoder.ephemeral;
|
65
|
+
}
|
64
66
|
}
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
+
type RLNEncoderOptions = {
|
69
|
+
encoder: IEncoder;
|
70
|
+
rlnInstance: RLNInstance;
|
71
|
+
index: number;
|
72
|
+
membershipKey: MembershipKey;
|
73
|
+
};
|
74
|
+
|
75
|
+
export const createRLNEncoder = (options: RLNEncoderOptions): RLNEncoder => {
|
76
|
+
return new RLNEncoder(
|
77
|
+
options.encoder,
|
78
|
+
options.rlnInstance,
|
79
|
+
options.index,
|
80
|
+
options.membershipKey
|
81
|
+
);
|
82
|
+
};
|
83
|
+
|
84
|
+
export class RLNDecoder<T extends IDecodedMessage>
|
85
|
+
implements IDecoder<RlnMessage<T>>
|
86
|
+
{
|
87
|
+
constructor(private rlnInstance: RLNInstance, private decoder: IDecoder<T>) {}
|
68
88
|
|
69
89
|
get contentTopic(): string {
|
70
90
|
return this.decoder.contentTopic;
|
71
91
|
}
|
72
92
|
|
73
|
-
fromWireToProtoObj(bytes: Uint8Array): Promise<
|
93
|
+
fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined> {
|
74
94
|
const protoMessage = this.decoder.fromWireToProtoObj(bytes);
|
75
95
|
log("Message decoded", protoMessage);
|
76
96
|
return Promise.resolve(protoMessage);
|
77
97
|
}
|
78
98
|
|
79
|
-
async fromProtoObj(
|
80
|
-
|
99
|
+
async fromProtoObj(
|
100
|
+
pubSubTopic: string,
|
101
|
+
proto: IProtoMessage
|
102
|
+
): Promise<RlnMessage<T> | undefined> {
|
103
|
+
const msg: T | undefined = await this.decoder.fromProtoObj(
|
104
|
+
pubSubTopic,
|
105
|
+
proto
|
106
|
+
);
|
81
107
|
if (!msg) return;
|
82
108
|
return new RlnMessage(this.rlnInstance, msg, proto.rateLimitProof);
|
83
109
|
}
|
84
110
|
}
|
111
|
+
|
112
|
+
type RLNDecoderOptions<T extends IDecodedMessage> = {
|
113
|
+
decoder: IDecoder<T>;
|
114
|
+
rlnInstance: RLNInstance;
|
115
|
+
};
|
116
|
+
|
117
|
+
export const createRLNDecoder = <T extends IDecodedMessage>(
|
118
|
+
options: RLNDecoderOptions<T>
|
119
|
+
): RLNDecoder<T> => {
|
120
|
+
return new RLNDecoder(options.rlnInstance, options.decoder);
|
121
|
+
};
|
package/src/constants.ts
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
export const RLN_ABI = [
|
2
|
+
"function MEMBERSHIP_DEPOSIT() public view returns(uint256)",
|
3
|
+
"function register(uint256 pubkey) external payable",
|
4
|
+
"function withdraw(uint256 secret, uint256 _pubkeyIndex, address payable receiver) external",
|
5
|
+
"event MemberRegistered(uint256 pubkey, uint256 index)",
|
6
|
+
"event MemberWithdrawn(uint256 pubkey, uint256 index)",
|
7
|
+
];
|
8
|
+
|
9
|
+
export const GOERLI_CONTRACT = {
|
10
|
+
chainId: 5,
|
11
|
+
startBlock: 7109391,
|
12
|
+
address: "0x4252105670fe33d2947e8ead304969849e64f2a6",
|
13
|
+
abi: RLN_ABI,
|
14
|
+
};
|
package/src/index.ts
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
import { RLNDecoder, RLNEncoder } from "./codec.js";
|
2
|
-
import
|
2
|
+
import { GOERLI_CONTRACT, RLN_ABI } from "./constants.js";
|
3
|
+
import { Proof, RLNInstance } from "./rln.js";
|
3
4
|
import { MembershipKey } from "./rln.js";
|
5
|
+
import { RLNContract } from "./rln_contract.js";
|
4
6
|
|
5
7
|
// reexport the create function, dynamically imported from rln.ts
|
6
8
|
export async function create(): Promise<RLNInstance> {
|
@@ -11,4 +13,13 @@ export async function create(): Promise<RLNInstance> {
|
|
11
13
|
return await rlnModule.create();
|
12
14
|
}
|
13
15
|
|
14
|
-
export {
|
16
|
+
export {
|
17
|
+
RLNInstance,
|
18
|
+
MembershipKey,
|
19
|
+
Proof,
|
20
|
+
RLNEncoder,
|
21
|
+
RLNDecoder,
|
22
|
+
RLNContract,
|
23
|
+
RLN_ABI,
|
24
|
+
GOERLI_CONTRACT,
|
25
|
+
};
|
package/src/message.ts
CHANGED
@@ -1,24 +1,33 @@
|
|
1
|
-
import {
|
2
|
-
|
1
|
+
import type {
|
2
|
+
IDecodedMessage,
|
3
|
+
IMessage,
|
4
|
+
IRateLimitProof,
|
5
|
+
} from "@waku/interfaces";
|
6
|
+
import * as utils from "@waku/utils/bytes";
|
3
7
|
|
4
8
|
import { epochBytesToInt } from "./epoch.js";
|
5
9
|
import { RLNInstance } from "./rln.js";
|
6
10
|
|
7
|
-
export function toRLNSignal(msg:
|
8
|
-
const contentTopicBytes = utils.utf8ToBytes(
|
11
|
+
export function toRLNSignal(contentTopic: string, msg: IMessage): Uint8Array {
|
12
|
+
const contentTopicBytes = utils.utf8ToBytes(contentTopic ?? "");
|
9
13
|
return new Uint8Array([...(msg.payload ?? []), ...contentTopicBytes]);
|
10
14
|
}
|
11
15
|
|
12
|
-
export class RlnMessage<T extends
|
16
|
+
export class RlnMessage<T extends IDecodedMessage> implements IDecodedMessage {
|
17
|
+
public pubSubTopic = "";
|
18
|
+
|
13
19
|
constructor(
|
14
20
|
public rlnInstance: RLNInstance,
|
15
21
|
public msg: T,
|
16
|
-
public rateLimitProof:
|
22
|
+
public rateLimitProof: IRateLimitProof | undefined
|
17
23
|
) {}
|
18
24
|
|
19
25
|
public verify(): boolean | undefined {
|
20
26
|
return this.rateLimitProof
|
21
|
-
? this.rlnInstance.verifyWithRoots(
|
27
|
+
? this.rlnInstance.verifyWithRoots(
|
28
|
+
this.rateLimitProof,
|
29
|
+
toRLNSignal(this.msg.contentTopic, this.msg)
|
30
|
+
) // this.rlnInstance.verifyRLNProof once issue status-im/nwaku#1248 is fixed
|
22
31
|
: undefined;
|
23
32
|
}
|
24
33
|
|
@@ -26,16 +35,16 @@ export class RlnMessage<T extends Message> implements Message {
|
|
26
35
|
return this.rateLimitProof
|
27
36
|
? this.rlnInstance.verifyWithNoRoot(
|
28
37
|
this.rateLimitProof,
|
29
|
-
toRLNSignal(this)
|
38
|
+
toRLNSignal(this.msg.contentTopic, this.msg)
|
30
39
|
) // this.rlnInstance.verifyRLNProof once issue status-im/nwaku#1248 is fixed
|
31
40
|
: undefined;
|
32
41
|
}
|
33
42
|
|
34
|
-
get payload(): Uint8Array
|
43
|
+
get payload(): Uint8Array {
|
35
44
|
return this.msg.payload;
|
36
45
|
}
|
37
46
|
|
38
|
-
get contentTopic(): string
|
47
|
+
get contentTopic(): string {
|
39
48
|
return this.msg.contentTopic;
|
40
49
|
}
|
41
50
|
|
@@ -43,6 +52,10 @@ export class RlnMessage<T extends Message> implements Message {
|
|
43
52
|
return this.msg.timestamp;
|
44
53
|
}
|
45
54
|
|
55
|
+
get ephemeral(): boolean | undefined {
|
56
|
+
return this.msg.ephemeral;
|
57
|
+
}
|
58
|
+
|
46
59
|
get epoch(): number | undefined {
|
47
60
|
const bytes = this.msg.rateLimitProof?.epoch;
|
48
61
|
if (!bytes) return;
|
package/src/rln.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
+
import type { IRateLimitProof } from "@waku/interfaces";
|
1
2
|
import init, * as zerokitRLN from "@waku/zerokit-rln-wasm";
|
2
|
-
import { RateLimitProof } from "js-waku/lib/interfaces";
|
3
3
|
|
4
4
|
import { writeUIntLE } from "./byte_utils.js";
|
5
5
|
import { dateToEpoch, epochIntToBytes } from "./epoch.js";
|
@@ -26,6 +26,16 @@ function concatenate(...input: Uint8Array[]): Uint8Array {
|
|
26
26
|
return result;
|
27
27
|
}
|
28
28
|
|
29
|
+
/**
|
30
|
+
* Transforms Uint8Array into BigInt
|
31
|
+
* @param array: Uint8Array
|
32
|
+
* @returns BigInt
|
33
|
+
*/
|
34
|
+
function buildBigIntFromUint8Array(array: Uint8Array): bigint {
|
35
|
+
const dataView = new DataView(array.buffer);
|
36
|
+
return dataView.getBigUint64(0, true);
|
37
|
+
}
|
38
|
+
|
29
39
|
const stringEncoder = new TextEncoder();
|
30
40
|
|
31
41
|
const DEPTH = 20;
|
@@ -59,13 +69,15 @@ export async function create(): Promise<RLNInstance> {
|
|
59
69
|
export class MembershipKey {
|
60
70
|
constructor(
|
61
71
|
public readonly IDKey: Uint8Array,
|
62
|
-
public readonly IDCommitment: Uint8Array
|
72
|
+
public readonly IDCommitment: Uint8Array,
|
73
|
+
public readonly IDCommitmentBigInt: bigint
|
63
74
|
) {}
|
64
75
|
|
65
76
|
static fromBytes(memKeys: Uint8Array): MembershipKey {
|
66
77
|
const idKey = memKeys.subarray(0, 32);
|
67
78
|
const idCommitment = memKeys.subarray(32);
|
68
|
-
|
79
|
+
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment);
|
80
|
+
return new MembershipKey(idKey, idCommitment, idCommitmentBigInt);
|
69
81
|
}
|
70
82
|
}
|
71
83
|
|
@@ -77,7 +89,7 @@ const shareYOffset = shareXOffset + 32;
|
|
77
89
|
const nullifierOffset = shareYOffset + 32;
|
78
90
|
const rlnIdentifierOffset = nullifierOffset + 32;
|
79
91
|
|
80
|
-
export class Proof implements
|
92
|
+
export class Proof implements IRateLimitProof {
|
81
93
|
readonly proof: Uint8Array;
|
82
94
|
readonly merkleRoot: Uint8Array;
|
83
95
|
readonly epoch: Uint8Array;
|
@@ -102,7 +114,7 @@ export class Proof implements RateLimitProof {
|
|
102
114
|
}
|
103
115
|
}
|
104
116
|
|
105
|
-
export function proofToBytes(p:
|
117
|
+
export function proofToBytes(p: IRateLimitProof): Uint8Array {
|
106
118
|
return concatenate(
|
107
119
|
p.proof,
|
108
120
|
p.merkleRoot,
|
@@ -163,7 +175,7 @@ export class RLNInstance {
|
|
163
175
|
index: number,
|
164
176
|
epoch: Uint8Array | Date | undefined,
|
165
177
|
idKey: Uint8Array
|
166
|
-
): Promise<
|
178
|
+
): Promise<IRateLimitProof> {
|
167
179
|
if (epoch == undefined) {
|
168
180
|
epoch = epochIntToBytes(dateToEpoch(new Date()));
|
169
181
|
} else if (epoch instanceof Date) {
|
@@ -194,7 +206,10 @@ export class RLNInstance {
|
|
194
206
|
return new Proof(proofBytes);
|
195
207
|
}
|
196
208
|
|
197
|
-
verifyRLNProof(
|
209
|
+
verifyRLNProof(
|
210
|
+
proof: IRateLimitProof | Uint8Array,
|
211
|
+
msg: Uint8Array
|
212
|
+
): boolean {
|
198
213
|
let pBytes: Uint8Array;
|
199
214
|
if (proof instanceof Uint8Array) {
|
200
215
|
pBytes = proof;
|
@@ -212,7 +227,7 @@ export class RLNInstance {
|
|
212
227
|
}
|
213
228
|
|
214
229
|
verifyWithRoots(
|
215
|
-
proof:
|
230
|
+
proof: IRateLimitProof | Uint8Array,
|
216
231
|
msg: Uint8Array
|
217
232
|
): boolean {
|
218
233
|
let pBytes: Uint8Array;
|
@@ -236,7 +251,7 @@ export class RLNInstance {
|
|
236
251
|
}
|
237
252
|
|
238
253
|
verifyWithNoRoot(
|
239
|
-
proof:
|
254
|
+
proof: IRateLimitProof | Uint8Array,
|
240
255
|
msg: Uint8Array
|
241
256
|
): boolean {
|
242
257
|
let pBytes: Uint8Array;
|
@@ -0,0 +1,104 @@
|
|
1
|
+
import { ethers } from "ethers";
|
2
|
+
|
3
|
+
import { RLN_ABI } from "./constants.js";
|
4
|
+
import { RLNInstance } from "./rln.js";
|
5
|
+
|
6
|
+
type Member = {
|
7
|
+
pubkey: string;
|
8
|
+
index: number;
|
9
|
+
};
|
10
|
+
|
11
|
+
type ContractOptions = {
|
12
|
+
address: string;
|
13
|
+
provider: ethers.Signer | ethers.providers.Provider;
|
14
|
+
};
|
15
|
+
|
16
|
+
export class RLNContract {
|
17
|
+
private _contract: ethers.Contract;
|
18
|
+
private membersFilter: ethers.EventFilter;
|
19
|
+
|
20
|
+
private _members: Member[] = [];
|
21
|
+
|
22
|
+
public static async init(
|
23
|
+
rlnInstance: RLNInstance,
|
24
|
+
options: ContractOptions
|
25
|
+
): Promise<RLNContract> {
|
26
|
+
const rlnContract = new RLNContract(options);
|
27
|
+
|
28
|
+
await rlnContract.fetchMembers(rlnInstance);
|
29
|
+
rlnContract.subscribeToMembers(rlnInstance);
|
30
|
+
|
31
|
+
return rlnContract;
|
32
|
+
}
|
33
|
+
|
34
|
+
constructor({ address, provider }: ContractOptions) {
|
35
|
+
this._contract = new ethers.Contract(address, RLN_ABI, provider);
|
36
|
+
this.membersFilter = this.contract.filters.MemberRegistered();
|
37
|
+
}
|
38
|
+
|
39
|
+
public get contract(): ethers.Contract {
|
40
|
+
return this._contract;
|
41
|
+
}
|
42
|
+
|
43
|
+
public get members(): Member[] {
|
44
|
+
return this._members;
|
45
|
+
}
|
46
|
+
|
47
|
+
public async fetchMembers(
|
48
|
+
rlnInstance: RLNInstance,
|
49
|
+
fromBlock?: number
|
50
|
+
): Promise<void> {
|
51
|
+
const registeredMemberEvents = await this.contract.queryFilter(
|
52
|
+
this.membersFilter,
|
53
|
+
fromBlock
|
54
|
+
);
|
55
|
+
|
56
|
+
for (const event of registeredMemberEvents) {
|
57
|
+
this.addMemberFromEvent(rlnInstance, event);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
public subscribeToMembers(rlnInstance: RLNInstance): void {
|
62
|
+
this.contract.on(this.membersFilter, (_pubkey, _index, event) =>
|
63
|
+
this.addMemberFromEvent(rlnInstance, event)
|
64
|
+
);
|
65
|
+
}
|
66
|
+
|
67
|
+
private addMemberFromEvent(
|
68
|
+
rlnInstance: RLNInstance,
|
69
|
+
event: ethers.Event
|
70
|
+
): void {
|
71
|
+
if (!event.args) {
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
|
75
|
+
const pubkey: string = event.args.pubkey;
|
76
|
+
const index: number = event.args.index;
|
77
|
+
|
78
|
+
this.members.push({ index, pubkey });
|
79
|
+
|
80
|
+
const idCommitment = ethers.utils.zeroPad(
|
81
|
+
ethers.utils.arrayify(pubkey),
|
82
|
+
32
|
83
|
+
);
|
84
|
+
rlnInstance.insertMember(idCommitment);
|
85
|
+
}
|
86
|
+
|
87
|
+
public async registerMember(
|
88
|
+
rlnInstance: RLNInstance,
|
89
|
+
signature: string
|
90
|
+
): Promise<ethers.Event | undefined> {
|
91
|
+
const membershipKey = await rlnInstance.generateSeededMembershipKey(
|
92
|
+
signature
|
93
|
+
);
|
94
|
+
const depositValue = await this.contract.MEMBERSHIP_DEPOSIT();
|
95
|
+
|
96
|
+
const txRegisterResponse: ethers.ContractTransaction =
|
97
|
+
await this.contract.register(membershipKey.IDCommitmentBigInt, {
|
98
|
+
value: depositValue,
|
99
|
+
});
|
100
|
+
const txRegisterReceipt = await txRegisterResponse.wait();
|
101
|
+
|
102
|
+
return txRegisterReceipt?.events?.[0];
|
103
|
+
}
|
104
|
+
}
|