tinfoil 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.js +28 -2
- package/dist/secure-client.js +3 -6
- package/package.json +11 -12
package/dist/client.js
CHANGED
|
@@ -9,6 +9,25 @@ const crypto_1 = require("crypto");
|
|
|
9
9
|
const secure_client_1 = require("./secure-client");
|
|
10
10
|
const https_1 = __importDefault(require("https"));
|
|
11
11
|
const config_1 = require("./config");
|
|
12
|
+
/**
|
|
13
|
+
* Detects if the code is running in a real browser environment.
|
|
14
|
+
* Returns false for Node.js environments, even with WASM loaded.
|
|
15
|
+
*/
|
|
16
|
+
function isRealBrowser() {
|
|
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) {
|
|
19
|
+
return false; // Definitely Node.js
|
|
20
|
+
}
|
|
21
|
+
// 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') {
|
|
23
|
+
// Additional check: real browsers have navigator.userAgent
|
|
24
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent) {
|
|
25
|
+
return true; // Likely a real browser
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// Default to safe: assume it's not a browser (Node.js with WASM)
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
12
31
|
/**
|
|
13
32
|
* Creates a proxy that allows property access and method calls on a Promise before it resolves.
|
|
14
33
|
* This enables a more ergonomic API where you can chain properties and methods without explicitly
|
|
@@ -108,10 +127,17 @@ class TinfoilAI {
|
|
|
108
127
|
});
|
|
109
128
|
// Create the OpenAI client with our custom configuration
|
|
110
129
|
// Note: baseURL will need to be determined by the verification process
|
|
111
|
-
|
|
130
|
+
const clientOptions = {
|
|
112
131
|
...options,
|
|
113
132
|
baseURL: config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL,
|
|
114
|
-
}
|
|
133
|
+
};
|
|
134
|
+
// Only enable dangerouslyAllowBrowser when we're NOT in a real browser
|
|
135
|
+
// This prevents API key exposure if code is ever bundled for browser use
|
|
136
|
+
if (!isRealBrowser()) {
|
|
137
|
+
// We're in Node.js with WASM, which makes OpenAI SDK think we're in a browser
|
|
138
|
+
clientOptions.dangerouslyAllowBrowser = true;
|
|
139
|
+
}
|
|
140
|
+
return new openai_1.default(clientOptions);
|
|
115
141
|
}
|
|
116
142
|
/**
|
|
117
143
|
* Helper method to ensure the OpenAI client is initialized before use.
|
package/dist/secure-client.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.SecureClient = void 0;
|
|
7
|
-
const
|
|
4
|
+
const undici_1 = require("undici");
|
|
8
5
|
const util_1 = require("util");
|
|
9
6
|
const config_1 = require("./config");
|
|
10
7
|
// Set up browser-like globals that the Go WASM runtime expects
|
|
@@ -79,7 +76,7 @@ class SecureClient {
|
|
|
79
76
|
SecureClient.initializationPromise = (async () => {
|
|
80
77
|
try {
|
|
81
78
|
SecureClient.goInstance = new globalThis.Go();
|
|
82
|
-
const wasmResponse = await (0,
|
|
79
|
+
const wasmResponse = await (0, undici_1.fetch)('https://tinfoilsh.github.io/verifier-js/tinfoil-verifier.wasm');
|
|
83
80
|
const wasmBuffer = await wasmResponse.arrayBuffer();
|
|
84
81
|
const result = await WebAssembly.instantiate(wasmBuffer, SecureClient.goInstance.importObject);
|
|
85
82
|
const runPromise = SecureClient.goInstance.run(result.instance);
|
|
@@ -119,7 +116,7 @@ class SecureClient {
|
|
|
119
116
|
if (typeof globalThis.verifyCode !== 'function' || typeof globalThis.verifyEnclave !== 'function') {
|
|
120
117
|
throw new Error('WASM functions not available');
|
|
121
118
|
}
|
|
122
|
-
const releaseResponse = await (0,
|
|
119
|
+
const releaseResponse = await (0, undici_1.fetch)(`https://api.github.com/repos/${this.repo}/releases/latest`, {
|
|
123
120
|
headers: {
|
|
124
121
|
'Accept': 'application/vnd.github.v3+json',
|
|
125
122
|
'User-Agent': 'tinfoil-node-client'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinfoil",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Tinfoil secure OpenAI client wrapper",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,22 +28,21 @@
|
|
|
28
28
|
"author": "Tinfoil",
|
|
29
29
|
"license": "AGPL-3.0-or-later",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@ai-sdk/openai-compatible": "^0.
|
|
32
|
-
"ai": "^
|
|
33
|
-
"dotenv": "^
|
|
34
|
-
"
|
|
35
|
-
"openai": "^4.87.3",
|
|
31
|
+
"@ai-sdk/openai-compatible": "^1.0.10",
|
|
32
|
+
"ai": "^5.0.19",
|
|
33
|
+
"dotenv": "^17.2.1",
|
|
34
|
+
"openai": "^5.13.1",
|
|
36
35
|
"ts-node": "^10.9.2",
|
|
37
|
-
"undici": "^7.
|
|
36
|
+
"undici": "^7.14.0"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
39
|
"@types/jest": "^29.5.12",
|
|
41
|
-
"@types/node": "^
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
43
|
-
"@typescript-eslint/parser": "^8.
|
|
40
|
+
"@types/node": "^24.3.0",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^8.40.0",
|
|
42
|
+
"@typescript-eslint/parser": "^8.40.0",
|
|
44
43
|
"eslint": "^8.57.0",
|
|
45
44
|
"jest": "^29.7.0",
|
|
46
|
-
"ts-jest": "^29.1
|
|
47
|
-
"typescript": "
|
|
45
|
+
"ts-jest": "^29.4.1",
|
|
46
|
+
"typescript": "^5.9.2"
|
|
48
47
|
}
|
|
49
48
|
}
|