const MimeSVG, MimePNG, MimeWebP, MimeJPEG, MimeGIF
IANA media types CheckImage and ImageDims understand. GIF is parsed for completeness; callers decide which types they accept.
Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.
Package safe holds the pure checks and formulas every platform realm shares: text and SVG validation, basis-point mat...
Package safe holds the pure checks and formulas every platform realm shares: text and SVG validation, basis-point math, payee splits, merkle proofs, provenance hashes and the one JSON writer. Nothing here has state.
IANA media types CheckImage and ImageDims understand. GIF is parsed for completeness; callers decide which types they accept.
Media limits.
CID codecs.
AvgBlockMs is the measured mainnet average block time (RA §1: 200k blocks in 708,660 s). Use it only for UI estimates and defaults; every on-chain rule is stated in blocks.
BpsDenominator is 100% in basis points (EIP-2981, royalty/v0).
Domain separates every hash this platform commits to from hashes of the same bytes made for any other purpose. It equals the brand slug and changes with it (paths change anyway when the brand is chosen).
IPFSScheme prefixes an IPFS URI.
MaxMerkleDepth bounds a proof: 2^32 leaves is far beyond any allowlist.
MerkleNodeTag prefixes every inner node (SA-I2): an inner node hashes 0x01 || lo || hi, while a leaf is the hash of a text that starts with Domain ("art|al|v1|…"), so an inner node can never be presented as a leaf or the other way round.
AllowlistLeaf is the leaf for addr in collection cid's allowlist tree.
AssertBps panics unless 0 <= bps <= cap.
AssertHex checks that s is exactly nBytes of hex and returns it lowercased.
AssertNonEmptyText is AssertText that also refuses "".
AssertSVG checks an engine's raw SVG output with a strict allowlist (SA-M3; it replaced a substring blacklist that namespace prefixes, URL whitespace and CSS escapes could slip past). The document is tokenized as XML and must be well formed:
The frontend shows art only through <img>, which never runs scripts; this check is the defence in depth for every other place a data: URI ends up (wallets, explorers, indexers; RA M-7, design §5.4).
v2 (mainnet plan §2.1, M-2) accepts exactly the documents v1 accepts, except the J-4 rule above, and returns the same error texts, at ~3k instead of ~30k gas per byte: one table-driven pass proves ordinary tokens clean, and every token it cannot prove clean goes through v1's checks unchanged (checkAttr, checkChars), so the first error found is v1's; the J-4 checks (checkCSSValue) run on a value only after v1's checks passed it. UTF-8 validity is one native MatchCharsetN call for ASCII documents, and long d/points values are skipped with native probes. Proof: v1's tests, the differential corpus zz_svg_corpus_test.gno (v2 = the TypeScript twin; v1 = v2 except on J-4 documents, listed by case) and the gas filetests z_svg_gas_*.
AssertSymbol enforces the grc721 symbol alphabet ([A-Za-z0-9_-], 1..11 bytes) up front, so the error names the field instead of surfacing from grc721.NewToken.
AssertText panics with the field name when CheckText rejects s.
BlocksFor converts a duration to blocks, rounding up.
BpsOf returns floor(amount * bps / 10000) without ever forming the full product, so it cannot overflow for any amount >= 0 and 0 <= bps <= 10000.
CIDFromDigest is the inverse of ParseCIDv1. It panics on an unsupported codec or a digest that is not 64 lower-case hex characters.
CheckImage checks a complete file against its declared IANA type: an SVG must pass AssertSVG with MaxSVGImageBytes; a raster file must carry the type's magic bytes and header dimensions of 1..MaxDim per side (ImageDims). Nothing else of a raster file is parsed: raster bytes are only ever shown through <img> (SA-M3).
CheckText reports why s may not be stored as user-visible text.
Rejected: invalid UTF-8; C0 and C1 control characters, which include tab, newline and carriage return (the record-injection vector of RA H-1); DEL; U+2028/U+2029, which end a line in older JavaScript parsers (RA L-12); and every bidi control or zero-width character that lets one string render as another.
Commit is the value a creator ("creator") or the beacon ("beacon") commits to for collection cid on chain chainID.
FormatPayees is the inverse of ParsePayees.
ImageDims returns a raster file's pixel dimensions after checking its magic bytes and header (PNG IHDR, WebP VP8/VP8L/VP8X, JPEG SOFn, GIF logical screen) and the 1..MaxDim bound per side.
InitialEntropy seeds a collection's mint-entropy accumulator.
IsHex32 reports whether s is exactly 64 lower-case hex characters.
IsIPFSURI reports whether s is IPFSScheme followed by a CIDv1 that ParseCIDv1 accepts.
JSONString returns s as a quoted JSON string. Beyond the mandatory escapes it also escapes U+2028/U+2029 (RA L-12) and '<', '>', '&', so the output is safe to inline in HTML as well. Strings that need no escape (printable ASCII without '"', '\', '<', '>', '&') take a native fast path; the output is the same.
MerkleParent is hashPair on hex nodes, for tests and the off-chain builder.
MerkleVerify checks a sorted-pair sha256 proof ("hex,hex,…", leaf to root). An empty proof means the tree has a single leaf equal to the root. Malformed input is simply false: proofs come from untrusted callers.
MixEntropy folds one mint call into the accumulator. The inputs are public, but none existed when the secrets were committed, which is what stops a committer from choosing the map their own mints receive.
PadHex renders n in lowercase hex, zero-padded to width.
PadInt renders n with leading zeros to width digits, so decimal ids and prices sort correctly as avl keys. n must be >= 0.
ParseCIDv1 returns the codec (CodecRaw or CodecDagPB) and the sha2-256 digest as lower-case hex.
ParseID parses a positive decimal id ("1", "42"). Leading zeros, signs and empty strings are refused so every id has exactly one spelling.
ParsePayees parses "g1…:7000,g1…:3000": 1..max distinct valid addresses, each with a positive share, shares summing to exactly 10000.
Raw32 decodes exactly 64 lower-case hex characters into 32 raw bytes (one pass, table lookups).
Salt binds both secrets ("" when not revealed) to the final accumulator.
Seed is the per-token engine seed once the salt is final.
SplitByBps divides amount by the payees' shares. The rounding remainder goes to the first payee, so the parts always sum to exactly amount — the property every "no balance left behind" invariant (I-3, I-4) relies on.
XMLEscape makes s safe as SVG/XML character data or a quoted attribute.
JSONWriter is the single JSON producer of every read API (design §2.5: reads return primitives or JSON, never positional text). It tracks commas itself, so callers only describe structure:
Key starts an object member; the next value call writes its value.
Raw writes v verbatim. Only for JSON produced by another JSONWriter.
RawStr writes v as a JSON string without escaping. v may only hold [A-Za-z0-9+/=:;,._-] (base64, hex, decimal, a data: URI header), which JSON never escapes; any other byte panics. One native pass instead of a rune loop: a 350 KB data URI costs well under 1M gas (M-4, UP-I1).
RawStrField is Key + RawStr.
StrField and IntField are Key+value shorthands.