|
1 | | -import { bytesToHex, computeVersionedHash, getBlobs } from '@ethereumjs/util' |
| 1 | +//import * as fs from 'fs' |
| 2 | +import { |
| 3 | + type PrefixedHexString, |
| 4 | + blobsToCellProofs, |
| 5 | + blobsToProofs, |
| 6 | + computeVersionedHash, |
| 7 | + hexToBytes, |
| 8 | +} from '@ethereumjs/util' |
| 9 | +import { trustedSetup } from '@paulmillr/trusted-setups/fast-peerdas.js' |
| 10 | +import { KZG as microEthKZG } from 'micro-eth-signer/kzg.js' |
2 | 11 |
|
3 | | -const blobs = getBlobs('test input') |
| 12 | +const kzg = new microEthKZG(trustedSetup) |
4 | 13 |
|
5 | | -console.log('Created the following blobs:') |
6 | | -console.log(blobs) |
| 14 | +/** |
| 15 | + * Uncomment for a more realistic example using a real blob, e.g. from https://blobscan.com/ |
| 16 | + * Use with node ./examples/blobs.ts <file path> |
| 17 | + */ |
| 18 | +// const filePath = process.argv[2] |
| 19 | +//const blob: PrefixedHexString = `0x${fs.readFileSync(filePath, 'ascii')}` |
| 20 | +const blob: PrefixedHexString = `0x${'11'.repeat(131072)}` // 128 KiB |
| 21 | +console.log(blob) |
| 22 | + |
| 23 | +const commitment = kzg.blobToKzgCommitment(blob) |
7 | 24 |
|
8 | | -const commitment = bytesToHex(new Uint8Array([1, 2, 3])) |
9 | 25 | const blobCommitmentVersion = 0x01 |
10 | | -const versionedHash = computeVersionedHash(commitment, blobCommitmentVersion) |
| 26 | +const versionedHash = computeVersionedHash(commitment as PrefixedHexString, blobCommitmentVersion) |
| 27 | + |
| 28 | +// EIP-4844 only |
| 29 | +const blobProof = blobsToProofs(kzg, [blob], [commitment as PrefixedHexString]) |
| 30 | +const cellProofs = blobsToCellProofs(kzg, [blob]) |
11 | 31 |
|
12 | | -console.log(`Versioned hash ${versionedHash} computed`) |
| 32 | +console.log(`Blob size : ${hexToBytes(blob).length / 1024}KiB`) |
| 33 | +console.log(`Commitment : ${commitment}`) |
| 34 | +console.log(`Versioned hash : ${versionedHash}`) |
| 35 | +console.log(`Blob proof (EIP-4844) : ${blobProof}`) |
| 36 | +console.log(`First cell proof (EIP-7594) : ${cellProofs[0]}`) |
| 37 | +console.log(`Num cell proofs (EIP-7594) : ${cellProofs.length}`) |
0 commit comments