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.
- package/README.md +13 -10
- package/call.mjs +727 -0
- package/carrier.mjs +1204 -137
- package/control.mjs +81 -22
- package/device.mjs +1 -1
- package/enrol.mjs +239 -43
- package/gen-carrier.mjs +4 -4
- package/gen-device.mjs +2 -2
- package/gen-envelope.mjs +3 -3
- package/gen-invite.mjs +3 -3
- package/gen-short.mjs +3 -3
- package/group.mjs +616 -0
- package/invite.mjs +63 -13
- package/kdf.mjs +1 -1
- package/link.mjs +24 -16
- package/package.json +49 -7
- package/page.mjs +1172 -70
- package/photo.mjs +37 -0
- package/platform-node.mjs +125 -18
- package/prekeys.mjs +10 -2
- package/public.mjs +93 -0
- package/relays.mjs +1 -1
- package/restore.mjs +3 -3
- package/rtc-web.mjs +95 -0
- package/short.mjs +31 -3
- package/store.mjs +147 -12
- package/test-carrier.mjs +138 -21
- package/test-device.mjs +1 -1
- package/test-enrol.mjs +157 -8
- package/test-envelope.mjs +16 -3
- package/test-file.mjs +5 -5
- package/test-group.mjs +413 -0
- package/test-invite.mjs +15 -2
- package/test-link.mjs +11 -8
- package/test-platform.mjs +5 -5
- package/test-presence.mjs +169 -0
- package/test-push.mjs +136 -0
- package/test-relay-lane.mjs +248 -0
- package/test-short.mjs +38 -12
- package/test-tier.mjs +6 -6
- package/test-transfer-web.mjs +246 -0
- package/test-transfer.mjs +463 -0
- package/test-voice.mjs +158 -0
- package/test-ws.mjs +5 -5
- package/transfer-engine.mjs +800 -0
- package/transfer-node.mjs +449 -0
- package/transfer-web.mjs +80 -0
- package/transfer.mjs +388 -0
- package/voice-web.mjs +113 -0
- package/voice.mjs +65 -0
- package/words-lock.mjs +115 -0
package/enrol.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Enrolment, contract sigelo-enrol/1: the operator places worker i, an identity DERIVED from its
|
|
3
3
|
// keeper root K (MONERO.md §2, ts/src/keys.ts agentIdentitySeed(K, i, n)), on another machine, so
|
|
4
|
-
// the 25 words bring the same DID back. THREAT-MODEL §2.11,
|
|
4
|
+
// the 25 words bring the same DID back. THREAT-MODEL §2.11, apps/agent/ENROL.md.
|
|
5
5
|
//
|
|
6
6
|
// operatorIdentity(S, n) → the operator's own identity file: the root identity of S (keys.ts
|
|
7
7
|
// identitySeed(S, n), genesis pinned the same way), marked `derived: {path, n}`
|
|
@@ -10,20 +10,26 @@
|
|
|
10
10
|
// bytes at every call: `created` pinned, the nonce from the key (SPEC §4 `nonce`),
|
|
11
11
|
// rotations m → m+1 voluntary with iat 0. A second copy of a rotation is the same
|
|
12
12
|
// rotation, never a fork.
|
|
13
|
-
// operator: issue({ carrier, file, i, n, name, keeper, relay? }) → a short
|
|
14
|
-
// minutes, once) for a normal invite (at `relay`, else the carrier's), and
|
|
15
|
-
// enrolment kept in `file` for 24 hours, with the operator attestation signed now
|
|
16
|
-
// ≤ 90; a device's 14)
|
|
17
|
-
//
|
|
13
|
+
// operator: issue({ carrier, file, i, n, name, keeper, relay?, operatorName?, started?, ttl? }) → a short
|
|
14
|
+
// code (short.mjs, 10 minutes or ttl: 60 s to an hour, once) for a normal invite (at `relay`, else the carrier's), and
|
|
15
|
+
// a pending enrolment kept in `file` for 24 hours, with the operator attestation signed now
|
|
16
|
+
// (`days`, ≤ 90; a device's 14). operatorName: how the worker files its operator (default
|
|
17
|
+
// "operator"); started: the carrier's (a search the human started, carrier.mjs POW_SEARCHES);
|
|
18
|
+
// confirmWords: kept with it, handed to confirm() as `ask` (the optional words switch)
|
|
19
|
+
// machine: accept({ carrier, file, code, temp, strict? }) → `carrier` is a TEMPORARY identity (`temp`, its
|
|
18
20
|
// file): it fetches the code, pairs, and once paired sends a request, label LABEL_ENROL,
|
|
19
21
|
// {v, typ: "enrol-request", proof}
|
|
20
22
|
// both: complete({ carrier, file, wait, until, keeper | place, temp, confirm }) → one inbox or more:
|
|
21
23
|
// the operator answers a request whose proof matches an enrolment it issued with the
|
|
22
24
|
// worker's identity, label LABEL_IDENTITY, end to end, once per enrolment (after
|
|
23
|
-
// confirm({ words, … }) says yes, when given: the device words gate
|
|
25
|
+
// confirm({ words, … }) says yes, when given: the device words gate, or the operator's
|
|
26
|
+
// optional "confirm the four words" switch; null: not yet, the request comes back in
|
|
27
|
+
// `held`), with a long
|
|
24
28
|
// invite the worker accepts; once the worker has paired, the operator files it (observe:
|
|
25
29
|
// ours by the attestation; tier own unless the operator chose one) and forgets the
|
|
26
|
-
// temporary DID.
|
|
30
|
+
// temporary DID. `verified`: the worker that paired is the DID derived HERE from K (own
|
|
31
|
+
// enrolment needs no four words: the operator's side checks the result itself; THREAT-MODEL
|
|
32
|
+
// §2.11 says what is left). The machine takes the identity only from the DID it paired with
|
|
27
33
|
// through the code, checks it (checkIdentity)
|
|
28
34
|
// and hands it to place(), which writes the file and pairs as the worker; then it
|
|
29
35
|
// forgets the operator on the temporary identity, which gives its mailboxes up.
|
|
@@ -51,9 +57,42 @@
|
|
|
51
57
|
//
|
|
52
58
|
// The pending file, 0600, beside the identity (x.json → x.enrol.json), under its own lock:
|
|
53
59
|
// { v, issued: { invite nonce: { key, i, n, name, did, old_pair, relay, exp, attestation, issuer,
|
|
54
|
-
// temp?, invite?, done? } },
|
|
55
|
-
// joining: { invite nonce: { key, code_did, relay, exp, sent, temp } } }
|
|
60
|
+
// temp?, invite?, done?, sent_at?, needs_send?, short_hash?, unparked? } },
|
|
61
|
+
// joining: { invite nonce: { key, code_did, relay, exp, sent, temp, long?, short_hash?, answered? } } }
|
|
62
|
+
//
|
|
63
|
+
// The code is spent at the grant, not before (the agent-setup feedback, point 2). The operator parks its short
|
|
64
|
+
// code as an enrolment code (relay/park.mjs: fetched again until the grant) and spends it there once
|
|
65
|
+
// the worker's identity has gone (unparkHash, `unparked`). The machine keeps its joining entry from the
|
|
66
|
+
// fetch on: the long code, the short code's hash and its temporary identity, whether its answer went
|
|
67
|
+
// (`answered`); a refused proof of work or a crash leaves it, and init --enrol with the same code, or
|
|
68
|
+
// enrol --finish, takes it up again (resumeAnswer) instead of fetching the code or making another
|
|
69
|
+
// temporary identity.
|
|
70
|
+
//
|
|
71
|
+
// Who may enrol a machine (THREAT-MODEL §2.11a): only the identity that issued the code it fetched. The
|
|
72
|
+
// grant (LABEL_IDENTITY) is taken on the temporary identity only, from the contact holding the code's
|
|
73
|
+
// DID, for the code it names (`id`, the code's nonce: a grant for another code is refused enrol_replay),
|
|
74
|
+
// while its joining entry lives; a worker's own identity never takes one (no place() runs on it).
|
|
56
75
|
// Entries go at exp, 24 hours after they were made, whatever their state.
|
|
76
|
+
//
|
|
77
|
+
// Neither side waits on one message (0.1.17: a lost identity left both sides waiting for the other).
|
|
78
|
+
// The machine sends its request again at most every RESEND_S while no identity has come (`sent`:
|
|
79
|
+
// the unix time of the last send; true, as an earlier version kept it, counts as long ago). The
|
|
80
|
+
// operator whose identity send was refused or failed marks the enrolment `needs_send` (the time of
|
|
81
|
+
// that try) and sends again at its next round, at most every RESEND_S, while the entry lives.
|
|
82
|
+
//
|
|
83
|
+
// The machine is told why (0.1.17: `enrol --finish` said "not done yet" for ever while the operator
|
|
84
|
+
// refused or held its request). The operator answers the temporary identity with a status, label
|
|
85
|
+
// LABEL_ENROL, {v, typ: "status", check, detail}: no key, no secret, no other DID; the check is the
|
|
86
|
+
// operator's (enrol_proof, enrol_unpaired, enrol_from, enrol_used, enrol_done, enrol_words while the
|
|
87
|
+
// words gate holds the key, device_words when they differed, or the failed send's check). Sent once
|
|
88
|
+
// per reason, again when the reason changes: the pending file's `told` { temp DID: { check, exp } }.
|
|
89
|
+
// The machine takes a status only from the contact it paired with through the code, keeps the last in
|
|
90
|
+
// its joining entry (`status`), and complete() hands it out (`status`).
|
|
91
|
+
//
|
|
92
|
+
// A request held (the words gate: confirm() said not yet) is kept in its issued entry (`held`: the message,
|
|
93
|
+
// proof only, no key), not only in the caller's memory: each complete() as the operator takes the held ones
|
|
94
|
+
// again first, so an app restarted, killed in the background or offline meanwhile still answers it once the
|
|
95
|
+
// words are confirmed, without the machine asking again (0.1.17: two real enrolments stalled this way).
|
|
57
96
|
import { hkdf } from '@noble/hashes/hkdf.js';
|
|
58
97
|
import { hmac } from '@noble/hashes/hmac.js';
|
|
59
98
|
import { sha256 } from '@noble/hashes/sha2.js';
|
|
@@ -62,12 +101,12 @@ import { canonicalize, decodeKey, did as didOf, keygen, rotate, sign, structure,
|
|
|
62
101
|
import { agentIdentitySeed, identitySeed, recoveryCommitment } from 'sigelo/dist/keys.js';
|
|
63
102
|
import { keepLong, readCode } from './carrier.mjs';
|
|
64
103
|
import { MsgError, checkNow, fail, pairId, signAs, unhex } from './kdf.mjs';
|
|
65
|
-
import { codeKind, fingerprint } from './short.mjs';
|
|
104
|
+
import { codeHash, codeKind, fingerprint, formatEnrol, normaliseShort, stripEnrol } from './short.mjs';
|
|
66
105
|
import { platform as nodePlatform } from './platform-node.mjs';
|
|
67
106
|
|
|
68
107
|
export const ENROL_V = 'sigelo-enrol/1';
|
|
69
108
|
export const LABEL_ENROL = 'sigelo-enrol/1', LABEL_IDENTITY = 'sigelo-identity/0';
|
|
70
|
-
export const TYP_REQUEST = 'enrol-request', TYP_IDENTITY = 'enrol-identity';
|
|
109
|
+
export const TYP_REQUEST = 'enrol-request', TYP_IDENTITY = 'enrol-identity', TYP_STATUS = 'status';
|
|
71
110
|
export const OPERATOR_CTX = 'sigelo-relay/operator', OPERATOR_DAYS = 90, DAY = 86400;
|
|
72
111
|
// How long an enrolment stays pending, on either side: the invite's own default life.
|
|
73
112
|
export const PENDING_TTL = DAY;
|
|
@@ -76,6 +115,10 @@ export const PENDING_TTL = DAY;
|
|
|
76
115
|
export const PINNED_CREATED = '1970-01-01T00:00:00Z', ROTATION_IAT = 0, MAX_N = 64;
|
|
77
116
|
const KEY_INFO = 'sigelo-enrol/0 key', PROOF_PREFIX = 'sigelo-enrol/0 request\n';
|
|
78
117
|
const SKEW = 300, WAIT_STEP = 300;
|
|
118
|
+
/** The least time between two sends of the same request, or of the same identity after a failure (seconds). */
|
|
119
|
+
export const RESEND_S = 60;
|
|
120
|
+
// Due: never sent (false, undefined), sent by an earlier version (true: long ago), or RESEND_S since.
|
|
121
|
+
const due = (at, now) => at === undefined || at === null || at === false || at === true || !(now - at < RESEND_S);
|
|
79
122
|
|
|
80
123
|
// ---------------------------------------------------------------- the worker's identity
|
|
81
124
|
|
|
@@ -155,17 +198,44 @@ export function matches(content, key, pair) {
|
|
|
155
198
|
return d === 0;
|
|
156
199
|
}
|
|
157
200
|
|
|
158
|
-
|
|
159
|
-
|
|
201
|
+
// What the machine is told for each check: for its human, never naming another DID (the operator's own
|
|
202
|
+
// detail may name the one that took the code).
|
|
203
|
+
const TOLD = {
|
|
204
|
+
enrol_proof: 'the request matches no enrolment code the operator issued in the last 24 hours (expired or cancelled): ask for a new code',
|
|
205
|
+
enrol_unpaired: 'the operator has not seen this machine pair through the code yet: it answers once the pairing completes',
|
|
206
|
+
enrol_from: 'another identity paired through this code first: ask the operator for a new code',
|
|
207
|
+
enrol_used: 'this code placed another worker already: ask the operator for a new code',
|
|
208
|
+
enrol_done: 'this worker was placed already: nothing more is sent',
|
|
209
|
+
enrol_words: 'the operator\'s app waits for its human to compare the four words: check that both sides show the same',
|
|
210
|
+
device_words: 'the operator said the four words differ: the key was not sent and the code is dropped; ask for a new code',
|
|
211
|
+
};
|
|
212
|
+
/** The operator's status for the machine: why its request is refused or held. No key, no DID. */
|
|
213
|
+
export const statusMessage = (check, detail) => ({ v: ENROL_V, typ: TYP_STATUS, check, detail });
|
|
214
|
+
/** The machine's reading of a status: { check, detail }, or null for any other shape. */
|
|
215
|
+
export function readStatus(content) {
|
|
216
|
+
if (!isObject(content) || content.v !== ENROL_V || content.typ !== TYP_STATUS || typeof content.check !== 'string' || !/^[a-z][a-z0-9_]{0,39}$/.test(content.check) || typeof content.detail !== 'string') return null;
|
|
217
|
+
return { check: content.check, detail: content.detail.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g, ' ').slice(0, 300) };
|
|
218
|
+
}
|
|
219
|
+
/** The status the machine is sent for an operator's check (its own words for the known ones). */
|
|
220
|
+
export const toldFor = (check, detail) => TOLD[check] ?? `the operator could not send the key yet (${detail.replace(/ \(did:sigelo:[^)]*\)/g, '')}): it tries again within a minute`;
|
|
221
|
+
|
|
222
|
+
/** The message that carries the worker: its identity file, a long invite to pair as it, and how it files its operator (optional). */
|
|
223
|
+
// id: the code's nonce this grant is for (the machine refuses one for any other code: enrol_replay).
|
|
224
|
+
export const identityMessage = (identity, invite, worker = null, operatorName = null, id = null) => ({ v: ENROL_V, typ: TYP_IDENTITY, identity, invite, worker, ...(operatorName !== null && { operator_name: operatorName }), ...(id !== null && { id }) });
|
|
225
|
+
// The operator's label for itself, as the worker files it: a contact name (1 to 64, no control or bidi characters).
|
|
226
|
+
const LABEL_BAD = /[\u0000-\u001f\u007f-\u009f\u061c\u200e\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069]/;
|
|
227
|
+
export const operatorLabel = (v) => (typeof v === 'string' && v.trim() !== '' && [...v.trim()].length <= 64 && !LABEL_BAD.test(v) ? v.trim() : null);
|
|
160
228
|
|
|
161
229
|
/**
|
|
162
230
|
* The machine: an identity message from `operator` (the contact store's record of whoever it paired
|
|
163
231
|
* with through the code), naming `relay`. → { identity, did, original, invite }, or a MsgError
|
|
164
232
|
* naming the check.
|
|
165
233
|
*/
|
|
166
|
-
export function checkIdentity(content, { operator, relay, now }) {
|
|
234
|
+
export function checkIdentity(content, { operator, relay, now, id }) {
|
|
167
235
|
checkNow(now);
|
|
168
236
|
if (!isObject(content) || content.v !== ENROL_V || content.typ !== TYP_IDENTITY || !isObject(content.identity) || typeof content.invite !== 'string') fail('enrol_message', `not a ${ENROL_V} ${TYP_IDENTITY}`);
|
|
237
|
+
// A grant names its code (0.1.19 on): one for another code than this enrolment's is an old or a misrouted one.
|
|
238
|
+
if (content.id !== undefined && id !== undefined && content.id !== id) fail('enrol_replay', 'a worker identity for another enrolment code than the one this machine answered: not taken');
|
|
169
239
|
const x = content.identity, keys = ['v', 'secret', 'genesis', 'rotations', 'attestations', 'issuers'];
|
|
170
240
|
if (Object.keys(x).sort().join() !== [...keys].sort().join() || typeof x.secret !== 'string' || !/^[0-9a-f]{64}$/.test(x.secret)) fail('enrol_message', `the identity must be exactly {${keys.join(', ')}}, secret 64 hex`);
|
|
171
241
|
if (![x.rotations, x.attestations, x.issuers].every(Array.isArray) || x.attestations.length !== 1 || x.issuers.length !== 1) fail('enrol_message', 'the identity carries rotations, and exactly one attestation and one issuer');
|
|
@@ -186,7 +256,8 @@ export function checkIdentity(content, { operator, relay, now }) {
|
|
|
186
256
|
try { code = readCode(content.invite, now); } catch (e) { fail('enrol_invite', `the worker's invite does not parse (${e.message})`); }
|
|
187
257
|
if (code.did !== operator.current_did) fail('enrol_invite', `the worker's invite names ${code.did}, not the operator ${operator.current_did}`);
|
|
188
258
|
const worker = Number.isSafeInteger(content.worker) && content.worker >= 0 ? content.worker : null;
|
|
189
|
-
return { identity: { v: 'sigelo/0', secret: x.secret, genesis: x.genesis, rotations: x.rotations, attestations: [{ body: b, sig: a.sig }], issuers: x.issuers }, did: r.did, original: r.chain[0], invite: content.invite, worker, exp: b.exp
|
|
259
|
+
return { identity: { v: 'sigelo/0', secret: x.secret, genesis: x.genesis, rotations: x.rotations, attestations: [{ body: b, sig: a.sig }], issuers: x.issuers }, did: r.did, original: r.chain[0], invite: content.invite, worker, exp: b.exp,
|
|
260
|
+
operator_name: operatorLabel(content.operator_name) ?? 'operator' };
|
|
190
261
|
}
|
|
191
262
|
|
|
192
263
|
// ---------------------------------------------------------------- the pending file
|
|
@@ -209,7 +280,7 @@ export function pending(file, now, fn = () => undefined, platform = nodePlatform
|
|
|
209
280
|
if (s?.v !== ENROL_V || !isObject(s.issued) || !isObject(s.joining)) fail('enrol_file', `${file} is not a ${ENROL_V} file: delete it to drop the pending enrolments`);
|
|
210
281
|
}
|
|
211
282
|
const before = canonicalize(s);
|
|
212
|
-
for (const k of ['issued', 'joining']) for (const [id, e] of Object.entries(s[k])) if (!(e.exp > now)) delete s[k][id];
|
|
283
|
+
for (const k of ['issued', 'joining', 'told']) for (const [id, e] of Object.entries(s[k] ?? {})) if (!(e.exp > now)) delete s[k][id];
|
|
213
284
|
const out = fn(s);
|
|
214
285
|
if (canonicalize(s) !== before) platform.files.write(file, utf8ToBytes(JSON.stringify(s, null, 2)));
|
|
215
286
|
return out;
|
|
@@ -244,19 +315,22 @@ const checkKeeper = (k) => {
|
|
|
244
315
|
* stands for (24 hours). The operator attestation is signed here, at derivation time.
|
|
245
316
|
* → { short, short_exp, code, id, did (the worker's current DID), original }.
|
|
246
317
|
*/
|
|
247
|
-
export async function issue({ carrier, file, i, n, name, keeper, days = OPERATOR_DAYS, relay }) {
|
|
318
|
+
export async function issue({ carrier, file, i, n, name, keeper, days = OPERATOR_DAYS, relay, operatorName, started, confirmWords = false, ttl }) {
|
|
248
319
|
checkKeeper(keeper);
|
|
320
|
+
if (operatorName !== undefined && operatorName !== null && operatorLabel(operatorName) === null) fail('enrol', 'operatorName: 1 to 64 characters, no control characters');
|
|
249
321
|
const w = workerChain(keeper.K, i, n, keeper.recovery);
|
|
250
322
|
// The temporary identity's contact, named apart from the worker's (forgotten once it has paired).
|
|
251
|
-
const r = await carrier.invite({ name: `${name ?? `worker ${i}`} (enrolling)`, short: true, ...(relay !== undefined && relay !== carrier.relay && { relay }) });
|
|
323
|
+
const r = await carrier.invite({ name: `${name ?? `worker ${i}`} (enrolling)`, short: true, enrol: true, ...(relay !== undefined && relay !== carrier.relay && { relay }), ...(started !== undefined && { started }), ...(ttl !== undefined && { ttl }) });
|
|
252
324
|
const now = nowOf(carrier), code = readCode(r.code, now), me = self(carrier, now);
|
|
253
325
|
const attestation = operatorAttestation({ sign: me.sign, iss: me.did, sub: w.original, relay: code.relay, now, days });
|
|
254
326
|
const old = liveHolding(carrier, w.original);
|
|
255
327
|
pendingOf(carrier)(file, now, (s) => {
|
|
256
328
|
s.issued[code.nonce] = { key: bytesToHex(enrolKey(code.secret)), i, n, name: name ?? null, did: w.did, original: w.original, old_pair: old ? pairOf(old) : null,
|
|
257
|
-
relay: code.relay, exp: now + PENDING_TTL, attestation, issuer: me.genesis }
|
|
329
|
+
relay: code.relay, exp: now + PENDING_TTL, attestation, issuer: me.genesis, ...(operatorLabel(operatorName) !== null && { operator_name: operatorLabel(operatorName) }), ...(confirmWords && { confirm_words: true }),
|
|
330
|
+
...(r.short && { short_hash: codeHash(r.short) }) };
|
|
258
331
|
});
|
|
259
|
-
|
|
332
|
+
// enrol_code: how it is shown to an agent (ENROL-K7F3-Q9ZP, short.mjs), never taken for a pairing code.
|
|
333
|
+
return { ...r, id: code.nonce, did: w.did, original: w.original, ...(r.short && { enrol_code: formatEnrol(normaliseShort(r.short)) }) };
|
|
260
334
|
}
|
|
261
335
|
|
|
262
336
|
/**
|
|
@@ -265,14 +339,47 @@ export async function issue({ carrier, file, i, n, name, keeper, days = OPERATOR
|
|
|
265
339
|
* else at a later complete(). temp: the temporary identity's file, kept with the entry.
|
|
266
340
|
* → { status, did: the operator's DID as the code names it, contact?, id, long? }.
|
|
267
341
|
*/
|
|
268
|
-
|
|
269
|
-
|
|
342
|
+
// strict: a short code must be one the relay parked as an enrolment code (relay/park.mjs isEnrol), and a
|
|
343
|
+
// long code is refused (it says nothing of what it is for): an agent's init --enrol, never a pairing code.
|
|
344
|
+
export async function accept({ carrier, file, code: given, name, wait = 10, temp, strict = false, relay }) {
|
|
345
|
+
const text = stripEnrol(given), short = codeKind(text) === 'short';
|
|
346
|
+
if (strict && !short) fail('enrol_not', 'init --enrol takes the enrol code your operator\'s app or sigelo-agent enrol gave (ENROL-K7F3-Q9ZP), not a long sgl1… code; a pairing code from a contact goes to accept CODE');
|
|
347
|
+
const got = short ? await carrier.unparkFrom(text, { ...(relay !== undefined && { relay }) }) : { invite: text, enrol: false }, long = got.invite;
|
|
348
|
+
if (strict && got.enrol !== true) fail('enrol_not', 'that is a pairing code, not an enrol code (the relay parked it as an invite; or your operator\'s app is older than 0.1.19): a pairing code goes to accept CODE; for enrolment ask your operator for a new enrol code');
|
|
349
|
+
const now = nowOf(carrier), code = readCode(long, now, short ? 'parked' : 'long');
|
|
350
|
+
pendingOf(carrier)(file, now, (s) => {
|
|
351
|
+
s.joining[code.nonce] = { key: bytesToHex(enrolKey(code.secret)), code_did: code.did, relay: code.relay, exp: now + PENDING_TTL, sent: false, temp: temp ?? null,
|
|
352
|
+
long, ...(short && { short_hash: codeHash(text) }), answered: false };
|
|
353
|
+
});
|
|
354
|
+
return answer(carrier, file, code.nonce, long, { name, wait, short, did: code.did });
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// The machine's answer to the code of joining entry `id`, marked `answered` once it went or waits queued
|
|
358
|
+
// in the carrier (a refusal that withdrew it leaves it false: resumeAnswer sends it again).
|
|
359
|
+
async function answer(carrier, file, id, long, { name, wait, short, did }) {
|
|
360
|
+
const mark = () => pendingOf(carrier)(file, nowOf(carrier), (s) => { if (s.joining[id]) s.joining[id].answered = true; });
|
|
270
361
|
try {
|
|
271
|
-
const now = nowOf(carrier), code = readCode(long, now, short ? 'parked' : 'long');
|
|
272
|
-
pendingOf(carrier)(file, now, (s) => { s.joining[code.nonce] = { key: bytesToHex(enrolKey(code.secret)), code_did: code.did, relay: code.relay, exp: now + PENDING_TTL, sent: false, temp: temp ?? null }; });
|
|
273
362
|
const r = await carrier.accept(long, { name, wait });
|
|
274
|
-
|
|
275
|
-
|
|
363
|
+
mark();
|
|
364
|
+
return { ...r, did, id, ...(short && { long }) };
|
|
365
|
+
} catch (e) {
|
|
366
|
+
if (e?.kept) mark();
|
|
367
|
+
// The entry stays: init --enrol with the same code, or enrol --finish, takes it up again.
|
|
368
|
+
throw Object.assign(short ? keepLong(e, long) : e, { pending: id });
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** The machine: each joining entry of `temp` whose answer did not go (a refused proof of work withdrew it)
|
|
373
|
+
* and whose code still lives is answered again. → how many were sent or queued again. */
|
|
374
|
+
export async function resumeAnswer({ carrier, file, temp, name = 'operator', wait = 30 }) {
|
|
375
|
+
const now = nowOf(carrier);
|
|
376
|
+
const todo = pendingOf(carrier)(file, now, (s) => Object.entries(s.joining).filter(([, j]) => j.temp === temp && j.answered === false && typeof j.long === 'string'));
|
|
377
|
+
let n = 0;
|
|
378
|
+
for (const [id, j] of todo) {
|
|
379
|
+
if (liveHolding(carrier, j.code_did)) { pendingOf(carrier)(file, nowOf(carrier), (s) => { if (s.joining[id]) s.joining[id].answered = true; }); continue; }
|
|
380
|
+
try { await answer(carrier, file, id, j.long, { name, wait, short: false, did: j.code_did }); n++; } catch (e) { if (!(e instanceof MsgError) && !e?.check) throw e; if (e.kept) n++; }
|
|
381
|
+
}
|
|
382
|
+
return n;
|
|
276
383
|
}
|
|
277
384
|
|
|
278
385
|
/**
|
|
@@ -283,45 +390,88 @@ export async function accept({ carrier, file, code: text, name, wait = 10, temp
|
|
|
283
390
|
* machine: temp = the temporary identity's file this carrier runs on; place(checked, { operator })
|
|
284
391
|
* writes the worker's file and pairs as it → { status, contact? }.
|
|
285
392
|
* → { delivered: [{ id, name, temp, did }], placed: [{ id, name, did, original, … }], refused: [{ check, detail, from }],
|
|
393
|
+
* status (machine): [{ check, detail, at }] the operator's word on its request, told (operator): [{ to, check, detail }],
|
|
286
394
|
* sent: [{ did }], rest: the batch without what was handled, offline? }
|
|
287
395
|
*/
|
|
288
396
|
export async function complete({ carrier, file, wait = 0, until = () => false, keeper = null, place = null, temp = null, confirm = null }) {
|
|
289
397
|
if (keeper) checkKeeper(keeper);
|
|
290
|
-
const out = { delivered: [], placed: [], refused: [], sent: [], rest: { messages: [], events: [], dropped: {} } };
|
|
398
|
+
const out = { delivered: [], placed: [], refused: [], sent: [], held: [], status: [], told: [], rest: { messages: [], events: [], dropped: {} } };
|
|
291
399
|
const end = Date.now() + wait * 1000;
|
|
400
|
+
// One request answered once per call, however it came (held before, and the same again from the inbox).
|
|
401
|
+
const done = new Set(), once = (m) => { const k = `${m?.from} ${m?.content?.proof}`; if (done.has(k)) return false; done.add(k); return true; };
|
|
292
402
|
for (let first = true; ; first = false) {
|
|
293
|
-
if (first && place) await sendRequests(carrier, file, temp, out
|
|
403
|
+
if (first && place) await sendRequests(carrier, file, temp, out);
|
|
404
|
+
// The requests held before (the header's "A request held"): taken again first, once per complete().
|
|
405
|
+
if (first && keeper) {
|
|
406
|
+
const kept = pendingOf(carrier)(file, nowOf(carrier), (s) => Object.values(s.issued).filter((e) => e.held && !e.done).map((e) => e.held));
|
|
407
|
+
for (const m of kept) if (once(m)) await onRequest(carrier, file, keeper, m, out, confirm);
|
|
408
|
+
}
|
|
409
|
+
if (keeper) await resend(carrier, file, keeper, out);
|
|
294
410
|
if (keeper) await settle(carrier, file, keeper, out);
|
|
295
411
|
const left = Math.max(0, Math.ceil((end - Date.now()) / 1000));
|
|
296
412
|
const batch = await carrier.inbox({ wait: Math.min(left, WAIT_STEP), paired: true });
|
|
297
413
|
out.rest.events.push(...batch.events);
|
|
298
414
|
for (const [k, n] of Object.entries(batch.dropped ?? {})) out.rest.dropped[k] = (out.rest.dropped[k] ?? 0) + n;
|
|
299
415
|
for (const m of batch.messages) {
|
|
300
|
-
if (m?.label === LABEL_ENROL &&
|
|
416
|
+
if (m?.label === LABEL_ENROL && place && readStatus(m.content) && onStatus(carrier, file, temp, m, out)) continue;
|
|
417
|
+
if (m?.label === LABEL_ENROL && keeper && !readStatus(m.content)) { if (once(m)) await onRequest(carrier, file, keeper, m, out, confirm); }
|
|
301
418
|
else if (m?.label === LABEL_IDENTITY && place && await onIdentity(carrier, file, temp, m, out, place)) continue;
|
|
302
419
|
else out.rest.messages.push(m);
|
|
303
420
|
}
|
|
304
421
|
if (batch.offline !== undefined) { out.offline = batch.offline; out.lastError = carrier.lastError; break; }
|
|
305
422
|
// A pairing this inbox completed sends its request now, not at the next run; a worker that
|
|
306
423
|
// paired in this inbox is filed now.
|
|
307
|
-
if (place && out.placed.length === 0) await sendRequests(carrier, file, temp, out
|
|
424
|
+
if (place && out.placed.length === 0) await sendRequests(carrier, file, temp, out);
|
|
308
425
|
if (keeper) await settle(carrier, file, keeper, out);
|
|
309
426
|
if (until(out) || Date.now() >= end) break;
|
|
310
427
|
}
|
|
428
|
+
// The machine: the operator's last word when none came in this run (an earlier run kept it).
|
|
429
|
+
if (place && out.status.length === 0 && out.placed.length === 0) {
|
|
430
|
+
const kept = pendingOf(carrier)(file, nowOf(carrier), (s) => Object.values(s.joining).filter((j) => j.temp === temp && j.status).map((j) => j.status));
|
|
431
|
+
out.status.push(...kept);
|
|
432
|
+
}
|
|
311
433
|
return out;
|
|
312
434
|
}
|
|
313
435
|
|
|
436
|
+
// The operator: tell the temporary DID `to` (a live contact) why its request is refused or held, once per
|
|
437
|
+
// check (the header's "The machine is told why"). Best effort: a send that fails is tried at the next reason.
|
|
438
|
+
async function tell(carrier, file, to, check, detail, out) {
|
|
439
|
+
const c = readStore(carrier).contacts[to];
|
|
440
|
+
if (!c || c.revoked || !c.pair_key) return;
|
|
441
|
+
const now = nowOf(carrier);
|
|
442
|
+
const fresh = pendingOf(carrier)(file, now, (s) => s.told?.[to]?.check !== check);
|
|
443
|
+
if (!fresh) return;
|
|
444
|
+
const words = toldFor(check, detail);
|
|
445
|
+
try {
|
|
446
|
+
await carrier.send(c.did, statusMessage(check, words), { label: LABEL_ENROL });
|
|
447
|
+
pendingOf(carrier)(file, nowOf(carrier), (s) => { (s.told ??= {})[to] = { check, detail: words, exp: now + PENDING_TTL }; });
|
|
448
|
+
out.told.push({ to, check, detail: words });
|
|
449
|
+
} catch (e) { if (!(e instanceof MsgError)) throw e; }
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// The machine: the operator's status, from the contact it paired with through a code → true when taken.
|
|
453
|
+
function onStatus(carrier, file, temp, m, out) {
|
|
454
|
+
const c = readStore(carrier).contacts[m.from], st = readStatus(m.content);
|
|
455
|
+
const now = nowOf(carrier);
|
|
456
|
+
const id = c && !c.revoked ? pendingOf(carrier)(file, now, (s) => Object.entries(s.joining).find(([, j]) => j.temp === temp && c.chain.includes(j.code_did))?.[0]) : undefined;
|
|
457
|
+
if (!id) return false;
|
|
458
|
+
pendingOf(carrier)(file, now, (s) => { if (s.joining[id]) s.joining[id].status = { ...st, at: now }; });
|
|
459
|
+
out.status.push({ ...st, at: now, from: m.from });
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
462
|
+
|
|
314
463
|
// The machine: a request for each enrolment of this temporary identity whose pairing is complete
|
|
315
|
-
// and that has not sent one
|
|
316
|
-
// operator
|
|
317
|
-
async function sendRequests(carrier, file, temp, out
|
|
318
|
-
const
|
|
464
|
+
// and that has not sent one, or sent it RESEND_S ago or more with no identity come since (it was
|
|
465
|
+
// lost, refused, or read elsewhere; the operator answers a request again until the worker paired).
|
|
466
|
+
async function sendRequests(carrier, file, temp, out) {
|
|
467
|
+
const now0 = nowOf(carrier);
|
|
468
|
+
const todo = pendingOf(carrier)(file, now0, (s) => Object.entries(s.joining).filter(([, j]) => j.temp === temp && due(j.sent, now0)));
|
|
319
469
|
for (const [id, j] of todo) {
|
|
320
470
|
const c = liveHolding(carrier, j.code_did);
|
|
321
471
|
if (!c) continue;
|
|
322
472
|
try {
|
|
323
473
|
const r = await carrier.send(c.did, request(hexToBytes(j.key), pairOf(c)), { label: LABEL_ENROL });
|
|
324
|
-
pendingOf(carrier)(file, nowOf(carrier), (s) => { if (s.joining[id]) s.joining[id].sent =
|
|
474
|
+
pendingOf(carrier)(file, nowOf(carrier), (s) => { if (s.joining[id]) s.joining[id].sent = nowOf(carrier); });
|
|
325
475
|
out.sent.push({ did: c.did, status: r.status });
|
|
326
476
|
} catch (e) {
|
|
327
477
|
out.refused.push({ check: e.check ?? 'error', detail: `the enrolment request to ${c.name} did not go (${e.message}): it goes at the next sigelo-agent enrol --finish`, from: c.did });
|
|
@@ -350,16 +500,33 @@ async function onRequest(carrier, file, keeper, m, out, confirm) {
|
|
|
350
500
|
e.temp = c.did;
|
|
351
501
|
return { id, e };
|
|
352
502
|
});
|
|
353
|
-
if (r.check) { out.refused.push({ ...r, from: m.from }); return; }
|
|
503
|
+
if (r.check) { out.refused.push({ ...r, from: m.from }); await tell(carrier, file, m.from, r.check, r.detail, out); return; }
|
|
354
504
|
const { id, e } = r;
|
|
355
505
|
// The words gate (devices.md §5.1): the human compares the pairing's four words on this side
|
|
356
506
|
// before the key goes. Declined: the enrolment is dropped, nothing is ever sent for it.
|
|
357
|
-
|
|
507
|
+
// An enrolment made with the switch on is never sent unasked: without a confirm() here, it waits.
|
|
508
|
+
const said = e.confirmed ? true : confirm ? await confirm({ id, name: e.name, i: e.i, did: e.did, temp: c.did, words: fingerprint(pair), ask: e.confirm_words === true }) : e.confirm_words ? null : true;
|
|
509
|
+
// Not yet (the page waits for the human's tap): the request is kept, nothing goes.
|
|
510
|
+
if (said === null || said === undefined) {
|
|
511
|
+
const kept = { from: m.from, name: m.name ?? null, label: LABEL_ENROL, content: m.content };
|
|
512
|
+
pendingOf(carrier)(file, nowOf(carrier), (s) => { if (s.issued[id]) s.issued[id].held = kept; });
|
|
513
|
+
out.held.push(m); await tell(carrier, file, c.did, 'enrol_words', '', out); return;
|
|
514
|
+
}
|
|
515
|
+
pendingOf(carrier)(file, nowOf(carrier), (s) => { if (s.issued[id]) delete s.issued[id].held; });
|
|
516
|
+
if (!said) {
|
|
358
517
|
pendingOf(carrier)(file, nowOf(carrier), (s) => { delete s.issued[id]; });
|
|
359
518
|
out.refused.push({ check: 'device_words', detail: `the four words of ${who} were not confirmed: worker ${e.i} not sent, the code is dropped; make a new one`, from: m.from });
|
|
519
|
+
await tell(carrier, file, c.did, 'device_words', '', out);
|
|
360
520
|
return;
|
|
361
521
|
}
|
|
362
|
-
if (confirm) pendingOf(carrier)(file, nowOf(carrier), (s) => { if (s.issued[id]) s.issued[id].confirmed = true; });
|
|
522
|
+
if (confirm || e.confirm_words) pendingOf(carrier)(file, nowOf(carrier), (s) => { if (s.issued[id]) s.issued[id].confirmed = true; });
|
|
523
|
+
await sendIdentity(carrier, file, keeper, id, e, c, out);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// The operator: worker e.i's identity to the temporary DID c, with its own invite. Refused or failed:
|
|
527
|
+
// marked needs_send (resend tries again), never left to a request that may not come again.
|
|
528
|
+
async function sendIdentity(carrier, file, keeper, id, e, c, out) {
|
|
529
|
+
const now = nowOf(carrier), who = `${c.name ?? c.did} (${c.did})`;
|
|
363
530
|
try {
|
|
364
531
|
// The worker's own invite, made once per enrolment: a repeated request gets the same.
|
|
365
532
|
let invite = e.invite;
|
|
@@ -369,11 +536,38 @@ async function onRequest(carrier, file, keeper, m, out, confirm) {
|
|
|
369
536
|
}
|
|
370
537
|
const identity = workerIdentity({ K: keeper.K, i: e.i, n: e.n, recovery: keeper.recovery, attestation: e.attestation, issuer: e.issuer });
|
|
371
538
|
if (didOf([identity.genesis, ...identity.rotations.map((x) => x.next_genesis)].at(-1)) !== e.did) fail('keeper', `worker ${e.i} derives to another DID than at enrol: the keeper root changed since (sigelo-agent keeper)`);
|
|
372
|
-
const sent = await carrier.send(c.did, identityMessage(identity, invite, e.i), { label: LABEL_IDENTITY });
|
|
539
|
+
const sent = await carrier.send(c.did, identityMessage(identity, invite, e.i, e.operator_name ?? null, id), { label: LABEL_IDENTITY });
|
|
540
|
+
pendingOf(carrier)(file, nowOf(carrier), (s) => { if (s.issued[id]) { s.issued[id].sent_at = nowOf(carrier); delete s.issued[id].needs_send; } });
|
|
373
541
|
out.delivered.push({ id, name: e.name, temp: c.did, did: e.did, status: sent.status });
|
|
542
|
+
await spend(carrier, file, id, e);
|
|
374
543
|
} catch (x) {
|
|
375
544
|
if (!(x instanceof MsgError)) throw x;
|
|
376
|
-
|
|
545
|
+
if (x.check !== 'keeper') pendingOf(carrier)(file, nowOf(carrier), (s) => { if (s.issued[id]) s.issued[id].needs_send = nowOf(carrier); });
|
|
546
|
+
out.refused.push({ check: x.check, detail: `worker ${e.i} did not go to ${who} (${x.message}): it goes again at the next round, or when the machine asks again (sigelo-agent enrol --finish there)`, from: c.did, needs_send: id });
|
|
547
|
+
if (x.check !== 'keeper') await tell(carrier, file, c.did, x.check, x.message, out);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// The operator: the grant went, so the enrolment code is spent at the relay (relay/park.mjs: until now it
|
|
552
|
+
// could be fetched again). Best effort: one not spent runs out there by itself, and its pairing is taken.
|
|
553
|
+
async function spend(carrier, file, id, e) {
|
|
554
|
+
if (!e.short_hash || e.unparked || typeof carrier.unparkHash !== 'function') return;
|
|
555
|
+
try {
|
|
556
|
+
const r = await carrier.unparkHash(e.short_hash, e.relay);
|
|
557
|
+
if (r.unparked) pendingOf(carrier)(file, nowOf(carrier), (s) => { if (s.issued[id]) s.issued[id].unparked = true; });
|
|
558
|
+
} catch {}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// The operator: each enrolment whose identity send failed (needs_send), sent again once RESEND_S
|
|
562
|
+
// passed, while the entry lives, its worker has not paired, and its temporary DID is still a live
|
|
563
|
+
// contact. Only what onRequest already let go (its proof checked, its words confirmed when asked).
|
|
564
|
+
async function resend(carrier, file, keeper, out) {
|
|
565
|
+
const now = nowOf(carrier);
|
|
566
|
+
const todo = pendingOf(carrier)(file, now, (s) => Object.entries(s.issued).filter(([, e]) => e.needs_send !== undefined && e.temp && !e.done && due(e.needs_send, now) && (e.confirmed || !e.confirm_words)));
|
|
567
|
+
for (const [id, e] of todo) {
|
|
568
|
+
const c = readStore(carrier).contacts[e.temp];
|
|
569
|
+
if (!c || c.revoked || !c.pair_key) continue;
|
|
570
|
+
await sendIdentity(carrier, file, keeper, id, e, c, out);
|
|
377
571
|
}
|
|
378
572
|
}
|
|
379
573
|
|
|
@@ -387,10 +581,12 @@ async function settle(carrier, file, keeper, out) {
|
|
|
387
581
|
const identity = workerIdentity({ K: keeper.K, i: e.i, n: e.n, recovery: keeper.recovery, attestation: e.attestation, issuer: e.issuer });
|
|
388
582
|
const bundle = { v: 'sigelo/0', typ: 'bundle', genesis: identity.genesis, rotations: identity.rotations, bindings: [], attestations: identity.attestations, issuers: identity.issuers };
|
|
389
583
|
const seen = carrier.observe(bundle), tier = seen?.tier ?? null, ours = seen?.ours ?? null;
|
|
584
|
+
// Derived here from K, not read from the pending file: the DID that paired IS worker i of these words.
|
|
585
|
+
const verified = c.did === didOf(identity.genesis) && c.did === workerChain(keeper.K, e.i, 0, keeper.recovery).original;
|
|
390
586
|
let released = false;
|
|
391
587
|
try { released = (await carrier.forget(e.temp)).released; } catch (x) { if (!(x instanceof MsgError) || x.check !== 'not_contact') throw x; }
|
|
392
588
|
pendingOf(carrier)(file, nowOf(carrier), (s) => { if (s.issued[id]) s.issued[id].done = nowOf(carrier); });
|
|
393
|
-
out.placed.push({ id, name: c.name, did: c.current_did, original: c.did, i: e.i, n: e.n, ours, tier, temp: e.temp, released, exp: e.attestation.body.exp });
|
|
589
|
+
out.placed.push({ id, name: c.name, did: c.current_did, original: c.did, i: e.i, n: e.n, ours, tier, temp: e.temp, released, exp: e.attestation.body.exp, verified, words: c.pair_key ? fingerprint(pairOf(c)) : null });
|
|
394
590
|
}
|
|
395
591
|
}
|
|
396
592
|
|
|
@@ -407,7 +603,7 @@ async function onIdentity(carrier, file, temp, m, out, place) {
|
|
|
407
603
|
}
|
|
408
604
|
const [id, j] = hit;
|
|
409
605
|
try {
|
|
410
|
-
const x = checkIdentity(m.content, { operator: c, relay: j.relay, now }), tempDid = self(carrier, now).original;
|
|
606
|
+
const x = checkIdentity(m.content, { operator: c, relay: j.relay, now, id }), tempDid = self(carrier, now).original;
|
|
411
607
|
const r = await place(x, { operator: c, id });
|
|
412
608
|
// The temporary identity is done: the operator is forgotten on it, its mailboxes given up.
|
|
413
609
|
let released = false, offline;
|
package/gen-carrier.mjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Regenerates fixtures/carrier-v0.json, byte for byte, from the documented seeds below: the frames
|
|
3
3
|
// of contract sigelo-carrier/0 (carrier.mjs header, "Frames"), kinds 1, 2, 4 (a rotation and a
|
|
4
4
|
// recovery) and 5.
|
|
5
|
-
// node contact/gen-carrier.mjs write the file
|
|
6
|
-
// node contact/gen-carrier.mjs --check exit 1 if the committed file differs
|
|
5
|
+
// node apps/contact/gen-carrier.mjs write the file
|
|
6
|
+
// node apps/contact/gen-carrier.mjs --check exit 1 if the committed file differs
|
|
7
7
|
// Independent of carrier.mjs, invite.mjs and prekeys.mjs on purpose: headers, keys, topics,
|
|
8
8
|
// padding, proofs and prekey bundles are assembled here from the contract with @noble and the
|
|
9
9
|
// sigelo library, so the fixture checks carrier.mjs (test-carrier.mjs) instead of echoing it.
|
|
@@ -67,7 +67,7 @@ export function build() {
|
|
|
67
67
|
const rB1 = rotate({ genesis: B0.genesis, next_genesis: B1.genesis, iat: T0 + 100, reason: 'voluntary', secret: B0.secret, next_secret: B1.secret });
|
|
68
68
|
const rB2 = rotate({ genesis: B0.genesis, next_genesis: B2.genesis, iat: T0 + 200, reason: 'recovery', secret: id('B-recovery', ZERO).secret, next_secret: B2.secret });
|
|
69
69
|
|
|
70
|
-
// The invite secret, alice's code and what they yield (contact/invite.mjs, sigelo-invite/0). Code:
|
|
70
|
+
// The invite secret, alice's code and what they yield (apps/contact/invite.mjs, sigelo-invite/0). Code:
|
|
71
71
|
// version 1 | SHA-256(JCS(A0's genesis)) | secret | exp, u32 BE | relay length | relay | checksum =
|
|
72
72
|
// SHA-256(all before)[0..4]. Its nonce hashes the whole code, so it binds the inviter it names.
|
|
73
73
|
const secret = seed('invite secret'), exp = T0 + DAY, expBytes = new Uint8Array(4);
|
|
@@ -197,7 +197,7 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
|
|
|
197
197
|
if (process.argv.includes('--check')) {
|
|
198
198
|
let cur = '';
|
|
199
199
|
try { cur = readFileSync(OUT, 'utf8'); } catch {}
|
|
200
|
-
if (cur !== text) { console.error('carrier-v0.json differs from the seeds: run node contact/gen-carrier.mjs'); process.exit(1); }
|
|
200
|
+
if (cur !== text) { console.error('carrier-v0.json differs from the seeds: run node apps/contact/gen-carrier.mjs'); process.exit(1); }
|
|
201
201
|
console.log('carrier-v0.json reproduces byte for byte');
|
|
202
202
|
} else { writeFileSync(OUT, text); console.log(`wrote ${OUT.split('/').slice(-2).join('/')} (${text.length} bytes)`); }
|
|
203
203
|
}
|
package/gen-device.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Regenerates fixtures/device-v1.json, byte for byte: contract sigelo-device/1 (device.mjs header).
|
|
3
|
-
// node contact/gen-device.mjs write the file
|
|
4
|
-
// node contact/gen-device.mjs --check exit 1 if the committed file differs
|
|
3
|
+
// node apps/contact/gen-device.mjs write the file
|
|
4
|
+
// node apps/contact/gen-device.mjs --check exit 1 if the committed file differs
|
|
5
5
|
// Independent of device.mjs on purpose: base45, the header, argon2id (node:crypto), the AEAD and the
|
|
6
6
|
// frames are worked out here, so the fixture checks device.mjs (test-device.mjs) instead of echoing
|
|
7
7
|
// it. The material is built with enrol.mjs from a fixed seed: S = SHA-256("sigelo-device/1 root S"),
|
package/gen-envelope.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Regenerates fixtures/envelope-v0.json, byte for byte, from the documented seeds below.
|
|
3
|
-
// node contact/gen-envelope.mjs write the file
|
|
4
|
-
// node contact/gen-envelope.mjs --check exit 1 if the committed file differs
|
|
3
|
+
// node apps/contact/gen-envelope.mjs write the file
|
|
4
|
+
// node apps/contact/gen-envelope.mjs --check exit 1 if the committed file differs
|
|
5
5
|
// Seeds: seed(label) = SHA-256(UTF-8 "sigelo-msg/0 " + label); genesis nonces are the first 16
|
|
6
6
|
// bytes of SHA-256("sigelo-msg/0 nonce " + label); `created` and every time are fixed. Ed25519 is
|
|
7
7
|
// deterministic. X-Wing (@noble/post-quantum 0.7.1 ml_kem768_x25519) takes a 32-byte keygen seed
|
|
@@ -251,7 +251,7 @@ export function build() {
|
|
|
251
251
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
252
252
|
const text = build();
|
|
253
253
|
if (process.argv.includes('--check')) {
|
|
254
|
-
if (readFileSync(OUT, 'utf8') !== text) { console.error('envelope-v0.json differs from the seeds: run node contact/gen-envelope.mjs'); process.exit(1); }
|
|
254
|
+
if (readFileSync(OUT, 'utf8') !== text) { console.error('envelope-v0.json differs from the seeds: run node apps/contact/gen-envelope.mjs'); process.exit(1); }
|
|
255
255
|
console.log('envelope-v0.json reproduces byte for byte');
|
|
256
256
|
} else { writeFileSync(OUT, text); console.log(`wrote ${OUT.split('/').slice(-2).join('/')} (${text.length} bytes)`); }
|
|
257
257
|
}
|
package/gen-invite.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Regenerates fixtures/invite-v0.json, byte for byte, from the documented seeds below.
|
|
3
|
-
// node contact/gen-invite.mjs write the file
|
|
4
|
-
// node contact/gen-invite.mjs --check exit 1 if the committed file differs
|
|
3
|
+
// node apps/contact/gen-invite.mjs write the file
|
|
4
|
+
// node apps/contact/gen-invite.mjs --check exit 1 if the committed file differs
|
|
5
5
|
// Independent of invite.mjs on purpose: code bytes, nonces, topics, keys, proofs and expected
|
|
6
6
|
// results are assembled here from design/relay-plan.md §3 with node:crypto, so the fixture checks
|
|
7
7
|
// invite.mjs instead of echoing it. Needs ts/dist. Ed25519 is deterministic, so fixed seeds,
|
|
@@ -371,6 +371,6 @@ const out = {
|
|
|
371
371
|
const json = JSON.stringify(out, null, 2) + '\n';
|
|
372
372
|
if (process.argv.includes('--check')) {
|
|
373
373
|
let cur = ''; try { cur = readFileSync(OUT, 'utf8'); } catch {}
|
|
374
|
-
if (cur !== json) { console.error('FAIL fixtures/invite-v0.json differs from what the seeds generate: run node contact/gen-invite.mjs'); process.exit(1); }
|
|
374
|
+
if (cur !== json) { console.error('FAIL fixtures/invite-v0.json differs from what the seeds generate: run node apps/contact/gen-invite.mjs'); process.exit(1); }
|
|
375
375
|
console.log(`ok fixtures/invite-v0.json reproduces from the seeds (${out.codes.length} codes, ${parse.length} parse cases, ${steps.length} steps)`);
|
|
376
376
|
} else writeFileSync(OUT, json);
|
package/gen-short.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Regenerates fixtures/short-code-v0.json, byte for byte: contract sigelo-park/0 (short.mjs header).
|
|
3
|
-
// node contact/gen-short.mjs write the file
|
|
4
|
-
// node contact/gen-short.mjs --check exit 1 if the committed file differs
|
|
3
|
+
// node apps/contact/gen-short.mjs write the file
|
|
4
|
+
// node apps/contact/gen-short.mjs --check exit 1 if the committed file differs
|
|
5
5
|
// Independent of short.mjs on purpose: base32, normalisation, hashes and words are worked out here
|
|
6
6
|
// with node:crypto and string handling of their own, so the fixture checks short.mjs (test-short.mjs)
|
|
7
7
|
// instead of echoing it. The word list is read from bip39-english.mjs (data only; its hash is
|
|
@@ -102,7 +102,7 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
|
|
|
102
102
|
if (process.argv.includes('--check')) {
|
|
103
103
|
let cur = '';
|
|
104
104
|
try { cur = readFileSync(OUT, 'utf8'); } catch {}
|
|
105
|
-
if (cur !== text) { console.error('short-code-v0.json differs from the seeds: run node contact/gen-short.mjs'); process.exit(1); }
|
|
105
|
+
if (cur !== text) { console.error('short-code-v0.json differs from the seeds: run node apps/contact/gen-short.mjs'); process.exit(1); }
|
|
106
106
|
console.log('short-code-v0.json reproduces byte for byte');
|
|
107
107
|
} else { writeFileSync(OUT, text); console.log(`wrote ${OUT.split('/').slice(-2).join('/')} (${text.length} bytes)`); }
|
|
108
108
|
}
|