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