tinfoil 0.8.6 → 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/ai-sdk-provider.js +1 -1
- package/dist/encrypted-body-fetch.d.ts +1 -0
- package/dist/encrypted-body-fetch.js +43 -80
- package/dist/esm/ai-sdk-provider.js +1 -1
- package/dist/esm/encrypted-body-fetch.d.ts +1 -0
- package/dist/esm/encrypted-body-fetch.js +42 -80
- package/dist/esm/index.browser.d.ts +1 -2
- package/dist/esm/index.browser.js +1 -2
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.js +2 -3
- package/dist/esm/pinned-tls-fetch.d.ts +1 -1
- package/dist/esm/pinned-tls-fetch.js +4 -4
- package/dist/esm/secure-client.js +2 -21
- package/dist/esm/secure-fetch.browser.d.ts +1 -0
- package/dist/esm/secure-fetch.browser.js +10 -0
- package/dist/esm/secure-fetch.d.ts +1 -0
- package/dist/esm/secure-fetch.js +22 -0
- package/dist/esm/tinfoilai.js +1 -1
- package/dist/esm/verifier.d.ts +25 -5
- package/dist/esm/verifier.js +120 -56
- package/dist/index.browser.d.ts +1 -2
- package/dist/index.browser.js +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +4 -4
- package/dist/pinned-tls-fetch.d.ts +1 -1
- package/dist/pinned-tls-fetch.js +4 -4
- package/dist/secure-client.js +2 -21
- package/dist/secure-fetch.browser.d.ts +1 -0
- package/dist/secure-fetch.browser.js +13 -0
- package/dist/secure-fetch.d.ts +1 -0
- package/dist/secure-fetch.js +25 -0
- package/dist/tinfoilai.js +1 -1
- package/dist/verifier.d.ts +25 -5
- package/dist/verifier.js +120 -56
- package/package.json +7 -7
- package/dist/esm/secure-client.browser.d.ts +0 -20
- package/dist/esm/secure-client.browser.js +0 -57
- package/dist/esm/verification-runner.d.ts +0 -91
- package/dist/esm/verification-runner.js +0 -182
- package/dist/secure-client.browser.d.ts +0 -20
- package/dist/secure-client.browser.js +0 -61
- package/dist/verification-runner.d.ts +0 -91
- package/dist/verification-runner.js +0 -187
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SecureClient = void 0;
|
|
4
|
-
const verifier_1 = require("./verifier");
|
|
5
|
-
const config_1 = require("./config");
|
|
6
|
-
const encrypted_body_fetch_1 = require("./encrypted-body-fetch");
|
|
7
|
-
const env_1 = require("./env");
|
|
8
|
-
class SecureClient {
|
|
9
|
-
constructor(options = {}) {
|
|
10
|
-
this.initPromise = null;
|
|
11
|
-
this.verificationDocument = null;
|
|
12
|
-
this._fetch = null;
|
|
13
|
-
this.baseURL = options.baseURL || config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL;
|
|
14
|
-
this.enclaveURL = options.enclaveURL || config_1.TINFOIL_CONFIG.ENCLAVE_URL;
|
|
15
|
-
this.configRepo = options.configRepo || config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
|
|
16
|
-
}
|
|
17
|
-
async ready() {
|
|
18
|
-
if (!this.initPromise) {
|
|
19
|
-
this.initPromise = this.initSecureClient();
|
|
20
|
-
}
|
|
21
|
-
return this.initPromise;
|
|
22
|
-
}
|
|
23
|
-
async initSecureClient() {
|
|
24
|
-
const verifier = new verifier_1.Verifier({
|
|
25
|
-
serverURL: this.enclaveURL,
|
|
26
|
-
configRepo: this.configRepo,
|
|
27
|
-
});
|
|
28
|
-
await verifier.verify();
|
|
29
|
-
const doc = verifier.getVerificationDocument();
|
|
30
|
-
if (!doc) {
|
|
31
|
-
throw new Error("Verification document not available after successful verification");
|
|
32
|
-
}
|
|
33
|
-
this.verificationDocument = doc;
|
|
34
|
-
const hpkePublicKey = this.verificationDocument.enclaveMeasurement.hpkePublicKey;
|
|
35
|
-
if (!hpkePublicKey) {
|
|
36
|
-
if ((0, env_1.isRealBrowser)()) {
|
|
37
|
-
throw new Error("HPKE public key not available and TLS-only verification is not supported in browsers. " +
|
|
38
|
-
"Only HPKE-enabled enclaves can be used in browser environments.");
|
|
39
|
-
}
|
|
40
|
-
throw new Error("HPKE public key is required in browser environments");
|
|
41
|
-
}
|
|
42
|
-
this._fetch = (0, encrypted_body_fetch_1.createEncryptedBodyFetch)(this.baseURL, hpkePublicKey, this.enclaveURL);
|
|
43
|
-
}
|
|
44
|
-
async getVerificationDocument() {
|
|
45
|
-
if (!this.initPromise) {
|
|
46
|
-
await this.ready();
|
|
47
|
-
}
|
|
48
|
-
await this.initPromise;
|
|
49
|
-
if (!this.verificationDocument) {
|
|
50
|
-
throw new Error("Verification document unavailable: client not verified yet");
|
|
51
|
-
}
|
|
52
|
-
return this.verificationDocument;
|
|
53
|
-
}
|
|
54
|
-
get fetch() {
|
|
55
|
-
return async (input, init) => {
|
|
56
|
-
await this.ready();
|
|
57
|
-
return this._fetch(input, init);
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.SecureClient = SecureClient;
|
|
@@ -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,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
|
-
}
|