tinfoil 0.6.0 → 0.6.3

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 CHANGED
@@ -14,16 +14,16 @@ npm install tinfoil
14
14
  ## Quick Start
15
15
 
16
16
  ```typescript
17
- import { TinfoilAI } from 'tinfoil';
17
+ import { TinfoilAI } from "tinfoil";
18
18
 
19
19
  const client = new TinfoilAI({
20
- apiKey: '<YOUR_API_KEY>' // or use TINFOIL_API_KEY env var
20
+ apiKey: "<YOUR_API_KEY>", // or use TINFOIL_API_KEY env var
21
21
  });
22
22
 
23
23
  // Uses identical method calls as the OpenAI client
24
24
  const completion = await client.chat.completions.create({
25
- messages: [{ role: 'user', content: 'Hello!' }],
26
- model: 'llama3-3-70b'
25
+ messages: [{ role: "user", content: "Hello!" }],
26
+ model: "llama3-3-70b",
27
27
  });
28
28
  ```
29
29
 
@@ -62,7 +62,6 @@ Supports Node.js 18+, Deno, Bun, Cloudflare Workers, and more. Browser usage is
62
62
 
63
63
  This library is a drop-in replacement for the official OpenAI Node.js client that can be used with Tinfoil. All methods and types are identical. See the [OpenAI client](https://github.com/openai/openai-node) for complete API usage and documentation.
64
64
 
65
-
66
65
  ## Reporting Vulnerabilities
67
66
 
68
67
  Please report security vulnerabilities by either:
@@ -71,4 +70,4 @@ Please report security vulnerabilities by either:
71
70
 
72
71
  - Opening an issue on GitHub on this repository
73
72
 
74
- We aim to respond to security reports within 24 hours and will keep you updated on our progress.
73
+ We aim to respond to security reports within 24 hours and will keep you updated on our progress.
@@ -19,24 +19,24 @@ async function createTinfoilAI(apiKey) {
19
19
  const connect = (0, undici_1.buildConnector)({
20
20
  checkServerIdentity: (host, cert) => {
21
21
  if (!cert.pubkey) {
22
- throw new Error('No public key available in certificate');
22
+ throw new Error("No public key available in certificate");
23
23
  }
24
24
  const x509 = new node_crypto_1.X509Certificate(cert.raw);
25
25
  const publicKeyDer = x509.publicKey.export({
26
- type: 'spki',
27
- format: 'der'
26
+ type: "spki",
27
+ format: "der",
28
28
  });
29
- const pubKeyFP = (0, node_crypto_1.createHash)('sha256').update(publicKeyDer).digest('hex');
29
+ const pubKeyFP = (0, node_crypto_1.createHash)("sha256").update(publicKeyDer).digest("hex");
30
30
  if (pubKeyFP !== groundTruth.publicKeyFP) {
31
31
  throw new Error(`Certificate public key fingerprint mismatch. Expected: ${groundTruth.publicKeyFP}, Got: ${pubKeyFP}`);
32
32
  }
33
33
  return (0, node_tls_1.checkServerIdentity)(host, cert);
34
- }
34
+ },
35
35
  });
36
36
  const agent = new undici_1.Agent({ connect });
37
37
  return (0, openai_compatible_1.createOpenAICompatible)({
38
38
  name: "tinfoil",
39
- baseURL: config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL.replace(/\/$/, ''),
39
+ baseURL: config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL.replace(/\/$/, ""),
40
40
  apiKey: apiKey,
41
41
  fetch: (async (input, init) => {
42
42
  if (!init) {
package/dist/client.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { Chat, Files, FineTuning, Images, Audio, Embeddings, Models, Moderations, Beta } from 'openai/resources';
1
+ import OpenAI from "openai";
2
+ import type { Chat, Files, FineTuning, Images, Audio, Embeddings, Models, Moderations, Beta } from "openai/resources";
2
3
  /**
3
4
  * TinfoilAI is a wrapper around the OpenAI API client that adds additional
4
5
  * security measures through enclave verification and certificate fingerprint validation.
@@ -17,6 +18,8 @@ export declare class TinfoilAI {
17
18
  private groundTruth?;
18
19
  private clientPromise;
19
20
  private readyPromise?;
21
+ apiKey?: string;
22
+ baseURL?: string;
20
23
  /**
21
24
  * Creates a new TinfoilAI instance.
22
25
  * @param options - Configuration options including apiKey and other OpenAI client options
@@ -82,4 +85,19 @@ export declare class TinfoilAI {
82
85
  */
83
86
  get beta(): Beta;
84
87
  }
88
+ export declare namespace TinfoilAI {
89
+ export import Chat = OpenAI.Chat;
90
+ export import Audio = OpenAI.Audio;
91
+ export import Beta = OpenAI.Beta;
92
+ export import Batches = OpenAI.Batches;
93
+ export import Completions = OpenAI.Completions;
94
+ export import Embeddings = OpenAI.Embeddings;
95
+ export import Files = OpenAI.Files;
96
+ export import FineTuning = OpenAI.FineTuning;
97
+ export import Images = OpenAI.Images;
98
+ export import Models = OpenAI.Models;
99
+ export import Moderations = OpenAI.Moderations;
100
+ export import Uploads = OpenAI.Uploads;
101
+ export import VectorStores = OpenAI.VectorStores;
102
+ }
85
103
  export {};
package/dist/client.js CHANGED
@@ -15,13 +15,15 @@ const config_1 = require("./config");
15
15
  */
16
16
  function isRealBrowser() {
17
17
  // Check for Node.js-specific globals that wouldn't exist in a real browser
18
- if (typeof process !== 'undefined' && process.versions && process.versions.node) {
18
+ if (typeof process !== "undefined" &&
19
+ process.versions &&
20
+ process.versions.node) {
19
21
  return false; // Definitely Node.js
20
22
  }
21
23
  // Check for browser-specific window object AND ensure it's not a Node.js global mock
22
- if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {
24
+ if (typeof window !== "undefined" && typeof window.document !== "undefined") {
23
25
  // Additional check: real browsers have navigator.userAgent
24
- if (typeof navigator !== 'undefined' && navigator.userAgent) {
26
+ if (typeof navigator !== "undefined" && navigator.userAgent) {
25
27
  return true; // Likely a real browser
26
28
  }
27
29
  }
@@ -52,19 +54,21 @@ function createAsyncProxy(promise) {
52
54
  get(target, prop) {
53
55
  return new Proxy(() => { }, {
54
56
  get(_, nestedProp) {
55
- return (...args) => promise.then(obj => {
57
+ return (...args) => promise.then((obj) => {
56
58
  const value = obj[prop][nestedProp];
57
- return typeof value === 'function' ? value.apply(obj[prop], args) : value;
59
+ return typeof value === "function"
60
+ ? value.apply(obj[prop], args)
61
+ : value;
58
62
  });
59
63
  },
60
64
  apply(_, __, args) {
61
- return promise.then(obj => {
65
+ return promise.then((obj) => {
62
66
  const value = obj[prop];
63
- return typeof value === 'function' ? value.apply(obj, args) : value;
67
+ return typeof value === "function" ? value.apply(obj, args) : value;
64
68
  });
65
- }
69
+ },
66
70
  });
67
- }
71
+ },
68
72
  });
69
73
  }
70
74
  class TinfoilAI {
@@ -78,6 +82,9 @@ class TinfoilAI {
78
82
  if (options.apiKey || process.env.TINFOIL_API_KEY) {
79
83
  openAIOptions.apiKey = options.apiKey || process.env.TINFOIL_API_KEY;
80
84
  }
85
+ // Store properties for compatibility
86
+ this.apiKey = openAIOptions.apiKey;
87
+ this.baseURL = config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL;
81
88
  this.clientPromise = this.initClient(openAIOptions);
82
89
  }
83
90
  /**
@@ -110,20 +117,25 @@ class TinfoilAI {
110
117
  rejectUnauthorized: true,
111
118
  checkServerIdentity: (host, cert) => {
112
119
  if (!cert || !cert.raw) {
113
- throw new Error('No certificate found');
120
+ throw new Error("No certificate found");
114
121
  }
115
122
  if (!cert.pubkey) {
116
- throw new Error('No public key found');
123
+ throw new Error("No public key found");
117
124
  }
118
- const pemCert = `-----BEGIN CERTIFICATE-----\n${cert.raw.toString('base64')}\n-----END CERTIFICATE-----`;
125
+ const pemCert = `-----BEGIN CERTIFICATE-----\n${cert.raw.toString("base64")}\n-----END CERTIFICATE-----`;
119
126
  const x509Cert = new crypto_1.X509Certificate(pemCert);
120
- const publicKey = x509Cert.publicKey.export({ format: 'der', type: 'spki' });
121
- const publicKeyHash = (0, crypto_1.createHash)('sha256').update(publicKey).digest('hex');
127
+ const publicKey = x509Cert.publicKey.export({
128
+ format: "der",
129
+ type: "spki",
130
+ });
131
+ const publicKeyHash = (0, crypto_1.createHash)("sha256")
132
+ .update(publicKey)
133
+ .digest("hex");
122
134
  if (publicKeyHash !== expectedFingerprint) {
123
135
  throw new Error(`Certificate fingerprint mismatch. Got ${publicKeyHash}, expected ${expectedFingerprint}`);
124
136
  }
125
137
  return undefined; // Validation successful
126
- }
138
+ },
127
139
  });
128
140
  // Create the OpenAI client with our custom configuration
129
141
  // Note: baseURL will need to be determined by the verification process
@@ -155,63 +167,80 @@ class TinfoilAI {
155
167
  * Automatically initializes the client if needed.
156
168
  */
157
169
  get chat() {
158
- return createAsyncProxy(this.ensureReady().then(client => client.chat));
170
+ return createAsyncProxy(this.ensureReady().then((client) => client.chat));
159
171
  }
160
172
  /**
161
173
  * Access to OpenAI's files API for managing files used with the API.
162
174
  * Automatically initializes the client if needed.
163
175
  */
164
176
  get files() {
165
- return createAsyncProxy(this.ensureReady().then(client => client.files));
177
+ return createAsyncProxy(this.ensureReady().then((client) => client.files));
166
178
  }
167
179
  /**
168
180
  * Access to OpenAI's fine-tuning API for creating and managing fine-tuned models.
169
181
  * Automatically initializes the client if needed.
170
182
  */
171
183
  get fineTuning() {
172
- return createAsyncProxy(this.ensureReady().then(client => client.fineTuning));
184
+ return createAsyncProxy(this.ensureReady().then((client) => client.fineTuning));
173
185
  }
174
186
  /**
175
187
  * Access to OpenAI's image generation and editing API.
176
188
  * Automatically initializes the client if needed.
177
189
  */
178
190
  get images() {
179
- return createAsyncProxy(this.ensureReady().then(client => client.images));
191
+ return createAsyncProxy(this.ensureReady().then((client) => client.images));
180
192
  }
181
193
  /**
182
194
  * Access to OpenAI's audio API for speech-to-text and text-to-speech.
183
195
  * Automatically initializes the client if needed.
184
196
  */
185
197
  get audio() {
186
- return createAsyncProxy(this.ensureReady().then(client => client.audio));
198
+ return createAsyncProxy(this.ensureReady().then((client) => client.audio));
187
199
  }
188
200
  /**
189
201
  * Access to OpenAI's embeddings API for creating vector embeddings of text.
190
202
  * Automatically initializes the client if needed.
191
203
  */
192
204
  get embeddings() {
193
- return createAsyncProxy(this.ensureReady().then(client => client.embeddings));
205
+ return createAsyncProxy(this.ensureReady().then((client) => client.embeddings));
194
206
  }
195
207
  /**
196
208
  * Access to OpenAI's models API for listing and managing available models.
197
209
  * Automatically initializes the client if needed.
198
210
  */
199
211
  get models() {
200
- return createAsyncProxy(this.ensureReady().then(client => client.models));
212
+ return createAsyncProxy(this.ensureReady().then((client) => client.models));
201
213
  }
202
214
  /**
203
215
  * Access to OpenAI's content moderation API.
204
216
  * Automatically initializes the client if needed.
205
217
  */
206
218
  get moderations() {
207
- return createAsyncProxy(this.ensureReady().then(client => client.moderations));
219
+ return createAsyncProxy(this.ensureReady().then((client) => client.moderations));
208
220
  }
209
221
  /**
210
222
  * Access to OpenAI's beta features.
211
223
  * Automatically initializes the client if needed.
212
224
  */
213
225
  get beta() {
214
- return createAsyncProxy(this.ensureReady().then(client => client.beta));
226
+ return createAsyncProxy(this.ensureReady().then((client) => client.beta));
215
227
  }
216
228
  }
217
229
  exports.TinfoilAI = TinfoilAI;
230
+ // Namespace declaration merge to add OpenAI types to TinfoilAI
231
+ (function (TinfoilAI) {
232
+ // Re-export all OpenAI namespace types
233
+ TinfoilAI.Chat = openai_1.default.Chat;
234
+ TinfoilAI.Audio = openai_1.default.Audio;
235
+ TinfoilAI.Beta = openai_1.default.Beta;
236
+ TinfoilAI.Batches = openai_1.default.Batches;
237
+ TinfoilAI.Completions = openai_1.default.Completions;
238
+ TinfoilAI.Embeddings = openai_1.default.Embeddings;
239
+ TinfoilAI.Files = openai_1.default.Files;
240
+ TinfoilAI.FineTuning = openai_1.default.FineTuning;
241
+ TinfoilAI.Images = openai_1.default.Images;
242
+ TinfoilAI.Models = openai_1.default.Models;
243
+ TinfoilAI.Moderations = openai_1.default.Moderations;
244
+ TinfoilAI.Uploads = openai_1.default.Uploads;
245
+ TinfoilAI.VectorStores = openai_1.default.VectorStores;
246
+ })(TinfoilAI || (exports.TinfoilAI = TinfoilAI = {}));
package/dist/config.js CHANGED
@@ -8,9 +8,9 @@ exports.TINFOIL_CONFIG = {
8
8
  /**
9
9
  * The full base URL for the inference API
10
10
  */
11
- INFERENCE_BASE_URL: 'https://inference.tinfoil.sh/v1/',
11
+ INFERENCE_BASE_URL: "https://inference.tinfoil.sh/v1/",
12
12
  /**
13
13
  * The GitHub repository for the confidential inference proxy
14
14
  */
15
- INFERENCE_PROXY_REPO: 'tinfoilsh/confidential-inference-proxy',
15
+ INFERENCE_PROXY_REPO: "tinfoilsh/confidential-inference-proxy",
16
16
  };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export * from './client';
2
- export * from './secure-client';
3
- export * from './ai-sdk-provider';
4
- export * from './config';
1
+ export { TinfoilAI } from "./client";
2
+ export { TinfoilAI as default } from "./client";
3
+ export * from "./secure-client";
4
+ export * from "./ai-sdk-provider";
5
+ export * from "./config";
6
+ 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,32 @@ 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
- __exportStar(require("./client"), exports);
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
+ // 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; } });
23
+ // Export secure client and config
18
24
  __exportStar(require("./secure-client"), exports);
19
25
  __exportStar(require("./ai-sdk-provider"), exports);
20
26
  __exportStar(require("./config"), exports);
27
+ // Re-export OpenAI utility types and classes that users might need
28
+ // Using public exports from the main OpenAI package instead of deep imports
29
+ var openai_1 = require("openai");
30
+ Object.defineProperty(exports, "toFile", { enumerable: true, get: function () { return openai_1.toFile; } });
31
+ Object.defineProperty(exports, "APIPromise", { enumerable: true, get: function () { return openai_1.APIPromise; } });
32
+ Object.defineProperty(exports, "PagePromise", { enumerable: true, get: function () { return openai_1.PagePromise; } });
33
+ Object.defineProperty(exports, "OpenAIError", { enumerable: true, get: function () { return openai_1.OpenAIError; } });
34
+ Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return openai_1.APIError; } });
35
+ Object.defineProperty(exports, "APIConnectionError", { enumerable: true, get: function () { return openai_1.APIConnectionError; } });
36
+ Object.defineProperty(exports, "APIConnectionTimeoutError", { enumerable: true, get: function () { return openai_1.APIConnectionTimeoutError; } });
37
+ Object.defineProperty(exports, "APIUserAbortError", { enumerable: true, get: function () { return openai_1.APIUserAbortError; } });
38
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return openai_1.NotFoundError; } });
39
+ Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return openai_1.ConflictError; } });
40
+ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return openai_1.RateLimitError; } });
41
+ Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return openai_1.BadRequestError; } });
42
+ Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return openai_1.AuthenticationError; } });
43
+ Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return openai_1.InternalServerError; } });
44
+ Object.defineProperty(exports, "PermissionDeniedError", { enumerable: true, get: function () { return openai_1.PermissionDeniedError; } });
45
+ Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, get: function () { return openai_1.UnprocessableEntityError; } });
@@ -9,19 +9,14 @@ const globalThis = global;
9
9
  // Performance API
