chat / client / test / vectors / generate-orbit-address.mjs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
 * The one interop invariant this port cannot get wrong: the OrbitDB address.
 *
 *   SUETA_TS=1 node test/vectors/generate-orbit-address.mjs
 *
 * PROTOCOL.md §5 — "every member independently computes the same address" — the
 * CID of the manifest {name, type, accessController}. If the port derived a
 * different dbName, or the hardened controller's manifest drifted from the
 * vanilla one, every CLJS client would silently open a DIFFERENT database from
 * every deployed browser in the room: no error, no missing message, just two
 * disjoint histories.
 *
 * Not reachable from any pure function — it needs a real libp2p, a real Helia
 * and a real @orbitdb/core open. So this boots the TypeScript build through
 * helpers/orbit-address.mjs and records what it produces;
 * test/orbit-address.test.mjs boots the ClojureScript build the same way and
 * demands the same strings.
 */
import { writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { installDom } from "../harness/dom.mjs";

installDom();

const { mods, TS_MODE } = await import("../helpers/load.mjs");
if (!TS_MODE) throw new Error("run with SUETA_TS=1: fixtures come from the TypeScript, never from the port");
const M = await mods();
const { addressCases, openAddressCase } = await import("../helpers/orbit-address.mjs");

const OUT = dirname(fileURLToPath(import.meta.url));
const out = [];
for (const c of addressCases) {
  out.push(await openAddressCase(M, c));
  console.log(`${c.appSalt} identity=${c.withIdentity}: ${out.at(-1).address}`);
}
writeFileSync(join(OUT, "orbit-address.json"), `${JSON.stringify(out, null, 2)}\n`);
console.log("wrote orbit-address.json");
process.exit(0);

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/chat.git