Files
ssw-mvp/demo/hello/index.html
T
admin a602e0cc0b feat(demo): 尚数网算子集市 — 12 个 nax 算子可视化(PSI/SCQL/PIR/LR/FedAvg/MLP/binning/audit/hello/dry_run/k8s)
- `demo/` 统一入口:server.py (Flask 30000→18850) + index.html (导航页 + 尚数网 logo + 3 段 L1/L2/L3/L4 卡片)
- 12 个子模块:psi / scql / pir / vertical_lr / horizontal_fedavg / dp_fedavg / secure_mlp / hetero_binning / policy_audit / hello / dry_run / k8s_two_party
  - 每个子模块 `{__init__.py, app.py, index.html}` 蓝图模式
  - 共享 `_shared/demo.css` 暗色主题
- 八大算子用 nax 真接口(Crypto PSI / Lattice PIR / Paillier 等)跑,跨三方不直接给用户看的中间数据
- PSI 重点演示:7 阶段动画 (hash → 自盲 → 传输 → 重盲 → 比较 → 求交 → 输出) + 6 列状态表 + manual/nax_data/compare 3 路径
- 场景:两家银行 VIP 客户姓名 + 存款场景,A 行 + B 行存款相加 = 共同客户总存款
- 启动:cd demo && python server.py  → http://0.0.0.0:18850/

gitignore: 过滤 demo/**/screenshots/(playwright 验证产物)
2026-08-11 10:26:46 +08:00

102 lines
4.5 KiB
HTML

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hello MPC · 尚数网算子集市</title>
<link rel="icon" type="image/png" href="https://shangshuwang.cn/images/logo-white-data.png" />
<link rel="stylesheet" href="/_shared/demo.css" />
<style>
.row3 { display:grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.vec-cell { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; font-family: var(--mono); font-size: 12px; }
.vec-cell .head { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; }
.vec-cell.alice .head { color: var(--alice); }
.vec-cell.bob .head { color: var(--bob); }
.vec-cell.carol .head { color: var(--text-dim); }
.vec-cell .val { color: var(--text); }
.vec-cell .share { color: var(--text-faint); font-size: 11px; margin-top: 4px; }
</style>
</head>
<body>
<div class="topbar">
<a href="/" class="back"><img src="https://shangshuwang.cn/images/logo-white-data.png" alt="尚数网"/></a>
<h1>Hello MPC <small>· 三方密文算术入门</small></h1>
<span style="flex:1"></span>
<a href="/" class="back">← 算子集市</a>
</div>
<main>
<div class="row3">
<div class="panel">
<h2>三方明文输入</h2>
<label>alice 向量</label>
<input type="text" id="a-input" value="1.5, -2.0, 3.25, 0.5" />
<label style="margin-top:8px">bob 向量</label>
<input type="text" id="b-input" value="2.0, 4.0, -1.0, 8.0" />
<label style="margin-top:8px">carol 向量(仅参与方,不参与本次运算)</label>
<input type="text" id="c-input" value="0.5, 1.5, 2.0, -0.5" />
<div class="button-row">
<button id="btn-run" class="primary">▶ 计算 z = x·y + 1.0</button>
</div>
<p class="small-note">后端 <code>POST /hello/api/run</code>。<code>site.put</code> 把数据留在本地;<code>vault.share</code> 切成加性分片;密文四则运算;<code>reveal(to="alice")</code> 一次性出域给 alice。</p>
</div>
<div class="panel">
<h2>share 阶段</h2>
<div class="row3" id="share-stages">
<div class="vec-cell alice"><div class="head">alice 持有</div><div class="val" id="alice-share">—</div></div>
<div class="vec-cell bob"><div class="head">bob 持有</div><div class="val" id="bob-share">—</div></div>
<div class="vec-cell carol"><div class="head">carol 持有</div><div class="val" id="carol-share">—</div></div>
</div>
<p class="small-note">每行展示加性分片(生产中拿不到,这里只作演示)。三片之和 = 原始向量。</p>
</div>
<div class="panel">
<h2>密文运算 + reveal</h2>
<div class="vec-cell" style="background: rgba(77,139,255,0.10); border-color: var(--alice);">
<div class="head alice">reveal to alice</div>
<div class="val alice" id="reveal-result" style="font-size: 14px;">—</div>
</div>
<p class="small-note" id="compare-note">—</p>
</div>
</div>
</main>
<script>
const $ = s => document.querySelector(s);
let state = {};
function fmtArr(a) { return '[' + a.map(v => Number.isInteger(v) ? v : v.toFixed(3)).join(', ') + ']'; }
async function runHello() {
const body = {
a: $('#a-input').value.split(',').map(s => parseFloat(s.trim())),
b: $('#b-input').value.split(',').map(s => parseFloat(s.trim())),
c: $('#c-input').value.split(',').map(s => parseFloat(s.trim())),
};
$('#btn-run').disabled = true;
try {
const r = await fetch('/hello/api/run', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(body) });
if (!r.ok) throw new Error('HTTP ' + r.status);
state = await r.json();
const shares = state.stages.s1_share.shares_x;
$('#alice-share').textContent = fmtArr(shares.alice) + ' …';
$('#bob-share').textContent = fmtArr(shares.bob) + ' …';
$('#carol-share').textContent = fmtArr(shares.carol) + ' …';
$('#reveal-result').textContent = fmtArr(state.stages.s3_reveal.value);
const dev = state.stages.s4_compare.max_deviation;
$('#compare-note').innerHTML = `明文对照: <code>${fmtArr(state.stages.s4_compare.plain)}</code>,最大偏差 ${dev.toExponential(2)}`;
} catch (e) {
alert('失败:' + e.message);
} finally {
$('#btn-run').disabled = false;
}
}
window.addEventListener('DOMContentLoaded', () => {
$('#btn-run').addEventListener('click', runHello);
});
</script>
</body>
</html>