sigelo-contact 0.1.13 → 0.1.20

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 (51) hide show
  1. package/README.md +13 -10
  2. package/call.mjs +727 -0
  3. package/carrier.mjs +1204 -137
  4. package/control.mjs +81 -22
  5. package/device.mjs +1 -1
  6. package/enrol.mjs +239 -43
  7. package/gen-carrier.mjs +4 -4
  8. package/gen-device.mjs +2 -2
  9. package/gen-envelope.mjs +3 -3
  10. package/gen-invite.mjs +3 -3
  11. package/gen-short.mjs +3 -3
  12. package/group.mjs +616 -0
  13. package/invite.mjs +63 -13
  14. package/kdf.mjs +1 -1
  15. package/link.mjs +24 -16
  16. package/package.json +49 -7
  17. package/page.mjs +1172 -70
  18. package/photo.mjs +37 -0
  19. package/platform-node.mjs +125 -18
  20. package/prekeys.mjs +10 -2
  21. package/public.mjs +93 -0
  22. package/relays.mjs +1 -1
  23. package/restore.mjs +3 -3
  24. package/rtc-web.mjs +95 -0
  25. package/short.mjs +31 -3
  26. package/store.mjs +147 -12
  27. package/test-carrier.mjs +138 -21
  28. package/test-device.mjs +1 -1
  29. package/test-enrol.mjs +157 -8
  30. package/test-envelope.mjs +16 -3
  31. package/test-file.mjs +5 -5
  32. package/test-group.mjs +413 -0
  33. package/test-invite.mjs +15 -2
  34. package/test-link.mjs +11 -8
  35. package/test-platform.mjs +5 -5
  36. package/test-presence.mjs +169 -0
  37. package/test-push.mjs +136 -0
  38. package/test-relay-lane.mjs +248 -0
  39. package/test-short.mjs +38 -12
  40. package/test-tier.mjs +6 -6
  41. package/test-transfer-web.mjs +246 -0
  42. package/test-transfer.mjs +463 -0
  43. package/test-voice.mjs +158 -0
  44. package/test-ws.mjs +5 -5
  45. package/transfer-engine.mjs +800 -0
  46. package/transfer-node.mjs +449 -0
  47. package/transfer-web.mjs +80 -0
  48. package/transfer.mjs +388 -0
  49. package/voice-web.mjs +113 -0
  50. package/voice.mjs +65 -0
  51. package/words-lock.mjs +115 -0
package/invite.mjs CHANGED
@@ -22,6 +22,9 @@ export const V = 'sigelo-invite/0';
22
22
  export const TYP_ANSWER = 'invite-answer', TYP_REPLY = 'invite-reply';
23
23
  // SKEW: how far the answering side's clock may lag the inviter's when it checks the 7-day cap.
24
24
  export const TTL = 86400, TTL_MAX = 7 * 86400, SKEW = 300, PREFIX = 'sgl1', VERSION = 0x01;
25
+ // A public code (contract sigelo-public/0, public.mjs): version 2, sgl2…, the same layout, living up
26
+ // to PUBLIC_TTL_MAX; its answers carry iat and are taken up to REQUEST_TTL old.
27
+ export const PUBLIC_VERSION = 0x02, PUBLIC_PREFIX = 'sgl2', PUBLIC_TTL_MAX = 366 * 86400, REQUEST_TTL = 7 * 86400;
25
28
  // HKDF-SHA256 and hash labels, part of the wire contract. The three from the one-time secret use
26
29
  // no salt (the secret is 32 random bytes) and one info label each:
