@waku/rln 0.1.5-6198efb.0 → 0.1.5-731214b.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.
Files changed (64) hide show
  1. package/bundle/index.js +4 -3
  2. package/bundle/packages/rln/dist/contract/constants.js +1 -0
  3. package/bundle/packages/rln/dist/contract/{rln_light_contract.js → rln_base_contract.js} +188 -179
  4. package/bundle/packages/rln/dist/contract/rln_contract.js +9 -419
  5. package/bundle/packages/rln/dist/contract/types.js +9 -0
  6. package/bundle/packages/rln/dist/create.js +1 -1
  7. package/bundle/packages/rln/dist/{rln_light.js → credentials_manager.js} +113 -47
  8. package/bundle/packages/rln/dist/keystore/keystore.js +10 -6
  9. package/bundle/packages/rln/dist/rln.js +56 -166
  10. package/bundle/packages/rln/dist/zerokit.js +5 -5
  11. package/dist/.tsbuildinfo +1 -1
  12. package/dist/contract/index.d.ts +1 -0
  13. package/dist/contract/index.js +1 -0
  14. package/dist/contract/index.js.map +1 -1
  15. package/dist/contract/{rln_light_contract.d.ts → rln_base_contract.d.ts} +24 -58
  16. package/dist/contract/{rln_light_contract.js → rln_base_contract.js} +188 -179
  17. package/dist/contract/rln_base_contract.js.map +1 -0
  18. package/dist/contract/rln_contract.d.ts +5 -122
  19. package/dist/contract/rln_contract.js +8 -417
  20. package/dist/contract/rln_contract.js.map +1 -1
  21. package/dist/contract/test-utils.js +1 -1
  22. package/dist/contract/test-utils.js.map +1 -1
  23. package/dist/contract/types.d.ts +45 -0
  24. package/dist/contract/types.js +8 -0
  25. package/dist/contract/types.js.map +1 -0
  26. package/dist/create.js +1 -1
  27. package/dist/create.js.map +1 -1
  28. package/dist/credentials_manager.d.ts +44 -0
  29. package/dist/credentials_manager.js +197 -0
  30. package/dist/credentials_manager.js.map +1 -0
  31. package/dist/index.d.ts +5 -4
  32. package/dist/index.js +4 -3
  33. package/dist/index.js.map +1 -1
  34. package/dist/keystore/keystore.js +10 -6
  35. package/dist/keystore/keystore.js.map +1 -1
  36. package/dist/keystore/types.d.ts +3 -3
  37. package/dist/rln.d.ts +9 -52
  38. package/dist/rln.js +54 -163
  39. package/dist/rln.js.map +1 -1
  40. package/dist/types.d.ts +27 -0
  41. package/dist/types.js +2 -0
  42. package/dist/types.js.map +1 -0
  43. package/dist/zerokit.d.ts +3 -3
  44. package/dist/zerokit.js +5 -5
  45. package/dist/zerokit.js.map +1 -1
  46. package/package.json +1 -1
  47. package/src/contract/index.ts +1 -0
  48. package/src/contract/{rln_light_contract.ts → rln_base_contract.ts} +304 -313
  49. package/src/contract/rln_contract.ts +9 -663
  50. package/src/contract/test-utils.ts +1 -1
  51. package/src/contract/types.ts +53 -0
  52. package/src/create.ts +1 -1
  53. package/src/credentials_manager.ts +282 -0
  54. package/src/index.ts +7 -5
  55. package/src/keystore/keystore.ts +22 -12
  56. package/src/keystore/types.ts +3 -3
  57. package/src/rln.ts +67 -258
  58. package/src/types.ts +31 -0
  59. package/src/zerokit.ts +3 -3
  60. package/dist/contract/rln_light_contract.js.map +0 -1
  61. package/dist/rln_light.d.ts +0 -64
  62. package/dist/rln_light.js +0 -144
  63. package/dist/rln_light.js.map +0 -1
  64. package/src/rln_light.ts +0 -235
