Merge pull request #4 from dgcoffman/dgc/publish-node-bindings-to-npm
Publish NodeJS bindings to npm
This commit is contained in:
commit
dc6e43ae55
|
@ -9,3 +9,4 @@ inc/blst_aux.h*
|
||||||
*bindings/csharp/*.exe
|
*bindings/csharp/*.exe
|
||||||
*bindings/csharp/*.dll
|
*bindings/csharp/*.dll
|
||||||
__pycache__
|
__pycache__
|
||||||
|
.DS_Store
|
||||||
|
|
23
README.md
23
README.md
|
@ -1,6 +1,7 @@
|
||||||
# C-KZG-4844: A minimal library for EIP-4844 Polynomial Commitments
|
# C-KZG-4844: A minimal library for EIP-4844 Polynomial Commitments
|
||||||
|
|
||||||
This is a copy of C-KZG stripped down to support the [Polynomial Commitments](https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/polynomial-commitments.md) API:
|
This is a copy of C-KZG stripped down to support the [Polynomial Commitments](https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/polynomial-commitments.md) API:
|
||||||
|
|
||||||
- `compute_aggregate_kzg_proof`
|
- `compute_aggregate_kzg_proof`
|
||||||
- `verify_aggregate_kzg_proof`
|
- `verify_aggregate_kzg_proof`
|
||||||
- `blob_to_kzg_commitment`
|
- `blob_to_kzg_commitment`
|
||||||
|
@ -9,3 +10,25 @@ This is a copy of C-KZG stripped down to support the [Polynomial Commitments](ht
|
||||||
We also provide `load_trusted_setup` and `free_trusted_setup` to load the
|
We also provide `load_trusted_setup` and `free_trusted_setup` to load the
|
||||||
trusted setup data from a file into an object that can be passed to the API
|
trusted setup data from a file into an object that can be passed to the API
|
||||||
functions, and functions for converting commitments/proofs/points to/from bytes.
|
functions, and functions for converting commitments/proofs/points to/from bytes.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Install the blst submodule
|
||||||
|
|
||||||
|
```
|
||||||
|
git submodule update --init
|
||||||
|
```
|
||||||
|
|
||||||
|
Build blst
|
||||||
|
|
||||||
|
```
|
||||||
|
cd src
|
||||||
|
make blst
|
||||||
|
```
|
||||||
|
|
||||||
|
Build the C-KZG code
|
||||||
|
|
||||||
|
```
|
||||||
|
cd src
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
build
|
build
|
||||||
|
dist
|
||||||
*.node
|
*.node
|
||||||
node_modules
|
node_modules
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
.vscode
|
||||||
|
build
|
||||||
|
!dist/deps/blst/build
|
||||||
|
node_modules
|
||||||
|
.gitignore
|
||||||
|
.npmignore
|
||||||
|
.prettierignore
|
||||||
|
.prettierrc.json
|
||||||
|
*.o
|
||||||
|
*.node
|
||||||
|
test.ts
|
||||||
|
kzg.ts
|
||||||
|
jest.config.js
|
||||||
|
rollup.config.js
|
||||||
|
tsconfig.json
|
||||||
|
babel.config.js
|
||||||
|
*.bak
|
|
@ -2,7 +2,7 @@
|
||||||
"trailingComma": "all",
|
"trailingComma": "all",
|
||||||
"overrides": [
|
"overrides": [
|
||||||
{
|
{
|
||||||
"files": "binding.gyp",
|
"files": "*.gyp",
|
||||||
"options": { "parser": "json" }
|
"options": { "parser": "json" }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -3,8 +3,8 @@ all: clean build format test bundle
|
||||||
clean:
|
clean:
|
||||||
yarn node-gyp clean
|
yarn node-gyp clean
|
||||||
rm -rf build
|
rm -rf build
|
||||||
|
rm -rf dist
|
||||||
rm -f *.node
|
rm -f *.node
|
||||||
rm -f dist/kzg.node
|
|
||||||
rm -f *.a
|
rm -f *.a
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
|
|
||||||
|
@ -18,5 +18,14 @@ test: build
|
||||||
format:
|
format:
|
||||||
yarn prettier --write .
|
yarn prettier --write .
|
||||||
|
|
||||||
bundle:
|
bundle: clean
|
||||||
yarn rollup --config rollup.config.js --bundleConfigAsCjs
|
yarn rollup --config rollup.config.js --bundleConfigAsCjs
|
||||||
|
mkdir -p dist/deps/c-kzg
|
||||||
|
cp -r ../../blst dist/deps
|
||||||
|
cp ../../src/c_kzg_4844.c dist/deps/c-kzg
|
||||||
|
cp ../../src/c_kzg_4844.h dist/deps/c-kzg
|
||||||
|
|
||||||
|
publish: bundle
|
||||||
|
mv binding.gyp binding.gyp.bak
|
||||||
|
cp binding.dist.gyp binding.gyp
|
||||||
|
npm publish && mv binding.gyp.bak binding.gyp || mv binding.gyp.bak binding.gyp
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
{
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"target_name": "kzg",
|
||||||
|
"cflags!": ["-fno-exceptions"],
|
||||||
|
"cflags_cc!": ["-fno-exceptions"],
|
||||||
|
"xcode_settings": {
|
||||||
|
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
||||||
|
"CLANG_CXX_LIBRARY": "libc++",
|
||||||
|
"MACOSX_DEPLOYMENT_TARGET": "13.0"
|
||||||
|
},
|
||||||
|
"sources": ["kzg.cxx"],
|
||||||
|
"include_dirs": [
|
||||||
|
"<(module_root_dir)/dist/deps/blst/bindings",
|
||||||
|
"<(module_root_dir)/dist/deps/c-kzg",
|
||||||
|
"<!@(node -p \"require('node-addon-api').include\")"
|
||||||
|
],
|
||||||
|
"libraries": [
|
||||||
|
"<(module_root_dir)/libblst.a",
|
||||||
|
"<(module_root_dir)/c_kzg_4844.o"
|
||||||
|
],
|
||||||
|
"dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"],
|
||||||
|
"defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"],
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"action_name": "build_blst",
|
||||||
|
"inputs": ["<(module_root_dir)/dist/deps/blst/build.sh"],
|
||||||
|
"outputs": ["<(module_root_dir)/libblst.a"],
|
||||||
|
"action": ["<(module_root_dir)/dist/deps/blst/build.sh"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"action_name": "build_ckzg",
|
||||||
|
"inputs": [
|
||||||
|
"<(module_root_dir)/dist/deps/c-kzg/c_kzg_4844.c",
|
||||||
|
"<(module_root_dir)/libblst.a"
|
||||||
|
],
|
||||||
|
"outputs": ["<(module_root_dir)/c_kzg_4844.o"],
|
||||||
|
"action": [
|
||||||
|
"cc",
|
||||||
|
"-I<(module_root_dir)/dist/deps/blst/bindings",
|
||||||
|
"-O2",
|
||||||
|
"-c",
|
||||||
|
"<(module_root_dir)/dist/deps/c-kzg/c_kzg_4844.c"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"target_name": "action_after_build",
|
||||||
|
"type": "none",
|
||||||
|
"dependencies": ["kzg"],
|
||||||
|
"copies": [
|
||||||
|
{
|
||||||
|
"files": ["./build/Release/kzg.node"],
|
||||||
|
"destination": "./dist"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -30,10 +30,6 @@
|
||||||
{
|
{
|
||||||
"files": ["./build/Release/kzg.node"],
|
"files": ["./build/Release/kzg.node"],
|
||||||
"destination": "."
|
"destination": "."
|
||||||
},
|
|
||||||
{
|
|
||||||
"files": ["./build/Release/kzg.node"],
|
|
||||||
"destination": "./dist"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
export declare type BLSFieldElement = Uint8Array;
|
|
||||||
export declare type KZGProof = Uint8Array;
|
|
||||||
export declare type KZGCommitment = Uint8Array;
|
|
||||||
export declare type Blob = Uint8Array;
|
|
||||||
export declare const FIELD_ELEMENTS_PER_BLOB: number;
|
|
||||||
export declare const BYTES_PER_FIELD_ELEMENT: number;
|
|
||||||
export declare function loadTrustedSetup(filePath: string): void;
|
|
||||||
export declare function freeTrustedSetup(): void;
|
|
||||||
export declare function blobToKzgCommitment(blob: Blob): KZGCommitment;
|
|
||||||
export declare function computeAggregateKzgProof(blobs: Blob[]): KZGProof;
|
|
||||||
export declare function verifyAggregateKzgProof(blobs: Blob[], expectedKzgCommitments: KZGCommitment[], kzgAggregatedProof: KZGProof): boolean;
|
|
|
@ -1 +0,0 @@
|
||||||
export {};
|
|
|
@ -1,44 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The public interface of this module exposes the functions as specified by
|
|
||||||
* https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/polynomial-commitments.md#kzg
|
|
||||||
*/
|
|
||||||
const kzg = require("./kzg.node");
|
|
||||||
const FIELD_ELEMENTS_PER_BLOB = kzg.FIELD_ELEMENTS_PER_BLOB;
|
|
||||||
const BYTES_PER_FIELD_ELEMENT = kzg.BYTES_PER_FIELD_ELEMENT;
|
|
||||||
// Stored as internal state
|
|
||||||
let setupHandle;
|
|
||||||
function requireSetupHandle() {
|
|
||||||
if (!setupHandle) {
|
|
||||||
throw new Error("You must call loadTrustedSetup to initialize KZG.");
|
|
||||||
}
|
|
||||||
return setupHandle;
|
|
||||||
}
|
|
||||||
function loadTrustedSetup(filePath) {
|
|
||||||
if (setupHandle) {
|
|
||||||
throw new Error("Call freeTrustedSetup before loading a new trusted setup.");
|
|
||||||
}
|
|
||||||
setupHandle = kzg.loadTrustedSetup(filePath);
|
|
||||||
}
|
|
||||||
function freeTrustedSetup() {
|
|
||||||
kzg.freeTrustedSetup(requireSetupHandle());
|
|
||||||
setupHandle = undefined;
|
|
||||||
}
|
|
||||||
function blobToKzgCommitment(blob) {
|
|
||||||
return kzg.blobToKzgCommitment(blob, requireSetupHandle());
|
|
||||||
}
|
|
||||||
function computeAggregateKzgProof(blobs) {
|
|
||||||
return kzg.computeAggregateKzgProof(blobs, requireSetupHandle());
|
|
||||||
}
|
|
||||||
function verifyAggregateKzgProof(blobs, expectedKzgCommitments, kzgAggregatedProof) {
|
|
||||||
return kzg.verifyAggregateKzgProof(blobs, expectedKzgCommitments, kzgAggregatedProof, requireSetupHandle());
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.BYTES_PER_FIELD_ELEMENT = BYTES_PER_FIELD_ELEMENT;
|
|
||||||
exports.FIELD_ELEMENTS_PER_BLOB = FIELD_ELEMENTS_PER_BLOB;
|
|
||||||
exports.blobToKzgCommitment = blobToKzgCommitment;
|
|
||||||
exports.computeAggregateKzgProof = computeAggregateKzgProof;
|
|
||||||
exports.freeTrustedSetup = freeTrustedSetup;
|
|
||||||
exports.loadTrustedSetup = loadTrustedSetup;
|
|
||||||
exports.verifyAggregateKzgProof = verifyAggregateKzgProof;
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "c-kzg",
|
"name": "c-kzg",
|
||||||
"version": "0.0.1",
|
"version": "0.0.7",
|
||||||
"description": "NodeJS bindings for C-KZG",
|
"description": "NodeJS bindings for C-KZG",
|
||||||
"author": "Dan Coffman",
|
"author": "Dan Coffman",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
@ -6,5 +6,9 @@ export default {
|
||||||
dir: "dist",
|
dir: "dist",
|
||||||
format: "cjs",
|
format: "cjs",
|
||||||
},
|
},
|
||||||
plugins: [typescript()],
|
plugins: [
|
||||||
|
typescript({
|
||||||
|
exclude: ["test.ts"],
|
||||||
|
}),
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue