> ## Documentation Index
> Fetch the complete documentation index at: https://docs.555hyper.link/llms.txt
> Use this file to discover all available pages before exploring further.

# VAP

> Verifiable Attention Protocol

# The Heartbeat of the Economy

**VAP (Verifiable Attention Protocol)** is the mechanism that transforms "playing a game" into "verifiable work". It is the "Proof of Engagement" layer of the Streaming OS.

Unlike traditional analytics which are "fire and forget", VAP is a bidirectional, cryptographic handshake between the Client (User) and the Server (Verifier).

## Protocol Mechanics

VAP operates over a secure WebSocket connection (`wss://vap.rendernet.work`).

### 1. The Handshake

When a session begins, the client must authenticate and establish a secure channel.

**Client -> Server (INIT)**

```json theme={null}
{
  "type": "INIT",
  "payload": {
    "appId": "sector-13",
    "wallet": "HuW...9zP",
    "timestamp": 1717171717
  },
  "signature": "Ed25519_Signature_of_Payload"
}
```

**Server -> Client (ACK)**

```json theme={null}
{
  "type": "ACK",
  "sessionId": "sess_88239123",
  "nonce": 0,
  "difficulty": 1 // Current Proof-of-Work difficulty for anti-spam
}
```

### 2. The Heartbeat (Pulse)

Every `N` seconds (dynamic based on trust score), the client sends a "Pulse". This pulse proves liveness and state continuity.

**Client -> Server (PULSE)**

```json theme={null}
{
  "type": "PULSE",
  "sessionId": "sess_88239123",
  "nonce": 1,
  "delta": {
    "inputHash": "sha256_of_mouse_movements",
    "gameStateHash": "sha256_of_memory_snapshot",
    "score": 150
  },
  "signature": "Ed25519_Signature_of_Delta"
}
```

### 3. State Channels & Settlement

To scale to millions of concurrent users, VAP uses **State Channels**. We do not write every pulse to Solana.

1. **Off-Chain Aggregation**: The VAP Verifier Node maintains a "Ledger" of the session in Redis. It verifies the signatures and the hash chain (Nonce `N` must follow Nonce `N-1`).
2. **The Dispute Window**: The session is kept "Optimistic". If the server detects cheating, it can slash the user's reputation immediately.
3. **On-Chain Settlement**: When the session ends (or reaches a value threshold, e.g., 100 USDC), the Verifier submits a **Settlement Transaction** to the `vap_escrow` program on Solana.

**Solana Instruction (Settle)**

```rust theme={null}
pub fn settle_session(ctx: Context<Settle>, amount: u64, proof: [u8; 64]) -> Result<()> {
    // 1. Verify the Aggregated Signature (Proof)
    // 2. Transfer Tokens from Escrow to User
    // 3. Mint "Audience Inventory" cNFT to Creator
}
```

## Anti-Fraud Engine

VAP includes a multi-layered anti-fraud engine to ensure "Proof of Human".

### Layer 1: Cryptographic Integrity

* **Signature Verification**: Every packet must be signed by the user's wallet.
* **Replay Protection**: Nonces ensure packets cannot be replayed.

### Layer 2: Behavioral Heuristics

The VAP Verifier analyzes the `inputHash` and `gameStateHash`.

* **Entropy Analysis**: Human input has high entropy (micro-jitters). Bots are too perfect or too random.
* **Timing Analysis**: Reaction times \< 150ms are flagged as suspicious.

### Layer 3: Active Challenges (Turing Tests)

At random intervals, the server sends a `CHALLENGE` packet.

* **"Click the Glitch"**: An overlay appears in-game that must be clicked.
* **"Input Sequence"**: "Press UP, DOWN, A" within 2 seconds.

Failure to respond to a challenge results in immediate session termination and reputation slashing.

## Audience Rewards

VAP doesn't just verify attention; it values it. By proving "Proof of Human" engagement, VAP enables a direct value transfer to the audience.

* **Yield Bearing Attention**: Verified minutes spent watching or playing generate `$555` or partner tokens.
* **Loot Drops**: High-quality sessions (high entropy, long duration) increase the probability of receiving rare NFT drops.
* **Staking Multipliers**: Users who stake `$555` on their favorite creators receive boosted yields on their VAP sessions.

## Integration Guide

Developers can integrate VAP into any HTML5 game using the `@555x402/vap` SDK.

```typescript theme={null}
import { VAP } from '@555x402/vap';

// 1. Initialize
const vap = new VAP({
  appId: 'sector-13',
  wallet: window.solana, // Injected wallet
  endpoint: 'wss://vap.rendernet.work'
});

// 2. Start Session
await vap.connect();

// 3. Hook into Game Loop
game.on('update', (state) => {
  // Automatically handles Pulse timing and hashing
  vap.recordFrame({
    score: state.score,
    position: state.player.position,
    inputs: inputBuffer
  });
});

// 4. Handle Challenges
vap.on('challenge', (challenge) => {
  game.showOverlay(challenge);
});
```
