`;
let plansRow = "";
try {
const pl = JSON.parse(await readFile(join(ROOT, "web/app/deploy-plans-4663.json"), "utf8")), ex = "https://explorer.mainnet.chain.robinhood.com";
plansRow = `
Token utility
Plans and HASHFORT
Contract
Address
Verified source
Robinhood Chain · HashfortPlans
Pro ${Number(pl.proPrice) / 1e6} USDG and Team ${Number(pl.teamPrice) / 1e6} USDG per 30 days, paid straight to the treasury. planOf() gives Pro to any account holding ${(BigInt(pl.holderThreshold) / 10n ** 18n).toLocaleString("en-US")} HASHFORT.
The contracts, the signing code and the app, as served right now, with their SHA-256 so anyone can compare what runs on chain and in the browser.
On chain
Deployed contracts
Contract
Address
Verified source
${deployed}
${plansRow}
In use
Vaults on Robinhood Chain
Every vault the factories created, read from the chain now (VaultCreated), and how many vault-key operations each has run (Executed: a hash-based signature the contract verified).
Vault
Created in
Vault-key operations
${vrows}
Source
Files
File
Lines
SHA-256
${rows.join("")}
Build
Compile it yourself
solc 0.8.24, optimizer on, 10,000 runs, evmVersion shanghai
v3 primary key ML-DSA-65 (FIPS 204): q = 8380417, (k, l) = (6, 5), signature 3,309 B, public key 1,952 B; SHAKE128/256 in Yul
v3 recovery key SLH-DSA-SHA2-128s (FIPS 205): n = 16, h = 63, d = 7, a = 12, k = 14; signature 7,856 B; SHA-256 precompile
Standard key HashSig: WOTS+ n = 32 bytes, w = 16, 67 chains, Merkle height 10 (1,024 one-time keys); keccak256 with tweaks
Test suite: 40 tests (Hardhat): signatures, replay, forgery, expiry, limits, rotation, guardians, factory, agent keys, Sentinel freeze,\nML-DSA-65 and SLH-DSA-SHA2-128s verifiers against browser-made signatures, v3 vaults (primary key, recovery delay, guardians)
`;
}
// Free audit for the app: 30 an hour per address; the plain-language summary (if the AI is on) 15 a day per address.
const hits = new Map();
const allow = (key, n, ms) => { const now = Date.now(), xs = (hits.get(key) || []).filter((t) => now - t < ms); if (xs.length >= n) return false; xs.push(now); hits.set(key, xs); if (hits.size > 20000) hits.clear(); return true; };
async function freeAudit(req) {
const ip = ipOf(req), body = await jsonBody(req);
if (!allow("audit:" + ip, 30, 3600_000)) throw Object.assign(new Error("Too many audits from this address. Try again later."), { status: 429 });
const report = await S.audit(body);
let paidTier = 0;
if (body.explain && AI.configured() && ethers.isAddress(body.vault || "")) {
const own = await new ethers.Contract(body.vault, ["function owner() view returns (address)"], provider(Number(body.chainId) || 4663)).owner().catch(() => null);
paidTier = (await S.tierOf([body.vault, own])).tier;
}
if (body.explain && AI.configured() && paidTier < 1) report.explanation = null, report.explainNote = "The plain-language AI summary is a Pro feature (buy Pro, or hold HASHFORT). The checks above are complete on every plan.";
else if (body.explain && AI.configured()) {
if (allow("explain:" + ip, 15, 86400_000)) report.explanation = await AI.explainAudit(report).catch((e) => "(summary unavailable: " + e.message + ")");
else report.explanation = "(daily summary limit reached; the checks above are complete)";
}
report.ai = AI.configured();
return report;
}
async function agentRoute(req, url) {
const k = `${req.method} ${url.pathname}`;
if (k === "GET /api/sentinel/public") return { address: A.sentinelAddress(), x402: S.x402Status(), ai: AI.configured(), usdg: S.usdgOf(Number(url.searchParams.get("chain")) || 4663) };
if (k === "GET /api/agents/session") {
const chainId = Number(url.searchParams.get("chain")), vault = ethers.getAddress(url.searchParams.get("vault") || ""), issued = Math.floor(Date.now() / 1000);
return { issued, message: A.sessionMessage(chainId, vault, issued) };
}
if (req.method !== "POST") throw Object.assign(new Error("Not found."), { status: 404 });
const body = await jsonBody(req);
const route = {
"/api/agents/create": A.createAgent, "/api/agents/list": A.listAgents, "/api/agents/memory": A.setMemory, "/api/agents/forget": A.forgetAgent, "/api/agents/run": A.runAgent,
"/api/sentinel/get": A.sentinelGet, "/api/sentinel/set": A.sentinelSet, "/api/sentinel/subscribe": A.pushSubscribe,
"/api/team/vaults": (r, b) => A.teamVaults(r, b, async () => Object.entries((await liveVaults()).vaults).map(([vault, v]) => ({ vault, ...v }))),
}[url.pathname];
if (!route) throw Object.assign(new Error("Not found."), { status: 404 });
return route(req, body);
}
const send = (res, code, body, type = "application/json") => {
const cache = type.startsWith("application/json") ? "no-store" : type.startsWith("text/html") ? "no-cache" : "public, max-age=300";
const h = { "content-type": type, "cache-control": cache, "x-content-type-options": "nosniff", "referrer-policy": "strict-origin-when-cross-origin" };
if (type.startsWith("image/")) { h["access-control-allow-origin"] = "*"; h["cross-origin-resource-policy"] = "cross-origin"; if (Buffer.isBuffer(body)) h["content-length"] = body.length; }
res.writeHead(code, h);
res.end(typeof body === "string" || Buffer.isBuffer(body) ? body : JSON.stringify(body));
};
http.createServer(async (req, res) => {
const url = new URL(req.url, "http://x");
try {
if (url.pathname === "/api/chain") return send(res, 200, await chain());
if (url.pathname === "/api/rpc" && req.method === "POST") return send(res, 200, await rpcProxy(req, Number(url.searchParams.get("chain")) || 4663));
if (url.pathname === "/api/deployments") return send(res, 200, await deployments());
if (url.pathname === "/api/token") return send(res, 200, await token());
if (url.pathname.startsWith("/api/studio/")) return send(res, 200, await studio(req, url.pathname));
if (url.pathname === "/api/relay/status") { await deployments(); return send(res, 200, await R.publicStatus(Number(url.searchParams.get("chain")))); }
if (url.pathname === "/api/relay" && req.method === "POST") { await deployments(); return send(res, 200, await R.relay(await jsonBody(req), ipOf(req))); }
if (url.pathname === "/studio") {
res.writeHead(200, { "content-type": "text/html; charset=utf-8", "cache-control": "no-cache", "x-robots-tag": "noindex", "x-frame-options": "DENY", "referrer-policy": "no-referrer", "x-content-type-options": "nosniff" });
return res.end(await readFile(join(ROOT, "web", "studio.html")));
}
if (url.pathname === "/api/scan") return send(res, 200, await scan(url.searchParams.get("address") || ""));
if (url.pathname === "/api/audit" && req.method === "POST") { await deployments(); return send(res, 200, await freeAudit(req)); }
if (url.pathname === "/api/live") { // proof of use: vaults the factories made and the vault-key operations the contracts verified
const lv = await liveVaults(), list = Object.entries(lv.vaults);
const withExec = list.filter(([, v]) => v.last).sort((a, b) => b[1].block - a[1].block);
return send(res, 200, { chainId: 4663, vaults: list.length, vaultKeyOperations: list.reduce((n, [, v]) => n + v.executes, 0), scannedTo: lv.to,
latest: withExec[0] ? { vault: withExec[0][0], createdTx: withExec[0][1].created, executeTx: withExec[0][1].last, version: withExec[0][1].version } : null });
}
if (url.pathname === "/x402" || url.pathname === "/.well-known/x402") { await deployments(); return send(res, 200, S.x402Status()); }
if (url.pathname.startsWith("/api/proof/tx/")) { await deployments(); return send(res, 200, await S.proofTx(url.pathname.slice(14))); }
if (url.pathname === "/api/proof/demo") {
const list = await deployments(), d = list.find((x) => x.chainId === 4663 && x.v3);
if (!d) return send(res, 503, { error: "v3 is not deployed" });
if (!allow("proof:" + ipOf(req), 12, 600_000)) return send(res, 429, { error: "Too many proofs from this address; try again in a few minutes." });
return send(res, 200, await S.proofDemo({ verifierMl: d.v3.mldsa, verifierSlh: d.v3.slhdsa }));
}
if (url.pathname === "/api/exposure") return send(res, 200, X.view());
if (url.pathname === "/api/plans") { await deployments(); return send(res, 200, S.plansInfo()); }
if (url.pathname === "/api/plan") { await deployments(); const a = (url.searchParams.get("address") || "").split(",").filter(Boolean); return send(res, 200, { ...(await S.tierOf(a)), checked: a }); }
if (url.pathname === "/api/holder") { await deployments(); return send(res, 200, await S.holderStatus(url.searchParams.get("address") || "")); }
if (url.pathname === "/api/holder/message") { const a = url.searchParams.get("address") || ""; if (!ethers.isAddress(a)) return send(res, 400, { error: "address required" }); const issued = Math.floor(Date.now() / 1000); return send(res, 200, { issued, message: S.holderMessage(ethers.getAddress(a), issued) }); }
if (url.pathname === "/x402/exposure" && req.method === "POST") {
const body = await jsonBody(req), list = (body.addresses || []).map((x) => String(x).trim()).filter(Boolean);
if (!list.length || list.length > 20) return send(res, 400, { error: "Send 1 to 20 addresses." });
for (const a of list) if (!/^0x[0-9a-fA-F]{40}$/.test(a) && !btcType(a)) return send(res, 400, { error: `Not an EVM or Bitcoin address: ${a}` });
const paid = await S.gate(req, res, "exposure", url.href); if (!paid) return;
const results = [];
for (const a of list) results.push(/^0x/.test(a) ? { address: a, kind: "evm", results: await scanEvm(a, true) } : { address: a, kind: "bitcoin", results: await scanBtc(a) });
const exposed = results.filter((r) => r.results.some((x) => x.status === "exposed")).length;
return send(res, 200, { service: "exposure", at: new Date().toISOString(), paidBy: paid.from, paymentTx: paid.txHash, holderAccess: !!paid.holder, summary: { addresses: list.length, exposed, hidden: list.length - exposed }, results });
}
if (url.pathname === "/x402/audit" && req.method === "POST") {
await deployments(); const body = await jsonBody(req);
const report = await S.audit(body); // validate before taking payment
const paid = await S.gate(req, res, "audit", url.href); if (!paid) return;
if (AI.configured()) report.explanation = await AI.explainAudit(report).catch((e) => "(summary unavailable: " + e.message + ")");
return send(res, 200, { ...report, paidBy: paid.from, paymentTx: paid.txHash });
}
if (url.pathname.startsWith("/api/agents/") || url.pathname.startsWith("/api/sentinel/")) { await deployments(); return send(res, 200, await agentRoute(req, url)); }
if (url.pathname === "/code" || url.pathname === "/code/") return send(res, 200, await codePage(), "text/html; charset=utf-8");
let file;
if (url.pathname.startsWith("/code/")) {
const name = url.pathname.slice(6);
const known = CODE.map(([f]) => f).find((f) => f.split("/").pop() === name);
if (!known) return send(res, 404, { error: "not found" });
file = join(ROOT, known);
return send(res, 200, await readFile(file), "text/plain; charset=utf-8");
} else {
const p = normalize(decodeURIComponent(url.pathname)).replace(/^(\.\.[/\\])+/, "");
file = join(ROOT, "web", p.endsWith("/") ? p + "index.html" : p);
if (!file.startsWith(join(ROOT, "web"))) return send(res, 403, { error: "forbidden" });
}
const body = await readFile(file), type = TYPES[extname(file)] || "application/octet-stream";
const range = /^bytes=(\d*)-(\d*)$/.exec(req.headers.range || "");
if (range && type.startsWith("video/")) { // Safari only plays video served with byte ranges
const size = body.length;
let start = range[1] === "" ? size - Number(range[2]) : Number(range[1]);
let end = range[1] === "" || range[2] === "" ? size - 1 : Math.min(Number(range[2]), size - 1);
if (!(start >= 0 && start <= end && end < size)) { res.writeHead(416, { "content-range": `bytes */${size}` }); return res.end(); }
res.writeHead(206, { "content-type": type, "content-length": end - start + 1, "content-range": `bytes ${start}-${end}/${size}`, "accept-ranges": "bytes", "cache-control": "public, max-age=86400" });
return res.end(body.subarray(start, end + 1));
}
if (type.startsWith("video/")) res.setHeader("accept-ranges", "bytes");
send(res, 200, body, type);
} catch (e) {
if (e.code === "ENOENT" || e.code === "EISDIR") return send(res, 404, { error: "not found" });
send(res, e.status || 502, { error: e.message });
}
}).listen(PORT, process.env.HOST || "127.0.0.1", () => { console.log(`http://${process.env.HOST || "127.0.0.1"}:${PORT}`); deployments().then(() => A.startWatcher(Number(process.env.SENTINEL_MS) || 20_000)).catch((e) => console.error(e));
if (!process.env.HF_LOCAL) T.publicView().then((pv) => X.start(pv.live && pv.ca ? [{ address: pv.ca, symbol: pv.symbol || "HASHFORT", name: "Hashfort Vault" }] : [])).catch(() => X.start()); });