c-kzg-4844/bindings/node.js
Matthew Keil 2642595e39
Reorganize/Clean-Up Node Bindings (#189)
* refactor(node-bindings): create src/lib/test folders

* feat(node-bindings): update bundle/publish commands

* refactor(node-bindings): remove unused files and dependencies

* refactor(node-bindings): move fixtures to __fixtures__

* fix(node-bindings): revert format of fixture json file

* fix(node-bindings): prettierignore and gitignore

* feat(node-bindings): add bindings package

* fix(node-bindings): fix test setup path

* fix(node-bindings): remove post-build copy action in bindings.gyp

* fix(node-bindings): package.json keys

* Update contributors

---------

Co-authored-by: George Kadianakis <desnacked@riseup.net>
2023-03-09 18:21:28 +02:00
..
lib Reorganize/Clean-Up Node Bindings (#189) 2023-03-09 18:21:28 +02:00
src Reorganize/Clean-Up Node Bindings (#189) 2023-03-09 18:21:28 +02:00
test Reorganize/Clean-Up Node Bindings (#189) 2023-03-09 18:21:28 +02:00
.gitignore Reorganize/Clean-Up Node Bindings (#189) 2023-03-09 18:21:28 +02:00
.prettierignore Reorganize/Clean-Up Node Bindings (#189) 2023-03-09 18:21:28 +02:00
.prettierrc.json Messy publish but it works 2022-11-05 00:46:26 -07:00
Dockerfile Fix uint type for newer g++ 2022-11-22 12:27:32 -08:00
Makefile Reorganize/Clean-Up Node Bindings (#189) 2023-03-09 18:21:28 +02:00
README.md Fix uint type for newer g++ 2022-11-22 12:27:32 -08:00
binding.dist.gyp Reorganize/Clean-Up Node Bindings (#189) 2023-03-09 18:21:28 +02:00
binding.gyp Reorganize/Clean-Up Node Bindings (#189) 2023-03-09 18:21:28 +02:00
jest.config.js Cleanup 2022-11-03 15:13:49 -07:00
package.json Reorganize/Clean-Up Node Bindings (#189) 2023-03-09 18:21:28 +02:00
tsconfig.build.json Reorganize/Clean-Up Node Bindings (#189) 2023-03-09 18:21:28 +02:00
tsconfig.json Reorganize/Clean-Up Node Bindings (#189) 2023-03-09 18:21:28 +02:00
yarn.lock Reorganize/Clean-Up Node Bindings (#189) 2023-03-09 18:21:28 +02: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. Your environment will need

  • A compiler like g++ or clang
  • make
  • python3

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