@noir-lang/noir_wasm 0.6.0 → 0.11.0

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/noir_wasm.d.ts CHANGED
@@ -15,3 +15,42 @@ export function acir_from_bytes(bytes: Uint8Array): any;
15
15
  * @returns {Uint8Array}
16
16
  */
17
17
  export function acir_to_bytes(acir: any): Uint8Array;
18
+
19
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
20
+
21
+ export interface InitOutput {
22
+ readonly memory: WebAssembly.Memory;
23
+ readonly compile: (a: number, b: number) => number;
24
+ readonly acir_from_bytes: (a: number, b: number) => number;
25
+ readonly acir_to_bytes: (a: number, b: number) => void;
26
+ readonly rust_psm_on_stack: (a: number, b: number, c: number, d: number) => void;
27
+ readonly rust_psm_stack_direction: () => number;
28
+ readonly rust_psm_stack_pointer: () => number;
29
+ readonly rust_psm_replace_stack: (a: number, b: number, c: number) => void;
30
+ readonly __wbindgen_export_0: (a: number) => number;
31
+ readonly __wbindgen_export_1: (a: number, b: number, c: number) => number;
32
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
33
+ readonly __wbindgen_export_2: (a: number, b: number) => void;
34
+ readonly __wbindgen_export_3: (a: number) => void;
35
+ }
36
+
37
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
38
+ /**
39
+ * Instantiates the given `module`, which can either be bytes or
40
+ * a precompiled `WebAssembly.Module`.
41
+ *
42
+ * @param {SyncInitInput} module
43
+ *
44
+ * @returns {InitOutput}
45
+ */
46
+ export function initSync(module: SyncInitInput): InitOutput;
47
+
48
+ /**
49
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
50
+ * for everything else, calls `WebAssembly.instantiate` directly.
51
+ *
52
+ * @param {InitInput | Promise<InitInput>} module_or_path
53
+ *
54
+ * @returns {Promise<InitOutput>}
55
+ */
56
+ export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
package/noir_wasm.js CHANGED
@@ -1,16 +1,10 @@
1
- let imports = {};
2
- imports['__wbindgen_placeholder__'] = module.exports;
3
- let wasm;
4
- const { read_file } = require(String.raw`./snippets/fm-cffb18dcbd478425/file_reader.js`);
5
- const { TextEncoder, TextDecoder } = require(`util`);
6
-
7
- const heap = new Array(32).fill(undefined);
1
+ import { read_file } from './snippets/fm-cffb18dcbd478425/file_reader.js';
8
2
 
9
- heap.push(undefined, null, true, false);
3
+ let wasm;
10
4
 
11
- function getObject(idx) { return heap[idx]; }
5
+ const cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
12
6
 
13
- let WASM_VECTOR_LEN = 0;
7
+ cachedTextDecoder.decode();
14
8
 
15
9
  let cachedUint8Memory0 = new Uint8Array();
16
10
 
@@ -21,7 +15,30 @@ function getUint8Memory0() {
21
15
  return cachedUint8Memory0;
22
16
  }
23
17
 
24
- let cachedTextEncoder = new TextEncoder('utf-8');
18
+ function getStringFromWasm0(ptr, len) {
19
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
20
+ }
21
+
22
+ const heap = new Array(32).fill(undefined);
23
+
24
+ heap.push(undefined, null, true, false);
25
+
26
+ let heap_next = heap.length;
27
+
28
+ function addHeapObject(obj) {
29
+ if (heap_next === heap.length) heap.push(heap.length + 1);
30
+ const idx = heap_next;
31
+ heap_next = heap[idx];
32
+
33
+ heap[idx] = obj;
34
+ return idx;
35
+ }
36
+
37
+ function getObject(idx) { return heap[idx]; }
38
+
39
+ let WASM_VECTOR_LEN = 0;
40
+
41
+ const cachedTextEncoder = new TextEncoder('utf-8');
25
42
 
