@noir-lang/noir_wasm 1.0.0-beta.22 → 1.0.0-beta.23

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.
@@ -4,7 +4,7 @@
4
4
  "The Noir Team <team@noir-lang.org>"
5
5
  ],
6
6
  "description": "A JS interface to the Noir compiler",
7
- "version": "1.0.0-beta.22",
7
+ "version": "1.0.0-beta.23",
8
8
  "license": "MIT OR Apache-2.0",
9
9
  "repository": {
10
10
  "type": "git",
@@ -5,7 +5,7 @@
5
5
  "The Noir Team <team@noir-lang.org>"
6
6
  ],
7
7
  "description": "A JS interface to the Noir compiler",
8
- "version": "1.0.0-beta.22",
8
+ "version": "1.0.0-beta.23",
9
9
  "license": "MIT OR Apache-2.0",
10
10
  "repository": {
11
11
  "type": "git",
Binary file
package/dist/node/main.js CHANGED
@@ -10888,7 +10888,7 @@ module.exports = webpackEmptyAsyncContext;
10888
10888
 
10889
10889
  /**
10890
10890
  * This is a wrapper class that is wasm-bindgen compatible
10891
- * We do not use js_name and rename it like CrateId because
10891
+ * We do not use `js_name` and rename it like `CrateId` because
10892
10892
  * then the impl block is not picked up in javascript.
10893
10893
  */
10894
10894
  class CompilerContext {
@@ -11074,7 +11074,7 @@ exports.compile_contract = compile_contract;
11074
11074
 
11075
11075
  /**
11076
11076
  * This is a method that exposes the same API as `compile`
11077
- * But uses the Context based APi internally
11077
+ * But uses the Context based `APi` internally
11078
11078
  * @param {string} entry_point
11079
11079
  * @param {DependencyGraph | null | undefined} dependency_graph
11080
11080
  * @param {PathToFileSourceMap} file_source_map
@@ -11114,7 +11114,7 @@ exports.compile_program = compile_program;
11114
11114
 
11115
11115
  /**
11116
11116
  * This is a method that exposes the same API as `compile`
11117
- * But uses the Context based APi internally
11117
+ * But uses the Context based `APi` internally
11118
11118
  * @param {string} entry_point
11119
11119
  * @param {DependencyGraph | null | undefined} dependency_graph
11120
11120
  * @param {PathToFileSourceMap} file_source_map
@@ -11168,16 +11168,16 @@ function __wbg_get_imports() {
11168
11168
  __wbg___wbindgen_throw_39bc967c0e5a9b58: function(arg0, arg1) {
11169
11169
  throw new Error(getStringFromWasm0(arg0, arg1));
11170
11170
  },
11171
- __wbg_constructor_6abccea0d4936b07: function() {
11172
- const ret = new Object();
11171
+ __wbg_constructor_bb7885f61729f9d6: function(arg0) {
11172
+ const ret = new Error(arg0);
11173
11173
  return ret;
11174
11174
  },
11175
- __wbg_constructor_8751639ef442c1ca: function() {
11175
+ __wbg_constructor_cdfdba3326ae7d4c: function() {
11176
11176
  const ret = new Object();
11177
11177
  return ret;
11178
11178
  },
11179
- __wbg_constructor_f5ae126ef3073c7e: function(arg0) {
11180
- const ret = new Error(arg0);
11179
+ __wbg_constructor_d9e7c2461f7ee7c6: function() {
11180
+ const ret = new Object();
11181
11181
  return ret;
11182
11182
  },
11183
11183
  __wbg_debug_8804c16f548276da: function(arg0, arg1, arg2, arg3) {
@@ -11501,7 +11501,7 @@ __webpack_require__.r(__webpack_exports__);
11501
11501
  /* harmony export */ unzip: () => (/* binding */ unzip),
11502
11502
  /* harmony export */ unzipRaw: () => (/* binding */ unzipRaw)
11503
11503
  /* harmony export */ });
11504
- /* unzipit@2.0.1, license MIT */
11504
+ /* unzipit@2.0.3, license MIT */
11505
11505
  var _a, _b;
