Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v1 source pure

Package katman is the composition logic of Katman, Sinopia's open PFP tool engine: an artist uploads trait layers (SV...

Overview

Package katman is the composition logic of Katman, Sinopia's open PFP tool engine: an artist uploads trait layers (SVG parts with rarity weights) to a sealed assets/v1 store, and every revealed token is one part per layer, drawn from the token's final seed by weight and stacked bottom-up into one SVG. Parts may paint with currentColor; the collection's palette then gives every layer its own ink, shuffled per token, over a paper backdrop.

This package is pure: it never reads a store. The adapter realm (r/…/sinopia/engines/katman) reads the drawn parts from assets/v1 and hands their bytes to ComposeParts. The demo kit in demo.gno (params store 0) is the engine's own sample: the jug characters of the engine gallery, redrawn. frontend/src/engines/katman.ts is a byte-identical TypeScript twin; katman_test.gno and katman.test.ts pin the same golden vectors.

Why composition can never break the SVG allowlist: every part is a whole document that passed safe.AssertSVG when its last byte was stored (assets/v1 AppendBytes → media.CheckImage). Its root tag is exactly Root(w, h) and the document ends with the closing tag of that root (AssertSVG refuses content after the root), so the bytes between them are a balanced run of allowlisted elements, attributes and text. ComposeParts only concatenates such runs inside <g> elements under one Root(w, h); every rule of the allowlist is local to an element, an attribute value or a text run, so the result passes too. Core re-checks every render anyway.

Pure integer maths: no floats, no time, no block data.

Constants 4

const MaxLayers, MaxPartsPerLayer, MaxParts, MaxKitBytes, MaxSVGBytes, MaxCanvas, MaxStore, DemoCanvas

 1const (
 2	MaxLayers        = 8      // = assets/v1 MaxTraitTypes = MaxTiers; trait types
 3	MaxPartsPerLayer = 64     // parts of one layer
 4	MaxParts         = 128    // parts of a kit
 5	MaxKitBytes      = 262144 // on-chain bytes of a kit (sum of part files)
 6	MaxSVGBytes      = 28672  // worst composed token (Manifest.MaxSVGBytes)
 7	MaxCanvas        = 4096   // viewBox width and height, 1..MaxCanvas
 8	MaxStore         = 999999999
 9	DemoCanvas       = 400
10)
source

Kit limits (the adapter enforces them on a store at CreateCollection).

const DefaultParams

1const DefaultParams = `{"store":0,"palette":"Terracotta"}`
source

DefaultParams is the canonical form of the defaults; it renders exactly like "".

const PaletteKit

1const PaletteKit = 7
source

PaletteKit is the index of "Kit Colours": no paper, no layer inks.

const ParamsSchema

1const ParamsSchema = `{"type":"object","properties":{` +
2	`"store":{"type":"integer","title":"Part store (0 = demo kit)","minimum":0,"maximum":999999999,"default":0},` +
3	`"palette":{"type":"string","title":"Palette","enum":["Terracotta","Riso","Iznik","Sea Glass","Dusk",` +
4	`"Sinopia","Mono","Kit Colours"],"default":"Terracotta"}}}`
source

ParamsSchema is the Studio form. Studio sends JSON.stringify of the values in this property order; ValidateParams accepts exactly that or "".

Functions 19

func ComposeParts

1func ComposeParts(seed string, pal int, parts []string) string
source

ComposeParts is a store kit's token: parts[k] is the whole file of the part drawn for layer k (bottom first). The canvas is the first part whose root parses; a part with another root, or no file (""), leaves its layer empty, so an unchecked kit still composes a valid document (a checked kit never has such a part: the adapter refuses it at CreateCollection).

func DemoLayerNames

1func DemoLayerNames() []string
source

DemoLayerNames are the demo kit's layers: its trait types.

func DemoTraits

1func DemoTraits(seed string) []engine.Trait
source

DemoTraits are the demo kit's part names for seed, in layer order.

func Draw

1func Draw(seed string, totals []int64) []int64
source

Draw returns, per layer, a point in 0..totals[k]-1: the token's position on that layer's weight line (the sum of its parts' weights). Part i of a layer covers [w_0+…+w_{i-1}, w_0+…+w_i): exactly the slot ranges assets/v1 gives editions, so the adapter maps the point to a part with assets.SlotArtwork. One draw per layer, also for an empty layer (0).

func Inks

1func Inks(seed string, pal, n int) []string
source

Inks is the ink of each of n layers under palette pal for seed: the palette's eight inks shuffled per token (Fisher-Yates), layer k taking the (k mod 8)-th. nil for Kit Colours.

func Inner

1func Inner(svg, root string) (string, bool)
source

Inner is a part's content between its root tag and its final </svg>, or ok false when the part does not start with root or end with </svg>.

func Manifest

1func Manifest() engine.Manifest
source

Manifest describes the engine. Author and FeeBps are set by the adapter.

func PaletteName

1func PaletteName(i int) string
source

PaletteName is the palette's enum value.

func ParseRoot

1func ParseRoot(svg string) (root string, w, h int, ok bool)
source

ParseRoot reads a part's root tag: exactly Root(w, h) with canonical decimals 1..MaxCanvas. ok is false for anything else.

func Pick

1func Pick(seed string, weights [][]int64) []int
source

Pick maps Draw onto explicit weight lists: the index of the drawn part of every layer (the walk the TS twin and the demo kit use).

func Render

1func Render(in engine.Input) string
source

Render is the demo kit's art (params store 0). Store kits are composed by the adapter (ComposeParts); asking this package for one panics.

func Root

1func Root(w, h int) string
source

Root is the one root tag every part of a w x h kit starts with, and the root of every composed token.

func SVG

1func SVG(seed string, pal int) string
source

SVG is the demo kit's token for seed under palette pal.

func Traits

1func Traits(in engine.Input) []engine.Trait
source

Traits are the demo kit's traits (params store 0): one per layer.

func ValidateParams

1func ValidateParams(params string) error
source

ValidateParams accepts "" (the demo kit) and the canonical JSON. Whether a store kit is usable is the adapter's call (it reads the store).

func WorstBytes

1func WorstBytes(root string, w, h, pal int, maxInner []int) int
source

WorstBytes is the largest token a kit can compose under palette pal: maxInner[k] is the largest inner part of layer k (0 = all empty).

func Defaults

1func Defaults() Config
source

Defaults is params "": the demo kit in Terracotta.

func MustConfig

1func MustConfig(params string) Config
source

MustConfig is ParseParams for params core already validated.

func ParseParams

1func ParseParams(params string) (Config, error)
source

ParseParams accepts "" or the canonical JSON Studio produces, nothing else.

Types 1

type Config

struct
1type Config struct {
2	Store   int64 // assets/v1 store id; 0 = the demo kit
3	Palette int   // index into the palettes; PaletteKit = the kit's own colours
4}
source

Config is a parsed params string.

Dependencies

Source Files 3