sigelo-contact 0.1.21 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/GROUPS-REFERENCE.md +165 -0
  2. package/GROUPS.md +53 -0
  3. package/LICENSE +235 -21
  4. package/README.md +4 -5
  5. package/call.mjs +89 -28
  6. package/carrier.mjs +230 -51
  7. package/control.mjs +2 -2
  8. package/create.mjs +2 -2
  9. package/device.mjs +2 -2
  10. package/enrol.mjs +2 -2
  11. package/envelope.mjs +6 -6
  12. package/file.mjs +2 -2
  13. package/fixtures/carrier-v0.json +1 -1
  14. package/fixtures/envelope-v0.json +1 -1
  15. package/fixtures/group-v2.json +2999 -0
  16. package/gen-carrier.mjs +2 -2
  17. package/gen-device.mjs +1 -1
  18. package/gen-envelope.mjs +2 -2
  19. package/gen-group2.mjs +291 -0
  20. package/gen-invite.mjs +2 -2
  21. package/gen-short.mjs +1 -1
  22. package/group.mjs +116 -17
  23. package/group2.mjs +1534 -0
  24. package/home-wire.mjs +812 -0
  25. package/invite.mjs +3 -3
  26. package/kdf.mjs +2 -2
  27. package/kin.mjs +62 -0
  28. package/link.mjs +6 -6
  29. package/package.json +25 -8
  30. package/page.mjs +507 -57
  31. package/photo.mjs +2 -2
  32. package/platform-node.mjs +6 -6
  33. package/prekeys.mjs +3 -3
  34. package/public.mjs +2 -2
  35. package/qr-decode.mjs +1 -1
  36. package/qr.mjs +2 -2
  37. package/relays.mjs +2 -2
  38. package/restore.mjs +2 -2
  39. package/rtc-web.mjs +3 -3
  40. package/short.mjs +2 -2
  41. package/store.mjs +22 -9
  42. package/test-carrier.mjs +32 -11
  43. package/test-device.mjs +3 -3
  44. package/test-enrol.mjs +9 -4
  45. package/test-envelope.mjs +2 -2
  46. package/test-file.mjs +2 -2
  47. package/test-group-move.mjs +225 -0
  48. package/test-group.mjs +1 -1
  49. package/test-group2.mjs +202 -0
  50. package/test-home.mjs +225 -0
  51. package/test-invite.mjs +1 -1
  52. package/test-link.mjs +3 -3
  53. package/test-platform.mjs +2 -2
  54. package/test-presence.mjs +2 -2
  55. package/test-push.mjs +5 -5
  56. package/test-relay-lane.mjs +3 -3
  57. package/test-short.mjs +1 -1
  58. package/test-tier.mjs +8 -2
  59. package/test-transfer-web.mjs +7 -7
  60. package/test-transfer.mjs +6 -6
  61. package/test-voice.mjs +2 -2
  62. package/test-ws.mjs +1 -1
  63. package/transfer-engine.mjs +6 -6
  64. package/transfer-node.mjs +5 -5
  65. package/transfer-web.mjs +3 -3
  66. package/transfer.mjs +8 -8
  67. package/voice-web.mjs +2 -2
  68. package/voice.mjs +7 -3
  69. package/words-lock.mjs +2 -2
package/photo.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: MIT
2
- // A photo's inline preview (design/transfer.md §10.4): what a chat shows at once while the full file
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // A photo's inline preview (apps/agent/TRANSFER.md "The phone app"): what a chat shows at once while the full file
3
3
  // comes by a transfer. Not sigelo-picture/0, which sets a contact's own picture. One contact message
4
4
  // labelled PHOTO_LABEL (inside the pairing's end-to-end envelope, as any message), or the `photo` of a
5
5
  // group's msg (group.mjs); either way the content is
package/platform-node.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: MIT
2
- // The Node platform of sigelo-contact (design/apps.md §4.2): every call the carrier, the contact
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // The Node platform of sigelo-contact (README.md "Platforms"): every call the carrier, the contact
3
3
  // store and the enrolment file make to the file system, the network, the lock and the CPU, as one
4
4
  // object. new Carrier({ ..., platform }) takes another (a browser's, a test's in-memory one); without
5
5
  // one it is this, and the behaviour is the one these calls had inside carrier.mjs.
@@ -85,8 +85,8 @@ export const path = { join, dirname, resolve };
85
85
  // One lock file per name: every change is load, change, save inside it, so a CLI verb and a
86
86
  // long-running carrier on the same identity cannot undo each other. As
87
87
  // apps/agent/sigelo-agent-monero.ts withLock. who: the processes named in the refusal.
88
- // The lock holds its process's pid: a lock whose process is gone (a CLI killed holding it, the agent-setup feedback
89
- // point 9: every verb then waited and failed until a human deleted the file) is removed, with one line.
88
+ // The lock holds its process's pid: a lock whose process is gone (a CLI killed holding it:
89
+ // every verb then waited and failed until a human deleted the file) is removed, with one line.
90
90
  // Read twice before removal, so a lock taken over in between is never removed; an empty one (being
