tinfoil 0.10.1 → 0.10.9

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.
@@ -2,33 +2,50 @@
2
2
  * VERIFIER COMPONENT OVERVIEW
3
3
  * ==========================
4
4
  *
5
- * This implementation performs three security checks entirely on the client using
6
- * a Go WebAssembly module, and exposes a small TypeScript API around it.
5
+ * This implementation performs end-to-end enclave and code verification entirely on the
6
+ * client using a Go WebAssembly module, and exposes a small TypeScript API around it.
7
7
  *
8
- * 1) REMOTE ATTESTATION (Enclave Verification)
9
- * - Invokes Go WASM `verifyEnclave(host)` against the target enclave hostname
10
- * - Verifies vendor certificate chains inside WASM (AMD SEV-SNP / Intel TDX)
11
- * - Returns the enclave's runtime measurement and at least one public key (TLS fingerprint and/or HPKE)
12
- * - Falls back to TLS-only verification if only TLS key is available (Node.js only)
8
+ * UNIFIED VERIFICATION FLOW
9
+ * The primary API is `verify()`, which invokes the Go WASM `verify(enclaveHost, repo)`
10
+ * function that performs all verification steps atomically:
11
+ *
12
+ * 1) DIGEST FETCH
13
+ * - Fetches the latest release digest from GitHub
14
+ * - Uses Tinfoil GitHub proxy (https://api-github-proxy.tinfoil.sh) to avoid rate limits
13
15
  *
14
16
  * 2) CODE INTEGRITY (Release Verification)
15
- * - Fetches the latest release notes via the Tinfoil GitHub proxy and extracts a digest
16
- * (endpoint: https://api-github-proxy.tinfoil.sh)
17
- * - Invokes Go WASM `verifyCode(configRepo, digest)` to obtain the expected code measurement
18
- * - The Go implementation verifies provenance using Sigstore/Rekor for GitHub Actions builds
17
+ * - Verifies code provenance using Sigstore/Rekor for GitHub Actions builds
18
+ * - Returns the expected code measurement for the release
19
+ *
20
+ * 3) REMOTE ATTESTATION (Enclave Verification)
21
+ * - Performs runtime attestation against the target enclave hostname
22
+ * - Verifies vendor certificate chains inside WASM (AMD SEV-SNP / Intel TDX)
23
+ * - Returns the enclave's runtime measurement and cryptographic keys (TLS fingerprint and HPKE)
24
+ *
25
+ * 4) HARDWARE VERIFICATION (for TDX platforms)
26
+ * - Fetches and verifies TDX platform measurements if required
27
+ * - Validates hardware attestation against expected measurements
28
+ *
29
+ * 5) CODE CONSISTENCY (Measurement Comparison)
30
+ * - Compares the runtime measurement with the expected code measurement
31
+ * - Uses platform-aware comparison rules for different TEE types
19
32
  *
20
- * 3) CODE CONSISTENCY (Measurement Comparison)
21
- * - Compares the runtime measurement with the expected code measurement using
22
- * platform-aware rules implemented in `compareMeasurements()`
33
+ * ERROR HANDLING
34
+ * When verification fails, errors are prefixed with the failing step:
35
+ * - `fetchDigest:` - Failed to fetch GitHub release digest
36
+ * - `verifyCode:` - Failed to verify code provenance
37
+ * - `verifyEnclave:` - Failed runtime attestation
38
+ * - `verifyHardware:` - Failed TDX hardware verification
39
+ * - `validateTLS:` - TLS public key validation failed
40
+ * - `measurements:` - Measurement comparison failed
23
41
  *
24
42
  * RUNTIME AND DELIVERY
25
43
  * - All verification executes locally via WebAssembly (Go → WASM)
26
44
  * - WASM loader: `wasm-exec.js`
27
- * - WASM module URL: https://tinfoilsh.github.io/verifier-js/tinfoil-verifier.wasm
45
+ * - WASM module URL: https://tinfoilsh.github.io/verifier/tinfoil-verifier.wasm
28
46
  * - Works in Node 20+ and modern browsers with lightweight polyfills for