@@ -16,54 +16,109 @@ import '../../../node_modules/multiformats/dist/src/bases/identity.js';
16
16
  import '../../../node_modules/multiformats/dist/src/codecs/json.js';
17
17
  import { Logger } from '../../utils/dist/logger/index.js';
18
18
  import { LINEA_CONTRACT } from './contract/constants.js';
19
- import { RLNLightContract } from './contract/rln_light_contract.js';
19
+ import { RLNBaseContract } from './contract/rln_base_contract.js';
20
20
  import { IdentityCredential } from './identity.js';
21
21
  import { Keystore } from './keystore/keystore.js';
22
22
  import { extractMetaMaskSigner } from './utils/metamask.js';
23
23
  import { buildBigIntFromUint8Array } from './utils/bytes.js';
24
24
  import './utils/epoch.js';
25
25
 
26
- new Logger("waku:rln");
27
- class RLNLightInstance {
26
+ const log = new Logger("waku:credentials");
27
+ /**
28
+ * Manages credentials for RLN
29
+ * This is a lightweight implementation of the RLN contract that doesn't require Zerokit
30
+ * It is used to register membership and generate identity credentials
31
+ */
32
+ class RLNCredentialsManager {
28
33
  started = false;
29
34
  starting = false;
30
- _contract;
31
- _signer;
35
+ contract;
36
+ signer;
32
37
  keystore = Keystore.create();
33
- _credentials;
34
- constructor() { }
35
- get contract() {
36
- return this._contract;
38
+ credentials;
39
+ zerokit;
40
+ constructor(zerokit) {
41
+ log.info("RLNCredentialsManager initialized");
42
+ this.zerokit = zerokit;
37
43
  }
38
- get signer() {
39
- return this._signer;
44
+ get provider() {
45
+ return this.contract?.provider;
40
46
  }
41
47
  async start(options = {}) {
42
48
  if (this.started || this.starting) {
49
+ log.info("RLNCredentialsManager already started or starting");
43
50
  return;
44
51
  }
52
+ log.info("Starting RLNCredentialsManager");
45
53
  this.starting = true;
46
54
  try {
47
- const { credentials, keystore } = await RLNLightInstance.decryptCredentialsIfNeeded(options.credentials);
55
+ const { credentials, keystore } = await RLNCredentialsManager.decryptCredentialsIfNeeded(options.credentials);
56
+ if (credentials) {
57
+ log.info("Credentials successfully decrypted");
58
+ }
48
59
  const { signer, address, rateLimit } = await this.determineStartOptions(options, credentials);
60
+ log.info(`Using contract address: ${address}`);
49
61
  if (keystore) {
50
62
  this.keystore = keystore;
63
+ log.info("Using provided keystore");
51
64
  }
52
- this._credentials = credentials;
53
- this._signer = signer;
54
- this._contract = await RLNLightContract.init({
65
+ this.credentials = credentials;
66
+ this.signer = signer;
67
+ this.contract = new RLNBaseContract({
55
68
  address: address,
56
69
  signer: signer,
57
- rateLimit: rateLimit
70
+ rateLimit: rateLimit ?? this.zerokit?.rateLimit
58
71
  });
72
+ log.info("RLNCredentialsManager successfully started");
59
73
  this.started = true;
60
74
  }
75
+ catch (error) {
76
+ log.error("Failed to start RLNCredentialsManager", error);
77
+ throw error;
78
+ }
61
79
  finally {
62
80
  this.starting = false;
63
81
  }
64
82
  }
65
- get credentials() {
66
- return this._credentials;
83
+ async registerMembership(options) {
84
+ if (!this.contract) {
85
+ log.error("RLN Contract is not initialized");
86
+ throw Error("RLN Contract is not initialized.");
87
+ }
88
+ log.info("Registering membership");
89
+ let identity = "identity" in options && options.identity;
90
+ if ("signature" in options) {
91
+ log.info("Generating identity from signature");
92
+ if (this.zerokit) {
93
+ log.info("Using Zerokit to generate identity");
94
+ identity = this.zerokit.generateSeededIdentityCredential(options.signature);
95
+ }
96
+ else {
97
+ log.info("Using local implementation to generate identity");
98
+ identity = this.generateSeededIdentityCredential(options.signature);
99
+ }
100
+ }
101
+ if (!identity) {
102
+ log.error("Missing signature or identity to register membership");
103
+ throw Error("Missing signature or identity to register membership.");
104
+ }
105
+ log.info("Registering identity with contract");
106
+ return this.contract.registerWithIdentity(identity);
107
+ }
108
+ /**
109
+ * Changes credentials in use by relying on provided Keystore earlier in rln.start
110
+ * @param id: string, hash of credentials to select from Keystore
111
+ * @param password: string or bytes to use to decrypt credentials from Keystore
112
+ */
113
+ async useCredentials(id, password) {
114
+ log.info(`Attempting to use credentials with ID: ${id}`);
115
+ this.credentials = await this.keystore?.readCredential(id, password);
116
+ if (this.credentials) {
117
+ log.info("Successfully loaded credentials");
118
+ }
119
+ else {
120
+ log.warn("Failed to load credentials");
121
+ }
67
122
  }
68
123
  async determineStartOptions(options, credentials) {
69
124
  let chainId = credentials?.membership.chainId;
@@ -71,11 +126,14 @@ class RLNLightInstance {
71
126
  options.address ||
72
127
  LINEA_CONTRACT.address;
73
128
  if (address === LINEA_CONTRACT.address) {
74
- chainId = LINEA_CONTRACT.chainId;
129
+ chainId = LINEA_CONTRACT.chainId.toString();
130
+ log.info(`Using Linea contract with chainId: ${chainId}`);
75
131
  }
76
132
  const signer = options.signer || (await extractMetaMaskSigner());
77
133
  const currentChainId = await signer.getChainId();
78
- if (chainId && chainId !== currentChainId) {
134
+ log.info(`Current chain ID: ${currentChainId}`);
135
+ if (chainId && chainId !== currentChainId.toString()) {
136
+ log.error(`Chain ID mismatch: contract=${chainId}, current=${currentChainId}`);
79
137
  throw Error(`Failed to start RLN contract, chain ID of contract is different from current one: contract-${chainId}, current network-${currentChainId}`);
80
138
  }
81
139
  return {
@@ -85,20 +143,47 @@ class RLNLightInstance {
85
143
  }
86
144
  static async decryptCredentialsIfNeeded(credentials) {
87
145
  if (!credentials) {
146
+ log.info("No credentials provided");
88
147
  return {};
89
148
  }
90
149
  if ("identity" in credentials) {
150
+ log.info("Using already decrypted credentials");
91
151
  return { credentials };
92
152
  }
153
+ log.info("Attempting to decrypt credentials");
93
154
  const keystore = Keystore.fromString(credentials.keystore);
94
155
  if (!keystore) {
156
+ log.warn("Failed to create keystore from string");
95
157
  return {};
96
158
  }
97
- const decryptedCredentials = await keystore.readCredential(credentials.id, credentials.password);
98
- return {
99
- keystore,
100
- credentials: decryptedCredentials
101
- };
159
+ try {
160
+ const decryptedCredentials = await keystore.readCredential(credentials.id, credentials.password);
161
+ log.info(`Successfully decrypted credentials with ID: ${credentials.id}`);
162
+ return {
163
+ keystore,
164
+ credentials: decryptedCredentials
165
+ };
166
+ }
167
+ catch (error) {
168
+ log.error("Failed to decrypt credentials", error);
169
+ throw error;
170
+ }
171
+ }
172
+ async verifyCredentialsAgainstContract(credentials) {
173
+ if (!this.contract) {
174
+ throw Error("Failed to verify chain coordinates: no contract initialized.");
175
+ }
176
+ const registryAddress = credentials.membership.address;
177
+ const currentRegistryAddress = this.contract.address;
178
+ if (registryAddress !== currentRegistryAddress) {
179
+ throw Error(`Failed to verify chain coordinates: credentials contract address=${registryAddress} is not equal to registryContract address=${currentRegistryAddress}`);
180
+ }
181
+ const chainId = credentials.membership.chainId;
182
+ const network = await this.contract.provider.getNetwork();
183
+ const currentChainId = network.chainId;
184
+ if (chainId !== currentChainId.toString()) {
185
+ throw Error(`Failed to verify chain coordinates: credentials chainID=${chainId} is not equal to registryContract chainID=${currentChainId}`);
186
+ }
102
187
  }
103
188
  /**
104
189
  * Generates an identity credential from a seed string
@@ -107,6 +192,7 @@ class RLNLightInstance {
107
192
  * @returns IdentityCredential
108
193
  */
109
194
  generateSeededIdentityCredential(seed) {
195
+ log.info("Generating seeded identity credential");
110
196
  // Convert the seed to bytes
111
197
  const encoder = new TextEncoder();
112
198
  const seedBytes = encoder.encode(seed);
@@ -121,29 +207,9 @@ class RLNLightInstance {
121
207
  const idCommitment = sha256(idSecretHash);
122
208
  // Convert IDCommitment to BigInt
123
209
  const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment);
210
+ log.info("Successfully generated identity credential");
124
211
  return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
125
212
  }
126
- async registerMembership(options) {
127
- if (!this.contract) {
128
- throw Error("RLN Contract is not initialized.");
129
- }
130
- let identity = "identity" in options && options.identity;
131
- if ("signature" in options) {
132
- identity = this.generateSeededIdentityCredential(options.signature);
133
- }
134
- if (!identity) {
135
- throw Error("Missing signature or identity to register membership.");
136
- }
137
- return this.contract.registerWithIdentity(identity);
138
- }
139
- /**
140
- * Changes credentials in use by relying on provided Keystore earlier in rln.start
141
- * @param id: string, hash of credentials to select from Keystore
142
- * @param password: string or bytes to use to decrypt credentials from Keystore
143
- */
144
- async useCredentials(id, password) {
145
- this._credentials = await this.keystore?.readCredential(id, password);
146
- }
147
213
  }
148
214
 
149
- export { RLNLightInstance };
215
+ export { RLNCredentialsManager };
@@ -177,7 +177,7 @@ class Keystore {
177
177
  treeIndex: _.get(obj, "treeIndex"),
178
178
  chainId: _.get(obj, "membershipContract.chainId"),
179
179
  address: _.get(obj, "membershipContract.address"),
180
- rateLimit: _.get(obj, "membershipContract.rateLimit")
180
+ rateLimit: _.get(obj, "userMessageLimit")
181
181
  }
182
182
  };
183
183
  }
@@ -187,6 +187,9 @@ class Keystore {
187
187
  }
188
188
  }
189
189
  static fromArraylikeToBytes(obj) {
190
+ if (Array.isArray(obj)) {
191
+ return new Uint8Array(obj);
192
+ }
190
193
  const bytes = [];
191
194
  let index = 0;
192
195
  let lastElement = obj[index];
@@ -208,15 +211,16 @@ class Keystore {
208
211
  return utf8ToBytes(JSON.stringify({
209
212
  treeIndex: options.membership.treeIndex,
210
213
  identityCredential: {
211
- idCommitment: options.identity.IDCommitment,
212
- idNullifier: options.identity.IDNullifier,
213
- idSecretHash: options.identity.IDSecretHash,
214
- idTrapdoor: options.identity.IDTrapdoor
214
+ idCommitment: Array.from(options.identity.IDCommitment),
215
+ idNullifier: Array.from(options.identity.IDNullifier),
216
+ idSecretHash: Array.from(options.identity.IDSecretHash),
217
+ idTrapdoor: Array.from(options.identity.IDTrapdoor)
215
218
  },
216
219
  membershipContract: {
217
220
  chainId: options.membership.chainId,
218
221
  address: options.membership.address
219
- }
222
+ },
223
+ userMessageLimit: options.membership.rateLimit
220
224
  }));
221
225
  }
222
226
  }
@@ -21,167 +21,45 @@ import { Logger } from '../../utils/dist/logger/index.js';
21
21
  import '../../core/dist/lib/metadata/metadata.js';
22
22
  import __wbg_init, { init_panic_hook, newRLN } from '../../../node_modules/@waku/zerokit-rln-wasm/rln_wasm.js';
23
23
  import { createRLNEncoder, createRLNDecoder } from './codec.js';
24
- import { LINEA_CONTRACT, DEFAULT_RATE_LIMIT } from './contract/constants.js';
25
- import { RLNContract } from './contract/rln_contract.js';
26
- import { Keystore } from './keystore/keystore.js';
24
+ import { DEFAULT_RATE_LIMIT } from './contract/constants.js';
25
+ import { RLNCredentialsManager } from './credentials_manager.js';
27
26
  import verificationKey from './resources/verification_key.js';
28
27
  import { builder } from './resources/witness_calculator.js';
29
- import { extractMetaMaskSigner } from './utils/metamask.js';
30
- import './utils/epoch.js';
31
28
  import { Zerokit } from './zerokit.js';
32
29
 
33
30
  const log = new Logger("waku:rln");
34
- async function loadWitnessCalculator() {
35
- try {
36
- const url = new URL("./resources/rln.wasm", import.meta.url);
37
- const response = await fetch(url);
38
- if (!response.ok) {
39
- throw new Error(`Failed to fetch witness calculator: ${response.status} ${response.statusText}`);
40
- }
41
- return await builder(new Uint8Array(await response.arrayBuffer()), false);
42
- }
43
- catch (error) {
44
- log.error("Error loading witness calculator:", error);
45
- throw new Error(`Failed to load witness calculator: ${error instanceof Error ? error.message : String(error)}`);
46
- }
47
- }
48
- async function loadZkey() {
49
- try {
50
- const url = new URL("./resources/rln_final.zkey", import.meta.url);
51
- const response = await fetch(url);
52
- if (!response.ok) {
53
- throw new Error(`Failed to fetch zkey: ${response.status} ${response.statusText}`);
54
- }
55
- return new Uint8Array(await response.arrayBuffer());
56
- }
57
- catch (error) {
58
- log.error("Error loading zkey:", error);
59
- throw new Error(`Failed to load zkey: ${error instanceof Error ? error.message : String(error)}`);
60
- }
61
- }
62
- /**
63
- * Create an instance of RLN
64
- * @returns RLNInstance
65
- */
66
- async function create() {
67
- try {
68
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
- await __wbg_init?.();
70
- init_panic_hook();
71
- const witnessCalculator = await loadWitnessCalculator();
72
- const zkey = await loadZkey();
73
- const stringEncoder = new TextEncoder();
74
- const vkey = stringEncoder.encode(JSON.stringify(verificationKey));
75
- const DEPTH = 20;
76
- const zkRLN = newRLN(DEPTH, zkey, vkey);
77
- const zerokit = new Zerokit(zkRLN, witnessCalculator, DEFAULT_RATE_LIMIT);
78
- return new RLNInstance(zerokit);
79
- }
80
- catch (error) {
81
- log.error("Failed to initialize RLN:", error);
82
- throw error;
83
- }
84
- }
85
- class RLNInstance {
31
+ class RLNInstance extends RLNCredentialsManager {
86
32
  zerokit;
87
- started = false;
88
- starting = false;
89
- _contract;
90
- _signer;
91
- keystore = Keystore.create();
92
- _credentials;
93
- constructor(zerokit) {
94
- this.zerokit = zerokit;
95
- }
96
- get contract() {
97
- return this._contract;
98
- }
99
- get signer() {
100
- return this._signer;
101
- }
102
- async start(options = {}) {
103
- if (this.started || this.starting) {
104
- return;
105
- }
106
- this.starting = true;
33
+ /**
34
+ * Create an instance of RLN
35
+ * @returns RLNInstance
36
+ */
37
+ static async create() {
107
38
  try {
108
- const { credentials, keystore } = await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
109
- const { signer, address, rateLimit } = await this.determineStartOptions(options, credentials);
110
- if (keystore) {
111
- this.keystore = keystore;
112
- }
113
- this._credentials = credentials;
114
- this._signer = signer;
115
- this._contract = await RLNContract.init(this, {
116
- address: address,
117
- signer: signer,
118
- rateLimit: rateLimit ?? this.zerokit.getRateLimit
119
- });
120
- this.started = true;
39
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
+ await __wbg_init?.();
41
+ init_panic_hook();
42
+ const witnessCalculator = await RLNInstance.loadWitnessCalculator();
43
+ const zkey = await RLNInstance.loadZkey();
44
+ const stringEncoder = new TextEncoder();
45
+ const vkey = stringEncoder.encode(JSON.stringify(verificationKey));
46
+ const DEPTH = 20;
47
+ const zkRLN = newRLN(DEPTH, zkey, vkey);
48
+ const zerokit = new Zerokit(zkRLN, witnessCalculator, DEFAULT_RATE_LIMIT);
49
+ return new RLNInstance(zerokit);
50
+ }
51
+ catch (error) {
52
+ log.error("Failed to initialize RLN:", error);
53
+ throw error;
121
54
  }
122
- finally {
123
- this.starting = false;
124
- }
125
- }
126
- async determineStartOptions(options, credentials) {
127
- let chainId = credentials?.membership.chainId;
128
- const address = credentials?.membership.address ||
129
- options.address ||
130
- LINEA_CONTRACT.address;
131
- if (address === LINEA_CONTRACT.address) {
132
- chainId = LINEA_CONTRACT.chainId;
133
- }
134
- const signer = options.signer || (await extractMetaMaskSigner());
135
- const currentChainId = await signer.getChainId();
136
- if (chainId && chainId !== currentChainId) {
137
- throw Error(`Failed to start RLN contract, chain ID of contract is different from current one: contract-${chainId}, current network-${currentChainId}`);
138
- }
139
- return {
140
- signer,
141
- address
142
- };
143
55
  }
144
- static async decryptCredentialsIfNeeded(credentials) {
145
- if (!credentials) {
146
- return {};
147
- }
148
- if ("identity" in credentials) {
149
- return { credentials };
150
- }
151
- const keystore = Keystore.fromString(credentials.keystore);
152
- if (!keystore) {
153
- return {};
154
- }
155
- const decryptedCredentials = await keystore.readCredential(credentials.id, credentials.password);
156
- return {
157
- keystore,
158
- credentials: decryptedCredentials
159
- };
160
- }
161
- async registerMembership(options) {
162
- if (!this.contract) {
163
- throw Error("RLN Contract is not initialized.");
164
- }
165
- let identity = "identity" in options && options.identity;
166
- if ("signature" in options) {
167
- identity = this.zerokit.generateSeededIdentityCredential(options.signature);
168
- }
169
- if (!identity) {
170
- throw Error("Missing signature or identity to register membership.");
171
- }
172
- return this.contract.registerWithIdentity(identity);
173
- }
174
- /**
175
- * Changes credentials in use by relying on provided Keystore earlier in rln.start
176
- * @param id: string, hash of credentials to select from Keystore
177
- * @param password: string or bytes to use to decrypt credentials from Keystore
178
- */
179
- async useCredentials(id, password) {
180
- this._credentials = await this.keystore?.readCredential(id, password);
56
+ constructor(zerokit) {
57
+ super(zerokit);
58
+ this.zerokit = zerokit;
181
59
  }
182
60
  async createEncoder(options) {
183
61
  const { credentials: decryptedCredentials } = await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
184
- const credentials = decryptedCredentials || this._credentials;
62
+ const credentials = decryptedCredentials || this.credentials;
185
63
  if (!credentials) {
186
64
  throw Error("Failed to create Encoder: missing RLN credentials. Use createRLNEncoder directly.");
187
65
  }
@@ -193,28 +71,40 @@ class RLNInstance {
193
71
  credential: credentials.identity
194
72
  });
195
73
  }
196
- async verifyCredentialsAgainstContract(credentials) {
197
- if (!this._contract) {
198
- throw Error("Failed to verify chain coordinates: no contract initialized.");
199
- }
200
- const registryAddress = credentials.membership.address;
201
- const currentRegistryAddress = this._contract.address;
202
- if (registryAddress !== currentRegistryAddress) {
203
- throw Error(`Failed to verify chain coordinates: credentials contract address=${registryAddress} is not equal to registryContract address=${currentRegistryAddress}`);
204
- }
205
- const chainId = credentials.membership.chainId;
206
- const network = await this._contract.provider.getNetwork();
207
- const currentChainId = network.chainId;
208
- if (chainId !== currentChainId) {
209
- throw Error(`Failed to verify chain coordinates: credentials chainID=${chainId} is not equal to registryContract chainID=${currentChainId}`);
210
- }
211
- }
212
74
  createDecoder(contentTopic) {
213
75
  return createRLNDecoder({
214
76
  rlnInstance: this,
215
77
  decoder: createDecoder(contentTopic)
216
78
  });
217
79
  }
80
+ static async loadWitnessCalculator() {
81
+ try {
82
+ const url = new URL("./resources/rln.wasm", import.meta.url);
83
+ const response = await fetch(url);
84
+ if (!response.ok) {
85
+ throw new Error(`Failed to fetch witness calculator: ${response.status} ${response.statusText}`);
86
+ }
87
+ return await builder(new Uint8Array(await response.arrayBuffer()), false);
88
+ }
89
+ catch (error) {
90
+ log.error("Error loading witness calculator:", error);
91
+ throw new Error(`Failed to load witness calculator: ${error instanceof Error ? error.message : String(error)}`);
92
+ }
93
+ }
94
+ static async loadZkey() {
95
+ try {
96
+ const url = new URL("./resources/rln_final.zkey", import.meta.url);
97
+ const response = await fetch(url);
98
+ if (!response.ok) {
99
+ throw new Error(`Failed to fetch zkey: ${response.status} ${response.statusText}`);
100
+ }
101
+ return new Uint8Array(await response.arrayBuffer());
102
+ }
103
+ catch (error) {
104
+ log.error("Error loading zkey:", error);
105
+ throw new Error(`Failed to load zkey: ${error instanceof Error ? error.message : String(error)}`);
106
+ }
107
+ }
218
108
  }
219
109
 
220
- export { RLNInstance, create };
110
+ export { RLNInstance };
@@ -8,11 +8,11 @@ import { epochIntToBytes, dateToEpoch } from './utils/epoch.js';
8
8
  class Zerokit {
9
9
  zkRLN;
10
10
  witnessCalculator;
11
- rateLimit;
12
- constructor(zkRLN, witnessCalculator, rateLimit = DEFAULT_RATE_LIMIT) {
11
+ _rateLimit;
12
+ constructor(zkRLN, witnessCalculator, _rateLimit = DEFAULT_RATE_LIMIT) {
13
13
  this.zkRLN = zkRLN;
14
14
  this.witnessCalculator = witnessCalculator;
15
- this.rateLimit = rateLimit;
15
+ this._rateLimit = _rateLimit;
16
16
  }
17
17
  get getZkRLN() {
18
18
  return this.zkRLN;
@@ -20,8 +20,8 @@ class Zerokit {
20
20
  get getWitnessCalculator() {
21
21
  return this.witnessCalculator;
22
22
  }
23
- get getRateLimit() {
24
- return this.rateLimit;
23
+ get rateLimit() {
24
+ return this._rateLimit;
25
25
  }
26
26
  generateIdentityCredentials() {
27
27
  const memKeys = generateExtendedMembershipKey(this.zkRLN); // TODO: rename this function in zerokit rln-wasm