10
10
  globalThis.performance = {
11
11
  now: () => Date.now(),
12
- markResourceTiming: () => {
13
- },
14
- mark: () => {
15
- },
16
- measure: () => {
17
- },
18
- clearMarks: () => {
19
- },
20
- clearMeasures: () => {
21
- },
12
+ markResourceTiming: () => { },
13
+ mark: () => { },
14
+ measure: () => { },
15
+ clearMarks: () => { },
16
+ clearMeasures: () => { },
22
17
  getEntriesByName: () => [],
23
18
  getEntriesByType: () => [],
24
- getEntries: () => []
19
+ getEntries: () => [],
25
20
  };
26
21
  // Text encoding
27
22
  globalThis.TextEncoder = util_1.TextEncoder;
@@ -30,21 +25,20 @@ globalThis.TextDecoder = util_1.TextDecoder;
30
25
  if (!globalThis.crypto) {
31
26
  globalThis.crypto = {
32
27
  getRandomValues: (buffer) => {
33
- const randomBytes = require('crypto').randomBytes(buffer.length);
28
+ const randomBytes = require("crypto").randomBytes(buffer.length);
34
29
  buffer.set(new Uint8Array(randomBytes));
35
30
  return buffer;
36
- }
31
+ },
37
32
  };
38
33
  }
