@noir-lang/noir_wasm 0.23.0 → 0.24.0-6169a5b.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 +24 -1
- package/build/cjs/package.json +1 -1
- package/build/esm/package.json +1 -1
- package/dist/node/index_bg.wasm +0 -0
- package/dist/node/main.js +76 -43
- package/dist/node/main.js.map +1 -1
- package/dist/types/build/cjs/index.d.ts +4 -4
- package/dist/types/build/esm/index.d.ts +4 -4
- package/dist/types/src/index.d.cts +30 -0
- package/dist/types/src/index.d.mts +30 -0
- package/dist/types/src/noir/debug.d.ts +4 -1
- package/dist/types/src/noir/file-manager/nodejs-file-manager.d.ts +3 -2
- package/dist/types/src/types/noir_artifact.d.ts +1 -1
- package/dist/types/webpack.config.d.ts +0 -1
- package/dist/web/main.mjs +76 -43
- package/dist/web/main.mjs.map +1 -1
- package/package.json +10 -6
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:
|
package/build/cjs/package.json
CHANGED
package/build/esm/package.json
CHANGED
package/dist/node/index_bg.wasm
CHANGED
|
Binary file
|
package/dist/node/main.js
CHANGED
|
@@ -18,6 +18,12 @@ heap.push(undefined, null, true, false);
|
|
|
18
18
|
|
|
19
19
|
function getObject(idx) { return heap[idx]; }
|
|
20
20
|
|
|
21
|
+
function _assertBoolean(n) {
|
|
22
|
+
if (typeof(n) !== 'boolean') {
|
|
23
|
+
throw new Error('expected a boolean argument');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
21
27
|
let heap_next = heap.length;
|
|
22
28
|
|
|
23
29
|
function dropObject(idx) {
|
|
@@ -32,12 +38,6 @@ function takeObject(idx) {
|
|
|
32
38
|
return ret;
|
|
33
39
|
}
|
|
34
40
|
|
|
35
|
-
function _assertBoolean(n) {
|
|
36
|
-
if (typeof(n) !== 'boolean') {
|
|
37
|
-
throw new Error('expected a boolean argument');
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
41
|
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
42
42
|
|
|
43
43
|
cachedTextDecoder.decode();
|
|
@@ -202,40 +202,26 @@ function debugString(val) {
|
|
|
202
202
|
return className;
|
|
203
203
|
}
|
|
204
204
|
|
|
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
205
|
function _assertClass(instance, klass) {
|
|
226
206
|
if (!(instance instanceof klass)) {
|
|
227
207
|
throw new Error(`expected instance of ${klass.name}`);
|
|
228
208
|
}
|
|
229
209
|
return instance.ptr;
|
|
230
210
|
}
|
|
211
|
+
|
|
212
|
+
function _assertNum(n) {
|
|
213
|
+
if (typeof(n) !== 'number') throw new Error('expected a number argument');
|
|
214
|
+
}
|
|
231
215
|
/**
|
|
216
|
+
* This is a method that exposes the same API as `compile`
|
|
217
|
+
* But uses the Context based APi internally
|
|
232
218
|
* @param {string} entry_point
|
|
233
219
|
* @param {boolean | undefined} contracts
|
|
234
220
|
* @param {DependencyGraph | undefined} dependency_graph
|
|
235
221
|
* @param {PathToFileSourceMap} file_source_map
|
|
236
222
|
* @returns {CompileResult}
|
|
237
223
|
*/
|
|
238
|
-
module.exports.
|
|
224
|
+
module.exports.compile_ = function(entry_point, contracts, dependency_graph, file_source_map) {
|
|
239
225
|
try {
|
|
240
226
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
241
227
|
const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|
|
@@ -248,7 +234,7 @@ module.exports.compile = function(entry_point, contracts, dependency_graph, file
|
|
|
248
234
|
throw new Error('Attempt to use a moved value');
|
|
249
235
|
}
|
|
250
236
|
var ptr1 = file_source_map.__destroy_into_raw();
|
|
251
|
-
wasm.
|
|
237
|
+
wasm.compile_(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
|
|
252
238
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
253
239
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
254
240
|
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
@@ -261,16 +247,29 @@ module.exports.compile = function(entry_point, contracts, dependency_graph, file
|
|
|
261
247
|
}
|
|
262
248
|
};
|
|
263
249
|
|
|
250
|
+
function logError(f, args) {
|
|
251
|
+
try {
|
|
252
|
+
return f.apply(this, args);
|
|
253
|
+
} catch (e) {
|
|
254
|
+
let error = (function () {
|
|
255
|
+
try {
|
|
256
|
+
return e instanceof Error ? `${e.message}\n\nStack:\n${e.stack}` : e.toString();
|
|
257
|
+
} catch(_) {
|
|
258
|
+
return "<failed to stringify thrown value>";
|
|
259
|
+
}
|
|
260
|
+
}());
|
|
261
|
+
console.error("wasm-bindgen: imported JS function that was not marked as `catch` threw an error:", error);
|
|
262
|
+
throw e;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
264
265
|
/**
|
|
265
|
-
* This is a method that exposes the same API as `compile`
|
|
266
|
-
* But uses the Context based APi internally
|
|
267
266
|
* @param {string} entry_point
|
|
268
267
|
* @param {boolean | undefined} contracts
|
|
269
268
|
* @param {DependencyGraph | undefined} dependency_graph
|
|
270
269
|
* @param {PathToFileSourceMap} file_source_map
|
|
271
270
|
* @returns {CompileResult}
|
|
272
271
|
*/
|
|
273
|
-
module.exports.
|
|
272
|
+
module.exports.compile = function(entry_point, contracts, dependency_graph, file_source_map) {
|
|
274
273
|
try {
|
|
275
274
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
276
275
|
const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
|
|
@@ -283,7 +282,7 @@ module.exports.compile_ = function(entry_point, contracts, dependency_graph, fil
|
|
|
283
282
|
throw new Error('Attempt to use a moved value');
|
|
284
283
|
}
|
|
285
284
|
var ptr1 = file_source_map.__destroy_into_raw();
|
|
286
|
-
wasm.
|
|
285
|
+
wasm.compile(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
|
|
287
286
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
288
287
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
289
288
|
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
@@ -536,22 +535,22 @@ class PathToFileSourceMap {
|
|
|
536
535
|
}
|
|
537
536
|
module.exports.PathToFileSourceMap = PathToFileSourceMap;
|
|
538
537
|
|
|
538
|
+
module.exports.__wbindgen_is_undefined = function(arg0) {
|
|
539
|
+
const ret = getObject(arg0) === undefined;
|
|
540
|
+
_assertBoolean(ret);
|
|
541
|
+
return ret;
|
|
542
|
+
};
|
|
543
|
+
|
|
539
544
|
module.exports.__wbindgen_object_drop_ref = function(arg0) {
|
|
540
545
|
takeObject(arg0);
|
|
541
546
|
};
|
|
542
547
|
|
|
543
|
-
module.exports.
|
|
548
|
+
module.exports.__wbg_constructor_05d6d198f3477d6f = function() { return logError(function () {
|
|
544
549
|
const ret = new Object();
|
|
545
550
|
return addHeapObject(ret);
|
|
546
551
|
}, arguments) };
|
|
547
552
|
|
|
548
|
-
module.exports.
|
|
549
|
-
const ret = getObject(arg0) === undefined;
|
|
550
|
-
_assertBoolean(ret);
|
|
551
|
-
return ret;
|
|
552
|
-
};
|
|
553
|
-
|
|
554
|
-
module.exports.__wbg_constructor_287b714b768ecf13 = function() { return logError(function (arg0) {
|
|
553
|
+
module.exports.__wbg_constructor_e8767839abf8a966 = function() { return logError(function (arg0) {
|
|
555
554
|
const ret = new Error(takeObject(arg0));
|
|
556
555
|
return addHeapObject(ret);
|
|
557
556
|
}, arguments) };
|
|
@@ -686,7 +685,10 @@ module.exports.__wasm = wasm;
|
|
|
686
685
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
687
686
|
exports.inflateDebugSymbols = void 0;
|
|
688
687
|
const pako_1 = __webpack_require__(/*! pako */ "../../node_modules/pako/index.js");
|
|
689
|
-
/**
|
|
688
|
+
/**
|
|
689
|
+
* Decompresses and decodes the debug symbols
|
|
690
|
+
* @param debugSymbols - The base64 encoded debug symbols
|
|
691
|
+
*/
|
|
690
692
|
function inflateDebugSymbols(debugSymbols) {
|
|
691
693
|
return JSON.parse((0, pako_1.inflate)(Buffer.from(debugSymbols, 'base64'), { to: 'string', raw: true }));
|
|
692
694
|
}
|
|
@@ -1143,8 +1145,9 @@ async function readdirRecursive(dir) {
|
|
|
1143
1145
|
}
|
|
1144
1146
|
exports.readdirRecursive = readdirRecursive;
|
|
1145
1147
|
/**
|
|
1146
|
-
* Creates a new FileManager instance based on
|
|
1147
|
-
*
|
|
1148
|
+
* Creates a new FileManager instance based on fs in node and memfs in the browser (via webpack alias)
|
|
1149
|
+
*
|
|
1150
|
+
* @param dataDir - root of the file system
|
|
1148
1151
|
*/
|
|
1149
1152
|
function createNodejsFileManager(dataDir) {
|
|
1150
1153
|
return new file_manager_1.FileManager({
|
|
@@ -12818,6 +12821,36 @@ const nodejs_file_manager_1 = __webpack_require__(/*! ./noir/file-manager/nodejs
|
|
|
12818
12821
|
const noir_wasm_compiler_1 = __webpack_require__(/*! ./noir/noir-wasm-compiler */ "./src/noir/noir-wasm-compiler.ts");
|
|
12819
12822
|
const debug_1 = __webpack_require__(/*! ./noir/debug */ "./src/noir/debug.ts");
|
|
12820
12823
|
Object.defineProperty(exports, "inflateDebugSymbols", ({ enumerable: true, get: function () { return debug_1.inflateDebugSymbols; } }));
|
|
12824
|
+
/**
|
|
12825
|
+
* Compiles a Noir project
|
|
12826
|
+
*
|
|
12827
|
+
* @param fileManager - The file manager to use
|
|
12828
|
+
* @param projectPath - The path to the project inside the file manager. Defaults to the root of the file manager
|
|
12829
|
+
* @param logFn - A logging function. If not provided, console.log will be used
|
|
12830
|
+
* @param debugLogFn - A debug logging function. If not provided, logFn will be used
|
|
12831
|
+
*
|
|
12832
|
+
* @example
|
|
12833
|
+
* ```typescript
|
|
12834
|
+
* // Node.js
|
|
12835
|
+
*
|
|
12836
|
+
* import { compile, createFileManager } from '@noir-lang/noir_wasm';
|
|
12837
|
+
*
|
|
12838
|
+
* const fm = createFileManager(myProjectPath);
|
|
12839
|
+
* const myCompiledCode = await compile(fm);
|
|
12840
|
+
* ```
|
|
12841
|
+
*
|
|
12842
|
+
* ```typescript
|
|
12843
|
+
* // Browser
|
|
12844
|
+
*
|
|
12845
|
+
* import { compile, createFileManager } from '@noir-lang/noir_wasm';
|
|
12846
|
+
*
|
|
12847
|
+
* const fm = createFileManager('/');
|
|
12848
|
+
* for (const path of files) {
|
|
12849
|
+
* await fm.writeFile(path, await getFileAsStream(path));
|
|
12850
|
+
* }
|
|
12851
|
+
* const myCompiledCode = await compile(fm);
|
|
12852
|
+
* ```
|
|
12853
|
+
*/
|
|
12821
12854
|
async function compile(fileManager, projectPath, logFn, debugLogFn) {
|
|
12822
12855
|
if (logFn && !debugLogFn) {
|
|
12823
12856
|
debugLogFn = logFn;
|