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.
@@ -1,187 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TINFOIL_CONFIG = exports.suppressWasmLogs = exports.VerifierWithState = void 0;
4
- exports.loadVerifier = loadVerifier;
5
- const verifier_1 = require("./verifier");
6
- Object.defineProperty(exports, "suppressWasmLogs", { enumerable: true, get: function () { return verifier_1.suppressWasmLogs; } });
7
- const config_1 = require("./config");
8
- Object.defineProperty(exports, "TINFOIL_CONFIG", { enumerable: true, get: function () { return config_1.TINFOIL_CONFIG; } });
9
- /**
10
- * Enhanced verifier with state management and subscription support
11
- */
12
- class VerifierWithState extends verifier_1.Verifier {
13
- constructor() {
14
- super(...arguments);
15
- // State management
16
- this.state = {
17
- releaseDigest: "",
18
- runtime: { status: "pending" },
19
- code: { status: "pending" },
20
- verification: { status: "pending" },
21
- };
22
- // Subscribers
23
- this.subscribers = new Set();
24
- }
25
- /**
26
- * Subscribe to verification state updates
27
- * @param subscriber - Callback function to receive state updates
28
- * @returns Unsubscribe function
29
- */
30
- subscribe(subscriber) {
31
- this.subscribers.add(subscriber);
32
- // Send current state immediately
33
- subscriber(this.state);
34
- return () => {
35
- this.subscribers.delete(subscriber);
36
- };
37
- }
38
- /**
39
- * Update state and notify subscribers
40
- */
41
- updateState(updates) {
42
- this.state = { ...this.state, ...updates };
43
- this.subscribers.forEach(subscriber => subscriber(this.state));
44
- }
45
- /**
46
- * Update a specific step state
47
- */
48
- updateStepState(step, updates) {
49
- this.state = {
50
- ...this.state,
51
- [step]: { ...this.state[step], ...updates }
52
- };
53
- this.subscribers.forEach(subscriber => subscriber(this.state));
54
- }
55
- /**
56
- * Run full verification flow with state updates
57
- * @param options - Verification options
58
- * @returns Final verification result
59
- */
60
- async runVerification(options) {
61
- const configRepo = options?.configRepo || config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
62
- const enclaveURL = options?.serverURL || new URL(config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL).hostname;
63
- let releaseDigest = options?.releaseDigest || "";
64
- // If no digest provided, we need to fetch it first before checking cache
65
- if (!releaseDigest) {
66
- // Reset state for fresh verification
67
- this.updateState({
68
- releaseDigest: "resolving...",
69
- runtime: { status: "pending" },
70
- code: { status: "pending" },
71
- verification: { status: "pending" },
72
- });
73
- try {
74
- releaseDigest = await this.fetchLatestDigest(configRepo);
75
- this.updateState({ releaseDigest: releaseDigest });
76
- }
77
- catch (error) {
78
- // If we can't fetch the digest, mark all steps as error
79
- this.updateState({ releaseDigest: "" });
80
- this.updateStepState("code", {
81
- status: "error",
82
- error: error instanceof Error ? error.message : "Failed to fetch digest",
83
- });
84
- this.updateStepState("runtime", {
85
- status: "error",
86
- error: "Cannot proceed without digest",
87
- });
88
- this.updateStepState("verification", {
89
- status: "error",
90
- error: "Cannot proceed without digest",
91
- });
92
- return this.state;
93
- }
94
- }
95
- const verificationPromise = this._runVerificationInternal(configRepo, enclaveURL, releaseDigest);
96
- if (options?.onUpdate) {
97
- const unsubscribe = this.subscribe(options.onUpdate);
98
- verificationPromise.finally(() => unsubscribe());
99
- }
100
- return verificationPromise;
101
- }
102
- async _runVerificationInternal(configRepo, enclaveURL, releaseDigest) {
103
- try {
104
- // Reset state for this verification
105
- this.updateState({
106
- releaseDigest: releaseDigest,
107
- runtime: { status: "pending" },
108
- code: { status: "pending" },
109
- verification: { status: "pending" },
110
- });
111
- // Step 2: Runtime attestation
112
- this.updateStepState("runtime", { status: "loading" });
113
- try {
114
- const runtimeResult = await this.verifyEnclave(enclaveURL);
115
- this.updateStepState("runtime", {
116
- status: "success",
117
- measurement: runtimeResult.measurement,
118
- tlsPublicKeyFingerprint: runtimeResult.tlsPublicKeyFingerprint,
119
- hpkePublicKey: runtimeResult.hpkePublicKey,
120
- });
121
- }
122
- catch (error) {
123
- this.updateStepState("runtime", {
124
- status: "error",
125
- error: error instanceof Error ? error.message : "Runtime attestation failed",
126
- });
127
- this.updateStepState("verification", {
128
- status: "error",
129
- error: "Cannot verify security without runtime attestation",
130
- });
131
- return this.state;
132
- }
133
- // Step 3: Code attestation
134
- this.updateStepState("code", { status: "loading" });
135
- try {
136
- const codeResult = await this.verifyCode(configRepo, releaseDigest);
137
- this.updateStepState("code", {
138
- status: "success",
139
- measurement: codeResult.measurement,
140
- });
141
- }
142
- catch (error) {
143
- this.updateStepState("code", {
144
- status: "error",
145
- error: error instanceof Error ? error.message : "Code attestation failed",
146
- });
147
- this.updateStepState("verification", {
148
- status: "error",
149
- error: "Cannot verify security without code attestation",
150
- });
151
- return this.state;
152
- }
153
- // Step 4: Compare measurements
154
- this.updateStepState("verification", { status: "loading" });
155
- const codeMeasurement = this.state.code.measurement;
156
- const runtimeMeasurement = this.state.runtime.measurement;
157
- // Use the compareMeasurements function
158
- const measurementsMatch = (0, verifier_1.compareMeasurements)(codeMeasurement, runtimeMeasurement);
159
- this.updateStepState("verification", {
160
- status: "success",
161
- securityVerified: measurementsMatch,
162
- });
163
- return this.state;
164
- }
165
- catch (error) {
166
- // Catch any unexpected errors
167
- if (this.state.verification.status === "pending" || this.state.verification.status === "loading") {
168
- this.updateStepState("verification", {
169
- status: "error",
170
- error: error instanceof Error ? error.message : "Verification failed",
171
- });
172
- }
173
- return this.state;
174
- }
175
- }
176
- }
177
- exports.VerifierWithState = VerifierWithState;
178
- /**
179
- * Load and initialize a verifier instance with state management
180
- * @returns Initialized verifier instance with state management
181
- */
182
- async function loadVerifier() {
183
- // Ensure WASM is initialized with the default runtime
184
- await verifier_1.Verifier.initializeWasm();
185
- // Return a new verifier instance with state management
186
- return new VerifierWithState();
187
- }