sigelo-contact 0.1.21 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/GROUPS-REFERENCE.md +165 -0
  2. package/GROUPS.md +53 -0
  3. package/LICENSE +235 -21
  4. package/README.md +4 -5
  5. package/call.mjs +89 -28
  6. package/carrier.mjs +230 -51
  7. package/control.mjs +2 -2
  8. package/create.mjs +2 -2
  9. package/device.mjs +2 -2
  10. package/enrol.mjs +2 -2
  11. package/envelope.mjs +6 -6
  12. package/file.mjs +2 -2
  13. package/fixtures/carrier-v0.json +1 -1
  14. package/fixtures/envelope-v0.json +1 -1
  15. package/fixtures/group-v2.json +2999 -0
  16. package/gen-carrier.mjs +2 -2
  17. package/gen-device.mjs +1 -1
  18. package/gen-envelope.mjs +2 -2
  19. package/gen-group2.mjs +291 -0
  20. package/gen-invite.mjs +2 -2
  21. package/gen-short.mjs +1 -1
  22. package/group.mjs +116 -17
  23. package/group2.mjs +1534 -0
  24. package/home-wire.mjs +812 -0
  25. package/invite.mjs +3 -3
  26. package/kdf.mjs +2 -2
  27. package/kin.mjs +62 -0
  28. package/link.mjs +6 -6
  29. package/package.json +25 -8
  30. package/page.mjs +542 -63
  31. package/photo.mjs +2 -2
  32. package/platform-node.mjs +6 -6
  33. package/prekeys.mjs +3 -3
  34. package/public.mjs +2 -2
  35. package/qr-decode.mjs +1 -1
  36. package/qr.mjs +2 -2
  37. package/relays.mjs +2 -2
  38. package/restore.mjs +2 -2
  39. package/rtc-web.mjs +3 -3
  40. package/short.mjs +2 -2
  41. package/store.mjs +22 -9
  42. package/test-carrier.mjs +32 -11
  43. package/test-device.mjs +3 -3
  44. package/test-enrol.mjs +9 -4
  45. package/test-envelope.mjs +2 -2
  46. package/test-file.mjs +2 -2
  47. package/test-group-move.mjs +225 -0
  48. package/test-group.mjs +1 -1
  49. package/test-group2.mjs +202 -0
  50. package/test-home.mjs +225 -0
  51. package/test-invite.mjs +1 -1
  52. package/test-link.mjs +3 -3
  53. package/test-platform.mjs +2 -2
  54. package/test-presence.mjs +2 -2
  55. package/test-push.mjs +5 -5
  56. package/test-relay-lane.mjs +3 -3
  57. package/test-short.mjs +1 -1
  58. package/test-tier.mjs +8 -2
  59. package/test-transfer-web.mjs +15 -7
  60. package/test-transfer.mjs +24 -6
  61. package/test-voice.mjs +2 -2
  62. package/test-ws.mjs +1 -1
  63. package/transfer-engine.mjs +46 -16
  64. package/transfer-node.mjs +9 -7
  65. package/transfer-web.mjs +4 -4
  66. package/transfer.mjs +8 -8
  67. package/voice-web.mjs +2 -2
  68. package/voice.mjs +7 -3
  69. package/words-lock.mjs +2 -2
