@waku/rln 0.0.14 → 0.1.0-e52107d

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 CHANGED
@@ -1732,7 +1732,7 @@ const sha$1 = name =>
1732
1732
  */
1733
1733
  async data => new Uint8Array(await crypto.subtle.digest(name, data));
1734
1734
 
1735
- const sha256$2 = from({
1735
+ const sha256$3 = from({
1736
1736
  name: 'sha2-256',
1737
1737
  code: 0x12,
1738
1738
  encode: sha$1('SHA-256')
@@ -1746,7 +1746,7 @@ const sha512$1 = from({
1746
1746
 
1747
1747
  var sha2 = /*#__PURE__*/Object.freeze({
1748
1748
  __proto__: null,
1749
- sha256: sha256$2,
1749
+ sha256: sha256$3,
1750
1750
  sha512: sha512$1
1751
1751
  });
1752
1752
 
@@ -1941,13 +1941,13 @@ class RlnMessage {
1941
1941
 
1942
1942
  const log = debug("waku:rln:encoder");
1943
1943
  class RLNEncoder {
1944
- constructor(encoder, rlnInstance, index, membershipKey) {
1944
+ constructor(encoder, rlnInstance, index, identityCredential) {
1945
1945
  this.encoder = encoder;
1946
1946
  this.rlnInstance = rlnInstance;
1947
1947
  this.index = index;
1948
1948
  if (index < 0)
1949
1949
  throw "invalid membership index";
1950
- this.idKey = membershipKey.IDKey;
1950
+ this.idSecretHash = identityCredential.IDSecretHash;
1951
1951
  }
1952
1952
  async toWire(message) {
1953
1953
  message.rateLimitProof = await this.generateProof(message);
@@ -1966,7 +1966,7 @@ class RLNEncoder {
1966
1966
  async generateProof(message) {
1967
1967
  const signal = toRLNSignal(this.contentTopic, message);
1968
1968
  console.time("proof_gen_timer");
1969
- const proof = await this.rlnInstance.generateRLNProof(signal, this.index, message.timestamp, this.idKey);
1969
+ const proof = await this.rlnInstance.generateRLNProof(signal, this.index, message.timestamp, this.idSecretHash);
1970
1970
  console.timeEnd("proof_gen_timer");
1971
1971
  return proof;
1972
1972
  }
@@ -2014,16 +2014,42 @@ const GOERLI_CONTRACT = {
2014
2014
 
2015
2015
  let wasm;
2016
2016
 
2017
- const heap = new Array(32).fill(undefined);
2017
+ const heap = new Array(128).fill(undefined);
2018
2018
 
2019
2019
  heap.push(undefined, null, true, false);
2020
2020
 
2021
2021
  function getObject(idx) { return heap[idx]; }
2022
2022
 
2023
+ const cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
2024
+
2025
+ cachedTextDecoder.decode();
2026
+
2027
+ let cachedUint8Memory0 = null;
2028
+
2029
+ function getUint8Memory0() {
2030
+ if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
2031
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
2032
+ }
2033
+ return cachedUint8Memory0;
2034
+ }
2035
+
2036
+ function getStringFromWasm0(ptr, len) {
2037
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
2038
+ }
2039
+
2023
2040
  let heap_next = heap.length;
2024
2041
 
2042
+ function addHeapObject(obj) {
2043
+ if (heap_next === heap.length) heap.push(heap.length + 1);
2044
+ const idx = heap_next;
2045
+ heap_next = heap[idx];
2046
+
2047
+ heap[idx] = obj;
2048
+ return idx;
2049
+ }
2050
+
2025
2051
  function dropObject(idx) {
2026
- if (idx < 36) return;
2052
+ if (idx < 132) return;
2027
2053
  heap[idx] = heap_next;
2028
2054
  heap_next = idx;
2029
2055
  }
@@ -2036,15 +2062,6 @@ function takeObject(idx) {
2036
2062
 
2037
2063
  let WASM_VECTOR_LEN = 0;
2038
2064
 
2039
- let cachedUint8Memory0 = new Uint8Array();
2040
-
2041
- function getUint8Memory0() {
2042
- if (cachedUint8Memory0.byteLength === 0) {
2043
- cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
2044
- }
2045
- return cachedUint8Memory0;
2046
- }
2047
-
2048
2065
  const cachedTextEncoder = new TextEncoder('utf-8');
2049
2066
 
2050
2067
  const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
@@ -2102,32 +2119,15 @@ function isLikeNone(x) {
2102
2119
  return x === undefined || x === null;
2103
2120
  }
2104
2121
 
2105
- let cachedInt32Memory0 = new Int32Array();
2122
+ let cachedInt32Memory0 = null;
2106
2123
 
2107
2124
  function getInt32Memory0() {
2108
- if (cachedInt32Memory0.byteLength === 0) {
2125
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
2109
2126
  cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
2110
2127
  }
2111
2128
  return cachedInt32Memory0;
2112
2129
  }
2113
2130
 
2114
- const cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
2115
-
2116
- cachedTextDecoder.decode();
2117
-
2118
- function getStringFromWasm0(ptr, len) {
2119
- return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
2120
- }
2121
-
2122
- function addHeapObject(obj) {
2123
- if (heap_next === heap.length) heap.push(heap.length + 1);
2124
- const idx = heap_next;
2125
- heap_next = heap[idx];
2126
-
2127
- heap[idx] = obj;
2128
- return idx;
2129
- }
2130
-
2131
2131
  function debugString(val) {
2132
2132
  // primitive types
2133
2133
  const type = typeof val;
@@ -2205,8 +2205,19 @@ function init_panic_hook() {
2205
2205
  * @returns {number}
2206
2206
  */
2207
2207
  function newRLN(tree_height, zkey, vk) {
2208
- const ret = wasm.newRLN(tree_height, addHeapObject(zkey), addHeapObject(vk));
2209
- return ret;
2208
+ try {
2209
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2210
+ wasm.newRLN(retptr, tree_height, addHeapObject(zkey), addHeapObject(vk));
2211
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2212
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2213
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
2214
+ if (r2) {
2215
+ throw takeObject(r1);
2216
+ }
2217
+ return r0;
2218
+ } finally {
2219
+ wasm.__wbindgen_add_to_stack_pointer(16);
2220
+ }
2210
2221
  }
2211
2222
 
2212
2223
  /**
@@ -2215,8 +2226,19 @@ function newRLN(tree_height, zkey, vk) {
2215
2226
  * @returns {Uint8Array}
2216
2227
  */
2217
2228
  function getSerializedRLNWitness(ctx, input) {
2218
- const ret = wasm.getSerializedRLNWitness(ctx, addHeapObject(input));
2219
- return takeObject(ret);
2229
+ try {
2230
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2231
+ wasm.getSerializedRLNWitness(retptr, ctx, addHeapObject(input));
2232
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2233
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2234
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
2235
+ if (r2) {
2236
+ throw takeObject(r1);
2237
+ }
2238
+ return takeObject(r0);
2239
+ } finally {
2240
+ wasm.__wbindgen_add_to_stack_pointer(16);
2241
+ }
2220
2242
  }
2221
2243
 
2222
2244
  /**
@@ -2237,20 +2259,68 @@ function insertMember(ctx, input) {
2237
2259
  }
2238
2260
  }
2239
2261
 
2262
+ /**
2263
+ * @param {number} ctx
2264
+ * @param {number} index
2265
+ * @param {Uint8Array} input
2266
+ */
2267
+ function setLeavesFrom(ctx, index, input) {
2268
+ try {
2269
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2270
+ wasm.setLeavesFrom(retptr, ctx, index, addHeapObject(input));
2271
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2272
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2273
+ if (r1) {
2274
+ throw takeObject(r0);
2275
+ }
2276
+ } finally {
2277
+ wasm.__wbindgen_add_to_stack_pointer(16);
2278
+ }
2279
+ }
2280
+
2281
+ /**
2282
+ * @param {number} ctx
2283
+ * @param {number} index
2284
+ */
2285
+ function deleteLeaf(ctx, index) {
2286
+ try {
2287
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2288
+ wasm.deleteLeaf(retptr, ctx, index);
2289
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2290
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2291
+ if (r1) {
2292
+ throw takeObject(r0);
2293
+ }
2294
+ } finally {
2295
+ wasm.__wbindgen_add_to_stack_pointer(16);
2296
+ }
2297
+ }
2298
+
2240
2299
  /**
2241
2300
  * @param {number} ctx
2242
2301
  * @param {Uint8Array} serialized_witness
2243
2302
  * @returns {object}
2244
2303
  */
2245
2304
  function RLNWitnessToJson(ctx, serialized_witness) {
2246
- const ret = wasm.RLNWitnessToJson(ctx, addHeapObject(serialized_witness));
2247
- return takeObject(ret);
2305
+ try {
2306
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2307
+ wasm.RLNWitnessToJson(retptr, ctx, addHeapObject(serialized_witness));
2308
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2309
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2310
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
2311
+ if (r2) {
2312
+ throw takeObject(r1);
2313
+ }
2314
+ return takeObject(r0);
2315
+ } finally {
2316
+ wasm.__wbindgen_add_to_stack_pointer(16);
2317
+ }
2248
2318
  }
2249
2319
 
2250
- let cachedUint32Memory0 = new Uint32Array();
2320
+ let cachedUint32Memory0 = null;
2251
2321
 
2252
2322
  function getUint32Memory0() {
2253
- if (cachedUint32Memory0.byteLength === 0) {
2323
+ if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
2254
2324
  cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
2255
2325
  }
2256
2326
  return cachedUint32Memory0;
@@ -2293,10 +2363,10 @@ function generate_rln_proof_with_witness(ctx, calculated_witness, serialized_wit
2293
2363
  * @param {number} ctx
2294
2364
  * @returns {Uint8Array}
2295
2365
  */
2296
- function generateMembershipKey(ctx) {
2366
+ function generateExtendedMembershipKey(ctx) {
2297
2367
  try {
2298
2368
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2299
- wasm.generateMembershipKey(retptr, ctx);
2369
+ wasm.generateExtendedMembershipKey(retptr, ctx);
2300
2370
  var r0 = getInt32Memory0()[retptr / 4 + 0];
2301
2371
  var r1 = getInt32Memory0()[retptr / 4 + 1];
2302
2372
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -2314,10 +2384,10 @@ function generateMembershipKey(ctx) {
2314
2384
  * @param {Uint8Array} seed
2315
2385
  * @returns {Uint8Array}
2316
2386
  */
2317
- function generateSeededMembershipKey(ctx, seed) {
2387
+ function generateSeededExtendedMembershipKey(ctx, seed) {
2318
2388
  try {
2319
2389
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2320
- wasm.generateSeededMembershipKey(retptr, ctx, addHeapObject(seed));
2390
+ wasm.generateSeededExtendedMembershipKey(retptr, ctx, addHeapObject(seed));
2321
2391
  var r0 = getInt32Memory0()[retptr / 4 + 0];
2322
2392
  var r1 = getInt32Memory0()[retptr / 4 + 1];
2323
2393
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -2393,6 +2463,46 @@ function getRoot(ctx) {
2393
2463
  }
2394
2464
  }
2395
2465
 
2466
+ /**
2467
+ * @param {Uint8Array} input
2468
+ * @returns {Uint8Array}
2469
+ */
2470
+ function hash$1(input) {
2471
+ try {
2472
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2473
+ wasm.hash(retptr, addHeapObject(input));
2474
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2475
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2476
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
2477
+ if (r2) {
2478
+ throw takeObject(r1);
2479
+ }
2480
+ return takeObject(r0);
2481
+ } finally {
2482
+ wasm.__wbindgen_add_to_stack_pointer(16);
2483
+ }
2484
+ }
2485
+
2486
+ /**
2487
+ * @param {Uint8Array} input
2488
+ * @returns {Uint8Array}
2489
+ */
2490
+ function poseidonHash$1(input) {
2491
+ try {
2492
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2493
+ wasm.poseidonHash(retptr, addHeapObject(input));
2494
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2495
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2496
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
2497
+ if (r2) {
2498
+ throw takeObject(r1);
2499
+ }
2500
+ return takeObject(r0);
2501
+ } finally {
2502
+ wasm.__wbindgen_add_to_stack_pointer(16);
2503
+ }
2504
+ }
2505
+
2396
2506
  function handleError(f, args) {
2397
2507
  try {
2398
2508
  return f.apply(this, args);
@@ -2439,9 +2549,21 @@ async function load(module, imports) {
2439
2549
  function getImports() {
2440
2550
  const imports = {};
2441
2551
  imports.wbg = {};
2552
+ imports.wbg.__wbindgen_is_string = function(arg0) {
2553
+ const ret = typeof(getObject(arg0)) === 'string';
2554
+ return ret;
2555
+ };
2556
+ imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
2557
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
2558
+ return addHeapObject(ret);
2559
+ };
2442
2560
  imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
2443
2561
  takeObject(arg0);
2444
2562
  };
2563
+ imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
2564
+ const ret = getStringFromWasm0(arg0, arg1);
2565
+ return addHeapObject(ret);
2566
+ };
2445
2567
  imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
2446
2568
  const obj = getObject(arg1);
2447
2569
  const ret = typeof(obj) === 'string' ? obj : undefined;
@@ -2450,40 +2572,30 @@ function getImports() {
2450
2572
  getInt32Memory0()[arg0 / 4 + 1] = len0;
2451
2573
  getInt32Memory0()[arg0 / 4 + 0] = ptr0;
2452
2574
  };
2453
- imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
2454
- const ret = getStringFromWasm0(arg0, arg1);
2455
- return addHeapObject(ret);
2456
- };
2457
- imports.wbg.__wbindgen_is_string = function(arg0) {
2458
- const ret = typeof(getObject(arg0)) === 'string';
2459
- return ret;
2460
- };
2461
- imports.wbg.__wbg_BigInt_d0c7d465bfa30d3b = function(arg0) {
2462
- const ret = BigInt(arg0);
2575
+ imports.wbg.__wbindgen_bigint_from_i64 = function(arg0) {
2576
+ const ret = arg0;
2463
2577
  return addHeapObject(ret);
2464
2578
  };
2465
2579
  imports.wbg.__wbindgen_number_new = function(arg0) {
2466
2580
  const ret = arg0;
2467
2581
  return addHeapObject(ret);
2468
2582
  };
2469
- imports.wbg.__wbg_BigInt_1fab4952b6c4a499 = function(arg0) {
2470
- const ret = BigInt(BigInt.asUintN(64, arg0));
2583
+ imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
2584
+ const ret = BigInt.asUintN(64, arg0);
2471
2585
  return addHeapObject(ret);
2472
2586
  };
2473
2587
  imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
2474
2588
  const ret = getObject(arg0);
2475
2589
  return addHeapObject(ret);
2476
2590
  };
2477
- imports.wbg.__wbindgen_is_undefined = function(arg0) {
2478
- const ret = getObject(arg0) === undefined;
2479
- return ret;
2480
- };
2481
- imports.wbg.__wbindgen_is_object = function(arg0) {
2482
- const val = getObject(arg0);
2483
- const ret = typeof(val) === 'object' && val !== null;
2484
- return ret;
2591
+ imports.wbg.__wbg_String_91fba7ded13ba54c = function(arg0, arg1) {
2592
+ const ret = String(getObject(arg1));
2593
+ const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2594
+ const len0 = WASM_VECTOR_LEN;
2595
+ getInt32Memory0()[arg0 / 4 + 1] = len0;
2596
+ getInt32Memory0()[arg0 / 4 + 0] = ptr0;
2485
2597
  };
2486
- imports.wbg.__wbg_set_c943d600fa71e4dd = function(arg0, arg1, arg2) {
2598
+ imports.wbg.__wbg_set_20cbc34131e76824 = function(arg0, arg1, arg2) {
2487
2599
  getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
2488
2600
  };
2489
2601
  imports.wbg.__wbg_new_abda76e883ba8a5f = function() {
@@ -2504,119 +2616,128 @@ function getImports() {
2504
2616
  wasm.__wbindgen_free(arg0, arg1);
2505
2617
  }
2506
2618
  };
2507
- imports.wbg.__wbg_randomFillSync_065afffde01daa66 = function() { return handleError(function (arg0, arg1, arg2) {
2619
+ imports.wbg.__wbindgen_is_undefined = function(arg0) {
2620
+ const ret = getObject(arg0) === undefined;
2621
+ return ret;
2622
+ };
2623
+ imports.wbg.__wbg_randomFillSync_6894564c2c334c42 = function() { return handleError(function (arg0, arg1, arg2) {
2508
2624
  getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2));
2509
2625
  }, arguments) };
2510
- imports.wbg.__wbg_getRandomValues_b99eec4244a475bb = function() { return handleError(function (arg0, arg1) {
2626
+ imports.wbg.__wbg_getRandomValues_805f1c3d65988a5a = function() { return handleError(function (arg0, arg1) {
2511
2627
  getObject(arg0).getRandomValues(getObject(arg1));
2512
2628
  }, arguments) };
2513
- imports.wbg.__wbg_process_0cc2ada8524d6f83 = function(arg0) {
2629
+ imports.wbg.__wbg_crypto_e1d53a1d73fb10b8 = function(arg0) {
2630
+ const ret = getObject(arg0).crypto;
2631
+ return addHeapObject(ret);
2632
+ };
2633
+ imports.wbg.__wbindgen_is_object = function(arg0) {
2634
+ const val = getObject(arg0);
2635
+ const ret = typeof(val) === 'object' && val !== null;
2636
+ return ret;
2637
+ };
2638
+ imports.wbg.__wbg_process_038c26bf42b093f8 = function(arg0) {
2514
2639
  const ret = getObject(arg0).process;
2515
2640
  return addHeapObject(ret);
2516
2641
  };
2517
- imports.wbg.__wbg_versions_c11acceab27a6c87 = function(arg0) {
2642
+ imports.wbg.__wbg_versions_ab37218d2f0b24a8 = function(arg0) {
2518
2643
  const ret = getObject(arg0).versions;
2519
2644
  return addHeapObject(ret);
2520
2645
  };
2521
- imports.wbg.__wbg_node_7ff1ce49caf23815 = function(arg0) {
2646
+ imports.wbg.__wbg_node_080f4b19d15bc1fe = function(arg0) {
2522
2647
  const ret = getObject(arg0).node;
2523
2648
  return addHeapObject(ret);
2524
2649
  };
2525
- imports.wbg.__wbg_static_accessor_NODE_MODULE_cf6401cc1091279e = function() {
2526
- const ret = module;
2650
+ imports.wbg.__wbg_msCrypto_6e7d3e1f92610cbb = function(arg0) {
2651
+ const ret = getObject(arg0).msCrypto;
2527
2652
  return addHeapObject(ret);
2528
2653
  };
2529
- imports.wbg.__wbg_require_a746e79b322b9336 = function() { return handleError(function (arg0, arg1, arg2) {
2530
- const ret = getObject(arg0).require(getStringFromWasm0(arg1, arg2));
2654
+ imports.wbg.__wbg_require_78a3dcfbdba9cbce = function() { return handleError(function () {
2655
+ const ret = module.require;
2531
2656
  return addHeapObject(ret);
2532
2657
  }, arguments) };
2533
- imports.wbg.__wbg_crypto_2036bed7c44c25e7 = function(arg0) {
2534
- const ret = getObject(arg0).crypto;
2535
- return addHeapObject(ret);
2536
- };
2537
- imports.wbg.__wbg_msCrypto_a21fc88caf1ecdc8 = function(arg0) {
2538
- const ret = getObject(arg0).msCrypto;
2539
- return addHeapObject(ret);
2658
+ imports.wbg.__wbindgen_is_function = function(arg0) {
2659
+ const ret = typeof(getObject(arg0)) === 'function';
2660
+ return ret;
2540
2661
  };
2541
- imports.wbg.__wbg_new_1d9a920c6bfc44a8 = function() {
2662
+ imports.wbg.__wbg_new_b525de17f44a8943 = function() {
2542
2663
  const ret = new Array();
2543
2664
  return addHeapObject(ret);
2544
2665
  };
2545
- imports.wbg.__wbg_newnoargs_b5b063fc6c2f0376 = function(arg0, arg1) {
2666
+ imports.wbg.__wbg_newnoargs_2b8b6bd7753c76ba = function(arg0, arg1) {
2546
2667
  const ret = new Function(getStringFromWasm0(arg0, arg1));
2547
2668
  return addHeapObject(ret);
2548
2669
  };
2549
- imports.wbg.__wbg_new_268f7b7dd3430798 = function() {
2670
+ imports.wbg.__wbg_new_f841cc6f2098f4b5 = function() {
2550
2671
  const ret = new Map();
2551
2672
  return addHeapObject(ret);
2552
2673
  };
2553
- imports.wbg.__wbg_call_97ae9d8645dc388b = function() { return handleError(function (arg0, arg1) {
2674
+ imports.wbg.__wbg_call_95d1ea488d03e4e8 = function() { return handleError(function (arg0, arg1) {
2554
2675
  const ret = getObject(arg0).call(getObject(arg1));
2555
2676
  return addHeapObject(ret);
2556
2677
  }, arguments) };
2557
- imports.wbg.__wbg_new_0b9bfdd97583284e = function() {
2678
+ imports.wbg.__wbg_new_f9876326328f45ed = function() {
2558
2679
  const ret = new Object();
2559
2680
  return addHeapObject(ret);
2560
2681
  };
2561
- imports.wbg.__wbg_self_6d479506f72c6a71 = function() { return handleError(function () {
2682
+ imports.wbg.__wbg_self_e7c1f827057f6584 = function() { return handleError(function () {
2562
2683
  const ret = self.self;
2563
2684
  return addHeapObject(ret);
2564
2685
  }, arguments) };
2565
- imports.wbg.__wbg_window_f2557cc78490aceb = function() { return handleError(function () {
2686
+ imports.wbg.__wbg_window_a09ec664e14b1b81 = function() { return handleError(function () {
2566
2687
  const ret = window.window;
2567
2688
  return addHeapObject(ret);
2568
2689
  }, arguments) };
2569
- imports.wbg.__wbg_globalThis_7f206bda628d5286 = function() { return handleError(function () {
2690
+ imports.wbg.__wbg_globalThis_87cbb8506fecf3a9 = function() { return handleError(function () {
2570
2691
  const ret = globalThis.globalThis;
2571
2692
  return addHeapObject(ret);
2572
2693
  }, arguments) };
2573
- imports.wbg.__wbg_global_ba75c50d1cf384f4 = function() { return handleError(function () {
2694
+ imports.wbg.__wbg_global_c85a9259e621f3db = function() { return handleError(function () {
2574
2695
  const ret = global.global;
2575
2696
  return addHeapObject(ret);
2576
2697
  }, arguments) };
2577
- imports.wbg.__wbg_set_a68214f35c417fa9 = function(arg0, arg1, arg2) {
2698
+ imports.wbg.__wbg_set_17224bc548dd1d7b = function(arg0, arg1, arg2) {
2578
2699
  getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
2579
2700
  };
2580
- imports.wbg.__wbg_toString_d9cd5f001405e8ff = function() { return handleError(function (arg0, arg1) {
2701
+ imports.wbg.__wbg_toString_91b13ec0b518b06b = function() { return handleError(function (arg0, arg1) {
2581
2702
  const ret = getObject(arg0).toString(arg1);
2582
2703
  return addHeapObject(ret);
2583
2704
  }, arguments) };
2584
- imports.wbg.__wbg_new_8d2af00bc1e329ee = function(arg0, arg1) {
2585
- const ret = new Error(getStringFromWasm0(arg0, arg1));
2705
+ imports.wbg.__wbg_call_9495de66fdbe016b = function() { return handleError(function (arg0, arg1, arg2) {
2706
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
2586
2707
  return addHeapObject(ret);
2587
- };
2588
- imports.wbg.__wbg_set_933729cf5b66ac11 = function(arg0, arg1, arg2) {
2708
+ }, arguments) };
2709
+ imports.wbg.__wbg_set_388c4c6422704173 = function(arg0, arg1, arg2) {
2589
2710
  const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
2590
2711
  return addHeapObject(ret);
2591
2712
  };
2592
- imports.wbg.__wbg_fromEntries_7abdcb92016eb4b9 = function() { return handleError(function (arg0) {
2713
+ imports.wbg.__wbg_fromEntries_47a432d7604fc06a = function() { return handleError(function (arg0) {
2593
2714
  const ret = Object.fromEntries(getObject(arg0));
2594
2715
  return addHeapObject(ret);
2595
2716
  }, arguments) };
2596
- imports.wbg.__wbg_buffer_3f3d764d4747d564 = function(arg0) {
2717
+ imports.wbg.__wbg_buffer_cf65c07de34b9a08 = function(arg0) {
2597
2718
  const ret = getObject(arg0).buffer;
2598
2719
  return addHeapObject(ret);
2599
2720
  };
2600
- imports.wbg.__wbg_newwithbyteoffsetandlength_d9aa266703cb98be = function(arg0, arg1, arg2) {
2721
+ imports.wbg.__wbg_newwithbyteoffsetandlength_9fb2f11355ecadf5 = function(arg0, arg1, arg2) {
2601
2722
  const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
2602
2723
  return addHeapObject(ret);
2603
2724
  };
2604
- imports.wbg.__wbg_new_8c3f0052272a457a = function(arg0) {
2725
+ imports.wbg.__wbg_new_537b7341ce90bb31 = function(arg0) {
2605
2726
  const ret = new Uint8Array(getObject(arg0));
2606
2727
  return addHeapObject(ret);
2607
2728
  };
2608
- imports.wbg.__wbg_set_83db9690f9353e79 = function(arg0, arg1, arg2) {
2729
+ imports.wbg.__wbg_set_17499e8aa4003ebd = function(arg0, arg1, arg2) {
2609
2730
  getObject(arg0).set(getObject(arg1), arg2 >>> 0);
2610
2731
  };
2611
- imports.wbg.__wbg_length_9e1ae1900cb0fbd5 = function(arg0) {
2732
+ imports.wbg.__wbg_length_27a2afe8ab42b09f = function(arg0) {
2612
2733
  const ret = getObject(arg0).length;
2613
2734
  return ret;
2614
2735
  };
2615
- imports.wbg.__wbg_newwithlength_f5933855e4f48a19 = function(arg0) {
2736
+ imports.wbg.__wbg_newwithlength_b56c882b57805732 = function(arg0) {
2616
2737
  const ret = new Uint8Array(arg0 >>> 0);
2617
2738
  return addHeapObject(ret);
2618
2739
  };
2619
- imports.wbg.__wbg_subarray_58ad4efbb5bcb886 = function(arg0, arg1, arg2) {
2740
+ imports.wbg.__wbg_subarray_7526649b91a252a6 = function(arg0, arg1, arg2) {
2620
2741
  const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
2621
2742
  return addHeapObject(ret);
2622
2743
  };
@@ -2641,9 +2762,9 @@ function getImports() {
2641
2762
  function finalizeInit(instance, module) {
2642
2763
  wasm = instance.exports;
2643
2764
  init.__wbindgen_wasm_module = module;
2644
- cachedInt32Memory0 = new Int32Array();
2645
- cachedUint32Memory0 = new Uint32Array();
2646
- cachedUint8Memory0 = new Uint8Array();
2765
+ cachedInt32Memory0 = null;
2766
+ cachedUint32Memory0 = null;
2767
+ cachedUint8Memory0 = null;
2647
2768
 
2648
2769
 
2649
2770
  return wasm;
@@ -2651,7 +2772,7 @@ function finalizeInit(instance, module) {
2651
2772
 
2652
2773
  async function init(input) {
2653
2774
  if (typeof input === 'undefined') {
2654
- input = new URL(new URL('assets/rln_wasm_bg-4d82d6a4.wasm', import.meta.url).href, import.meta.url);
2775
+ input = new URL(new URL('assets/rln_wasm_bg-6f96f821.wasm', import.meta.url).href, import.meta.url);
2655
2776
  }
2656
2777
  const imports = getImports();
2657
2778
 
@@ -2689,123 +2810,114 @@ function writeUIntLE(buf, value, offset, byteLength, noAssert) {
2689
2810
  }
2690
2811
 
2691
2812
  const verificationKey = {
2692
- "protocol": "groth16",
2693
- "curve": "bn128",
2694
- "nPublic": 6,
2695
- "vk_alpha_1": [
2696
- "1805378556360488226980822394597799963030511477964155500103132920745199284516",
2697
- "11990395240534218699464972016456017378439762088320057798320175886595281336136",
2698
- "1"
2813
+ protocol: "groth16",
2814
+ curve: "bn128",
2815
+ nPublic: 6,
2816
+ vk_alpha_1: [
2817
+ "20124996762962216725442980738609010303800849578410091356605067053491763969391",
2818
+ "9118593021526896828671519912099489027245924097793322973632351264852174143923",
2819
+ "1",
2699
2820
  ],
2700
- "vk_beta_2": [
2821
+ vk_beta_2: [
2701
2822
  [
2702
- "11031529986141021025408838211017932346992429731488270384177563837022796743627",
2703
- "16042159910707312759082561183373181639420894978640710177581040523252926273854"
2823
+ "4693952934005375501364248788849686435240706020501681709396105298107971354382",
2824
+ "14346958885444710485362620645446987998958218205939139994511461437152241966681",
2704
2825
  ],
2705
2826
  [
2706
- "20112698439519222240302944148895052359035104222313380895334495118294612255131",
2707
- "19441583024670359810872018179190533814486480928824742448673677460151702019379"
2827
+ "16851772916911573982706166384196538392731905827088356034885868448550849804972",
2828
+ "823612331030938060799959717749043047845343400798220427319188951998582076532",
2708
2829
  ],
2709
- [
2710
- "1",
2711
- "0"
2712
- ]
2830
+ ["1", "0"],
2713
2831
  ],
2714
- "vk_gamma_2": [
2832
+ vk_gamma_2: [
2715
2833
  [
2716
2834
  "10857046999023057135944570762232829481370756359578518086990519993285655852781",
2717
- "11559732032986387107991004021392285783925812861821192530917403151452391805634"
2835
+ "11559732032986387107991004021392285783925812861821192530917403151452391805634",
2718
2836
  ],
2719
2837
  [
2720
2838
  "8495653923123431417604973247489272438418190587263600148770280649306958101930",
2721
- "4082367875863433681332203403145435568316851327593401208105741076214120093531"
2839
+ "4082367875863433681332203403145435568316851327593401208105741076214120093531",
2722
2840
  ],
2723
- [
2724
- "1",
2725
- "0"
2726
- ]
2841
+ ["1", "0"],
2727
2842
  ],
2728
- "vk_delta_2": [
2843
+ vk_delta_2: [
2729
2844
  [
2730
- "1948496782571164085469528023647105317580208688174386157591917599801657832035",
2731
- "20445814069256658101339037520922621162739470138213615104905368409238414511981"
2845
+ "8353516066399360694538747105302262515182301251524941126222712285088022964076",
2846
+ "9329524012539638256356482961742014315122377605267454801030953882967973561832",
2732
2847
  ],
2733
2848
  [
2734
- "10024680869920840984813249386422727863826862577760330492647062850849851925340",
2735
- "10512156247842686783409460795717734694774542185222602679117887145206209285142"
2849
+ "16805391589556134376869247619848130874761233086443465978238468412168162326401",
2850
+ "10111259694977636294287802909665108497237922060047080343914303287629927847739",
2736
2851
  ],
2737
- [
2738
- "1",
2739
- "0"
2740
- ]
2852
+ ["1", "0"],
2741
2853
  ],
2742
- "vk_alphabeta_12": [
2854
+ vk_alphabeta_12: [
2743
2855
  [
2744
2856
  [
2745
- "5151991366823434428398919091000210787450832786814248297320989361921939794156",
2746
- "15735191313289001022885148627913534790382722933676436876510746491415970766821"
2857
+ "12608968655665301215455851857466367636344427685631271961542642719683786103711",
2858
+ "9849575605876329747382930567422916152871921500826003490242628251047652318086",
2747
2859
  ],
2748
2860
  [
2749
- "3387907257437913904447588318761906430938415556102110876587455322225272831272",
2750
- "1998779853452712881084781956683721603875246565720647583735935725110674288056"
2861
+ "6322029441245076030714726551623552073612922718416871603535535085523083939021",
2862
+ "8700115492541474338049149013125102281865518624059015445617546140629435818912",
2751
2863
  ],
2752
2864
  [
2753
- "14280074182991498185075387990446437410077692353432005297922275464876153151820",
2754
- "17092408446352310039633488224969232803092763095456307462247653153107223117633"
2755
- ]
2865
+ "10674973475340072635573101639867487770811074181475255667220644196793546640210",
2866
+ "2926286967251299230490668407790788696102889214647256022788211245826267484824",
2867
+ ],
2756
2868
  ],
2757
2869
  [
2758
2870
  [
2759
- "4359046709531668109201634396816565829237358165496082832279660960675584351266",
2760
- "4511888308846208349307186938266411423935335853916317436093178288331845821336"
2871
+ "9660441540778523475944706619139394922744328902833875392144658911530830074820",
2872
+ "19548113127774514328631808547691096362144426239827206966690021428110281506546",
2761
2873
  ],
2762
2874
  [
2763
- "11429499807090785857812316277335883295048773373068683863667725283965356423273",
2764
- "16232274853200678548795010078253506586114563833318973594428907292096178657392"
2875
+ "1870837942477655969123169532603615788122896469891695773961478956740992497097",
2876
+ "12536105729661705698805725105036536744930776470051238187456307227425796690780",
2765
2877
  ],
2766
2878
  [
2767
- "18068999605870933925311275504102553573815570223888590384919752303726860800970",
2768
- "17309569111965782732372130116757295842160193489132771344011460471298173784984"
2769
- ]
2770
- ]
2879
+ "21811903352654147452884857281720047789720483752548991551595462057142824037334",
2880
+ "19021616763967199151052893283384285352200445499680068407023236283004353578353",
2881
+ ],
2882
+ ],
2771
2883
  ],
2772
- "IC": [
2884
+ IC: [
2773
2885
  [
2774
- "18693301901828818437917730940595978397160482710354161265484535387752523310572",
2775
- "17985273354976640088538673802000794244421192643855111089693820179790551470769",
2776
- "1"
2886
+ "11992897507809711711025355300535923222599547639134311050809253678876341466909",
2887
+ "17181525095924075896332561978747020491074338784673526378866503154966799128110",
2888
+ "1",
2777
2889
  ],
2778
2890
  [
2779
- "21164641723988537620541455173278629777250883365474191521194244273980931825942",
2780
- "998385854410718613441067082771678946155853656328717326195057262123686425518",
2781
- "1"
2891
+ "17018665030246167677911144513385572506766200776123272044534328594850561667818",
2892
+ "18601114175490465275436712413925513066546725461375425769709566180981674884464",
2893
+ "1",
2782
2894
  ],
2783
2895
  [
2784
- "21666968581672145768705229094968410656430989593283335488162701230986314747515",
2785
- "17996457608540683483506630273632100555125353447506062045735279661096094677264",
2786
- "1"
2896
+ "18799470100699658367834559797874857804183288553462108031963980039244731716542",
2897
+ "13064227487174191981628537974951887429496059857753101852163607049188825592007",
2898
+ "1",
2787
2899
  ],
2788
2900
  [
2789
- "20137761979695192602424300886442379728165712610493092740175904438282083668117",
2790
- "19184814924890679891263780109959113289320127263583260218200636509492157834679",
2791
- "1"
2901
+ "17432501889058124609368103715904104425610382063762621017593209214189134571156",
2902
+ "13406815149699834788256141097399354592751313348962590382887503595131085938635",
2903
+ "1",
2792
2904
  ],
2793
2905
  [
2794
- "10943171273393803842589314082509655332154393332394322726077270895078286354146",
2795
- "10872472035685319847811233167729172672344935625121511932198535224727331126439",
2796
- "1"
2906
+ "10320964835612716439094703312987075811498239445882526576970512041988148264481",
2907
+ "9024164961646353611176283204118089412001502110138072989569118393359029324867",
2908
+ "1",
2797
2909
  ],
2798
2910
  [
2799
- "13049169779481227658517545034348883391527506091990880778783387628208561946597",
2800
- "10083689369261379027228809473568899816311684698866922944902456565434209079955",
2801
- "1"
2911
+ "718355081067365548229685160476620267257521491773976402837645005858953849298",
2912
+ "14635482993933988261008156660773180150752190597753512086153001683711587601974",
2913
+ "1",
2802
2914
  ],
2803
2915
  [
2804
- "19633516378466409167014413361365552102431118630694133723053441455184566611083",
2805
- "8059525100726933978719058611146131904598011633549012007359165766216730722269",
2806
- "1"
2807
- ]
2808
- ]
2916
+ "11777720285956632126519898515392071627539405001940313098390150593689568177535",
2917
+ "8483603647274280691250972408211651407952870456587066148445913156086740744515",
2918
+ "1",
2919
+ ],
2920
+ ],
2809
2921
  };
2810
2922
 
2811
2923
  // File generated with https://github.com/iden3/circom
@@ -3128,12 +3240,12 @@ function buildBigIntFromUint8Array(array) {
3128
3240
  const stringEncoder = new TextEncoder();
3129
3241
  const DEPTH = 20;
3130
3242
  async function loadWitnessCalculator() {
3131
- const url = new URL(new URL('assets/rln-fb4d7b4b.wasm', import.meta.url).href, import.meta.url);
3243
+ const url = new URL(new URL('assets/rln-6ded2896.wasm', import.meta.url).href, import.meta.url);
3132
3244
  const response = await fetch(url);
3133
3245
  return await builder(new Uint8Array(await response.arrayBuffer()), false);
3134
3246
  }
3135
3247
  async function loadZkey() {
3136
- const url = new URL(new URL('assets/rln_final-a641c06e.zkey', import.meta.url).href, import.meta.url);
3248
+ const url = new URL(new URL('assets/rln_final-8b299152.zkey', import.meta.url).href, import.meta.url);
3137
3249
  const response = await fetch(url);
3138
3250
  return new Uint8Array(await response.arrayBuffer());
3139
3251
  }
@@ -3150,17 +3262,21 @@ async function create$1() {
3150
3262
  const zkRLN = newRLN(DEPTH, zkey, vkey);
3151
3263
  return new RLNInstance(zkRLN, witnessCalculator);
3152
3264
  }
3153
- class MembershipKey {
3154
- constructor(IDKey, IDCommitment, IDCommitmentBigInt) {
3155
- this.IDKey = IDKey;
3265
+ class IdentityCredential {
3266
+ constructor(IDTrapdoor, IDNullifier, IDSecretHash, IDCommitment, IDCommitmentBigInt) {
3267
+ this.IDTrapdoor = IDTrapdoor;
3268
+ this.IDNullifier = IDNullifier;
3269
+ this.IDSecretHash = IDSecretHash;
3156
3270
  this.IDCommitment = IDCommitment;
3157
3271
  this.IDCommitmentBigInt = IDCommitmentBigInt;
3158
3272
  }
3159
3273
  static fromBytes(memKeys) {
3160
- const idKey = memKeys.subarray(0, 32);
3161
- const idCommitment = memKeys.subarray(32);
3274
+ const idTrapdoor = memKeys.subarray(0, 32);
3275
+ const idNullifier = memKeys.subarray(32, 64);
3276
+ const idSecretHash = memKeys.subarray(64, 96);
3277
+ const idCommitment = memKeys.subarray(96);
3162
3278
  const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment);
3163
- return new MembershipKey(idKey, idCommitment, idCommitmentBigInt);
3279
+ return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
3164
3280
  }
3165
3281
  }
3166
3282
  const proofOffset = 128;
@@ -3170,6 +3286,14 @@ const shareXOffset = epochOffset + 32;
3170
3286
  const shareYOffset = shareXOffset + 32;
3171
3287
  const nullifierOffset = shareYOffset + 32;
3172
3288
  const rlnIdentifierOffset = nullifierOffset + 32;
3289
+ class ProofMetadata {
3290
+ constructor(nullifier, shareX, shareY, externalNullifier) {
3291
+ this.nullifier = nullifier;
3292
+ this.shareX = shareX;
3293
+ this.shareY = shareY;
3294
+ this.externalNullifier = externalNullifier;
3295
+ }
3296
+ }
3173
3297
  class Proof {
3174
3298
  constructor(proofBytes) {
3175
3299
  if (proofBytes.length < rlnIdentifierOffset)
@@ -3183,27 +3307,52 @@ class Proof {
3183
3307
  this.nullifier = proofBytes.subarray(shareYOffset, nullifierOffset);
3184
3308
  this.rlnIdentifier = proofBytes.subarray(nullifierOffset, rlnIdentifierOffset);
3185
3309
  }
3310
+ extractMetadata() {
3311
+ const externalNullifier = poseidonHash(this.epoch, this.rlnIdentifier);
3312
+ return new ProofMetadata(this.nullifier, this.shareX, this.shareY, externalNullifier);
3313
+ }
3186
3314
  }
3187
3315
  function proofToBytes(p) {
3188
3316
  return concatenate(p.proof, p.merkleRoot, p.epoch, p.shareX, p.shareY, p.nullifier, p.rlnIdentifier);
3189
3317
  }
3318
+ function poseidonHash(...input) {
3319
+ const inputLen = writeUIntLE(new Uint8Array(8), input.length, 0, 8);
3320
+ const lenPrefixedData = concatenate(inputLen, ...input);
3321
+ return poseidonHash$1(lenPrefixedData);
3322
+ }
3323
+ function sha256$2(input) {
3324
+ const inputLen = writeUIntLE(new Uint8Array(8), input.length, 0, 8);
3325
+ const lenPrefixedData = concatenate(inputLen, input);
3326
+ return hash$1(lenPrefixedData);
3327
+ }
3190
3328
  class RLNInstance {
3191
3329
  constructor(zkRLN, witnessCalculator) {
3192
3330
  this.zkRLN = zkRLN;
3193
3331
  this.witnessCalculator = witnessCalculator;
3194
3332
  }
3195
- generateMembershipKey() {
3196
- const memKeys = generateMembershipKey(this.zkRLN);
3197
- return MembershipKey.fromBytes(memKeys);
3333
+ generateIdentityCredentials() {
3334
+ const memKeys = generateExtendedMembershipKey(this.zkRLN); // TODO: rename this function in zerokit rln-wasm
3335
+ return IdentityCredential.fromBytes(memKeys);
3198
3336
  }
3199
- generateSeededMembershipKey(seed) {
3337
+ generateSeededIdentityCredential(seed) {
3200
3338
  const seedBytes = stringEncoder.encode(seed);
3201
- const memKeys = generateSeededMembershipKey(this.zkRLN, seedBytes);
3202
- return MembershipKey.fromBytes(memKeys);
3339
+ // TODO: rename this function in zerokit rln-wasm
3340
+ const memKeys = generateSeededExtendedMembershipKey(this.zkRLN, seedBytes);
3341
+ return IdentityCredential.fromBytes(memKeys);
3203
3342
  }
3204
3343
  insertMember(idCommitment) {
3205
3344
  insertMember(this.zkRLN, idCommitment);
3206
3345
  }
3346
+ insertMembers(index, ...idCommitments) {
3347
+ // serializes a seq of IDCommitments to a byte seq
3348
+ // the order of serialization is |id_commitment_len<8>|id_commitment<var>|
3349
+ const idCommitmentLen = writeUIntLE(new Uint8Array(8), idCommitments.length, 0, 8);
3350
+ const idCommitmentBytes = concatenate(idCommitmentLen, ...idCommitments);
3351
+ setLeavesFrom(this.zkRLN, index, idCommitmentBytes);
3352
+ }
3353
+ deleteMember(index) {
3354
+ deleteLeaf(this.zkRLN, index);
3355
+ }
3207
3356
  getMerkleRoot() {
3208
3357
  return getRoot(this.zkRLN);
3209
3358
  }
@@ -3215,7 +3364,7 @@ class RLNInstance {
3215
3364
  // [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> ]
3216
3365
  return concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg);
3217
3366
  }
3218
- async generateRLNProof(msg, index, epoch, idKey) {
3367
+ async generateRLNProof(msg, index, epoch, idSecretHash) {
3219
3368
  if (epoch == undefined) {
3220
3369
  epoch = epochIntToBytes(dateToEpoch(new Date()));
3221
3370
  }
@@ -3224,11 +3373,11 @@ class RLNInstance {
3224
3373
  }
3225
3374
  if (epoch.length != 32)
3226
3375
  throw "invalid epoch";
3227
- if (idKey.length != 32)
3228
- throw "invalid id key";
3376
+ if (idSecretHash.length != 32)
3377
+ throw "invalid id secret hash";
3229
3378
  if (index < 0)
3230
3379
  throw "index must be >= 0";
3231
- const serialized_msg = this.serializeMessage(msg, index, epoch, idKey);
3380
+ const serialized_msg = this.serializeMessage(msg, index, epoch, idSecretHash);
3232
3381
  const rlnWitness = getSerializedRLNWitness(this.zkRLN, serialized_msg);
3233
3382
  const inputs = RLNWitnessToJson(this.zkRLN, rlnWitness);
3234
3383
  const calculatedWitness = await this.witnessCalculator.calculateWitness(inputs, false); // no sanity check being used in zerokit
@@ -3247,7 +3396,7 @@ class RLNInstance {
3247
3396
  const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
3248
3397
  return verifyRLNProof(this.zkRLN, concatenate(pBytes, msgLen, msg));
3249
3398
  }
3250
- verifyWithRoots(proof, msg) {
3399
+ verifyWithRoots(proof, msg, ...roots) {
3251
3400
  let pBytes;
3252
3401
  if (proof instanceof Uint8Array) {
3253
3402
  pBytes = proof;
@@ -3257,9 +3406,8 @@ class RLNInstance {
3257
3406
  }
3258
3407
  // calculate message length
3259
3408
  const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
3260
- // obtain root
3261
- const root = getRoot(this.zkRLN);
3262
- return verifyWithRoots(this.zkRLN, concatenate(pBytes, msgLen, msg), root);
3409
+ const rootsBytes = concatenate(...roots);
3410
+ return verifyWithRoots(this.zkRLN, concatenate(pBytes, msgLen, msg), rootsBytes);
3263
3411
  }
3264
3412
  verifyWithNoRoot(proof, msg) {
3265
3413
  let pBytes;
@@ -3278,9 +3426,12 @@ class RLNInstance {
3278
3426
  var rln = /*#__PURE__*/Object.freeze({
3279
3427
  __proto__: null,
3280
3428
  create: create$1,
3281
- MembershipKey: MembershipKey,
3429
+ IdentityCredential: IdentityCredential,
3430
+ ProofMetadata: ProofMetadata,
3282
3431
  Proof: Proof,
3283
3432
  proofToBytes: proofToBytes,
3433
+ poseidonHash: poseidonHash,
3434
+ sha256: sha256$2,
3284
3435
  RLNInstance: RLNInstance
3285
3436
  });
3286
3437
 
@@ -27014,8 +27165,11 @@ class RLNContract {
27014
27165
  get members() {
27015
27166
  return this._members;
27016
27167
  }
27017
- async fetchMembers(rlnInstance, fromBlock) {
27018
- const registeredMemberEvents = await this.contract.queryFilter(this.membersFilter, fromBlock);
27168
+ async fetchMembers(rlnInstance, options = {}) {
27169
+ const registeredMemberEvents = await queryFilter(this.contract, {
27170
+ ...options,
27171
+ membersFilter: this.membersFilter,
27172
+ });
27019
27173
  for (const event of registeredMemberEvents) {
27020
27174
  this.addMemberFromEvent(rlnInstance, event);
27021
27175
  }
@@ -27033,16 +27187,141 @@ class RLNContract {
27033
27187
  const idCommitment = zeroPad(arrayify(pubkey), 32);
27034
27188
  rlnInstance.insertMember(idCommitment);
27035
27189
  }
27036
- async registerMember(rlnInstance, signature) {
27037
- const membershipKey = await rlnInstance.generateSeededMembershipKey(signature);
27190
+ async registerWithSignature(rlnInstance, signature) {
27191
+ const identityCredential = await rlnInstance.generateSeededIdentityCredential(signature);
27192
+ return this.registerWithKey(identityCredential);
27193
+ }
27194
+ async registerWithKey(credential) {
27038
27195
  const depositValue = await this.contract.MEMBERSHIP_DEPOSIT();
27039
- const txRegisterResponse = await this.contract.register(membershipKey.IDCommitmentBigInt, {
27196
+ const txRegisterResponse = await this.contract.register(credential.IDCommitmentBigInt, {
27040
27197
  value: depositValue,
27041
27198
  });
27042
27199
  const txRegisterReceipt = await txRegisterResponse.wait();
27043
27200
  return txRegisterReceipt?.events?.[0];
27044
27201
  }
27045
27202
  }
27203
+ // these value should be tested on other networks
27204
+ const FETCH_CHUNK = 5;
27205
+ const BLOCK_RANGE = 3000;
27206
+ async function queryFilter(contract, options) {
27207
+ const { fromBlock, membersFilter, fetchRange = BLOCK_RANGE, fetchChunks = FETCH_CHUNK, } = options;
27208
+ if (!fromBlock) {
27209
+ return contract.queryFilter(membersFilter);
27210
+ }
27211
+ if (!contract.signer.provider) {
27212
+ throw Error("No provider found on the contract's signer.");
27213
+ }
27214
+ const toBlock = await contract.signer.provider.getBlockNumber();
27215
+ if (toBlock - fromBlock < fetchRange) {
27216
+ return contract.queryFilter(membersFilter);
27217
+ }
27218
+ const events = [];
27219
+ const chunks = splitToChunks(fromBlock, toBlock, fetchRange);
27220
+ for (const portion of takeN(chunks, fetchChunks)) {
27221
+ const promises = portion.map(([left, right]) => ignoreErrors(contract.queryFilter(membersFilter, left, right), []));
27222
+ const fetchedEvents = await Promise.all(promises);
27223
+ events.push(fetchedEvents.flatMap((v) => v));
27224
+ }
27225
+ return events.flatMap((v) => v);
27226
+ }
27227
+ function splitToChunks(from, to, step) {
27228
+ const chunks = [];
27229
+ let left = from;
27230
+ while (left < to) {
27231
+ const right = left + step < to ? left + step : to;
27232
+ chunks.push([left, right]);
27233
+ left = right;
27234
+ }
27235
+ return chunks;
27236
+ }
27237
+ function* takeN(array, size) {
27238
+ let start = 0;
27239
+ let skip = size;
27240
+ while (skip < array.length) {
27241
+ const portion = array.slice(start, skip);
27242
+ yield portion;
27243
+ start = skip;
27244
+ skip += size;
27245
+ }
27246
+ }
27247
+ function ignoreErrors(promise, defaultValue) {
27248
+ return promise.catch((err) => {
27249
+ console.error(`Ignoring an error during query: ${err?.message}`);
27250
+ return defaultValue;
27251
+ });
27252
+ }
27253
+
27254
+ class RootPerBlock {
27255
+ constructor(root, blockNumber) {
27256
+ this.root = root;
27257
+ this.blockNumber = blockNumber;
27258
+ }
27259
+ }
27260
+ const maxBufferSize = 20;
27261
+ class MerkleRootTracker {
27262
+ constructor(acceptableRootWindowSize, initialRoot) {
27263
+ this.acceptableRootWindowSize = acceptableRootWindowSize;
27264
+ this.validMerkleRoots = new Array();
27265
+ this.merkleRootBuffer = new Array();
27266
+ this.pushRoot(0, initialRoot);
27267
+ }
27268
+ backFill(fromBlockNumber) {
27269
+ if (this.validMerkleRoots.length == 0)
27270
+ return;
27271
+ let numBlocks = 0;
27272
+ for (let i = this.validMerkleRoots.length - 1; i >= 0; i--) {
27273
+ if (this.validMerkleRoots[i].blockNumber >= fromBlockNumber) {
27274
+ numBlocks++;
27275
+ }
27276
+ }
27277
+ if (numBlocks == 0)
27278
+ return;
27279
+ const olderBlock = fromBlockNumber < this.validMerkleRoots[0].blockNumber;
27280
+ // Remove last roots
27281
+ let rootsToPop = numBlocks;
27282
+ if (this.validMerkleRoots.length < rootsToPop) {
27283
+ rootsToPop = this.validMerkleRoots.length;
27284
+ }
27285
+ this.validMerkleRoots = this.validMerkleRoots.slice(0, this.validMerkleRoots.length - rootsToPop);
27286
+ if (this.merkleRootBuffer.length == 0)
27287
+ return;
27288
+ if (olderBlock) {
27289
+ const idx = this.merkleRootBuffer.findIndex((x) => x.blockNumber == fromBlockNumber);
27290
+ if (idx > -1) {
27291
+ this.merkleRootBuffer = this.merkleRootBuffer.slice(0, idx);
27292
+ }
27293
+ }
27294
+ // Backfill the tree's acceptable roots
27295
+ let rootsToRestore = this.acceptableRootWindowSize - this.validMerkleRoots.length;
27296
+ if (this.merkleRootBuffer.length < rootsToRestore) {
27297
+ rootsToRestore = this.merkleRootBuffer.length;
27298
+ }
27299
+ for (let i = 0; i < rootsToRestore; i++) {
27300
+ const x = this.merkleRootBuffer.pop();
27301
+ if (x)
27302
+ this.validMerkleRoots.unshift(x);
27303
+ }
27304
+ }
27305
+ pushRoot(blockNumber, root) {
27306
+ this.validMerkleRoots.push(new RootPerBlock(root, blockNumber));
27307
+ // Maintain valid merkle root window
27308
+ if (this.validMerkleRoots.length > this.acceptableRootWindowSize) {
27309
+ const x = this.validMerkleRoots.shift();
27310
+ if (x)
27311
+ this.merkleRootBuffer.push(x);
27312
+ }
27313
+ // Maintain merkle root buffer
27314
+ if (this.merkleRootBuffer.length > maxBufferSize) {
27315
+ this.merkleRootBuffer.shift();
27316
+ }
27317
+ }
27318
+ roots() {
27319
+ return this.validMerkleRoots.map((x) => x.root);
27320
+ }
27321
+ buffer() {
27322
+ return this.merkleRootBuffer.map((x) => x.root);
27323
+ }
27324
+ }
27046
27325
 
27047
27326
  // reexport the create function, dynamically imported from rln.ts
27048
27327
  async function create() {
@@ -27053,4 +27332,4 @@ async function create() {
27053
27332
  return await rlnModule.create();
27054
27333
  }
27055
27334
 
27056
- export { GOERLI_CONTRACT, MembershipKey, Proof, RLNContract, RLNDecoder, RLNEncoder, RLNInstance, RLN_ABI, create };
27335
+ export { GOERLI_CONTRACT, IdentityCredential, MerkleRootTracker, Proof, ProofMetadata, RLNContract, RLNDecoder, RLNEncoder, RLNInstance, RLN_ABI, create };