File size: 16,234 Bytes
80d02ce
 
 
 
 
810ef53
80d02ce
810ef53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80d02ce
 
 
810ef53
 
80d02ce
 
810ef53
 
 
 
80d02ce
 
810ef53
 
 
 
80d02ce
 
810ef53
80d02ce
810ef53
 
 
80d02ce
 
 
810ef53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80d02ce
 
 
810ef53
 
80d02ce
 
810ef53
 
 
 
 
 
 
 
 
 
 
 
80d02ce
810ef53
80d02ce
 
810ef53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80d02ce
 
810ef53
 
 
 
80d02ce
810ef53
 
80d02ce
810ef53
 
 
80d02ce
 
810ef53
 
 
 
 
 
 
 
 
80d02ce
 
810ef53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80d02ce
 
810ef53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80d02ce
810ef53
 
 
80d02ce
810ef53
80d02ce
 
810ef53
 
 
 
 
 
80d02ce
810ef53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80d02ce
810ef53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80d02ce
810ef53
80d02ce
810ef53
80d02ce
 
810ef53
 
 
 
 
 
 
 
 
 
 
 
 
80d02ce
810ef53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80d02ce
810ef53
80d02ce
 
 
810ef53
 
 
 
 
 
 
 
 
 
 
 
 
 
80d02ce
 
810ef53
 
