commitmentToVersionedHash
Transforms a KZG commitment to its versioned hash
Loading...
Transforms a KZG commitment to its versioned hash
Transforms a KZG commitment to its versioned hash. The versioned hash is SHA256(commitment) with the first byte replaced by the version.
import "github.com/ChefBingbong/viem-go/utils/blob"import "github.com/ChefBingbong/viem-go/utils/kzg"import "github.com/ChefBingbong/viem-go/utils/blob"import "github.com/ChefBingbong/viem-go/utils/kzg"
commitment, _ := kzgImpl.BlobToKzgCommitment(blob)
// Transform commitment to versioned hashversionedHash := blob.CommitmentToVersionedHash(commitment, kzg.VersionedHashVersionKzg)// []byte{0x01, ...} (32 bytes)
// Use default KZG versionversionedHash = blob.CommitmentToVersionedHashDefault(commitment)// []byte{0x01, ...} (32 bytes)
// Get as hex stringhexHash := blob.CommitmentToVersionedHashHex(commitment, kzg.VersionedHashVersionKzg)// "0x01..."[]byte for CommitmentToVersionedHash, string for CommitmentToVersionedHashHexThe versioned hash. It's a 32-byte value where the first byte is the version and the remaining 31 bytes are from SHA256(commitment).
[]byte for CommitmentToVersionedHash, string for CommitmentHexToVersionedHashThe KZG commitment to transform. Must be 48 bytes.
commitment, _ := kzgImpl.BlobToKzgCommitment(blob)versionedHash := blob.CommitmentToVersionedHash(commitment, kzg.VersionedHashVersionKzg)byteThe version byte to use. For KZG commitments, use kzg.VersionedHashVersionKzg (0x01).
versionedHash := blob.CommitmentToVersionedHash(commitment, kzg.VersionedHashVersionKzg)Transforms a commitment to a versioned hash:
versionedHash := blob.CommitmentToVersionedHash(commitment, kzg.VersionedHashVersionKzg)
Transforms a commitment using the default KZG version:
versionedHash := blob.CommitmentToVersionedHashDefault(commitment)
Transforms a commitment and returns a hex string:
hexHash := blob.CommitmentToVersionedHashHex(commitment, kzg.VersionedHashVersionKzg)
Transforms a hex commitment to a versioned hash:
versionedHash, _ := blob.CommitmentHexToVersionedHash(hexCommitment, kzg.VersionedHashVersionKzg)
Transforms a hex commitment and returns a hex versioned hash:
hexHash, _ := blob.CommitmentHexToVersionedHashHex(hexCommitment, kzg.VersionedHashVersionKzg)
The versioned hash is computed as: