Skip to content
Merged
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
39 changes: 32 additions & 7 deletions packages/util/examples/blobs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
import { bytesToHex, computeVersionedHash, getBlobs } from '@ethereumjs/util'
//import * as fs from 'fs'
import {
type PrefixedHexString,
blobsToCellProofs,
blobsToProofs,
computeVersionedHash,
hexToBytes,
} 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)
/**
* Uncomment for a more realistic example using a real blob, e.g. from https://blobscan.com/
* Use with node ./examples/blobs.ts <file path>
*/
// const filePath = process.argv[2]
//const blob: PrefixedHexString = `0x${fs.readFileSync(filePath, 'ascii')}`
const blob: PrefixedHexString = `0x${'11'.repeat(131072)}` // 128 KiB
console.log(blob)

const commitment = kzg.blobToKzgCommitment(blob)

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, [blob], [commitment as PrefixedHexString])
const cellProofs = blobsToCellProofs(kzg, [blob])

console.log(`Versioned hash ${versionedHash} computed`)
console.log(`Blob size : ${hexToBytes(blob).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