tinfoil 0.8.7 → 0.9.0

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 CHANGED
@@ -75,7 +75,7 @@ This package exposes verification helpers that load the Go-based WebAssembly ver
75
75
 
76
76
  The verification functionality is split into two modules:
77
77
  - `verifier.ts`: Core verification logic with low-level attestation methods
78
- - `verification-runner.ts`: Higher-level orchestration with state management and subscriptions
78
+
79
79
 
80
80
  ### Core Verifier API
81
81
 
@@ -96,76 +96,6 @@ const code = await verifier.verifyCode("tinfoilsh/repo", "digest-hash");
96
96
  const digest = await verifier.fetchLatestDigest("tinfoilsh/repo");
97
97
  ```
98
98
 
99
- ### High-level Orchestration API
100
-
101
- - `loadVerifier()` boots the verifier with state management and returns an enhanced client.
102
- - `client.subscribe(callback)` subscribes to real-time verification state updates.
103
- - `client.runVerification({ configRepo?, serverURL?, releaseDigest?, onUpdate? })` orchestrates the full flow and returns a structured result with step statuses and a comparison outcome. Both `configRepo` and `serverURL` default to values from `TINFOIL_CONFIG`.
104
-
105
- ### End-to-end orchestration
106
-
107
- ```typescript
108
- import { loadVerifier, TINFOIL_CONFIG } from "tinfoil";
109
-
110
- const verifier = await loadVerifier();
111
-
112
- const result = await verifier.runVerification({
113
- onUpdate: (state) => {
114
- // Receive stepwise updates: pending -> loading -> success/error
115
- // Useful for logging or progress indicators
116
- console.log("verification update:", state);
117
- },
118
- // Optional: override defaults if needed
119
- // configRepo: "tinfoilsh/confidential-inference-proxy",
120
- // serverURL: "https://inference.tinfoil.sh",
121
- // releaseDigest: "<specific-release-sha256>",
122
- });
123
-
124
- if (result.verification.status === "success" && result.verification.securityVerified) {
125
- console.log("Measurements match. Digest:", result.releaseDigest);
126
- } else {
127
- console.error("Verification failed:", result);
128
- }
129
- ```
130
-
131
- `runVerification` returns:
132
-
133
- ```typescript
134
- type VerificationResult = {
135
- code: { status: StepStatus; measurement?: AttestationMeasurement; error?: string };
136
- runtime: {
137
- status: StepStatus;
138
- measurement?: AttestationMeasurement;
139
- tlsPublicKeyFingerprint?: string;
140
- hpkePublicKey?: string;
141
- error?: string;
142
- };
143
- verification: { status: StepStatus; securityVerified?: boolean; error?: string };
144
- releaseDigest: string;
145
- };
146
- ```
147
-
148
- ### Subscribe to state updates
149
-
150
- ```typescript
151
- const verifier = await loadVerifier();
152
- const unsubscribe = verifier.subscribe((state) => {
153
- console.log("state:", state);
154
- });
155
-
156
- // Run verification with default config (recommended)
157
- await verifier.runVerification();
158
-
159
- // Or override specific parameters if needed
160
- // await verifier.runVerification({
161
- // configRepo: "tinfoilsh/confidential-inference-proxy",
162
- // serverURL: "https://inference.tinfoil.sh",
163
- // releaseDigest: "<specific-release-sha256>",
164
- // });
165
-
166
- unsubscribe();
167
- ```
168
-
169
99
  ## Testing
170
100
 
171
101
  The project includes both unit tests and integration tests:
@@ -201,6 +131,7 @@ The chat example demonstrates both streaming chat completions and real-time atte
201
131
 
202
132
  ```bash
203
133
  npm install