39
34
  // Modified secure-client.ts
40
- if (typeof window === 'undefined') {
35
+ if (typeof window === "undefined") {
41
36
  // Node.js environment
42
37
  globalThis.window = globalThis;
43
38
  globalThis.document = {
44
39
  createElement: () => ({
45
- setAttribute: () => {
46
- }
47
- })
40
+ setAttribute: () => { },
41
+ }),
48
42
  };
49
43
  }
50
44
  // Force process to stay running (prevent Go from exiting Node process)
@@ -55,14 +49,15 @@ process.exit = ((code) => {
55
49
  return undefined;
56
50
  });
57
51
  // Load the Go runtime helper
58
- require('./wasm-exec.js');
52
+ require("./wasm-exec.js");
59
53
  /**
60
54
  * SecureClient handles verification of code and runtime measurements using WebAssembly
61
55
  */
62
56
  class SecureClient {
63
57
  constructor() {
64
58
  // Values for the Tinfoil inference proxy from config
65
- this.enclave = new URL(config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL).hostname;
59
+ this.enclave = new URL(config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL)
60
+ .hostname;
66
61
  this.repo = config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
67
62
  }
68
63
  /**
@@ -76,25 +71,28 @@ class SecureClient {
76
71
  SecureClient.initializationPromise = (async () => {
77
72
  try {
78
73
  SecureClient.goInstance = new globalThis.Go();
79
- const wasmResponse = await (0, undici_1.fetch)('https://tinfoilsh.github.io/verifier-js/tinfoil-verifier.wasm');
74
+ const wasmResponse = await (0, undici_1.fetch)("https://tinfoilsh.github.io/verifier-js/tinfoil-verifier.wasm");
80
75
  const wasmBuffer = await wasmResponse.arrayBuffer();
81
76
  const result = await WebAssembly.instantiate(wasmBuffer, SecureClient.goInstance.importObject);
82
- const runPromise = SecureClient.goInstance.run(result.instance);
77
+ SecureClient.goInstance.run(result.instance).catch((error) => {
78
+ console.error("Go instance failed to run:", error);
79
+ throw error;
80
+ });
83
81
  let attempts = 0;
84
82
  const maxAttempts = 10;
85
83
  while (attempts < maxAttempts) {
86
84
  attempts++;
87
- await new Promise(resolve => setTimeout(resolve, 100));
88
- const hasVerifyCode = typeof globalThis.verifyCode === 'function';
89
- const hasVerifyEnclave = typeof globalThis.verifyEnclave === 'function';
85
+ await new Promise((resolve) => setTimeout(resolve, 100));
86
+ const hasVerifyCode = typeof globalThis.verifyCode === "function";
87
+ const hasVerifyEnclave = typeof globalThis.verifyEnclave === "function";
90
88
  if (hasVerifyCode && hasVerifyEnclave) {
91
89
  return;
92
90
  }
93
91
  }
94
- throw new Error('WASM functions not exposed after multiple attempts');
92
+ throw new Error("WASM functions not exposed after multiple attempts");
95
93
  }
96
94
  catch (error) {
97
- console.error('WASM initialization error:', error);
95
+ console.error("WASM initialization error:", error);
98
96
  throw error;
99
97
  }
100
98
  })();
@@ -113,19 +111,20 @@ class SecureClient {
113
111
  async verify() {
114
112
  await this.initialize();
115
113
  try {
116
- if (typeof globalThis.verifyCode !== 'function' || typeof globalThis.verifyEnclave !== 'function') {
117
- throw new Error('WASM functions not available');
114
+ if (typeof globalThis.verifyCode !== "function" ||
115
+ typeof globalThis.verifyEnclave !== "function") {
116
+ throw new Error("WASM functions not available");
118
117
  }
119
- const releaseResponse = await (0, undici_1.fetch)(`https://api.github.com/repos/${this.repo}/releases/latest`, {
118
+ const releaseResponse = await (0, undici_1.fetch)(`https://api-github-proxy.tinfoil.sh/repos/${this.repo}/releases/latest`, {
120
119
  headers: {
121
- 'Accept': 'application/vnd.github.v3+json',
122
- 'User-Agent': 'tinfoil-node-client'
123
- }
120
+ Accept: "application/vnd.github.v3+json",
121
+ "User-Agent": "tinfoil-node-client",
122
+ },
124
123
  });
125
124
  if (!releaseResponse.ok) {
126
125
  throw new Error(`GitHub API request failed: ${releaseResponse.status} ${releaseResponse.statusText}`);
127
126
  }
128
- const releaseData = await releaseResponse.json();
127
+ const releaseData = (await releaseResponse.json());
129
128
  const eifRegex = /EIF hash: ([a-f0-9]{64})/i;
130
129
  const digestRegex = /Digest: `([a-f0-9]{64})`/;
131
130
  let digest;
@@ -138,14 +137,14 @@ class SecureClient {
138
137
  digest = digestMatch[1];
139
138
  }
140
139
  else {
141
- throw new Error('Could not find digest in release notes');
140
+ throw new Error("Could not find digest in release notes");
142
141
  }
143
142
  const [measurement, attestationResponse] = await Promise.all([
144
143
  globalThis.verifyCode(this.repo, digest),
145
- globalThis.verifyEnclave(this.enclave)
144
+ globalThis.verifyEnclave(this.enclave),
146
145
  ]);
147
146
  if (measurement !== attestationResponse.measurement) {
148
- throw new Error('Measurements do not match');
147
+ throw new Error("Measurements do not match");
149
148
  }
150
149
  return {
151
150
  publicKeyFP: attestationResponse.certificate,
package/dist/wasm-exec.js CHANGED
@@ -144,25 +144,25 @@
144
144
 
145
145
  if (!globalThis.crypto) {
146
146
  throw new Error(
147
- "globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)"
147
+ "globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)",
148
148
  );
149
149
  }
150
150
 
151
151
  if (!globalThis.performance) {
152
152
  throw new Error(
153
- "globalThis.performance is not available, polyfill required (performance.now only)"
153
+ "globalThis.performance is not available, polyfill required (performance.now only)",
154
154
  );
155
155
  }
156
156
 
157
157
  if (!globalThis.TextEncoder) {
158
158
  throw new Error(
159
- "globalThis.TextEncoder is not available, polyfill required"
159
+ "globalThis.TextEncoder is not available, polyfill required",
160
160
  );
161
161
  }
162
162
 
163
163
  if (!globalThis.TextDecoder) {
164
164
  throw new Error(
165
- "globalThis.TextDecoder is not available, polyfill required"
165
+ "globalThis.TextDecoder is not available, polyfill required",
166
166
  );
167
167
  }
168
168
 
@@ -283,7 +283,7 @@
283
283
  const saddr = getInt64(addr + 0);
284
284
  const len = getInt64(addr + 8);
285
285
  return decoder.decode(
286
- new DataView(this._inst.exports.mem.buffer, saddr, len)
286
+ new DataView(this._inst.exports.mem.buffer, saddr, len),
287
287
  );
288
288
  };
289
289
 
@@ -319,7 +319,7 @@
319
319
  const n = this.mem.getInt32(sp + 24, true);
320
320
  fs.writeSync(
321
321
  fd,
322
- new Uint8Array(this._inst.exports.mem.buffer, p, n)
322
+ new Uint8Array(this._inst.exports.mem.buffer, p, n),
323
323
  );
324
324
  },
325
325
 
@@ -350,15 +350,18 @@
350
350
  this._nextCallbackTimeoutID++;
351
351
  this._scheduledTimeouts.set(
352
352
  id,
353
- setTimeout(() => {
354
- this._resume();
355
- while (this._scheduledTimeouts.has(id)) {
356
- // for some reason Go failed to register the timeout event, log and try again
357
- // (temporary workaround for https://github.com/golang/go/issues/28975)
358
- console.warn("scheduleTimeoutEvent: missed timeout event");
353
+ setTimeout(
354
+ () => {
359
355
  this._resume();
360
- }
361
- }, getInt64(sp + 8))
356
+ while (this._scheduledTimeouts.has(id)) {
357
+ // for some reason Go failed to register the timeout event, log and try again
358
+ // (temporary workaround for https://github.com/golang/go/issues/28975)
359
+ console.warn("scheduleTimeoutEvent: missed timeout event");
360
+ this._resume();
361
+ }
362
+ },
363
+ getInt64(sp + 8),
364
+ ),
362
365
  );
363
366
  this.mem.setInt32(sp + 16, id, true);
364
367
  },
@@ -410,7 +413,7 @@
410
413
  Reflect.set(
411
414
  loadValue(sp + 8),
412
415
  loadString(sp + 16),
413
- loadValue(sp + 32)
416
+ loadValue(sp + 32),
414
417
  );
415
418
  },
416
419
 
@@ -425,7 +428,7 @@
425
428
  sp >>>= 0;
426
429
  storeValue(
427
430
  sp + 24,
428
- Reflect.get(loadValue(sp + 8), getInt64(sp + 16))
431
+ Reflect.get(loadValue(sp + 8), getInt64(sp + 16)),
429
432
  );
430
433
  },
431
434
 
@@ -435,7 +438,7 @@
435
438
  Reflect.set(
436
439
  loadValue(sp + 8),
437
440
  getInt64(sp + 16),
438
- loadValue(sp + 24)
441
+ loadValue(sp + 24),
439
442
  );
440
443
  },
441
444
 
@@ -517,7 +520,7 @@
517
520
  sp >>>= 0;
518
521
  this.mem.setUint8(
519
522
  sp + 24,
520
- loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0
523
+ loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0,
521
524
  );
522
525
  },
523
526
 
@@ -631,7 +634,7 @@
631
634
  const wasmMinDataAddr = 4096 + 8192;
632
635
  if (offset >= wasmMinDataAddr) {
633
636
  throw new Error(
634
- "total length of command line and environment variables exceeds limit"
637
+ "total length of command line and environment variables exceeds limit",
635
638
  );
636
639
  }
637
640
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinfoil",
3
- "version": "0.6.0",
3
+ "version": "0.6.3",
4
4
  "description": "Tinfoil secure OpenAI client wrapper",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",