@noir-lang/noir_js 0.29.0 → 0.30.0-2e543b4.nightly
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/lib/index.d.ts +3 -2
- package/lib/program.cjs +1 -53
- package/lib/program.d.ts +2 -41
- package/lib/program.mjs +1 -53
- package/lib/witness_generation.cjs +27 -15
- package/lib/witness_generation.d.ts +4 -1
- package/lib/witness_generation.mjs +29 -17
- package/package.json +4 -4
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as acvm from '@noir-lang/acvm_js';
|
|
2
2
|
import * as abi from '@noir-lang/noirc_abi';
|
|
3
|
-
import { CompiledCircuit
|
|
3
|
+
import { CompiledCircuit } from '@noir-lang/types';
|
|
4
4
|
export { ecdsa_secp256r1_verify, ecdsa_secp256k1_verify, keccak256, blake2s256, sha256, xor, and, } from '@noir-lang/acvm_js';
|
|
5
5
|
export { InputMap } from '@noir-lang/noirc_abi';
|
|
6
6
|
export { WitnessMap, ForeignCallHandler, ForeignCallInput, ForeignCallOutput } from '@noir-lang/acvm_js';
|
|
7
7
|
export { Noir } from './program.js';
|
|
8
|
+
export { ErrorWithPayload } from './witness_generation.js';
|
|
8
9
|
/** @ignore */
|
|
9
10
|
export { acvm, abi };
|
|
10
|
-
export { CompiledCircuit
|
|
11
|
+
export { CompiledCircuit };
|
package/lib/program.cjs
CHANGED
|
@@ -29,10 +29,8 @@ const noirc_abi_1 = __importStar(require("@noir-lang/noirc_abi"));
|
|
|
29
29
|
const acvm_js_1 = __importStar(require("@noir-lang/acvm_js"));
|
|
30
30
|
class Noir {
|
|
31
31
|
circuit;
|
|
32
|
-
|
|
33
|
-
constructor(circuit, backend) {
|
|
32
|
+
constructor(circuit) {
|
|
34
33
|
this.circuit = circuit;
|
|
35
|
-
this.backend = backend;
|
|
36
34
|
}
|
|
37
35
|
/** @ignore */
|
|
38
36
|
async init() {
|
|
@@ -43,26 +41,6 @@ class Noir {
|
|
|
43
41
|
await Promise.all([(0, noirc_abi_1.default)(), (0, acvm_js_1.default)()]);
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
|
-
/**
|
|
47
|
-
*
|
|
48
|
-
* @description
|
|
49
|
-
* Destroys the underlying backend instance.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* await noir.destroy();
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
*/
|
|
57
|
-
async destroy() {
|
|
58
|
-
await this.backend?.destroy();
|
|
59
|
-
}
|
|
60
|
-
getBackend() {
|
|
61
|
-
if (this.backend === undefined)
|
|
62
|
-
throw new Error('Operation requires a backend but none was provided');
|
|
63
|
-
return this.backend;
|
|
64
|
-
}
|
|
65
|
-
// Initial inputs to your program
|
|
66
44
|
/**
|
|
67
45
|
* @description
|
|
68
46
|
* Allows to execute a circuit to get its witness and return value.
|
|
@@ -79,35 +57,5 @@ class Noir {
|
|
|
79
57
|
const { return_value: returnValue } = (0, noirc_abi_1.abiDecode)(this.circuit.abi, main_witness);
|
|
80
58
|
return { witness: (0, acvm_js_1.compressWitnessStack)(witness_stack), returnValue };
|
|
81
59
|
}
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
84
|
-
* @description
|
|
85
|
-
* Generates a witness and a proof given an object as input.
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```typescript
|
|
89
|
-
* async generateProof(input)
|
|
90
|
-
* ```
|
|
91
|
-
*
|
|
92
|
-
*/
|
|
93
|
-
async generateProof(inputs, foreignCallHandler) {
|
|
94
|
-
const { witness } = await this.execute(inputs, foreignCallHandler);
|
|
95
|
-
return this.getBackend().generateProof(witness);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
*
|
|
99
|
-
* @description
|
|
100
|
-
* Instantiates the verification key and verifies a proof.
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* ```typescript
|
|
105
|
-
* async verifyProof(proof)
|
|
106
|
-
* ```
|
|
107
|
-
*
|
|
108
|
-
*/
|
|
109
|
-
async verifyProof(proofData) {
|
|
110
|
-
return this.getBackend().verifyProof(proofData);
|
|
111
|
-
}
|
|
112
60
|
}
|
|
113
61
|
exports.Noir = Noir;
|
package/lib/program.d.ts
CHANGED
|
@@ -1,25 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CompiledCircuit } from '@noir-lang/types';
|
|
2
2
|
import { InputMap, InputValue } from '@noir-lang/noirc_abi';
|
|
3
3
|
import { ForeignCallHandler } from '@noir-lang/acvm_js';
|
|
4
4
|
export declare class Noir {
|
|
5
5
|
private circuit;
|
|
6
|
-
|
|
7
|
-
constructor(circuit: CompiledCircuit, backend?: Backend | undefined);
|
|
6
|
+
constructor(circuit: CompiledCircuit);
|
|
8
7
|
/** @ignore */
|
|
9
8
|
init(): Promise<void>;
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
* @description
|
|
13
|
-
* Destroys the underlying backend instance.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* await noir.destroy();
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
destroy(): Promise<void>;
|
|
22
|
-
private getBackend;
|
|
23
9
|
/**
|
|
24
10
|
* @description
|
|
25
11
|
* Allows to execute a circuit to get its witness and return value.
|
|
@@ -33,29 +19,4 @@ export declare class Noir {
|
|
|
33
19
|
witness: Uint8Array;
|
|
34
20
|
returnValue: InputValue;
|
|
35
21
|
}>;
|
|
36
|
-
/**
|
|
37
|
-
*
|
|
38
|
-
* @description
|
|
39
|
-
* Generates a witness and a proof given an object as input.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* async generateProof(input)
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
*/
|
|
47
|
-
generateProof(inputs: InputMap, foreignCallHandler?: ForeignCallHandler): Promise<ProofData>;
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
50
|
-
* @description
|
|
51
|
-
* Instantiates the verification key and verifies a proof.
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* async verifyProof(proof)
|
|
57
|
-
* ```
|
|
58
|
-
*
|
|
59
|
-
*/
|
|
60
|
-
verifyProof(proofData: ProofData): Promise<boolean>;
|
|
61
22
|
}
|
package/lib/program.mjs
CHANGED
|
@@ -3,10 +3,8 @@ import initAbi, { abiDecode } from '@noir-lang/noirc_abi';
|
|
|
3
3
|
import initACVM, { compressWitnessStack } from '@noir-lang/acvm_js';
|
|
4
4
|
export class Noir {
|
|
5
5
|
circuit;
|
|
6
|
-
|
|
7
|
-
constructor(circuit, backend) {
|
|
6
|
+
constructor(circuit) {
|
|
8
7
|
this.circuit = circuit;
|
|
9
|
-
this.backend = backend;
|
|
10
8
|
}
|
|
11
9
|
/** @ignore */
|
|
12
10
|
async init() {
|
|
@@ -17,26 +15,6 @@ export class Noir {
|
|
|
17
15
|
await Promise.all([initAbi(), initACVM()]);
|
|
18
16
|
}
|
|
19
17
|
}
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
* @description
|
|
23
|
-
* Destroys the underlying backend instance.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* await noir.destroy();
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
*/
|
|
31
|
-
async destroy() {
|
|
32
|
-
await this.backend?.destroy();
|
|
33
|
-
}
|
|
34
|
-
getBackend() {
|
|
35
|
-
if (this.backend === undefined)
|
|
36
|
-
throw new Error('Operation requires a backend but none was provided');
|
|
37
|
-
return this.backend;
|
|
38
|
-
}
|
|
39
|
-
// Initial inputs to your program
|
|
40
18
|
/**
|
|
41
19
|
* @description
|
|
42
20
|
* Allows to execute a circuit to get its witness and return value.
|
|
@@ -53,34 +31,4 @@ export class Noir {
|
|
|
53
31
|
const { return_value: returnValue } = abiDecode(this.circuit.abi, main_witness);
|
|
54
32
|
return { witness: compressWitnessStack(witness_stack), returnValue };
|
|
55
33
|
}
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
* @description
|
|
59
|
-
* Generates a witness and a proof given an object as input.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```typescript
|
|
63
|
-
* async generateProof(input)
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
*/
|
|
67
|
-
async generateProof(inputs, foreignCallHandler) {
|
|
68
|
-
const { witness } = await this.execute(inputs, foreignCallHandler);
|
|
69
|
-
return this.getBackend().generateProof(witness);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
*
|
|
73
|
-
* @description
|
|
74
|
-
* Instantiates the verification key and verifies a proof.
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```typescript
|
|
79
|
-
* async verifyProof(proof)
|
|
80
|
-
* ```
|
|
81
|
-
*
|
|
82
|
-
*/
|
|
83
|
-
async verifyProof(proofData) {
|
|
84
|
-
return this.getBackend().verifyProof(proofData);
|
|
85
|
-
}
|
|
86
34
|
}
|
|
@@ -4,13 +4,6 @@ exports.generateWitness = void 0;
|
|
|
4
4
|
const noirc_abi_1 = require("@noir-lang/noirc_abi");
|
|
5
5
|
const base64_decode_js_1 = require("./base64_decode.cjs");
|
|
6
6
|
const acvm_js_1 = require("@noir-lang/acvm_js");
|
|
7
|
-
let solver;
|
|
8
|
-
const getSolver = () => {
|
|
9
|
-
if (!solver) {
|
|
10
|
-
solver = (0, acvm_js_1.createBlackBoxSolver)();
|
|
11
|
-
}
|
|
12
|
-
return solver;
|
|
13
|
-
};
|
|
14
7
|
const defaultForeignCallHandler = async (name, args) => {
|
|
15
8
|
if (name == 'print') {
|
|
16
9
|
// By default we do not print anything for `print` foreign calls due to a need for formatting,
|
|
@@ -19,15 +12,30 @@ const defaultForeignCallHandler = async (name, args) => {
|
|
|
19
12
|
// If a user needs to print values then they should provide a custom foreign call handler.
|
|
20
13
|
return [];
|
|
21
14
|
}
|
|
22
|
-
else if (name == 'assert_message') {
|
|
23
|
-
// By default we do not do anything for `assert_message` foreign calls due to a need for formatting,
|
|
24
|
-
// however we provide an empty response in order to not halt execution.
|
|
25
|
-
//
|
|
26
|
-
// If a user needs to use dynamic assertion messages then they should provide a custom foreign call handler.
|
|
27
|
-
return [];
|
|
28
|
-
}
|
|
29
15
|
throw Error(`Unexpected oracle during execution: ${name}(${args.join(', ')})`);
|
|
30
16
|
};
|
|
17
|
+
function parseErrorPayload(abi, originalError) {
|
|
18
|
+
const payload = originalError.rawAssertionPayload;
|
|
19
|
+
if (!payload)
|
|
20
|
+
return originalError;
|
|
21
|
+
const enrichedError = originalError;
|
|
22
|
+
try {
|
|
23
|
+
// Decode the payload
|
|
24
|
+
const decodedPayload = (0, noirc_abi_1.abiDecodeError)(abi, payload);
|
|
25
|
+
if (typeof decodedPayload === 'string') {
|
|
26
|
+
// If it's a string, just add it to the error message
|
|
27
|
+
enrichedError.message = `Circuit execution failed: ${decodedPayload}`;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// If not, attach the payload to the original error
|
|
31
|
+
enrichedError.decodedAssertionPayload = decodedPayload;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (_errorDecoding) {
|
|
35
|
+
// Ignore errors decoding the payload
|
|
36
|
+
}
|
|
37
|
+
return enrichedError;
|
|
38
|
+
}
|
|
31
39
|
// Generates the witnesses needed to feed into the chosen proving system
|
|
32
40
|
async function generateWitness(compiledProgram, inputs, foreignCallHandler = defaultForeignCallHandler) {
|
|
33
41
|
// Throws on ABI encoding error
|
|
@@ -35,10 +43,14 @@ async function generateWitness(compiledProgram, inputs, foreignCallHandler = def
|
|
|
35
43
|
// Execute the circuit to generate the rest of the witnesses and serialize
|
|
36
44
|
// them into a Uint8Array.
|
|
37
45
|
try {
|
|
38
|
-
const solvedWitness = await (0, acvm_js_1.
|
|
46
|
+
const solvedWitness = await (0, acvm_js_1.executeProgram)((0, base64_decode_js_1.base64Decode)(compiledProgram.bytecode), witnessMap, foreignCallHandler);
|
|
39
47
|
return solvedWitness;
|
|
40
48
|
}
|
|
41
49
|
catch (err) {
|
|
50
|
+
// Typescript types catched errors as unknown or any, so we need to narrow its type to check if it has raw assertion payload.
|
|
51
|
+
if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err) {
|
|
52
|
+
throw parseErrorPayload(compiledProgram.abi, err);
|
|
53
|
+
}
|
|
42
54
|
throw new Error(`Circuit execution failed: ${err}`);
|
|
43
55
|
}
|
|
44
56
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { InputMap } from '@noir-lang/noirc_abi';
|
|
2
|
-
import { WitnessStack, ForeignCallHandler } from '@noir-lang/acvm_js';
|
|
2
|
+
import { WitnessStack, ForeignCallHandler, ExecutionError } from '@noir-lang/acvm_js';
|
|
3
3
|
import { CompiledCircuit } from '@noir-lang/types';
|
|
4
|
+
export type ErrorWithPayload = ExecutionError & {
|
|
5
|
+
decodedAssertionPayload?: any;
|
|
6
|
+
};
|
|
4
7
|
export declare function generateWitness(compiledProgram: CompiledCircuit, inputs: InputMap, foreignCallHandler?: ForeignCallHandler): Promise<WitnessStack>;
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import { abiEncode } from '@noir-lang/noirc_abi';
|
|
1
|
+
import { abiDecodeError, abiEncode } from '@noir-lang/noirc_abi';
|
|
2
2
|
import { base64Decode } from "./base64_decode.mjs";
|
|
3
|
-
import {
|
|
4
|
-
let solver;
|
|
5
|
-
const getSolver = () => {
|
|
6
|
-
if (!solver) {
|
|
7
|
-
solver = createBlackBoxSolver();
|
|
8
|
-
}
|
|
9
|
-
return solver;
|
|
10
|
-
};
|
|
3
|
+
import { executeProgram } from '@noir-lang/acvm_js';
|
|
11
4
|
const defaultForeignCallHandler = async (name, args) => {
|
|
12
5
|
if (name == 'print') {
|
|
13
6
|
// By default we do not print anything for `print` foreign calls due to a need for formatting,
|
|
@@ -16,15 +9,30 @@ const defaultForeignCallHandler = async (name, args) => {
|
|
|
16
9
|
// If a user needs to print values then they should provide a custom foreign call handler.
|
|
17
10
|
return [];
|
|
18
11
|
}
|
|
19
|
-
else if (name == 'assert_message') {
|
|
20
|
-
// By default we do not do anything for `assert_message` foreign calls due to a need for formatting,
|
|
21
|
-
// however we provide an empty response in order to not halt execution.
|
|
22
|
-
//
|
|
23
|
-
// If a user needs to use dynamic assertion messages then they should provide a custom foreign call handler.
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
26
12
|
throw Error(`Unexpected oracle during execution: ${name}(${args.join(', ')})`);
|
|
27
13
|
};
|
|
14
|
+
function parseErrorPayload(abi, originalError) {
|
|
15
|
+
const payload = originalError.rawAssertionPayload;
|
|
16
|
+
if (!payload)
|
|
17
|
+
return originalError;
|
|
18
|
+
const enrichedError = originalError;
|
|
19
|
+
try {
|
|
20
|
+
// Decode the payload
|
|
21
|
+
const decodedPayload = abiDecodeError(abi, payload);
|
|
22
|
+
if (typeof decodedPayload === 'string') {
|
|
23
|
+
// If it's a string, just add it to the error message
|
|
24
|
+
enrichedError.message = `Circuit execution failed: ${decodedPayload}`;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// If not, attach the payload to the original error
|
|
28
|
+
enrichedError.decodedAssertionPayload = decodedPayload;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (_errorDecoding) {
|
|
32
|
+
// Ignore errors decoding the payload
|
|
33
|
+
}
|
|
34
|
+
return enrichedError;
|
|
35
|
+
}
|
|
28
36
|
// Generates the witnesses needed to feed into the chosen proving system
|
|
29
37
|
export async function generateWitness(compiledProgram, inputs, foreignCallHandler = defaultForeignCallHandler) {
|
|
30
38
|
// Throws on ABI encoding error
|
|
@@ -32,10 +40,14 @@ export async function generateWitness(compiledProgram, inputs, foreignCallHandle
|
|
|
32
40
|
// Execute the circuit to generate the rest of the witnesses and serialize
|
|
33
41
|
// them into a Uint8Array.
|
|
34
42
|
try {
|
|
35
|
-
const solvedWitness = await
|
|
43
|
+
const solvedWitness = await executeProgram(base64Decode(compiledProgram.bytecode), witnessMap, foreignCallHandler);
|
|
36
44
|
return solvedWitness;
|
|
37
45
|
}
|
|
38
46
|
catch (err) {
|
|
47
|
+
// Typescript types catched errors as unknown or any, so we need to narrow its type to check if it has raw assertion payload.
|
|
48
|
+
if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err) {
|
|
49
|
+
throw parseErrorPayload(compiledProgram.abi, err);
|
|
50
|
+
}
|
|
39
51
|
throw new Error(`Circuit execution failed: ${err}`);
|
|
40
52
|
}
|
|
41
53
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"contributors": [
|
|
4
4
|
"The Noir Team <team@noir-lang.org>"
|
|
5
5
|
],
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.30.0-2e543b4.nightly",
|
|
7
7
|
"packageManager": "yarn@3.5.1",
|
|
8
8
|
"license": "(MIT OR Apache-2.0)",
|
|
9
9
|
"type": "module",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"url": "https://github.com/noir-lang/noir/issues"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@noir-lang/acvm_js": "0.
|
|
21
|
-
"@noir-lang/noirc_abi": "0.
|
|
22
|
-
"@noir-lang/types": "0.
|
|
20
|
+
"@noir-lang/acvm_js": "0.46.0-2e543b4.nightly",
|
|
21
|
+
"@noir-lang/noirc_abi": "0.30.0-2e543b4.nightly",
|
|
22
|
+
"@noir-lang/types": "0.30.0-2e543b4.nightly"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"lib",
|