https://github.com/dl-solarity/zktype
Typescript bindings for Circom circuits
https://github.com/dl-solarity/zktype
circom types typescript zkp
Last synced: about 1 year ago
JSON representation
Typescript bindings for Circom circuits
- Host: GitHub
- URL: https://github.com/dl-solarity/zktype
- Owner: dl-solarity
- License: mit
- Created: 2024-03-14T12:08:57.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-05-22T15:47:41.000Z (about 1 year ago)
- Last Synced: 2025-05-23T16:23:43.180Z (about 1 year ago)
- Topics: circom, types, typescript, zkp
- Language: Circom
- Homepage: https://npmjs.com/package/@solarity/zktype
- Size: 799 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/@solarity/zktype)
[](https://opensource.org/licenses/MIT)
# ZKType - TypeScript bindings for Circom circuits
**ZKType simplifies and makes user-friendly the process of working with Circom circuits.**
- Generate a typed [zkit](https://github.com/dl-solarity/zkit) wrapper for given circuits.
- Support for `groth16` and `plonk` proving systems.
- Ensure that all inputs and proofs are correctly formatted.
- Typization for witness signals substitution.
## Installation
To install the package, run:
```bash
npm install --save-dev @solarity/zktype
```
## Usage
> [!IMPORTANT]
> ZKType is not meant to be used directly as its fitness relies heavily on the environment, e.g., on Circom compilation artifacts management. Consider using [hardhat-zkit](https://github.com/dl-solarity/hardhat-zkit), which is a complete, developer-friendly package.
### CircuitTypesGenerator
`CircuitTypesGenerator` is an entry point for generating TypeScript bindings for a given circuit.
To create a `CircuitTypesGenerator` object, it is necessary to pass a config:
```typescript
ZKTypeConfig = {
basePath: "circuits",
projectRoot: process.cwd(),
circuitsArtifacts: [
{
artifactPath: "circuits/auth/Matrix_artifacts.json",
circuitProtocolType: ["groth16"],
},
],
outputTypesDir: "generated-types/circuits",
signalNamesTypeLimit: 50000,
}
```
This config contains all the information required to generate TypeScript bindings for given circuits.
- `basePath` - Path to the root directory of the project where circuits are stored.
- `projectRoot` - Absolute path to the root directory of the project.
- `circuitsArtifacts` - Array of object containing the path to the circuit artifact and the protocol type of the circuit.
- `outputTypesDir` - Path to the directory where the generated types will be stored.
- Optional. Default: `generated-types/circuits`.
- `signalNamesTypeLimit` - Maximum number of signals allowed to generate a `SignalNames` union type for the circuit.
- Optional. Default: 50000.
#### API reference
---
- **`async generateTypes()`**
Generates TypeScript bindings for the given circuits, based on the provided config.
```typescript
const generator = new CircuitTypesGenerator(config);
await generator.generateTypes();
```
Also, this function generates the `hardhat.d.ts` file, where you can find all the possible objects that can be retrieved by the function below.
- **`async getCircuitObject(circuitName: string, protocolType?: string): Promise`**
Returns the constructible object for the given circuit.
```typescript
const generator = new CircuitTypesGenerator(config);
await generator.generateTypes();
const circuitObject = await generator.getCircuitObject("MyCircuit", "groth16");
```
The package supports generation of circuits by the `groth16` and `plonk` protocols at the same time.
In this case, you will have to specify the protocol type when retrieving the object.
After the `circuitObject` is retrieved, check out the [zkit](https://github.com/dl-solarity/zkit) documentation to see how to work with it.
To ensure that the object can be imported, check the `hardhat.d.ts` file.