C-KZG-4844
This is a TypeScript library for EIP-4844 that implements the Polynomial
Commitments
API. The core functionality was originally a stripped-down copy of
C-KZG, but has been heavily modified
since then. This package wraps that native c-kzg
C code in C/C++ NAPI
bindings for use in node.js applications.
Spec: https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/polynomial-commitments.md
Prerequisites
Installation requires compilation of C code. Target environment must have:
Installation
yarn add c-kzg
npm i -S c-kzg
Usage
import {
BYTES_PER_BLOB,
Blob,
Bytes48,
blobToKzgCommitment,
computeBlobKzgProof,
verifyBlobKzgProofBatch,
} from "c-kzg";
const blobs = [] as Blob[];
const commitments = [] as Bytes48[];
const proofs = [] as Bytes48[];
for (let i = 0; i < BATCH_SIZE; i++) {
blobs.push(Buffer.alloc(BYTES_PER_BLOB, "*"));
commitments.push(blobToKzgCommitment(blobs[i]));
proofs.push(computeBlobKzgProof(blobs[i], commitments[i]));
}
const isValid = verifyBlobKzgProofBatch(blobs, commitments, proofs);
API
loadTrustedSetup
loadTrustedSetup(filePath: string): void;
blobToKzgCommitment
blobToKzgCommitment(blob: Blob): KZGCommitment;
computeKzgProof
computeKzgProof(blob: Blob, zBytes: Bytes32): ProofResult;
computeBlobKzgProof
computeBlobKzgProof(
blob: Blob,
commitmentBytes: Bytes48,
): KZGProof;
verifyKzgProof
verifyKzgProof(
commitmentBytes: Bytes48,
zBytes: Bytes32,
yBytes: Bytes32,
proofBytes: Bytes48,
): boolean;
verifyBlobKzgProof
verifyBlobKzgProof(
blob: Blob,
commitmentBytes: Bytes48,
proofBytes: Bytes48,
): boolean;
verifyBlobKzgProofBatch
verifyBlobKzgProofBatch(
blobs: Blob[],
commitmentsBytes: Bytes48[],
proofsBytes: Bytes48[],
): boolean;