tinfoil 0.9.0 → 0.10.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/README.md +41 -42
- package/dist/ai-sdk-provider.js +8 -3
- package/dist/config.d.ts +4 -11
- package/dist/config.js +4 -11
- package/dist/encrypted-body-fetch.d.ts +4 -6
- package/dist/encrypted-body-fetch.js +38 -95
- package/dist/esm/ai-sdk-provider.js +8 -3
- package/dist/esm/config.d.ts +4 -11
- package/dist/esm/config.js +4 -11
- package/dist/esm/encrypted-body-fetch.d.ts +4 -6
- package/dist/esm/encrypted-body-fetch.js +33 -56
- package/dist/esm/index.browser.d.ts +1 -0
- package/dist/esm/index.browser.js +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/router.d.ts +11 -0
- package/dist/esm/router.js +33 -0
- package/dist/esm/secure-client.d.ts +3 -2
- package/dist/esm/secure-client.js +116 -13
- package/dist/esm/tinfoilai.js +5 -3
- package/dist/esm/unverified-client.d.ts +18 -0
- package/dist/esm/unverified-client.js +61 -0
- package/dist/esm/verifier.d.ts +4 -1
- package/dist/esm/verifier.js +16 -4
- package/dist/index.browser.d.ts +1 -0
- package/dist/index.browser.js +3 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/dist/router.d.ts +11 -0
- package/dist/router.js +36 -0
- package/dist/secure-client.d.ts +3 -2
- package/dist/secure-client.js +116 -13
- package/dist/tinfoilai.js +5 -3
- package/dist/unverified-client.d.ts +18 -0
- package/dist/unverified-client.js +65 -0
- package/dist/verifier.d.ts +4 -1
- package/dist/verifier.js +16 -4
- package/package.json +2 -2
|
@@ -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>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { TINFOIL_CONFIG } from "./config";
|
|
2
|
+
/**
|
|
3
|
+
* Router utilities for fetching available Tinfoil routers
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Fetches the list of available routers from the ATC API
|
|
7
|
+
* and returns a randomly selected address.
|
|
8
|
+
*
|
|
9
|
+
* @returns Promise<string> A randomly selected router address
|
|
10
|
+
* @throws Error if no routers are found or if the request fails
|
|
11
|
+
*/
|
|
12
|
+
export async function fetchRouter() {
|
|
13
|
+
const routersUrl = TINFOIL_CONFIG.ATC_API_URL;
|
|
14
|
+
try {
|
|
15
|
+
const response = await fetch(routersUrl);
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
throw new Error(`Failed to fetch routers: ${response.status} ${response.statusText}`);
|
|
18
|
+
}
|
|
19
|
+
const routers = await response.json();
|
|
20
|
+
if (!Array.isArray(routers) || routers.length === 0) {
|
|
21
|
+
throw new Error("No routers found in the response");
|
|
22
|
+
}
|
|
23
|
+
// Return a randomly selected router
|
|
24
|
+
const randomIndex = Math.floor(Math.random() * routers.length);
|
|
25
|
+
return routers[randomIndex];
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (error instanceof Error) {
|
|
29
|
+
throw new Error(`Failed to fetch router: ${error.message}`);
|
|
30
|
+
}
|
|
31
|
+
throw new Error("Failed to fetch router: Unknown error");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -8,13 +8,14 @@ export declare class SecureClient {
|
|
|
8
8
|
private initPromise;
|
|
9
9
|
private verificationDocument;
|
|
10
10
|
private _fetch;
|
|
11
|
-
private
|
|
12
|
-
private
|
|
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 {};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Verifier } from "./verifier";
|
|
2
2
|
import { TINFOIL_CONFIG } from "./config";
|
|
3
3
|
import { createSecureFetch } from "tinfoil/secure-fetch";
|
|
4
|
+
import { fetchRouter } from "./router";
|
|
4
5
|
export class SecureClient {
|
|
5
6
|
constructor(options = {}) {
|
|
6
7
|
this.initPromise = null;
|
|
7
8
|
this.verificationDocument = null;
|
|
8
9
|
this._fetch = null;
|
|
9
|
-
this.baseURL = options.baseURL
|
|
10
|
-
this.enclaveURL = options.enclaveURL
|
|
10
|
+
this.baseURL = options.baseURL;
|
|
11
|
+
this.enclaveURL = options.enclaveURL;
|
|
11
12
|
this.configRepo = options.configRepo || TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
|
|
12
13
|
}
|
|
13
14
|
async ready() {
|
|
@@ -17,34 +18,136 @@ export class SecureClient {
|
|
|
17
18
|
return this.initPromise;
|
|
18
19
|
}
|
|
19
20
|
async initSecureClient() {
|
|
21
|
+
// Only fetch router if neither baseURL nor enclaveURL is provided
|
|
22
|
+
if (!this.baseURL && !this.enclaveURL) {
|
|
23
|
+
const routerAddress = await fetchRouter();
|
|
24
|
+
this.enclaveURL = `https://${routerAddress}`;
|
|
25
|
+
this.baseURL = `https://${routerAddress}/v1/`;
|
|
26
|
+
}
|
|
27
|
+
// Ensure both baseURL and enclaveURL are initialized
|
|
28
|
+
if (!this.baseURL) {
|
|
29
|
+
if (this.enclaveURL) {
|
|
30
|
+
// If enclaveURL is provided but baseURL is not, derive baseURL from enclaveURL
|
|
31
|
+
const enclaveUrl = new URL(this.enclaveURL);
|
|
32
|
+
this.baseURL = `${enclaveUrl.origin}/v1/`;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new Error("Unable to determine baseURL: neither baseURL nor enclaveURL provided");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (!this.enclaveURL) {
|
|
39
|
+
if (this.baseURL) {
|
|
40
|
+
// If baseURL is provided but enclaveURL is not, derive enclaveURL from baseURL
|
|
41
|
+
const baseUrl = new URL(this.baseURL);
|
|
42
|
+
this.enclaveURL = baseUrl.origin;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
throw new Error("Unable to determine enclaveURL: neither baseURL nor enclaveURL provided");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
20
48
|
const verifier = new Verifier({
|
|
21
49
|
serverURL: this.enclaveURL,
|
|
22
50
|
configRepo: this.configRepo,
|
|
23
51
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
52
|
+
try {
|
|
53
|
+
await verifier.verify();
|
|
54
|
+
const doc = verifier.getVerificationDocument();
|
|
55
|
+
if (!doc) {
|
|
56
|
+
throw new Error("Verification document not available after successful verification");
|
|
57
|
+
}
|
|
58
|
+
this.verificationDocument = doc;
|
|
59
|
+
// Extract keys from the verification document
|
|
60
|
+
const { hpkePublicKey, tlsPublicKeyFingerprint } = this.verificationDocument.enclaveMeasurement;
|
|
61
|
+
try {
|
|
62
|
+
this._fetch = createSecureFetch(this.baseURL, this.enclaveURL, hpkePublicKey, tlsPublicKeyFingerprint);
|
|
63
|
+
}
|
|
64
|
+
catch (transportError) {
|
|
65
|
+
this.verificationDocument.steps.createTransport = {
|
|
66
|
+
status: 'failed',
|
|
67
|
+
error: transportError.message
|
|
68
|
+
};
|
|
69
|
+
this.verificationDocument.securityVerified = false;
|
|
70
|
+
throw transportError;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
const doc = verifier.getVerificationDocument();
|
|
75
|
+
if (doc) {
|
|
76
|
+
this.verificationDocument = doc;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this.verificationDocument = {
|
|
80
|
+
configRepo: this.configRepo,
|
|
81
|
+
enclaveHost: new URL(this.enclaveURL).hostname,
|
|
82
|
+
releaseDigest: '',
|
|
83
|
+
codeMeasurement: { type: '', registers: [] },
|
|
84
|
+
enclaveMeasurement: { measurement: { type: '', registers: [] } },
|
|
85
|
+
securityVerified: false,
|
|
86
|
+
steps: {
|
|
87
|
+
fetchDigest: { status: 'pending' },
|
|
88
|
+
verifyCode: { status: 'pending' },
|
|
89
|
+
verifyEnclave: { status: 'pending' },
|
|
90
|
+
compareMeasurements: { status: 'pending' },
|
|
91
|
+
otherError: { status: 'failed', error: error.message }
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
33
97
|
}
|
|
34
98
|
async getVerificationDocument() {
|
|
35
99
|
if (!this.initPromise) {
|
|
36
100
|
await this.ready();
|
|
37
101
|
}
|
|
38
|
-
await this.initPromise;
|
|
102
|
+
await this.initPromise.catch(() => { });
|
|
39
103
|
if (!this.verificationDocument) {
|
|
40
104
|
throw new Error("Verification document unavailable: client not verified yet");
|
|
41
105
|
}
|
|
42
106
|
return this.verificationDocument;
|
|
43
107
|
}
|
|
108
|
+
getBaseURL() {
|
|
109
|
+
return this.baseURL;
|
|
110
|
+
}
|
|
44
111
|
get fetch() {
|
|
45
112
|
return async (input, init) => {
|
|
46
113
|
await this.ready();
|
|
47
|
-
|
|
114
|
+
try {
|
|
115
|
+
return await this._fetch(input, init);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
if (this.verificationDocument) {
|
|
119
|
+
const errorMessage = error.message;
|
|
120
|
+
if (errorMessage.includes('HPKE public key mismatch')) {
|
|
121
|
+
this.verificationDocument.steps.verifyHPKEKey = {
|
|
122
|
+
status: 'failed',
|
|
123
|
+
error: errorMessage
|
|
124
|
+
};
|
|
125
|
+
this.verificationDocument.securityVerified = false;
|
|
126
|
+
}
|
|
127
|
+
else if (errorMessage.includes('Transport initialization failed') || errorMessage.includes('Request initialization failed')) {
|
|
128
|
+
this.verificationDocument.steps.createTransport = {
|
|
129
|
+
status: 'failed',
|
|
130
|
+
error: errorMessage
|
|
131
|
+
};
|
|
132
|
+
this.verificationDocument.securityVerified = false;
|
|
133
|
+
}
|
|
134
|
+
else if (errorMessage.includes('Failed to get HPKE key')) {
|
|
135
|
+
this.verificationDocument.steps.verifyHPKEKey = {
|
|
136
|
+
status: 'failed',
|
|
137
|
+
error: errorMessage
|
|
138
|
+
};
|
|
139
|
+
this.verificationDocument.securityVerified = false;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
this.verificationDocument.steps.otherError = {
|
|
143
|
+
status: 'failed',
|
|
144
|
+
error: errorMessage
|
|
145
|
+
};
|
|
146
|
+
this.verificationDocument.securityVerified = false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
48
151
|
};
|
|
49
152
|
}
|
|
50
153
|
}
|
package/dist/esm/tinfoilai.js
CHANGED
|
@@ -36,8 +36,8 @@ export class TinfoilAI {
|
|
|
36
36
|
openAIOptions.apiKey = process.env.TINFOIL_API_KEY;
|
|
37
37
|
}
|
|
38
38
|
this.apiKey = openAIOptions.apiKey;
|
|
39
|
-
this.baseURL = options.baseURL
|
|
40
|
-
this.enclaveURL = options.enclaveURL
|
|
39
|
+
this.baseURL = options.baseURL;
|
|
40
|
+
this.enclaveURL = options.enclaveURL;
|
|
41
41
|
this.configRepo = options.configRepo || TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
|
|
42
42
|
this.secureClient = new SecureClient({
|
|
43
43
|
baseURL: this.baseURL,
|
|
@@ -63,9 +63,11 @@ export class TinfoilAI {
|
|
|
63
63
|
if (!this.verificationDocument) {
|
|
64
64
|
throw new Error("Verification document not available after successful verification");
|
|
65
65
|
}
|
|
66
|
+
// Use the provided baseURL, or get it from SecureClient after initialization
|
|
67
|
+
const baseURL = this.baseURL || this.secureClient.getBaseURL();
|
|
66
68
|
const clientOptions = {
|
|
67
69
|
...options,
|
|
68
|
-
baseURL:
|
|
70
|
+
baseURL: baseURL,
|
|
69
71
|
fetch: this.secureClient.fetch,
|
|
70
72
|
};
|
|
71
73
|
if (isRealBrowser() || options.dangerouslyAllowBrowser === true) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface UnverifiedClientOptions {
|
|
2
|
+
baseURL?: string;
|
|
3
|
+
enclaveURL?: string;
|
|
4
|
+
configRepo?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class UnverifiedClient {
|
|
7
|
+
private initPromise;
|
|
8
|
+
private _fetch;
|
|
9
|
+
private baseURL?;
|
|
10
|
+
private enclaveURL?;
|
|
11
|
+
private readonly configRepo;
|
|
12
|
+
constructor(options?: UnverifiedClientOptions);
|
|
13
|
+
ready(): Promise<void>;
|
|
14
|
+
private initUnverifiedClient;
|
|
15
|
+
getVerificationDocument(): Promise<void>;
|
|
16
|
+
get fetch(): typeof fetch;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { TINFOIL_CONFIG } from "./config";
|
|
2
|
+
import { createEncryptedBodyFetch } from "./encrypted-body-fetch";
|
|
3
|
+
import { fetchRouter } from "./router";
|
|
4
|
+
export class UnverifiedClient {
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
this.initPromise = null;
|
|
7
|
+
this._fetch = null;
|
|
8
|
+
this.baseURL = options.baseURL;
|
|
9
|
+
this.enclaveURL = options.enclaveURL;
|
|
10
|
+
this.configRepo = options.configRepo || TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
|
|
11
|
+
}
|
|
12
|
+
async ready() {
|
|
13
|
+
if (!this.initPromise) {
|
|
14
|
+
this.initPromise = this.initUnverifiedClient();
|
|
15
|
+
}
|
|
16
|
+
return this.initPromise;
|
|
17
|
+
}
|
|
18
|
+
async initUnverifiedClient() {
|
|
19
|
+
// Only fetch router if neither baseURL nor enclaveURL is provided
|
|
20
|
+
if (!this.baseURL && !this.enclaveURL) {
|
|
21
|
+
const routerAddress = await fetchRouter();
|
|
22
|
+
this.enclaveURL = `https://${routerAddress}`;
|
|
23
|
+
this.baseURL = `https://${routerAddress}/v1/`;
|
|
24
|
+
}
|
|
25
|
+
// Ensure both baseURL and enclaveURL are initialized
|
|
26
|
+
if (!this.baseURL) {
|
|
27
|
+
if (this.enclaveURL) {
|
|
28
|
+
// If enclaveURL is provided but baseURL is not, derive baseURL from enclaveURL
|
|
29
|
+
const enclaveUrl = new URL(this.enclaveURL);
|
|
30
|
+
this.baseURL = `${enclaveUrl.origin}/v1/`;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
throw new Error("Unable to determine baseURL: neither baseURL nor enclaveURL provided");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (!this.enclaveURL) {
|
|
37
|
+
if (this.baseURL) {
|
|
38
|
+
// If baseURL is provided but enclaveURL is not, derive enclaveURL from baseURL
|
|
39
|
+
const baseUrl = new URL(this.baseURL);
|
|
40
|
+
this.enclaveURL = baseUrl.origin;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error("Unable to determine enclaveURL: neither baseURL nor enclaveURL provided");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
this._fetch = createEncryptedBodyFetch(this.baseURL, undefined, this.enclaveURL);
|
|
47
|
+
}
|
|
48
|
+
async getVerificationDocument() {
|
|
49
|
+
if (!this.initPromise) {
|
|
50
|
+
await this.ready();
|
|
51
|
+
}
|
|
52
|
+
await this.initPromise;
|
|
53
|
+
throw new Error("Verification document unavailable: this version of the client is unverified");
|
|
54
|
+
}
|
|
55
|
+
get fetch() {
|
|
56
|
+
return async (input, init) => {
|
|
57
|
+
await this.ready();
|
|
58
|
+
return this._fetch(input, init);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
package/dist/esm/verifier.d.ts
CHANGED
|
@@ -37,6 +37,9 @@ export interface VerificationDocument {
|
|
|
37
37
|
verifyCode: VerificationStepState;
|
|
38
38
|
verifyEnclave: VerificationStepState;
|
|
39
39
|
compareMeasurements: VerificationStepState;
|
|
40
|
+
createTransport?: VerificationStepState;
|
|
41
|
+
verifyHPKEKey?: VerificationStepState;
|
|
42
|
+
otherError?: VerificationStepState;
|
|
40
43
|
};
|
|
41
44
|
}
|
|
42
45
|
export interface MeasurementComparisonResult {
|
|
@@ -84,7 +87,7 @@ export declare class Verifier {
|
|
|
84
87
|
private static executeWithWasm;
|
|
85
88
|
/**
|
|
86
89
|
* Fetch the latest release digest from GitHub
|
|
87
|
-
* @param configRepo - Repository name (e.g., "tinfoilsh/confidential-
|
|
90
|
+
* @param configRepo - Repository name (e.g., "tinfoilsh/confidential-model-router")
|
|
88
91
|
* @returns The digest hash
|
|
89
92
|
*/
|
|
90
93
|
fetchLatestDigest(configRepo?: string): Promise<string>;
|
package/dist/esm/verifier.js
CHANGED
|
@@ -124,7 +124,8 @@ function compareMeasurementsError(codeMeasurement, runtimeMeasurement) {
|
|
|
124
124
|
}
|
|
125
125
|
if (codeMeasurement.type === PLATFORM_TYPES.SNP_TDX_MULTI_PLATFORM_V1) {
|
|
126
126
|
switch (runtimeMeasurement.type) {
|
|
127
|
-
case PLATFORM_TYPES.TDX_GUEST_V1:
|
|
127
|
+
case PLATFORM_TYPES.TDX_GUEST_V1:
|
|
128
|
+
case PLATFORM_TYPES.TDX_GUEST_V2: {
|
|
128
129
|
if (codeMeasurement.registers.length < 3 || runtimeMeasurement.registers.length < 4) {
|
|
129
130
|
return new Error(MEASUREMENT_ERROR_MESSAGES.FEW_REGISTERS);
|
|
130
131
|
}
|
|
@@ -194,8 +195,10 @@ export function compareMeasurements(codeMeasurement, runtimeMeasurement) {
|
|
|
194
195
|
*/
|
|
195
196
|
export class Verifier {
|
|
196
197
|
constructor(options) {
|
|
197
|
-
|
|
198
|
-
|
|
198
|
+
if (!options?.serverURL) {
|
|
199
|
+
throw new Error("serverURL is required for Verifier");
|
|
200
|
+
}
|
|
201
|
+
this.serverURL = new URL(options.serverURL).hostname;
|
|
199
202
|
this.configRepo = options?.configRepo ?? TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
|
|
200
203
|
}
|
|
201
204
|
/**
|
|
@@ -256,7 +259,7 @@ export class Verifier {
|
|
|
256
259
|
}
|
|
257
260
|
/**
|
|
258
261
|
* Fetch the latest release digest from GitHub
|
|
259
|
-
* @param configRepo - Repository name (e.g., "tinfoilsh/confidential-
|
|
262
|
+
* @param configRepo - Repository name (e.g., "tinfoilsh/confidential-model-router")
|
|
260
263
|
* @returns The digest hash
|
|
261
264
|
*/
|
|
262
265
|
async fetchLatestDigest(configRepo) {
|
|
@@ -439,6 +442,15 @@ export class Verifier {
|
|
|
439
442
|
}
|
|
440
443
|
catch (error) {
|
|
441
444
|
steps.fetchDigest = { status: 'failed', error: error.message };
|
|
445
|
+
this.lastVerificationDocument = {
|
|
446
|
+
configRepo: this.configRepo,
|
|
447
|
+
enclaveHost: this.serverURL,
|
|
448
|
+
releaseDigest: '',
|
|
449
|
+
codeMeasurement: { type: '', registers: [] },
|
|
450
|
+
enclaveMeasurement: { measurement: { type: '', registers: [] } },
|
|
451
|
+
securityVerified: false,
|
|
452
|
+
steps,
|
|
453
|
+
};
|
|
442
454
|
throw error;
|
|
443
455
|
}
|
|
444
456
|
try {
|
package/dist/index.browser.d.ts
CHANGED
package/dist/index.browser.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.SecureClient = exports.default = exports.TinfoilAI = void 0;
|
|
17
|
+
exports.UnverifiedClient = exports.SecureClient = exports.default = exports.TinfoilAI = void 0;
|
|
18
18
|
// Browser-safe entry point: avoids Node built-ins
|
|
19
19
|
var tinfoilai_1 = require("./tinfoilai");
|
|
20
20
|
Object.defineProperty(exports, "TinfoilAI", { enumerable: true, get: function () { return tinfoilai_1.TinfoilAI; } });
|
|
@@ -25,3 +25,5 @@ __exportStar(require("./ai-sdk-provider"), exports);
|
|
|
25
25
|
__exportStar(require("./config"), exports);
|
|
26
26
|
var secure_client_1 = require("./secure-client");
|
|
27
27
|
Object.defineProperty(exports, "SecureClient", { enumerable: true, get: function () { return secure_client_1.SecureClient; } });
|
|
28
|
+
var unverified_client_1 = require("./unverified-client");
|
|
29
|
+
Object.defineProperty(exports, "UnverifiedClient", { enumerable: true, get: function () { return unverified_client_1.UnverifiedClient; } });
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,6 @@ export * from "./verifier";
|
|
|
4
4
|
export * from "./ai-sdk-provider";
|
|
5
5
|
export * from "./config";
|
|
6
6
|
export { SecureClient } from "./secure-client";
|
|
7
|
+
export { UnverifiedClient } from "./unverified-client";
|
|
8
|
+
export { fetchRouter } from "./router";
|
|
7
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.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; } });
|
|
@@ -26,6 +26,10 @@ __exportStar(require("./ai-sdk-provider"), exports);
|
|
|
26
26
|
__exportStar(require("./config"), exports);
|
|
27
27
|
var secure_client_1 = require("./secure-client");
|
|
28
28
|
Object.defineProperty(exports, "SecureClient", { enumerable: true, get: function () { return secure_client_1.SecureClient; } });
|
|
29
|
+
var unverified_client_1 = require("./unverified-client");
|
|
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; } });
|
|
29
33
|
// Re-export OpenAI utility types and classes that users might need
|
|
30
34
|
// Using public exports from the main OpenAI package instead of deep imports
|
|
31
35
|
var openai_1 = require("openai");
|
package/dist/router.d.ts
ADDED
|
@@ -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
|
+
}
|
package/dist/secure-client.d.ts
CHANGED
|
@@ -8,13 +8,14 @@ export declare class SecureClient {
|
|
|
8
8
|
private initPromise;
|
|
9
9
|
private verificationDocument;
|
|
10
10
|
private _fetch;
|
|
11
|
-
private
|
|
12
|
-
private
|
|
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 {};
|