Skip to main content
Version: 0.17.0

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

ParameterTypeDescription
circuitObjectA circuit represented in a json format, containing the ABI and bytecode. Typically obtained by running nargo compile
backendObjectA 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

ParameterTypeDescription
inputsObjectAn object containing the inputs to your circuit.

Returns

Return valueTypeDescription
witnessPromise <Uint8Array>The witness
returnValuePromise <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

ParameterTypeDescription
inputObjectAn object containing the inputs to your circuit.

Returns

Return valueTypeDescription
proofPromise <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

ParameterTypeDescription
proofUint8ArrayThe Uint8Array representation of your proof, usually obtained by calling generateFinalProof

Returns

Return valueTypeDescription
verifiedPromise <boolean>A boolean for whether the proof was verified

Usage

const proof = noirInstance.generateProof(input);
noirInstance.verifyFinalProof(proof);