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.

v2 source pure

Package media is the pure half of Sinopia's uploaded collections, version 2 (docs/uploaded-collections.md §5.1, §0a; ...

Overview

Package media is the pure half of Sinopia's uploaded collections, version 2 (docs/uploaded-collections.md §5.1, §0a; mainnet plan §2.1, §3.2 WP-F): storage kinds and media types, the typed views of a store (Artwork, StoreInfo), the storage badge and the salt-keyed permutation that assigns tokens to artworks. It has no state.

v2 against v1: the image header checks and the CIDv1 grammar moved into p/safe/v2 (core validates engine media with them, I-15). The functions of the same name here delegate to safe/v2, so the asset store (r/…/assets/v1), the upload engine (r/…/engines/upload) and core apply one implementation. Everything else is v1's code unchanged; the permutation keeps its domain "art|upload|perm|v1|" (same algorithm, same golden vectors). Frontend twins: chain/perm.ts (Permute, PermKey, Slot), chain/cid.ts (CIDv1) and checkImage in chain/upload.ts, pinned by docs/test-vectors/upload-v2.json (docs/test-vectors/gen-upload-v2.py).

Constants 6

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         = safe.MaxDim           // 4096 px per side, decompression-bomb guard
3	MaxSVGBytes    = safe.MaxSVGImageBytes // 16,384: on-chain SVG (= engine/v2 MaxMediaSVGBytes)
4	MaxRasterBytes = 262144                // on-chain png/webp/jpeg per artwork (= engine/v2 MaxMediaBytes)
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 IPFSScheme

1const IPFSScheme = safe.IPFSScheme
source

IPFSScheme prefixes an IPFS URI ("ipfs://<CIDv1>").

const PermDomain

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

PermDomain separates the permutation key from every other platform hash (under safe.Domain "art"). Unchanged from v1: same algorithm, same keys.

Functions 15

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 (v1 signature): SVG must pass safe.AssertSVG with MaxSVGBytes (w = h = 0); a raster file must carry its type's magic bytes and header dimensions of 1..MaxDim per side (safe.ImageDims). Error texts are v1's.

func IsHex32

1func IsHex32(s string) bool
source

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

func IsIPFSURI

1func IsIPFSURI(s string) bool
source

IsIPFSURI reports whether s is "ipfs://" + a CIDv1 ParseCIDv1 accepts.

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 (safe/v2 grammar, unchanged from media/v1).

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.

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 MimeType

method on Artwork
1func (a Artwork) MimeType() string
source

MimeType is the artwork's IANA media type.

func MimeVerified

method on Artwork
1func (a Artwork) MimeVerified() bool
source

MimeVerified reports whether the chain checked the file against its declared type (UP-I6): on-chain bytes passed CheckImage when their last chunk arrived; an IPFS file's type is the creator's claim (the chain never sees the bytes; a raw CID binds the bytes, not the type).

func OnChain

method on Artwork
1func (a Artwork) OnChain() bool
source

OnChain reports whether the artwork's bytes live in the store.

func SlotStart

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

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

func URI

method on Artwork
1func (a Artwork) URI() string
source

URI is "ipfs://<cid>" for an IPFS artwork, "" for on-chain bytes.

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.

Methods on StoreInfo

func Badge

method on StoreInfo
1func (s StoreInfo) Badge() string
source

Badge is the store's storage badge (see Badge).

func HasEditions

method on StoreInfo
1func (s StoreInfo) HasEditions() bool
source

HasEditions reports whether some artwork of the store has more than one edition (slots > artworks).

Dependencies

Source Files 3