PathrockNetwork Gno Explorer
HomeBlocksTransactionsTokensRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/moul/agents/commit/v0

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v0
Namespace
moul / agents / commit
Files
4 (README)(gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/moul/agents/commit/v0
gno
0.9

Files (4)

  • README.mdmarkdown
  • gnomod.tomltoml
  • commit.gnogno
  • commit_test.gnogno
commit.gnogno
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}52

Functions

not supported for pure packages by the node (vm/qfuncs)

Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.