sigelo-contact 0.1.13 → 0.1.14
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/carrier.mjs +277 -35
- package/enrol.mjs +34 -17
- package/group.mjs +597 -0
- package/link.mjs +23 -15
- package/package.json +19 -4
- package/page.mjs +278 -19
- package/platform-node.mjs +15 -5
- package/short.mjs +12 -0
- package/store.mjs +21 -2
- package/test-carrier.mjs +18 -4
- package/test-enrol.mjs +36 -2
- package/test-group.mjs +383 -0
- package/test-link.mjs +5 -2
- package/test-presence.mjs +169 -0
- package/test-short.mjs +4 -1
- package/test-transfer.mjs +435 -0
- package/transfer-node.mjs +845 -0
- package/transfer.mjs +371 -0
- package/words-lock.mjs +100 -0
package/link.mjs
CHANGED
|
@@ -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 }) →
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
3
|
+
"version": "0.1.14",
|
|
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": [
|
|
@@ -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,12 @@
|
|
|
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
|
+
"./words-lock": "./words-lock.mjs",
|
|
78
|
+
"./words-lock.mjs": "./words-lock.mjs",
|
|
71
79
|
"./package.json": "./package.json"
|
|
72
80
|
},
|
|
73
81
|
"files": [
|
|
@@ -83,6 +91,7 @@
|
|
|
83
91
|
"invite.mjs",
|
|
84
92
|
"kdf.mjs",
|
|
85
93
|
"link.mjs",
|
|
94
|
+
"group.mjs",
|
|
86
95
|
"page.mjs",
|
|
87
96
|
"platform-node.mjs",
|
|
88
97
|
"prekeys.mjs",
|
|
@@ -92,6 +101,9 @@
|
|
|
92
101
|
"restore.mjs",
|
|
93
102
|
"short.mjs",
|
|
94
103
|
"store.mjs",
|
|
104
|
+
"transfer.mjs",
|
|
105
|
+
"transfer-node.mjs",
|
|
106
|
+
"words-lock.mjs",
|
|
95
107
|
"fixtures/carrier-v0.json",
|
|
96
108
|
"fixtures/device-v1.json",
|
|
97
109
|
"fixtures/envelope-v0.json",
|
|
@@ -107,18 +119,21 @@
|
|
|
107
119
|
"test-envelope.mjs",
|
|
108
120
|
"test-file.mjs",
|
|
109
121
|
"test-tier.mjs",
|
|
122
|
+
"test-presence.mjs",
|
|
110
123
|
"test-ws.mjs",
|
|
111
124
|
"test-invite.mjs",
|
|
112
125
|
"test-link.mjs",
|
|
126
|
+
"test-group.mjs",
|
|
113
127
|
"test-platform.mjs",
|
|
114
128
|
"test-short.mjs",
|
|
115
|
-
"test-device.mjs"
|
|
129
|
+
"test-device.mjs",
|
|
130
|
+
"test-transfer.mjs"
|
|
116
131
|
],
|
|
117
132
|
"engines": {
|
|
118
133
|
"node": ">=22.18"
|
|
119
134
|
},
|
|
120
135
|
"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",
|
|
136
|
+
"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-presence.mjs && node test-link.mjs && node test-device.mjs && node test-platform.mjs && node test-group.mjs && node test-transfer.mjs",
|
|
122
137
|
"gen": "node gen-invite.mjs && node gen-envelope.mjs && node gen-carrier.mjs && node gen-short.mjs && node gen-device.mjs",
|
|
123
138
|
"prepack": "node ../release/prepack.mjs pre",
|
|
124
139
|
"postpack": "node ../release/prepack.mjs post",
|
|
@@ -129,6 +144,6 @@
|
|
|
129
144
|
"@noble/hashes": "^2.4.0",
|
|
130
145
|
"@noble/post-quantum": "^0.7.1",
|
|
131
146
|
"mqtt": "^5.16.0",
|
|
132
|
-
"sigelo": "^0.1.
|
|
147
|
+
"sigelo": "^0.1.14"
|
|
133
148
|
}
|
|
134
149
|
}
|