sigelo-contact 0.1.2 → 0.1.3
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 +9 -7
- package/carrier.mjs +92 -20
- package/fixtures/carrier-v0.json +113 -1
- package/gen-carrier.mjs +14 -6
- package/package.json +2 -2
- package/store.mjs +4 -2
- package/test-carrier.mjs +67 -14
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!-- SPDX-License-Identifier: MIT -->
|
|
2
2
|
# sigelo-contact
|
|
3
3
|
|
|
4
|
-
Two agents swap a one-line code
|
|
4
|
+
Two agents swap a one-line code, then send each other end-to-end encrypted
|
|
5
5
|
messages through a relay that holds them while one is offline and cannot read them. Each checks
|
|
6
6
|
the other's sigelo chain offline; a key rotation keeps the contact. MIT; the relay,
|
|
7
7
|
[sigelo-relay](https://github.com/csigelo/sigelo-relay), is AGPL-3.0.
|
|
@@ -15,15 +15,17 @@ sigelo-agent inbox # what came since last time
|
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
Also `contacts`, `forget <did>`, and all as MCP tools
|
|
18
|
-
([`integrations/mcp/contact.mjs`](../integrations/mcp/contact.mjs))
|
|
18
|
+
([`integrations/mcp/contact.mjs`](../integrations/mcp/contact.mjs)).
|
|
19
19
|
Each verb logs in once (a relay allows 30 a minute per network).
|
|
20
|
-
The first login proves work (
|
|
20
|
+
The first login proves work (5 to 60 s on a phone). `SIGELO_RELAY` names the relay for new codes
|
|
21
21
|
(default `relay.sigelo.ai`); a Pro reader sets `SIGELO_RELAY_RETENTION_DAYS=90`. State sits
|
|
22
22
|
beside the identity file (0600); messages wait there in plaintext until `inbox` takes them.
|
|
23
23
|
`carrier.mjs`'s header is its API; with `onEvent`, nothing is kept.
|
|
24
24
|
|
|
25
25
|
## Tests
|
|
26
26
|
|
|
27
|
+
Node 22.18 or newer; tested on 24.
|
|
28
|
+
|
|
27
29
|
```sh
|
|
28
30
|
node test-invite.mjs && node test-envelope.mjs
|
|
29
31
|
node test-carrier.mjs # with ../relay, on loopback
|
|
@@ -55,7 +57,8 @@ Each regenerates byte for byte from seeds (`gen-*.mjs`); refusals name their che
|
|
|
55
57
|
reads a reply, each envelope repeats the encapsulation: a reader offline past retention loses
|
|
56
58
|
those messages, not the epoch. Prekeys travel under `K`, replaced weekly.
|
|
57
59
|
5. **Rotation**: the rotated agent sends each contact its chain under `K`, proven by its new key,
|
|
58
|
-
until the contact
|
|
60
|
+
until the contact confirms it, so recovery beats a thief (SPEC §7.1). After a recovery both
|
|
61
|
+
mark the pairing `re_pair`: only that notice goes under `K` until a new code replaces it.
|
|
59
62
|
6. **Relay login**: a signed `{v:"sigelo-relay/0", typ:"relay-login", did, relay, nonce}`, a
|
|
60
63
|
type no challenge signer produces.
|
|
61
64
|
|
|
@@ -67,8 +70,7 @@ Key agreement is hybrid post-quantum (X25519 + ML-KEM-768), as in Signal and Sim
|
|
|
67
70
|
(signed).
|
|
68
71
|
- Heal inside an epoch after a key theft (no double ratchet): a stolen state file reads what
|
|
69
72
|
contacts write until the next weekly prekey replacement.
|
|
70
|
-
-
|
|
71
|
-
|
|
72
|
-
with an epoch's key agreement loses what follows until fresh prekeys restart it.
|
|
73
|
+
- Confirm delivery (the relay acknowledges, not the contact): a relay withholding an epoch's key
|
|
74
|
+
agreement loses what follows until fresh prekeys restart it.
|
|
73
75
|
- Check where a stranger's relay resolves: only its name is checked.
|
|
74
76
|
- Push, groups, direct delivery, a second carrier (version 2), unsend.
|
package/carrier.mjs
CHANGED
|
@@ -10,14 +10,15 @@
|
|
|
10
10
|
// await c.send(to, content, { label }) → { status: 'sent' | 'queued', … }, or throws the relay's code
|
|
11
11
|
// await c.sendAll(to, contents, { label }) → one result each ('refused' with its code), one login
|
|
12
12
|
// await c.inbox({ wait }) → { messages, events, dropped, offline? }: all are taken (messages: those kept)
|
|
13
|
-
// await c.forget(did) → { name, did, revoked: true, released }
|
|
13
|
+
// await c.forget(did) → { name, did, revoked: true, released, offline? }
|
|
14
14
|
// await c.start(), c.sync(), c.stop() stay connected, reconnecting with backoff; events reach onEvent
|
|
15
15
|
//
|
|
16
16
|
// identity() → { secret, bundle }: the agent's current secret key and SPEC §8 bundle, read again at
|
|
17
17
|
// every operation, so a rotation made by another process is seen at once. store: the contact store
|
|
18
18
|
// (store.mjs); state: this file's own JSON (sessions, outbox, inbox), both 0600 and written under one
|
|
19
19
|
// lock file, `<state>.lock`. pathsFor(identityFile) names both beside the identity file. onEvent(e):
|
|
20
|
-
// each event as it happens, messages included
|
|
20
|
+
// each event as it happens, messages included, and `pow` / `pow_done` around a proof-of-work search
|
|
21
|
+
// (seconds to a minute on a phone: say so to the operator). keep: messages also wait in the state file for
|
|
21
22
|
// inbox(), in plaintext, until taken (INBOX_MAX at most: the oldest go, counted as inbox_full); by
|
|
22
23
|
// default only without onEvent, so a message onEvent took is not left at rest after the keys that
|
|
23
24
|
// opened it are gone (contacts.md §3: keys stolen today must not open yesterday's messages).
|
|
@@ -93,6 +94,15 @@
|
|
|
93
94
|
// on reading the notice, retires the prekeys it listed and sends fresh ones. The pairing key
|
|
94
95
|
// K stays: whoever copied the store can compute and claim later mailbox topics until the two
|
|
95
96
|
// pair again (invite and accept between existing contacts replace K: `rekeyed`).
|
|
97
|
+
// - After a recovery, K is burned on both sides (re_pair, in the contact store): the recovered
|
|
98
|
+
// agent marks every contact it paired with before the recovery (`own_recovery`, #markRecovered),
|
|
99
|
+
// and a contact marks it on merging a notice that brings a recovery it had not followed
|
|
100
|
+
// (`contact_recovery`). Toward a marked contact nothing goes but the rotation notice, and no
|
|
101
|
+
// new mailbox of the pair is claimed: a thief holding K claims weeks nobody writes in. A
|
|
102
|
+
// message queued for it before the mark is refused, and noted (`refused`, code re_pair). A new
|
|
103
|
+
// invite and accept replace K and clear the mark (store.admit writes the record afresh). A
|
|
104
|
+
// contact on sigelo-contact 0.1.2 follows the recovery but marks nothing and keeps writing
|
|
105
|
+
// under K, to weeks nobody may read but a thief: the recovered side pairs again at once.
|
|
96
106
|
// - Mailboxes: an agent holds the topics of every ISO week from `retention` ago to AHEAD (7 days,
|
|
97
107
|
// or its retention if shorter) ahead. The relay drops a publish to a topic nobody claimed (and
|
|
98
108
|
// says no_reader), so next week's topic must be claimed before a contact writes in it while
|
|
@@ -512,6 +522,12 @@ async function http(url, init = {}) {
|
|
|
512
522
|
// Text a relay writes reaches the operator, and perhaps a model, inside this client's messages:
|
|
513
523
|
// quoted and cut short, so it reads as data.
|
|
514
524
|
const relaySays = (s) => `the relay says ${JSON.stringify(String(s ?? '').slice(0, 200))}`;
|
|
525
|
+
// A refusal's words without its check: a verb that adds to them keeps one "check: " in front.
|
|
526
|
+
const reason = (e) => (e instanceof MsgError && e.message.startsWith(`${e.check}: `) ? e.message.slice(e.check.length + 2) : e.message);
|
|
527
|
+
// Why nothing goes to a contact marked re_pair (the header's "After a recovery").
|
|
528
|
+
const rePairWhy = (c) => (c.re_pair === 'contact_recovery'
|
|
529
|
+
? `${c.name} recovered its identity after a theft: the pairing key may be the thief's; pair again (invite, accept) before writing`
|
|
530
|
+
: `this agent recovered its identity: the pairing key with ${c.name} may be the thief's; pair again (invite, and ${c.name}'s operator accepts the code) before writing`);
|
|
515
531
|
|
|
516
532
|
// MQTT 3.1.1 says only "bad user name or password": POST /check with the same credentials names
|
|
517
533
|
// the failing check (relay/auth.mjs).
|
|
@@ -627,7 +643,13 @@ export class Carrier {
|
|
|
627
643
|
let r;
|
|
628
644
|
try { r = verify(chainOf(bundle), now); } catch (e) { fail('identity', `this agent's bundle does not verify: ${e.message}`); }
|
|
629
645
|
const genesis = [bundle.genesis, ...bundle.rotations.map((x) => x.next_genesis)].find((g) => didOf(g) === r.did);
|
|
630
|
-
|
|
646
|
+
// The last edge of the chain followed that a recovery rotation took (-1: none): chain[recovery]
|
|
647
|
+
// is the node the owner recovered from (#markRecovered).
|
|
648
|
+
let recovery = -1;
|
|
649
|
+
for (let i = 0; i + 1 < r.chain.length; i++) {
|
|
650
|
+
if (bundle.rotations.some((x) => x.body.id === r.chain[i] && x.body.next === r.chain[i + 1] && x.body.reason === 'recovery')) recovery = i;
|
|
651
|
+
}
|
|
652
|
+
return { did: r.chain[0], current_did: r.did, secret, genesis, bundle, chain: r.chain, recovery };
|
|
631
653
|
}
|
|
632
654
|
|
|
633
655
|
// The state is saved before the store's held writes (store.mjs hold: a handshake's), so a crash
|
|
@@ -636,6 +658,9 @@ export class Carrier {
|
|
|
636
658
|
return withLock(this.statePath, () => {
|
|
637
659
|
const now = checkNow(this.clock()), me = this.#me(now);
|
|
638
660
|
const ctx = { now, me, store: new Contacts(this.storePath, me.did), st: loadState(this.statePath, me.did) };
|
|
661
|
+
// Before anything reads the store: a recovery made by another process (sigelo-agent recover)
|
|
662
|
+
// is seen at once. The store's marks are written first; the state keeps the events.
|
|
663
|
+
if (this.#markRecovered(ctx)) saveState(this.statePath, ctx.st);
|
|
639
664
|
const out = fn(ctx);
|
|
640
665
|
if (write) { saveState(this.statePath, ctx.st); ctx.store.commit(); }
|
|
641
666
|
return out;
|
|
@@ -644,6 +669,27 @@ export class Carrier {
|
|
|
644
669
|
#locked(fn) { return this.#with(true, fn); }
|
|
645
670
|
#read(fn) { return this.#with(false, fn); }
|
|
646
671
|
|
|
672
|
+
// This agent recovered after it last told a contact of its keys (`announced`: a DID at or before
|
|
673
|
+
// the node it recovered from, or one the recovery dropped, or none known): K and the session sat
|
|
674
|
+
// in the files a thief copied with the key. The contact is marked re_pair, `own_recovery` (the
|
|
675
|
+
// header's "After a recovery"), and the next inbox says so. A contact paired after the recovery
|
|
676
|
+
// was announced a later DID: not marked.
|
|
677
|
+
#markRecovered({ now, me, store, st }) {
|
|
678
|
+
if (me.recovery < 0) return false;
|
|
679
|
+
const marked = [];
|
|
680
|
+
for (const c of Object.values(store.load().s.contacts)) {
|
|
681
|
+
if (c.revoked || !c.pair_key || c.re_pair) continue;
|
|
682
|
+
const e = st.peers[c.did];
|
|
683
|
+
if (e && me.chain.indexOf(e.announced) > me.recovery) continue;
|
|
684
|
+
c.re_pair = 'own_recovery';
|
|
685
|
+
marked.push(c);
|
|
686
|
+
}
|
|
687
|
+
if (marked.length === 0) return false;
|
|
688
|
+
store.save();
|
|
689
|
+
for (const c of marked) this.#note(st, now, { type: 're_pair', did: c.did, name: c.name, re_pair: c.re_pair });
|
|
690
|
+
return true;
|
|
691
|
+
}
|
|
692
|
+
|
|
647
693
|
// announced: the current DID this agent last sent its rotation notice for, noticed: when; known:
|
|
648
694
|
// the current DID of this agent's the contact last said it holds (a prekeys frame's `known`;
|
|
649
695
|
// pairing: the one it checked); notice_asked: that was another one, so the notice goes again.
|
|
@@ -729,7 +775,8 @@ export class Carrier {
|
|
|
729
775
|
const add = (x) => { if (!seen.has(x.topic)) { seen.add(x.topic); out.push(x); } };
|
|
730
776
|
for (const p of Object.values(store.s.invites)) if (p.relay === relay && p.exp > now) add({ topic: inviteKeys(hexToBytes(p.secret)).answer_topic });
|
|
731
777
|
for (const p of Object.values(store.s.accepts)) if (p.relay === relay && p.exp > now) add({ topic: inviteKeys(hexToBytes(p.secret)).reply_topic });
|
|
732
|
-
|
|
778
|
+
// No new mailbox under a burned K (re_pair): those held run out at their time (#refresh).
|
|
779
|
+
const contacts = this.#liveContacts(store, relay).filter((c) => !c.re_pair).map((c) => ({ did: c.did, K: hexToBytes(c.pair_key) }));
|
|
733
780
|
const weeks = this.#weeks(now), at = Math.max(0, weeks.findIndex((w) => w.week === isoWeek(now)));
|
|
734
781
|
for (const w of [...weeks.slice(at), ...weeks.slice(0, at).reverse()]) {
|
|
735
782
|
for (const c of contacts) add({ topic: topic(c.K, c.did, me.did, w.week), peer: c.did, until: w.until });
|
|
@@ -761,15 +808,18 @@ export class Carrier {
|
|
|
761
808
|
|
|
762
809
|
#resolve(store, to) {
|
|
763
810
|
if (typeof to !== 'string' || to === '') fail('not_contact', 'name a contact: its DID or its name');
|
|
811
|
+
let c;
|
|
764
812
|
if (to.startsWith('did:sigelo:')) {
|
|
765
|
-
|
|
813
|
+
c = store.lookup(to) ?? fail('not_contact', `${to} is not a contact`);
|
|
766
814
|
if (c.revoked) fail('revoked', `${c.did} was revoked by this owner`);
|
|
767
|
-
|
|
815
|
+
} else {
|
|
816
|
+
const hits = this.#liveContacts(store).filter((x) => x.name === to);
|
|
817
|
+
if (hits.length === 0) fail('not_contact', `no contact named ${JSON.stringify(to)}`);
|
|
818
|
+
if (hits.length > 1) fail('name', `${hits.length} contacts are named ${JSON.stringify(to)}: use the DID`);
|
|
819
|
+
c = hits[0];
|
|
768
820
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
if (hits.length > 1) fail('name', `${hits.length} contacts are named ${JSON.stringify(to)}: use the DID`);
|
|
772
|
-
return hits[0];
|
|
821
|
+
if (c.re_pair) fail('re_pair', rePairWhy(c));
|
|
822
|
+
return c;
|
|
773
823
|
}
|
|
774
824
|
|
|
775
825
|
// ---- incoming
|
|
@@ -994,7 +1044,8 @@ export class Carrier {
|
|
|
994
1044
|
if (p.body.did !== r.did || p.body.pair !== pairId(K)) fail('notice_sig', 'the proof names another DID than the chain ends at, or another pairing');
|
|
995
1045
|
if (!verifySig(keyOf(bundle, bundle.rotations, r.did), p.body, p.sig)) fail('notice_sig', 'the proof does not verify under the key the chain ends at');
|
|
996
1046
|
const before = structuredClone(c);
|
|
997
|
-
|
|
1047
|
+
// A mark stays with the record through a merge (admit writes it afresh); a new pairing clears it.
|
|
1048
|
+
const a = store.admit(bundle, r, null, { relay: c.relay, pair_key: c.pair_key, ...(c.re_pair && { re_pair: c.re_pair }) }, now);
|
|
998
1049
|
// admit writes every rotation either side held. The store keeps only those followed(); a
|
|
999
1050
|
// merged chain too long to keep puts the record back as it was. Held rotations come first, so
|
|
1000
1051
|
// on an edge both hold, the one this store followed before stays. store.mjs has no verb for
|
|
@@ -1007,6 +1058,11 @@ export class Carrier {
|
|
|
1007
1058
|
throw e;
|
|
1008
1059
|
}
|
|
1009
1060
|
merged.rotations = kept;
|
|
1061
|
+
// A recovery this store had not followed: the key it superseded, and the files a thief copied
|
|
1062
|
+
// with it, held K. Burned here too (the header's "After a recovery").
|
|
1063
|
+
const held = new Set(before.rotations.map(canonicalize));
|
|
1064
|
+
const recovered = kept.some((x) => x.body.reason === 'recovery' && !held.has(canonicalize(x)));
|
|
1065
|
+
if (recovered) merged.re_pair ??= 'contact_recovery';
|
|
1010
1066
|
store.save();
|
|
1011
1067
|
if (a.current_did === c.current_did) return [];
|
|
1012
1068
|
// The contact's old key, and perhaps its state with the prekeys we listed, may be a thief's:
|
|
@@ -1014,7 +1070,7 @@ export class Carrier {
|
|
|
1014
1070
|
const s = this.#restore(st, store, me, c.did);
|
|
1015
1071
|
if (s) { s.in.prekeys.retire(now); this.#persist(st, s); }
|
|
1016
1072
|
this.#entry(st, c.did).prekeys_resend = true;
|
|
1017
|
-
return [this.#note(st, now, { type: 'rotated', did: c.did, name: c.name, current_did: a.current_did })];
|
|
1073
|
+
return [this.#note(st, now, { type: 'rotated', did: c.did, name: c.name, current_did: a.current_did, ...(recovered && { re_pair: merged.re_pair }) })];
|
|
1018
1074
|
}
|
|
1019
1075
|
|
|
1020
1076
|
// Alice: an answer to one of her codes. checkAnswer runs sigelo-pair's checks in its order and
|
|
@@ -1180,7 +1236,8 @@ export class Carrier {
|
|
|
1180
1236
|
const ask = missing !== null && e.outbox.length > 0 && now - (e.asked ?? 0) >= DAY;
|
|
1181
1237
|
const resync = e.renew === true || (e.resync_due === true && now - (e.resync_at ?? 0) >= RESYNC);
|
|
1182
1238
|
const told = e.known_due === true && now - (e.prekeys_iat ?? 0) >= RESYNC;
|
|
1183
|
-
|
|
1239
|
+
// Under a burned K (re_pair) the notice alone goes: no bundle, no message.
|
|
1240
|
+
const bundle = !c.re_pair && (e.prekeys_resend || s.in.prekeys.due(now, me) || ask || resync || told);
|
|
1184
1241
|
// The rotation notice: after this agent's own rotation (announced), and again, at most every
|
|
1185
1242
|
// RESYNC, while the contact has not said it holds the current DID (known): before a frame
|
|
1186
1243
|
// signed by the current key goes (a bundle, an envelope), or when the contact's frame named
|
|
@@ -1203,6 +1260,15 @@ export class Carrier {
|
|
|
1203
1260
|
return this.#queue(st, { relay, topic: t, bytes: seal(KIND_NOTICE, noticeKey(K, me.did, c.did), t, { bundle: chainOf(me.bundle), proof: { body: proof, sig: sign(me.secret, proof) } }),
|
|
1204
1261
|
kind: KIND_NOTICE, peer: c.did, control: 'notice' });
|
|
1205
1262
|
}
|
|
1263
|
+
if (c.re_pair) {
|
|
1264
|
+
// Queued before the mark: refused here, unsealed. Noted too: the send that queued it has
|
|
1265
|
+
// exited, and its agent was told it goes at a later connection.
|
|
1266
|
+
for (const item of e.outbox.splice(0)) {
|
|
1267
|
+
this.#results.set(item.id, { code: 're_pair', detail: rePairWhy(c), local: true });
|
|
1268
|
+
this.#emit(this.#note(st, now, { type: 'refused', id: item.id, peer: c.did, name: c.name, code: 're_pair', detail: rePairWhy(c) }));
|
|
1269
|
+
}
|
|
1270
|
+
continue;
|
|
1271
|
+
}
|
|
1206
1272
|
if (bundle) {
|
|
1207
1273
|
// The contact refuses a bundle no newer than the one it holds (envelope.mjs acceptPrekeys),
|
|
1208
1274
|
// so two issued within one second get iat one apart (checkPrekeys allows SKEW ahead).
|
|
@@ -1474,7 +1540,10 @@ export class Carrier {
|
|
|
1474
1540
|
}
|
|
1475
1541
|
at.searches = [...recent, now];
|
|
1476
1542
|
});
|
|
1477
|
-
|
|
1543
|
+
const t0 = Date.now();
|
|
1544
|
+
if (bits > 0) this.#emit({ type: 'pow', relay, bits });
|
|
1545
|
+
pow = await solvePow(relay, me.did, ch.nonce, bits, t0 + POW_MS) ?? fail('pow', `no ${bits}-bit proof of work found within the challenge's 5 minutes on this machine: try again, or later (the relay raises it under load)`);
|
|
1546
|
+
if (bits > 0) this.#emit({ type: 'pow_done', relay, bits, ms: Date.now() - t0 });
|
|
1478
1547
|
}
|
|
1479
1548
|
const password = canonicalize({ v: LOGIN_V, nonce: ch.nonce, sig, bundle: loginBundle(me.bundle, relay), ...(pow !== undefined && { pow }) });
|
|
1480
1549
|
return { username: me.current_did, clientId: clientIdOf(me.did), password, pow };
|
|
@@ -1669,7 +1738,7 @@ export class Carrier {
|
|
|
1669
1738
|
return 'withdrawn';
|
|
1670
1739
|
});
|
|
1671
1740
|
const why = { withdrawn: 'the answer is withdrawn', queued: 'the answer stays queued: it goes at the next connection', delivered: 'the relay holds the answer: the reply is read at a later connection' }[left];
|
|
1672
|
-
throw new MsgError(e.check ?? 'connect', `${e
|
|
1741
|
+
throw new MsgError(e.check ?? 'connect', `${reason(e)} (${why})`);
|
|
1673
1742
|
}
|
|
1674
1743
|
const h = this.#handshakes.get(id), sent = this.#results.get(entry), reply = inviteKeys(code.secret).reply_topic;
|
|
1675
1744
|
this.#handshakes.delete(id); this.#results.delete(entry);
|
|
@@ -1685,7 +1754,8 @@ export class Carrier {
|
|
|
1685
1754
|
return this.#read(({ now, store, st }) => {
|
|
1686
1755
|
const s = store.load().s;
|
|
1687
1756
|
return {
|
|
1688
|
-
contacts: Object.values(s.contacts).map((c) => ({ name: c.name, did: c.did, current_did: c.current_did, revoked: c.revoked, relay: c.relay, queued: st.peers[c.did]?.outbox.length ?? 0
|
|
1757
|
+
contacts: Object.values(s.contacts).map((c) => ({ name: c.name, did: c.did, current_did: c.current_did, revoked: c.revoked, relay: c.relay, queued: st.peers[c.did]?.outbox.length ?? 0,
|
|
1758
|
+
re_pair: c.re_pair ?? null })),
|
|
1689
1759
|
invites: Object.values(s.invites).filter((p) => p.exp > now).map((p) => ({ name: p.name, exp: p.exp, relay: p.relay })),
|
|
1690
1760
|
answers: Object.values(s.accepts).filter((p) => p.exp > now).map((p) => ({ name: p.name, did: p.code_did, exp: p.exp, relay: p.relay })),
|
|
1691
1761
|
};
|
|
@@ -1715,7 +1785,7 @@ export class Carrier {
|
|
|
1715
1785
|
return { ids, c };
|
|
1716
1786
|
});
|
|
1717
1787
|
try { await this.#session([c.relay]); } catch (e) {
|
|
1718
|
-
throw new MsgError(e.check ?? 'connect', `${e
|
|
1788
|
+
throw new MsgError(e.check ?? 'connect', `${reason(e)} (${ids.length === 1 ? 'the message stays' : `the ${ids.length} messages stay`} queued for ${c.name}: they go at the next connection)`);
|
|
1719
1789
|
}
|
|
1720
1790
|
return ids.map((id) => {
|
|
1721
1791
|
const r = this.#results.get(id);
|
|
@@ -1734,7 +1804,7 @@ export class Carrier {
|
|
|
1734
1804
|
const inUse = this.#relaysInUse(), relays = inUse.length > 0 ? inUse : [this.relay];
|
|
1735
1805
|
try {
|
|
1736
1806
|
await this.#session(relays, wait > 0 ? { max: wait * 1000, until: () => this.#read(({ st }) => st.inbox.length > 0) } : {});
|
|
1737
|
-
} catch (e) { offline =
|
|
1807
|
+
} catch (e) { offline = e instanceof MsgError ? e.message : `connect: ${e.message}`; }
|
|
1738
1808
|
return this.#locked(({ st }) => {
|
|
1739
1809
|
const out = { messages: st.inbox, events: st.events, dropped: st.dropped, ...(offline && { offline }) };
|
|
1740
1810
|
st.inbox = []; st.events = []; st.dropped = {};
|
|
@@ -1750,9 +1820,11 @@ export class Carrier {
|
|
|
1750
1820
|
return c;
|
|
1751
1821
|
});
|
|
1752
1822
|
this.#routes = new Map();
|
|
1753
|
-
|
|
1823
|
+
// Revoked here whatever the relay says; offline: its mailboxes are given up at a later round.
|
|
1824
|
+
let offline = null;
|
|
1825
|
+
try { await this.#session([c.relay]); } catch (e) { offline = e instanceof MsgError ? e.message : `connect: ${e.message}`; }
|
|
1754
1826
|
const released = this.#read(({ st }) => !Object.values(st.relays[c.relay]?.claims ?? {}).some((x) => x.peer === c.did));
|
|
1755
|
-
return { name: c.name, did: c.did, revoked: true, released };
|
|
1827
|
+
return { name: c.name, did: c.did, revoked: true, released, ...(offline && { offline }) };
|
|
1756
1828
|
}
|
|
1757
1829
|
|
|
1758
1830
|
// ---- staying connected
|
package/fixtures/carrier-v0.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"kinds": {
|
|
6
6
|
"1": "invite answer (sigelo-invite/0), on the answer topic, key invite.key",
|
|
7
7
|
"2": "invite reply, on the reply topic, key invite.key",
|
|
8
|
-
"4": "contact notice {bundle: the chain, proof: {body: {v, typ: \"contact-notice\", did: the current DID, pair}, sig}}, on the mailbox topic, key notice_key",
|
|
8
|
+
"4": "contact notice {bundle: the chain, proof: {body: {v, typ: \"contact-notice\", did: the current DID, pair}, sig}}, on the mailbox topic, key notice_key; a chain that brings a recovery the receiver had not followed burns K there (re_pair)",
|
|
9
9
|
"5": "prekeys {prekeys: a signed sigelo-msg/0 bundle, want: boolean, known: the receiver's current DID as the sender holds it}, on the mailbox topic, key prekeys_key"
|
|
10
10
|
},
|
|
11
11
|
"checks": [
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"A-recovery": "454ce5f5685e58e88ef2f2486044619ea68a0b6debb29ac75e2a171be584e715",
|
|
22
22
|
"B0": "86763120acce1ef54ab133204f4cf69389897db660550bcb66123dce83cbceb2",
|
|
23
23
|
"B1": "c7383152d2b12d9d3f3bdf624ee5da01bd59fb5f934579c824a38bdd5e7dd1c6",
|
|
24
|
+
"B2": "c063e86891a773ab781ed81440d8804e22e38eb6303fe1e88117125fe8f8a401",
|
|
24
25
|
"B-recovery": "89b2386ca7a917c6ce924b50275199c9a3023ce0d6ba7073c8eba67e0237da1e",
|
|
25
26
|
"invite secret": "b0172e2b06c6823696fe004a47548fab886e6b02497ca5c60f42e357ab66485f",
|
|
26
27
|
"frame key": "c7f3174feec9236091ae203740b316e664923afd0cbdee075b8b7051d6b7bb08"
|
|
@@ -61,6 +62,18 @@
|
|
|
61
62
|
"created": "2026-10-01T00:00:00Z",
|
|
62
63
|
"nonce": "zBMQvrDEGNvFkXT9FSwbomb"
|
|
63
64
|
}
|
|
65
|
+
},
|
|
66
|
+
"B2": {
|
|
67
|
+
"did": "did:sigelo:z89LJWNN6xhZecZh3etsoeN3B5PVTR6ZpFdG5WTmowmhw",
|
|
68
|
+
"key": "z6MkswVBj5QuowJ8p2q74fwwp9ro5T8gUsBdbzeVJBfU21WF",
|
|
69
|
+
"genesis": {
|
|
70
|
+
"v": "sigelo/0",
|
|
71
|
+
"typ": "genesis",
|
|
72
|
+
"key": "z6MkswVBj5QuowJ8p2q74fwwp9ro5T8gUsBdbzeVJBfU21WF",
|
|
73
|
+
"recovery": "sha256:30386f4d6dd00e8db89549701991ebefc774cdde58930d4fcb05de20963d6fb6",
|
|
74
|
+
"created": "2026-10-01T00:00:00Z",
|
|
75
|
+
"nonce": "z6kBjogap2P7sYPpZiZsYit"
|
|
76
|
+
}
|
|
64
77
|
}
|
|
65
78
|
},
|
|
66
79
|
"rotation": {
|
|
@@ -82,6 +95,26 @@
|
|
|
82
95
|
"nonce": "zBMQvrDEGNvFkXT9FSwbomb"
|
|
83
96
|
}
|
|
84
97
|
},
|
|
98
|
+
"recovery": {
|
|
99
|
+
"body": {
|
|
100
|
+
"v": "sigelo/0",
|
|
101
|
+
"typ": "rotation",
|
|
102
|
+
"id": "did:sigelo:z6TXk8bPrkHpTXzuo3gjyNnsibUhR19Nswq5v89iBo8B3",
|
|
103
|
+
"next": "did:sigelo:z89LJWNN6xhZecZh3etsoeN3B5PVTR6ZpFdG5WTmowmhw",
|
|
104
|
+
"iat": 1791257000,
|
|
105
|
+
"reason": "recovery",
|
|
106
|
+
"recovery_key": "z6MknFEB9GzhsiMvQuYotqHKSXgumZkLZaJc6pkyGa6sir4B"
|
|
107
|
+
},
|
|
108
|
+
"sig": "zcNFYTahu2C7A32BG7ehGNN2HfsnyWu4ommKao1ZtsW9po9AroyzMFsdU7Hhyb7YEkWb5QaWMTZbYZ69jSt4QXbw",
|
|
109
|
+
"next_genesis": {
|
|
110
|
+
"v": "sigelo/0",
|
|
111
|
+
"typ": "genesis",
|
|
112
|
+
"key": "z6MkswVBj5QuowJ8p2q74fwwp9ro5T8gUsBdbzeVJBfU21WF",
|
|
113
|
+
"recovery": "sha256:30386f4d6dd00e8db89549701991ebefc774cdde58930d4fcb05de20963d6fb6",
|
|
114
|
+
"created": "2026-10-01T00:00:00Z",
|
|
115
|
+
"nonce": "z6kBjogap2P7sYPpZiZsYit"
|
|
116
|
+
}
|
|
117
|
+
},
|
|
85
118
|
"derived": {
|
|
86
119
|
"invite": {
|
|
87
120
|
"secret": "b0172e2b06c6823696fe004a47548fab886e6b02497ca5c60f42e357ab66485f",
|
|
@@ -550,6 +583,85 @@
|
|
|
550
583
|
"length": 1342,
|
|
551
584
|
"sha256": "53fbcaab644a093926f31fe67f9361ad0cfb95ae9ed3187891ec2f0ba377a0d0",
|
|
552
585
|
"hex": "0104000000000000000000000000000000000000000120164d0813e9a54ba2ca466de71493e863dad8a1345afac944d2757810c1c1c66831dbfcf3bc33cd2684c719c06e9f3d0dc56c0d35da73051f23f1d9af660bb99df6e2c4b424f46f4567ffcecec98ac789bcf1cf12dc4fa371e65e3ab826720329609cfa92f4c850ecc9b0a9fb93b457e57c51aba991e5d05d5a8b07561531dd680463557f0b278d9b9eee402559eadd21bbd878b9cd4ee8e31990f2f68c90667af80f105ab943cd94f449a6bcfa066db10e389304412474ffa0994947dc5b62386d8a6ad56f3b94e5a95ae28227bc0477c43ba184cac87d249c4be847120d54c255d84ed7d6ec1d27c0ea35f662bfd06f41f13c46ab81076bbf837e5298a8c3afa051a3b70e3dd1ca9ffc43eee04c463d4071b4a4696dcb01ff10dd929ba99884b23db71109c52f359d762172a55ca511ba8f7d94b249e6b002fd56bbdc958119a8277f9fc0bf96531641ac98dda85874847ebd063cbfcc5e8648eb2ccbd829088400904a64c5e6f9ac7aafeee4debf026071c1cb2ecdcbebc06b859c8e33fa84130aa69b76fd864cc01e4cfabeceb0ca372a1526af3b4febc639f37e15d122baff2cf04f684c1c7e9810b87112bc539ccae8e03614b300545c0a1515779f0f33a2544d808ea77bd58aacf64fb8c0270a0e9092ea6d1408a5a3ed47785f1f4f076e0012d32eebcdaaeb99d9599b8d2d5406cac5c3c6d7144112f03ae445e8db677222fa84447a260a025619a8d3e52cd2ab873321643d3099e5aa930d8f47219a7db6fa4f9f526b032f51c7af9a0571e2f903ead7cdbfae2faf7cd5bfc1a9ba7c2ea0f4e48fa79fa228e90c0bb59d7a1b23a20c1be938250a73049dacb0287543018667a78eb309cfdffcbdbf6e45b54f1903c59a8f5847ee52b42e22d405d6fb3ec711c42f58f8f34cbe33c0fcaebaf8d08243d80fb7904674ed63d604aacc97fe71a308c35ac795836d404ab2578c29805e988ae11722f8d7fdf945a1d352b67bed9b2fa9fd5d7b0e17df6c2bdc5ffa8fb2dc21f41ac020d1ffbd22e496c26c2a28eaee0496417db2022ec42ce82cc927827e171f0245c1c491c04f978635e36d65ffeb1dca97a7e187b855ee811906a0f7c46f61ed4467dedf8c015db4e776b5e0e3dd095271b0a87b96e92315f1d8e3554ff07071190493c22ad65280758123dce3e129c4f649f5526eee5bedfbaed106aa46e28daba40ee7c1ca160ed98a28cd4092580d4e5c06dc3f0368079aaf39b893976cf7f4226dc582934c80254d7ab12d16e5a9f7ad50412d8e90a7be46d374763aa8d691ff168ed242ecf2eb63978edf61d4e43ef046f08cd190a1d4cd4d356c8a7816eecb0482d7fb5ef7ac71e6c0635b6b26b98b0022ce897b70f2e0aa0d78461e5b75c40cb278e91fa1df40c8dfe8e75fa04813916fa79f8f68cfa2f839469da1d976fa5ae5a76cf0426bbfb067dac512159e879abb2360383b7032ed03702cb6f688dbc5e4212769e1fa5a8078247312a884d691745c3b5250933a1f95419b0f596f6f14d6958fa5e51366b1fee699baf5cb711a4015d3e3296f8f4900a67477591d659837700ded9259d4038e9670c4cb6fc13d225728339ae2eb0fe9c09650be3576165049a431d07097257b21d033338c97f0b54fdd0ad8b74274524bf2efc06705f760d92500c509e41e527926694b58204fe29bed4338854abdb2a3bc542846b3b5aa5b2d059d83a637d3797708832b350871d44362a566d48489567ac5ac62d05de3cc6a5015edacddaab1717634dff4d99644903980c3cb82036e68bd961d9e822ec8aa3eb246c195476134ee175448a279842b1dd7205244d9c22e8f8c9745f8d0fc789c81ba9accd1390b79cafd"
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
"case": "notice_recovery",
|
|
589
|
+
"kind": 4,
|
|
590
|
+
"key_from": "notice_key",
|
|
591
|
+
"key": "ba99871b3e22c5c71e5c95c79a73741fbd701168d0183cfffbb99c1386c6306c",
|
|
592
|
+
"topic": "m/5be6b9f80c7b2439a5cb6904c3e06778",
|
|
593
|
+
"nonce": "0056d1281c0173fc533bc7f74fd7d566e39c49584b129be4",
|
|
594
|
+
"value": {
|
|
595
|
+
"bundle": {
|
|
596
|
+
"v": "sigelo/0",
|
|
597
|
+
"typ": "bundle",
|
|
598
|
+
"genesis": {
|
|
599
|
+
"v": "sigelo/0",
|
|
600
|
+
"typ": "genesis",
|
|
601
|
+
"key": "z6MkkoWKy8Aw6tZ1KNcrQYKjU2MeXDvPoVv5NBpvEq3rzyyy",
|
|
602
|
+
"recovery": "sha256:30386f4d6dd00e8db89549701991ebefc774cdde58930d4fcb05de20963d6fb6",
|
|
603
|
+
"created": "2026-10-01T00:00:00Z",
|
|
604
|
+
"nonce": "zLgygMUMhQs4vPUovYXLLXN"
|
|
605
|
+
},
|
|
606
|
+
"rotations": [
|
|
607
|
+
{
|
|
608
|
+
"body": {
|
|
609
|
+
"v": "sigelo/0",
|
|
610
|
+
"typ": "rotation",
|
|
611
|
+
"id": "did:sigelo:z6TXk8bPrkHpTXzuo3gjyNnsibUhR19Nswq5v89iBo8B3",
|
|
612
|
+
"next": "did:sigelo:z92ycmgLsn2XUVi9ED3W2b3M5C8AtPQRB1gb2ar7zbF4f",
|
|
613
|
+
"iat": 1791256900,
|
|
614
|
+
"reason": "voluntary"
|
|
615
|
+
},
|
|
616
|
+
"sig": "z3ZJ4sidVA6QX1mNKLzFBMPcjKGw1dP9FQCfSyrBxfpEBUM6MWJ77hi2zg4Z4biYYqurt73s3992U873dGKJH5Ye6",
|
|
617
|
+
"next_genesis": {
|
|
618
|
+
"v": "sigelo/0",
|
|
619
|
+
"typ": "genesis",
|
|
620
|
+
"key": "z6MkuE83V94fRXCUkCErBcLe7LA9TLPkoSmZ8KAgRPzNvQQ7",
|
|
621
|
+
"recovery": "sha256:30386f4d6dd00e8db89549701991ebefc774cdde58930d4fcb05de20963d6fb6",
|
|
622
|
+
"created": "2026-10-01T00:00:00Z",
|
|
623
|
+
"nonce": "zBMQvrDEGNvFkXT9FSwbomb"
|
|
624
|
+
}
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
"body": {
|
|
628
|
+
"v": "sigelo/0",
|
|
629
|
+
"typ": "rotation",
|
|
630
|
+
"id": "did:sigelo:z6TXk8bPrkHpTXzuo3gjyNnsibUhR19Nswq5v89iBo8B3",
|
|
631
|
+
"next": "did:sigelo:z89LJWNN6xhZecZh3etsoeN3B5PVTR6ZpFdG5WTmowmhw",
|
|
632
|
+
"iat": 1791257000,
|
|
633
|
+
"reason": "recovery",
|
|
634
|
+
"recovery_key": "z6MknFEB9GzhsiMvQuYotqHKSXgumZkLZaJc6pkyGa6sir4B"
|
|
635
|
+
},
|
|
636
|
+
"sig": "zcNFYTahu2C7A32BG7ehGNN2HfsnyWu4ommKao1ZtsW9po9AroyzMFsdU7Hhyb7YEkWb5QaWMTZbYZ69jSt4QXbw",
|
|
637
|
+
"next_genesis": {
|
|
638
|
+
"v": "sigelo/0",
|
|
639
|
+
"typ": "genesis",
|
|
640
|
+
"key": "z6MkswVBj5QuowJ8p2q74fwwp9ro5T8gUsBdbzeVJBfU21WF",
|
|
641
|
+
"recovery": "sha256:30386f4d6dd00e8db89549701991ebefc774cdde58930d4fcb05de20963d6fb6",
|
|
642
|
+
"created": "2026-10-01T00:00:00Z",
|
|
643
|
+
"nonce": "z6kBjogap2P7sYPpZiZsYit"
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
],
|
|
647
|
+
"bindings": [],
|
|
648
|
+
"attestations": [],
|
|
649
|
+
"issuers": []
|
|
650
|
+
},
|
|
651
|
+
"proof": {
|
|
652
|
+
"body": {
|
|
653
|
+
"v": "sigelo-carrier/0",
|
|
654
|
+
"typ": "contact-notice",
|
|
655
|
+
"did": "did:sigelo:z89LJWNN6xhZecZh3etsoeN3B5PVTR6ZpFdG5WTmowmhw",
|
|
656
|
+
"pair": "a2cf45bd3d6aee6d6e3f14ffd2751924"
|
|
657
|
+
},
|
|
658
|
+
"sig": "zfohWGDS1r8mzxuVoAjXPu8R3GEeBo7jNo6gBBywk4w4zXe23Ki7ZEqR5xu2LwqPo447EGkan9Ea55rMWjWiBrT7"
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
"note": "bob's contact notice after his recovery B0 -> B2, which beats the thief's B0 -> B1: a proof signed by B2. Alice, who followed B1, merges a recovery she had not followed: she marks bob re_pair \"contact_recovery\", since K may be the thief's, and sends him nothing more until a new pairing",
|
|
662
|
+
"length": 2110,
|
|
663
|
+
"sha256": "14fe3e6b39686760134678f5904206d14e42609da2f3548b1aec37d0ee192fa5",
|
|
664
|
+
"hex": "010400000000000000000000000000000000000000010056d1281c0173fc533bc7f74fd7d566e39c49584b129be4c34de3627486193ede6942f1cab6c91afd85996bf59752463c81e48eb56db6e25f9883e535362baed3210f1f95d2638cfea2b9146e79ece77e8715a90fa604e26cb1a59891a09829f144cf211f1124bce328b5da013b43735d33f3144a4cf86aecb053a29f96fca0f4478d2a008e4045db9ac6ff837e98e6335417d3e5f95b6451ad51e88c0aa696911dc6b92ae470e6c63a9eabb6f918b879b82229163cbd5cfdd4a5fb1bb9af8b013702d492cd399818c3c1ad69e1b0927a43fee4237b8cf3b66a02d029aae3d544a9d7752ff35a4bb4d545662d8d68ec75a028244077e7f4b69ec4c76836bbfc9ee09bf3bf169b776322089c1693ac124083f89f820d0dd2a1625d59e4d5b12e098d57766bdb1cabddd8679921435d403166cbcf914b967268efdb78ad7969c96e93bf3ec3626c0754cb2f914807e314b9b6fed42c119860903a366ceda6c9095ecdffb9bfb8cc4cd0f5ab392430ab75891c94b774a7b994f59f71628fd9c33412fa88975aa5b4af7a0e1dc35f6368a9097d1ab37ff6c649d09ec53612a97776de3f89f16028d184073c423718f769bf8e2daf9077015b393df0db3d715048a34ccc8725ad0cf02018d050267756cc7cc20e7f96222877f25593c86d195c57c4f82567462a7692a18471eb9a18941e4eaca937be01f262e4d00210ac3d95124bd21905dfe1e0a875f94ca7e2a04c586e39580cdea9f26db9f06b817193f9d5f690c368ab0246ac0952c573e2dfadb253fc3f4c4190ab69d4c1b40da144f1f013034088727cd4d8af1a853ea4010ab28ca3137e1bb6bab3f909f18265fd519fed6425124100d70ac40dc35d899cb0f54fd2714d8ccf64df65ac6e2d51c4d4e3983c9a6bc2b04d3fab410246259506b9896f822e6a49c8a6447aea61492acb50d2e3014ecccef47b59748b7c1238f6814df5ac8d7412a08523683d14b57e05a87fad90fb118d1842cf5f50a2c71bcbdb1e5ac3287d22e947952f9b78cec0a0ff229383e455e930a93441956305088d4621a7310fd761133143aecc9a586834878ee7f3144e0091545f03ecae2e9145d86afbd35578ee05e2938fffa651354cdaea0363edc523212b62d419193a8a44d8c6a407d1f7470fd937f35c9a6edb297ae5349f516858a8154d95c5e0c270191d9e421b5dd25bc9e4b5271914c3f7a1bbd1e54f80fc291ef5f8e89f2cf0340eb37477096d1e94c38480cff5e2ce3fc831dc059986a71bb838f835c97c86ce84a1ccb91e00c4ce26dde9fd2cd76e3d725cadbd0775e1615d8af825dd16cb8a8660afa67a62ce3d514aba3078c074b9ddfef8ce87fd66f3112f45ba363a88d395e258078ae028534e6cbfd494ff8426de257ddccc585cfb0a95e450b03e19f03560dfff242b4ddf350f02169de4378aa0c3148eebf580530e45c81f9625d910e50043d8e345d772202dc03bb91a400d82622b317f396df9d50628cffaf97ccbbe0e9c0a43d2e460c90817e2605e028ef1a6df1dfbc757358576b21db16d0604d197d7d88f214d505b60cf3a9c90b11bcef4544ca628aa5606115111de64a0cc67056620309c3ae2d66e6ea64b3be59ea49c27f6726fcf50898faf7538e38d9cb96e6b168342a5fef446b0fdd94d9bda60c72254147d3dd39ad2be53c220d4dddd5d531ce6262853c71a9c4107555a1608b3993e8d43aa64fbb6ab3bcc7587fc9e30e0cbf5f76cae40b697d5b978b7388018336a1cd598d34a2344f8ad33a0bee0746bd02cf5c0d443dbfb679ea044e67aa255988c7835a88b590a9b206db8d2ae9161267447471cac3f547be96f6c42a34c8d224a1f3717c5580888abbd1a1bc6ef6f7140a156bd7371a1b5261b17b5e99e47258db8d553a9be4b221323eb57845a20a528a2122d3f8c48447eb8299ed41414eb3586556be5ddd5102687bd480c5a8de8ad27ef249672986579becf8d95937d4800e08de5e9819355c3d2b9ccc9c72ffd237343ebd8bb78aafc994db163aaa3d8fbc5b5cc3ae4546e797a25e363e307cdad2827b35a0b085699f2dc91bcb14368b734e4377dd2dc1e3fc95c634748002cc1da7a5bab03ca84e86ac8df4a31064ce82072a549740b4f713517bc8bdb0b720e2780f03ab8d1b138988b6ff04dccc94c3e1de1c2b01a3a9bfee8a4f1e8ddf6ba353c24084a61d3f99b246c1256284a9405aec6ef29cf92eda584e39c84d215ab89139833ecba4199b9723b8c56ceb36befcfab6900a0802122eacbe44f7d93731d3dabc6ca3d312e3e1484a4a23c26b6242c715e40e4860d2cb8b6b641a3b737317ab85f756ede2d0845296d91eddb92c3620ff1e515679a379bd64184a2a1a67402d8dc54d2e3a7436394fed0c16e502faabf595ea6ac82fbf6ace711e61868b5fbbed3dd6e4b6ca99b8134bfa3bf778cf71dcf962e599067bfce8d46548942151a905f2c66fe5bd3562fe6304bc93752563b182dd31d64abdeb0c0f127b1635a5200b56145339b3debf50e02f9cc52a6c46d04b1d5571c3addd75bec5e08208a266d894cad98b9fceccf11edf7e477c751d0e42807721aab6859a52a5838c2b401a5717576b00f8e3f93fd6c3c23a1614e8fb70a367e1f057469cfc3bd7e592981407e38632dc46cf36bb32cf2d02f6aa2e3df9cac828d9c92cbabcfcf75f40fa4cf2838a9fff696eba3c29ea554687daff5da87caf10c8aab6e7bcc2c89e40c2c7ddbf6c1a00549821fe0fbabadba518c6b1e9e9de69bcd88872d4f67dda453dd540223ff8605639a86e37ea11c205a13f65d3d85d64156e28c3c9a712455676b20670dad041cb85b9192bca8c8c6c6829a275cf9576d5154ac78bad596b778fb32e9bc07daddcc8e65f00b1fe41efe0849a6462c66dd38b94d7d135a7dcb418fe63ae5a5ba05c7a33b52342987bc1d180c722f90"
|
|
553
665
|
}
|
|
554
666
|
],
|
|
555
667
|
"refusals": [
|
package/gen-carrier.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Regenerates fixtures/carrier-v0.json, byte for byte, from the documented seeds below: the frames
|
|
3
|
-
// of contract sigelo-carrier/0 (carrier.mjs header, "Frames"), kinds 1, 2, 4 and
|
|
3
|
+
// of contract sigelo-carrier/0 (carrier.mjs header, "Frames"), kinds 1, 2, 4 (a rotation and a
|
|
4
|
+
// recovery) and 5.
|
|
4
5
|
// node contact/gen-carrier.mjs write the file
|
|
5
6
|
// node contact/gen-carrier.mjs --check exit 1 if the committed file differs
|
|
6
7
|
// Independent of carrier.mjs, invite.mjs and prekeys.mjs on purpose: headers, keys, topics,
|
|
@@ -59,10 +60,12 @@ const frameOf = (kind, key, topic, plaintext, nonce) => concatBytes(head(kind),
|
|
|
59
60
|
const derive = (ikm, salt, info, n) => hkdf(sha256, ikm, salt === null ? undefined : u8(salt), u8(info), n);
|
|
60
61
|
|
|
61
62
|
export function build() {
|
|
62
|
-
// Identities: alice (A0) invites, bob (B0) answers and later rotates to B1.
|
|
63
|
+
// Identities: alice (A0) invites, bob (B0) answers and later rotates to B1. Then B1 turns out to
|
|
64
|
+
// be a thief's: bob recovers from B0 to B2 with his recovery key, which beats B1 (SPEC §7.1).
|
|
63
65
|
const [aRec, bRec] = ['A-recovery', 'B-recovery'].map((l) => id(l, ZERO).key);
|
|
64
|
-
const A0 = id('A0', aRec), B0 = id('B0', bRec), B1 = id('B1', bRec);
|
|
66
|
+
const A0 = id('A0', aRec), B0 = id('B0', bRec), B1 = id('B1', bRec), B2 = id('B2', bRec);
|
|
65
67
|
const rB1 = rotate({ genesis: B0.genesis, next_genesis: B1.genesis, iat: T0 + 100, reason: 'voluntary', secret: B0.secret });
|
|
68
|
+
const rB2 = rotate({ genesis: B0.genesis, next_genesis: B2.genesis, iat: T0 + 200, reason: 'recovery', secret: id('B-recovery', ZERO).secret });
|
|
66
69
|
|
|
67
70
|
// The invite secret, alice's code and what they yield (contact/invite.mjs, sigelo-invite/0). Code:
|
|
68
71
|
// version 1 | SHA-256(JCS(A0's genesis)) | secret | exp, u32 BE | relay length | relay | checksum =
|
|
@@ -112,6 +115,8 @@ export function build() {
|
|
|
112
115
|
const prekeysKey = derive(K, 'sigelo-prekeys/0', `${B0.did}\n${A0.did}`, 32), noticeKey = derive(K, 'sigelo-notice/0', `${B0.did}\n${A0.did}`, 32);
|
|
113
116
|
const noticeBody = { v: V, typ: 'contact-notice', did: B1.did, pair };
|
|
114
117
|
const notice = { bundle: chainOf(B0.genesis, [rB1]), proof: { body: noticeBody, sig: sign(B1.secret, noticeBody) } };
|
|
118
|
+
const recoveredBody = { v: V, typ: 'contact-notice', did: B2.did, pair };
|
|
119
|
+
const noticeRecovered = { bundle: chainOf(B0.genesis, [rB1, rB2]), proof: { body: recoveredBody, sig: sign(B2.secret, recoveredBody) } };
|
|
115
120
|
|
|
116
121
|
const frames = [];
|
|
117
122
|
const counting = Uint8Array.from({ length: 24 }, (_, i) => i + 1);
|
|
@@ -128,6 +133,8 @@ export function build() {
|
|
|
128
133
|
frame('reply', 2, 'invite.key', derive(secret, null, 'sigelo-invite/0 key', 32), invite.reply_topic, reply, 'alice\'s invite reply, her prekeys inside, on the reply topic');
|
|
129
134
|
frame('prekeys', 5, 'prekeys_key', prekeysKey, mailbox, { prekeys: bundleOf(B0, 'bob prekeys', T0 + 40), want: false, known: A0.did }, 'bob\'s prekeys, his first frame after the reply, on his mailbox to alice; known: alice\'s current DID as he holds it');
|
|
130
135
|
frame('notice', 4, 'notice_key', noticeKey, mailbox, notice, 'bob\'s contact notice after his rotation B0 -> B1: his chain, a proof signed by B1');
|
|
136
|
+
frame('notice_recovery', 4, 'notice_key', noticeKey, mailbox, noticeRecovered, 'bob\'s contact notice after his recovery B0 -> B2, which beats the thief\'s B0 -> B1: '
|
|
137
|
+
+ 'a proof signed by B2. Alice, who followed B1, merges a recovery she had not followed: she marks bob re_pair "contact_recovery", since K may be the thief\'s, and sends him nothing more until a new pairing');
|
|
131
138
|
|
|
132
139
|
// Refusals, in unseal's order: frame, aead, padding, plaintext, the same ten for each kind, so a
|
|
133
140
|
// branch of one kind cannot pass what another refuses. Each frame is read as `read_as` under the
|
|
@@ -158,12 +165,13 @@ export function build() {
|
|
|
158
165
|
+ '`refusals`: opening `hex` as kind `read_as` under the generic key on `topic` fails with `error`, the first failing check. '
|
|
159
166
|
+ '`derived`: what the seeds yield, each from the formula beside it.',
|
|
160
167
|
layout: 'version 0x01 (1) | kind (1) | 16 zero bytes | counter 1, u32 big-endian (4) | XChaCha20-Poly1305 nonce (24) | ciphertext + tag of pad(JCS(value)); additional data = the 22-byte header ‖ UTF-8 topic; pad: 0x80 then 0x00 to the next multiple of 256',
|
|
161
|
-
kinds: { 1: 'invite answer (sigelo-invite/0), on the answer topic, key invite.key', 2: 'invite reply, on the reply topic, key invite.key', 4: 'contact notice {bundle: the chain, proof: {body: {v, typ: "contact-notice", did: the current DID, pair}, sig}}, on the mailbox topic, key notice_key', 5: 'prekeys {prekeys: a signed sigelo-msg/0 bundle, want: boolean, known: the receiver\'s current DID as the sender holds it}, on the mailbox topic, key prekeys_key' },
|
|
168
|
+
kinds: { 1: 'invite answer (sigelo-invite/0), on the answer topic, key invite.key', 2: 'invite reply, on the reply topic, key invite.key', 4: 'contact notice {bundle: the chain, proof: {body: {v, typ: "contact-notice", did: the current DID, pair}, sig}}, on the mailbox topic, key notice_key; a chain that brings a recovery the receiver had not followed burns K there (re_pair)', 5: 'prekeys {prekeys: a signed sigelo-msg/0 bundle, want: boolean, known: the receiver\'s current DID as the sender holds it}, on the mailbox topic, key prekeys_key' },
|
|
162
169
|
checks: ['frame', 'aead', 'padding', 'plaintext'],
|
|
163
170
|
created: CREATED, t0: T0,
|
|
164
|
-
seeds: Object.fromEntries(['A0', 'A-recovery', 'B0', 'B1', 'B-recovery', 'invite secret', 'frame key'].map((l) => [l, hex(seed(l))])),
|
|
165
|
-
identities: Object.fromEntries(Object.entries({ A0, B0, B1 }).map(([k, x]) => [k, { did: x.did, key: x.key, genesis: x.genesis }])),
|
|
171
|
+
seeds: Object.fromEntries(['A0', 'A-recovery', 'B0', 'B1', 'B2', 'B-recovery', 'invite secret', 'frame key'].map((l) => [l, hex(seed(l))])),
|
|
172
|
+
identities: Object.fromEntries(Object.entries({ A0, B0, B1, B2 }).map(([k, x]) => [k, { did: x.did, key: x.key, genesis: x.genesis }])),
|
|
166
173
|
rotation: rB1,
|
|
174
|
+
recovery: rB2,
|
|
167
175
|
derived: {
|
|
168
176
|
invite,
|
|
169
177
|
kem_pk: 'X-Wing keygen(rng("kem key") 32 bytes): the answer\'s kem_pk',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sigelo-contact",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Agent contacts for sigelo identities: invite codes, a contact store, end-to-end encrypted envelopes with hybrid post-quantum key agreement, and an MQTT carrier. Client code (MIT); the relay server is csigelo/sigelo-relay (AGPL-3.0).",
|
|
6
6
|
"keywords": [
|
|
@@ -75,6 +75,6 @@
|
|
|
75
75
|
"@noble/hashes": "^2.4.0",
|
|
76
76
|
"@noble/post-quantum": "^0.7.1",
|
|
77
77
|
"mqtt": "^5.16.0",
|
|
78
|
-
"sigelo": "^0.1.
|
|
78
|
+
"sigelo": "^0.1.3"
|
|
79
79
|
}
|
|
80
80
|
}
|
package/store.mjs
CHANGED
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
// a rotation keeps the contact and a recovery still beats a thief (SPEC §7.1).
|
|
5
5
|
// { v, self, invites: { nonce: { secret, exp, name, peer, relay } },
|
|
6
6
|
// accepts: { answer id: { secret, code_did, exp, name, relay, kem_sk, as } },
|
|
7
|
-
// contacts: { original DID: { name, did, current_did, current_key, revoked, chain, rotations, relay, pair_key } } }
|
|
7
|
+
// contacts: { original DID: { name, did, current_did, current_key, revoked, chain, rotations, relay, pair_key, re_pair? } } }
|
|
8
8
|
// invites: codes this owner handed out, keyed by inviteNonce(code bytes); peer: the original DID of
|
|
9
9
|
// the contact a re-key code is for, null on a new contact's code. accepts: codes this owner
|
|
10
|
-
// answered, keyed by answerId(answer).
|
|
10
|
+
// answered, keyed by answerId(answer). re_pair: "own_recovery" or "contact_recovery" once a recovery
|
|
11
|
+
// burned pair_key (carrier.mjs, "After a recovery"); a new pairing writes the record without it.
|
|
12
|
+
// The file holds one-time secrets, Bob's one-time key and
|
|
11
13
|
// pairing keys, so it is written 0600. Two simultaneous writers still need the integrator's lock.
|
|
12
14
|
import { randomBytes } from 'node:crypto';
|
|
13
15
|
import { existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
package/test-carrier.mjs
CHANGED
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
// undone and reported; hostile hosts (an endless answer, a greedy proof of work, proof of work
|
|
13
13
|
// asked again at every reconnection, redirects to a host inside, a 100 MB MQTT packet, a code
|
|
14
14
|
// naming an address or a local name); a 502 refuses nothing and a delivered answer outlives a refusal for good; a slow packet
|
|
15
|
-
// does not read as a drained queue; a thief's fork of 63 rotations loses to the owner's recovery
|
|
15
|
+
// does not read as a drained queue; a thief's fork of 63 rotations loses to the owner's recovery,
|
|
16
|
+
// after which both sides hold the pairing key as burned (re_pair: only the notice goes, no new
|
|
17
|
+
// mailbox is claimed) until they pair again, and a thief holding the old key claims next week's
|
|
18
|
+
// mailboxes under it and gets nothing;
|
|
16
19
|
// a notice whose chain ends at a key its sender does not hold is refused (notice_sig); a refused
|
|
17
20
|
// first envelope gives its prekey back; 32 days with no bundle across heal without pairing again;
|
|
18
21
|
// a carrier with onEvent keeps no plaintext at rest; one code accepted twice; an epoch outlives its
|
|
@@ -43,7 +46,7 @@ import { PassThrough } from 'node:stream';
|
|
|
43
46
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
44
47
|
import { xchacha20poly1305 } from '@noble/ciphers/chacha.js';
|
|
45
48
|
import { connect } from 'mqtt';
|
|
46
|
-
import { canonicalize, keygen, rotate, sign } from 'sigelo';
|
|
49
|
+
import { canonicalize, keygen, rotate, sign, verify, verifySig } from 'sigelo';
|
|
47
50
|
import { Carrier, INVITE_BYTES, KIND_PREKEYS, LABEL_PREKEYS, MAX_PACKET, MAX_ROTATIONS, NOTICE_CHECKS, POW_SEARCHES, TYP_NOTICE, V as CARRIER_V, limitPackets, noticeKey, pathsFor, prekeysKey, seal, solvePow, unseal } from './carrier.mjs';
|
|
48
51
|
import { MAX_ENVELOPE, header, pad } from './envelope.mjs';
|
|
49
52
|
import { V as STORE_V, answerId, buildAnswer, checkAnswer, checkReply, inviteKeys, makeInvite, parseInvite } from './invite.mjs';
|
|
@@ -88,6 +91,13 @@ const report = () => {
|
|
|
88
91
|
const ik = inviteKeys(unhex(d.invite.secret));
|
|
89
92
|
ok(ik.answer_topic === d.invite.answer_topic && ik.reply_topic === d.invite.reply_topic && hexOf(ik.key) === d.invite.key, 'what the invite secret yields (invite.mjs)');
|
|
90
93
|
ok(checkPrekeys(value('prekeys').prekeys, { did: B0.did, current_did: B0.did, current_key: B0.key }, d.pair.hex, F.t0 + 40).keys.length === 20, 'bob\'s bundle in the prekeys frame passes the sender\'s check');
|
|
94
|
+
{
|
|
95
|
+
// The recovery notice: its chain follows the recovery past the thief's B1 and ends at B2, whose
|
|
96
|
+
// key signs the proof. A receiver that followed B1 marks bob re_pair (the relay part below).
|
|
97
|
+
const n = value('notice_recovery'), r = verify(n.bundle, F.t0 + 300), B2 = F.identities.B2;
|
|
98
|
+
ok(r.did === B2.did && r.chain.join() === `${B0.did},${B2.did}` && F.recovery.body.reason === 'recovery' && verifySig(B2.key, n.proof.body, n.proof.sig),
|
|
99
|
+
'the recovery notice: the recovery from B0 beats the thief\'s B1, the chain ends at B2, the proof verifies under B2\'s key');
|
|
100
|
+
}
|
|
91
101
|
const sd = mkdtempSync(join(tmpdir(), 'sigelo-carrier-fixture-'));
|
|
92
102
|
try {
|
|
93
103
|
// alice's code from the fixture's inputs: its bytes, and a nonce that hashes all of them.
|
|
@@ -171,6 +181,9 @@ const make = (a, extra = {}) => {
|
|
|
171
181
|
const seen = (who, f) => events[who].filter(f);
|
|
172
182
|
const texts = (who) => seen(who, (e) => e.type === 'message').map((e) => e.content);
|
|
173
183
|
const stateOf = (a) => JSON.parse(readFileSync(pathsFor(join(dir, `${a.label}.local.json`)).state, 'utf8'));
|
|
184
|
+
// The contact's re_pair as the carrier's contacts() lists it.
|
|
185
|
+
const marked = (carrier, peer) => carrier.contacts().contacts.find((c) => c.did === peer.original)?.re_pair;
|
|
186
|
+
const claimsOf = (a) => Object.keys(stateOf(a).relays[HOST]?.claims ?? {});
|
|
174
187
|
const editState = (a, f) => { const file = pathsFor(join(dir, `${a.label}.local.json`)).state, s = JSON.parse(readFileSync(file, 'utf8')); f(s); writeFileSync(file, JSON.stringify(s)); };
|
|
175
188
|
const oneTimeLeft = (holder, peer) => stateOf(holder).peers[peer.original].session.in.prekeys.oneTime.length;
|
|
176
189
|
const q = (sql, ...p) => relay.db.raw.prepare(sql).all(...p);
|
|
@@ -896,13 +909,25 @@ try {
|
|
|
896
909
|
const thief = make(T), heldBy = (x) => storeOf(x).contacts[A.original];
|
|
897
910
|
ok((await thief.send('bob', say('from the thief'))).status === 'sent' && await until(() => texts('bob').includes('from the thief')), 'the thief, holding alice\'s key and files, rotates 63 times and writes to bob');
|
|
898
911
|
ok(bob.contacts().contacts.find((c) => c.did === A.original).current_did === T.did && heldBy(B).rotations.length === 64, 'bob follows the thief\'s chain, 64 rotations: nothing offline can tell it from alice\'s');
|
|
912
|
+
// A message alice queued for bob before the recovery, as a send that returned `queued` leaves
|
|
913
|
+
// it: that send has exited, so only her inbox can tell her it never went.
|
|
914
|
+
const QUEUED = 'queued-before-the-recovery';
|
|
915
|
+
editState(A, (s) => s.peers[B.original].outbox.push({ id: QUEUED, label: '', content: say('queued before the recovery') }));
|
|
899
916
|
recoverAgent(A);
|
|
900
917
|
const recovered = A.did;
|
|
901
918
|
secrets.add(recovered);
|
|
902
|
-
|
|
903
|
-
ok(
|
|
919
|
+
// The thief copied K with the key: after the recovery both sides hold it as burned (re_pair).
|
|
920
|
+
ok(marked(alice, B) === 'own_recovery' && storeOf(A).contacts[B.original].re_pair === 'own_recovery', 'alice recovers: her store marks bob re_pair, own_recovery, before any connection');
|
|
921
|
+
await refuses(() => alice.send('bob', 'after recovery'), 're_pair', 'and she sends him nothing under the old K');
|
|
922
|
+
const afterRecovery = (await alice.inbox()).events;
|
|
923
|
+
ok(afterRecovery.some((e) => e.type === 're_pair' && e.did === B.original && e.re_pair === 'own_recovery'), 'her next inbox says so');
|
|
924
|
+
ok(afterRecovery.some((e) => e.type === 'refused' && e.id === QUEUED && e.peer === B.original && e.code === 're_pair')
|
|
925
|
+
&& stateOf(A).peers[B.original].outbox.length === 0 && seen('alice', (e) => e.type === 'refused' && e.id === QUEUED).length === 1,
|
|
926
|
+
'and that the message queued for him before the recovery was refused, unsent (a refused event, code re_pair)');
|
|
927
|
+
ok(await until(() => heldBy(B).current_did === recovered), 'her rotation notice still goes: bob\'s store merged both chains, the recovery wins (SPEC §7.1)');
|
|
904
928
|
ok(heldBy(B).rotations.length === 2, `and keeps the chain followed: her first rotation and the recovery, the thief's fork gone (${heldBy(B).rotations.length})`);
|
|
905
|
-
ok(seen('bob', (e) => e.type === '
|
|
929
|
+
ok(marked(bob, A) === 'contact_recovery' && seen('bob', (e) => e.type === 'rotated' && e.current_did === recovered && e.re_pair === 'contact_recovery').length === 1,
|
|
930
|
+
'bob marks alice re_pair, contact_recovery, and his rotated event says so');
|
|
906
931
|
// She rotates again. First a notice from whoever holds K, with a copy of that rotation whose
|
|
907
932
|
// signature is not valid ahead of the real one: refused, and bob's record left as it was.
|
|
908
933
|
rotateAgent(A);
|
|
@@ -917,19 +942,29 @@ try {
|
|
|
917
942
|
ok(await until(() => seen('bob', (e) => e.type === 'dropped' && e.check === 'bundle' && /two rotations on one edge/.test(e.detail)).length === 1), 'a notice with two rotations on one edge, the first not valid: refused');
|
|
918
943
|
ok(heldBy(B).current_did === recovered && heldBy(B).rotations.length === 2, 'and bob\'s record is as it was');
|
|
919
944
|
}
|
|
920
|
-
|
|
921
|
-
ok(heldBy(B).current_did === A.did && heldBy(B).rotations.length === 3, 'bob follows her rotation after the recovery');
|
|
945
|
+
await alice.inbox();
|
|
946
|
+
ok(await until(() => heldBy(B).current_did === A.did) && heldBy(B).rotations.length === 3 && heldBy(B).re_pair === 'contact_recovery', 'her own notice follows: bob follows her rotation after the recovery, the mark kept');
|
|
922
947
|
await refuses(() => thief.send('bob', 'thief again'), 'bundle', 'the relay, which kept alice\'s recovery, refuses the thief\'s login');
|
|
923
|
-
|
|
924
|
-
ok((await alice.inbox()).messages.some((m) => m.content === 'to the recovered key'), 'alice reads it: her fresh prekeys followed her notice');
|
|
948
|
+
await refuses(() => bob.send('alice', 'to the recovered key'), 're_pair', 'bob sends nothing to alice under the old K either');
|
|
925
949
|
}
|
|
926
950
|
|
|
927
951
|
// ================================================================ pairing again replaces K
|
|
928
952
|
{
|
|
929
953
|
// The thief also copied K, and with it every later mailbox topic of the pair, which it can
|
|
930
|
-
// claim first from any identity. A recovery does not change K
|
|
931
|
-
//
|
|
932
|
-
|
|
954
|
+
// claim first from any identity. A recovery does not change K, so neither side claims a new
|
|
955
|
+
// mailbox under it (re_pair); pairing again does: a code between two contacts keeps the
|
|
956
|
+
// contact, replaces K, and its topics with it, and clears the mark. A week passes first.
|
|
957
|
+
const K0 = storeOf(A).contacts[B.original].pair_key, K0b = Buffer.from(K0, 'hex');
|
|
958
|
+
now += 7 * DAY;
|
|
959
|
+
await bob.sync();
|
|
960
|
+
await alice.inbox();
|
|
961
|
+
const ahead = isoWeek(now + 7 * DAY), squat = [topic(K0b, B.original, A.original, ahead), topic(K0b, A.original, B.original, ahead)];
|
|
962
|
+
ok(!squat.some((t) => claimsOf(A).includes(t) || claimsOf(B).includes(t)), 'a week after the recovery, neither has claimed next week\'s mailboxes under the burned K');
|
|
963
|
+
const squatter = await rawClient(agent('squatter')), squatted = [], takenBefore = seen('alice', (e) => e.code === 'mailbox_taken').length;
|
|
964
|
+
squatter.on('message', (t) => { if (squat.includes(t)) squatted.push(t); });
|
|
965
|
+
// The SUBACK's codes: MQTT.js hands back the topics asked, at the QoS asked, when one is refused.
|
|
966
|
+
const claim = (topics) => new Promise((resolve) => squatter.subscribe(topics, { qos: 1 }, (_err, _subs, packet) => resolve(packet?.granted ?? [])));
|
|
967
|
+
ok((await claim(squat)).join() === '1,1', 'the thief, holding K0, claims both of them first: the relay cannot tell (the live test\'s squat)');
|
|
933
968
|
const code = (await alice.invite({ name: 'bob again' })).code;
|
|
934
969
|
ok((await bob.accept(code, { name: 'alice again', wait: 0.3 })).status === 'waiting', 'bob answers a new code from alice, his contact already');
|
|
935
970
|
const a1 = await alice.inbox();
|
|
@@ -938,9 +973,24 @@ try {
|
|
|
938
973
|
const K1 = storeOf(A).contacts[B.original].pair_key;
|
|
939
974
|
ok(K1 !== K0 && K1 === storeOf(B).contacts[A.original].pair_key, 'both hold a new K, unknown to whoever copied the old one');
|
|
940
975
|
ok(alice.contacts().contacts.filter((c) => c.did === B.original).map((c) => c.name).join() === 'bob', 'one contact, its name kept');
|
|
976
|
+
ok(marked(alice, B) === null && marked(bob, A) === null, 'and neither marks the other any more: the new K is not burned');
|
|
941
977
|
await alice.inbox(); // bob's prekeys for the new pairing
|
|
942
978
|
ok((await alice.send('bob', say('under the new K'))).status === 'sent' && await until(() => texts('bob').includes('under the new K')), 'alice writes under the new K, bob reads it');
|
|
979
|
+
ok(seen('bob', (e) => e.type === 'message' && e.content === 'under the new K')[0]?.current_did === A.did, 'signed by her key after the recovery');
|
|
943
980
|
ok((await bob.send('alice', say('back under the new K'))).status === 'sent' && (await alice.inbox()).messages.some((m) => m.content === 'back under the new K'), 'and back');
|
|
981
|
+
// Next week's mailboxes of the pair are now K1's, held ahead by the pair: a thief with K0 cannot
|
|
982
|
+
// derive them, and one that learnt them could not claim them.
|
|
983
|
+
const K1b = Buffer.from(K1, 'hex'), theirs = [topic(K1b, B.original, A.original, ahead), topic(K1b, A.original, B.original, ahead)];
|
|
984
|
+
ok(await until(() => claimsOf(A).includes(theirs[0]) && claimsOf(B).includes(theirs[1])), 'next week\'s mailboxes under the new K are already claimed, each by its reader');
|
|
985
|
+
const refused = await claim(theirs);
|
|
986
|
+
ok(refused.join() === '128,128', `claimed by anyone else: refused (mailbox_taken; SUBACK ${refused.join()})`);
|
|
987
|
+
now += 7 * DAY;
|
|
988
|
+
await alice.inbox();
|
|
989
|
+
ok((await bob.send('alice', say('next week, under the new K'))).status === 'sent' && (await alice.inbox()).messages.some((m) => m.content === 'next week, under the new K'),
|
|
990
|
+
'a week later bob writes in that week\'s mailbox and alice reads it');
|
|
991
|
+
await sleep(300);
|
|
992
|
+
squatter.end(true);
|
|
993
|
+
ok(squatted.length === 0 && seen('alice', (e) => e.code === 'mailbox_taken').length === takenBefore, `the thief's mailboxes under K0 got nothing (${squatted.length}), and alice never met mailbox_taken`);
|
|
944
994
|
}
|
|
945
995
|
|
|
946
996
|
// ================================================================ the MCP tools: the same verbs
|
|
@@ -1115,8 +1165,11 @@ try {
|
|
|
1115
1165
|
recoverAgent(O);
|
|
1116
1166
|
const recovered = O.did;
|
|
1117
1167
|
secrets.add(recovered);
|
|
1118
|
-
|
|
1119
|
-
|
|
1168
|
+
await refuses(() => odile.send('piet', 'odile recovered'), 're_pair', 'within that hour odile recovers: she writes nothing to piet under the old K');
|
|
1169
|
+
await odile.inbox();
|
|
1170
|
+
await piet.inbox();
|
|
1171
|
+
ok(storeOf(Pi).contacts[O.original].current_did === recovered && storeOf(Pi).contacts[O.original].re_pair === 'contact_recovery',
|
|
1172
|
+
'her notice, bringing the recovery, is checked all the same: piet follows it, and marks her re_pair');
|
|
1120
1173
|
t += 3601;
|
|
1121
1174
|
await publish(mal, tp(), junk(NOTICE_CHECKS + 2));
|
|
1122
1175
|
mal.end(true);
|