@solarity/zkit 0.1.1 → 0.2.1
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/README.md +23 -51
- package/dist/core/CircuitZKit.d.ts +30 -89
- package/dist/core/CircuitZKit.d.ts.map +1 -1
- package/dist/core/CircuitZKit.js +80 -235
- package/dist/core/CircuitZKit.js.map +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -6
- package/dist/index.js.map +1 -1
- package/dist/types/circuit-zkit.d.ts +43 -0
- package/dist/types/circuit-zkit.d.ts.map +1 -0
- package/dist/types/circuit-zkit.js +3 -0
- package/dist/types/circuit-zkit.js.map +1 -0
- package/package.json +21 -10
- package/src/core/CircuitZKit.ts +88 -283
- package/src/index.ts +1 -6
- package/src/types/{types.ts → circuit-zkit.ts} +8 -12
- package/src/config/config.ts +0 -43
- package/src/core/CircomZKit.ts +0 -110
- package/src/core/ManagerZKit.ts +0 -231
- package/src/utils/utils.ts +0 -60
package/dist/core/CircuitZKit.js
CHANGED
|
@@ -27,75 +27,58 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.CircuitZKit = void 0;
|
|
30
|
-
const crypto_1 = require("crypto");
|
|
31
30
|
const ejs_1 = __importDefault(require("ejs"));
|
|
32
31
|
const fs_1 = __importDefault(require("fs"));
|
|
33
32
|
const path_1 = __importDefault(require("path"));
|
|
34
33
|
const snarkjs = __importStar(require("snarkjs"));
|
|
35
|
-
const config_1 = require("../config/config");
|
|
36
|
-
const utils_1 = require("../utils/utils");
|
|
37
|
-
const { CircomRunner, bindings } = require("@distributedlab/circom2");
|
|
38
34
|
/**
|
|
39
35
|
* `CircuitZKit` represents a single circuit and provides a high-level API to work with it.
|
|
40
|
-
*
|
|
41
|
-
* @dev This class is not meant to be used directly. Use the `CircomZKit` to create its instance.
|
|
42
36
|
*/
|
|
43
37
|
class CircuitZKit {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* Creates a new instance of `CircuitZKit`.
|
|
48
|
-
*
|
|
49
|
-
* @param {string} _circuit - The path to the circuit.
|
|
50
|
-
* @param {ManagerZKit} _manager - The manager that maintains the global state.
|
|
51
|
-
*/
|
|
52
|
-
constructor(_circuit, _manager) {
|
|
53
|
-
this._circuit = _circuit;
|
|
54
|
-
this._manager = _manager;
|
|
38
|
+
_config;
|
|
39
|
+
constructor(_config) {
|
|
40
|
+
this._config = _config;
|
|
55
41
|
}
|
|
56
42
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* @dev If compilation fails, the latest valid artifacts will be preserved.
|
|
60
|
-
* @dev Doesn't show the compilation error if `quiet` is set to `true`.
|
|
43
|
+
* Returns the Solidity verifier template for the specified proving system.
|
|
61
44
|
*
|
|
62
|
-
* @param {
|
|
45
|
+
* @param {VerifierTemplateType} templateType - The template type.
|
|
46
|
+
* @returns {string} The Solidity verifier template.
|
|
63
47
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
await this._compile(overriddenOptions, tempDir);
|
|
71
|
-
await this._generateZKey(overriddenOptions, tempDir);
|
|
72
|
-
await this._generateVKey(tempDir);
|
|
73
|
-
this._moveFromTempDirToOutDir(tempDir, artifactDir);
|
|
74
|
-
}
|
|
75
|
-
finally {
|
|
76
|
-
fs_1.default.rmSync(tempDir, { recursive: true, force: true });
|
|
48
|
+
static getTemplate(templateType) {
|
|
49
|
+
switch (templateType) {
|
|
50
|
+
case "groth16":
|
|
51
|
+
return fs_1.default.readFileSync(path_1.default.join(__dirname, "templates", "verifier_groth16.sol.ejs"), "utf8");
|
|
52
|
+
default:
|
|
53
|
+
throw new Error(`Ambiguous template type: ${templateType}.`);
|
|
77
54
|
}
|
|
78
55
|
}
|
|
79
56
|
/**
|
|
80
|
-
* Creates a verifier contract.
|
|
57
|
+
* Creates a Solidity verifier contract.
|
|
81
58
|
*/
|
|
82
59
|
async createVerifier() {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const verifierFile = this._getFile("sol", tempDir);
|
|
89
|
-
const groth16Template = this._manager.getTemplate("groth16");
|
|
90
|
-
const templateParams = JSON.parse(fs_1.default.readFileSync(vKeyFile, "utf-8"));
|
|
91
|
-
templateParams["verifier_id"] = this.getVerifierId();
|
|
92
|
-
const verifierCode = ejs_1.default.render(groth16Template, templateParams);
|
|
93
|
-
fs_1.default.writeFileSync(verifierFile, verifierCode, "utf-8");
|
|
94
|
-
this._moveFromTempDirToOutDir(tempDir, verifierDir);
|
|
95
|
-
}
|
|
96
|
-
finally {
|
|
97
|
-
fs_1.default.rmSync(tempDir, { recursive: true, force: true });
|
|
60
|
+
const vKeyFilePath = this.mustGetArtifactsFilePath("vkey");
|
|
61
|
+
const verifierFilePath = path_1.default.join(this._config.verifierDirPath, `${this.getVerifierName()}.sol`);
|
|
62
|
+
const verifierTemplate = CircuitZKit.getTemplate(this.getTemplateType());
|
|
63
|
+
if (!fs_1.default.existsSync(this._config.verifierDirPath)) {
|
|
64
|
+
fs_1.default.mkdirSync(this._config.verifierDirPath, { recursive: true });
|
|
98
65
|
}
|
|
66
|
+
const templateParams = JSON.parse(fs_1.default.readFileSync(vKeyFilePath, "utf-8"));
|
|
67
|
+
templateParams["verifier_id"] = this.getVerifierName();
|
|
68
|
+
const verifierCode = ejs_1.default.render(verifierTemplate, templateParams);
|
|
69
|
+
fs_1.default.writeFileSync(verifierFilePath, verifierCode, "utf-8");
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Creates a witness for the given inputs.
|
|
73
|
+
*
|
|
74
|
+
* @dev The `inputs` should be in the same order as the circuit expects them.
|
|
75
|
+
*
|
|
76
|
+
* @param {Inputs} inputs - The inputs for the circuit.
|
|
77
|
+
*/
|
|
78
|
+
async createWitness(inputs) {
|
|
79
|
+
const wasmFile = this.mustGetArtifactsFilePath("wasm");
|
|
80
|
+
const wtnsFile = this.getArtifactsFilePath("wtns");
|
|
81
|
+
await snarkjs.wtns.calculate(inputs, wasmFile, wtnsFile);
|
|
99
82
|
}
|
|
100
83
|
/**
|
|
101
84
|
* Generates a proof for the given inputs.
|
|
@@ -107,8 +90,8 @@ class CircuitZKit {
|
|
|
107
90
|
* @todo Add support for other proving systems.
|
|
108
91
|
*/
|
|
109
92
|
async generateProof(inputs) {
|
|
110
|
-
const zKeyFile = this.
|
|
111
|
-
const wasmFile = this.
|
|
93
|
+
const zKeyFile = this.mustGetArtifactsFilePath("zkey");
|
|
94
|
+
const wasmFile = this.mustGetArtifactsFilePath("wasm");
|
|
112
95
|
return (await snarkjs.groth16.fullProve(inputs, wasmFile, zKeyFile));
|
|
113
96
|
}
|
|
114
97
|
/**
|
|
@@ -121,7 +104,7 @@ class CircuitZKit {
|
|
|
121
104
|
* @returns {Promise<boolean>} Whether the proof is valid.
|
|
122
105
|
*/
|
|
123
106
|
async verifyProof(proof) {
|
|
124
|
-
const vKeyFile = this.
|
|
107
|
+
const vKeyFile = this.mustGetArtifactsFilePath("vkey");
|
|
125
108
|
const verifier = JSON.parse(fs_1.default.readFileSync(vKeyFile).toString());
|
|
126
109
|
return await snarkjs.groth16.verify(verifier, proof.publicSignals, proof.proof);
|
|
127
110
|
}
|
|
@@ -137,217 +120,79 @@ class CircuitZKit {
|
|
|
137
120
|
return JSON.parse(`[${calldata}]`);
|
|
138
121
|
}
|
|
139
122
|
/**
|
|
140
|
-
* Returns the circuit
|
|
123
|
+
* Returns the circuit name. The circuit name is the name of the circuit file without the extension.
|
|
141
124
|
*
|
|
142
|
-
* @returns {string} The circuit
|
|
125
|
+
* @returns {string} The circuit name.
|
|
143
126
|
*/
|
|
144
|
-
|
|
145
|
-
return
|
|
127
|
+
getCircuitName() {
|
|
128
|
+
return this._config.circuitName;
|
|
146
129
|
}
|
|
147
130
|
/**
|
|
148
|
-
* Returns the verifier
|
|
131
|
+
* Returns the verifier name. The verifier name is the name of the circuit file without the extension, suffixed with "Verifier".
|
|
149
132
|
*
|
|
150
|
-
* @returns {string} The verifier
|
|
133
|
+
* @returns {string} The verifier name.
|
|
151
134
|
*/
|
|
152
|
-
|
|
153
|
-
return `${
|
|
135
|
+
getVerifierName() {
|
|
136
|
+
return `${this._config.circuitName}Verifier`;
|
|
154
137
|
}
|
|
155
138
|
/**
|
|
156
|
-
*
|
|
139
|
+
* Returns the type of verifier template that was stored in the config
|
|
157
140
|
*
|
|
158
|
-
* @
|
|
159
|
-
* @param {string} outDir - The directory to save the generated key.
|
|
160
|
-
* @todo This method may cause issues https://github.com/iden3/snarkjs/issues/494
|
|
141
|
+
* @returns {VerifierTemplateType} The verifier template type.
|
|
161
142
|
*/
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const zKeyFile = this._getFile("zkey", outDir);
|
|
165
|
-
const constraints = await this._getConstraints(outDir);
|
|
166
|
-
const ptauFile = await this._manager.fetchPtauFile(constraints);
|
|
167
|
-
if (options.setup == "groth16") {
|
|
168
|
-
await snarkjs.zKey.newZKey(r1csFile, ptauFile, zKeyFile);
|
|
169
|
-
const zKeyFileNext = `${zKeyFile}.next.zkey`;
|
|
170
|
-
for (let i = 0; i < options.contributions; ++i) {
|
|
171
|
-
await snarkjs.zKey.contribute(zKeyFile, zKeyFileNext, `${zKeyFile}_contribution_${i}`, (0, crypto_1.randomBytes)(32).toString("hex"));
|
|
172
|
-
fs_1.default.rmSync(zKeyFile);
|
|
173
|
-
fs_1.default.renameSync(zKeyFileNext, zKeyFile);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Generates verification key for the circuit.
|
|
179
|
-
*
|
|
180
|
-
* @param {string} outDir - The directory to save the generated key.
|
|
181
|
-
*/
|
|
182
|
-
async _generateVKey(outDir) {
|
|
183
|
-
const zKeyFile = this._getFile("zkey", outDir);
|
|
184
|
-
const vKeyFile = this._getFile("vkey", outDir);
|
|
185
|
-
const vKeyData = await snarkjs.zKey.exportVerificationKey(zKeyFile);
|
|
186
|
-
fs_1.default.writeFileSync(vKeyFile, JSON.stringify(vKeyData));
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Returns the arguments to compile the circuit.
|
|
190
|
-
*
|
|
191
|
-
* @param {CompileOptions} options - Compilation options.
|
|
192
|
-
* @param {string} outDir - The directory to save the compiled artifacts.
|
|
193
|
-
* @returns {string[]} The arguments to compile the circuit.
|
|
194
|
-
*/
|
|
195
|
-
_getCompileArgs(options, outDir) {
|
|
196
|
-
let args = [this._circuit, "--r1cs", "--wasm"];
|
|
197
|
-
options.sym && args.push("--sym");
|
|
198
|
-
options.json && args.push("--json");
|
|
199
|
-
options.c && args.push("--c");
|
|
200
|
-
args.push("-o", outDir);
|
|
201
|
-
return args;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Compiles the circuit.
|
|
205
|
-
*
|
|
206
|
-
* @param {CompileOptions} options - Compilation options.
|
|
207
|
-
* @param {string} outDir - The directory to save the compiled artifacts.
|
|
208
|
-
*/
|
|
209
|
-
async _compile(options, outDir) {
|
|
210
|
-
const args = this._getCompileArgs(options, outDir);
|
|
211
|
-
try {
|
|
212
|
-
await this._getCircomRunner(args, options.quiet).execute(this._manager.getCompiler());
|
|
213
|
-
}
|
|
214
|
-
catch (err) {
|
|
215
|
-
if (options.quiet) {
|
|
216
|
-
throw new Error('Compilation failed with an unknown error. Consider passing "quiet=false" flag to see the compilation error.', { cause: err });
|
|
217
|
-
}
|
|
218
|
-
throw new Error("Compilation failed.", { cause: err });
|
|
219
|
-
}
|
|
143
|
+
getTemplateType() {
|
|
144
|
+
return this._config.templateType ?? "groth16";
|
|
220
145
|
}
|
|
221
146
|
/**
|
|
222
|
-
* Returns the
|
|
147
|
+
* Returns the path to the file of the given type inside artifacts directory. Throws an error if the file doesn't exist.
|
|
223
148
|
*
|
|
224
|
-
* @param {
|
|
225
|
-
* @returns {
|
|
149
|
+
* @param {ArtifactsFileType} fileType - The type of the file.
|
|
150
|
+
* @returns {string} The path to the file.
|
|
226
151
|
*/
|
|
227
|
-
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const buffer = Buffer.alloc(length);
|
|
232
|
-
fs_1.default.readSync(r1csDescriptor, buffer, { length, position });
|
|
233
|
-
return BigInt(`0x${buffer.reverse().toString("hex")}`);
|
|
234
|
-
};
|
|
235
|
-
/// @dev https://github.com/iden3/r1csfile/blob/d82959da1f88fbd06db0407051fde94afbf8824a/doc/r1cs_bin_format.md#format-of-the-file
|
|
236
|
-
const numberOfSections = readBytes(8, 4);
|
|
237
|
-
let sectionStart = 12;
|
|
238
|
-
for (let i = 0; i < numberOfSections; ++i) {
|
|
239
|
-
const sectionType = Number(readBytes(sectionStart, 4));
|
|
240
|
-
const sectionSize = Number(readBytes(sectionStart + 4, 8));
|
|
241
|
-
/// @dev Reading header section
|
|
242
|
-
if (sectionType == 1) {
|
|
243
|
-
const totalConstraintsOffset = 4 + 8 + 4 + 32 + 4 + 4 + 4 + 4 + 8;
|
|
244
|
-
return Number(readBytes(sectionStart + totalConstraintsOffset, 4));
|
|
245
|
-
}
|
|
246
|
-
sectionStart += 4 + 8 + sectionSize;
|
|
152
|
+
mustGetArtifactsFilePath(fileType) {
|
|
153
|
+
const file = this.getArtifactsFilePath(fileType);
|
|
154
|
+
if (!fs_1.default.existsSync(file)) {
|
|
155
|
+
throw new Error(`Expected the file "${file}" to exist`);
|
|
247
156
|
}
|
|
248
|
-
|
|
157
|
+
return file;
|
|
249
158
|
}
|
|
250
159
|
/**
|
|
251
|
-
* Returns the path to the file of the given type.
|
|
160
|
+
* Returns the path to the file of the given type inside artifacts directory.
|
|
252
161
|
*
|
|
253
|
-
* @param {
|
|
254
|
-
* @param {string | undefined} temp - The temporary directory to use.
|
|
162
|
+
* @param {ArtifactsFileType} fileType - The type of the file.
|
|
255
163
|
* @returns {string} The path to the file.
|
|
256
164
|
*/
|
|
257
|
-
|
|
258
|
-
const
|
|
165
|
+
getArtifactsFilePath(fileType) {
|
|
166
|
+
const circuitName = this.getCircuitName();
|
|
167
|
+
let fileName;
|
|
168
|
+
let fileDir = this._config.circuitArtifactsPath;
|
|
259
169
|
switch (fileType) {
|
|
260
170
|
case "r1cs":
|
|
261
|
-
|
|
171
|
+
fileName = `${circuitName}.r1cs`;
|
|
172
|
+
break;
|
|
262
173
|
case "zkey":
|
|
263
|
-
|
|
174
|
+
fileName = `${circuitName}.zkey`;
|
|
175
|
+
break;
|
|
264
176
|
case "vkey":
|
|
265
|
-
|
|
177
|
+
fileName = `${circuitName}.vkey.json`;
|
|
178
|
+
break;
|
|
266
179
|
case "sym":
|
|
267
|
-
|
|
180
|
+
fileName = `${circuitName}.sym`;
|
|
181
|
+
break;
|
|
268
182
|
case "json":
|
|
269
|
-
|
|
183
|
+
fileName = `${circuitName}_constraints.json`;
|
|
184
|
+
break;
|
|
185
|
+
case "wtns":
|
|
186
|
+
fileName = `${circuitName}.wtns`;
|
|
187
|
+
break;
|
|
270
188
|
case "wasm":
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
189
|
+
fileName = `${circuitName}.wasm`;
|
|
190
|
+
fileDir = path_1.default.join(fileDir, `${circuitName}_js`);
|
|
191
|
+
break;
|
|
274
192
|
default:
|
|
275
193
|
throw new Error(`Ambiguous file type: ${fileType}.`);
|
|
276
194
|
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Returns the path to the directory of the given type.
|
|
280
|
-
*
|
|
281
|
-
* @param {DirType} dirType - The type of the directory.
|
|
282
|
-
* @returns {string} The path to the directory.
|
|
283
|
-
*/
|
|
284
|
-
_getDir(dirType) {
|
|
285
|
-
const circuitRelativePath = path_1.default.relative(this._manager.getCircuitsDir(), this._circuit);
|
|
286
|
-
switch (dirType) {
|
|
287
|
-
case "circuit":
|
|
288
|
-
return path_1.default.join(this._manager.getCircuitsDir(), circuitRelativePath, "..");
|
|
289
|
-
case "artifact":
|
|
290
|
-
return path_1.default.join(this._manager.getArtifactsDir(), circuitRelativePath);
|
|
291
|
-
case "verifier":
|
|
292
|
-
return path_1.default.join(this._manager.getVerifiersDir(), circuitRelativePath, "..");
|
|
293
|
-
default:
|
|
294
|
-
throw new Error(`Ambiguous dir type: ${dirType}.`);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Returns the path to the file of the given type. Throws an error if the file doesn't exist.
|
|
299
|
-
*
|
|
300
|
-
* @param {FileType} fileType - The type of the file.
|
|
301
|
-
* @param {string | undefined} temp - The temporary directory to use.
|
|
302
|
-
* @returns {string} The path to the file.
|
|
303
|
-
*/
|
|
304
|
-
_mustGetFile(fileType, temp) {
|
|
305
|
-
const file = this._getFile(fileType, temp);
|
|
306
|
-
if (!fs_1.default.existsSync(file)) {
|
|
307
|
-
throw new Error(`Expected the file "${file}" to exist`);
|
|
308
|
-
}
|
|
309
|
-
return file;
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Moves the files from the temporary directory to the output directory.
|
|
313
|
-
*
|
|
314
|
-
* @param {string} tempDir - The temporary directory.
|
|
315
|
-
* @param {string} outDir - The output directory.
|
|
316
|
-
*/
|
|
317
|
-
_moveFromTempDirToOutDir(tempDir, outDir) {
|
|
318
|
-
fs_1.default.mkdirSync(outDir, { recursive: true });
|
|
319
|
-
(0, utils_1.readDirRecursively)(tempDir, (dir, file) => {
|
|
320
|
-
const correspondingOutDir = path_1.default.join(outDir, path_1.default.relative(tempDir, dir));
|
|
321
|
-
const correspondingOutFile = path_1.default.join(outDir, path_1.default.relative(tempDir, file));
|
|
322
|
-
if (!fs_1.default.existsSync(correspondingOutDir)) {
|
|
323
|
-
fs_1.default.mkdirSync(correspondingOutDir);
|
|
324
|
-
}
|
|
325
|
-
if (fs_1.default.existsSync(correspondingOutFile)) {
|
|
326
|
-
fs_1.default.rmSync(correspondingOutFile);
|
|
327
|
-
}
|
|
328
|
-
fs_1.default.copyFileSync(file, correspondingOutFile);
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Returns a new instance of `CircomRunner`. The `CircomRunner` is used to compile the circuit.
|
|
333
|
-
*
|
|
334
|
-
* @param {string[]} args - The arguments to run the `circom` compiler.
|
|
335
|
-
* @param {boolean} quiet - Whether to suppress the compilation error.
|
|
336
|
-
* @returns {typeof CircomRunner} The `CircomRunner` instance.
|
|
337
|
-
*/
|
|
338
|
-
_getCircomRunner(args, quiet) {
|
|
339
|
-
return new CircomRunner({
|
|
340
|
-
args,
|
|
341
|
-
preopens: { "/": "/" },
|
|
342
|
-
bindings: {
|
|
343
|
-
...bindings,
|
|
344
|
-
exit(code) {
|
|
345
|
-
throw new Error(`Compilation error. Exit code: ${code}.`);
|
|
346
|
-
},
|
|
347
|
-
fs: fs_1.default,
|
|
348
|
-
},
|
|
349
|
-
quiet,
|
|
350
|
-
});
|
|
195
|
+
return path_1.default.join(fileDir, fileName);
|
|
351
196
|
}
|
|
352
197
|
}
|
|
353
198
|
exports.CircuitZKit = CircuitZKit;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CircuitZKit.js","sourceRoot":"","sources":["../../src/core/CircuitZKit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"CircuitZKit.js","sourceRoot":"","sources":["../../src/core/CircuitZKit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAsB;AACtB,4CAAoB;AACpB,gDAAwB;AACxB,iDAAmC;AAWnC;;GAEG;AACH,MAAa,WAAW;IACO;IAA7B,YAA6B,OAA0B;QAA1B,YAAO,GAAP,OAAO,CAAmB;IAAG,CAAC;IAE3D;;;;;OAKG;IACI,MAAM,CAAC,WAAW,CAAC,YAAkC;QAC1D,QAA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O,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,WAAW,KAAK,CAAC,CAAC;gBAClD,MAAM;YACR;gBACE,MAAM,IAAI,KAAK,CAAC,wBAAwB,QAAQ,GAAG,CAAC,CAAC;QACzD,CAAC;QAED,OAAO,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACtC,CAAC;CACF;AAvLD,kCAuLC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export * from "./core/CircomZKit";
|
|
2
1
|
export * from "./core/CircuitZKit";
|
|
3
|
-
export * from "./
|
|
4
|
-
export { NumericString, PublicSignals, Groth16Proof, Calldata, ProofStruct, Inputs, CircuitInfo } from "./types/types";
|
|
5
|
-
export { CompileOptions, ManagerZKitConfig, defaultCompileOptions, defaultManagerOptions } from "./config/config";
|
|
2
|
+
export * from "./types/circuit-zkit";
|
|
6
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,11 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.defaultManagerOptions = exports.defaultCompileOptions = void 0;
|
|
18
|
-
__exportStar(require("./core/CircomZKit"), exports);
|
|
19
17
|
__exportStar(require("./core/CircuitZKit"), exports);
|
|
20
|
-
__exportStar(require("./
|
|
21
|
-
var config_1 = require("./config/config");
|
|
22
|
-
Object.defineProperty(exports, "defaultCompileOptions", { enumerable: true, get: function () { return config_1.defaultCompileOptions; } });
|
|
23
|
-
Object.defineProperty(exports, "defaultManagerOptions", { enumerable: true, get: function () { return config_1.defaultManagerOptions; } });
|
|
18
|
+
__exportStar(require("./types/circuit-zkit"), exports);
|
|
24
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,uDAAqC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type NumericString = `${number}` | string;
|
|
2
|
+
export type PublicSignals = NumericString[];
|
|
3
|
+
export type Groth16Proof = {
|
|
4
|
+
pi_a: [NumericString, NumericString];
|
|
5
|
+
pi_b: [[NumericString, NumericString], [NumericString, NumericString]];
|
|
6
|
+
pi_c: [NumericString, NumericString];
|
|
7
|
+
protocol: string;
|
|
8
|
+
curve: string;
|
|
9
|
+
};
|
|
10
|
+
export type Calldata = [
|
|
11
|
+
[
|
|
12
|
+
NumericString,
|
|
13
|
+
NumericString
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
[NumericString, NumericString],
|
|
17
|
+
[NumericString, NumericString]
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
NumericString,
|
|
21
|
+
NumericString
|
|
22
|
+
],
|
|
23
|
+
[
|
|
24
|
+
NumericString
|
|
25
|
+
]
|
|
26
|
+
];
|
|
27
|
+
export type ProofStruct = {
|
|
28
|
+
proof: Groth16Proof;
|
|
29
|
+
publicSignals: PublicSignals;
|
|
30
|
+
};
|
|
31
|
+
export type NumberLike = number | bigint | string;
|
|
32
|
+
export type ArrayLike = NumberLike[] | ArrayLike[];
|
|
33
|
+
export type InputLike = NumberLike | ArrayLike;
|
|
34
|
+
export type Inputs = Record<string, InputLike>;
|
|
35
|
+
export type ArtifactsFileType = "r1cs" | "zkey" | "vkey" | "sym" | "json" | "wasm" | "wtns";
|
|
36
|
+
export type VerifierTemplateType = "groth16";
|
|
37
|
+
export type CircuitZKitConfig = {
|
|
38
|
+
circuitName: string;
|
|
39
|
+
circuitArtifactsPath: string;
|
|
40
|
+
verifierDirPath: string;
|
|
41
|
+
templateType?: VerifierTemplateType;
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=circuit-zkit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuit-zkit.d.ts","sourceRoot":"","sources":["../../src/types/circuit-zkit.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC;AAEjD,MAAM,MAAM,aAAa,GAAG,aAAa,EAAE,CAAC;AAE5C,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,aAAa,EAAE,aAAa,CAAC,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;IACvE,IAAI,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB;QAAC,aAAa;QAAE,aAAa;KAAC;IAC9B;QAAC,CAAC,aAAa,EAAE,aAAa,CAAC;QAAE,CAAC,aAAa,EAAE,aAAa,CAAC;KAAC;IAChE;QAAC,aAAa;QAAE,aAAa;KAAC;IAC9B;QAAC,aAAa;KAAC;CAChB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,YAAY,CAAC;IACpB,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAClD,MAAM,MAAM,SAAS,GAAG,UAAU,EAAE,GAAG,SAAS,EAAE,CAAC;AACnD,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;AAE/C,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE/C,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAC5F,MAAM,MAAM,oBAAoB,GAAG,SAAS,CAAC;AAE7C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,oBAAoB,CAAC;CACrC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuit-zkit.js","sourceRoot":"","sources":["../../src/types/circuit-zkit.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solarity/zkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Distributed Lab",
|
|
6
6
|
"readme": "README.md",
|
|
@@ -26,25 +26,36 @@
|
|
|
26
26
|
"scripts": {
|
|
27
27
|
"prepare": "husky",
|
|
28
28
|
"build": "tsc",
|
|
29
|
-
"test": "
|
|
30
|
-
"
|
|
29
|
+
"test": "mocha --recursive 'test/**/*.ts' --exit",
|
|
30
|
+
"coverage": "nyc mocha --recursive 'test/**/*.ts' --exit",
|
|
31
|
+
"lint-fix": "prettier --write \"./**/*.ts\"",
|
|
31
32
|
"publish-to-npm": "npm run lint-fix && bash ./scripts/publish.sh"
|
|
32
33
|
},
|
|
34
|
+
"nyc": {
|
|
35
|
+
"reporter": [
|
|
36
|
+
"html",
|
|
37
|
+
"text"
|
|
38
|
+
]
|
|
39
|
+
},
|
|
33
40
|
"dependencies": {
|
|
34
|
-
"@distributedlab/circom2": "0.2.18-rc.2",
|
|
35
41
|
"ejs": "3.1.10",
|
|
36
|
-
"snarkjs": "0.7.3"
|
|
37
|
-
"uuid": "9.0.1"
|
|
42
|
+
"snarkjs": "0.7.3"
|
|
38
43
|
},
|
|
39
44
|
"devDependencies": {
|
|
45
|
+
"@nomicfoundation/hardhat-ethers": "3.0.5",
|
|
40
46
|
"@types/ejs": "^3.1.5",
|
|
41
|
-
"@types/jest": "^29.5.12",
|
|
42
47
|
"@types/snarkjs": "^0.7.8",
|
|
43
|
-
"@types/
|
|
48
|
+
"@types/chai": "^4.3.12",
|
|
49
|
+
"@types/chai-as-promised": "^7.1.8",
|
|
50
|
+
"@types/mocha": "^10.0.6",
|
|
51
|
+
"chai": "^4.4.1",
|
|
52
|
+
"chai-as-promised": "^7.1.1",
|
|
53
|
+
"mocha": "^10.3.0",
|
|
54
|
+
"nyc": "^15.1.0",
|
|
55
|
+
"ethers": "6.11.1",
|
|
56
|
+
"hardhat": "2.20.1",
|
|
44
57
|
"husky": "^9.0.11",
|
|
45
|
-
"jest": "^29.7.0",
|
|
46
58
|
"prettier": "^3.2.5",
|
|
47
|
-
"ts-jest": "^29.1.2",
|
|
48
59
|
"ts-node": "^10.9.2",
|
|
49
60
|
"typescript": "^5.4.5"
|
|
50
61
|
}
|