package/test-home.mjs ADDED
@@ -0,0 +1,225 @@
1
+ #!/usr/bin/env node
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ // Home groups end to end (group2.mjs over carrier.mjs home(), sigelo-group/2 on sigelo-home/0), on two
4
+ // loopback relays with one clock: A (own relay R1) makes a group homed at R1 and a link; B (own relay
5
+ // R2) joins by the GRP code, approved at once (auto); C (own relay R1) joins by the long invite, approved
6
+ // by A; they chat; reactions, an edit, a poll and votes, a pin; A makes its agent B admin (ruling 15)
7
+ // and B, an admin, may not make another agent admin; A kicks C: the renewal (epoch 2) reaches A and B,
8
+ // not C, whose open ends; a forged sender is refused by name; D joins under history "always" and reads
9
+ // the old messages; an admin made after a link reads its requests, and made member again reads none. Prints "ALL PASS (n)".
10
+ // node test-home.mjs
11
+ import { createHash } from 'node:crypto';
12
+ import { existsSync, mkdtempSync, readFileSync } from 'node:fs';
13
+ import { tmpdir } from 'node:os';
14
+ import { dirname, join } from 'node:path';
15
+ import { fileURLToPath, pathToFileURL } from 'node:url';
16
+ import { keygen } from 'sigelo';
17
+ import * as G2 from './group2.mjs';
18
+
19
+ const HERE = dirname(fileURLToPath(import.meta.url));
20
+ let count = 0;
21
+ const fails = [];
22
+ const ok = (cond, what, more) => { count++; console.log(`${cond ? 'ok ' : 'FAIL'} ${what}`); if (!cond) fails.push(more === undefined ? what : `${what} (${String(more).slice(0, 900)})`); };
23
+ const failure = async (f) => { try { await f(); return 'accepted'; } catch (e) { return e.check ?? `exception ${e.stack}`; } };
24
+ const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', '..', 'relay');
25
+ if (!existsSync(join(RELAY_DIR, 'server.mjs')) || !existsSync(join(RELAY_DIR, 'node_modules'))) { console.log('ALL PASS (0): SKIP, no relay checkout beside apps/contact/ (SIGELO_RELAY_DIR)'); process.exit(0); }
26
+ setTimeout(() => { console.log(`FAIL the run did not finish in 900 s (${count} checks so far)`); process.exit(1); }, 900000).unref();
27
+ const { startRelay } = await import(pathToFileURL(join(RELAY_DIR, 'server.mjs')).href);
28
+ const { relayPolicy } = await import(pathToFileURL(join(RELAY_DIR, 'allowance.mjs')).href);
29
+ const { Carrier, pathsFor } = await import('./carrier.mjs');
30
+
31
+ const CREATED = '2026-10-01T00:00:00Z';
32
+ let now = Math.floor(Date.now() / 1000);
33
+ setInterval(() => { now = Math.floor(Date.now() / 1000); }, 200).unref();
34
+ const seed = (l) => new Uint8Array(createHash('sha256').update(`sigelo-home-test/0 ${l}`).digest());
35
+ const dir = mkdtempSync(join(tmpdir(), 'sigelo-home-'));
36
+ const policy = (ctx) => relayPolicy(ctx, { pow: { bits: 4, loadBits: 8, loadPerHour: 1000, cost: { m: 8, t: 1, p: 1 } } });
37
+ const R = {};
38
+ for (const host of ['relay.test', 'relay2.test']) R[host] = await startRelay({ host, db: join(dir, `${host}.db`), tcpPort: 0, httpPort: 0, loginRate: 100000, verifyBudget: 1e9, clock: () => now, diskUsed: () => 0.1, log: () => {}, policy,
39
+ park: { lookups: { n: 1000, window: 600 }, parks: { n: 1000, window: 3600 }, lookupsAll: { n: 8000, window: 600 }, publicFetches: { n: 1000, window: 600 }, pro: () => true } });
40
+ const endpoints = Object.fromEntries(Object.entries(R).map(([h, r]) => [h, { mqtt: `mqtt://127.0.0.1:${r.ports.tcp}`, http: `http://127.0.0.1:${r.ports.http}` }]));
41
+ function agent(label, relay) {
42
+ const k = keygen({ seed: seed(label), recovery: 'sha256:' + '0'.repeat(64), created: CREATED, nonce: seed(`${label} nonce`).slice(0, 16) });
43
+ const a = { label, did: k.did, secret: k.secret, bundle: { v: 'sigelo/0', typ: 'bundle', genesis: k.genesis, rotations: [], bindings: [], attestations: [], issuers: [] } };
44
+ a.c = new Carrier({ identity: () => ({ secret: a.secret, bundle: a.bundle }), ...pathsFor(join(dir, `${label}.local.json`)), relay, endpoints, shortRelay: 'relay.test', clock: () => now, keep: true, backoff: [100, 400] });
45
+ a.o = { carrier: a.c, file: G2.groups2Path(join(dir, `${label}.local.json`)) };
46
+ return a;
47
+ }
48
+ const A = agent('a', 'relay.test'), B = agent('b', 'relay2.test'), C = agent('c', 'relay.test'), D = agent('d', 'relay2.test'), E = agent('e', 'relay2.test'), F = agent('f', 'relay.test');
49
+ const texts = (r) => r.items.map((i) => i.content);
50
+
51
+ try {
52
+ const mk = await G2.create({ ...A.o, name: 'crew', kind: 'human', selfName: 'alice' });
53
+ const g = mk.group;
54
+ ok(g.home === 'relay.test' && g.role === 'owner' && g.members.length === 1 && g.members[0].name === 'alice' && g.epoch === 1, 'A creates crew at its relay: owner, one member, epoch 1', JSON.stringify(g));
55
+ const l1 = await G2.link({ ...A.o, group: 'crew', approve: 'auto' });
56
+ ok(/^GRP-[0-9A-Z]{4}-[0-9A-Z]{4}$/.test(l1.code) && l1.link.endsWith(l1.code) && l1.words.split(' ').length === 4, `A makes a link: ${l1.code}, ${l1.link}, the owner's four words`, JSON.stringify(l1));
57
+ const jb = await G2.join({ ...B.o, code: l1.link, name: 'bot', kind: 'agent' });
58
+ ok(jb.status === 'waiting' && jb.words === l1.words, 'B (own relay R2) joins by the link: waiting, the same four words', JSON.stringify(jb));
59
+ const sa = await G2.sync(A.o);
60
+ ok(sa.groups[0].members.length === 2, 'A syncs: the auto link approves B at once (add, welcome, answer)', JSON.stringify(sa.groups[0]));
61
+ const sb = await G2.sync(B.o);
62
+ ok(sb.groups[0].status === 'member' && sb.groups[0].members.length === 2 && sb.groups[0].role === 'member', 'B syncs: the answer on its reply topic, the welcome, the roster: a member', JSON.stringify(sb.groups[0]));
63
+ const m1 = await G2.send({ ...B.o, group: 'crew', text: 'hello from R2' });
64
+ ok(typeof m1.seq === 'number', 'B sends through the home relay', JSON.stringify(m1));
65
+ const ra = await G2.sync(A.o);
66
+ ok(texts(ra).includes('hello from R2') && ra.items[0].name === 'bot' && ra.items[0].note === 'not your operator', 'A reads it, labelled', JSON.stringify(ra.items));
67
+ await G2.send({ ...A.o, group: 'crew', text: 'hi bot' });
68
+ const rb = await G2.sync(B.o);
69
+ ok(texts(rb).includes('hi bot'), 'B reads A\'s reply', JSON.stringify(rb));
70
+
71
+ // C (own relay R1) joins by the long invite of a link that needs an admin.
72
+ const l2 = await G2.link({ ...A.o, group: 'crew', approve: 'admin', ttl: 3600, cap: 5 });
73
+ const jc = await G2.join({ ...C.o, code: l2.invite, name: 'carl', kind: 'agent' });
74
+ ok(jc.status === 'waiting', 'C joins by the long invite (approve: admin): waiting', JSON.stringify(jc));
75
+ await G2.sync(A.o);
76
+ const rq = await G2.requests({ ...A.o, group: 'crew' });
77
+ ok(rq.length === 1 && rq[0].name === 'carl' && rq[0].agent === true && rq[0].kind === 'join', 'A: one request waiting, carl, an agent', JSON.stringify(rq));
78
+ ok(await failure(() => G2.approve({ ...B.o, group: 'crew', id: rq[0].id })) === 'group_request', 'B (a member) has no such request to approve');
79
+ const ap = await G2.approve({ ...A.o, group: 'crew', id: rq[0].id });
80
+ ok(ap.added === true && ap.member.name === 'carl', 'A approves carl', JSON.stringify(ap));
81
+ const sc = await G2.sync(C.o);
82
+ ok(sc.groups[0].status === 'member' && sc.groups[0].members.length === 3, 'C syncs: a member of three', JSON.stringify(sc.groups[0]));
83
+ await G2.sync(B.o);
84
+
85
+ // Content: reactions, an edit, a delete, a poll and its votes, a pin.
86
+ const p = await G2.send({ ...C.o, group: 'crew', text: 'typo hree' });
87
+ await G2.edit({ ...C.o, group: 'crew', re: p.mid, text: 'typo here' });
88
+ await G2.react({ ...B.o, group: 'crew', re: p.mid, emoji: '👍' });
89
+ ok(await failure(() => G2.edit({ ...B.o, group: 'crew', re: p.mid, text: 'not mine' })) === 'group_role', 'B edits C\'s message: group_role');
90
+ const pl = await G2.poll({ ...A.o, group: 'crew', question: 'Lunch?', options: ['pizza', 'soup'] });
91
+ await G2.vote({ ...B.o, group: 'crew', re: pl.mid, choices: [1] });
92
+ await G2.vote({ ...C.o, group: 'crew', re: pl.mid, choices: [0] });
93
+ ok(await failure(() => G2.vote({ ...C.o, group: 'crew', re: pl.mid, choices: [0, 1] })) === 'group_message', 'two choices in a one-answer poll: group_message');
94
+ await G2.pin({ ...A.o, group: 'crew', re: p.mid });
95
+ ok(await failure(() => G2.pin({ ...B.o, group: 'crew', re: p.mid })) === 'group_role', 'B (a member) pins: group_role');
96
+ const gone = await G2.send({ ...B.o, group: 'crew', text: 'oops' });
97
+ await G2.remove({ ...B.o, group: 'crew', re: gone.mid });
98
+ await G2.sync(A.o);
99
+ const sh = G2.show({ ...A.o, group: 'crew' }), msg = (m) => sh.messages.find((x) => x.mid === m);
100
+ ok(msg(p.mid)?.text === 'typo here' && msg(p.mid).edited && msg(p.mid).reactions['👍']?.length === 1 && msg(p.mid).pinned, 'A sees the edit, B\'s reaction and the pin', JSON.stringify(msg(p.mid)));
101
+ ok(JSON.stringify(msg(pl.mid)?.poll.votes) === JSON.stringify({ [B.did]: [1], [C.did]: [0] }) && msg(gone.mid)?.deleted && msg(gone.mid).text === undefined, 'A sees both votes and the deletion', JSON.stringify(sh.messages));
102
+
103
+ // Ruling 15: the owner makes its own agent B admin; B, an admin, may not make agent C admin.
104
+ await G2.role({ ...A.o, group: 'crew', member: 'bot', role: 'admin' });
105
+ const sb2 = await G2.sync(B.o);
106
+ ok(sb2.groups[0].role === 'admin' && sb2.groups[0].epoch === 2, 'B, an agent, made admin by the owner: the vault, then epoch 2 by a letter', JSON.stringify(sb2.groups[0]));
107
+ ok(await failure(() => G2.role({ ...B.o, group: 'crew', member: 'carl', role: 'admin' })) === 'group_role', 'B (admin) makes agent C admin: group_role (owner only)');
108
+ await G2.role({ ...B.o, group: 'crew', member: 'carl', role: 'moderator' });
109
+ await G2.sync(C.o);
110
+ await G2.role({ ...B.o, group: 'crew', member: 'carl', role: 'member' });
111
+
112
+ // Agents moderate, people administer. A model's person acts: group_person, before anything
113
+ // connects. The caps (settings.mod) are the owner's; a capped member (B: an admin that is an agent) counts its own.
114
+ for (const [what, f] of [['role', () => G2.role({ ...B.o, group: 'crew', member: 'carl', role: 'moderator', model: true })], ['set', () => G2.set({ ...B.o, group: 'crew', key: 'about', value: 'x', model: true })],
115
+ ['link', () => G2.link({ ...B.o, group: 'crew', model: true })], ['unlink', () => G2.unlink({ ...B.o, group: 'crew', id: 'x', model: true })], ['handover', () => G2.handover({ ...A.o, group: 'crew', member: 'bot', model: true })],
116
+ ['end', () => G2.end({ ...A.o, group: 'crew', model: true })], ['moderate', () => G2.moderate({ ...A.o, group: 'crew', kicks: 1, model: true })]]) ok(await failure(f) === 'group_person', `a model's ${what}: group_person`);
117
+ ok(await failure(() => G2.moderate({ ...B.o, group: 'crew', kicks: 1 })) === 'group_role', 'B (an admin, not the owner) sets the caps: group_role');
118
+ ok(await failure(() => G2.moderate({ ...A.o, group: 'crew', kicks: 21 })) === 'group_settings', 'caps past 20 kicks: group_settings');
119
+ const mo = await G2.moderate({ ...A.o, group: 'crew', kicks: 0, deletes: 1 });
120
+ ok(mo.caps.kicks === 0 && mo.caps.deletes === 1 && mo.moderate.on === true && mo.moderate.capped === false, 'A (owner) sets the caps 0 kicks, 1 delete: a settings body; the owner not capped', JSON.stringify(mo));
121
+ const d1 = await G2.send({ ...C.o, group: 'crew', text: 'delete me' }), d2 = await G2.send({ ...C.o, group: 'crew', text: 'delete me too' });
122
+ await G2.sync(B.o);
123
+ const bm = G2.list(B.o)[0].moderate;
124
+ ok(bm.capped === true && bm.kicks === 0 && bm.kicks_left === 0 && bm.deletes_left === 1, 'B (agent admin) reads the caps: capped, 0 kicks, 1 delete left', JSON.stringify(bm));
125
+ ok(await failure(() => G2.kick({ ...B.o, group: 'crew', member: 'carl' })) === 'group_limit', 'B kicks at the cap (0): group_limit, no model flag (the CLI\'s path)');
126
+ await G2.remove({ ...B.o, group: 'crew', re: d1.mid });
127
+ ok(await failure(() => G2.remove({ ...B.o, group: 'crew', re: d2.mid })) === 'group_limit', 'B deletes one of carl\'s, then a second: group_limit (the owner\'s 1)');
128
+ ok(JSON.parse(readFileSync(B.o.file, 'utf8')).mod.delete === 1, 'counted in B\'s own file');
129
+
130
+ // A forged sender: C seals an entry under its own chain whose body says it is from B.
131
+ {
132
+ const { b64u: b64, unb64u, sealEntry, senderHint, signBody, newMid } = await import('./home-wire.mjs');
133
+ const { step } = await import('./kdf.mjs');
134
+ const file = JSON.parse(readFileSync(C.o.file, 'utf8')), Gc = Object.values(file.groups)[0], ek = Gc.epochs[Gc.epoch];
135
+ const r = step(unb64u(Gc.mine.ck));
136
+ const body = { v: 'sigelo-group/2', typ: 'msg', gid: Gc.gid, mid: newMid(), iat: now, from: B.did, epoch: Gc.epoch, at: Gc.seq, text: 'I am bot' };
137
+ const content = signBody({ secret: C.secret }, body);
138
+ const { ed25519 } = await import('@noble/curves/ed25519.js');
139
+ const seedW = unb64u(ek.W), bytes = sealEntry({ topic: Gc.topic, epoch: Gc.epoch, write: { seed: seedW, pub: ed25519.getPublicKey(seedW) }, HK: unb64u(ek.HK), hint: senderHint(unb64u(ek.HK), C.did), n: Gc.mine.n, mk: r.mk, content });
140
+ // The group's rate (2 a second, burst 20) may be spent by the roles and renewals above: tried again a second later, as group2.mjs post does.
141
+ await C.c.home('relay.test', async (h) => {
142
+ let r = await h.publish(Gc.topic, bytes);
143
+ for (let i = 0; r?.code === 'rate' && i < 5; i++) { await new Promise((ok_) => setTimeout(ok_, 1100)); r = await h.publish(Gc.topic, bytes); }
144
+ ok(r === null, 'the relay stores the forged entry (it holds the write key)', JSON.stringify(r));
145
+ });
146
+ const before = JSON.parse(readFileSync(A.o.file, 'utf8')).groups[Gc.gid].dropped.group_sig ?? 0;
147
+ const ra2 = await G2.sync(A.o);
148
+ ok(!texts(ra2).includes('I am bot') && JSON.parse(readFileSync(A.o.file, 'utf8')).groups[Gc.gid].dropped.group_sig === before + 1, 'A drops it, counted group_sig', JSON.stringify(ra2));
149
+ }
150
+
151
+ // A kicks C: the renewal (epoch 3) reaches A and B by letters, not C.
152
+ await G2.send({ ...C.o, group: 'crew', text: 'still here' }).catch(() => {});
153
+ await new Promise((r) => setTimeout(r, 10500)); // the relay: one switch per 10 s
154
+ await G2.kick({ ...A.o, group: 'crew', member: 'carl', bar: true });
155
+ const sa3 = await G2.sync(A.o), sb3 = await G2.sync(B.o), sc3 = await G2.sync(C.o).catch((e) => ({ error: e.check }));
156
+ ok(sa3.groups[0].epoch === 3 && sb3.groups[0].epoch === 3 && sa3.groups[0].members.length === 2, 'A kicks carl (barred): epoch 3 at A and B, two members (the owner: not capped, caps 0 kicks)', JSON.stringify([sa3.groups[0], sb3.groups[0]]));
157
+ const cs = G2.list(C.o)[0];
158
+ ok(cs.status === 'removed' && cs.epoch === 2, 'C: removed, still at epoch 2 (no letter)', JSON.stringify(cs));
159
+ await G2.send({ ...B.o, group: 'crew', text: 'after the kick' });
160
+ ok(texts(await G2.sync(A.o)).includes('after the kick'), 'B writes under epoch 3; A reads it');
161
+ ok(await failure(() => G2.send({ ...C.o, group: 'crew', text: 'let me in' })) !== 'accepted', 'C cannot send any more');
162
+ ok(await failure(() => C.c.home('relay.test', async (h) => {
163
+ const Gc = Object.values(JSON.parse(readFileSync(C.o.file, 'utf8')).groups)[0];
164
+ const { ed25519 } = await import('@noble/curves/ed25519.js'), { unb64u, b64u } = await import('./home-wire.mjs');
165
+ return h.control({ typ: 'open', topic: Gc.topic, epoch: 3, since: 0, as: 'member', proof: b64u(ed25519.sign(G2.openInput(Gc.topic, 3, h.account, Math.floor(now / 86400)), unb64u(Gc.epochs[2].W))) });
166
+ })) === 'home_credential', 'C opens epoch 3 with its old key: home_credential');
167
+
168
+ // History "always": D joins and reads what was said before.
169
+ await G2.set({ ...A.o, group: 'crew', key: 'history', value: 'always' });
170
+ ok(await failure(() => G2.set({ ...B.o, group: 'crew', key: 'history', value: 'never' })) === 'group_role', 'B (admin) sets history: group_role (the owner\'s)');
171
+ const l3 = await G2.link({ ...B.o, group: 'crew', approve: 'auto' });
172
+ ok(typeof l3.code === 'string', 'B, the owner\'s agent admin, makes a link', JSON.stringify(l3));
173
+ await G2.join({ ...D.o, code: l3.code, name: 'dora', kind: 'human' });
174
+ await G2.sync(B.o);
175
+ const sd = await G2.sync(D.o);
176
+ ok(sd.groups[0].status === 'member' && texts(sd).includes('hello from R2') && texts(sd).includes('after the kick'), 'D (approved by B\'s agent) reads the history before it joined', JSON.stringify([texts(sd), sd.groups[0].dropped]));
177
+
178
+ // Leave and end.
179
+ await new Promise((r) => setTimeout(r, 10500));
180
+ await G2.leave({ ...D.o, group: 'crew' });
181
+ const sa4 = await G2.sync(A.o);
182
+ ok(sa4.groups[0].members.length === 2 && sa4.groups[0].epoch === 4, 'D leaves: A renews (epoch 4)', JSON.stringify(sa4.groups[0]));
183
+ await G2.end({ ...A.o, group: 'crew' });
184
+ await G2.sync(B.o);
185
+ ok(G2.list(B.o)[0].status === 'closed', 'A ends the group: B sees it closed');
186
+
187
+ // An admin made after a link reads its requests (design/groups-build.md §4.15): the vault carries the door seeds of the
188
+ // open links. Made member again, after the full renewal it sees no request, and the relay refuses its old admin key.
189
+ const groupOf = (who, name) => Object.values(JSON.parse(readFileSync(who.o.file, 'utf8')).groups).find((x) => x.name === name);
190
+ await G2.create({ ...A.o, name: 'door', kind: 'human', selfName: 'alice' });
191
+ const lb = await G2.link({ ...A.o, group: 'door', approve: 'auto' });
192
+ await G2.join({ ...B.o, code: lb.code, name: 'bea', kind: 'human' });
193
+ await G2.sync(A.o); await G2.sync(B.o);
194
+ const lk = await G2.link({ ...A.o, group: 'door', approve: 'admin' });
195
+ await G2.sync(B.o);
196
+ ok(groupOf(B, 'door').links[lk.id] && !groupOf(B, 'door').links[lk.id].seed, 'B (a member) reads the link body: no door seed (it holds no V)', JSON.stringify(groupOf(B, 'door').links));
197
+ await G2.role({ ...A.o, group: 'door', member: 'bea', role: 'admin' });
198
+ await G2.sync(B.o);
199
+ ok(G2.list(B.o).find((x) => x.name === 'door').role === 'admin' && groupOf(B, 'door').links[lk.id].seed === groupOf(A, 'door').links[lk.id].seed, 'A makes B admin after the link: B\'s vault brings the link\'s door seed', JSON.stringify(groupOf(B, 'door').links[lk.id]));
200
+ await G2.join({ ...E.o, code: lk.code, name: 'eve', kind: 'human' });
201
+ await G2.sync(B.o);
202
+ const rqb = await G2.requests({ ...B.o, group: 'door' });
203
+ ok(rqb.length === 1 && rqb[0].name === 'eve' && rqb[0].link === lk.id, 'E joins through the earlier link: B, the later admin, sees the request', JSON.stringify(rqb));
204
+ const apb = await G2.approve({ ...B.o, group: 'door', id: rqb[0].id });
205
+ const se = await G2.sync(E.o);
206
+ ok(apb.added === true && se.groups.find((x) => x.name === 'door')?.status === 'member', 'B approves eve: E a member', JSON.stringify([apb, se.groups]));
207
+ const oldV = groupOf(B, 'door').V;
208
+ await new Promise((r) => setTimeout(r, 10500)); // the relay: one switch per 10 s (the role's renewal)
209
+ await G2.role({ ...A.o, group: 'door', member: 'bea', role: 'member' });
210
+ await G2.sync(B.o);
211
+ const gb = groupOf(B, 'door'), ga = groupOf(A, 'door');
212
+ ok(gb.roster[B.did].role === 'member' && gb.epoch === ga.epoch && !gb.V && !Object.values(gb.links).some((l) => l.seed), 'A makes B member: a full renewal; B forgets V and the door seeds', JSON.stringify({ epoch: [gb.epoch, ga.epoch], links: gb.links }));
213
+ await G2.join({ ...F.o, code: lk.code, name: 'fay', kind: 'human' });
214
+ await G2.sync(B.o); await G2.sync(A.o);
215
+ ok((await G2.requests({ ...B.o, group: 'door' })).length === 0 && (await G2.requests({ ...A.o, group: 'door' })).some((r) => r.name === 'fay'), 'F joins through the link: A sees the request, B (member again) none', JSON.stringify(await G2.requests({ ...A.o, group: 'door' })));
216
+ ok(await failure(() => B.c.home('relay.test', async (h) => {
217
+ const { ed25519 } = await import('@noble/curves/ed25519.js'), W = await import('./home-wire.mjs');
218
+ return h.control({ typ: 'open', topic: gb.topic, epoch: gb.epoch, since: 0, as: 'admin', proof: W.b64u(ed25519.sign(G2.openInput(gb.topic, gb.epoch, h.account, Math.floor(now / 86400)), W.adminKey(W.unb64u(oldV), gb.gid, gb.epoch).seed)) });
219
+ })) === 'home_credential', 'B opens as admin with the V it kept: home_credential (no door rows after the renewal)');
220
+ } finally {
221
+ for (const r of Object.values(R)) await r.close?.();
222
+ }
223
+ for (const f of fails) console.log('FAIL ' + f);
224
+ console.log(fails.length ? `${fails.length} FAILED, ${count - fails.length} passed` : `ALL PASS (${count})`);
225
+ process.exit(fails.length ? 1 : 0);
package/test-invite.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: MIT
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
2
  // Runs fixtures/invite-v0.json against invite.mjs and store.mjs, then gen-invite.mjs --check.