29
47
  * `performance`, `TextEncoder`/`TextDecoder`, and `crypto.getRandomValues`
30
48
  * - Go stdout/stderr is suppressed by default; toggle via `suppressWasmLogs()`
31
- * - Module auto-initializes the WASM runtime on import
32
49
  *
33
50
  * PROXIES AND TRUST
34
51
  * - GitHub proxy is used only to avoid rate limits; the WASM logic independently
@@ -36,19 +53,16 @@
36
53
  * - AMD KDS access may be proxied within the WASM for availability; AMD roots are
37
54
  * embedded and the full chain is verified in Go to prevent forgery
38
55
  *
39
- * SUPPORTED PLATFORMS AND PREDICATES
40
- * - Predicate types supported by this client: SNP/TDX multi-platform v1,
41
- * TDX guest v1, SEV-SNP guest v1
42
- * - See `compareMeasurements()` for exact register mapping rules
56
+ * SUPPORTED PLATFORMS
57
+ * - AMD SEV-SNP
58
+ * - Intel TDX (with hardware platform verification)
59
+ * - Predicate types: SNP/TDX multi-platform v1, TDX guest v1/v2, SEV-SNP guest v1
43
60
  *
44
61
  * PUBLIC API (this module)
45
- * - `new Verifier({ serverURL?, configRepo? })`
46
- * - `verify()` → full end-to-end verification and attestation response
47
- * - `verifyEnclave(host?)` → runtime attestation only
48
- * - `verifyCode(configRepo, digest)` → expected measurement for a specific release
49
- * - `compareMeasurements(code, runtime)` → predicate-based comparison
50
- * - `fetchLatestDigest(configRepo?)` → release digest via proxy
51
- * - `suppressWasmLogs(suppress?)` → control WASM log output
62
+ * - `new Verifier({ serverURL, configRepo? })`
63
+ * - `verify()` → Promise<AttestationResponse> - full end-to-end verification returning cryptographic keys and measurement
64
+ * - `getVerificationDocument()` → VerificationDocument | undefined - detailed step-by-step verification results
65
+ * - `suppressWasmLogs(suppress?)` → void - control WASM log output
52
66
  */
53
67
  import { TINFOIL_CONFIG } from "./config.mjs";
54
68
  // Use native fetch and TextEncoder/TextDecoder
@@ -86,112 +100,19 @@ function getTextDecoder() {
86
100
  }
87
101
  const nodeRequire = createNodeRequire();
88
102
  let wasmExecLoader = null;