11506
11506
  function readBlobAsArrayBuffer(blob) {
11507
11507
  if (blob.arrayBuffer) {
@@ -11622,24 +11622,30 @@ let nextId = 0;
11622
11622
  // come in before a worker gets added to `workers`
11623
11623
  let numWorkers = 0;
11624
11624
  let canUseWorkers = true; // gets set to false if we can't start a worker
11625
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11626
11625
  const workers = [];
11627
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11628
11626
  const availableWorkers = [];
11629
11627
  const waitingForWorkerQueue = [];
11630
11628
  const currentlyProcessingIdToRequestMap = new Map();
11631
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11632
11629
  function handleResult(e) {
11633
11630
  makeWorkerAvailable(e.target);
11634
11631
  const { id, error, data } = e.data;
11635
11632
  const request = currentlyProcessingIdToRequestMap.get(id);
11636
11633
  currentlyProcessingIdToRequestMap.delete(id);
11637
11634
  if (error) {
11638
- request.reject(error);
11635
+ // The worker can only structured-clone the error as a string, so wrap it
11636
+ // back into an Error to match the rejection type of the non-worker path.
11637
+ request.reject(new Error(error));
11638
+ return;
11639
11639
  }
11640
- else {
11641
- request.resolve(data);
11640
+ // Verify that the decompressed size matches the declared uncompressedSize
11641
+ // Treat declared size as authoritative metadata that must be verified.
11642
+ const expected = request.uncompressedSize;
11643
+ const actual = data instanceof ArrayBuffer ? data.byteLength : data === null || data === void 0 ? void 0 : data.size;
11644
+ if (typeof expected === 'number' && typeof actual === 'number' && expected !== actual) {
11645
+ request.reject(new Error(`decompressed size mismatch. declared: ${expected}, actual: ${actual}`));
11646
+ return;
11642
11647
  }
11648
+ request.resolve(data);
11643
11649
  }
11644
11650
  // Because Firefox uses non-standard onerror to signal an error.
11645
11651
  function startWorker(url) {
@@ -11661,28 +11667,25 @@ function startWorker(url) {
11661
11667
  const workerHelper = (function () {
11662
11668
  if (isNode) {
11663
11669
  return {
11664
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11665
11670
  async createWorker(url) {
11666
11671
  const moduleId = 'node:worker_threads';
11667
11672
  const { Worker } = await __webpack_require__("../../node_modules/unzipit/dist lazy recursive referencedExports: Worker")(moduleId);
11668
11673
  return new Worker(url);
11669
11674
  },
11670
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11671
11675
  addEventListener(worker, fn) {
11672
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11673
- worker.on('message', (data) => {
11676
+ var _a;
11677
+ (_a = worker.on) === null || _a === void 0 ? void 0 : _a.call(worker, 'message', (data) => {
11674
11678
  fn({ target: worker, data });
11675
11679
  });
11676
11680
  },
11677
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11678
11681
  async terminate(worker) {
11679
- await worker.terminate();
11682
+ var _a;
11683
+ await ((_a = worker.terminate) === null || _a === void 0 ? void 0 : _a.call(worker));
11680
11684
  },
11681
11685
  };
11682
11686
  }
11683
11687
  else {
11684
11688
  return {
11685
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11686
11689
  async createWorker(url) {
11687
11690
  // I don't understand this security issue
11688
11691
  // Apparently there is some iframe setting or http header
@@ -11725,23 +11728,23 @@ const workerHelper = (function () {
11725
11728
  console.warn('workers will not be used');
11726
11729
  throw new Error('can not start workers');
11727
11730
  },
11728
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11729
11731
  addEventListener(worker, fn) {
11730
- worker.addEventListener('message', fn);
11732
+ var _a;
11733
+ // The browser delivers a MessageEvent whose `target` is the worker
11734
+ // and whose `data` is the InflateResultMessage, matching WorkerResultEvent.
11735
+ (_a = worker.addEventListener) === null || _a === void 0 ? void 0 : _a.call(worker, 'message', fn);
11731
11736
  },
11732
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11733
11737
  async terminate(worker) {
11734
- worker.terminate();
11738
+ var _a;
11739
+ await ((_a = worker.terminate) === null || _a === void 0 ? void 0 : _a.call(worker));
11735
11740
  },
11736
11741
  };
11737
11742
  }
11738
11743
  }());
11739
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11740
11744
  function makeWorkerAvailable(worker) {
11741
11745
  availableWorkers.push(worker);
11742
11746
  processWaitingForWorkerQueue();
11743
11747
  }
11744
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11745
11748
  async function getAvailableWorker() {
11746
11749
  if (availableWorkers.length === 0 && numWorkers < config.numWorkers) {
11747
11750
  ++numWorkers; // see comment at numWorkers declaration
@@ -11758,7 +11761,7 @@ async function getAvailableWorker() {
11758
11761
  }
11759
11762
  return availableWorkers.pop();
11760
11763
  }
11761
- async function decompressRaw(src) {
11764
+ async function decompressRaw(src, limit) {
11762
11765
  const ds = new DecompressionStream('deflate-raw');
11763
11766
  const writer = ds.writable.getWriter();
11764
11767
  // Do not await the write — doing so before reading causes a deadlock when
@@ -11766,12 +11769,19 @@ async function decompressRaw(src) {
11766
11769
  writer.write(src).then(() => writer.close()).catch(() => { });
11767
11770
  const chunks = [];
11768
11771
  const reader = ds.readable.getReader();
11772
+ let seen = 0;
11769
11773
  for (;;) {
11770
11774
  const { done, value } = await reader.read();
11771
11775
  if (done) {
11772
11776
  break;
11773
11777
  }
11778
+ // If this chunk would push us past the configured/declared limit, abort
11779
+ const newSeen = seen + value.byteLength;
11780
+ if (typeof limit === 'number' && newSeen > limit) {
11781
+ throw new Error(`decompressed size exceeds limit: ${newSeen} > ${limit}`);
11782
+ }
11774
11783
  chunks.push(value);
11784
+ seen = newSeen;
11775
11785
  }
11776
11786
  const size = chunks.reduce((s, c) => s + c.byteLength, 0);
11777
11787
  const result = new Uint8Array(size);
@@ -11785,9 +11795,15 @@ async function decompressRaw(src) {
11785
11795
  // @param {Uint8Array} src
11786
11796
  // @param {string} [type] mime-type
11787
11797
  // @returns {ArrayBuffer|Blob} ArrayBuffer if type is falsy or Blob otherwise.
11788
- async function inflateRawLocal(src, type, resolve, reject) {
11798
+ async function inflateRawLocal(src, uncompressedSize, type, resolve, reject) {
11789
11799
  try {
11790
- const dst = await decompressRaw(src);
11800
+ const limit = uncompressedSize;
11801
+ const dst = await decompressRaw(src, limit);
11802
+ const actual = dst.byteLength;
11803
+ if (typeof uncompressedSize === 'number' && actual !== uncompressedSize) {
11804
+ reject(new Error(`decompressed size mismatch. declared: ${uncompressedSize}, actual: ${actual}`));
11805
+ return;
11806
+ }
11791
11807
  resolve(type ? new Blob([dst], { type }) : dst.buffer);
11792
11808
  }
11793
11809
  catch (e) {
@@ -11795,6 +11811,7 @@ async function inflateRawLocal(src, type, resolve, reject) {
11795
11811
  }
11796
11812
  }
11797
11813
  async function processWaitingForWorkerQueue() {
11814
+ var _a;
11798
11815
  if (waitingForWorkerQueue.length === 0) {
11799
11816
  return;
11800
11817
  }
@@ -11824,7 +11841,7 @@ async function processWaitingForWorkerQueue() {
11824
11841
  //if (!isBlob(src) && !isSharedArrayBuffer(src)) {
11825
11842
  // transferables.push(src);
11826
11843
  //}
11827
- worker.postMessage({
11844
+ (_a = worker.postMessage) === null || _a === void 0 ? void 0 : _a.call(worker, {
11828
11845
  type: 'inflate',
11829
11846
  data: {
11830
11847
  id,
@@ -11843,9 +11860,14 @@ async function processWaitingForWorkerQueue() {
11843
11860
  // will then be on the queue. But if we fail to make workers then there
11844
11861
  // are pending requests.
11845
11862
  while (waitingForWorkerQueue.length) {
11846
- const { src, type, resolve, reject } = waitingForWorkerQueue.shift();
11863
+ const { src, uncompressedSize, type, resolve, reject } = waitingForWorkerQueue.shift();
11847
11864
  const data = isBlob(src) ? await readBlobAsUint8Array(src) : src;
11848
- inflateRawLocal(data, type, resolve, reject);
11865
+ try {
11866
+ await inflateRawLocal(data, uncompressedSize, type, resolve, reject);
11867
+ }
11868
+ catch (e) {
11869
+ reject(e);
11870
+ }
11849
11871
  }
11850
11872
  }
11851
11873
  function setOptions$1(options) {