Noir
Table of Contents
constructor
The constructor
is a method used to create and initialize objects created within the Noir
class. In the Noir
class constructor, you need to pass two parameters: circuit
and backend
.
Syntax
constructor(circuit, backend);
Parameters
Parameter | Type | Description |
---|---|---|
circuit | Object | A circuit represented in a json format, containing the ABI and bytecode. Typically obtained by running nargo compile |
backend | Object | A backend instance, before initialization. |
Usage
const noir = new Noir(circuit, backend);
init
This async method should be called after class instantiation. It will run processes on the ACVM, instantiate your backend, etc.
Syntax
async init()
Parameters
This method takes no parameters
Usage
await noirInstance.init();
execute
This async method allows to execute a circuit to get its witness and return value. generateFinalProof
calls it for you, but you can call it directly (i.e. to feed directly to a backend, or to get the return value).
Syntax
async execute(inputs)
Parameters
Parameter | Type | Description |
---|---|---|
inputs | Object | An object containing the inputs to your circuit. |
Returns
Return value | Type | Description |
---|---|---|
witness | Promise <Uint8Array> | The witness |
returnValue | Promise <InputMap> | The return value |
Usage
const { witness, returnValue } = await noir.execute(inputs)
generateFinalProof
This async method generates a witness and a proof given an object as input.
Syntax
async generateFinalproof(input)
Parameters
Parameter | Type | Description |
---|---|---|
input | Object | An object containing the inputs to your circuit. |
Returns
Return value | Type | Description |
---|---|---|
proof | Promise <Uint8Array> | An array with the byte representation of the proof. |
Usage
// consider the Standard Noir Example given with nargo init
const input = { x: 1, y: 2 };
noirInstance.generateProof(input);
verifyFinalProof
This async method instantiates the verification key and verifies your proof.
Syntax
async verifyFinalProof(proof)
Parameters
Parameter | Type | Description |
---|---|---|
proof | Uint8Array | The Uint8Array representation of your proof, usually obtained by calling generateFinalProof |
Returns
Return value | Type | Description |
---|---|---|
verified | Promise <boolean> | A boolean for whether the proof was verified |
Usage
const proof = noirInstance.generateProof(input);
noirInstance.verifyFinalProof(proof);