Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

commitreveal source pure

Package commitreveal provides a minimal commit-reveal primitive: commit to (salt, data) by publishing only their hash...

Overview

Package commitreveal provides a minimal commit-reveal primitive: commit to (salt, data) by publishing only their hash, then later reveal the actual salt and data for anyone to verify against the published commitment. This is the standard way to prevent front- running on gno.land -- e.g. sealed-bid auctions, commit-based voting, or any scheme where revealing intent early would let others react to it before the reveal phase.

This package holds no chain state and does not manage commit/reveal deadlines itself -- the importing realm stores the returned [32]byte commitment and decides its own phase timing (typically via chain/runtime.ChainHeight(), the same way gno.land/p/demo/ratelimit takes a caller-supplied block height instead of reading the chain itself).

Functions 2

func Commit

1func Commit(salt, data []byte) [32]byte
source

Commit produces the commitment hash for (salt, data). salt must be at least 16 bytes; data must be non-empty. Panics otherwise -- this is the "I'm constructing a real commitment" path, so invalid input here is a caller bug, not something to fail quietly on.

func Verify

1func Verify(commitHash [32]byte, salt, data []byte) bool
source

Verify checks whether (salt, data) reveals commitHash. Unlike Commit, this never panics -- a reveal attempt is untrusted input from whoever's revealing, and a malformed one (e.g. a short salt someone hand-crafted) should just fail verification, not abort the caller's whole transaction.

Imports 1

  • crypto/sha256 stdlib

Source Files 2