# Phase 1: anitya Engine Integration

Phase 1 replaces video recording with a Deterministic Event Logging System. Since anitya is the execution environment, we capture the "DNA" of the creation process (commands) rather than visual output (pixels).

Core Stack: TypeScript (Frontend), Solana/Anchor (Registry), Arweave (Log Storage), AWS KMS (Identity)

### **Architecture Overview**

The logic moves from a desktop screen recorder to the anitya Engine Command Stack. Instead of heavy video files, the "Proof of Process" becomes a lightweight Cryptographic Event Log recording every significant user action (object creation, transformation, scripting, texturing) in a sequential, tamper-evident chain.

<figure><img src="/files/FfuFoiTAay8BsU7UlfQq" alt=""><figcaption></figcaption></figure>

### **The Event Sourcing Engine**

The core component is a TypeScript module integrated into anitya's Editor, observing the Undo/Redo stack.

### Event Structure (JSON Schema)

Every action is serialized into a JSON object. Critical to security is hash chaining: each event includes the hash of the previous event, creating a "local blockchain" within the session. This makes it impossible to insert or delete actions without breaking the chain.

```json
{
  "seq": 42,
  "timestamp": 1715000123,
  "prev_hash": "a1b2c3d4...",
  "action_type": "TRANSFORM_UPDATE",
  "user_id": "anitya_user_88",
  "payload": {
    "target_uuid": "obj_uuid_99",
    "position": { "x": 10.5, "y": 0, "z": -5 },
    "rotation": { "x": 0, "y": 90, "z": 0 },
    "scale": { "x": 1, "y": 1, "z": 1 }
  }
}
```

### Asset Import (Remixing & Lineage)

When a user imports an existing anitya asset into their scene, the engine records the provenance link. This allows the Smart Contract to build the Royalty Graph automatically.

```json
{
  "seq": 43,
  "prev_hash": "e5f6g7...",
  "action_type": "ASSET_IMPORT",
  "payload": {
    "local_uuid": "new_instance_id",
    "source_asset_address": "Solana_Pubkey_Of_Original_Asset"
  }
}
```

### **Storage Strategy (The Proof Package)**

When the user clicks "Publish" or "Register IP":

1. **Serialization:** The frontend compiles the CommandStack into a single `session_log.json`
2. **Visual Proof:** The engine renders a high-res JPG thumbnail (`preview.jpg`)
3. **Manifest:** A file detailing dependencies (`manifest.json`)

These files are bundled and sent to the anitya Backend.

### Arweave Upload (via Irys)

The backend uploads the package to Arweave.

* **Result:** A permanent, immutable URL (e.g., `ar://TxID_123`)
* **Cost efficiency:** A text log of 4 hours of work is \~500KB. Cost to store forever: < $0.01

### **Identity Management (Seamless Wallet)**

We use a Custodial KMS Architecture integrated into anitya's existing Auth system.

1. **Onboarding:** When a user signs up (Email/Google), the backend triggers AWS KMS to generate a Solana Keypair

2. **Mapping:**

```
SQL DB: User: john@email.com <-> Wallet: Public_Key_ABC
HSM (Secure): Key_ID_XYZ (stores the Private Key)
```

3. **Signing:**

{% code overflow="wrap" %}

```
User clicks "Publish" → Backend authenticates via JWT → KMS signs the Solana transaction using Key_ID_XYZ
```

{% endcode %}

### **Smart Contract (Solana Program)**

The Onchain Registry stores the asset record:

```rust
use anchor_lang::prelude::*;

#[account]
pub struct AnityaAsset {
    // Identity
    pub authority: Pubkey,          // Creator's Wallet
    pub collection: Pubkey,         // Anitya Official Collection Address
    
    // Proof of Creation
    pub log_arweave_tx: String,     // Link to the JSON Event Log
    pub preview_arweave_tx: String, // Link to the Thumbnail
    pub log_root_hash: [u8; 32],    // Hash of the FINAL event in the log
    
    // Lineage (Dependencies)
    // Stores a list of other Assets used in this scene
    pub dependencies: Vec<Pubkey>,  
    
    // Metadata
    pub engine_version: String,     // e.g., "anitya v2.4"
    pub timestamp: i64,
}
```

### **Replay Verification**

This is the unique selling point of Phase 1. To verify an asset, the anitya Viewer fetches the `log_arweave_tx`.

1. **Load:** It parses the JSON.
2. **Verify:** It recalculates the hash chain locally. If the math matches the `log_root_hash` on Solana, the file is authentic.
3. **Replay:** The engine executes the commands in "Ghost Mode" (Speed 10x), visually reconstructing the scene from scratch before the viewer's eyes.

### **Strategic Benefits of Phase 1**

**1. Control:** We control the environment, eliminating 90% of anti-cheat/anti-fraud edge cases

**2. Data Quality:** Event logs are searchable and indexable. Query "show me all worlds that used this asset" - impossible with video

**3. Adoption:** By making this a default feature, we bootstrap the network with thousands of verifiable assets before asking anyone to install external software

***

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://anitya.gitbook.io/lightpaper/technical-deep-dive/phase-1-anitya-engine-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
