aleatory-embed-renderer
v0.1.0
Published
Aleatory Embeddable Renderer: portable, deterministic renderer and embed component for ALEATORY-001 generative art
Readme
Aleatory Embeddable Renderer (aleatory-embed-renderer)
Portable, deterministic renderer and embed component for ALEATORY-001 generative artworks on Tezos.
Aleatory generators are self-contained HTML files stored immutably on chain, drawing deterministically from a mint operation hash seed. This package handles the execution harness, zero-warmup PRNG, dependency resolution, metadata extraction, and sandboxed iframe isolation for any web application or indexer.
Installation
npm install aleatory-embed-rendereraleatory-embed-renderer ships dual ESM and CommonJS builds with TypeScript declarations.
Usage
1. React Component
import { AleatoryViewer } from "aleatory-embed-renderer/react";
export function ArtCard({ code, seed, params }) {
return (
<div style={{ width: "100%", aspectRatio: "1 / 1" }}>
<AleatoryViewer
code={code}
seed={seed}
params={params}
liveClock={true}
onReady={(detail) => console.log("Piece ready:", detail)}
onError={(err) => console.error("Piece error:", err)}
/>
</div>
);
}The component parses <meta name="alea:library"> declarations, resolves and verifies external scripts (e.g. p5.js, three.js), and executes the piece inside a sandboxed iframe with connect-src 'none'.
2. Custom Web Component
Zero-framework, works in vanilla HTML, Vue, Svelte, or Angular:
<script type="module" src="aleatory-embed-renderer/viewer"></script>
<aleatory-viewer
code="<!doctype html>..."
seed="ooKxY..."
params='{"density": 120}'
live-clock="true"
></aleatory-viewer>
<script>
const viewer = document.querySelector("aleatory-viewer");
viewer.addEventListener("ready", (e) => {
console.log("Ready, traits:", e.detail.features);
});
</script>3. Core Document Assembler (Headless / Node / Puppeteer)
For static thumbnail captures, CI determinism checks, or headless capture pipelines:
import { buildDocument, createPrng } from "aleatory-embed-renderer/core";
// Generate standalone sandboxed document string with CSP and harness:
const html = buildDocument({
code: generatorHtml,
seed: "ooKxY...",
params: { density: 140 },
liveClock: false, // Freezes Date.now() and performance.now() at 0
maxDpr: 1 // Canonical 1000x1000 DPR 1 capture
});
// Or evaluate PRNG numbers directly:
const prng = createPrng("ooKxY...");
console.log(prng.rand()); // Float [0, 1) with canonical zero-warmup sfc32
console.log(prng.randInt(1, 10)); // Inclusive4. Indexer & Metadata Extraction
Standardized extraction of seed and parameters across TzKT and marketplace indexers:
import { extractPieceMetadata, decodeCode, fetchMintRecord } from "aleatory-embed-renderer/indexer";
// 1. Extract from token metadata JSON:
const { seed, params, features } = extractPieceMetadata(tokenMetadata);
// 2. Fetch mint transfer and seed from TzKT when metadata is pending:
const mint = await fetchMintRecord("KT1...", 0);
console.log("Canonical seed:", mint.hash);
// 3. Decode contract storage code (gzip or identity):
const html = await decodeCode(storageHex, "gzip");Architectural Rules
- Zero-warmup PRNG: The PRNG uses
xmur3seeding intosfc32directly with 0 warmup cycles. Discarding initial draws shifts the stream and diverges from the canonical render. - String Seed: The seed is the base58 mint operation hash. Parsing it as hex or an integer (
parseInt) producesNaNand coerces the seed to0. - Execution Order: The harness replaces
Math.randombefore any declared libraries (such asp5.js) load, ensuring library noise and internal random states are deterministic. - Clock Modes: Captures run with frozen time (
liveClock: false). Interactive viewers run with live time (liveClock: true).
Subpath Exports
aleatory-embed-renderer: Everythingaleatory-embed-renderer/core: Pure PRNG, harness generator, and document assembleraleatory-embed-renderer/libraries: Dependency coordinate parser, CDN resolver, and blake2b integrityaleatory-embed-renderer/indexer: Metadata parsing, storage code decoder, and TzKT query recipesaleatory-embed-renderer/viewer: Sandboxed iframe manager and<aleatory-viewer>web componentaleatory-embed-renderer/react: React<AleatoryViewer />component