3
3
  // node apps/contact/test-invite.mjs -> "ALL PASS (n)", or one FAIL line per failing check and exit 1
4
4
  // Stores live in a fresh temporary directory, removed at the end.
package/test-link.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: MIT
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
2
  // Links (link.mjs, contract sigelo-link/1): the message checks and the file first, the store's
3
3
  // `link` (setLink, link_tier, revoke); then, with the relay checkout beside apps/contact/ (SIGELO_RELAY_DIR,
4
4
  // else ../../relay), on a loopback relay with one clock: an operator links two of its agents (tiers,
@@ -119,7 +119,7 @@ const D0 = 'did:sigelo:z' + '1'.repeat(44);
119
119
  ok(a1.link === undefined && a1.tier === 'friend' && a1.tier_by === 'owner', 'setLink null with prior: the tier before restored');
120
120
  hs.revoke(F.did);
121
121
  ok(hs.load().s.contacts[F.did].link === undefined, 'revoke drops the link');
122
- // Relink (design/links.md §7.1a): a link's end is remembered (ended); a new link pairs only with a permit.
122
+ // Relink: a link's end is remembered (ended); a new link pairs only with a permit.
123
123
  ok(hs.load().s.contacts[F.did].ended === undefined && checkOf(() => hs.relink(F.did, 'DDDDDDDD', now + 60, now)) === 'revoked', 'forgotten by hand: no ended; relink refused (revoked)');
