c-kzg-4844/bindings/node.js/README.md

94 lines
1.8 KiB
Markdown
Raw Normal View History

2022-11-18 00:47:47 +00:00
This package wraps the c-kzg C code in C++ NAPI bindings which allow it to be imported into a NodeJS program.
Spec: https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/polynomial-commitments.md
# Usage
Install this library with
```sh
yarn add c-kzg
```
Import from it like any other library
```js
import {
KZGCommitment,
blobToKzgCommitment,
verifyAggregateKzgProof,
loadTrustedSetup,
transformTrustedSetupJSON,
} from "c-kzg";
```
2022-11-22 20:27:32 +00:00
# Requirements
2022-11-18 00:47:47 +00:00
2022-11-22 20:27:32 +00:00
The C and C++ code is compiled by node-gyp on installation. Your environment will need
- A compiler like g++ or clang
- `make`
- `python3`
2022-11-18 00:47:47 +00:00
# Contributing
2022-11-03 22:13:49 +00:00
This directory contains the code necessary to generate NodeJS bindings for C-KZG.
2022-11-18 00:47:47 +00:00
The bindings file has the following interface:
2022-11-04 06:44:08 +00:00
```js
2022-11-03 22:13:49 +00:00
2022-11-04 06:44:08 +00:00
loadTrustedSetup: (filePath: string) => SetupHandle;
freeTrustedSetup: (setupHandle: SetupHandle) => void;
blobToKzgCommitment: (blob: Blob, setupHandle: SetupHandle) => KZGCommitment;
computeAggregateKzgProof: (
blobs: Blob[],
setupHandle: SetupHandle
) => KZGProof;
verifyAggregateKzgProof: (
blobs: Blob[],
expectedKzgCommitments: KZGCommitment[],
kzgAggregatedProof: KZGProof,
setupHandle: SetupHandle
) => boolean;
2022-11-03 22:13:49 +00:00
```
2022-11-04 06:44:08 +00:00
2022-11-18 00:47:47 +00:00
But this library wraps it in module with manages the setupHandle internally.
2022-11-04 06:44:08 +00:00
2022-11-04 07:13:02 +00:00
First,
2022-11-04 06:44:08 +00:00
`npm install -g yarn` if you don't have it.
Install the blst submodule
```sh
git submodule update --init
2022-11-03 22:13:49 +00:00
```
2022-11-04 06:44:08 +00:00
Build blst and c_kzg_4844.c
2022-11-03 22:13:49 +00:00
```
2022-11-04 06:44:08 +00:00
cd src && make blst lib
2022-11-03 22:13:49 +00:00
```
2022-11-04 06:44:08 +00:00
Generate NodeJS bindings and run the TypeScript tests against them
2022-11-03 22:13:49 +00:00
2022-11-04 06:44:08 +00:00
```sh
cd ../bindings/node.js && yarn install && make test
2022-11-03 22:13:49 +00:00
```
2022-11-04 06:44:08 +00:00
After doing this once, you can re-build (if necessary) and re-run the tests with
```sh
make build test
2022-11-03 22:13:49 +00:00
```
2022-11-04 07:13:02 +00:00
After making changes, regenerate the distributable JS and type defs
```sh
make bundle
```