sigelo-contact 0.1.14 → 0.1.21
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/README.md +13 -10
- package/call.mjs +831 -0
- package/carrier.mjs +1013 -112
- package/control.mjs +81 -22
- package/device.mjs +1 -1
- package/enrol.mjs +214 -35
- package/gen-carrier.mjs +4 -4
- package/gen-device.mjs +2 -2
- package/gen-envelope.mjs +3 -3
- package/gen-invite.mjs +3 -3
- package/gen-short.mjs +3 -3
- package/group.mjs +28 -9
- package/invite.mjs +63 -13
- package/kdf.mjs +1 -1
- package/link.mjs +1 -1
- package/package.json +34 -7
- package/page.mjs +1018 -81
- package/photo.mjs +37 -0
- package/platform-node.mjs +110 -13
- package/prekeys.mjs +10 -2
- package/public.mjs +93 -0
- package/relays.mjs +1 -1
- package/restore.mjs +3 -3
- package/rtc-web.mjs +109 -0
- package/short.mjs +19 -3
- package/store.mjs +126 -10
- package/test-carrier.mjs +121 -18
- package/test-device.mjs +1 -1
- package/test-enrol.mjs +123 -8
- package/test-envelope.mjs +16 -3
- package/test-file.mjs +5 -5
- package/test-group.mjs +48 -7
- package/test-invite.mjs +15 -2
- package/test-link.mjs +6 -6
- package/test-platform.mjs +5 -5
- package/test-presence.mjs +5 -5
- package/test-push.mjs +136 -0
- package/test-relay-lane.mjs +323 -0
- package/test-short.mjs +35 -12
- package/test-tier.mjs +6 -6
- package/test-transfer-web.mjs +313 -0
- package/test-transfer.mjs +51 -11
- package/test-voice.mjs +161 -0
- package/test-ws.mjs +5 -5
- package/transfer-engine.mjs +858 -0
- package/transfer-node.mjs +254 -641
- package/transfer-web.mjs +80 -0
- package/transfer.mjs +25 -6
- package/voice-web.mjs +113 -0
- package/voice.mjs +70 -0
- package/words-lock.mjs +25 -10
package/test-enrol.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Enrolment (enrol.mjs, contract sigelo-enrol/1): the worker's derivation from a fixed keeper root
|
|
3
3
|
// (keys.ts agentIdentitySeed, a pinned DID), the marker, the identity message and its checks; then,
|
|
4
|
-
// with the relay checkout beside contact/ (SIGELO_RELAY_DIR, else
|
|
4
|
+
// with the relay checkout beside apps/contact/ (SIGELO_RELAY_DIR, else ../../relay), the flow on a loopback
|
|
5
5
|
// relay: issue → a temporary identity joins → the worker's identity travels end to end → the
|
|
6
6
|
// machine places it and pairs as the worker → the operator files it own and forgets the temporary
|
|
7
7
|
// DID; the code a second time; a request no enrolment matches; an identity from another DID; the
|
|
8
8
|
// same flow lazily, one run at a time on each side.
|
|
9
|
-
// node contact/test-enrol.mjs → ALL PASS (n)
|
|
9
|
+
// node apps/contact/test-enrol.mjs → ALL PASS (n)
|
|
10
10
|
import { createHash } from 'node:crypto';
|
|
11
11
|
import { existsSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
12
12
|
import { tmpdir } from 'node:os';
|
|
@@ -16,10 +16,10 @@ import { canonicalize, decodeKey, did as didOf, keygen, verify } from 'sigelo';
|
|
|
16
16
|
import { agentIdentitySeed, identitySeed, keeperRoot, recoveryCommitment } from 'sigelo/dist/keys.js';
|
|
17
17
|
import { makeInvite } from './invite.mjs';
|
|
18
18
|
import {
|
|
19
|
-
DAY, ENROL_V, LABEL_ENROL, LABEL_IDENTITY, OPERATOR_CTX, OPERATOR_DAYS, PENDING_TTL, PINNED_CREATED, TYP_IDENTITY, TYP_REQUEST, accept as joinEnrol, checkIdentity, complete,
|
|
20
|
-
enrolKey, enrolPath, identityMessage, IDENTITY_PATH, issue, matches, operatorAttestation, operatorChain, operatorIdentity, operatorLabel, pending, proofOf, request, workerChain, workerGenesis, workerIdentity,
|
|
19
|
+
resumeAnswer, DAY, ENROL_V, LABEL_ENROL, LABEL_IDENTITY, OPERATOR_CTX, OPERATOR_DAYS, PENDING_TTL, PINNED_CREATED, TYP_IDENTITY, TYP_REQUEST, accept as joinEnrol, checkIdentity, complete,
|
|
20
|
+
enrolKey, enrolPath, identityMessage, IDENTITY_PATH, issue, matches, operatorAttestation, operatorChain, operatorIdentity, operatorLabel, pending, proofOf, readStatus, request, statusMessage, workerChain, workerGenesis, workerIdentity,
|
|
21
21
|
} from './enrol.mjs';
|
|
22
|
-
import { fingerprint } from './short.mjs';
|
|
22
|
+
import { codeHash, fingerprint, isEnrolCode } from './short.mjs';
|
|
23
23
|
|
|
24
24
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
25
25
|
let count = 0;
|
|
@@ -125,10 +125,10 @@ const OPERATOR_0 = 'did:sigelo:z9VfjcNZXn1QfpRguA1uZTZYMDSffUZv4VAB69E5aYGDy';
|
|
|
125
125
|
} finally { rmSync(d, { recursive: true, force: true }); }
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', 'relay');
|
|
128
|
+
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', '..', 'relay');
|
|
129
129
|
if (!existsSync(join(RELAY_DIR, 'server.mjs')) || !existsSync(join(RELAY_DIR, 'node_modules'))) {
|
|
130
130
|
report();
|
|
131
|
-
console.log(`ALL PASS (${count}): the unit part; SKIP the flow, no relay checkout with its dependencies beside contact/: set SIGELO_RELAY_DIR`);
|
|
131
|
+
console.log(`ALL PASS (${count}): the unit part; SKIP the flow, no relay checkout with its dependencies beside apps/contact/: set SIGELO_RELAY_DIR`);
|
|
132
132
|
process.exit(0);
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -141,7 +141,9 @@ setTimeout(() => { console.log(`FAIL the run did not finish in 420 s (${count} c
|
|
|
141
141
|
const HOST = 'relay.test';
|
|
142
142
|
const dir = mkdtempSync(join(tmpdir(), 'sigelo-enrol-'));
|
|
143
143
|
const relay = await startRelay({ host: HOST, db: join(dir, 'relay.db'), tcpPort: 0, httpPort: 0, loginRate: 100000, verifyBudget: 1e9, clock: () => Math.floor(Date.now() / 1000), diskUsed: () => 0.1,
|
|
144
|
-
|
|
144
|
+
// One network (loopback): an enrolment's park, its fetches and its spend at the grant each count as a lookup.
|
|
145
|
+
park: { lookups: { n: 1000, window: 600 }, parks: { n: 1000, window: 3600 }, lookupsAll: { n: 8000, window: 600 } },
|
|
146
|
+
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits: 4, loadBits: 8, loadPerHour: 1000, cost: { m: 8, t: 1, p: 1 } } }) });
|
|
145
147
|
const endpoints = { [HOST]: { mqtt: `mqtt://127.0.0.1:${relay.ports.tcp}`, http: `http://127.0.0.1:${relay.ports.http}` } };
|
|
146
148
|
// An agent in memory: its identity file's content (sigelo-agent's Store) and a carrier on it.
|
|
147
149
|
function agent(label, store) {
|
|
@@ -183,6 +185,10 @@ try {
|
|
|
183
185
|
ok(mc.placed.length === 1 && mc.placed[0].did === w0.did && mc.placed[0].status === 'connected' && mc.refused.length === 0, `the machine placed worker 0 and paired as it (${JSON.stringify(mc.placed)} ${JSON.stringify(mc.refused)})`);
|
|
184
186
|
ok(op.delivered.length === 1 && op.delivered[0].temp === vps.did && op.placed.length === 1 && op.placed[0].did === w0.did && op.placed[0].tier === 'own' && op.refused.length === 0,
|
|
185
187
|
`the operator sent worker 0 once to the temporary DID, then filed the worker own (${JSON.stringify(op.placed)} ${JSON.stringify(op.refused)})`);
|
|
188
|
+
// No manual step (0.1.16: the agent was set as one by hand): the contacts list shows the worker ours, tier own (works for
|
|
189
|
+
// me), and the temporary identity is gone from it.
|
|
190
|
+
const cw = co.contacts().contacts.find((x) => x.did === w0.original && !x.revoked);
|
|
191
|
+
ok(cw?.ours === true && cw.tier === 'own' && !co.contacts().contacts.some((x) => x.did === vps.did && !x.revoked), `the operator's contacts: the worker ours, tier own; no temporary contact left (${JSON.stringify(cw && { ours: cw.ours, tier: cw.tier })})`);
|
|
186
192
|
ok(op.placed[0].verified === true && op.placed[0].words === fingerprint(pairWith0(owner, w0.did)) && op.held.length === 0,
|
|
187
193
|
'own enrolment: the worker that paired is the DID derived here (verified), its four words given only to show; no words gate asked');
|
|
188
194
|
ok(workers.vps?.operatorName === 'operator', 'the worker files its operator as "operator" by default');
|
|
@@ -214,6 +220,15 @@ try {
|
|
|
214
220
|
await eve.carrier.send(owner.did, request(enrolKey(seed('no such code')), pairWith(eve, owner)), { label: LABEL_ENROL });
|
|
215
221
|
const bd = await bad;
|
|
216
222
|
ok(pa.status === 'connected' && bd.delivered.length === 0 && bd.refused.some((x) => x.check === 'enrol_proof'), `a plain accept, then a request no enrolment matches: enrol_proof, nothing sent (${JSON.stringify(bd.refused)})`);
|
|
223
|
+
// The requester is told why (a status, label sigelo-enrol/1: no key, no DID), once per reason.
|
|
224
|
+
const toldE = (await eve.carrier.inbox({ wait: 3 })).messages.filter((x) => x.label === LABEL_ENROL);
|
|
225
|
+
ok(bd.told.length === 1 && toldE.length === 1 && toldE[0].content.typ === 'status' && toldE[0].content.check === 'enrol_proof' && /no enrolment code/.test(toldE[0].content.detail)
|
|
226
|
+
&& Object.keys(toldE[0].content).sort().join() === 'check,detail,typ,v' && !/did:sigelo/.test(toldE[0].content.detail), `and told why: {v, typ: status, check: enrol_proof, detail}, no key, no DID (${JSON.stringify(toldE.map((x) => x.content))})`);
|
|
227
|
+
const bad2 = complete({ carrier: co, file: fileOf(owner), keeper, wait: 30, until: (o) => o.refused.length > 0 });
|
|
228
|
+
await eve.carrier.send(owner.did, request(enrolKey(seed('no such code')), pairWith(eve, owner)), { label: LABEL_ENROL });
|
|
229
|
+
ok((await bad2).told.length === 0, 'the same request again: refused, not told twice');
|
|
230
|
+
ok(readStatus(statusMessage('enrol_x', 'a\u202eb\nc'))?.detail === 'a b c' && readStatus({ ...statusMessage('Bad!', 'x') }) === null && readStatus(request(enrolKey(seed('x')), '0'.repeat(32))) === null,
|
|
231
|
+
'readStatus: control and bidi characters blanked; a bad check or a request is no status');
|
|
217
232
|
|
|
218
233
|
// A worker identity from a DID the machine did not enrol with: not taken, left in the inbox.
|
|
219
234
|
const mi = await mallory.carrier.invite({ name: 'vps2', short: true });
|
|
@@ -296,12 +311,112 @@ try {
|
|
|
296
311
|
const h1 = await complete({ carrier: feed(unasked.held), file: fileOf(owner), keeper, confirm: gate });
|
|
297
312
|
ok(h1.held.length === 1 && h1.delivered.length === 0 && asked?.ask === true && asked.words === fingerprint(pairWith0(owner, hd.did)) && asked.i === 5,
|
|
298
313
|
`confirm() null (not yet): held again, nothing sent; it was asked with ask: true and the temporary pairing's words (${JSON.stringify(asked)})`);
|
|
314
|
+
const hs = await complete({ carrier: hd.carrier, file: fileOf(hd), temp: 'held-temp', place: placer('held', 1), wait: 10, until: (o) => o.status.length > 0 });
|
|
315
|
+
const hk = await complete({ carrier: hd.carrier, file: fileOf(hd), temp: 'held-temp', place: placer('held', 1) });
|
|
316
|
+
ok(unasked.told.map((x) => x.check).join() === 'enrol_words' && h1.told.length === 0 && hs.status.at(-1)?.check === 'enrol_words' && /four words/.test(hs.status.at(-1).detail) && hk.status[0]?.check === 'enrol_words',
|
|
317
|
+
`held: the machine is told once (enrol_words), and keeps it for its next finish (${JSON.stringify([unasked.told, hs.status, hk.status])})`);
|
|
299
318
|
answer = true;
|
|
300
319
|
const h2 = await complete({ carrier: feed(h1.held), file: fileOf(owner), keeper, confirm: gate });
|
|
301
320
|
const h3 = await complete({ carrier: hd.carrier, file: fileOf(hd), temp: 'held-temp', place: placer('held', 1), wait: 10, until: (o) => o.placed.length > 0 });
|
|
302
321
|
const h4 = await complete({ carrier: co, file: fileOf(owner), keeper, wait: 10, until: (o) => o.placed.length > 0 });
|
|
303
322
|
ok(h2.delivered[0]?.did === w5.did && h3.placed[0]?.did === w5.did && workers.held?.operatorName === 'boss' && h4.placed[0]?.did === w5.did && h4.placed[0].verified === true,
|
|
304
323
|
`yes: sent, placed (the worker files its operator as "boss", the label the enrolment carried), filed verified (${JSON.stringify(h4.placed)} ${JSON.stringify(h3.refused)})`);
|
|
324
|
+
// The identity lost (0.1.17: both sides then waited on each other for ever). Each side's clock moved by `later`.
|
|
325
|
+
const { MsgError } = await import('./kdf.mjs');
|
|
326
|
+
const NOW = () => Math.floor(Date.now() / 1000);
|
|
327
|
+
const later = (c, sec) => new Proxy(c, { get: (x, p) => (p === 'clock' ? () => x.clock() + sec : typeof x[p] === 'function' ? x[p].bind(x) : x[p]) });
|
|
328
|
+
// The operator's first identity send: gone on the way ('lost', the send said sent), or refused by the relay ('no_reader').
|
|
329
|
+
const dropping = (c, mode) => {
|
|
330
|
+
let n = 0;
|
|
331
|
+
return new Proxy(c, { get: (x, p) => (p === 'send' ? async (to, content, o) => {
|
|
332
|
+
if (o?.label === LABEL_IDENTITY && n++ === 0) { if (mode === 'lost') return { status: 'sent', id: 'lost', to }; throw new MsgError('no_reader', 'refused (nobody holds that mailbox yet)'); }
|
|
333
|
+
return x.send(to, content, o);
|
|
334
|
+
} : typeof x[p] === 'function' ? x[p].bind(x) : x[p]) });
|
|
335
|
+
};
|
|
336
|
+
// Lost: the machine asks again at its next finish once RESEND_S passed (not before), and is answered.
|
|
337
|
+
const inv7 = await issue({ carrier: co, file: fileOf(owner), i: 6, n: 0, name: 'lost', keeper });
|
|
338
|
+
const ls = agent('lost-temp'), w6 = workerChain(K, 6, 0, RECOVERY), opL = dropping(co, 'lost');
|
|
339
|
+
await joinEnrol({ carrier: ls.carrier, file: fileOf(ls), code: inv7.short, name: 'owner', wait: 1, temp: 'lost-temp' }).catch(() => {});
|
|
340
|
+
await complete({ carrier: co, file: fileOf(owner), keeper });
|
|
341
|
+
const mL = (c, o) => ({ carrier: c, file: fileOf(ls), temp: 'lost-temp', place: placer('lost', 1), ...o });
|
|
342
|
+
const q1 = await complete(mL(ls.carrier, { wait: 10, until: (o) => o.sent.length > 0 }));
|
|
343
|
+
const q2 = await complete({ carrier: opL, file: fileOf(owner), keeper, wait: 10, until: (o) => o.delivered.length > 0 });
|
|
344
|
+
const q3 = await complete(mL(ls.carrier, { wait: 2 }));
|
|
345
|
+
const q4 = await complete(mL(later(ls.carrier, 61), { wait: 10, until: (o) => o.sent.length > 0 }));
|
|
346
|
+
const q5 = await complete({ carrier: opL, file: fileOf(owner), keeper, wait: 10, until: (o) => o.delivered.length > 0 });
|
|
347
|
+
const q6 = await complete(mL(ls.carrier, { wait: 10, until: (o) => o.placed.length > 0 }));
|
|
348
|
+
const q7 = await complete({ carrier: co, file: fileOf(owner), keeper, wait: 10, until: (o) => o.placed.length > 0 });
|
|
349
|
+
ok(q1.sent.length === 1 && q2.delivered.length === 1 && q3.placed.length === 0 && q3.sent.length === 0 && q4.sent.length === 1 && q5.delivered[0]?.did === w6.did && q6.placed[0]?.did === w6.did && q7.placed[0]?.did === w6.did,
|
|
350
|
+
`the identity lost: no request again within 60 s; at the next finish after, the machine asks again, is answered, placed, filed (${JSON.stringify([q3.sent, q4.refused, q5.refused, q6.refused])})`);
|
|
351
|
+
// Refused (no_reader): the operator keeps it needs_send and sends again at its next round after RESEND_S, with no new request.
|
|
352
|
+
const inv8 = await issue({ carrier: co, file: fileOf(owner), i: 7, n: 0, name: 'refused', keeper });
|
|
353
|
+
const rf = agent('refused-temp'), w7 = workerChain(K, 7, 0, RECOVERY), opR = dropping(co, 'no_reader');
|
|
354
|
+
await joinEnrol({ carrier: rf.carrier, file: fileOf(rf), code: inv8.short, name: 'owner', wait: 1, temp: 'refused-temp' }).catch(() => {});
|
|
355
|
+
await complete({ carrier: co, file: fileOf(owner), keeper });
|
|
356
|
+
const mR = (o) => ({ carrier: rf.carrier, file: fileOf(rf), temp: 'refused-temp', place: placer('refused', 1), ...o });
|
|
357
|
+
const r1 = await complete(mR({ wait: 10, until: (o) => o.sent.length > 0 }));
|
|
358
|
+
const r2 = await complete({ carrier: opR, file: fileOf(owner), keeper, wait: 10, until: (o) => o.refused.length > 0 || o.delivered.length > 0 });
|
|
359
|
+
const marked = pending(fileOf(owner), NOW(), (x) => x.issued[inv8.id]?.needs_send);
|
|
360
|
+
const r3 = await complete({ carrier: opR, file: fileOf(owner), keeper });
|
|
361
|
+
const r4 = await complete({ carrier: later(opR, 61), file: fileOf(owner), keeper });
|
|
362
|
+
const r5 = await complete(mR({ wait: 10, until: (o) => o.placed.length > 0 }));
|
|
363
|
+
const r6 = await complete({ carrier: co, file: fileOf(owner), keeper, wait: 10, until: (o) => o.placed.length > 0 });
|
|
364
|
+
ok(r1.sent.length === 1 && r2.refused.some((x) => x.check === 'no_reader' && x.needs_send === inv8.id) && Number.isSafeInteger(marked) && r3.delivered.length === 0
|
|
365
|
+
&& r4.delivered[0]?.did === w7.did && pending(fileOf(owner), NOW(), (x) => x.issued[inv8.id]?.needs_send) === undefined && r5.placed[0]?.did === w7.did && r6.placed[0]?.did === w7.did,
|
|
366
|
+
`the identity refused (no_reader): kept needs_send, not again within 60 s, sent again at the operator's next round after, placed, filed (${JSON.stringify([r2.refused, r4.refused, r5.refused])})`);
|
|
367
|
+
ok(r2.told[0]?.check === 'no_reader' && r5.status.some((x) => x.check === 'no_reader' && /tries again within a minute/.test(x.detail) && !/did:sigelo/.test(x.detail)), `and the machine was told why the key had not come (${JSON.stringify(r5.status)})`);
|
|
368
|
+
// the agent-setup feedback, points 2, 5 and the enrolment boundary (THREAT-MODEL §2.11a): an enrolment code is
|
|
369
|
+
// ENROL-…, parked as one, refused by accept unspent, fetched again until the grant, and a machine joining
|
|
370
|
+
// strictly takes only it; a grant for another code than the one answered is refused.
|
|
371
|
+
{
|
|
372
|
+
const invE = await issue({ carrier: co, file: fileOf(owner), i: 8, n: 0, name: 'strict', keeper });
|
|
373
|
+
const parked = relay.park.isEnrol(codeHash(invE.short));
|
|
374
|
+
const byAccept = await failure(() => eve.carrier.accept(invE.enrol_code, { name: 'owner', wait: 1 }));
|
|
375
|
+
ok(isEnrolCode(invE.enrol_code) && invE.enrol_code.endsWith(invE.short) && parked && byAccept.check === 'enrol_code' && /init --enrol CODE/.test(byAccept.message) && relay.park.isEnrol(codeHash(invE.short)),
|
|
376
|
+
`issue: an enrol code ${invE.enrol_code}, parked as one; accept refuses it before any fetch (${byAccept.check}), and it stays at the relay`);
|
|
377
|
+
const plain = await mallory.carrier.invite({ name: 'not-an-operator', short: true }), st = agent('strict-temp');
|
|
378
|
+
const asPair = await failure(() => joinEnrol({ carrier: st.carrier, file: fileOf(st), code: plain.short, wait: 1, temp: 'strict-temp', strict: true }));
|
|
379
|
+
const asLong = await failure(() => joinEnrol({ carrier: st.carrier, file: fileOf(st), code: plain.code, wait: 1, temp: 'strict-temp', strict: true }));
|
|
380
|
+
ok(asPair.check === 'enrol_not' && /pairing code/.test(asPair.message) && asLong.check === 'enrol_not' && pending(fileOf(st), NOW(), (x) => Object.keys(x.joining).length === 0),
|
|
381
|
+
`a contact's pairing code can never start an enrolment: a short one the relay parked as an invite, and any long code: enrol_not, nothing pending (${asPair.message})`);
|
|
382
|
+
// Fetched again before the grant: a first try that failed fetches the same code again (relay/park.mjs).
|
|
383
|
+
const t1 = agent('retry-temp');
|
|
384
|
+
const first = await joinEnrol({ carrier: t1.carrier, file: fileOf(t1), code: invE.enrol_code, wait: 1, temp: 'retry-temp', strict: true }).catch((e) => e);
|
|
385
|
+
const again2 = await t1.carrier.unparkFrom(invE.enrol_code);
|
|
386
|
+
const jn = pending(fileOf(t1), NOW(), (x) => Object.values(x.joining)[0]);
|
|
387
|
+
ok(again2.enrol === true && jn?.long === again2.invite && jn.short_hash === codeHash(invE.short) && jn.temp === 'retry-temp',
|
|
388
|
+
`before the grant the code is fetched again, and the joining entry keeps the long code, the code's hash and its temporary identity (${first?.check ?? first?.status})`);
|
|
389
|
+
// An answer withdrawn (as by a refused proof of work): resumeAnswer sends it again from the entry.
|
|
390
|
+
pending(fileOf(t1), NOW(), (x) => { for (const j of Object.values(x.joining)) j.answered = false; });
|
|
391
|
+
const opE = complete({ carrier: co, file: fileOf(owner), keeper, wait: 60, until: (o) => o.placed.some((x) => x.id === invE.id) });
|
|
392
|
+
const re = await resumeAnswer({ carrier: t1.carrier, file: fileOf(t1), temp: 'retry-temp', wait: 20 });
|
|
393
|
+
const mE = await complete({ carrier: t1.carrier, file: fileOf(t1), temp: 'retry-temp', wait: 60, place: placer('strict'), until: (o) => o.placed.length > 0 });
|
|
394
|
+
const oE = await opE;
|
|
395
|
+
ok(re >= 0 && mE.placed[0]?.did === workerChain(K, 8, 0, RECOVERY).did && oE.placed.some((x) => x.id === invE.id), `taken up from the pending entry: answered, placed, filed (${JSON.stringify(mE.refused)})`);
|
|
396
|
+
ok(!relay.park.isEnrol(codeHash(invE.short)) && pending(fileOf(owner), NOW(), (x) => x.issued[invE.id]?.unparked) === true,
|
|
397
|
+
'the grant went: the operator spent the code at the relay (unparked), nobody fetches it again');
|
|
398
|
+
const burnt = await failure(() => joinEnrol({ carrier: eve.carrier, file: fileOf(eve), code: invE.enrol_code, wait: 1, temp: 'eve', strict: true }));
|
|
399
|
+
ok(burnt.check === 'park_unknown', `an attacker with the burnt code after the grant: park_unknown (${burnt.check})`);
|
|
400
|
+
// A grant for another code than the one this machine answered (an old one, or another enrolment's).
|
|
401
|
+
const opC = { did: owner.did, current_did: owner.did, current_key: owner.s.genesis.key, name: 'owner' };
|
|
402
|
+
const att = operatorAttestation({ secret: Buffer.from(owner.s.secret, 'hex'), iss: owner.did, sub: workerChain(K, 9, 0, RECOVERY).original, relay: HOST, now: NOW() });
|
|
403
|
+
const grant = identityMessage(workerIdentity({ K, i: 9, n: 0, recovery: RECOVERY, attestation: att, issuer: owner.s.genesis }), (await co.invite({ name: 'g', local: true })).code, 9, null, 'the-old-code');
|
|
404
|
+
const replay = await failure(() => checkIdentity(grant, { operator: opC, relay: HOST, now: NOW(), id: 'this-code' }));
|
|
405
|
+
const right = await failure(() => checkIdentity(grant, { operator: opC, relay: HOST, now: NOW(), id: 'the-old-code' }));
|
|
406
|
+
ok(replay.check === 'enrol_replay' && right.check === 'accepted', `a grant naming another code: enrol_replay; for this code: taken (${replay.message})`);
|
|
407
|
+
for (const a of [st, t1]) await a.carrier.stop();
|
|
408
|
+
}
|
|
409
|
+
// the agent-setup feedback, point 9: two contacts never share a name (send <name> refused both): the second gets -2.
|
|
410
|
+
{
|
|
411
|
+
const t1 = await co.invite({ name: 'twin' }), t2 = await co.invite({ name: 'twin' }), ta = agent('twin-a'), tb = agent('twin-b');
|
|
412
|
+
await co.start();
|
|
413
|
+
const pa = await ta.carrier.accept(t1.code, { name: 'owner', wait: 20 }), pb = await tb.carrier.accept(t2.code, { name: 'owner', wait: 20 });
|
|
414
|
+
await co.stop();
|
|
415
|
+
const names = Object.values(storeOf(owner).contacts).filter((c) => [ta.did, tb.did].includes(c.did)).map((c) => c.name).sort();
|
|
416
|
+
ok(names.join() === 'twin,twin-2', `a second contact named like the first is filed as name-2 (${names.join()}; ${pa.status}, ${pb.status})`);
|
|
417
|
+
for (const a of [ta, tb]) await a.carrier.stop();
|
|
418
|
+
}
|
|
419
|
+
for (const a of [ls, rf]) await a.carrier.stop();
|
|
305
420
|
for (const a of [alice, real, pl, hd]) await a.carrier.stop();
|
|
306
421
|
for (const a of [owner, vps, eve, mallory, vps2, lz, ...Object.values(workers)]) await a.carrier.stop();
|
|
307
422
|
} finally {
|
package/test-envelope.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// sigelo-msg/0 envelopes, prekeys and key schedule, against fixtures/envelope-v0.json and in code.
|
|
3
|
-
// node contact/test-envelope.mjs → ALL PASS (n)
|
|
3
|
+
// node apps/contact/test-envelope.mjs → ALL PASS (n)
|
|
4
4
|
import { readFileSync } from 'node:fs';
|
|
5
5
|
import { xchacha20poly1305 } from '@noble/ciphers/chacha.js';
|
|
6
6
|
import { sha256 } from '@noble/hashes/sha2.js';
|
|
@@ -9,7 +9,7 @@ import { ml_kem768_x25519 as xwing } from '@noble/post-quantum/hybrid.js';
|
|
|
9
9
|
import { canonicalize, did as didOf, sign, verify } from 'sigelo';
|
|
10
10
|
import { acceptPrekeys, expire, header, nextSlot, open, pad, parse, restartEpoch, seal, send, session, unpad, CARRIES, ENDED_MAX, EPOCHS_MAX, EPOCH_SECONDS, KIND, MAX_ENVELOPE, WINDOW } from './envelope.mjs';
|
|
11
11
|
import { epochId, epochKey, hex, isoWeek, pairId, pairKey, step, topic } from './kdf.mjs';
|
|
12
|
-
import { Prekeys, REISSUE, REPLACE_DAYS, RETIRED_MAX, TTL, USED_MAX, checkPrekeys, kemDecapsulate, kemEncapsulate, kemKey } from './prekeys.mjs';
|
|
12
|
+
import { Prekeys, REISSUE, REPLACE_DAYS, replaceDays, RETIRED_MAX, TTL, USED_MAX, checkPrekeys, kemDecapsulate, kemEncapsulate, kemKey } from './prekeys.mjs';
|
|
13
13
|
import { DAY, OUT, T0, build, contact, id, identities, me, receivers, rng, seed } from './gen-envelope.mjs';
|
|
14
14
|
|
|
15
15
|
let count = 0, failed = 0;
|
|
@@ -21,7 +21,7 @@ const same = (a, b) => canonicalize(a) === canonicalize(b);
|
|
|
21
21
|
|
|
22
22
|
// 1. The fixture reproduces byte for byte from the seeds.
|
|
23
23
|
const text = readFileSync(OUT, 'utf8'), f = JSON.parse(text);
|
|
24
|
-
ok(build() === text, 'fixtures/envelope-v0.json reproduces byte for byte (node contact/gen-envelope.mjs)');
|
|
24
|
+
ok(build() === text, 'fixtures/envelope-v0.json reproduces byte for byte (node apps/contact/gen-envelope.mjs)');
|
|
25
25
|
|
|
26
26
|
// 2. kdf.mjs against the §3 derivations spelled out with HKDF/HMAC in the generator.
|
|
27
27
|
const ids = identities(), { A0, A1, B0, C0, K } = ids, tr = f.trace_e01;
|
|
@@ -170,6 +170,19 @@ const reply = (from, to, now) => { const m = send(from, { label: '', content: 'r
|
|
|
170
170
|
refuses(() => checkPrekeys(P, c, pair, T0 + 0.5), 'time', 'a float now');
|
|
171
171
|
ok(checkPrekeys(P, c, pair, P.body.iat - 300).keys.length === 20, 'issued 300 s in our future: accepted');
|
|
172
172
|
}
|
|
173
|
+
{
|
|
174
|
+
// SIGELO_PREKEY_DAYS: a shorter replacement on this holder (1 to 7), the bundle unchanged.
|
|
175
|
+
const holder = new Prekeys(), who = me(B0, B0), pair = pairId(K.AB);
|
|
176
|
+
process.env.SIGELO_PREKEY_DAYS = '2';
|
|
177
|
+
try {
|
|
178
|
+
const first = holder.issue(who, pair, T0, rng('test-days'));
|
|
179
|
+
ok(replaceDays() === 2 && !holder.due(T0 + 2 * DAY - 1, who) && holder.due(T0 + 2 * DAY, who), 'SIGELO_PREKEY_DAYS=2: the one-time keys are due after two days');
|
|
180
|
+
const ids = new Set(first.body.keys.map((k) => k.id)), next = holder.issue(who, pair, T0 + 2 * DAY, rng('test-days-2'));
|
|
181
|
+
ok(next.body.keys.length === 20 && next.body.keys.every((k) => !ids.has(k.id)) && same(Object.keys(next.body), Object.keys(first.body)), 'and then all twenty are replaced; the bundle has the same fields');
|
|
182
|
+
for (const bad of ['0', '8', '1.5', 'week']) { process.env.SIGELO_PREKEY_DAYS = bad; refuses(() => holder.due(T0, who), 'prekey_days', `SIGELO_PREKEY_DAYS=${bad}`); }
|
|
183
|
+
} finally { delete process.env.SIGELO_PREKEY_DAYS; }
|
|
184
|
+
ok(replaceDays() === 7 && replaceDays({ SIGELO_PREKEY_DAYS: '' }) === 7, 'unset or empty: 7 days, as before');
|
|
185
|
+
}
|
|
173
186
|
{
|
|
174
187
|
// Holder: replenish below five (at most every REISSUE seconds), reissue lists every unused key,
|
|
175
188
|
// the sender forgets consumed ids; every REPLACE_DAYS all one-time keys are replaced at once.
|
package/test-file.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// File transfer (file.mjs, carrier.sendFile and its receive path; design/human-ui-plan.md §4):
|
|
3
3
|
// the pure part (byte-exact round trips from fixed seeds, a tampered chunk, oversize, names); then,
|
|
4
|
-
// with the relay checkout beside contact/ (SIGELO_RELAY_DIR, else
|
|
4
|
+
// with the relay checkout beside apps/contact/ (SIGELO_RELAY_DIR, else ../../relay), on a loopback relay: a
|
|
5
5
|
// 1 MiB file each way, saved 0600 under <identity>.files/<contact>-<16 hex of its DID hash>/, never over a file, a forged file refused, an
|
|
6
6
|
// incomplete one dropped at the retention.
|
|
7
|
-
// node contact/test-file.mjs → ALL PASS (n)
|
|
7
|
+
// node apps/contact/test-file.mjs → ALL PASS (n)
|
|
8
8
|
import { createHash } from 'node:crypto';
|
|
9
9
|
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
10
10
|
import { tmpdir } from 'node:os';
|
|
@@ -90,10 +90,10 @@ const ID = 'ab'.repeat(16);
|
|
|
90
90
|
ok(sizeText(812) === '812 B' && sizeText(12 * 1024) === '12.0 KiB' && sizeText(1 << 20) === '1.0 MiB', 'sizes for people');
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', 'relay');
|
|
93
|
+
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', '..', 'relay');
|
|
94
94
|
if (!existsSync(join(RELAY_DIR, 'server.mjs'))) {
|
|
95
95
|
report();
|
|
96
|
-
console.log(`ALL PASS (${count}): the pure part; SKIP the flow, no relay checkout beside contact/: set SIGELO_RELAY_DIR`);
|
|
96
|
+
console.log(`ALL PASS (${count}): the pure part; SKIP the flow, no relay checkout beside apps/contact/: set SIGELO_RELAY_DIR`);
|
|
97
97
|
process.exit(0);
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -107,7 +107,7 @@ const HOST = 'relay.test', CREATED = '2026-10-01T00:00:00Z';
|
|
|
107
107
|
const dir = mkdtempSync(join(tmpdir(), 'sigelo-file-'));
|
|
108
108
|
let now = Date.parse('2026-10-14T12:00:00Z') / 1000;
|
|
109
109
|
const relay = await startRelay({ host: HOST, db: join(dir, 'relay.db'), tcpPort: 0, httpPort: 0, loginRate: 100000, verifyBudget: 1e9, clock: () => now, diskUsed: () => 0.1,
|
|
110
|
-
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits:
|
|
110
|
+
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits: 4, loadBits: 8, loadPerHour: 1000, cost: { m: 8, t: 1, p: 1 } } }) });
|
|
111
111
|
const endpoints = { [HOST]: { mqtt: `mqtt://127.0.0.1:${relay.ports.tcp}`, http: `http://127.0.0.1:${relay.ports.http}` } };
|
|
112
112
|
const seed = (l) => new Uint8Array(createHash('sha256').update(`sigelo-file-test/0 ${l}`).digest());
|
|
113
113
|
function agent(label) {
|
package/test-group.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Groups (group.mjs, contract sigelo-group/1): the message and roster checks and the file first;
|
|
3
|
-
// then, with the relay checkout beside contact/ (SIGELO_RELAY_DIR, else
|
|
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
|
|
5
5
|
// in all, two of the agents paired with nobody but the creator), the friend's copy waits for its
|
|
6
6
|
// operator (join), messages reach the two unpaired through the creator with the sender's signature,
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// members, free and Pro), the join policy (friend: asked once; quiet: ignored), a stranger added to a
|
|
10
10
|
// foreign group noticed, the creator's leave freezes the roster; and no group message reaches
|
|
11
11
|
// inbox(), the log or history().
|
|
12
|
-
// node contact/test-group.mjs → ALL PASS (n)
|
|
12
|
+
// node apps/contact/test-group.mjs → ALL PASS (n)
|
|
13
13
|
import { createHash } from 'node:crypto';
|
|
14
14
|
import { existsSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
15
15
|
import { tmpdir } from 'node:os';
|
|
@@ -17,7 +17,7 @@ import { dirname, join } from 'node:path';
|
|
|
17
17
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
18
18
|
import { attest, keygen, sign } from 'sigelo';
|
|
19
19
|
import { OPERATOR_CTX } from './store.mjs';
|
|
20
|
-
import { BRAKE, GROUP_LABEL, GROUP_V, LIMITS, add, limitsFor, setRole, share, tierOf, checkBody, checkBrake, checkContent, checkRoster, create, groupsPath, handle, history, join as joinGroup, leave, list, newGid, newMid, remove, rename, send, setBrake, state } from './group.mjs';
|
|
20
|
+
import { BRAKE, GROUP_LABEL, GROUP_V, LIMITS, add, limitsFor, setRole, share, tierOf, checkBody, checkBrake, checkContent, checkRoster, create, groupsPath, handle, history, join as joinGroup, leave, list, newGid, newMid, refreshNames, remove, rename, send, setBrake, state } from './group.mjs';
|
|
21
21
|
import { groupTierOf } from './carrier.mjs';
|
|
22
22
|
|
|
23
23
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
@@ -92,10 +92,10 @@ const GID = 'ab'.repeat(16), MID = 'cd'.repeat(8);
|
|
|
92
92
|
} finally { rmSync(d, { recursive: true, force: true }); }
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', 'relay');
|
|
95
|
+
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', '..', 'relay');
|
|
96
96
|
if (!existsSync(join(RELAY_DIR, 'server.mjs')) || !existsSync(join(RELAY_DIR, 'node_modules'))) {
|
|
97
97
|
report();
|
|
98
|
-
console.log(`ALL PASS (${count}): the unit part; SKIP the flow, no relay checkout with its dependencies beside contact/: set SIGELO_RELAY_DIR`);
|
|
98
|
+
console.log(`ALL PASS (${count}): the unit part; SKIP the flow, no relay checkout with its dependencies beside apps/contact/: set SIGELO_RELAY_DIR`);
|
|
99
99
|
process.exit(0);
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -108,11 +108,11 @@ setTimeout(() => { console.log(`FAIL the run did not finish in 1200 s (${count}
|
|
|
108
108
|
const HOST = 'relay.test';
|
|
109
109
|
const dir = mkdtempSync(join(tmpdir(), 'sigelo-group-'));
|
|
110
110
|
const relay = await startRelay({ host: HOST, db: join(dir, 'relay.db'), tcpPort: 0, httpPort: 0, loginRate: 100000, verifyBudget: 1e9, clock: () => now, diskUsed: () => 0.1,
|
|
111
|
-
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits:
|
|
111
|
+
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits: 4, loadBits: 8, loadPerHour: 1000, cost: { m: 8, t: 1, p: 1 } } }) });
|
|
112
112
|
const endpoints = { [HOST]: { mqtt: `mqtt://127.0.0.1:${relay.ports.tcp}`, http: `http://127.0.0.1:${relay.ports.http}` } };
|
|
113
113
|
const make = (a) => {
|
|
114
114
|
const paths = pathsFor(join(dir, `${a.label}.local.json`));
|
|
115
|
-
a.c = new Carrier({ identity: () => ({ secret: a.secret, bundle: a.bundle }), ...paths, relay: HOST, endpoints, clock: () => now, keep: true, backoff: [100, 400], retentionDays: 7 });
|
|
115
|
+
a.c = new Carrier({ identity: () => ({ secret: a.secret, bundle: a.bundle }), ...paths, relay: HOST, endpoints, clock: () => now, keep: true, backoff: [100, 400], retentionDays: 7, ...(a.selfName && { selfName: a.selfName }), ...(a.selfKind !== undefined && { selfKind: a.selfKind }) });
|
|
116
116
|
a.f = groupsPath(join(dir, `${a.label}.local.json`)); a.paths = paths; a.out = []; a.seen = [];
|
|
117
117
|
return a;
|
|
118
118
|
};
|
|
@@ -374,6 +374,47 @@ try {
|
|
|
374
374
|
ok(!logs.includes('sigelo-group'), 'no group message in any inbox.log');
|
|
375
375
|
ok(all.every((a) => !a.c.history().messages.some((m) => m.label === GROUP_LABEL)), 'none in history()');
|
|
376
376
|
ok(all.every((a) => (JSON.parse(readFileSync(a.paths.state, 'utf8')).groups ?? []).length === 0), 'and none left in any carrier state');
|
|
377
|
+
// ---- names (carrier.mjs "Names"; 0.1.17: a new contact was "contact-…"): each side tells its own once paired; an
|
|
378
|
+
// unnamed pairing takes it (name_from "them"), sanitised; a name the human gave stays; a group code's join, filed
|
|
379
|
+
// before the name came, gets it in the roster (refreshNames).
|
|
380
|
+
const N1 = make(Object.assign(agent('names one'), { selfName: 'Nora \u202ex\n' })), N2 = make(Object.assign(agent('names two'), { selfName: () => 'Ben' }));
|
|
381
|
+
const N3 = make(Object.assign(agent('names three'), { selfName: 'Carl' })), N4 = make(Object.assign(agent('names four'), { selfName: 'Dee' }));
|
|
382
|
+
const inv1 = await N1.c.invite({});
|
|
383
|
+
await N2.c.accept(inv1.code, { wait: 0.3 });
|
|
384
|
+
for (let i = 0; i < 3; i++) { now += 5; await N1.c.inbox(); await N2.c.inbox(); }
|
|
385
|
+
const cOf = (a, b) => a.c.contacts().contacts.find((x) => x.did === b.did);
|
|
386
|
+
ok(cOf(N1, N2)?.name === 'Ben' && cOf(N1, N2).name_from === 'them' && cOf(N2, N1)?.name === 'Nora x' && cOf(N2, N1).name_from === 'them',
|
|
387
|
+
`names: an unnamed invite and accept take the names each side told, sanitised (${cOf(N1, N2)?.name}, ${JSON.stringify(cOf(N2, N1)?.name)})`);
|
|
388
|
+
await pair(N1, N3, 'carl-chosen', 'boss');
|
|
389
|
+
now += 5; await N1.c.inbox(); await N3.c.inbox();
|
|
390
|
+
ok(cOf(N1, N3)?.name === 'carl-chosen' && cOf(N1, N3).name_from === null && cOf(N3, N1)?.name === 'boss', 'names: a name the human gave stays');
|
|
391
|
+
N1.c.rename(N2.did, 'benny');
|
|
392
|
+
ok(cOf(N1, N2).name === 'benny' && cOf(N1, N2).name_from === null, 'names: renamed by the human: no longer from them');
|
|
393
|
+
const inv4 = await N1.c.invite({ name: 'contact-ab12', named: false });
|
|
394
|
+
await N4.c.accept(inv4.code, { wait: 0.3 });
|
|
395
|
+
now += 5; await N1.c.inbox();
|
|
396
|
+
const g4 = (await create({ carrier: N1.c, file: N1.f, name: 'naming', members: [N4.did], selfName: N1.c.selfName() })).group;
|
|
397
|
+
for (let i = 0; i < 3 && cOf(N1, N4)?.name !== 'Dee'; i++) { now += 5; await N4.c.inbox(); await N1.c.inbox(); }
|
|
398
|
+
const before4 = groupAt(N1, g4.gid).group.members.find((m) => m.did === N4.did).name;
|
|
399
|
+
await refreshNames({ carrier: N1.c, file: N1.f, did: N4.did });
|
|
400
|
+
ok(cOf(N1, N4)?.name === 'Dee' && before4 === 'contact-ab12' && groupAt(N1, g4.gid).group.members.find((m) => m.did === N4.did).name === 'Dee',
|
|
401
|
+
`names: a join filed before its name came; the name, then the roster gets it (${before4} → ${groupAt(N1, g4.gid).group.members.map((m) => m.name)})`);
|
|
402
|
+
const g4at4 = async () => { now += 5; await turn(N4); return groupAt(N4, g4.gid)?.group.members.find((m) => m.did === N1.did)?.name; };
|
|
403
|
+
let creatorName = null;
|
|
404
|
+
for (let i = 0; i < 3 && creatorName !== 'Nora x'; i++) creatorName = await g4at4();
|
|
405
|
+
ok(creatorName === 'Nora x', `names: the creator's own name in the roster is its told one, not "creator" (${creatorName})`);
|
|
406
|
+
// ---- kinds (carrier.mjs "Kinds", 2026-11-26): a desk and an agent say so in the name's receipt; a person's app says
|
|
407
|
+
// nothing; the receiver keeps kind_peer; an unknown kind is ignored; a kind with no name is not taken for a receipt.
|
|
408
|
+
const K1 = make(Object.assign(agent('kinds person'), { selfName: 'Pia' })), K2 = make(Object.assign(agent('kinds desk'), { selfName: 'Help', selfKind: () => 'desk' }));
|
|
409
|
+
const K3 = make(Object.assign(agent('kinds agent'), { selfKind: 'agent' })), K4 = make(Object.assign(agent('kinds odd'), { selfName: 'Odd', selfKind: () => 'robot' }));
|
|
410
|
+
for (const x of [K2, K3, K4]) { const inv = await x.c.invite({}); await K1.c.accept(inv.code, { wait: 0.3 }); }
|
|
411
|
+
for (let i = 0; i < 3; i++) { now += 5; for (const x of [K1, K2, K3, K4]) await x.c.inbox(); }
|
|
412
|
+
ok(cOf(K1, K2)?.kind_peer === 'desk' && cOf(K1, K2).name === 'Help' && cOf(K1, K3)?.kind_peer === 'agent' && cOf(K1, K4)?.kind_peer === null,
|
|
413
|
+
`kinds: the desk's and the agent's said, kept as kind_peer; an unknown one ignored (${[cOf(K1, K2)?.kind_peer, cOf(K1, K3)?.kind_peer, cOf(K1, K4)?.kind_peer]})`);
|
|
414
|
+
ok([K2, K3, K4].every((x) => cOf(x, K1)?.kind_peer === null) && cOf(K1, K3).seen_peer === false, 'kinds: a person says nothing (null on the other side); a kind-only receipt is not a seen receipt');
|
|
415
|
+
ok(K2.c.selfKind() === 'desk' && K4.c.selfKind() === null && K1.c.selfKind() === null, 'selfKind(): desk; an unknown one or none: null');
|
|
416
|
+
ok((() => { try { make(Object.assign(agent('kinds bad'), { selfKind: 'robot' })); return false; } catch (e) { return e instanceof TypeError; } })(), 'selfKind: a string not a kind refused at construction');
|
|
417
|
+
for (const a of [N1, N2, N3, N4, K1, K2, K3, K4]) await a.c.stop();
|
|
377
418
|
for (const a of all) await a.c.stop();
|
|
378
419
|
} finally {
|
|
379
420
|
await relay.close();
|
package/test-invite.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Runs fixtures/invite-v0.json against invite.mjs and store.mjs, then gen-invite.mjs --check.
|
|
3
|
-
// node contact/test-invite.mjs -> "ALL PASS (n)", or one FAIL line per failing check and exit 1
|
|
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.
|
|
5
5
|
import { spawnSync } from 'node:child_process';
|
|
6
6
|
import { mkdtempSync, readFileSync, readdirSync, rmSync, statSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
@@ -181,7 +181,7 @@ try {
|
|
|
181
181
|
|
|
182
182
|
let thrown;
|
|
183
183
|
try { parseInvite('sgl2', c.now); } catch (e) { thrown = e; }
|
|
184
|
-
ok(thrown?.constructor === MsgError && thrown.check === 'code_version', 'invite refusals are MsgError, the one error class of contact/, with .check');
|
|
184
|
+
ok(thrown?.constructor === MsgError && thrown.check === 'code_version', 'invite refusals are MsgError, the one error class of apps/contact/, with .check');
|
|
185
185
|
} finally {
|
|
186
186
|
rmSync(dir, { recursive: true, force: true });
|
|
187
187
|
}
|
|
@@ -189,6 +189,19 @@ try {
|
|
|
189
189
|
const gen = spawnSync(process.execPath, [join(HERE, 'gen-invite.mjs'), '--check'], { encoding: 'utf8' });
|
|
190
190
|
ok(gen.status === 0, `gen-invite.mjs --check: ${(gen.stderr || gen.stdout).trim()}`);
|
|
191
191
|
|
|
192
|
+
// Names (carrier.mjs "Names"): the pairing's handshake is unchanged (an unknown member is still refused, `card`); each
|
|
193
|
+
// side's display name goes after it, in a seen receipt {seen: 0, name}, which an older client takes as a receipt.
|
|
194
|
+
{
|
|
195
|
+
const { theirName, THEIR_NAME_MAX } = await import('./carrier.mjs');
|
|
196
|
+
ok(theirName(' Ana ') === 'Ana' && theirName('A\u202eB\u0007C\n') === 'ABC' && theirName('') === null && theirName('\u200f') === null && theirName(5) === null
|
|
197
|
+
&& [...theirName('x'.repeat(100))].length === THEIR_NAME_MAX && THEIR_NAME_MAX === 40, 'theirName: trimmed, control and bidi characters dropped, at most 40, else null');
|
|
198
|
+
// Replies (carrier.mjs "Replies"): the label names the quoted text's hash and whose it is, read back from the other side.
|
|
199
|
+
const { reLabel, reOf, quoteHash } = await import('./carrier.mjs');
|
|
200
|
+
const l1 = reLabel('Dinner on Friday?', false), l2 = reLabel('Dinner on Friday?', true);
|
|
201
|
+
ok(/^re\/[0-9a-f]{16}\/r$/.test(l1) && l2.endsWith('/s') && reOf(l1)?.by === 'me' && reOf(l2)?.by === 'them' && reOf(l1).sha === quoteHash('Dinner on Friday?') && reOf('reply') === null && reOf('re/zz/r') === null,
|
|
202
|
+
'reLabel / reOf: re/<16 hex>/<s|r>, read as by them (the sender quoted its own) or by me');
|
|
203
|
+
}
|
|
204
|
+
|
|
192
205
|
for (const f of fails) console.log('FAIL ' + f);
|
|
193
206
|
if (fails.length) { console.log(`${fails.length} FAILED, ${pass} passed`); process.exit(1); }
|
|
194
207
|
console.log(`ALL PASS (${pass})`);
|
package/test-link.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Links (link.mjs, contract sigelo-link/1): the message checks and the file first, the store's
|
|
3
|
-
// `link` (setLink, link_tier, revoke); then, with the relay checkout beside contact/ (SIGELO_RELAY_DIR,
|
|
4
|
-
// else
|
|
3
|
+
// `link` (setLink, link_tier, revoke); then, with the relay checkout beside apps/contact/ (SIGELO_RELAY_DIR,
|
|
4
|
+
// else ../../relay), on a loopback relay with one clock: an operator links two of its agents (tiers,
|
|
5
5
|
// purpose, expiry on both sides), links two already paired (the purpose attached, the tier restored
|
|
6
6
|
// at the end), refuses by name (link_from, link_tier, link_stale, link_peer both ways, link_not_ours,
|
|
7
7
|
// link_text), unlinks; then external links (an agent and the operator's contact "hotel", not its
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// none when quiet), never taken unasked, accepted at quiet, refused silently or told (--tell),
|
|
10
10
|
// lapsing with its code, auto-accepted by an allow rule at its tier, not after deny; and no link
|
|
11
11
|
// message reaches inbox(), the log or history().
|
|
12
|
-
// node contact/test-link.mjs → ALL PASS (n)
|
|
12
|
+
// node apps/contact/test-link.mjs → ALL PASS (n)
|
|
13
13
|
import { createHash } from 'node:crypto';
|
|
14
14
|
import { existsSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
15
15
|
import { tmpdir } from 'node:os';
|
|
@@ -136,10 +136,10 @@ const D0 = 'did:sigelo:z' + '1'.repeat(44);
|
|
|
136
136
|
} finally { rmSync(dir, { recursive: true, force: true }); }
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', 'relay');
|
|
139
|
+
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', '..', 'relay');
|
|
140
140
|
if (!existsSync(join(RELAY_DIR, 'server.mjs')) || !existsSync(join(RELAY_DIR, 'node_modules'))) {
|
|
141
141
|
report();
|
|
142
|
-
console.log(`ALL PASS (${count}): the unit part; SKIP the flow, no relay checkout with its dependencies beside contact/: set SIGELO_RELAY_DIR`);
|
|
142
|
+
console.log(`ALL PASS (${count}): the unit part; SKIP the flow, no relay checkout with its dependencies beside apps/contact/: set SIGELO_RELAY_DIR`);
|
|
143
143
|
process.exit(0);
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -152,7 +152,7 @@ setTimeout(() => { console.log(`FAIL the run did not finish in 900 s (${count} c
|
|
|
152
152
|
const HOST = 'relay.test';
|
|
153
153
|
const dir = mkdtempSync(join(tmpdir(), 'sigelo-link-'));
|
|
154
154
|
const relay = await startRelay({ host: HOST, db: join(dir, 'relay.db'), tcpPort: 0, httpPort: 0, loginRate: 100000, verifyBudget: 1e9, clock: () => now, diskUsed: () => 0.1,
|
|
155
|
-
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits:
|
|
155
|
+
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits: 4, loadBits: 8, loadPerHour: 1000, cost: { m: 8, t: 1, p: 1 } } }) });
|
|
156
156
|
const endpoints = { [HOST]: { mqtt: `mqtt://127.0.0.1:${relay.ports.tcp}`, http: `http://127.0.0.1:${relay.ports.http}` } };
|
|
157
157
|
const make = (a) => {
|
|
158
158
|
const paths = pathsFor(join(dir, `${a.label}.local.json`));
|
package/test-platform.mjs
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// this process) reached through Node's fetch, MQTT and proof of work. Their names point into a
|
|
6
6
|
// folder that does not exist: one call past the platform to the disk would fail. Also: the Node
|
|
7
7
|
// platform's own files (write, new, add, list, remove) in a temporary folder.
|
|
8
|
-
// node contact/test-platform.mjs → ALL PASS (n)
|
|
9
|
-
// The relay is its own AGPL package: SIGELO_RELAY_DIR, else
|
|
8
|
+
// node apps/contact/test-platform.mjs → ALL PASS (n)
|
|
9
|
+
// The relay is its own AGPL package: SIGELO_RELAY_DIR, else ../../relay; without it, SKIP the carrier part.
|
|
10
10
|
import { createHash } from 'node:crypto';
|
|
11
11
|
import { existsSync, mkdtempSync, rmSync, statSync } from 'node:fs';
|
|
12
12
|
import { tmpdir } from 'node:os';
|
|
@@ -81,15 +81,15 @@ function memory() {
|
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', 'relay');
|
|
85
|
-
if (!existsSync(join(RELAY_DIR, 'server.mjs'))) report(': the part without a relay; SKIP the rest, no relay checkout beside contact/ (set SIGELO_RELAY_DIR)');
|
|
84
|
+
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', '..', 'relay');
|
|
85
|
+
if (!existsSync(join(RELAY_DIR, 'server.mjs'))) report(': the part without a relay; SKIP the rest, no relay checkout beside apps/contact/ (set SIGELO_RELAY_DIR)');
|
|
86
86
|
const { startRelay } = await import(pathToFileURL(join(RELAY_DIR, 'server.mjs')).href);
|
|
87
87
|
const { relayPolicy } = await import(pathToFileURL(join(RELAY_DIR, 'allowance.mjs')).href);
|
|
88
88
|
|
|
89
89
|
const HOST = 'relay.test', CREATED = '2026-10-01T00:00:00Z';
|
|
90
90
|
const dir = mkdtempSync(join(tmpdir(), 'sigelo-platform-relay-'));
|
|
91
91
|
const relay = await startRelay({ host: HOST, db: join(dir, 'relay.db'), tcpPort: 0, httpPort: 0, loginRate: 100000, verifyBudget: 1e9, diskUsed: () => 0.1,
|
|
92
|
-
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits:
|
|
92
|
+
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits: 4, loadBits: 8, loadPerHour: 1000, cost: { m: 8, t: 1, p: 1 } } }) });
|
|
93
93
|
const endpoints = { [HOST]: { mqtt: `mqtt://127.0.0.1:${relay.ports.tcp}`, http: `http://127.0.0.1:${relay.ports.http}` } };
|
|
94
94
|
const seed = (l) => new Uint8Array(createHash('sha256').update(`sigelo-platform-test/0 ${l}`).digest());
|
|
95
95
|
function agent(label) {
|
package/test-presence.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Presence (carrier.mjs "Presence", design/transfer.md §8 T0): 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
|
-
// contact/ (SIGELO_RELAY_DIR, else
|
|
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
|
|
6
6
|
// connection are the relay's offline with its time; a reconnection is online again; a deny clears
|
|
7
7
|
// what the contact sees.
|
|
8
|
-
// node contact/test-presence.mjs → ALL PASS (n)
|
|
8
|
+
// node apps/contact/test-presence.mjs → ALL PASS (n)
|
|
9
9
|
import { createHash } from 'node:crypto';
|
|
10
10
|
import { existsSync, mkdtempSync, rmSync } from 'node:fs';
|
|
11
11
|
import { tmpdir } from 'node:os';
|
|
@@ -60,10 +60,10 @@ const chainOnly = (a) => ({ ...a.bundle, attestations: [], issuers: [] });
|
|
|
60
60
|
} finally { rmSync(dir, { recursive: true, force: true }); }
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', 'relay');
|
|
63
|
+
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', '..', 'relay');
|
|
64
64
|
if (!existsSync(join(RELAY_DIR, 'server.mjs'))) {
|
|
65
65
|
report();
|
|
66
|
-
console.log(`ALL PASS (${count}): the store part; SKIP the rest, no relay checkout beside contact/ (the relay is its own AGPL package): set SIGELO_RELAY_DIR`);
|
|
66
|
+
console.log(`ALL PASS (${count}): the store part; SKIP the rest, no relay checkout beside apps/contact/ (the relay is its own AGPL package): set SIGELO_RELAY_DIR`);
|
|
67
67
|
process.exit(0);
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -76,7 +76,7 @@ setTimeout(() => { console.log(`FAIL the run did not finish in 300 s (${count} c
|
|
|
76
76
|
const HOST = 'relay.test';
|
|
77
77
|
const dir = mkdtempSync(join(tmpdir(), 'sigelo-presence-'));
|
|
78
78
|
const relay = await startRelay({ host: HOST, db: join(dir, 'relay.db'), tcpPort: 0, httpPort: 0, loginRate: 100000, verifyBudget: 1e9, clock: () => now, diskUsed: () => 0.1,
|
|
79
|
-
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits:
|
|
79
|
+
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits: 4, loadBits: 8, loadPerHour: 1000, cost: { m: 8, t: 1, p: 1 } } }) });
|
|
80
80
|
const endpoints = { [HOST]: { mqtt: `mqtt://127.0.0.1:${relay.ports.tcp}`, http: `http://127.0.0.1:${relay.ports.http}` } };
|
|
81
81
|
const events = {};
|
|
82
82
|
const make = (a) => {
|