tinfoil 0.6.1 → 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 +5 -6
- package/dist/ai-sdk-provider.js +6 -6
- package/dist/client.d.ts +2 -2
- package/dist/client.js +33 -24
- package/dist/config.js +2 -2
- package/dist/index.d.ts +6 -6
- package/dist/secure-client.js +35 -36
- package/dist/wasm-exec.js +22 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,16 +14,16 @@ npm install tinfoil
|
|
|
14
14
|
## Quick Start
|
|
15
15
|
|
|
16
16
|
```typescript
|
|
17
|
-
import { TinfoilAI } from
|
|
17
|
+
import { TinfoilAI } from "tinfoil";
|
|
18
18
|
|
|
19
19
|
const client = new TinfoilAI({
|
|
20
|
-
apiKey:
|
|
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:
|
|
26
|
-
model:
|
|
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.
|
package/dist/ai-sdk-provider.js
CHANGED
|
@@ -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(
|
|
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:
|
|
27
|
-
format:
|
|
26
|
+
type: "spki",
|
|
27
|
+
format: "der",
|
|
28
28
|
});
|
|
29
|
-
const pubKeyFP = (0, node_crypto_1.createHash)(
|
|
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,5 +1,5 @@
|
|
|
1
|
-
import OpenAI from
|
|
2
|
-
import type { Chat, Files, FineTuning, Images, Audio, Embeddings, Models, Moderations, Beta } from
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import type { Chat, Files, FineTuning, Images, Audio, Embeddings, Models, Moderations, Beta } from "openai/resources";
|
|
3
3
|
/**
|
|
4
4
|
* TinfoilAI is a wrapper around the OpenAI API client that adds additional
|
|
5
5
|
* security measures through enclave verification and certificate fingerprint validation.
|
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 !==
|
|
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 !==
|
|
24
|
+
if (typeof window !== "undefined" && typeof window.document !== "undefined") {
|
|
23
25
|
// Additional check: real browsers have navigator.userAgent
|
|
24
|
-
if (typeof navigator !==
|
|
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 ===
|
|
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 ===
|
|
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 {
|
|
@@ -113,20 +117,25 @@ class TinfoilAI {
|
|
|
113
117
|
rejectUnauthorized: true,
|
|
114
118
|
checkServerIdentity: (host, cert) => {
|
|
115
119
|
if (!cert || !cert.raw) {
|
|
116
|
-
throw new Error(
|
|
120
|
+
throw new Error("No certificate found");
|
|
117
121
|
}
|
|
118
122
|
if (!cert.pubkey) {
|
|
119
|
-
throw new Error(
|
|
123
|
+
throw new Error("No public key found");
|
|
120
124
|
}
|
|
121
|
-
const pemCert = `-----BEGIN CERTIFICATE-----\n${cert.raw.toString(
|
|
125
|
+
const pemCert = `-----BEGIN CERTIFICATE-----\n${cert.raw.toString("base64")}\n-----END CERTIFICATE-----`;
|
|
122
126
|
const x509Cert = new crypto_1.X509Certificate(pemCert);
|
|
123
|
-
const publicKey = x509Cert.publicKey.export({
|
|
124
|
-
|
|
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");
|
|
125
134
|
if (publicKeyHash !== expectedFingerprint) {
|
|
126
135
|
throw new Error(`Certificate fingerprint mismatch. Got ${publicKeyHash}, expected ${expectedFingerprint}`);
|
|
127
136
|
}
|
|
128
137
|
return undefined; // Validation successful
|
|
129
|
-
}
|
|
138
|
+
},
|
|
130
139
|
});
|
|
131
140
|
// Create the OpenAI client with our custom configuration
|
|
132
141
|
// Note: baseURL will need to be determined by the verification process
|
|
@@ -158,63 +167,63 @@ class TinfoilAI {
|
|
|
158
167
|
* Automatically initializes the client if needed.
|
|
159
168
|
*/
|
|
160
169
|
get chat() {
|
|
161
|
-
return createAsyncProxy(this.ensureReady().then(client => client.chat));
|
|
170
|
+
return createAsyncProxy(this.ensureReady().then((client) => client.chat));
|
|
162
171
|
}
|
|
163
172
|
/**
|
|
164
173
|
* Access to OpenAI's files API for managing files used with the API.
|
|
165
174
|
* Automatically initializes the client if needed.
|
|
166
175
|
*/
|
|
167
176
|
get files() {
|
|
168
|
-
return createAsyncProxy(this.ensureReady().then(client => client.files));
|
|
177
|
+
return createAsyncProxy(this.ensureReady().then((client) => client.files));
|
|
169
178
|
}
|
|
170
179
|
/**
|
|
171
180
|
* Access to OpenAI's fine-tuning API for creating and managing fine-tuned models.
|
|
172
181
|
* Automatically initializes the client if needed.
|
|
173
182
|
*/
|
|
174
183
|
get fineTuning() {
|
|
175
|
-
return createAsyncProxy(this.ensureReady().then(client => client.fineTuning));
|
|
184
|
+
return createAsyncProxy(this.ensureReady().then((client) => client.fineTuning));
|
|
176
185
|
}
|
|
177
186
|
/**
|
|
178
187
|
* Access to OpenAI's image generation and editing API.
|
|
179
188
|
* Automatically initializes the client if needed.
|
|
180
189
|
*/
|
|
181
190
|
get images() {
|
|
182
|
-
return createAsyncProxy(this.ensureReady().then(client => client.images));
|
|
191
|
+
return createAsyncProxy(this.ensureReady().then((client) => client.images));
|
|
183
192
|
}
|
|
184
193
|
/**
|
|
185
194
|
* Access to OpenAI's audio API for speech-to-text and text-to-speech.
|
|
186
195
|
* Automatically initializes the client if needed.
|
|
187
196
|
*/
|
|
188
197
|
get audio() {
|
|
189
|
-
return createAsyncProxy(this.ensureReady().then(client => client.audio));
|
|
198
|
+
return createAsyncProxy(this.ensureReady().then((client) => client.audio));
|
|
190
199
|
}
|
|
191
200
|
/**
|
|
192
201
|
* Access to OpenAI's embeddings API for creating vector embeddings of text.
|
|
193
202
|
* Automatically initializes the client if needed.
|
|
194
203
|
*/
|
|
195
204
|
get embeddings() {
|
|
196
|
-
return createAsyncProxy(this.ensureReady().then(client => client.embeddings));
|
|
205
|
+
return createAsyncProxy(this.ensureReady().then((client) => client.embeddings));
|
|
197
206
|
}
|
|
198
207
|
/**
|
|
199
208
|
* Access to OpenAI's models API for listing and managing available models.
|
|
200
209
|
* Automatically initializes the client if needed.
|
|
201
210
|
*/
|
|
202
211
|
get models() {
|
|
203
|
-
return createAsyncProxy(this.ensureReady().then(client => client.models));
|
|
212
|
+
return createAsyncProxy(this.ensureReady().then((client) => client.models));
|
|
204
213
|
}
|
|
205
214
|
/**
|
|
206
215
|
* Access to OpenAI's content moderation API.
|
|
207
216
|
* Automatically initializes the client if needed.
|
|
208
217
|
*/
|
|
209
218
|
get moderations() {
|
|
210
|
-
return createAsyncProxy(this.ensureReady().then(client => client.moderations));
|
|
219
|
+
return createAsyncProxy(this.ensureReady().then((client) => client.moderations));
|
|
211
220
|
}
|
|
212
221
|
/**
|
|
213
222
|
* Access to OpenAI's beta features.
|
|
214
223
|
* Automatically initializes the client if needed.
|
|
215
224
|
*/
|
|
216
225
|
get beta() {
|
|
217
|
-
return createAsyncProxy(this.ensureReady().then(client => client.beta));
|
|
226
|
+
return createAsyncProxy(this.ensureReady().then((client) => client.beta));
|
|
218
227
|
}
|
|
219
228
|
}
|
|
220
229
|
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:
|
|
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:
|
|
15
|
+
INFERENCE_PROXY_REPO: "tinfoilsh/confidential-inference-proxy",
|
|
16
16
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { TinfoilAI } from
|
|
2
|
-
export { TinfoilAI as default } from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export { type Uploadable, toFile, APIPromise, PagePromise, OpenAIError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from
|
|
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/secure-client.js
CHANGED
|
@@ -9,19 +9,14 @@ const globalThis = global;
|
|
|
9
9
|
// Performance API
|
|
10
10
|
globalThis.performance = {
|
|
11
11
|
now: () => Date.now(),
|
|
12
|
-
markResourceTiming: () => {
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
},
|
|
16
|
-
|
|
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(
|
|
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 ===
|
|
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(
|
|
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)
|
|
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)(
|
|
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
|
-
|
|
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 ===
|
|
89
|
-
const hasVerifyEnclave = typeof globalThis.verifyEnclave ===
|
|
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(
|
|
92
|
+
throw new Error("WASM functions not exposed after multiple attempts");
|
|
95
93
|
}
|
|
96
94
|
catch (error) {
|
|
97
|
-
console.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 !==
|
|
117
|
-
|
|
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
|
|
118
|
+
const releaseResponse = await (0, undici_1.fetch)(`https://api-github-proxy.tinfoil.sh/repos/${this.repo}/releases/latest`, {
|
|
120
119
|
headers: {
|
|
121
|
-
|
|
122
|
-
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|