@le-space/build-journey 0.0.0-stage → 0.12.12
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 +124 -2
- package/package.json +36 -4
- package/src/BuildJourney.svelte +1252 -0
- package/src/index.mjs +3 -0
- package/src/model.mjs +421 -0
package/src/index.mjs
ADDED
package/src/model.mjs
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
// The build of a sealed image as one journey in stations, for a view that
|
|
2
|
+
// shows it while it runs (BuildJourney.svelte): the steps
|
|
3
|
+
// `@le-space/sealed-image` reports (`onProgress({ step, data })`) mapped onto
|
|
4
|
+
// stations with typical durations, the facts reported on the way (kept only
|
|
5
|
+
// when they look like what they claim), the time left from what is known,
|
|
6
|
+
// the small steps of a station, what flows where, and the evidence with
|
|
7
|
+
// links to check it. An app may add stations after the build (a VM's start:
|
|
8
|
+
// `startStation`). Only the fetch and a start's steps report real progress;
|
|
9
|
+
// everything else is an estimate. Pure: no DOM, no network, no clock read
|
|
10
|
+
// unless handed in.
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* What the build (and a start after it) reported so far. All optional.
|
|
14
|
+
* @typedef {{
|
|
15
|
+
* vprogram?: string, node?: string, relay?: string, measurement?: string,
|
|
16
|
+
* plainSha256?: string, cid?: string, size?: number, got?: number,
|
|
17
|
+
* lanes?: number, attested?: number, fetchSince?: number, storeHash?: string,
|
|
18
|
+
* host?: string, attempt?: number, processed?: boolean,
|
|
19
|
+
* instanceHash?: string, vmStep?: string, vmMeasurement?: string
|
|
20
|
+
* }} Facts
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* What flows where right now: the path (place keys in order), what it
|
|
25
|
+
* carries, how far it is (0–1) when that is known, and its kind: `data`
|
|
26
|
+
* (pieces), `key` (a secret on its way, drawn as a key) or `report` (an
|
|
27
|
+
* attestation report, drawn as a shield).
|
|
28
|
+
* @typedef {{ path: string[], what: string, share: number | null, kind?: 'data' | 'key' | 'report' }} Flow
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Something that happened at a place, for the picture: a key arrived or
|
|
33
|
+
* signed (`key`, `sign`), a report was checked (`attest`), the hardware
|
|
34
|
+
* measured (`measure`), Aleph stored (`store`). `label` is a text key
|
|
35
|
+
* (`marks.<…>`) with `vars`; `ok` false when the check failed; `now` while
|
|
36
|
+
* it is happening.
|
|
37
|
+
* @typedef {{ at: string, kind: 'key' | 'sign' | 'attest' | 'measure' | 'store', label: string, vars?: Record<string, any>, ok?: boolean, now?: boolean }} Mark
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A station of the journey. The build's five come with their small steps and
|
|
42
|
+
* flows; a station of the app's own brings them as functions.
|
|
43
|
+
* @typedef {{
|
|
44
|
+
* key: string,
|
|
45
|
+
* typical: number,
|
|
46
|
+
* steps?: (f: Facts) => [string, boolean][],
|
|
47
|
+
* flow?: (f: Facts) => Flow,
|
|
48
|
+
* marks?: (f: Facts, current: boolean) => Mark[]
|
|
49
|
+
* }} Station
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/** The typical seconds of the build's stations (measured on Aleph 2026-11-14: builder about 4 min, fetch of about 900 MiB about 9 min). */
|
|
53
|
+
export const BUILD_TYPICAL = Object.freeze({ wake: 240, check: 20, seal: 100, fetch: 540, store: 90 });
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The build's five stations, with other typical seconds where an app knows
|
|
57
|
+
* better (a smaller image, a slower relay).
|
|
58
|
+
* @param {Partial<Record<keyof typeof BUILD_TYPICAL, number>>} [typical]
|
|
59
|
+
* @returns {Station[]}
|
|
60
|
+
*/
|
|
61
|
+
export function buildStations(typical = {}) {
|
|
62
|
+
return Object.entries(BUILD_TYPICAL).map(([key, s]) => ({
|
|
63
|
+
key,
|
|
64
|
+
typical: positive(/** @type {any} */ (typical)[key]) ?? s
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The build's stations at their typical times. */
|
|
69
|
+
export const BUILD_STATIONS = Object.freeze(buildStations());
|
|
70
|
+
|
|
71
|
+
/** A start's steps, in order (a VM from the sealed image: measured, placed, reachable, unlocked, ready). */
|
|
72
|
+
export const START_STEPS = Object.freeze(['measure', 'instance', 'network', 'unlock', 'ready']);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A station after the build: the VM started from the sealed image. Its small
|
|
76
|
+
* steps follow `facts.vmStep` (one of START_STEPS); its flow shows the order
|
|
77
|
+
* for the VM, the VM's report, once the browser has checked it the key that
|
|
78
|
+
* unlocks the VM, and at `ready` the restore from `restoreFrom` when given (a
|
|
79
|
+
* place key, e.g. 'filecoin'). Its marks: the VM's measurement, checked in
|
|
80
|
+
* the browser, and the key in the VM.
|
|
81
|
+
* @param {{ key?: string, typical?: number, restoreFrom?: string | null }} [o]
|
|
82
|
+
* @returns {Station}
|
|
83
|
+
*/
|
|
84
|
+
export function startStation({ key = 'start', typical = 600, restoreFrom = null } = {}) {
|
|
85
|
+
return {
|
|
86
|
+
key,
|
|
87
|
+
typical,
|
|
88
|
+
steps: (f) =>
|
|
89
|
+
START_STEPS.map((s) => [
|
|
90
|
+
s,
|
|
91
|
+
Boolean(f.vmStep && START_STEPS.indexOf(f.vmStep) > START_STEPS.indexOf(s))
|
|
92
|
+
]),
|
|
93
|
+
flow: (f) =>
|
|
94
|
+
f.vmStep === 'unlock'
|
|
95
|
+
? f.vmMeasurement
|
|
96
|
+
? { path: ['browser', 'relay', 'node'], what: 'unlockKey', share: null, kind: 'key' }
|
|
97
|
+
: { path: ['node', 'relay', 'browser'], what: 'vmReport', share: null, kind: 'report' }
|
|
98
|
+
: f.vmStep === 'ready' && restoreFrom
|
|
99
|
+
? { path: [restoreFrom, 'node'], what: 'backup', share: null, kind: 'data' }
|
|
100
|
+
: { path: ['browser', 'aleph', 'node'], what: 'instance', share: null, kind: 'data' },
|
|
101
|
+
marks: (f, current) => {
|
|
102
|
+
const at = f.vmStep ? START_STEPS.indexOf(f.vmStep) : -1;
|
|
103
|
+
/** @type {Mark[]} */
|
|
104
|
+
const out = [];
|
|
105
|
+
if (f.vmMeasurement) {
|
|
106
|
+
out.push({ at: 'node', kind: 'measure', label: 'marks.vmMeasured', ok: true });
|
|
107
|
+
out.push({ at: 'browser', kind: 'attest', label: 'marks.vmAttested', ok: true });
|
|
108
|
+
} else if (current && f.vmStep === 'unlock')
|
|
109
|
+
out.push({ at: 'node', kind: 'measure', label: 'marks.vmMeasuring', now: true });
|
|
110
|
+
if (at > START_STEPS.indexOf('unlock')) out.push({ at: 'node', kind: 'key', label: 'marks.unlocked' });
|
|
111
|
+
else if (current && f.vmStep === 'unlock' && f.vmMeasurement)
|
|
112
|
+
out.push({ at: 'node', kind: 'key', label: 'marks.unlocking', now: true });
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** A build step (`onProgress({ step })`) as a station, or null. @param {string} step */
|
|
119
|
+
export function stationOfBuildStep(step) {
|
|
120
|
+
if (step === 'start') return 'wake';
|
|
121
|
+
if (step === 'attest') return 'check';
|
|
122
|
+
if (step === 'build') return 'seal';
|
|
123
|
+
if (step === 'fetch') return 'fetch';
|
|
124
|
+
if (step === 'sign' || step === 'upload' || step === 'confirm') return 'store';
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const HEX64 = /^[0-9a-f]{64}$/;
|
|
129
|
+
const HEXISH = /^[0-9a-f]{32,128}$/i;
|
|
130
|
+
const CIDISH = /^[A-Za-z0-9]{40,64}$/;
|
|
131
|
+
const RELAY = /^(wss?:\/\/)?[a-z0-9.-]{1,253}(:\d{1,5})?(\/[\w/-]*)?$/i;
|
|
132
|
+
const HOST = /^(https?:\/\/)?[a-z0-9.-]{1,253}(:\d{1,5})?\/?$/i;
|
|
133
|
+
const COMMIT = /^[0-9a-f]{7,40}$/;
|
|
134
|
+
|
|
135
|
+
/** @param {unknown} v */
|
|
136
|
+
function positive(v) {
|
|
137
|
+
return typeof v === 'number' && Number.isFinite(v) && v >= 0 ? v : undefined;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* What was reported so far, merged with one more report: only values that
|
|
142
|
+
* look like what they claim are kept (they are shown, never interpreted).
|
|
143
|
+
* The fetch's start is noted at its first report, for its speed.
|
|
144
|
+
* @param {Facts} facts @param {string} step @param {Record<string, any>} [data] @param {number} [now]
|
|
145
|
+
* @returns {Facts}
|
|
146
|
+
*/
|
|
147
|
+
export function withFacts(facts, step, data = {}, now = Date.now()) {
|
|
148
|
+
/** @type {Record<string, any>} */
|
|
149
|
+
const out = { ...facts };
|
|
150
|
+
const text = (/** @type {unknown} */ v, /** @type {RegExp} */ re) =>
|
|
151
|
+
typeof v === 'string' && re.test(v) ? v : undefined;
|
|
152
|
+
const set = (/** @type {string} */ k, /** @type {unknown} */ v) => {
|
|
153
|
+
if (v !== undefined) out[k] = v;
|
|
154
|
+
};
|
|
155
|
+
const d = data ?? {};
|
|
156
|
+
set('vprogram', text(d.vprogram, HEX64));
|
|
157
|
+
set('node', text(d.node, HEX64));
|
|
158
|
+
set('relay', text(d.relay, RELAY));
|
|
159
|
+
set('measurement', text(d.measurement, HEXISH));
|
|
160
|
+
set('plainSha256', text(d.plainSha256, HEX64));
|
|
161
|
+
set('cid', text(d.cid, CIDISH));
|
|
162
|
+
set('storeHash', text(d.storeHash, HEX64));
|
|
163
|
+
set('host', text(d.host, HOST));
|
|
164
|
+
set('instanceHash', text(d.instanceHash, HEX64));
|
|
165
|
+
set('vmMeasurement', text(d.vmMeasurement, HEXISH));
|
|
166
|
+
set('vmStep', START_STEPS.includes(d.vmStep) ? d.vmStep : undefined);
|
|
167
|
+
for (const k of ['size', 'got', 'lanes', 'attested', 'attempt']) set(k, positive(d[k]));
|
|
168
|
+
if (d.processed === true) out.processed = true;
|
|
169
|
+
if (step === 'fetch' && out.fetchSince == null) out.fetchSince = now;
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The share of the fetch done, 0–100, or null. @param {Facts} f */
|
|
174
|
+
export function fetchPercent(f) {
|
|
175
|
+
return f.size && f.got != null ? Math.min(100, Math.round((f.got / f.size) * 100)) : null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** MiB/s since the fetch began, or null. @param {Facts} f @param {number} now */
|
|
179
|
+
export function fetchRate(f, now) {
|
|
180
|
+
if (f.fetchSince == null || !f.got) return null;
|
|
181
|
+
const s = (now - f.fetchSince) / 1000;
|
|
182
|
+
return s > 2 ? f.got / 1048576 / s : null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** @param {Station[]} stations @param {string} key */
|
|
186
|
+
const indexOf = (stations, key) => stations.findIndex((s) => s.key === key);
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Where the journey stands: the station's index, the share done, the seconds
|
|
190
|
+
* left and when it is expected to end. The fetch counts by its bytes (or
|
|
191
|
+
* `fetchPct` when only a percentage is known) and, once measured, its speed;
|
|
192
|
+
* the others count their typical time down, and an overrun keeps a minute in
|
|
193
|
+
* hand instead of saying "0".
|
|
194
|
+
* @param {{ stations?: Station[], station: string, since: number, now: number, facts?: Facts, fetchPct?: number | null, done?: boolean }} a
|
|
195
|
+
*/
|
|
196
|
+
export function journey({ stations = BUILD_STATIONS, station, since, now, facts = {}, fetchPct = null, done = false }) {
|
|
197
|
+
const total = stations.reduce((a, s) => a + s.typical, 0);
|
|
198
|
+
if (done) return { index: stations.length, share: 1, left: 0, ends: now, total };
|
|
199
|
+
const index = Math.max(0, indexOf(stations, station));
|
|
200
|
+
const here = stations[index];
|
|
201
|
+
const inStation = Math.max(0, (now - since) / 1000);
|
|
202
|
+
const pct = here.key === 'fetch' ? (fetchPercent(facts) ?? fetchPct) : null;
|
|
203
|
+
const doneHere = pct != null ? (here.typical * pct) / 100 : Math.min(inStation, here.typical * 0.95);
|
|
204
|
+
const rate = here.key === 'fetch' ? fetchRate(facts, now) : null;
|
|
205
|
+
const measured = rate && facts.size && facts.got != null ? (facts.size - facts.got) / 1048576 / rate : null;
|
|
206
|
+
const before = stations.slice(0, index).reduce((a, s) => a + s.typical, 0);
|
|
207
|
+
const after = stations.slice(index + 1).reduce((a, s) => a + s.typical, 0);
|
|
208
|
+
const left = Math.max(60, (measured ?? here.typical - doneHere) + after);
|
|
209
|
+
return {
|
|
210
|
+
index,
|
|
211
|
+
share: total ? Math.min(0.99, (before + doneHere) / total) : 0,
|
|
212
|
+
left,
|
|
213
|
+
ends: now + left * 1000,
|
|
214
|
+
total
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** @type {Record<string, (f: Facts) => [string, boolean][]>} */
|
|
219
|
+
const BUILD_STEPS = {
|
|
220
|
+
wake: (f) => [
|
|
221
|
+
['ask', Boolean(f.vprogram)],
|
|
222
|
+
['boot', Boolean(f.relay || f.measurement)],
|
|
223
|
+
['answer', Boolean(f.relay || f.measurement)]
|
|
224
|
+
],
|
|
225
|
+
check: (f) => [
|
|
226
|
+
['relay', Boolean(f.relay)],
|
|
227
|
+
['report', Boolean(f.measurement)],
|
|
228
|
+
['match', Boolean(f.measurement)]
|
|
229
|
+
],
|
|
230
|
+
seal: (f) => [
|
|
231
|
+
['send', Boolean(f.plainSha256 || f.cid)],
|
|
232
|
+
['verify', Boolean(f.cid)],
|
|
233
|
+
['luks', Boolean(f.cid)]
|
|
234
|
+
],
|
|
235
|
+
fetch: (f) => [
|
|
236
|
+
['lanes', Boolean(f.attested)],
|
|
237
|
+
['bytes', Boolean(f.size && f.got != null && f.got >= f.size)]
|
|
238
|
+
],
|
|
239
|
+
store: (f) => [
|
|
240
|
+
['sign', Boolean(f.storeHash)],
|
|
241
|
+
['upload', Boolean(f.processed)],
|
|
242
|
+
['confirm', Boolean(f.processed)]
|
|
243
|
+
]
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* The small steps of a station, each 'done', 'active' (blinking) or 'next':
|
|
248
|
+
* done when a report says so or the journey is past the station; the first
|
|
249
|
+
* step not done of the current station is the active one.
|
|
250
|
+
* @param {{ stations?: Station[], station: string, current?: string, facts?: Facts, done?: boolean }} a
|
|
251
|
+
* @returns {{ key: string, state: 'done' | 'active' | 'next' }[]}
|
|
252
|
+
*/
|
|
253
|
+
export function substeps({ stations = BUILD_STATIONS, station, current = station, facts = {}, done = false }) {
|
|
254
|
+
const s = stations.find((x) => x.key === station);
|
|
255
|
+
const rows = (s?.steps ?? BUILD_STEPS[station])?.(facts) ?? [];
|
|
256
|
+
const past = done || indexOf(stations, current) > indexOf(stations, station);
|
|
257
|
+
let active = false;
|
|
258
|
+
return rows.map(([key, ok]) => {
|
|
259
|
+
if (past || ok) return { key, state: /** @type {const} */ ('done') };
|
|
260
|
+
if (station === current && !active) {
|
|
261
|
+
active = true;
|
|
262
|
+
return { key, state: /** @type {const} */ ('active') };
|
|
263
|
+
}
|
|
264
|
+
return { key, state: /** @type {const} */ ('next') };
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* What flows where right now, for the picture.
|
|
270
|
+
* @param {{ stations?: Station[], station: string, facts?: Facts, fetchPct?: number | null }} a
|
|
271
|
+
* @returns {Flow}
|
|
272
|
+
*/
|
|
273
|
+
export function flowNow({ stations = BUILD_STATIONS, station, facts = {}, fetchPct = null }) {
|
|
274
|
+
const own = stations.find((x) => x.key === station)?.flow;
|
|
275
|
+
if (own) return own(facts);
|
|
276
|
+
if (station === 'wake') return { path: ['browser', 'aleph', 'node'], what: 'program', share: null, kind: 'data' };
|
|
277
|
+
if (station === 'check') return { path: ['node', 'relay', 'browser'], what: 'report', share: null, kind: 'report' };
|
|
278
|
+
if (station === 'seal') return { path: ['browser', 'relay', 'node'], what: 'passphrase', share: null, kind: 'key' };
|
|
279
|
+
if (station === 'fetch') {
|
|
280
|
+
const pct = fetchPercent(facts) ?? fetchPct;
|
|
281
|
+
return { path: ['node', 'relay', 'browser'], what: 'pieces', share: pct == null ? null : pct / 100, kind: 'data' };
|
|
282
|
+
}
|
|
283
|
+
return { path: ['browser', 'aleph'], what: 'image', share: facts.processed ? 1 : null, kind: 'data' };
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* What happened where so far, for the picture: the hardware's measurement at
|
|
288
|
+
* the node and the browser's check of it, the key that seals the image in the
|
|
289
|
+
* node, the connections of the fetch each checked, the STORE signed in the
|
|
290
|
+
* browser and stored on Aleph; then what a station of the app's own adds.
|
|
291
|
+
* Only what a report says happened, or what happens in the current station
|
|
292
|
+
* (`now`). One mark per place and kind, the latest wins.
|
|
293
|
+
* @param {{ stations?: Station[], station: string, facts?: Facts, builder?: BuilderPin, done?: boolean }} a
|
|
294
|
+
* @returns {Mark[]}
|
|
295
|
+
*/
|
|
296
|
+
export function marksNow({ stations = BUILD_STATIONS, station, facts: f = {}, builder = null, done = false }) {
|
|
297
|
+
const at = done ? stations.length : Math.max(0, indexOf(stations, station));
|
|
298
|
+
const past = (/** @type {string} */ key) => indexOf(stations, key) >= 0 && indexOf(stations, key) < at;
|
|
299
|
+
const here = (/** @type {string} */ key) => !done && key === station;
|
|
300
|
+
/** @type {Mark[]} */
|
|
301
|
+
const out = [];
|
|
302
|
+
if (f.measurement) {
|
|
303
|
+
const ok = !builder?.measurements?.length || builder.measurements.includes(f.measurement);
|
|
304
|
+
out.push({ at: 'node', kind: 'measure', label: 'marks.measured', ok });
|
|
305
|
+
out.push({ at: 'browser', kind: 'attest', label: ok ? 'marks.attested' : 'marks.mismatch', ok });
|
|
306
|
+
} else if (here('check')) out.push({ at: 'node', kind: 'measure', label: 'marks.measuring', now: true });
|
|
307
|
+
if (f.cid || past('seal')) out.push({ at: 'node', kind: 'key', label: 'marks.sealed' });
|
|
308
|
+
else if (here('seal')) out.push({ at: 'node', kind: 'key', label: 'marks.sealing', now: true });
|
|
309
|
+
if (f.attested && (here('fetch') || past('fetch')))
|
|
310
|
+
out.push({ at: 'browser', kind: 'attest', label: 'marks.lanes', vars: { count: f.attested }, ok: true, now: here('fetch') });
|
|
311
|
+
if (f.storeHash) out.push({ at: 'browser', kind: 'sign', label: 'marks.signed' });
|
|
312
|
+
else if (here('store')) out.push({ at: 'browser', kind: 'sign', label: 'marks.signing', now: true });
|
|
313
|
+
if (f.processed) out.push({ at: 'aleph', kind: 'store', label: 'marks.stored', ok: true });
|
|
314
|
+
for (const s of stations) if (s.marks && (s.key === station || past(s.key))) out.push(...s.marks(f, here(s.key)));
|
|
315
|
+
/** @type {Map<string, Mark>} */
|
|
316
|
+
const latest = new Map();
|
|
317
|
+
for (const m of out) {
|
|
318
|
+
latest.delete(`${m.at} ${m.kind}`);
|
|
319
|
+
latest.set(`${m.at} ${m.kind}`, m);
|
|
320
|
+
}
|
|
321
|
+
return [...latest.values()];
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* What an app pins of its builder, as `@le-space/sealed-image` takes it: the
|
|
326
|
+
* plain image (SHA-256, its STORE on Aleph, the commit it was built from),
|
|
327
|
+
* the measurements the hardware must show, and the node.
|
|
328
|
+
* @typedef {{ plain?: { sha256?: string, store?: string, commit?: string }, measurements?: string[], crn?: string } | null | undefined} BuilderPin
|
|
329
|
+
*/
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Where evidence can be checked: `aleph` the base of a message by its hash
|
|
333
|
+
* (`${aleph}/${hash}`), `repo` the source repository of the plain image
|
|
334
|
+
* (`${repo}/commit/${commit}`), `expected` where the app pins the expected
|
|
335
|
+
* measurement.
|
|
336
|
+
* @typedef {{ aleph?: string | null, repo?: string | null, expected?: string | null }} EvidenceLinks
|
|
337
|
+
*/
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* @typedef {{ key: string, value: string, href: string | null, ok?: boolean }} Evidence
|
|
341
|
+
*/
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* The evidence gathered so far, each with its value and a link to where it
|
|
345
|
+
* can be checked. Only values that look like what they claim are shown, and
|
|
346
|
+
* only those become links. `ok` on the measurement: it is one the app pins.
|
|
347
|
+
* @param {Facts} f @param {BuilderPin} builder @param {EvidenceLinks} [at]
|
|
348
|
+
* @returns {Evidence[]}
|
|
349
|
+
*/
|
|
350
|
+
export function evidence(f, builder, at = {}) {
|
|
351
|
+
/** @type {Evidence[]} */
|
|
352
|
+
const rows = [];
|
|
353
|
+
const msg = (/** @type {string | undefined} */ h) => (at.aleph && h && HEX64.test(h) ? `${at.aleph}/${h}` : null);
|
|
354
|
+
const commit = builder?.plain?.commit;
|
|
355
|
+
if (commit && COMMIT.test(commit))
|
|
356
|
+
rows.push({ key: 'commit', value: commit, href: at.repo ? `${at.repo}/commit/${commit}` : null });
|
|
357
|
+
const plain = builder?.plain?.sha256 ?? f.plainSha256;
|
|
358
|
+
if (plain && HEX64.test(plain)) rows.push({ key: 'plain', value: plain, href: msg(builder?.plain?.store) });
|
|
359
|
+
const expected = builder?.measurements?.find((m) => HEXISH.test(m));
|
|
360
|
+
if (expected) rows.push({ key: 'expected', value: expected, href: at.expected ?? null });
|
|
361
|
+
if (f.vprogram) rows.push({ key: 'vprogram', value: f.vprogram, href: msg(f.vprogram) });
|
|
362
|
+
const node = f.node ?? builder?.crn;
|
|
363
|
+
if (node && HEX64.test(node)) rows.push({ key: 'node', value: node, href: null });
|
|
364
|
+
if (f.relay && RELAY.test(f.relay)) rows.push({ key: 'relay', value: f.relay.replace(/^wss?:\/\//, ''), href: null });
|
|
365
|
+
if (f.measurement && HEXISH.test(f.measurement))
|
|
366
|
+
rows.push({
|
|
367
|
+
key: 'measured',
|
|
368
|
+
value: f.measurement,
|
|
369
|
+
href: null,
|
|
370
|
+
ok: !builder?.measurements?.length || builder.measurements.includes(f.measurement)
|
|
371
|
+
});
|
|
372
|
+
if (f.cid && CIDISH.test(f.cid)) rows.push({ key: 'cid', value: f.cid, href: null });
|
|
373
|
+
if (f.storeHash) rows.push({ key: 'store', value: f.storeHash, href: msg(f.storeHash), ...(f.processed ? { ok: true } : {}) });
|
|
374
|
+
if (f.instanceHash) rows.push({ key: 'instance', value: f.instanceHash, href: msg(f.instanceHash) });
|
|
375
|
+
if (f.vmMeasurement && HEXISH.test(f.vmMeasurement)) rows.push({ key: 'vmMeasured', value: f.vmMeasurement, href: null, ok: true });
|
|
376
|
+
return rows;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** Evidence the build itself reported (not what the app pins): shown once there is any. @param {Evidence[]} rows */
|
|
380
|
+
export const reported = (rows) => rows.filter((r) => !['commit', 'plain', 'expected', 'node'].includes(r.key));
|
|
381
|
+
|
|
382
|
+
/** The hardware the checks rest on, with the makers' pages. */
|
|
383
|
+
export const HARDWARE = Object.freeze([
|
|
384
|
+
Object.freeze({ key: 'sev', href: 'https://www.amd.com/en/developer/sev.html' }),
|
|
385
|
+
Object.freeze({ key: 'epyc', href: 'https://www.amd.com/en/products/processors/server/epyc.html' })
|
|
386
|
+
]);
|
|
387
|
+
|
|
388
|
+
/** The places of the flow picture and where they sit (viewBox 720×250). */
|
|
389
|
+
export const PLACES = Object.freeze({
|
|
390
|
+
browser: Object.freeze(/** @type {[number, number]} */ ([100, 120])),
|
|
391
|
+
relay: Object.freeze(/** @type {[number, number]} */ ([360, 44])),
|
|
392
|
+
node: Object.freeze(/** @type {[number, number]} */ ([620, 120])),
|
|
393
|
+
aleph: Object.freeze(/** @type {[number, number]} */ ([360, 196]))
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
/** The lines between the places. */
|
|
397
|
+
export const LINKS = Object.freeze([
|
|
398
|
+
['browser', 'relay'],
|
|
399
|
+
['relay', 'node'],
|
|
400
|
+
['browser', 'aleph'],
|
|
401
|
+
['aleph', 'node']
|
|
402
|
+
]);
|
|
403
|
+
|
|
404
|
+
/** The SVG path through the places, for the moving packets. @param {string[]} path @param {Record<string, readonly number[]>} at */
|
|
405
|
+
export function pathOf(path, at) {
|
|
406
|
+
return path
|
|
407
|
+
.filter((p) => at[p])
|
|
408
|
+
.map((p, i) => `${i ? 'L' : 'M'}${at[p][0]} ${at[p][1]}`)
|
|
409
|
+
.join(' ');
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/** Whether a line between two places is on the path. @param {string[]} path @param {string} a @param {string} b */
|
|
413
|
+
export function onPath(path, a, b) {
|
|
414
|
+
return path.some((p, i) => i > 0 && ((path[i - 1] === a && p === b) || (path[i - 1] === b && p === a)));
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** A long hash, shortened for the eye. @param {string} v */
|
|
418
|
+
export const short = (v) => (v.length > 20 ? `${v.slice(0, 10)}…${v.slice(-6)}` : v);
|
|
419
|
+
|
|
420
|
+
/** Whole minutes, at least one. @param {number} s */
|
|
421
|
+
export const minutes = (s) => Math.max(1, Math.round(s / 60));
|