27
30
  export const LABELS = {
@@ -35,7 +38,7 @@ export const LABELS = {
35
38
  pair_salt: 'sigelo-pair/0', // salt of the pairing key K
36
39
  };
37
40
 
38
- // Every refusal names its check (.check), as contact/kdf.mjs's MsgError: one error class for
41
+ // Every refusal names its check (.check), as apps/contact/kdf.mjs's MsgError: one error class for
39
42
  // the whole package, invite, envelope, prekeys and carrier alike.
40
43
  export const fail = (check, why) => { throw new MsgError(check, why); };
41
44
  export const attempt = (check, f) => { try { return f(); } catch (e) { return fail(check, e.message); } };
@@ -109,28 +112,38 @@ export function inviteKeys(secret) {
109
112
  return { answer_topic: 'i/' + hex(d(LABELS.answer_topic, 16)), reply_topic: 'i/' + hex(d(LABELS.reply_topic, 16)), key: d(LABELS.key, 32) };
110
113
  }
111
114
 
112
- /** Alice: a new code for her CURRENT DID. `secret` and `now` are parameters so a fixture fixes every byte. */
113
- export function makeInvite({ did, relay, now, ttl = TTL, secret = new Uint8Array(randomBytes(32)) }) {
115
+ /** Alice: a new code for her CURRENT DID. `secret` and `now` are parameters so a fixture fixes every byte.
116
+ * version 2: a public code (sgl2…, public.mjs), ttl up to PUBLIC_TTL_MAX. */
117
+ export function makeInvite({ did, relay, now, ttl = TTL, secret = new Uint8Array(randomBytes(32)), version = VERSION }) {
114
118
  const digest = didDigest(did);
115
119
  if (!(secret instanceof Uint8Array) || secret.length !== 32) fail('secret', 'must be 32 bytes');
116
120
  checkTime(now);
117
- if (!Number.isSafeInteger(ttl) || ttl < 1 || ttl > TTL_MAX) fail('ttl', `must be 1 to ${TTL_MAX} seconds`);
121
+ if (version !== VERSION && version !== PUBLIC_VERSION) fail('code_version', `version ${version}: 1, or 2 for a public code`);
122
+ const max = version === PUBLIC_VERSION ? PUBLIC_TTL_MAX : TTL_MAX;
123
+ if (!Number.isSafeInteger(ttl) || ttl < 1 || ttl > max) fail('ttl', `must be 1 to ${max} seconds`);
118
124
  const exp = now + ttl;
119
125
  if (exp > 0xffffffff) fail('ttl', 'the expiry does not fit 4 bytes');
120
126
  checkRelay(relay);
121
127
  const host = utf8ToBytes(relay), e = new Uint8Array(4);
122
128
  new DataView(e.buffer).setUint32(0, exp);
123
- const body = concatBytes(Uint8Array.of(VERSION), digest, secret, e, Uint8Array.of(host.length), host);
129
+ const body = concatBytes(Uint8Array.of(version), digest, secret, e, Uint8Array.of(host.length), host);
124
130
  const bytes = concatBytes(body, sha256(body).subarray(0, 4));
125
- return { did: 'did:sigelo:' + multibase(digest), secret, exp, relay, bytes, text: PREFIX + multibase(bytes).slice(1), nonce: inviteNonce(bytes) };
131
+ return { did: 'did:sigelo:' + multibase(digest), secret, exp, relay, bytes, text: `sgl${version}` + multibase(bytes).slice(1), nonce: inviteNonce(bytes), version };
126
132
  }
127
133
 
128
134
  /** Bob: the code back from its text. Throws code_version, code_checksum, code_length, code_relay, code_expired or code_ttl. */
129
- export function parseInvite(text, now) {
135
+ export function parseInvite(text, now) { return parseCode(text, now, VERSION); }
136
+ /** A public code (sgl2…) back from its text, as parseInvite; it lives up to PUBLIC_TTL_MAX. */
137
+ export function parsePublicCode(text, now) { return parseCode(text, now, PUBLIC_VERSION); }
138
+
139
+ function parseCode(text, now, version) {
130
140
  checkTime(now);
141
+ const PREFIX = `sgl${version}`, VERSION = version, TTL_MAX = version === PUBLIC_VERSION ? PUBLIC_TTL_MAX : 7 * 86400;
131
142
  // Only another version's prefix is a version error. Any other start ("sgI1", "Sgl1", a lost
132
143
  // first character) is a typo, and reads as one, like a typo among the digits.
133
- if (typeof text === 'string' && /^sgl[02-9]/.test(text)) fail('code_version', `a ${text.slice(0, 4)} code; this library reads ${PREFIX}`);
144
+ if (typeof text === 'string' && /^sgl[0-9]/.test(text) && !text.startsWith(PREFIX)) {
145
+ fail('code_version', `a ${text.slice(0, 4)} code; this ${version === PUBLIC_VERSION ? 'reads public codes' : 'library reads'} ${PREFIX}${text.startsWith(PUBLIC_PREFIX) ? ' (sgl2 is a public code: read it with parsePublicCode)' : ''}`);
146
+ }
134
147
  if (typeof text !== 'string' || !text.startsWith(PREFIX)) fail('code_checksum', `it does not start with ${PREFIX}: paste the whole code, from ${PREFIX} to its last character`);
135
148
  const digits = text.slice(PREFIX.length);
136
149
  if (digits.length === 0 || digits.length > MAX_DIGITS) fail('code_length', `${digits.length} characters after ${PREFIX}, ${digits.length === 0 ? 'none' : `at most ${MAX_DIGITS}`}: not the whole code, or two codes run together`);
@@ -154,9 +167,9 @@ export function parseInvite(text, now) {
154
167
  if (now >= exp) fail('code_expired', `it expired at ${iso(exp)}, ${ago(now - exp)} ago by this machine's clock (${iso(now)}): ask for a new code; if it was made just now, this clock is wrong (date -u)`);
155
168
  // No inviter makes a code for longer than 7 days. A longer one would keep Bob's one-time secret
156
169
  // and key in his store for as long as it says.
157
- if (exp - now > TTL_MAX + SKEW) fail('code_ttl', `it expires at ${iso(exp)}, ${ago(exp - now)} from now by this machine's clock (${iso(now)}), and a code lives at most 7 days: this clock is behind (date -u), or the code was not made by sigelo`);
170
+ if (exp - now > TTL_MAX + SKEW) fail('code_ttl', `it expires at ${iso(exp)}, ${ago(exp - now)} from now by this machine's clock (${iso(now)}), and a code lives at most ${version === PUBLIC_VERSION ? 'a year' : '7 days'}: this clock is behind (date -u), or the code was not made by sigelo`);
158
171
  const secret = b.slice(AT_SECRET, AT_EXP);
159
- return { did: 'did:sigelo:' + multibase(b.slice(AT_DID, AT_SECRET)), secret, exp, relay, bytes: b, text, nonce: inviteNonce(b) };
172
+ return { did: 'did:sigelo:' + multibase(b.slice(AT_DID, AT_SECRET)), secret, exp, relay, bytes: b, text, nonce: inviteNonce(b), version };
160
173
  }
161
174
 
162
175
  // ---------------------------------------------------------------- handshake messages
@@ -191,10 +204,13 @@ function prove(identity, typ, nonce, label, rest) {
191
204
  * His proof binds the whole code (its nonce: the inviter it names, relay, expiry, secret) and every
192
205
  * other member of the answer (transcript).
193
206
  */
194
- export function buildAnswer({ code, identity, bundle, kem_pk, prekeys }) {
207
+ export function buildAnswer({ code, identity, bundle, kem_pk, prekeys, iat }) {
195
208
  opaque(kem_pk, 'kem_pk'); opaque(prekeys, 'prekeys'); canonicalBundle(bundle);
196
209
  if (!(code?.bytes instanceof Uint8Array)) throw new TypeError('code is required: what parseInvite returned');
197
- const rest = { v: V, typ: 'answer', bundle, kem_pk, prekeys };
210
+ // A public code's answer carries iat, in its transcript (sigelo-public/0): the inviter takes it
211
+ // up to REQUEST_TTL old, so no answer replays past the joiner's reply topic.
212
+ if (code.version === PUBLIC_VERSION) checkTime(iat);
213
+ const rest = { v: V, typ: 'answer', bundle, kem_pk, prekeys, ...(code.version === PUBLIC_VERSION && { iat }) };
198
214
  return { ...rest, proof: prove(identity, TYP_ANSWER, inviteNonce(code.bytes), LABELS.answer, rest) };
199
215
  }
200
216
 
@@ -242,7 +258,7 @@ function checkProof(m, want, label, r) {
242
258
 
243
259
  // The key agreement runs only once the peer's identity is proven. agree(value, kem_sk) returns
244
260
  // the 32-byte shared secret, from M2: Alice encapsulates to kem_pk; Bob decapsulates kem_ct with
245
- // the kem_sk he gave addAccept. K itself is contact/kdf.mjs's pairKey; the fixture pins its bytes.
261
+ // the kem_sk he gave addAccept. K itself is apps/contact/kdf.mjs's pairKey; the fixture pins its bytes.
246
262
  function agreed(agree, value, secret, store, r, kem_sk) {
247
263
  if (r.chain.includes(store.self)) fail('self', 'the peer is this store\'s own identity');
248
264
  let shared;
@@ -281,6 +297,40 @@ export function checkAnswer(answer, store, now, agree) {
281
297
  return { ...a, pair_key, secret: p.secret, answer_id: answerId(answer) };
282
298
  }
283
299
 
300
+ /**
301
+ * Alice, a public code's answer (sigelo-public/0): every check of checkAnswer before the key
302
+ * agreement, with iat (REQUEST_TTL old at most, SKEW ahead) instead of a pending invite taken: the
303
+ * code `p` ({ nonce, exp }) stays. Nothing is stored. → { did: the original DID, current_did, r,
304
+ * answer_id }. Throws card, challenge_unknown, challenge_expired, bundle, card_did, challenge_body,
305
+ * transcript, sig, self, revoked.
306
+ */
307
+ export function screenAnswer(answer, p, store, now) {
308
+ checkTime(now);
309
+ shape(answer, 'answer', ['v', 'typ', 'bundle', 'proof', 'kem_pk', 'prekeys', 'iat']);
310
+ if (answer.proof.body.nonce !== p.nonce) fail('challenge_unknown', 'the answer names another code');
311
+ if (now >= p.exp) fail('challenge_expired', `the code expired at ${p.exp}`);
312
+ if (!Number.isSafeInteger(answer.iat) || answer.iat < now - REQUEST_TTL || answer.iat > now + SKEW) fail('challenge_expired', `iat ${answer.iat}: an answer is taken up to 7 days old`);
313
+ const r = attempt('bundle', () => verify(answer.bundle, now));
314
+ if (r.did !== answer.proof.body.did) fail('card_did', `the bundle resolves to ${r.did}, the proof claims ${answer.proof.body.did}`);
315
+ checkProof(answer, { v: V, typ: TYP_ANSWER, did: r.did, nonce: p.nonce }, LABELS.answer, r);
316
+ if (r.chain.includes(store.self)) fail('self', 'the peer is this store\'s own identity');
317
+ const held = Object.values(store.load().s.contacts).find((c) => c.chain.some((d) => r.chain.includes(d)));
318
+ if (held?.revoked) fail('revoked', `${held.did} was revoked by this owner`);
319
+ return { did: r.chain[0], current_did: r.did, r, answer_id: answerId(answer) };
320
+ }
321
+
322
+ /**
323
+ * Alice approves a public code's answer: screened again (a rotation or a revocation since), then
324
+ * the key agreement and admit, as checkAnswer. p: { nonce, exp, secret (hex), name, relay };
325
+ * fields: more for the contact record (via). → checkAnswer's result.
326
+ */
327
+ export function admitAnswer(answer, p, store, now, agree, fields = {}) {
328
+ const { r } = screenAnswer(answer, p, store, now);
329
+ const pair_key = agreed(agree, answer.kem_pk, p.secret, store, r);
330
+ const a = store.admit(answer.bundle, r, p.name, { relay: p.relay, pair_key, ...fields }, now);
331
+ return { ...a, pair_key, secret: p.secret, answer_id: answerId(answer) };
332
+ }
333
+
284
334
  /**
285
335
  * Bob: check Alice's reply and store her under her ORIGINAL DID. The same order; code_did stands
286
336
  * where sigelo-pair has challenge_did: Bob accepts only if the code's DID is in Alice's chain.
package/kdf.mjs CHANGED
@@ -9,7 +9,7 @@ import { sign } from 'sigelo';
9
9
 
10
10
  export const MSG_V = 'sigelo-msg/0';
11
11
 
12
- // Every refusal in contact/ names its check, as accept/node/sigelo-pair.mjs's PairingError does:
12
+ // Every refusal in apps/contact/ names its check, as accept/node/sigelo-pair.mjs's PairingError does:
13
13
  // one class for invite, envelope, prekeys and carrier, so a caller catches MsgError and reads .check.
14
14
  // extra, for whoever debugs (SIGELO_DEBUG=1 prints it): cause, the error underneath; http, the
15
15
  // relay's answer ({ url, status, body }).
package/link.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Links, contract sigelo-link/1: the operator introduces two of its own agents, or one of its agents
3
- // to an external contact X (adapters/moadim/LINKS.md, THREAT-MODEL §2.16). The operator asks agent A
3
+ // to an external contact X (apps/agent/LINKS.md, THREAT-MODEL §2.16). The operator asks agent A
4
4
  // for a one-use long code (never parked,
5
5
  // never printed), checks the code names A, and offers it to agent B with the purpose; B accepts
6
6
  // because the offer comes from its operator and the code names the A it was told of; A checks that
@@ -16,8 +16,9 @@
16
16
  // (answer: accept, or refuse, silent unless tell) or the code lapses (≤ 7 days); an allow rule for
17
17
  // that contact accepts it at the rule's tier (default quiet, never own). Purpose and note are data.
18
18
  //
19
- // operator: link({ carrier, file, a, b, purpose, tierA, tierB, days, ttl, note, relay }) → the
20
- // record, pending; the ask is sent to A
19
+ // operator: link({ carrier, file, a, b, purpose, tierA, tierB, days, ttl, note, relay, nameA, nameB }) →
20
+ // the record, pending; the ask is sent to A. nameB: what A files B as (peer_name in the ask),
21
+ // nameA: what B files A as (peer_name in the offer); without them, the operator's names (name)
21
22
  // X: answer({ carrier, file, id, accept, tell, tier }) → { id, status }: an introduction
22
23
  // accepted or refused (carried out at the next handle, which needs the session; a
23
24
  // silent refusal at once); allow({ carrier, file, contact, tier, days }) / deny({ …,
@@ -36,10 +37,13 @@
36
37
  //
37
38
  // The messages: label LINK_LABEL on sigelo-msg/0, content {v, typ, id, iat, …}, id 8 characters of
38
39
  // short.mjs's alphabet:
39
- // ask operator → A {peer: B's original DID, name, kind: own|external, tier?, purpose, expires?, ttl, relay?}
40
+ // ask operator → A {peer: B's original DID, name, peer_name?, kind: own|external, tier?, purpose, expires?, ttl, relay?}
40
41
  // invite A → operator {code} (a long code, A's own), or {paired: true} (A and B were paired)
41
42
  // offer operator → B {from: A's original DID, did: the DID the code names, code | paired, name,
42
- // purpose, expires?, tier? (own only), note?, ttl}
43
+ // peer_name?, purpose, expires?, tier? (own only), note?, ttl}
44
+ // name is the operator's own name for the peer; peer_name, when present, the name the operator chose
45
+ // for the receiver to file it under: the receiver files the peer as peer_name ?? name (never as
46
+ // "contact-…"). peer_name goes only when the operator gave one (a receiver before it refuses the key).
43
47
  // status A or B → the operator (or the asker of a refused ask) {status: linked|refused|ended, check?}
44
48
  // end operator → A or B, A ↔ B {reason: unlink|expired|forgot}
45
49
  // Checks, by name: link_from (an ask or offer not from the receiver's operator: a DID holding an
@@ -105,9 +109,9 @@ export function checkPurpose(p) {
105
109
  const checkName = (n) => (n === undefined ? n : typeof n === 'string' && n.trim() !== '' && [...n].length <= NAME_MAX && !CONTROL.test(n) ? n : fail('link_text', `a name is 1 to ${NAME_MAX} characters, no control characters`));
106
110
 
107
111
  const SHAPES = {
108
- ask: { need: ['peer', 'kind', 'purpose', 'ttl'], may: ['name', 'tier', 'expires', 'relay'] },
112
+ ask: { need: ['peer', 'kind', 'purpose', 'ttl'], may: ['name', 'peer_name', 'tier', 'expires', 'relay'] },
109
113
  invite: { need: [], may: ['code', 'paired'] },
110
- offer: { need: ['from', 'did', 'purpose', 'ttl'], may: ['code', 'paired', 'name', 'tier', 'expires', 'note'] },
114
+ offer: { need: ['from', 'did', 'purpose', 'ttl'], may: ['code', 'paired', 'name', 'peer_name', 'tier', 'expires', 'note'] },
111
115
  status: { need: ['status'], may: ['check'] },
112
116
  end: { need: ['reason'], may: [] },
113
117
  };
@@ -135,8 +139,11 @@ export function checkMessage(x) {
135
139
  if (Object.hasOwn(x, 'purpose')) checkPurpose(x.purpose);
136
140
  if (Object.hasOwn(x, 'note')) { if (x.note === null) bad('note: a string'); checkNote(x.note); }
137
141
  checkName(x.name);
142
+ checkName(x.peer_name);
138
143
  return x;
139
144
  }
145
+ /** The name a receiver files the introduced peer under: the operator's choice for it, else the operator's own name for it. */
146
+ export const peerName = (x) => x.peer_name ?? x.name;
140
147
 
141
148
  // ---------------------------------------------------------------- the file
142
149
 
@@ -216,7 +223,7 @@ function contactNamed(carrier, who) {
216
223
  * DAYS_EXTERNAL); note: for X (external), data; relay: the relay A's code names (external default:
217
224
  * the relay of the operator's pairing with X). → the record { id, a, b, kind, …, status: "pending" }.
218
225
  */
219
- export async function link({ carrier, file, a, b, purpose, tierA, tierB, days, ttl, note, relay }) {
226
+ export async function link({ carrier, file, a, b, purpose, tierA, tierB, days, ttl, note, relay, nameA, nameB }) {
220
227
  for (const t of [tierA, tierB]) {
221
228
  if (t === 'own') fail('link_tier', 'a link never makes a contact own: own comes from your operator attestation alone (leave the tier out: two of your agents find each other own)');
222
229
  if (t !== undefined && t !== null && !LINK_TIERS.includes(t)) fail('tier', `a link's tier is ${LINK_TIERS.join(' or ')}, not ${JSON.stringify(t)}`);
@@ -228,7 +235,8 @@ export async function link({ carrier, file, a, b, purpose, tierA, tierB, days, t
228
235
  let A = contactNamed(carrier, a), B = contactNamed(carrier, b);
229
236
  if (A.did === B.did) fail('link_peer', `${A.name} twice: a link joins two agents`);
230
237
  if (!A.ours && !B.ours) fail('link_not_ours', `neither ${A.name} nor ${B.name} is yours by key (an operator attestation of yours): a link introduces one of your agents`);
231
- if (!A.ours) [A, B] = [B, A];
238
+ for (const x of [nameA, nameB]) if (x !== undefined && x !== null) checkName(x);
239
+ if (!A.ours) { [A, B] = [B, A]; [nameA, nameB] = [nameB, nameA]; }
232
240
  const kind = B.ours ? 'own' : 'external';
233
241
  if (kind === 'external' && tierB) fail('link_tier', `${B.name} is not yours: how it files ${A.name} is its operator's choice (leave --tier-b out)`);
234
242
  const tA = tierA ?? (kind === 'external' ? 'friend' : null), life = days ?? (kind === 'external' ? DAYS_EXTERNAL : null);
@@ -237,12 +245,12 @@ export async function link({ carrier, file, a, b, purpose, tierA, tierB, days, t
237
245
  const rec = state(file, now, (s) => {
238
246
  let id;
239
247
  do id = newId(); while (Object.hasOwn(s.links, id));
240
- s.links[id] = { id, a: A.did, b: B.did, a_name: A.name, b_name: B.name, kind, purpose: p, note: n, tier_a: tA, tier_b: tierB ?? null, expires, relay: at,
248
+ s.links[id] = { id, a: A.did, b: B.did, a_name: A.name, b_name: B.name, ...(nameA && { a_peer_name: nameA.trim() }), ...(nameB && { b_peer_name: nameB.trim() }), kind, purpose: p, note: n, tier_a: tA, tier_b: tierB ?? null, expires, relay: at,
241
249
  status: 'pending', step: 'ask', check: null, at: now, exp: now + t, ttl: t, steps: { a: null, b: null } };
242
250
  return s.links[id];
243
251
  }, platformOf(carrier));
244
252
  try {
245
- await send(carrier, A.did, msg('ask', rec.id, now, { peer: B.did, name: B.name, kind, purpose: p, ttl: t, ...(tA && { tier: tA }), ...(expires && { expires }), ...(at && { relay: at }) }));
253
+ await send(carrier, A.did, msg('ask', rec.id, now, { peer: B.did, name: B.name, ...(rec.b_peer_name && { peer_name: rec.b_peer_name }), kind, purpose: p, ttl: t, ...(tA && { tier: tA }), ...(expires && { expires }), ...(at && { relay: at }) }));
246
254
  } catch (e) {
247
255
  if (!(e instanceof MsgError)) throw e;
248
256
  state(file, nowOf(carrier), (s) => { Object.assign(s.links[rec.id], { status: 'refused', check: e.check, at: nowOf(carrier) }); }, platformOf(carrier));
@@ -370,7 +378,7 @@ async function onMessage(carrier, file, m, out, wait) {
370
378
  }
371
379
  if (x.typ === 'ask') {
372
380
  if (x.tier) carrier.presetTier(x.peer, x.tier);
373
- const inv = await carrier.invite({ name: x.name, ttl: Math.max(TTL_MIN, x.iat + x.ttl - now), ...(x.relay && { relay: x.relay }) });
381
+ const inv = await carrier.invite({ name: peerName(x), ttl: Math.max(TTL_MIN, x.iat + x.ttl - now), ...(x.relay && { relay: x.relay }) });
374
382
  const code = readCode(inv.code, now);
375
383
  state(file, now, (s) => { s.pending[`${m.from} ${x.id}`] = { ...base, role: 'a', peer: x.peer, nonce: code.nonce, exp: code.exp + 3600 }; }, platformOf(carrier));
376
384
  await send(carrier, m.from, msg('invite', x.id, now, { code: inv.code }));
@@ -381,7 +389,7 @@ async function onMessage(carrier, file, m, out, wait) {
381
389
  try { code = readCode(x.code, now); } catch (e) { return refuse(carrier, out, m.from, x.id, 'link_message', `the offer's code does not parse (${e.message})`); }
382
390
  if (code.did !== x.did) return refuse(carrier, out, m.from, x.id, 'link_peer', `the offer's code names ${code.did}, not ${x.did}`);
383
391
  state(file, now, (s) => { s.pending[`${m.from} ${x.id}`] = { ...base, role: 'b', peer: x.from, code_did: code.did, exp: code.exp + 3600 }; }, platformOf(carrier));
384
- try { await carrier.accept(x.code, { name: x.name, wait, ...(x.tier && { tier: x.tier }) }); } catch (e) {
392
+ try { await carrier.accept(x.code, { name: peerName(x), wait, ...(x.tier && { tier: x.tier }) }); } catch (e) {
385
393
  if (!(e instanceof MsgError)) throw e;
386
394
  state(file, nowOf(carrier), (s) => { delete s.pending[`${m.from} ${x.id}`]; }, platformOf(carrier));
387
395
  return refuse(carrier, out, m.from, x.id, e.check, `the link's code was not accepted (${e.message})`);
@@ -423,7 +431,7 @@ async function onOperator(carrier, file, m, x, out) {
423
431
  offer = { code: x.code, did: code.did };
424
432
  }
425
433
  try {
426
- await send(carrier, rec.b, msg('offer', x.id, now, { from: rec.a, ...offer, name: rec.a_name, purpose: rec.purpose, ttl: rec.ttl, ...(rec.tier_b && { tier: rec.tier_b }), ...(rec.expires && { expires: rec.expires }), ...(rec.note && { note: rec.note }) }));
434
+ await send(carrier, rec.b, msg('offer', x.id, now, { from: rec.a, ...offer, name: rec.a_name, ...(rec.a_peer_name && { peer_name: rec.a_peer_name }), purpose: rec.purpose, ttl: rec.ttl, ...(rec.tier_b && { tier: rec.tier_b }), ...(rec.expires && { expires: rec.expires }), ...(rec.note && { note: rec.note }) }));
427
435
  set((l) => { l.step = 'offer'; });
428
436
  } catch (e) {
429
437
  if (!(e instanceof MsgError)) throw e;
@@ -481,7 +489,7 @@ async function introduced(carrier, file, m, x, mine, out, wait) {
481
489
  exp = code.exp;
482
490
  }
483
491
  const by = carrier.contacts().contacts.find((c) => c.did === m.from);
484
- const key = `${m.from} ${x.id}`, rec = { id: x.id, from: m.from, peer: x.from, did: x.did, name: x.name ?? null, purpose: x.purpose, note: x.note ?? null,
492
+ const key = `${m.from} ${x.id}`, rec = { id: x.id, from: m.from, peer: x.from, did: x.did, name: peerName(x) ?? null, purpose: x.purpose, note: x.note ?? null,
485
493
  expires: x.expires ?? null, ...(x.code !== undefined ? { code: x.code } : { paired: true }), exp, at: now };
486
494
  const kept = state(file, now, (s) => {
487
495
  // One contact cannot crowd out the others: at most a quarter of the places each.
@@ -493,7 +501,7 @@ async function introduced(carrier, file, m, x, mine, out, wait) {
493
501
  }, platformOf(carrier));
494
502
  if (kept === 'full') return quietly('link_full', `${RECEIVED_MAX} introductions wait already (sigelo-agent links)`);
495
503
  if (kept === 'allowed') return; // carried out by this handle's rounds
496
- out.received.push({ id: x.id, from: m.from, name: by?.name ?? who, peer: x.from, peer_name: x.name ?? null, purpose: x.purpose, note: x.note ?? null, exp, notice: by?.tier !== 'quiet' });
504
+ out.received.push({ id: x.id, from: m.from, name: by?.name ?? who, peer: x.from, peer_name: peerName(x) ?? null, purpose: x.purpose, note: x.note ?? null, exp, notice: by?.tier !== 'quiet' });
497
505
  }
498
506
 
499
507
  // X's operator's answer, carried out (it needs the session): accept the code at the tier (quiet by
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sigelo-contact",
3
- "version": "0.1.13",
3
+ "version": "0.1.20",
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": [
@@ -22,7 +22,7 @@
22
22
  "repository": {
23
23
  "type": "git",
24
24
  "url": "git+https://github.com/csigelo/sigelo.git",
25
- "directory": "contact"
25
+ "directory": "apps/contact"
26
26
  },
27
27
  "bugs": {
28
28
  "url": "https://github.com/csigelo/sigelo/issues"
@@ -52,6 +52,8 @@
52
52
  "./enrol.mjs": "./enrol.mjs",
53
53
  "./link": "./link.mjs",
54
54
  "./link.mjs": "./link.mjs",
55
+ "./group": "./group.mjs",
56
+ "./group.mjs": "./group.mjs",
55
57
  "./page": "./page.mjs",
56
58
  "./page.mjs": "./page.mjs",
57
59
  "./platform-node": "./platform-node.mjs",
@@ -68,6 +70,26 @@
68
70
  "./restore.mjs": "./restore.mjs",
69
71
  "./create": "./create.mjs",
70
72
  "./create.mjs": "./create.mjs",
73
+ "./transfer": "./transfer.mjs",
74
+ "./transfer.mjs": "./transfer.mjs",
75
+ "./transfer-node": "./transfer-node.mjs",
76
+ "./transfer-node.mjs": "./transfer-node.mjs",
77
+ "./transfer-engine": "./transfer-engine.mjs",
78
+ "./transfer-engine.mjs": "./transfer-engine.mjs",
79
+ "./transfer-web": "./transfer-web.mjs",
80
+ "./transfer-web.mjs": "./transfer-web.mjs",
81
+ "./rtc-web": "./rtc-web.mjs",
82
+ "./rtc-web.mjs": "./rtc-web.mjs",
83
+ "./photo": "./photo.mjs",
84
+ "./photo.mjs": "./photo.mjs",
85
+ "./voice": "./voice.mjs",
86
+ "./voice.mjs": "./voice.mjs",
87
+ "./voice-web": "./voice-web.mjs",
88
+ "./voice-web.mjs": "./voice-web.mjs",
89
+ "./call": "./call.mjs",
90
+ "./call.mjs": "./call.mjs",
91
+ "./words-lock": "./words-lock.mjs",
92
+ "./words-lock.mjs": "./words-lock.mjs",
71
93
  "./package.json": "./package.json"
72
94
  },
73
95
  "files": [
@@ -83,6 +105,7 @@
83
105
  "invite.mjs",
84
106
  "kdf.mjs",
85
107
  "link.mjs",
108
+ "group.mjs",
86
109
  "page.mjs",
87
110
  "platform-node.mjs",
88
111
  "prekeys.mjs",
@@ -92,6 +115,17 @@
92
115
  "restore.mjs",
93
116
  "short.mjs",
94
117
  "store.mjs",
118
+ "transfer.mjs",
119
+ "transfer-node.mjs",
120
+ "transfer-engine.mjs",
121
+ "transfer-web.mjs",
122
+ "rtc-web.mjs",
123
+ "photo.mjs",
124
+ "voice.mjs",
125
+ "voice-web.mjs",
126
+ "call.mjs",
127
+ "public.mjs",
128
+ "words-lock.mjs",
95
129
  "fixtures/carrier-v0.json",
96
130
  "fixtures/device-v1.json",
97
131
  "fixtures/envelope-v0.json",
@@ -107,28 +141,36 @@
107
141
  "test-envelope.mjs",
108
142
  "test-file.mjs",
109
143
  "test-tier.mjs",
144
+ "test-presence.mjs",
110
145
  "test-ws.mjs",
111
146
  "test-invite.mjs",
112
147
  "test-link.mjs",
148
+ "test-group.mjs",
113
149
  "test-platform.mjs",
114
150
  "test-short.mjs",
115
- "test-device.mjs"
151
+ "test-device.mjs",
152
+ "test-transfer.mjs",
153
+ "test-transfer-web.mjs",
154
+ "test-relay-lane.mjs",
155
+ "test-voice.mjs",
156
+ "test-push.mjs"
116
157
  ],
117
158
  "engines": {
118
159
  "node": ">=22.18"
119
160
  },
120
161
  "scripts": {
121
- "test": "node test-invite.mjs && node test-envelope.mjs && node test-carrier.mjs && node test-ws.mjs && node test-short.mjs && node test-file.mjs && node test-enrol.mjs && node test-tier.mjs && node test-link.mjs && node test-device.mjs && node test-platform.mjs",
162
+ "test": "node test-invite.mjs && node test-envelope.mjs && node test-carrier.mjs && node test-ws.mjs && node test-short.mjs && node test-renew.mjs && node test-public.mjs && node test-file.mjs && node test-enrol.mjs && node test-tier.mjs && node test-presence.mjs && node test-ended.mjs && node test-link.mjs && node test-device.mjs && node test-platform.mjs && node test-group.mjs && node test-transfer.mjs && node test-transfer-web.mjs && node test-relay-lane.mjs && node test-voice.mjs && node test-push.mjs && node test-call.mjs",
122
163
  "gen": "node gen-invite.mjs && node gen-envelope.mjs && node gen-carrier.mjs && node gen-short.mjs && node gen-device.mjs",
123
- "prepack": "node ../release/prepack.mjs pre",
124
- "postpack": "node ../release/prepack.mjs post",
164
+ "prepack": "node ../../release/prepack.mjs pre",
165
+ "postpack": "node ../../release/prepack.mjs post",
125
166
  "prepublishOnly": "node -e \"if(process.env.SIGELO_PUBLISH!=='1'){console.error('refusing: publish the release tarball (release/RELEASE.md) with SIGELO_PUBLISH=1');process.exit(1)}\""
126
167
  },
127
168
  "dependencies": {
128
169
  "@noble/ciphers": "^2.4.0",
129
170
  "@noble/hashes": "^2.4.0",
130
171
  "@noble/post-quantum": "^0.7.1",
172
+ "hash-wasm": "4.12.0",
131
173
  "mqtt": "^5.16.0",
132
- "sigelo": "^0.1.13"
174
+ "sigelo": "^0.1.20"
133
175
  }
134
176
  }