Documentation
¶
Overview ¶
Package entviz renders high-entropy values as comparable SVG fingerprints. It is a Go port of the certified reference implementation; see https://github.com/dhh1128/entviz for the spec.
The deterministic shared core lives here: alphabets, tokenization + 24-bit quant extension, the SHA-512 fingerprint, ftok median/quartile selection, the Oklab color rules + weighted-RGB edge selection, and grid selection. The format-specific parsers live in entropy.go and the SVG renderer in pipeline.go.
Index ¶
- Constants
- Variables
- func ClosestPaletteColor(target string, palette []string) string
- func ComputeFingerprint(core string) [64]byte
- func NucleusColors(quant uint32) (string, string)
- func OklabLightness(r, g, b uint8) float64
- func Render(entropyText string, targetAR, fontSizePt float64, note *string) (string, error)
- func SecondDigest(core string) [64]byte
- func WeightedRGBDistance(c1, c2 string) float64
- type Alphabet
- type Characterization
- type ChecksumError
- type Eip55Error
- type Grid
- type OrderedMap
- type Parsed
- type Part
- type RenderError
- type Token
- type VisualStyle
Constants ¶
const LibVersion = "0.15.1"
LibVersion is this Go module's own version stamp. It is per-impl and is not compared by the conformance checker (only data-entviz-version is).
const (
MARGIN = 1.0
)
const SpecVersion = "v15"
SpecVersion is the entviz spec level this library implements.
Variables ¶
var ( HEX = Alphabet{ Name: "hex", Chars: "0123456789ABCDEF", BitsPerChar: 4, } BASE64URL = Alphabet{ Name: "base64url", Chars: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", BitsPerChar: 6, } BASE58 = Alphabet{ Name: "base58", Chars: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", BitsPerChar: 6, } BASE64 = Alphabet{ Name: "base64", Chars: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", BitsPerChar: 6, } BASE32 = Alphabet{ Name: "base32", Chars: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", BitsPerChar: 5, } BECH32 = Alphabet{ Name: "bech32", Chars: "qpzry9x8gf2tvdw0s3jn54khce6mua7l", BitsPerChar: 5, } CROCKFORD32 = Alphabet{ Name: "crockford32", Chars: "0123456789ABCDEFGHJKMNPQRSTVWXYZ", BitsPerChar: 5, } BASE36 = Alphabet{ Name: "base36", Chars: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", BitsPerChar: 6, } DECIMAL = Alphabet{ Name: "decimal", Chars: "0123456789", BitsPerChar: 4, } )
Canonical alphabet constants used across the core and parsers.
var MiddleDomainTag = []byte("entviz/fingerprint-middle/v6\x00")
MiddleDomainTag is the frozen domain-separation constant for the second digest. The trailing NUL is included; the v6 here is the *construction* version (frozen), NOT the spec version — see the spec's large-input section.
var PossibleEdgeColors = [5]string{"#ffffff", "#e7be00", "#ff3f2f", "#2f3fbf", "#000000"}
PossibleEdgeColors is the fixed palette; indices 0-3 are background candidates, black (index 4) is always an edge color.
Functions ¶
func ClosestPaletteColor ¶
ClosestPaletteColor returns the palette entry with minimum weighted distance.
func ComputeFingerprint ¶
ComputeFingerprint returns the SHA-512 digest of the core text bytes.
func NucleusColors ¶
NucleusColors returns (bgHex, fgHex). Red is the low byte of the quant.
func OklabLightness ¶
OklabLightness returns the Oklab L of an sRGB color.
func SecondDigest ¶
SecondDigest returns SHA-512(MiddleDomainTag ‖ core). Computed for every input: it drives the two color-bar markers (and the middle cells on large inputs).
func WeightedRGBDistance ¶
WeightedRGBDistance is the spec's cheap CIELAB ΔE stand-in for edge selection.
Types ¶
type Characterization ¶ added in v0.15.1
type Characterization struct {
Encoding string
Scheme *string
Role *string
Qualifiers *OrderedMap
SizeBasis string
SizeBits int
Parts []Part
EntropyType string
}
Characterization is the 8-field structured entropy characterization. Scheme and Role use pointers so a nil pointer serializes to the empty string (data-scheme/data-role) and JSON null semantics; every other field is always present.
func Characterize ¶ added in v0.15.1
func Characterize(entropy string) (*Characterization, error)
Characterize characterizes an entropy string into the structured model. Never errors for an in-range input: an unrecognized input falls back to the UTF-8 -> base64url path (scheme=nil, role=nil, size_basis="utf8", size measured over the ORIGINAL input bytes). A hard parse rejection (EIP-55) is surfaced via the error, matching Parse.
func (*Characterization) PartsJSON ¶ added in v0.15.1
func (c *Characterization) PartsJSON() string
PartsJSON returns the compact JSON array for data-parts, no spaces: [{"text":"...","bind":"core"}]. Insertion order matches reading order.
func (*Characterization) QualifiersJSON ¶ added in v0.15.1
func (c *Characterization) QualifiersJSON() string
QualifiersJSON returns the compact JSON object for data-qualifiers, keys in insertion order, no spaces: {"algorithm":"Blake3-256"}. Empty map -> {}.
func (*Characterization) RenderLabel ¶ added in v0.15.1
func (c *Characterization) RenderLabel(truncated bool, suffix, note string, lineChars int) (string, string)
RenderLabel projects the characterization into the (top, bottom) label strips. Pure function of the eight fields plus presentation facts the fields don't carry: whether the input was >512-bit truncated, the bound suffix checksum, the out-of-band user note, and the monospace lineChars budget the grid leaves for the top strip (used only to truncate the elastic prefix slot; lineChars < 0 = do not truncate).
top = [+hash ]PRIMARY[, MOD]...[, SIZE][, PREFIX] (", " joined, no trailing ':'). bottom = ...<suffix> then " (<note>)", "" when neither present.
func (*Characterization) RoleAttr ¶ added in v0.15.1
func (c *Characterization) RoleAttr() string
func (*Characterization) SchemeAttr ¶ added in v0.15.1
func (c *Characterization) SchemeAttr() string
SchemeAttr / RoleAttr return the empty string for a nil scheme/role.
type ChecksumError ¶ added in v0.15.1
type ChecksumError struct {
Kind string // e.g. "Bitcoin legacy", "bech32", "Bitcoin Cash", "LEI"
Address string
}
ChecksumError is a hard rejection: a structure that clearly matches a scheme (right prefix / length / reserved bytes) but whose bound checksum — surfaced in the label — does not verify. Covers base58check (BTC/LTC legacy), bech32 (BTC segwit, LTC, generic cosmos), CashAddr (BCH), and LEI MOD 97-10. A bound checksum is shown, so it must be verified; a mismatch rejects rather than rendering an invalid address. Mirrors Base58CheckError / Bech32ChecksumError / LEIChecksumError in src/entviz/entropy.py.
func (*ChecksumError) Error ¶ added in v0.15.1
func (e *ChecksumError) Error() string
type Eip55Error ¶
type Eip55Error struct {
Position int
}
Eip55Error is a hard rejection: an EIP-55 mixed-case checksum mismatch. The Position is the 0-based index (within the 40-hex body) of the first digit whose case disagrees with the canonical case.
func (*Eip55Error) Error ¶
func (e *Eip55Error) Error() string
type Grid ¶
Grid is the chosen layout.
func ChooseGrid ¶
ChooseGrid selects the layout whose aspect ratio is closest to (but not below) the target, with at least 2 columns and 2 rows.
type OrderedMap ¶ added in v0.15.1
type OrderedMap struct {
// contains filtered or unexported fields
}
OrderedMap is a small string->value map that preserves insertion order, so the emitted data-qualifiers JSON matches the reference insertion order. Values are either string or int (the CID version qualifier is numeric).
func (*OrderedMap) Get ¶ added in v0.15.1
func (m *OrderedMap) Get(k string) any
Get returns the value for a key.
func (*OrderedMap) Keys ¶ added in v0.15.1
func (m *OrderedMap) Keys() []string
Keys returns the insertion-ordered keys.
type Parsed ¶
type Parsed struct {
TypeName string
Alphabet Alphabet
Prefix *string
Core string
Suffix *string
PrefixSemantic bool
}
Parsed is a recognized entropy classification.
type RenderError ¶
type RenderError struct {
Kind string // "note" | "input-too-long" | "font-size" | "aspect-ratio" | "no-tokens" | "eip55"
Message string
Position int // for eip55
}
RenderError represents a render rejection. Kind discriminates the reason.
func (*RenderError) Error ¶
func (e *RenderError) Error() string
type Token ¶
Token is one rendered chunk of entropy (or one ftok of a fingerprint).
func MedianToken ¶
MedianToken returns the lower-middle token of the ASCII text-sorted list.
func QuartileTokens ¶
QuartileTokens returns the first token of each of the four mirror-sorted quartiles; a slot is absent (ok=false) when it would fall in padding.
func Tokenize ¶
Tokenize splits text into 24-bit tokens under the given alphabet, extending short trailing chunks to a full 24-bit quant by the bit-repeat rule.
func TokenizeEntropy ¶
TokenizeEntropy tokenizes entropy with head/middle/tail large-input handling. It returns (tokens, truncated).
func TokenizeFingerprint ¶
TokenizeFingerprint serializes the 64-byte digest to base64url and splits it into the 22 ftoks the spec guarantees.
type VisualStyle ¶
VisualStyle is the entviz background plus the 4-entry edge palette.
func SelectVisualStyle ¶
func SelectVisualStyle(medianFtok Token) VisualStyle
SelectVisualStyle picks the background from the median ftok's low 2 bits and forms the edge palette from the remaining four colors.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
entviz-conformance
command
Command entviz-conformance is the conformance CLI: read one vector's JSON on stdin, write the entviz SVG to stdout (exit 0), or exit non-zero to reject (the contract in the entviz repo's compliance/README.md).
|
Command entviz-conformance is the conformance CLI: read one vector's JSON on stdin, write the entviz SVG to stdout (exit 0), or exit non-zero to reject (the contract in the entviz repo's compliance/README.md). |