80d02ce
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Hurrian Hymn h.6 — 71-Shard NFT Collection</title>
<style>
*{box-sizing:border-box;margin:0;padding:0}
body{font:14px/1.5 'SF Mono',monospace;background:#0d1117;color:#c9d1d9;padding:1rem}
h1{font-size:1.4rem;color:#f0f6fc;margin-bottom:.3rem}
.sub{color:#8b949e;font-size:.8rem;margin-bottom:1rem}
.stats{display:flex;gap:1.5rem;flex-wrap:wrap;margin-bottom:1rem;font-size:.85rem}
.stat{background:#161b22;border:1px solid #30363d;border-radius:6px;padding:.4rem .8rem}
.stat b{color:#58a6ff}
.filters{margin-bottom:1rem;display:flex;gap:.5rem;flex-wrap:wrap}
.filters button{background:#21262d;color:#c9d1d9;border:1px solid #30363d;border-radius:4px;padding:3px 10px;cursor:pointer;font-size:.75rem}
.filters button.active{background:#1f6feb;border-color:#1f6feb;color:#fff}
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(100px,1fr));gap:6px;margin-bottom:1rem}
.tile{position:relative;cursor:pointer;border:2px solid #30363d;border-radius:4px;overflow:hidden;aspect-ratio:1;transition:transform .15s}
.tile:hover{transform:scale(1.05);z-index:1}
.tile.prime{border-color:#ffd700}
.tile.collected{opacity:1}.tile:not(.collected){opacity:.6}
.tile img{width:100%;height:100%;display:block}
.tile .label{position:absolute;bottom:0;left:0;right:0;background:rgba(0,0,0,.7);font-size:9px;padding:1px 3px;color:#c9d1d9;text-align:center}
.detail{position:fixed;top:0;right:-50%;width:50%;height:100%;background:#161b22;border-left:2px solid #30363d;overflow-y:auto;transition:right .3s;padding:1rem;z-index:10}
.detail.open{right:0}
.detail h2{font-size:1.1rem;color:#f0f6fc;margin-bottom:.5rem}
.close{position:absolute;top:.5rem;right:.5rem;background:none;border:none;color:#8b949e;font-size:1.5rem;cursor:pointer}
.layer-tabs{display:flex;gap:4px;margin:.5rem 0;flex-wrap:wrap}
.layer-tabs button{background:#21262d;color:#8b949e;border:1px solid #30363d;border-radius:4px;padding:2px 8px;cursor:pointer;font-size:.7rem}
.layer-tabs button.active{background:#238636;border-color:#238636;color:#fff}
.layer-content{background:#0d1117;border:1px solid #30363d;border-radius:4px;padding:.5rem;font-size:.75rem;max-height:300px;overflow:auto;white-space:pre-wrap;word-break:break-all;margin:.5rem 0}
.stego-canvas{border:1px solid #30363d;border-radius:4px;margin:.5rem 0}
.progress{background:#21262d;border-radius:4px;height:8px;margin:.5rem 0}
.progress-bar{background:linear-gradient(90deg,#238636,#ffd700);height:100%;border-radius:4px;transition:width .3s}
.hex{color:#7ee787}.cunei{color:#ffd700;font-size:1.2rem}
canvas{image-rendering:pixelated}
</style>
</head>
<body>
<h1>𒀸𒌑𒄴𒊑 Hurrian Hymn h.6 — 71-Shard NFT Collection</h1>
<p class="sub">Tablet RS 15.30 · ~1400 BC · Ugarit · West (1994) · DA51 CBOR · Groth16/BN254 · 6-Layer Stego</p>

<div class="stats">
  <div class="stat">Collected: <b id="count">0</b>/71</div>
  <div class="stat">Decoded: <b id="decoded">0</b> B</div>
  <div class="stat">Stego: <b id="stego-status"></b></div>
  <div class="stat">ZK: <b id="zk-status">pending</b></div>
</div>

<div class="progress"><div class="progress-bar" id="pbar" style="width:0%"></div></div>

<div class="filters" id="filters"></div>
<div class="grid" id="grid"></div>

<div class="detail" id="detail">
  <button class="close" onclick="closeDetail()">×</button>
  <h2 id="detail-title"></h2>
  <canvas id="tile-canvas" class="stego-canvas" width="512" height="512"></canvas>
  <div class="layer-tabs" id="layer-tabs"></div>
  <div class="layer-content" id="layer-content"></div>
</div>

<script>
const BASE = 'https://solana.solfunmeme.com/retro-sync';
const TILES_URL = BASE + '/tiles';
const SHARDS_URL = BASE + '/shards';

const CATEGORIES = ['generator','source','artifact','witness','eigenspace','metadata','reconstruction','reference','youtube','pipeline','reserved'];
const CAT_COLORS = {generator:'#ffd700',source:'#d2a8ff',artifact:'#7ee787',witness:'#e3b341',eigenspace:'#79c0ff',metadata:'#ff7b72',reconstruction:'#a5d6ff',reference:'#d29922',youtube:'#f778ba',pipeline:'#56d364',reserved:'#484f58'};
const PRIMES = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71];

const STEGO_PLANES = [
  {name:'R bit 0 — CBOR shard', ch:0, bit:0, color:'#ff6b6b'},
  {name:'G bit 0 — Witness',    ch:1, bit:0, color:'#51cf66'},
  {name:'B bit 0 — Eigenspace', ch:2, bit:0, color:'#339af0'},
  {name:'R bit 1 — Source',     ch:0, bit:1, color:'#ff922b'},
  {name:'G bit 1 — Notation',   ch:1, bit:1, color:'#20c997'},
  {name:'B bit 1 — Cuneiform',  ch:2, bit:1, color:'#845ef7'},
];

let manifest = null;
let collected = new Set();
let shardCache = {};
let stegoCache = {};
let activeFilter = 'all';

async function init() {
  const r = await fetch(BASE + '/manifest.json');
  manifest = await r.json();
  renderFilters();
  renderGrid();
}

function renderFilters() {
  const el = document.getElementById('filters');
  let html = '<button class="active" onclick="setFilter(\'all\',this)">all (71)</button>';
  for (const cat of CATEGORIES) {
    const n = manifest.shards.filter(s => s.category === cat).length;
    if (n > 0) html += `<button onclick="setFilter('${cat}',this)">${cat} (${n})</button>`;
  }
  el.innerHTML = html;
}

function setFilter(cat, btn) {
  activeFilter = cat;
  document.querySelectorAll('.filters button').forEach(b => b.classList.remove('active'));
  btn.classList.add('active');
  renderGrid();
}

function renderGrid() {
  const shards = activeFilter === 'all' ? manifest.shards : manifest.shards.filter(s => s.category === activeFilter);
  const el = document.getElementById('grid');
  el.innerHTML = shards.map(s => {
    const prime = PRIMES.includes(s.index);
    const cls = [prime ? 'prime' : '', collected.has(s.index) ? 'collected' : ''].join(' ');
    return `<div class="tile ${cls}" onclick="collect(${s.index})" title="#${s.index} ${s.name} [${s.category}]">
      <img src="${TILES_URL}/${String(s.index).padStart(2,'0')}.png" loading="lazy" alt="Shard ${s.index}">
      <div class="label">${prime?'★':'·'}${s.index} ${s.category}</div>
    </div>`;
  }).join('');
}

async function collect(idx) {
  collected.add(idx);
  document.getElementById('count').textContent = collected.size;
  document.getElementById('pbar').style.width = (collected.size/71*100)+'%';

  // Fetch JSON shard
  if (!shardCache[idx]) {
    try {
      const r = await fetch(`${SHARDS_URL}/${String(idx).padStart(2,'0')}.json`);
      shardCache[idx] = await r.json();
    } catch(e) { shardCache[idx] = {error: e.message}; }
  }

  // Decode stego from tile image
  if (!stegoCache[idx]) {
    stegoCache[idx] = await decodeStegoFromImage(idx);
  }

  updateStats();
  showDetail(idx);
  renderGrid();
  if (collected.size === 71) reconstructPayload();
}

async function decodeStegoFromImage(idx) {
  return new Promise((resolve) => {
    const img = new Image();
    img.crossOrigin = 'anonymous';
    img.onload = () => {
      const c = document.createElement('canvas');
      c.width = 512; c.height = 512;
      const ctx = c.getContext('2d');
      ctx.drawImage(img, 0, 0);
      const pixels = ctx.getImageData(0, 0, 512, 512).data; // RGBA

      // Extract 6 bit planes
      const layers = {};
      for (const plane of STEGO_PLANES) {
        const bytes = [];
        const npx = 512*512;
        const bytesPerLayer = npx / 8;
        for (let i = 0; i < bytesPerLayer; i++) {
          let byte = 0;
          for (let b = 0; b < 8; b++) {
            const px = i * 8 + b;
            if (px >= npx) break;
            const rgbaIdx = px * 4 + plane.ch;
            byte |= ((pixels[rgbaIdx] >> plane.bit) & 1) << b;
          }
          bytes.push(byte);
        }
        layers[plane.name] = new Uint8Array(bytes);
      }
      resolve(layers);
    };
    img.onerror = () => resolve({});
    img.src = `${TILES_URL}/${String(idx).padStart(2,'0')}.png`;
  });
}

function updateStats() {
  let totalBytes = 0;
  for (const idx of collected) {
    if (stegoCache[idx]) {
      for (const layer of Object.values(stegoCache[idx])) {
        totalBytes += layer.length;
      }
    }
  }
  document.getElementById('decoded').textContent = totalBytes.toLocaleString();
  document.getElementById('stego-status').textContent = `${collected.size}×6 planes`;
}

function showDetail(idx) {
  const s = manifest.shards.find(x => x.index === idx);
  const detail = document.getElementById('detail');
  detail.className = 'detail open';
  const prime = PRIMES.includes(idx);
  document.getElementById('detail-title').textContent = `${prime?'★':''} Shard #${idx}${s.name} [${s.category}]`;

  // Draw tile on canvas
  const canvas = document.getElementById('tile-canvas');
  const ctx = canvas.getContext('2d');
  const img = new Image();
  img.crossOrigin = 'anonymous';
  img.onload = () => ctx.drawImage(img, 0, 0, 512, 512);
  img.src = `${TILES_URL}/${String(idx).padStart(2,'0')}.png`;

  // Layer tabs
  const tabs = document.getElementById('layer-tabs');
  const layers = [
    {id:'json', name:'JSON Shard', color:'#58a6ff'},
    {id:'data_layers', name:'Data Layers', color:'#79c0ff'},
    ...STEGO_PLANES.map((p,i) => ({id:'stego_'+i, name:p.name, color:p.color})),
    {id:'hex', name:'Raw Hex', color:'#7ee787'},
    {id:'visual', name:'Stego Visual', color:'#d2a8ff'},
  ];
  tabs.innerHTML = layers.map((l,i) =>
    `<button style="border-color:${l.color}" onclick="showLayer(${idx},'${l.id}',this)">${l.name}</button>`
  ).join('');

  showLayer(idx, 'json', tabs.firstChild);
}

function showLayer(idx, layerId, btn) {
  document.querySelectorAll('#layer-tabs button').forEach(b => b.classList.remove('active'));
  if (btn) btn.classList.add('active');
  const el = document.getElementById('layer-content');
  const shard = shardCache[idx];
  const stego = stegoCache[idx] || {};

  if (layerId === 'json') {
    el.innerHTML = `<pre>${JSON.stringify(shard, null, 2).slice(0, 4000)}</pre>`;
  } else if (layerId === 'data_layers') {
    if (shard && shard.data_layers) {
      const dl = shard.data_layers;
      el.innerHTML = Object.keys(dl).map(k => {
        const l = dl[k];
        return `<b>${k}</b>: chunk ${l.chunk}/${l.of}, ${l.total_bytes.toLocaleString()} B total\n` +
               `  data: ${l.data.slice(0,80)}${l.data.length>80?'...':''}`;
      }).join('\n\n');
    } else {
      el.textContent = 'No data_layers in shard';
    }
  } else if (layerId === 'hex') {
    const bytes = stego[STEGO_PLANES[0].name];
    if (bytes) {
      const hex = Array.from(bytes.slice(0, 256)).map(b => b.toString(16).padStart(2,'0')).join(' ');
      el.innerHTML = `<span class="hex">${hex}</span>\n\n... ${bytes.length} bytes in R bit 0 plane`;
    } else {
      el.textContent = 'Collect this shard to decode stego';
    }
  } else if (layerId === 'visual') {
    visualizeStegoPlanes(idx);
    el.textContent = 'Stego bit planes rendered on canvas above.\nEach plane shown as a separate color channel.';
  } else if (layerId.startsWith('stego_')) {
    const pi = parseInt(layerId.split('_')[1]);
    const plane = STEGO_PLANES[pi];
    const bytes = stego[plane.name];
    if (bytes) {
      // Try to decode as text
      let text = '';
      try { text = new TextDecoder('utf-8', {fatal: false}).decode(bytes.slice(0, 512)); } catch(e) {}
      const nonNull = bytes.filter(b => b !== 0).length;
      const hex = Array.from(bytes.slice(0, 128)).map(b => b.toString(16).padStart(2,'0')).join(' ');
      el.innerHTML = `<b>${plane.name}</b>\nBytes: ${bytes.length} (${nonNull} non-zero)\n\n` +
        `<b>Text preview:</b>\n${text.replace(/\0/g,'·').slice(0,300)}\n\n` +
        `<b>Hex:</b>\n<span class="hex">${hex}</span>...`;
    } else {
      el.textContent = 'Collect this shard to decode';
    }
  }
}

function visualizeStegoPlanes(idx) {
  const canvas = document.getElementById('tile-canvas');
  const ctx = canvas.getContext('2d');
  const stego = stegoCache[idx];
  if (!stego) return;

  // Render each plane as colored pixels
  const imgData = ctx.createImageData(512, 512);
  for (const plane of STEGO_PLANES) {
    const bytes = stego[plane.name];
    if (!bytes) continue;
    const color = plane.color;
    const r = parseInt(color.slice(1,3),16);
    const g = parseInt(color.slice(3,5),16);
    const b = parseInt(color.slice(5,7),16);
    for (let i = 0; i < bytes.length; i++) {
      for (let bit = 0; bit < 8; bit++) {
        const px = i * 8 + bit;
        if (px >= 512*512) break;
        if ((bytes[i] >> bit) & 1) {
          const off = px * 4;
          imgData.data[off] = Math.min(255, imgData.data[off] + r/6);
          imgData.data[off+1] = Math.min(255, imgData.data[off+1] + g/6);
          imgData.data[off+2] = Math.min(255, imgData.data[off+2] + b/6);
          imgData.data[off+3] = 255;
        }
      }
    }
  }
  ctx.putImageData(imgData, 0, 0);
}

async function reconstructPayload() {
  document.getElementById('zk-status').textContent = 'reconstructing...';
  // Collect all stego data in order — use the full 6-plane stream per tile
  const allBytes = [];
  const CAP = 512*512*6/8; // 196608 per tile

  for (let idx = 1; idx <= 71; idx++) {
    const stego = stegoCache[idx];
    if (!stego) { allBytes.push(...new Array(CAP).fill(0)); continue; }

    // Re-extract as interleaved stream (matching Rust embed_all order)
    const img = await loadImagePixels(idx);
    if (!img) { allBytes.push(...new Array(CAP).fill(0)); continue; }

    for (let i = 0; i < CAP; i++) {
      let byte = 0;
      for (let b = 0; b < 8; b++) {
        const bitIdx = i * 8 + b;
        const px = Math.floor(bitIdx / 6);
        const plane = bitIdx % 6;
        if (px >= 512*512) break;
        const ch = plane % 3;
        const bitPos = Math.floor(plane / 3);
        const val = (img[px * 4 + ch] >> bitPos) & 1;
        byte |= val << b;
      }
      allBytes.push(byte);
    }
  }

  // Parse NFT7 header
  const data = new Uint8Array(allBytes);
  const magic = String.fromCharCode(data[0], data[1], data[2], data[3]);
  if (magic === 'NFT7') {
    const view = new DataView(data.buffer);
    const segCount = view.getUint32(4, true);
    let offset = 8;
    const segments = [];
    for (let s = 0; s < segCount && offset < data.length; s++) {
      const nameLen = view.getUint32(offset, true); offset += 4;
      const name = new TextDecoder().decode(data.slice(offset, offset + nameLen)); offset += nameLen;
      const dataLen = view.getUint32(offset, true); offset += 4;
      const segData = data.slice(offset, offset + dataLen); offset += dataLen;
      segments.push({name, data: segData, size: dataLen});
    }

    document.getElementById('zk-status').innerHTML = `<span style="color:#238636">✓ NFT7 DECODED</span> — ${segments.length} segments`;

    // Offer WAV playback
    const wav = segments.find(s => s.name === 'wav');
    if (wav) {
      const blob = new Blob([wav.data], {type: 'audio/wav'});
      const url = URL.createObjectURL(blob);
      const info = document.getElementById('layer-content');
      info.innerHTML = `<b>🎵 Full payload reconstructed from 71 stego tiles!</b>\n\n` +
        segments.map(s => `${s.name}: ${s.size.toLocaleString()} bytes`).join('\n') +
        `\n\n<audio controls src="${url}" style="width:100%"></audio>\n` +
        `<a href="${url}" download="h6_west.wav" style="color:#58a6ff">⬇ Download WAV</a>`;
    }
  } else {
    document.getElementById('zk-status').textContent = 'reconstruction failed — collect all 71';
  }
}

function loadImagePixels(idx) {
  return new Promise(resolve => {
    const img = new Image();
    img.crossOrigin = 'anonymous';
    img.onload = () => {
      const c = document.createElement('canvas');
      c.width = 512; c.height = 512;
      const ctx = c.getContext('2d');
      ctx.drawImage(img, 0, 0);
      resolve(ctx.getImageData(0, 0, 512, 512).data);
    };
    img.onerror = () => resolve(null);
    img.src = `${TILES_URL}/${String(idx).padStart(2,'0')}.png`;
  });
}

function closeDetail() {
  document.getElementById('detail').className = 'detail';
}

init();
</script>
</body>
</html>