91
91
  // written, or an older client's) waits as before.
92
92
  const LOCK_TRIES = 200, LOCK_MS = 25;
@@ -263,7 +263,7 @@ function powIdle(w) {
263
263
  /** The first c (0, 1, 2, …) with Argon2id(password = prefix ‖ c, salt, m KiB, t passes, p lanes,
264
264
  * 32 bytes) starting with `bits` zero bits (carrier.mjs solvePow), or null once Date.now() passes
265
265
  * deadline (or signal aborts). In a worker thread: one evaluation at 64 MiB is ~0.5 s of a core
266
- * on a phone-class CPU, which this thread never waits through, so the process's connections,
266
+ * on a low-end ARM64 CPU, which this thread never waits through, so the process's connections,
267
267
  * keepalives and other identities carry on. onProgress(tried) after each evaluation. */
268
268
  export function pow(job, bits, { deadline = Infinity, signal, onProgress } = {}) {
269
269
  const { prefix, salt, m, t, p } = job ?? {};
@@ -353,7 +353,7 @@ export function sendable(file, own, max) {
353
353
 
354
354
  // ---------------------------------------------------------------- the platform
355
355
 
356
- /** The Node platform (design/apps.md §4.2), the carrier's default. */
356
+ /** The Node platform (README.md "Platforms"), the carrier's default. */
357
357
  export const platform = Object.freeze({
358
358
  files, path, flush: async () => {}, transact, owner, fetch: nodeFetch, mqtt, transports: Object.freeze(['mqtts', 'wss']), pow, openPath,
359
359
  get env() {
package/prekeys.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: MIT
2
- // sigelo-msg/0 prekeys (design/relay-plan.md §3 "Prekeys"). A holder hands each contact a signed
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // sigelo-msg/0 prekeys (README.md "How it works", 4). A holder hands each contact a signed
3
3
  // bundle of single-use X-Wing (ML-KEM-768 + X25519) public keys; a sender starts an epoch by
4
4
  // encapsulating to one. Sent only to that contact, inside the pairwise mailbox: no directory.
5
5
  // holder: const p = new Prekeys(); const signed = p.issue(me, pair, now) → send signed; reissue when p.due(now, me)
@@ -234,7 +234,7 @@ export function checkPrekeys(signed, contact, pair, now) {
234
234
  return { did: b.did, iat: b.iat, exp: b.exp, keys, last_resort };
235
235
  }
236
236
 
237
- // The invite handshake's one-time key agreement (relay-plan §3 "Invite handshake"; invite.mjs
237
+ // The invite handshake's one-time key agreement (README.md "How it works", 2; invite.mjs
238
238
  // leaves kem_pk, kem_ct and agree() to this layer). Bob sends kemKey().pk in his answer; Alice
239
239
  // replies with kemEncapsulate(pk).ct; both hold the same 32-byte shared secret for pairKey.
240
240
  // Values travel as unpadded base64url, like prekeys. rng order: keygen seed (32); randomness (64).
package/public.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: MIT
2
- // Public codes, contract sigelo-public/0 (design/public-invite.md): one code a business or an agent
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Public codes, contract sigelo-public/0 (THREAT-MODEL §2.19): one code a business or an agent
3
3
  // service posts for months, each use of it a pairing request. No network here; the carrier parks,
4
4
  // fetches, answers and approves (carrier.mjs invitePublic, accept, approvePublic). Runner:
5
5
  // test-public.mjs; the relay side: relay/park.mjs.
package/qr-decode.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- // Reading QR codes from images (design/devices.md §5.3, §6.4): a PNG reader and a QR decoder, pure
2
+ // Reading QR codes from images (apps/agent/DEVICES.md): a PNG reader and a QR decoder, pure
3
3
  // JavaScript over node:zlib. No I/O: the caller reads the file (sigelo-agent device scan, which also
4
4
  // tries zbarimg first when it is on PATH; this package starts no process).
5
5
  //
package/qr.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: MIT
2
- // QR codes for the device flows (design/devices.md §6): encode text to a module matrix, show it in a
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // QR codes for the device flows (apps/agent/DEVICES.md): encode text to a module matrix, show it in a
3
3
  // terminal with half blocks, write it as a PNG. No I/O and no dependency beyond node:zlib.
4
4
  //
5
5
  // encode(text, { ecc: 'M', minVersion: 1, maxVersion: 40, mask }) → { version, size, ecc, mask, modules }
package/relays.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: MIT
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
2
  // Which relay a 12-character short code was made on: its relay tag
3
3
  // (short.mjs relayTag) resolved to a host. No network here but loadRegistry's one fetch, which the
4
4
  // carrier passes in; nothing in pairing by long code or in verification calls this file.
@@ -25,7 +25,7 @@
25
25
  // signed by relay/site/sign-relays.mjs. Here: SPEC §9 at now, the chain's first DID the pinned one,
26
26
  // one attestation of the identity about itself with that ctx; then every entry whose tag is not
27
27
  // relayTag(host), or whose host is no host[:port], is dropped (counted), never trusted.
28
- // Files: the platform's (design/apps.md §4.2; the carrier passes its own), Node's by default.
28
+ // Files: the platform's (README.md "Platforms"; the carrier passes its own), Node's by default.
29
29
  import { verify } from 'sigelo';
30
30
  import { files as nodeFiles } from './platform-node.mjs';
31
31
  import { checkRelay } from './invite.mjs';
package/restore.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: MIT
2
- // Restore from seed in an app (design/apps-seed.md, pass A9): the operator's files from the 25 words,
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Restore from seed in an app: the operator's files from the 25 words,
3
3
  // exactly as `sigelo-agent keeper --from-words` writes them, and this device as the first FULL device
4
4
  // of a new device list holding the seat (`device seat init`), or as a standby when the human says the
5
5
  // seat is on another device. No network, no storage and no clock here: the page (apps/web/seed.mjs)
package/rtc-web.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: MIT
2
- // The direct path of a transfer in a page (design/transfer.md §10.1): the WebView's own RTCPeerConnection
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // The direct path of a transfer in a page (apps/agent/TRANSFER.md "The phone app"): the WebView's own RTCPeerConnection
3
3
  // behind the interface of apps/transfer/rtc.mjs (werift, Node), so transfer-engine.mjs drives both alike
4
4
  // and a phone talks to a Node agent or another phone over the same `sigelo-transfer/0` channel.
5
5
  //
@@ -59,7 +59,7 @@ export async function peer({ stun = [], turn = null, gatherMs = 3000, RTC = glob
59
59
  const dcP = new Promise((r) => { gotDc = r; });
60
60
  pc.addEventListener('datachannel', (ev) => {
61
61
  const ch = ev.channel;
62
- // Only the channel this attempt named; any other is closed (design §3 "Binding").
62
+ // Only the channel this attempt named; any other is closed (the binding).
63
63
  if (want === null || ch.label !== want || dc) { try { ch.close(); } catch {} return; }
64
64
  dc = ch; gotDc(ch);
65
65
  });
package/short.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: MIT
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
2
  // Short invite codes and the four words of a pairing, contract sigelo-park/0.
3
3
  // No network here; the carrier parks and fetches (carrier.mjs invite, accept). Fixture and runner:
4
4
  // fixtures/short-code-v0.json, gen-short.mjs, test-short.mjs.
@@ -126,7 +126,7 @@ export const codeHash = (text) => bytesToHex(sha256(concatBytes(utf8ToBytes(PARK
126
126
 
127
127
  // Enrolment codes (enrol.mjs issue): a short code like any other, shown with the prefix ENROL-
128
128
  // (ENROL-K7F3-Q9ZP), so an agent given one knows it by its shape and never takes it for a pairing code
129
- // (the agent-setup feedback, points 5 and 7: models fed enrolment codes to accept and lost them). The prefix is
129
+ // (models fed enrolment codes to accept and lost them). The prefix is
130
130
  // shown and read, never hashed or sent: the relay parks and fetches the 8 (or 12) characters as before.
131
131
  // ENROL_TTL_MAX: an enrolment code may live a day (relay/park.mjs ENROL_TTL), an invite's short code an hour.
132
132
  export const ENROL_PREFIX = 'ENROL', ENROL_TTL_MAX = 86400;
package/store.mjs CHANGED
@@ -1,11 +1,11 @@
1
- // SPDX-License-Identifier: MIT
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
2
  // The contact store of sigelo-invite/0: one JSON file per identity. Contacts are keyed by the
3
3
  // peer's ORIGINAL DID with every rotation seen, as accept/node/sigelo-pair.mjs keeps pairings, so
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, short?, short_exp?, renew? } },
6
6
  // accepts: { answer id: { secret, code_did, exp, name, relay, kem_sk, as, named?, tier? } },
7
7
  // contacts: { original DID: { name, did, current_did, current_key, revoked, chain, rotations, relay, pair_key, re_pair?,
8
- // tier, tier_by, operator_exp?, link?, presence? } },
8
+ // tier, tier_by, operator_exp?, link?, presence?, kin? } },
9
9
  // preset?: { original DID: tier },
10
10
  // renew?: { series id: { name, ttl, relay, n, used: [{ short, did, name, at }], due?, claim?, retry?, error? } } }
11
11
  // invites: codes this owner handed out, keyed by inviteNonce(code bytes); peer: the original DID of
@@ -28,10 +28,12 @@
28
28
  // restores them instead of forgetting). Kept by a re-pair, a merge and a rename; gone with revoke. A
29
29
  // link never writes operator_exp, so never ours; while it lasts a contact that is not ours cannot be
30
30
  // set own (link_tier). ended: {id, by, at} on a contact a link's end revoked (revoke(did, ended)), and
31
- // relink: {id, until}, the one-use permit a NEW link leaves on it (design/links.md §7.1a): the pairing
31
+ // relink: {id, until}, the one-use permit a NEW link leaves on it (apps/agent/LINKS.md): the pairing
32
32
  // through that link's code is admitted, the record written afresh. Forgotten by hand: no ended, never.
33
+ // kin: {operator, exp}, a sibling (kin.mjs): its operator proof also carried my operator's attestation
34
+ // and its commitment is mine (carrier.mjs #onOperator, setKin); kinOf reads it until exp. Kept as the tier is.
33
35
  // presence: true when the owner lets this contact see whether this agent is online (setPresence; off
34
- // by default, design/transfer.md §8 T0). An own agent (ours, or tier own) always sees it: presenceOf.
36
+ // by default, THREAT-MODEL §2.17). An own agent (ours, or tier own) always sees it: presenceOf.
35
37
  // Kept by a re-pair, a merge and a rename, as the tier is.
36
38
  // short, short_exp: the short code parked for an invite of mine (carrier.mjs invite) and the relay's
37
39
  // exp of it, so a cancel by the short code finds the invite and the state shows it. renew (an invite's
@@ -63,7 +65,7 @@ export const NAME_MAX = 64;
63
65
  // Renewing codes: seconds a process's claim on a due series holds; the codes used kept per series.
64
66
  export const RENEW_CLAIM = 120, RENEW_USED = 10;
65
67
  // What a record keeps of its tier through admit (a re-pair, a merged notice).
66
- const TIER_KEYS = ['tier', 'tier_by', 'operator_exp', 'link', 'presence'];
68
+ const TIER_KEYS = ['tier', 'tier_by', 'operator_exp', 'link', 'presence', 'kin'];
67
69
  // A recovery key used and replaced still governs every node up to its retirement (SPEC §7.2), and
68
70
  // no offline verifier tells its thief from its owner (THREAT-MODEL §2.5a). A known contact's record
69
71
  // remembers: its chain holds the recovery rotation that retired the key. → commitment → JCS of that
@@ -116,6 +118,17 @@ export class Contacts {
116
118
  /** Ours: marked by an operator attestation of mine (or one of my operators), the tier aside. */
117
119
  oursOf(c, now) { return this.#auto(c, now) === 'own'; }
118
120
 
121
+ /** A sibling's mark (kin.mjs) while its attestation lasts, else null. */
122
+ kinOf(c, now) { return c.kin && c.kin.exp > now ? c.kin : null; }
123
+
124
+ /** File a sibling proven by kin.mjs: {operator, exp}. → true when that is news (another operator or none before). */
125
+ setKin(did, k, now) {
126
+ const c = this.lookup(did) ?? fail('not_contact', `${did} is not a contact`), was = this.kinOf(c, now);
127
+ c.kin = { operator: k.operator, exp: k.exp };
128
+ this.save();
129
+ return was?.operator !== k.operator;
130
+ }
131
+
119
132
  /** original DID → tier, every contact, one read. */
120
133
  tiers(now) {
121
134
  return new Map(Object.values(this.load().s.contacts).map((c) => [c.did, this.tierOf(c, now)]));
@@ -195,8 +208,8 @@ export class Contacts {
195
208
  return { did, tier, preset: true };
196
209
  }
197
210
 
198
- // A new contact's name, unique among the live ones (the agent-setup feedback, point 9: two contacts with one
199
- // name, and send <name> refused both): taken, it gets the first free numeric suffix, name-2, name-3…
211
+ // A new contact's name, unique among the live ones (two contacts with one
212
+ // name made send <name> refuse both): taken, it gets the first free numeric suffix, name-2, name-3…
200
213
  freeName(name, did) {
201
214
  if (typeof name !== 'string') return name;
202
215
  const taken = (n) => Object.values(this.s.contacts).some((x) => !x.revoked && x.did !== did && x.name === n);
@@ -473,7 +486,7 @@ export class Contacts {
473
486
  }
474
487
 
475
488
  /**
476
- * A NEW link with a contact an ended link revoked (design/links.md §7.1a): a one-use permit, until
489
+ * A NEW link with a contact an ended link revoked (apps/agent/LINKS.md): a one-use permit, until
477
490
  * `until`, for the pairing through that link's code (admit). → true; null when `did` is no revoked
478
491
  * contact here (nothing to permit). Forgotten by hand: revoked; the ended link's own id: link_stale.
479
492
  */
@@ -505,7 +518,7 @@ export class Contacts {
505
518
  */
506
519
  admit(bundle, r, name, fields, now) {
507
520
  const held = this.#holders(r.chain), gone = held.find((c) => c.revoked);
508
- // A relink (design/links.md §7.1a): a pairing (named) of a contact an ended link revoked, with a
521
+ // A relink: a pairing (named) of a contact an ended link revoked, with a
509
522
  // live permit; written afresh, its rotations seen kept.
510
523
  const relinking = gone && name !== null && held.length === 1 && gone.relink && gone.relink.until > now ? gone : null;
511
524
  if (gone && !relinking) fail('revoked', `${gone.did} was revoked by this owner`);
package/test-carrier.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: MIT
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
2
  // The carrier (carrier.mjs) against a loopback relay (relay/server.mjs in this process, an injected
3
3
  // clock): two fixture agents pair by code while each is offline in turn, exchange messages, one goes
4
4
  // offline across a week boundary and receives on return, one rotates its key mid-conversation and
@@ -19,7 +19,7 @@
19
19
  // a notice whose chain ends at a key its sender does not hold is refused (notice_sig); a refused
20
20
  // first envelope gives its prekey back; 32 days with no bundle across heal without pairing again;
21
21
  // a carrier with onEvent keeps no plaintext at rest; one code accepted twice; an epoch outlives its
22
- // lost first envelope and a reader away longer than retention (relay-plan §11 "Epoch recovery"); an
22
+ // lost first envelope and a reader away longer than retention (epoch recovery, README.md "How it works"); an
23
23
  // envelope longer than a relay takes in one packet is refused before it is queued; through a network
24
24
  // that delivers packet by packet, each refusal read against its own publish, and a notice naming
25
25
  // another packet id against none; an epoch begun on a key already spent (prekey_reused) heals,
@@ -46,7 +46,7 @@ import { PassThrough } from 'node:stream';
46
46
  import { fileURLToPath, pathToFileURL } from 'node:url';
47
47
  import { xchacha20poly1305 } from '@noble/ciphers/chacha.js';
48
48
  import { connect } from 'mqtt';
49
- import { canonicalize, keygen, rotate, sign, verify, verifySig } from 'sigelo';
49
+ import { canonicalize, did, keygen, rotate, sign, verify, verifySig } from 'sigelo';
50
50
  import { Carrier, INVITE_BYTES, KIND_PREKEYS, LABEL_PREKEYS, MAX_PACKET, MAX_ROTATIONS, NOTICE_CHECKS, POW_COST, POW_MAX, POW_MAX_OTHER, POW_SEARCHES, SEEN_LABEL, BUSY_LABEL, BUSY_TTL_S, TYP_NOTICE, V as CARRIER_V, limitPackets, noticeKey, pathsFor, powCost, prekeysKey, retentionOf, seal, solvePow, unseal } from './carrier.mjs';
51
51
  import { MAX_ENVELOPE, header, pad } from './envelope.mjs';
52
52
  import { V as STORE_V, answerId, buildAnswer, checkAnswer, checkReply, inviteKeys, makeInvite, parseInvite } from './invite.mjs';
@@ -113,7 +113,7 @@ const report = () => {
113
113
  const pending = () => bs.addAccept(code, answerId(answer), 'alice', F.t0 + 5, hexOf(kemKey(fixtureRng('kem key')).secretKey));
114
114
  pending();
115
115
  // Swapped by a code holder on the path for an encapsulation of its own to the same key: the
116
- // reply's transcript, under alice's signature, covers kem_ct (relay-plan §11).
116
+ // reply's transcript, under alice's signature, covers kem_ct.
117
117
  const swapped = { ...reply, kem_ct: kemEncapsulate(answer.kem_pk, fixtureRng('mallory')).ct };
118
118
  ok(checkOf(() => checkReply(swapped, bs, F.t0 + 30, (c, sk) => kemDecapsulate(c, unhex(sk)))) === 'transcript', 'a reply whose kem_ct was swapped on the way fails transcript');
119
119
  pending();
@@ -137,7 +137,7 @@ const until = async (cond, ms = 8000) => { const end = Date.now() + ms; while (D
137
137
  const refuses = async (f, check, what) => {
138
138
  try { await f(); ok(false, `${what}: accepted, expected ${check}`); } catch (e) { ok(e.check === check, `${what}: ${e.check ?? 'exception'} (${e.message}), expected ${check}`); }
139
139
  };
140
- // A phone-class machine needs about 300 s for the whole run; the deadline catches a hang, not a slow device.
140
+ // A low-end ARM64 machine needs about 300 s for the whole run; the deadline catches a hang, not a slow device.
141
141
  setTimeout(() => { console.log(`FAIL the run did not finish in 600 s (${count} checks so far)`); process.exit(1); }, 600000).unref();
142
142
 
143
143
  const HOST = 'relay.test', DAY = 86400, CREATED = '2026-10-01T00:00:00Z';
@@ -544,7 +544,7 @@ try {
544
544
  ok(await until(() => powErrors() === 3, 30000), '24 hours later, una searches again, and stops again');
545
545
  await sleep(1500);
546
546
  ok(searches === 2 * POW_SEARCHES, `${searches} searches in all, ${POW_SEARCHES} in each 24 hours`);
547
- // design/profiles.md §6: the cap is the automatic retries'. Its refusal names the next automatic try;
547
+ // The cap is the automatic retries'. Its refusal names the next automatic try;
548
548
  // one the human starts (Try now) is never refused: past the cap it asks (pow_confirm), then goes.
549
549
  const cap = seen('una', (e) => e.type === 'error' && e.check === 'pow').at(-1);
550
550
  ok(Number.isSafeInteger(cap?.next) && cap.next > uNow && cap.detail.includes(`Next automatic try at ${new Date(cap.next * 1000).toISOString().slice(11, 16)} UTC`),
@@ -632,7 +632,7 @@ try {
632
632
  const inv = await alice.invite({ name: 'bob' });
633
633
  ok(inv.code.startsWith('sgl1') && inv.relay === HOST && inv.did === A.did, 'invite: a code for alice\'s current DID at the relay');
634
634
  ok(alice.contacts().invites.length === 1, 'the invite is pending in alice\'s store');
635
- ok(stateOf(A).relays[HOST].proven === true, 'the first login carried a proof of work (relay-plan §3), remembered for this relay');
635
+ ok(stateOf(A).relays[HOST].proven === true, 'the first login carried a proof of work, remembered for this relay');
636
636
  const acc = await bob.accept(inv.code, { name: 'alice', wait: 0.3 });
637
637
  ok(acc.status === 'waiting', `accept while alice is offline: the answer reaches the relay, the pairing waits (${acc.status})`);
638
638
  ok(bob.contacts().answers.length === 1, 'bob\'s answer is pending in his store');
@@ -730,6 +730,27 @@ try {
730
730
  ok(box.messages.map((m) => m.content).join('|') === [0, 1, 2, 3, 4].map((i) => `one-shot ${i}`).join('|'), 'bob receives the five, in order');
731
731
  ok(box.messages.every((m) => m.from === A.original && m.name === 'alice' && m.current_did === A.did && m.label === ''), 'each from alice\'s original DID, signed by her current key');
732
732
  ok(box.messages.every((m) => m.last_resort === false), 'each in an epoch begun on a one-time prekey (last_resort false)');
733
+ {
734
+ // The signed envelope beside the plaintext (carrier.mjs signedOf; WATCH.md "Re-verifying a spooled message").
735
+ const m = box.messages[0], g = m.signed;
736
+ ok(m.verified === true && g && JSON.stringify(Object.keys(g)) === JSON.stringify(['body', 'sig', 'epoch', 'n', 'key'])
737
+ && JSON.stringify(Object.keys(g.body).sort()) === JSON.stringify(['content', 'epoch', 'from', 'iat', 'label', 'n', 'pair', 'to', 'typ', 'v']),
738
+ 'each message carries signed {body, sig, epoch, n, key} (the body sigelo-msg/0 as opened) and verified: true', JSON.stringify(m));
739
+ ok(g.body.v === 'sigelo-msg/0' && g.body.typ === 'message' && g.body.from === m.current_did && g.body.to === B.original && g.body.content === m.content
740
+ && g.body.label === m.label && g.body.iat === m.iat && g.body.epoch === g.epoch && g.body.n === g.n && g.key === A.bundle.genesis.key,
741
+ 'the body agrees with the plaintext fields, names bob as to, and the key is alice\'s current one');
742
+ // Offline, with only the public library and alice's bundle: §9 gives her current DID, its genesis the key.
743
+ const r = verify(A.bundle, now), key = [A.bundle.genesis, ...A.bundle.rotations.map((x) => x.next_genesis)].find((x) => did(x) === r.did)?.key;
744
+ ok(r.did === g.body.from && key === g.key && verifySig(key, g.body, g.sig), 're-verified away from the carrier: verify(alice\'s bundle) names body.from, and the sig verifies under its key');
745
+ ok(!verifySig(key, { ...g.body, content: 'forged' }, g.sig) && !verifySig(key, { ...g.body, to: A.original }, g.sig), 'a changed content or to does not verify');
746
+ // At rest the signed body leaves its content out (the item's own): the log's caps hold as many messages; history gives it whole.
747
+ {
748
+ const line = bob.logPath === null ? undefined : readFileSync(bob.logPath, 'utf8').split('\n').filter((l) => l !== '').map((l) => JSON.parse(l)).find((x) => x.id === m.id);
749
+ const h = bob.history().messages.find((x) => x.id === m.id);
750
+ ok(line && line.signed && !('content' in line.signed.body) && !JSON.stringify(line.signed).includes('one-shot 0') && line.content === m.content && h?.signed.body.content === m.content && verifySig(key, h.signed.body, h.signed.sig),
751
+ 'the log keeps the signed body without its content (no second copy); history puts it back, and it verifies', JSON.stringify(line));
752
+ }
753
+ }
733
754
  ok((await bob.inbox()).messages.length === 0, 'the inbox is taken once');
734
755
  {
735
756
  // Receiving keys have a time, saved with the session (envelope.mjs expire): with the free
@@ -1186,7 +1207,7 @@ try {
1186
1207
  const id = await import(pathToFileURL(join(HERE, '..', 'agent', 'sigelo-agent.ts')).href);
1187
1208
  const env = { SIGELO_RELAY: HOST, SIGELO_RELAY_ENDPOINTS: JSON.stringify(endpoints) };
1188
1209
  const tools = await mcp.load({ installed: false, id, env, clock: () => now });
1189
- ok(tools && tools.tools.map(([n]) => n).join() === 'sigelo_invite,sigelo_accept,sigelo_contacts,sigelo_set_tier,sigelo_presence,sigelo_send,sigelo_send_file,sigelo_inbox,sigelo_forget_contact,sigelo_links,sigelo_group,sigelo_transfer,sigelo_wait_for_message,sigelo_reply,sigelo_enrol,sigelo_enrol_finish,sigelo_public,sigelo_history', 'the MCP module lists the eighteen tools');
1210
+ ok(tools && tools.tools.map(([n]) => n).join() === 'sigelo_invite,sigelo_accept,sigelo_contacts,sigelo_kin,sigelo_set_tier,sigelo_presence,sigelo_send,sigelo_send_file,sigelo_inbox,sigelo_forget_contact,sigelo_links,sigelo_group,sigelo_transfer,sigelo_wait_for_message,sigelo_reply,sigelo_enrol,sigelo_enrol_finish,sigelo_public,sigelo_history', 'the MCP module lists the nineteen tools');
1190
1211
  ok(tools.tools.every(([, d, s]) => typeof d === 'string' && s.type === 'object' && s.additionalProperties === false && s.properties.identity), 'each with a closed schema and the profile argument');
1191
1212
  const daveFile = join(dir, 'dave.local.json');
1192
1213
  id.init(daveFile, keygen({ seed: seed('dave recovery'), recovery: 'sha256:' + '0'.repeat(64) }).key);
@@ -1326,7 +1347,7 @@ try {
1326
1347
  // ================================================================ notices from whoever holds K
1327
1348
  {
1328
1349
  // Audit finding: a notice refused after its chain was verified was verified again at every
1329
- // delivery, and again in store.admit: 0.27 s a 64-rotation chain on a phone-class CPU, from
1350
+ // delivery, and again in store.admit: 0.27 s a 64-rotation chain on a low-end ARM64 CPU, from
1330
1351
  // anyone holding K (the contact, a thief of either side's state). Now one refused after that
1331
1352
  // check is refused again unchecked, and at most NOTICE_CHECKS notices of a contact's are
1332
1353
  // checked an hour, unless one brings its owner's recovery. Its own relay and clock.
@@ -1397,7 +1418,7 @@ try {
1397
1418
  const contents = (box) => box.messages.map((m) => m.content).join();
1398
1419
  const carrying = () => stateOf(Q).peers[Rh.original].session.out.epoch.carry;
1399
1420
  // A relay that acknowledges an epoch's first envelope and throws it away: the next carries the
1400
- // epoch's encapsulation too (relay-plan §11 "Epoch recovery"), so rhea opens it.
1421
+ // epoch's encapsulation too (epoch recovery), so rhea opens it.
1401
1422
  editState(Q, (x) => { x.peers[Rh.original].session.out.epoch = null; });
1402
1423
  ok((await quill.send('rhea', 'withheld')).status === 'sent', 'a message beginning an epoch: acknowledged by the relay');
1403
1424
  relay3.db.raw.prepare('DELETE FROM messages WHERE account = ?').run(accountOf(Rh.original));
@@ -1834,7 +1855,7 @@ try {
1834
1855
  await relay12.close();
1835
1856
  }
1836
1857
 
1837
- // ================================================================ the 0.1.3 live re-test (2026-10-14)
1858
+ // ================================================================ the 0.1.3 live re-test
1838
1859
  {
1839
1860
  // Its own relay and clock. connect.html's order: ines invites, jon accepts while she is offline
1840
1861
  // (waiting), ines runs inbox (paired), then send. Jon's mailbox for the pairing needs K, which
package/test-device.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: MIT
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
2
  // Devices (device.mjs, contract sigelo-device/1) and the QR plumbing under them (qr.mjs, qr-decode.mjs):
3
3
  // base45 against RFC 9285's examples, the words, argon2id native against @noble/hashes, the
4
4
  // container byte for byte against fixtures/device-v1.json (gen-device.mjs), frames in any order,
@@ -338,7 +338,7 @@ for (const v of fx.base45_rfc9285) {
338
338
  ok(UNLOGGED.test('sigelo-device/1') && UNLOGGED.test('sigelo-identity/0') && UNLOGGED.test('sigelo-enrol/1') && !UNLOGGED.test('sigelo-file/0') && !UNLOGGED.test('') && !UNLOGGED.test('x-sigelo-device/1'),
339
339
  'UNLOGGED: sigelo-device/, sigelo-identity/, sigelo-enrol/ (never in inbox.log); sigelo-file/0 and plain messages logged');
340
340
 
341
- // ---- remote control over the relay (control.mjs, design/apps.md §6.3): the text, the messages, the identity, the cap
341
+ // ---- remote control over the relay (control.mjs, apps/agent/UI-API.md "Remote"): the text, the messages, the identity, the cap
342
342
  {
343
343
  const t = C.controlText('k7f3q9zp'), h = C.controlText('K7F3-Q9ZP-4WXN', 'relay.test:1883');
344
344
  ok(t === 'SIGELO:CTL:K7F3-Q9ZP' && h === 'SIGELO:CTL:K7F3-Q9ZP-4WXN:RELAY.TEST:1883' && h.length <= 60, 'control text: SIGELO:CTL:<short code>[:<HOST>], ≤ 60 characters');
@@ -360,7 +360,7 @@ ok(UNLOGGED.test('sigelo-device/1') && UNLOGGED.test('sigelo-identity/0') && UNL
360
360
  ok(first.filter(Boolean).length === C.BURST && first.slice(0, 10).every(Boolean) && [b.take(), b.take(), b.take(), b.take()].filter(Boolean).length === 3 * C.RATE, 'the cap: a burst of 10, then one a second');
361
361
  }
362
362
 
363
- // ---- restore from seed in the apps (restore.mjs, design/apps-seed.md): the files keeper --from-words writes, the seat
363
+ // ---- restore from seed in the apps (restore.mjs): the files keeper --from-words writes, the seat
364
364
  {
365
365
  const S0 = new Uint8Array(32).fill(7); S0[31] = 0x0f; // a canonical root (< l), fixed
366
366
  const words = mnemonicFromRoot(S0), list = words.split(' '), now = 1761400000;
package/test-enrol.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: MIT
1
+ // SPDX-License-Identifier: AGPL-3.0-only
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
4
  // with the relay checkout beside apps/contact/ (SIGELO_RELAY_DIR, else ../../relay), the flow on a loopback
@@ -143,7 +143,12 @@ 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
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 } } }) });
146
+ // The subscribe brake ten times over (RATE.subscribe: 20 a second, 256 at once): the owner here makes ~20
147
+ // invites and reconnects, ~1,400 SUBSCRIBEs in a few minutes, each connection asking every open invite
148
+ // topic again. On a phone that left ~0 tokens; on a faster CI runner the brake refused an invite's own
149
+ // topic ("rate", run 46774361909). The brake itself is tested in relay/test/allowance.mjs and test-carrier.mjs.
150
+ log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits: 4, loadBits: 8, loadPerHour: 1000, cost: { m: 8, t: 1, p: 1 } },
151
+ rate: { subscribe: { perSecond: 200, burst: 2560 }, network: { subscribe: { perSecond: 2000, burst: 20000 } } } }) });
147
152
  const endpoints = { [HOST]: { mqtt: `mqtt://127.0.0.1:${relay.ports.tcp}`, http: `http://127.0.0.1:${relay.ports.http}` } };
148
153
  // An agent in memory: its identity file's content (sigelo-agent's Store) and a carrier on it.
149
154
  function agent(label, store) {
@@ -365,7 +370,7 @@ try {
365
370
  && 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
371
  `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
372
  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
373
+ // The enrolment boundary (THREAT-MODEL §2.11a): an enrolment code is
369
374
  // ENROL-…, parked as one, refused by accept unspent, fetched again until the grant, and a machine joining
370
375
  // strictly takes only it; a grant for another code than the one answered is refused.
371
376
  {
@@ -406,7 +411,7 @@ try {
406
411
  ok(replay.check === 'enrol_replay' && right.check === 'accepted', `a grant naming another code: enrol_replay; for this code: taken (${replay.message})`);
407
412
  for (const a of [st, t1]) await a.carrier.stop();
408
413
  }
409
- // the agent-setup feedback, point 9: two contacts never share a name (send <name> refused both): the second gets -2.
414
+ // Two contacts never share a name (send <name> refused both): the second gets -2.
410
415
  {
411
416
  const t1 = await co.invite({ name: 'twin' }), t2 = await co.invite({ name: 'twin' }), ta = agent('twin-a'), tb = agent('twin-b');
412
417
  await co.start();
package/test-envelope.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: MIT
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
2
  // sigelo-msg/0 envelopes, prekeys and key schedule, against fixtures/envelope-v0.json and in code.
3
3
  // node apps/contact/test-envelope.mjs → ALL PASS (n)
4
4
  import { readFileSync } from 'node:fs';
@@ -448,7 +448,7 @@ const reply = (from, to, now) => { const m = send(from, { label: '', content: 'r
448
448
  }
449
449
 
450
450
  {
451
- // Epoch recovery (relay-plan §11): an epoch whose first envelope never reached the contact. Its
451
+ // Epoch recovery (README.md "How it works", 4): an epoch whose first envelope never reached the contact. Its
452
452
  // second carries the encapsulation too and begins the epoch there; the first, arriving after
453
453
  // all, opens from the key kept behind. A bundle the contact issued before opening it still lists
454
454
  // its key: while the encapsulation is carried, the epoch goes on.
package/test-file.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: MIT
2
- // File transfer (file.mjs, carrier.sendFile and its receive path; design/human-ui-plan.md §4):
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // File transfer (file.mjs, carrier.sendFile and its receive path):
3
3
  // the pure part (byte-exact round trips from fixed seeds, a tampered chunk, oversize, names); then,
4
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