mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-12 15:38:18 -05:00
Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com> Co-authored-by: yiweichi <yiweichi@users.noreply.github.com>
24 lines
604 B
Go
24 lines
604 B
Go
package utils
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"fmt"
|
|
|
|
"github.com/scroll-tech/go-ethereum/crypto/kzg4844"
|
|
)
|
|
|
|
// CalculateVersionedBlobHash calculate the kzg4844 versioned blob hash from a blob
|
|
func CalculateVersionedBlobHash(blob kzg4844.Blob) ([32]byte, error) {
|
|
// calculate kzg4844 commitment from blob
|
|
commit, err := kzg4844.BlobToCommitment(&blob)
|
|
if err != nil {
|
|
return [32]byte{}, fmt.Errorf("failed to get blob commitment, err: %w", err)
|
|
}
|
|
|
|
// calculate kzg4844 versioned blob hash from blob commitment
|
|
hasher := sha256.New()
|
|
vh := kzg4844.CalcBlobHashV1(hasher, &commit)
|
|
|
|
return vh, nil
|
|
}
|