@noir-lang/noir_js 0.18.0 → 0.19.0-e5a1f78.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.cjs CHANGED
@@ -23,10 +23,18 @@ 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.abi = exports.acvm = void 0;
26
+ exports.abi = exports.acvm = exports.Noir = exports.and = exports.xor = exports.sha256 = exports.blake2s256 = exports.keccak256 = exports.ecdsa_secp256k1_verify = exports.ecdsa_secp256r1_verify = 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 acvm_js_1 = require("@noir-lang/acvm_js");
32
+ Object.defineProperty(exports, "ecdsa_secp256r1_verify", { enumerable: true, get: function () { return acvm_js_1.ecdsa_secp256r1_verify; } });
33
+ Object.defineProperty(exports, "ecdsa_secp256k1_verify", { enumerable: true, get: function () { return acvm_js_1.ecdsa_secp256k1_verify; } });
34
+ Object.defineProperty(exports, "keccak256", { enumerable: true, get: function () { return acvm_js_1.keccak256; } });
35
+ Object.defineProperty(exports, "blake2s256", { enumerable: true, get: function () { return acvm_js_1.blake2s256; } });
36
+ Object.defineProperty(exports, "sha256", { enumerable: true, get: function () { return acvm_js_1.sha256; } });
37
+ Object.defineProperty(exports, "xor", { enumerable: true, get: function () { return acvm_js_1.xor; } });
38
+ Object.defineProperty(exports, "and", { enumerable: true, get: function () { return acvm_js_1.and; } });
31
39
  var program_js_1 = require("./program.cjs");
32
40
  Object.defineProperty(exports, "Noir", { enumerable: true, get: function () { return program_js_1.Noir; } });
package/lib/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import * as acvm from '@noir-lang/acvm_js';
2
2
  import * as abi from '@noir-lang/noirc_abi';
3
- export { acvm, abi };
4
- export { WitnessMap } from '@noir-lang/acvm_js';
3
+ import { CompiledCircuit, ProofData } from '@noir-lang/types';
4
+ export { ecdsa_secp256r1_verify, ecdsa_secp256k1_verify, keccak256, blake2s256, sha256, xor, and, } from '@noir-lang/acvm_js';
5
+ export { WitnessMap, ForeignCallHandler, ForeignCallInput, ForeignCallOutput } from '@noir-lang/acvm_js';
5
6
  export { Noir } from './program.js';
7
+ /** @ignore */
8
+ export { acvm, abi };
9
+ export { CompiledCircuit, ProofData };
package/lib/index.mjs CHANGED
@@ -1,4 +1,6 @@
1
1
  import * as acvm from '@noir-lang/acvm_js';
2
2
  import * as abi from '@noir-lang/noirc_abi';
3
- export { acvm, abi };
3
+ export { ecdsa_secp256r1_verify, ecdsa_secp256k1_verify, keccak256, blake2s256, sha256, xor, and, } from '@noir-lang/acvm_js';
4
4
  export { Noir } from "./program.mjs";
5
+ /** @ignore */
6
+ export { acvm, abi };
package/lib/program.cjs CHANGED
@@ -34,6 +34,7 @@ class Noir {
34
34
  this.circuit = circuit;
35
35
  this.backend = backend;
36
36
  }
37
+ /** @ignore */
37
38
  async init() {
38
39
  // If these are available, then we are in the
39
40
  // web environment. For the node environment, this
@@ -42,6 +43,17 @@ class Noir {
42
43
  await Promise.all([(0, noirc_abi_1.default)(), (0, acvm_js_1.default)()]);
43
44
  }
44
45
  }
46
+ /**
47
+ *
48
+ * @description
49
+ * Destroys the underlying backend instance.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * await noir.destroy();
54
+ * ```
55
+ *
56
+ */
45
57
  async destroy() {
46
58
  await this.backend?.destroy();
47
59
  }
@@ -51,17 +63,48 @@ class Noir {
51
63
  return this.backend;
52
64
  }
53
65
  // Initial inputs to your program
