diff --git a/.gitignore b/.gitignore index 6117ff7..eb324ca 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ publish # Compilation output /build-test/ -/dist +# /dist .nyc_output diff --git a/dist/constants.d.ts b/dist/constants.d.ts new file mode 100644 index 0000000..5e31d73 --- /dev/null +++ b/dist/constants.d.ts @@ -0,0 +1,3 @@ +export declare const BN128_CURVE_NAME = "bn128"; +export declare const MAX_FILE_NAME_LENGTH = 255; +//# sourceMappingURL=constants.d.ts.map diff --git a/dist/constants.d.ts.map b/dist/constants.d.ts.map new file mode 100644 index 0000000..4f7ea03 --- /dev/null +++ b/dist/constants.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,UAAU,CAAC;AAExC,eAAO,MAAM,oBAAoB,MAAM,CAAC"} \ No newline at end of file diff --git a/dist/constants.js b/dist/constants.js new file mode 100644 index 0000000..dcf9d4b --- /dev/null +++ b/dist/constants.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.MAX_FILE_NAME_LENGTH = exports.BN128_CURVE_NAME = void 0; +exports.BN128_CURVE_NAME = "bn128"; +exports.MAX_FILE_NAME_LENGTH = 255; +//# sourceMappingURL=constants.js.map \ No newline at end of file diff --git a/dist/constants.js.map b/dist/constants.js.map new file mode 100644 index 0000000..0059e85 --- /dev/null +++ b/dist/constants.js.map @@ -0,0 +1 @@ +{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG,OAAO,CAAC;AAE3B,QAAA,oBAAoB,GAAG,GAAG,CAAC"} \ No newline at end of file diff --git a/dist/core/CircuitZKit.d.ts b/dist/core/CircuitZKit.d.ts new file mode 100644 index 0000000..d93a729 --- /dev/null +++ b/dist/core/CircuitZKit.d.ts @@ -0,0 +1,147 @@ +import { + ArtifactsFileType, + CircuitZKitConfig, + VerifierLanguageType, + Signals, + CalldataByProtocol, + IProtocolImplementer, + ProofStructByProtocol, + ProvingSystemType, +} from "../types"; +/** + * `CircuitZKit` represents a single circuit and provides a high-level API to work with it. + */ +export declare class CircuitZKit { + private readonly _config; + private readonly _implementer; + constructor(_config: CircuitZKitConfig, _implementer: IProtocolImplementer); + /** + * Creates a verifier contract for the specified contract language with optional name suffix. + * For more details regarding the structure of the contract verifier name, see {@link getVerifierName} description. + * + * In case the length of the verifier filename exceeds the {@link MAX_FILE_NAME_LENGTH}, + * the `verifierNameSuffix` will be replaced by the first four bytes of its `sha1` hash. + * + * If no suffix was passed, but the verifier's filename still exceeds {@link MAX_FILE_NAME_LENGTH}, an error will be thrown. + * + * @param {VerifierLanguageType} languageExtension - The verifier contract language extension. + * @param {string} verifierNameSuffix - The optional verifier name suffix. + */ + createVerifier(languageExtension: VerifierLanguageType, verifierNameSuffix?: string): Promise; + /** + * Calculates a witness for the given inputs. + * + * If `witnessOverrides` are provided, the corresponding witness values will be substituted in the result. + * + * Signal names in `witnessOverrides` must be provided in their full form as represented in the `.sym` file, e.g., + * `main.signal`, `main.component.signal`, or `main.component.signal[n][m]`. + * + * @param {Signals} inputs - The inputs for the circuit. + * @param {Record} [witnessOverrides] - Optional map of signal names to override their witness values. + * @param {string} witnessFilePath - The inputs for the witness file path. + * @returns {Promise} The generated witness. + */ + calculateWitness( + inputs: Signals, + witnessOverrides?: Record, + witnessFilePath?: string, + ): Promise; + /** + * Generates a proof for the given inputs. + * + * @dev The `inputs` should be in the same order as the circuit expects them. + * + * If `witnessOverrides` are provided, the witness will be calculated from the inputs and overridden accordingly. + * Otherwise, a standard witness will be calculated and used. + * + * Signal names in `witnessOverrides` must be provided in their full form as represented in the `.sym` file, e.g., + * `main.signal`, `main.component.signal`, or `main.component.signal[n][m]`. + * + * @param {Signals} inputs - The inputs for the circuit. + * @param {Record} [witnessOverrides] - Optional map of signal names to override their witness values. + * @param {boolean} uniqueWitnessPath - The flag for unique witness path to avoid I/O concurrent conflicts. default - false + * @returns {Promise>} The generated proof. + */ + generateProof( + inputs: Signals, + witnessOverrides?: Record, + uniqueWitnessPath?: boolean, + ): Promise>; + /** + * Verifies the given proof. + * + * @dev The `proof` can be generated using the `generateProof` method. + * @dev The `proof.publicSignals` should be in the same order as the circuit expects them. + * + * @param {ProofStructByProtocol} proof - The proof to verify. + * @returns {Promise} Whether the proof is valid. + */ + verifyProof(proof: ProofStructByProtocol): Promise; + /** + * Generates the calldata for the given proof. The calldata can be used to verify the proof on-chain. + * + * @param {ProofStructByProtocol} proof - The proof to generate calldata for. + * @returns {Promise>} - The generated calldata. + */ + generateCalldata(proof: ProofStructByProtocol): Promise>; + /** + * Returns the circuit name. The circuit name is the name of the circuit file without the extension. + * + * @returns {string} The circuit name. + */ + getCircuitName(): string; + /** + * Returns the verifier name. The verifier name has the next structure: + * `