124
124
  ok(hs.relink(A.did, 'DDDDDDDD', now + 60, now) === null && hs.relink(D0, 'DDDDDDDD', now + 60, now) === null, 'relink of a live contact, or of no contact: nothing to permit (null)');
125
125
  const X2 = agent('store relink');
@@ -295,7 +295,7 @@ try {
295
295
  ok(A.out.some((r) => r.ended.some((x) => x.id === L.id && x.forgot)) && B.out.some((r) => r.ended.some((x) => x.id === L.id)), 'handle reports the end on both');
296
296
  ok(await failure(() => unlink({ carrier: H.c, file: H.f, id: 'ZZZZZZZZ' })) === 'link_unknown', 'unlink of no link: link_unknown');
297
297
 
298
- // ---- relink (design/links.md §7.1a): the end remembered on both sides; one side's ask alone is
298
+ // ---- relink: the end remembered on both sides; one side's ask alone is
299
299
  // refused; the ended id never again; both asked afresh: linked again under a new id.
300
300
  ok(contactOf(A, B.did).ended?.id === L.id && contactOf(B, A.did).ended?.id === L.id, 'the end remembered on both revoked records (ended: the link id)');
301
301
  const R1 = await link({ carrier: H.c, file: H.f, a: 'project', b: 'review', purpose: 'review again' });
package/test-platform.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: MIT
2
- // The platform seam (platform-node.mjs, design/apps.md §4.2): two carriers whose files live in a
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // The platform seam (platform-node.mjs, README.md "Platforms"): two carriers whose files live in a
3
3
  // Map, whose lock is in-process and whose owner is a Set, pair by code, write, send a file given as
4
4
  // bytes and a name, read it, and read their history, against a loopback relay (relay/server.mjs in
5
5
  // this process) reached through Node's fetch, MQTT and proof of work. Their names point into a
package/test-presence.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: MIT
2
- // Presence (carrier.mjs "Presence", design/transfer.md §8 T0): the store part first (off by default,
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Presence (carrier.mjs "Presence", THREAT-MODEL §2.17): the store part first (off by default,
3
3
  // allow and deny, own agents always, kept through a re-pair); then, with the relay checkout beside
4
4
  // apps/contact/ (SIGELO_RELAY_DIR, else ../../relay), on a loopback relay: a started carrier's marker is
5
5
  // read by an allowed contact and by its own agents, never by a denied one; a stop and a cut
package/test-push.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: MIT
2
- // The carrier's push registration (carrier.mjs setPush, sigelo-push/0; design/push.md) against a loopback
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // The carrier's push registration (carrier.mjs setPush, sigelo-push/0; apps/agent/UI-API.md "Push") against a loopback
3
3
  // relay (relay/server.mjs, relay/push.mjs) and a fake UnifiedPush distributor over HTTPS: registered at
4
4
  // every login of a started carrier, a wake POSTed when a contact writes while it is stopped (opened here
5
5
  // as the phone opens it, RFC 8291), removed with null, refused by name, nothing sent to a relay that does
@@ -28,7 +28,7 @@ setTimeout(() => { console.log(`FAIL the run did not finish in 180 s (${count} c
28
28
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
29
29
  const until = async (cond, ms = 8000) => { const end = Date.now() + ms; while (Date.now() < end) { if (cond()) return true; await sleep(20); } return cond(); };
30
30
 
31
- // The phone's push keys (WebPush.java makes them on the phone): a P-256 pair and a 16-byte auth secret.
31
+ // A phone app's push keys (WebPush.java makes them on the phone): a P-256 pair and a 16-byte auth secret.
32
32
  const ua = createECDH('prime256v1');
33
33
  ua.generateKeys();
34
34
  const AUTH = createHash('sha256').update('sigelo push test auth').digest().subarray(0, 16);
@@ -93,12 +93,12 @@ try {
93
93
  await sleep(200);
94
94
  await alice.send('bob', 'while bob is away');
95
95
  ok(await until(() => posts.length === 1), 'bob stopped, alice writes: one POST to his endpoint');
96
- ok(posts[0].url === '/upPhone?up=1' && open(posts[0].body).equals(WAKE), 'the wake opens under the phone\'s keys to WAKE (RFC 8291): no sender, no text');
96
+ ok(posts[0].url === '/upPhone?up=1' && open(posts[0].body).equals(WAKE), 'the wake opens under the phone push keys to WAKE (RFC 8291): no sender, no text');
97
97
  await alice.send('bob', 'again');
98
98
  await sleep(300);
99
99
  ok(posts.length === 1, 'a second message before bob is back: no second wake');
100
100
 
101
- // The phone's app wakes: bob logs in, takes his mail. The same registration again changes nothing at the relay.
101
+ // The phone app wakes: bob logs in, takes his mail. The same registration again changes nothing at the relay.
102
102
  bob = make(B);
103
103
  bob.setPush({ endpoint: ENDPOINT, ...KEYS });
104
104
  const box = await bob.inbox();
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: MIT
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
2
  // The relay lane for transfers (0.1.19; transfer-engine.mjs "The relay lane", apps/agent/TRANSFER.md): the units first
3
3
  // (the end `relay`, who may fall back and up to what size, resume on a stuck transfer, a stalled channel, a record stuck
4
4
  // for 10 minutes listed as interrupted), then, with the relay checkout beside apps/contact/ (SIGELO_RELAY_DIR, else
@@ -132,7 +132,7 @@ const OWN = { did: 'did:sigelo:zOwn', name: 'own', tier: 'own' }, PAL = { did: '
132
132
  }
133
133
  }
134
134
 
135
- // ================================================================ the accept rule, whatever the lane (2026-11-25)
135
+ // ================================================================ the accept rule, whatever the lane
136
136
  // On the phone, with direct off, every file waited for a manual accept. The rule (transfer auto <contact> <MB>)
137
137
  // says yes under the size; the direct switch only picks the lane: off, no Tor, the receiver ends no_path at once and the
138
138
  // sender's relay lane carries it (up to 8 MiB).
@@ -304,7 +304,7 @@ try {
304
304
  ok(aRec(r3.id).state === 'failed' && !aRec(r3.id).relay && !aRec(r3.id).path_used, 'not fallen back to the relay lane');
305
305
  ok(await failure(() => A.relay(r3.id, { manual: true })) === 'file_too_large', 'Send over the relay is refused past 8 MiB (the bubble offers Retry)');
306
306
 
307
- // 4. Direct off at the receiver (2026-11-25), its rule "transfer auto alice 100": no question, over the relay lane.
307
+ // 4. Direct off at the receiver, its rule "transfer auto alice 100": no question, over the relay lane.
308
308
  net.blocked = false;
309
309
  X.setDirect({ carrier: bob.c, identity: bob.identity, contact: 'alice', on: false });
310
310
  X.setAuto({ carrier: bob.c, identity: bob.identity, contact: 'alice', mb: 100 });
package/test-short.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: MIT
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
2
  // Short invite codes (short.mjs, contract sigelo-park/0): fixtures/short-code-v0.json against
3
3
  // short.mjs, gen-short.mjs --check, the word list's hash; then, with the relay checkout beside
4
4
  // apps/contact/ (SIGELO_RELAY_DIR, else ../../relay), the whole flow on a loopback relay: invite → short
package/test-tier.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: MIT
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
2
  // Contact tiers (store.mjs "Tiers", carrier.mjs "Operator hints"): the store part first (own by an
3
3
  // operator attestation from this identity or its operators, friend by default, the owner's choice
4
4
  // kept through a re-pair, a merge and a rename, refusals by name); then, with the relay checkout
@@ -18,7 +18,7 @@ import { Contacts, OPERATOR_CTX, TIERS } from './store.mjs';
18
18
  const HERE = dirname(fileURLToPath(import.meta.url));
19
19
  let count = 0;
20
20
  const fails = [];
21
- const ok = (cond, what) => { count++; if (!cond) fails.push(what); };
21
+ const ok = (cond, what, x) => { count++; if (!cond) fails.push(x === undefined ? what : `${what} (${JSON.stringify(x)})`); };
22
22
  const checkOf = (f) => { try { f(); return 'accepted'; } catch (e) { return e.check ?? `exception ${e.constructor.name}: ${e.message}`; } };
23
23
  const report = () => {
24
24
  for (const f of fails) console.log('FAIL ' + f);
@@ -158,6 +158,10 @@ try {
158
158
  await rounds(ca, cb);
159
159
  ok(tierAt(ca, B.did) === 'own' && tierAt(cb, A.did) === 'own', 'after their operator hints, asks and proofs cross: each is own to the other');
160
160
  ok(events.claude.some((e) => e.type === 'tier' && e.did === B.did && e.tier === 'own'), 'a tier event says so');
161
+ // Siblings (kin.mjs): the same operator's attestation and one recovery commitment (these test agents share one).
162
+ const kinAt = (c, did) => c.contacts().contacts.find((x) => x.did === did)?.kin;
163
+ ok(kinAt(ca, B.did)?.operator === H.did && kinAt(cb, A.did)?.operator === H.did, 'and each is filed kin, its operator mine', kinAt(ca, B.did));
164
+ ok(events.claude.filter((e) => e.type === 'kin' && e.did === B.did && e.operator === H.did).length === 1, 'one kin event (no four words to compare)');
161
165
  const as = JSON.parse(readFileSync(pathsFor(join(dir, 'claude.local.json')).store, 'utf8')).contacts[B.did];
162
166
  ok(as.tier === 'own' && as.tier_by === 'auto' && as.operator_exp === A.bundle.attestations[0].body.exp, 'written: tier own, auto, until the attestation expires');
163
167
 
@@ -165,6 +169,7 @@ try {
165
169
  await rounds(ca, cf);
166
170
  const fBox = await cf.inbox();
167
171
  ok(tierAt(ca, F.did) === 'friend' && tierAt(cf, A.did) === 'friend', 'a contact who knows none of the operators: friend both ways');
172
+ ok(kinAt(ca, F.did) === null && kinAt(cf, A.did) === null, 'and kin neither way');
168
173
  const fState = JSON.parse(readFileSync(pathsFor(join(dir, 'friend.local.json')).state, 'utf8'));
169
174
  ok(fBox.messages.length === 0 && !JSON.stringify(fState).includes(H.did) && !(fState.peers[A.did]?.op_asked), 'it got hints only: no operator DID, nothing asked, nothing in its inbox');
170
175
 
@@ -172,6 +177,7 @@ try {
172
177
  ok(tierAt(ca, H.did) === 'own', 'an agent and its operator: the operator is own at once');
173
178
  await rounds(ch, ca);
174
179
  ok(tierAt(ch, A.did) === 'own', 'and the agent is own to the operator once it proves the attestation');
180
+ ok(kinAt(ca, H.did) === null && kinAt(ch, A.did)?.operator === H.did, 'the operator is no sibling; to the operator, its agent is kin');
175
181
 
176
182
  // accept with a tier: the owner's choice, filed with the contact.
177
183
  const r = await pair(ca, cq, 'hotel', 'claude', { tier: 'quiet' });
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: MIT
2
- // Transfers in the phone app (design/transfer.md §10; transfer-engine.mjs, transfer-web.mjs, rtc-web.mjs,
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Transfers in the phone app (apps/agent/TRANSFER.md "The phone app"; transfer-engine.mjs, transfer-web.mjs, rtc-web.mjs,
3
3
  // photo.mjs): the accept rule's table and who counts as known; a group's fan-out (paired, through the
4
4
  // creator, offline, direct asked first) over a fake carrier; the preview's checks; the page's data
5
5
  // channel over a fake RTCDataChannel (the 1 MiB low mark, binary frames only); then, with the relay
@@ -87,7 +87,7 @@ export function fakeShell({ landFails = null } = {}) {
87
87
  ok(t({ size: 25e6 }) === 'auto' && t({ size: 25e6 + 1 }) === 'ask', '25 MB exactly lands; one byte more asks (MB = 10^6)');
88
88
  ok(t({ limitMb: 0 }) === 'ask' && t({ limitMb: 2 }) === 'ask' && t({ limitMb: 4 }) === 'auto', 'the contact\'s own size wins: 0 always asks');
89
89
  ok(t({ defaultMb: 0 }) === 'ask' && t({ defaultMb: 1, limitMb: 5 }) === 'auto', 'the default 0: always ask, unless the contact has its own');
90
- ok(t({ direct: null }) === 'auto' && t({ direct: false }) === 'auto', 'the direct switch is not the rule\'s (2026-11-25): off or not asked, still auto (the lane falls to Tor or the relay)');
90
+ ok(t({ direct: null }) === 'auto' && t({ direct: false }) === 'auto', 'the direct switch is not the rule\'s: off or not asked, still auto (the lane falls to Tor or the relay)');
91
91
  const c = (x) => ({ did: 'did:sigelo:zA', tier: 'friend', ...x });
92
92
  ok(E.trustOf(c({ tier: 'own' })) === 'own' && E.trustOf(c({ ours: true })) === 'own', 'trustOf: own tier and ours are own');
93
93
  ok(E.trustOf(c({}), () => true) === 'compared' && E.trustOf(c({}), () => false) === 'other', 'trustOf: a friend is known once the words were compared');
@@ -144,7 +144,7 @@ export function fakeShell({ landFails = null } = {}) {
144
144
  ok(X.setAuto({ carrier, contact: 'bob', mb: 0 }).auto_mb === 0 && X.list({ carrier }).auto['did:sigelo:zBob'] === 0, 'setAuto: per contact, in the list');
145
145
  }
146
146
 
147
- // ================================================================ TURN (2026-11-26): the relay's credential at each attempt
147
+ // ================================================================ TURN: the relay's credential at each attempt
148
148
  const TURN = { urls: ['turn:relay.test:3478?transport=udp', 'turn:relay.test:3478?transport=tcp'], username: '1764200000:abcdefghijklmnop', credential: 'Y3JlZGVudGlhbA==', exp: 1764200000 };
149
149
  {
150
150
  ok(JSON.stringify(iceServers(['relay.test:3478'])) === '[{"urls":["stun:relay.test:3478"]}]' && JSON.stringify(iceServers([], null)) === '[]', 'the page\'s ICE servers without TURN: STUN alone, as before');
@@ -165,9 +165,17 @@ const TURN = { urls: ['turn:relay.test:3478?transport=udp', 'turn:relay.test:347
165
165
  'a module that does not say TURN_OK true (werift without its handshake checks): no credential asked');
166
166
  ok((await eng({}, c1).turnOf(await import('../transfer/rtc.mjs')))?.username === TURN.username && asked.length === 2,
167
167
  'werift (apps/transfer/rtc.mjs) with its handshake checks in place: TURN_OK true, a credential asked');
168
- // "Always relay my media" (design/calls.md §6): the policy, the page's peer under it, the engine's.
168
+ // "Always relay my media" (UI-API.md "Settings"): the policy, the page's peer under it, the engine's.
169
169
  ok(eng({}, {}).policyNow() === 'all' && eng({ policy: () => 'relay' }, {}).policyNow() === 'relay' && eng({ env: { SIGELO_ICE_POLICY: 'relay' } }, {}).policyNow() === 'relay'
170
170
  && eng({ policy: () => { throw new Error('x'); } }, {}).policyNow() === 'all', 'the engine\'s policy: the setting (policy()) or SIGELO_ICE_POLICY=relay; else all');
171
+ {
172
+ // A contact's route "relay" (the app's How files go): the direct lane only through TURN for that contact alone.
173
+ let rec = JSON.stringify({ v: E.FILE_V, out: {}, in: {}, direct: { 'did:x:r': 'relay', 'did:x:d': true }, auto: {}, settings: {} });
174
+ const io = { lock: (f) => f(), read: () => rec, write: (t) => { rec = t; } };
175
+ const e = eng({ io }, {});
176
+ ok(e.policyNow({ did: 'did:x:r', tier: 'friend' }) === 'relay' && e.policyNow({ did: 'did:x:d', tier: 'friend' }) === 'all' && e.policyNow() === 'all',
177
+ 'the engine\'s policy per contact: route relay → relay for that one; direct → all');
178
+ }
171
179
  ok(await failure(() => webPeer({ stun: ['relay.test:3478'], turn: null, RTC: R, policy: 'relay' })) === 'relay_only', 'rtc-web peer(): relay only without TURN: refused relay_only, no connection made');
172
180
  cfg = null;
173
181
  class RS { constructor(c) { cfg = c; this.iceGatheringState = 'complete'; this.localDescription = null; } addEventListener() {} createDataChannel() { return { readyState: 'connecting', addEventListener() {} }; }
@@ -245,7 +253,7 @@ try {
245
253
  ok(r1.state === 'offered' && r1.file === d1.doc && r1.sha256 === sha(shot), 'the phone offers a picked file by its doc, hashed in the shell');
246
254
  ok(await until(() => nRec('in', r1.id)?.state === 'done', 120000), 'phone → computer, own contact, 3 MB: landed by the rule', JSON.stringify(nRec('in', r1.id)));
247
255
  ok(sha(readFileSync(nRec('in', r1.id).saved)) === sha(shot) && nRec('in', r1.id).path_used === 'direct', 'whole, over the direct path (the page\'s engine, werift in this test)');
248
- ok(await until(() => pRec('out', r1.id)?.state === 'done'), 'the phone\'s record: done');
256
+ ok(await until(() => pRec('out', r1.id)?.state === 'done'), 'the phone record: done');
249
257
  ok(nRec('in', r1.id).relayed === false && pRec('out', r1.id).relayed === false, 'both records: relayed false (the selected pair is direct: the transfers list says "direct")', JSON.stringify([nRec('in', r1.id).relayed, pRec('out', r1.id).relayed]));
250
258
  ok(sh.big.ops.filter((x) => x === 'read').length === 4, `read by range, one per chunk (${sh.big.ops.filter((x) => x === 'read').length})`);
251
259
 
@@ -299,7 +307,7 @@ try {
299
307
  const r6 = await X.send({ carrier: N.c, identity: N.identity, to: 'phone', path: join(dir, 'ro.bin') });
300
308
  ok(await until(() => pRec('in', r6.id)?.reason === 'relay_only' || pRec('in', r6.id)?.state === 'relayed', 60000) && peers.length === n0,
301
309
  'relay only, no TURN: no peer made on the phone; failed relay_only (or relayed by the sender\'s relay lane)', JSON.stringify(pRec('in', r6.id)));
302
- ok(pEvents.some((e) => e.what === 'no_direct' && e.id === r6.id && e.detail === E.RELAY_ONLY), `the phone's event says "${E.RELAY_ONLY}"`);
310
+ ok(pEvents.some((e) => e.what === 'no_direct' && e.id === r6.id && e.detail === E.RELAY_ONLY), `the phone side's event says "${E.RELAY_ONLY}"`);
303
311
  ok(await until(() => ['failed', 'relaying', 'done'].includes(nRec('out', r6.id)?.state), 60000) && nRec('out', r6.id)?.path_used !== 'direct', 'the sender told: not over the direct lane', JSON.stringify(nRec('out', r6.id)));
304
312
  P.e.policy = () => 'all';
305
313
  } finally {
package/test-transfer.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: MIT
2
- // Transfers (transfer.mjs, transfer-node.mjs, sigelo-transfer; design/transfer.md): the messages and
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Transfers (transfer.mjs, transfer-node.mjs, sigelo-transfer; apps/agent/TRANSFER.md): the messages and
3
3
  // frames; the chunk protocol over a fake channel (a whole file, a drop and the resume, a chunk altered
4
4
  // once and always, the list altered, the 16 GiB cap, back-pressure); the path order; then with the
5
5
  // relay checkout beside apps/contact/ (SIGELO_RELAY_DIR, else ../../relay) two agents on a loopback relay:
@@ -91,7 +91,7 @@ const NOW = Date.parse('2026-11-03T12:00:00Z') / 1000;
91
91
  ok(checkOf(() => new Have(10, new Uint8Array(3))) === 'transfer_have', 'Have of the wrong length: transfer_have');
92
92
  ok(chunkLength(3 * CHUNK + 5, 3) === 5 && chunkLength(3 * CHUNK + 5, 2) === CHUNK, 'chunkLength: the last chunk is the rest');
93
93
 
94
- // The path order (design §2, §9).
94
+ // The path order (apps/agent/TRANSFER.md "Paths").
95
95
  ok(JSON.stringify(pathOrder({ direct: true, tor: true })) === '["direct","tor"]', 'free: direct, then Tor');
96
96
  ok(JSON.stringify(pathOrder({ direct: false, tor: true })) === '["tor"]' && JSON.stringify(pathOrder({ direct: true, tor: false })) === '["direct"]' && pathOrder({ direct: false, tor: false }).length === 0, 'free: what is allowed only; nothing: refused');
97
97
  ok(JSON.stringify(pathOrder({ pro: true, prefer: 'fast', direct: true, tor: true })) === '["direct","tor"]', 'Pro fast without TURN yet: direct, then Tor (TURN is T4)');
@@ -269,8 +269,26 @@ try {
269
269
  // The direct switch: friend contacts are asked once; own ones are on.
270
270
  ok(await failure(() => send(file('small.bin', seeded('s', 1000)))) === 'direct_ask', 'send to a friend contact, the direct switch not set: direct_ask');
271
271
  ok(X.list({ carrier: A.c, identity: A.identity }).out.length === 0, 'and nothing was sent');
272
+ // The route (the app's Settings → Privacy): a default for everyone answers instead of the question; per contact over it.
273
+ const R = (direct, settings = {}) => ({ direct, settings });
274
+ ok(X.routeFor(R({}, { route: 'relay' }), { did: 'd', tier: 'friend' }) === 'relay' && X.directFor(R({}, { route: 'relay' }), { did: 'd', tier: 'friend' }) === true
275
+ && X.directFor(R({}, { route: 'tor' }), { did: 'd', tier: 'friend' }) === false && X.routeFor(R({}, { route: 'tor' }), { did: 'd', tier: 'own' }) === 'direct'
276
+ && X.routeFor(R({ d: 'relay' }, { route: 'tor' }), { did: 'd', tier: 'friend' }) === 'relay' && X.routeFor(R({ d: false }), { did: 'd', tier: 'own' }) === 'tor',
277
+ 'routeFor: per contact first ("relay" kept), own direct, then the default; directFor reads relay as direct, tor as off');
278
+ const dset = X.settings({ identity: A.identity, patch: { route: 'relay' } });
279
+ const noFile = await failure(() => send(join(dir, 'not-there.bin')));
280
+ ok(dset.route === 'relay' && noFile !== 'direct_ask' && noFile !== 'accepted' && !(Object.keys(X.list({ carrier: A.c, identity: A.identity }).route).length), `a default route set: the send is not asked (it got to the file: ${noFile}), nothing kept per contact`);
281
+ const sr = X.setRoute({ carrier: A.c, identity: A.identity, contact: 'bob', route: 'tor' }), L1 = X.list({ carrier: A.c, identity: A.identity });
282
+ ok(sr.route === 'tor' && sr.uses === 'tor' && L1.route[sr.did] === 'tor' && L1.direct[sr.did] === false, 'setRoute: bob tor, listed (route tor, direct false)');
283
+ X.setRoute({ carrier: A.c, identity: A.identity, contact: 'bob', route: 'relay' });
284
+ const L2 = X.list({ carrier: A.c, identity: A.identity });
285
+ ok(L2.route[sr.did] === 'relay' && L2.direct[sr.did] === true, 'setRoute relay: listed relay, direct true for older pages');
286
+ const back = X.setRoute({ carrier: A.c, identity: A.identity, contact: 'bob', route: null });
287
+ ok(back.route === null && back.uses === 'relay' && !(sr.did in X.list({ carrier: A.c, identity: A.identity }).route) && await failure(() => X.setRoute({ carrier: A.c, identity: A.identity, contact: 'bob', route: 'fast' })) === 'usage',
288
+ 'setRoute null: the default again (relay); a route not one of three: usage');
289
+ ok(X.settings({ identity: A.identity, patch: { route: null } }).route === null && await failure(() => X.settings({ identity: A.identity, patch: { route: 'x' } })) === 'usage', 'settings route null: none again; a bad one: usage');
272
290
  A.c.setTier('bob', 'own'); B.c.setTier('alice', 'own');
273
- // The accept rule (design §10.2) would land small files from an own contact unasked: asked here until its own part below.
291
+ // The accept rule would land small files from an own contact unasked: asked here until its own part below.
274
292
  ok(X.settings({ identity: B.identity }).auto_mb === 25 && X.settings({ identity: B.identity, patch: { auto_mb: 0 } }).auto_mb === 0, 'the accept rule: 25 MB by default; 0 (always ask) kept');
275
293
  ok(X.directFor({ direct: {} }, { tier: 'own' }) === true && X.directFor({ direct: {} }, { tier: 'friend' }) === null && X.directFor({ direct: { d: false } }, { did: 'd', tier: 'own' }) === false, 'directFor: own on, others asked (null), a kept choice wins');
276
294
 
@@ -334,7 +352,7 @@ try {
334
352
  ok(await until(() => B.rec('in', r5.id)?.state === 'cancelled'), 'the sender cancels: cancelled at the receiver');
335
353
  ok(await failure(() => X.accept({ carrier: B.c, identity: B.identity, id: r5.id })) === 'transfer_state', 'a cancelled transfer cannot be accepted');
336
354
 
337
- // The accept rule (design §10.2): from an own contact, under the size set, it lands without a question.
355
+ // The accept rule: from an own contact, under the size set, it lands without a question.
338
356
  X.settings({ identity: B.identity, patch: { auto_mb: 25 } });
339
357
  const small = seeded('auto', 2 * CHUNK + 1), r9 = await send(file('auto.jpg', small));
340
358
  ok(await until(() => B.rec('in', r9.id)?.state === 'done', 120000), 'own contact, 2 MB under 25 MB: landed with no accept', JSON.stringify(B.rec('in', r9.id)));
@@ -349,7 +367,7 @@ try {
349
367
  const r11 = await send(file('big2.bin', seeded('big2', 2 * CHUNK)));
350
368
  ok(await until(() => B.rec('in', r11.id)?.state === 'asked'), 'larger than the size set (2 MB over 1 MB): asked');
351
369
  await X.decline({ carrier: B.c, identity: B.identity, id: r11.id });
352
- // A group's file (design §10.3): one transfer per member paired with; one reached only through the creator: unpaired.
370
+ // A group's file: one transfer per member paired with; one reached only through the creator: unpaired.
353
371
  const gf = await X.prepare({ carrier: A.c, identity: A.identity, path: file('g.bin', seeded('g', 5000)) });
354
372
  const fan = await X.fanOut({ carrier: A.c, identity: A.identity, members: [{ did: B.did, name: 'bob', contact: true }, { did: 'did:sigelo:zCarol', name: 'carol', contact: false }], f: gf, group: 'ab'.repeat(16) });
355
373
  ok(fan.sent.length === 1 && fan.sent[0].did === B.did && fan.unpaired.length === 1 && fan.unpaired[0].name === 'carol' && fan.failed.length === 0, 'fanOut: bob sent, carol unpaired', JSON.stringify(fan));
package/test-voice.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: MIT
2
- // Voice messages (design/transfer.md "Voice"; voice.mjs, voice-web.mjs, transfer-node.mjs voiceFiles): the
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Voice messages (voice.mjs, voice-web.mjs, transfer-node.mjs voiceFiles): the
3
3
  // sigelo-voice/0 message's shape and checks, the line the CLI and MCP print, a group msg's voice, the
4
4
  // recorder over a fake MediaRecorder (format, duration, waveform, cancel, the refusals), and the
5
5
  // computer's recordings on disk (pieces, kept outside the files received, read back only from its own).
package/test-ws.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: MIT
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
2
  // The carrier (carrier.mjs) over MQTT over WebSocket, against a loopback relay (relay/server.mjs)
3
3
  // whose only listener is its HTTP port: two agents pair, write and read with 8883 unreachable,
4
4
  // with transport "wss" and with "auto" (the default), which falls back once, after the probe when