54
- async execute(inputs) {
66
+ /**
67
+ * @description
68
+ * Allows to execute a circuit to get its witness and return value.
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * async execute(inputs)
73
+ * ```
74
+ */
75
+ async execute(inputs, foreignCallHandler) {
55
76
  await this.init();
56
- const witness = await (0, witness_generation_js_1.generateWitness)(this.circuit, inputs);
77
+ const witness = await (0, witness_generation_js_1.generateWitness)(this.circuit, inputs, foreignCallHandler);
57
78
  const { return_value: returnValue } = (0, noirc_abi_1.abiDecode)(this.circuit.abi, witness);
58
79
  return { witness: (0, acvm_js_1.compressWitness)(witness), returnValue };
59
80
  }
60
- // Initial inputs to your program
81
+ /**
82
+ *
83
+ * @description
84
+ * Generates a witness and a proof given an object as input.
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * async generateFinalproof(input)
89
+ * ```
90
+ *
91
+ */
61
92
  async generateFinalProof(inputs) {
62
93
  const { witness } = await this.execute(inputs);
63
94
  return this.getBackend().generateFinalProof(witness);
64
95
  }
96
+ /**
97
+ *
98
+ * @description
99
+ * Instantiates the verification key and verifies a proof.
100
+ *
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * async verifyFinalProof(proof)
105
+ * ```
106
+ *
107
+ */
65
108
  async verifyFinalProof(proofData) {
66
109
  return this.getBackend().verifyFinalProof(proofData);
67
110
  }
package/lib/program.d.ts CHANGED
@@ -1,16 +1,61 @@
1
1
  import { Backend, CompiledCircuit, ProofData } from '@noir-lang/types';
2
2
  import { InputMap, InputValue } from '@noir-lang/noirc_abi';
3
+ import { ForeignCallHandler } from '@noir-lang/acvm_js';
3
4
  export declare class Noir {
4
5
  private circuit;
5
6
  private backend?;
6
7
  constructor(circuit: CompiledCircuit, backend?: Backend | undefined);
8
+ /** @ignore */
7
9
  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
+ */
8
21
  destroy(): Promise<void>;
9
22
  private getBackend;
10
- execute(inputs: InputMap): Promise<{
23
+ /**
24
+ * @description
25
+ * Allows to execute a circuit to get its witness and return value.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * async execute(inputs)
30
+ * ```
31
+ */
32
+ execute(inputs: InputMap, foreignCallHandler?: ForeignCallHandler): Promise<{
11
33
  witness: Uint8Array;
12
34
  returnValue: InputValue;
13
35
  }>;
36
+ /**
37
+ *
38
+ * @description
39
+ * Generates a witness and a proof given an object as input.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * async generateFinalproof(input)
44
+ * ```
45
+ *
46
+ */
14
47
  generateFinalProof(inputs: InputMap): Promise<ProofData>;
48
+ /**
49
+ *
50
+ * @description
51
+ * Instantiates the verification key and verifies a proof.
52
+ *
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * async verifyFinalProof(proof)
57
+ * ```
58
+ *
59
+ */
15
60
  verifyFinalProof(proofData: ProofData): Promise<boolean>;
16
61
  }
package/lib/program.mjs CHANGED
@@ -8,6 +8,7 @@ export class Noir {
8
8
  this.circuit = circuit;
9
9
  this.backend = backend;
10
10
  }
11
+ /** @ignore */
11
12
  async init() {
12
13
  // If these are available, then we are in the
13
14
  // web environment. For the node environment, this
@@ -16,6 +17,17 @@ export class Noir {
16
17
  await Promise.all([initAbi(), initACVM()]);
17
18
  }
18
19
  }
20
+ /**
21
+ *
22
+ * @description
23
+ * Destroys the underlying backend instance.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * await noir.destroy();
28
+ * ```
29
+ *
30
+ */
19
31
  async destroy() {
20
32
  await this.backend?.destroy();
21
33
  }
@@ -25,17 +37,48 @@ export class Noir {
25
37
  return this.backend;
26
38
  }
27
39
  // Initial inputs to your program
28
- async execute(inputs) {
40
+ /**
41
+ * @description
42
+ * Allows to execute a circuit to get its witness and return value.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * async execute(inputs)
47
+ * ```
48
+ */
49
+ async execute(inputs, foreignCallHandler) {
29
50
  await this.init();
30
- const witness = await generateWitness(this.circuit, inputs);
51
+ const witness = await generateWitness(this.circuit, inputs, foreignCallHandler);
31
52
  const { return_value: returnValue } = abiDecode(this.circuit.abi, witness);
32
53
  return { witness: compressWitness(witness), returnValue };
33
54
  }
34
- // Initial inputs to your program
55
+ /**
56
+ *
57
+ * @description
58
+ * Generates a witness and a proof given an object as input.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * async generateFinalproof(input)
63
+ * ```
64
+ *
65
+ */
35
66
  async generateFinalProof(inputs) {
36
67
  const { witness } = await this.execute(inputs);
37
68
  return this.getBackend().generateFinalProof(witness);
38
69
  }
70
+ /**
71
+ *
72
+ * @description
73
+ * Instantiates the verification key and verifies a proof.
74
+ *
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * async verifyFinalProof(proof)
79
+ * ```
80
+ *
81
+ */
39
82
  async verifyFinalProof(proofData) {
40
83
  return this.getBackend().verifyFinalProof(proofData);
41
84
  }
@@ -4,16 +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 defaultForeignCallHandler = (name, args) => {
8
+ throw Error(`Unexpected oracle during execution: ${name}(${args.join(', ')})`);
9
+ };
7
10
  // Generates the witnesses needed to feed into the chosen proving system
8
- async function generateWitness(compiledProgram, inputs) {
11
+ async function generateWitness(compiledProgram, inputs, foreignCallHandler = defaultForeignCallHandler) {
9
12
  // Throws on ABI encoding error
10
13
  const witnessMap = (0, noirc_abi_1.abiEncode)(compiledProgram.abi, inputs);
11
14
  // Execute the circuit to generate the rest of the witnesses and serialize
12
15
  // them into a Uint8Array.
13
16
  try {
14
- const solvedWitness = await (0, acvm_js_1.executeCircuit)((0, base64_decode_js_1.base64Decode)(compiledProgram.bytecode), witnessMap, () => {
15
- throw Error('unexpected oracle during execution');
16
- });
17
+ const solvedWitness = await (0, acvm_js_1.executeCircuit)((0, base64_decode_js_1.base64Decode)(compiledProgram.bytecode), witnessMap, foreignCallHandler);
17
18
  return solvedWitness;
18
19
  }
19
20
  catch (err) {
@@ -1,4 +1,4 @@
1
1
  import { InputMap } from '@noir-lang/noirc_abi';
2
- import { WitnessMap } from '@noir-lang/acvm_js';
2
+ import { WitnessMap, ForeignCallHandler } from '@noir-lang/acvm_js';
3
3
  import { CompiledCircuit } from '@noir-lang/types';
4
- export declare function generateWitness(compiledProgram: CompiledCircuit, inputs: InputMap): Promise<WitnessMap>;
4
+ export declare function generateWitness(compiledProgram: CompiledCircuit, inputs: InputMap, foreignCallHandler?: ForeignCallHandler): Promise<WitnessMap>;
@@ -1,16 +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
+ const defaultForeignCallHandler = (name, args) => {
5
+ throw Error(`Unexpected oracle during execution: ${name}(${args.join(', ')})`);
6
+ };
4
7
  // Generates the witnesses needed to feed into the chosen proving system
5
- export async function generateWitness(compiledProgram, inputs) {
8
+ export async function generateWitness(compiledProgram, inputs, foreignCallHandler = defaultForeignCallHandler) {
6
9
  // Throws on ABI encoding error
7
10
  const witnessMap = abiEncode(compiledProgram.abi, inputs);
8
11
  // Execute the circuit to generate the rest of the witnesses and serialize
9
12
  // them into a Uint8Array.
10
13
  try {
11
- const solvedWitness = await executeCircuit(base64Decode(compiledProgram.bytecode), witnessMap, () => {
12
- throw Error('unexpected oracle during execution');
13
- });
14
+ const solvedWitness = await executeCircuit(base64Decode(compiledProgram.bytecode), witnessMap, foreignCallHandler);
14
15
  return solvedWitness;
15
16
  }
16
17
  catch (err) {
package/package.json CHANGED
@@ -3,14 +3,14 @@
3
3
  "collaborators": [
4
4
  "The Noir Team <team@noir-lang.org>"
5
5
  ],
6
- "version": "0.18.0",
6
+ "version": "0.19.0-e5a1f78.nightly",
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.30.0",
12
- "@noir-lang/noirc_abi": "0.18.0",
13
- "@noir-lang/types": "0.18.0"
11
+ "@noir-lang/acvm_js": "0.31.0-e5a1f78.nightly",
12
+ "@noir-lang/noirc_abi": "0.19.0-e5a1f78.nightly",
13
+ "@noir-lang/types": "0.19.0-e5a1f78.nightly"
14
14
  },
15
15
  "files": [
16
16
  "lib",