c-kzg-4844/bindings/node.js
Ramana Kumar bcc138560a
Update interface for verify_kzg_proof
2022-11-19 09:35:55 +00:00
..
.gitignore Add ability to parse JSON trusted setup to text format expected by C-KZG 2022-11-17 16:41:09 -08:00
.npmignore Bump package version. npmignore testing_trusted_setups.json 2022-11-17 16:41:09 -08:00
.prettierignore Do not run prettier on dist 2022-11-03 22:37:56 -07:00
.prettierrc.json Messy publish but it works 2022-11-05 00:46:26 -07:00
Dockerfile Add ability to parse JSON trusted setup to text format expected by C-KZG 2022-11-17 16:41:09 -08:00
Makefile Add ability to parse JSON trusted setup to text format expected by C-KZG 2022-11-17 16:41:09 -08:00
README.md Add contributing note 2022-11-17 16:47:47 -08:00
babel.config.js Cleanup 2022-11-03 15:13:49 -07:00
binding.dist.gyp Turn CPP exceptions back off to see if that fixes the ELF problem 2022-11-16 16:23:06 -08:00
binding.gyp Turn CPP exceptions back off to see if that fixes the ELF problem 2022-11-16 16:23:06 -08:00
jest.config.js Cleanup 2022-11-03 15:13:49 -07:00
kzg.cxx Update interface for verify_kzg_proof 2022-11-19 09:35:55 +00:00
kzg.ts Add ability to parse JSON trusted setup to text format expected by C-KZG 2022-11-17 16:41:09 -08:00
package.json Add contributing note 2022-11-17 16:47:47 -08:00
rollup.config.js Start working on NPM publish 2022-11-04 18:48:52 -07:00
test.ts Skip the tests which fails 2022-11-17 16:41:09 -08:00
testing_trusted_setups.json Add ability to parse JSON trusted setup to text format expected by C-KZG 2022-11-17 16:41:09 -08:00
tsconfig.json Do not run prettier on dist 2022-11-03 22:37:56 -07:00
yarn.lock Always make, never package.json scripts 2022-11-03 22:49:06 -07:00

README.md

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

yarn add c-kzg

Import from it like any other library

import {
  KZGCommitment,
  blobToKzgCommitment,
  verifyAggregateKzgProof,
  loadTrustedSetup,
  transformTrustedSetupJSON,
} from "c-kzg";

Requirements

  • The C and C++ code is compiled by node-gyp on installation, so your environment will need a compiler like GCC or clang

Contributing

This directory contains the code necessary to generate NodeJS bindings for C-KZG.

The bindings file has the following interface:


  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;

But this library wraps it in module with manages the setupHandle internally.

First, npm install -g yarn if you don't have it.

Install the blst submodule

git submodule update --init

Build blst and c_kzg_4844.c

cd src && make blst lib

Generate NodeJS bindings and run the TypeScript tests against them

cd ../bindings/node.js && yarn install && make test

After doing this once, you can re-build (if necessary) and re-run the tests with

make build test

After making changes, regenerate the distributable JS and type defs

make bundle