1.5 KiB

description
description
Defines a KZG interface.

defineKzg

Defines a EIP-4844 compatible KZG interface. The KZG interface is used in the blob transaction signing process to generate KZG commitments & proofs.

defineKzg accepts a KZG interface that implements two functions:

  • blobToKzgCommitment: A function that takes a blob and returns it's KZG commitment.
  • computeBlobKzgProof: A function that takes a blob and it's commitment, and returns the KZG proof.

A couple of KZG implementations we recommend are:

  • c-kzg: Node.js bindings to c-kzg.
  • kzg-wasm: WebAssembly bindings to c-kzg.

Import

import { defineKzg } from 'viem'

Usage

// @noErrors
import * as cKzg from 'c-kzg'
import { defineKzg } from 'viem'
import { mainnetTrustedSetupPath } from 'viem/node'

cKzg.loadTrustedSetup(mainnetTrustedSetupPath)

const kzg = defineKzg(cKzg)

Returns

Kzg

The KZG interface.

Parameters

blobToKzgCommitment

  • Type: (blob: ByteArray) => ByteArray

Convert a blob to a KZG commitment.

computeBlobKzgProof

  • Type: (blob: ByteArray, commitment: ByteArray) => ByteArray

Given a blob, return the KZG proof that is used to verify it against the commitment.