Skip to content

Blobs.commitmentToVersionedHash

Transform a Commitment to its Blob Versioned Hash.

Imports

Named
import { Blobs } from 'ox'

Examples

import { Blobs } from 'ox'
import { kzg } from './kzg'
 
const blobs = Blobs.from('0xdeadbeef')
const [commitment] = Blobs.toCommitments(blobs, { kzg })
const versionedHash = Blobs.commitmentToVersionedHash(commitment)

Configuring Return Type

It is possible to configure the return type for the Versioned Hash with the as option.

import { Blobs } from 'viem'
import { kzg } from './kzg'
 
const blobs = Blobs.from('0xdeadbeef')
const [commitment] = Blobs.toCommitments(blobs, { kzg })
const versionedHashes = Blobs.commitmentToVersionedHash(commitment, {
  as: 'Bytes', 
})
[Uint8Array [ ... ], Uint8Array [ ... ]]

Versioning Hashes

It is possible to configure the version for the Versioned Hash with the version option.

import { Blobs } from 'viem'
import { kzg } from './kzg'
 
const blobs = Blobs.from('0xdeadbeef')
const [commitment] = Blobs.toCommitments(blobs, { kzg })
const versionedHashes = Blobs.commitmentToVersionedHash(commitment, {
  version: 2, 
})

Definition

function commitmentToVersionedHash<commitment, as>(
  commitment: commitment | Hex.Hex | Bytes.Bytes,
  options?: commitmentToVersionedHash.Options<as>,
): commitmentToVersionedHash.ReturnType<as>

Source: src/Blobs.ts

Parameters

commitment

  • Type: commitment | Hex.Hex | Bytes.Bytes

The commitment.

options

  • Type: commitmentToVersionedHash.Options<as>
  • Optional

Options.

options.as

  • Type: "Bytes" | "Hex" | as
  • Optional

Return type.

options.version

  • Type: number
  • Optional

Version to tag onto the hash.

Return Type

The Blob Versioned Hash.

commitmentToVersionedHash.ReturnType<as>