Skip to main content
@tevm/voltaire
@tevm/voltaire / crypto/KZG

crypto/KZG

Classes

KzgError

Defined in: src/crypto/KZG/errors.ts:13 Base KZG error for polynomial commitment operations

See

https://voltaire.tevm.sh/crypto/kzg for KZG documentation

Since

0.0.0

Extends

Extended by

Constructors

Constructor
new KzgError(message, options?): KzgError
Defined in: src/crypto/KZG/errors.ts:14
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
KzgError
Overrides
CryptoError.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
CryptoError.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
CryptoError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
CryptoError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
Inherited from
CryptoError.docsPath

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
CryptoError.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
CryptoError.toJSON

KzgInvalidBlobError

Defined in: src/crypto/KZG/errors.ts:70 Invalid blob error for EIP-4844 blob validation Thrown when blob data is malformed, wrong length, or contains invalid field elements

See

https://voltaire.tevm.sh/crypto/kzg/validate-blob

Since

0.0.0

Extends

Constructors

Constructor
new KzgInvalidBlobError(message, options?): KzgInvalidBlobError
Defined in: src/crypto/KZG/errors.ts:71
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
KzgInvalidBlobError
Overrides
KzgError.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
KzgError.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
KzgError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
KzgError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
Inherited from
KzgError.docsPath

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
KzgError.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
KzgError.toJSON

KzgNotInitializedError

Defined in: src/crypto/KZG/errors.ts:41 Trusted setup not initialized error Thrown when KZG operations are attempted before loadTrustedSetup() is called

See

https://voltaire.tevm.sh/crypto/kzg/load-trusted-setup

Since

0.0.0

Extends

Constructors

Constructor
new KzgNotInitializedError(message, options?): KzgNotInitializedError
Defined in: src/crypto/KZG/errors.ts:42
Parameters
message
string = "KZG trusted setup not initialized"
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
KzgNotInitializedError
Overrides
KzgError.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
KzgError.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
KzgError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
KzgError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
Inherited from
KzgError.docsPath

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
KzgError.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
KzgError.toJSON

KzgVerificationError

Defined in: src/crypto/KZG/errors.ts:98 Verification error for KZG proof verification failures Thrown when proof verification fails or verification inputs are invalid

See

https://voltaire.tevm.sh/crypto/kzg/verify-blob-kzg-proof

Since

0.0.0

Extends

Constructors

Constructor
new KzgVerificationError(message, options?): KzgVerificationError
Defined in: src/crypto/KZG/errors.ts:99
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
KzgVerificationError
Overrides
KzgError.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
KzgError.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
KzgError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
KzgError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
Inherited from
KzgError.docsPath

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
KzgError.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
KzgError.toJSON

Type Aliases

BlobType

BlobType = Uint8Array & object
Defined in: src/crypto/KZG/BlobType.ts:11 Branded type for Blob (EIP-4844) A blob is 131072 bytes (128 KB) containing 4096 field elements

Type Declaration

[brand]
readonly [brand]: "Blob"

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

KzgCommitmentType

KzgCommitmentType = Uint8Array & object
Defined in: src/crypto/KZG/KzgCommitmentType.ts:11 Branded type for KZG Commitment (EIP-4844) A KZG commitment is 48 bytes representing a BLS12-381 G1 point

Type Declaration

[brand]
readonly [brand]: "KzgCommitment"

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

KzgProofType

KzgProofType = Uint8Array & object
Defined in: src/crypto/KZG/KzgProofType.ts:11 Branded type for KZG Proof (EIP-4844) A KZG proof is 48 bytes representing a BLS12-381 G1 point

Type Declaration

[brand]
readonly [brand]: "KzgProof"

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Variables

blobToKzgCommitment()

const blobToKzgCommitment: (blob) => Uint8Array
Defined in: src/crypto/KZG/KZG.js:60 Convert blob to KZG commitment

Parameters

blob
Uint8Array

Returns

Uint8Array

BYTES_PER_BLOB

const BYTES_PER_BLOB: number = 131072
Defined in: src/crypto/KZG/constants.js:13 Total bytes per blob (128 KB)

Since

0.0.0

BYTES_PER_COMMITMENT

const BYTES_PER_COMMITMENT: number = 48
Defined in: src/crypto/KZG/constants.js:20 Bytes per KZG commitment (BLS12-381 G1 point)

Since

0.0.0

BYTES_PER_FIELD_ELEMENT

const BYTES_PER_FIELD_ELEMENT: number = 32
Defined in: src/crypto/KZG/constants.js:34 Bytes per field element

Since

0.0.0

BYTES_PER_PROOF

const BYTES_PER_PROOF: number = 48
Defined in: src/crypto/KZG/constants.js:27 Bytes per KZG proof (BLS12-381 G1 point)

Since

0.0.0

computeBlobKzgProof()

const computeBlobKzgProof: (blob, commitment) => Uint8Array
Defined in: src/crypto/KZG/KZG.js:76 Compute KZG blob proof given commitment

Parameters

blob
Uint8Array
commitment
Uint8Array

Returns

