tinfoil 0.9.1 → 0.10.1

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.
Files changed (45) hide show
  1. package/README.md +34 -0
  2. package/dist/ai-sdk-provider.js +8 -3
  3. package/dist/config.d.ts +4 -11
  4. package/dist/config.js +4 -11
  5. package/dist/encrypted-body-fetch.d.ts +3 -5
  6. package/dist/encrypted-body-fetch.js +34 -93
  7. package/dist/esm/{ai-sdk-provider.js → ai-sdk-provider.mjs} +10 -5
  8. package/dist/esm/config.d.ts +4 -11
  9. package/dist/esm/config.mjs +13 -0
  10. package/dist/esm/encrypted-body-fetch.d.ts +3 -5
  11. package/dist/esm/{encrypted-body-fetch.js → encrypted-body-fetch.mjs} +29 -54
  12. package/dist/esm/index.browser.mjs +8 -0
  13. package/dist/esm/index.d.ts +1 -0
  14. package/dist/esm/{index.js → index.mjs} +8 -7
  15. package/dist/esm/router.d.ts +11 -0
  16. package/dist/esm/router.mjs +33 -0
  17. package/dist/esm/secure-client.d.ts +3 -2
  18. package/dist/esm/secure-client.mjs +153 -0
  19. package/dist/esm/{secure-fetch.browser.js → secure-fetch.browser.mjs} +1 -1
  20. package/dist/esm/{secure-fetch.js → secure-fetch.mjs} +3 -3
  21. package/dist/esm/{tinfoilai.js → tinfoilai.mjs} +8 -6
  22. package/dist/esm/unverified-client.d.ts +2 -2
  23. package/dist/esm/unverified-client.mjs +61 -0
  24. package/dist/esm/verifier.d.ts +4 -1
  25. package/dist/esm/{verifier.js → verifier.mjs} +18 -6
  26. package/dist/esm/wasm-exec.mjs +668 -0
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.js +3 -1
  29. package/dist/router.d.ts +11 -0
  30. package/dist/router.js +36 -0
  31. package/dist/secure-client.d.ts +3 -2
  32. package/dist/secure-client.js +116 -13
  33. package/dist/tinfoilai.js +5 -3
  34. package/dist/unverified-client.d.ts +2 -2
  35. package/dist/unverified-client.js +30 -2
  36. package/dist/verifier.d.ts +4 -1
  37. package/dist/verifier.js +16 -4
  38. package/package.json +15 -15
  39. package/dist/esm/config.js +0 -20
  40. package/dist/esm/index.browser.js +0 -8
  41. package/dist/esm/secure-client.js +0 -50
  42. package/dist/esm/unverified-client.js +0 -33
  43. /package/dist/esm/__tests__/{test-utils.js → test-utils.mjs} +0 -0
  44. /package/dist/esm/{env.js → env.mjs} +0 -0
  45. /package/dist/esm/{pinned-tls-fetch.js → pinned-tls-fetch.mjs} +0 -0
package/dist/router.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchRouter = fetchRouter;
4
+ const config_1 = require("./config");
5
+ /**
6
+ * Router utilities for fetching available Tinfoil routers
7
+ */
8
+ /**
9
+ * Fetches the list of available routers from the ATC API
10
+ * and returns a randomly selected address.
11
+ *
12
+ * @returns Promise<string> A randomly selected router address
13
+ * @throws Error if no routers are found or if the request fails
14
+ */
15
+ async function fetchRouter() {
16
+ const routersUrl = config_1.TINFOIL_CONFIG.ATC_API_URL;
17
+ try {
18
+ const response = await fetch(routersUrl);
19
+ if (!response.ok) {
20
+ throw new Error(`Failed to fetch routers: ${response.status} ${response.statusText}`);
21
+ }
22
+ const routers = await response.json();
23
+ if (!Array.isArray(routers) || routers.length === 0) {
24
+ throw new Error("No routers found in the response");
25
+ }
26
+ // Return a randomly selected router
27
+ const randomIndex = Math.floor(Math.random() * routers.length);
28
+ return routers[randomIndex];
29
+ }
30
+ catch (error) {
31
+ if (error instanceof Error) {
32
+ throw new Error(`Failed to fetch router: ${error.message}`);
33
+ }
34
+ throw new Error("Failed to fetch router: Unknown error");
35
+ }
36
+ }
@@ -8,13 +8,14 @@ export declare class SecureClient {
8
8
  private initPromise;
9
9
  private verificationDocument;
10
10
  private _fetch;
11
- private readonly baseURL?;
12
- private readonly enclaveURL?;
11
+ private baseURL?;
12
+ private enclaveURL?;
13
13
  private readonly configRepo?;
14
14
  constructor(options?: SecureClientOptions);
15
15
  ready(): Promise<void>;
16
16
  private initSecureClient;
17
17
  getVerificationDocument(): Promise<VerificationDocument>;
18
+ getBaseURL(): string | undefined;
18
19
  get fetch(): typeof fetch;
19
20
  }
