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 +2 -71
- package/dist/encrypted-body-fetch.d.ts +1 -0
- package/dist/encrypted-body-fetch.js +22 -6
- package/dist/esm/encrypted-body-fetch.d.ts +1 -0
- package/dist/esm/encrypted-body-fetch.js +21 -6
- package/dist/esm/index.browser.d.ts +0 -1
- package/dist/esm/index.browser.js +0 -1
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/pinned-tls-fetch.d.ts +1 -1
- package/dist/esm/pinned-tls-fetch.js +4 -4
- package/dist/esm/secure-fetch.js +1 -1
- package/dist/esm/verifier.d.ts +25 -5
- package/dist/esm/verifier.js +120 -56
- package/dist/index.browser.d.ts +0 -1
- package/dist/index.browser.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -2
- package/dist/pinned-tls-fetch.d.ts +1 -1
- package/dist/pinned-tls-fetch.js +4 -4
- package/dist/secure-fetch.js +1 -1
- package/dist/verifier.d.ts +25 -5
- package/dist/verifier.js +120 -56
- package/package.json +1 -6
- package/dist/esm/verification-runner.d.ts +0 -91
- package/dist/esm/verification-runner.js +0 -182
- package/dist/verification-runner.d.ts +0 -91
- package/dist/verification-runner.js +0 -187
package/dist/verifier.d.ts
CHANGED
|
@@ -15,7 +15,15 @@ export interface AttestationResponse {
|
|
|
15
15
|
measurement: AttestationMeasurement;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
68
|
-
* This
|
|
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
|
|
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
|
*/
|
package/dist/verifier.js
CHANGED
|
@@ -238,51 +238,60 @@ class Verifier {
|
|
|
238
238
|
this.configRepo = options?.configRepo ?? config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
|
|
239
239
|
}
|
|
240
240
|
/**
|
|
241
|
-
*
|
|
242
|
-
* This
|
|
241
|
+
* Execute a function with a fresh WASM instance that auto-cleans up
|
|
242
|
+
* This ensures Go runtime doesn't keep the process alive
|
|
243
243
|
*/
|
|
244
|
-
static async
|
|
245
|
-
|
|
246
|
-
|
|
244
|
+
static async executeWithWasm(fn) {
|
|
245
|
+
await initializeWasmGlobals();
|
|
246
|
+
const goInstance = new globalThis.Go();
|
|
247
|
+
// Load WASM module
|
|
248
|
+
const fetchFn = getFetch();
|
|
249
|
+
const wasmResponse = await fetchFn(Verifier.defaultWasmUrl);
|
|
250
|
+
if (!wasmResponse.ok) {
|
|
251
|
+
throw new Error(`Failed to fetch WASM: ${wasmResponse.status} ${wasmResponse.statusText}`);
|
|
247
252
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
253
|
+
const wasmBuffer = await wasmResponse.arrayBuffer();
|
|
254
|
+
const result = await WebAssembly.instantiate(wasmBuffer, goInstance.importObject);
|
|
255
|
+
// Start the Go instance in the background
|
|
256
|
+
// We don't await this - it runs continuously
|
|
257
|
+
goInstance.run(result.instance);
|
|
258
|
+
// Wait for WASM functions to be available
|
|
259
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
260
|
+
if (typeof globalThis.verifyCode === "undefined" || typeof globalThis.verifyEnclave === "undefined") {
|
|
261
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
262
|
+
}
|
|
263
|
+
// Apply log suppression if requested
|
|
264
|
+
if (Verifier.wasmLogsSuppressed && globalThis.fs?.writeSync) {
|
|
265
|
+
const fsObj = globalThis.fs;
|
|
266
|
+
if (!Verifier.originalFsWriteSync) {
|
|
267
|
+
Verifier.originalFsWriteSync = fsObj.writeSync.bind(fsObj);
|
|
268
|
+
}
|
|
269
|
+
fsObj.writeSync = function (_fd, buf) {
|
|
270
|
+
return buf.length;
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
// Execute the user's function
|
|
275
|
+
const result = await fn();
|
|
276
|
+
return result;
|
|
277
|
+
}
|
|
278
|
+
finally {
|
|
279
|
+
// Clean up the Go instance
|
|
280
|
+
if (goInstance._scheduledTimeouts instanceof Map) {
|
|
281
|
+
for (const timeoutId of goInstance._scheduledTimeouts.values()) {
|
|
282
|
+
clearTimeout(timeoutId);
|
|
258
283
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
265
|
-
// Ensure required functions are available
|
|
266
|
-
if (typeof globalThis.verifyCode === "undefined" || typeof globalThis.verifyEnclave === "undefined") {
|
|
267
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
284
|
+
goInstance._scheduledTimeouts.clear();
|
|
285
|
+
}
|
|
286
|
+
if (typeof goInstance.exit === 'function') {
|
|
287
|
+
try {
|
|
288
|
+
goInstance.exit(0);
|
|
268
289
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const fsObj = globalThis.fs;
|
|
272
|
-
if (!Verifier.originalFsWriteSync) {
|
|
273
|
-
Verifier.originalFsWriteSync = fsObj.writeSync.bind(fsObj);
|
|
274
|
-
}
|
|
275
|
-
fsObj.writeSync = function (_fd, buf) {
|
|
276
|
-
return buf.length;
|
|
277
|
-
};
|
|
290
|
+
catch (e) {
|
|
291
|
+
// Ignore exit errors
|
|
278
292
|
}
|
|
279
293
|
}
|
|
280
|
-
|
|
281
|
-
console.error("WASM initialization error:", error);
|
|
282
|
-
throw error;
|
|
283
|
-
}
|
|
284
|
-
})();
|
|
285
|
-
return Verifier.initializationPromise;
|
|
294
|
+
}
|
|
286
295
|
}
|
|
287
296
|
/**
|
|
288
297
|
* Fetch the latest release digest from GitHub
|
|
@@ -327,7 +336,6 @@ class Verifier {
|
|
|
327
336
|
return new Promise(async (resolve, reject) => {
|
|
328
337
|
try {
|
|
329
338
|
const targetHost = enclaveHost || this.serverURL;
|
|
330
|
-
await Verifier.initializeWasm();
|
|
331
339
|
if (typeof globalThis.verifyEnclave !== "function") {
|
|
332
340
|
reject(new Error("WASM verifyEnclave function not available"));
|
|
333
341
|
return;
|
|
@@ -405,7 +413,6 @@ class Verifier {
|
|
|
405
413
|
* @returns Code measurement
|
|
406
414
|
*/
|
|
407
415
|
async verifyCode(configRepo, digest) {
|
|
408
|
-
await Verifier.initializeWasm();
|
|
409
416
|
if (typeof globalThis.verifyCode !== "function") {
|
|
410
417
|
throw new Error("WASM verifyCode function not available");
|
|
411
418
|
}
|
|
@@ -443,30 +450,92 @@ class Verifier {
|
|
|
443
450
|
* 4. Compares measurements using platform-specific logic (see `compareMeasurements()`)
|
|
444
451
|
* 5. Returns the attestation response if verification succeeds
|
|
445
452
|
*
|
|
453
|
+
* The WASM runtime is automatically initialized and cleaned up within this method.
|
|
454
|
+
*
|
|
446
455
|
* @throws Error if measurements don't match or verification fails
|
|
447
456
|
*/
|
|
448
457
|
async verify() {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
458
|
+
return Verifier.executeWithWasm(async () => {
|
|
459
|
+
return this.verifyInternal();
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Internal verification logic that runs within WASM context
|
|
464
|
+
*/
|
|
465
|
+
async verifyInternal() {
|
|
466
|
+
const steps = {
|
|
467
|
+
fetchDigest: { status: 'pending' },
|
|
468
|
+
verifyCode: { status: 'pending' },
|
|
469
|
+
verifyEnclave: { status: 'pending' },
|
|
470
|
+
compareMeasurements: { status: 'pending' },
|
|
471
|
+
};
|
|
472
|
+
let releaseDigest;
|
|
473
|
+
let codeMeasurement;
|
|
474
|
+
let attestation;
|
|
475
|
+
try {
|
|
476
|
+
releaseDigest = await this.fetchLatestDigest(this.configRepo);
|
|
477
|
+
steps.fetchDigest = { status: 'success' };
|
|
478
|
+
}
|
|
479
|
+
catch (error) {
|
|
480
|
+
steps.fetchDigest = { status: 'failed', error: error.message };
|
|
481
|
+
throw error;
|
|
482
|
+
}
|
|
483
|
+
try {
|
|
484
|
+
const results = await Promise.all([
|
|
485
|
+
this.verifyCode(this.configRepo, releaseDigest).then((result) => {
|
|
486
|
+
steps.verifyCode = { status: 'success' };
|
|
487
|
+
return result;
|
|
488
|
+
}, (error) => {
|
|
489
|
+
steps.verifyCode = { status: 'failed', error: error.message };
|
|
490
|
+
throw error;
|
|
491
|
+
}),
|
|
492
|
+
this.verifyEnclave(this.serverURL).then((result) => {
|
|
493
|
+
steps.verifyEnclave = { status: 'success' };
|
|
494
|
+
return result;
|
|
495
|
+
}, (error) => {
|
|
496
|
+
steps.verifyEnclave = { status: 'failed', error: error.message };
|
|
497
|
+
throw error;
|
|
498
|
+
}),
|
|
499
|
+
]);
|
|
500
|
+
codeMeasurement = results[0].measurement;
|
|
501
|
+
attestation = results[1];
|
|
502
|
+
}
|
|
503
|
+
catch (error) {
|
|
504
|
+
this.lastVerificationDocument = {
|
|
505
|
+
configRepo: this.configRepo,
|
|
506
|
+
enclaveHost: this.serverURL,
|
|
507
|
+
releaseDigest: releaseDigest,
|
|
508
|
+
codeMeasurement: codeMeasurement,
|
|
509
|
+
enclaveMeasurement: attestation,
|
|
510
|
+
securityVerified: false,
|
|
511
|
+
steps,
|
|
512
|
+
};
|
|
513
|
+
throw error;
|
|
514
|
+
}
|
|
457
515
|
const measurementsMatchError = compareMeasurementsError(codeMeasurement, attestation.measurement);
|
|
458
516
|
if (measurementsMatchError) {
|
|
517
|
+
steps.compareMeasurements = { status: 'failed', error: measurementsMatchError.message };
|
|
518
|
+
this.lastVerificationDocument = {
|
|
519
|
+
configRepo: this.configRepo,
|
|
520
|
+
enclaveHost: this.serverURL,
|
|
521
|
+
releaseDigest: releaseDigest,
|
|
522
|
+
codeMeasurement,
|
|
523
|
+
enclaveMeasurement: attestation,
|
|
524
|
+
securityVerified: false,
|
|
525
|
+
steps,
|
|
526
|
+
};
|
|
459
527
|
throw new Error(`Verification failed: measurements did not match.\nCode measurement (${codeMeasurement.type}: ${codeMeasurement.registers})\n` +
|
|
460
528
|
`Runtime measurement (${attestation.measurement.type}: ${attestation.measurement.registers}:)\n ${measurementsMatchError.message}`);
|
|
461
529
|
}
|
|
462
|
-
|
|
530
|
+
steps.compareMeasurements = { status: 'success' };
|
|
463
531
|
this.lastVerificationDocument = {
|
|
464
532
|
configRepo: this.configRepo,
|
|
465
533
|
enclaveHost: this.serverURL,
|
|
466
534
|
releaseDigest: releaseDigest,
|
|
467
535
|
codeMeasurement,
|
|
468
536
|
enclaveMeasurement: attestation,
|
|
469
|
-
|
|
537
|
+
securityVerified: true,
|
|
538
|
+
steps,
|
|
470
539
|
};
|
|
471
540
|
return attestation;
|
|
472
541
|
}
|
|
@@ -505,11 +574,6 @@ function shouldAutoInitializeWasm() {
|
|
|
505
574
|
const hasBrowserGlobals = typeof globalAny.window === "object" && typeof globalAny.document === "object";
|
|
506
575
|
return hasBrowserGlobals;
|
|
507
576
|
}
|
|
508
|
-
if (shouldAutoInitializeWasm()) {
|
|
509
|
-
void Verifier.initializeWasm().catch(error => {
|
|
510
|
-
console.error(error);
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
577
|
/**
|
|
514
578
|
* Control WASM log output
|
|
515
579
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinfoil",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Tinfoil secure OpenAI client wrapper",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -32,11 +32,6 @@
|
|
|
32
32
|
"import": "./dist/esm/verifier.js",
|
|
33
33
|
"require": "./dist/verifier.js"
|
|
34
34
|
},
|
|
35
|
-
"./verification-runner": {
|
|
36
|
-
"types": "./dist/verification-runner.d.ts",
|
|
37
|
-
"import": "./dist/esm/verification-runner.js",
|
|
38
|
-
"require": "./dist/verification-runner.js"
|
|
39
|
-
},
|
|
40
35
|
"./config": {
|
|
41
36
|
"types": "./dist/config.d.ts",
|
|
42
37
|
"import": "./dist/esm/config.js",
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { Verifier, suppressWasmLogs } from "./verifier";
|
|
2
|
-
import type { AttestationMeasurement } from "./verifier";
|
|
3
|
-
import { TINFOIL_CONFIG } from "./config";
|
|
4
|
-
/**
|
|
5
|
-
* Step status for verification progress
|
|
6
|
-
*/
|
|
7
|
-
export type StepStatus = "pending" | "loading" | "success" | "error";
|
|
8
|
-
/**
|
|
9
|
-
* State for individual verification steps
|
|
10
|
-
*/
|
|
11
|
-
export interface StepState {
|
|
12
|
-
status: StepStatus;
|
|
13
|
-
measurement?: AttestationMeasurement;
|
|
14
|
-
error?: string;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Runtime verification state with additional key information
|
|
18
|
-
*/
|
|
19
|
-
export interface RuntimeStepState extends StepState {
|
|
20
|
-
tlsPublicKeyFingerprint?: string;
|
|
21
|
-
hpkePublicKey?: string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Final verification summary
|
|
25
|
-
*/
|
|
26
|
-
export interface VerificationSummary {
|
|
27
|
-
status: StepStatus;
|
|
28
|
-
securityVerified?: boolean;
|
|
29
|
-
error?: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Overall verification state
|
|
33
|
-
*/
|
|
34
|
-
export interface VerificationState {
|
|
35
|
-
releaseDigest: string;
|
|
36
|
-
runtime: RuntimeStepState;
|
|
37
|
-
code: StepState;
|
|
38
|
-
verification: VerificationSummary;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Verification result returned by runVerification
|
|
42
|
-
*/
|
|
43
|
-
export interface VerificationResult extends VerificationState {
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Options for runVerification method
|
|
47
|
-
*/
|
|
48
|
-
export interface RunVerificationOptions {
|
|
49
|
-
/** GitHub repository to verify. Defaults to TINFOIL_CONFIG.INFERENCE_PROXY_REPO */
|
|
50
|
-
configRepo?: string;
|
|
51
|
-
/** Enclave hostname to verify. Defaults to hostname from TINFOIL_CONFIG.INFERENCE_BASE_URL */
|
|
52
|
-
serverURL?: string;
|
|
53
|
-
/** Specific release digest to verify. If not provided, fetches latest release digest */
|
|
54
|
-
releaseDigest?: string;
|
|
55
|
-
/** Callback for receiving verification state updates */
|
|
56
|
-
onUpdate?: (state: VerificationState) => void;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Enhanced verifier with state management and subscription support
|
|
60
|
-
*/
|
|
61
|
-
export declare class VerifierWithState extends Verifier {
|
|
62
|
-
private state;
|
|
63
|
-
private subscribers;
|
|
64
|
-
/**
|
|
65
|
-
* Subscribe to verification state updates
|
|
66
|
-
* @param subscriber - Callback function to receive state updates
|
|
67
|
-
* @returns Unsubscribe function
|
|
68
|
-
*/
|
|
69
|
-
subscribe(subscriber: (state: VerificationState) => void): () => void;
|
|
70
|
-
/**
|
|
71
|
-
* Update state and notify subscribers
|
|
72
|
-
*/
|
|
73
|
-
private updateState;
|
|
74
|
-
/**
|
|
75
|
-
* Update a specific step state
|
|
76
|
-
*/
|
|
77
|
-
private updateStepState;
|
|
78
|
-
/**
|
|
79
|
-
* Run full verification flow with state updates
|
|
80
|
-
* @param options - Verification options
|
|
81
|
-
* @returns Final verification result
|
|
82
|
-
*/
|
|
83
|
-
runVerification(options?: RunVerificationOptions): Promise<VerificationResult>;
|
|
84
|
-
private _runVerificationInternal;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Load and initialize a verifier instance with state management
|
|
88
|
-
* @returns Initialized verifier instance with state management
|
|
89
|
-
*/
|
|
90
|
-
export declare function loadVerifier(): Promise<VerifierWithState>;
|
|
91
|
-
export { suppressWasmLogs, TINFOIL_CONFIG };
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { Verifier, compareMeasurements, suppressWasmLogs } from "./verifier";
|
|
2
|
-
import { TINFOIL_CONFIG } from "./config";
|
|
3
|
-
/**
|
|
4
|
-
* Enhanced verifier with state management and subscription support
|
|
5
|
-
*/
|
|
6
|
-
export class VerifierWithState extends Verifier {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(...arguments);
|
|
9
|
-
// State management
|
|
10
|
-
this.state = {
|
|
11
|
-
releaseDigest: "",
|
|
12
|
-
runtime: { status: "pending" },
|
|
13
|
-
code: { status: "pending" },
|
|
14
|
-
verification: { status: "pending" },
|
|
15
|
-
};
|
|
16
|
-
// Subscribers
|
|
17
|
-
this.subscribers = new Set();
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Subscribe to verification state updates
|
|
21
|
-
* @param subscriber - Callback function to receive state updates
|
|
22
|
-
* @returns Unsubscribe function
|
|
23
|
-
*/
|
|
24
|
-
subscribe(subscriber) {
|
|
25
|
-
this.subscribers.add(subscriber);
|
|
26
|
-
// Send current state immediately
|
|
27
|
-
subscriber(this.state);
|
|
28
|
-
return () => {
|
|
29
|
-
this.subscribers.delete(subscriber);
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Update state and notify subscribers
|
|
34
|
-
*/
|
|
35
|
-
updateState(updates) {
|
|
36
|
-
this.state = { ...this.state, ...updates };
|
|
37
|
-
this.subscribers.forEach(subscriber => subscriber(this.state));
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Update a specific step state
|
|
41
|
-
*/
|
|
42
|
-
updateStepState(step, updates) {
|
|
43
|
-
this.state = {
|
|
44
|
-
...this.state,
|
|
45
|
-
[step]: { ...this.state[step], ...updates }
|
|
46
|
-
};
|
|
47
|
-
this.subscribers.forEach(subscriber => subscriber(this.state));
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Run full verification flow with state updates
|
|
51
|
-
* @param options - Verification options
|
|
52
|
-
* @returns Final verification result
|
|
53
|
-
*/
|
|
54
|
-
async runVerification(options) {
|
|
55
|
-
const configRepo = options?.configRepo || TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
|
|
56
|
-
const enclaveURL = options?.serverURL || new URL(TINFOIL_CONFIG.INFERENCE_BASE_URL).hostname;
|
|
57
|
-
let releaseDigest = options?.releaseDigest || "";
|
|
58
|
-
// If no digest provided, we need to fetch it first before checking cache
|
|
59
|
-
if (!releaseDigest) {
|
|
60
|
-
// Reset state for fresh verification
|
|
61
|
-
this.updateState({
|
|
62
|
-
releaseDigest: "resolving...",
|
|
63
|
-
runtime: { status: "pending" },
|
|
64
|
-
code: { status: "pending" },
|
|
65
|
-
verification: { status: "pending" },
|
|
66
|
-
});
|
|
67
|
-
try {
|
|
68
|
-
releaseDigest = await this.fetchLatestDigest(configRepo);
|
|
69
|
-
this.updateState({ releaseDigest: releaseDigest });
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
// If we can't fetch the digest, mark all steps as error
|
|
73
|
-
this.updateState({ releaseDigest: "" });
|
|
74
|
-
this.updateStepState("code", {
|
|
75
|
-
status: "error",
|
|
76
|
-
error: error instanceof Error ? error.message : "Failed to fetch digest",
|
|
77
|
-
});
|
|
78
|
-
this.updateStepState("runtime", {
|
|
79
|
-
status: "error",
|
|
80
|
-
error: "Cannot proceed without digest",
|
|
81
|
-
});
|
|
82
|
-
this.updateStepState("verification", {
|
|
83
|
-
status: "error",
|
|
84
|
-
error: "Cannot proceed without digest",
|
|
85
|
-
});
|
|
86
|
-
return this.state;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const verificationPromise = this._runVerificationInternal(configRepo, enclaveURL, releaseDigest);
|
|
90
|
-
if (options?.onUpdate) {
|
|
91
|
-
const unsubscribe = this.subscribe(options.onUpdate);
|
|
92
|
-
verificationPromise.finally(() => unsubscribe());
|
|
93
|
-
}
|
|
94
|
-
return verificationPromise;
|
|
95
|
-
}
|
|
96
|
-
async _runVerificationInternal(configRepo, enclaveURL, releaseDigest) {
|
|
97
|
-
try {
|
|
98
|
-
// Reset state for this verification
|
|
99
|
-
this.updateState({
|
|
100
|
-
releaseDigest: releaseDigest,
|
|
101
|
-
runtime: { status: "pending" },
|
|
102
|
-
code: { status: "pending" },
|
|
103
|
-
verification: { status: "pending" },
|
|
104
|
-
});
|
|
105
|
-
// Step 2: Runtime attestation
|
|
106
|
-
this.updateStepState("runtime", { status: "loading" });
|
|
107
|
-
try {
|
|
108
|
-
const runtimeResult = await this.verifyEnclave(enclaveURL);
|
|
109
|
-
this.updateStepState("runtime", {
|
|
110
|
-
status: "success",
|
|
111
|
-
measurement: runtimeResult.measurement,
|
|
112
|
-
tlsPublicKeyFingerprint: runtimeResult.tlsPublicKeyFingerprint,
|
|
113
|
-
hpkePublicKey: runtimeResult.hpkePublicKey,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
catch (error) {
|
|
117
|
-
this.updateStepState("runtime", {
|
|
118
|
-
status: "error",
|
|
119
|
-
error: error instanceof Error ? error.message : "Runtime attestation failed",
|
|
120
|
-
});
|
|
121
|
-
this.updateStepState("verification", {
|
|
122
|
-
status: "error",
|
|
123
|
-
error: "Cannot verify security without runtime attestation",
|
|
124
|
-
});
|
|
125
|
-
return this.state;
|
|
126
|
-
}
|
|
127
|
-
// Step 3: Code attestation
|
|
128
|
-
this.updateStepState("code", { status: "loading" });
|
|
129
|
-
try {
|
|
130
|
-
const codeResult = await this.verifyCode(configRepo, releaseDigest);
|
|
131
|
-
this.updateStepState("code", {
|
|
132
|
-
status: "success",
|
|
133
|
-
measurement: codeResult.measurement,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
catch (error) {
|
|
137
|
-
this.updateStepState("code", {
|
|
138
|
-
status: "error",
|
|
139
|
-
error: error instanceof Error ? error.message : "Code attestation failed",
|
|
140
|
-
});
|
|
141
|
-
this.updateStepState("verification", {
|
|
142
|
-
status: "error",
|
|
143
|
-
error: "Cannot verify security without code attestation",
|
|
144
|
-
});
|
|
145
|
-
return this.state;
|
|
146
|
-
}
|
|
147
|
-
// Step 4: Compare measurements
|
|
148
|
-
this.updateStepState("verification", { status: "loading" });
|
|
149
|
-
const codeMeasurement = this.state.code.measurement;
|
|
150
|
-
const runtimeMeasurement = this.state.runtime.measurement;
|
|
151
|
-
// Use the compareMeasurements function
|
|
152
|
-
const measurementsMatch = compareMeasurements(codeMeasurement, runtimeMeasurement);
|
|
153
|
-
this.updateStepState("verification", {
|
|
154
|
-
status: "success",
|
|
155
|
-
securityVerified: measurementsMatch,
|
|
156
|
-
});
|
|
157
|
-
return this.state;
|
|
158
|
-
}
|
|
159
|
-
catch (error) {
|
|
160
|
-
// Catch any unexpected errors
|
|
161
|
-
if (this.state.verification.status === "pending" || this.state.verification.status === "loading") {
|
|
162
|
-
this.updateStepState("verification", {
|
|
163
|
-
status: "error",
|
|
164
|
-
error: error instanceof Error ? error.message : "Verification failed",
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
return this.state;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Load and initialize a verifier instance with state management
|
|
173
|
-
* @returns Initialized verifier instance with state management
|
|
174
|
-
*/
|
|
175
|
-
export async function loadVerifier() {
|
|
176
|
-
// Ensure WASM is initialized with the default runtime
|
|
177
|
-
await Verifier.initializeWasm();
|
|
178
|
-
// Return a new verifier instance with state management
|
|
179
|
-
return new VerifierWithState();
|
|
180
|
-
}
|
|
181
|
-
// Re-export utilities
|
|
182
|
-
export { suppressWasmLogs, TINFOIL_CONFIG };
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { Verifier, suppressWasmLogs } from "./verifier";
|
|
2
|
-
import type { AttestationMeasurement } from "./verifier";
|
|
3
|
-
import { TINFOIL_CONFIG } from "./config";
|
|
4
|
-
/**
|
|
5
|
-
* Step status for verification progress
|
|
6
|
-
*/
|
|
7
|
-
export type StepStatus = "pending" | "loading" | "success" | "error";
|
|
8
|
-
/**
|
|
9
|
-
* State for individual verification steps
|
|
10
|
-
*/
|
|
11
|
-
export interface StepState {
|
|
12
|
-
status: StepStatus;
|
|
13
|
-
measurement?: AttestationMeasurement;
|
|
14
|
-
error?: string;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Runtime verification state with additional key information
|
|
18
|
-
*/
|
|
19
|
-
export interface RuntimeStepState extends StepState {
|
|
20
|
-
tlsPublicKeyFingerprint?: string;
|
|
21
|
-
hpkePublicKey?: string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Final verification summary
|
|
25
|
-
*/
|
|
26
|
-
export interface VerificationSummary {
|
|
27
|
-
status: StepStatus;
|
|
28
|
-
securityVerified?: boolean;
|
|
29
|
-
error?: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Overall verification state
|
|
33
|
-
*/
|
|
34
|
-
export interface VerificationState {
|
|
35
|
-
releaseDigest: string;
|
|
36
|
-
runtime: RuntimeStepState;
|
|
37
|
-
code: StepState;
|
|
38
|
-
verification: VerificationSummary;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Verification result returned by runVerification
|
|
42
|
-
*/
|
|
43
|
-
export interface VerificationResult extends VerificationState {
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Options for runVerification method
|
|
47
|
-
*/
|
|
48
|
-
export interface RunVerificationOptions {
|
|
49
|
-
/** GitHub repository to verify. Defaults to TINFOIL_CONFIG.INFERENCE_PROXY_REPO */
|
|
50
|
-
configRepo?: string;
|
|
51
|
-
/** Enclave hostname to verify. Defaults to hostname from TINFOIL_CONFIG.INFERENCE_BASE_URL */
|
|
52
|
-
serverURL?: string;
|
|
53
|
-
/** Specific release digest to verify. If not provided, fetches latest release digest */
|
|
54
|
-
releaseDigest?: string;
|
|
55
|
-
/** Callback for receiving verification state updates */
|
|
56
|
-
onUpdate?: (state: VerificationState) => void;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Enhanced verifier with state management and subscription support
|
|
60
|
-
*/
|
|
61
|
-
export declare class VerifierWithState extends Verifier {
|
|
62
|
-
private state;
|
|
63
|
-
private subscribers;
|
|
64
|
-
/**
|
|
65
|
-
* Subscribe to verification state updates
|
|
66
|
-
* @param subscriber - Callback function to receive state updates
|
|
67
|
-
* @returns Unsubscribe function
|
|
68
|
-
*/
|
|
69
|
-
subscribe(subscriber: (state: VerificationState) => void): () => void;
|
|
70
|
-
/**
|
|
71
|
-
* Update state and notify subscribers
|
|
72
|
-
*/
|
|
73
|
-
private updateState;
|
|
74
|
-
/**
|
|
75
|
-
* Update a specific step state
|
|
76
|
-
*/
|
|
77
|
-
private updateStepState;
|
|
78
|
-
/**
|
|
79
|
-
* Run full verification flow with state updates
|
|
80
|
-
* @param options - Verification options
|
|
81
|
-
* @returns Final verification result
|
|
82
|
-
*/
|
|
83
|
-
runVerification(options?: RunVerificationOptions): Promise<VerificationResult>;
|
|
84
|
-
private _runVerificationInternal;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Load and initialize a verifier instance with state management
|
|
88
|
-
* @returns Initialized verifier instance with state management
|
|
89
|
-
*/
|
|
90
|
-
export declare function loadVerifier(): Promise<VerifierWithState>;
|
|
91
|
-
export { suppressWasmLogs, TINFOIL_CONFIG };
|