134
+ npm run build
204
135
  ```
205
136
 
206
137
  3. Optionally create a `.env` file with your configuration:
@@ -1,4 +1,5 @@
1
1
  type EhbpModule = typeof import("ehbp");
2
+ export declare function getHPKEKey(enclaveURL: string): Promise<CryptoKey>;
2
3
  export declare function normalizeEncryptedBodyRequestArgs(input: RequestInfo | URL, init?: RequestInit): {
3
4
  url: string;
4
5
  init?: RequestInit;
@@ -33,6 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.getHPKEKey = getHPKEKey;
36
37
  exports.normalizeEncryptedBodyRequestArgs = normalizeEncryptedBodyRequestArgs;
37
38
  exports.encryptedBodyRequest = encryptedBodyRequest;
38
39
  exports.createEncryptedBodyFetch = createEncryptedBodyFetch;
@@ -43,6 +44,25 @@ let transport = null;
43
44
  let ehbpModulePromise = null;
44
45
  let ehbpModuleOverride;
45
46
  // Public API
47
+ async function getHPKEKey(enclaveURL) {
48
+ const { Identity, PROTOCOL } = await getEhbpModule();
49
+ const url = new URL(enclaveURL);
50
+ const keysURL = new URL(PROTOCOL.KEYS_PATH, enclaveURL);
51
+ if (keysURL.protocol !== 'https:') {
52
+ throw new Error(`HTTPS is required for remote key retrieval. Invalid protocol: ${keysURL.protocol}`);
53
+ }
54
+ const response = await fetch(keysURL.toString());
55
+ if (!response.ok) {
56
+ throw new Error(`Failed to get server public key: ${response.status}`);
57
+ }
58
+ const contentType = response.headers.get('content-type');
59
+ if (contentType !== PROTOCOL.KEYS_MEDIA_TYPE) {
60
+ throw new Error(`Invalid content type: ${contentType}`);
61
+ }
62
+ const keysData = new Uint8Array(await response.arrayBuffer());
63
+ const serverIdentity = await Identity.unmarshalPublicConfig(keysData);
64
+ return serverIdentity.getPublicKey();
65
+ }
46
66
  function normalizeEncryptedBodyRequestArgs(input, init) {
47
67
  if (typeof input === "string") {
48
68
  return { url: input, init };
@@ -112,7 +132,7 @@ function getEhbpModule() {
112
132
  return ehbpModulePromise;
113
133
  }
114
134
  async function getTransportForOrigin(origin, keyOrigin) {
115
- const { Identity, createTransport, Transport } = await getEhbpModule();
135
+ const { Identity, Transport } = await getEhbpModule();
116
136
  // Ensure secure browser context
117
137
  if (typeof globalThis !== 'undefined') {
118
138
  const isSecure = globalThis.isSecureContext !== false;
@@ -122,12 +142,8 @@ async function getTransportForOrigin(origin, keyOrigin) {
122
142
  throw new Error(`EHBP requires a secure browser context: ${reason}`);
123
143
  }
124
144
  }
125
- // Create a single client identity to use for both key discovery and requests
126
145
  const clientIdentity = await Identity.generate();
127
- // Fetch the server's HPKE public key from the dedicated key origin.
128
- // TODO: clean up this code. EHBP should make it easy to fetch the key without creating a transport object.
129
- const keyTransport = await createTransport(keyOrigin, clientIdentity);
130
- const serverPublicKey = keyTransport.getServerPublicKey();
146
+ const serverPublicKey = await getHPKEKey(keyOrigin);
131
147
  const requestHost = new URL(origin).host;
132
148
  return new Transport(clientIdentity, requestHost, serverPublicKey);
133
149
  }
@@ -1,4 +1,5 @@
1
1
  type EhbpModule = typeof import("ehbp");
2
+ export declare function getHPKEKey(enclaveURL: string): Promise<CryptoKey>;
2
3
  export declare function normalizeEncryptedBodyRequestArgs(input: RequestInfo | URL, init?: RequestInit): {
3
4
  url: string;
4
5
  init?: RequestInit;
@@ -3,6 +3,25 @@ let transport = null;
3
3
  let ehbpModulePromise = null;
4
4
  let ehbpModuleOverride;
5
5
  // Public API
6
+ export async function getHPKEKey(enclaveURL) {
7
+ const { Identity, PROTOCOL } = await getEhbpModule();
8
+ const url = new URL(enclaveURL);
9
+ const keysURL = new URL(PROTOCOL.KEYS_PATH, enclaveURL);
10
+ if (keysURL.protocol !== 'https:') {
11
+ throw new Error(`HTTPS is required for remote key retrieval. Invalid protocol: ${keysURL.protocol}`);
12
+ }
13
+ const response = await fetch(keysURL.toString());
14
+ if (!response.ok) {
15
+ throw new Error(`Failed to get server public key: ${response.status}`);
16
+ }
17
+ const contentType = response.headers.get('content-type');
18
+ if (contentType !== PROTOCOL.KEYS_MEDIA_TYPE) {
19
+ throw new Error(`Invalid content type: ${contentType}`);
20
+ }
21
+ const keysData = new Uint8Array(await response.arrayBuffer());
22
+ const serverIdentity = await Identity.unmarshalPublicConfig(keysData);
23
+ return serverIdentity.getPublicKey();
24
+ }
6
25
  export function normalizeEncryptedBodyRequestArgs(input, init) {
7
26
  if (typeof input === "string") {
8
27
  return { url: input, init };
@@ -72,7 +91,7 @@ function getEhbpModule() {
72
91
  return ehbpModulePromise;
73
92
  }
74
93
  async function getTransportForOrigin(origin, keyOrigin) {
75
- const { Identity, createTransport, Transport } = await getEhbpModule();
94
+ const { Identity, Transport } = await getEhbpModule();
76
95
  // Ensure secure browser context
77
96
  if (typeof globalThis !== 'undefined') {
78
97
  const isSecure = globalThis.isSecureContext !== false;
@@ -82,12 +101,8 @@ async function getTransportForOrigin(origin, keyOrigin) {
82
101
  throw new Error(`EHBP requires a secure browser context: ${reason}`);
83
102
  }
84
103
  }
85
- // Create a single client identity to use for both key discovery and requests
86
104
  const clientIdentity = await Identity.generate();
87
- // Fetch the server's HPKE public key from the dedicated key origin.
88
- // TODO: clean up this code. EHBP should make it easy to fetch the key without creating a transport object.
89
- const keyTransport = await createTransport(keyOrigin, clientIdentity);
90
- const serverPublicKey = keyTransport.getServerPublicKey();
105
+ const serverPublicKey = await getHPKEKey(keyOrigin);
91
106
  const requestHost = new URL(origin).host;
92
107
  return new Transport(clientIdentity, requestHost, serverPublicKey);
93
108
  }
@@ -1,7 +1,6 @@
1
1
  export { TinfoilAI } from "./tinfoilai";
2
2
  export { TinfoilAI as default } from "./tinfoilai";
3
3
  export * from "./verifier";
4
- export * from "./verification-runner";
5
4
  export * from "./ai-sdk-provider";
6
5
  export * from "./config";
7
6
  export { SecureClient } from "./secure-client";
@@ -2,7 +2,6 @@
2
2
  export { TinfoilAI } from "./tinfoilai";
3
3
  export { TinfoilAI as default } from "./tinfoilai";
4
4
  export * from "./verifier";
5
- export * from "./verification-runner";
6
5
  export * from "./ai-sdk-provider";
7
6
  export * from "./config";
8
7
  export { SecureClient } from "./secure-client";
@@ -1,7 +1,6 @@
1
1
  export { TinfoilAI } from "./tinfoilai";
2
2
  export { TinfoilAI as default } from "./tinfoilai";
3
3
  export * from "./verifier";
4
- export * from "./verification-runner";
5
4
  export * from "./ai-sdk-provider";
6
5
  export * from "./config";
7
6
  export { SecureClient } from "./secure-client";
package/dist/esm/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  // Re-export the TinfoilAI class
2
2
  export { TinfoilAI } from "./tinfoilai";
3
3
  export { TinfoilAI as default } from "./tinfoilai";
4
- // Export verifier and loader
4
+ // Export verifier
5
5
  export * from "./verifier";
6
- export * from "./verification-runner";
7
6
  export * from "./ai-sdk-provider";
8
7
  export * from "./config";
9
8
  export { SecureClient } from "./secure-client";
@@ -1 +1 @@
1
- export declare function createPinnedTlsFetch(expectedFingerprintHex: string): typeof fetch;
1
+ export declare function createPinnedTlsFetch(baseURL: string, expectedFingerprintHex: string): typeof fetch;
@@ -2,15 +2,15 @@ import https from "https";
2
2
  import { checkServerIdentity as tlsCheckServerIdentity } from "tls";
3
3
  import { X509Certificate, createHash } from "crypto";
4
4
  import { Readable } from "stream";
5
- export function createPinnedTlsFetch(expectedFingerprintHex) {
5
+ export function createPinnedTlsFetch(baseURL, expectedFingerprintHex) {
6
6
  return (async (input, init) => {
7
- // Normalize URL
7
+ // Normalize URL with base URL support
8
8
  const makeURL = (value) => {
9
9
  if (typeof value === "string")
10
- return new URL(value);
10
+ return new URL(value, baseURL);
11
11
  if (value instanceof URL)
12
12
  return value;
13
- return new URL(value.url);
13
+ return new URL(value.url, baseURL);
14
14
  };
15
15
  const url = makeURL(input);
16
16
  if (url.protocol !== "https:") {
@@ -16,7 +16,7 @@ export function createSecureFetch(baseURL, enclaveURL, hpkePublicKey, tlsPublicK
16
16
  if (!tlsPublicKeyFingerprint) {
17
17
  throw new Error("Neither HPKE public key nor TLS public key fingerprint available for verification");
18
18
  }
19
- fetchFunction = createPinnedTlsFetch(tlsPublicKeyFingerprint);
19
+ fetchFunction = createPinnedTlsFetch(baseURL, tlsPublicKeyFingerprint);
20
20
  }
21
21
  return fetchFunction;
22
22
  }
@@ -15,7 +15,15 @@ export interface AttestationResponse {
15
15
  measurement: AttestationMeasurement;
16
16
  }
17
17
  /**
18
- * Full verification document produced by a successful verify() call
18
+ * State of an intermediate verification step
19
+ */
20
+ export interface VerificationStepState {
21
+ status: 'pending' | 'success' | 'failed';
22
+ error?: string;
23
+ }
24
+ /**
25
+ * Full verification document produced by a verify() call
26
+ * Includes state tracking for all intermediate steps
19
27
  */
20
28
  export interface VerificationDocument {
21
29
  configRepo: string;
@@ -23,7 +31,13 @@ export interface VerificationDocument {
23
31
  releaseDigest: string;
24
32
  codeMeasurement: AttestationMeasurement;
25
33
  enclaveMeasurement: AttestationResponse;
26
- match: boolean;
34
+ securityVerified: boolean;
35
+ steps: {
36
+ fetchDigest: VerificationStepState;
37
+ verifyCode: VerificationStepState;
38
+ verifyEnclave: VerificationStepState;
39
+ compareMeasurements: VerificationStepState;
40
+ };
27
41
  }
28
42
  export interface MeasurementComparisonResult {
29
43
  match: boolean;
@@ -64,10 +78,10 @@ export declare class Verifier {
64
78
  configRepo?: string;
65
79
  });
66
80
  /**
67
- * Initialize the WebAssembly module
68
- * This loads the Go runtime and makes verification functions available
81
+ * Execute a function with a fresh WASM instance that auto-cleans up
82
+ * This ensures Go runtime doesn't keep the process alive
69
83
  */
70
- static initializeWasm(): Promise<void>;
84
+ private static executeWithWasm;
71
85
  /**
72
86
  * Fetch the latest release digest from GitHub
73
87
  * @param configRepo - Repository name (e.g., "tinfoilsh/confidential-inference-proxy")
@@ -99,9 +113,15 @@ export declare class Verifier {
99
113
  * 4. Compares measurements using platform-specific logic (see `compareMeasurements()`)
100
114
  * 5. Returns the attestation response if verification succeeds
101
115
  *
116
+ * The WASM runtime is automatically initialized and cleaned up within this method.
117
+ *
102
118
  * @throws Error if measurements don't match or verification fails
103
119
  */
104
120
  verify(): Promise<AttestationResponse>;
121
+ /**
122
+ * Internal verification logic that runs within WASM context
123
+ */
124
+ private verifyInternal;
105
125
  /**
106
126
  * Returns the full verification document from the last successful verify() call
107
127
  */
@@ -199,51 +199,60 @@ export class Verifier {
199
199
  this.configRepo = options?.configRepo ?? TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
200
200
  }
201
201
  /**
202
- * Initialize the WebAssembly module
203
- * This loads the Go runtime and makes verification functions available
202
+ * Execute a function with a fresh WASM instance that auto-cleans up
203
+ * This ensures Go runtime doesn't keep the process alive
204
204
  */
205
- static async initializeWasm() {
206
- if (Verifier.initializationPromise) {
207
- return Verifier.initializationPromise;
205
+ static async executeWithWasm(fn) {
206
+ await initializeWasmGlobals();
207
+ const goInstance = new globalThis.Go();
208
+ // Load WASM module
209
+ const fetchFn = getFetch();
210
+ const wasmResponse = await fetchFn(Verifier.defaultWasmUrl);
211
+ if (!wasmResponse.ok) {
212
+ throw new Error(`Failed to fetch WASM: ${wasmResponse.status} ${wasmResponse.statusText}`);
208
213
  }
209
- Verifier.initializationPromise = (async () => {
210
- try {
211
- // Initialize globals if not already done
212
- await initializeWasmGlobals();
213
- Verifier.goInstance = new globalThis.Go();
214
- // Load WASM module
215
- const fetchFn = getFetch();
216
- const wasmResponse = await fetchFn(Verifier.defaultWasmUrl);
217
- if (!wasmResponse.ok) {
218
- throw new Error(`Failed to fetch WASM: ${wasmResponse.status} ${wasmResponse.statusText}`);
214
+ const wasmBuffer = await wasmResponse.arrayBuffer();
215
+ const result = await WebAssembly.instantiate(wasmBuffer, goInstance.importObject);
216
+ // Start the Go instance in the background
217
+ // We don't await this - it runs continuously
218
+ goInstance.run(result.instance);
219
+ // Wait for WASM functions to be available
220
+ await new Promise(resolve => setTimeout(resolve, 100));
221
+ if (typeof globalThis.verifyCode === "undefined" || typeof globalThis.verifyEnclave === "undefined") {
222
+ await new Promise(resolve => setTimeout(resolve, 500));
223
+ }
224
+ // Apply log suppression if requested
225
+ if (Verifier.wasmLogsSuppressed && globalThis.fs?.writeSync) {
226
+ const fsObj = globalThis.fs;
227
+ if (!Verifier.originalFsWriteSync) {
228
+ Verifier.originalFsWriteSync = fsObj.writeSync.bind(fsObj);
229
+ }
230
+ fsObj.writeSync = function (_fd, buf) {
231
+ return buf.length;
232
+ };
233
+ }
234
+ try {
235
+ // Execute the user's function
236
+ const result = await fn();
237
+ return result;
238
+ }
239
+ finally {
240
+ // Clean up the Go instance
241
+ if (goInstance._scheduledTimeouts instanceof Map) {
242
+ for (const timeoutId of goInstance._scheduledTimeouts.values()) {
243
+ clearTimeout(timeoutId);
219
244
  }
220
- const wasmBuffer = await wasmResponse.arrayBuffer();
221
- const result = await WebAssembly.instantiate(wasmBuffer, Verifier.goInstance.importObject);
222
- // Run the Go instance - this makes functions available on globalThis
223
- Verifier.goInstance.run(result.instance);
224
- // Wait for initialization to complete
225
- await new Promise(resolve => setTimeout(resolve, 100));
226
- // Ensure required functions are available
227
- if (typeof globalThis.verifyCode === "undefined" || typeof globalThis.verifyEnclave === "undefined") {
228
- await new Promise(resolve => setTimeout(resolve, 500));
245
+ goInstance._scheduledTimeouts.clear();
246
+ }
247
+ if (typeof goInstance.exit === 'function') {
248
+ try {
249
+ goInstance.exit(0);
229
250
  }
230
- // Apply log suppression if requested
231
- if (Verifier.wasmLogsSuppressed && globalThis.fs?.writeSync) {
232
- const fsObj = globalThis.fs;
233
- if (!Verifier.originalFsWriteSync) {
234
- Verifier.originalFsWriteSync = fsObj.writeSync.bind(fsObj);
235
- }
236
- fsObj.writeSync = function (_fd, buf) {
237
- return buf.length;
238
- };
251
+ catch (e) {
252
+ // Ignore exit errors
239
253
  }
240
254
  }
241
- catch (error) {
242
- console.error("WASM initialization error:", error);
243
- throw error;
244
- }
245
- })();
246
- return Verifier.initializationPromise;
255
+ }
247
256
  }
248
257
  /**
249
258
  * Fetch the latest release digest from GitHub
@@ -288,7 +297,6 @@ export class Verifier {
288
297
  return new Promise(async (resolve, reject) => {
289
298
  try {
290
299
  const targetHost = enclaveHost || this.serverURL;
291
- await Verifier.initializeWasm();
292
300
  if (typeof globalThis.verifyEnclave !== "function") {
293
301
  reject(new Error("WASM verifyEnclave function not available"));
294
302
  return;
@@ -366,7 +374,6 @@ export class Verifier {
366
374
  * @returns Code measurement
367
375
  */
368
376
  async verifyCode(configRepo, digest) {
369
- await Verifier.initializeWasm();
370
377
  if (typeof globalThis.verifyCode !== "function") {
371
378
  throw new Error("WASM verifyCode function not available");
372
379
  }
@@ -404,30 +411,92 @@ export class Verifier {
404
411
  * 4. Compares measurements using platform-specific logic (see `compareMeasurements()`)
405
412
  * 5. Returns the attestation response if verification succeeds
406
413
  *
414
+ * The WASM runtime is automatically initialized and cleaned up within this method.
415
+ *
407
416
  * @throws Error if measurements don't match or verification fails
408
417
  */
409
418
  async verify() {
410
- // Get latest release digest first
411
- const releaseDigest = await this.fetchLatestDigest(this.configRepo);
412
- // Perform code attestation and runtime attestation in parallel
413
- const [{ measurement: codeMeasurement }, attestation] = await Promise.all([
414
- this.verifyCode(this.configRepo, releaseDigest),
415
- this.verifyEnclave(this.serverURL),
416
- ]);
417
- // Compare measurements using platform-specific logic
419
+ return Verifier.executeWithWasm(async () => {
420
+ return this.verifyInternal();
421
+ });
422
+ }
423
+ /**
424
+ * Internal verification logic that runs within WASM context
425
+ */
426
+ async verifyInternal() {
427
+ const steps = {
428
+ fetchDigest: { status: 'pending' },
429
+ verifyCode: { status: 'pending' },
430
+ verifyEnclave: { status: 'pending' },
431
+ compareMeasurements: { status: 'pending' },
432
+ };
433
+ let releaseDigest;
434
+ let codeMeasurement;
435
+ let attestation;
436
+ try {
437
+ releaseDigest = await this.fetchLatestDigest(this.configRepo);
438
+ steps.fetchDigest = { status: 'success' };
439
+ }
440
+ catch (error) {
441
+ steps.fetchDigest = { status: 'failed', error: error.message };
442
+ throw error;
443
+ }
444
+ try {
445
+ const results = await Promise.all([
446
+ this.verifyCode(this.configRepo, releaseDigest).then((result) => {
447
+ steps.verifyCode = { status: 'success' };
448
+ return result;
449
+ }, (error) => {
450
+ steps.verifyCode = { status: 'failed', error: error.message };
451
+ throw error;
452
+ }),
453
+ this.verifyEnclave(this.serverURL).then((result) => {
454
+ steps.verifyEnclave = { status: 'success' };
455
+ return result;
456
+ }, (error) => {
457
+ steps.verifyEnclave = { status: 'failed', error: error.message };
458
+ throw error;
459
+ }),
460
+ ]);
461
+ codeMeasurement = results[0].measurement;
462
+ attestation = results[1];
463
+ }
464
+ catch (error) {
465
+ this.lastVerificationDocument = {
466
+ configRepo: this.configRepo,
467
+ enclaveHost: this.serverURL,
468
+ releaseDigest: releaseDigest,
469
+ codeMeasurement: codeMeasurement,
470
+ enclaveMeasurement: attestation,
471
+ securityVerified: false,
472
+ steps,
473
+ };
474
+ throw error;
475
+ }
418
476
  const measurementsMatchError = compareMeasurementsError(codeMeasurement, attestation.measurement);
419
477
  if (measurementsMatchError) {
478
+ steps.compareMeasurements = { status: 'failed', error: measurementsMatchError.message };
479
+ this.lastVerificationDocument = {
480
+ configRepo: this.configRepo,
481
+ enclaveHost: this.serverURL,
482
+ releaseDigest: releaseDigest,
483
+ codeMeasurement,
484
+ enclaveMeasurement: attestation,
485
+ securityVerified: false,
486
+ steps,
487
+ };
420
488
  throw new Error(`Verification failed: measurements did not match.\nCode measurement (${codeMeasurement.type}: ${codeMeasurement.registers})\n` +
421
489
  `Runtime measurement (${attestation.measurement.type}: ${attestation.measurement.registers}:)\n ${measurementsMatchError.message}`);
422
490
  }
423
- // Persist a full verification document for later retrieval by clients
491
+ steps.compareMeasurements = { status: 'success' };
424
492
  this.lastVerificationDocument = {
425
493
  configRepo: this.configRepo,
426
494
  enclaveHost: this.serverURL,
427
495
  releaseDigest: releaseDigest,
428
496
  codeMeasurement,
429
497
  enclaveMeasurement: attestation,
430
- match: true,
498
+ securityVerified: true,
499
+ steps,
431
500
  };
432
501
  return attestation;
433
502
  }
@@ -465,11 +534,6 @@ function shouldAutoInitializeWasm() {
465
534
  const hasBrowserGlobals = typeof globalAny.window === "object" && typeof globalAny.document === "object";
466
535
  return hasBrowserGlobals;
467
536
  }
468
- if (shouldAutoInitializeWasm()) {
469
- void Verifier.initializeWasm().catch(error => {
470
- console.error(error);
471
- });
472
- }
473
537
  /**
474
538
  * Control WASM log output
475
539
  *
@@ -1,7 +1,6 @@
1
1
  export { TinfoilAI } from "./tinfoilai";
2
2
  export { TinfoilAI as default } from "./tinfoilai";
3
3
  export * from "./verifier";
4
- export * from "./verification-runner";
5
4
  export * from "./ai-sdk-provider";
6
5
  export * from "./config";
7
6
  export { SecureClient } from "./secure-client";
@@ -21,7 +21,6 @@ Object.defineProperty(exports, "TinfoilAI", { enumerable: true, get: function ()
21
21
  var tinfoilai_2 = require("./tinfoilai");
22
22
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return tinfoilai_2.TinfoilAI; } });
23
23
  __exportStar(require("./verifier"), exports);
24
- __exportStar(require("./verification-runner"), exports);
25
24
  __exportStar(require("./ai-sdk-provider"), exports);
26
25
  __exportStar(require("./config"), exports);
27
26
  var secure_client_1 = require("./secure-client");
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  export { TinfoilAI } from "./tinfoilai";
2
2
  export { TinfoilAI as default } from "./tinfoilai";
3
3
  export * from "./verifier";
4
- export * from "./verification-runner";
5
4
  export * from "./ai-sdk-provider";
6
5
  export * from "./config";
7
6
  export { SecureClient } from "./secure-client";
package/dist/index.js CHANGED
@@ -20,9 +20,8 @@ var tinfoilai_1 = require("./tinfoilai");
20
20
  Object.defineProperty(exports, "TinfoilAI", { enumerable: true, get: function () { return tinfoilai_1.TinfoilAI; } });
21
21
  var tinfoilai_2 = require("./tinfoilai");
22
22
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return tinfoilai_2.TinfoilAI; } });
23
- // Export verifier and loader
23
+ // Export verifier
24
24
  __exportStar(require("./verifier"), exports);
25
- __exportStar(require("./verification-runner"), exports);
26
25
  __exportStar(require("./ai-sdk-provider"), exports);
27
26
  __exportStar(require("./config"), exports);
28
27
  var secure_client_1 = require("./secure-client");
@@ -1 +1 @@
1
- export declare function createPinnedTlsFetch(expectedFingerprintHex: string): typeof fetch;
1
+ export declare function createPinnedTlsFetch(baseURL: string, expectedFingerprintHex: string): typeof fetch;
@@ -8,15 +8,15 @@ const https_1 = __importDefault(require("https"));
8
8
  const tls_1 = require("tls");
9
9
  const crypto_1 = require("crypto");
10
10
  const stream_1 = require("stream");
11
- function createPinnedTlsFetch(expectedFingerprintHex) {
11
+ function createPinnedTlsFetch(baseURL, expectedFingerprintHex) {
12
12
  return (async (input, init) => {
13
- // Normalize URL
13
+ // Normalize URL with base URL support
14
14
  const makeURL = (value) => {
15
15
  if (typeof value === "string")
16
- return new URL(value);
16
+ return new URL(value, baseURL);
17
17
  if (value instanceof URL)
18
18
  return value;
19
- return new URL(value.url);
19
+ return new URL(value.url, baseURL);
20
20
  };
21
21
  const url = makeURL(input);
22
22
  if (url.protocol !== "https:") {
@@ -19,7 +19,7 @@ function createSecureFetch(baseURL, enclaveURL, hpkePublicKey, tlsPublicKeyFinge
19
19
  if (!tlsPublicKeyFingerprint) {
20
20
  throw new Error("Neither HPKE public key nor TLS public key fingerprint available for verification");
21
21
  }
22
- fetchFunction = (0, pinned_tls_fetch_1.createPinnedTlsFetch)(tlsPublicKeyFingerprint);
22
+ fetchFunction = (0, pinned_tls_fetch_1.createPinnedTlsFetch)(baseURL, tlsPublicKeyFingerprint);
23
23
  }
24
24
  return fetchFunction;
25
25
  }