/** * NexArt Code Mode Runtime SDK - Types * See version.ts for SDK version (single source of truth) * * Type definitions for the Code Mode runtime engine. * This is the canonical type surface for @nexart/codemode-sdk. */ /** * Protocol Constants * These define the locked protocol identity. * Imports from version.ts (single source of truth). */ export declare const PROTOCOL_IDENTITY: { readonly protocol: "nexart"; readonly engine: "codemode"; readonly protocolVersion: "1.2.0"; readonly phase: 3; readonly deterministic: true; }; export type RenderMode = 'static' | 'loop'; /** * Runtime Canvas * Abstraction for browser (HTMLCanvasElement) and Node (canvas package) environments. * In Node, the `canvas` npm package provides an HTMLCanvasElement-compatible interface. */ export type RuntimeCanvas = HTMLCanvasElement; export interface EngineConfig { mode: RenderMode; width?: number; height?: number; duration?: number; fps?: number; } /** * Render Result (Discriminated Union) * * Static mode can return either: * - blob: For display/download (PNG) * - imageData: For oracle hashing (raw pixels) * * Video mode returns blob with frame/duration metadata. */ export type RenderResult = { type: 'image'; blob: Blob; } | { type: 'image'; imageData: ImageData; } | { type: 'video'; blob: Blob; frames?: number; duration?: number; }; export interface RunOptions { code: string; seed?: number; vars?: number[]; onPreview?: (canvas: RuntimeCanvas) => void; onProgress?: (progress: ProgressInfo) => void; onComplete: (result: RenderResult) => void; onError?: (error: Error) => void; returnImageData?: boolean; } export interface ProgressInfo { phase: 'setup' | 'rendering' | 'encoding' | 'complete'; frame?: number; totalFrames?: number; percent: number; message: string; } export interface Engine { run: (options: RunOptions) => Promise; stop: () => void; getConfig: () => Readonly; } export interface TimeVariables { frameCount: number; t: number; time: number; tGlobal: number; totalFrames: number; } /** * Protocol Variables (VAR[0..9]) * First-class protocol inputs for deterministic rendering. * Used by SoundArt, Shapes, Noise, and ByX collections. * * Rules (SDK v1.0.2, Protocol v1.0.0): * - Input array can have 0-10 elements (protocol error if > 10) * - All values MUST be finite numbers (protocol error if not) * - Values MUST be in range 0-100 (protocol error if out of range, NO clamping) * - Runtime VAR is ALWAYS 10 elements (padded with zeros for consistency) * - Read-only inside sketches (write attempts throw protocol error) * - Default: all zeros if not provided */ export interface ProtocolVariables { VAR: readonly [number, number, number, number, number, number, number, number, number, number]; } /** * Default protocol variables (all zeros) */ export declare const DEFAULT_VARS: ProtocolVariables; export declare const DEFAULT_CONFIG: { readonly width: 1950; readonly height: 2400; readonly duration: 2; readonly fps: 30; readonly minDuration: 1; readonly maxDuration: 4; }; /** * Protocol Metadata * Attached to every execution result for verification. */ export interface ProtocolMetadata { protocol: 'nexart'; engine: 'codemode'; protocolVersion: '1.2.0'; phase: 3; deterministic: true; seed: number; vars: number[]; width: number; height: number; mode: RenderMode; totalFrames?: number; } /** * Canonical Execution Input * The single entry point for all Code Mode execution. */ export interface ExecuteCodeModeInput { source: string; width: number; height: number; seed: number; vars?: number[]; mode: RenderMode; totalFrames?: number; } /** * Canonical Execution Result * Every execution produces this structure. */ export interface ExecuteCodeModeResult { image?: Blob; video?: Blob; frames?: ImageData[]; metadata: ProtocolMetadata; } /** * ───────────────────────────────────────────────────────────────────────────── * Verification Reason Codes (v1.9.0) * ───────────────────────────────────────────────────────────────────────────── * * Stable, string-valued reason codes returned by all Code Mode verification * functions. Additive-only: existing codes will never be renamed or removed. */ export declare const CodeVerifyCode: { readonly OK: "OK"; readonly CERTIFICATE_HASH_MISMATCH: "CERTIFICATE_HASH_MISMATCH"; readonly SNAPSHOT_HASH_MISMATCH: "SNAPSHOT_HASH_MISMATCH"; readonly RENDER_HASH_MISMATCH: "RENDER_HASH_MISMATCH"; readonly INVALID_SHA256_FORMAT: "INVALID_SHA256_FORMAT"; readonly CANONICALIZATION_ERROR: "CANONICALIZATION_ERROR"; readonly SCHEMA_ERROR: "SCHEMA_ERROR"; readonly NODE_RECEIPT_MISSING: "NODE_RECEIPT_MISSING"; readonly NODE_RECEIPT_KEY_NOT_FOUND: "NODE_RECEIPT_KEY_NOT_FOUND"; readonly NODE_RECEIPT_INVALID_SIGNATURE: "NODE_RECEIPT_INVALID_SIGNATURE"; readonly NODE_RECEIPT_KEY_FORMAT_UNSUPPORTED: "NODE_RECEIPT_KEY_FORMAT_UNSUPPORTED"; readonly UNKNOWN_ERROR: "UNKNOWN_ERROR"; }; export type CodeVerifyCode = typeof CodeVerifyCode[keyof typeof CodeVerifyCode]; /** * Verification result returned by Code Mode verification functions. * `ok` — true on success * `code` — stable machine-readable reason code (CodeVerifyCode) * `details` — optional human-readable detail lines */ export interface CodeVerificationResult { ok: boolean; code: CodeVerifyCode; details?: string[]; } /** * ───────────────────────────────────────────────────────────────────────────── * Signed Attestation Receipt — Code Mode (v1.9.0) * ───────────────────────────────────────────────────────────────────────────── * * Payload signed by the attestation node over a Code Mode snapshot bundle. * The signature is Ed25519 over the canonical JSON bytes of this object. */ export interface SignedAttestationReceipt { receiptVersion: 'attestation.receipt.v1'; attestationId: string; attestedAt: string; nodeId: string; attestorKeyId: string; nodeRuntimeHash: string; certificateHash: string; protocolVersion: string; [key: string]: unknown; } /** * Node Keys Document * Fetched from /.well-known/nexart-node.json on the attestation node. */ export interface NodeKeysDocument { nodeId: string; activeKid?: string; keys: Array<{ kid: string; alg: 'Ed25519'; use: 'sig'; publicKeyJwk?: { kty: 'OKP'; crv: 'Ed25519'; x: string; }; publicKey?: string; publicKeySpkiB64?: string; createdAt?: string; }>; } /** * Result of node receipt signature verification (Code Mode variant). * Alias of CodeVerificationResult — kept as a distinct named type for * clarity in function signatures. */ export type NodeReceiptVerifyResult = CodeVerificationResult; /** * Normalised attestation receipt extracted from any Code Mode bundle format. * Returned by getAttestationReceipt(). */ export interface CodeAttestationReceipt { attestationId: string; attestedAt: string; nodeId?: string; attestorKeyId?: string; nodeRuntimeHash?: string; certificateHash?: string; protocolVersion?: string; receipt?: SignedAttestationReceipt; signature?: string; [key: string]: unknown; } /** * Builder Manifest (v1.6.0) * * Passive, declarative metadata for builder attribution. * This is data-only with no logic, rewards, or enforcement attached. * * Rules: * - Registration is optional * - Missing or invalid manifest does NOT throw * - No network calls, no telemetry, no analytics * - Does NOT affect execution behavior or determinism * - Used for future attribution and ecosystem discovery */ export interface NexArtBuilderManifest { protocol: 'nexart'; manifestVersion: string; app?: { name?: string; url?: string; description?: string; contact?: string; }; sdk?: { package?: string; version?: string; execution?: string; }; renderer?: { package?: string; version?: string; mode?: 'preview' | 'canonical'; }; features?: Record; declaration?: { usesOfficialSdk?: boolean; noRuntimeModification?: boolean; noProtocolBypass?: boolean; }; timestamp?: string; } //# sourceMappingURL=types.d.ts.map