tinfoil 0.8.4 → 0.8.6

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 (39) hide show
  1. package/dist/ai-sdk-provider.d.ts +1 -1
  2. package/dist/ai-sdk-provider.js +3 -3
  3. package/dist/config.d.ts +4 -3
  4. package/dist/config.js +4 -3
  5. package/dist/encrypted-body-fetch.d.ts +2 -2
  6. package/dist/encrypted-body-fetch.js +4 -4
  7. package/dist/esm/ai-sdk-provider.d.ts +1 -1
  8. package/dist/esm/ai-sdk-provider.js +3 -3
  9. package/dist/esm/config.d.ts +4 -3
  10. package/dist/esm/config.js +4 -3
  11. package/dist/esm/encrypted-body-fetch.d.ts +2 -2
  12. package/dist/esm/encrypted-body-fetch.js +4 -4
  13. package/dist/esm/index.browser.d.ts +3 -3
  14. package/dist/esm/index.browser.js +3 -3
  15. package/dist/esm/index.d.ts +3 -3
  16. package/dist/esm/index.js +3 -3
  17. package/dist/esm/secure-client.browser.d.ts +2 -2
  18. package/dist/esm/secure-client.browser.js +3 -3
  19. package/dist/esm/secure-client.d.ts +2 -2
  20. package/dist/esm/secure-client.js +5 -4
  21. package/dist/{client.browser.d.ts → esm/tinfoilai.d.ts} +2 -2
  22. package/dist/esm/{client.browser.js → tinfoilai.js} +12 -7
  23. package/dist/esm/verifier.js +2 -2
  24. package/dist/index.browser.d.ts +3 -3
  25. package/dist/index.browser.js +7 -6
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.js +5 -5
  28. package/dist/secure-client.browser.d.ts +2 -2
  29. package/dist/secure-client.browser.js +3 -3
  30. package/dist/secure-client.d.ts +2 -2
  31. package/dist/secure-client.js +5 -4
  32. package/dist/{esm/client.browser.d.ts → tinfoilai.d.ts} +2 -2
  33. package/dist/{client.browser.js → tinfoilai.js} +13 -8
  34. package/dist/verifier.js +2 -2
  35. package/package.json +2 -3
  36. package/dist/client.d.ts +0 -123
  37. package/dist/client.js +0 -218
  38. package/dist/esm/client.d.ts +0 -123
  39. package/dist/esm/client.js +0 -211
@@ -1,6 +1,6 @@
1
1
  interface CreateTinfoilAIOptions {
2
2
  baseURL?: string;
3
- hpkeKeyURL?: string;
3
+ enclaveURL?: string;
4
4
  configRepo?: string;
5
5
  }
6
6
  export declare function createTinfoilAI(apiKey: string, options?: CreateTinfoilAIOptions): Promise<import("@ai-sdk/openai-compatible").OpenAICompatibleProvider<string, string, string, string>>;
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTinfoilAI = createTinfoilAI;
4
4
  const openai_compatible_1 = require("@ai-sdk/openai-compatible");
5
5
  const config_1 = require("./config");
