Files

30 lines
804 B
Go
Raw Permalink Normal View History

2026-09-24 17:59:23 +03:00
// Code generated by apigen. DO NOT EDIT.
package abi
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
)
// DataHash is the canonical hash of a manifest primitives block. The generated data package bakes
// it in and an upload whose manifest does not match it is rejected, so a manifest edited without a
// regenerate never runs against stale generated types. Key order and whitespace do not matter.
// A module with no primitives hashes to the empty string.
func DataHash(primitives json.RawMessage) string {
var decoded any
if err := json.Unmarshal(primitives, &decoded); err != nil || decoded == nil {
return ""
}
encoded, err := json.Marshal(decoded)
if err != nil || string(encoded) == "{}" {
return ""
}
sum := sha256.Sum256(encoded)
return hex.EncodeToString(sum[:])
}