@waku/rln 0.1.5-9901863.0 → 0.1.5-a8ff776.0
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/bundle/index.js +0 -2
- package/bundle/packages/rln/dist/contract/constants.js +1 -1
- package/bundle/packages/rln/dist/contract/rln_contract.js +419 -9
- package/bundle/packages/rln/dist/create.js +1 -1
- package/bundle/packages/rln/dist/identity.js +0 -8
- package/bundle/packages/rln/dist/keystore/keystore.js +28 -19
- package/bundle/packages/rln/dist/rln.js +166 -56
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/constants.d.ts +1 -1
- package/dist/contract/constants.js +1 -1
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_contract.d.ts +122 -5
- package/dist/contract/rln_contract.js +417 -8
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/create.js +1 -1
- package/dist/create.js.map +1 -1
- package/dist/identity.d.ts +0 -1
- package/dist/identity.js +0 -8
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/keystore/keystore.d.ts +1 -0
- package/dist/keystore/keystore.js +28 -19
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/types.d.ts +1 -1
- package/dist/rln.d.ts +52 -9
- package/dist/rln.js +163 -54
- package/dist/rln.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/constants.ts +1 -1
- package/src/contract/rln_contract.ts +663 -9
- package/src/create.ts +1 -1
- package/src/identity.ts +0 -9
- package/src/index.ts +0 -4
- package/src/keystore/keystore.ts +46 -31
- package/src/keystore/types.ts +1 -1
- package/src/rln.ts +259 -67
- package/bundle/packages/rln/dist/contract/rln_base_contract.js +0 -477
- package/bundle/packages/rln/dist/contract/types.js +0 -9
- package/bundle/packages/rln/dist/credentials_manager.js +0 -233
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/_assert.js +0 -43
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/_sha2.js +0 -116
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/hmac.js +0 -79
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/sha256.js +0 -126
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/utils.js +0 -43
- package/dist/contract/rln_base_contract.d.ts +0 -96
- package/dist/contract/rln_base_contract.js +0 -460
- package/dist/contract/rln_base_contract.js.map +0 -1
- package/dist/contract/types.d.ts +0 -40
- package/dist/contract/types.js +0 -8
- package/dist/contract/types.js.map +0 -1
- package/dist/credentials_manager.d.ts +0 -50
- package/dist/credentials_manager.js +0 -215
- package/dist/credentials_manager.js.map +0 -1
- package/dist/types.d.ts +0 -27
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/src/contract/rln_base_contract.ts +0 -707
- package/src/contract/types.ts +0 -48
- package/src/credentials_manager.ts +0 -306
- package/src/types.ts +0 -31
package/dist/identity.js
CHANGED
@@ -23,13 +23,5 @@ export class IdentityCredential {
|
|
23
23
|
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment, 32);
|
24
24
|
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
25
25
|
}
|
26
|
-
toJSON() {
|
27
|
-
return {
|
28
|
-
idTrapdoor: Array.from(this.IDTrapdoor),
|
29
|
-
idNullifier: Array.from(this.IDNullifier),
|
30
|
-
idSecretHash: Array.from(this.IDSecretHash),
|
31
|
-
idCommitment: Array.from(this.IDCommitment)
|
32
|
-
};
|
33
|
-
}
|
34
26
|
}
|
35
27
|
//# sourceMappingURL=identity.js.map
|
package/dist/identity.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,MAAM,OAAO,kBAAkB;IAEX;IACA;IACA;IACA;IACA;IALlB,YACkB,UAA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Y,CAAY;QACxB,iBAAY,GAAZ,YAAY,CAAY;QACxB,uBAAkB,GAAlB,kBAAkB,CAAQ;IACzC,CAAC;IAEG,MAAM,CAAC,SAAS,CAAC,OAAmB;QACzC,IAAI,OAAO,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;QAED,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC3C,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC7C,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC9C,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;QAC/C,MAAM,kBAAkB,GAAG,yBAAyB,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAEvE,OAAO,IAAI,kBAAkB,CAC3B,UAAU,EACV,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,kBAAkB,CACnB,CAAC;IACJ,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
import { RLNDecoder, RLNEncoder } from "./codec.js";
|
2
2
|
import { RLN_ABI } from "./contract/abi.js";
|
3
3
|
import { LINEA_CONTRACT, RLNContract } from "./contract/index.js";
|
4
|
-
import { RLNBaseContract } from "./contract/rln_base_contract.js";
|
5
4
|
import { createRLN } from "./create.js";
|
6
|
-
import { RLNCredentialsManager } from "./credentials_manager.js";
|
7
5
|
import { IdentityCredential } from "./identity.js";
|
8
6
|
import { Keystore } from "./keystore/index.js";
|
9
7
|
import { Proof } from "./proof.js";
|
10
8
|
import { RLNInstance } from "./rln.js";
|
11
9
|
import { MerkleRootTracker } from "./root_tracker.js";
|
12
10
|
import { extractMetaMaskSigner } from "./utils/index.js";
|
13
|
-
export {
|
11
|
+
export { createRLN, Keystore, RLNInstance, IdentityCredential, Proof, RLNEncoder, RLNDecoder, MerkleRootTracker, RLNContract, LINEA_CONTRACT, extractMetaMaskSigner, RLN_ABI };
|
14
12
|
export type { DecryptedCredentials, EncryptedCredentials, Keccak256Hash, KeystoreEntity, MembershipHash, MembershipInfo, Password, Sha256Hash } from "./keystore/types.js";
|
package/dist/index.js
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
import { RLNDecoder, RLNEncoder } from "./codec.js";
|
2
2
|
import { RLN_ABI } from "./contract/abi.js";
|
3
3
|
import { LINEA_CONTRACT, RLNContract } from "./contract/index.js";
|
4
|
-
import { RLNBaseContract } from "./contract/rln_base_contract.js";
|
5
4
|
import { createRLN } from "./create.js";
|
6
|
-
import { RLNCredentialsManager } from "./credentials_manager.js";
|
7
5
|
import { IdentityCredential } from "./identity.js";
|
8
6
|
import { Keystore } from "./keystore/index.js";
|
9
7
|
import { Proof } from "./proof.js";
|
10
8
|
import { RLNInstance } from "./rln.js";
|
11
9
|
import { MerkleRootTracker } from "./root_tracker.js";
|
12
10
|
import { extractMetaMaskSigner } from "./utils/index.js";
|
13
|
-
export {
|
11
|
+
export { createRLN, Keystore, RLNInstance, IdentityCredential, Proof, RLNEncoder, RLNDecoder, MerkleRootTracker, RLNContract, LINEA_CONTRACT, extractMetaMaskSigner, RLN_ABI };
|
14
12
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EACL,SAAS,EACT,QAAQ,EACR,WAAW,EACX,kBAAkB,EAClB,KAAK,EACL,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,qBAAqB,EACrB,OAAO,EACR,CAAC"}
|
@@ -43,6 +43,7 @@ export declare class Keystore {
|
|
43
43
|
private static fromCredentialToEip;
|
44
44
|
private static fromEipToCredential;
|
45
45
|
private static fromBytesToIdentity;
|
46
|
+
private static fromArraylikeToBytes;
|
46
47
|
private static computeMembershipHash;
|
47
48
|
private static fromIdentityToBytes;
|
48
49
|
}
|
@@ -4,7 +4,6 @@ import { sha256 } from "ethereum-cryptography/sha256";
|
|
4
4
|
import { bytesToHex, bytesToUtf8, utf8ToBytes } from "ethereum-cryptography/utils";
|
5
5
|
import _ from "lodash";
|
6
6
|
import { v4 as uuidV4 } from "uuid";
|
7
|
-
import { IdentityCredential } from "../identity.js";
|
8
7
|
import { buildBigIntFromUint8Array } from "../utils/bytes.js";
|
9
8
|
import { decryptEipKeystore, keccak256Checksum } from "./cipher.js";
|
10
9
|
import { isCredentialValid, isKeystoreValid } from "./schema_validator.js";
|
@@ -148,20 +147,20 @@ export class Keystore {
|
|
148
147
|
try {
|
149
148
|
const str = bytesToUtf8(bytes);
|
150
149
|
const obj = JSON.parse(str);
|
151
|
-
//
|
152
|
-
const { idTrapdoor, idNullifier, idSecretHash, idCommitment } = _.get(obj, "identityCredential", {});
|
153
|
-
const idTrapdoorArray = new Uint8Array(idTrapdoor || []);
|
154
|
-
const idNullifierArray = new Uint8Array(idNullifier || []);
|
155
|
-
const idSecretHashArray = new Uint8Array(idSecretHash || []);
|
156
|
-
const idCommitmentArray = new Uint8Array(idCommitment || []);
|
157
|
-
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitmentArray);
|
150
|
+
// TODO: add runtime validation of nwaku credentials
|
158
151
|
return {
|
159
|
-
identity:
|
152
|
+
identity: {
|
153
|
+
IDCommitment: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idCommitment", [])),
|
154
|
+
IDTrapdoor: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idTrapdoor", [])),
|
155
|
+
IDNullifier: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idNullifier", [])),
|
156
|
+
IDCommitmentBigInt: buildBigIntFromUint8Array(Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idCommitment", []))),
|
157
|
+
IDSecretHash: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idSecretHash", []))
|
158
|
+
},
|
160
159
|
membership: {
|
161
160
|
treeIndex: _.get(obj, "treeIndex"),
|
162
161
|
chainId: _.get(obj, "membershipContract.chainId"),
|
163
162
|
address: _.get(obj, "membershipContract.address"),
|
164
|
-
rateLimit: _.get(obj, "
|
163
|
+
rateLimit: _.get(obj, "membershipContract.rateLimit")
|
165
164
|
}
|
166
165
|
};
|
167
166
|
}
|
@@ -170,6 +169,17 @@ export class Keystore {
|
|
170
169
|
return;
|
171
170
|
}
|
172
171
|
}
|
172
|
+
static fromArraylikeToBytes(obj) {
|
173
|
+
const bytes = [];
|
174
|
+
let index = 0;
|
175
|
+
let lastElement = obj[index];
|
176
|
+
while (lastElement !== undefined) {
|
177
|
+
bytes.push(lastElement);
|
178
|
+
index += 1;
|
179
|
+
lastElement = obj[index];
|
180
|
+
}
|
181
|
+
return new Uint8Array(bytes);
|
182
|
+
}
|
173
183
|
// follows nwaku implementation
|
174
184
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L111
|
175
185
|
static computeMembershipHash(info) {
|
@@ -179,18 +189,17 @@ export class Keystore {
|
|
179
189
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L98
|
180
190
|
static fromIdentityToBytes(options) {
|
181
191
|
return utf8ToBytes(JSON.stringify({
|
182
|
-
membershipContract: {
|
183
|
-
chainId: options.membership.chainId,
|
184
|
-
address: options.membership.address
|
185
|
-
},
|
186
192
|
treeIndex: options.membership.treeIndex,
|
187
193
|
identityCredential: {
|
188
|
-
|
189
|
-
idNullifier:
|
190
|
-
idSecretHash:
|
191
|
-
|
194
|
+
idCommitment: options.identity.IDCommitment,
|
195
|
+
idNullifier: options.identity.IDNullifier,
|
196
|
+
idSecretHash: options.identity.IDSecretHash,
|
197
|
+
idTrapdoor: options.identity.IDTrapdoor
|
192
198
|
},
|
193
|
-
|
199
|
+
membershipContract: {
|
200
|
+
chainId: options.membership.chainId,
|
201
|
+
address: options.membership.address
|
202
|
+
}
|
194
203
|
}));
|
195
204
|
}
|
196
205
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"keystore.js","sourceRoot":"","sources":["../../src/keystore/keystore.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,IAAI,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,E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,CAAC;YACb,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,SAAS;YACvC,kBAAkB,EAAE;gBAClB,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAC,YAAY;gBAC3C,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,WAAW;gBACzC,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAC,YAAY;gBAC3C,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,UAAU;aACxC;YACD,kBAAkB,EAAE;gBAClB,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO;gBACnC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO;aACpC;SACF,CAAC,CACH,CAAC;IACJ,CAAC;CACF"}
|
package/dist/keystore/types.d.ts
CHANGED
package/dist/rln.d.ts
CHANGED
@@ -1,23 +1,66 @@
|
|
1
1
|
import type { ContentTopic, IDecodedMessage, EncoderOptions as WakuEncoderOptions } from "@waku/interfaces";
|
2
|
+
import { ethers } from "ethers";
|
2
3
|
import { type RLNDecoder, type RLNEncoder } from "./codec.js";
|
3
|
-
import {
|
4
|
+
import { RLNContract } from "./contract/index.js";
|
5
|
+
import { IdentityCredential } from "./identity.js";
|
4
6
|
import type { DecryptedCredentials, EncryptedCredentials } from "./keystore/index.js";
|
5
|
-
import {
|
7
|
+
import { Password } from "./keystore/types.js";
|
6
8
|
import { Zerokit } from "./zerokit.js";
|
9
|
+
/**
|
10
|
+
* Create an instance of RLN
|
11
|
+
* @returns RLNInstance
|
12
|
+
*/
|
13
|
+
export declare function create(): Promise<RLNInstance>;
|
14
|
+
type StartRLNOptions = {
|
15
|
+
/**
|
16
|
+
* If not set - will extract MetaMask account and get signer from it.
|
17
|
+
*/
|
18
|
+
signer?: ethers.Signer;
|
19
|
+
/**
|
20
|
+
* If not set - will use default LINEA_CONTRACT address.
|
21
|
+
*/
|
22
|
+
address?: string;
|
23
|
+
/**
|
24
|
+
* Credentials to use for generating proofs and connecting to the contract and network.
|
25
|
+
* If provided used for validating the network chainId and connecting to registry contract.
|
26
|
+
*/
|
27
|
+
credentials?: EncryptedCredentials | DecryptedCredentials;
|
28
|
+
/**
|
29
|
+
* Rate limit for the member.
|
30
|
+
*/
|
31
|
+
rateLimit?: number;
|
32
|
+
};
|
33
|
+
type RegisterMembershipOptions = {
|
34
|
+
signature: string;
|
35
|
+
} | {
|
36
|
+
identity: IdentityCredential;
|
37
|
+
};
|
7
38
|
type WakuRLNEncoderOptions = WakuEncoderOptions & {
|
8
39
|
credentials: EncryptedCredentials | DecryptedCredentials;
|
9
40
|
};
|
10
|
-
export declare class RLNInstance
|
41
|
+
export declare class RLNInstance {
|
11
42
|
zerokit: Zerokit;
|
43
|
+
private started;
|
44
|
+
private starting;
|
45
|
+
private _contract;
|
46
|
+
private _signer;
|
47
|
+
private keystore;
|
48
|
+
private _credentials;
|
49
|
+
constructor(zerokit: Zerokit);
|
50
|
+
get contract(): undefined | RLNContract;
|
51
|
+
get signer(): undefined | ethers.Signer;
|
52
|
+
start(options?: StartRLNOptions): Promise<void>;
|
53
|
+
private determineStartOptions;
|
54
|
+
private static decryptCredentialsIfNeeded;
|
55
|
+
registerMembership(options: RegisterMembershipOptions): Promise<undefined | DecryptedCredentials>;
|
12
56
|
/**
|
13
|
-
*
|
14
|
-
* @
|
57
|
+
* Changes credentials in use by relying on provided Keystore earlier in rln.start
|
58
|
+
* @param id: string, hash of credentials to select from Keystore
|
59
|
+
* @param password: string or bytes to use to decrypt credentials from Keystore
|
15
60
|
*/
|
16
|
-
|
17
|
-
private constructor();
|
61
|
+
useCredentials(id: string, password: Password): Promise<void>;
|
18
62
|
createEncoder(options: WakuRLNEncoderOptions): Promise<RLNEncoder>;
|
63
|
+
private verifyCredentialsAgainstContract;
|
19
64
|
createDecoder(contentTopic: ContentTopic): RLNDecoder<IDecodedMessage>;
|
20
|
-
static loadWitnessCalculator(): Promise<WitnessCalculator>;
|
21
|
-
static loadZkey(): Promise<Uint8Array>;
|
22
65
|
}
|
23
66
|
export {};
|
package/dist/rln.js
CHANGED
@@ -4,43 +4,164 @@ import init from "@waku/zerokit-rln-wasm";
|
|
4
4
|
import * as zerokitRLN from "@waku/zerokit-rln-wasm";
|
5
5
|
import { createRLNDecoder, createRLNEncoder } from "./codec.js";
|
6
6
|
import { DEFAULT_RATE_LIMIT } from "./contract/constants.js";
|
7
|
-
import {
|
7
|
+
import { LINEA_CONTRACT, RLNContract } from "./contract/index.js";
|
8
|
+
import { Keystore } from "./keystore/index.js";
|
8
9
|
import verificationKey from "./resources/verification_key";
|
9
10
|
import * as wc from "./resources/witness_calculator";
|
11
|
+
import { extractMetaMaskSigner } from "./utils/index.js";
|
10
12
|
import { Zerokit } from "./zerokit.js";
|
11
13
|
const log = new Logger("waku:rln");
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
static async create() {
|
19
|
-
try {
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
21
|
-
await init?.();
|
22
|
-
zerokitRLN.init_panic_hook();
|
23
|
-
const witnessCalculator = await RLNInstance.loadWitnessCalculator();
|
24
|
-
const zkey = await RLNInstance.loadZkey();
|
25
|
-
const stringEncoder = new TextEncoder();
|
26
|
-
const vkey = stringEncoder.encode(JSON.stringify(verificationKey));
|
27
|
-
const DEPTH = 20;
|
28
|
-
const zkRLN = zerokitRLN.newRLN(DEPTH, zkey, vkey);
|
29
|
-
const zerokit = new Zerokit(zkRLN, witnessCalculator, DEFAULT_RATE_LIMIT);
|
30
|
-
return new RLNInstance(zerokit);
|
31
|
-
}
|
32
|
-
catch (error) {
|
33
|
-
log.error("Failed to initialize RLN:", error);
|
34
|
-
throw error;
|
14
|
+
async function loadWitnessCalculator() {
|
15
|
+
try {
|
16
|
+
const url = new URL("./resources/rln.wasm", import.meta.url);
|
17
|
+
const response = await fetch(url);
|
18
|
+
if (!response.ok) {
|
19
|
+
throw new Error(`Failed to fetch witness calculator: ${response.status} ${response.statusText}`);
|
35
20
|
}
|
21
|
+
return await wc.builder(new Uint8Array(await response.arrayBuffer()), false);
|
36
22
|
}
|
23
|
+
catch (error) {
|
24
|
+
log.error("Error loading witness calculator:", error);
|
25
|
+
throw new Error(`Failed to load witness calculator: ${error instanceof Error ? error.message : String(error)}`);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
async function loadZkey() {
|
29
|
+
try {
|
30
|
+
const url = new URL("./resources/rln_final.zkey", import.meta.url);
|
31
|
+
const response = await fetch(url);
|
32
|
+
if (!response.ok) {
|
33
|
+
throw new Error(`Failed to fetch zkey: ${response.status} ${response.statusText}`);
|
34
|
+
}
|
35
|
+
return new Uint8Array(await response.arrayBuffer());
|
36
|
+
}
|
37
|
+
catch (error) {
|
38
|
+
log.error("Error loading zkey:", error);
|
39
|
+
throw new Error(`Failed to load zkey: ${error instanceof Error ? error.message : String(error)}`);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
/**
|
43
|
+
* Create an instance of RLN
|
44
|
+
* @returns RLNInstance
|
45
|
+
*/
|
46
|
+
export async function create() {
|
47
|
+
try {
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
49
|
+
await init?.();
|
50
|
+
zerokitRLN.init_panic_hook();
|
51
|
+
const witnessCalculator = await loadWitnessCalculator();
|
52
|
+
const zkey = await loadZkey();
|
53
|
+
const stringEncoder = new TextEncoder();
|
54
|
+
const vkey = stringEncoder.encode(JSON.stringify(verificationKey));
|
55
|
+
const DEPTH = 20;
|
56
|
+
const zkRLN = zerokitRLN.newRLN(DEPTH, zkey, vkey);
|
57
|
+
const zerokit = new Zerokit(zkRLN, witnessCalculator, DEFAULT_RATE_LIMIT);
|
58
|
+
return new RLNInstance(zerokit);
|
59
|
+
}
|
60
|
+
catch (error) {
|
61
|
+
log.error("Failed to initialize RLN:", error);
|
62
|
+
throw error;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
export class RLNInstance {
|
66
|
+
zerokit;
|
67
|
+
started = false;
|
68
|
+
starting = false;
|
69
|
+
_contract;
|
70
|
+
_signer;
|
71
|
+
keystore = Keystore.create();
|
72
|
+
_credentials;
|
37
73
|
constructor(zerokit) {
|
38
|
-
super(zerokit);
|
39
74
|
this.zerokit = zerokit;
|
40
75
|
}
|
76
|
+
get contract() {
|
77
|
+
return this._contract;
|
78
|
+
}
|
79
|
+
get signer() {
|
80
|
+
return this._signer;
|
81
|
+
}
|
82
|
+
async start(options = {}) {
|
83
|
+
if (this.started || this.starting) {
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
this.starting = true;
|
87
|
+
try {
|
88
|
+
const { credentials, keystore } = await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
|
89
|
+
const { signer, address } = await this.determineStartOptions(options, credentials);
|
90
|
+
if (keystore) {
|
91
|
+
this.keystore = keystore;
|
92
|
+
}
|
93
|
+
this._credentials = credentials;
|
94
|
+
this._signer = signer;
|
95
|
+
this._contract = await RLNContract.init(this, {
|
96
|
+
address: address,
|
97
|
+
signer: signer,
|
98
|
+
rateLimit: options.rateLimit ?? this.zerokit.getRateLimit
|
99
|
+
});
|
100
|
+
this.started = true;
|
101
|
+
}
|
102
|
+
finally {
|
103
|
+
this.starting = false;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
async determineStartOptions(options, credentials) {
|
107
|
+
let chainId = credentials?.membership.chainId;
|
108
|
+
const address = credentials?.membership.address ||
|
109
|
+
options.address ||
|
110
|
+
LINEA_CONTRACT.address;
|
111
|
+
if (address === LINEA_CONTRACT.address) {
|
112
|
+
chainId = LINEA_CONTRACT.chainId;
|
113
|
+
}
|
114
|
+
const signer = options.signer || (await extractMetaMaskSigner());
|
115
|
+
const currentChainId = await signer.getChainId();
|
116
|
+
if (chainId && chainId !== currentChainId) {
|
117
|
+
throw Error(`Failed to start RLN contract, chain ID of contract is different from current one: contract-${chainId}, current network-${currentChainId}`);
|
118
|
+
}
|
119
|
+
return {
|
120
|
+
signer,
|
121
|
+
address
|
122
|
+
};
|
123
|
+
}
|
124
|
+
static async decryptCredentialsIfNeeded(credentials) {
|
125
|
+
if (!credentials) {
|
126
|
+
return {};
|
127
|
+
}
|
128
|
+
if ("identity" in credentials) {
|
129
|
+
return { credentials };
|
130
|
+
}
|
131
|
+
const keystore = Keystore.fromString(credentials.keystore);
|
132
|
+
if (!keystore) {
|
133
|
+
return {};
|
134
|
+
}
|
135
|
+
const decryptedCredentials = await keystore.readCredential(credentials.id, credentials.password);
|
136
|
+
return {
|
137
|
+
keystore,
|
138
|
+
credentials: decryptedCredentials
|
139
|
+
};
|
140
|
+
}
|
141
|
+
async registerMembership(options) {
|
142
|
+
if (!this.contract) {
|
143
|
+
throw Error("RLN Contract is not initialized.");
|
144
|
+
}
|
145
|
+
let identity = "identity" in options && options.identity;
|
146
|
+
if ("signature" in options) {
|
147
|
+
identity = this.zerokit.generateSeededIdentityCredential(options.signature);
|
148
|
+
}
|
149
|
+
if (!identity) {
|
150
|
+
throw Error("Missing signature or identity to register membership.");
|
151
|
+
}
|
152
|
+
return this.contract.registerWithIdentity(identity);
|
153
|
+
}
|
154
|
+
/**
|
155
|
+
* Changes credentials in use by relying on provided Keystore earlier in rln.start
|
156
|
+
* @param id: string, hash of credentials to select from Keystore
|
157
|
+
* @param password: string or bytes to use to decrypt credentials from Keystore
|
158
|
+
*/
|
159
|
+
async useCredentials(id, password) {
|
160
|
+
this._credentials = await this.keystore?.readCredential(id, password);
|
161
|
+
}
|
41
162
|
async createEncoder(options) {
|
42
163
|
const { credentials: decryptedCredentials } = await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
|
43
|
-
const credentials = decryptedCredentials || this.
|
164
|
+
const credentials = decryptedCredentials || this._credentials;
|
44
165
|
if (!credentials) {
|
45
166
|
throw Error("Failed to create Encoder: missing RLN credentials. Use createRLNEncoder directly.");
|
46
167
|
}
|
@@ -52,39 +173,27 @@ export class RLNInstance extends RLNCredentialsManager {
|
|
52
173
|
credential: credentials.identity
|
53
174
|
});
|
54
175
|
}
|
176
|
+
async verifyCredentialsAgainstContract(credentials) {
|
177
|
+
if (!this._contract) {
|
178
|
+
throw Error("Failed to verify chain coordinates: no contract initialized.");
|
179
|
+
}
|
180
|
+
const registryAddress = credentials.membership.address;
|
181
|
+
const currentRegistryAddress = this._contract.address;
|
182
|
+
if (registryAddress !== currentRegistryAddress) {
|
183
|
+
throw Error(`Failed to verify chain coordinates: credentials contract address=${registryAddress} is not equal to registryContract address=${currentRegistryAddress}`);
|
184
|
+
}
|
185
|
+
const chainId = credentials.membership.chainId;
|
186
|
+
const network = await this._contract.provider.getNetwork();
|
187
|
+
const currentChainId = network.chainId;
|
188
|
+
if (chainId !== currentChainId) {
|
189
|
+
throw Error(`Failed to verify chain coordinates: credentials chainID=${chainId} is not equal to registryContract chainID=${currentChainId}`);
|
190
|
+
}
|
191
|
+
}
|
55
192
|
createDecoder(contentTopic) {
|
56
193
|
return createRLNDecoder({
|
57
194
|
rlnInstance: this,
|
58
195
|
decoder: createDecoder(contentTopic)
|
59
196
|
});
|
60
197
|
}
|
61
|
-
static async loadWitnessCalculator() {
|
62
|
-
try {
|
63
|
-
const url = new URL("./resources/rln.wasm", import.meta.url);
|
64
|
-
const response = await fetch(url);
|
65
|
-
if (!response.ok) {
|
66
|
-
throw new Error(`Failed to fetch witness calculator: ${response.status} ${response.statusText}`);
|
67
|
-
}
|
68
|
-
return await wc.builder(new Uint8Array(await response.arrayBuffer()), false);
|
69
|
-
}
|
70
|
-
catch (error) {
|
71
|
-
log.error("Error loading witness calculator:", error);
|
72
|
-
throw new Error(`Failed to load witness calculator: ${error instanceof Error ? error.message : String(error)}`);
|
73
|
-
}
|
74
|
-
}
|
75
|
-
static async loadZkey() {
|
76
|
-
try {
|
77
|
-
const url = new URL("./resources/rln_final.zkey", import.meta.url);
|
78
|
-
const response = await fetch(url);
|
79
|
-
if (!response.ok) {
|
80
|
-
throw new Error(`Failed to fetch zkey: ${response.status} ${response.statusText}`);
|
81
|
-
}
|
82
|
-
return new Uint8Array(await response.arrayBuffer());
|
83
|
-
}
|
84
|
-
catch (error) {
|
85
|
-
log.error("Error loading zkey:", error);
|
86
|
-
throw new Error(`Failed to load zkey: ${error instanceof Error ? error.message : String(error)}`);
|
87
|
-
}
|
88
|
-
}
|
89
198
|
}
|
90
199
|
//# sourceMappingURL=rln.js.map
|
package/dist/rln.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rln.js","sourceRoot":"","sources":["../src/rln.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAM1D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,MAAM,wBAAwB,CAAC;AAC1C,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;
|
1
|
+
{"version":3,"file":"rln.js","sourceRoot":"","sources":["../src/rln.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAM1D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,MAAM,wBAAwB,CAAC;AAC1C,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAGrD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAGjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAM/C,OAAO,eAAe,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAErD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;AAEnC,KAAK,UAAU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,CAC5C,WAA2B;QAE3B,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,MAAM,KAAK,CACT,8DAA8D,CAC/D,CAAC;QACJ,CAAC;QAED,MAAM,eAAe,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC;QACvD,MAAM,sBAAsB,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;QACtD,IAAI,eAAe,KAAK,sBAAsB,EAAE,CAAC;YAC/C,MAAM,KAAK,CACT,oEAAoE,eAAe,6CAA6C,sBAAsB,EAAE,CACzJ,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC;QAC/C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QAC3D,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;QACvC,IAAI,OAAO,KAAK,cAAc,EAAE,CAAC;YAC/B,MAAM,KAAK,CACT,2DAA2D,OAAO,6CAA6C,cAAc,EAAE,CAChI,CAAC;QACJ,CAAC;IACH,CAAC;IAEM,aAAa,CAClB,YAA0B;QAE1B,OAAO,gBAAgB,CAAC;YACtB,WAAW,EAAE,IAAI;YACjB,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC;SACrC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"name":"@waku/rln","version":"0.1.5-
|
1
|
+
{"name":"@waku/rln","version":"0.1.5-a8ff776.0","description":"RLN (Rate Limiting Nullifier) implementation for Waku","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"type":"module","homepage":"https://github.com/waku-org/js-waku/tree/master/packages/rln#readme","repository":{"type":"git","url":"https://github.com/waku-org/js-waku.git"},"bugs":{"url":"https://github.com/waku-org/js-waku/issues"},"license":"MIT OR Apache-2.0","keywords":["waku","rln","rate-limiting","privacy","web3"],"scripts":{"build":"run-s build:**","build:copy":"mkdir -p dist/resources && cp -r src/resources/* dist/resources/","build:esm":"tsc","build:bundle":"rollup --config rollup.config.js","fix":"run-s fix:*","fix:lint":"eslint src *.js --fix","check":"run-s check:*","check:tsc":"tsc -p tsconfig.dev.json","check:lint":"eslint \"src/!(resources)/**/*.{ts,js}\" *.js","check:spelling":"cspell \"{README.md,src/**/*.ts}\"","test":"NODE_ENV=test run-s test:*","test:browser":"karma start karma.conf.cjs","watch:build":"tsc -p tsconfig.json -w","watch:test":"mocha --watch","prepublish":"npm run build","reset-hard":"git clean -dfx -e .idea && git reset --hard && npm i && npm run build"},"engines":{"node":">=20"},"devDependencies":{"@rollup/plugin-commonjs":"^25.0.7","@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.2.3","@types/chai":"^5.0.1","@types/chai-spies":"^1.0.6","@types/deep-equal-in-any-order":"^1.0.4","@types/lodash":"^4.17.15","@types/sinon":"^17.0.3","@waku/build-utils":"^1.0.0","@waku/message-encryption":"0.0.33-a8ff776.0","deep-equal-in-any-order":"^2.0.6","fast-check":"^3.23.2","rollup-plugin-copy":"^3.5.0"},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"],"dependencies":{"@chainsafe/bls-keystore":"3.0.0","@waku/core":"0.0.35-a8ff776.0","@waku/utils":"0.0.23-a8ff776.0","@waku/zerokit-rln-wasm":"^0.0.13","ethereum-cryptography":"^3.1.0","ethers":"^5.7.2","lodash":"^4.17.21","uuid":"^11.0.5","chai":"^5.1.2","chai-as-promised":"^8.0.1","chai-spies":"^1.1.0","chai-subset":"^1.6.0","sinon":"^19.0.2"}}
|