@noir-lang/noir_js 0.30.0 → 0.31.0
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 +2 -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 +1 -8
- package/lib/witness_generation.mjs +2 -9
- package/package.json +4 -4
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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';
|
|
@@ -8,4 +8,4 @@ export { Noir } from './program.js';
|
|
|
8
8
|
export { ErrorWithPayload } from './witness_generation.js';
|
|
9
9
|
/** @ignore */
|
|
10
10
|
export { acvm, abi };
|
|
11
|
-
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,
|
|
@@ -50,7 +43,7 @@ async function generateWitness(compiledProgram, inputs, foreignCallHandler = def
|
|
|
50
43
|
// Execute the circuit to generate the rest of the witnesses and serialize
|
|
51
44
|
// them into a Uint8Array.
|
|
52
45
|
try {
|
|
53
|
-
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);
|
|
54
47
|
return solvedWitness;
|
|
55
48
|
}
|
|
56
49
|
catch (err) {
|
|
@@ -1,13 +1,6 @@
|
|
|
1
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,
|
|
@@ -47,7 +40,7 @@ export async function generateWitness(compiledProgram, inputs, foreignCallHandle
|
|
|
47
40
|
// Execute the circuit to generate the rest of the witnesses and serialize
|
|
48
41
|
// them into a Uint8Array.
|
|
49
42
|
try {
|
|
50
|
-
const solvedWitness = await
|
|
43
|
+
const solvedWitness = await executeProgram(base64Decode(compiledProgram.bytecode), witnessMap, foreignCallHandler);
|
|
51
44
|
return solvedWitness;
|
|
52
45
|
}
|
|
53
46
|
catch (err) {
|
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.31.0",
|
|
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.47.0",
|
|
21
|
+
"@noir-lang/noirc_abi": "0.31.0",
|
|
22
|
+
"@noir-lang/types": "0.31.0"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"lib",
|