canonical

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package canonical provides the deterministic JSON representation used by Flow's durable identities. It implements the JSON Canonicalization Scheme from RFC 8785 over I-JSON-compatible values.

Index

Constants

View Source
const DefaultMaxDepth = 100

Variables

View Source
var (
	ErrInvalidJSON = errors.New("invalid JSON")
	ErrTooDeep     = errors.New("JSON nesting exceeds limit")
	ErrTooLarge    = errors.New("canonical JSON exceeds size limit")
)

Functions

func Decode

func Decode(data []byte, dst any) error

Decode decodes a canonical value into a typed destination.

func ValidateCanonical

func ValidateCanonical(raw []byte, maxBytes int) error

ValidateCanonical validates one complete JSON value and requires that its bytes already use Flow's canonical representation. It does not construct a second canonical byte slice.

Types

type Value

type Value struct {
	Bytes  []byte
	Digest [sha256.Size]byte
}

Value is an immutable-by-convention canonical byte sequence and its digest. Call BytesCopy when bytes escape the owning operation.

func Canonicalize

func Canonicalize(raw []byte, maxBytes int) (Value, error)

Canonicalize validates and canonicalizes one complete JSON value. A zero maxBytes disables the size bound.

func Marshal

func Marshal(v any, maxBytes int) (Value, error)

Marshal encodes a Go value, canonicalizes it, and computes its SHA-256 digest. A zero maxBytes disables the size bound.

func (Value) BytesCopy

func (v Value) BytesCopy() []byte

func (Value) DigestHex

func (v Value) DigestHex() string

func (Value) Equal

func (v Value) Equal(other Value) bool

Jump to

Keyboard shortcuts

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