@aztec/noir-acvm_js 0.75.0-commit.8a71f57856e217a77b6e50cbc8833c1cd5395b96

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/web/acvm_js.js ADDED
@@ -0,0 +1,964 @@
1
+ let wasm;
2
+
3
+ const heap = new Array(128).fill(undefined);
4
+
5
+ heap.push(undefined, null, true, false);
6
+
7
+ function getObject(idx) { return heap[idx]; }
8
+
9
+ let heap_next = heap.length;
10
+
11
+ function dropObject(idx) {
12
+ if (idx < 132) return;
13
+ heap[idx] = heap_next;
14
+ heap_next = idx;
15
+ }
16
+
17
+ function takeObject(idx) {
18
+ const ret = getObject(idx);
19
+ dropObject(idx);
20
+ return ret;
21
+ }
22
+
23
+ function addHeapObject(obj) {
24
+ if (heap_next === heap.length) heap.push(heap.length + 1);
25
+ const idx = heap_next;
26
+ heap_next = heap[idx];
27
+
28
+ heap[idx] = obj;
29
+ return idx;
30
+ }
31
+
32
+ const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
33
+
34
+ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
35
+
36
+ let cachedUint8Memory0 = null;
37
+
38
+ function getUint8Memory0() {
39
+ if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
40
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
41
+ }
42
+ return cachedUint8Memory0;
43
+ }
44
+
45
+ function getStringFromWasm0(ptr, len) {
46
+ ptr = ptr >>> 0;
47
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
48
+ }
49
+
50
+ let WASM_VECTOR_LEN = 0;
51
+
52
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
53
+
54
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
55
+ ? function (arg, view) {
56
+ return cachedTextEncoder.encodeInto(arg, view);
57
+ }
58
+ : function (arg, view) {
59
+ const buf = cachedTextEncoder.encode(arg);
60
+ view.set(buf);
61
+ return {
62
+ read: arg.length,
63
+ written: buf.length
64
+ };
65
+ });
66
+
67
+ function passStringToWasm0(arg, malloc, realloc) {
68
+
69
+ if (realloc === undefined) {
70
+ const buf = cachedTextEncoder.encode(arg);
71
+ const ptr = malloc(buf.length) >>> 0;
72
+ getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
73
+ WASM_VECTOR_LEN = buf.length;
74
+ return ptr;
75
+ }
76
+
77
+ let len = arg.length;
78
+ let ptr = malloc(len) >>> 0;
79
+
80
+ const mem = getUint8Memory0();
81
+
82
+ let offset = 0;
83
+
84
+ for (; offset < len; offset++) {
85
+ const code = arg.charCodeAt(offset);
86
+ if (code > 0x7F) break;
87
+ mem[ptr + offset] = code;
88
+ }
89
+
90
+ if (offset !== len) {
91
+ if (offset !== 0) {
92
+ arg = arg.slice(offset);
93
+ }
94
+ ptr = realloc(ptr, len, len = offset + arg.length * 3) >>> 0;
95
+ const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
96
+ const ret = encodeString(arg, view);
97
+
98
+ offset += ret.written;
99
+ }
100
+
101
+ WASM_VECTOR_LEN = offset;
102
+ return ptr;
103
+ }
104
+
105
+ function isLikeNone(x) {
106
+ return x === undefined || x === null;
107
+ }
108
+
109
+ let cachedInt32Memory0 = null;
110
+
111
+ function getInt32Memory0() {
112
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
113
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
114
+ }
115
+ return cachedInt32Memory0;
116
+ }
117
+
118
+ let cachedFloat64Memory0 = null;
119
+
120
+ function getFloat64Memory0() {
121
+ if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) {
122
+ cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer);
123
+ }
124
+ return cachedFloat64Memory0;
125
+ }
126
+
127
+ function debugString(val) {
128
+ // primitive types
129
+ const type = typeof val;
130
+ if (type == 'number' || type == 'boolean' || val == null) {
131
+ return `${val}`;
132
+ }
133
+ if (type == 'string') {
134
+ return `"${val}"`;
135
+ }
136
+ if (type == 'symbol') {
137
+ const description = val.description;
138
+ if (description == null) {
139
+ return 'Symbol';
140
+ } else {
141
+ return `Symbol(${description})`;
142
+ }
143
+ }
144
+ if (type == 'function') {
145
+ const name = val.name;
146
+ if (typeof name == 'string' && name.length > 0) {
147
+ return `Function(${name})`;
148
+ } else {
149
+ return 'Function';
150
+ }
151
+ }
152
+ // objects
153
+ if (Array.isArray(val)) {
154
+ const length = val.length;
155
+ let debug = '[';
156
+ if (length > 0) {
157
+ debug += debugString(val[0]);
158
+ }
159
+ for(let i = 1; i < length; i++) {
160
+ debug += ', ' + debugString(val[i]);
161
+ }
162
+ debug += ']';
163
+ return debug;
164
+ }
165
+ // Test for built-in
166
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
167
+ let className;
168
+ if (builtInMatches.length > 1) {
169
+ className = builtInMatches[1];
170
+ } else {
171
+ // Failed to match the standard '[object ClassName]'
172
+ return toString.call(val);
173
+ }
174
+ if (className == 'Object') {
175
+ // we're a user defined class or Object
176
+ // JSON.stringify avoids problems with cycles, and is generally much
177
+ // easier than looping through ownProperties of `val`.
178
+ try {
179
+ return 'Object(' + JSON.stringify(val) + ')';
180
+ } catch (_) {
181
+ return 'Object';
182
+ }
183
+ }
184
+ // errors
185
+ if (val instanceof Error) {
186
+ return `${val.name}: ${val.message}\n${val.stack}`;
187
+ }
188
+ // TODO we could test for more things here, like `Set`s and `Map`s.
189
+ return className;
190
+ }
191
+
192
+ function makeMutClosure(arg0, arg1, dtor, f) {
193
+ const state = { a: arg0, b: arg1, cnt: 1, dtor };
194
+ const real = (...args) => {
195
+ // First up with a closure we increment the internal reference
196
+ // count. This ensures that the Rust closure environment won't
197
+ // be deallocated while we're invoking it.
198
+ state.cnt++;
199
+ const a = state.a;
200
+ state.a = 0;
201
+ try {
202
+ return f(a, state.b, ...args);
203
+ } finally {
204
+ if (--state.cnt === 0) {
205
+ wasm.__wbindgen_export_2.get(state.dtor)(a, state.b);
206
+
207
+ } else {
208
+ state.a = a;
209
+ }
210
+ }
211
+ };
212
+ real.original = state;
213
+
214
+ return real;
215
+ }
216
+ function __wbg_adapter_22(arg0, arg1, arg2) {
217
+ wasm.wasm_bindgen__convert__closures__invoke1_mut__h88a56384c96b757b(arg0, arg1, addHeapObject(arg2));
218
+ }
219
+
220
+ function passArray8ToWasm0(arg, malloc) {
221
+ const ptr = malloc(arg.length * 1) >>> 0;
222
+ getUint8Memory0().set(arg, ptr / 1);
223
+ WASM_VECTOR_LEN = arg.length;
224
+ return ptr;
225
+ }
226
+ /**
227
+ * Executes an ACIR circuit to generate the solved witness from the initial witness.
228
+ *
229
+ * @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
230
+ * @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`..
231
+ * @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit.
232
+ * @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs.
233
+ */
234
+ export function executeCircuit(program, initial_witness, foreign_call_handler) {
235
+ const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc);
236
+ const len0 = WASM_VECTOR_LEN;
237
+ const ret = wasm.executeCircuit(ptr0, len0, addHeapObject(initial_witness), addHeapObject(foreign_call_handler));
238
+ return takeObject(ret);
239
+ }
240
+
241
+ /**
242
+ * Executes an ACIR circuit to generate the solved witness from the initial witness.
243
+ * This method also extracts the public return values from the solved witness into its own return witness.
244
+ *
245
+ * @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
246
+ * @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`..
247
+ * @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit.
248
+ * @returns {SolvedAndReturnWitness} The solved witness calculated by executing the circuit on the provided inputs, as well as the return witness indices as specified by the circuit.
249
+ */
250
+ export function executeCircuitWithReturnWitness(program, initial_witness, foreign_call_handler) {
251
+ const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc);
252
+ const len0 = WASM_VECTOR_LEN;
253
+ const ret = wasm.executeCircuitWithReturnWitness(ptr0, len0, addHeapObject(initial_witness), addHeapObject(foreign_call_handler));
254
+ return takeObject(ret);
255
+ }
256
+
257
+ /**
258
+ * Executes an ACIR circuit to generate the solved witness from the initial witness.
259
+ *
260
+ * @param {Uint8Array} program - A serialized representation of an ACIR program
261
+ * @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `program`.
262
+ * @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the program.
263
+ * @returns {WitnessStack} The solved witness calculated by executing the program on the provided inputs.
264
+ */
265
+ export function executeProgram(program, initial_witness, foreign_call_handler) {
266
+ const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc);
267
+ const len0 = WASM_VECTOR_LEN;
268
+ const ret = wasm.executeProgram(ptr0, len0, addHeapObject(initial_witness), addHeapObject(foreign_call_handler));
269
+ return takeObject(ret);
270
+ }
271
+
272
+ /**
273
+ * Sets the package's logging level.
274
+ *
275
+ * @param {LogLevel} level - The maximum level of logging to be emitted.
276
+ */
277
+ export function initLogLevel(filter) {
278
+ try {
279
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
280
+ const ptr0 = passStringToWasm0(filter, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
281
+ const len0 = WASM_VECTOR_LEN;
282
+ wasm.initLogLevel(retptr, ptr0, len0);
283
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
284
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
285
+ if (r1) {
286
+ throw takeObject(r0);
287
+ }
288
+ } finally {
289
+ wasm.__wbindgen_add_to_stack_pointer(16);
290
+ }
291
+ }
292
+
293
+ function getArrayU8FromWasm0(ptr, len) {
294
+ ptr = ptr >>> 0;
295
+ return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
296
+ }
297
+ /**
298
+ * Compresses a `WitnessMap` into the binary format outputted by Nargo.
299
+ *
300
+ * @param {WitnessMap} witness_map - A witness map.
301
+ * @returns {Uint8Array} A compressed witness map
302
+ */
303
+ export function compressWitness(witness_map) {
304
+ try {
305
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
306
+ wasm.compressWitness(retptr, addHeapObject(witness_map));
307
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
308
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
309
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
310
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
311
+ if (r3) {
312
+ throw takeObject(r2);
313
+ }
314
+ var v1 = getArrayU8FromWasm0(r0, r1).slice();
315
+ wasm.__wbindgen_free(r0, r1 * 1);
316
+ return v1;
317
+ } finally {
318
+ wasm.__wbindgen_add_to_stack_pointer(16);
319
+ }
320
+ }
321
+
322
+ /**
323
+ * Decompresses a compressed witness as outputted by Nargo into a `WitnessMap`.
324
+ * This should be used to only fetch the witness map for the main function.
325
+ *
326
+ * @param {Uint8Array} compressed_witness - A compressed witness.
327
+ * @returns {WitnessMap} The decompressed witness map.
328
+ */
329
+ export function decompressWitness(compressed_witness) {
330
+ try {
331
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
332
+ const ptr0 = passArray8ToWasm0(compressed_witness, wasm.__wbindgen_malloc);
333
+ const len0 = WASM_VECTOR_LEN;
334
+ wasm.decompressWitness(retptr, ptr0, len0);
335
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
336
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
337
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
338
+ if (r2) {
339
+ throw takeObject(r1);
340
+ }
341
+ return takeObject(r0);
342
+ } finally {
343
+ wasm.__wbindgen_add_to_stack_pointer(16);
344
+ }
345
+ }
346
+
347
+ /**
348
+ * Compresses a `WitnessStack` into the binary format outputted by Nargo.
349
+ *
350
+ * @param {WitnessStack} witness_stack - A witness stack.
351
+ * @returns {Uint8Array} A compressed witness stack
352
+ */
353
+ export function compressWitnessStack(witness_stack) {
354
+ try {
355
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
356
+ wasm.compressWitnessStack(retptr, addHeapObject(witness_stack));
357
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
358
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
359
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
360
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
361
+ if (r3) {
362
+ throw takeObject(r2);
363
+ }
364
+ var v1 = getArrayU8FromWasm0(r0, r1).slice();
365
+ wasm.__wbindgen_free(r0, r1 * 1);
366
+ return v1;
367
+ } finally {
368
+ wasm.__wbindgen_add_to_stack_pointer(16);
369
+ }
370
+ }
371
+
372
+ /**
373
+ * Decompresses a compressed witness stack as outputted by Nargo into a `WitnessStack`.
374
+ *
375
+ * @param {Uint8Array} compressed_witness - A compressed witness.
376
+ * @returns {WitnessStack} The decompressed witness stack.
377
+ */
378
+ export function decompressWitnessStack(compressed_witness) {
379
+ try {
380
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
381
+ const ptr0 = passArray8ToWasm0(compressed_witness, wasm.__wbindgen_malloc);
382
+ const len0 = WASM_VECTOR_LEN;
383
+ wasm.decompressWitnessStack(retptr, ptr0, len0);
384
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
385
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
386
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
387
+ if (r2) {
388
+ throw takeObject(r1);
389
+ }
390
+ return takeObject(r0);
391
+ } finally {
392
+ wasm.__wbindgen_add_to_stack_pointer(16);
393
+ }
394
+ }
395
+
396
+ /**
397
+ * Performs a bitwise AND operation between `lhs` and `rhs`
398
+ * @param {string} lhs
399
+ * @param {string} rhs
400
+ * @returns {string}
401
+ */
402
+ export function and(lhs, rhs) {
403
+ const ret = wasm.and(addHeapObject(lhs), addHeapObject(rhs));
404
+ return takeObject(ret);
405
+ }
406
+
407
+ /**
408
+ * Performs a bitwise XOR operation between `lhs` and `rhs`
409
+ * @param {string} lhs
410
+ * @param {string} rhs
411
+ * @returns {string}
412
+ */
413
+ export function xor(lhs, rhs) {
414
+ const ret = wasm.xor(addHeapObject(lhs), addHeapObject(rhs));
415
+ return takeObject(ret);
416
+ }
417
+
418
+ let cachedUint32Memory0 = null;
419
+
420
+ function getUint32Memory0() {
421
+ if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
422
+ cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
423
+ }
424
+ return cachedUint32Memory0;
425
+ }
426
+
427
+ function passArray32ToWasm0(arg, malloc) {
428
+ const ptr = malloc(arg.length * 4) >>> 0;
429
+ getUint32Memory0().set(arg, ptr / 4);
430
+ WASM_VECTOR_LEN = arg.length;
431
+ return ptr;
432
+ }
433
+
434
+ function getArrayU32FromWasm0(ptr, len) {
435
+ ptr = ptr >>> 0;
436
+ return getUint32Memory0().subarray(ptr / 4, ptr / 4 + len);
437
+ }
438
+ /**
439
+ * Sha256 compression function
440
+ * @param {Uint32Array} inputs
441
+ * @param {Uint32Array} state
442
+ * @returns {Uint32Array}
443
+ */
444
+ export function sha256_compression(inputs, state) {
445
+ try {
446
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
447
+ const ptr0 = passArray32ToWasm0(inputs, wasm.__wbindgen_malloc);
448
+ const len0 = WASM_VECTOR_LEN;
449
+ const ptr1 = passArray32ToWasm0(state, wasm.__wbindgen_malloc);
450
+ const len1 = WASM_VECTOR_LEN;
451
+ wasm.sha256_compression(retptr, ptr0, len0, ptr1, len1);
452
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
453
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
454
+ var v3 = getArrayU32FromWasm0(r0, r1).slice();
455
+ wasm.__wbindgen_free(r0, r1 * 4);
456
+ return v3;
457
+ } finally {
458
+ wasm.__wbindgen_add_to_stack_pointer(16);
459
+ }
460
+ }
461
+
462
+ /**
463
+ * Calculates the Blake2s256 hash of the input bytes
464
+ * @param {Uint8Array} inputs
465
+ * @returns {Uint8Array}
466
+ */
467
+ export function blake2s256(inputs) {
468
+ try {
469
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
470
+ const ptr0 = passArray8ToWasm0(inputs, wasm.__wbindgen_malloc);
471
+ const len0 = WASM_VECTOR_LEN;
472
+ wasm.blake2s256(retptr, ptr0, len0);
473
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
474
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
475
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
476
+ wasm.__wbindgen_free(r0, r1 * 1);
477
+ return v2;
478
+ } finally {
479
+ wasm.__wbindgen_add_to_stack_pointer(16);
480
+ }
481
+ }
482
+
483
+ /**
484
+ * Verifies a ECDSA signature over the secp256k1 curve.
485
+ * @param {Uint8Array} hashed_msg
486
+ * @param {Uint8Array} public_key_x_bytes
487
+ * @param {Uint8Array} public_key_y_bytes
488
+ * @param {Uint8Array} signature
489
+ * @returns {boolean}
490
+ */
491
+ export function ecdsa_secp256k1_verify(hashed_msg, public_key_x_bytes, public_key_y_bytes, signature) {
492
+ const ptr0 = passArray8ToWasm0(hashed_msg, wasm.__wbindgen_malloc);
493
+ const len0 = WASM_VECTOR_LEN;
494
+ const ptr1 = passArray8ToWasm0(public_key_x_bytes, wasm.__wbindgen_malloc);
495
+ const len1 = WASM_VECTOR_LEN;
496
+ const ptr2 = passArray8ToWasm0(public_key_y_bytes, wasm.__wbindgen_malloc);
497
+ const len2 = WASM_VECTOR_LEN;
498
+ const ptr3 = passArray8ToWasm0(signature, wasm.__wbindgen_malloc);
499
+ const len3 = WASM_VECTOR_LEN;
500
+ const ret = wasm.ecdsa_secp256k1_verify(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
501
+ return ret !== 0;
502
+ }
503
+
504
+ /**
505
+ * Verifies a ECDSA signature over the secp256r1 curve.
506
+ * @param {Uint8Array} hashed_msg
507
+ * @param {Uint8Array} public_key_x_bytes
508
+ * @param {Uint8Array} public_key_y_bytes
509
+ * @param {Uint8Array} signature
510
+ * @returns {boolean}
511
+ */
512
+ export function ecdsa_secp256r1_verify(hashed_msg, public_key_x_bytes, public_key_y_bytes, signature) {
513
+ const ptr0 = passArray8ToWasm0(hashed_msg, wasm.__wbindgen_malloc);
514
+ const len0 = WASM_VECTOR_LEN;
515
+ const ptr1 = passArray8ToWasm0(public_key_x_bytes, wasm.__wbindgen_malloc);
516
+ const len1 = WASM_VECTOR_LEN;
517
+ const ptr2 = passArray8ToWasm0(public_key_y_bytes, wasm.__wbindgen_malloc);
518
+ const len2 = WASM_VECTOR_LEN;
519
+ const ptr3 = passArray8ToWasm0(signature, wasm.__wbindgen_malloc);
520
+ const len3 = WASM_VECTOR_LEN;
521
+ const ret = wasm.ecdsa_secp256r1_verify(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
522
+ return ret !== 0;
523
+ }
524
+
525
+ /**
526
+ * Returns the `BuildInfo` object containing information about how the installed package was built.
527
+ * @returns {BuildInfo} - Information on how the installed package was built.
528
+ */
529
+ export function buildInfo() {
530
+ const ret = wasm.buildInfo();
531
+ return takeObject(ret);
532
+ }
533
+
534
+ /**
535
+ * Extracts a `WitnessMap` containing the witness indices corresponding to the circuit's return values.
536
+ *
537
+ * @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
538
+ * @param {WitnessMap} witness_map - The completed witness map after executing the circuit.
539
+ * @returns {WitnessMap} A witness map containing the circuit's return values.
540
+ * @param {Uint8Array} program
541
+ * @param {WitnessMap} witness_map
542
+ * @returns {WitnessMap}
543
+ */
544
+ export function getReturnWitness(program, witness_map) {
545
+ try {
546
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
547
+ const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc);
548
+ const len0 = WASM_VECTOR_LEN;
549
+ wasm.getReturnWitness(retptr, ptr0, len0, addHeapObject(witness_map));
550
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
551
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
552
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
553
+ if (r2) {
554
+ throw takeObject(r1);
555
+ }
556
+ return takeObject(r0);
557
+ } finally {
558
+ wasm.__wbindgen_add_to_stack_pointer(16);
559
+ }
560
+ }
561
+
562
+ /**
563
+ * Extracts a `WitnessMap` containing the witness indices corresponding to the circuit's public parameters.
564
+ *
565
+ * @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
566
+ * @param {WitnessMap} witness_map - The completed witness map after executing the circuit.
567
+ * @returns {WitnessMap} A witness map containing the circuit's public parameters.
568
+ * @param {Uint8Array} program
569
+ * @param {WitnessMap} solved_witness
570
+ * @returns {WitnessMap}
571
+ */
572
+ export function getPublicParametersWitness(program, solved_witness) {
573
+ try {
574
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
575
+ const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc);
576
+ const len0 = WASM_VECTOR_LEN;
577
+ wasm.getPublicParametersWitness(retptr, ptr0, len0, addHeapObject(solved_witness));
578
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
579
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
580
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
581
+ if (r2) {
582
+ throw takeObject(r1);
583
+ }
584
+ return takeObject(r0);
585
+ } finally {
586
+ wasm.__wbindgen_add_to_stack_pointer(16);
587
+ }
588
+ }
589
+
590
+ /**
591
+ * Extracts a `WitnessMap` containing the witness indices corresponding to the circuit's public inputs.
592
+ *
593
+ * @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
594
+ * @param {WitnessMap} witness_map - The completed witness map after executing the circuit.
595
+ * @returns {WitnessMap} A witness map containing the circuit's public inputs.
596
+ * @param {Uint8Array} program
597
+ * @param {WitnessMap} solved_witness
598
+ * @returns {WitnessMap}
599
+ */
600
+ export function getPublicWitness(program, solved_witness) {
601
+ try {
602
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
603
+ const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc);
604
+ const len0 = WASM_VECTOR_LEN;
605
+ wasm.getPublicWitness(retptr, ptr0, len0, addHeapObject(solved_witness));
606
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
607
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
608
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
609
+ if (r2) {
610
+ throw takeObject(r1);
611
+ }
612
+ return takeObject(r0);
613
+ } finally {
614
+ wasm.__wbindgen_add_to_stack_pointer(16);
615
+ }
616
+ }
617
+
618
+ function __wbg_adapter_75(arg0, arg1, arg2, arg3, arg4) {
619
+ wasm.wasm_bindgen__convert__closures__invoke3_mut__h24d1dd0bd469df82(arg0, arg1, addHeapObject(arg2), arg3, addHeapObject(arg4));
620
+ }
621
+
622
+ function handleError(f, args) {
623
+ try {
624
+ return f.apply(this, args);
625
+ } catch (e) {
626
+ wasm.__wbindgen_exn_store(addHeapObject(e));
627
+ }
628
+ }
629
+ function __wbg_adapter_92(arg0, arg1, arg2, arg3) {
630
+ wasm.wasm_bindgen__convert__closures__invoke2_mut__h57a2220e5f1e0a1e(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
631
+ }
632
+
633
+ async function __wbg_load(module, imports) {
634
+ if (typeof Response === 'function' && module instanceof Response) {
635
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
636
+ try {
637
+ return await WebAssembly.instantiateStreaming(module, imports);
638
+
639
+ } catch (e) {
640
+ if (module.headers.get('Content-Type') != 'application/wasm') {
641
+ 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);
642
+
643
+ } else {
644
+ throw e;
645
+ }
646
+ }
647
+ }
648
+
649
+ const bytes = await module.arrayBuffer();
650
+ return await WebAssembly.instantiate(bytes, imports);
651
+
652
+ } else {
653
+ const instance = await WebAssembly.instantiate(module, imports);
654
+
655
+ if (instance instanceof WebAssembly.Instance) {
656
+ return { instance, module };
657
+
658
+ } else {
659
+ return instance;
660
+ }
661
+ }
662
+ }
663
+
664
+ function __wbg_get_imports() {
665
+ const imports = {};
666
+ imports.wbg = {};
667
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
668
+ takeObject(arg0);
669
+ };
670
+ imports.wbg.__wbindgen_is_array = function(arg0) {
671
+ const ret = Array.isArray(getObject(arg0));
672
+ return ret;
673
+ };
674
+ imports.wbg.__wbg_constructor_a10f2b77c63b8d5e = function(arg0) {
675
+ const ret = new Error(takeObject(arg0));
676
+ return addHeapObject(ret);
677
+ };
678
+ imports.wbg.__wbg_new_d86d15722f6b14a4 = function() {
679
+ const ret = new Map();
680
+ return addHeapObject(ret);
681
+ };
682
+ imports.wbg.__wbindgen_number_new = function(arg0) {
683
+ const ret = arg0;
684
+ return addHeapObject(ret);
685
+ };
686
+ imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
687
+ const ret = getStringFromWasm0(arg0, arg1);
688
+ return addHeapObject(ret);
689
+ };
690
+ imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
691
+ const obj = getObject(arg1);
692
+ const ret = typeof(obj) === 'string' ? obj : undefined;
693
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
694
+ var len1 = WASM_VECTOR_LEN;
695
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
696
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
697
+ };
698
+ imports.wbg.__wbindgen_cb_drop = function(arg0) {
699
+ const obj = takeObject(arg0).original;
700
+ if (obj.cnt-- == 1) {
701
+ obj.a = 0;
702
+ return true;
703
+ }
704
+ const ret = false;
705
+ return ret;
706
+ };
707
+ imports.wbg.__wbindgen_is_string = function(arg0) {
708
+ const ret = typeof(getObject(arg0)) === 'string';
709
+ return ret;
710
+ };
711
+ imports.wbg.__wbindgen_number_get = function(arg0, arg1) {
712
+ const obj = getObject(arg1);
713
+ const ret = typeof(obj) === 'number' ? obj : undefined;
714
+ getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;
715
+ getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
716
+ };
717
+ imports.wbg.__wbg_new_a16954212d33afab = function() {
718
+ const ret = new Array();
719
+ return addHeapObject(ret);
720
+ };
721
+ imports.wbg.__wbg_new_abda76e883ba8a5f = function() {
722
+ const ret = new Error();
723
+ return addHeapObject(ret);
724
+ };
725
+ imports.wbg.__wbg_stack_658279fe44541cf6 = function(arg0, arg1) {
726
+ const ret = getObject(arg1).stack;
727
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
728
+ const len1 = WASM_VECTOR_LEN;
729
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
730
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
731
+ };
732
+ imports.wbg.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) {
733
+ let deferred0_0;
734
+ let deferred0_1;
735
+ try {
736
+ deferred0_0 = arg0;
737
+ deferred0_1 = arg1;
738
+ console.error(getStringFromWasm0(arg0, arg1));
739
+ } finally {
740
+ wasm.__wbindgen_free(deferred0_0, deferred0_1);
741
+ }
742
+ };
743
+ imports.wbg.__wbg_debug_e3f6a1578e6d45ca = function(arg0) {
744
+ console.debug(getObject(arg0));
745
+ };
746
+ imports.wbg.__wbg_debug_efabe4eb183aa5d4 = function(arg0, arg1, arg2, arg3) {
747
+ console.debug(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
748
+ };
749
+ imports.wbg.__wbg_error_a7e23606158b68b9 = function(arg0) {
750
+ console.error(getObject(arg0));
751
+ };
752
+ imports.wbg.__wbg_error_50f42b952a595a23 = function(arg0, arg1, arg2, arg3) {
753
+ console.error(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
754
+ };
755
+ imports.wbg.__wbg_info_05db236d79f1b785 = function(arg0) {
756
+ console.info(getObject(arg0));
757
+ };
758
+ imports.wbg.__wbg_info_24d8f53d98f12b95 = function(arg0, arg1, arg2, arg3) {
759
+ console.info(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
760
+ };
761
+ imports.wbg.__wbg_warn_9bdd743e9f5fe1e0 = function(arg0) {
762
+ console.warn(getObject(arg0));
763
+ };
764
+ imports.wbg.__wbg_warn_8342bfbc6028193a = function(arg0, arg1, arg2, arg3) {
765
+ console.warn(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
766
+ };
767
+ imports.wbg.__wbg_get_7303ed2ef026b2f5 = function(arg0, arg1) {
768
+ const ret = getObject(arg0)[arg1 >>> 0];
769
+ return addHeapObject(ret);
770
+ };
771
+ imports.wbg.__wbg_length_820c786973abdd8a = function(arg0) {
772
+ const ret = getObject(arg0).length;
773
+ return ret;
774
+ };
775
+ imports.wbg.__wbg_new_0394642eae39db16 = function() {
776
+ const ret = new Array();
777
+ return addHeapObject(ret);
778
+ };
779
+ imports.wbg.__wbg_new_0f2b71ca2f2a6029 = function() {
780
+ const ret = new Map();
781
+ return addHeapObject(ret);
782
+ };
783
+ imports.wbg.__wbg_from_6bc98a09a0b58bb1 = function(arg0) {
784
+ const ret = Array.from(getObject(arg0));
785
+ return addHeapObject(ret);
786
+ };
787
+ imports.wbg.__wbg_forEach_5ae261259d7517c8 = function(arg0, arg1, arg2) {
788
+ try {
789
+ var state0 = {a: arg1, b: arg2};
790
+ var cb0 = (arg0, arg1, arg2) => {
791
+ const a = state0.a;
792
+ state0.a = 0;
793
+ try {
794
+ return __wbg_adapter_75(a, state0.b, arg0, arg1, arg2);
795
+ } finally {
796
+ state0.a = a;
797
+ }
798
+ };
799
+ getObject(arg0).forEach(cb0);
800
+ } finally {
801
+ state0.a = state0.b = 0;
802
+ }
803
+ };
804
+ imports.wbg.__wbg_push_109cfc26d02582dd = function(arg0, arg1) {
805
+ const ret = getObject(arg0).push(getObject(arg1));
806
+ return ret;
807
+ };
808
+ imports.wbg.__wbg_reverse_a322332d916e2705 = function(arg0) {
809
+ const ret = getObject(arg0).reverse();
810
+ return addHeapObject(ret);
811
+ };
812
+ imports.wbg.__wbg_new_87297f22973157c8 = function(arg0, arg1) {
813
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
814
+ return addHeapObject(ret);
815
+ };
816
+ imports.wbg.__wbg_setcause_394738aae0ce9341 = function(arg0, arg1) {
817
+ getObject(arg0).cause = getObject(arg1);
818
+ };
819
+ imports.wbg.__wbg_call_587b30eea3e09332 = function() { return handleError(function (arg0, arg1, arg2) {
820
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
821
+ return addHeapObject(ret);
822
+ }, arguments) };
823
+ imports.wbg.__wbg_call_4c73e4aecced6a7d = function() { return handleError(function (arg0, arg1, arg2, arg3) {
824
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2), getObject(arg3));
825
+ return addHeapObject(ret);
826
+ }, arguments) };
827
+ imports.wbg.__wbg_forEach_942772130a8d06a6 = function(arg0, arg1, arg2) {
828
+ try {
829
+ var state0 = {a: arg1, b: arg2};
830
+ var cb0 = (arg0, arg1) => {
831
+ const a = state0.a;
832
+ state0.a = 0;
833
+ try {
834
+ return __wbg_adapter_92(a, state0.b, arg0, arg1);
835
+ } finally {
836
+ state0.a = a;
837
+ }
838
+ };
839
+ getObject(arg0).forEach(cb0);
840
+ } finally {
841
+ state0.a = state0.b = 0;
842
+ }
843
+ };
844
+ imports.wbg.__wbg_set_da7be7bf0e037b14 = function(arg0, arg1, arg2) {
845
+ const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
846
+ return addHeapObject(ret);
847
+ };
848
+ imports.wbg.__wbg_fromEntries_d1b310956d20d858 = function() { return handleError(function (arg0) {
849
+ const ret = Object.fromEntries(getObject(arg0));
850
+ return addHeapObject(ret);
851
+ }, arguments) };
852
+ imports.wbg.__wbg_values_099fd000c271c313 = function(arg0) {
853
+ const ret = Object.values(getObject(arg0));
854
+ return addHeapObject(ret);
855
+ };
856
+ imports.wbg.__wbg_new_2b55e405e4af4986 = function(arg0, arg1) {
857
+ try {
858
+ var state0 = {a: arg0, b: arg1};
859
+ var cb0 = (arg0, arg1) => {
860
+ const a = state0.a;
861
+ state0.a = 0;
862
+ try {
863
+ return __wbg_adapter_92(a, state0.b, arg0, arg1);
864
+ } finally {
865
+ state0.a = a;
866
+ }
867
+ };
868
+ const ret = new Promise(cb0);
869
+ return addHeapObject(ret);
870
+ } finally {
871
+ state0.a = state0.b = 0;
872
+ }
873
+ };
874
+ imports.wbg.__wbg_resolve_ae38ad63c43ff98b = function(arg0) {
875
+ const ret = Promise.resolve(getObject(arg0));
876
+ return addHeapObject(ret);
877
+ };
878
+ imports.wbg.__wbg_then_8df675b8bb5d5e3c = function(arg0, arg1) {
879
+ const ret = getObject(arg0).then(getObject(arg1));
880
+ return addHeapObject(ret);
881
+ };
882
+ imports.wbg.__wbg_then_835b073a479138e5 = function(arg0, arg1, arg2) {
883
+ const ret = getObject(arg0).then(getObject(arg1), getObject(arg2));
884
+ return addHeapObject(ret);
885
+ };
886
+ imports.wbg.__wbg_parse_76a8a18ca3f8730b = function() { return handleError(function (arg0, arg1) {
887
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
888
+ return addHeapObject(ret);
889
+ }, arguments) };
890
+ imports.wbg.__wbg_set_07da13cc24b69217 = function() { return handleError(function (arg0, arg1, arg2) {
891
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
892
+ return ret;
893
+ }, arguments) };
894
+ imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
895
+ const ret = debugString(getObject(arg1));
896
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
897
+ const len1 = WASM_VECTOR_LEN;
898
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
899
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
900
+ };
901
+ imports.wbg.__wbindgen_throw = function(arg0, arg1) {
902
+ throw new Error(getStringFromWasm0(arg0, arg1));
903
+ };
904
+ imports.wbg.__wbindgen_closure_wrapper767 = function(arg0, arg1, arg2) {
905
+ const ret = makeMutClosure(arg0, arg1, 301, __wbg_adapter_22);
906
+ return addHeapObject(ret);
907
+ };
908
+
909
+ return imports;
910
+ }
911
+
912
+ function __wbg_init_memory(imports, maybe_memory) {
913
+
914
+ }
915
+
916
+ function __wbg_finalize_init(instance, module) {
917
+ wasm = instance.exports;
918
+ __wbg_init.__wbindgen_wasm_module = module;
919
+ cachedFloat64Memory0 = null;
920
+ cachedInt32Memory0 = null;
921
+ cachedUint32Memory0 = null;
922
+ cachedUint8Memory0 = null;
923
+
924
+
925
+ return wasm;
926
+ }
927
+
928
+ function initSync(module) {
929
+ if (wasm !== undefined) return wasm;
930
+
931
+ const imports = __wbg_get_imports();
932
+
933
+ __wbg_init_memory(imports);
934
+
935
+ if (!(module instanceof WebAssembly.Module)) {
936
+ module = new WebAssembly.Module(module);
937
+ }
938
+
939
+ const instance = new WebAssembly.Instance(module, imports);
940
+
941
+ return __wbg_finalize_init(instance, module);
942
+ }
943
+
944
+ async function __wbg_init(input) {
945
+ if (wasm !== undefined) return wasm;
946
+
947
+ if (typeof input === 'undefined') {
948
+ input = new URL('acvm_js_bg.wasm', import.meta.url);
949
+ }
950
+ const imports = __wbg_get_imports();
951
+
952
+ if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
953
+ input = fetch(input);
954
+ }
955
+
956
+ __wbg_init_memory(imports);
957
+
958
+ const { instance, module } = await __wbg_load(await input, imports);
959
+
960
+ return __wbg_finalize_init(instance, module);
961
+ }
962
+
963
+ export { initSync }
964
+ export default __wbg_init;