@waku/rln 0.0.1 → 0.0.2

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
@@ -3,7 +3,7 @@ async function create() {
3
3
  // A dependency graph that contains any wasm must all be imported
4
4
  // asynchronously. This file does the single async import, so
5
5
  // that no one else needs to worry about it again.
6
- const rlnModule = await import('./rln-f87f6dbe.js');
6
+ const rlnModule = await import('./rln-0e12a076.js');
7
7
  return await rlnModule.create();
8
8
  }
9
9
 
@@ -516,10 +516,62 @@ class MembershipKey {
516
516
  this.IDCommitment = memKeys.subarray(32);
517
517
  }
518
518
  }
519
+ // Adapted from https://github.com/feross/buffer
520
+ function checkInt(buf, value, offset, ext, max, min) {
521
+ if (value > max || value < min)
522
+ throw new RangeError('"value" argument is out of bounds');
523
+ if (offset + ext > buf.length)
524
+ throw new RangeError("Index out of range");
525
+ }
526
+ const writeUIntLE = function writeUIntLE(buf, value, offset, byteLength, noAssert) {
527
+ value = +value;
528
+ offset = offset >>> 0;
529
+ byteLength = byteLength >>> 0;
530
+ if (!noAssert) {
531
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
532
+ checkInt(buf, value, offset, byteLength, maxBytes, 0);
533
+ }
534
+ let mul = 1;
535
+ let i = 0;
536
+ buf[offset] = value & 0xff;
537
+ while (++i < byteLength && (mul *= 0x100)) {
538
+ buf[offset + i] = (value / mul) & 0xff;
539
+ }
540
+ return buf;
541
+ };
542
+ const DefaultEpochUnitSeconds = 10; // the rln-relay epoch length in seconds
543
+ function toEpoch(timestamp, epochUnitSeconds = DefaultEpochUnitSeconds) {
544
+ const unix = Math.floor(timestamp.getTime() / 1000 / epochUnitSeconds);
545
+ return writeUIntLE(new Uint8Array(32), unix, 0, 8);
546
+ }
547
+ const proofOffset = 128;
548
+ const rootOffset = proofOffset + 32;
549
+ const epochOffset = rootOffset + 32;
550
+ const shareXOffset = epochOffset + 32;
551
+ const shareYOffset = shareXOffset + 32;
552
+ const nullifierOffset = shareYOffset + 32;
553
+ const rlnIdentifierOffset = nullifierOffset + 32;
554
+ class RateLimitProof {
555
+ constructor(proofBytes) {
556
+ if (proofBytes.length < rlnIdentifierOffset)
557
+ throw "invalid proof";
558
+ // parse the proof as proof<128> | share_y<32> | nullifier<32> | root<32> | epoch<32> | share_x<32> | rln_identifier<32>
559
+ this.proof = proofBytes.subarray(0, proofOffset);
560
+ this.merkleRoot = proofBytes.subarray(proofOffset, rootOffset);
561
+ this.epoch = proofBytes.subarray(rootOffset, epochOffset);
562
+ this.shareX = proofBytes.subarray(epochOffset, shareXOffset);
563
+ this.shareY = proofBytes.subarray(shareXOffset, shareYOffset);
564
+ this.nullifier = proofBytes.subarray(shareYOffset, nullifierOffset);
565
+ this.rlnIdentifier = proofBytes.subarray(nullifierOffset, rlnIdentifierOffset);
566
+ }
567
+ toBytes() {
568
+ return concatenate(this.proof, this.merkleRoot, this.epoch, this.shareX, this.shareY, this.nullifier, this.rlnIdentifier);
569
+ }
570
+ }
519
571
  class RLNInstance {
520
- constructor(zkRLN, wc) {
572
+ constructor(zkRLN, witnessCalculator) {
521
573
  this.zkRLN = zkRLN;
522
- this.witnessCalculator = wc;
574
+ this.witnessCalculator = witnessCalculator;
523
575
  }
524
576
  generateMembershipKey() {
525
577
  const memKeys = generateMembershipKey(this.zkRLN);
@@ -529,20 +581,20 @@ class RLNInstance {
529
581
  insertMember(this.zkRLN, idCommitment);
530
582
  }
531
583
  serializeMessage(uint8Msg, memIndex, epoch, idKey) {
532
- if (epoch.length != 32)
533
- throw "invalid epoch";
534
- if (idKey.length != 32)
535
- throw "invalid id key";
536
584
  // calculate message length
537
- const msgLen = Buffer.allocUnsafe(8);
538
- msgLen.writeUIntLE(uint8Msg.length, 0, 8);
585
+ const msgLen = writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
539
586
  // Converting index to LE bytes
540
- const memIndexBytes = Buffer.allocUnsafe(8);
541
- memIndexBytes.writeUIntLE(memIndex, 0, 8);
587
+ const memIndexBytes = writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
542
588
  // [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> ]
543
589
  return concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg);
544
590
  }
545
591
  async generateProof(msg, index, epoch, idKey) {
592
+ if (epoch == undefined) {
593
+ epoch = toEpoch(new Date());
594
+ }
595
+ else if (epoch instanceof Date) {
596
+ epoch = toEpoch(epoch);
597
+ }
546
598
  if (epoch.length != 32)
547
599
  throw "invalid epoch";
548
600
  if (idKey.length != 32)
@@ -553,11 +605,15 @@ class RLNInstance {
553
605
  const rlnWitness = getSerializedRLNWitness(this.zkRLN, serialized_msg);
554
606
  const inputs = RLNWitnessToJson(this.zkRLN, rlnWitness);
555
607
  const calculatedWitness = await this.witnessCalculator.calculateWitness(inputs, false); // no sanity check being used in zerokit
556
- return generate_rln_proof_with_witness(this.zkRLN, calculatedWitness, rlnWitness);
608
+ const proofBytes = generate_rln_proof_with_witness(this.zkRLN, calculatedWitness, rlnWitness);
609
+ return new RateLimitProof(proofBytes);
557
610
  }
558
611
  verifyProof(proof) {
612
+ if (proof instanceof RateLimitProof) {
613
+ proof = proof.toBytes();
614
+ }
559
615
  return verifyProof(this.zkRLN, proof);
560
616
  }
561
617
  }
562
618
 
563
- export { MembershipKey, RLNInstance, create };
619
+ export { MembershipKey, RLNInstance, RateLimitProof, create, toEpoch };
package/dist/.tsbuildinfo CHANGED
@@ -1 +1 @@
1
- {"program":{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/typescript/lib/lib.es2020.date.d.ts","../node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/typescript/lib/lib.es2020.number.d.ts","../node_modules/typescript/lib/lib.esnext.intl.d.ts","../src/resources.ts","../src/witness_calculator.d.ts","../src/zerokit/rln_wasm.d.ts","../src/rln.ts","../src/index.ts","../src/witness_calculator.js","../src/zerokit/rln_wasm_bg.wasm.d.ts","../src/zerokit/rln_wasm_bg.js","../src/zerokit/rln_wasm.js","../node_modules/@types/node/assert.d.ts","../node_modules/@types/node/assert/strict.d.ts","../node_modules/@types/node/globals.d.ts","../node_modules/@types/node/async_hooks.d.ts","../node_modules/@types/node/buffer.d.ts","../node_modules/@types/node/child_process.d.ts","../node_modules/@types/node/cluster.d.ts","../node_modules/@types/node/console.d.ts","../node_modules/@types/node/constants.d.ts","../node_modules/@types/node/crypto.d.ts","../node_modules/@types/node/dgram.d.ts","../node_modules/@types/node/diagnostics_channel.d.ts","../node_modules/@types/node/dns.d.ts","../node_modules/@types/node/dns/promises.d.ts","../node_modules/@types/node/domain.d.ts","../node_modules/@types/node/events.d.ts","../node_modules/@types/node/fs.d.ts","../node_modules/@types/node/fs/promises.d.ts","../node_modules/@types/node/http.d.ts","../node_modules/@types/node/http2.d.ts","../node_modules/@types/node/https.d.ts","../node_modules/@types/node/inspector.d.ts","../node_modules/@types/node/module.d.ts","../node_modules/@types/node/net.d.ts","../node_modules/@types/node/os.d.ts","../node_modules/@types/node/path.d.ts","../node_modules/@types/node/perf_hooks.d.ts","../node_modules/@types/node/process.d.ts","../node_modules/@types/node/punycode.d.ts","../node_modules/@types/node/querystring.d.ts","../node_modules/@types/node/readline.d.ts","../node_modules/@types/node/repl.d.ts","../node_modules/@types/node/stream.d.ts","../node_modules/@types/node/stream/promises.d.ts","../node_modules/@types/node/stream/consumers.d.ts","../node_modules/@types/node/stream/web.d.ts","../node_modules/@types/node/string_decoder.d.ts","../node_modules/@types/node/timers.d.ts","../node_modules/@types/node/timers/promises.d.ts","../node_modules/@types/node/tls.d.ts","../node_modules/@types/node/trace_events.d.ts","../node_modules/@types/node/tty.d.ts","../node_modules/@types/node/url.d.ts","../node_modules/@types/node/util.d.ts","../node_modules/@types/node/v8.d.ts","../node_modules/@types/node/vm.d.ts","../node_modules/@types/node/wasi.d.ts","../node_modules/@types/node/worker_threads.d.ts","../node_modules/@types/node/zlib.d.ts","../node_modules/@types/node/globals.global.d.ts","../node_modules/@types/node/index.d.ts","../node_modules/@types/mocha/index.d.ts"],"fileInfos":[{"version":"f20c05dbfe50a208301d2a1da37b9931bce0466eb5a1f4fe240971b4ecc82b67","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","1fc5ab7a764205c68fa10d381b08417795fc73111d6dd16b5b1ed36badb743d9",{"version":"9b087de7268e4efc5f215347a62656663933d63c0b1d7b624913240367b999ea","affectsGlobalScope":true},{"version":"adb996790133eb33b33aadb9c09f15c2c575e71fb57a62de8bf74dbf59ec7dfb","affectsGlobalScope":true},{"version":"8cc8c5a3bac513368b0157f3d8b31cfdcfe78b56d3724f30f80ed9715e404af8","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true},{"version":"0d5f52b3174bee6edb81260ebcd792692c32c81fd55499d69531496f3f2b25e7","affectsGlobalScope":true},{"version":"55f400eec64d17e888e278f4def2f254b41b89515d3b88ad75d5e05f019daddd","affectsGlobalScope":true},{"version":"181f1784c6c10b751631b24ce60c7f78b20665db4550b335be179217bacc0d5f","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"81cac4cbc92c0c839c70f8ffb94eb61e2d32dc1c3cf6d95844ca099463cf37ea","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"09aa50414b80c023553090e2f53827f007a301bc34b0495bfb2c3c08ab9ad1eb","affectsGlobalScope":true},{"version":"d7f680a43f8cd12a6b6122c07c54ba40952b0c8aa140dcfcf32eb9e6cb028596","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"775d9c9fd150d5de79e0450f35bc8b8f94ae64e3eb5da12725ff2a649dccc777","affectsGlobalScope":true},{"version":"b248e32ca52e8f5571390a4142558ae4f203ae2f94d5bac38a3084d529ef4e58","affectsGlobalScope":true},{"version":"52d1bb7ab7a3306fd0375c8bff560feed26ed676a5b0457fa8027b563aecb9a4","affectsGlobalScope":true},{"version":"832ec1c9d3001b9b6dc75dcb536b30ad2fc278af20e8bd2a951348f71b6ce1ff","signature":"528a4c000f46e7b8d04033eae2c99107a14a4faeae58d8f172e730157c4604d0"},"18e63e4f6a513425aaf40a04e557d486a7b3bb6304807efea8493af640a157ce","2f7f8d917dc2490fe70c038876b6f222a431e5938a3fbf8b5a48c7f7c5e67dbe",{"version":"d81bc94856ef34ec2e2bd065c7d292f24027a5b97881a77ad879cf92ce2c1487","signature":"6388836354648d6b472e3a8d8f394239ea5d1782b834a3145eb9132baff6358c"},{"version":"15ead200210c49472e354b654221f71c7d72003429be54a8561dde647345d36f","signature":"cdeb995118bcecf124ab788533cf95d11df2e75e9b67e640b4d2e28bf376347f"},{"version":"cb732dfea79ca2a9a5fd4ed240df67d6c47fd5b66fe188c645367efd1762ed24","signature":"39257e47f71a52d198342c47d3a6b35338a3c8618e4335b56530f2cb3b0dc511"},"58a2096632137825c18cd96c4f120a55582b8e79affa01d388f3c844b987be57",{"version":"ff682c0a5ea90d89c05d1b8c94970057a0fc56c99f6c924f5312d799a446f456","signature":"7ec505c3a1feb7705fc8bf5921617c8dd2759a1d385787190621456f82d32d4c"},{"version":"00e10803e106181f7ca7b3e9ff55ce919200e1937bf949a6a5db59c27cba9308","signature":"dba888cc0cb4ae7a8e32b8df4c6d693d8029d93f92b7fbfb9d1c645279f465ef"},"0cba3a5d7b81356222594442753cf90dd2892e5ccfe1d262aaca6896ba6c1380","a69c09dbea52352f479d3e7ac949fde3d17b195abe90b045d619f747b38d6d1a",{"version":"77f0b5c6a193a699c9f7d7fb0578e64e562d271afa740783665d2a827104a873","affectsGlobalScope":true},"e5979905796fe2740d85fbaf4f11f42b7ee1851421afe750823220813421b1af",{"version":"fcdcb42da18dd98dc286b1876dd425791772036012ae61263c011a76b13a190f","affectsGlobalScope":true},"1dab5ab6bcf11de47ab9db295df8c4f1d92ffa750e8f095e88c71ce4c3299628","f71f46ccd5a90566f0a37b25b23bc4684381ab2180bdf6733f4e6624474e1894",{"version":"54e65985a3ee3cec182e6a555e20974ea936fc8b8d1738c14e8ed8a42bd921d4","affectsGlobalScope":true},"82408ed3e959ddc60d3e9904481b5a8dc16469928257af22a3f7d1a3bc7fd8c4","5b30f550565fd0a7524282c81c27fe8534099e2cd26170ca80852308f07ae68d","34e5de87d983bc6aefef8b17658556e3157003e8d9555d3cb098c6bef0b5fbc8","d97cd8a4a42f557fc62271369ed0461c8e50d47b7f9c8ad0b5462f53306f6060","f27371653aded82b2b160f7a7033fb4a5b1534b6f6081ef7be1468f0f15327d3","c762cd6754b13a461c54b59d0ae0ab7aeef3c292c6cf889873f786ee4d8e75c9","f4ea7d5df644785bd9fbf419930cbaec118f0d8b4160037d2339b8e23c059e79",{"version":"bfea28e6162ed21a0aeed181b623dcf250aa79abf49e24a6b7e012655af36d81","affectsGlobalScope":true},"b8aca9d0c81abb02bec9b7621983ae65bde71da6727580070602bd2500a9ce2a","ae97e20f2e10dbeec193d6a2f9cd9a367a1e293e7d6b33b68bacea166afd7792","10d4796a130577d57003a77b95d8723530bbec84718e364aa2129fa8ffba0378","063f53ff674228c190efa19dd9448bcbd540acdbb48a928f4cf3a1b9f9478e43","bf73c576885408d4a176f44a9035d798827cc5020d58284cb18d7573430d9022","7ae078ca42a670445ae0c6a97c029cb83d143d62abd1730efb33f68f0b2c0e82",{"version":"e8b18c6385ff784228a6f369694fcf1a6b475355ba89090a88de13587a9391d5","affectsGlobalScope":true},"287b21dc1d1b9701c92e15e7dd673dfe6044b15812956377adffb6f08825b1bc","12eea70b5e11e924bb0543aea5eadc16ced318aa26001b453b0d561c2fd0bd1e","08777cd9318d294646b121838574e1dd7acbb22c21a03df84e1f2c87b1ad47f2","08a90bcdc717df3d50a2ce178d966a8c353fd23e5c392fd3594a6e39d9bb6304",{"version":"4cd4cff679c9b3d9239fd7bf70293ca4594583767526916af8e5d5a47d0219c7","affectsGlobalScope":true},"2a12d2da5ac4c4979401a3f6eaafa874747a37c365e4bc18aa2b171ae134d21b","002b837927b53f3714308ecd96f72ee8a053b8aeb28213d8ec6de23ed1608b66","1dc9c847473bb47279e398b22c740c83ea37a5c88bf66629666e3cf4c5b9f99c","a9e4a5a24bf2c44de4c98274975a1a705a0abbaad04df3557c2d3cd8b1727949","00fa7ce8bc8acc560dc341bbfdf37840a8c59e6a67c9bfa3fa5f36254df35db2","1b952304137851e45bc009785de89ada562d9376177c97e37702e39e60c2f1ff",{"version":"806ef4cac3b3d9fa4a48d849c8e084d7c72fcd7b16d76e06049a9ed742ff79c0","affectsGlobalScope":true},"44b8b584a338b190a59f4f6929d072431950c7bd92ec2694821c11bce180c8a5","5f0ed51db151c2cdc4fa3bb0f44ce6066912ad001b607a34e65a96c52eb76248",{"version":"af9771b066ec35ffa1c7db391b018d2469d55e51b98ae95e62b6cbef1b0169ca","affectsGlobalScope":true},"664d8f2d59164f2e08c543981453893bc7e003e4dfd29651ce09db13e9457980","103d70bfbeb3cd3a3f26d1705bf986322d8738c2c143f38ebb743b1e228d7444","f52fbf64c7e480271a9096763c4882d356b05cab05bf56a64e68a95313cd2ce2","59bdb65f28d7ce52ccfc906e9aaf422f8b8534b2d21c32a27d7819be5ad81df7",{"version":"3a2da34079a2567161c1359316a32e712404b56566c45332ac9dcee015ecce9f","affectsGlobalScope":true},"28a2e7383fd898c386ffdcacedf0ec0845e5d1a86b5a43f25b86bc315f556b79","3aff9c8c36192e46a84afe7b926136d520487155154ab9ba982a8b544ea8fc95","a880cf8d85af2e4189c709b0fea613741649c0e40fffb4360ec70762563d5de0","85bbf436a15bbeda4db888be3062d47f99c66fd05d7c50f0f6473a9151b6a070","9f9c49c95ecd25e0cb2587751925976cf64fd184714cb11e213749c80cf0f927","f0c75c08a71f9212c93a719a25fb0320d53f2e50ca89a812640e08f8ad8c408c",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"9cafe917bf667f1027b2bb62e2de454ecd2119c80873ad76fc41d941089753b8",{"version":"3f6d6465811321abc30a1e5f667feed63e5b3917b3d6c8d6645daf96c75f97ba","affectsGlobalScope":true}],"options":{"alwaysStrict":true,"declaration":true,"esModuleInterop":true,"module":6,"noFallthroughCasesInSwitch":true,"noImplicitAny":true,"noImplicitReturns":true,"noImplicitThis":true,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","rootDir":"../src","skipLibCheck":true,"sourceMap":true,"strict":true,"strictFunctionTypes":true,"strictNullChecks":true,"strictPropertyInitialization":true,"target":7,"tsBuildInfoFile":"./.tsbuildinfo"},"fileIdsList":[[94],[51,94],[54,94],[55,60,94],[56,66,67,74,83,93,94],[56,57,66,74,94],[58,94],[59,60,67,75,94],[60,83,90,94],[61,63,66,74,94],[62,94],[63,64,94],[65,66,94],[66,94],[66,67,68,83,93,94],[66,67,68,83,94],[94,98],[69,74,83,93,94],[66,67,69,70,74,83,90,93,94],[69,71,83,90,93,94],[51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100],[66,72,94],[73,93,94],[63,66,74,83,94],[75,94],[76,94],[54,77,94],[78,92,94,98],[79,94],[80,94],[66,81,94],[81,82,94,96],[66,83,84,85,94],[83,85,94],[83,84,94],[86,94],[87,94],[66,88,89,94],[88,89,94],[60,74,83,90,94],[91,94],[74,92,94],[55,69,80,93,94],[60,94],[83,94,95],[94,96],[94,97],[55,60,66,68,77,83,93,94,96,98],[83,94,99],[45,94],[42,43,44,94],[48,49,94],[48,94],[45]],"referencedMap":[[102,1],[51,2],[52,2],[54,3],[55,4],[56,5],[57,6],[58,7],[59,8],[60,9],[61,10],[62,11],[63,12],[64,12],[65,13],[66,14],[67,15],[68,16],[53,17],[100,1],[69,18],[70,19],[71,20],[101,21],[72,22],[73,23],[74,24],[75,25],[76,26],[77,27],[78,28],[79,29],[80,30],[81,31],[82,32],[83,33],[85,34],[84,35],[86,36],[87,37],[88,38],[89,39],[90,40],[91,41],[92,42],[93,43],[94,44],[95,45],[96,46],[97,47],[98,48],[99,49],[8,1],[10,1],[9,1],[2,1],[11,1],[12,1],[13,1],[14,1],[15,1],[16,1],[17,1],[18,1],[3,1],[4,1],[22,1],[19,1],[20,1],[21,1],[23,1],[24,1],[25,1],[5,1],[26,1],[27,1],[28,1],[29,1],[6,1],[30,1],[31,1],[32,1],[33,1],[7,1],[34,1],[39,1],[40,1],[35,1],[36,1],[37,1],[38,1],[1,1],[41,1],[46,50],[42,1],[45,51],[43,1],[47,1],[44,1],[50,52],[49,53],[48,1]],"exportedModulesMap":[[102,1],[51,2],[52,2],[54,3],[55,4],[56,5],[57,6],[58,7],[59,8],[60,9],[61,10],[62,11],[63,12],[64,12],[65,13],[66,14],[67,15],[68,16],[53,17],[100,1],[69,18],[70,19],[71,20],[101,21],[72,22],[73,23],[74,24],[75,25],[76,26],[77,27],[78,28],[79,29],[80,30],[81,31],[82,32],[83,33],[85,34],[84,35],[86,36],[87,37],[88,38],[89,39],[90,40],[91,41],[92,42],[93,43],[94,44],[95,45],[96,46],[97,47],[98,48],[99,49],[8,1],[10,1],[9,1],[2,1],[11,1],[12,1],[13,1],[14,1],[15,1],[16,1],[17,1],[18,1],[3,1],[4,1],[22,1],[19,1],[20,1],[21,1],[23,1],[24,1],[25,1],[5,1],[26,1],[27,1],[28,1],[29,1],[6,1],[30,1],[31,1],[32,1],[33,1],[7,1],[34,1],[39,1],[40,1],[35,1],[36,1],[37,1],[38,1],[1,1],[41,1],[46,54],[43,1],[44,1],[48,1]],"semanticDiagnosticsPerFile":[102,51,52,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,53,100,69,70,71,101,72,73,74,75,76,77,78,79,80,81,82,83,85,84,86,87,88,89,90,91,92,93,94,95,96,97,98,99,8,10,9,2,11,12,13,14,15,16,17,18,3,4,22,19,20,21,23,24,25,5,26,27,28,29,6,30,31,32,33,7,34,39,40,35,36,37,38,1,41,46,42,45,43,47,44,50,49,48]},"version":"4.8.2"}
1
+ {"program":{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/typescript/lib/lib.es2020.date.d.ts","../node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/typescript/lib/lib.es2020.number.d.ts","../node_modules/typescript/lib/lib.esnext.intl.d.ts","../src/resources.ts","../src/witness_calculator.d.ts","../src/zerokit/rln_wasm.d.ts","../src/rln.ts","../src/index.ts","../src/witness_calculator.js","../src/zerokit/rln_wasm_bg.wasm.d.ts","../src/zerokit/rln_wasm_bg.js","../src/zerokit/rln_wasm.js","../node_modules/@types/node/assert.d.ts","../node_modules/@types/node/assert/strict.d.ts","../node_modules/@types/node/globals.d.ts","../node_modules/@types/node/async_hooks.d.ts","../node_modules/@types/node/buffer.d.ts","../node_modules/@types/node/child_process.d.ts","../node_modules/@types/node/cluster.d.ts","../node_modules/@types/node/console.d.ts","../node_modules/@types/node/constants.d.ts","../node_modules/@types/node/crypto.d.ts","../node_modules/@types/node/dgram.d.ts","../node_modules/@types/node/diagnostics_channel.d.ts","../node_modules/@types/node/dns.d.ts","../node_modules/@types/node/dns/promises.d.ts","../node_modules/@types/node/domain.d.ts","../node_modules/@types/node/events.d.ts","../node_modules/@types/node/fs.d.ts","../node_modules/@types/node/fs/promises.d.ts","../node_modules/@types/node/http.d.ts","../node_modules/@types/node/http2.d.ts","../node_modules/@types/node/https.d.ts","../node_modules/@types/node/inspector.d.ts","../node_modules/@types/node/module.d.ts","../node_modules/@types/node/net.d.ts","../node_modules/@types/node/os.d.ts","../node_modules/@types/node/path.d.ts","../node_modules/@types/node/perf_hooks.d.ts","../node_modules/@types/node/process.d.ts","../node_modules/@types/node/punycode.d.ts","../node_modules/@types/node/querystring.d.ts","../node_modules/@types/node/readline.d.ts","../node_modules/@types/node/repl.d.ts","../node_modules/@types/node/stream.d.ts","../node_modules/@types/node/stream/promises.d.ts","../node_modules/@types/node/stream/consumers.d.ts","../node_modules/@types/node/stream/web.d.ts","../node_modules/@types/node/string_decoder.d.ts","../node_modules/@types/node/timers.d.ts","../node_modules/@types/node/timers/promises.d.ts","../node_modules/@types/node/tls.d.ts","../node_modules/@types/node/trace_events.d.ts","../node_modules/@types/node/tty.d.ts","../node_modules/@types/node/url.d.ts","../node_modules/@types/node/util.d.ts","../node_modules/@types/node/v8.d.ts","../node_modules/@types/node/vm.d.ts","../node_modules/@types/node/wasi.d.ts","../node_modules/@types/node/worker_threads.d.ts","../node_modules/@types/node/zlib.d.ts","../node_modules/@types/node/globals.global.d.ts","../node_modules/@types/node/index.d.ts","../node_modules/@types/mocha/index.d.ts"],"fileInfos":[{"version":"f20c05dbfe50a208301d2a1da37b9931bce0466eb5a1f4fe240971b4ecc82b67","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","1fc5ab7a764205c68fa10d381b08417795fc73111d6dd16b5b1ed36badb743d9",{"version":"9b087de7268e4efc5f215347a62656663933d63c0b1d7b624913240367b999ea","affectsGlobalScope":true},{"version":"adb996790133eb33b33aadb9c09f15c2c575e71fb57a62de8bf74dbf59ec7dfb","affectsGlobalScope":true},{"version":"8cc8c5a3bac513368b0157f3d8b31cfdcfe78b56d3724f30f80ed9715e404af8","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true},{"version":"0d5f52b3174bee6edb81260ebcd792692c32c81fd55499d69531496f3f2b25e7","affectsGlobalScope":true},{"version":"55f400eec64d17e888e278f4def2f254b41b89515d3b88ad75d5e05f019daddd","affectsGlobalScope":true},{"version":"181f1784c6c10b751631b24ce60c7f78b20665db4550b335be179217bacc0d5f","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"81cac4cbc92c0c839c70f8ffb94eb61e2d32dc1c3cf6d95844ca099463cf37ea","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"09aa50414b80c023553090e2f53827f007a301bc34b0495bfb2c3c08ab9ad1eb","affectsGlobalScope":true},{"version":"d7f680a43f8cd12a6b6122c07c54ba40952b0c8aa140dcfcf32eb9e6cb028596","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"775d9c9fd150d5de79e0450f35bc8b8f94ae64e3eb5da12725ff2a649dccc777","affectsGlobalScope":true},{"version":"b248e32ca52e8f5571390a4142558ae4f203ae2f94d5bac38a3084d529ef4e58","affectsGlobalScope":true},{"version":"52d1bb7ab7a3306fd0375c8bff560feed26ed676a5b0457fa8027b563aecb9a4","affectsGlobalScope":true},{"version":"832ec1c9d3001b9b6dc75dcb536b30ad2fc278af20e8bd2a951348f71b6ce1ff","signature":"528a4c000f46e7b8d04033eae2c99107a14a4faeae58d8f172e730157c4604d0"},"18e63e4f6a513425aaf40a04e557d486a7b3bb6304807efea8493af640a157ce","2f7f8d917dc2490fe70c038876b6f222a431e5938a3fbf8b5a48c7f7c5e67dbe",{"version":"85136e25f71168b80870652326212f6b21790af3d6e732fbfdd03790703737a6","signature":"1b7a4830dd5380cdb4d889df6c0285b22a94bc5be1f9ae22a8ce670d571902f0"},{"version":"15ead200210c49472e354b654221f71c7d72003429be54a8561dde647345d36f","signature":"cdeb995118bcecf124ab788533cf95d11df2e75e9b67e640b4d2e28bf376347f"},{"version":"cb732dfea79ca2a9a5fd4ed240df67d6c47fd5b66fe188c645367efd1762ed24","signature":"39257e47f71a52d198342c47d3a6b35338a3c8618e4335b56530f2cb3b0dc511"},"58a2096632137825c18cd96c4f120a55582b8e79affa01d388f3c844b987be57",{"version":"ff682c0a5ea90d89c05d1b8c94970057a0fc56c99f6c924f5312d799a446f456","signature":"7ec505c3a1feb7705fc8bf5921617c8dd2759a1d385787190621456f82d32d4c"},{"version":"00e10803e106181f7ca7b3e9ff55ce919200e1937bf949a6a5db59c27cba9308","signature":"dba888cc0cb4ae7a8e32b8df4c6d693d8029d93f92b7fbfb9d1c645279f465ef"},"0cba3a5d7b81356222594442753cf90dd2892e5ccfe1d262aaca6896ba6c1380","a69c09dbea52352f479d3e7ac949fde3d17b195abe90b045d619f747b38d6d1a",{"version":"77f0b5c6a193a699c9f7d7fb0578e64e562d271afa740783665d2a827104a873","affectsGlobalScope":true},"e5979905796fe2740d85fbaf4f11f42b7ee1851421afe750823220813421b1af",{"version":"fcdcb42da18dd98dc286b1876dd425791772036012ae61263c011a76b13a190f","affectsGlobalScope":true},"1dab5ab6bcf11de47ab9db295df8c4f1d92ffa750e8f095e88c71ce4c3299628","f71f46ccd5a90566f0a37b25b23bc4684381ab2180bdf6733f4e6624474e1894",{"version":"54e65985a3ee3cec182e6a555e20974ea936fc8b8d1738c14e8ed8a42bd921d4","affectsGlobalScope":true},"82408ed3e959ddc60d3e9904481b5a8dc16469928257af22a3f7d1a3bc7fd8c4","5b30f550565fd0a7524282c81c27fe8534099e2cd26170ca80852308f07ae68d","34e5de87d983bc6aefef8b17658556e3157003e8d9555d3cb098c6bef0b5fbc8","d97cd8a4a42f557fc62271369ed0461c8e50d47b7f9c8ad0b5462f53306f6060","f27371653aded82b2b160f7a7033fb4a5b1534b6f6081ef7be1468f0f15327d3","c762cd6754b13a461c54b59d0ae0ab7aeef3c292c6cf889873f786ee4d8e75c9","f4ea7d5df644785bd9fbf419930cbaec118f0d8b4160037d2339b8e23c059e79",{"version":"bfea28e6162ed21a0aeed181b623dcf250aa79abf49e24a6b7e012655af36d81","affectsGlobalScope":true},"b8aca9d0c81abb02bec9b7621983ae65bde71da6727580070602bd2500a9ce2a","ae97e20f2e10dbeec193d6a2f9cd9a367a1e293e7d6b33b68bacea166afd7792","10d4796a130577d57003a77b95d8723530bbec84718e364aa2129fa8ffba0378","063f53ff674228c190efa19dd9448bcbd540acdbb48a928f4cf3a1b9f9478e43","bf73c576885408d4a176f44a9035d798827cc5020d58284cb18d7573430d9022","7ae078ca42a670445ae0c6a97c029cb83d143d62abd1730efb33f68f0b2c0e82",{"version":"e8b18c6385ff784228a6f369694fcf1a6b475355ba89090a88de13587a9391d5","affectsGlobalScope":true},"287b21dc1d1b9701c92e15e7dd673dfe6044b15812956377adffb6f08825b1bc","12eea70b5e11e924bb0543aea5eadc16ced318aa26001b453b0d561c2fd0bd1e","08777cd9318d294646b121838574e1dd7acbb22c21a03df84e1f2c87b1ad47f2","08a90bcdc717df3d50a2ce178d966a8c353fd23e5c392fd3594a6e39d9bb6304",{"version":"4cd4cff679c9b3d9239fd7bf70293ca4594583767526916af8e5d5a47d0219c7","affectsGlobalScope":true},"2a12d2da5ac4c4979401a3f6eaafa874747a37c365e4bc18aa2b171ae134d21b","002b837927b53f3714308ecd96f72ee8a053b8aeb28213d8ec6de23ed1608b66","1dc9c847473bb47279e398b22c740c83ea37a5c88bf66629666e3cf4c5b9f99c","a9e4a5a24bf2c44de4c98274975a1a705a0abbaad04df3557c2d3cd8b1727949","00fa7ce8bc8acc560dc341bbfdf37840a8c59e6a67c9bfa3fa5f36254df35db2","1b952304137851e45bc009785de89ada562d9376177c97e37702e39e60c2f1ff",{"version":"806ef4cac3b3d9fa4a48d849c8e084d7c72fcd7b16d76e06049a9ed742ff79c0","affectsGlobalScope":true},"44b8b584a338b190a59f4f6929d072431950c7bd92ec2694821c11bce180c8a5","5f0ed51db151c2cdc4fa3bb0f44ce6066912ad001b607a34e65a96c52eb76248",{"version":"af9771b066ec35ffa1c7db391b018d2469d55e51b98ae95e62b6cbef1b0169ca","affectsGlobalScope":true},"664d8f2d59164f2e08c543981453893bc7e003e4dfd29651ce09db13e9457980","103d70bfbeb3cd3a3f26d1705bf986322d8738c2c143f38ebb743b1e228d7444","f52fbf64c7e480271a9096763c4882d356b05cab05bf56a64e68a95313cd2ce2","59bdb65f28d7ce52ccfc906e9aaf422f8b8534b2d21c32a27d7819be5ad81df7",{"version":"3a2da34079a2567161c1359316a32e712404b56566c45332ac9dcee015ecce9f","affectsGlobalScope":true},"28a2e7383fd898c386ffdcacedf0ec0845e5d1a86b5a43f25b86bc315f556b79","3aff9c8c36192e46a84afe7b926136d520487155154ab9ba982a8b544ea8fc95","a880cf8d85af2e4189c709b0fea613741649c0e40fffb4360ec70762563d5de0","85bbf436a15bbeda4db888be3062d47f99c66fd05d7c50f0f6473a9151b6a070","9f9c49c95ecd25e0cb2587751925976cf64fd184714cb11e213749c80cf0f927","f0c75c08a71f9212c93a719a25fb0320d53f2e50ca89a812640e08f8ad8c408c",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"9cafe917bf667f1027b2bb62e2de454ecd2119c80873ad76fc41d941089753b8",{"version":"3f6d6465811321abc30a1e5f667feed63e5b3917b3d6c8d6645daf96c75f97ba","affectsGlobalScope":true}],"options":{"alwaysStrict":true,"declaration":true,"esModuleInterop":true,"module":6,"noFallthroughCasesInSwitch":true,"noImplicitAny":true,"noImplicitReturns":true,"noImplicitThis":true,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","rootDir":"../src","skipLibCheck":true,"sourceMap":true,"strict":true,"strictFunctionTypes":true,"strictNullChecks":true,"strictPropertyInitialization":true,"target":7,"tsBuildInfoFile":"./.tsbuildinfo"},"fileIdsList":[[94],[51,94],[54,94],[55,60,94],[56,66,67,74,83,93,94],[56,57,66,74,94],[58,94],[59,60,67,75,94],[60,83,90,94],[61,63,66,74,94],[62,94],[63,64,94],[65,66,94],[66,94],[66,67,68,83,93,94],[66,67,68,83,94],[94,98],[69,74,83,93,94],[66,67,69,70,74,83,90,93,94],[69,71,83,90,93,94],[51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100],[66,72,94],[73,93,94],[63,66,74,83,94],[75,94],[76,94],[54,77,94],[78,92,94,98],[79,94],[80,94],[66,81,94],[81,82,94,96],[66,83,84,85,94],[83,85,94],[83,84,94],[86,94],[87,94],[66,88,89,94],[88,89,94],[60,74,83,90,94],[91,94],[74,92,94],[55,69,80,93,94],[60,94],[83,94,95],[94,96],[94,97],[55,60,66,68,77,83,93,94,96,98],[83,94,99],[45,94],[42,43,44,94],[48,49,94],[48,94],[45]],"referencedMap":[[102,1],[51,2],[52,2],[54,3],[55,4],[56,5],[57,6],[58,7],[59,8],[60,9],[61,10],[62,11],[63,12],[64,12],[65,13],[66,14],[67,15],[68,16],[53,17],[100,1],[69,18],[70,19],[71,20],[101,21],[72,22],[73,23],[74,24],[75,25],[76,26],[77,27],[78,28],[79,29],[80,30],[81,31],[82,32],[83,33],[85,34],[84,35],[86,36],[87,37],[88,38],[89,39],[90,40],[91,41],[92,42],[93,43],[94,44],[95,45],[96,46],[97,47],[98,48],[99,49],[8,1],[10,1],[9,1],[2,1],[11,1],[12,1],[13,1],[14,1],[15,1],[16,1],[17,1],[18,1],[3,1],[4,1],[22,1],[19,1],[20,1],[21,1],[23,1],[24,1],[25,1],[5,1],[26,1],[27,1],[28,1],[29,1],[6,1],[30,1],[31,1],[32,1],[33,1],[7,1],[34,1],[39,1],[40,1],[35,1],[36,1],[37,1],[38,1],[1,1],[41,1],[46,50],[42,1],[45,51],[43,1],[47,1],[44,1],[50,52],[49,53],[48,1]],"exportedModulesMap":[[102,1],[51,2],[52,2],[54,3],[55,4],[56,5],[57,6],[58,7],[59,8],[60,9],[61,10],[62,11],[63,12],[64,12],[65,13],[66,14],[67,15],[68,16],[53,17],[100,1],[69,18],[70,19],[71,20],[101,21],[72,22],[73,23],[74,24],[75,25],[76,26],[77,27],[78,28],[79,29],[80,30],[81,31],[82,32],[83,33],[85,34],[84,35],[86,36],[87,37],[88,38],[89,39],[90,40],[91,41],[92,42],[93,43],[94,44],[95,45],[96,46],[97,47],[98,48],[99,49],[8,1],[10,1],[9,1],[2,1],[11,1],[12,1],[13,1],[14,1],[15,1],[16,1],[17,1],[18,1],[3,1],[4,1],[22,1],[19,1],[20,1],[21,1],[23,1],[24,1],[25,1],[5,1],[26,1],[27,1],[28,1],[29,1],[6,1],[30,1],[31,1],[32,1],[33,1],[7,1],[34,1],[39,1],[40,1],[35,1],[36,1],[37,1],[38,1],[1,1],[41,1],[46,54],[43,1],[44,1],[48,1]],"semanticDiagnosticsPerFile":[102,51,52,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,53,100,69,70,71,101,72,73,74,75,76,77,78,79,80,81,82,83,85,84,86,87,88,89,90,91,92,93,94,95,96,97,98,99,8,10,9,2,11,12,13,14,15,16,17,18,3,4,22,19,20,21,23,24,25,5,26,27,28,29,6,30,31,32,33,7,34,39,40,35,36,37,38,1,41,46,42,45,43,47,44,50,49,48]},"version":"4.8.2"}
package/dist/rln.d.ts CHANGED
@@ -8,13 +8,25 @@ export declare class MembershipKey {
8
8
  readonly IDCommitment: Uint8Array;
9
9
  constructor(memKeys: Uint8Array);
10
10
  }
