Documentation Index
Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
Use this file to discover all available pages before exploring further.
Try it Live
Run Blob examples in the interactive playground
Validation Rules
A valid versioned hash must:
- Be exactly 32 bytes
- Have version byte 0x01 (KZG commitment version)
import { Blob } from 'tevm';
function isValidVersionedHash(hash: Uint8Array): boolean {
// Check length
if (hash.length !== 32) {
return false;
}
// Check version byte
if (hash[0] !== 0x01) {
return false;
}
return true;
}
// Equivalent to Blob.isValidVersion()
Version Byte
Current supported version:
import { Blob } from 'tevm';
console.log(Blob.COMMITMENT_VERSION_KZG); // 0x01
const hash = blob.toVersionedHash();
console.log(hash[0]); // 0x01
// Future versions (not yet supported)
// 0x02 = Future commitment scheme
// 0x03 = Another scheme
VersionedHash Utilities
import { Blob } from 'tevm';
const versionedHash = blob.toVersionedHash();
// Validate format
console.log(Blob.isValidVersion(versionedHash)); // true
// Check specific validation using VersionedHash namespace
console.log(Blob.VersionedHash.isValid(versionedHash)); // true
// Get version byte
const version = Blob.VersionedHash.getVersion(versionedHash);
console.log(version); // 1
// Alternative: version() method
console.log(Blob.VersionedHash.version(versionedHash)); // 1
Transaction Validation
import { Blob } from 'tevm';
function validateBlobVersionedHashes(
hashes: Uint8Array[],
maxBlobs: number = Blob.MAX_PER_TRANSACTION
): boolean {
// Check count
if (hashes.length === 0 || hashes.length > maxBlobs) {
return false;
}
// Validate each hash
for (const hash of hashes) {
if (!Blob.isValidVersion(hash)) {
return false;
}
}
return true;
}
// Usage
const tx = { blobVersionedHashes: [hash1, hash2, hash3] };
if (!validateBlobVersionedHashes(tx.blobVersionedHashes)) {
throw new Error('Invalid versioned hashes');
}
Error Cases
import { Blob } from 'tevm';
// Wrong length
const tooShort = Bytes16();
console.log(Blob.isValidVersion(tooShort)); // false
const tooLong = Bytes64();
console.log(Blob.isValidVersion(tooLong)); // false
// Wrong version
const wrongVersion = Bytes32();
wrongVersion[0] = 0x02; // Unsupported
console.log(Blob.isValidVersion(wrongVersion)); // false
wrongVersion[0] = 0x00; // Invalid
console.log(Blob.isValidVersion(wrongVersion)); // false
// Correct
const correct = Bytes32();
correct[0] = 0x01; // KZG version
console.log(Blob.isValidVersion(correct)); // true
See Also