@solarity/zkit 0.1.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/LICENSE +21 -0
- package/README.md +120 -0
- package/dist/config/config.d.ts +24 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +17 -0
- package/dist/config/config.js.map +1 -0
- package/dist/core/CircomZKit.d.ts +39 -0
- package/dist/core/CircomZKit.d.ts.map +1 -0
- package/dist/core/CircomZKit.js +94 -0
- package/dist/core/CircomZKit.js.map +1 -0
- package/dist/core/CircuitZKit.d.ts +146 -0
- package/dist/core/CircuitZKit.d.ts.map +1 -0
- package/dist/core/CircuitZKit.js +342 -0
- package/dist/core/CircuitZKit.js.map +1 -0
- package/dist/core/ManagerZKit.d.ts +97 -0
- package/dist/core/ManagerZKit.d.ts.map +1 -0
- package/dist/core/ManagerZKit.js +222 -0
- package/dist/core/ManagerZKit.js.map +1 -0
- package/dist/core/templates/verifier_groth16.sol.ejs +164 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/types/types.d.ts +46 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +3 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/utils.d.ts +18 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +58 -0
- package/dist/utils/utils.js.map +1 -0
- package/package.json +51 -0
- package/src/config/config.ts +37 -0
- package/src/core/CircomZKit.ts +110 -0
- package/src/core/CircuitZKit.ts +375 -0
- package/src/core/ManagerZKit.ts +231 -0
- package/src/core/templates/verifier_groth16.sol.ejs +164 -0
- package/src/index.ts +7 -0
- package/src/types/types.ts +43 -0
- package/src/utils/utils.ts +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Solarity
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@solarity/zkit)
|
|
2
|
+
[](https://opensource.org/licenses/MIT)
|
|
3
|
+
|
|
4
|
+
# ZKit - Circom Zero Knowledge Kit
|
|
5
|
+
|
|
6
|
+
**A zero knowledge kit that helps you develop circuits using Circom.**
|
|
7
|
+
|
|
8
|
+
- Compile and interact with circuits without snarkjs hassle.
|
|
9
|
+
- Generate and verify ZK proofs with a single line of code.
|
|
10
|
+
- Render optimized Solidity verifiers.
|
|
11
|
+
- Forget about native dependencies - everything is in TypeScript.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
To install the package, run:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install --save-dev @solarity/zkit
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### CircomZKit
|
|
24
|
+
|
|
25
|
+
ZKit is a configless package, which means you don't need to provide any configuration to use it:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { CircomZKit } from "@solarity/zkit";
|
|
29
|
+
|
|
30
|
+
async function main() {
|
|
31
|
+
const zkit = new CircomZKit();
|
|
32
|
+
|
|
33
|
+
const multiplier = zkit.getCircuit("Multiplier");
|
|
34
|
+
|
|
35
|
+
// Generates artifacts in the "./zkit-artifacts" directory
|
|
36
|
+
await multiplier.compile();
|
|
37
|
+
|
|
38
|
+
// Generates ZK proof
|
|
39
|
+
const proof = await multiplier.generateProof({ a: 2, b: 3});
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
By default, ZKit will look for the circuit file in the `./circuits` directory. However, you can change this by providing a custom one:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
new CircomZKit({ circuitsDir: "./my-circuits" });
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
To generate zkey, the power-of-tau file is required. ZKit automatically downloads those files from [Hermes](https://hermez.s3-eu-west-1.amazonaws.com/) to the `${HOME}/.zkit/.ptau` directory, so you don't need to re-download them every time you start a new project.
|
|
50
|
+
|
|
51
|
+
You can also provide a custom path to the directory where the power-of-tau files are stored:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
new CircomZKit({ ptauDir: "./my-ptau" });
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
> [!IMPORTANT]
|
|
58
|
+
> Note that all the files in the `ptauDir` directory must have the `powers-of-tau-{x}.ptau` name format, where `{x}` is a maximum degree (2<sup>x</sup>) of constraints a `ptau` supports.
|
|
59
|
+
|
|
60
|
+
ZKit may also ask you for the permission to download the power-of-tau files. You can enable this by toggling off the `allowDownload` option:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
new CircomZKit({ allowDownload: false });
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### CircuitZKit
|
|
67
|
+
|
|
68
|
+
Once you created a `CircuitZKit` instance using the `getCircuit` method, you can manage the underlying circuit using the following methods:
|
|
69
|
+
|
|
70
|
+
> [!NOTE]
|
|
71
|
+
> You should first compile the circuit before creating verifiers or generating proofs.
|
|
72
|
+
|
|
73
|
+
#### compile()
|
|
74
|
+
|
|
75
|
+
Compiles the circuit and generates the artifacts in the `./zkit-artifacts` or in the provided `artifactsDir` directory. The default output is `r1cs`, `zkey` and `vkey` files.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
await multiplier.compile();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### createVerifier()
|
|
82
|
+
|
|
83
|
+
Creates Solidity verifier contract in the `./contracts/verifiers` or in the provided `verifiersDir` directory.
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
await multiplier.createVerifier();
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### generateProof()
|
|
90
|
+
|
|
91
|
+
Generates a proof for the given inputs.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
/// { proof: { pi_a, pi_b, pi_c, protocol, curve }, publicSignals: [6] }
|
|
95
|
+
const proof = await multiplier.generateProof({ a: 2, b: 3});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### verifyProof()
|
|
99
|
+
|
|
100
|
+
Verifies the proof.
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
/// true
|
|
104
|
+
const isValidProof = await multiplier.verifyProof(proof);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### generateCalldata()
|
|
108
|
+
|
|
109
|
+
Generates calldata by proof for the Solidity verifier's `verifyProof()` method.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
/// You can use this calldata to call the verifier contract
|
|
113
|
+
const calldata = await multiplier.generateCalldata(proof);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Known limitations
|
|
117
|
+
|
|
118
|
+
- Currently, ZKit supports only the Groth16 proving system.
|
|
119
|
+
- Zkey generation doesn't allow additional contributions.
|
|
120
|
+
- The `compile` method may cause [issues](https://github.com/iden3/snarkjs/issues/494).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
declare const Context: any;
|
|
2
|
+
export type ManagerZKitConfig = {
|
|
3
|
+
circuitsDir: string;
|
|
4
|
+
artifactsDir: string;
|
|
5
|
+
verifiersDir: string;
|
|
6
|
+
ptauDir: string;
|
|
7
|
+
allowDownload: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const defaultManagerOptions: Partial<ManagerZKitConfig>;
|
|
10
|
+
export type CompileOptions = {
|
|
11
|
+
sym: boolean;
|
|
12
|
+
json: boolean;
|
|
13
|
+
c: boolean;
|
|
14
|
+
quiet: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare const defaultCompileOptions: CompileOptions;
|
|
17
|
+
export type ManagerZKitPrivateConfig = ManagerZKitConfig & {
|
|
18
|
+
compiler: typeof Context;
|
|
19
|
+
templates: {
|
|
20
|
+
groth16: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAAA,QAAA,MAAQ,OAAO,KAAuC,CAAC;AAEvD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,OAAO,CAAC,iBAAiB,CAK5D,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;IACd,CAAC,EAAE,OAAO,CAAC;IACX,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,cAKnC,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,iBAAiB,GAAG;IACzD,QAAQ,EAAE,OAAO,OAAO,CAAC;IACzB,SAAS,EAAE;QACT,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultCompileOptions = exports.defaultManagerOptions = void 0;
|
|
4
|
+
const { Context } = require("@distributedlab/circom2");
|
|
5
|
+
exports.defaultManagerOptions = {
|
|
6
|
+
circuitsDir: "circuits",
|
|
7
|
+
artifactsDir: "zkit-artifacts",
|
|
8
|
+
verifiersDir: "contracts/verifiers",
|
|
9
|
+
allowDownload: true,
|
|
10
|
+
};
|
|
11
|
+
exports.defaultCompileOptions = {
|
|
12
|
+
sym: false,
|
|
13
|
+
json: false,
|
|
14
|
+
c: false,
|
|
15
|
+
quiet: false,
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":";;;AAAA,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAU1C,QAAA,qBAAqB,GAA+B;IAC/D,WAAW,EAAE,UAAU;IACvB,YAAY,EAAE,gBAAgB;IAC9B,YAAY,EAAE,qBAAqB;IACnC,aAAa,EAAE,IAAI;CACpB,CAAC;AASW,QAAA,qBAAqB,GAAmB;IACnD,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,KAAK;IACX,CAAC,EAAE,KAAK;IACR,KAAK,EAAE,KAAK;CACb,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CircuitZKit } from "./CircuitZKit";
|
|
2
|
+
import { CircuitInfo } from "../types/types";
|
|
3
|
+
import { ManagerZKitConfig } from "../config/config";
|
|
4
|
+
/**
|
|
5
|
+
* `CircomZKit` acts as a factory for `CircuitZKit` instances.
|
|
6
|
+
*/
|
|
7
|
+
export declare class CircomZKit {
|
|
8
|
+
private readonly _manager;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new `CircomZKit` instance.
|
|
11
|
+
*
|
|
12
|
+
* @param {Partial<ManagerZKitConfig>} [options=defaultManagerOptions] - The configuration options to use.
|
|
13
|
+
*/
|
|
14
|
+
constructor(options?: Partial<ManagerZKitConfig>);
|
|
15
|
+
/**
|
|
16
|
+
* Returns a `CircuitZKit` instance for the specified circuit.
|
|
17
|
+
*
|
|
18
|
+
* @dev If the circuit id is not unique, the path to the circuit file must be provided.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} circuit - The path to the circuit file or the circuit id (filename without extension).
|
|
21
|
+
* @returns {CircomZKit} The `CircuitZKit` instance.
|
|
22
|
+
*/
|
|
23
|
+
getCircuit(circuit: string): CircuitZKit;
|
|
24
|
+
/**
|
|
25
|
+
* Returns an array of all circuits available in the circuits directory.
|
|
26
|
+
*
|
|
27
|
+
* @dev If a circuit id is not unique, the id will be set to `null`.
|
|
28
|
+
*
|
|
29
|
+
* @returns {CircuitInfo[]} An array of circuit information objects.
|
|
30
|
+
*/
|
|
31
|
+
getCircuits(): CircuitInfo[];
|
|
32
|
+
/**
|
|
33
|
+
* Returns an array of all circuits paths available in the circuits directory.
|
|
34
|
+
*
|
|
35
|
+
* @returns {string[]} An array of circuit paths.
|
|
36
|
+
*/
|
|
37
|
+
private _getAllCircuits;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=CircomZKit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CircomZKit.d.ts","sourceRoot":"","sources":["../../src/core/CircomZKit.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAyB,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE5E;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAc;IAEvC;;;;OAIG;gBACS,OAAO,GAAE,OAAO,CAAC,iBAAiB,CAAyB;IAIvE;;;;;;;OAOG;IACI,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW;IA2B/C;;;;;;OAMG;IACI,WAAW,IAAI,WAAW,EAAE;IAyBnC;;;;OAIG;IACH,OAAO,CAAC,eAAe;CAaxB"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CircomZKit = void 0;
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const CircuitZKit_1 = require("./CircuitZKit");
|
|
10
|
+
const ManagerZKit_1 = require("./ManagerZKit");
|
|
11
|
+
const utils_1 = require("../utils/utils");
|
|
12
|
+
const config_1 = require("../config/config");
|
|
13
|
+
/**
|
|
14
|
+
* `CircomZKit` acts as a factory for `CircuitZKit` instances.
|
|
15
|
+
*/
|
|
16
|
+
class CircomZKit {
|
|
17
|
+
_manager;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new `CircomZKit` instance.
|
|
20
|
+
*
|
|
21
|
+
* @param {Partial<ManagerZKitConfig>} [options=defaultManagerOptions] - The configuration options to use.
|
|
22
|
+
*/
|
|
23
|
+
constructor(options = config_1.defaultManagerOptions) {
|
|
24
|
+
this._manager = new ManagerZKit_1.ManagerZKit({ ...config_1.defaultManagerOptions, ...options });
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns a `CircuitZKit` instance for the specified circuit.
|
|
28
|
+
*
|
|
29
|
+
* @dev If the circuit id is not unique, the path to the circuit file must be provided.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} circuit - The path to the circuit file or the circuit id (filename without extension).
|
|
32
|
+
* @returns {CircomZKit} The `CircuitZKit` instance.
|
|
33
|
+
*/
|
|
34
|
+
getCircuit(circuit) {
|
|
35
|
+
const circuits = this._getAllCircuits();
|
|
36
|
+
const candidates = circuits.filter((file) => {
|
|
37
|
+
if (circuit.endsWith(".circom")) {
|
|
38
|
+
return file == path_1.default.normalize(circuit);
|
|
39
|
+
}
|
|
40
|
+
return path_1.default.basename(file) == `${circuit}.circom`;
|
|
41
|
+
});
|
|
42
|
+
if (candidates.length == 0) {
|
|
43
|
+
throw Error(`No circuits with name \"${circuit}\" found`);
|
|
44
|
+
}
|
|
45
|
+
if (candidates.length > 1) {
|
|
46
|
+
throw Error(`Found multiple entries for the circuit "${circuit}".
|
|
47
|
+
|
|
48
|
+
\rConsider replacing \"${circuit}\" with one of the valid paths:
|
|
49
|
+
\r${candidates.map((candidate) => `"${candidate}"`).join(os_1.default.EOL)}`);
|
|
50
|
+
}
|
|
51
|
+
return new CircuitZKit_1.CircuitZKit(path_1.default.join(this._manager.getCircuitsDir(), candidates[0]), this._manager);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns an array of all circuits available in the circuits directory.
|
|
55
|
+
*
|
|
56
|
+
* @dev If a circuit id is not unique, the id will be set to `null`.
|
|
57
|
+
*
|
|
58
|
+
* @returns {CircuitInfo[]} An array of circuit information objects.
|
|
59
|
+
*/
|
|
60
|
+
getCircuits() {
|
|
61
|
+
const circuits = this._getAllCircuits();
|
|
62
|
+
let circuitsCount = {};
|
|
63
|
+
for (const circuit of circuits) {
|
|
64
|
+
const circuitId = path_1.default.parse(circuit).name;
|
|
65
|
+
circuitsCount[circuitId] = (circuitsCount[circuitId] || 0) + 1;
|
|
66
|
+
}
|
|
67
|
+
let result = [];
|
|
68
|
+
for (const circuit of circuits) {
|
|
69
|
+
const circuitId = path_1.default.parse(circuit).name;
|
|
70
|
+
result.push({
|
|
71
|
+
path: circuit,
|
|
72
|
+
id: circuitsCount[circuitId] > 1 ? null : circuitId,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns an array of all circuits paths available in the circuits directory.
|
|
79
|
+
*
|
|
80
|
+
* @returns {string[]} An array of circuit paths.
|
|
81
|
+
*/
|
|
82
|
+
_getAllCircuits() {
|
|
83
|
+
const circuitsDir = this._manager.getCircuitsDir();
|
|
84
|
+
let circuits = [];
|
|
85
|
+
(0, utils_1.readDirRecursively)(circuitsDir, (_dir, file) => {
|
|
86
|
+
if (path_1.default.extname(file) == ".circom") {
|
|
87
|
+
circuits.push(path_1.default.relative(circuitsDir, file));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return circuits;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.CircomZKit = CircomZKit;
|
|
94
|
+
//# sourceMappingURL=CircomZKit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CircomZKit.js","sourceRoot":"","sources":["../../src/core/CircomZKit.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { CompileOptions } from "../config/config";
|
|
2
|
+
import { ManagerZKit } from "./ManagerZKit";
|
|
3
|
+
import { Calldata, Inputs, ProofStruct } from "../types/types";
|
|
4
|
+
/**
|
|
5
|
+
* `CircuitZKit` represents a single circuit and provides a high-level API to work with it.
|
|
6
|
+
*
|
|
7
|
+
* @dev This class is not meant to be used directly. Use the `CircomZKit` to create its instance.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CircuitZKit {
|
|
10
|
+
private readonly _circuit;
|
|
11
|
+
private readonly _manager;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new instance of `CircuitZKit`.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} _circuit - The path to the circuit.
|
|
16
|
+
* @param {ManagerZKit} _manager - The manager that maintains the global state.
|
|
17
|
+
*/
|
|
18
|
+
constructor(_circuit: string, _manager: ManagerZKit);
|
|
19
|
+
/**
|
|
20
|
+
* Compiles the circuit and generates the artifacts.
|
|
21
|
+
*
|
|
22
|
+
* @dev If compilation fails, the latest valid artifacts will be preserved.
|
|
23
|
+
* @dev Doesn't show the compilation error if `quiet` is set to `true`.
|
|
24
|
+
*
|
|
25
|
+
* @param {Partial<CompileOptions>} [options=defaultCompileOptions] - Compilation options.
|
|
26
|
+
*/
|
|
27
|
+
compile(options?: Partial<CompileOptions>): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a verifier contract.
|
|
30
|
+
*/
|
|
31
|
+
createVerifier(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Generates a proof for the given inputs.
|
|
34
|
+
*
|
|
35
|
+
* @dev The `inputs` should be in the same order as the circuit expects them.
|
|
36
|
+
*
|
|
37
|
+
* @param {Inputs} inputs - The inputs for the circuit.
|
|
38
|
+
* @returns {Promise<ProofStruct>} The generated proof.
|
|
39
|
+
* @todo Add support for other proving systems.
|
|
40
|
+
*/
|
|
41
|
+
generateProof(inputs: Inputs): Promise<ProofStruct>;
|
|
42
|
+
/**
|
|
43
|
+
* Verifies the given proof.
|
|
44
|
+
*
|
|
45
|
+
* @dev The `proof` can be generated using the `generateProof` method.
|
|
46
|
+
* @dev The `proof.publicSignals` should be in the same order as the circuit expects them.
|
|
47
|
+
*
|
|
48
|
+
* @param {ProofStruct} proof - The proof to verify.
|
|
49
|
+
* @returns {Promise<boolean>} Whether the proof is valid.
|
|
50
|
+
*/
|
|
51
|
+
verifyProof(proof: ProofStruct): Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Generates the calldata for the given proof. The calldata can be used to verify the proof on-chain.
|
|
54
|
+
*
|
|
55
|
+
* @param {ProofStruct} proof - The proof to generate calldata for.
|
|
56
|
+
* @returns {Promise<Calldata>} - The generated calldata.
|
|
57
|
+
* @todo Add other types of calldata.
|
|
58
|
+
*/
|
|
59
|
+
generateCalldata(proof: ProofStruct): Promise<Calldata>;
|
|
60
|
+
/**
|
|
61
|
+
* Returns the circuit ID. The circuit ID is the name of the circuit file without the extension.
|
|
62
|
+
*
|
|
63
|
+
* @returns {string} The circuit ID.
|
|
64
|
+
*/
|
|
65
|
+
getCircuitId(): string;
|
|
66
|
+
/**
|
|
67
|
+
* Returns the verifier ID. The verifier ID is the name of the circuit file without the extension, suffixed with "Verifier".
|
|
68
|
+
*
|
|
69
|
+
* @returns {string} The verifier ID.
|
|
70
|
+
*/
|
|
71
|
+
getVerifierId(): string;
|
|
72
|
+
/**
|
|
73
|
+
* Generates zero-knowledge key for the circuit.
|
|
74
|
+
*
|
|
75
|
+
* @param {string} outDir - The directory to save the generated key.
|
|
76
|
+
* @todo This method may cause issues https://github.com/iden3/snarkjs/issues/494
|
|
77
|
+
*/
|
|
78
|
+
private _generateZKey;
|
|
79
|
+
/**
|
|
80
|
+
* Generates verification key for the circuit.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} outDir - The directory to save the generated key.
|
|
83
|
+
*/
|
|
84
|
+
private _generateVKey;
|
|
85
|
+
/**
|
|
86
|
+
* Returns the arguments to compile the circuit.
|
|
87
|
+
*
|
|
88
|
+
* @param {CompileOptions} options - Compilation options.
|
|
89
|
+
* @param {string} outDir - The directory to save the compiled artifacts.
|
|
90
|
+
* @returns {string[]} The arguments to compile the circuit.
|
|
91
|
+
*/
|
|
92
|
+
private _getCompileArgs;
|
|
93
|
+
/**
|
|
94
|
+
* Compiles the circuit.
|
|
95
|
+
*
|
|
96
|
+
* @param {CompileOptions} options - Compilation options.
|
|
97
|
+
* @param {string} outDir - The directory to save the compiled artifacts.
|
|
98
|
+
*/
|
|
99
|
+
private _compile;
|
|
100
|
+
/**
|
|
101
|
+
* Returns the number of constraints in the circuit. This value is used to fetch the correct `ptau` file.
|
|
102
|
+
*
|
|
103
|
+
* @param {string} outDir - The directory where the compiled artifacts are saved.
|
|
104
|
+
* @returns {Promise<number>} The number of constraints in the circuit.
|
|
105
|
+
*/
|
|
106
|
+
_getConstraints(outDir: string): Promise<number>;
|
|
107
|
+
/**
|
|
108
|
+
* Returns the path to the file of the given type.
|
|
109
|
+
*
|
|
110
|
+
* @param {FileType} fileType - The type of the file.
|
|
111
|
+
* @param {string | undefined} temp - The temporary directory to use.
|
|
112
|
+
* @returns {string} The path to the file.
|
|
113
|
+
*/
|
|
114
|
+
private _getFile;
|
|
115
|
+
/**
|
|
116
|
+
* Returns the path to the directory of the given type.
|
|
117
|
+
*
|
|
118
|
+
* @param {DirType} dirType - The type of the directory.
|
|
119
|
+
* @returns {string} The path to the directory.
|
|
120
|
+
*/
|
|
121
|
+
private _getDir;
|
|
122
|
+
/**
|
|
123
|
+
* Returns the path to the file of the given type. Throws an error if the file doesn't exist.
|
|
124
|
+
*
|
|
125
|
+
* @param {FileType} fileType - The type of the file.
|
|
126
|
+
* @param {string | undefined} temp - The temporary directory to use.
|
|
127
|
+
* @returns {string} The path to the file.
|
|
128
|
+
*/
|
|
129
|
+
private _mustGetFile;
|
|
130
|
+
/**
|
|
131
|
+
* Moves the files from the temporary directory to the output directory.
|
|
132
|
+
*
|
|
133
|
+
* @param {string} tempDir - The temporary directory.
|
|
134
|
+
* @param {string} outDir - The output directory.
|
|
135
|
+
*/
|
|
136
|
+
private _moveFromTempDirToOutDir;
|
|
137
|
+
/**
|
|
138
|
+
* Returns a new instance of `CircomRunner`. The `CircomRunner` is used to compile the circuit.
|
|
139
|
+
*
|
|
140
|
+
* @param {string[]} args - The arguments to run the `circom` compiler.
|
|
141
|
+
* @param {boolean} quiet - Whether to suppress the compilation error.
|
|
142
|
+
* @returns {typeof CircomRunner} The `CircomRunner` instance.
|
|
143
|
+
*/
|
|
144
|
+
private _getCircomRunner;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=CircuitZKit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CircuitZKit.d.ts","sourceRoot":"","sources":["../../src/core/CircuitZKit.ts"],"names":[],"mappings":"AAKA,OAAO,EAAyB,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAqB,MAAM,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAKlF;;;;GAIG;AACH,qBAAa,WAAW;IAQpB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAR3B;;;;;OAKG;gBAEgB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,WAAW;IAGxC;;;;;;;OAOG;IACU,OAAO,CAAC,OAAO,GAAE,OAAO,CAAC,cAAc,CAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB7F;;OAEG;IACU,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IA0B5C;;;;;;;;OAQG;IACU,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAOhE;;;;;;;;OAQG;IACU,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAQ9D;;;;;;OAMG;IACU,gBAAgB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMpE;;;;OAIG;IACI,YAAY,IAAI,MAAM;IAI7B;;;;OAIG;IACI,aAAa,IAAI,MAAM;IAI9B;;;;;OAKG;YACW,aAAa;IAU3B;;;;OAIG;YACW,aAAa;IAS3B;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;IAYvB;;;;;OAKG;YACW,QAAQ;IAiBtB;;;;;OAKG;IACG,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAkCtD;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAuBhB;;;;;OAKG;IACH,OAAO,CAAC,OAAO;IAef;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAUpB;;;;;OAKG;IACH,OAAO,CAAC,wBAAwB;IAgBhC;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;CAczB"}
|