canon

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package canon defines the language-neutral canonical serialization for the event log's tamper-evident hash-chain. content_hash is defined over RFC 8785 (JCS) applied to the proto3-JSON mapping of the event, so ANY implementation — not only this Go host — can recompute and independently verify the chain. That independent verifiability is the "provenance anyone can audit" property: an auditor does not have to trust the binary that wrote the journal. See the determinism contract §7.

content_hash = lc-hex( SHA-256( JCS({
    "event":     proto3-JSON(Event),
    "prev_hash": <hex>,
    "seq":       <int64-as-string>,
}) ) )

proto3-JSON maps int64→string, bytes→base64, enum→name; JCS then sorts keys and canonicalizes numbers/strings/whitespace. Because the event is serialized via proto3-JSON, structured content maps must be JSON-shaped (no int64 > 2^53) — see package wire.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Event

func Event(ev api.Event) ([]byte, error)

Event returns the canonical bytes of a single event: JCS applied to its proto3-JSON form. Useful anywhere a stable, cross-implementation event fingerprint is needed (e.g. a model input hash).

func HashRecord

func HashRecord(prevHash string, seq int64, ev api.Event) (string, error)

HashRecord is content_hash: lowercase-hex SHA-256 over the canonical record bytes. At a fork, a child's first record uses prev_hash = parent@R.content_hash, turning the chain into a tree.

func Proto

func Proto(m proto.Message) ([]byte, error)

Proto returns the canonical bytes of any message: JCS applied to its proto3-JSON form under the same pinned options the journal uses. A digest over these bytes can be recomputed by any implementation, which is why the harness registry's spec_digest is defined over them.

func Record

func Record(prevHash string, seq int64, ev api.Event) ([]byte, error)

Record returns the canonical bytes that content_hash is computed over: the event plus the chain envelope (prev_hash, seq), canonicalized as one JCS object. seq is encoded as a string (proto3-JSON's int64 convention) so it is exact regardless of a consumer's JSON number type.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL