@zeke-02/tinfoil 0.0.2 → 0.0.4

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 (43) hide show
  1. package/dist/ai-sdk-provider.js +8 -3
  2. package/dist/config.d.ts +4 -8
  3. package/dist/config.js +4 -8
  4. package/dist/encrypted-body-fetch.d.ts +3 -2
  5. package/dist/encrypted-body-fetch.js +31 -16
  6. package/dist/esm/{ai-sdk-provider.js → ai-sdk-provider.mjs} +10 -5
  7. package/dist/esm/config.d.ts +4 -8
  8. package/dist/esm/{config.js → config.mjs} +4 -8
  9. package/dist/esm/encrypted-body-fetch.d.ts +3 -2
  10. package/dist/esm/{encrypted-body-fetch.js → encrypted-body-fetch.mjs} +32 -17
  11. package/dist/esm/index.browser.mjs +8 -0
  12. package/dist/esm/index.d.ts +1 -0
  13. package/dist/esm/{index.js → index.mjs} +8 -7
  14. package/dist/esm/router.d.ts +11 -0
  15. package/dist/esm/router.mjs +33 -0
  16. package/dist/esm/secure-client.d.ts +3 -2
  17. package/dist/esm/{secure-client.js → secure-client.mjs} +36 -5
  18. package/dist/esm/{secure-fetch.browser.js → secure-fetch.browser.mjs} +1 -1
  19. package/dist/esm/{secure-fetch.js → secure-fetch.mjs} +3 -3
  20. package/dist/esm/{tinfoilai.js → tinfoilai.mjs} +8 -6
  21. package/dist/esm/unverified-client.d.ts +2 -2
  22. package/dist/esm/unverified-client.mjs +61 -0
  23. package/dist/esm/verifier.d.ts +1 -1
  24. package/dist/esm/{verifier.js → verifier.mjs} +10 -7
  25. package/dist/esm/wasm-exec.mjs +668 -0
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.js +3 -1
  28. package/dist/router.d.ts +11 -0
  29. package/dist/router.js +36 -0
  30. package/dist/secure-client.d.ts +3 -2
  31. package/dist/secure-client.js +33 -2
  32. package/dist/tinfoilai.js +5 -3
  33. package/dist/unverified-client.d.ts +2 -2
  34. package/dist/unverified-client.js +30 -2
  35. package/dist/verifier.d.ts +1 -1
  36. package/dist/verifier.js +7 -4
  37. package/package.json +22 -16
  38. package/dist/esm/index.browser.js +0 -8
  39. package/dist/esm/unverified-client.js +0 -33
  40. /package/dist/esm/__tests__/{test-utils.js → test-utils.mjs} +0 -0
  41. /package/dist/esm/{env.js → env.mjs} +0 -0
  42. /package/dist/esm/{fetch-adapter.js → fetch-adapter.mjs} +0 -0
  43. /package/dist/esm/{pinned-tls-fetch.js → pinned-tls-fetch.mjs} +0 -0
package/dist/index.d.ts CHANGED
@@ -5,4 +5,5 @@ export * from "./ai-sdk-provider";
5
5
  export * from "./config";
6
6
  export { SecureClient } from "./secure-client";
7
7
  export { UnverifiedClient } from "./unverified-client";
