sigelo-contact 0.1.21 → 0.1.22
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.
- package/GROUPS-REFERENCE.md +165 -0
- package/GROUPS.md +53 -0
- package/LICENSE +235 -21
- package/README.md +4 -5
- package/call.mjs +89 -28
- package/carrier.mjs +230 -51
- package/control.mjs +2 -2
- package/create.mjs +2 -2
- package/device.mjs +2 -2
- package/enrol.mjs +2 -2
- package/envelope.mjs +6 -6
- package/file.mjs +2 -2
- package/fixtures/carrier-v0.json +1 -1
- package/fixtures/envelope-v0.json +1 -1
- package/fixtures/group-v2.json +2999 -0
- package/gen-carrier.mjs +2 -2
- package/gen-device.mjs +1 -1
- package/gen-envelope.mjs +2 -2
- package/gen-group2.mjs +291 -0
- package/gen-invite.mjs +2 -2
- package/gen-short.mjs +1 -1
- package/group.mjs +116 -17
- package/group2.mjs +1534 -0
- package/home-wire.mjs +812 -0
- package/invite.mjs +3 -3
- package/kdf.mjs +2 -2
- package/kin.mjs +62 -0
- package/link.mjs +6 -6
- package/package.json +25 -8
- package/page.mjs +507 -57
- package/photo.mjs +2 -2
- package/platform-node.mjs +6 -6
- package/prekeys.mjs +3 -3
- package/public.mjs +2 -2
- package/qr-decode.mjs +1 -1
- package/qr.mjs +2 -2
- package/relays.mjs +2 -2
- package/restore.mjs +2 -2
- package/rtc-web.mjs +3 -3
- package/short.mjs +2 -2
- package/store.mjs +22 -9
- package/test-carrier.mjs +32 -11
- package/test-device.mjs +3 -3
- package/test-enrol.mjs +9 -4
- package/test-envelope.mjs +2 -2
- package/test-file.mjs +2 -2
- package/test-group-move.mjs +225 -0
- package/test-group.mjs +1 -1
- package/test-group2.mjs +202 -0
- package/test-home.mjs +225 -0
- package/test-invite.mjs +1 -1
- package/test-link.mjs +3 -3
- package/test-platform.mjs +2 -2
- package/test-presence.mjs +2 -2
- package/test-push.mjs +5 -5
- package/test-relay-lane.mjs +3 -3
- package/test-short.mjs +1 -1
- package/test-tier.mjs +8 -2
- package/test-transfer-web.mjs +7 -7
- package/test-transfer.mjs +6 -6
- package/test-voice.mjs +2 -2
- package/test-ws.mjs +1 -1
- package/transfer-engine.mjs +6 -6
- package/transfer-node.mjs +5 -5
- package/transfer-web.mjs +3 -3
- package/transfer.mjs +8 -8
- package/voice-web.mjs +2 -2
- package/voice.mjs +7 -3
- 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:
|
|
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:
|
|
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
|
|
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
|
|
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:
|
|
2
|
-
// The platform seam (platform-node.mjs,
|
|
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:
|
|
2
|
-
// Presence (carrier.mjs "Presence",
|
|
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:
|
|
2
|
-
// The carrier's push registration (carrier.mjs setPush, sigelo-push/0;
|
|
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
|
-
//
|
|
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
|
|
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
|
|
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();
|
package/test-relay-lane.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
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
|
|
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
|
|
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:
|
|
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:
|
|
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' });
|
package/test-transfer-web.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// Transfers in the phone app (
|
|
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
|
|
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
|
|
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,7 +165,7 @@ 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" (
|
|
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
171
|
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');
|
|
@@ -245,7 +245,7 @@ try {
|
|
|
245
245
|
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
246
|
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
247
|
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
|
|
248
|
+
ok(await until(() => pRec('out', r1.id)?.state === 'done'), 'the phone record: done');
|
|
249
249
|
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
250
|
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
251
|
|
|
@@ -299,7 +299,7 @@ try {
|
|
|
299
299
|
const r6 = await X.send({ carrier: N.c, identity: N.identity, to: 'phone', path: join(dir, 'ro.bin') });
|
|
300
300
|
ok(await until(() => pRec('in', r6.id)?.reason === 'relay_only' || pRec('in', r6.id)?.state === 'relayed', 60000) && peers.length === n0,
|
|
301
301
|
'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}"`);
|
|
302
|
+
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
303
|
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
304
|
P.e.policy = () => 'all';
|
|
305
305
|
} finally {
|
package/test-transfer.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// Transfers (transfer.mjs, transfer-node.mjs, sigelo-transfer;
|
|
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 (
|
|
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)');
|
|
@@ -270,7 +270,7 @@ try {
|
|
|
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
272
|
A.c.setTier('bob', 'own'); B.c.setTier('alice', 'own');
|
|
273
|
-
// The accept rule
|
|
273
|
+
// The accept rule would land small files from an own contact unasked: asked here until its own part below.
|
|
274
274
|
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
275
|
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
276
|
|
|
@@ -334,7 +334,7 @@ try {
|
|
|
334
334
|
ok(await until(() => B.rec('in', r5.id)?.state === 'cancelled'), 'the sender cancels: cancelled at the receiver');
|
|
335
335
|
ok(await failure(() => X.accept({ carrier: B.c, identity: B.identity, id: r5.id })) === 'transfer_state', 'a cancelled transfer cannot be accepted');
|
|
336
336
|
|
|
337
|
-
// The accept rule
|
|
337
|
+
// The accept rule: from an own contact, under the size set, it lands without a question.
|
|
338
338
|
X.settings({ identity: B.identity, patch: { auto_mb: 25 } });
|
|
339
339
|
const small = seeded('auto', 2 * CHUNK + 1), r9 = await send(file('auto.jpg', small));
|
|
340
340
|
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 +349,7 @@ try {
|
|
|
349
349
|
const r11 = await send(file('big2.bin', seeded('big2', 2 * CHUNK)));
|
|
350
350
|
ok(await until(() => B.rec('in', r11.id)?.state === 'asked'), 'larger than the size set (2 MB over 1 MB): asked');
|
|
351
351
|
await X.decline({ carrier: B.c, identity: B.identity, id: r11.id });
|
|
352
|
-
// A group's file
|
|
352
|
+
// A group's file: one transfer per member paired with; one reached only through the creator: unpaired.
|
|
353
353
|
const gf = await X.prepare({ carrier: A.c, identity: A.identity, path: file('g.bin', seeded('g', 5000)) });
|
|
354
354
|
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
355
|
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:
|
|
2
|
-
// Voice messages (
|
|
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:
|
|
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
|
package/transfer-engine.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// Transfers, the part every host shares (
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Transfers, the part every host shares (apps/agent/TRANSFER.md): the
|
|
3
3
|
// records, the consent and the accept rule, the verbs and the Engine, with the disk, the file sent and
|
|
4
4
|
// Tor behind `io`. Node: transfer-node.mjs (fs, a tor daemon). The phone: transfer-web.mjs (the bridge
|
|
5
5
|
// holds the bytes; no Tor). The protocol is transfer.mjs's; the carrier is carrier.mjs's, in both.
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
// The records file: { v, out: { id: sender's record }, in: { id: receiver's record }, direct: { DID: true|false },
|
|
17
17
|
// auto: { DID: MB (0: always ask) }, settings: { tor, prefer, auto_mb, keep_location } }.
|
|
18
18
|
//
|
|
19
|
-
// The accept rule
|
|
19
|
+
// The accept rule: a file lands without a question up to the size set
|
|
20
20
|
// (settings.auto_mb, default 25 MB; per contact auto[DID]) from own agents and own contacts (tier own,
|
|
21
21
|
// ours) and from friends whose four words were compared (compared(did), the page's), when the disk has
|
|
22
22
|
// room; larger, or from anyone else (words not compared, a public-code joiner, quiet), it is asked. The
|
|
23
|
-
// direct switch picks the lane, not the yes
|
|
23
|
+
// direct switch picks the lane, not the yes: off, it comes over Tor or the relay lane.
|
|
24
24
|
//
|
|
25
25
|
// The relay lane (0.1.19): a file of at most RELAY_MAX (8 MiB, send-file's) to an own agent or contact, or to a friend
|
|
26
26
|
// whose words were compared, that cannot go direct (no path, no Tor: the end no_path) or whose channel dropped and did
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
// up to 8 MiB, Send over the relay. A channel that moves no byte for stallMs (30 s) counts as dropped; a receiver's
|
|
31
31
|
// record active with nothing for STALE_S (10 minutes) is listed as interrupted, and resume takes it again.
|
|
32
32
|
//
|
|
33
|
-
// "Always relay my media" (
|
|
33
|
+
// "Always relay my media" (UI-API.md "Settings"): policy() "relay" (the page's setting) or env
|
|
34
34
|
// SIGELO_ICE_POLICY=relay: the direct lane only through the relay's TURN (iceTransportPolicy relay, relayed candidates
|
|
35
35
|
// only in the SDP: rtc-web.mjs, apps/transfer/rtc.mjs); with no TURN to be had the direct lane is left out at once
|
|
36
36
|
// (RELAY_ONLY, reason relay_only on the receiver's record) and the file goes over Tor or the relay lane as without one.
|
|
@@ -123,7 +123,7 @@ export async function sendTo({ carrier, io, to, f, via = 'auto', direct, local =
|
|
|
123
123
|
return sendPrepared({ carrier, io, c, f, via, local, group, now });
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
|
-
* A group's file
|
|
126
|
+
* A group's file: one transfer per member this side is paired with, the file hashed once
|
|
127
127
|
* (f); members reached only through the creator are listed unpaired (they get the preview alone).
|
|
128
128
|
* members: [{ did, name, contact }] (the others; contact: paired here). Before anything is sent, a member
|
|
129
129
|
* whose direct switch is not set and no direct given: direct_ask naming them. → { sent, unpaired, failed }.
|
package/transfer-node.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// Transfers on Node (
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Transfers on Node (apps/agent/TRANSFER.md): transfer-engine.mjs's records, verbs
|
|
3
3
|
// and Engine over this machine's disk, the file sent read in place, and the Tor path (a tor daemon's
|
|
4
4
|
// control and SOCKS ports; nothing is ever installed for it); the direct path is sigelo-transfer,
|
|
5
5
|
// loaded only when a transfer starts. The protocol is transfer.mjs's.
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
// them. A finished file is placed as send-file places one (<identity>.files/<contact>-<16 hex>/<sha256[0..8]>-<name>),
|
|
24
24
|
// never opened, and given to inbox as one item {type: "file", …, transfer: id}.
|
|
25
25
|
//
|
|
26
|
-
// The direct switch (
|
|
26
|
+
// The direct switch (TRANSFER.md "Consent and the direct switch"): direct gives the contact this agent's public and LAN addresses. On
|
|
27
27
|
// for own contacts (tier own or ours), asked once for the others (direct_ask until a yes or a no is
|
|
28
|
-
// kept); off: Tor, else no path. The accept rule
|
|
28
|
+
// kept); off: Tor, else no path. The accept rule: transfer-engine.mjs. Tor: settings.tor
|
|
29
29
|
// (default on), effective only when a tor daemon answers (SIGELO_TOR: "<control host:port>[,<socks
|
|
30
30
|
// host:port>]", default 127.0.0.1:9051,127.0.0.1:9050; "off": none; SIGELO_TOR_PASSWORD for a
|
|
31
31
|
// HashedControlPassword). STUN: SIGELO_STUN, host:port, comma-separated ("" = host candidates only),
|
|
@@ -187,7 +187,7 @@ export class Engine extends E.Engine {
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
// ---------------------------------------------------------------- Tor
|
|
190
|
+
// ---------------------------------------------------------------- Tor
|
|
191
191
|
|
|
192
192
|
/** SIGELO_TOR → { control: [host, port], socks: [host, port], password } | null ("off"). */
|
|
193
193
|
export function torConfig(env = process.env) {
|
package/transfer-web.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// Transfers in a page that holds its own identity (the phone app,
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Transfers in a page that holds its own identity (the phone app, apps/agent/TRANSFER.md "The phone app"): the io of
|
|
3
3
|
// transfer-engine.mjs over the platform's files (the records, the chunk bitmaps and lists: small) and
|
|
4
4
|
// the shell's big-file bridge (the bytes: never in the page's storage, never a Blob held whole).
|
|
5
5
|
//
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// hash(doc) → { size, mtime, sha256, hashes } in the shell (each 1 MiB chunk and the whole), hashes: bytes
|
|
13
13
|
// stat(doc) → { size, mtime } read(doc, offset, length, { size, mtime }) → bytes (a range; file_changed when either moved)
|
|
14
14
|
// write(part, offset, bytes); flush(part); sha256(part) → hex; drop(part); free() → bytes
|
|
15
|
-
// land(part, name) → { uri, name } the partial moved into
|
|
15
|
+
// land(part, name) → { uri, name } the partial moved into Android's Downloads (MediaStore, pending until whole)
|
|
16
16
|
// part: the transfer id. Partials live in the app's private storage until they land.
|
|
17
17
|
import { CHUNK, chunkLength } from './transfer.mjs';
|
|
18
18
|
import { fail } from './kdf.mjs';
|