/**
* THE interop invariant: the OrbitDB address this build opens must be
* byte-for-byte the address the deployed TypeScript build opens, and the one
* every other member derives (PROTOCOL.md §5).
*
* It is the CID of the manifest {name, type, accessController}: a pure function
* of the secret-derived dbName and the hardened access controller's own address.
* Nothing is exchanged to agree on it, and nothing fails loudly if it diverges —
* a diverged build just replicates a database nobody else is in.
*
* So this boots the real stack (libp2p v2, Helia on the IndexedDB blockstore the
* browser build uses, @orbitdb/core with entry+payload encryption and the sueta
* identity provider) and compares the strings against
* test/vectors/orbit-address.json, extracted from the TypeScript by
* test/vectors/generate-orbit-address.mjs.
*
* Needs the libdatachannel native addon (helia's graph pulls @libp2p/webrtc).
* `npm install` fetches it; if it is missing, run
* (cd node_modules/@ipshipyard/node-datachannel && npx prebuild-install -r napi)
*/
import { test } from "node:test";
import assert from "node:assert/strict";
import { installDom } from "./harness/dom.mjs";
import { mods, readVector } from "./helpers/load.mjs";
installDom();
const M = await mods();
const { addressCases, openAddressCase, SEED } = await import("./helpers/orbit-address.mjs");
test("the OrbitDB address matches the TypeScript build byte-for-byte", async () => {
const expected = readVector("orbit-address");
assert.equal(expected.length, addressCases.length);
for (let i = 0; i < addressCases.length; i++) {
const got = await openAddressCase(M, addressCases[i]);
assert.deepEqual(got, expected[i], `case ${i}: ${addressCases[i].appSalt}`);
assert.match(got.address, /^\/orbitdb\/zdpu/);
}
// identity-less and identity-carrying members open the SAME database: the
// manifest hashes only {name, type, accessController}, never the creator
assert.equal(expected[0].address, expected[1].address);
// a different app salt is a different room even with the same secret
assert.notEqual(expected[0].address, expected[2].address);
// and the sueta identity is what authorship chains to
assert.equal(expected[0].seed, SEED);
assert.match(expected[0].myAuthorId, /^[A-Za-z0-9_-]{43}$/);
});
test("the address agrees with rooms-kit's independently generated fixture", () => {
// rooms-kit generated its orbit-address.json from its OWN (byte-identical
// ancestor) TypeScript, on a filesystem blockstore, in a different repo. Two
// independent extractions landing on the same string is the strongest
// available evidence that the deployed browsers derive it too.
const mine = readVector("orbit-address");
assert.equal(mine[0].address, "/orbitdb/zdpuAss8b52EWFgwGv4F2b96pN1Z1teDXd8j9wa8toDV3VH1a");
assert.equal(mine[0].dbName, "NebUR6HrhA5rG70qD-5X-4c1DHBuiWRm0nR-wdSAjls");
assert.equal(mine[2].address, "/orbitdb/zdpuAkwUfBWM3JVzCgooRhmjhDzRrNzz5kFugxfbDovvmZSAw");
});