8
+ export { fetchRouter } from "./router";
8
9
  export { type Uploadable, toFile, APIPromise, PagePromise, OpenAIError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "openai";
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.UnprocessableEntityError = exports.PermissionDeniedError = exports.InternalServerError = exports.AuthenticationError = exports.BadRequestError = exports.RateLimitError = exports.ConflictError = exports.NotFoundError = exports.APIUserAbortError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIError = exports.OpenAIError = exports.PagePromise = exports.APIPromise = exports.toFile = exports.UnverifiedClient = exports.SecureClient = exports.default = exports.TinfoilAI = void 0;
17
+ exports.UnprocessableEntityError = exports.PermissionDeniedError = exports.InternalServerError = exports.AuthenticationError = exports.BadRequestError = exports.RateLimitError = exports.ConflictError = exports.NotFoundError = exports.APIUserAbortError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIError = exports.OpenAIError = exports.PagePromise = exports.APIPromise = exports.toFile = exports.fetchRouter = exports.UnverifiedClient = exports.SecureClient = exports.default = exports.TinfoilAI = void 0;
18
18
  // Re-export the TinfoilAI class
19
19
  var tinfoilai_1 = require("./tinfoilai");
20
20
  Object.defineProperty(exports, "TinfoilAI", { enumerable: true, get: function () { return tinfoilai_1.TinfoilAI; } });
@@ -28,6 +28,8 @@ var secure_client_1 = require("./secure-client");
28
28
  Object.defineProperty(exports, "SecureClient", { enumerable: true, get: function () { return secure_client_1.SecureClient; } });
29
29
  var unverified_client_1 = require("./unverified-client");
30
30
  Object.defineProperty(exports, "UnverifiedClient", { enumerable: true, get: function () { return unverified_client_1.UnverifiedClient; } });
31
+ var router_1 = require("./router");
32
+ Object.defineProperty(exports, "fetchRouter", { enumerable: true, get: function () { return router_1.fetchRouter; } });
31
33
  // Re-export OpenAI utility types and classes that users might need
32
34
  // Using public exports from the main OpenAI package instead of deep imports
33
35
  var openai_1 = require("openai");
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Router utilities for fetching available Tinfoil routers
3
+ */
4
+ /**
5
+ * Fetches the list of available routers from the ATC API
6
+ * and returns a randomly selected address.
7
+ *
8
+ * @returns Promise<string> A randomly selected router address
9
+ * @throws Error if no routers are found or if the request fails
10
+ */
11
+ export declare function fetchRouter(): Promise<string>;
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("./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,6 +21,33 @@ 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,
@@ -80,6 +108,9 @@ class SecureClient {
80
108
  }
81
109
  return this.verificationDocument;
82
110
  }
111
+ getBaseURL() {
112
+ return this.baseURL;
113
+ }
83
114
  get fetch() {
84
115
  return async (input, init) => {
85
116
  await this.ready();
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() {
@@ -87,7 +87,7 @@ export declare class Verifier {
87
87
  private static executeWithWasm;
88
88
  /**
89
89
  * Fetch the latest release digest from GitHub
90
- * @param configRepo - Repository name (e.g., "tinfoilsh/confidential-inference-proxy")
90
+ * @param configRepo - Repository name (e.g., "tinfoilsh/confidential-model-router")
91
91
  * @returns The digest hash
92
92
  */
93
93
  fetchLatestDigest(configRepo?: string): Promise<string>;
package/dist/verifier.js CHANGED
@@ -151,7 +151,8 @@ function compareMeasurementsError(codeMeasurement, runtimeMeasurement) {
151
151
  }
152
152
  if (codeMeasurement.type === PLATFORM_TYPES.SNP_TDX_MULTI_PLATFORM_V1) {
153
153
  switch (runtimeMeasurement.type) {
154
- case PLATFORM_TYPES.TDX_GUEST_V1: {
154
+ case PLATFORM_TYPES.TDX_GUEST_V1:
155
+ case PLATFORM_TYPES.TDX_GUEST_V2: {
155
156
  if (codeMeasurement.registers.length < 3 ||
156
157
  runtimeMeasurement.registers.length < 4) {
157
158
  return new Error(MEASUREMENT_ERROR_MESSAGES.FEW_REGISTERS);
@@ -223,8 +224,10 @@ function compareMeasurements(codeMeasurement, runtimeMeasurement) {
223
224
  */
224
225
  class Verifier {
225
226
  constructor(options) {
226
- const serverURL = options?.serverURL ?? config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL;
227
- this.serverURL = new URL(serverURL).hostname;
227
+ if (!options?.serverURL) {
228
+ throw new Error("serverURL is required for Verifier");
229
+ }
230
+ this.serverURL = new URL(options.serverURL).hostname;
228
231
  this.configRepo =
229
232
  options?.configRepo ?? config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
230
233
  }
@@ -287,7 +290,7 @@ class Verifier {
287
290
  }
288
291
  /**
289
292
  * Fetch the latest release digest from GitHub
290
- * @param configRepo - Repository name (e.g., "tinfoilsh/confidential-inference-proxy")
293
+ * @param configRepo - Repository name (e.g., "tinfoilsh/confidential-model-router")
291
294
  * @returns The digest hash
292
295
  */
293
296
  async fetchLatestDigest(configRepo) {
package/package.json CHANGED
@@ -1,58 +1,64 @@
1
1
  {
2
2
  "name": "@zeke-02/tinfoil",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Tinfoil secure OpenAI client wrapper for Tauri v2",
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
- "default": "./dist/index.js"
18
+ "default": "./dist/esm/index.browser.mjs"
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",
49
- "require": "./dist/secure-fetch.js"
47
+ "browser": "./dist/esm/secure-fetch.browser.mjs",
48
+ "import": "./dist/esm/secure-fetch.mjs",
49
+ "require": "./dist/secure-fetch.js",
50
+ "default": "./dist/esm/secure-fetch.browser.mjs"
51
+ },
52
+ "./router": {
53
+ "types": "./dist/router.d.ts",
54
+ "import": "./dist/esm/router.mjs",
55
+ "require": "./dist/router.js"
50
56
  }
51
57
  },
52
58
  "scripts": {
53
59
  "build": "npm run build:cjs && npm run build:esm",
54
60
  "build:cjs": "tsc && cp src/wasm-exec.js dist/",
55
- "build:esm": "tsc -p tsconfig.esm.json && cp src/wasm-exec.js dist/esm/",
61
+ "build:esm": "tsc -p tsconfig.esm.json && node scripts/convert-to-mjs.js && cp src/wasm-exec.js dist/esm/",
56
62
  "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
63
  "lint": "eslint src/**/*.ts",
58
64
  "prepublishOnly": "npm run build"
@@ -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,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