Uint8Array

computeKzgProof()

const computeKzgProof: (blob, z) => object
Defined in: src/crypto/KZG/KZG.js:68 Compute KZG proof for a blob at a given point

Parameters

blob
Uint8Array
z
Uint8Array

Returns

object
proof
proof: Uint8Array
y
y: Uint8Array

FIELD_ELEMENTS_PER_BLOB

const FIELD_ELEMENTS_PER_BLOB: number = 4096
Defined in: src/crypto/KZG/constants.js:41 Number of field elements per blob

Since

0.0.0

verifyBlobKzgProof()

const verifyBlobKzgProof: (blob, commitment, proof) => boolean
Defined in: src/crypto/KZG/KZG.js:92 Verify a KZG blob proof

Parameters

blob
Uint8Array
commitment
Uint8Array
proof
Uint8Array

Returns

boolean

verifyBlobKzgProofBatch()

const verifyBlobKzgProofBatch: (blobs, commitments, proofs) => boolean
Defined in: src/crypto/KZG/KZG.js:100 Verify multiple KZG blob proofs in batch

Parameters

blobs
Uint8Array<ArrayBufferLike>[]
commitments
Uint8Array<ArrayBufferLike>[]
proofs
Uint8Array<ArrayBufferLike>[]

Returns

boolean

verifyKzgProof()

const verifyKzgProof: (commitment, z, y, proof) => boolean
Defined in: src/crypto/KZG/KZG.js:84 Verify a KZG proof

Parameters

commitment
Uint8Array
z
Uint8Array
y
Uint8Array
proof
Uint8Array

Returns

boolean

Functions

BlobToKzgCommitment()

BlobToKzgCommitment(deps): (blob) => Uint8Array
Defined in: src/crypto/KZG/blobToKzgCommitment.js:21 Factory: Convert blob to KZG commitment

Parameters

deps
Crypto dependencies
blobToKzgCommitment
(blob) => Uint8Array c-kzg blobToKzgCommitment function

Returns

Function that converts blob to KZG commitment
(blob): Uint8Array
Parameters
blob
Uint8Array
Returns
Uint8Array

Example

import { BlobToKzgCommitment } from '@tevm/voltaire/crypto/KZG'
import * as ckzg from 'c-kzg'

const blobToKzgCommitment = BlobToKzgCommitment({ blobToKzgCommitment: ckzg.blobToKzgCommitment })
const commitment = blobToKzgCommitment(blob)

ComputeBlobKzgProof()

ComputeBlobKzgProof(deps): (blob, commitment) => Uint8Array
Defined in: src/crypto/KZG/computeBlobKzgProof.js:28 Factory: Compute blob KZG proof for a blob given its commitment This is the optimized version for blob verification (EIP-4844). Unlike computeKzgProof which requires an evaluation point z, this function generates a proof that can be used with verifyBlobKzgProof.

Parameters

deps
Crypto dependencies
computeBlobKzgProof
(blob, commitment) => Uint8Array c-kzg computeBlobKzgProof function

Returns

Function that computes blob KZG proof
(blob, commitment): Uint8Array
Parameters
blob
Uint8Array
commitment
Uint8Array
Returns
Uint8Array

Example

import { ComputeBlobKzgProof } from '@tevm/voltaire/crypto/KZG'
import * as ckzg from 'c-kzg'

const computeBlobKzgProof = ComputeBlobKzgProof({ computeBlobKzgProof: ckzg.computeBlobKzgProof })
const commitment = KZG.blobToKzgCommitment(blob)
const proof = computeBlobKzgProof(blob, commitment)
// Use with verifyBlobKzgProof(blob, commitment, proof)

ComputeKzgProof()

ComputeKzgProof(deps): (blob, z) => object
Defined in: src/crypto/KZG/computeKzgProof.js:22 Factory: Compute KZG proof for blob at evaluation point z

Parameters

deps
Crypto dependencies
computeKzgProof
(blob, z) => [Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>] c-kzg computeKzgProof function

Returns

Function that computes KZG proof
(blob, z): object
Parameters
blob
Uint8Array
z
Uint8Array
Returns
object
proof
proof: Uint8Array
y
y: Uint8Array

Example

import { ComputeKzgProof } from '@tevm/voltaire/crypto/KZG'
import * as ckzg from 'c-kzg'

const computeKzgProof = ComputeKzgProof({ computeKzgProof: ckzg.computeKzgProof })
const { proof, y } = computeKzgProof(blob, z)

createEmptyBlob()

createEmptyBlob(): Uint8Array<ArrayBufferLike>
Defined in: src/crypto/KZG/createEmptyBlob.js:16 Create empty blob filled with zeros

Returns

Uint8Array<ArrayBufferLike> New zero-filled blob

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

Example

import { createEmptyBlob } from './crypto/KZG/index.js';
const blob = createEmptyBlob();

freeTrustedSetup()

freeTrustedSetup(): void
Defined in: src/crypto/KZG/loadTrustedSetup.js:53 Free trusted setup resources Call when KZG operations are no longer needed.

Returns

void

See

