board / client / test / orbit-address.test.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
 * 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 the two independently generated fixtures", () => {
  // rooms-kit and chat each generated their own orbit-address.json from their
  // OWN (byte-identical ancestor) TypeScript, one on a filesystem blockstore and
  // one on IndexedDB, in different repos. THREE independent extractions landing
  // on the same string is the strongest available evidence that the deployed
  // browsers derive it too.
  const mine = readVector("orbit-address");
  // board's own room, the string every deployed board client must open
  assert.equal(mine[0].address, "/orbitdb/zdpuAkwUfBWM3JVzCgooRhmjhDzRrNzz5kFugxfbDovvmZSAw");
  assert.equal(mine[0].dbName, "ru7ohY_tFNM65DW8Kh2RtrQLgWFk3Y8HsMIldhW6ja4");
  // and chat's room under the same secret machinery — a different app salt is a
  // different database, which is the whole point of APP_SALT
  assert.equal(mine[2].address, "/orbitdb/zdpuAss8b52EWFgwGv4F2b96pN1Z1teDXd8j9wa8toDV3VH1a");
  assert.equal(mine[2].dbName, "NebUR6HrhA5rG70qD-5X-4c1DHBuiWRm0nR-wdSAjls");
});

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