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 media is the pure half of Sinopia's uploaded collections (docs/uploaded-collections.md §5.1, §0a): media kind...

Overview

Package media is the pure half of Sinopia's uploaded collections (docs/uploaded-collections.md §5.1, §0a): media kinds and types, the CIDv1 grammar the platform accepts, image header checks, and the salt-keyed permutation that assigns tokens to artworks. It has no state; the asset store (r/…/assets/v1), the upload engine (r/…/engines/upload) and the frontend (chain/cid.ts, chain/perm.ts) share these definitions, pinned by the golden vectors in docs/test-vectors/upload-v1.json.

Constants 5

const KindChain, KindIPFSRaw, KindIPFSUnixFS

1const (
2	KindChain      = 1 // bytes stored in assets/v1
3	KindIPFSRaw    = 2 // raw-leaf CIDv1: the CID's digest is the file's sha256 (checked on chain)
4	KindIPFSUnixFS = 3 // dag-pb CIDv1: digest of the root node, file sha256 stored separately
5)
source

Storage kinds of one artwork.

const MaxDim, MaxSVGBytes, MaxRasterBytes, MaxIPFSRaw, MaxIPFSUnixFS

1const (
2	MaxDim         = 4096     // px per side, decompression-bomb guard
3	MaxSVGBytes    = 16384    // on-chain SVG: AssertSVG costs ~30-50k gas/B (WP0)
4	MaxRasterBytes = 262144   // on-chain png/webp/jpeg per artwork
5	MaxIPFSRaw     = 1 << 20  // single raw block
6	MaxIPFSUnixFS  = 50 << 20 // declared; the frontend enforces it while streaming
7)
source

Limits (decision D4 and design §4).

const PermDomain

1const PermDomain = "art|upload|perm|v1|"
source

PermDomain separates the permutation key from every other platform hash (under safe.Domain "art").

Functions 14

func Badge

1func Badge(onchainN, ipfsN int64) string
source

Badge is a store's storage badge from its counters (design §9): "onchain", "ipfs", "mixed", or "empty" for a store without artworks.

func CIDFromDigest

1func CIDFromDigest(codec int, digestHex string) string
source

CIDFromDigest is the inverse of ParseCIDv1. It panics on an unsupported codec or a digest that is not 64 lower-case hex characters.

func CheckImage

1func CheckImage(mime int, data string) (w, h int, err error)
source

CheckImage checks a complete file against its declared type: the magic bytes and the header's pixel dimensions (each 1..MaxDim, the decompression-bomb guard). SVG has no header dimensions (w, h = 0) and must pass safe.AssertSVG with the on-chain cap MaxSVGBytes (§0a), the same allowlist core applies to every render. Nothing else of a raster file is parsed: raster bytes are only ever shown through <img> (SA-M3).

func IsHex32

1func IsHex32(s string) bool
source

IsHex32 reports whether s is exactly 64 lower-case hex characters.

func KindName

1func KindName(k int) string
source

KindName is "chain" or "ipfs".

func MaxBytes

1func MaxBytes(kind, mime int) int64
source

MaxBytes is the size cap of one artwork of this kind and type.

func MimeName

1func MimeName(m int) string
source

MimeName is the short name ParseMime accepts ("svg", "png", …).

func MimeType

1func MimeType(m int) string
source

MimeType is the IANA type of a media constant ("" for an unknown one).

func ParseCIDv1

1func ParseCIDv1(s string) (codec int, digestHex string, err error)
source

ParseCIDv1 returns the codec (CodecRaw or CodecDagPB) and the sha2-256 digest as lower-case hex.

func ParseMime

1func ParseMime(s string) int
source

ParseMime maps "svg" | "png" | "webp" | "jpeg" to its constant and panics on anything else, "gif" included (D5).

func PermKey

1func PermKey(cid, salt string) string
source

PermKey is the permutation key of collection cid with its final salt.

func Permute

1func Permute(keyHex string, n, x int64) int64
source

Permute is a bijection on [0, n): a 4-round Feistel network over b bits (b = bitlen(n-1) rounded up to an even number ≥ 2, so 2^b < 4n) with cycle walking. Round function: F = big-endian uint64 of the first 8 bytes of sha256(keyHex + "|" + r + "|" + R), masked to h = b/2 bits, with r and R in decimal. It panics unless 1 ≤ n and 0 ≤ x < n.

func Raw32

1func Raw32(s string) (string, bool)
source

Raw32 decodes exactly 64 lower-case hex characters into 32 raw bytes (one pass, table lookups: VM loops cost ~5k gas per character).

func Slot

1func Slot(keyHex string, artworks, slots, tid int64) int64
source

Slot is the slot of token tid (1-based) in a store of `artworks` artworks and `slots` slots: the identity tid-1 for a single-artwork store (1/1 and editions: "Edition 3 of 50"), Permute(K, slots, tid-1) otherwise.

Types 2

type Artwork

struct
 1type Artwork struct {
 2	Index                            int64
 3	Kind, Mime                       int
 4	Size, Have, Editions, SlotEnd    int64
 5	SHA256, Digest, CID, Title, Tier string
 6	Traits                           []string // one value per store trait type ("" = none)
 7	Complete                         bool
 8	// JSON escaped once by the store (filled by assets/v1 reads, "" otherwise):
 9	// TierJSON is the tier name as a JSON string ("" = no tier); TraitsJSON the
10	// creator traits as comma-joined {"trait_type":…,"value":…} items in store
11	// order ("" = none). Lets token reads avoid per-call escaping (review UP-M1).
12	TierJSON, TraitsJSON string
13}
source

Artwork is one record of a store as plain data. It crosses realm boundaries as a copy and never points into store state.

Methods on Artwork

func SlotStart

method on Artwork
1func (a Artwork) SlotStart() int64
source

SlotStart is the first slot of the artwork's range [SlotStart, SlotEnd).

type StoreInfo

struct
1type StoreInfo struct {
2	ID                                             string
3	Owner                                          address
4	Label                                          string
5	Sealed                                         bool
6	SealedHeight                                   int64
7	Artworks, Slots, OnchainN, IPFSN, OnchainBytes int64
8	TraitTypes, Tiers                              []string
9}
source

StoreInfo is a store's header as plain data.

Dependencies

Source Files 5