🧰 ZK-kit
A monorepo of reusable JS libraries for zero-knowledge technologies.
| ZK-kit is a set of NPM modules (algorithms or utility functions) that can be reused in different projects and zero-knowledge protocols, making it easier for developers to access ready-to-use and tested libraries for common tasks. |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
♚ [Yarn workspaces](https://yarnpkg.com/features/workspaces): minimal monorepo package management (`yarn`, `yarn build`, `yarn docs`)\
♛ [Conventional Commits](https://www.conventionalcommits.org): human and machine readable meaning to commit messages (`yarn commit`)\
♜ [Jest](https://jestjs.io/): tests and test coverage for all packages (`yarn test`, `yarn test:all`)\
♞ [ESLint](https://eslint.org/), [Prettier](https://prettier.io/): code quality and formatting (`yarn prettier` & `yarn lint`)\
♝ [Typedocs](https://typedoc.org/): documentation generator for TypeScript (`yarn docs`)\
♟ [Benny](https://github.com/caderek/benny): simple benchmarking framework for JavaScript/TypeScript (`yarn benchmarks`)\
♟ [Github actions](https://github.com/features/actions): software workflows for automatic testing, documentation deploy and code quality checks
## 📦 Packages
## 👥 Ways to contribute
- 🔧 Work on [open issues](https://github.com/privacy-scaling-explorations/zk-kit/contribute)
- 📦 Suggest new [packages](https://github.com/privacy-scaling-explorations/zk-kit/issues/new?assignees=&labels=feature+%3Arocket%3A&template=---package.md&title=)
- 🚀 Share ideas for new [features](https://github.com/privacy-scaling-explorations/zk-kit/issues/new?assignees=&labels=feature+%3Arocket%3A&template=---feature.md&title=)
- 🐛 Create a report if you find any [bugs](https://github.com/privacy-scaling-explorations/zk-kit/issues/new?assignees=&labels=bug+%F0%9F%90%9B&template=---bug.md&title=) in the code
## 🛠 Install
Clone this repository:
```bash
git clone https://github.com/privacy-scaling-explorations/zk-kit.git
```
and install the dependencies:
```bash
cd zk-kit && yarn
```
## 📜 Usage
### Code quality and formatting
Run [ESLint](https://eslint.org/) to analyze the code and catch bugs:
```bash
yarn lint
```
Run [Prettier](https://prettier.io/) to check formatting rules:
```bash
yarn prettier
```
or to automatically format the code:
```bash
yarn prettier:write
```
### Conventional commits
Semaphore uses [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/). A [command line utility](https://github.com/commitizen/cz-cli) to commit using the correct syntax can be used by running:
```bash
yarn commit
```
It will also automatically check that the modified files comply with ESLint and Prettier rules.
### Testing
Run [Jest](https://jestjs.io/) to test the code with coverage:
```bash
yarn test
```
### Build packages
Run [Rollup](https://www.rollupjs.org) to build all the packages:
```bash
yarn build
```
A `dist` folder will be created inside each package.
### Documentation
Run [TypeDoc](https://typedoc.org/) to generate a documentation website for each package:
```bash
yarn docs
```
The output will be placed on the `docs` folder.
## ❓ FAQ
#### I have a library that could be reused in other projects. How can I integrate it on ZK-kit?
ZK-kit provides a set of pre-configured development tools. All you have to deal with is your own code, testing and documentation. To create a package follow these steps:
1. Fork this repository and clone it (or simply clone it directly if you are a collaborator),
2. Copy one of our current libraries and update the `README.md` and `package.json` files with your package name:
```bash
cd zk-kit
cp -r packages/sparse-merkle-tree packages/my-package
cd packages/my-package && rm -fr node_modules dist
grep -r -l "sparse-merkle-tree" . | xargs sed -i 's/sparse-merkle-tree/my-package/'
# Update the remaining description/usage sections, and write your code in the src & tests folders!
```
3. Create an [issue](https://github.com/privacy-scaling-explorations/zk-kit/issues/new?assignees=&labels=feature+%3Arocket%3A&template=---package.md&title=) for your package and open a PR.
#### How can I create benchmarks for my library?
You can see some examples in the `benchmarks` folder. All you have to do is create a file that exports a function to run your benchmark in that folder, and add that function to the `index.ts` file. The `yarn benchmarks` command can be run with no parameters (it will run all the benchmarks), or you can specify the name of your benchmark file to run just that. When you run the command it will create a `benchmarks/results` folder with your results.
#### How can I publish the documentation of my library with Typedocs?
You just need to insert the NPM `docs` command in your `package.json` file, as in the other packages. This command will be executed by Yarn and the output of `typedocs` will be placed in the `docs` folder of the root directory, which will be used to deploy the documentation websites by the Github `docs` workflow whenever the `main` branch is updated.