Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions packages/util/examples/blobs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
import { bytesToHex, computeVersionedHash, getBlobs } from '@ethereumjs/util'
import * as fs from 'fs'
import {
type PrefixedHexString,
blobsToCellProofs,
blobsToProofs,
computeVersionedHash,
getBlob,
getBlobs,
hexToBytes,
unprefixedHexToBytes,
} from '@ethereumjs/util'
import { trustedSetup } from '@paulmillr/trusted-setups/fast-peerdas.js'
import { KZG as microEthKZG } from 'micro-eth-signer/kzg.js'

const blobs = getBlobs('test input')
const kzg = new microEthKZG(trustedSetup)

console.log('Created the following blobs:')
console.log(blobs)
// Use with node ./examples/blobs.ts <file path>
const filePath = process.argv[2]
const blobData: PrefixedHexString = `0x${fs.readFileSync(filePath, 'ascii')}`
console.log(blobData)

const blobs = [blobData]

const commitment = kzg.blobToKzgCommitment(blobs[0])

const commitment = bytesToHex(new Uint8Array([1, 2, 3]))
const blobCommitmentVersion = 0x01
const versionedHash = computeVersionedHash(commitment, blobCommitmentVersion)
const versionedHash = computeVersionedHash(commitment as PrefixedHexString, blobCommitmentVersion)

// EIP-4844 only
const blobProof = blobsToProofs(kzg, blobs, [commitment as PrefixedHexString])
const cellProofs = blobsToCellProofs(kzg, blobs)

console.log(`Versioned hash ${versionedHash} computed`)
console.log(`Blob size : ${hexToBytes(blobData).length / 1024}KiB`)
console.log(`Commitment : ${commitment}`)
console.log(`Versioned hash : ${versionedHash}`)
console.log(`Blob proof (EIP-4844) : ${blobProof}`)
console.log(`First cell proof (EIP-7594) : ${cellProofs[0]}`)
console.log(`Num cell proofs (EIP-7594) : ${cellProofs.length}`)
2 changes: 1 addition & 1 deletion packages/util/src/blobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function getPadded(data: Uint8Array, blobs_len: number): Uint8Array {
* @param data Input data (must be exactly BLOB_SIZE bytes)
* @returns Hex-prefixed blob string
*/
function getBlob(data: Uint8Array): PrefixedHexString {
export function getBlob(data: Uint8Array): PrefixedHexString {
const blob = new Uint8Array(BLOB_SIZE)
for (let i = 0; i < FIELD_ELEMENTS_PER_BLOB; i++) {
const chunk = new Uint8Array(32)
Expand Down
Loading