11
+ export declare function toEpoch(timestamp: Date, epochUnitSeconds?: number): Uint8Array;
12
+ export declare class RateLimitProof {
13
+ readonly proof: Uint8Array;
14
+ readonly merkleRoot: Uint8Array;
15
+ readonly epoch: Uint8Array;
16
+ readonly shareX: Uint8Array;
17
+ readonly shareY: Uint8Array;
18
+ readonly nullifier: Uint8Array;
19
+ readonly rlnIdentifier: Uint8Array;
20
+ constructor(proofBytes: Uint8Array);
21
+ toBytes(): Uint8Array;
22
+ }
11
23
  export declare class RLNInstance {
12
- zkRLN: number;
13
- witnessCalculator: any;
14
- constructor(zkRLN: number, wc: any);
24
+ private zkRLN;
25
+ private witnessCalculator;
26
+ constructor(zkRLN: number, witnessCalculator: any);
15
27
  generateMembershipKey(): MembershipKey;
16
28
  inserMember(idCommitment: Uint8Array): void;
17
29
  serializeMessage(uint8Msg: Uint8Array, memIndex: number, epoch: Uint8Array, idKey: Uint8Array): Uint8Array;
18
- generateProof(msg: Uint8Array, index: number, epoch: Uint8Array, idKey: Uint8Array): Promise<Uint8Array>;
19
- verifyProof(proof: Uint8Array): boolean;
30
+ generateProof(msg: Uint8Array, index: number, epoch: Uint8Array | Date | undefined, idKey: Uint8Array): Promise<RateLimitProof>;
31
+ verifyProof(proof: RateLimitProof | Uint8Array): boolean;
20
32
  }
