'use client'; // Animated 3D explainer: a 3-of-5 vault guarded by five hardware keys. // Story (loops): locked → one stolen key is rejected → three approvers sign → // vault opens and pays → a lost key is replaced while funds stay safe. // three.js is loaded lazily so the landing page's first paint stays light. import { useEffect, useRef, useState } from 'react'; import type * as T from 'three'; const N = 5; const M = 3; const KEYS = ['CFO · Ledger', 'CEO · Trezor', 'COO · Coldcard', 'Backup · Keystone', 'Board · Jade']; const STOLEN = 4; const LOST = 3; const APPROVERS = [0, 1, 2]; const PHASES = [ { dur: 4.2, title: 'Funds sit behind a 3-of-5 quorum', text: 'Five hardware keys, held by five people in different places. The vault opens only when any three of them agree.' }, { dur: 4.6, title: 'One stolen key gets nothing', text: 'An attacker who phishes or steals a single key can sign, but one signature out of the three required is rejected. Nothing moves.' }, { dur: 5.0, title: 'Approvers sign on their own devices', text: 'Each approver checks the amount and destination on their device screen and signs there. Private keys never leave the hardware.' }, { dur: 4.6, title: 'Threshold met: payment released', text: 'With three valid signatures the transaction is complete, and the network accepts it.' }, { dur: 5.2, title: 'A lost key is not a lost treasury', text: 'If a device is lost, four keys remain and three are still enough. The team swaps in a replacement key, and the funds were never at risk.' }, ] as const; const STARTS = PHASES.reduce((a, p, i) => [...a, i ? a[i - 1] + PHASES[i - 1].dur : 0], []); const TOTAL = PHASES.reduce((s, p) => s + p.dur, 0); type Pulse = { key: number; start: number; dur: number; blocked?: boolean }; const PULSES: Pulse[][] = [ [], [{ key: STOLEN, start: 0.7, dur: 1.3, blocked: true }], APPROVERS.map((k, i) => ({ key: k, start: 0.3 + i * 1.25, dur: 1.05 })), [], [], ]; const clamp01 = (x: number) => (x < 0 ? 0 : x > 1 ? 1 : x); const ease = (x: number) => { x = clamp01(x); return x < 0.5 ? 2 * x * x : 1 - Math.pow(-2 * x + 2, 2) / 2; }; const COLORS = { idle: 0x3a5163, green: 0x3ee6a0, red: 0xff4d5e, blue: 0x7cc4ff, gold: 0xf5c451, accent: 0x34d399 }; export default function MultisigScene() { const box = useRef(null); const labels = useRef<(HTMLDivElement | null)[]>([]); const counter = useRef(null); const ctl = useRef({ t: 0, playing: true, jump: -1 }); const [phase, setPhase] = useState(0); const [playing, setPlaying] = useState(true); const [failed, setFailed] = useState(false); useEffect(() => { const reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches; if (reduced) { ctl.current.playing = false; ctl.current.t = PHASES[0].dur - 0.2; setPlaying(false); } let disposed = false; let cleanup = () => {}; (async () => { const THREE = await import('three'); const { RoundedBoxGeometry } = await import('three/addons/geometries/RoundedBoxGeometry.js'); const { RoomEnvironment } = await import('three/addons/environments/RoomEnvironment.js'); const el = box.current; if (disposed || !el) return; let renderer: T.WebGLRenderer; try { renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true, powerPreference: 'high-performance' }); } catch { setFailed(true); return; } renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); renderer.setClearColor(0x000000, 0); renderer.toneMapping = THREE.ACESFilmicToneMapping; renderer.toneMappingExposure = 1.05; renderer.domElement.className = 'scene3d-canvas'; el.prepend(renderer.domElement); const scene = new THREE.Scene(); const pmrem = new THREE.PMREMGenerator(renderer); const envTex = pmrem.fromScene(new RoomEnvironment(), 0.04).texture; scene.environment = envTex; scene.environmentIntensity = 0.55; const camera = new THREE.PerspectiveCamera(36, 1, 0.1, 100); const camBase = new THREE.Vector3(0, 2.7, 12.6); camera.position.copy(camBase); scene.add(new THREE.AmbientLight(0xffffff, 0.25)); const sun = new THREE.DirectionalLight(0xffffff, 2.0); sun.position.set(4, 8, 6); scene.add(sun); const rim = new THREE.PointLight(COLORS.accent, 40, 20); rim.position.set(-5, 2.5, -2); scene.add(rim); const fill = new THREE.PointLight(0x6a8cff, 18, 20); fill.position.set(5, -1, 3); scene.add(fill); // glow sprite texture const gc = document.createElement('canvas'); gc.width = gc.height = 64; const g2 = gc.getContext('2d')!; const gr = g2.createRadialGradient(32, 32, 0, 32, 32, 32); gr.addColorStop(0, 'rgba(255,255,255,1)'); gr.addColorStop(0.22, 'rgba(255,255,255,.55)'); gr.addColorStop(1, 'rgba(255,255,255,0)'); g2.fillStyle = gr; g2.fillRect(0, 0, 64, 64); const glowTex = new THREE.CanvasTexture(gc); const glow = (color: number, size: number) => { const s = new THREE.Sprite(new THREE.SpriteMaterial({ map: glowTex, color, blending: THREE.AdditiveBlending, transparent: true, depthWrite: false, opacity: 0 })); s.scale.set(size, size, 1); return s; }; // ---------------------------------------------------------- vault const metal = new THREE.MeshStandardMaterial({ color: 0x1a222b, metalness: 0.85, roughness: 0.32 }); const steel = new THREE.MeshStandardMaterial({ color: 0x8a99a8, metalness: 0.95, roughness: 0.22 }); const vault = new THREE.Group(); scene.add(vault); vault.add(new THREE.Mesh(new RoundedBoxGeometry(2.4, 2.4, 1.3, 5, 0.14), metal)); const frame = new THREE.Mesh(new THREE.TorusGeometry(1.02, 0.07, 16, 72), new THREE.MeshStandardMaterial({ color: COLORS.accent, emissive: COLORS.accent, emissiveIntensity: 0.6, metalness: 0.6, roughness: 0.3 })); frame.position.z = 0.66; vault.add(frame); const inside = new THREE.Mesh(new THREE.CircleGeometry(0.95, 48), new THREE.MeshBasicMaterial({ color: COLORS.gold, transparent: true, opacity: 0 })); inside.position.z = 0.651; vault.add(inside); const insideLight = new THREE.PointLight(COLORS.gold, 0, 8); insideLight.position.set(0, 0, 1.4); vault.add(insideLight); const hinge = new THREE.Group(); hinge.position.set(-0.95, 0, 0.74); vault.add(hinge); const door = new THREE.Group(); door.position.x = 0.95; hinge.add(door); const doorDisc = new THREE.Mesh(new THREE.CylinderGeometry(0.95, 0.95, 0.16, 64), steel); doorDisc.rotation.x = Math.PI / 2; door.add(doorDisc); const dial = new THREE.Group(); dial.position.z = 0.09; door.add(dial); dial.add(new THREE.Mesh(new THREE.TorusGeometry(0.34, 0.05, 12, 48), metal)); for (let i = 0; i < 3; i++) { const spoke = new THREE.Mesh(new THREE.BoxGeometry(0.62, 0.05, 0.05), metal); spoke.rotation.z = (i * Math.PI) / 3; dial.add(spoke); } dial.add(new THREE.Mesh(new THREE.CylinderGeometry(0.09, 0.09, 0.08, 24).rotateX(Math.PI / 2), steel)); // quorum lamps: one per required signature const lamps = Array.from({ length: M }, (_, i) => { const mat = new THREE.MeshStandardMaterial({ color: 0x24303a, emissive: COLORS.green, emissiveIntensity: 0, metalness: 0.3, roughness: 0.4 }); const lamp = new THREE.Mesh(new THREE.SphereGeometry(0.09, 20, 14), mat); lamp.position.set((i - (M - 1) / 2) * 0.36, 1.0, 0.66); const halo = glow(COLORS.green, 0.7); halo.position.copy(lamp.position); halo.position.z += 0.05; vault.add(lamp, halo); return { mat, halo }; }); const shieldMat = new THREE.MeshBasicMaterial({ color: COLORS.accent, wireframe: true, transparent: true, opacity: 0.05 }); const shield = new THREE.Mesh(new THREE.IcosahedronGeometry(2.25, 3), shieldMat); scene.add(shield); // floor const floorY = -1.55; const ringPts = Array.from({ length: 129 }, (_, i) => { const a = (i / 128) * Math.PI * 2; return new THREE.Vector3(Math.sin(a) * 3.4, floorY, Math.cos(a) * 3.4); }); scene.add(new THREE.Line(new THREE.BufferGeometry().setFromPoints(ringPts), new THREE.LineBasicMaterial({ color: COLORS.accent, transparent: true, opacity: 0.22 }))); const disc = glow(COLORS.accent, 9); disc.material.opacity = 0.07; disc.position.set(0, floorY, 0); scene.add(disc); // ----------------------------------------------------------- keys const keyBodyGeo = new RoundedBoxGeometry(0.62, 0.95, 0.16, 4, 0.06); const keys = Array.from({ length: N }, () => { const g = new THREE.Group(); const bodyMat = new THREE.MeshStandardMaterial({ color: 0x2a3440, metalness: 0.7, roughness: 0.35, transparent: true }); const screenMat = new THREE.MeshBasicMaterial({ color: COLORS.idle, transparent: true }); const btnMat = new THREE.MeshBasicMaterial({ color: 0x55626f, transparent: true }); const body = new THREE.Mesh(keyBodyGeo, bodyMat); const screen = new THREE.Mesh(new THREE.PlaneGeometry(0.46, 0.34), screenMat); screen.position.set(0, 0.17, 0.081); const btn = new THREE.Mesh(new THREE.CircleGeometry(0.07, 20), btnMat); btn.position.set(0, -0.23, 0.081); const halo = glow(COLORS.green, 1.9); g.add(body, screen, btn, halo); scene.add(g); return { g, bodyMat, screenMat, btnMat, halo, pos: new THREE.Vector3() }; }); // pulses (signatures in flight) const pulses = Array.from({ length: 4 }, () => { const s = glow(COLORS.green, 0.75); scene.add(s); const geo = new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(), new THREE.Vector3()]); const line = new THREE.Line(geo, new THREE.LineBasicMaterial({ color: COLORS.green, transparent: true, opacity: 0 })); scene.add(line); return { s, line, geo }; }); // coins const coinGeo = new THREE.CylinderGeometry(0.15, 0.15, 0.04, 28); const coinMat = new THREE.MeshStandardMaterial({ color: COLORS.gold, metalness: 1, roughness: 0.25, emissive: 0x3a2a00, transparent: true }); const coins = Array.from({ length: 14 }, () => { const c = new THREE.Mesh(coinGeo, coinMat); c.visible = false; scene.add(c); return c; }); // ------------------------------------------------------ interaction let ringOffset = 0, dragging = false, lastX = 0, px = 0, py = 0; const canvas = renderer.domElement; const onDown = (e: PointerEvent) => { dragging = true; lastX = e.clientX; canvas.setPointerCapture(e.pointerId); }; const onMove = (e: PointerEvent) => { const r = canvas.getBoundingClientRect(); px = ((e.clientX - r.left) / r.width) * 2 - 1; py = ((e.clientY - r.top) / r.height) * 2 - 1; if (dragging) { ringOffset += (e.clientX - lastX) * 0.01; lastX = e.clientX; } }; const onUp = () => { dragging = false; }; canvas.addEventListener('pointerdown', onDown); canvas.addEventListener('pointermove', onMove); canvas.addEventListener('pointerup', onUp); canvas.addEventListener('pointerleave', () => { px = 0; py = 0; }); let w = 0, h = 0; const resize = () => { w = el.clientWidth; h = el.clientHeight; renderer.setSize(w, h, false); camera.aspect = w / h; // keep the whole ring in frame on narrow screens camera.position.z = camBase.z * Math.max(1, 1.05 / camera.aspect); camera.updateProjectionMatrix(); }; const ro = new ResizeObserver(resize); ro.observe(el); resize(); let visible = true; const io = new IntersectionObserver(([e]) => { visible = e.isIntersecting; }, { threshold: 0.05 }); io.observe(el); // ------------------------------------------------------------ loop const tmp = new THREE.Vector3(), target = new THREE.Vector3(), doorTarget = new THREE.Vector3(0, 0, 0.85); const lastLabel: string[] = [], lastCls: string[] = []; let lastCounter = '', lastPhase = -1, ringAngle = 0, prev = performance.now(), raf = 0; const frameFn = (now: number) => { raf = requestAnimationFrame(frameFn); const dt = Math.min((now - prev) / 1000, 0.05); prev = now; if (!visible || document.hidden) return; const c = ctl.current; if (c.jump >= 0) { c.t = STARTS[c.jump] + (c.playing ? 0 : PHASES[c.jump].dur - 0.2); c.jump = -1; } if (c.playing) c.t = (c.t + dt) % TOTAL; let p = 0; while (p < PHASES.length - 1 && c.t >= STARTS[p + 1]) p++; const t = c.t - STARTS[p]; if (p !== lastPhase) { lastPhase = p; setPhase(p); } if (!reduced) ringAngle += dt * 0.12; camera.position.x += (camBase.x + px * 0.9 - camera.position.x) * 0.05; camera.position.y += (camBase.y - py * 0.6 - camera.position.y) * 0.05; camera.lookAt(0, -0.1, 0); // key placement keys.forEach((k, i) => { const a = ringAngle + ringOffset + (i / N) * Math.PI * 2; k.pos.set(Math.sin(a) * 3.4, -0.35 + Math.sin(now / 900 + i * 1.7) * 0.08, Math.cos(a) * 3.4); k.g.position.copy(k.pos); k.g.lookAt(camera.position); }); // per-key visual state const pulseList = PULSES[p]; keys.forEach((k, i) => { let color = COLORS.idle, halo = 0, op = 1, scale = 1, label = KEYS[i], cls = ''; const myPulse = pulseList.find((q) => q.key === i); if (p === 1 && i === STOLEN && t > 0.25) { color = COLORS.red; halo = 0.55 + 0.25 * Math.sin(now / 120); label = 'Stolen key'; cls = 'bad'; } if (p === 2 && myPulse && t > myPulse.start) { color = COLORS.green; halo = t < myPulse.start + myPulse.dur ? 0.85 : 0.35; label = `${KEYS[i].split(' ·')[0]} · signed`; cls = 'on'; } if (p === 3 && APPROVERS.includes(i)) { color = COLORS.green; halo = 0.3; label = `${KEYS[i].split(' ·')[0]} · signed`; cls = 'on'; } if (p === 4 && i === LOST) { if (t < 2.4) { op = 1 - 0.9 * ease(t / 1.3); color = COLORS.red; halo = 0.4 * (1 - ease(t / 1.3)); label = 'Lost device'; cls = 'lost'; } else { scale = ease((t - 2.4) / 0.8); color = COLORS.blue; halo = 0.6 * scale; label = 'Replacement key'; cls = 'new'; } } k.screenMat.color.setHex(color); k.halo.material.color.setHex(color); k.halo.material.opacity = halo; k.bodyMat.opacity = op; k.screenMat.opacity = op; k.btnMat.opacity = op; k.g.scale.setScalar(Math.max(scale, 0.001)); const lab = labels.current[i]; if (lab) { tmp.copy(k.pos); tmp.y += 0.78; tmp.project(camera); const behind = k.pos.z < -1.2; const half = lab.offsetWidth / 2 + 6; const lx = Math.min(Math.max(((tmp.x + 1) / 2) * w, half), w - half); lab.style.transform = `translate(-50%, -100%) translate(${lx}px, ${((1 - tmp.y) / 2) * h}px)`; lab.style.opacity = String((behind ? 0.35 : 1) * (cls === 'lost' ? Math.max(op, 0.6) : 1)); lab.style.zIndex = behind ? '1' : '3'; if (lastLabel[i] !== label) { lab.textContent = label; lastLabel[i] = label; } if (lastCls[i] !== cls) { lab.className = `scene3d-label ${cls}`; lastCls[i] = cls; } } }); // signatures in flight let arrived = 0, blockedHit = -1; pulses.forEach((pl, j) => { const q = pulseList[j]; const mat = pl.s.material, lm = pl.line.material as T.LineBasicMaterial; if (!q || t < q.start) { mat.opacity = 0; lm.opacity = 0; return; } const from = keys[q.key].pos; if (q.blocked) target.copy(from).normalize().multiplyScalar(2.25); else target.copy(doorTarget); const u = (t - q.start) / q.dur; const col = q.blocked ? COLORS.red : COLORS.green; mat.color.setHex(col); lm.color.setHex(col); if (u < 1) { tmp.lerpVectors(from, target, ease(u)); pl.s.position.copy(tmp); pl.s.scale.setScalar(0.75); mat.opacity = 1; const arr = pl.geo.attributes.position as T.BufferAttribute; arr.setXYZ(0, from.x, from.y, from.z); arr.setXYZ(1, tmp.x, tmp.y, tmp.z); arr.needsUpdate = true; lm.opacity = 0.55; } else { const f = clamp01((u - 1) * q.dur / 0.5); pl.s.position.copy(target); pl.s.scale.setScalar(0.75 + f * (q.blocked ? 2.2 : 1.2)); mat.opacity = 1 - f; lm.opacity = 0.55 * (1 - f); if (q.blocked) blockedHit = (u - 1) * q.dur; else arrived++; } }); // shield flash on rejection const flash = blockedHit >= 0 ? Math.exp(-blockedHit * 1.6) : 0; shieldMat.color.setHex(flash > 0.02 ? COLORS.red : COLORS.accent); shieldMat.opacity = 0.05 + flash * 0.5; shield.rotation.y += dt * 0.05; shield.rotation.x += dt * 0.02; // lamps and counter const lit = p === 2 ? arrived : p === 3 ? M : 0; lamps.forEach((l, i) => { const on = i < lit; l.mat.emissiveIntensity += ((on ? 2.2 : 0) - l.mat.emissiveIntensity) * 0.2; l.halo.material.opacity += ((on ? 0.8 : 0) - l.halo.material.opacity) * 0.2; }); let text = `0 of ${M} signatures`; if (p === 1) text = blockedHit >= 0 ? `1 of ${M} · rejected` : `0 of ${M} signatures`; if (p === 2) text = `${arrived} of ${M} signatures`; if (p === 3) text = `${M} of ${M} · released`; if (p === 4) text = t < 2.4 ? `${N - 1} keys left · ${M} needed` : `${N} of ${N} keys · restored`; if (counter.current) { tmp.set(0, 1.55, 0.6).project(camera); counter.current.style.transform = `translate(-50%, -100%) translate(${((tmp.x + 1) / 2) * w}px, ${((1 - tmp.y) / 2) * h}px)`; if (text !== lastCounter) { counter.current.textContent = text; lastCounter = text; counter.current.className = `scene3d-counter ${p === 1 && blockedHit >= 0 ? 'bad' : p === 3 || (p === 2 && arrived === M) ? 'on' : ''}`; } } // door, vault interior, dial const open = p === 3 ? ease(t / 1.2) : p === 4 ? 1 - ease(t / 0.8) : 0; hinge.rotation.y = -1.9 * open; (inside.material as T.MeshBasicMaterial).opacity = open; insideLight.intensity = open * 12; dial.rotation.z += dt * (p === 2 ? 4 : 0.4); // coins coins.forEach((coin, i) => { const s = p === 3 ? (t - 0.9 - i * 0.17) / 1.6 : -1; if (s < 0 || s > 1) { coin.visible = false; return; } coin.visible = true; const ex = 2.6 + (i % 3) * 0.45, ey = -0.9 + (i % 4) * 0.3, ez = 3.0 + (i % 2) * 0.6; const e = ease(s); coin.position.set(ex * e, ey * e + Math.sin(Math.PI * s) * 1.3, 0.8 + (ez - 0.8) * e); coin.rotation.set(now / 300 + i, now / 400, 0); coin.scale.setScalar(s > 0.8 ? 1 - (s - 0.8) / 0.2 : 1); }); renderer.render(scene, camera); }; raf = requestAnimationFrame(frameFn); cleanup = () => { cancelAnimationFrame(raf); ro.disconnect(); io.disconnect(); canvas.removeEventListener('pointerdown', onDown); canvas.removeEventListener('pointermove', onMove); canvas.removeEventListener('pointerup', onUp); scene.traverse((o: any) => { o.geometry?.dispose?.(); const m = o.material; (Array.isArray(m) ? m : m ? [m] : []).forEach((x: any) => x.dispose?.()); }); glowTex.dispose(); envTex.dispose(); pmrem.dispose(); renderer.dispose(); canvas.remove(); }; })(); return () => { disposed = true; cleanup(); }; }, []); const go = (i: number) => { ctl.current.jump = i; setPhase(i); }; const toggle = () => { ctl.current.playing = !ctl.current.playing; setPlaying(ctl.current.playing); }; return (
{failed &&

3D view needs WebGL. The steps below explain the same story.

}
{PHASES.map((ph, i) => ( ))}
{PHASES[phase].title}

{PHASES[phase].text}

); }