C-KZG-4844
This is a TypeScript library for EIP-4844 and EIP-7594 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.
Important Links:
EIP-4844 - Polynomial Commitments
EIP-7594 - Polynomial Commitments Sampling
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;
computeCellsAndKzgProofs
export function computeCellsAndKzgProofs(blob: Blob): [Cell[], KZGProof[]];
recoverCellsAndKzgProofs
export function recoverCellsAndKzgProofs(
cellIndices: number[],
cells: Cell[],
): [Cell[], KZGProof[]];
verifyCellKzgProofBatch
export function verifyCellKzgProofBatch(
commitmentsBytes: Bytes48[],
cellIndices: number[],
cells: Cell[],
proofsBytes: Bytes48[]
): boolean;