package/dist/rln.js CHANGED
@@ -53,10 +53,62 @@ export class MembershipKey {
53
53
  this.IDCommitment = memKeys.subarray(32);
54
54
  }
55
55
  }
56
+ // Adapted from https://github.com/feross/buffer
57
+ function checkInt(buf, value, offset, ext, max, min) {
58
+ if (value > max || value < min)
59
+ throw new RangeError('"value" argument is out of bounds');
60
+ if (offset + ext > buf.length)
61
+ throw new RangeError("Index out of range");
62
+ }
63
+ const writeUIntLE = function writeUIntLE(buf, value, offset, byteLength, noAssert) {
64
+ value = +value;
65
+ offset = offset >>> 0;
66
+ byteLength = byteLength >>> 0;
67
+ if (!noAssert) {
68
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
69
+ checkInt(buf, value, offset, byteLength, maxBytes, 0);
70
+ }
71
+ let mul = 1;
72
+ let i = 0;
73
+ buf[offset] = value & 0xff;
74
+ while (++i < byteLength && (mul *= 0x100)) {
75
+ buf[offset + i] = (value / mul) & 0xff;
76
+ }
77
+ return buf;
78
+ };
79
+ const DefaultEpochUnitSeconds = 10; // the rln-relay epoch length in seconds
80
+ export function toEpoch(timestamp, epochUnitSeconds = DefaultEpochUnitSeconds) {
81
+ const unix = Math.floor(timestamp.getTime() / 1000 / epochUnitSeconds);
82
+ return writeUIntLE(new Uint8Array(32), unix, 0, 8);
83
+ }
84
+ const proofOffset = 128;
85
+ const rootOffset = proofOffset + 32;
86
+ const epochOffset = rootOffset + 32;
87
+ const shareXOffset = epochOffset + 32;
88
+ const shareYOffset = shareXOffset + 32;
89
+ const nullifierOffset = shareYOffset + 32;
90
+ const rlnIdentifierOffset = nullifierOffset + 32;
91
+ export class RateLimitProof {
92
+ constructor(proofBytes) {
93
+ if (proofBytes.length < rlnIdentifierOffset)
94
+ throw "invalid proof";
95
+ // parse the proof as proof<128> | share_y<32> | nullifier<32> | root<32> | epoch<32> | share_x<32> | rln_identifier<32>
96
+ this.proof = proofBytes.subarray(0, proofOffset);
97
+ this.merkleRoot = proofBytes.subarray(proofOffset, rootOffset);
98
+ this.epoch = proofBytes.subarray(rootOffset, epochOffset);
99
+ this.shareX = proofBytes.subarray(epochOffset, shareXOffset);
100
+ this.shareY = proofBytes.subarray(shareXOffset, shareYOffset);
101
+ this.nullifier = proofBytes.subarray(shareYOffset, nullifierOffset);
102
+ this.rlnIdentifier = proofBytes.subarray(nullifierOffset, rlnIdentifierOffset);
103
+ }
104
+ toBytes() {
105
+ return concatenate(this.proof, this.merkleRoot, this.epoch, this.shareX, this.shareY, this.nullifier, this.rlnIdentifier);
106
+ }
107
+ }
56
108
  export class RLNInstance {
57
- constructor(zkRLN, wc) {
109
+ constructor(zkRLN, witnessCalculator) {
58
110
  this.zkRLN = zkRLN;
59
- this.witnessCalculator = wc;
111
+ this.witnessCalculator = witnessCalculator;
60
112
  }
61
113
  generateMembershipKey() {
62
114
  const memKeys = zerokitRLN.generateMembershipKey(this.zkRLN);
@@ -66,20 +118,20 @@ export class RLNInstance {
66
118
  zerokitRLN.insertMember(this.zkRLN, idCommitment);
67
119
  }
68
120
  serializeMessage(uint8Msg, memIndex, epoch, idKey) {
69
- if (epoch.length != 32)
70
- throw "invalid epoch";
71
- if (idKey.length != 32)
72
- throw "invalid id key";
73
121
  // calculate message length
74
- const msgLen = Buffer.allocUnsafe(8);
75
- msgLen.writeUIntLE(uint8Msg.length, 0, 8);
122
+ const msgLen = writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
76
123
  // Converting index to LE bytes
77
- const memIndexBytes = Buffer.allocUnsafe(8);
78
- memIndexBytes.writeUIntLE(memIndex, 0, 8);
124
+ const memIndexBytes = writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
79
125
  // [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> ]
80
126
  return concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg);
81
127
  }
82
128
  async generateProof(msg, index, epoch, idKey) {
129
+ if (epoch == undefined) {
130
+ epoch = toEpoch(new Date());
131
+ }
132
+ else if (epoch instanceof Date) {
133
+ epoch = toEpoch(epoch);
134
+ }
83
135
  if (epoch.length != 32)
84
136
  throw "invalid epoch";
85
137
  if (idKey.length != 32)
@@ -90,9 +142,13 @@ export class RLNInstance {
90
142
  const rlnWitness = zerokitRLN.getSerializedRLNWitness(this.zkRLN, serialized_msg);
91
143
  const inputs = zerokitRLN.RLNWitnessToJson(this.zkRLN, rlnWitness);
92
144
  const calculatedWitness = await this.witnessCalculator.calculateWitness(inputs, false); // no sanity check being used in zerokit
93
- return zerokitRLN.generate_rln_proof_with_witness(this.zkRLN, calculatedWitness, rlnWitness);
145
+ const proofBytes = zerokitRLN.generate_rln_proof_with_witness(this.zkRLN, calculatedWitness, rlnWitness);
146
+ return new RateLimitProof(proofBytes);
94
147
  }
95
148
  verifyProof(proof) {
149
+ if (proof instanceof RateLimitProof) {
150
+ proof = proof.toBytes();
151
+ }
96
152
  return zerokitRLN.verifyProof(this.zkRLN, proof);
97
153
  }
98
154
  }
package/dist/rln.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"rln.js","sourceRoot":"","sources":["../src/rln.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AAEjD;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,MAAc;IACxC,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC;IACjC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;QAC5B,KAAK,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;KACxC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAC,GAAG,KAAmB;IACzC,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;QACvB,WAAW,IAAI,GAAG,CAAC,MAAM,CAAC;KAC3B;IACD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;QACvB,MAAM,CAAC,GA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AK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;SACxB;QAED,IAAI,KAAK,CAAC,MAAM,IAAI,EAAE;YAAE,MAAM,eAAe,CAAC;QAC9C,IAAI,KAAK,CAAC,MAAM,IAAI,EAAE;YAAE,MAAM,gBAAgB,CAAC;QAC/C,IAAI,KAAK,GAAG,CAAC;YAAE,MAAM,oBAAoB,CAAC;QAE1C,MAAM,cAAc,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QACvE,MAAM,UAAU,GAAG,UAAU,CAAC,uBAAuB,CACnD,IAAI,CAAC,KAAK,EACV,cAAc,CACf,CAAC;QACF,MAAM,MAAM,GAAG,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QACnE,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CACrE,MAAM,EACN,KAAK,CACN,CAAC,CAAC,wCAAwC;QAE3C,MAAM,UAAU,GAAG,UAAU,CAAC,+BAA+B,CAC3D,IAAI,CAAC,KAAK,EACV,iBAAiB,EACjB,UAAU,CACX,CAAC;QAEF,OAAO,IAAI,cAAc,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAED,WAAW,CAAC,KAAkC;QAC5C,IAAI,KAAK,YAAY,cAAc,EAAE;YACnC,KAAK,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;SACzB;QACD,OAAO,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnD,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waku/rln",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Rate Limit Nullifier for js-waku",
5
5
  "types": "./dist/index.d.ts",
6
6
  "module": "./dist/index.js",
package/src/rln.ts CHANGED
@@ -63,15 +63,104 @@ export class MembershipKey {
63
63
  }
64
64
  }
65
65
 
66
- export class RLNInstance {
67
- zkRLN: number;
68
- witnessCalculator: any;
66
+ // Adapted from https://github.com/feross/buffer
67
+
68
+ function checkInt(
69
+ buf: Uint8Array,
70
+ value: number,
71
+ offset: number,
72
+ ext: number,
73
+ max: number,
74
+ min: number
75
+ ): void {
76
+ if (value > max || value < min)
77
+ throw new RangeError('"value" argument is out of bounds');
78
+ if (offset + ext > buf.length) throw new RangeError("Index out of range");
79
+ }
80
+
81
+ const writeUIntLE = function writeUIntLE(
82
+ buf: Uint8Array,
83
+ value: number,
84
+ offset: number,
85
+ byteLength: number,
86
+ noAssert?: boolean
87
+ ): Uint8Array {
88
+ value = +value;
89
+ offset = offset >>> 0;
90
+ byteLength = byteLength >>> 0;
91
+ if (!noAssert) {
92
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
93
+ checkInt(buf, value, offset, byteLength, maxBytes, 0);
94
+ }
95
+
96
+ let mul = 1;
97
+ let i = 0;
98
+ buf[offset] = value & 0xff;
99
+ while (++i < byteLength && (mul *= 0x100)) {
100
+ buf[offset + i] = (value / mul) & 0xff;
101
+ }
69
102
 
70
- constructor(zkRLN: number, wc: any) {
71
- this.zkRLN = zkRLN;
72
- this.witnessCalculator = wc;
103
+ return buf;
104
+ };
105
+
106
+ const DefaultEpochUnitSeconds = 10; // the rln-relay epoch length in seconds
107
+
108
+ export function toEpoch(
109
+ timestamp: Date,
110
+ epochUnitSeconds: number = DefaultEpochUnitSeconds
111
+ ): Uint8Array {
112
+ const unix = Math.floor(timestamp.getTime() / 1000 / epochUnitSeconds);
113
+ return writeUIntLE(new Uint8Array(32), unix, 0, 8);
114
+ }
115
+
116
+ const proofOffset = 128;
117
+ const rootOffset = proofOffset + 32;
118
+ const epochOffset = rootOffset + 32;
119
+ const shareXOffset = epochOffset + 32;
120
+ const shareYOffset = shareXOffset + 32;
121
+ const nullifierOffset = shareYOffset + 32;
122
+ const rlnIdentifierOffset = nullifierOffset + 32;
123
+
124
+ export class RateLimitProof {
125
+ readonly proof: Uint8Array;
126
+ readonly merkleRoot: Uint8Array;
127
+ readonly epoch: Uint8Array;
128
+ readonly shareX: Uint8Array;
129
+ readonly shareY: Uint8Array;
130
+ readonly nullifier: Uint8Array;
131
+ readonly rlnIdentifier: Uint8Array;
132
+
133
+ constructor(proofBytes: Uint8Array) {
134
+ if (proofBytes.length < rlnIdentifierOffset) throw "invalid proof";
135
+ // parse the proof as proof<128> | share_y<32> | nullifier<32> | root<32> | epoch<32> | share_x<32> | rln_identifier<32>
136
+ this.proof = proofBytes.subarray(0, proofOffset);
137
+ this.merkleRoot = proofBytes.subarray(proofOffset, rootOffset);
138
+ this.epoch = proofBytes.subarray(rootOffset, epochOffset);
139
+ this.shareX = proofBytes.subarray(epochOffset, shareXOffset);
140
+ this.shareY = proofBytes.subarray(shareXOffset, shareYOffset);
141
+ this.nullifier = proofBytes.subarray(shareYOffset, nullifierOffset);
142
+ this.rlnIdentifier = proofBytes.subarray(
143
+ nullifierOffset,
144
+ rlnIdentifierOffset
145
+ );
73
146
  }
74
147
 
148
+ toBytes(): Uint8Array {
149
+ return concatenate(
150
+ this.proof,
151
+ this.merkleRoot,
152
+ this.epoch,
153
+ this.shareX,
154
+ this.shareY,
155
+ this.nullifier,
156
+ this.rlnIdentifier
157
+ );
158
+ }
159
+ }
160
+
161
+ export class RLNInstance {
162
+ constructor(private zkRLN: number, private witnessCalculator: any) {}
163
+
75
164
  generateMembershipKey(): MembershipKey {
76
165
  const memKeys = zerokitRLN.generateMembershipKey(this.zkRLN);
77
166
  return new MembershipKey(memKeys);
@@ -87,16 +176,11 @@ export class RLNInstance {
87
176
  epoch: Uint8Array,
88
177
  idKey: Uint8Array
89
178
  ): Uint8Array {
90
- if (epoch.length != 32) throw "invalid epoch";
91
- if (idKey.length != 32) throw "invalid id key";
92
-
93
179
  // calculate message length
94
- const msgLen = Buffer.allocUnsafe(8);
95
- msgLen.writeUIntLE(uint8Msg.length, 0, 8);
180
+ const msgLen = writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
96
181
 
97
182
  // Converting index to LE bytes
98
- const memIndexBytes = Buffer.allocUnsafe(8);
99
- memIndexBytes.writeUIntLE(memIndex, 0, 8);
183
+ const memIndexBytes = writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
100
184
 
101
185
  // [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> ]
102
186
  return concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg);
@@ -105,9 +189,15 @@ export class RLNInstance {
105
189
  async generateProof(
106
190
  msg: Uint8Array,
107
191
  index: number,
108
- epoch: Uint8Array,
192
+ epoch: Uint8Array | Date | undefined,
109
193
  idKey: Uint8Array
110
- ): Promise<Uint8Array> {
194
+ ): Promise<RateLimitProof> {
195
+ if (epoch == undefined) {
196
+ epoch = toEpoch(new Date());
197
+ } else if (epoch instanceof Date) {
198
+ epoch = toEpoch(epoch);
199
+ }
200
+
111
201
  if (epoch.length != 32) throw "invalid epoch";
112
202
  if (idKey.length != 32) throw "invalid id key";
113
203
  if (index < 0) throw "index must be >= 0";
@@ -123,14 +213,19 @@ export class RLNInstance {
123
213
  false
124
214
  ); // no sanity check being used in zerokit
125
215
 
126
- return zerokitRLN.generate_rln_proof_with_witness(
216
+ const proofBytes = zerokitRLN.generate_rln_proof_with_witness(
127
217
  this.zkRLN,
128
218
  calculatedWitness,
129
219
  rlnWitness
130
220
  );
221
+
222
+ return new RateLimitProof(proofBytes);
131
223
  }
132
224
 
133
- verifyProof(proof: Uint8Array): boolean {
225
+ verifyProof(proof: RateLimitProof | Uint8Array): boolean {
226
+ if (proof instanceof RateLimitProof) {
227
+ proof = proof.toBytes();
228
+ }
134
229
  return zerokitRLN.verifyProof(this.zkRLN, proof);
135
230
  }
136
231
  }