1// Package commit provides small, deterministic commitment helpers shared by2// the agent demos. On-chain realms store *commitments* to off-chain data3// (reports, patches, verdicts) rather than the data itself; this package is4// the one place that defines how those commitments are computed, so several5// realms agree on the scheme.6package commit78import (9 "crypto/sha256"10 "encoding/hex"11)1213// Hash returns the hex-encoded SHA-256 over its parts, length-prefixed so14// that Hash("ab","c") != Hash("a","bc"). Use it to commit to structured15// off-chain material without revealing it.16func Hash(parts ...string) string {17 var buf []byte18 for _, p := range parts {19 buf = appendUvarint(buf, uint64(len(p)))20 buf = append(buf, p...)21 }22 sum := sha256.Sum256(buf)23 return hex.EncodeToString(sum[:])24}2526// Verdict is the canonical commitment used by commit-reveal voting: a hidden27// boolean plus a salt. Reveal the same (verdict, salt) later and any observer28// can recompute this and confirm the vote was not changed after the fact.29func Verdict(verdict bool, salt string) string {30 v := "no"31 if verdict {32 v = "yes"33 }34 return Hash("verdict", v, salt)35}3637// Short abbreviates a hex commitment for display.38func Short(h string) string {39 if len(h) <= 12 {40 return h41 }42 return h[:6] + "…" + h[len(h)-4:]43}4445func appendUvarint(buf []byte, x uint64) []byte {46 for x >= 0x80 {47 buf = append(buf, byte(x)|0x80)48 x >>= 749 }50 return append(buf, byte(x))51}52Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.