89
- // Platform type constants
90
- // See https://github.com/tinfoilsh/verifier/
91
- const PLATFORM_TYPES = {
92
- SNP_TDX_MULTI_PLATFORM_V1: "https://tinfoil.sh/predicate/snp-tdx-multiplatform/v1",
93
- TDX_GUEST_V1: "https://tinfoil.sh/predicate/tdx-guest/v1",
94
- TDX_GUEST_V2: "https://tinfoil.sh/predicate/tdx-guest/v2",
95
- SEV_GUEST_V1: "https://tinfoil.sh/predicate/sev-snp-guest/v1",
96
- SEV_GUEST_V2: "https://tinfoil.sh/predicate/sev-snp-guest/v2",
97
- HARDWARE_MEASUREMENTS_V1: "https://tinfoil.sh/predicate/hardware-measurements/v1",
98
- };
99
- const MEASUREMENT_ERROR_MESSAGES = {
100
- FORMAT_MISMATCH: "attestation format mismatch",
101
- MEASUREMENT_MISMATCH: "measurement mismatch",
102
- RTMR1_MISMATCH: "RTMR1 mismatch",
103
- RTMR2_MISMATCH: "RTMR2 mismatch",
104
- FEW_REGISTERS: "fewer registers than expected",
105
- MULTI_PLATFORM_MISMATCH: "multi-platform measurement mismatch",
106
- MULTI_PLATFORM_SEV_SNP_MISMATCH: "multi-platform SEV-SNP measurement mismatch",
107
- };
108
- function registersEqual(a, b) {
109
- if (a.length !== b.length) {
110
- return false;
111
- }
112
- return a.every((value, index) => value === b[index]);
113
- }
114
- function compareMeasurementsError(codeMeasurement, runtimeMeasurement) {
115
- if (codeMeasurement.type === PLATFORM_TYPES.SNP_TDX_MULTI_PLATFORM_V1 &&
116
- runtimeMeasurement.type === PLATFORM_TYPES.SNP_TDX_MULTI_PLATFORM_V1) {
117
- if (!registersEqual(codeMeasurement.registers, runtimeMeasurement.registers)) {
118
- return new Error(MEASUREMENT_ERROR_MESSAGES.MULTI_PLATFORM_MISMATCH);
119
- }
120
- return null;
121
- }
122
- if (runtimeMeasurement.type === PLATFORM_TYPES.SNP_TDX_MULTI_PLATFORM_V1) {
123
- return compareMeasurementsError(runtimeMeasurement, codeMeasurement);
124
- }
125
- if (codeMeasurement.type === PLATFORM_TYPES.SNP_TDX_MULTI_PLATFORM_V1) {
126
- switch (runtimeMeasurement.type) {
127
- case PLATFORM_TYPES.TDX_GUEST_V1:
128
- case PLATFORM_TYPES.TDX_GUEST_V2: {
129
- if (codeMeasurement.registers.length < 3 || runtimeMeasurement.registers.length < 4) {
130
- return new Error(MEASUREMENT_ERROR_MESSAGES.FEW_REGISTERS);
131
- }
132
- const expectedRtmr1 = codeMeasurement.registers[1];
133
- const expectedRtmr2 = codeMeasurement.registers[2];
134
- const actualRtmr1 = runtimeMeasurement.registers[2];
135
- const actualRtmr2 = runtimeMeasurement.registers[3];
136
- if (expectedRtmr1 !== actualRtmr1) {
137
- return new Error(MEASUREMENT_ERROR_MESSAGES.RTMR1_MISMATCH);
138
- }
139
- if (expectedRtmr2 !== actualRtmr2) {
140
- return new Error(MEASUREMENT_ERROR_MESSAGES.RTMR2_MISMATCH);
141
- }
142
- return null;
143
- }
144
- case PLATFORM_TYPES.SEV_GUEST_V1:
145
- case PLATFORM_TYPES.SEV_GUEST_V2: {
146
- if (codeMeasurement.registers.length < 1 || runtimeMeasurement.registers.length < 1) {
147
- return new Error(MEASUREMENT_ERROR_MESSAGES.FEW_REGISTERS);
148
- }
149
- const expectedSevSnp = codeMeasurement.registers[0];
150
- const actualSevSnp = runtimeMeasurement.registers[0];
151
- if (expectedSevSnp !== actualSevSnp) {
152
- return new Error(MEASUREMENT_ERROR_MESSAGES.MULTI_PLATFORM_SEV_SNP_MISMATCH);
153
- }
154
- return null;
155
- }
156
- default:
157
- return new Error(`unsupported enclave platform for multi-platform code measurements: ${runtimeMeasurement.type}`);
158
- }
159
- }
160
- if (codeMeasurement.type !== runtimeMeasurement.type) {
161
- return new Error(MEASUREMENT_ERROR_MESSAGES.FORMAT_MISMATCH);
162
- }
163
- if (!registersEqual(codeMeasurement.registers, runtimeMeasurement.registers)) {
164
- return new Error(MEASUREMENT_ERROR_MESSAGES.MEASUREMENT_MISMATCH);
165
- }
166
- return null;
167
- }
168
- export function compareMeasurementsDetailed(codeMeasurement, runtimeMeasurement) {
169
- const error = compareMeasurementsError(codeMeasurement, runtimeMeasurement);
170
- if (error) {
171
- return { match: false, error };
172
- }
173
- return { match: true };
174
- }
175
- /**
176
- * Compare two measurements according to platform-specific rules
177
- * This is predicate function for comparing attestation measurements
178
- * taken from https://github.com/tinfoilsh/verifier/blob/main/attestation/attestation.go
179
- *
180
- * @param codeMeasurement - Expected measurement from code attestation
181
- * @param runtimeMeasurement - Actual measurement from runtime attestation
182
- * @returns true if measurements match according to platform rules
183
- */
184
- export function compareMeasurements(codeMeasurement, runtimeMeasurement) {
185
- return compareMeasurementsError(codeMeasurement, runtimeMeasurement) === null;
186
- }
187
103
  /**
188
104
  * Verifier performs attestation verification for Tinfoil enclaves
189
105
  *
190
- * The verifier loads a WebAssembly module that:
106
+ * The verifier loads a WebAssembly module (compiled from Go) that performs
107
+ * end-to-end attestation verification:
191
108
  * 1. Fetches the latest code release digest from GitHub
192
- * 2. Performs runtime attestation against the enclave
193
- * 3. Performs code attestation using the digest
194
- * 4. Compares measurements using platform-specific logic
109
+ * 2. Verifies code provenance using Sigstore/Rekor
110
+ * 3. Performs runtime attestation against the enclave
111
+ * 4. Verifies hardware measurements (for TDX platforms)
112
+ * 5. Compares code and runtime measurements using platform-specific logic
113
+ *
114
+ * Primary method: verify() - Returns AttestationResponse with cryptographic keys
115
+ * Verification details: getVerificationDocument() - Returns step-by-step results
195
116
  */
