@noir-lang/noir_wasm 0.23.0 → 0.24.0-10e8292.nightly

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/README.md CHANGED
@@ -1,9 +1,32 @@
1
1
  # Noir Lang WASM JavaScript Package
2
2
 
3
- This JavaScript package enables users to compile a Noir program, i.e. generating its artifacts.
3
+ This JavaScript package enables users to compile a Noir program, i.e. generating its artifacts, both in Node.JS environments and the browser.
4
4
 
5
5
  The package also handles dependency management like how Nargo (Noir's CLI tool) operates, but the package is used just for compilation, not proving, verifying and simulating functions.
6
6
 
7
+ ## Usage
8
+
9
+ ```typescript
10
+ // Node.js
11
+
12
+ import { compile, createFileManager } from '@noir-lang/noir_wasm';
13
+
14
+ const fm = createFileManager(myProjectPath);
15
+ const myCompiledCode = await compile(fm);
16
+ ```
17
+
18
+ ```typescript
19
+ // Browser
20
+
21
+ import { compile, createFileManager } from '@noir-lang/noir_wasm';
22
+
23
+ const fm = createFileManager('/');
24
+ for (const path of files) {
25
+ await fm.writeFile(path, await getFileAsStream(path));
26
+ }
27
+ const myCompiledCode = await compile(fm);
28
+ ```
29
+
7
30
  ## Building from source
8
31
 
9
32
  Outside of the [noir repo](https://github.com/noir-lang/noir), this package can be built using the command below:
@@ -3,7 +3,7 @@
3
3
  "collaborators": [
4
4
  "The Noir Team <team@noir-lang.org>"
5
5
  ],
6
- "version": "0.23.0",
6
+ "version": "0.24.0",
7
7
  "license": "MIT OR Apache-2.0",
8
8
  "files": [
9
9
  "index_bg.wasm",
@@ -3,7 +3,7 @@
3
3
  "collaborators": [
4
4
  "The Noir Team <team@noir-lang.org>"
5
5
  ],
6
- "version": "0.23.0",
6
+ "version": "0.24.0",
7
7
  "license": "MIT OR Apache-2.0",
8
8
  "files": [
9
9
  "index_bg.wasm",
Binary file
package/dist/node/main.js CHANGED
@@ -32,12 +32,6 @@ function takeObject(idx) {
32
32
  return ret;
33
33
  }
34
34
 
35
- function _assertBoolean(n) {
36
- if (typeof(n) !== 'boolean') {
37
- throw new Error('expected a boolean argument');
38
- }
39
- }
40
-
41
35
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
42
36
 
43
37
  cachedTextDecoder.decode();
@@ -61,8 +55,6 @@ function addHeapObject(obj) {
61
55
  const idx = heap_next;
62
56
  heap_next = heap[idx];
63
57
 
64
- if (typeof(heap_next) !== 'number') throw new Error('corrupt heap');
65
-
66
58
  heap[idx] = obj;
67
59
  return idx;
68
60
  }
@@ -86,8 +78,6 @@ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
86
78
 
87
79
  function passStringToWasm0(arg, malloc, realloc) {
88
80
 
89
- if (typeof(arg) !== 'string') throw new Error('expected a string argument');
90
-
91
81
  if (realloc === undefined) {
92
82
  const buf = cachedTextEncoder.encode(arg);
93
83
  const ptr = malloc(buf.length) >>> 0;
@@ -116,7 +106,7 @@ function passStringToWasm0(arg, malloc, realloc) {
116
106
  ptr = realloc(ptr, len, len = offset + arg.length * 3) >>> 0;
117
107
  const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
118
108
  const ret = encodeString(arg, view);
119
- if (ret.read !== arg.length) throw new Error('failed to pass whole string');
109
+
120
110
  offset += ret.written;
121
111
  }
122
112
 
@@ -202,26 +192,6 @@ function debugString(val) {
202
192
  return className;
203
193
  }
204
194
 
205
- function logError(f, args) {
206
- try {
207
- return f.apply(this, args);
208
- } catch (e) {
209
- let error = (function () {
210
- try {
211
- return e instanceof Error ? `${e.message}\n\nStack:\n${e.stack}` : e.toString();
212
- } catch(_) {
213
- return "<failed to stringify thrown value>";
214
- }
215
- }());
216
- console.error("wasm-bindgen: imported JS function that was not marked as `catch` threw an error:", error);
217
- throw e;
218
- }
219
- }
220
-
221
- function _assertNum(n) {
222
- if (typeof(n) !== 'number') throw new Error('expected a number argument');
223
- }
224
-
225
195
  function _assertClass(instance, klass) {
226
196
  if (!(instance instanceof klass)) {
227
197
  throw new Error(`expected instance of ${klass.name}`);
@@ -229,26 +199,21 @@ function _assertClass(instance, klass) {
229
199
  return instance.ptr;
230
200
  }
231
201
  /**
202
+ * This is a method that exposes the same API as `compile`
203
+ * But uses the Context based APi internally
232
204
  * @param {string} entry_point
233
- * @param {boolean | undefined} contracts
234
205
  * @param {DependencyGraph | undefined} dependency_graph
235
206
  * @param {PathToFileSourceMap} file_source_map
236
- * @returns {CompileResult}
207
+ * @returns {ProgramCompileResult}
237
208
  */
238
- module.exports.compile = function(entry_point, contracts, dependency_graph, file_source_map) {
209
+ module.exports.compile_program_ = function(entry_point, dependency_graph, file_source_map) {
239
210
  try {
240
211
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
241
212
  const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
242
213
  const len0 = WASM_VECTOR_LEN;
243
- if (!isLikeNone(contracts)) {
244
- _assertBoolean(contracts);
245
- }
246
214
  _assertClass(file_source_map, PathToFileSourceMap);
247
- if (file_source_map.__wbg_ptr === 0) {
248
- throw new Error('Attempt to use a moved value');
249
- }
250
215
  var ptr1 = file_source_map.__destroy_into_raw();
251
- wasm.compile(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
216
+ wasm.compile_program_(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
252
217
  var r0 = getInt32Memory0()[retptr / 4 + 0];
253
218
  var r1 = getInt32Memory0()[retptr / 4 + 1];
254
219
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -265,25 +230,70 @@ module.exports.compile = function(entry_point, contracts, dependency_graph, file
265
230
  * This is a method that exposes the same API as `compile`
266
231
  * But uses the Context based APi internally
267
232
  * @param {string} entry_point
268
- * @param {boolean | undefined} contracts
269
233
  * @param {DependencyGraph | undefined} dependency_graph
270
234
  * @param {PathToFileSourceMap} file_source_map
271
- * @returns {CompileResult}
235
+ * @returns {ContractCompileResult}
272
236
  */
273
- module.exports.compile_ = function(entry_point, contracts, dependency_graph, file_source_map) {
237
+ module.exports.compile_contract_ = function(entry_point, dependency_graph, file_source_map) {
274
238
  try {
275
239
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
276
240
  const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
277
241
  const len0 = WASM_VECTOR_LEN;
278
- if (!isLikeNone(contracts)) {
279
- _assertBoolean(contracts);
242
+ _assertClass(file_source_map, PathToFileSourceMap);
243
+ var ptr1 = file_source_map.__destroy_into_raw();
244
+ wasm.compile_contract_(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
245
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
246
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
247
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
248
+ if (r2) {
249
+ throw takeObject(r1);
280
250
  }
251
+ return takeObject(r0);
252
+ } finally {
253
+ wasm.__wbindgen_add_to_stack_pointer(16);
254
+ }
255
+ };
256
+
257
+ /**
258
+ * @param {string} entry_point
259
+ * @param {DependencyGraph | undefined} dependency_graph
260
+ * @param {PathToFileSourceMap} file_source_map
261
+ * @returns {ProgramCompileResult}
262
+ */
263
+ module.exports.compile_program = function(entry_point, dependency_graph, file_source_map) {
264
+ try {
265
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
266
+ const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
267
+ const len0 = WASM_VECTOR_LEN;
281
268
  _assertClass(file_source_map, PathToFileSourceMap);
282
- if (file_source_map.__wbg_ptr === 0) {
283
- throw new Error('Attempt to use a moved value');
269
+ var ptr1 = file_source_map.__destroy_into_raw();
270
+ wasm.compile_program(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
271
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
272
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
273
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
274
+ if (r2) {
275
+ throw takeObject(r1);
284
276
  }
277
+ return takeObject(r0);
278
+ } finally {
279
+ wasm.__wbindgen_add_to_stack_pointer(16);
280
+ }
281
+ };
282
+
283
+ /**
284
+ * @param {string} entry_point
285
+ * @param {DependencyGraph | undefined} dependency_graph
286
+ * @param {PathToFileSourceMap} file_source_map
287
+ * @returns {ContractCompileResult}
288
+ */
289
+ module.exports.compile_contract = function(entry_point, dependency_graph, file_source_map) {
290
+ try {
291
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
292
+ const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
293
+ const len0 = WASM_VECTOR_LEN;
294
+ _assertClass(file_source_map, PathToFileSourceMap);
285
295
  var ptr1 = file_source_map.__destroy_into_raw();
286
- wasm.compile_(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
296
+ wasm.compile_contract(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
287
297
  var r0 = getInt32Memory0()[retptr / 4 + 0];
288
298
  var r1 = getInt32Memory0()[retptr / 4 + 1];
289
299
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -297,10 +307,10 @@ module.exports.compile_ = function(entry_point, contracts, dependency_graph, fil
297
307
  };
298
308
 
299
309
  /**
300
- * @param {string} filter
310
+ * @param {string} level
301
311
  */
302
- module.exports.init_log_level = function(filter) {
303
- const ptr0 = passStringToWasm0(filter, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
312
+ module.exports.init_log_level = function(level) {
313
+ const ptr0 = passStringToWasm0(level, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
304
314
  const len0 = WASM_VECTOR_LEN;
305
315
  wasm.init_log_level(ptr0, len0);
306
316
  };
@@ -351,9 +361,6 @@ class CompilerContext {
351
361
  */
352
362
  constructor(source_map) {
353
363
  _assertClass(source_map, PathToFileSourceMap);
354
- if (source_map.__wbg_ptr === 0) {
355
- throw new Error('Attempt to use a moved value');
356
- }
357
364
  var ptr0 = source_map.__destroy_into_raw();
358
365
  const ret = wasm.compilercontext_new(ptr0);
359
366
  return CompilerContext.__wrap(ret);
@@ -363,8 +370,6 @@ class CompilerContext {
363
370
  * @returns {CrateId}
364
371
  */
365
372
  process_root_crate(path_to_crate) {
366
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
367
- _assertNum(this.__wbg_ptr);
368
373
  const ptr0 = passStringToWasm0(path_to_crate, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
369
374
  const len0 = WASM_VECTOR_LEN;
370
375
  const ret = wasm.compilercontext_process_root_crate(this.__wbg_ptr, ptr0, len0);
@@ -375,8 +380,6 @@ class CompilerContext {
375
380
  * @returns {CrateId}
376
381
  */
377
382
  process_dependency_crate(path_to_crate) {
378
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
379
- _assertNum(this.__wbg_ptr);
380
383
  const ptr0 = passStringToWasm0(path_to_crate, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
381
384
  const len0 = WASM_VECTOR_LEN;
382
385
  const ret = wasm.compilercontext_process_dependency_crate(this.__wbg_ptr, ptr0, len0);
@@ -389,19 +392,11 @@ class CompilerContext {
389
392
  */
390
393
  add_dependency_edge(crate_name, from, to) {
391
394
  try {
392
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
393
395
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
394
- _assertNum(this.__wbg_ptr);
395
396
  const ptr0 = passStringToWasm0(crate_name, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
396
397
  const len0 = WASM_VECTOR_LEN;
397
398
  _assertClass(from, CrateId);
398
- if (from.__wbg_ptr === 0) {
399
- throw new Error('Attempt to use a moved value');
400
- }
401
399
  _assertClass(to, CrateId);
402
- if (to.__wbg_ptr === 0) {
403
- throw new Error('Attempt to use a moved value');
404
- }
405
400
  wasm.compilercontext_add_dependency_edge(retptr, this.__wbg_ptr, ptr0, len0, from.__wbg_ptr, to.__wbg_ptr);
406
401
  var r0 = getInt32Memory0()[retptr / 4 + 0];
407
402
  var r1 = getInt32Memory0()[retptr / 4 + 1];
@@ -414,15 +409,12 @@ class CompilerContext {
414
409
  }
415
410
  /**
416
411
  * @param {number} program_width
417
- * @returns {CompileResult}
412
+ * @returns {ProgramCompileResult}
418
413
  */
419
414
  compile_program(program_width) {
420
415
  try {
421
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
422
416
  const ptr = this.__destroy_into_raw();
423
417
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
424
- _assertNum(ptr);
425
- _assertNum(program_width);
426
418
  wasm.compilercontext_compile_program(retptr, ptr, program_width);
427
419
  var r0 = getInt32Memory0()[retptr / 4 + 0];
428
420
  var r1 = getInt32Memory0()[retptr / 4 + 1];
@@ -437,15 +429,12 @@ class CompilerContext {
437
429
  }
438
430
  /**
439
431
  * @param {number} program_width
440
- * @returns {CompileResult}
432
+ * @returns {ContractCompileResult}
441
433
  */
442
434
  compile_contract(program_width) {
443
435
  try {
444
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
445
436
  const ptr = this.__destroy_into_raw();
446
437
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
447
- _assertNum(ptr);
448
- _assertNum(program_width);
449
438
  wasm.compilercontext_compile_contract(retptr, ptr, program_width);
450
439
  var r0 = getInt32Memory0()[retptr / 4 + 0];
451
440
  var r1 = getInt32Memory0()[retptr / 4 + 1];
@@ -464,10 +453,6 @@ module.exports.CompilerContext = CompilerContext;
464
453
  */
465
454
  class CrateId {
466
455
 
467
- constructor() {
468
- throw new Error('cannot invoke `new` directly');
469
- }
470
-
471
456
  static __wrap(ptr) {
472
457
  ptr = ptr >>> 0;
473
458
  const obj = Object.create(CrateId.prototype);
@@ -524,8 +509,6 @@ class PathToFileSourceMap {
524
509
  * @returns {boolean}
525
510
  */
526
511
  add_source_code(path, source_code) {
527
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
528
- _assertNum(this.__wbg_ptr);
529
512
  const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
530
513
  const len0 = WASM_VECTOR_LEN;
531
514
  const ptr1 = passStringToWasm0(source_code, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
@@ -540,36 +523,35 @@ module.exports.__wbindgen_object_drop_ref = function(arg0) {
540
523
  takeObject(arg0);
541
524
  };
542
525
 
543
- module.exports.__wbg_constructor_28ca684b2f9696ac = function() { return logError(function () {
544
- const ret = new Object();
545
- return addHeapObject(ret);
546
- }, arguments) };
547
-
548
526
  module.exports.__wbindgen_is_undefined = function(arg0) {
549
527
  const ret = getObject(arg0) === undefined;
550
- _assertBoolean(ret);
551
528
  return ret;
552
529
  };
553
530
 
554
- module.exports.__wbg_constructor_287b714b768ecf13 = function() { return logError(function (arg0) {
531
+ module.exports.__wbg_constructor_05d6d198f3477d6f = function() {
532
+ const ret = new Object();
533
+ return addHeapObject(ret);
534
+ };
535
+
536
+ module.exports.__wbg_constructor_e8767839abf8a966 = function(arg0) {
555
537
  const ret = new Error(takeObject(arg0));
556
538
  return addHeapObject(ret);
557
- }, arguments) };
539
+ };
558
540
 
559
- module.exports.__wbg_new_abda76e883ba8a5f = function() { return logError(function () {
541
+ module.exports.__wbg_new_abda76e883ba8a5f = function() {
560
542
  const ret = new Error();
561
543
  return addHeapObject(ret);
562
- }, arguments) };
544
+ };
563
545
 
564
- module.exports.__wbg_stack_658279fe44541cf6 = function() { return logError(function (arg0, arg1) {
546
+ module.exports.__wbg_stack_658279fe44541cf6 = function(arg0, arg1) {
565
547
  const ret = getObject(arg1).stack;
566
548
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
567
549
  const len1 = WASM_VECTOR_LEN;
568
550
  getInt32Memory0()[arg0 / 4 + 1] = len1;
569
551
  getInt32Memory0()[arg0 / 4 + 0] = ptr1;
570
- }, arguments) };
552
+ };
571
553
 
572
- module.exports.__wbg_error_f851667af71bcfc6 = function() { return logError(function (arg0, arg1) {
554
+ module.exports.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) {
573
555
  let deferred0_0;
574
556
  let deferred0_1;
575
557
  try {
@@ -579,52 +561,44 @@ module.exports.__wbg_error_f851667af71bcfc6 = function() { return logError(funct
579
561
  } finally {
580
562
  wasm.__wbindgen_export_2(deferred0_0, deferred0_1);
581
563
  }
582
- }, arguments) };
564
+ };
583
565
 
584
566
  module.exports.__wbindgen_string_new = function(arg0, arg1) {
585
567
  const ret = getStringFromWasm0(arg0, arg1);
586
568
  return addHeapObject(ret);
587
569
  };
588
570
 
589
- module.exports.__wbg_debug_e3f6a1578e6d45ca = function() { return logError(function (arg0) {
571
+ module.exports.__wbg_debug_e3f6a1578e6d45ca = function(arg0) {
590
572
  console.debug(getObject(arg0));
591
- }, arguments) };
573
+ };
592
574
 
593
- module.exports.__wbg_debug_efabe4eb183aa5d4 = function() { return logError(function (arg0, arg1, arg2, arg3) {
575
+ module.exports.__wbg_debug_efabe4eb183aa5d4 = function(arg0, arg1, arg2, arg3) {
594
576
  console.debug(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
595
- }, arguments) };
577
+ };
596
578
 
597
- module.exports.__wbg_error_a7e23606158b68b9 = function() { return logError(function (arg0) {
579
+ module.exports.__wbg_error_a7e23606158b68b9 = function(arg0) {
598
580
  console.error(getObject(arg0));
599
- }, arguments) };
581
+ };
600
582
 
601
- module.exports.__wbg_error_50f42b952a595a23 = function() { return logError(function (arg0, arg1, arg2, arg3) {
583
+ module.exports.__wbg_error_50f42b952a595a23 = function(arg0, arg1, arg2, arg3) {
602
584
  console.error(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
603
- }, arguments) };
585
+ };
604
586
 
605
- module.exports.__wbg_info_05db236d79f1b785 = function() { return logError(function (arg0) {
587
+ module.exports.__wbg_info_05db236d79f1b785 = function(arg0) {
606
588
  console.info(getObject(arg0));
607
- }, arguments) };
589
+ };
608
590
 
609
- module.exports.__wbg_info_24d8f53d98f12b95 = function() { return logError(function (arg0, arg1, arg2, arg3) {
591
+ module.exports.__wbg_info_24d8f53d98f12b95 = function(arg0, arg1, arg2, arg3) {
610
592
  console.info(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
611
- }, arguments) };
612
-
613
- module.exports.__wbg_log_dc06ec929fc95a20 = function() { return logError(function (arg0) {
614
- console.log(getObject(arg0));
615
- }, arguments) };
616
-
617
- module.exports.__wbg_log_2f6947e39440ae3b = function() { return logError(function (arg0, arg1, arg2, arg3, arg4) {
618
- console.log(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3), getObject(arg4));
619
- }, arguments) };
593
+ };
620
594
 
621
- module.exports.__wbg_warn_9bdd743e9f5fe1e0 = function() { return logError(function (arg0) {
595
+ module.exports.__wbg_warn_9bdd743e9f5fe1e0 = function(arg0) {
622
596
  console.warn(getObject(arg0));
623
- }, arguments) };
597
+ };
624
598
 
625
- module.exports.__wbg_warn_8342bfbc6028193a = function() { return logError(function (arg0, arg1, arg2, arg3) {
599
+ module.exports.__wbg_warn_8342bfbc6028193a = function(arg0, arg1, arg2, arg3) {
626
600
  console.warn(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
627
- }, arguments) };
601
+ };
628
602
 
629
603
  module.exports.__wbindgen_string_get = function(arg0, arg1) {
630
604
  const obj = getObject(arg1);
@@ -647,7 +621,6 @@ module.exports.__wbg_stringify_d06ad2addc54d51e = function() { return handleErro
647
621
 
648
622
  module.exports.__wbg_set_07da13cc24b69217 = function() { return handleError(function (arg0, arg1, arg2) {
649
623
  const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
650
- _assertBoolean(ret);
651
624
  return ret;
652
625
  }, arguments) };
653
626
 
@@ -686,7 +659,10 @@ module.exports.__wasm = wasm;
686
659
  Object.defineProperty(exports, "__esModule", ({ value: true }));
687
660
  exports.inflateDebugSymbols = void 0;
688
661
  const pako_1 = __webpack_require__(/*! pako */ "../../node_modules/pako/index.js");
689
- /** Decompresses and decodes the debug symbols */
662
+ /**
663
+ * Decompresses and decodes the debug symbols
664
+ * @param debugSymbols - The base64 encoded debug symbols
665
+ */
690
666
  function inflateDebugSymbols(debugSymbols) {
691
667
  return JSON.parse((0, pako_1.inflate)(Buffer.from(debugSymbols, 'base64'), { to: 'string', raw: true }));
692
668
  }
@@ -1143,8 +1119,9 @@ async function readdirRecursive(dir) {
1143
1119
  }
1144
1120
  exports.readdirRecursive = readdirRecursive;
1145
1121
  /**
1146
- * Creates a new FileManager instance based on nodejs fs
1147
- * @param dataDir - where to store files
1122
+ * Creates a new FileManager instance based on fs in node and memfs in the browser (via webpack alias)
1123
+ *
1124
+ * @param dataDir - root of the file system
1148
1125
  */
1149
1126
  function createNodejsFileManager(dataDir) {
1150
1127
  return new file_manager_1.FileManager({
@@ -1234,18 +1211,54 @@ class NoirWasmCompiler {
1234
1211
  /**
1235
1212
  * Compile EntryPoint
1236
1213
  */
1214
+ async compile_program() {
1215
+ console.log(`Compiling at ${this.#package.getEntryPointPath()}`);
1216
+ if (this.#package.getType() !== 'bin') {
1217
+ throw new Error(`Expected to find package type "bin" but found ${this.#package.getType()}`);
1218
+ }
1219
+ await this.#dependencyManager.resolveDependencies();
1220
+ this.#debugLog(`Dependencies: ${this.#dependencyManager.getPackageNames().join(', ')}`);
1221
+ try {
1222
+ const entrypoint = this.#package.getEntryPointPath();
1223
+ const deps = {
1224
+ /* eslint-disable camelcase */
1225
+ root_dependencies: this.#dependencyManager.getEntrypointDependencies(),
1226
+ library_dependencies: this.#dependencyManager.getLibraryDependencies(),
1227
+ /* eslint-enable camelcase */
1228
+ };
1229
+ const packageSources = await this.#package.getSources(this.#fm);
1230
+ const librarySources = (await Promise.all(this.#dependencyManager
1231
+ .getLibraries()
1232
+ .map(async ([alias, library]) => await library.package.getSources(this.#fm, alias)))).flat();
1233
+ [...packageSources, ...librarySources].forEach((sourceFile) => {
1234
+ this.#debugLog(`Adding source ${sourceFile.path}`);
1235
+ this.#sourceMap.add_source_code(sourceFile.path, sourceFile.source);
1236
+ });
1237
+ const result = this.#wasmCompiler.compile_program(entrypoint, deps, this.#sourceMap);
1238
+ return result;
1239
+ }
1240
+ catch (err) {
1241
+ if (err instanceof Error && err.name === 'CompileError') {
1242
+ const logs = await this.#processCompileError(err);
1243
+ for (const log of logs) {
1244
+ this.#log(log);
1245
+ }
1246
+ throw new Error(logs.join('\n'));
1247
+ }
1248
+ throw err;
1249
+ }
1250
+ }
1237
1251
  /**
1238
1252
  * Compile EntryPoint
1239
1253
  */
1240
- async compile() {
1254
+ async compile_contract() {
1241
1255
  console.log(`Compiling at ${this.#package.getEntryPointPath()}`);
1242
- if (!(this.#package.getType() === 'contract' || this.#package.getType() === 'bin')) {
1243
- throw new Error(`Only supports compiling "contract" and "bin" package types (${this.#package.getType()})`);
1256
+ if (this.#package.getType() !== 'contract') {
1257
+ throw new Error(`Expected to find package type "contract" but found ${this.#package.getType()}`);
1244
1258
  }
1245
1259
  await this.#dependencyManager.resolveDependencies();
1246
1260
  this.#debugLog(`Dependencies: ${this.#dependencyManager.getPackageNames().join(', ')}`);
1247
1261
  try {
1248
- const isContract = this.#package.getType() === 'contract';
1249
1262
  const entrypoint = this.#package.getEntryPointPath();
1250
1263
  const deps = {
1251
1264
  /* eslint-disable camelcase */
@@ -1261,10 +1274,7 @@ class NoirWasmCompiler {
1261
1274
  this.#debugLog(`Adding source ${sourceFile.path}`);
1262
1275
  this.#sourceMap.add_source_code(sourceFile.path, sourceFile.source);
1263
1276
  });
1264
- const result = this.#wasmCompiler.compile(entrypoint, isContract, deps, this.#sourceMap);
1265
- if ((isContract && !('contract' in result)) || (!isContract && !('program' in result))) {
1266
- throw new Error('Invalid compilation result');
1267
- }
1277
+ const result = this.#wasmCompiler.compile_contract(entrypoint, deps, this.#sourceMap);
1268
1278
  return result;
1269
1279
  }
1270
1280
  catch (err) {
@@ -1393,7 +1403,7 @@ class Package {
1393
1403
  * Gets this package's dependencies.
1394
1404
  */
1395
1405
  getDependencies() {
1396
- return this.#config.dependencies;
1406
+ return this.#config.dependencies ?? {};
1397
1407
  }
1398
1408
  /**
1399
1409
  * Gets this package's sources.
@@ -12813,17 +12823,88 @@ var exports = __webpack_exports__;
12813
12823
  \***********************/
12814
12824
 
12815
12825
  Object.defineProperty(exports, "__esModule", ({ value: true }));
12816
- exports.inflateDebugSymbols = exports.createFileManager = exports.compile = void 0;
12826
+ exports.inflateDebugSymbols = exports.createFileManager = exports.compile_contract = exports.compile_program = exports.compile = void 0;
12817
12827
  const nodejs_file_manager_1 = __webpack_require__(/*! ./noir/file-manager/nodejs-file-manager */ "./src/noir/file-manager/nodejs-file-manager.ts");
12818
12828
  const noir_wasm_compiler_1 = __webpack_require__(/*! ./noir/noir-wasm-compiler */ "./src/noir/noir-wasm-compiler.ts");
12819
12829
  const debug_1 = __webpack_require__(/*! ./noir/debug */ "./src/noir/debug.ts");
12820
12830
  Object.defineProperty(exports, "inflateDebugSymbols", ({ enumerable: true, get: function () { return debug_1.inflateDebugSymbols; } }));
12821
- async function compile(fileManager, projectPath, logFn, debugLogFn) {
12831
+ /**
12832
+ * Compiles a Noir project
12833
+ *
12834
+ * @param fileManager - The file manager to use
12835
+ * @param projectPath - The path to the project inside the file manager. Defaults to the root of the file manager
12836
+ * @param logFn - A logging function. If not provided, console.log will be used
12837
+ * @param debugLogFn - A debug logging function. If not provided, logFn will be used
12838
+ *
12839
+ * @example
12840
+ * ```typescript
12841
+ * // Node.js
12842
+ *
12843
+ * import { compile_program, createFileManager } from '@noir-lang/noir_wasm';
12844
+ *
12845
+ * const fm = createFileManager(myProjectPath);
12846
+ * const myCompiledCode = await compile_program(fm);
12847
+ * ```
12848
+ *
12849
+ * ```typescript
12850
+ * // Browser
12851
+ *
12852
+ * import { compile_program, createFileManager } from '@noir-lang/noir_wasm';
12853
+ *
12854
+ * const fm = createFileManager('/');
12855
+ * for (const path of files) {
12856
+ * await fm.writeFile(path, await getFileAsStream(path));
12857
+ * }
12858
+ * const myCompiledCode = await compile_program(fm);
12859
+ * ```
12860
+ */
12861
+ async function compile_program(fileManager, projectPath, logFn, debugLogFn) {
12862
+ const compiler = await setup_compiler(fileManager, projectPath, logFn, debugLogFn);
12863
+ return await compiler.compile_program();
12864
+ }
12865
+ exports.compile = compile_program;
12866
+ exports.compile_program = compile_program;
12867
+ /**
12868
+ * Compiles a Noir project
12869
+ *
12870
+ * @param fileManager - The file manager to use
12871
+ * @param projectPath - The path to the project inside the file manager. Defaults to the root of the file manager
12872
+ * @param logFn - A logging function. If not provided, console.log will be used
12873
+ * @param debugLogFn - A debug logging function. If not provided, logFn will be used
12874
+ *
12875
+ * @example
12876
+ * ```typescript
12877
+ * // Node.js
12878
+ *
12879
+ * import { compile_contract, createFileManager } from '@noir-lang/noir_wasm';
12880
+ *
12881
+ * const fm = createFileManager(myProjectPath);
12882
+ * const myCompiledCode = await compile_contract(fm);
12883
+ * ```
12884
+ *
12885
+ * ```typescript
12886
+ * // Browser
12887
+ *
12888
+ * import { compile_contract, createFileManager } from '@noir-lang/noir_wasm';
12889
+ *
12890
+ * const fm = createFileManager('/');
12891
+ * for (const path of files) {
12892
+ * await fm.writeFile(path, await getFileAsStream(path));
12893
+ * }
12894
+ * const myCompiledCode = await compile_contract(fm);
12895
+ * ```
12896
+ */
12897
+ async function compile_contract(fileManager, projectPath, logFn, debugLogFn) {
12898
+ const compiler = await setup_compiler(fileManager, projectPath, logFn, debugLogFn);
12899
+ return await compiler.compile_contract();
12900
+ }
12901
+ exports.compile_contract = compile_contract;
12902
+ async function setup_compiler(fileManager, projectPath, logFn, debugLogFn) {
12822
12903
  if (logFn && !debugLogFn) {
12823
12904
  debugLogFn = logFn;
12824
12905
  }
12825
12906
  const cjs = await __webpack_require__(/*! ../build/cjs */ "./build/cjs/index.js");
12826
- const compiler = await noir_wasm_compiler_1.NoirWasmCompiler.new(fileManager, projectPath ?? fileManager.getDataDir(), cjs, new cjs.PathToFileSourceMap(), {
12907
+ return await noir_wasm_compiler_1.NoirWasmCompiler.new(fileManager, projectPath ?? fileManager.getDataDir(), cjs, new cjs.PathToFileSourceMap(), {
12827
12908
  log: logFn ??
12828
12909
  function (msg, data) {
12829
12910
  if (data) {
@@ -12843,9 +12924,7 @@ async function compile(fileManager, projectPath, logFn, debugLogFn) {
12843
12924
  }
12844
12925
  },
12845
12926
  });
12846
- return await compiler.compile();
12847
12927
  }
12848
- exports.compile = compile;
12849
12928
  const createFileManager = nodejs_file_manager_1.createNodejsFileManager;
12850
12929
  exports.createFileManager = createFileManager;
12851
12930