npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@blobkit/kzg-wasm

v2.3.0

Published

a WASM compilation of c-kzg-4844

Readme

KZG-WASM

This module implements a JS wrapper around a WASM compilation of the c-kzg-4844 C library built for use with EIP-4844. Starting with v1.0.0, the library also support cell-based operations in the context of EIP-7594 (PeerDAS).

This library is produced by building the original C code to WASM using the empscripten toolchain in this fork of c-kzg-4844.

Usage

This module exposes a single export, an async function called loadKZG which loads and compiles the WASM object, loads a trusted setup (defaults to the official setup from the KZG ceremony) and returns an object that exposes the API defined in the KZG type interface in @ethereumjs/util

To use with the @ethereumjs libraries, do the following:

import { loadKZG } from 'kzg-wasm'
import { Common, Chain, Hardfork } from '@ethereumjs/common'

const main = async () => {
    const kzg = await loadKZG()
    const common = new Common({
        chain: Chain.Mainnet,
        hardfork: Hardfork.Cancun,
        customCrypto: { kzg },
    })
    console.log(common.customCrypto.kzg) // Should print the initialized KZG interface
}

main()

API Reference

The loadKZG() function returns an object that implements the KZG interface with the following methods:

Core KZG Operations (EIP-4844)

loadTrustedSetup(trustedSetup?, precompute?)

loadTrustedSetup(trustedSetup: TrustedSetup = mainnetTrustedSetup, precompute: number = 0): number

Loads a trusted setup for KZG operations. Returns 0 on success, non-zero on failure.

freeTrustedSetup()

freeTrustedSetup(): void

Frees the loaded trusted setup from memory.

blobToKZGCommitment(blob)

blobToKZGCommitment(blob: string): string

Converts a blob of data into a KZG commitment. Takes a prefixed hex string containing 4096 big endian KZG field elements and returns a 48-byte KZG commitment as a prefixed hex string.

computeBlobKZGProof(blob, commitment)

computeBlobKZGProof(blob: string, commitment: string): string

Computes a KZG proof for a blob and its commitment. Returns a 48-byte KZG proof as a prefixed hex string.

verifyBlobKZGProof(blob, commitment, proof)

verifyBlobKZGProof(blob: string, commitment: string, proof: string): boolean

Verifies a KZG proof against a blob and its commitment. Returns true if the proof is valid, false otherwise.

verifyBlobKZGProofBatch(blobs, commitments, proofs)

verifyBlobKZGProofBatch(blobs: string[], commitments: string[], proofs: string[]): boolean

Verifies multiple KZG proofs in batch. All arrays must have the same length. Returns true if all proofs are valid, false otherwise.

verifyKZGProof(commitment, z, y, proof)

verifyKZGProof(commitment: string, z: string, y: string, proof: string): boolean

Verifies a KZG proof for specific points z and y against a commitment. Returns true if the proof is valid, false otherwise.

Cell-based Operations (EIP-7594)

computeCellsAndKZGProofs(blob)

computeCellsAndKZGProofs(blob: string): KZGProofWithCells

Computes all 128 cells and their corresponding KZG proofs for a blob. Returns an object containing arrays of proofs and cells.

recoverCellsFromKZGProofs(cellIndices, partialCells, numCells)

recoverCellsFromKZGProofs(cellIndices: number[], partialCells: string[], numCells: number): KZGProofWithCells

Recovers all cells and proofs from partial cell data. Requires at least 50% of the total cells to be provided. Returns the complete set of proofs and cells.

verifyCellKZGProof(commitment, cells, proofs)

verifyCellKZGProof(commitment: string, cells: string[], proofs: string[]): boolean

Verifies KZG proofs for specific cells against a commitment. Returns true if all proofs are valid, false otherwise.

verifyCellKZGProofBatch(commitments, cellIndices, cells, proofs, numCells)

verifyCellKZGProofBatch(commitments: string[], cellIndices: number[], cells: string[], proofs: string[], numCells: number): boolean

Verifies multiple cell KZG proofs in batch. All arrays must have the same length and match numCells. Returns true if all proofs are valid, false otherwise.

Compatibility Aliases

The library also provides aliases for compatibility with different naming conventions:

  • blobToKzgCommitment - alias for blobToKZGCommitment
  • computeBlobProof - alias for computeBlobKZGProof

Types

TrustedSetup

type TrustedSetup = {
    g1_monomial: string
    g1_lagrange: string
    g2_monomial: string
}

KZGProofWithCells

type KZGProofWithCells = {
    proofs: string[] // Array of 128 proofs, each 48 bytes
    cells: string[]  // Array of 128 cells, each 2048 bytes
}

Development

Build Process

This section outlines the build scripts included in this repository to create distributable JavaScript/TypeScript packages from the WASM compilation.

Prerequisites

Ensure you have the following installed:

  • Node.js (v16+)
  • npm
  • TypeScript (installed as dev dependency)
  • Babel (installed as dev dependency)

Build Scripts Overview

The repository includes the following build scripts:

  1. build - Main build command
  2. build:ts - TypeScript compilation to multiple targets
  3. transpileCJS - Babel transpilation for CommonJS compatibility
  4. fixRequire - Fix dynamic require statements
  5. fixWasmDirInNode - Fix WASM paths for Node.js builds
  6. fixWasmDirInWeb - Fix WASM paths for browser builds

Script Details

build:ts (scripts/ts-build.sh)

  • Copies WASM file to dist/wasm/
  • Compiles TypeScript to CommonJS (dist/cjs/)
  • Compiles TypeScript to ESM (dist/esm/)
  • Creates browser build (dist/browser/)

transpileCJS

  • Uses Babel to transpile src/kzg.js to dist/cjs/
  • Ensures CommonJS compatibility

fixRequire

  • Fixes dynamic require statements in CommonJS build
  • Replaces \_require('url') with require('url')

fixWasmDirInNode

  • Updates WASM file paths in Node.js builds
  • Changes kzg-node.wasmkzg.wasm../wasm/kzg.wasm

fixWasmDirInWeb

  • Updates WASM file paths in browser builds
  • Changes kzg-web.wasm../wasm/kzg.wasm

Build Output Structure

dist/
├── cjs/           # CommonJS build for Node.js
│   ├── index.js
│   ├── kzg.js
│   ├── loader.cjs
│   └── package.json
├── esm/           # ES Modules build
│   ├── index.js
│   ├── kzg.js
│   ├── loader.mjs
│   └── package.json
├── browser/       # Browser build
│   ├── index.js
│   ├── kzg.js
│   └── package.json
└── wasm/          # WASM binary
    └── kzg.wasm

Testing Builds

# Test all builds
npm test

# Test specific builds
npm run test:dist    # Test distribution build
npm run test:src     # Test source code
npm run test:browser # Test browser environment