@noir-lang/acvm_js
Advanced tools
Comparing version 1.0.0-beta.0 to 1.0.0-beta.1
/* tslint:disable */ | ||
/* eslint-disable */ | ||
export const memory: WebAssembly.Memory; | ||
export function compressWitness(a: number, b: number): void; | ||
export function decompressWitness(a: number, b: number, c: number): void; | ||
export function compressWitnessStack(a: number, b: number): void; | ||
export function decompressWitnessStack(a: number, b: number, c: number): void; | ||
export function executeCircuit(a: number, b: number, c: number, d: number): number; | ||
export function executeCircuitWithReturnWitness(a: number, b: number, c: number, d: number): number; | ||
export function executeProgram(a: number, b: number, c: number, d: number): number; | ||
export function and(a: number, b: number): number; | ||
@@ -22,2 +15,9 @@ export function xor(a: number, b: number): number; | ||
export function getPublicWitness(a: number, b: number, c: number, d: number): void; | ||
export function compressWitness(a: number, b: number): void; | ||
export function decompressWitness(a: number, b: number, c: number): void; | ||
export function compressWitnessStack(a: number, b: number): void; | ||
export function decompressWitnessStack(a: number, b: number, c: number): void; | ||
export function executeCircuit(a: number, b: number, c: number, d: number): number; | ||
export function executeCircuitWithReturnWitness(a: number, b: number, c: number, d: number): number; | ||
export function executeProgram(a: number, b: number, c: number, d: number): number; | ||
export function __wbindgen_malloc(a: number): number; | ||
@@ -24,0 +24,0 @@ export function __wbindgen_realloc(a: number, b: number, c: number): number; |
/* tslint:disable */ | ||
/* eslint-disable */ | ||
/** | ||
* Compresses a `WitnessMap` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessMap} witness_map - A witness map. | ||
* @returns {Uint8Array} A compressed witness map | ||
*/ | ||
export function compressWitness(witness_map: WitnessMap): Uint8Array; | ||
/** | ||
* Decompresses a compressed witness as outputted by Nargo into a `WitnessMap`. | ||
* This should be used to only fetch the witness map for the main function. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessMap} The decompressed witness map. | ||
*/ | ||
export function decompressWitness(compressed_witness: Uint8Array): WitnessMap; | ||
/** | ||
* Compresses a `WitnessStack` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessStack} witness_stack - A witness stack. | ||
* @returns {Uint8Array} A compressed witness stack | ||
*/ | ||
export function compressWitnessStack(witness_stack: WitnessStack): Uint8Array; | ||
/** | ||
* Decompresses a compressed witness stack as outputted by Nargo into a `WitnessStack`. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessStack} The decompressed witness stack. | ||
*/ | ||
export function decompressWitnessStack(compressed_witness: Uint8Array): WitnessStack; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs. | ||
*/ | ||
export function executeCircuit(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<WitnessMap>; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* This method also extracts the public return values from the solved witness into its own return witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @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. | ||
*/ | ||
export function executeCircuitWithReturnWitness(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<SolvedAndReturnWitness>; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} program - A serialized representation of an ACIR program | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `program`. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the program. | ||
* @returns {WitnessStack} The solved witness calculated by executing the program on the provided inputs. | ||
*/ | ||
export function executeProgram(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<WitnessStack>; | ||
/** | ||
* Performs a bitwise AND operation between `lhs` and `rhs` | ||
@@ -149,26 +92,60 @@ * @param {string} lhs | ||
export function getPublicWitness(program: Uint8Array, solved_witness: WitnessMap): WitnessMap; | ||
export type ForeignCallInput = string[] | ||
export type ForeignCallOutput = string | string[] | ||
/** | ||
* A callback which performs an foreign call and returns the response. | ||
* @callback ForeignCallHandler | ||
* @param {string} name - The identifier for the type of foreign call being performed. | ||
* @param {string[][]} inputs - An array of hex encoded inputs to the foreign call. | ||
* @returns {Promise<string[]>} outputs - An array of hex encoded outputs containing the results of the foreign call. | ||
* Compresses a `WitnessMap` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessMap} witness_map - A witness map. | ||
* @returns {Uint8Array} A compressed witness map | ||
*/ | ||
export type ForeignCallHandler = (name: string, inputs: ForeignCallInput[]) => Promise<ForeignCallOutput[]>; | ||
export function compressWitness(witness_map: WitnessMap): Uint8Array; | ||
/** | ||
* Decompresses a compressed witness as outputted by Nargo into a `WitnessMap`. | ||
* This should be used to only fetch the witness map for the main function. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessMap} The decompressed witness map. | ||
*/ | ||
export function decompressWitness(compressed_witness: Uint8Array): WitnessMap; | ||
/** | ||
* Compresses a `WitnessStack` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessStack} witness_stack - A witness stack. | ||
* @returns {Uint8Array} A compressed witness stack | ||
*/ | ||
export function compressWitnessStack(witness_stack: WitnessStack): Uint8Array; | ||
/** | ||
* Decompresses a compressed witness stack as outputted by Nargo into a `WitnessStack`. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessStack} The decompressed witness stack. | ||
*/ | ||
export function decompressWitnessStack(compressed_witness: Uint8Array): WitnessStack; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs. | ||
*/ | ||
export function executeCircuit(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<WitnessMap>; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* This method also extracts the public return values from the solved witness into its own return witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @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. | ||
*/ | ||
export function executeCircuitWithReturnWitness(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<SolvedAndReturnWitness>; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} program - A serialized representation of an ACIR program | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `program`. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the program. | ||
* @returns {WitnessStack} The solved witness calculated by executing the program on the provided inputs. | ||
*/ | ||
export function executeProgram(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<WitnessStack>; | ||
export type StackItem = { | ||
index: number; | ||
witness: WitnessMap; | ||
} | ||
export type WitnessStack = Array<StackItem>; | ||
/** | ||
@@ -188,2 +165,16 @@ * @typedef {Object} BuildInfo - Information about how the installed package was built | ||
export type ForeignCallInput = string[] | ||
export type ForeignCallOutput = string | string[] | ||
/** | ||
* A callback which performs an foreign call and returns the response. | ||
* @callback ForeignCallHandler | ||
* @param {string} name - The identifier for the type of foreign call being performed. | ||
* @param {string[][]} inputs - An array of hex encoded inputs to the foreign call. | ||
* @returns {Promise<string[]>} outputs - An array of hex encoded outputs containing the results of the foreign call. | ||
*/ | ||
export type ForeignCallHandler = (name: string, inputs: ForeignCallInput[]) => Promise<ForeignCallOutput[]>; | ||
export type RawAssertionPayload = { | ||
@@ -202,2 +193,11 @@ selector: string; | ||
export type StackItem = { | ||
index: number; | ||
witness: WitnessMap; | ||
} | ||
export type WitnessStack = Array<StackItem>; | ||
// Map from witness index to hex string value of witness. | ||
@@ -204,0 +204,0 @@ export type WitnessMap = Map<number, string>; |
@@ -48,11 +48,2 @@ let imports = {}; | ||
function addHeapObject(obj) { | ||
if (heap_next === heap.length) heap.push(heap.length + 1); | ||
const idx = heap_next; | ||
heap_next = heap[idx]; | ||
heap[idx] = obj; | ||
return idx; | ||
} | ||
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); | ||
@@ -76,2 +67,11 @@ | ||
function addHeapObject(obj) { | ||
if (heap_next === heap.length) heap.push(heap.length + 1); | ||
const idx = heap_next; | ||
heap_next = heap[idx]; | ||
heap[idx] = obj; | ||
return idx; | ||
} | ||
let WASM_VECTOR_LEN = 0; | ||
@@ -225,158 +225,3 @@ | ||
function getArrayU8FromWasm0(ptr, len) { | ||
ptr = ptr >>> 0; | ||
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); | ||
} | ||
/** | ||
* Compresses a `WitnessMap` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessMap} witness_map - A witness map. | ||
* @returns {Uint8Array} A compressed witness map | ||
*/ | ||
module.exports.compressWitness = function(witness_map) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
wasm.compressWitness(retptr, addHeapObject(witness_map)); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
var r3 = getInt32Memory0()[retptr / 4 + 3]; | ||
if (r3) { | ||
throw takeObject(r2); | ||
} | ||
var v1 = getArrayU8FromWasm0(r0, r1).slice(); | ||
wasm.__wbindgen_free(r0, r1 * 1); | ||
return v1; | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
}; | ||
function passArray8ToWasm0(arg, malloc) { | ||
const ptr = malloc(arg.length * 1) >>> 0; | ||
getUint8Memory0().set(arg, ptr / 1); | ||
WASM_VECTOR_LEN = arg.length; | ||
return ptr; | ||
} | ||
/** | ||
* Decompresses a compressed witness as outputted by Nargo into a `WitnessMap`. | ||
* This should be used to only fetch the witness map for the main function. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessMap} The decompressed witness map. | ||
*/ | ||
module.exports.decompressWitness = function(compressed_witness) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
const ptr0 = passArray8ToWasm0(compressed_witness, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
wasm.decompressWitness(retptr, ptr0, len0); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
if (r2) { | ||
throw takeObject(r1); | ||
} | ||
return takeObject(r0); | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
}; | ||
/** | ||
* Compresses a `WitnessStack` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessStack} witness_stack - A witness stack. | ||
* @returns {Uint8Array} A compressed witness stack | ||
*/ | ||
module.exports.compressWitnessStack = function(witness_stack) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
wasm.compressWitnessStack(retptr, addHeapObject(witness_stack)); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
var r3 = getInt32Memory0()[retptr / 4 + 3]; | ||
if (r3) { | ||
throw takeObject(r2); | ||
} | ||
var v1 = getArrayU8FromWasm0(r0, r1).slice(); | ||
wasm.__wbindgen_free(r0, r1 * 1); | ||
return v1; | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
}; | ||
/** | ||
* Decompresses a compressed witness stack as outputted by Nargo into a `WitnessStack`. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessStack} The decompressed witness stack. | ||
*/ | ||
module.exports.decompressWitnessStack = function(compressed_witness) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
const ptr0 = passArray8ToWasm0(compressed_witness, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
wasm.decompressWitnessStack(retptr, ptr0, len0); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
if (r2) { | ||
throw takeObject(r1); | ||
} | ||
return takeObject(r0); | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
}; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs. | ||
*/ | ||
module.exports.executeCircuit = function(program, initial_witness, foreign_call_handler) { | ||
const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ret = wasm.executeCircuit(ptr0, len0, addHeapObject(initial_witness), addHeapObject(foreign_call_handler)); | ||
return takeObject(ret); | ||
}; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* This method also extracts the public return values from the solved witness into its own return witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @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. | ||
*/ | ||
module.exports.executeCircuitWithReturnWitness = function(program, initial_witness, foreign_call_handler) { | ||
const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ret = wasm.executeCircuitWithReturnWitness(ptr0, len0, addHeapObject(initial_witness), addHeapObject(foreign_call_handler)); | ||
return takeObject(ret); | ||
}; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} program - A serialized representation of an ACIR program | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `program`. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the program. | ||
* @returns {WitnessStack} The solved witness calculated by executing the program on the provided inputs. | ||
*/ | ||
module.exports.executeProgram = function(program, initial_witness, foreign_call_handler) { | ||
const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ret = wasm.executeProgram(ptr0, len0, addHeapObject(initial_witness), addHeapObject(foreign_call_handler)); | ||
return takeObject(ret); | ||
}; | ||
/** | ||
* Performs a bitwise AND operation between `lhs` and `rhs` | ||
@@ -447,2 +292,13 @@ * @param {string} lhs | ||
function passArray8ToWasm0(arg, malloc) { | ||
const ptr = malloc(arg.length * 1) >>> 0; | ||
getUint8Memory0().set(arg, ptr / 1); | ||
WASM_VECTOR_LEN = arg.length; | ||
return ptr; | ||
} | ||
function getArrayU8FromWasm0(ptr, len) { | ||
ptr = ptr >>> 0; | ||
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); | ||
} | ||
/** | ||
@@ -625,2 +481,147 @@ * Calculates the Blake2s256 hash of the input bytes | ||
/** | ||
* Compresses a `WitnessMap` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessMap} witness_map - A witness map. | ||
* @returns {Uint8Array} A compressed witness map | ||
*/ | ||
module.exports.compressWitness = function(witness_map) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
wasm.compressWitness(retptr, addHeapObject(witness_map)); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
var r3 = getInt32Memory0()[retptr / 4 + 3]; | ||
if (r3) { | ||
throw takeObject(r2); | ||
} | ||
var v1 = getArrayU8FromWasm0(r0, r1).slice(); | ||
wasm.__wbindgen_free(r0, r1 * 1); | ||
return v1; | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
}; | ||
/** | ||
* Decompresses a compressed witness as outputted by Nargo into a `WitnessMap`. | ||
* This should be used to only fetch the witness map for the main function. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessMap} The decompressed witness map. | ||
*/ | ||
module.exports.decompressWitness = function(compressed_witness) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
const ptr0 = passArray8ToWasm0(compressed_witness, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
wasm.decompressWitness(retptr, ptr0, len0); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
if (r2) { | ||
throw takeObject(r1); | ||
} | ||
return takeObject(r0); | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
}; | ||
/** | ||
* Compresses a `WitnessStack` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessStack} witness_stack - A witness stack. | ||
* @returns {Uint8Array} A compressed witness stack | ||
*/ | ||
module.exports.compressWitnessStack = function(witness_stack) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
wasm.compressWitnessStack(retptr, addHeapObject(witness_stack)); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
var r3 = getInt32Memory0()[retptr / 4 + 3]; | ||
if (r3) { | ||
throw takeObject(r2); | ||
} | ||
var v1 = getArrayU8FromWasm0(r0, r1).slice(); | ||
wasm.__wbindgen_free(r0, r1 * 1); | ||
return v1; | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
}; | ||
/** | ||
* Decompresses a compressed witness stack as outputted by Nargo into a `WitnessStack`. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessStack} The decompressed witness stack. | ||
*/ | ||
module.exports.decompressWitnessStack = function(compressed_witness) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
const ptr0 = passArray8ToWasm0(compressed_witness, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
wasm.decompressWitnessStack(retptr, ptr0, len0); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
if (r2) { | ||
throw takeObject(r1); | ||
} | ||
return takeObject(r0); | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
}; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs. | ||
*/ | ||
module.exports.executeCircuit = function(program, initial_witness, foreign_call_handler) { | ||
const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ret = wasm.executeCircuit(ptr0, len0, addHeapObject(initial_witness), addHeapObject(foreign_call_handler)); | ||
return takeObject(ret); | ||
}; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* This method also extracts the public return values from the solved witness into its own return witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @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. | ||
*/ | ||
module.exports.executeCircuitWithReturnWitness = function(program, initial_witness, foreign_call_handler) { | ||
const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ret = wasm.executeCircuitWithReturnWitness(ptr0, len0, addHeapObject(initial_witness), addHeapObject(foreign_call_handler)); | ||
return takeObject(ret); | ||
}; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} program - A serialized representation of an ACIR program | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `program`. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the program. | ||
* @returns {WitnessStack} The solved witness calculated by executing the program on the provided inputs. | ||
*/ | ||
module.exports.executeProgram = function(program, initial_witness, foreign_call_handler) { | ||
const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ret = wasm.executeProgram(ptr0, len0, addHeapObject(initial_witness), addHeapObject(foreign_call_handler)); | ||
return takeObject(ret); | ||
}; | ||
function __wbg_adapter_75(arg0, arg1, arg2, arg3, arg4) { | ||
@@ -645,2 +646,9 @@ wasm.wasm_bindgen__convert__closures__invoke3_mut__h45040feada3ebb25(arg0, arg1, addHeapObject(arg2), arg3, addHeapObject(arg4)); | ||
module.exports.__wbindgen_number_get = function(arg0, arg1) { | ||
const obj = getObject(arg1); | ||
const ret = typeof(obj) === 'number' ? obj : undefined; | ||
getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret; | ||
getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); | ||
}; | ||
module.exports.__wbindgen_cb_drop = function(arg0) { | ||
@@ -656,15 +664,13 @@ const obj = takeObject(arg0).original; | ||
module.exports.__wbindgen_number_get = function(arg0, arg1) { | ||
const obj = getObject(arg1); | ||
const ret = typeof(obj) === 'number' ? obj : undefined; | ||
getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret; | ||
getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); | ||
module.exports.__wbg_constructor_a10f2b77c63b8d5e = function(arg0) { | ||
const ret = new Error(takeObject(arg0)); | ||
return addHeapObject(ret); | ||
}; | ||
module.exports.__wbindgen_is_array = function(arg0) { | ||
const ret = Array.isArray(getObject(arg0)); | ||
return ret; | ||
module.exports.__wbindgen_string_new = function(arg0, arg1) { | ||
const ret = getStringFromWasm0(arg0, arg1); | ||
return addHeapObject(ret); | ||
}; | ||
module.exports.__wbg_new_1549a44c58f2740a = function() { | ||
module.exports.__wbg_new_a16954212d33afab = function() { | ||
const ret = new Array(); | ||
@@ -679,12 +685,7 @@ return addHeapObject(ret); | ||
module.exports.__wbindgen_string_new = function(arg0, arg1) { | ||
const ret = getStringFromWasm0(arg0, arg1); | ||
return addHeapObject(ret); | ||
module.exports.__wbindgen_is_array = function(arg0) { | ||
const ret = Array.isArray(getObject(arg0)); | ||
return ret; | ||
}; | ||
module.exports.__wbg_constructor_f8f83aa6ec3644b9 = function(arg0) { | ||
const ret = new Error(takeObject(arg0)); | ||
return addHeapObject(ret); | ||
}; | ||
module.exports.__wbindgen_is_string = function(arg0) { | ||
@@ -695,3 +696,3 @@ const ret = typeof(getObject(arg0)) === 'string'; | ||
module.exports.__wbg_new_d9156d5ca3339252 = function() { | ||
module.exports.__wbg_new_d86d15722f6b14a4 = function() { | ||
const ret = new Map(); | ||
@@ -928,4 +929,4 @@ return addHeapObject(ret); | ||
module.exports.__wbindgen_closure_wrapper727 = function(arg0, arg1, arg2) { | ||
const ret = makeMutClosure(arg0, arg1, 265, __wbg_adapter_22); | ||
module.exports.__wbindgen_closure_wrapper729 = function(arg0, arg1, arg2) { | ||
const ret = makeMutClosure(arg0, arg1, 267, __wbg_adapter_22); | ||
return addHeapObject(ret); | ||
@@ -932,0 +933,0 @@ }; |
{ | ||
"name": "@noir-lang/acvm_js", | ||
"version": "1.0.0-beta.0", | ||
"version": "1.0.0-beta.1", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
/* tslint:disable */ | ||
/* eslint-disable */ | ||
export const memory: WebAssembly.Memory; | ||
export function compressWitness(a: number, b: number): void; | ||
export function decompressWitness(a: number, b: number, c: number): void; | ||
export function compressWitnessStack(a: number, b: number): void; | ||
export function decompressWitnessStack(a: number, b: number, c: number): void; | ||
export function executeCircuit(a: number, b: number, c: number, d: number): number; | ||
export function executeCircuitWithReturnWitness(a: number, b: number, c: number, d: number): number; | ||
export function executeProgram(a: number, b: number, c: number, d: number): number; | ||
export function and(a: number, b: number): number; | ||
@@ -22,2 +15,9 @@ export function xor(a: number, b: number): number; | ||
export function getPublicWitness(a: number, b: number, c: number, d: number): void; | ||
export function compressWitness(a: number, b: number): void; | ||
export function decompressWitness(a: number, b: number, c: number): void; | ||
export function compressWitnessStack(a: number, b: number): void; | ||
export function decompressWitnessStack(a: number, b: number, c: number): void; | ||
export function executeCircuit(a: number, b: number, c: number, d: number): number; | ||
export function executeCircuitWithReturnWitness(a: number, b: number, c: number, d: number): number; | ||
export function executeProgram(a: number, b: number, c: number, d: number): number; | ||
export function __wbindgen_malloc(a: number): number; | ||
@@ -24,0 +24,0 @@ export function __wbindgen_realloc(a: number, b: number, c: number): number; |
/* tslint:disable */ | ||
/* eslint-disable */ | ||
/** | ||
* Compresses a `WitnessMap` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessMap} witness_map - A witness map. | ||
* @returns {Uint8Array} A compressed witness map | ||
*/ | ||
export function compressWitness(witness_map: WitnessMap): Uint8Array; | ||
/** | ||
* Decompresses a compressed witness as outputted by Nargo into a `WitnessMap`. | ||
* This should be used to only fetch the witness map for the main function. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessMap} The decompressed witness map. | ||
*/ | ||
export function decompressWitness(compressed_witness: Uint8Array): WitnessMap; | ||
/** | ||
* Compresses a `WitnessStack` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessStack} witness_stack - A witness stack. | ||
* @returns {Uint8Array} A compressed witness stack | ||
*/ | ||
export function compressWitnessStack(witness_stack: WitnessStack): Uint8Array; | ||
/** | ||
* Decompresses a compressed witness stack as outputted by Nargo into a `WitnessStack`. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessStack} The decompressed witness stack. | ||
*/ | ||
export function decompressWitnessStack(compressed_witness: Uint8Array): WitnessStack; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs. | ||
*/ | ||
export function executeCircuit(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<WitnessMap>; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* This method also extracts the public return values from the solved witness into its own return witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @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. | ||
*/ | ||
export function executeCircuitWithReturnWitness(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<SolvedAndReturnWitness>; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} program - A serialized representation of an ACIR program | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `program`. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the program. | ||
* @returns {WitnessStack} The solved witness calculated by executing the program on the provided inputs. | ||
*/ | ||
export function executeProgram(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<WitnessStack>; | ||
/** | ||
* Performs a bitwise AND operation between `lhs` and `rhs` | ||
@@ -149,26 +92,60 @@ * @param {string} lhs | ||
export function getPublicWitness(program: Uint8Array, solved_witness: WitnessMap): WitnessMap; | ||
export type ForeignCallInput = string[] | ||
export type ForeignCallOutput = string | string[] | ||
/** | ||
* A callback which performs an foreign call and returns the response. | ||
* @callback ForeignCallHandler | ||
* @param {string} name - The identifier for the type of foreign call being performed. | ||
* @param {string[][]} inputs - An array of hex encoded inputs to the foreign call. | ||
* @returns {Promise<string[]>} outputs - An array of hex encoded outputs containing the results of the foreign call. | ||
* Compresses a `WitnessMap` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessMap} witness_map - A witness map. | ||
* @returns {Uint8Array} A compressed witness map | ||
*/ | ||
export type ForeignCallHandler = (name: string, inputs: ForeignCallInput[]) => Promise<ForeignCallOutput[]>; | ||
export function compressWitness(witness_map: WitnessMap): Uint8Array; | ||
/** | ||
* Decompresses a compressed witness as outputted by Nargo into a `WitnessMap`. | ||
* This should be used to only fetch the witness map for the main function. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessMap} The decompressed witness map. | ||
*/ | ||
export function decompressWitness(compressed_witness: Uint8Array): WitnessMap; | ||
/** | ||
* Compresses a `WitnessStack` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessStack} witness_stack - A witness stack. | ||
* @returns {Uint8Array} A compressed witness stack | ||
*/ | ||
export function compressWitnessStack(witness_stack: WitnessStack): Uint8Array; | ||
/** | ||
* Decompresses a compressed witness stack as outputted by Nargo into a `WitnessStack`. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessStack} The decompressed witness stack. | ||
*/ | ||
export function decompressWitnessStack(compressed_witness: Uint8Array): WitnessStack; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs. | ||
*/ | ||
export function executeCircuit(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<WitnessMap>; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* This method also extracts the public return values from the solved witness into its own return witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @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. | ||
*/ | ||
export function executeCircuitWithReturnWitness(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<SolvedAndReturnWitness>; | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} program - A serialized representation of an ACIR program | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `program`. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the program. | ||
* @returns {WitnessStack} The solved witness calculated by executing the program on the provided inputs. | ||
*/ | ||
export function executeProgram(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<WitnessStack>; | ||
export type StackItem = { | ||
index: number; | ||
witness: WitnessMap; | ||
} | ||
export type WitnessStack = Array<StackItem>; | ||
/** | ||
@@ -188,2 +165,16 @@ * @typedef {Object} BuildInfo - Information about how the installed package was built | ||
export type ForeignCallInput = string[] | ||
export type ForeignCallOutput = string | string[] | ||
/** | ||
* A callback which performs an foreign call and returns the response. | ||
* @callback ForeignCallHandler | ||
* @param {string} name - The identifier for the type of foreign call being performed. | ||
* @param {string[][]} inputs - An array of hex encoded inputs to the foreign call. | ||
* @returns {Promise<string[]>} outputs - An array of hex encoded outputs containing the results of the foreign call. | ||
*/ | ||
export type ForeignCallHandler = (name: string, inputs: ForeignCallInput[]) => Promise<ForeignCallOutput[]>; | ||
export type RawAssertionPayload = { | ||
@@ -202,2 +193,11 @@ selector: string; | ||
export type StackItem = { | ||
index: number; | ||
witness: WitnessMap; | ||
} | ||
export type WitnessStack = Array<StackItem>; | ||
// Map from witness index to hex string value of witness. | ||
@@ -222,9 +222,2 @@ export type WitnessMap = Map<number, string>; | ||
readonly memory: WebAssembly.Memory; | ||
readonly compressWitness: (a: number, b: number) => void; | ||
readonly decompressWitness: (a: number, b: number, c: number) => void; | ||
readonly compressWitnessStack: (a: number, b: number) => void; | ||
readonly decompressWitnessStack: (a: number, b: number, c: number) => void; | ||
readonly executeCircuit: (a: number, b: number, c: number, d: number) => number; | ||
readonly executeCircuitWithReturnWitness: (a: number, b: number, c: number, d: number) => number; | ||
readonly executeProgram: (a: number, b: number, c: number, d: number) => number; | ||
readonly and: (a: number, b: number) => number; | ||
@@ -241,2 +234,9 @@ readonly xor: (a: number, b: number) => number; | ||
readonly getPublicWitness: (a: number, b: number, c: number, d: number) => void; | ||
readonly compressWitness: (a: number, b: number) => void; | ||
readonly decompressWitness: (a: number, b: number, c: number) => void; | ||
readonly compressWitnessStack: (a: number, b: number) => void; | ||
readonly decompressWitnessStack: (a: number, b: number, c: number) => void; | ||
readonly executeCircuit: (a: number, b: number, c: number, d: number) => number; | ||
readonly executeCircuitWithReturnWitness: (a: number, b: number, c: number, d: number) => number; | ||
readonly executeProgram: (a: number, b: number, c: number, d: number) => number; | ||
readonly __wbindgen_malloc: (a: number) => number; | ||
@@ -243,0 +243,0 @@ readonly __wbindgen_realloc: (a: number, b: number, c: number) => number; |
@@ -45,11 +45,2 @@ let wasm; | ||
function addHeapObject(obj) { | ||
if (heap_next === heap.length) heap.push(heap.length + 1); | ||
const idx = heap_next; | ||
heap_next = heap[idx]; | ||
heap[idx] = obj; | ||
return idx; | ||
} | ||
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); | ||
@@ -73,2 +64,11 @@ | ||
function addHeapObject(obj) { | ||
if (heap_next === heap.length) heap.push(heap.length + 1); | ||
const idx = heap_next; | ||
heap_next = heap[idx]; | ||
heap[idx] = obj; | ||
return idx; | ||
} | ||
let WASM_VECTOR_LEN = 0; | ||
@@ -222,158 +222,3 @@ | ||
function getArrayU8FromWasm0(ptr, len) { | ||
ptr = ptr >>> 0; | ||
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); | ||
} | ||
/** | ||
* Compresses a `WitnessMap` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessMap} witness_map - A witness map. | ||
* @returns {Uint8Array} A compressed witness map | ||
*/ | ||
export function compressWitness(witness_map) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
wasm.compressWitness(retptr, addHeapObject(witness_map)); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
var r3 = getInt32Memory0()[retptr / 4 + 3]; | ||
if (r3) { | ||
throw takeObject(r2); | ||
} | ||
var v1 = getArrayU8FromWasm0(r0, r1).slice(); | ||
wasm.__wbindgen_free(r0, r1 * 1); | ||
return v1; | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
} | ||
function passArray8ToWasm0(arg, malloc) { | ||
const ptr = malloc(arg.length * 1) >>> 0; | ||
getUint8Memory0().set(arg, ptr / 1); | ||
WASM_VECTOR_LEN = arg.length; | ||
return ptr; | ||
} | ||
/** | ||
* Decompresses a compressed witness as outputted by Nargo into a `WitnessMap`. | ||
* This should be used to only fetch the witness map for the main function. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessMap} The decompressed witness map. | ||
*/ | ||
export function decompressWitness(compressed_witness) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
const ptr0 = passArray8ToWasm0(compressed_witness, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
wasm.decompressWitness(retptr, ptr0, len0); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
if (r2) { | ||
throw takeObject(r1); | ||
} | ||
return takeObject(r0); | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
} | ||
/** | ||
* Compresses a `WitnessStack` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessStack} witness_stack - A witness stack. | ||
* @returns {Uint8Array} A compressed witness stack | ||
*/ | ||
export function compressWitnessStack(witness_stack) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
wasm.compressWitnessStack(retptr, addHeapObject(witness_stack)); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
var r3 = getInt32Memory0()[retptr / 4 + 3]; | ||
if (r3) { | ||
throw takeObject(r2); | ||
} | ||
var v1 = getArrayU8FromWasm0(r0, r1).slice(); | ||
wasm.__wbindgen_free(r0, r1 * 1); | ||
return v1; | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
} | ||
/** | ||
* Decompresses a compressed witness stack as outputted by Nargo into a `WitnessStack`. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessStack} The decompressed witness stack. | ||
*/ | ||
export function decompressWitnessStack(compressed_witness) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
const ptr0 = passArray8ToWasm0(compressed_witness, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
wasm.decompressWitnessStack(retptr, ptr0, len0); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
if (r2) { | ||
throw takeObject(r1); | ||
} | ||
return takeObject(r0); | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
} | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs. | ||
*/ | ||
export function executeCircuit(program, initial_witness, foreign_call_handler) { | ||
const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ret = wasm.executeCircuit(ptr0, len0, addHeapObject(initial_witness), addHeapObject(foreign_call_handler)); | ||
return takeObject(ret); | ||
} | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* This method also extracts the public return values from the solved witness into its own return witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @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. | ||
*/ | ||
export function executeCircuitWithReturnWitness(program, initial_witness, foreign_call_handler) { | ||
const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ret = wasm.executeCircuitWithReturnWitness(ptr0, len0, addHeapObject(initial_witness), addHeapObject(foreign_call_handler)); | ||
return takeObject(ret); | ||
} | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} program - A serialized representation of an ACIR program | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `program`. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the program. | ||
* @returns {WitnessStack} The solved witness calculated by executing the program on the provided inputs. | ||
*/ | ||
export function executeProgram(program, initial_witness, foreign_call_handler) { | ||
const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ret = wasm.executeProgram(ptr0, len0, addHeapObject(initial_witness), addHeapObject(foreign_call_handler)); | ||
return takeObject(ret); | ||
} | ||
/** | ||
* Performs a bitwise AND operation between `lhs` and `rhs` | ||
@@ -444,2 +289,13 @@ * @param {string} lhs | ||
function passArray8ToWasm0(arg, malloc) { | ||
const ptr = malloc(arg.length * 1) >>> 0; | ||
getUint8Memory0().set(arg, ptr / 1); | ||
WASM_VECTOR_LEN = arg.length; | ||
return ptr; | ||
} | ||
function getArrayU8FromWasm0(ptr, len) { | ||
ptr = ptr >>> 0; | ||
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); | ||
} | ||
/** | ||
@@ -622,2 +478,147 @@ * Calculates the Blake2s256 hash of the input bytes | ||
/** | ||
* Compresses a `WitnessMap` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessMap} witness_map - A witness map. | ||
* @returns {Uint8Array} A compressed witness map | ||
*/ | ||
export function compressWitness(witness_map) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
wasm.compressWitness(retptr, addHeapObject(witness_map)); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
var r3 = getInt32Memory0()[retptr / 4 + 3]; | ||
if (r3) { | ||
throw takeObject(r2); | ||
} | ||
var v1 = getArrayU8FromWasm0(r0, r1).slice(); | ||
wasm.__wbindgen_free(r0, r1 * 1); | ||
return v1; | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
} | ||
/** | ||
* Decompresses a compressed witness as outputted by Nargo into a `WitnessMap`. | ||
* This should be used to only fetch the witness map for the main function. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessMap} The decompressed witness map. | ||
*/ | ||
export function decompressWitness(compressed_witness) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
const ptr0 = passArray8ToWasm0(compressed_witness, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
wasm.decompressWitness(retptr, ptr0, len0); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
if (r2) { | ||
throw takeObject(r1); | ||
} | ||
return takeObject(r0); | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
} | ||
/** | ||
* Compresses a `WitnessStack` into the binary format outputted by Nargo. | ||
* | ||
* @param {WitnessStack} witness_stack - A witness stack. | ||
* @returns {Uint8Array} A compressed witness stack | ||
*/ | ||
export function compressWitnessStack(witness_stack) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
wasm.compressWitnessStack(retptr, addHeapObject(witness_stack)); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
var r3 = getInt32Memory0()[retptr / 4 + 3]; | ||
if (r3) { | ||
throw takeObject(r2); | ||
} | ||
var v1 = getArrayU8FromWasm0(r0, r1).slice(); | ||
wasm.__wbindgen_free(r0, r1 * 1); | ||
return v1; | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
} | ||
/** | ||
* Decompresses a compressed witness stack as outputted by Nargo into a `WitnessStack`. | ||
* | ||
* @param {Uint8Array} compressed_witness - A compressed witness. | ||
* @returns {WitnessStack} The decompressed witness stack. | ||
*/ | ||
export function decompressWitnessStack(compressed_witness) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
const ptr0 = passArray8ToWasm0(compressed_witness, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
wasm.decompressWitnessStack(retptr, ptr0, len0); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
if (r2) { | ||
throw takeObject(r1); | ||
} | ||
return takeObject(r0); | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
} | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs. | ||
*/ | ||
export function executeCircuit(program, initial_witness, foreign_call_handler) { | ||
const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ret = wasm.executeCircuit(ptr0, len0, addHeapObject(initial_witness), addHeapObject(foreign_call_handler)); | ||
return takeObject(ret); | ||
} | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* This method also extracts the public return values from the solved witness into its own return witness. | ||
* | ||
* @param {Uint8Array} circuit - A serialized representation of an ACIR circuit | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`.. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit. | ||
* @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. | ||
*/ | ||
export function executeCircuitWithReturnWitness(program, initial_witness, foreign_call_handler) { | ||
const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ret = wasm.executeCircuitWithReturnWitness(ptr0, len0, addHeapObject(initial_witness), addHeapObject(foreign_call_handler)); | ||
return takeObject(ret); | ||
} | ||
/** | ||
* Executes an ACIR circuit to generate the solved witness from the initial witness. | ||
* | ||
* @param {Uint8Array} program - A serialized representation of an ACIR program | ||
* @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `program`. | ||
* @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the program. | ||
* @returns {WitnessStack} The solved witness calculated by executing the program on the provided inputs. | ||
*/ | ||
export function executeProgram(program, initial_witness, foreign_call_handler) { | ||
const ptr0 = passArray8ToWasm0(program, wasm.__wbindgen_malloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ret = wasm.executeProgram(ptr0, len0, addHeapObject(initial_witness), addHeapObject(foreign_call_handler)); | ||
return takeObject(ret); | ||
} | ||
function __wbg_adapter_75(arg0, arg1, arg2, arg3, arg4) { | ||
@@ -675,2 +676,8 @@ wasm.wasm_bindgen__convert__closures__invoke3_mut__h45040feada3ebb25(arg0, arg1, addHeapObject(arg2), arg3, addHeapObject(arg4)); | ||
}; | ||
imports.wbg.__wbindgen_number_get = function(arg0, arg1) { | ||
const obj = getObject(arg1); | ||
const ret = typeof(obj) === 'number' ? obj : undefined; | ||
getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret; | ||
getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); | ||
}; | ||
imports.wbg.__wbindgen_cb_drop = function(arg0) { | ||
@@ -685,13 +692,11 @@ const obj = takeObject(arg0).original; | ||
}; | ||
imports.wbg.__wbindgen_number_get = function(arg0, arg1) { | ||
const obj = getObject(arg1); | ||
const ret = typeof(obj) === 'number' ? obj : undefined; | ||
getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret; | ||
getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); | ||
imports.wbg.__wbg_constructor_a10f2b77c63b8d5e = function(arg0) { | ||
const ret = new Error(takeObject(arg0)); | ||
return addHeapObject(ret); | ||
}; | ||
imports.wbg.__wbindgen_is_array = function(arg0) { | ||
const ret = Array.isArray(getObject(arg0)); | ||
return ret; | ||
imports.wbg.__wbindgen_string_new = function(arg0, arg1) { | ||
const ret = getStringFromWasm0(arg0, arg1); | ||
return addHeapObject(ret); | ||
}; | ||
imports.wbg.__wbg_new_1549a44c58f2740a = function() { | ||
imports.wbg.__wbg_new_a16954212d33afab = function() { | ||
const ret = new Array(); | ||
@@ -704,10 +709,6 @@ return addHeapObject(ret); | ||
}; | ||
imports.wbg.__wbindgen_string_new = function(arg0, arg1) { | ||
const ret = getStringFromWasm0(arg0, arg1); | ||
return addHeapObject(ret); | ||
imports.wbg.__wbindgen_is_array = function(arg0) { | ||
const ret = Array.isArray(getObject(arg0)); | ||
return ret; | ||
}; | ||
imports.wbg.__wbg_constructor_f8f83aa6ec3644b9 = function(arg0) { | ||
const ret = new Error(takeObject(arg0)); | ||
return addHeapObject(ret); | ||
}; | ||
imports.wbg.__wbindgen_is_string = function(arg0) { | ||
@@ -717,3 +718,3 @@ const ret = typeof(getObject(arg0)) === 'string'; | ||
}; | ||
imports.wbg.__wbg_new_d9156d5ca3339252 = function() { | ||
imports.wbg.__wbg_new_d86d15722f6b14a4 = function() { | ||
const ret = new Map(); | ||
@@ -913,4 +914,4 @@ return addHeapObject(ret); | ||
}; | ||
imports.wbg.__wbindgen_closure_wrapper727 = function(arg0, arg1, arg2) { | ||
const ret = makeMutClosure(arg0, arg1, 265, __wbg_adapter_22); | ||
imports.wbg.__wbindgen_closure_wrapper729 = function(arg0, arg1, arg2) { | ||
const ret = makeMutClosure(arg0, arg1, 267, __wbg_adapter_22); | ||
return addHeapObject(ret); | ||
@@ -917,0 +918,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
3973043