Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Note: This is an alpha release with peerDas functionality. For the current stable release use v3
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
Installation requires compilation of C code. Target environment must have:
yarn add c-kzg
# or
npm i -S c-kzg
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);
loadTrustedSetup
/**
* Sets up the c-kzg library. Pass in a properly formatted trusted setup file
* to configure the library. File must be in json format, see TrustedSetupJson
* interface for more details, or as a properly formatted utf-8 encoded file.
*
* @remark This function must be run before any other functions in this
* library can be run.
*
* @param {string} filePath - The absolute path of the trusted setup
*/
loadTrustedSetup(filePath: string): void;
blobToKzgCommitment
/**
* Convert a blob to a KZG commitment.
*
* @param {Blob} blob - The blob representing the polynomial to be committed to
*/
blobToKzgCommitment(blob: Blob): KZGCommitment;
computeKzgProof
/**
* Compute KZG proof for polynomial in Lagrange form at position z.
*
* @param {Blob} blob - The blob (polynomial) to generate a proof for
* @param {Bytes32} zBytes - The generator z-value for the evaluation points
*
* @return {ProofResult} - Tuple containing the resulting proof and evaluation
* of the polynomial at the evaluation point z
*/
computeKzgProof(blob: Blob, zBytes: Bytes32): ProofResult;
computeBlobKzgProof
/**
* Given a blob, return the KZG proof that is used to verify it against the
* commitment.
*
* @param {Blob} blob - The blob (polynomial) to generate a proof for
* @param {Bytes48} commitmentBytes - Commitment to verify
*/
computeBlobKzgProof(
blob: Blob,
commitmentBytes: Bytes48,
): KZGProof;
verifyKzgProof
/**
* Verify a KZG poof claiming that `p(z) == y`.
*
* @param {Bytes48} commitmentBytes - The serialized commitment corresponding to
* polynomial p(x)
* @param {Bytes32} zBytes - The serialized evaluation point
* @param {Bytes32} yBytes - The serialized claimed evaluation result
* @param {Bytes48} proofBytes - The serialized KZG proof
*/
verifyKzgProof(
commitmentBytes: Bytes48,
zBytes: Bytes32,
yBytes: Bytes32,
proofBytes: Bytes48,
): boolean;
verifyBlobKzgProof
/**
* Given a blob and its proof, verify that it corresponds to the provided
* commitment.
*
* @param {Blob} blob - The serialized blob to verify
* @param {Bytes48} commitmentBytes - The serialized commitment to verify
* @param {Bytes48} proofBytes - The serialized KZG proof for verification
*/
verifyBlobKzgProof(
blob: Blob,
commitmentBytes: Bytes48,
proofBytes: Bytes48,
): boolean;
verifyBlobKzgProofBatch
/**
* Given an array of blobs and their proofs, verify that they correspond to
* their provided commitment.
*
* Note: blobs[0] relates to commitmentBytes[0] and proofBytes[0]
*
* @param {Blob} blobs - An array of serialized blobs to verify
* @param {Bytes48} commitmentBytes - An array of serialized commitments to
* verify
* @param {Bytes48} proofBytes - An array of serialized KZG proofs for
* verification
*/
verifyBlobKzgProofBatch(
blobs: Blob[],
commitmentsBytes: Bytes48[],
proofsBytes: Bytes48[],
): boolean;
computeCells
/**
* Get the cells for a given blob.
*
* @param {Blob} blob - The blob to get cells for
*
* @return {Cell[]} - An array of cells
*
* @throws {Error} - Failure to allocate or compute cells
*/
export function computeCells(blob: Blob): Cell[];
computeCellsAndKzgProofs
/**
* Get the cells and proofs for a given blob.
*
* @param {Blob} blob - the blob to get cells/proofs for
*
* @return {[Cell[], KZGProof[]]} - A tuple of cells and proofs
*
* @throws {Error} - Failure to allocate or compute cells and proofs
*/
export function computeCellsAndKzgProofs(blob: Blob): [Cell[], KZGProof[]];
cellsToBlob
/**
* Convert an array of cells to a blob.
*
* @param {Cell[]} cells - The cells to convert to a blob
*
* @return {Blob} - The blob for the given cells
*
* @throws {Error} - Invalid input, failure to allocate, or invalid conversion
*/
export function cellsToBlob(cells: Cell[]): Blob;
recoverAllCells
/**
* Given at least 50% of cells, reconstruct the missing ones.
*
* @param {number[]} cellIds - The identifiers for the cells you have
* @param {Cell[]} cells - The cells you have
*
* @return {Cell[]} - All cells for that blob
*
* @throws {Error} - Invalid input, failure to allocate or error recovering cells
*/
export function recoverAllCells(cellIds: number[], cells: Cell[]): Cell[];
verifyCellKzgProof
/**
* Verify that a cell's proof is valid.
*
* @param {Bytes48} commitmentBytes - Commitment bytes
* @param {number} cellId - The cell identifier
* @param {Cell} cell - The cell to verify
* @param {Bytes48} proofBytes - The proof for the cell
*
* @return {boolean} - True if the cell is valid with respect to this commitment
*
* @throws {Error} - Errors validating cell's proof
*/
export function verifyCellKzgProof(commitmentBytes: Bytes48, cellId: number, cell: Cell, proofBytes: Bytes48): boolean;
verifyCellKzgProofBatch
/**
* Verify that multiple cells' proofs are valid.
*
* @param {Bytes48[]} commitmentsBytes - The commitments for all blobs
* @param {number[]} rowIndices - The row index for each cell
* @param {number[]} columnIndices - The column index for each cell
* @param {Cell[]} cells - The cells to verify
* @param {Bytes48[]} proofsBytes - The proof for each cell
*
* @return {boolean} - True if the cells are valid with respect to the given commitments
*
* @throws {Error} - Invalid input, failure to allocate memory, or errors verifying batch
*/
export function verifyCellKzgProofBatch(
commitmentsBytes: Bytes48[],
rowIndices: number[],
columnIndices: number[],
cells: Cell[],
proofsBytes: Bytes48[]
): boolean;
FAQs
NodeJS bindings for C-KZG
The npm package c-kzg receives a total of 430 weekly downloads. As such, c-kzg popularity was classified as not popular.
We found that c-kzg demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.