https://voltaire.tevm.sh/crypto/kzg

Since

0.0.0

generateRandomBlob()

generateRandomBlob(seed?): Uint8Array<ArrayBufferLike>
Defined in: src/crypto/KZG/generateRandomBlob.js:23 Generate random valid blob (for testing)

Parameters

seed?
number Optional seed for deterministic generation

Returns

Uint8Array<ArrayBufferLike> Random blob with valid field elements

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

If crypto.getRandomValues not available

Example

import { generateRandomBlob } from './crypto/KZG/index.js';
const blob = generateRandomBlob();
const deterministicBlob = generateRandomBlob(12345);

isInitialized()

isInitialized(): boolean
Defined in: src/crypto/KZG/isInitialized.js:18 Check if KZG is initialized

Returns

boolean true if trusted setup is loaded

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

Example

import { isInitialized, loadTrustedSetup } from './crypto/KZG/index.js';
if (!isInitialized()) {
  loadTrustedSetup();
}

loadTrustedSetup()

loadTrustedSetup(_filePath?): void
Defined in: src/crypto/KZG/loadTrustedSetup.js:28 Load trusted setup from embedded data Uses the embedded trusted setup from c-kzg-4844. Call this once during application startup before using any KZG operations. Available in both native FFI and WASM environments.

Parameters

_filePath?
string Optional path (ignored, uses embedded setup)

Returns

void

See

https://voltaire.tevm.sh/crypto/kzg

Since

0.0.0

Throws

If loading fails

Example

import { loadTrustedSetup } from './crypto/KZG/index.js';

loadTrustedSetup();

validateBlob()

validateBlob(blob): void
Defined in: src/crypto/KZG/validateBlob.js:22 Validate blob format

Parameters

blob
Uint8Array<ArrayBufferLike> Blob to validate

Returns

void

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

If blob is invalid

Example

import { validateBlob } from './crypto/KZG/index.js';
validateBlob(blob); // throws if invalid

VerifyBlobKzgProof()

VerifyBlobKzgProof(deps): (blob, commitment, proof) => boolean
Defined in: src/crypto/KZG/verifyBlobKzgProof.js:22 Factory: Verify blob KZG proof (optimized for blob verification)

Parameters

deps
Crypto dependencies
verifyBlobKzgProof
(blob, commitment, proof) => boolean c-kzg verifyBlobKzgProof function

Returns

Function that verifies blob KZG proof
(blob, commitment, proof): boolean
Parameters
blob
Uint8Array
commitment
Uint8Array
proof
Uint8Array
Returns
boolean

Example

import { VerifyBlobKzgProof } from '@tevm/voltaire/crypto/KZG'
import * as ckzg from 'c-kzg'

const verifyBlobKzgProof = VerifyBlobKzgProof({ verifyBlobKzgProof: ckzg.verifyBlobKzgProof })
const valid = verifyBlobKzgProof(blob, commitment, proof)

VerifyBlobKzgProofBatch()

VerifyBlobKzgProofBatch(deps): (blobs, commitments, proofs) => boolean
Defined in: src/crypto/KZG/verifyBlobKzgProofBatch.js:21 Factory: Verify multiple blob KZG proofs (batch verification)

Parameters

deps
Crypto dependencies
verifyBlobKzgProofBatch
(blobs, commitments, proofs) => boolean c-kzg verifyBlobKzgProofBatch function

Returns

Function that verifies batch of blob KZG proofs
(blobs, commitments, proofs): boolean
Parameters
blobs
Uint8Array<ArrayBufferLike>[]
commitments
Uint8Array<ArrayBufferLike>[]
proofs
Uint8Array<ArrayBufferLike>[]
Returns
boolean

Example

import { VerifyBlobKzgProofBatch } from '@tevm/voltaire/crypto/KZG'
import * as ckzg from 'c-kzg'

const verifyBlobKzgProofBatch = VerifyBlobKzgProofBatch({ verifyBlobKzgProofBatch: ckzg.verifyBlobKzgProofBatch })
const valid = verifyBlobKzgProofBatch(blobs, commitments, proofs)

VerifyKzgProof()

VerifyKzgProof(deps): (commitment, z, y, proof) => boolean
Defined in: src/crypto/KZG/verifyKzgProof.js:25 Factory: Verify KZG proof

Parameters

deps
Crypto dependencies
verifyKzgProof
(commitment, z, y, proof) => boolean c-kzg verifyKzgProof function

Returns

Function that verifies KZG proof
(commitment, z, y, proof): boolean
Parameters
commitment
Uint8Array
z
Uint8Array
y
Uint8Array
proof
Uint8Array
Returns
boolean

Example

import { VerifyKzgProof } from '@tevm/voltaire/crypto/KZG'
import * as ckzg from 'c-kzg'

const verifyKzgProof = VerifyKzgProof({ verifyKzgProof: ckzg.verifyKzgProof })
const valid = verifyKzgProof(commitment, z, y, proof)

References

InvalidFormatError

Re-exports InvalidFormatError

InvalidLengthError

Re-exports InvalidLengthError

KZG

Re-exports KZG