6
- const secure_client_1 = require("./secure-client");
6
+ const secure_client_1 = require("tinfoil/secure-client");
7
7
  async function createTinfoilAI(apiKey, options = {}) {
8
8
  const baseURL = options.baseURL || config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL;
9
- const hpkeKeyURL = options.hpkeKeyURL || config_1.TINFOIL_CONFIG.HPKE_KEY_URL;
9
+ const enclaveURL = options.enclaveURL || config_1.TINFOIL_CONFIG.ENCLAVE_URL;
10
10
  const configRepo = options.configRepo || config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
11
11
  const secureClient = new secure_client_1.SecureClient({
12
12
  baseURL,
13
- hpkeKeyURL,
13
+ enclaveURL,
14
14
  configRepo,
15
15
  });
16
16
  await secureClient.ready();
package/dist/config.d.ts CHANGED
@@ -7,11 +7,12 @@ export declare const TINFOIL_CONFIG: {
7
7
  */
8
8
  readonly INFERENCE_BASE_URL: "https://inference.tinfoil.sh/v1/";
9
9
  /**
10
- * The URL used to fetch the HPKE server public key (via EHBP .well-known endpoint).
11
- * Defaults to the same value as `INFERENCE_BASE_URL` so hpkeKeyURL and baseURL share
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
12
13
  * the same default. Callers may override independently if key discovery is hosted elsewhere.
13
14
  */
14
- readonly HPKE_KEY_URL: "https://inference.tinfoil.sh/v1/";
15
+ readonly ENCLAVE_URL: "https://inference.tinfoil.sh/v1/";
15
16
  /**
16
17
  * The GitHub repository for the confidential inference proxy
17
18
  */
package/dist/config.js CHANGED
@@ -10,11 +10,12 @@ exports.TINFOIL_CONFIG = {
10
10
  */
11
11
  INFERENCE_BASE_URL: "https://inference.tinfoil.sh/v1/",
12
12
  /**
13
- * The URL used to fetch the HPKE server public key (via EHBP .well-known endpoint).
14
- * Defaults to the same value as `INFERENCE_BASE_URL` so hpkeKeyURL and baseURL share
13
+ * The URL used to fetch the enclave server public key (via EHBP .well-known endpoint).
14
+ * and the attestation (vial the attestation .well-known endpoint too).
15
+ * Defaults to the same value as `INFERENCE_BASE_URL` so enclaveURL and baseURL share
15
16
  * the same default. Callers may override independently if key discovery is hosted elsewhere.
16
17
  */
17
- HPKE_KEY_URL: "https://inference.tinfoil.sh/v1/",
18
+ ENCLAVE_URL: "https://inference.tinfoil.sh/v1/",
18
19
  /**
19
20
  * The GitHub repository for the confidential inference proxy
20
21
  */
@@ -3,8 +3,8 @@ export declare function normalizeEncryptedBodyRequestArgs(input: RequestInfo | U
3
3
  url: string;
4
4
  init?: RequestInit;
5
5
  };
6
- export declare function encryptedBodyRequest(input: RequestInfo | URL, hpkePublicKey: string, init?: RequestInit, hpkeKeyURL?: string): Promise<Response>;
7
- export declare function createEncryptedBodyFetch(baseURL: string, hpkePublicKey: string, hpkeKeyURL?: string): typeof fetch;
6
+ export declare function encryptedBodyRequest(input: RequestInfo | URL, hpkePublicKey: string, init?: RequestInit, enclaveURL?: string): Promise<Response>;
7
+ export declare function createEncryptedBodyFetch(baseURL: string, hpkePublicKey: string, enclaveURL?: string): typeof fetch;
8
8
  export declare function __setEhbpModuleForTests(module: EhbpModule | undefined): void;
9
9
  export declare function __resetEhbpModuleStateForTests(): void;
10
10
  export {};
@@ -64,12 +64,12 @@ function normalizeEncryptedBodyRequestArgs(input, init) {
64
64
  init: { ...derivedInit, ...init },
65
65
  };
66
66
  }
67
- async function encryptedBodyRequest(input, hpkePublicKey, init, hpkeKeyURL) {
67
+ async function encryptedBodyRequest(input, hpkePublicKey, init, enclaveURL) {
68
68
  const { url: requestUrl, init: requestInit } = normalizeEncryptedBodyRequestArgs(input, init);
69
69
  const u = new URL(requestUrl);
70
70
  const { origin } = u;
71
71
  // Determine which origin to fetch the HPKE key from (may be different from request origin)
72
- const keyOrigin = hpkeKeyURL ? new URL(hpkeKeyURL).origin : origin;
72
+ const keyOrigin = enclaveURL ? new URL(enclaveURL).origin : origin;
73
73
  // If key origin matches request origin, use the standard transport (fetches keys from origin)
74
74
  // Otherwise, build a composite transport that routes to `origin` but uses the key fetched from `keyOrigin`.
75
75
  const transport = keyOrigin === origin
@@ -91,11 +91,11 @@ async function encryptedBodyRequest(input, hpkePublicKey, init, hpkeKeyURL) {
91
91
  }
92
92
  return transport.request(requestUrl, requestInit);
93
93
  }
94
- function createEncryptedBodyFetch(baseURL, hpkePublicKey, hpkeKeyURL) {
94
+ function createEncryptedBodyFetch(baseURL, hpkePublicKey, enclaveURL) {
95
95
  return (async (input, init) => {
96
96
  const normalized = normalizeEncryptedBodyRequestArgs(input, init);
97
97
  const targetUrl = new URL(normalized.url, baseURL);
98
- return encryptedBodyRequest(targetUrl.toString(), hpkePublicKey, normalized.init, hpkeKeyURL);
98
+ return encryptedBodyRequest(targetUrl.toString(), hpkePublicKey, normalized.init, enclaveURL);
99
99
  });
100
100
  }
101
101
  // Private helper functions
@@ -1,6 +1,6 @@
1
1
  interface CreateTinfoilAIOptions {
2
2
  baseURL?: string;
3
- hpkeKeyURL?: string;
3
+ enclaveURL?: string;
4
4
  configRepo?: string;
5
5
  }
6
6
  export declare function createTinfoilAI(apiKey: string, options?: CreateTinfoilAIOptions): Promise<import("@ai-sdk/openai-compatible").OpenAICompatibleProvider<string, string, string, string>>;
@@ -1,13 +1,13 @@
1
1
  import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
2
2
  import { TINFOIL_CONFIG } from "./config";
3
- import { SecureClient } from "./secure-client";
3
+ import { SecureClient } from "tinfoil/secure-client";
4
4
  export async function createTinfoilAI(apiKey, options = {}) {
5
5
  const baseURL = options.baseURL || TINFOIL_CONFIG.INFERENCE_BASE_URL;
6
- const hpkeKeyURL = options.hpkeKeyURL || TINFOIL_CONFIG.HPKE_KEY_URL;
6
+ const enclaveURL = options.enclaveURL || TINFOIL_CONFIG.ENCLAVE_URL;
7
7
  const configRepo = options.configRepo || TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
8
8
  const secureClient = new SecureClient({
9
9
  baseURL,
10
- hpkeKeyURL,
10
+ enclaveURL,
11
11
  configRepo,
12
12
  });
13
13
  await secureClient.ready();
@@ -7,11 +7,12 @@ export declare const TINFOIL_CONFIG: {
7
7
  */
8
8
  readonly INFERENCE_BASE_URL: "https://inference.tinfoil.sh/v1/";
9
9
  /**
10
- * The URL used to fetch the HPKE server public key (via EHBP .well-known endpoint).
11
- * Defaults to the same value as `INFERENCE_BASE_URL` so hpkeKeyURL and baseURL share
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
12
13
  * the same default. Callers may override independently if key discovery is hosted elsewhere.
13
14
  */
14
- readonly HPKE_KEY_URL: "https://inference.tinfoil.sh/v1/";
15
+ readonly ENCLAVE_URL: "https://inference.tinfoil.sh/v1/";
15
16
  /**
16
17
  * The GitHub repository for the confidential inference proxy
17
18
  */
@@ -7,11 +7,12 @@ export const TINFOIL_CONFIG = {
7
7
  */
8
8
  INFERENCE_BASE_URL: "https://inference.tinfoil.sh/v1/",
9
9
  /**
10
- * The URL used to fetch the HPKE server public key (via EHBP .well-known endpoint).
11
- * Defaults to the same value as `INFERENCE_BASE_URL` so hpkeKeyURL and baseURL share
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
12
13
  * the same default. Callers may override independently if key discovery is hosted elsewhere.
13
14
  */
14
- HPKE_KEY_URL: "https://inference.tinfoil.sh/v1/",
15
+ ENCLAVE_URL: "https://inference.tinfoil.sh/v1/",
15
16
  /**
16
17
  * The GitHub repository for the confidential inference proxy
17
18
  */
@@ -3,8 +3,8 @@ export declare function normalizeEncryptedBodyRequestArgs(input: RequestInfo | U
3
3
  url: string;
4
4
  init?: RequestInit;
5
5
  };
6
- export declare function encryptedBodyRequest(input: RequestInfo | URL, hpkePublicKey: string, init?: RequestInit, hpkeKeyURL?: string): Promise<Response>;
7
- export declare function createEncryptedBodyFetch(baseURL: string, hpkePublicKey: string, hpkeKeyURL?: string): typeof fetch;
6
+ export declare function encryptedBodyRequest(input: RequestInfo | URL, hpkePublicKey: string, init?: RequestInit, enclaveURL?: string): Promise<Response>;
7
+ export declare function createEncryptedBodyFetch(baseURL: string, hpkePublicKey: string, enclaveURL?: string): typeof fetch;
8
8
  export declare function __setEhbpModuleForTests(module: EhbpModule | undefined): void;
9
9
  export declare function __resetEhbpModuleStateForTests(): void;
10
10
  export {};
@@ -24,12 +24,12 @@ export function normalizeEncryptedBodyRequestArgs(input, init) {
24
24
  init: { ...derivedInit, ...init },
25
25
  };
26
26
  }
27
- export async function encryptedBodyRequest(input, hpkePublicKey, init, hpkeKeyURL) {
27
+ export async function encryptedBodyRequest(input, hpkePublicKey, init, enclaveURL) {
28
28
  const { url: requestUrl, init: requestInit } = normalizeEncryptedBodyRequestArgs(input, init);
29
29
  const u = new URL(requestUrl);
30
30
  const { origin } = u;
31
31
  // Determine which origin to fetch the HPKE key from (may be different from request origin)
32
- const keyOrigin = hpkeKeyURL ? new URL(hpkeKeyURL).origin : origin;
32
+ const keyOrigin = enclaveURL ? new URL(enclaveURL).origin : origin;
33
33
  // If key origin matches request origin, use the standard transport (fetches keys from origin)
34
34
  // Otherwise, build a composite transport that routes to `origin` but uses the key fetched from `keyOrigin`.
35
35
  const transport = keyOrigin === origin
@@ -51,11 +51,11 @@ export async function encryptedBodyRequest(input, hpkePublicKey, init, hpkeKeyUR
51
51
  }
52
52
  return transport.request(requestUrl, requestInit);
53
53
  }
54
- export function createEncryptedBodyFetch(baseURL, hpkePublicKey, hpkeKeyURL) {
54
+ export function createEncryptedBodyFetch(baseURL, hpkePublicKey, enclaveURL) {
55
55
  return (async (input, init) => {
56
56
  const normalized = normalizeEncryptedBodyRequestArgs(input, init);
57
57
  const targetUrl = new URL(normalized.url, baseURL);
58
- return encryptedBodyRequest(targetUrl.toString(), hpkePublicKey, normalized.init, hpkeKeyURL);
58
+ return encryptedBodyRequest(targetUrl.toString(), hpkePublicKey, normalized.init, enclaveURL);
59
59
  });
60
60
  }
61
61
  // Private helper functions
@@ -1,7 +1,7 @@
1
- export { TinfoilAI } from "./client.browser";
2
- export { TinfoilAI as default } from "./client.browser";
1
+ export { TinfoilAI } from "./tinfoilai";
2
+ export { TinfoilAI as default } from "./tinfoilai";
3
3
  export * from "./verifier";
4
4
  export * from "./verification-runner";
5
5
  export * from "./ai-sdk-provider";
6
6
  export * from "./config";
7
- export * from "./secure-client";
7
+ export { SecureClient } from "tinfoil/secure-client";
@@ -1,8 +1,8 @@
1
1
  // Browser-safe entry point: avoids Node built-ins
2
- export { TinfoilAI } from "./client.browser";
3
- export { TinfoilAI as default } from "./client.browser";
2
+ export { TinfoilAI } from "./tinfoilai";
3
+ export { TinfoilAI as default } from "./tinfoilai";
4
4
  export * from "./verifier";
5
5
  export * from "./verification-runner";
6
6
  export * from "./ai-sdk-provider";
7
7
  export * from "./config";
8
- export * from "./secure-client";
8
+ export { SecureClient } from "tinfoil/secure-client";
@@ -1,8 +1,8 @@
1
- export { TinfoilAI } from "./client";
2
- export { TinfoilAI as default } from "./client";
1
+ export { TinfoilAI } from "./tinfoilai";
2
+ export { TinfoilAI as default } from "./tinfoilai";
3
3
  export * from "./verifier";
4
4
  export * from "./verification-runner";
5
5
  export * from "./ai-sdk-provider";
6
6
  export * from "./config";
7
- export * from "./secure-client";
7
+ export * from "tinfoil/secure-client";
8
8
  export { type Uploadable, toFile, APIPromise, PagePromise, OpenAIError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "openai";
package/dist/esm/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  // Re-export the TinfoilAI class
2
- export { TinfoilAI } from "./client";
3
- export { TinfoilAI as default } from "./client";
2
+ export { TinfoilAI } from "./tinfoilai";
3
+ export { TinfoilAI as default } from "./tinfoilai";
4
4
  // Export verifier and loader
5
5
  export * from "./verifier";
6
6
  export * from "./verification-runner";
7
7
  export * from "./ai-sdk-provider";
8
8
  export * from "./config";
9
- export * from "./secure-client";
9
+ export * from "tinfoil/secure-client";
10
10
  // Re-export OpenAI utility types and classes that users might need
11
11
  // Using public exports from the main OpenAI package instead of deep imports
12
12
  export { toFile, APIPromise, PagePromise, OpenAIError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "openai";
@@ -1,7 +1,7 @@
1
1
  import type { VerificationDocument } from "./verifier";
2
2
  interface SecureClientOptions {
3
3
  baseURL?: string;
4
- hpkeKeyURL?: string;
4
+ enclaveURL?: string;
5
5
  configRepo?: string;
6
6
  }
7
7
  export declare class SecureClient {
@@ -9,7 +9,7 @@ export declare class SecureClient {
9
9
  private verificationDocument;
10
10
  private _fetch;
11
11
  private readonly baseURL?;
12
- private readonly hpkeKeyURL?;
12
+ private readonly enclaveURL?;
13
13
  private readonly configRepo?;
14
14
  constructor(options?: SecureClientOptions);
15
15
  ready(): Promise<void>;
@@ -8,7 +8,7 @@ export class SecureClient {
8
8
  this.verificationDocument = null;
9
9
  this._fetch = null;
10
10
  this.baseURL = options.baseURL || TINFOIL_CONFIG.INFERENCE_BASE_URL;
11
- this.hpkeKeyURL = options.hpkeKeyURL || TINFOIL_CONFIG.HPKE_KEY_URL;
11
+ this.enclaveURL = options.enclaveURL || TINFOIL_CONFIG.ENCLAVE_URL;
12
12
  this.configRepo = options.configRepo || TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
13
13
  }
14
14
  async ready() {
@@ -19,7 +19,7 @@ export class SecureClient {
19
19
  }
20
20
  async initSecureClient() {
21
21
  const verifier = new Verifier({
22
- serverURL: this.baseURL,
22
+ serverURL: this.enclaveURL,
23
23
  configRepo: this.configRepo,
24
24
  });
25
25
  await verifier.verify();
@@ -36,7 +36,7 @@ export class SecureClient {
36
36
  }
37
37
  throw new Error("HPKE public key is required in browser environments");
38
38
  }
39
- this._fetch = createEncryptedBodyFetch(this.baseURL, hpkePublicKey, this.hpkeKeyURL);
39
+ this._fetch = createEncryptedBodyFetch(this.baseURL, hpkePublicKey, this.enclaveURL);
40
40
  }
41
41
  async getVerificationDocument() {
42
42
  if (!this.initPromise) {
@@ -1,7 +1,7 @@
1
1
  import type { VerificationDocument } from "./verifier";
2
2
  interface SecureClientOptions {
3
3
  baseURL?: string;
4
- hpkeKeyURL?: string;
4
+ enclaveURL?: string;
5
5
  configRepo?: string;
6
6
  }
7
7
  export declare class SecureClient {
@@ -9,7 +9,7 @@ export declare class SecureClient {
9
9
  private verificationDocument;
10
10
  private _fetch;
11
11
  private readonly baseURL?;
12
- private readonly hpkeKeyURL?;
12
+ private readonly enclaveURL?;
13
13
  private readonly configRepo?;
14
14
  constructor(options?: SecureClientOptions);
15
15
  ready(): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  import { Verifier } from "./verifier";
2
- import { TINFOIL_CONFIG } from "./config";
3
2
  import { createEncryptedBodyFetch } from "./encrypted-body-fetch";
4
3
  import { createPinnedTlsFetch } from "./pinned-tls-fetch";
4
+ import { TINFOIL_CONFIG } from "./config";
5
5
  import { isRealBrowser } from "./env";
6
6
  export class SecureClient {
7
7
  constructor(options = {}) {
@@ -9,7 +9,7 @@ export class SecureClient {
9
9
  this.verificationDocument = null;
10
10
  this._fetch = null;
11
11
  this.baseURL = options.baseURL || TINFOIL_CONFIG.INFERENCE_BASE_URL;
12
- this.hpkeKeyURL = options.hpkeKeyURL || TINFOIL_CONFIG.HPKE_KEY_URL;
12
+ this.enclaveURL = options.enclaveURL || TINFOIL_CONFIG.ENCLAVE_URL;
13
13
  this.configRepo = options.configRepo || TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
14
14
  }
15
15
  async ready() {
@@ -20,7 +20,7 @@ export class SecureClient {
20
20
  }
21
21
  async initSecureClient() {
22
22
  const verifier = new Verifier({
23
- serverURL: this.baseURL,
23
+ serverURL: this.enclaveURL,
24
24
  configRepo: this.configRepo,
25
25
  });
26
26
  await verifier.verify();
@@ -29,11 +29,12 @@ export class SecureClient {
29
29
  throw new Error("Verification document not available after successful verification");
30
30
  }
31
31
  this.verificationDocument = doc;
32
+ // Extract keys from the verification document
32
33
  const { hpkePublicKey, tlsPublicKeyFingerprint } = this.verificationDocument.enclaveMeasurement;
33
34
  let fetchFunction;
34
35
  if (hpkePublicKey) {
35
36
  // HPKE available: use encrypted body fetch
36
- fetchFunction = createEncryptedBodyFetch(this.baseURL, hpkePublicKey, this.hpkeKeyURL);
37
+ fetchFunction = createEncryptedBodyFetch(this.baseURL, hpkePublicKey, this.enclaveURL);
37
38
  }
38
39
  else {
39
40
  // HPKE not available: check if we're in a browser
@@ -4,7 +4,7 @@ import type { VerificationDocument } from "./verifier";
4
4
  interface TinfoilAIOptions {
5
5
  apiKey?: string;
6
6
  baseURL?: string;
7
- hpkeKeyURL?: string;
7
+ enclaveURL?: string;
8
8
  configRepo?: string;
9
9
  [key: string]: any;
10
10
  }
@@ -17,7 +17,7 @@ export declare class TinfoilAI {
17
17
  private verificationDocument?;
18
18
  apiKey?: string;
19
19
  baseURL?: string;
20
- hpkeKeyURL?: string;
20
+ enclaveURL?: string;
21
21
  constructor(options?: TinfoilAIOptions);
22
22
  ready(): Promise<void>;
23
23
  private initClient;
@@ -1,6 +1,7 @@
1
1
  import OpenAI from "openai";
2
- import { SecureClient } from "./secure-client.browser";
2
+ import { SecureClient } from "tinfoil/secure-client";
3
3
  import { TINFOIL_CONFIG } from "./config";
4
+ import { isRealBrowser } from "./env";
4
5
  function createAsyncProxy(promise) {
5
6
  return new Proxy({}, {
6
7
  get(target, prop) {
@@ -28,17 +29,19 @@ export class TinfoilAI {
28
29
  const openAIOptions = { ...options };
29
30
  // In browser builds, never read secrets from process.env to avoid
30
31
  // leaking credentials into client bundles. Require explicit apiKey.
31
- if (typeof options.apiKey === "string") {
32
+ if (options.apiKey) {
32
33
  openAIOptions.apiKey = options.apiKey;
33
34
  }
35
+ else if (!isRealBrowser() && process.env.TINFOIL_API_KEY) {
36
+ openAIOptions.apiKey = process.env.TINFOIL_API_KEY;
37
+ }
34
38
  this.apiKey = openAIOptions.apiKey;
35
39
  this.baseURL = options.baseURL || TINFOIL_CONFIG.INFERENCE_BASE_URL;
36
- this.hpkeKeyURL = options.hpkeKeyURL || TINFOIL_CONFIG.HPKE_KEY_URL;
40
+ this.enclaveURL = options.enclaveURL || TINFOIL_CONFIG.ENCLAVE_URL;
37
41
  this.configRepo = options.configRepo || TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
38
- // Create the secure client for handling transport security
39
42
  this.secureClient = new SecureClient({
40
43
  baseURL: this.baseURL,
41
- hpkeKeyURL: this.hpkeKeyURL,
44
+ enclaveURL: this.enclaveURL,
42
45
  configRepo: this.configRepo,
43
46
  });
44
47
  this.clientPromise = this.initClient(openAIOptions);
@@ -65,8 +68,9 @@ export class TinfoilAI {
65
68
  baseURL: this.baseURL,
66
69
  fetch: this.secureClient.fetch,
67
70
  };
68
- // In browser usage, OpenAI SDK typically needs dangerouslyAllowBrowser
69
- clientOptions.dangerouslyAllowBrowser = true;
71
+ if (isRealBrowser() || options.dangerouslyAllowBrowser === true) {
72
+ clientOptions.dangerouslyAllowBrowser = true;
73
+ }
70
74
  return new OpenAI(clientOptions);
71
75
  }
72
76
  async ensureReady() {
@@ -111,6 +115,7 @@ export class TinfoilAI {
111
115
  return createAsyncProxy(this.ensureReady().then((client) => client.beta));
112
116
  }
113
117
  }
118
+ // Namespace declaration merge to add OpenAI types to TinfoilAI
114
119
  (function (TinfoilAI) {
115
120
  TinfoilAI.Chat = OpenAI.Chat;
116
121
  TinfoilAI.Audio = OpenAI.Audio;
@@ -417,8 +417,8 @@ export class Verifier {
417
417
  // Compare measurements using platform-specific logic
418
418
  const measurementsMatchError = compareMeasurementsError(codeMeasurement, attestation.measurement);
419
419
  if (measurementsMatchError) {
420
- throw new Error(`Measurement verification failed: Code measurement (${codeMeasurement.type}) ` +
421
- `does not match runtime measurement (${attestation.measurement.type}): ${measurementsMatchError.message}`);
420
+ throw new Error(`Verification failed: measurements did not match.\nCode measurement (${codeMeasurement.type}: ${codeMeasurement.registers})\n` +
421
+ `Runtime measurement (${attestation.measurement.type}: ${attestation.measurement.registers}:)\n ${measurementsMatchError.message}`);
422
422
  }
423
423
  // Persist a full verification document for later retrieval by clients
424
424
  this.lastVerificationDocument = {
@@ -1,7 +1,7 @@
1
- export { TinfoilAI } from "./client.browser";
2
- export { TinfoilAI as default } from "./client.browser";
1
+ export { TinfoilAI } from "./tinfoilai";
2
+ export { TinfoilAI as default } from "./tinfoilai";
3
3
  export * from "./verifier";
4
4
  export * from "./verification-runner";
5
5
  export * from "./ai-sdk-provider";
6
6
  export * from "./config";
7
- export * from "./secure-client";
7
+ export { SecureClient } from "tinfoil/secure-client";
@@ -14,14 +14,15 @@ 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.default = exports.TinfoilAI = void 0;
17
+ exports.SecureClient = exports.default = exports.TinfoilAI = void 0;
18
18
  // Browser-safe entry point: avoids Node built-ins
19
- var client_browser_1 = require("./client.browser");
20
- Object.defineProperty(exports, "TinfoilAI", { enumerable: true, get: function () { return client_browser_1.TinfoilAI; } });
21
- var client_browser_2 = require("./client.browser");
22
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return client_browser_2.TinfoilAI; } });
19
+ var tinfoilai_1 = require("./tinfoilai");
20
+ Object.defineProperty(exports, "TinfoilAI", { enumerable: true, get: function () { return tinfoilai_1.TinfoilAI; } });
21
+ var tinfoilai_2 = require("./tinfoilai");
22
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return tinfoilai_2.TinfoilAI; } });
23
23
  __exportStar(require("./verifier"), exports);
24
24
  __exportStar(require("./verification-runner"), exports);
25
25
  __exportStar(require("./ai-sdk-provider"), exports);
26
26
  __exportStar(require("./config"), exports);
27
- __exportStar(require("./secure-client"), exports);
27
+ var secure_client_1 = require("tinfoil/secure-client");
28
+ Object.defineProperty(exports, "SecureClient", { enumerable: true, get: function () { return secure_client_1.SecureClient; } });
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export { TinfoilAI } from "./client";
2
- export { TinfoilAI as default } from "./client";
1
+ export { TinfoilAI } from "./tinfoilai";
2
+ export { TinfoilAI as default } from "./tinfoilai";
3
3
  export * from "./verifier";
4
4
  export * from "./verification-runner";
5
5
  export * from "./ai-sdk-provider";
6
6
  export * from "./config";
7
- export * from "./secure-client";
7
+ export * from "tinfoil/secure-client";
8
8
  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
@@ -16,16 +16,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
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.default = exports.TinfoilAI = void 0;
18
18
  // Re-export the TinfoilAI class
19
- var client_1 = require("./client");
20
- Object.defineProperty(exports, "TinfoilAI", { enumerable: true, get: function () { return client_1.TinfoilAI; } });
21
- var client_2 = require("./client");
22
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return client_2.TinfoilAI; } });
19
+ var tinfoilai_1 = require("./tinfoilai");
20
+ Object.defineProperty(exports, "TinfoilAI", { enumerable: true, get: function () { return tinfoilai_1.TinfoilAI; } });
21
+ var tinfoilai_2 = require("./tinfoilai");
22
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return tinfoilai_2.TinfoilAI; } });
23
23
  // Export verifier and loader
24
24
  __exportStar(require("./verifier"), exports);
25
25
  __exportStar(require("./verification-runner"), exports);
26
26
  __exportStar(require("./ai-sdk-provider"), exports);
27
27
  __exportStar(require("./config"), exports);
28
- __exportStar(require("./secure-client"), exports);
28
+ __exportStar(require("tinfoil/secure-client"), exports);
29
29
  // Re-export OpenAI utility types and classes that users might need
30
30
  // Using public exports from the main OpenAI package instead of deep imports
31
31
  var openai_1 = require("openai");
@@ -1,7 +1,7 @@
1
1
  import type { VerificationDocument } from "./verifier";
2
2
  interface SecureClientOptions {
3
3
  baseURL?: string;
4
- hpkeKeyURL?: string;
4
+ enclaveURL?: string;
5
5
  configRepo?: string;
6
6
  }
7
7
  export declare class SecureClient {
@@ -9,7 +9,7 @@ export declare class SecureClient {
9
9
  private verificationDocument;
10
10
  private _fetch;
11
11
  private readonly baseURL?;
12
- private readonly hpkeKeyURL?;
12
+ private readonly enclaveURL?;
13
13
  private readonly configRepo?;
14
14
  constructor(options?: SecureClientOptions);
15
15
  ready(): Promise<void>;
@@ -11,7 +11,7 @@ class SecureClient {
11
11
  this.verificationDocument = null;
12
12
  this._fetch = null;
13
13
  this.baseURL = options.baseURL || config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL;
14
- this.hpkeKeyURL = options.hpkeKeyURL || config_1.TINFOIL_CONFIG.HPKE_KEY_URL;
14
+ this.enclaveURL = options.enclaveURL || config_1.TINFOIL_CONFIG.ENCLAVE_URL;
15
15
  this.configRepo = options.configRepo || config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
16
16
  }
17
17
  async ready() {
@@ -22,7 +22,7 @@ class SecureClient {
22
22
  }
23
23
  async initSecureClient() {
24
24
  const verifier = new verifier_1.Verifier({
25
- serverURL: this.baseURL,
25
+ serverURL: this.enclaveURL,
26
26
  configRepo: this.configRepo,
27
27
  });
28
28
  await verifier.verify();
@@ -39,7 +39,7 @@ class SecureClient {
39
39
  }
40
40
  throw new Error("HPKE public key is required in browser environments");
41
41
  }
42
- this._fetch = (0, encrypted_body_fetch_1.createEncryptedBodyFetch)(this.baseURL, hpkePublicKey, this.hpkeKeyURL);
42
+ this._fetch = (0, encrypted_body_fetch_1.createEncryptedBodyFetch)(this.baseURL, hpkePublicKey, this.enclaveURL);
43
43
  }
44
44
  async getVerificationDocument() {
45
45
  if (!this.initPromise) {
@@ -1,7 +1,7 @@
1
1
  import type { VerificationDocument } from "./verifier";
2
2
  interface SecureClientOptions {
3
3
  baseURL?: string;
4
- hpkeKeyURL?: string;
4
+ enclaveURL?: string;
5
5
  configRepo?: string;
6
6
  }
7
7
  export declare class SecureClient {
@@ -9,7 +9,7 @@ export declare class SecureClient {
9
9
  private verificationDocument;
10
10
  private _fetch;
11
11
  private readonly baseURL?;
12
- private readonly hpkeKeyURL?;
12
+ private readonly enclaveURL?;
13
13
  private readonly configRepo?;
14
14
  constructor(options?: SecureClientOptions);
15
15
  ready(): Promise<void>;