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.
- 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 +542 -63
- 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 +15 -7
- package/test-transfer.mjs +24 -6
- package/test-voice.mjs +2 -2
- package/test-ws.mjs +1 -1
- package/transfer-engine.mjs +46 -16
- package/transfer-node.mjs +9 -7
- package/transfer-web.mjs +4 -4
- package/transfer.mjs +8 -8
- package/voice-web.mjs +2 -2
- package/voice.mjs +7 -3
- package/words-lock.mjs +2 -2
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
// Moving today's groups (design/groups-build.md §5, step 8), on a loopback relay with one clock: H (a person) made a
|
|
4
|
+
// sigelo-group/1 group of its own agent A, a friend F (a new app), an old app O (sigelo-group/1 only: the code before step 8,
|
|
5
|
+
// which has no branch for the label sigelo-group/2) that never updates, and an old app U that updates later. H moves it: a
|
|
6
|
+
// home group, each member invited over its pairing, the update line. A joins at once (own), F after its operator's yes, both
|
|
7
|
+
// let in by H's app without a tap; the old apps show the invite's text and the update line, and nothing breaks: O writes on
|
|
8
|
+
// in the old group and nobody files it. U updates and joins with the link the text gave. Then: a direct invite (group add)
|
|
9
|
+
// of a contact to a home group, a quiet contact's invite ignored, a forged one refused, a frozen group still read and not
|
|
10
|
+
// moved by a member, and no group of contacts left to make at any surface but this module. Prints "ALL PASS (n)".
|
|
11
|
+
// node test-group-move.mjs
|
|
12
|
+
import { createHash } from 'node:crypto';
|
|
13
|
+
import { copyFileSync, existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
14
|
+
import { tmpdir } from 'node:os';
|
|
15
|
+
import { dirname, join } from 'node:path';
|
|
16
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
17
|
+
import { attest, keygen } from 'sigelo';
|
|
18
|
+
import { OPERATOR_CTX } from './store.mjs';
|
|
19
|
+
import * as G1 from './group.mjs';
|
|
20
|
+
import * as G2 from './group2.mjs';
|
|
21
|
+
|
|
22
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
23
|
+
let count = 0;
|
|
24
|
+
const fails = [];
|
|
25
|
+
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)})`); };
|
|
26
|
+
const failure = async (f) => { try { await f(); return 'accepted'; } catch (e) { return e.check ?? `exception ${e.stack}`; } };
|
|
27
|
+
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', '..', 'relay');
|
|
28
|
+
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); }
|
|
29
|
+
setTimeout(() => { console.log(`FAIL the run did not finish in 900 s (${count} checks so far)`); process.exit(1); }, 900000).unref();
|
|
30
|
+
const { startRelay } = await import(pathToFileURL(join(RELAY_DIR, 'server.mjs')).href);
|
|
31
|
+
const { relayPolicy } = await import(pathToFileURL(join(RELAY_DIR, 'allowance.mjs')).href);
|
|
32
|
+
const { Carrier, GROUP_SEND, pathsFor } = await import('./carrier.mjs');
|
|
33
|
+
|
|
34
|
+
// The old app: this directory's modules as they were before step 8, made by taking out the two places that read the label
|
|
35
|
+
// sigelo-group/2 (the carrier's branch, isGroup). Each cut must be found: a change of either line fails here, not silently.
|
|
36
|
+
const dir = mkdtempSync(join(process.env.TMPDIR ?? tmpdir(), 'sigelo-move-')), oldDir = join(dir, 'old-app');
|
|
37
|
+
{
|
|
38
|
+
const { mkdirSync } = await import('node:fs');
|
|
39
|
+
mkdirSync(oldDir);
|
|
40
|
+
for (const f of readdirSync(HERE)) if (f.endsWith('.mjs') && !f.startsWith('test-') && !f.startsWith('gen-')) copyFileSync(join(HERE, f), join(oldDir, f));
|
|
41
|
+
symlinkSync(join(HERE, 'node_modules'), join(oldDir, 'node_modules'));
|
|
42
|
+
const cut = (file, from, to) => {
|
|
43
|
+
const p = join(oldDir, file), t = readFileSync(p, 'utf8');
|
|
44
|
+
if (!t.includes(from)) throw new Error(`the old app: ${file} no longer has ${JSON.stringify(from)}`);
|
|
45
|
+
writeFileSync(p, t.replace(from, to));
|
|
46
|
+
};
|
|
47
|
+
cut('carrier.mjs', 'r.body.label === GROUP_LABEL || r.body.label === GROUP2_LABEL', 'r.body.label === GROUP_LABEL');
|
|
48
|
+
cut('group.mjs', 'export const isGroup = (m) => m?.label === GROUP_LABEL || m?.label === GROUP2_LABEL;', 'export const isGroup = (m) => m?.label === GROUP_LABEL;');
|
|
49
|
+
}
|
|
50
|
+
const OC = await import(pathToFileURL(join(oldDir, 'carrier.mjs')).href), OG = await import(pathToFileURL(join(oldDir, 'group.mjs')).href);
|
|
51
|
+
|
|
52
|
+
const CREATED = '2026-10-01T00:00:00Z', DAY = 86400;
|
|
53
|
+
let skew = 0, now = Math.floor(Date.now() / 1000);
|
|
54
|
+
setInterval(() => { now = Math.floor(Date.now() / 1000) + skew; }, 200).unref();
|
|
55
|
+
const tick = (s = 5) => { skew += s; now = Math.floor(Date.now() / 1000) + skew; };
|
|
56
|
+
const seed = (l) => new Uint8Array(createHash('sha256').update(`sigelo-move-test/0 ${l}`).digest());
|
|
57
|
+
const HOST = 'relay.test';
|
|
58
|
+
const relay = await startRelay({ host: HOST, db: join(dir, 'relay.db'), tcpPort: 0, httpPort: 0, loginRate: 100000, verifyBudget: 1e9, clock: () => now, diskUsed: () => 0.1, log: () => {},
|
|
59
|
+
policy: (ctx) => relayPolicy(ctx, { pow: { bits: 4, loadBits: 8, loadPerHour: 1000, cost: { m: 8, t: 1, p: 1 } } }),
|
|
60
|
+
park: { lookups: { n: 1000, window: 600 }, parks: { n: 1000, window: 3600 }, lookupsAll: { n: 8000, window: 600 }, publicFetches: { n: 1000, window: 600 }, pro: () => true } });
|
|
61
|
+
const endpoints = { [HOST]: { mqtt: `mqtt://127.0.0.1:${relay.ports.tcp}`, http: `http://127.0.0.1:${relay.ports.http}` } };
|
|
62
|
+
function agent(label, { old = false, selfName, selfKind } = {}) {
|
|
63
|
+
const k = keygen({ seed: seed(label), recovery: 'sha256:' + '0'.repeat(64), created: CREATED, nonce: seed(`${label} nonce`).slice(0, 16) });
|
|
64
|
+
const a = { label, did: k.did, secret: k.secret, genesis: k.genesis, bundle: { v: 'sigelo/0', typ: 'bundle', genesis: k.genesis, rotations: [], bindings: [], attestations: [], issuers: [] }, out: [], seen: [] };
|
|
65
|
+
a.idf = join(dir, `${label}.local.json`);
|
|
66
|
+
a.start = (lib) => {
|
|
67
|
+
a.lib = lib;
|
|
68
|
+
a.c = new lib.C.Carrier({ identity: () => ({ secret: a.secret, bundle: a.bundle }), ...lib.C.pathsFor(a.idf), relay: HOST, endpoints, shortRelay: HOST, clock: () => now, keep: true, backoff: [100, 400],
|
|
69
|
+
...(selfName && { selfName }), ...(selfKind && { selfKind }) });
|
|
70
|
+
a.f = lib.G.groupsPath(a.idf); a.f2 = G2.groups2Path(a.idf); a.o2 = { carrier: a.c, file: a.f2 };
|
|
71
|
+
};
|
|
72
|
+
a.start(old ? { C: OC, G: OG } : { C: { Carrier, pathsFor }, G: G1 });
|
|
73
|
+
return a;
|
|
74
|
+
}
|
|
75
|
+
const operate = (op, a) => {
|
|
76
|
+
a.bundle.attestations.push(attest({ secret: op.secret, iss: op.did, sub: a.did, iat: now - 60, exp: now + 90 * DAY, ctx: OPERATOR_CTX, admission: 'invite', admission_by: op.did, claims: { relay: HOST } }));
|
|
77
|
+
a.bundle.issuers.push(op.genesis);
|
|
78
|
+
};
|
|
79
|
+
async function pair(ci, ca, name, back) {
|
|
80
|
+
const inv = await ci.c.invite({ name });
|
|
81
|
+
await ca.c.accept(inv.code, { name: back, wait: 0.3 });
|
|
82
|
+
await ci.c.inbox(); await ca.c.inbox(); await ci.c.inbox();
|
|
83
|
+
}
|
|
84
|
+
// One turn, as sigelo-agent's inbox does: the inbox, then the groups' handle (the old app's own module for an old app).
|
|
85
|
+
const turn = async (a) => {
|
|
86
|
+
tick();
|
|
87
|
+
const b = await a.c.inbox();
|
|
88
|
+
const r = await a.lib.G.handle({ carrier: a.c, file: a.f, batch: b });
|
|
89
|
+
a.out.push(r); a.seen.push(...r.batch.messages);
|
|
90
|
+
return r;
|
|
91
|
+
};
|
|
92
|
+
const rounds = async (n, ...as) => { for (let i = 0; i < n; i++) for (const a of as) await turn(a); };
|
|
93
|
+
const g1At = (a, gid) => a.lib.G.state(a.f, now, (s) => s.groups[gid] ?? null);
|
|
94
|
+
const homeOf = (a, gid) => G2.list(a.o2).find((g) => g.gid === gid) ?? null;
|
|
95
|
+
const said = (a, text) => a.seen.filter((m) => m.label === 'sigelo-group/1' && m.content === text);
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
const H = agent('human', { selfName: 'Hana' }), A = agent('agent'), F = agent('friend', { selfName: 'Fay' }), O = agent('old', { old: true }), U = agent('later', { old: true }), Q = agent('quiet');
|
|
99
|
+
operate(H, A);
|
|
100
|
+
for (const x of [A, F, O, U, Q]) await pair(H, x, x.label, 'human');
|
|
101
|
+
await pair(F, A, 'agent', 'friend');
|
|
102
|
+
await rounds(2, H, A, F, O, U, Q);
|
|
103
|
+
const tiers = Object.fromEntries(A.c.contacts().contacts.map((c) => [c.name, c.tier]));
|
|
104
|
+
ok(tiers.human === 'own' && tiers.friend === 'friend', 'set up: A is H\'s own agent; F a friend of A', JSON.stringify(tiers));
|
|
105
|
+
|
|
106
|
+
// ---- a group of contacts made before step 8, everyone in it
|
|
107
|
+
const made = await G1.create({ carrier: H.c, file: H.f, name: 'launch', members: ['agent', 'friend', 'old', 'later'], humans: ['friend', 'old', 'later'], brake: 7 });
|
|
108
|
+
const old = made.group.gid;
|
|
109
|
+
await rounds(1, A, F, O, U);
|
|
110
|
+
for (const x of [F, O, U]) x.lib.G.join({ carrier: x.c, file: x.f, group: old });
|
|
111
|
+
await G1.send({ carrier: H.c, file: H.f, group: 'launch', text: 'before the move' });
|
|
112
|
+
await rounds(1, A, F, O, U);
|
|
113
|
+
ok([A, F, O, U].every((x) => g1At(x, old)?.status === 'member' && said(x, 'before the move').length === 1), 'a sigelo-group/1 group of five: everyone reads H');
|
|
114
|
+
|
|
115
|
+
// ---- H moves it
|
|
116
|
+
ok(await failure(() => G1.move({ carrier: A.c, file: A.f, group: old })) === 'group_creator', 'a member moves it: group_creator');
|
|
117
|
+
const mv = await G1.move({ carrier: H.c, file: H.f, group: 'launch' });
|
|
118
|
+
const neu = mv.home.gid, hg = homeOf(H, neu);
|
|
119
|
+
ok(mv.group.status === 'moved' && mv.group.moved.gid === neu && hg?.role === 'owner' && hg.moved_from === old && hg.name === 'launch' && hg.settings.brake === 7 && hg.settings.history === 'request',
|
|
120
|
+
'H moves it: the home group (same name, brake kept, history request), the old one moved', JSON.stringify([mv.group, hg]));
|
|
121
|
+
ok(mv.invited.length === 4 && mv.invited.every((x) => x.status === 'sent') && mv.line.length === 4 && mv.line.every((x) => x.status === 'sent') && /^GRP-/.test(mv.code ?? ''),
|
|
122
|
+
'each member invited over its pairing, then the update line to each; the link has a GRP code', JSON.stringify(mv));
|
|
123
|
+
ok(await failure(() => G1.send({ carrier: H.c, file: H.f, group: old, text: 'still?' })) === 'group_moved' && await failure(() => G1.move({ carrier: H.c, file: H.f, group: old })) === 'group_moved',
|
|
124
|
+
'the old group takes nothing more from H: send and a second move refused, group_moved');
|
|
125
|
+
ok(G1.history({ carrier: H.c, file: H.f, group: old }).some((i) => i.content === 'before the move'), 'its history stays readable');
|
|
126
|
+
|
|
127
|
+
await rounds(1, A, F, O, U);
|
|
128
|
+
// A (own): joined at once; F (friend): an invitation for its operator; both: the old group moved, the update line not shown.
|
|
129
|
+
ok(A.out.at(-1).moved[0]?.to === neu && A.out.at(-1).joined.some((j) => j.gid === neu && j.home === HOST) && homeOf(A, neu)?.status === 'joining', 'A (own agent): the old group moved, the new one asked at once', JSON.stringify(A.out.at(-1)));
|
|
130
|
+
const fn = F.out.at(-1).notices.find((n) => n.gid === neu);
|
|
131
|
+
ok(fn?.why === 'invited' && fn.v === 2 && fn.moved_from === old && homeOf(F, neu)?.status === 'invited' && homeOf(F, neu).invited.by === H.did, 'F (friend): an invitation to the home group, for its operator', JSON.stringify(F.out.at(-1)));
|
|
132
|
+
ok([A, F].every((x) => g1At(x, old).status === 'moved' && said(x, G1.MOVED_TEXT).length === 0 && x.out.at(-1).refused.length === 0), 'the new apps: the old group moved, the update line not shown, nothing refused');
|
|
133
|
+
ok(G1.history({ carrier: F.c, file: F.f, group: old }).some((i) => i.content === 'before the move') && await failure(() => G1.send({ carrier: F.c, file: F.f, group: old, text: 'hi' })) === 'group_moved',
|
|
134
|
+
'F reads the old history, writes nothing more there');
|
|
135
|
+
// The old apps: the update line in the group, the invite as a message whose text comes first; no refusal.
|
|
136
|
+
for (const x of [O, U]) {
|
|
137
|
+
const inv = x.seen.find((m) => m.label === 'sigelo-group/2');
|
|
138
|
+
ok(said(x, G1.MOVED_TEXT).length === 1 && inv && inv.content.startsWith('launch moved to a home group. Update sigelo to keep reading it, then join with https://sigelo.io/join#GRP-')
|
|
139
|
+
&& x.out.at(-1).refused.length === 0 && g1At(x, old).status === 'member', `${x.label} (old app): the update line, the invite's text first, nothing refused`, JSON.stringify([inv?.content.slice(0, 120), x.out.at(-1).refused]));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// H's app lets A in without a tap (expected), F once its operator says yes.
|
|
143
|
+
await G2.sync(H.o2);
|
|
144
|
+
await G2.sync(A.o2);
|
|
145
|
+
ok(homeOf(A, neu)?.status === 'member', 'H\'s sync lets A in (it invited A): A a member', JSON.stringify(homeOf(A, neu)));
|
|
146
|
+
ok(await failure(() => G2.send({ ...F.o2, group: neu, text: 'x' })) === 'group_pending', 'F writes before joining: group_pending');
|
|
147
|
+
const fj = await G2.join({ ...F.o2, code: neu, name: 'Fay', kind: 'human' });
|
|
148
|
+
ok(fj.status === 'waiting', 'F\'s operator joins it (one tap): waiting', JSON.stringify(fj));
|
|
149
|
+
await G2.sync(H.o2);
|
|
150
|
+
await G2.sync(F.o2);
|
|
151
|
+
ok(homeOf(F, neu)?.status === 'member' && G2.requests && homeOf(H, neu).requests === 0, 'H\'s app lets F in at once: no request waits', JSON.stringify(homeOf(H, neu)));
|
|
152
|
+
await G2.send({ ...H.o2, group: neu, text: 'welcome to the new home' });
|
|
153
|
+
const fr = await G2.sync(F.o2), ar = await G2.sync(A.o2);
|
|
154
|
+
ok([fr, ar].every((r) => r.items.some((i) => i.content === 'welcome to the new home')), 'A and F read H in the home group');
|
|
155
|
+
|
|
156
|
+
// O never updates: it writes on in the old group; H (moved) neither files nor carries it, nobody refuses it.
|
|
157
|
+
const os = await O.lib.G.send({ carrier: O.c, file: O.f, group: old, text: 'anyone here?' });
|
|
158
|
+
ok(os.copies.every((x) => x.status === 'sent'), 'O (old app) writes in the old group: sent', JSON.stringify(os));
|
|
159
|
+
await rounds(1, H, A, F, U);
|
|
160
|
+
ok([H, A, F, U].every((x) => said(x, 'anyone here?').length === 0 && x.out.at(-1).refused.length === 0) && H.out.at(-1).forwarded === 0, 'nobody files it, H carries it on to nobody, no refusal');
|
|
161
|
+
|
|
162
|
+
// U updates (the same files, today's code) and joins with the link its message gave; H's app lets it in.
|
|
163
|
+
const link = /https:\/\/sigelo\.io\/join#GRP-[0-9A-Z-]+/.exec(U.seen.find((m) => m.label === 'sigelo-group/2').content)[0];
|
|
164
|
+
await U.c.stop?.();
|
|
165
|
+
U.start({ C: { Carrier, pathsFor }, G: G1 });
|
|
166
|
+
ok(g1At(U, old).status === 'member' && G1.history({ carrier: U.c, file: U.f, group: old }).some((i) => i.content === G1.MOVED_TEXT), 'U updated: its old group as it was, the update line in it');
|
|
167
|
+
await G2.join({ ...U.o2, code: link, name: 'Ulla', kind: 'human' });
|
|
168
|
+
await G2.sync(H.o2);
|
|
169
|
+
await G2.sync(U.o2);
|
|
170
|
+
ok(homeOf(U, neu)?.status === 'member' && homeOf(H, neu).members.length === 4, 'U joins with the link: let in at once, four members', JSON.stringify(homeOf(H, neu)?.members));
|
|
171
|
+
|
|
172
|
+
// ---- a direct invite to a home group (group add)
|
|
173
|
+
const crew = (await G2.create({ ...H.o2, name: 'crew', kind: 'human', selfName: 'Hana' })).group.gid;
|
|
174
|
+
ok(await failure(() => G2.add({ ...H.o2, group: crew, members: ['nobody'] })) === 'not_contact', 'add a name that is no contact: not_contact');
|
|
175
|
+
ok(await failure(() => G2.add({ ...F.o2, group: neu, members: ['agent'] })) === 'group_role', 'add by a member, not an admin: group_role');
|
|
176
|
+
ok(await failure(() => G2.add({ ...H.o2, group: neu, members: ['friend'] })) === 'group_member', 'add a member again: group_member');
|
|
177
|
+
const ad = await G2.add({ ...H.o2, group: crew, members: ['friend'] });
|
|
178
|
+
ok(ad.copies.length === 1 && ad.copies[0].status === 'sent' && ad.gid === crew, 'H invites F to crew over their pairing', JSON.stringify(ad));
|
|
179
|
+
await turn(F);
|
|
180
|
+
ok(homeOf(F, crew)?.status === 'invited' && F.out.at(-1).notices.some((n) => n.gid === crew && n.why === 'invited' && !n.moved_from), 'F: an invitation, its operator\'s to take');
|
|
181
|
+
const lv = await G2.leave({ ...F.o2, group: 'crew' });
|
|
182
|
+
ok(lv.declined === true && homeOf(F, crew) === null, 'F declines it: gone, nothing said', JSON.stringify(lv));
|
|
183
|
+
await G2.add({ ...H.o2, group: crew, members: ['friend'] });
|
|
184
|
+
await turn(F);
|
|
185
|
+
await G2.join({ ...F.o2, code: 'crew', name: 'Fay', kind: 'human' });
|
|
186
|
+
await G2.sync(H.o2);
|
|
187
|
+
await G2.sync(F.o2);
|
|
188
|
+
ok(homeOf(F, crew)?.status === 'member', 'invited again, F joins by the group\'s name: let in at once');
|
|
189
|
+
ok(Object.keys(JSON.parse(readFileSync(H.f2, 'utf8')).groups[crew].links).length === 1, 'the two invites share one direct link');
|
|
190
|
+
|
|
191
|
+
// A quiet contact's invite: ignored. A forged one (F passes on H's invite as if its own): refused, group_forged.
|
|
192
|
+
await Q.c.setTier('human', 'quiet');
|
|
193
|
+
const qg = (await G2.create({ ...H.o2, name: 'hush', kind: 'human' })).group.gid;
|
|
194
|
+
await G2.add({ ...H.o2, group: qg, members: ['quiet'] });
|
|
195
|
+
await turn(Q);
|
|
196
|
+
ok(homeOf(Q, qg) === null && Q.out.at(-1).ignored >= 1, 'an invite from a quiet contact: ignored', JSON.stringify(Q.out.at(-1)));
|
|
197
|
+
const inv = JSON.parse(readFileSync(F.f2, 'utf8')).groups[crew];
|
|
198
|
+
await G2.add({ ...H.o2, group: qg, members: ['friend'] });
|
|
199
|
+
await turn(F);
|
|
200
|
+
const passed = JSON.parse(readFileSync(F.f2, 'utf8')).groups[qg].invite;
|
|
201
|
+
await F.c.send(A.did, G2.pairContent('join this', passed), { label: 'sigelo-group/2', internal: GROUP_SEND });
|
|
202
|
+
await turn(A);
|
|
203
|
+
ok(A.out.at(-1).refused.some((x) => x.check === 'group_forged') && homeOf(A, qg) === null, 'H\'s invite passed on by F: group_forged at A', JSON.stringify(A.out.at(-1).refused));
|
|
204
|
+
ok(inv.status === 'member', 'and F stayed in crew');
|
|
205
|
+
ok(await failure(() => F.c.send(A.did, 'x', { label: 'sigelo-group/2' })) === 'body', 'a caller cannot send the label sigelo-group/2: body');
|
|
206
|
+
|
|
207
|
+
// ---- a frozen group: still read; a member cannot move it
|
|
208
|
+
const side = (await G1.create({ carrier: F.c, file: F.f, name: 'side', members: ['agent'] })).group.gid;
|
|
209
|
+
await turn(A);
|
|
210
|
+
G1.join({ carrier: A.c, file: A.f, group: side });
|
|
211
|
+
await G1.send({ carrier: F.c, file: F.f, group: side, text: 'side talk' });
|
|
212
|
+
await turn(A);
|
|
213
|
+
await G1.leave({ carrier: F.c, file: F.f, group: side });
|
|
214
|
+
await turn(A);
|
|
215
|
+
ok(g1At(A, side)?.status === 'frozen' && G1.history({ carrier: A.c, file: A.f, group: side }).some((i) => i.content === 'side talk'), 'a frozen group (its creator left): read as before', JSON.stringify(g1At(A, side)?.status));
|
|
216
|
+
ok(await failure(() => G1.move({ carrier: A.c, file: A.f, group: side })) === 'group_creator', 'a member moves a frozen group: group_creator (start a new group instead)');
|
|
217
|
+
ok(G1.list({ carrier: H.c, file: H.f }).find((g) => g.gid === old)?.moved?.gid === neu, 'the list says where a moved group went');
|
|
218
|
+
for (const x of [H, A, F, O, U, Q]) await x.c.stop?.();
|
|
219
|
+
} finally {
|
|
220
|
+
await relay.close();
|
|
221
|
+
rmSync(dir, { recursive: true, force: true });
|
|
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-group.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
2
|
// Groups (group.mjs, contract sigelo-group/1): the message and roster checks and the file first;
|
|
3
3
|
// then, with the relay checkout beside apps/contact/ (SIGELO_RELAY_DIR, else ../../relay), on a loopback
|
|
4
4
|
// relay with one clock: an operator makes a group of its five agents and a friend (eight identities
|
package/test-group2.mjs
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// sigelo-group/2, the wire (home-wire.mjs, GROUPS.md): fixtures/group-v2.json against the code, gen-group2.mjs
|
|
3
|
+
// --check, every entry opened from the seeds and its signature checked offline, the door and the answer,
|
|
4
|
+
// the letters (symmetric and KEM), the boxes, the invite and its GRP code, every refusal by check and
|
|
5
|
+
// exact message, every role rule.
|
|
6
|
+
// node apps/contact/test-group2.mjs → ALL PASS (n)
|
|
7
|
+
import { spawnSync } from 'node:child_process';
|
|
8
|
+
import { readFileSync } from 'node:fs';
|
|
9
|
+
import { dirname, join } from 'node:path';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { canonicalize } from 'sigelo';
|
|
12
|
+
import * as W from './home-wire.mjs';
|
|
13
|
+
import { cast, seed } from './gen-group2.mjs';
|
|
14
|
+
|
|
15
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
let count = 0;
|
|
17
|
+
const fails = [];
|
|
18
|
+
const ok = (cond, what) => { count++; if (!cond) fails.push(what); };
|
|
19
|
+
const err = (f) => { try { f(); return null; } catch (e) { return { check: e.check ?? `exception ${e.constructor.name}`, message: e.message }; } };
|
|
20
|
+
const checkOf = (f) => err(f)?.check ?? 'accepted';
|
|
21
|
+
const H = (h) => Uint8Array.from(Buffer.from(h, 'hex'));
|
|
22
|
+
const same = (a, b) => canonicalize(a) === canonicalize(b);
|
|
23
|
+
|
|
24
|
+
// ================================================================ the fixture reproduces
|
|
25
|
+
{
|
|
26
|
+
const gen = spawnSync(process.execPath, [join(HERE, 'gen-group2.mjs'), '--check'], { encoding: 'utf8' });
|
|
27
|
+
ok(gen.status === 0, `gen-group2.mjs --check: ${(gen.stderr || gen.stdout).trim()}`);
|
|
28
|
+
}
|
|
29
|
+
const F = JSON.parse(readFileSync(join(HERE, 'fixtures', 'group-v2.json'), 'utf8'));
|
|
30
|
+
const { A, B0, C, chains, gkeys } = cast();
|
|
31
|
+
const { gid, topic } = F.group;
|
|
32
|
+
const E1 = seed('E1'), E2 = seed('E2'), V = seed('V');
|
|
33
|
+
const K = { 1: W.epochKeys(E1, gid), 2: W.epochKeys(E2, gid) }, AW = { 1: W.adminKey(V, gid, 1), 2: W.adminKey(V, gid, 2) };
|
|
34
|
+
const ORIG = { A: A.did, B: B0.did, C: C.did };
|
|
35
|
+
|
|
36
|
+
// ================================================================ identifiers and keys from the seeds
|
|
37
|
+
{
|
|
38
|
+
ok(W.gidOf(A.did, F.group.nonce) === gid && W.topicOf(gid) === topic && /^g\/[0-9a-f]{32}$/.test(topic), 'gid from the creator\'s original DID and nonce; topic from gid');
|
|
39
|
+
ok(W.gidOf(B0.did, F.group.nonce) !== gid, 'another creator, another gid');
|
|
40
|
+
for (const e of [1, 2]) {
|
|
41
|
+
const k = F.keys[`epoch${e}`];
|
|
42
|
+
ok(Buffer.from(K[e].W.pub).toString('hex') === k.W && Buffer.from(K[e].HK).toString('hex') === k.HK && Buffer.from(AW[e].pub).toString('hex') === k.AW, `epoch ${e}: W, HK, AW from E and V`);
|
|
43
|
+
}
|
|
44
|
+
ok(Buffer.from(AW[1].pub).toString('hex') !== Buffer.from(AW[2].pub).toString('hex'), 'AW differs per epoch');
|
|
45
|
+
for (const k of ['A', 'B', 'C']) {
|
|
46
|
+
ok(Buffer.from(W.chainStart(E1, gid, ORIG[k])).toString('hex') === F.keys.chain_starts[k], `chain start of ${k}`);
|
|
47
|
+
ok(Buffer.from(W.senderHint(K[1].HK, ORIG[k])).toString('hex') === F.keys.hints[k], `sender hint of ${k}`);
|
|
48
|
+
}
|
|
49
|
+
ok(Buffer.from(W.vaultKey(V, gid)).toString('hex') === F.keys.vault && Buffer.from(W.addKey(K[1].HK, gid)).toString('hex') === F.keys.add && Buffer.from(W.callKey(E1, gid, '0'.repeat(32))).toString('hex') === F.keys.call, 'vault, add and call keys');
|
|
50
|
+
ok(W.letterHint(seed('L A'), 2) === F.keys.letter_hints.A && Buffer.from(W.nextLetterKey(seed('L A'), gid)).toString('hex') === F.keys.next_letter.A, 'letter hint and the letter key\'s step');
|
|
51
|
+
const ck = W.chainStart(E1, gid, A.did), mk3 = W.messageKey(ck, 3), at2 = W.chainAt(ck, 2);
|
|
52
|
+
ok(Buffer.from(W.messageKey(at2, 1)).equals(Buffer.from(mk3)) && Buffer.from(ck).toString('hex') === F.keys.chain_starts.A, 'messageKey(ck0, 3) = messageKey(chainAt(ck0, 2), 1); ck0 kept');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ================================================================ every entry: credential, header, body, signature
|
|
56
|
+
{
|
|
57
|
+
const chainOf = (x) => (x.signer === 'B1' ? chains.B1 : x.sender === 'B' ? chains.B0 : chains[x.sender]);
|
|
58
|
+
for (const x of F.entries) {
|
|
59
|
+
const bytes = H(x.entry), e = x.epoch, p = W.parseEntry(bytes);
|
|
60
|
+
ok(p.epoch === e && p.flags === x.flags && p.slot === x.slot, `${x.label}: the relay reads epoch ${e}, flags ${x.flags}, slot ${x.slot}`);
|
|
61
|
+
ok(W.credentialOk(bytes, topic, { write: K[e].W.pub, admin: AW[e].pub }), `${x.label}: the credential verifies`);
|
|
62
|
+
ok(!W.credentialOk(bytes, topic, { write: AW[e].pub, admin: K[e].W.pub }), `${x.label}: not under the other credential`);
|
|
63
|
+
ok(!W.credentialOk(bytes, W.topicOf('0'.repeat(32)), { write: K[e].W.pub, admin: AW[e].pub }), `${x.label}: not on another topic`);
|
|
64
|
+
const h = W.openHeader(bytes, topic, K[e].HK);
|
|
65
|
+
ok(Buffer.from(h.hint).equals(Buffer.from(W.senderHint(K[e].HK, ORIG[x.sender]))) && h.n === x.n, `${x.label}: header → ${x.sender}'s hint, n ${x.n}`);
|
|
66
|
+
const mk = W.messageKey(W.chainStart(e === 1 ? E1 : E2, gid, ORIG[x.sender]), h.n);
|
|
67
|
+
ok(Buffer.from(mk).toString('hex') === x.mk, `${x.label}: the message key from the chain start`);
|
|
68
|
+
const content = W.openEntry(bytes, topic, mk);
|
|
69
|
+
ok(same(content, x.content), `${x.label}: the body opens to the fixture's content`);
|
|
70
|
+
const who = W.verifyContent(content, chainOf(x), x.content.body.iat);
|
|
71
|
+
ok(who.original === ORIG[x.sender], `${x.label}: signed by ${x.sender} (original ${who.original.slice(0, 20)}…), offline`);
|
|
72
|
+
ok(checkOf(() => W.checkFresh(content.body, content.body.iat + 3600)) === 'accepted', `${x.label}: fresh an hour later`);
|
|
73
|
+
ok(bytes.length % 256 === (W.BODY + W.TAG) % 256 && bytes.length >= W.BODY + 256 + W.TAG, `${x.label}: ${bytes.length} bytes = 164 + padded body`);
|
|
74
|
+
}
|
|
75
|
+
const create = F.entries.find((x) => x.label === 'create');
|
|
76
|
+
ok(W.verifyCreate(create.content, chains.A, F.t0).original === A.did, 'the create: gid is the creator\'s');
|
|
77
|
+
const addC = F.entries.find((x) => x.label === 'add C');
|
|
78
|
+
const r = W.verifyAdd(addC.content, chains.A, F.t0);
|
|
79
|
+
ok(r.joiner.original === C.did && r.admin.original === A.did, 'an add: the admin\'s signature and the joiner\'s request inside, offline');
|
|
80
|
+
ok(Buffer.from(W.openForAdmins(V, gid, C.did, addC.content.body.vault)).equals(Buffer.from(seed('L C'))), 'add.vault: C\'s letter key for admins');
|
|
81
|
+
ok(Buffer.from(W.openChainStart(K[1].HK, gid, C.did, addC.content.body.ck)).equals(Buffer.from(W.chainStart(E1, gid, C.did))), 'add.ck: C\'s chain start for members without E');
|
|
82
|
+
ok(checkOf(() => W.openForAdmins(V, gid, A.did, addC.content.body.vault)) === 'group_key', 'add.vault bound to its member (another DID: group_key)');
|
|
83
|
+
const link = F.entries.find((x) => x.label === 'link');
|
|
84
|
+
ok(Buffer.from(W.openDoorSeed(V, gid, link.content.body.id, link.content.body.box)).equals(Buffer.from(seed('door seed'))), 'link.box: the door seed for admins');
|
|
85
|
+
// The rotated sender: its entry carries its chain; the new key signs.
|
|
86
|
+
const rot = F.entries.find((x) => x.label === 'msg after rotation');
|
|
87
|
+
ok(same(rot.content.chain, chains.B1) && W.verifyContent(rot.content, rot.content.chain, F.t0 + 2000).original === B0.did, 'after a rotation the entry carries the chain; the original DID stays');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ================================================================ welcome, answer, door
|
|
91
|
+
{
|
|
92
|
+
const welC = F.entries.find((x) => x.label === 'welcome C'), boxC = W.openBox(welC.content.body, gkeys.C.secretKey);
|
|
93
|
+
ok(Buffer.from(W.unb64u(boxC.L)).equals(Buffer.from(seed('L C'))) && boxC.secrets.length === 0, 'welcome C: its letter key; history "request": no old secrets');
|
|
94
|
+
ok(['A', 'B', 'C'].every((k) => boxC.chains.some((c) => c.hint === F.keys.hints[k])), 'welcome C: chains of A, B and its own');
|
|
95
|
+
const cB = boxC.chains.find((c) => c.hint === F.keys.hints.B), msg = F.entries.find((x) => x.label === 'msg');
|
|
96
|
+
ok(same(W.openEntry(H(msg.entry), topic, W.messageKey(W.unb64u(cB.ck), msg.n - cB.n)), msg.content), 'C reads B\'s message with the chain the welcome gave, holding no E');
|
|
97
|
+
ok(checkOf(() => W.openBox(welC.content.body, gkeys.B.secretKey)) === 'group_key', 'welcome C does not open with B\'s gkey');
|
|
98
|
+
// The vault's optional D (§4.15): the door seeds of the open links, for an admin made after them.
|
|
99
|
+
const vb = (pt) => { const x = W.sealBox('vault', gkeys.C.publicKey, gid, 1, pt); return { v: W.GROUP2_V, typ: 'vault', gid, epoch: 1, ...x }; };
|
|
100
|
+
const k32 = W.b64u(seed('V')), dseed = W.b64u(seed('door seed'));
|
|
101
|
+
ok(same(W.openBox(vb({ V: k32, L: { [C.did]: k32 }, D: [{ id: '0'.repeat(16), seed: dseed }] }), gkeys.C.secretKey).D, [{ id: '0'.repeat(16), seed: dseed }]) && W.openBox(vb({ V: k32, L: {} }), gkeys.C.secretKey).D === undefined, 'a vault box with D (door seeds) and one without both open');
|
|
102
|
+
ok(checkOf(() => vb({ V: k32, L: {}, D: [] })) === 'group_message' && checkOf(() => vb({ V: k32, L: {}, D: [{ id: '0'.repeat(16), seed: dseed }, { id: '0'.repeat(16), seed: dseed }] })) === 'group_message' && checkOf(() => vb({ V: k32, L: {}, X: 1 })) === 'group_message', 'a vault box: D empty, an id twice, an unknown key: group_message');
|
|
103
|
+
const a = W.openAnswer(H(F.answer.bytes), { gkeySecret: gkeys.C.secretKey, gid, reply: F.group.reply });
|
|
104
|
+
ok(a.link === F.group.link && same(a.content, F.answer.content) && W.verifyContent(a.content, a.content.chain, F.t0).original === A.did, 'the answer opens with C\'s gkey, signed by A');
|
|
105
|
+
const b = a.content.body;
|
|
106
|
+
ok(b.welcome === welC.seq && same(W.openEntry(H(welC.entry), topic, W.unb64u(b.mk)), welC.content), 'the answer\'s message key opens the welcome');
|
|
107
|
+
ok(Buffer.from(W.unb64u(b.hk)).equals(Buffer.from(K[1].HK)) && Buffer.from(W.unb64u(b.write)).equals(Buffer.from(K[1].W.seed)), 'the answer carries the epoch\'s header key and write seed');
|
|
108
|
+
const d = W.openDoor(H(F.door.bytes), { doorSecret: W.boxKey(seed('door seed')).secretKey, gid, door: F.group.door });
|
|
109
|
+
ok(same(d.content, F.door.content) && W.verifyJoin(d.content, F.t0).original === C.did && d.content.body.kind === 'agent', 'the door request opens with the door key; the join verifies under the chain it carries');
|
|
110
|
+
ok(checkOf(() => W.openDoor(H(F.door.bytes), { doorSecret: W.boxKey(seed('door seed')).secretKey, gid, door: 'd/' + '0'.repeat(32) })) === 'group_key', 'a door request moved to another door does not open');
|
|
111
|
+
ok(H(F.door.bytes).length <= W.MAX_DOOR && H(F.door.bytes).length === 2 + 8 + 1120 + 24 + 16 + Math.ceil((canonicalize(F.door.content).length + 1) / 256) * 256, 'door request: 0x02 0x04, link id, X-Wing ciphertext, nonce, padded body, tag');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ================================================================ letters: symmetric, KEM, none for the kicked
|
|
115
|
+
{
|
|
116
|
+
const ep = F.entries.find((x) => x.label === 'letters').content.body;
|
|
117
|
+
const a = W.openLetter(ep.letters, seed('L A'), gid, 2);
|
|
118
|
+
ok(a && Buffer.from(a.E).equals(Buffer.from(E2)) && Buffer.from(a.V).equals(Buffer.from(V)), 'A (an admin): E2 and V from its symmetric letter');
|
|
119
|
+
const c = W.openLetter(ep.letters, seed('L C'), gid, 2, gkeys.C.secretKey);
|
|
120
|
+
ok(c && Buffer.from(c.E).equals(Buffer.from(E2)) && Buffer.from(c.L).equals(Buffer.from(seed('L C fresh'))) && c.V === null, 'C: a fresh L and E2 from its KEM letter, no V');
|
|
121
|
+
ok(W.openLetter(ep.letters, seed('L B'), gid, 2) === null, 'B (kicked): no letter');
|
|
122
|
+
ok(checkOf(() => W.openLetter(ep.letters, seed('L C'), gid, 2, gkeys.A.secretKey)) === 'group_key', 'a KEM letter does not open with another gkey');
|
|
123
|
+
const m2 = F.entries.find((x) => x.label === 'msg epoch 2');
|
|
124
|
+
ok(checkOf(() => W.openHeader(H(m2.entry), topic, K[1].HK)) === 'group_key' && W.openHeader(H(m2.entry), topic, W.epochKeys(c.E, gid).HK).n === 0, 'an epoch 2 entry: closed to epoch 1\'s key, open with the letter\'s E2');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ================================================================ the invite and its code
|
|
128
|
+
{
|
|
129
|
+
const i = F.invite;
|
|
130
|
+
ok(W.checkInvite(i.invite, F.t0) === i.invite && same(W.parseInviteLong(i.long, F.t0), i.invite), 'the invite verifies offline under the admin\'s genesis; the long form round-trips');
|
|
131
|
+
ok(/^GRP-[0-9A-HJKMNP-TV-Z]{4}-[0-9A-HJKMNP-TV-Z]{4}$/.test(i.code) && W.normaliseGroupCode(i.code) === i.code.slice(4).replace('-', ''), `the code ${i.code}`);
|
|
132
|
+
ok(W.groupCodeHash(i.code) === i.code_hash && W.groupCodeHash(i.code.toLowerCase().replace(/-/g, ' ')) === i.code_hash && i.link === 'https://sigelo.io/join#' + i.code, 'code hash: shown, lower case or spaced alike; the link carries it in the fragment');
|
|
133
|
+
ok(W.isGroupCode(i.code) && !W.isGroupCode(i.code.slice(4)) && W.normaliseGroupCode('GRP-7Q4K-M2XD-4WXN') === '7Q4KM2XD4WXN', 'GRP prefix required; a relay tag kept');
|
|
134
|
+
ok(W.checkCard(F.card.body) && checkOf(() => W.checkCard({ ...F.card.body, colour: 1 })) === 'group_message', 'the card: a closed table');
|
|
135
|
+
const ib = { ...i.invite.body, moved_from: '0'.repeat(32) };
|
|
136
|
+
ok(checkOf(() => W.checkInvite({ ...i.invite, body: ib }, F.t0)) === 'group_sig', 'moved_from is a field of the invite (signed: an added one breaks the signature)');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ================================================================ refusals: check and exact message
|
|
140
|
+
{
|
|
141
|
+
const E = (label) => F.entries.find((x) => x.label === label);
|
|
142
|
+
for (const r of F.refusals) {
|
|
143
|
+
let got;
|
|
144
|
+
if (r.body && r.now !== undefined) got = err(() => W.checkFresh(r.body, r.now));
|
|
145
|
+
else if (r.body) got = err(() => W.checkBody(r.body));
|
|
146
|
+
else if (r.content && r.chain) got = err(() => (r.content.body.typ === 'create' ? W.verifyCreate : W.verifyContent)(r.content, r.chain, r.content.body.iat));
|
|
147
|
+
else if (r.content) got = err(() => W.checkContent(r.content));
|
|
148
|
+
else if (r.entry) {
|
|
149
|
+
const x = E(r.entry), b = H(x.entry);
|
|
150
|
+
if (r.xor) b[r.xor[0] < 0 ? b.length + r.xor[0] : r.xor[0]] ^= r.xor[1];
|
|
151
|
+
const tp = r.topic ?? topic;
|
|
152
|
+
got = err(() => (r.step === 'header' ? W.openHeader(b, tp, r.key ? K[1].HK : K[x.epoch].HK) : W.openEntry(b, tp, H(x.mk))));
|
|
153
|
+
} else if (r.door) got = err(() => W.openDoor(H(F.door.bytes), { doorSecret: gkeys.C.secretKey, gid, door: F.group.door }));
|
|
154
|
+
else if (r.invite === true) got = err(() => W.checkInvite(F.invite.invite, r.now));
|
|
155
|
+
else if (r.invite) got = err(() => W.checkInvite(r.invite, r.now));
|
|
156
|
+
else if (r.code) got = err(() => W.normaliseGroupCode(r.code));
|
|
157
|
+
else if (r.card) got = err(() => W.checkCard(r.card));
|
|
158
|
+
ok(got && got.check === r.check && got.message === r.message, `refusal "${r.case}": ${got ? `${got.message}` : 'accepted'}; expected ${r.message}`);
|
|
159
|
+
}
|
|
160
|
+
// A few by their literal text, so a change to the messages shows here as well as in the fixture.
|
|
161
|
+
const lit = Object.fromEntries(F.refusals.map((r) => [r.case, r.message]));
|
|
162
|
+
ok(lit['an unknown key'].endsWith('; not allowed colour') && lit['the reserved typ call'] === 'group_message: not a sigelo-group/2 body: typ call is reserved', 'closed tables: an unknown key and a reserved typ refused by name');
|
|
163
|
+
ok(lit['a role grant without the agent flag'] === 'group_message: not a sigelo-group/2 body: a role is {v, typ, gid, mid, iat, from, epoch, at, member, role, agent}; missing agent', 'a role grant carries the agent flag');
|
|
164
|
+
ok(lit['iat 10 minutes ahead'] === 'group_stale: iat is 600 s ahead of now, at most 300', 'the time window');
|
|
165
|
+
ok(F.refusals.length >= 50, `${F.refusals.length} refusals in the fixture`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// ================================================================ who may sign what
|
|
169
|
+
{
|
|
170
|
+
for (const r of F.rules) {
|
|
171
|
+
const got = err(() => W.authorize(r.body, r.ctx));
|
|
172
|
+
ok(r.ok ? got === null : got && got.check === r.check && got.message === r.message, `rule "${r.case}": ${got ? got.message : 'allowed'}`);
|
|
173
|
+
}
|
|
174
|
+
const ruled = (k) => F.rules.find((r) => r.case.startsWith(k));
|
|
175
|
+
ok(ruled('the owner makes an agent moderator').ok && ruled('an admin makes an agent moderator').ok, 'an agent may be moderator, granted by the owner or an admin');
|
|
176
|
+
ok(ruled('the owner makes its own agent admin').ok && ruled('the owner unmakes an agent admin').ok, 'the owner\'s own agents may be admin, granted (and unmade) by the owner');
|
|
177
|
+
ok(ruled('an admin makes an agent admin').check === 'group_role' && ruled('an admin makes an agent admin').message === 'group_role: a role body making or unmaking an admin needs the owner', 'an admin cannot make an agent admin');
|
|
178
|
+
ok(ruled('an admin unmakes an agent admin').check === 'group_role', 'an admin cannot unmake an agent admin');
|
|
179
|
+
ok(W.AGENT_ROLES.admin === 'owner' && W.AGENT_ROLES.moderator === 'admin' && Object.isFrozen(W.AGENT_ROLES), 'AGENT_ROLES: admin by the owner, moderator by an admin');
|
|
180
|
+
// The agent-flagged admin grant on its own: the owner passes, an admin does not, a false flag never.
|
|
181
|
+
const grant = { typ: 'role', member: C.did, role: 'admin', agent: true }, tgtC = { did: C.did, role: 'member', kind: 'agent' };
|
|
182
|
+
ok(checkOf(() => W.authorize(grant, { role: 'owner', self: A.did, target: tgtC })) === 'accepted' && checkOf(() => W.authorize(grant, { role: 'admin', self: B0.did, target: tgtC })) === 'group_role'
|
|
183
|
+
&& checkOf(() => W.authorize({ ...grant, agent: false }, { role: 'owner', self: A.did, target: tgtC })) === 'group_role', 'agent-flagged admin grant: valid only signed by the owner, and only flagged truly');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ================================================================ units
|
|
187
|
+
{
|
|
188
|
+
ok(W.unb64u('AA') !== null && W.unb64u('AB') === null && W.unb64u('AA==') === null && W.unb64u('A+') === null, 'base64url: unpadded and canonical only');
|
|
189
|
+
ok(checkOf(() => W.decodeJcs(new TextEncoder().encode('{"a":1,"a":2}'), 'x')) === 'group_message' && checkOf(() => W.decodeJcs(new TextEncoder().encode('{"b":1, "a":2}'), 'x')) === 'group_message', 'a sealed body: duplicate keys and non-canonical JSON refused');
|
|
190
|
+
ok(checkOf(() => W.sealEntry({ topic, epoch: 1, flags: W.FLAG.letters, write: K[1].W, HK: K[1].HK, hint: new Uint8Array(8), n: 0, mk: new Uint8Array(32), content: F.entries[0].content })) === 'group_entry', 'the letters flag needs the admin credential');
|
|
191
|
+
const msg = F.entries.find((x) => x.label === 'msg');
|
|
192
|
+
ok(checkOf(() => W.sealEntry({ topic, epoch: 2, write: K[2].W, HK: K[2].HK, hint: new Uint8Array(8), n: 0, mk: new Uint8Array(32), content: msg.content })) === 'group_epoch', 'a body of epoch 1 is not sealed under epoch 2');
|
|
193
|
+
ok(checkOf(() => W.sealEntry({ topic, epoch: 1, write: K[1].W, HK: K[1].HK, hint: new Uint8Array(8), n: 0, mk: new Uint8Array(32), content: F.door.content })) === 'group_entry', 'a join never goes into the log');
|
|
194
|
+
const state = F.entries.find((x) => x.label === 'state');
|
|
195
|
+
ok(checkOf(() => W.sealEntry({ topic, epoch: 1, flags: W.FLAG.admin, write: AW[1], HK: K[1].HK, hint: new Uint8Array(8), n: 0, mk: new Uint8Array(32), content: state.content })) === 'group_entry', 'a state part is always kept');
|
|
196
|
+
ok(checkOf(() => W.checkVote({ choices: [2] }, { options: ['a', 'b'], multi: false })) === 'group_message' && checkOf(() => W.checkVote({ choices: [0, 1] }, { options: ['a', 'b'], multi: false })) === 'group_message' && checkOf(() => W.checkVote({ choices: [0, 1] }, { options: ['a', 'b'], multi: true })) === 'accepted', 'a vote against its poll');
|
|
197
|
+
ok(W.TYPS.length === 31 && W.TYPS.includes('answer') && !W.TYPS.includes('call') && W.RESERVED.includes('call'), '31 body types, call reserved');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
for (const f of fails) console.log('FAIL ' + f);
|
|
201
|
+
if (fails.length) { console.log(`${fails.length} FAILED, ${count - fails.length} passed`); process.exit(1); }
|
|
202
|
+
console.log(`ALL PASS (${count})`);
|