20
21
  export {};
@@ -4,13 +4,14 @@ exports.SecureClient = void 0;
4
4
  const verifier_1 = require("./verifier");
5
5
  const config_1 = require("./config");
6
6
  const secure_fetch_1 = require("tinfoil/secure-fetch");
7
+ const router_1 = require("./router");
7
8
  class SecureClient {
8
9
  constructor(options = {}) {
9
10
  this.initPromise = null;
10
11
  this.verificationDocument = null;
11
12
  this._fetch = null;
12
- this.baseURL = options.baseURL || config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL;
13
- this.enclaveURL = options.enclaveURL || config_1.TINFOIL_CONFIG.ENCLAVE_URL;
13
+ this.baseURL = options.baseURL;
14
+ this.enclaveURL = options.enclaveURL;
14
15
  this.configRepo = options.configRepo || config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
15
16
  }
16
17
  async ready() {
@@ -20,34 +21,136 @@ class SecureClient {
20
21
  return this.initPromise;
21
22
  }
22
23
  async initSecureClient() {
24
+ // Only fetch router if neither baseURL nor enclaveURL is provided
25
+ if (!this.baseURL && !this.enclaveURL) {
26
+ const routerAddress = await (0, router_1.fetchRouter)();
27
+ this.enclaveURL = `https://${routerAddress}`;
28
+ this.baseURL = `https://${routerAddress}/v1/`;
29
+ }
30
+ // Ensure both baseURL and enclaveURL are initialized
31
+ if (!this.baseURL) {
32
+ if (this.enclaveURL) {
33
+ // If enclaveURL is provided but baseURL is not, derive baseURL from enclaveURL
34
+ const enclaveUrl = new URL(this.enclaveURL);
35
+ this.baseURL = `${enclaveUrl.origin}/v1/`;
36
+ }
37
+ else {
38
+ throw new Error("Unable to determine baseURL: neither baseURL nor enclaveURL provided");
39
+ }
40
+ }
41
+ if (!this.enclaveURL) {
42
+ if (this.baseURL) {
43
+ // If baseURL is provided but enclaveURL is not, derive enclaveURL from baseURL
44
+ const baseUrl = new URL(this.baseURL);
45
+ this.enclaveURL = baseUrl.origin;
46
+ }
47
+ else {
48
+ throw new Error("Unable to determine enclaveURL: neither baseURL nor enclaveURL provided");
49
+ }
50
+ }
23
51
  const verifier = new verifier_1.Verifier({
24
52
  serverURL: this.enclaveURL,
25
53
  configRepo: this.configRepo,
26
54
  });
27
- await verifier.verify();
28
- const doc = verifier.getVerificationDocument();
29
- if (!doc) {
30
- throw new Error("Verification document not available after successful verification");
31
- }
32
- this.verificationDocument = doc;
33
- // Extract keys from the verification document
34
- const { hpkePublicKey, tlsPublicKeyFingerprint } = this.verificationDocument.enclaveMeasurement;
35
- this._fetch = (0, secure_fetch_1.createSecureFetch)(this.baseURL, this.enclaveURL, hpkePublicKey, tlsPublicKeyFingerprint);
55
+ try {
56
+ await verifier.verify();
57
+ const doc = verifier.getVerificationDocument();
58
+ if (!doc) {
59
+ throw new Error("Verification document not available after successful verification");
60
+ }
61
+ this.verificationDocument = doc;
62
+ // Extract keys from the verification document
63
+ const { hpkePublicKey, tlsPublicKeyFingerprint } = this.verificationDocument.enclaveMeasurement;
64
+ try {
65
+ this._fetch = (0, secure_fetch_1.createSecureFetch)(this.baseURL, this.enclaveURL, hpkePublicKey, tlsPublicKeyFingerprint);
66
+ }
67
+ catch (transportError) {
68
+ this.verificationDocument.steps.createTransport = {
69
+ status: 'failed',
70
+ error: transportError.message
71
+ };
72
+ this.verificationDocument.securityVerified = false;
73
+ throw transportError;
74
+ }
75
+ }
76
+ catch (error) {
77
+ const doc = verifier.getVerificationDocument();
78
+ if (doc) {
79
+ this.verificationDocument = doc;
80
+ }
81
+ else {
82
+ this.verificationDocument = {
83
+ configRepo: this.configRepo,
84
+ enclaveHost: new URL(this.enclaveURL).hostname,
85
+ releaseDigest: '',
86
+ codeMeasurement: { type: '', registers: [] },
87
+ enclaveMeasurement: { measurement: { type: '', registers: [] } },
88
+ securityVerified: false,
89
+ steps: {
90
+ fetchDigest: { status: 'pending' },
91
+ verifyCode: { status: 'pending' },
92
+ verifyEnclave: { status: 'pending' },
93
+ compareMeasurements: { status: 'pending' },
94
+ otherError: { status: 'failed', error: error.message }
95
+ }
96
+ };
97
+ }
98
+ throw error;
99
+ }
36
100
  }
37
101
  async getVerificationDocument() {
38
102
  if (!this.initPromise) {
39
103
  await this.ready();
40
104
  }
41
- await this.initPromise;
105
+ await this.initPromise.catch(() => { });
42
106
  if (!this.verificationDocument) {
43
107
  throw new Error("Verification document unavailable: client not verified yet");
44
108
  }
45
109
  return this.verificationDocument;
46
110
  }
111
+ getBaseURL() {
112
+ return this.baseURL;
113
+ }
47
114
  get fetch() {
48
115
  return async (input, init) => {
49
116
  await this.ready();
50
- return this._fetch(input, init);
117
+ try {
118
+ return await this._fetch(input, init);
119
+ }
120
+ catch (error) {
121
+ if (this.verificationDocument) {
122
+ const errorMessage = error.message;
123
+ if (errorMessage.includes('HPKE public key mismatch')) {
124
+ this.verificationDocument.steps.verifyHPKEKey = {
125
+ status: 'failed',
126
+ error: errorMessage
127
+ };
128
+ this.verificationDocument.securityVerified = false;
129
+ }
130
+ else if (errorMessage.includes('Transport initialization failed') || errorMessage.includes('Request initialization failed')) {
131
+ this.verificationDocument.steps.createTransport = {
132
+ status: 'failed',
133
+ error: errorMessage
134
+ };
135
+ this.verificationDocument.securityVerified = false;
136
+ }
137
+ else if (errorMessage.includes('Failed to get HPKE key')) {
138
+ this.verificationDocument.steps.verifyHPKEKey = {
139
+ status: 'failed',
140
+ error: errorMessage
141
+ };
142
+ this.verificationDocument.securityVerified = false;
143
+ }
144
+ else {
145
+ this.verificationDocument.steps.otherError = {
146
+ status: 'failed',
147
+ error: errorMessage
148
+ };
149
+ this.verificationDocument.securityVerified = false;
150
+ }
151
+ }
152
+ throw error;
153
+ }
51
154
  };
52
155
  }
53
156
  }
package/dist/tinfoilai.js CHANGED
@@ -42,8 +42,8 @@ class TinfoilAI {
42
42
  openAIOptions.apiKey = process.env.TINFOIL_API_KEY;
43
43
  }
44
44
  this.apiKey = openAIOptions.apiKey;
45
- this.baseURL = options.baseURL || config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL;
46
- this.enclaveURL = options.enclaveURL || config_1.TINFOIL_CONFIG.ENCLAVE_URL;
45
+ this.baseURL = options.baseURL;
46
+ this.enclaveURL = options.enclaveURL;
47
47
  this.configRepo = options.configRepo || config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
48
48
  this.secureClient = new secure_client_1.SecureClient({
49
49
  baseURL: this.baseURL,
@@ -69,9 +69,11 @@ class TinfoilAI {
69
69
  if (!this.verificationDocument) {
70
70
  throw new Error("Verification document not available after successful verification");
71
71
  }
72
+ // Use the provided baseURL, or get it from SecureClient after initialization
73
+ const baseURL = this.baseURL || this.secureClient.getBaseURL();
72
74
  const clientOptions = {
73
75
  ...options,
74
- baseURL: this.baseURL,
76
+ baseURL: baseURL,
75
77
  fetch: this.secureClient.fetch,
76
78
  };
77
79
  if ((0, env_1.isRealBrowser)() || options.dangerouslyAllowBrowser === true) {
@@ -6,8 +6,8 @@ interface UnverifiedClientOptions {
6
6
  export declare class UnverifiedClient {
7
7
  private initPromise;
8
8
  private _fetch;
9
- private readonly baseURL;
10
- private readonly enclaveURL;
9
+ private baseURL?;
10
+ private enclaveURL?;
11
11
  private readonly configRepo;
12
12
  constructor(options?: UnverifiedClientOptions);
13
13
  ready(): Promise<void>;
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UnverifiedClient = void 0;
4
4
  const config_1 = require("./config");
5
5
  const encrypted_body_fetch_1 = require("./encrypted-body-fetch");
6
+ const router_1 = require("./router");
6
7
  class UnverifiedClient {
7
8
  constructor(options = {}) {
8
9
  this.initPromise = null;
9
10
  this._fetch = null;
10
- this.baseURL = options.baseURL || config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL;
11
- this.enclaveURL = options.enclaveURL || config_1.TINFOIL_CONFIG.ENCLAVE_URL;
11
+ this.baseURL = options.baseURL;
12
+ this.enclaveURL = options.enclaveURL;
12
13
  this.configRepo = options.configRepo || config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
13
14
  }
14
15
  async ready() {
@@ -18,6 +19,33 @@ class UnverifiedClient {
18
19
  return this.initPromise;
19
20
  }
20
21
  async initUnverifiedClient() {
22
+ // Only fetch router if neither baseURL nor enclaveURL is provided
23
+ if (!this.baseURL && !this.enclaveURL) {
24
+ const routerAddress = await (0, router_1.fetchRouter)();
25
+ this.enclaveURL = `https://${routerAddress}`;
26
+ this.baseURL = `https://${routerAddress}/v1/`;
27
+ }
28
+ // Ensure both baseURL and enclaveURL are initialized
29
+ if (!this.baseURL) {
30
+ if (this.enclaveURL) {
31
+ // If enclaveURL is provided but baseURL is not, derive baseURL from enclaveURL
32
+ const enclaveUrl = new URL(this.enclaveURL);
33
+ this.baseURL = `${enclaveUrl.origin}/v1/`;
34
+ }
35
+ else {
36
+ throw new Error("Unable to determine baseURL: neither baseURL nor enclaveURL provided");
37
+ }
38
+ }
39
+ if (!this.enclaveURL) {
40
+ if (this.baseURL) {
41
+ // If baseURL is provided but enclaveURL is not, derive enclaveURL from baseURL
42
+ const baseUrl = new URL(this.baseURL);
43
+ this.enclaveURL = baseUrl.origin;
44
+ }
45
+ else {
46
+ throw new Error("Unable to determine enclaveURL: neither baseURL nor enclaveURL provided");
47
+ }
48
+ }
21
49
  this._fetch = (0, encrypted_body_fetch_1.createEncryptedBodyFetch)(this.baseURL, undefined, this.enclaveURL);
22
50
  }
23
51
  async getVerificationDocument() {
@@ -37,6 +37,9 @@ export interface VerificationDocument {
37
37
  verifyCode: VerificationStepState;
38
38
  verifyEnclave: VerificationStepState;
39
39
  compareMeasurements: VerificationStepState;
40
+ createTransport?: VerificationStepState;
41
+ verifyHPKEKey?: VerificationStepState;
42
+ otherError?: VerificationStepState;
40
43
  };
41
44
  }
42
45
  export interface MeasurementComparisonResult {
@@ -84,7 +87,7 @@ export declare class Verifier {
84
87
  private static executeWithWasm;
85
88
  /**
86
89
  * Fetch the latest release digest from GitHub
87
- * @param configRepo - Repository name (e.g., "tinfoilsh/confidential-inference-proxy")
90
+ * @param configRepo - Repository name (e.g., "tinfoilsh/confidential-model-router")
88
91
  * @returns The digest hash
89
92
  */
90
93
  fetchLatestDigest(configRepo?: string): Promise<string>;
package/dist/verifier.js CHANGED
@@ -163,7 +163,8 @@ function compareMeasurementsError(codeMeasurement, runtimeMeasurement) {
163
163
  }
164
164
  if (codeMeasurement.type === PLATFORM_TYPES.SNP_TDX_MULTI_PLATFORM_V1) {
165
165
  switch (runtimeMeasurement.type) {
166
- case PLATFORM_TYPES.TDX_GUEST_V1: {
166
+ case PLATFORM_TYPES.TDX_GUEST_V1:
167
+ case PLATFORM_TYPES.TDX_GUEST_V2: {
167
168
  if (codeMeasurement.registers.length < 3 || runtimeMeasurement.registers.length < 4) {
168
169
  return new Error(MEASUREMENT_ERROR_MESSAGES.FEW_REGISTERS);
169
170
  }
@@ -233,8 +234,10 @@ function compareMeasurements(codeMeasurement, runtimeMeasurement) {
233
234
  */
234
235
  class Verifier {
235
236
  constructor(options) {
236
- const serverURL = options?.serverURL ?? config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL;
237
- this.serverURL = new URL(serverURL).hostname;
237
+ if (!options?.serverURL) {
238
+ throw new Error("serverURL is required for Verifier");
239
+ }
240
+ this.serverURL = new URL(options.serverURL).hostname;
238
241
  this.configRepo = options?.configRepo ?? config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
239
242
  }
240
243
  /**
@@ -295,7 +298,7 @@ class Verifier {
295
298
  }
296
299
  /**
297
300
  * Fetch the latest release digest from GitHub
298
- * @param configRepo - Repository name (e.g., "tinfoilsh/confidential-inference-proxy")
301
+ * @param configRepo - Repository name (e.g., "tinfoilsh/confidential-model-router")
299
302
  * @returns The digest hash
300
303
  */
301
304
  async fetchLatestDigest(configRepo) {
@@ -478,6 +481,15 @@ class Verifier {
478
481
  }
479
482
  catch (error) {
480
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
+ };
481
493
  throw error;
482
494
  }
483
495
  try {
package/package.json CHANGED
@@ -1,58 +1,58 @@
1
1
  {
2
2
  "name": "tinfoil",
3
- "version": "0.9.1",
3
+ "version": "0.10.1",
4
4
  "description": "Tinfoil secure OpenAI client wrapper",
5
5
  "main": "dist/index.js",
6
- "module": "dist/esm/index.js",
6
+ "module": "dist/esm/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
8
  "browser": {
9
- "./dist/index.js": "./dist/esm/index.browser.js",
10
- "./dist/esm/index.js": "./dist/esm/index.browser.js"
9
+ "./dist/index.js": "./dist/esm/index.browser.mjs",
10
+ "./dist/esm/index.mjs": "./dist/esm/index.browser.mjs"
11
11
  },
12
12
  "exports": {
13
13
  ".": {
14
14
  "types": "./dist/index.d.ts",
15
- "browser": "./dist/esm/index.browser.js",
16
- "import": "./dist/esm/index.js",
15
+ "browser": "./dist/esm/index.browser.mjs",
16
+ "import": "./dist/esm/index.mjs",
17
17
  "require": "./dist/index.js",
18
18
  "default": "./dist/index.js"
19
19
  },
20
20
  "./client": {
21
21
  "types": "./dist/client.d.ts",
22
- "import": "./dist/esm/client.js",
22
+ "import": "./dist/esm/client.mjs",
23
23
  "require": "./dist/client.js"
24
24
  },
25
25
  "./ai-sdk-provider": {
26
26
  "types": "./dist/ai-sdk-provider.d.ts",
27
- "import": "./dist/esm/ai-sdk-provider.js",
27
+ "import": "./dist/esm/ai-sdk-provider.mjs",
28
28
  "require": "./dist/ai-sdk-provider.js"
29
29
  },
30
30
  "./verifier": {
31
31
  "types": "./dist/verifier.d.ts",
32
- "import": "./dist/esm/verifier.js",
32
+ "import": "./dist/esm/verifier.mjs",
33
33
  "require": "./dist/verifier.js"
34
34
  },
35
35
  "./config": {
36
36
  "types": "./dist/config.d.ts",
37
- "import": "./dist/esm/config.js",
37
+ "import": "./dist/esm/config.mjs",
38
38
  "require": "./dist/config.js"
39
39
  },
40
40
  "./secure-client": {
41
41
  "types": "./dist/secure-client.d.ts",
42
- "import": "./dist/esm/secure-client.js",
42
+ "import": "./dist/esm/secure-client.mjs",
43
43
  "require": "./dist/secure-client.js"
44
44
  },
45
45
  "./secure-fetch": {
46
46
  "types": "./dist/secure-fetch.d.ts",
47
- "browser": "./dist/esm/secure-fetch.browser.js",
48
- "import": "./dist/esm/secure-fetch.js",
47
+ "browser": "./dist/esm/secure-fetch.browser.mjs",
48
+ "import": "./dist/esm/secure-fetch.mjs",
49
49
  "require": "./dist/secure-fetch.js"
50
50
  }
51
51
  },
52
52
  "scripts": {
53
53
  "build": "npm run build:cjs && npm run build:esm",
54
54
  "build:cjs": "tsc && cp src/wasm-exec.js dist/",
55
- "build:esm": "tsc -p tsconfig.esm.json && cp src/wasm-exec.js dist/esm/",
55
+ "build:esm": "tsc -p tsconfig.esm.json && node scripts/convert-to-mjs.js && cp src/wasm-exec.js dist/esm/",
56
56
  "test": "bash -lc 'rm -rf dist .node-tests && npm run build:cjs && tsc -p tsconfig.node-test.json && cp src/wasm-exec.js .node-tests/ && node --test $(find .node-tests -name \"*.test.js\" -print)'",
57
57
  "lint": "eslint src/**/*.ts",
58
58
  "prepublishOnly": "npm run build"
@@ -81,7 +81,7 @@
81
81
  "@ai-sdk/openai-compatible": "^1.0.10",
82
82
  "ai": "^5.0.19",
83
83
  "dotenv": "^17.2.1",
84
- "ehbp": "^0.0.2",
84
+ "ehbp": "^0.0.4",
85
85
  "openai": "^5.13.1",
86
86
  "ts-node": "^10.9.2"
87
87
  },
@@ -1,20 +0,0 @@
1
- /**
2
- * Configuration constants for the Tinfoil Node SDK
3
- */
4
- export const TINFOIL_CONFIG = {
5
- /**
6
- * The full base URL for the inference API
7
- */
8
- INFERENCE_BASE_URL: "https://inference.tinfoil.sh/v1/",
9
- /**
10
- * The URL used to fetch the enclave server public key (via EHBP .well-known endpoint).
11
- * and the attestation (vial the attestation .well-known endpoint too).
12
- * Defaults to the same value as `INFERENCE_BASE_URL` so enclaveURL and baseURL share
13
- * the same default. Callers may override independently if key discovery is hosted elsewhere.
14
- */
15
- ENCLAVE_URL: "https://inference.tinfoil.sh/v1/",
16
- /**
17
- * The GitHub repository for the confidential inference proxy
18
- */
19
- INFERENCE_PROXY_REPO: "tinfoilsh/confidential-inference-proxy",
20
- };
@@ -1,8 +0,0 @@
1
- // Browser-safe entry point: avoids Node built-ins
2
- export { TinfoilAI } from "./tinfoilai";
3
- export { TinfoilAI as default } from "./tinfoilai";
4
- export * from "./verifier";
5
- export * from "./ai-sdk-provider";
6
- export * from "./config";
7
- export { SecureClient } from "./secure-client";
8
- export { UnverifiedClient } from "./unverified-client";
@@ -1,50 +0,0 @@
1
- import { Verifier } from "./verifier";
2
- import { TINFOIL_CONFIG } from "./config";
3
- import { createSecureFetch } from "tinfoil/secure-fetch";
4
- export class SecureClient {
5
- constructor(options = {}) {
6
- this.initPromise = null;
7
- this.verificationDocument = null;
8
- this._fetch = null;
9
- this.baseURL = options.baseURL || TINFOIL_CONFIG.INFERENCE_BASE_URL;
10
- this.enclaveURL = options.enclaveURL || TINFOIL_CONFIG.ENCLAVE_URL;
11
- this.configRepo = options.configRepo || TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
12
- }
13
- async ready() {
14
- if (!this.initPromise) {
15
- this.initPromise = this.initSecureClient();
16
- }
17
- return this.initPromise;
18
- }
19
- async initSecureClient() {
20
- const verifier = new Verifier({
21
- serverURL: this.enclaveURL,
22
- configRepo: this.configRepo,
23
- });
24
- await verifier.verify();
25
- const doc = verifier.getVerificationDocument();
26
- if (!doc) {
27
- throw new Error("Verification document not available after successful verification");
28
- }
29
- this.verificationDocument = doc;
30
- // Extract keys from the verification document
31
- const { hpkePublicKey, tlsPublicKeyFingerprint } = this.verificationDocument.enclaveMeasurement;
32
- this._fetch = createSecureFetch(this.baseURL, this.enclaveURL, hpkePublicKey, tlsPublicKeyFingerprint);
33
- }
34
- async getVerificationDocument() {
35
- if (!this.initPromise) {
36
- await this.ready();
37
- }
38
- await this.initPromise;
39
- if (!this.verificationDocument) {
40
- throw new Error("Verification document unavailable: client not verified yet");
41
- }
42
- return this.verificationDocument;
43
- }
44
- get fetch() {
45
- return async (input, init) => {
46
- await this.ready();
47
- return this._fetch(input, init);
48
- };
49
- }
50
- }
@@ -1,33 +0,0 @@
1
- import { TINFOIL_CONFIG } from "./config";
2
- import { createEncryptedBodyFetch } from "./encrypted-body-fetch";
3
- export class UnverifiedClient {
4
- constructor(options = {}) {
5
- this.initPromise = null;
6
- this._fetch = null;
7
- this.baseURL = options.baseURL || TINFOIL_CONFIG.INFERENCE_BASE_URL;
8
- this.enclaveURL = options.enclaveURL || TINFOIL_CONFIG.ENCLAVE_URL;
9
- this.configRepo = options.configRepo || TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
10
- }
11
- async ready() {
12
- if (!this.initPromise) {
13
- this.initPromise = this.initUnverifiedClient();
14
- }
15
- return this.initPromise;
16
- }
17
- async initUnverifiedClient() {
18
- this._fetch = createEncryptedBodyFetch(this.baseURL, undefined, this.enclaveURL);
19
- }
20
- async getVerificationDocument() {
21
- if (!this.initPromise) {
22
- await this.ready();
23
- }
24
- await this.initPromise;
25
- throw new Error("Verification document unavailable: this version of the client is unverified");
26
- }
27
- get fetch() {
28
- return async (input, init) => {
29
- await this.ready();
30
- return this._fetch(input, init);
31
- };
32
- }
33
- }
File without changes