@noir-lang/noir_js 0.16.0 → 0.17.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.cjs +1 -6
- package/lib/index.d.ts +1 -2
- package/lib/index.mjs +0 -2
- package/lib/program.cjs +43 -9
- package/lib/program.d.ts +12 -5
- package/lib/program.mjs +21 -7
- package/lib/witness_generation.cjs +2 -3
- package/lib/witness_generation.d.ts +3 -1
- package/lib/witness_generation.mjs +2 -3
- package/package.json +6 -7
- package/lib/serialize.cjs +0 -20
- package/lib/serialize.d.ts +0 -3
- package/lib/serialize.mjs +0 -15
package/lib/index.cjs
CHANGED
|
@@ -23,15 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Noir = exports.
|
|
26
|
+
exports.Noir = exports.abi = exports.acvm = void 0;
|
|
27
27
|
const acvm = __importStar(require("@noir-lang/acvm_js"));
|
|
28
28
|
exports.acvm = acvm;
|
|
29
29
|
const abi = __importStar(require("@noir-lang/noirc_abi"));
|
|
30
30
|
exports.abi = abi;
|
|
31
|
-
var witness_generation_js_1 = require("./witness_generation.cjs");
|
|
32
|
-
Object.defineProperty(exports, "generateWitness", { enumerable: true, get: function () { return witness_generation_js_1.generateWitness; } });
|
|
33
|
-
var serialize_js_1 = require("./serialize.cjs");
|
|
34
|
-
Object.defineProperty(exports, "acirToUint8Array", { enumerable: true, get: function () { return serialize_js_1.acirToUint8Array; } });
|
|
35
|
-
Object.defineProperty(exports, "witnessMapToUint8Array", { enumerable: true, get: function () { return serialize_js_1.witnessMapToUint8Array; } });
|
|
36
31
|
var program_js_1 = require("./program.cjs");
|
|
37
32
|
Object.defineProperty(exports, "Noir", { enumerable: true, get: function () { return program_js_1.Noir; } });
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as acvm from '@noir-lang/acvm_js';
|
|
2
2
|
import * as abi from '@noir-lang/noirc_abi';
|
|
3
3
|
export { acvm, abi };
|
|
4
|
-
export {
|
|
5
|
-
export { acirToUint8Array, witnessMapToUint8Array } from './serialize.js';
|
|
4
|
+
export { WitnessMap } from '@noir-lang/acvm_js';
|
|
6
5
|
export { Noir } from './program.js';
|
package/lib/index.mjs
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import * as acvm from '@noir-lang/acvm_js';
|
|
2
2
|
import * as abi from '@noir-lang/noirc_abi';
|
|
3
3
|
export { acvm, abi };
|
|
4
|
-
export { generateWitness } from "./witness_generation.mjs";
|
|
5
|
-
export { acirToUint8Array, witnessMapToUint8Array } from "./serialize.mjs";
|
|
6
4
|
export { Noir } from "./program.mjs";
|
package/lib/program.cjs
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
4
24
|
};
|
|
5
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
26
|
exports.Noir = void 0;
|
|
7
27
|
const witness_generation_js_1 = require("./witness_generation.cjs");
|
|
8
|
-
const noirc_abi_1 =
|
|
9
|
-
const acvm_js_1 =
|
|
28
|
+
const noirc_abi_1 = __importStar(require("@noir-lang/noirc_abi"));
|
|
29
|
+
const acvm_js_1 = __importStar(require("@noir-lang/acvm_js"));
|
|
10
30
|
class Noir {
|
|
11
31
|
circuit;
|
|
12
32
|
backend;
|
|
@@ -22,14 +42,28 @@ class Noir {
|
|
|
22
42
|
await Promise.all([(0, noirc_abi_1.default)(), (0, acvm_js_1.default)()]);
|
|
23
43
|
}
|
|
24
44
|
}
|
|
45
|
+
async destroy() {
|
|
46
|
+
await this.backend?.destroy();
|
|
47
|
+
}
|
|
48
|
+
getBackend() {
|
|
49
|
+
if (this.backend === undefined)
|
|
50
|
+
throw new Error('Operation requires a backend but none was provided');
|
|
51
|
+
return this.backend;
|
|
52
|
+
}
|
|
25
53
|
// Initial inputs to your program
|
|
26
|
-
async
|
|
54
|
+
async execute(inputs) {
|
|
27
55
|
await this.init();
|
|
28
|
-
const
|
|
29
|
-
|
|
56
|
+
const witness = await (0, witness_generation_js_1.generateWitness)(this.circuit, inputs);
|
|
57
|
+
const { return_value: returnValue } = (0, noirc_abi_1.abiDecode)(this.circuit.abi, witness);
|
|
58
|
+
return { witness: (0, acvm_js_1.compressWitness)(witness), returnValue };
|
|
59
|
+
}
|
|
60
|
+
// Initial inputs to your program
|
|
61
|
+
async generateFinalProof(inputs) {
|
|
62
|
+
const { witness } = await this.execute(inputs);
|
|
63
|
+
return this.getBackend().generateFinalProof(witness);
|
|
30
64
|
}
|
|
31
|
-
async verifyFinalProof(
|
|
32
|
-
return this.
|
|
65
|
+
async verifyFinalProof(proofData) {
|
|
66
|
+
return this.getBackend().verifyFinalProof(proofData);
|
|
33
67
|
}
|
|
34
68
|
}
|
|
35
69
|
exports.Noir = Noir;
|
package/lib/program.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import { Backend, CompiledCircuit } from '@noir-lang/types';
|
|
1
|
+
import { Backend, CompiledCircuit, ProofData } from '@noir-lang/types';
|
|
2
|
+
import { InputMap, InputValue } from '@noir-lang/noirc_abi';
|
|
2
3
|
export declare class Noir {
|
|
3
4
|
private circuit;
|
|
4
|
-
private backend
|
|
5
|
-
constructor(circuit: CompiledCircuit, backend
|
|
5
|
+
private backend?;
|
|
6
|
+
constructor(circuit: CompiledCircuit, backend?: Backend | undefined);
|
|
6
7
|
init(): Promise<void>;
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
destroy(): Promise<void>;
|
|
9
|
+
private getBackend;
|
|
10
|
+
execute(inputs: InputMap): Promise<{
|
|
11
|
+
witness: Uint8Array;
|
|
12
|
+
returnValue: InputValue;
|
|
13
|
+
}>;
|
|
14
|
+
generateFinalProof(inputs: InputMap): Promise<ProofData>;
|
|
15
|
+
verifyFinalProof(proofData: ProofData): Promise<boolean>;
|
|
9
16
|
}
|
package/lib/program.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { generateWitness } from "./witness_generation.mjs";
|
|
2
|
-
import initAbi from '@noir-lang/noirc_abi';
|
|
3
|
-
import initACVM from '@noir-lang/acvm_js';
|
|
2
|
+
import initAbi, { abiDecode } from '@noir-lang/noirc_abi';
|
|
3
|
+
import initACVM, { compressWitness } from '@noir-lang/acvm_js';
|
|
4
4
|
export class Noir {
|
|
5
5
|
circuit;
|
|
6
6
|
backend;
|
|
@@ -16,13 +16,27 @@ export class Noir {
|
|
|
16
16
|
await Promise.all([initAbi(), initACVM()]);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
async destroy() {
|
|
20
|
+
await this.backend?.destroy();
|
|
21
|
+
}
|
|
22
|
+
getBackend() {
|
|
23
|
+
if (this.backend === undefined)
|
|
24
|
+
throw new Error('Operation requires a backend but none was provided');
|
|
25
|
+
return this.backend;
|
|
26
|
+
}
|
|
19
27
|
// Initial inputs to your program
|
|
20
|
-
async
|
|
28
|
+
async execute(inputs) {
|
|
21
29
|
await this.init();
|
|
22
|
-
const
|
|
23
|
-
|
|
30
|
+
const witness = await generateWitness(this.circuit, inputs);
|
|
31
|
+
const { return_value: returnValue } = abiDecode(this.circuit.abi, witness);
|
|
32
|
+
return { witness: compressWitness(witness), returnValue };
|
|
33
|
+
}
|
|
34
|
+
// Initial inputs to your program
|
|
35
|
+
async generateFinalProof(inputs) {
|
|
36
|
+
const { witness } = await this.execute(inputs);
|
|
37
|
+
return this.getBackend().generateFinalProof(witness);
|
|
24
38
|
}
|
|
25
|
-
async verifyFinalProof(
|
|
26
|
-
return this.
|
|
39
|
+
async verifyFinalProof(proofData) {
|
|
40
|
+
return this.getBackend().verifyFinalProof(proofData);
|
|
27
41
|
}
|
|
28
42
|
}
|
|
@@ -4,18 +4,17 @@ 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
|
-
const serialize_js_1 = require("./serialize.cjs");
|
|
8
7
|
// Generates the witnesses needed to feed into the chosen proving system
|
|
9
8
|
async function generateWitness(compiledProgram, inputs) {
|
|
10
9
|
// Throws on ABI encoding error
|
|
11
|
-
const witnessMap = (0, noirc_abi_1.abiEncode)(compiledProgram.abi, inputs
|
|
10
|
+
const witnessMap = (0, noirc_abi_1.abiEncode)(compiledProgram.abi, inputs);
|
|
12
11
|
// Execute the circuit to generate the rest of the witnesses and serialize
|
|
13
12
|
// them into a Uint8Array.
|
|
14
13
|
try {
|
|
15
14
|
const solvedWitness = await (0, acvm_js_1.executeCircuit)((0, base64_decode_js_1.base64Decode)(compiledProgram.bytecode), witnessMap, () => {
|
|
16
15
|
throw Error('unexpected oracle during execution');
|
|
17
16
|
});
|
|
18
|
-
return
|
|
17
|
+
return solvedWitness;
|
|
19
18
|
}
|
|
20
19
|
catch (err) {
|
|
21
20
|
throw new Error(`Circuit execution failed: ${err}`);
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
import { InputMap } from '@noir-lang/noirc_abi';
|
|
2
|
+
import { WitnessMap } from '@noir-lang/acvm_js';
|
|
1
3
|
import { CompiledCircuit } from '@noir-lang/types';
|
|
2
|
-
export declare function generateWitness(compiledProgram: CompiledCircuit, inputs:
|
|
4
|
+
export declare function generateWitness(compiledProgram: CompiledCircuit, inputs: InputMap): Promise<WitnessMap>;
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { abiEncode } from '@noir-lang/noirc_abi';
|
|
2
2
|
import { base64Decode } from "./base64_decode.mjs";
|
|
3
3
|
import { executeCircuit } from '@noir-lang/acvm_js';
|
|
4
|
-
import { witnessMapToUint8Array } from "./serialize.mjs";
|
|
5
4
|
// Generates the witnesses needed to feed into the chosen proving system
|
|
6
5
|
export async function generateWitness(compiledProgram, inputs) {
|
|
7
6
|
// Throws on ABI encoding error
|
|
8
|
-
const witnessMap = abiEncode(compiledProgram.abi, inputs
|
|
7
|
+
const witnessMap = abiEncode(compiledProgram.abi, inputs);
|
|
9
8
|
// Execute the circuit to generate the rest of the witnesses and serialize
|
|
10
9
|
// them into a Uint8Array.
|
|
11
10
|
try {
|
|
12
11
|
const solvedWitness = await executeCircuit(base64Decode(compiledProgram.bytecode), witnessMap, () => {
|
|
13
12
|
throw Error('unexpected oracle during execution');
|
|
14
13
|
});
|
|
15
|
-
return
|
|
14
|
+
return solvedWitness;
|
|
16
15
|
}
|
|
17
16
|
catch (err) {
|
|
18
17
|
throw new Error(`Circuit execution failed: ${err}`);
|
package/package.json
CHANGED
|
@@ -3,15 +3,14 @@
|
|
|
3
3
|
"collaborators": [
|
|
4
4
|
"The Noir Team <team@noir-lang.org>"
|
|
5
5
|
],
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.17.0",
|
|
7
7
|
"packageManager": "yarn@3.5.1",
|
|
8
8
|
"license": "(MIT OR Apache-2.0)",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@noir-lang/acvm_js": "0.
|
|
12
|
-
"@noir-lang/noirc_abi": "0.
|
|
13
|
-
"@noir-lang/types": "0.
|
|
14
|
-
"fflate": "^0.8.0"
|
|
11
|
+
"@noir-lang/acvm_js": "0.29.0",
|
|
12
|
+
"@noir-lang/noirc_abi": "0.17.0",
|
|
13
|
+
"@noir-lang/types": "0.17.0"
|
|
15
14
|
},
|
|
16
15
|
"files": [
|
|
17
16
|
"lib",
|
|
@@ -35,11 +34,11 @@
|
|
|
35
34
|
"prettier": "prettier 'src/**/*.ts'",
|
|
36
35
|
"prettier:fix": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
|
|
37
36
|
"lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0",
|
|
38
|
-
"
|
|
37
|
+
"nightly:version": "jq --arg new_version \"-$(git rev-parse --short HEAD)$1\" '.version = .version + $new_version' package.json > package-tmp.json && mv package-tmp.json package.json",
|
|
38
|
+
"publish": "echo 📡 publishing `$npm_package_name` && yarn npm publish",
|
|
39
39
|
"clean": "rm -rf ./lib"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@aztec/bb.js": "0.7.2",
|
|
43
42
|
"@types/chai": "^4",
|
|
44
43
|
"@types/mocha": "^10.0.1",
|
|
45
44
|
"@types/node": "^20.6.2",
|
package/lib/serialize.cjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.acirToUint8Array = exports.witnessMapToUint8Array = void 0;
|
|
4
|
-
const acvm_js_1 = require("@noir-lang/acvm_js");
|
|
5
|
-
const fflate_1 = require("fflate");
|
|
6
|
-
const base64_decode_js_1 = require("./base64_decode.cjs");
|
|
7
|
-
// After solving the witness, to pass it a backend, we need to serialize it to a Uint8Array
|
|
8
|
-
function witnessMapToUint8Array(solvedWitness) {
|
|
9
|
-
// TODO: We just want to serialize, but this will zip up the witness
|
|
10
|
-
// TODO so its not ideal
|
|
11
|
-
const compressedWitness = (0, acvm_js_1.compressWitness)(solvedWitness);
|
|
12
|
-
return (0, fflate_1.decompressSync)(compressedWitness);
|
|
13
|
-
}
|
|
14
|
-
exports.witnessMapToUint8Array = witnessMapToUint8Array;
|
|
15
|
-
// Converts an bytecode to a Uint8Array
|
|
16
|
-
function acirToUint8Array(base64EncodedBytecode) {
|
|
17
|
-
const compressedByteCode = (0, base64_decode_js_1.base64Decode)(base64EncodedBytecode);
|
|
18
|
-
return (0, fflate_1.decompressSync)(compressedByteCode);
|
|
19
|
-
}
|
|
20
|
-
exports.acirToUint8Array = acirToUint8Array;
|
package/lib/serialize.d.ts
DELETED
package/lib/serialize.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { compressWitness } from '@noir-lang/acvm_js';
|
|
2
|
-
import { decompressSync as gunzip } from 'fflate';
|
|
3
|
-
import { base64Decode } from "./base64_decode.mjs";
|
|
4
|
-
// After solving the witness, to pass it a backend, we need to serialize it to a Uint8Array
|
|
5
|
-
export function witnessMapToUint8Array(solvedWitness) {
|
|
6
|
-
// TODO: We just want to serialize, but this will zip up the witness
|
|
7
|
-
// TODO so its not ideal
|
|
8
|
-
const compressedWitness = compressWitness(solvedWitness);
|
|
9
|
-
return gunzip(compressedWitness);
|
|
10
|
-
}
|
|
11
|
-
// Converts an bytecode to a Uint8Array
|
|
12
|
-
export function acirToUint8Array(base64EncodedBytecode) {
|
|
13
|
-
const compressedByteCode = base64Decode(base64EncodedBytecode);
|
|
14
|
-
return gunzip(compressedByteCode);
|
|
15
|
-
}
|