@waku/rln 0.1.1 → 0.1.2-86d4f56
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 +26 -2
- package/bundle/assets/rln_wasm_bg-a503e304.wasm +0 -0
- package/bundle/index.js +58446 -12248
- package/dist/.tsbuildinfo +1 -1
- package/dist/byte_utils.d.ts +13 -0
- package/dist/byte_utils.js +22 -0
- package/dist/byte_utils.js.map +1 -1
- package/dist/codec.d.ts +5 -3
- package/dist/codec.js +8 -4
- package/dist/codec.js.map +1 -1
- package/dist/constants.d.ts +2 -2
- package/dist/constants.js +62 -9
- package/dist/constants.js.map +1 -1
- package/dist/create.d.ts +2 -0
- package/dist/create.js +8 -0
- package/dist/create.js.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +5 -10
- package/dist/index.js.map +1 -1
- package/dist/keystore/cipher.d.ts +4 -0
- package/dist/keystore/cipher.js +28 -0
- package/dist/keystore/cipher.js.map +1 -0
- package/dist/keystore/credential_validation_generated.d.ts +8 -0
- package/dist/keystore/credential_validation_generated.js +121 -0
- package/dist/keystore/credential_validation_generated.js.map +1 -0
- package/dist/keystore/index.d.ts +4 -0
- package/dist/keystore/index.js +3 -0
- package/dist/keystore/index.js.map +1 -0
- package/dist/keystore/keystore.d.ts +50 -0
- package/dist/keystore/keystore.js +202 -0
- package/dist/keystore/keystore.js.map +1 -0
- package/dist/keystore/keystore_validation_generated.d.ts +8 -0
- package/dist/keystore/keystore_validation_generated.js +75 -0
- package/dist/keystore/keystore_validation_generated.js.map +1 -0
- package/dist/keystore/schema_validator.d.ts +2 -0
- package/dist/keystore/schema_validator.js +18 -0
- package/dist/keystore/schema_validator.js.map +1 -0
- package/dist/keystore/types.d.ts +29 -0
- package/dist/keystore/types.js +2 -0
- package/dist/keystore/types.js.map +1 -0
- package/dist/message.d.ts +2 -1
- package/dist/message.js +4 -1
- package/dist/message.js.map +1 -1
- package/dist/metamask.d.ts +2 -0
- package/dist/metamask.js +11 -0
- package/dist/metamask.js.map +1 -0
- package/dist/rln.d.ts +51 -0
- package/dist/rln.js +134 -12
- package/dist/rln.js.map +1 -1
- package/dist/rln_contract.d.ts +25 -14
- package/dist/rln_contract.js +80 -34
- package/dist/rln_contract.js.map +1 -1
- package/package.json +23 -8
- package/src/byte_utils.ts +24 -0
- package/src/codec.ts +10 -5
- package/src/constants.ts +63 -9
- package/src/create.ts +9 -0
- package/src/index.ts +13 -11
- package/src/message.ts +5 -1
- package/src/metamask.ts +16 -0
- package/src/rln.ts +240 -14
- package/src/rln_contract.ts +135 -53
- package/bundle/assets/rln_wasm_bg-6f96f821.wasm +0 -0
package/dist/rln_contract.js.map
CHANGED
@@ -1 +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;
|
1
|
+
{"version":3,"file":"rln_contract.js","sourceRoot":"","sources":["../src/rln_contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AA0BtD,MAAM,OAAO,WAAW;IAWf,MAAM,CAAC,KAAK,CAAC,IAAI,CACtB,WAAwB,EACxB,OAA+B;QAE/B,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAE1D,MAAM,WAAW,CAAC,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACtD,MAAM,WAAW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json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@waku/rln",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.2-86d4f56",
|
4
4
|
"description": "Rate Limit Nullifier for js-waku",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"module": "./dist/index.js",
|
@@ -24,6 +24,7 @@
|
|
24
24
|
"scripts": {
|
25
25
|
"prepare": "husky install",
|
26
26
|
"build": "run-s build:**",
|
27
|
+
"build:codegen": "node ./scripts/schema_validator_codegen.js",
|
27
28
|
"build:tsc": "tsc",
|
28
29
|
"build:bundle": "rollup --config rollup.config.js",
|
29
30
|
"size": "npm run build && size-limit",
|
@@ -45,7 +46,7 @@
|
|
45
46
|
"crypto": false
|
46
47
|
},
|
47
48
|
"engines": {
|
48
|
-
"node": ">=
|
49
|
+
"node": ">=18"
|
49
50
|
},
|
50
51
|
"publishConfig": {
|
51
52
|
"access": "public",
|
@@ -59,19 +60,31 @@
|
|
59
60
|
"@size-limit/preset-big-lib": "^8.0.0",
|
60
61
|
"@types/app-root-path": "^1.2.4",
|
61
62
|
"@types/chai": "^4.2.15",
|
63
|
+
"@types/chai-as-promised": "^7.1.6",
|
62
64
|
"@types/chai-spies": "^1.0.3",
|
65
|
+
"@types/chai-subset": "^1.3.3",
|
63
66
|
"@types/debug": "^4.1.7",
|
67
|
+
"@types/deep-equal-in-any-order": "^1.0.1",
|
68
|
+
"@types/lodash": "^4.14.199",
|
64
69
|
"@types/mocha": "^9.1.0",
|
65
70
|
"@types/node": "^17.0.6",
|
66
71
|
"@types/tail": "^2.0.0",
|
67
72
|
"@types/uuid": "^8.3.0",
|
68
73
|
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
69
74
|
"@typescript-eslint/parser": "^5.8.1",
|
75
|
+
"@waku/core": "^0.0.25",
|
76
|
+
"@waku/interfaces": "^0.0.20",
|
77
|
+
"@waku/message-encryption": "^0.0.23",
|
70
78
|
"@web/rollup-plugin-import-meta-assets": "^1.0.7",
|
79
|
+
"ajv": "^8.12.0",
|
80
|
+
"ajv-formats": "^2.1.1",
|
71
81
|
"app-root-path": "^3.0.0",
|
72
82
|
"chai": "^4.3.4",
|
83
|
+
"chai-as-promised": "^7.1.1",
|
73
84
|
"chai-spies": "^1.0.0",
|
85
|
+
"chai-subset": "^1.6.0",
|
74
86
|
"cspell": "^5.14.0",
|
87
|
+
"deep-equal-in-any-order": "^2.0.6",
|
75
88
|
"eslint": "^8.6.0",
|
76
89
|
"eslint-config-prettier": "^8.3.0",
|
77
90
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
@@ -83,9 +96,6 @@
|
|
83
96
|
"husky": "^7.0.4",
|
84
97
|
"ignore-loader": "^0.1.2",
|
85
98
|
"isomorphic-fetch": "^3.0.0",
|
86
|
-
"@waku/interfaces": "^0.0.12",
|
87
|
-
"@waku/message-encryption": "^0.0.15",
|
88
|
-
"@waku/core": "^0.0.17",
|
89
99
|
"jsdom": "^19.0.0",
|
90
100
|
"jsdom-global": "^3.0.2",
|
91
101
|
"karma": "^6.3.12",
|
@@ -129,8 +139,13 @@
|
|
129
139
|
]
|
130
140
|
},
|
131
141
|
"dependencies": {
|
132
|
-
"@
|
133
|
-
"@waku/
|
134
|
-
"
|
142
|
+
"@chainsafe/bls-keystore": "^3.0.0",
|
143
|
+
"@waku/utils": "^0.0.13",
|
144
|
+
"@waku/zerokit-rln-wasm": "^0.0.13",
|
145
|
+
"ethereum-cryptography": "^2.1.2",
|
146
|
+
"ethers": "^5.7.2",
|
147
|
+
"lodash": "^4.17.21",
|
148
|
+
"rlnjs": "^3.2.3",
|
149
|
+
"uuid": "^9.0.1"
|
135
150
|
}
|
136
151
|
}
|
package/src/byte_utils.ts
CHANGED
@@ -37,3 +37,27 @@ export function writeUIntLE(
|
|
37
37
|
|
38
38
|
return buf;
|
39
39
|
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Transforms Uint8Array into BigInt
|
43
|
+
* @param array: Uint8Array
|
44
|
+
* @returns BigInt
|
45
|
+
*/
|
46
|
+
export function buildBigIntFromUint8Array(array: Uint8Array): bigint {
|
47
|
+
const dataView = new DataView(array.buffer);
|
48
|
+
return dataView.getBigUint64(0, true);
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Fills with zeros to set length
|
53
|
+
* @param array little endian Uint8Array
|
54
|
+
* @param length amount to pad
|
55
|
+
* @returns little endian Uint8Array padded with zeros to set length
|
56
|
+
*/
|
57
|
+
export function zeroPadLE(array: Uint8Array, length: number): Uint8Array {
|
58
|
+
const result = new Uint8Array(length);
|
59
|
+
for (let i = 0; i < length; i++) {
|
60
|
+
result[i] = array[i] || 0;
|
61
|
+
}
|
62
|
+
return result;
|
63
|
+
}
|
package/src/codec.ts
CHANGED
@@ -44,18 +44,19 @@ export class RLNEncoder implements IEncoder {
|
|
44
44
|
|
45
45
|
private async generateProof(message: IMessage): Promise<IRateLimitProof> {
|
46
46
|
const signal = toRLNSignal(this.contentTopic, message);
|
47
|
-
|
48
|
-
console.time("proof_gen_timer");
|
49
47
|
const proof = await this.rlnInstance.generateRLNProof(
|
50
48
|
signal,
|
51
49
|
this.index,
|
52
50
|
message.timestamp,
|
53
51
|
this.idSecretHash
|
54
52
|
);
|
55
|
-
console.timeEnd("proof_gen_timer");
|
56
53
|
return proof;
|
57
54
|
}
|
58
55
|
|
56
|
+
get pubsubTopic(): string {
|
57
|
+
return this.encoder.pubsubTopic;
|
58
|
+
}
|
59
|
+
|
59
60
|
get contentTopic(): string {
|
60
61
|
return this.encoder.contentTopic;
|
61
62
|
}
|
@@ -86,6 +87,10 @@ export class RLNDecoder<T extends IDecodedMessage>
|
|
86
87
|
{
|
87
88
|
constructor(private rlnInstance: RLNInstance, private decoder: IDecoder<T>) {}
|
88
89
|
|
90
|
+
get pubsubTopic(): string {
|
91
|
+
return this.decoder.pubsubTopic;
|
92
|
+
}
|
93
|
+
|
89
94
|
get contentTopic(): string {
|
90
95
|
return this.decoder.contentTopic;
|
91
96
|
}
|
@@ -97,11 +102,11 @@ export class RLNDecoder<T extends IDecodedMessage>
|
|
97
102
|
}
|
98
103
|
|
99
104
|
async fromProtoObj(
|
100
|
-
|
105
|
+
pubsubTopic: string,
|
101
106
|
proto: IProtoMessage
|
102
107
|
): Promise<RlnMessage<T> | undefined> {
|
103
108
|
const msg: T | undefined = await this.decoder.fromProtoObj(
|
104
|
-
|
109
|
+
pubsubTopic,
|
105
110
|
proto
|
106
111
|
);
|
107
112
|
if (!msg) return;
|
package/src/constants.ts
CHANGED
@@ -1,14 +1,68 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
"
|
4
|
-
"
|
5
|
-
"
|
6
|
-
"
|
1
|
+
// ref https://github.com/waku-org/waku-rln-contract/blob/19fded82bca07e7b535b429dc507cfb83f10dfcf/deployments/sepolia/WakuRlnRegistry_Implementation.json#L3
|
2
|
+
export const RLN_REGISTRY_ABI = [
|
3
|
+
"error IncompatibleStorage()",
|
4
|
+
"error IncompatibleStorageIndex()",
|
5
|
+
"error NoStorageContractAvailable()",
|
6
|
+
"error StorageAlreadyExists(address storageAddress)",
|
7
|
+
"event AdminChanged(address previousAdmin, address newAdmin)",
|
8
|
+
"event BeaconUpgraded(address indexed beacon)",
|
9
|
+
"event Initialized(uint8 version)",
|
10
|
+
"event NewStorageContract(uint16 index, address storageAddress)",
|
11
|
+
"event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)",
|
12
|
+
"event Upgraded(address indexed implementation)",
|
13
|
+
"function forceProgress()",
|
14
|
+
"function initialize(address _poseidonHasher)",
|
15
|
+
"function newStorage()",
|
16
|
+
"function nextStorageIndex() view returns (uint16)",
|
17
|
+
"function owner() view returns (address)",
|
18
|
+
"function poseidonHasher() view returns (address)",
|
19
|
+
"function proxiableUUID() view returns (bytes32)",
|
20
|
+
"function register(uint16 storageIndex, uint256 commitment)",
|
21
|
+
"function register(uint256[] commitments)",
|
22
|
+
"function register(uint16 storageIndex, uint256[] commitments)",
|
23
|
+
"function registerStorage(address storageAddress)",
|
24
|
+
"function renounceOwnership()",
|
25
|
+
"function storages(uint16) view returns (address)",
|
26
|
+
"function transferOwnership(address newOwner)",
|
27
|
+
"function upgradeTo(address newImplementation)",
|
28
|
+
"function upgradeToAndCall(address newImplementation, bytes data) payable",
|
29
|
+
"function usingStorageIndex() view returns (uint16)",
|
30
|
+
];
|
31
|
+
|
32
|
+
// ref https://github.com/waku-org/waku-rln-contract/blob/19fded82bca07e7b535b429dc507cfb83f10dfcf/deployments/sepolia/WakuRlnStorage_0.json#L3
|
33
|
+
export const RLN_STORAGE_ABI = [
|
34
|
+
"constructor(address _poseidonHasher, uint16 _contractIndex)",
|
35
|
+
"error DuplicateIdCommitment()",
|
36
|
+
"error FullTree()",
|
37
|
+
"error InvalidIdCommitment(uint256 idCommitment)",
|
38
|
+
"error NotImplemented()",
|
39
|
+
"event MemberRegistered(uint256 idCommitment, uint256 index)",
|
40
|
+
"event MemberWithdrawn(uint256 idCommitment, uint256 index)",
|
41
|
+
"event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)",
|
42
|
+
"function DEPTH() view returns (uint256)",
|
43
|
+
"function MEMBERSHIP_DEPOSIT() view returns (uint256)",
|
44
|
+
"function SET_SIZE() view returns (uint256)",
|
45
|
+
"function contractIndex() view returns (uint16)",
|
46
|
+
"function deployedBlockNumber() view returns (uint32)",
|
47
|
+
"function idCommitmentIndex() view returns (uint256)",
|
48
|
+
"function isValidCommitment(uint256 idCommitment) view returns (bool)",
|
49
|
+
"function memberExists(uint256) view returns (bool)",
|
50
|
+
"function members(uint256) view returns (uint256)",
|
51
|
+
"function owner() view returns (address)",
|
52
|
+
"function poseidonHasher() view returns (address)",
|
53
|
+
"function register(uint256[] idCommitments)",
|
54
|
+
"function register(uint256 idCommitment) payable",
|
55
|
+
"function renounceOwnership()",
|
56
|
+
"function slash(uint256 idCommitment, address receiver, uint256[8] proof) pure",
|
57
|
+
"function stakedAmounts(uint256) view returns (uint256)",
|
58
|
+
"function transferOwnership(address newOwner)",
|
59
|
+
"function verifier() view returns (address)",
|
60
|
+
"function withdraw() pure",
|
61
|
+
"function withdrawalBalance(address) view returns (uint256)",
|
7
62
|
];
|
8
63
|
|
9
64
|
export const SEPOLIA_CONTRACT = {
|
10
65
|
chainId: 11155111,
|
11
|
-
|
12
|
-
|
13
|
-
abi: RLN_ABI,
|
66
|
+
address: "0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4",
|
67
|
+
abi: RLN_REGISTRY_ABI,
|
14
68
|
};
|
package/src/create.ts
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
import type { RLNInstance } from "./rln.js";
|
2
|
+
|
3
|
+
export async function createRLN(): Promise<RLNInstance> {
|
4
|
+
// A dependency graph that contains any wasm must all be imported
|
5
|
+
// asynchronously. This file does the single async import, so
|
6
|
+
// that no one else needs to worry about it again.
|
7
|
+
const rlnModule = await import("./rln.js");
|
8
|
+
return rlnModule.create();
|
9
|
+
}
|
package/src/index.ts
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
import { RLNDecoder, RLNEncoder } from "./codec.js";
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
RLN_REGISTRY_ABI,
|
4
|
+
RLN_STORAGE_ABI,
|
5
|
+
SEPOLIA_CONTRACT,
|
6
|
+
} from "./constants.js";
|
7
|
+
import { createRLN } from "./create.js";
|
8
|
+
import { Keystore } from "./keystore/index.js";
|
9
|
+
import { extractMetaMaskSigner } from "./metamask.js";
|
3
10
|
import {
|
4
11
|
IdentityCredential,
|
5
12
|
Proof,
|
@@ -9,16 +16,9 @@ import {
|
|
9
16
|
import { RLNContract } from "./rln_contract.js";
|
10
17
|
import { MerkleRootTracker } from "./root_tracker.js";
|
11
18
|
|
12
|
-
// reexport the create function, dynamically imported from rln.ts
|
13
|
-
export async function create(): Promise<RLNInstance> {
|
14
|
-
// A dependency graph that contains any wasm must all be imported
|
15
|
-
// asynchronously. This file does the single async import, so
|
16
|
-
// that no one else needs to worry about it again.
|
17
|
-
const rlnModule = await import("./rln.js");
|
18
|
-
return await rlnModule.create();
|
19
|
-
}
|
20
|
-
|
21
19
|
export {
|
20
|
+
createRLN,
|
21
|
+
Keystore,
|
22
22
|
RLNInstance,
|
23
23
|
IdentityCredential,
|
24
24
|
Proof,
|
@@ -27,6 +27,8 @@ export {
|
|
27
27
|
RLNDecoder,
|
28
28
|
MerkleRootTracker,
|
29
29
|
RLNContract,
|
30
|
-
|
30
|
+
RLN_STORAGE_ABI,
|
31
|
+
RLN_REGISTRY_ABI,
|
31
32
|
SEPOLIA_CONTRACT,
|
33
|
+
extractMetaMaskSigner,
|
32
34
|
};
|
package/src/message.ts
CHANGED
@@ -14,7 +14,7 @@ export function toRLNSignal(contentTopic: string, msg: IMessage): Uint8Array {
|
|
14
14
|
}
|
15
15
|
|
16
16
|
export class RlnMessage<T extends IDecodedMessage> implements IDecodedMessage {
|
17
|
-
public
|
17
|
+
public pubsubTopic = "";
|
18
18
|
|
19
19
|
constructor(
|
20
20
|
public rlnInstance: RLNInstance,
|
@@ -57,6 +57,10 @@ export class RlnMessage<T extends IDecodedMessage> implements IDecodedMessage {
|
|
57
57
|
return this.msg.ephemeral;
|
58
58
|
}
|
59
59
|
|
60
|
+
get meta(): Uint8Array | undefined {
|
61
|
+
return this.msg.meta;
|
62
|
+
}
|
63
|
+
|
60
64
|
get epoch(): number | undefined {
|
61
65
|
const bytes = this.msg.rateLimitProof?.epoch;
|
62
66
|
if (!bytes) return;
|
package/src/metamask.ts
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
import { ethers } from "ethers";
|
2
|
+
|
3
|
+
export const extractMetaMaskSigner = async (): Promise<ethers.Signer> => {
|
4
|
+
const ethereum = (window as any).ethereum;
|
5
|
+
|
6
|
+
if (!ethereum) {
|
7
|
+
throw Error(
|
8
|
+
"Missing or invalid Ethereum provider. Please install a Web3 wallet such as MetaMask."
|
9
|
+
);
|
10
|
+
}
|
11
|
+
|
12
|
+
await ethereum.request({ method: "eth_requestAccounts" });
|
13
|
+
const provider = new ethers.providers.Web3Provider(ethereum, "any");
|
14
|
+
|
15
|
+
return provider.getSigner();
|
16
|
+
};
|
package/src/rln.ts
CHANGED
@@ -1,9 +1,28 @@
|
|
1
|
+
import { createDecoder, createEncoder } from "@waku/core";
|
1
2
|
import type { IRateLimitProof } from "@waku/interfaces";
|
2
|
-
import
|
3
|
-
|
4
|
-
|
3
|
+
import type {
|
4
|
+
ContentTopic,
|
5
|
+
IDecodedMessage,
|
6
|
+
EncoderOptions as WakuEncoderOptions,
|
7
|
+
} from "@waku/interfaces";
|
8
|
+
import init from "@waku/zerokit-rln-wasm";
|
9
|
+
import * as zerokitRLN from "@waku/zerokit-rln-wasm";
|
10
|
+
import { ethers } from "ethers";
|
11
|
+
|
12
|
+
import { buildBigIntFromUint8Array, writeUIntLE } from "./byte_utils.js";
|
13
|
+
import type { RLNDecoder, RLNEncoder } from "./codec.js";
|
14
|
+
import { createRLNDecoder, createRLNEncoder } from "./codec.js";
|
15
|
+
import { SEPOLIA_CONTRACT } from "./constants.js";
|
5
16
|
import { dateToEpoch, epochIntToBytes } from "./epoch.js";
|
17
|
+
import { Keystore } from "./keystore/index.js";
|
18
|
+
import type {
|
19
|
+
DecryptedCredentials,
|
20
|
+
EncryptedCredentials,
|
21
|
+
} from "./keystore/index.js";
|
22
|
+
import { KeystoreEntity, Password } from "./keystore/types.js";
|
23
|
+
import { extractMetaMaskSigner } from "./metamask.js";
|
6
24
|
import verificationKey from "./resources/verification_key.js";
|
25
|
+
import { RLNContract } from "./rln_contract.js";
|
7
26
|
import * as wc from "./witness_calculator.js";
|
8
27
|
import { WitnessCalculator } from "./witness_calculator.js";
|
9
28
|
|
@@ -26,16 +45,6 @@ function concatenate(...input: Uint8Array[]): Uint8Array {
|
|
26
45
|
return result;
|
27
46
|
}
|
28
47
|
|
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
|
-
|
39
48
|
const stringEncoder = new TextEncoder();
|
40
49
|
|
41
50
|
const DEPTH = 20;
|
@@ -57,7 +66,7 @@ async function loadZkey(): Promise<Uint8Array> {
|
|
57
66
|
* @returns RLNInstance
|
58
67
|
*/
|
59
68
|
export async function create(): Promise<RLNInstance> {
|
60
|
-
await init();
|
69
|
+
await (init as any)?.();
|
61
70
|
zerokitRLN.init_panic_hook();
|
62
71
|
const witnessCalculator = await loadWitnessCalculator();
|
63
72
|
const zkey = await loadZkey();
|
@@ -167,12 +176,229 @@ export function sha256(input: Uint8Array): Uint8Array {
|
|
167
176
|
return zerokitRLN.hash(lenPrefixedData);
|
168
177
|
}
|
169
178
|
|
179
|
+
type StartRLNOptions = {
|
180
|
+
/**
|
181
|
+
* If not set - will extract MetaMask account and get signer from it.
|
182
|
+
*/
|
183
|
+
signer?: ethers.Signer;
|
184
|
+
/**
|
185
|
+
* If not set - will use default SEPOLIA_CONTRACT address.
|
186
|
+
*/
|
187
|
+
registryAddress?: string;
|
188
|
+
/**
|
189
|
+
* Credentials to use for generating proofs and connecting to the contract and network.
|
190
|
+
* If provided used for validating the network chainId and connecting to registry contract.
|
191
|
+
*/
|
192
|
+
credentials?: EncryptedCredentials | DecryptedCredentials;
|
193
|
+
};
|
194
|
+
|
195
|
+
type RegisterMembershipOptions =
|
196
|
+
| { signature: string }
|
197
|
+
| { identity: IdentityCredential };
|
198
|
+
|
199
|
+
type WakuRLNEncoderOptions = WakuEncoderOptions & {
|
200
|
+
credentials: EncryptedCredentials | DecryptedCredentials;
|
201
|
+
};
|
202
|
+
|
170
203
|
export class RLNInstance {
|
204
|
+
private started = false;
|
205
|
+
private starting = false;
|
206
|
+
|
207
|
+
private _contract: undefined | RLNContract;
|
208
|
+
private _signer: undefined | ethers.Signer;
|
209
|
+
|
210
|
+
private keystore = Keystore.create();
|
211
|
+
private _credentials: undefined | DecryptedCredentials;
|
212
|
+
|
171
213
|
constructor(
|
172
214
|
private zkRLN: number,
|
173
215
|
private witnessCalculator: WitnessCalculator
|
174
216
|
) {}
|
175
217
|
|
218
|
+
public get contract(): undefined | RLNContract {
|
219
|
+
return this._contract;
|
220
|
+
}
|
221
|
+
|
222
|
+
public get signer(): undefined | ethers.Signer {
|
223
|
+
return this._signer;
|
224
|
+
}
|
225
|
+
|
226
|
+
public async start(options: StartRLNOptions = {}): Promise<void> {
|
227
|
+
if (this.started || this.starting) {
|
228
|
+
return;
|
229
|
+
}
|
230
|
+
|
231
|
+
this.starting = true;
|
232
|
+
|
233
|
+
try {
|
234
|
+
const { credentials, keystore } =
|
235
|
+
await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
|
236
|
+
const { signer, registryAddress } = await this.determineStartOptions(
|
237
|
+
options,
|
238
|
+
credentials
|
239
|
+
);
|
240
|
+
|
241
|
+
if (keystore) {
|
242
|
+
this.keystore = keystore;
|
243
|
+
}
|
244
|
+
|
245
|
+
this._credentials = credentials;
|
246
|
+
this._signer = signer!;
|
247
|
+
this._contract = await RLNContract.init(this, {
|
248
|
+
registryAddress: registryAddress!,
|
249
|
+
signer: signer!,
|
250
|
+
});
|
251
|
+
this.started = true;
|
252
|
+
} finally {
|
253
|
+
this.starting = false;
|
254
|
+
}
|
255
|
+
}
|
256
|
+
|
257
|
+
private async determineStartOptions(
|
258
|
+
options: StartRLNOptions,
|
259
|
+
credentials: KeystoreEntity | undefined
|
260
|
+
): Promise<StartRLNOptions> {
|
261
|
+
let chainId = credentials?.membership.chainId;
|
262
|
+
const registryAddress =
|
263
|
+
credentials?.membership.address ||
|
264
|
+
options.registryAddress ||
|
265
|
+
SEPOLIA_CONTRACT.address;
|
266
|
+
|
267
|
+
if (registryAddress === SEPOLIA_CONTRACT.address) {
|
268
|
+
chainId = SEPOLIA_CONTRACT.chainId;
|
269
|
+
}
|
270
|
+
|
271
|
+
const signer = options.signer || (await extractMetaMaskSigner());
|
272
|
+
const currentChainId = await signer.getChainId();
|
273
|
+
|
274
|
+
if (chainId && chainId !== currentChainId) {
|
275
|
+
throw Error(
|
276
|
+
`Failed to start RLN contract, chain ID of contract is different from current one: contract-${chainId}, current network-${currentChainId}`
|
277
|
+
);
|
278
|
+
}
|
279
|
+
|
280
|
+
return {
|
281
|
+
signer,
|
282
|
+
registryAddress,
|
283
|
+
};
|
284
|
+
}
|
285
|
+
|
286
|
+
private static async decryptCredentialsIfNeeded(
|
287
|
+
credentials?: EncryptedCredentials | DecryptedCredentials
|
288
|
+
): Promise<{ credentials?: DecryptedCredentials; keystore?: Keystore }> {
|
289
|
+
if (!credentials) {
|
290
|
+
return {};
|
291
|
+
}
|
292
|
+
|
293
|
+
if ("identity" in credentials) {
|
294
|
+
return { credentials };
|
295
|
+
}
|
296
|
+
|
297
|
+
const keystore = Keystore.fromString(credentials.keystore);
|
298
|
+
|
299
|
+
if (!keystore) {
|
300
|
+
return {};
|
301
|
+
}
|
302
|
+
|
303
|
+
const decryptedCredentials = await keystore.readCredential(
|
304
|
+
credentials.id,
|
305
|
+
credentials.password
|
306
|
+
);
|
307
|
+
|
308
|
+
return {
|
309
|
+
keystore,
|
310
|
+
credentials: decryptedCredentials,
|
311
|
+
};
|
312
|
+
}
|
313
|
+
|
314
|
+
public async registerMembership(
|
315
|
+
options: RegisterMembershipOptions
|
316
|
+
): Promise<undefined | DecryptedCredentials> {
|
317
|
+
if (!this.contract) {
|
318
|
+
throw Error("RLN Contract is not initialized.");
|
319
|
+
}
|
320
|
+
|
321
|
+
let identity = "identity" in options && options.identity;
|
322
|
+
|
323
|
+
if ("signature" in options) {
|
324
|
+
identity = await this.generateSeededIdentityCredential(options.signature);
|
325
|
+
}
|
326
|
+
|
327
|
+
if (!identity) {
|
328
|
+
throw Error("Missing signature or identity to register membership.");
|
329
|
+
}
|
330
|
+
|
331
|
+
return this.contract.registerWithIdentity(identity);
|
332
|
+
}
|
333
|
+
|
334
|
+
/**
|
335
|
+
* Changes credentials in use by relying on provided Keystore earlier in rln.start
|
336
|
+
* @param id: string, hash of credentials to select from Keystore
|
337
|
+
* @param password: string or bytes to use to decrypt credentials from Keystore
|
338
|
+
*/
|
339
|
+
public async useCredentials(id: string, password: Password): Promise<void> {
|
340
|
+
this._credentials = await this.keystore?.readCredential(id, password);
|
341
|
+
}
|
342
|
+
|
343
|
+
public async createEncoder(
|
344
|
+
options: WakuRLNEncoderOptions
|
345
|
+
): Promise<RLNEncoder> {
|
346
|
+
const { credentials: decryptedCredentials } =
|
347
|
+
await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
|
348
|
+
const credentials = decryptedCredentials || this._credentials;
|
349
|
+
|
350
|
+
if (!credentials) {
|
351
|
+
throw Error(
|
352
|
+
"Failed to create Encoder: missing RLN credentials. Use createRLNEncoder directly."
|
353
|
+
);
|
354
|
+
}
|
355
|
+
|
356
|
+
await this.verifyCredentialsAgainstContract(credentials);
|
357
|
+
|
358
|
+
return createRLNEncoder({
|
359
|
+
encoder: createEncoder(options),
|
360
|
+
rlnInstance: this,
|
361
|
+
index: credentials.membership.treeIndex,
|
362
|
+
credential: credentials.identity,
|
363
|
+
});
|
364
|
+
}
|
365
|
+
|
366
|
+
private async verifyCredentialsAgainstContract(
|
367
|
+
credentials: KeystoreEntity
|
368
|
+
): Promise<void> {
|
369
|
+
if (!this._contract) {
|
370
|
+
throw Error(
|
371
|
+
"Failed to verify chain coordinates: no contract initialized."
|
372
|
+
);
|
373
|
+
}
|
374
|
+
|
375
|
+
const registryAddress = credentials.membership.address;
|
376
|
+
const currentRegistryAddress = this._contract.registry.address;
|
377
|
+
if (registryAddress !== currentRegistryAddress) {
|
378
|
+
throw Error(
|
379
|
+
`Failed to verify chain coordinates: credentials contract address=${registryAddress} is not equal to registryContract address=${currentRegistryAddress}`
|
380
|
+
);
|
381
|
+
}
|
382
|
+
|
383
|
+
const chainId = credentials.membership.chainId;
|
384
|
+
const network = await this._contract.registry.getNetwork();
|
385
|
+
const currentChainId = network.chainId;
|
386
|
+
if (chainId !== currentChainId) {
|
387
|
+
throw Error(
|
388
|
+
`Failed to verify chain coordinates: credentials chainID=${chainId} is not equal to registryContract chainID=${currentChainId}`
|
389
|
+
);
|
390
|
+
}
|
391
|
+
}
|
392
|
+
|
393
|
+
public createDecoder(
|
394
|
+
contentTopic: ContentTopic
|
395
|
+
): RLNDecoder<IDecodedMessage> {
|
396
|
+
return createRLNDecoder({
|
397
|
+
rlnInstance: this,
|
398
|
+
decoder: createDecoder(contentTopic),
|
399
|
+
});
|
400
|
+
}
|
401
|
+
|
176
402
|
generateIdentityCredentials(): IdentityCredential {
|
177
403
|
const memKeys = zerokitRLN.generateExtendedMembershipKey(this.zkRLN); // TODO: rename this function in zerokit rln-wasm
|
178
404
|
return IdentityCredential.fromBytes(memKeys);
|