[share] Share links and the browser build: custos-share (blob v1, key in the fragment, optional password), custos-wasm (JSON ABI, no wasm-bindgen), docs/SHARE.md, threat model (v0.3.0)

This commit is contained in:
2026-10-31 18:20:51 +01:00
parent 4aac99fb47
commit 5ee1c0da6b
16 changed files with 1153 additions and 5 deletions
+32
View File
@@ -0,0 +1,32 @@
// node test.mjs <custos_wasm.wasm> [<vault file> <password>]: the JS loader against the real build.
import fs from 'node:fs';
import { loadCustos, toBase64 } from './custos.mjs';
const [wasmPath, vaultPath, password] = process.argv.slice(2);
const c = await loadCustos(fs.readFileSync(wasmPath));
const assert = (ok, msg) => { if (!ok) { console.error('FAIL', msg); process.exit(1); } };
const bad = c.call({ op: 'share_open', blob: 'Q1NIMQA=', fragment: 'k=x' });
assert(!bad.ok && bad.code === 'Malformed', JSON.stringify(bad));
assert(c.call({ op: 'items' }).error === 'The vault is locked.', 'locked');
if (vaultPath) {
const t0 = performance.now();
const r = c.call({ op: 'open', vault: toBase64(fs.readFileSync(vaultPath)), password });
const ms = Math.round(performance.now() - t0);
assert(r.ok, r.error);
console.log(`unlocked ${r.items.length} items in ${ms} ms (WebAssembly, default KDF)`);
const item = r.items.find((i) => i.hasMainSecret);
for (const pw of [null, 'by-phone']) {
const t1 = performance.now();
const s = c.call({ op: 'share_seal', id: item.id, password: pw });
assert(s.ok, s.error);
const o = c.call({ op: 'share_open', blob: s.blob, fragment: s.fragment, password: pw });
assert(o.ok && o.payload.title === item.title, JSON.stringify(o.error));
console.log(`share ${pw ? 'with' : 'without'} password: sealed and opened in ${Math.round(performance.now() - t1)} ms`);
}
const fresh = new Set(Array.from({ length: 100 }, () => c.call({ op: 'share_seal', id: item.id }).fragment));
assert(fresh.size === 100, 'link keys repeat: random_fill is broken');
c.call({ op: 'lock' });
}
console.log('ok');