mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
crypto/kzg4844: add helpers for versioned blob hashes (#28827)
This commit is contained in:
parent
824dea669c
commit
cae53aa7fd
1 changed files with 19 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ package kzg4844
|
|||
import (
|
||||
"embed"
|
||||
"errors"
|
||||
"hash"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
|
|
@ -108,3 +109,21 @@ func VerifyBlobProof(blob Blob, commitment Commitment, proof Proof) error {
|
|||
}
|
||||
return gokzgVerifyBlobProof(blob, commitment, proof)
|
||||
}
|
||||
|
||||
// CalcBlobHashV1 calculates the 'versioned blob hash' of a commitment.
|
||||
// The given hasher must be a sha256 hash instance, otherwise the result will be invalid!
|
||||
func CalcBlobHashV1(hasher hash.Hash, commit *Commitment) (vh [32]byte) {
|
||||
if hasher.Size() != 32 {
|
||||
panic("wrong hash size")
|
||||
}
|
||||
hasher.Reset()
|
||||
hasher.Write(commit[:])
|
||||
hasher.Sum(vh[:0])
|
||||
vh[0] = 0x01 // version
|
||||
return vh
|
||||
}
|
||||
|
||||
// IsValidVersionedHash checks that h is a structurally-valid versioned blob hash.
|
||||
func IsValidVersionedHash(h []byte) bool {
|
||||
return len(h) == 32 && h[0] == 0x01
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue