03/architecture

Three-Tier Architecture & 3-Tier Hot-Path Engine

How unpeek combines 3-tier call-graph exemption, 92-char / 64-bit salted vaults, >=4-var Rivest MBA + QNR guards, order-independent globalThis shield, and Tier 3 Micro-VM v2 + singleton <1.2 KB host-coupled WASM KDF.

3-Tier Call-Graph Exemption (TRUE_HOT_60FPS / Shallow Render / Workers)

Before rewriting a single token, unpeek classifies every function scope across three distinct tiers so frame budgets and SSR hydration stay untouched while UI event handlers still receive cold protection:

  • `TRUE_HOT_60FPS`: Loops (`for`, `while`, `do...while`, `for...in`, `for...of`), `requestAnimationFrame`, Three.js `useFrame` hooks, and loop-scoped array callbacks propagate exemption both top-down and bottom-up through their call chain.
  • `SHALLOW_RENDER_COMPONENT`: Direct PascalCase UI render bodies stay exempt for 60fps rendering and React SSR hydration, while nested async handlers (`onSubmit`, `handleSave`) and cold helpers are decoupled into protected cold paths.
  • `SERIALIZED_WORKER`: Web Worker factories calling `.toString()`, `importScripts()`, or `onmessage` remain completely unmangled so serialized worker blobs never break at runtime.

Zero-Escape 92-Char Vault, Noise Filters & In-Place Shader Vault

In Layer 1 (default), cold literals (`>= minStringLength`, default `4`) pass through a noise filter (exempting SVG path coordinates and Tailwind utility class chains) and encode via a seed-shuffled 92-character involutory ASCII permutation (`P[P[c]] == c`) that never emits `\u00xx` escapes, keeping LZ77/Gzip compression tight.

Large template literals and GPU shaders (`>= 256 B` or WebGPU `@vgpu/wgsl` / GLSL signatures) enter an encrypted `Uint8Array` buffer decoded in-place via `TextDecoder` and immediately re-encrypted in `finally`, preventing lingering heap plaintext and keeping React StrictMode remounts idempotent.

Order-Independent Shield & Non-Linear Rivest MBA Guards

Entry chunks execute a `WorkerGlobalScope`-safe (`self`/`globalThis`) FNV-1a integrity IIFE with `Reflect.apply` descriptor checks (`Function.prototype.toString`). When async split chunks (such as Next.js 16 Turbopack) execute before the entry shield initializes (`globalThis[sym] === undefined`), decoders return valid plaintext without poisoning cache (`d = -1` removed), failing closed only on active tampering.

Cold functions (`coldFlow: true`) receive `>=4`-variable semi-linear MBA predicates paired with degree-3 Rivest $\mathbb{Z}_{2^{32}}$ permutation polynomials, a 256-entry seeded S-Box, QNR conditions (`((Math.imul(z, z) + 1) & 3) === 3`), and neutral return-domain-aligned decoy bridges without mutating application branches or leaking source identifiers.

Tier 3 Deep-Dive: Micro-VM v2, Singleton Host-Coupled WASM KDF & 64-Bit Vault

Passing `--aggressive` or `--profile strict` activates Tier 3 enclave defense (prioritizing `@unpeek-critical` annotations and `critical.include` patterns) without risking application crashes or violating strict CSP:

  • `Bytecode Micro-VM v2 (43 Opcodes)`: Pre-VM lowering supports `&&`/`||`/`??`, `?:`, `for`/`while`/`do..while`, `try`/`throw`, `this`, `new`, `obj.arguments`, and closures across an `[8, 400]` AST node window using a `$step` direct-threaded closure trampoline and inter-block `$f.ac` accumulator ratchet—zero `eval()` or `new Function()`.
  • `Singleton Host-Coupled WASM KDF (<1.2 KB)`: Synthesizes a `371 B` WebAssembly binary importing `env.g`/`env.m` host hooks, compiled once into a shared `globalThis` singleton across split chunks, with a bit-identical non-linear Rivest + S-Box JavaScript fallback when WebAssembly is blocked by CSP.
  • `64-Bit Call-Site Salted Vault`: Replaces sequential counters with 31-bit salts derived via 64-bit mixing (`_uD(stringIndex, callSiteSalt)`), guaranteeing complete idempotence under React 19 Concurrent Mode and StrictMode.
Terminal: Tier 2 Aggressive Protection Invocation
# Activate Tier 2 Bytecode Micro-VM & inline WASM KDF
npx unpeek protect --aggressive --seed 0x7f4a2c

#   ▛▀▀▜  unpeek 1.12.0
#   ▙▄▄▟  client bundle protection
#
#   PROJECT ──────────────────────────────────────
#   framework            next
#   tier                 Tier 2 (--aggressive: Micro-VM & WASM KDF)
#   output               .next/static/chunks
#   bundles              18
#
#   CALL GRAPH ───────────────────────────────────
#   hot path exempt      24  0% tax
#   cold path protected  61
#
#   TRANSFORM ────────────────────────────────────
#   string vault         312 literals  O(1) memo
#   symbol mangling      489 bindings
#
#   OUTPUT ───────────────────────────────────────
#   source maps          18 moved -> .unpeek-maps/
#   gzip                 284.12 KB -> 316.50 KB  +11.39%
#   elapsed              186 ms
#
#   done. maps are private. hot path untouched.