196
117
  export class Verifier {
197
118
  constructor(options) {
@@ -258,171 +179,46 @@ export class Verifier {
258
179
  }
259
180
  }
260
181
  /**
261
- * Fetch the latest release digest from GitHub
262
- * @param configRepo - Repository name (e.g., "tinfoilsh/confidential-model-router")
263
- * @returns The digest hash
264
- */
265
- async fetchLatestDigest(configRepo) {
266
- // GitHub Proxy Note:
267
- // We use api-github-proxy.tinfoil.sh instead of the direct GitHub API to avoid
268
- // rate limiting that could degrade UX. The proxy caches responses while the
269
- // integrity of the data is independently verified in `verifyCode` via
270
- // Sigstore transparency logs (Rekor). Using the proxy therefore does not
271
- // weaken security.
272
- const targetRepo = configRepo || this.configRepo;
273
- const fetchFn = getFetch();
274
- const releaseResponse = await fetchFn(`https://api-github-proxy.tinfoil.sh/repos/${targetRepo}/releases/latest`, {
275
- headers: {
276
- Accept: "application/vnd.github.v3+json",
277
- "User-Agent": "tinfoil-node-client",
278
- },
279
- });
280
- if (!releaseResponse.ok) {
281
- throw new Error(`GitHub API request failed: ${releaseResponse.status} ${releaseResponse.statusText}`);
282
- }
283
- const releaseData = (await releaseResponse.json());
284
- // Extract digest from release notes
285
- const digestRegex = /Digest: `([a-f0-9]{64})`/;
286
- const digestMatch = releaseData.body?.match(digestRegex);
287
- if (!digestMatch) {
288
- throw new Error("Could not find digest in release notes");
289
- }
290
- const digest = digestMatch[1];
291
- return digest;
292
- }
293
- /**
294
- * Perform runtime attestation on the enclave
295
- * @param enclaveHost - The enclave hostname
296
- * @returns Attestation response with measurement and keys
297
- */
298
- async verifyEnclave(enclaveHost) {
299
- // Expose errors via explicit Promise rejection and add a timeout
300
- return new Promise(async (resolve, reject) => {
301
- try {
302
- const targetHost = enclaveHost || this.serverURL;
303
- if (typeof globalThis.verifyEnclave !== "function") {
304
- reject(new Error("WASM verifyEnclave function not available"));
305
- return;
306
- }
307
- let attestationResponse;
308
- let timeoutHandle;
309
- try {
310
- const timeoutPromise = new Promise((_, timeoutReject) => {
311
- timeoutHandle = setTimeout(() => timeoutReject(new Error("WASM verifyEnclave timed out after 10 seconds")), 10000);
312
- });
313
- attestationResponse = await Promise.race([
314
- globalThis.verifyEnclave(targetHost),
315
- timeoutPromise,
316
- ]);
317
- // Clear timeout on success
318
- if (timeoutHandle !== undefined) {
319
- clearTimeout(timeoutHandle);
320
- }
321
- }
322
- catch (error) {
323
- // Clear timeout on error
324
- if (timeoutHandle !== undefined) {
325
- clearTimeout(timeoutHandle);
326
- }
327
- reject(new Error(`WASM verifyEnclave failed: ${error}`));
328
- return;
329
- }
330
- // Validate required fields - fail fast with explicit rejection
331
- // At least one key must be present (TLS or HPKE)
332
- if (!attestationResponse?.tls_public_key && !attestationResponse?.hpke_public_key) {
333
- reject(new Error("Missing both tls_public_key and hpke_public_key in attestation response"));
334
- return;
335
- }
336
- // Parse runtime measurement
337
- let parsedRuntimeMeasurement;
338
- try {
339
- if (attestationResponse.measurement &&
340
- typeof attestationResponse.measurement === "string") {
341
- parsedRuntimeMeasurement = JSON.parse(attestationResponse.measurement);
342
- }
343
- else if (attestationResponse.measurement &&
344
- typeof attestationResponse.measurement === "object") {
345
- parsedRuntimeMeasurement = attestationResponse.measurement;
346
- }
347
- else {
348
- reject(new Error("Invalid runtime measurement format"));
349
- return;
350
- }
351
- }
352
- catch (parseError) {
353
- reject(new Error(`Failed to parse runtime measurement: ${parseError}`));
354
- return;
355
- }
356
- const result = {
357
- measurement: parsedRuntimeMeasurement,
358
- };
359
- // Include keys if available
360
- if (attestationResponse.tls_public_key) {
361
- result.tlsPublicKeyFingerprint = attestationResponse.tls_public_key;
362
- }
363
- if (attestationResponse.hpke_public_key) {
364
- result.hpkePublicKey = attestationResponse.hpke_public_key;
365
- }
366
- resolve(result);
367
- }
368
- catch (outerError) {
369
- reject(outerError);
370
- }
371
- });
372
- }
373
- /**
374
- * Perform code attestation
375
- * @param configRepo - Repository name
376
- * @param digest - Code digest hash
377
- * @returns Code measurement
378
- */
379
- async verifyCode(configRepo, digest) {
380
- if (typeof globalThis.verifyCode !== "function") {
381
- throw new Error("WASM verifyCode function not available");
382
- }
383
- const rawMeasurement = await globalThis.verifyCode(configRepo, digest);
384
- const normalizedMeasurement = typeof rawMeasurement === 'string'
385
- ? (() => {
386
- try {
387
- return JSON.parse(rawMeasurement);
388
- }
389
- catch (error) {
390
- throw new Error(`Invalid code measurement format: ${error.message}`);
391
- }
392
- })()
393
- : rawMeasurement;
394
- if (!normalizedMeasurement || typeof normalizedMeasurement !== 'object') {
395
- throw new Error('Invalid code measurement format');
396
- }
397
- const measurementObject = normalizedMeasurement;
398
- if (typeof measurementObject.type !== 'string' || !Array.isArray(measurementObject.registers)) {
399
- throw new Error('Invalid code measurement format');
400
- }
401
- const parsedCodeMeasurement = {
402
- type: measurementObject.type,
403
- registers: measurementObject.registers.map((value) => String(value))
404
- };
405
- return { measurement: parsedCodeMeasurement };
406
- }
407
- /**
408
- * Perform attestation verification
182
+ * Perform end-to-end attestation verification
409
183
  *
410
- * This method:
184
+ * This method performs all verification steps atomically via the Go WASM verify() function:
411
185
  * 1. Fetches the latest code digest from GitHub releases
412
- * 2. Calls verifyCode to get the expected measurement for the code
413
- * 3. Calls verifyEnclave to get the actual runtime measurement
414
- * 4. Compares measurements using platform-specific logic (see `compareMeasurements()`)
415
- * 5. Returns the attestation response if verification succeeds
186
+ * 2. Verifies code provenance using Sigstore/Rekor
187
+ * 3. Performs runtime attestation against the enclave
188
+ * 4. Verifies hardware measurements (for TDX platforms)
189
+ * 5. Compares code and runtime measurements using platform-specific logic
416
190
  *
417
191
  * The WASM runtime is automatically initialized and cleaned up within this method.
192
+ * A detailed verification document is saved and can be accessed via getVerificationDocument().
418
193
  *
419
- * @throws Error if measurements don't match or verification fails
194
+ * @returns AttestationResponse containing cryptographic keys (TLS/HPKE) and enclave measurement
195
+ * @throws Error if measurements don't match or verification fails at any step
420
196
  */
421
197
  async verify() {
422
198
  return Verifier.executeWithWasm(async () => {
423
199
  return this.verifyInternal();
424
200
  });
425
201
  }
202
+ /**
203
+ * Save a failed verification document
204
+ */
205
+ saveFailedVerificationDocument(steps) {
206
+ this.lastVerificationDocument = {
207
+ configRepo: this.configRepo,
208
+ enclaveHost: this.serverURL,
209
+ releaseDigest: '',
210
+ codeMeasurement: { type: '', registers: [] },
211
+ enclaveMeasurement: { measurement: { type: '', registers: [] } },
212
+ tlsPublicKey: '',
213
+ hpkePublicKey: '',
214
+ hardwareMeasurement: undefined,
215
+ codeFingerprint: '',
216
+ enclaveFingerprint: '',
217
+ selectedRouterEndpoint: this.serverURL,
218
+ securityVerified: false,
219
+ steps,
220
+ };
221
+ }
426
222
  /**
427
223
  * Internal verification logic that runs within WASM context
428
224
  */
@@ -433,87 +229,86 @@ export class Verifier {
433
229
  verifyEnclave: { status: 'pending' },
434
230
  compareMeasurements: { status: 'pending' },
435
231
  };
436
- let releaseDigest;
437
- let codeMeasurement;
438
- let attestation;
439
- try {
440
- releaseDigest = await this.fetchLatestDigest(this.configRepo);
441
- steps.fetchDigest = { status: 'success' };
442
- }
443
- catch (error) {
444
- steps.fetchDigest = { status: 'failed', error: error.message };
445
- this.lastVerificationDocument = {
446
- configRepo: this.configRepo,
447
- enclaveHost: this.serverURL,
448
- releaseDigest: '',
449
- codeMeasurement: { type: '', registers: [] },
450
- enclaveMeasurement: { measurement: { type: '', registers: [] } },
451
- securityVerified: false,
452
- steps,
453
- };
454
- throw error;
232
+ if (typeof globalThis.verify !== "function") {
233
+ steps.fetchDigest = { status: 'failed', error: 'WASM verify function not available' };
234
+ this.saveFailedVerificationDocument(steps);
235
+ throw new Error("WASM verify function not available");
455
236
  }
237
+ let groundTruth;
456
238
  try {
457
- const results = await Promise.all([
458
- this.verifyCode(this.configRepo, releaseDigest).then((result) => {
459
- steps.verifyCode = { status: 'success' };
460
- return result;
461
- }, (error) => {
462
- steps.verifyCode = { status: 'failed', error: error.message };
463
- throw error;
464
- }),
465
- this.verifyEnclave(this.serverURL).then((result) => {
466
- steps.verifyEnclave = { status: 'success' };
467
- return result;
468
- }, (error) => {
469
- steps.verifyEnclave = { status: 'failed', error: error.message };
470
- throw error;
471
- }),
472
- ]);
473
- codeMeasurement = results[0].measurement;
474
- attestation = results[1];
239
+ const groundTruthJSON = await globalThis.verify(this.serverURL, this.configRepo);
240
+ groundTruth = JSON.parse(groundTruthJSON);
241
+ // Mark all steps as successful since WASM verify() succeeded
242
+ steps.fetchDigest = { status: 'success' };
243
+ steps.verifyCode = { status: 'success' };
244
+ steps.verifyEnclave = { status: 'success' };
245
+ steps.compareMeasurements = { status: 'success' };
475
246
  }
476
247
  catch (error) {
477
- this.lastVerificationDocument = {
478
- configRepo: this.configRepo,
479
- enclaveHost: this.serverURL,
480
- releaseDigest: releaseDigest,
481
- codeMeasurement: codeMeasurement,
482
- enclaveMeasurement: attestation,
483
- securityVerified: false,
484
- steps,
485
- };
248
+ const errorMessage = error instanceof Error ? error.message : String(error);
249
+ if (errorMessage.startsWith('fetchDigest:')) {
250
+ steps.fetchDigest = { status: 'failed', error: errorMessage };
251
+ }
252
+ else if (errorMessage.startsWith('verifyCode:')) {
253
+ steps.fetchDigest = { status: 'success' };
254
+ steps.verifyCode = { status: 'failed', error: errorMessage };
255
+ }
256
+ else if (errorMessage.startsWith('verifyEnclave:')) {
257
+ steps.fetchDigest = { status: 'success' };
258
+ steps.verifyCode = { status: 'success' };
259
+ steps.verifyEnclave = { status: 'failed', error: errorMessage };
260
+ }
261
+ else if (errorMessage.startsWith('measurements:')) {
262
+ steps.fetchDigest = { status: 'success' };
263
+ steps.verifyCode = { status: 'success' };
264
+ steps.verifyEnclave = { status: 'success' };
265
+ steps.compareMeasurements = { status: 'failed', error: errorMessage };
266
+ }
267
+ else if (errorMessage.startsWith('verifyHardware:') || errorMessage.startsWith('validateTLS:')) {
268
+ steps.fetchDigest = { status: 'success' };
269
+ steps.verifyCode = { status: 'success' };
270
+ steps.verifyEnclave = { status: 'success' };
271
+ steps.otherError = { status: 'failed', error: errorMessage };
272
+ }
273
+ else {
274
+ steps.otherError = { status: 'failed', error: errorMessage };
275
+ }
276
+ this.saveFailedVerificationDocument(steps);
486
277
  throw error;
487
278
  }
488
- const measurementsMatchError = compareMeasurementsError(codeMeasurement, attestation.measurement);
489
- if (measurementsMatchError) {
490
- steps.compareMeasurements = { status: 'failed', error: measurementsMatchError.message };
491
- this.lastVerificationDocument = {
492
- configRepo: this.configRepo,
493
- enclaveHost: this.serverURL,
494
- releaseDigest: releaseDigest,
495
- codeMeasurement,
496
- enclaveMeasurement: attestation,
497
- securityVerified: false,
498
- steps,
499
- };
500
- throw new Error(`Verification failed: measurements did not match.\nCode measurement (${codeMeasurement.type}: ${codeMeasurement.registers})\n` +
501
- `Runtime measurement (${attestation.measurement.type}: ${attestation.measurement.registers}:)\n ${measurementsMatchError.message}`);
502
- }
503
- steps.compareMeasurements = { status: 'success' };
279
+ const attestation = {
280
+ tlsPublicKeyFingerprint: groundTruth.tls_public_key,
281
+ hpkePublicKey: groundTruth.hpke_public_key,
282
+ measurement: groundTruth.enclave_measurement,
283
+ };
504
284
  this.lastVerificationDocument = {
505
285
  configRepo: this.configRepo,
506
286
  enclaveHost: this.serverURL,
507
- releaseDigest: releaseDigest,
508
- codeMeasurement,
287
+ releaseDigest: groundTruth.digest,
288
+ codeMeasurement: groundTruth.code_measurement,
509
289
  enclaveMeasurement: attestation,
290
+ tlsPublicKey: groundTruth.tls_public_key,
291
+ hpkePublicKey: groundTruth.hpke_public_key,
292
+ hardwareMeasurement: groundTruth.hardware_measurement,
293
+ codeFingerprint: groundTruth.code_fingerprint,
294
+ enclaveFingerprint: groundTruth.enclave_fingerprint,
295
+ selectedRouterEndpoint: this.serverURL,
510
296
  securityVerified: true,
511
297
  steps,
512
298
  };
513
299
  return attestation;
514
300
  }
515
301
  /**
516
- * Returns the full verification document from the last successful verify() call
302
+ * Returns the verification document from the last verify() call
303
+ *
304
+ * The document contains detailed step-by-step verification results including:
305
+ * - Step status (pending/success/failed) for each verification phase
306
+ * - Measurements, fingerprints, and cryptographic keys
307
+ * - Error messages for any failed steps
308
+ *
309
+ * Available even if verification failed, allowing inspection of which step failed.
310
+ *
311
+ * @returns VerificationDocument with complete verification details, or undefined if verify() hasn't been called
517
312
  */
518
313
  getVerificationDocument() {
519
314
  return this.lastVerificationDocument;
@@ -521,7 +316,7 @@ export class Verifier {
521
316
  }
522
317
  Verifier.goInstance = null;
523
318
  Verifier.initializationPromise = null;
524
- Verifier.defaultWasmUrl = "https://tinfoilsh.github.io/verifier-js/tinfoil-verifier.wasm";
319
+ Verifier.defaultWasmUrl = "https://tinfoilsh.github.io/verifier/tinfoil-verifier.wasm";
525
320
  Verifier.originalFsWriteSync = null;
526
321
  Verifier.wasmLogsSuppressed = true;
527
322
  Verifier.globalsInitialized = false;
@@ -549,10 +344,12 @@ function shouldAutoInitializeWasm() {
549
344
  /**
550
345
  * Control WASM log output
551
346
  *
552
- * The Go WASM runtime outputs logs through a polyfilled fs.writeSync.
347
+ * The Go WASM runtime outputs logs (stdout/stderr) through a polyfilled fs.writeSync.
553
348
  * This function allows suppressing those logs without affecting other console output.
349
+ * By default, WASM logs are suppressed to reduce noise.
554
350
  *
555
351
  * @param suppress - Whether to suppress WASM logs (default: true)
352
+ * @returns void
556
353
  */
557
354
  export function suppressWasmLogs(suppress = true) {
558
355
  globalThis.__tinfoilSuppressWasmLogs = suppress;
@@ -85,13 +85,21 @@ class SecureClient {
85
85
  releaseDigest: '',
86
86
  codeMeasurement: { type: '', registers: [] },
87
87
  enclaveMeasurement: { measurement: { type: '', registers: [] } },
88
+ tlsPublicKey: '',
89
+ hpkePublicKey: '',
90
+ hardwareMeasurement: undefined,
91
+ codeFingerprint: '',
92
+ enclaveFingerprint: '',
93
+ selectedRouterEndpoint: new URL(this.enclaveURL).hostname,
88
94
  securityVerified: false,
89
95
  steps: {
90
96
  fetchDigest: { status: 'pending' },
91
97
  verifyCode: { status: 'pending' },
92
98
  verifyEnclave: { status: 'pending' },
93
99
  compareMeasurements: { status: 'pending' },
94
- otherError: { status: 'failed', error: error.message }
100
+ createTransport: undefined,
101
+ verifyHPKEKey: undefined,
102
+ otherError: { status: 'failed', error: error.message },
95
103
  }
96
104
  };
97
105
  }