26
43
  const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
27
44
  ? function (arg, view) {
@@ -83,8 +100,6 @@ function getInt32Memory0() {
83
100
  return cachedInt32Memory0;
84
101
  }
85
102
 
86
- let heap_next = heap.length;
87
-
88
103
  function dropObject(idx) {
89
104
  if (idx < 36) return;
90
105
  heap[idx] = heap_next;
@@ -96,33 +111,16 @@ function takeObject(idx) {
96
111
  dropObject(idx);
97
112
  return ret;
98
113
  }
99
-
100
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
101
-
102
- cachedTextDecoder.decode();
103
-
104
- function getStringFromWasm0(ptr, len) {
105
- return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
106
- }
107
-
108
- function addHeapObject(obj) {
109
- if (heap_next === heap.length) heap.push(heap.length + 1);
110
- const idx = heap_next;
111
- heap_next = heap[idx];
112
-
113
- heap[idx] = obj;
114
- return idx;
115
- }
116
114
  /**
117
115
  * @param {string} src
118
116
  * @returns {any}
119
117
  */
120
- module.exports.compile = function(src) {
118
+ export function compile(src) {
121
119
  const ptr0 = passStringToWasm0(src, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
122
120
  const len0 = WASM_VECTOR_LEN;
123
121
  const ret = wasm.compile(ptr0, len0);
124
122
  return takeObject(ret);
125
- };
123
+ }
126
124
 
127
125
  function passArray8ToWasm0(arg, malloc) {
128
126
  const ptr = malloc(arg.length * 1);
@@ -134,12 +132,12 @@ function passArray8ToWasm0(arg, malloc) {
134
132
  * @param {Uint8Array} bytes
135
133
  * @returns {any}
136
134
  */
137
- module.exports.acir_from_bytes = function(bytes) {
135
+ export function acir_from_bytes(bytes) {
138
136
  const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export_0);
139
137
  const len0 = WASM_VECTOR_LEN;
140
138
  const ret = wasm.acir_from_bytes(ptr0, len0);
141
139
  return takeObject(ret);
142
- };
140
+ }
143
141
 
144
142
  function getArrayU8FromWasm0(ptr, len) {
145
143
  return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
@@ -148,7 +146,7 @@ function getArrayU8FromWasm0(ptr, len) {
148
146
  * @param {any} acir
149
147
  * @returns {Uint8Array}
150
148
  */
151
- module.exports.acir_to_bytes = function(acir) {
149
+ export function acir_to_bytes(acir) {
152
150
  try {
153
151
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
154
152
  wasm.acir_to_bytes(retptr, addHeapObject(acir));
@@ -160,7 +158,7 @@ module.exports.acir_to_bytes = function(acir) {
160
158
  } finally {
161
159
  wasm.__wbindgen_add_to_stack_pointer(16);
162
160
  }
163
- };
161
+ }
164
162
 
165
163
  function handleError(f, args) {
166
164
  try {
@@ -170,190 +168,128 @@ function handleError(f, args) {
170
168
  }
171
169
  }
172
170
 
173
- module.exports.__wbindgen_json_serialize = function(arg0, arg1) {
174
- const obj = getObject(arg1);
175
- const ret = JSON.stringify(obj === undefined ? null : obj);
176
- const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
177
- const len0 = WASM_VECTOR_LEN;
178
- getInt32Memory0()[arg0 / 4 + 1] = len0;
179
- getInt32Memory0()[arg0 / 4 + 0] = ptr0;
180
- };
181
-
182
- module.exports.__wbindgen_object_drop_ref = function(arg0) {
183
- takeObject(arg0);
184
- };
185
-
186
- module.exports.__wbindgen_json_parse = function(arg0, arg1) {
187
- const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
188
- return addHeapObject(ret);
189
- };
190
-
191
- module.exports.__wbg_readfile_381ecedf0ec0c1aa = function() { return handleError(function (arg0, arg1, arg2) {
192
- const ret = read_file(getStringFromWasm0(arg1, arg2));
193
- const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
194
- const len0 = WASM_VECTOR_LEN;
195
- getInt32Memory0()[arg0 / 4 + 1] = len0;
196
- getInt32Memory0()[arg0 / 4 + 0] = ptr0;
197
- }, arguments) };
198
-
199
- module.exports.__wbg_new_693216e109162396 = function() {
200
- const ret = new Error();
201
- return addHeapObject(ret);
202
- };
203
-
204
- module.exports.__wbg_stack_0ddaca5d1abfb52f = function(arg0, arg1) {
205
- const ret = getObject(arg1).stack;
206
- const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
207
- const len0 = WASM_VECTOR_LEN;
208
- getInt32Memory0()[arg0 / 4 + 1] = len0;
209
- getInt32Memory0()[arg0 / 4 + 0] = ptr0;
210
- };
171
+ async function load(module, imports) {
172
+ if (typeof Response === 'function' && module instanceof Response) {
173
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
174
+ try {
175
+ return await WebAssembly.instantiateStreaming(module, imports);
211
176
 
212
- module.exports.__wbg_error_09919627ac0992f5 = function(arg0, arg1) {
213
- try {
214
- console.error(getStringFromWasm0(arg0, arg1));
215
- } finally {
216
- wasm.__wbindgen_export_2(arg0, arg1);
177
+ } catch (e) {
178
+ if (module.headers.get('Content-Type') != 'application/wasm') {
179
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
180
+
181
+ } else {
182
+ throw e;
183
+ }
184
+ }
185
+ }
186
+
187
+ const bytes = await module.arrayBuffer();
188
+ return await WebAssembly.instantiate(bytes, imports);
189
+
190
+ } else {
191
+ const instance = await WebAssembly.instantiate(module, imports);
192
+
193
+ if (instance instanceof WebAssembly.Instance) {
194
+ return { instance, module };
195
+
196
+ } else {
197
+ return instance;
198
+ }
217
199
  }
218
- };
200
+ }
219
201
 
220
- module.exports.__wbg_randomFillSync_91e2b39becca6147 = function() { return handleError(function (arg0, arg1, arg2) {
221
- getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2));
222
- }, arguments) };
202
+ function getImports() {
203
+ const imports = {};
204
+ imports.wbg = {};
205
+ imports.wbg.__wbindgen_json_parse = function(arg0, arg1) {
206
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
207
+ return addHeapObject(ret);
208
+ };
209
+ imports.wbg.__wbindgen_json_serialize = function(arg0, arg1) {
210
+ const obj = getObject(arg1);
211
+ const ret = JSON.stringify(obj === undefined ? null : obj);
212
+ const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
213
+ const len0 = WASM_VECTOR_LEN;
214
+ getInt32Memory0()[arg0 / 4 + 1] = len0;
215
+ getInt32Memory0()[arg0 / 4 + 0] = ptr0;
216
+ };
217
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
218
+ takeObject(arg0);
219
+ };
220
+ imports.wbg.__wbg_readfile_a255adfa6d841e23 = function() { return handleError(function (arg0, arg1, arg2) {
221
+ const ret = read_file(getStringFromWasm0(arg1, arg2));
222
+ const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
223
+ const len0 = WASM_VECTOR_LEN;
224
+ getInt32Memory0()[arg0 / 4 + 1] = len0;
225
+ getInt32Memory0()[arg0 / 4 + 0] = ptr0;
226
+ }, arguments) };
227
+ imports.wbg.__wbg_new_abda76e883ba8a5f = function() {
228
+ const ret = new Error();
229
+ return addHeapObject(ret);
230
+ };
231
+ imports.wbg.__wbg_stack_658279fe44541cf6 = function(arg0, arg1) {
232
+ const ret = getObject(arg1).stack;
233
+ const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
234
+ const len0 = WASM_VECTOR_LEN;
235
+ getInt32Memory0()[arg0 / 4 + 1] = len0;
236
+ getInt32Memory0()[arg0 / 4 + 0] = ptr0;
237
+ };
238
+ imports.wbg.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) {
239
+ try {
240
+ console.error(getStringFromWasm0(arg0, arg1));
241
+ } finally {
242
+ wasm.__wbindgen_export_2(arg0, arg1);
243
+ }
244
+ };
223
245
 
224
- module.exports.__wbg_getRandomValues_b14734aa289bc356 = function() { return handleError(function (arg0, arg1) {
225
- getObject(arg0).getRandomValues(getObject(arg1));
226
- }, arguments) };
246
+ return imports;
247
+ }
227
248
 
228
- module.exports.__wbg_process_e56fd54cf6319b6c = function(arg0) {
229
- const ret = getObject(arg0).process;
230
- return addHeapObject(ret);
231
- };
249
+ function initMemory(imports, maybe_memory) {
232
250
 
233
- module.exports.__wbindgen_is_object = function(arg0) {
234
- const val = getObject(arg0);
235
- const ret = typeof(val) === 'object' && val !== null;
236
- return ret;
237
- };
251
+ }
238
252
 
239
- module.exports.__wbg_versions_77e21455908dad33 = function(arg0) {
240
- const ret = getObject(arg0).versions;
241
- return addHeapObject(ret);
242
- };
253
+ function finalizeInit(instance, module) {
254
+ wasm = instance.exports;
255
+ init.__wbindgen_wasm_module = module;
256
+ cachedInt32Memory0 = new Int32Array();
257
+ cachedUint8Memory0 = new Uint8Array();
243
258
 
244
- module.exports.__wbg_node_0dd25d832e4785d5 = function(arg0) {
245
- const ret = getObject(arg0).node;
246
- return addHeapObject(ret);
247
- };
248
259
 
249
- module.exports.__wbindgen_is_string = function(arg0) {
250
- const ret = typeof(getObject(arg0)) === 'string';
251
- return ret;
252
- };
253
-
254
- module.exports.__wbg_crypto_b95d7173266618a9 = function(arg0) {
255
- const ret = getObject(arg0).crypto;
256
- return addHeapObject(ret);
257
- };
258
-
259
- module.exports.__wbg_msCrypto_5a86d77a66230f81 = function(arg0) {
260
- const ret = getObject(arg0).msCrypto;
261
- return addHeapObject(ret);
262
- };
263
-
264
- module.exports.__wbg_static_accessor_NODE_MODULE_26b231378c1be7dd = function() {
265
- const ret = module;
266
- return addHeapObject(ret);
267
- };
268
-
269
- module.exports.__wbg_require_0db1598d9ccecb30 = function() { return handleError(function (arg0, arg1, arg2) {
270
- const ret = getObject(arg0).require(getStringFromWasm0(arg1, arg2));
271
- return addHeapObject(ret);
272
- }, arguments) };
273
-
274
- module.exports.__wbg_newnoargs_971e9a5abe185139 = function(arg0, arg1) {
275
- const ret = new Function(getStringFromWasm0(arg0, arg1));
276
- return addHeapObject(ret);
277
- };
278
-
279
- module.exports.__wbg_call_33d7bcddbbfa394a = function() { return handleError(function (arg0, arg1) {
280
- const ret = getObject(arg0).call(getObject(arg1));
281
- return addHeapObject(ret);
282
- }, arguments) };
283
-
284
- module.exports.__wbindgen_object_clone_ref = function(arg0) {
285
- const ret = getObject(arg0);
286
- return addHeapObject(ret);
287
- };
288
-
289
- module.exports.__wbg_self_fd00a1ef86d1b2ed = function() { return handleError(function () {
290
- const ret = self.self;
291
- return addHeapObject(ret);
292
- }, arguments) };
293
-
294
- module.exports.__wbg_window_6f6e346d8bbd61d7 = function() { return handleError(function () {
295
- const ret = window.window;
296
- return addHeapObject(ret);
297
- }, arguments) };
298
-
299
- module.exports.__wbg_globalThis_3348936ac49df00a = function() { return handleError(function () {
300
- const ret = globalThis.globalThis;
301
- return addHeapObject(ret);
302
- }, arguments) };
303
-
304
- module.exports.__wbg_global_67175caf56f55ca9 = function() { return handleError(function () {
305
- const ret = global.global;
306
- return addHeapObject(ret);
307
- }, arguments) };
308
-
309
- module.exports.__wbindgen_is_undefined = function(arg0) {
310
- const ret = getObject(arg0) === undefined;
311
- return ret;
312
- };
260
+ return wasm;
261
+ }
313
262
 
314
- module.exports.__wbg_buffer_34f5ec9f8a838ba0 = function(arg0) {
315
- const ret = getObject(arg0).buffer;
316
- return addHeapObject(ret);
317
- };
263
+ function initSync(module) {
264
+ const imports = getImports();
318
265
 
319
- module.exports.__wbg_new_cda198d9dbc6d7ea = function(arg0) {
320
- const ret = new Uint8Array(getObject(arg0));
321
- return addHeapObject(ret);
322
- };
266
+ initMemory(imports);
323
267
 
324
- module.exports.__wbg_set_1a930cfcda1a8067 = function(arg0, arg1, arg2) {
325
- getObject(arg0).set(getObject(arg1), arg2 >>> 0);
326
- };
268
+ if (!(module instanceof WebAssembly.Module)) {
269
+ module = new WebAssembly.Module(module);
270
+ }
327
271
 
328
- module.exports.__wbg_length_51f19f73d6d9eff3 = function(arg0) {
329
- const ret = getObject(arg0).length;
330
- return ret;
331
- };
272
+ const instance = new WebAssembly.Instance(module, imports);
332
273
 
333
- module.exports.__wbg_newwithlength_66e5530e7079ea1b = function(arg0) {
334
- const ret = new Uint8Array(arg0 >>> 0);
335
- return addHeapObject(ret);
336
- };
274
+ return finalizeInit(instance, module);
275
+ }
337
276
 
338
- module.exports.__wbg_subarray_270ff8dd5582c1ac = function(arg0, arg1, arg2) {
339
- const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
340
- return addHeapObject(ret);
341
- };
277
+ async function init(input) {
278
+ if (typeof input === 'undefined') {
279
+ input = new URL('noir_wasm_bg.wasm', import.meta.url);
280
+ }
281
+ const imports = getImports();
342
282
 
343
- module.exports.__wbindgen_throw = function(arg0, arg1) {
344
- throw new Error(getStringFromWasm0(arg0, arg1));
345
- };
283
+ if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
284
+ input = fetch(input);
285
+ }
346
286
 
347
- module.exports.__wbindgen_memory = function() {
348
- const ret = wasm.memory;
349
- return addHeapObject(ret);
350
- };
287
+ initMemory(imports);
351
288
 
352
- const path = require('path').join(__dirname, 'noir_wasm_bg.wasm');
353
- const bytes = require('fs').readFileSync(path);
289
+ const { instance, module } = await load(await input, imports);
354
290
 
355
- const wasmModule = new WebAssembly.Module(bytes);
356
- const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
357
- wasm = wasmInstance.exports;
358
- module.exports.__wasm = wasm;
291
+ return finalizeInit(instance, module);
292
+ }
359
293
 
294
+ export { initSync }
295
+ export default init;
package/noir_wasm_bg.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noir-lang/noir_wasm",
3
- "version": "0.6.0",
3
+ "version": "0.11.0",
4
4
  "files": [
5
5
  "noir_wasm_bg.wasm",
6
6
  "noir_wasm.js",