tinfoil 1.0.1 → 1.0.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/dist/ai-sdk-provider.d.ts +41 -4
- package/dist/ai-sdk-provider.d.ts.map +1 -1
- package/dist/ai-sdk-provider.js +40 -3
- package/dist/ai-sdk-provider.js.map +1 -1
- package/dist/encrypted-body-fetch.d.ts +18 -7
- package/dist/encrypted-body-fetch.d.ts.map +1 -1
- package/dist/encrypted-body-fetch.js +68 -26
- package/dist/encrypted-body-fetch.js.map +1 -1
- package/dist/index.browser.d.ts +3 -0
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +4 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/secure-client.d.ts +100 -8
- package/dist/secure-client.d.ts.map +1 -1
- package/dist/secure-client.js +83 -41
- package/dist/secure-client.js.map +1 -1
- package/dist/secure-fetch.d.ts +1 -1
- package/dist/secure-fetch.d.ts.map +1 -1
- package/dist/secure-fetch.js +1 -1
- package/dist/secure-fetch.js.map +1 -1
- package/dist/tinfoil-ai.d.ts +93 -4
- package/dist/tinfoil-ai.d.ts.map +1 -1
- package/dist/tinfoil-ai.js +55 -4
- package/dist/tinfoil-ai.js.map +1 -1
- package/dist/unverified-client.d.ts +4 -2
- package/dist/unverified-client.d.ts.map +1 -1
- package/dist/unverified-client.js +29 -17
- package/dist/unverified-client.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,9 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Options for creating a Tinfoil AI SDK provider.
|
|
3
|
+
*/
|
|
4
|
+
export interface CreateTinfoilAIOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Override the base URL for API requests.
|
|
7
|
+
* Useful for proxying requests through your own backend.
|
|
8
|
+
*/
|
|
2
9
|
baseURL?: string;
|
|
3
|
-
|
|
10
|
+
/** GitHub repo for code verification. */
|
|
4
11
|
configRepo?: string;
|
|
12
|
+
/** URL to fetch the attestation bundle from. If not set, uses the default Tinfoil ATC. */
|
|
5
13
|
attestationBundleURL?: string;
|
|
6
14
|
}
|
|
7
|
-
|
|
8
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Create a Tinfoil provider for the Vercel AI SDK.
|
|
17
|
+
*
|
|
18
|
+
* This performs enclave verification and returns an OpenAI-compatible provider
|
|
19
|
+
* that can be used with Vercel AI SDK functions like `generateText` and `streamText`.
|
|
20
|
+
*
|
|
21
|
+
* @param apiKey - Your Tinfoil API key. Falls back to TINFOIL_API_KEY env var if not provided.
|
|
22
|
+
* @param options - Optional configuration
|
|
23
|
+
* @returns An AI SDK provider for Tinfoil
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { createTinfoilAI } from "tinfoil";
|
|
28
|
+
* import { generateText } from "ai";
|
|
29
|
+
*
|
|
30
|
+
* // Uses TINFOIL_API_KEY env var
|
|
31
|
+
* const tinfoil = await createTinfoilAI();
|
|
32
|
+
*
|
|
33
|
+
* // Or pass API key explicitly
|
|
34
|
+
* const tinfoil = await createTinfoilAI("your-api-key");
|
|
35
|
+
*
|
|
36
|
+
* const { text } = await generateText({
|
|
37
|
+
* model: tinfoil("llama3-3-70b"),
|
|
38
|
+
* prompt: "Hello!",
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @see https://docs.tinfoil.sh/sdk/javascript-sdk
|
|
43
|
+
* @see https://sdk.vercel.ai/ - Vercel AI SDK documentation
|
|
44
|
+
*/
|
|
45
|
+
export declare function createTinfoilAI(apiKey?: string, options?: CreateTinfoilAIOptions): Promise<import("@ai-sdk/openai-compatible").OpenAICompatibleProvider<string, string, string, string>>;
|
|
9
46
|
//# sourceMappingURL=ai-sdk-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sdk-provider.d.ts","sourceRoot":"","sources":["../src/ai-sdk-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ai-sdk-provider.d.ts","sourceRoot":"","sources":["../src/ai-sdk-provider.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,0FAA0F;IAC1F,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,eAAe,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B,yGAiC1F"}
|
package/dist/ai-sdk-provider.js
CHANGED
|
@@ -1,13 +1,50 @@
|
|
|
1
1
|
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
2
2
|
import { TINFOIL_CONFIG } from "./config.js";
|
|
3
3
|
import { SecureClient } from "./secure-client.js";
|
|
4
|
+
import { isRealBrowser } from "./env.js";
|
|
5
|
+
/**
|
|
6
|
+
* Create a Tinfoil provider for the Vercel AI SDK.
|
|
7
|
+
*
|
|
8
|
+
* This performs enclave verification and returns an OpenAI-compatible provider
|
|
9
|
+
* that can be used with Vercel AI SDK functions like `generateText` and `streamText`.
|
|
10
|
+
*
|
|
11
|
+
* @param apiKey - Your Tinfoil API key. Falls back to TINFOIL_API_KEY env var if not provided.
|
|
12
|
+
* @param options - Optional configuration
|
|
13
|
+
* @returns An AI SDK provider for Tinfoil
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { createTinfoilAI } from "tinfoil";
|
|
18
|
+
* import { generateText } from "ai";
|
|
19
|
+
*
|
|
20
|
+
* // Uses TINFOIL_API_KEY env var
|
|
21
|
+
* const tinfoil = await createTinfoilAI();
|
|
22
|
+
*
|
|
23
|
+
* // Or pass API key explicitly
|
|
24
|
+
* const tinfoil = await createTinfoilAI("your-api-key");
|
|
25
|
+
*
|
|
26
|
+
* const { text } = await generateText({
|
|
27
|
+
* model: tinfoil("llama3-3-70b"),
|
|
28
|
+
* prompt: "Hello!",
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @see https://docs.tinfoil.sh/sdk/javascript-sdk
|
|
33
|
+
* @see https://sdk.vercel.ai/ - Vercel AI SDK documentation
|
|
34
|
+
*/
|
|
4
35
|
export async function createTinfoilAI(apiKey, options = {}) {
|
|
36
|
+
// Resolve API key: use provided value, or fall back to env var (non-browser only)
|
|
37
|
+
let resolvedApiKey = apiKey;
|
|
38
|
+
if (!resolvedApiKey && !isRealBrowser() && typeof process !== 'undefined' && process.env.TINFOIL_API_KEY) {
|
|
39
|
+
resolvedApiKey = process.env.TINFOIL_API_KEY;
|
|
40
|
+
}
|
|
41
|
+
if (!resolvedApiKey) {
|
|
42
|
+
throw new Error("API key is required. Provide apiKey parameter or set TINFOIL_API_KEY environment variable.");
|
|
43
|
+
}
|
|
5
44
|
const baseURL = options.baseURL;
|
|
6
|
-
const enclaveURL = options.enclaveURL;
|
|
7
45
|
const configRepo = options.configRepo || TINFOIL_CONFIG.DEFAULT_ROUTER_REPO;
|
|
8
46
|
const secureClient = new SecureClient({
|
|
9
47
|
baseURL,
|
|
10
|
-
enclaveURL,
|
|
11
48
|
configRepo,
|
|
12
49
|
attestationBundleURL: options.attestationBundleURL,
|
|
13
50
|
});
|
|
@@ -20,7 +57,7 @@ export async function createTinfoilAI(apiKey, options = {}) {
|
|
|
20
57
|
return createOpenAICompatible({
|
|
21
58
|
name: "tinfoil",
|
|
22
59
|
baseURL: finalBaseURL,
|
|
23
|
-
apiKey:
|
|
60
|
+
apiKey: resolvedApiKey,
|
|
24
61
|
fetch: secureClient.fetch,
|
|
25
62
|
});
|
|
26
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sdk-provider.js","sourceRoot":"","sources":["../src/ai-sdk-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"ai-sdk-provider.js","sourceRoot":"","sources":["../src/ai-sdk-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAmBzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAAe,EAAE,UAAkC,EAAE;IACzF,kFAAkF;IAClF,IAAI,cAAc,GAAG,MAAM,CAAC;IAC5B,IAAI,CAAC,cAAc,IAAI,CAAC,aAAa,EAAE,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC;QACzG,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;IAC/C,CAAC;IACD,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;IAChH,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAChC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,cAAc,CAAC,mBAAmB,CAAC;IAE5E,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC;QACpC,OAAO;QACP,UAAU;QACV,oBAAoB,EAAE,OAAO,CAAC,oBAAoB;KACnD,CAAC,CAAC;IAEH,MAAM,YAAY,CAAC,KAAK,EAAE,CAAC;IAE3B,yDAAyD;IACzD,MAAM,YAAY,GAAG,OAAO,IAAI,YAAY,CAAC,UAAU,EAAE,CAAC;IAC1D,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IAED,OAAO,sBAAsB,CAAC;QAC5B,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,YAAY;QACrB,MAAM,EAAE,cAAc;QACtB,KAAK,EAAE,YAAY,CAAC,KAAK;KAC1B,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -8,11 +8,22 @@ export declare function normalizeEncryptedBodyRequestArgs(input: RequestInfo | U
|
|
|
8
8
|
url: string;
|
|
9
9
|
init?: RequestInit;
|
|
10
10
|
};
|
|
11
|
-
export declare function encryptedBodyRequest(input: RequestInfo | URL, hpkePublicKey
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
export declare function encryptedBodyRequest(input: RequestInfo | URL, hpkePublicKey: string, init?: RequestInit, transportInstance?: EhbpTransport): Promise<Response>;
|
|
12
|
+
export declare function createEncryptedBodyFetch(baseURL: string, hpkePublicKey: string, enclaveURL?: string): typeof fetch;
|
|
13
|
+
/**
|
|
14
|
+
* WARNING: THIS FUNCTION IS INSECURE.
|
|
15
|
+
*
|
|
16
|
+
* Creates an encrypted body fetch that fetches the HPKE key from the server without
|
|
17
|
+
* attestation verification. This is vulnerable to man-in-the-middle attacks where
|
|
18
|
+
* a malicious server could provide its own key.
|
|
19
|
+
*
|
|
20
|
+
* This function is useful for testing the EHBP protocol against a local development
|
|
21
|
+
* server that doesn't have attestation set up. For production, use createEncryptedBodyFetch
|
|
22
|
+
* with a key obtained through attestation verification.
|
|
23
|
+
*
|
|
24
|
+
* @param baseURL - Base URL for API requests
|
|
25
|
+
* @param keyOrigin - Origin URL for fetching the HPKE public key. If not provided, derived from baseURL.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createUnverifiedEncryptedBodyFetch(baseURL: string, keyOrigin?: string): typeof fetch;
|
|
28
|
+
export declare function getTransportForOrigin(origin: string, hpkePublicKeyHex: string): Promise<EhbpTransport>;
|
|
18
29
|
//# sourceMappingURL=encrypted-body-fetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encrypted-body-fetch.d.ts","sourceRoot":"","sources":["../src/encrypted-body-fetch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,IAAI,aAAa,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"encrypted-body-fetch.d.ts","sourceRoot":"","sources":["../src/encrypted-body-fetch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,IAAI,aAAa,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,MAAM,CAAC;AAwBjF;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAqBjF;AAED,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,GACjB;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,WAAW,CAAA;CAAE,CAuBrC;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,aAAa,EAAE,MAAM,EACrB,IAAI,CAAC,EAAE,WAAW,EAClB,iBAAiB,CAAC,EAAE,aAAa,GAChC,OAAO,CAAC,QAAQ,CAAC,CAgBnB;AAID,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,KAAK,CAwBlH;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,KAAK,CA+BpG;AAkBD,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAc5G"}
|
|
@@ -9,6 +9,14 @@ function getEhbp() {
|
|
|
9
9
|
}
|
|
10
10
|
return ehbpModulePromise;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Create an Identity from a raw public key hex string.
|
|
14
|
+
* This avoids fetching from the server when the key is already known.
|
|
15
|
+
*/
|
|
16
|
+
async function createIdentityFromPublicKeyHex(publicKeyHex) {
|
|
17
|
+
const { Identity } = await getEhbp();
|
|
18
|
+
return Identity.fromPublicKeyHex(publicKeyHex);
|
|
19
|
+
}
|
|
12
20
|
/**
|
|
13
21
|
* Fetch and parse server identity from the HPKE keys endpoint.
|
|
14
22
|
* Returns the server Identity which can be used to create a Transport.
|
|
@@ -50,60 +58,80 @@ export function normalizeEncryptedBodyRequestArgs(input, init) {
|
|
|
50
58
|
init: { ...derivedInit, ...init },
|
|
51
59
|
};
|
|
52
60
|
}
|
|
53
|
-
export async function encryptedBodyRequest(input, hpkePublicKey, init,
|
|
61
|
+
export async function encryptedBodyRequest(input, hpkePublicKey, init, transportInstance) {
|
|
54
62
|
const { url: requestUrl, init: requestInit } = normalizeEncryptedBodyRequestArgs(input, init);
|
|
55
63
|
let actualTransport;
|
|
56
64
|
if (transportInstance) {
|
|
57
|
-
// Use provided transport instance
|
|
58
65
|
actualTransport = transportInstance;
|
|
59
66
|
}
|
|
60
67
|
else {
|
|
61
|
-
// Create a new transport for this request
|
|
62
68
|
const u = new URL(requestUrl);
|
|
63
|
-
|
|
64
|
-
const keyOrigin = enclaveURL ? new URL(enclaveURL).origin : origin;
|
|
65
|
-
actualTransport = await getTransportForOrigin(origin, keyOrigin);
|
|
66
|
-
}
|
|
67
|
-
if (hpkePublicKey) {
|
|
68
|
-
const transportKeyHash = await actualTransport.getServerPublicKeyHex();
|
|
69
|
-
if (transportKeyHash !== hpkePublicKey) {
|
|
70
|
-
throw new Error(`HPKE public key mismatch. Expected: ${hpkePublicKey}, Got: ${transportKeyHash}`);
|
|
71
|
-
}
|
|
69
|
+
actualTransport = await getTransportForOrigin(u.origin, hpkePublicKey);
|
|
72
70
|
}
|
|
73
71
|
return actualTransport.request(requestUrl, requestInit);
|
|
74
72
|
}
|
|
75
73
|
const ENCLAVE_URL_HEADER = 'X-Tinfoil-Enclave-Url';
|
|
76
74
|
export function createEncryptedBodyFetch(baseURL, hpkePublicKey, enclaveURL) {
|
|
77
|
-
// Create a dedicated transport instance for this fetch function
|
|
78
75
|
let transportPromise = null;
|
|
79
76
|
const getOrCreateTransport = async () => {
|
|
80
77
|
if (!transportPromise) {
|
|
81
78
|
const baseUrl = new URL(baseURL);
|
|
82
|
-
|
|
83
|
-
transportPromise = getTransportForOrigin(baseUrl.origin, keyOrigin);
|
|
79
|
+
transportPromise = getTransportForOrigin(baseUrl.origin, hpkePublicKey);
|
|
84
80
|
}
|
|
85
81
|
return transportPromise;
|
|
86
82
|
};
|
|
87
|
-
|
|
83
|
+
return async (input, init) => {
|
|
88
84
|
const normalized = normalizeEncryptedBodyRequestArgs(input, init);
|
|
89
85
|
const targetUrl = new URL(normalized.url, baseURL);
|
|
90
|
-
// Add the enclave URL header so proxies know where to forward requests
|
|
91
|
-
// Only set if enclaveURL differs from baseURL (avoids CORS issues when hitting enclave directly)
|
|
92
86
|
const headers = new Headers(normalized.init?.headers);
|
|
93
87
|
if (enclaveURL && new URL(enclaveURL).origin !== new URL(baseURL).origin) {
|
|
94
88
|
headers.set(ENCLAVE_URL_HEADER, enclaveURL);
|
|
95
89
|
}
|
|
90
|
+
const initWithHeader = { ...normalized.init, headers };
|
|
91
|
+
const transportInstance = await getOrCreateTransport();
|
|
92
|
+
return encryptedBodyRequest(targetUrl.toString(), hpkePublicKey, initWithHeader, transportInstance);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* WARNING: THIS FUNCTION IS INSECURE.
|
|
97
|
+
*
|
|
98
|
+
* Creates an encrypted body fetch that fetches the HPKE key from the server without
|
|
99
|
+
* attestation verification. This is vulnerable to man-in-the-middle attacks where
|
|
100
|
+
* a malicious server could provide its own key.
|
|
101
|
+
*
|
|
102
|
+
* This function is useful for testing the EHBP protocol against a local development
|
|
103
|
+
* server that doesn't have attestation set up. For production, use createEncryptedBodyFetch
|
|
104
|
+
* with a key obtained through attestation verification.
|
|
105
|
+
*
|
|
106
|
+
* @param baseURL - Base URL for API requests
|
|
107
|
+
* @param keyOrigin - Origin URL for fetching the HPKE public key. If not provided, derived from baseURL.
|
|
108
|
+
*/
|
|
109
|
+
export function createUnverifiedEncryptedBodyFetch(baseURL, keyOrigin) {
|
|
110
|
+
console.warn("[tinfoil] WARNING: createUnverifiedEncryptedBodyFetch is insecure. " +
|
|
111
|
+
"The HPKE key is fetched from the server without attestation verification. " +
|
|
112
|
+
"Only use for local development and testing of the EHBP protocol.");
|
|
113
|
+
let transportPromise = null;
|
|
114
|
+
const getOrCreateTransport = async () => {
|
|
115
|
+
if (!transportPromise) {
|
|
116
|
+
const baseUrl = new URL(baseURL);
|
|
117
|
+
const resolvedKeyOrigin = keyOrigin ? new URL(keyOrigin).origin : baseUrl.origin;
|
|
118
|
+
transportPromise = getUnverifiedTransportForOrigin(baseUrl.origin, resolvedKeyOrigin);
|
|
119
|
+
}
|
|
120
|
+
return transportPromise;
|
|
121
|
+
};
|
|
122
|
+
return async (input, init) => {
|
|
123
|
+
const normalized = normalizeEncryptedBodyRequestArgs(input, init);
|
|
124
|
+
const targetUrl = new URL(normalized.url, baseURL);
|
|
125
|
+
const headers = new Headers(normalized.init?.headers);
|
|
126
|
+
if (keyOrigin && new URL(keyOrigin).origin !== new URL(baseURL).origin) {
|
|
127
|
+
headers.set(ENCLAVE_URL_HEADER, keyOrigin);
|
|
128
|
+
}
|
|
96
129
|
const initWithEnclaveHeader = { ...normalized.init, headers };
|
|
97
|
-
// Get the dedicated transport instance for this fetch function
|
|
98
130
|
const transportInstance = await getOrCreateTransport();
|
|
99
|
-
return
|
|
100
|
-
}
|
|
101
|
-
// Expose Response constructor for OpenAI SDK's FormData support detection
|
|
102
|
-
// This prevents the SDK from making a test request to 'data:,' which would fail through EHBP
|
|
103
|
-
secureFetch.Response = Response;
|
|
104
|
-
return secureFetch;
|
|
131
|
+
return transportInstance.request(targetUrl.toString(), initWithEnclaveHeader);
|
|
132
|
+
};
|
|
105
133
|
}
|
|
106
|
-
|
|
134
|
+
async function getUnverifiedTransportForOrigin(origin, keyOrigin) {
|
|
107
135
|
if (typeof globalThis !== 'undefined') {
|
|
108
136
|
const isSecure = globalThis.isSecureContext !== false;
|
|
109
137
|
const hasSubtle = !!(globalThis.crypto && globalThis.crypto.subtle);
|
|
@@ -117,4 +145,18 @@ export async function getTransportForOrigin(origin, keyOrigin) {
|
|
|
117
145
|
const requestHost = new URL(origin).host;
|
|
118
146
|
return new Transport(serverIdentity, requestHost);
|
|
119
147
|
}
|
|
148
|
+
export async function getTransportForOrigin(origin, hpkePublicKeyHex) {
|
|
149
|
+
if (typeof globalThis !== 'undefined') {
|
|
150
|
+
const isSecure = globalThis.isSecureContext !== false;
|
|
151
|
+
const hasSubtle = !!(globalThis.crypto && globalThis.crypto.subtle);
|
|
152
|
+
if (!isSecure || !hasSubtle) {
|
|
153
|
+
const reason = !isSecure ? 'insecure context (use HTTPS or localhost)' : 'missing WebCrypto SubtleCrypto';
|
|
154
|
+
throw new Error(`EHBP requires a secure browser context: ${reason}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const { Transport } = await getEhbp();
|
|
158
|
+
const serverIdentity = await createIdentityFromPublicKeyHex(hpkePublicKeyHex);
|
|
159
|
+
const requestHost = new URL(origin).host;
|
|
160
|
+
return new Transport(serverIdentity, requestHost);
|
|
161
|
+
}
|
|
120
162
|
//# sourceMapp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SAAS,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,IAAK,UAAU,CAAC,MAAiB,CAAC,MAAM,CAAC,CAAC;QAChF,IAAI,CAAC,QAAQ,IAAI,CAAC,SAAS,EAAE,CAAC;YAC5B,MAAM,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,2CAA2C,CAAC,CAAC,CAAC,gCAAgC,CAAC;YAC1G,MAAM,IAAI,KAAK,CAAC,2CAA2C,MAAM,EAAE,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IAED,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,OAAO,EAAE,CAAC;IACtC,MAAM,cAAc,GAAG,MAAM,8BAA8B,CAAC,gBAAgB,CAAC,CAAC;IAC9E,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;IACzC,OAAO,IAAI,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;AACpD,CAAC"}
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export { TinfoilAI } from "./tinfoil-ai.js";
|
|
2
2
|
export { TinfoilAI as default } from "./tinfoil-ai.js";
|
|
3
|
+
export type { TinfoilAIOptions } from "./tinfoil-ai.js";
|
|
3
4
|
export * from "./verifier.js";
|
|
4
5
|
export * from "./ai-sdk-provider.js";
|
|
5
6
|
export * from "./config.js";
|
|
6
7
|
export { SecureClient, type TransportMode } from "./secure-client.js";
|
|
7
8
|
export { UnverifiedClient } from "./unverified-client.js";
|
|
9
|
+
export { fetchRouter, fetchAttestationBundle } from "./atc.js";
|
|
10
|
+
export { type Uploadable, toFile, APIPromise, PagePromise, OpenAIError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "openai";
|
|
8
11
|
//# sourceMappingURL=index.browser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACvD,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAI/D,OAAO,EACL,KAAK,UAAU,EACf,MAAM,EACN,UAAU,EACV,WAAW,EACX,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,QAAQ,CAAC"}
|
package/dist/index.browser.js
CHANGED
|
@@ -7,4 +7,8 @@ export * from "./ai-sdk-provider.js";
|
|
|
7
7
|
export * from "./config.js";
|
|
8
8
|
export { SecureClient } from "./secure-client.js";
|
|
9
9
|
export { UnverifiedClient } from "./unverified-client.js";
|
|
10
|
+
export { fetchRouter, fetchAttestationBundle } from "./atc.js";
|
|
11
|
+
// Re-export OpenAI utility types and classes that users might need
|
|
12
|
+
// Using public exports from the main OpenAI package instead of deep imports
|
|
13
|
+
export { toFile, APIPromise, PagePromise, OpenAIError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "openai";
|
|
10
14
|
//# sourceMappingURL=index.browser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,yEAAyE;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,yEAAyE;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAGvD,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAsB,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE/D,mEAAmE;AACnE,4EAA4E;AAC5E,OAAO,EAEL,MAAM,EACN,UAAU,EACV,WAAW,EACX,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,QAAQ,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACvD,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAI/D,OAAO,EACL,KAAK,UAAU,EACf,MAAM,EACN,UAAU,EACV,WAAW,EACX,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,QAAQ,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAGvD,kBAAkB;AAClB,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAsB,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE/D,mEAAmE;AACnE,4EAA4E;AAC5E,OAAO,EAEL,MAAM,EACN,UAAU,EACV,WAAW,EACX,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,QAAQ,CAAC"}
|
package/dist/secure-client.d.ts
CHANGED
|
@@ -1,31 +1,123 @@
|
|
|
1
1
|
import { type VerificationDocument } from "./verifier.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Transport mode for secure communication with the enclave.
|
|
4
|
+
*
|
|
5
|
+
* - `'ehbp'` - HPKE encryption via the Encrypted HTTP Body Protocol (default).
|
|
6
|
+
* End-to-end encrypted, works through proxies. Requires X25519 WebCrypto support.
|
|
7
|
+
* - `'tls'` - TLS certificate pinning. Requires direct connection to the enclave;
|
|
8
|
+
* requests through a proxy will fail. Use this in runtimes without X25519 support (like Bun).
|
|
9
|
+
*
|
|
10
|
+
* @see https://docs.tinfoil.sh/resources/ehbp - EHBP Protocol specification
|
|
11
|
+
*/
|
|
12
|
+
export type TransportMode = 'ehbp' | 'tls';
|
|
13
|
+
/**
|
|
14
|
+
* Configuration options for SecureClient.
|
|
15
|
+
*/
|
|
16
|
+
export interface SecureClientOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Override the base URL for API requests.
|
|
19
|
+
* Useful for proxying requests through your own backend.
|
|
20
|
+
* @see https://docs.tinfoil.sh/guides/proxy-server
|
|
21
|
+
*/
|
|
4
22
|
baseURL?: string;
|
|
5
|
-
|
|
23
|
+
/** GitHub repo for code verification. Defaults to tinfoilsh/confidential-model-router. */
|
|
6
24
|
configRepo?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Transport mode for secure communication.
|
|
27
|
+
* @default 'ehbp'
|
|
28
|
+
*/
|
|
7
29
|
transport?: TransportMode;
|
|
30
|
+
/** URL to fetch the attestation bundle from. If not set, uses the default Tinfoil ATC. */
|
|
8
31
|
attestationBundleURL?: string;
|
|
9
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Low-level secure client providing a verified fetch function for custom HTTP requests.
|
|
35
|
+
*
|
|
36
|
+
* SecureClient performs enclave attestation verification and provides a `fetch` function
|
|
37
|
+
* that encrypts all request bodies end-to-end. Use this when you need direct control
|
|
38
|
+
* over HTTP requests or want to use a different OpenAI client.
|
|
39
|
+
*
|
|
40
|
+
* For most use cases, prefer {@link TinfoilAI} which wraps this with an OpenAI-compatible API.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* import { SecureClient } from "tinfoil";
|
|
45
|
+
*
|
|
46
|
+
* const client = new SecureClient();
|
|
47
|
+
* await client.ready();
|
|
48
|
+
*
|
|
49
|
+
* // Use with OpenAI SDK
|
|
50
|
+
* const openai = new OpenAI({
|
|
51
|
+
* apiKey: "your-key",
|
|
52
|
+
* baseURL: client.getBaseURL(),
|
|
53
|
+
* fetch: client.fetch,
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* // Direct fetch for custom requests
|
|
60
|
+
* const response = await client.fetch("/v1/chat/completions", {
|
|
61
|
+
* method: "POST",
|
|
62
|
+
* headers: { "Content-Type": "application/json" },
|
|
63
|
+
* body: JSON.stringify({ model: "llama3-3-70b", messages: [...] }),
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @see https://docs.tinfoil.sh/sdk/javascript-sdk
|
|
68
|
+
* @see https://docs.tinfoil.sh/guides/proxy-server - Proxy server setup
|
|
69
|
+
*/
|
|
10
70
|
export declare class SecureClient {
|
|
11
71
|
private initPromise;
|
|
12
72
|
private verificationDocument;
|
|
13
73
|
private _fetch;
|
|
14
|
-
private _didFallbackToTls;
|
|
15
|
-
private _tlsPublicKeyFingerprint?;
|
|
16
74
|
private baseURL?;
|
|
17
75
|
private enclaveURL?;
|
|
18
|
-
private readonly configRepo
|
|
76
|
+
private readonly configRepo;
|
|
19
77
|
private readonly transport;
|
|
20
78
|
private readonly attestationBundleURL?;
|
|
21
79
|
constructor(options?: SecureClientOptions);
|
|
80
|
+
/**
|
|
81
|
+
* Wait for the client to complete verification and be ready for requests.
|
|
82
|
+
*
|
|
83
|
+
* This performs enclave attestation, code verification, and establishes
|
|
84
|
+
* the secure transport. Must be called before using `fetch`.
|
|
85
|
+
*
|
|
86
|
+
* @throws Error if verification fails
|
|
87
|
+
*/
|
|
22
88
|
ready(): Promise<void>;
|
|
23
89
|
private initSecureClient;
|
|
90
|
+
/**
|
|
91
|
+
* Get the verification document containing attestation details.
|
|
92
|
+
*
|
|
93
|
+
* @returns The verification document with attestation results
|
|
94
|
+
* @throws Error if verification has not completed
|
|
95
|
+
* @see https://docs.tinfoil.sh/verification/attestation-architecture
|
|
96
|
+
*/
|
|
24
97
|
getVerificationDocument(): Promise<VerificationDocument>;
|
|
98
|
+
/**
|
|
99
|
+
* Get the base URL for API requests.
|
|
100
|
+
*
|
|
101
|
+
* @returns The base URL (e.g., "https://enclave.example.com/v1/")
|
|
102
|
+
*/
|
|
25
103
|
getBaseURL(): string | undefined;
|
|
26
104
|
private createTransport;
|
|
27
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Secure fetch function that encrypts request bodies end-to-end.
|
|
107
|
+
*
|
|
108
|
+
* Use this as a drop-in replacement for global `fetch`. Request bodies are
|
|
109
|
+
* encrypted using HPKE (or TLS pinning if configured) so only the verified
|
|
110
|
+
* enclave can decrypt them.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const response = await client.fetch("/v1/chat/completions", {
|
|
115
|
+
* method: "POST",
|
|
116
|
+
* headers: { "Content-Type": "application/json" },
|
|
117
|
+
* body: JSON.stringify({ model: "llama3-3-70b", messages: [...] }),
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
28
121
|
get fetch(): typeof fetch;
|
|
29
122
|
}
|
|
30
|
-
export {};
|
|
31
123
|
//# sourceMappingURL=secure-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secure-client.d.ts","sourceRoot":"","sources":["../src/secure-client.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"secure-client.d.ts","sourceRoot":"","sources":["../src/secure-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAKpE;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,KAAK,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,0FAA0F;IAC1F,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B,0FAA0F;IAC1F,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,oBAAoB,CAAqC;IACjE,OAAO,CAAC,MAAM,CAA6B;IAE3C,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAC1C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAS;gBAEnC,OAAO,GAAE,mBAAwB;IAO7C;;;;;;;OAOG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAOrB,gBAAgB;IAqE9B;;;;;;OAMG;IACU,uBAAuB,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAarE;;;;OAIG;IACI,UAAU,IAAI,MAAM,GAAG,SAAS;YAIzB,eAAe;IAQ7B;;;;;;;;;;;;;;;OAeG;IACH,IAAI,KAAK,IAAI,OAAO,KAAK,CAwCxB;CACF"}
|
package/dist/secure-client.js
CHANGED
|
@@ -2,12 +2,47 @@ import { Verifier } from "./verifier.js";
|
|
|
2
2
|
import { TINFOIL_CONFIG } from "./config.js";
|
|
3
3
|
import { createSecureFetch } from "./secure-fetch.js";
|
|
4
4
|
import { fetchAttestationBundle } from "./atc.js";
|
|
5
|
+
/**
|
|
6
|
+
* Low-level secure client providing a verified fetch function for custom HTTP requests.
|
|
7
|
+
*
|
|
8
|
+
* SecureClient performs enclave attestation verification and provides a `fetch` function
|
|
9
|
+
* that encrypts all request bodies end-to-end. Use this when you need direct control
|
|
10
|
+
* over HTTP requests or want to use a different OpenAI client.
|
|
11
|
+
*
|
|
12
|
+
* For most use cases, prefer {@link TinfoilAI} which wraps this with an OpenAI-compatible API.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { SecureClient } from "tinfoil";
|
|
17
|
+
*
|
|
18
|
+
* const client = new SecureClient();
|
|
19
|
+
* await client.ready();
|
|
20
|
+
*
|
|
21
|
+
* // Use with OpenAI SDK
|
|
22
|
+
* const openai = new OpenAI({
|
|
23
|
+
* apiKey: "your-key",
|
|
24
|
+
* baseURL: client.getBaseURL(),
|
|
25
|
+
* fetch: client.fetch,
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // Direct fetch for custom requests
|
|
32
|
+
* const response = await client.fetch("/v1/chat/completions", {
|
|
33
|
+
* method: "POST",
|
|
34
|
+
* headers: { "Content-Type": "application/json" },
|
|
35
|
+
* body: JSON.stringify({ model: "llama3-3-70b", messages: [...] }),
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @see https://docs.tinfoil.sh/sdk/javascript-sdk
|
|
40
|
+
* @see https://docs.tinfoil.sh/guides/proxy-server - Proxy server setup
|
|
41
|
+
*/
|
|
5
42
|
export class SecureClient {
|
|
6
43
|
initPromise = null;
|
|
7
44
|
verificationDocument = null;
|
|
8
45
|
_fetch = null;
|
|
9
|
-
_didFallbackToTls = false;
|
|
10
|
-
_tlsPublicKeyFingerprint;
|
|
11
46
|
baseURL;
|
|
12
47
|
enclaveURL;
|
|
13
48
|
configRepo;
|
|
@@ -15,11 +50,18 @@ export class SecureClient {
|
|
|
15
50
|
attestationBundleURL;
|
|
16
51
|
constructor(options = {}) {
|
|
17
52
|
this.baseURL = options.baseURL;
|
|
18
|
-
this.enclaveURL = options.enclaveURL;
|
|
19
53
|
this.configRepo = options.configRepo || TINFOIL_CONFIG.DEFAULT_ROUTER_REPO;
|
|
20
|
-
this.transport = options.transport || '
|
|
54
|
+
this.transport = options.transport || 'ehbp';
|
|
21
55
|
this.attestationBundleURL = options.attestationBundleURL;
|
|
22
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Wait for the client to complete verification and be ready for requests.
|
|
59
|
+
*
|
|
60
|
+
* This performs enclave attestation, code verification, and establishes
|
|
61
|
+
* the secure transport. Must be called before using `fetch`.
|
|
62
|
+
*
|
|
63
|
+
* @throws Error if verification fails
|
|
64
|
+
*/
|
|
23
65
|
async ready() {
|
|
24
66
|
if (!this.initPromise) {
|
|
25
67
|
this.initPromise = this.initSecureClient();
|
|
@@ -27,28 +69,17 @@ export class SecureClient {
|
|
|
27
69
|
return this.initPromise;
|
|
28
70
|
}
|
|
29
71
|
async initSecureClient() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if
|
|
33
|
-
bundle = await fetchAttestationBundle(this.attestationBundleURL);
|
|
34
|
-
this.enclaveURL = `https://${bundle.domain}`;
|
|
35
|
-
}
|
|
36
|
-
// Derive baseURL if not set
|
|
72
|
+
const bundle = await fetchAttestationBundle(this.attestationBundleURL);
|
|
73
|
+
this.enclaveURL = `https://${bundle.domain}`;
|
|
74
|
+
// Derive baseURL from bundle domain if not set
|
|
37
75
|
if (!this.baseURL) {
|
|
38
|
-
|
|
39
|
-
this.baseURL = `${enclaveUrl.origin}/v1/`;
|
|
76
|
+
this.baseURL = `${this.enclaveURL}/v1/`;
|
|
40
77
|
}
|
|
41
78
|
const verifier = new Verifier({
|
|
42
|
-
serverURL: this.enclaveURL,
|
|
43
79
|
configRepo: this.configRepo,
|
|
44
80
|
});
|
|
45
81
|
try {
|
|
46
|
-
|
|
47
|
-
await verifier.verifyBundle(bundle);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
await verifier.verify();
|
|
51
|
-
}
|
|
82
|
+
await verifier.verifyBundle(bundle);
|
|
52
83
|
const doc = verifier.getVerificationDocument();
|
|
53
84
|
if (!doc) {
|
|
54
85
|
throw new Error("Verification document not available after successful verification");
|
|
@@ -76,7 +107,7 @@ export class SecureClient {
|
|
|
76
107
|
else {
|
|
77
108
|
this.verificationDocument = {
|
|
78
109
|
configRepo: this.configRepo,
|
|
79
|
-
enclaveHost:
|
|
110
|
+
enclaveHost: bundle.domain,
|
|
80
111
|
releaseDigest: '',
|
|
81
112
|
codeMeasurement: { type: '', registers: [] },
|
|
82
113
|
enclaveMeasurement: { measurement: { type: '', registers: [] } },
|
|
@@ -85,7 +116,7 @@ export class SecureClient {
|
|
|
85
116
|
hardwareMeasurement: undefined,
|
|
86
117
|
codeFingerprint: '',
|
|
87
118
|
enclaveFingerprint: '',
|
|
88
|
-
selectedRouterEndpoint:
|
|
119
|
+
selectedRouterEndpoint: bundle.domain,
|
|
89
120
|
securityVerified: false,
|
|
90
121
|
steps: {
|
|
91
122
|
fetchDigest: { status: 'pending' },
|
|
@@ -101,6 +132,13 @@ export class SecureClient {
|
|
|
101
132
|
throw error;
|
|
102
133
|
}
|
|
103
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Get the verification document containing attestation details.
|
|
137
|
+
*
|
|
138
|
+
* @returns The verification document with attestation results
|
|
139
|
+
* @throws Error if verification has not completed
|
|
140
|
+
* @see https://docs.tinfoil.sh/verification/attestation-architecture
|
|
141
|
+
*/
|
|
104
142
|
async getVerificationDocument() {
|
|
105
143
|
if (!this.initPromise) {
|
|
106
144
|
await this.ready();
|
|
@@ -111,26 +149,36 @@ export class SecureClient {
|
|
|
111
149
|
}
|
|
112
150
|
return this.verificationDocument;
|
|
113
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Get the base URL for API requests.
|
|
154
|
+
*
|
|
155
|
+
* @returns The base URL (e.g., "https://enclave.example.com/v1/")
|
|
156
|
+
*/
|
|
114
157
|
getBaseURL() {
|
|
115
158
|
return this.baseURL;
|
|
116
159
|
}
|
|
117
160
|
async createTransport(hpkePublicKey, tlsPublicKeyFingerprint) {
|
|
118
161
|
if (this.transport === 'tls') {
|
|
119
|
-
return await createSecureFetch(this.baseURL,
|
|
162
|
+
return await createSecureFetch(this.baseURL, undefined, tlsPublicKeyFingerprint, this.enclaveURL);
|
|
120
163
|
}
|
|
121
|
-
|
|
122
|
-
return await createSecureFetch(this.baseURL, this.enclaveURL, hpkePublicKey, undefined);
|
|
123
|
-
}
|
|
124
|
-
// 'auto' mode: use EHBP, store TLS fingerprint for lazy fallback if needed
|
|
125
|
-
this._tlsPublicKeyFingerprint = tlsPublicKeyFingerprint;
|
|
126
|
-
return await createSecureFetch(this.baseURL, this.enclaveURL, hpkePublicKey, undefined);
|
|
127
|
-
}
|
|
128
|
-
isNotSupportedError(error) {
|
|
129
|
-
return error instanceof Error &&
|
|
130
|
-
(error.name === 'NotSupportedError' ||
|
|
131
|
-
error.message.includes('NotSupportedError') ||
|
|
132
|
-
error.message.includes('unsupported'));
|
|
164
|
+
return await createSecureFetch(this.baseURL, hpkePublicKey, undefined, this.enclaveURL);
|
|
133
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Secure fetch function that encrypts request bodies end-to-end.
|
|
168
|
+
*
|
|
169
|
+
* Use this as a drop-in replacement for global `fetch`. Request bodies are
|
|
170
|
+
* encrypted using HPKE (or TLS pinning if configured) so only the verified
|
|
171
|
+
* enclave can decrypt them.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* const response = await client.fetch("/v1/chat/completions", {
|
|
176
|
+
* method: "POST",
|
|
177
|
+
* headers: { "Content-Type": "application/json" },
|
|
178
|
+
* body: JSON.stringify({ model: "llama3-3-70b", messages: [...] }),
|
|
179
|
+
* });
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
134
182
|
get fetch() {
|
|
135
183
|
return async (input, init) => {
|
|
136
184
|
await this.ready();
|
|
@@ -138,12 +186,6 @@ export class SecureClient {
|
|
|
138
186
|
return await this._fetch(input, init);
|
|
139
187
|
}
|
|
140
188
|
catch (error) {
|
|
141
|
-
// In 'auto' mode, fall back to TLS on NotSupportedError (e.g., X25519 not available)
|
|
142
|
-
if (this.transport === 'auto' && !this._didFallbackToTls && this._tlsPublicKeyFingerprint && this.isNotSupportedError(error)) {
|
|
143
|
-
this._didFallbackToTls = true;
|
|
144
|
-
this._fetch = await createSecureFetch(this.baseURL, this.enclaveURL, undefined, this._tlsPublicKeyFingerprint);
|
|
145
|
-
return await this._fetch(input, init);
|
|
146
|
-
}
|
|
147
189
|
if (this.verificationDocument) {
|
|
148
190
|
const errorMessage = error.message;
|
|
149
191
|
if (errorMessage.includes('HPKE public key mismatch')) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secure-client.js","sourceRoot":"","sources":["../src/secure-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"secure-client.js","sourceRoot":"","sources":["../src/secure-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA6B,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAsClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,OAAO,YAAY;IACf,WAAW,GAAyB,IAAI,CAAC;IACzC,oBAAoB,GAAgC,IAAI,CAAC;IACzD,MAAM,GAAwB,IAAI,CAAC;IAEnC,OAAO,CAAU;IACjB,UAAU,CAAU;IACX,UAAU,CAAS;IACnB,SAAS,CAAgB;IACzB,oBAAoB,CAAU;IAE/C,YAAY,UAA+B,EAAE;QAC3C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,cAAc,CAAC,mBAAmB,CAAC;QAC3E,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,MAAM,CAAC;QAC7C,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAC3D,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,KAAK;QAChB,IAAI,CAAC,IAAI,CAAC,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createSecureFetch(baseURL: string,
|
|
10
|
+
export declare function createSecureFetch(baseURL: string, hpkePublicKey?: string, tlsPublicKeyFingerprint?: string, enclaveURL?: string): Promise<typeof fetch>;
|
|
11
11
|
//# sourceMappingURL=secure-fetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secure-fetch.d.ts","sourceRoot":"","sources":["../src/secure-fetch.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,MAAM,EACf,
|
|
1
|
+
{"version":3,"file":"secure-fetch.d.ts","sourceRoot":"","sources":["../src/secure-fetch.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,MAAM,EACtB,uBAAuB,CAAC,EAAE,MAAM,EAChC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,OAAO,KAAK,CAAC,CAwBvB"}
|
package/dist/secure-fetch.js
CHANGED
|
@@ -8,7 +8,7 @@ import { isRealBrowser } from "./env.js";
|
|
|
8
8
|
*
|
|
9
9
|
* All imports are dynamic to enable tree-shaking in browser bundles.
|
|
10
10
|
*/
|
|
11
|
-
export async function createSecureFetch(baseURL,
|
|
11
|
+
export async function createSecureFetch(baseURL, hpkePublicKey, tlsPublicKeyFingerprint, enclaveURL) {
|
|
12
12
|
if (hpkePublicKey) {
|
|
13
13
|
// Dynamic import to avoid loading ehbp/hpke modules when using TLS-only mode.
|
|
14
14
|
// This prevents WebCrypto X25519 errors in runtimes that don't support it (like Bun).
|
package/dist/secure-fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secure-fetch.js","sourceRoot":"","sources":["../src/secure-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAe,EACf,
|
|
1
|
+
{"version":3,"file":"secure-fetch.js","sourceRoot":"","sources":["../src/secure-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAe,EACf,aAAsB,EACtB,uBAAgC,EAChC,UAAmB;IAEnB,IAAI,aAAa,EAAE,CAAC;QAClB,8EAA8E;QAC9E,sFAAsF;QACtF,MAAM,EAAE,wBAAwB,EAAE,GAAG,MAAM,MAAM,CAAC,2BAA2B,CAAC,CAAC;QAC/E,OAAO,wBAAwB,CAAC,OAAO,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;IACtE,CAAC;IAED,IAAI,aAAa,EAAE,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,wFAAwF;YACxF,iEAAiE,CAClE,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CACb,mFAAmF,CACpF,CAAC;IACJ,CAAC;IAED,6EAA6E;IAC7E,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC;IACvE,OAAO,oBAAoB,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;AAChE,CAAC"}
|
package/dist/tinfoil-ai.d.ts
CHANGED
|
@@ -2,16 +2,76 @@ import OpenAI from "openai";
|
|
|
2
2
|
import type { Audio, Beta, Chat, Embeddings, Files, FineTuning, Images, Models, Moderations, Responses } from "openai/resources";
|
|
3
3
|
import { type TransportMode } from "./secure-client.js";
|
|
4
4
|
import type { VerificationDocument } from "./verifier.js";
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Configuration options for TinfoilAI client.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Server-side with API key
|
|
11
|
+
* const client = new TinfoilAI({ apiKey: "your-api-key" });
|
|
12
|
+
*
|
|
13
|
+
* // Browser with bearer token (from your auth system)
|
|
14
|
+
* const client = new TinfoilAI({ bearerToken: "your-jwt-token" });
|
|
15
|
+
*
|
|
16
|
+
* // With custom transport mode
|
|
17
|
+
* const client = new TinfoilAI({ apiKey: "key", transport: "tls" });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export interface TinfoilAIOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Tinfoil API key. Get one at https://docs.tinfoil.sh/get-api-key
|
|
23
|
+
* In Node.js, defaults to TINFOIL_API_KEY environment variable.
|
|
24
|
+
* Never use in browser code - use bearerToken instead.
|
|
25
|
+
*/
|
|
6
26
|
apiKey?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Bearer token for browser authentication (e.g., JWT from your auth system).
|
|
29
|
+
* Automatically enables browser usage without dangerouslyAllowBrowser.
|
|
30
|
+
*/
|
|
7
31
|
bearerToken?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Override the base URL for API requests.
|
|
34
|
+
* Useful for proxying requests through your own backend.
|
|
35
|
+
* @see https://docs.tinfoil.sh/guides/proxy-server
|
|
36
|
+
*/
|
|
8
37
|
baseURL?: string;
|
|
9
|
-
|
|
38
|
+
/** GitHub repo for code verification. Defaults to tinfoilsh/confidential-model-router. */
|
|
10
39
|
configRepo?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Transport mode for secure communication.
|
|
42
|
+
* - 'ehbp': HPKE encryption via EHBP protocol (default)
|
|
43
|
+
* - 'tls': TLS certificate pinning (for runtimes without X25519 support)
|
|
44
|
+
* @default 'ehbp'
|
|
45
|
+
*/
|
|
11
46
|
transport?: TransportMode;
|
|
47
|
+
/** URL to fetch the attestation bundle from. If not set, uses the default Tinfoil ATC. */
|
|
12
48
|
attestationBundleURL?: string;
|
|
49
|
+
/** Additional OpenAI client options (passed through to underlying client) */
|
|
13
50
|
[key: string]: any;
|
|
14
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Secure OpenAI-compatible client for Tinfoil's verifiably private AI inference.
|
|
54
|
+
*
|
|
55
|
+
* TinfoilAI automatically verifies you're connected to a genuine secure enclave
|
|
56
|
+
* and encrypts all requests end-to-end. The API is fully compatible with OpenAI's client.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* import { TinfoilAI } from "tinfoil";
|
|
61
|
+
*
|
|
62
|
+
* const client = new TinfoilAI({
|
|
63
|
+
* apiKey: "your-api-key", // or use TINFOIL_API_KEY env var
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* const completion = await client.chat.completions.create({
|
|
67
|
+
* messages: [{ role: "user", content: "Hello!" }],
|
|
68
|
+
* model: "llama3-3-70b",
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @see https://docs.tinfoil.sh/sdk/javascript-sdk - Full documentation
|
|
73
|
+
* @see https://docs.tinfoil.sh/cc/how-it-works - How verification works
|
|
74
|
+
*/
|
|
15
75
|
export declare class TinfoilAI {
|
|
16
76
|
private client?;
|
|
17
77
|
private clientPromise;
|
|
@@ -23,11 +83,41 @@ export declare class TinfoilAI {
|
|
|
23
83
|
apiKey?: string;
|
|
24
84
|
bearerToken?: string;
|
|
25
85
|
baseURL?: string;
|
|
26
|
-
enclaveURL?: string;
|
|
27
86
|
constructor(options?: TinfoilAIOptions);
|
|
87
|
+
/**
|
|
88
|
+
* Wait for the client to complete verification and be ready for requests.
|
|
89
|
+
*
|
|
90
|
+
* Most methods automatically wait for ready(), but you can call this explicitly
|
|
91
|
+
* in browsers to show loading state during verification.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const client = new TinfoilAI({ bearerToken: jwt });
|
|
96
|
+
* await client.ready(); // Wait for verification
|
|
97
|
+
* // Now make requests
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
28
100
|
ready(): Promise<void>;
|
|
29
101
|
private createOpenAIClient;
|
|
30
102
|
private ensureReady;
|
|
103
|
+
/**
|
|
104
|
+
* Get the verification document containing attestation details.
|
|
105
|
+
*
|
|
106
|
+
* The document includes information about the enclave, code measurements,
|
|
107
|
+
* and the status of each verification step.
|
|
108
|
+
*
|
|
109
|
+
* @returns The verification document with attestation results
|
|
110
|
+
* @throws Error if verification has not completed
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const doc = await client.getVerificationDocument();
|
|
115
|
+
* console.log(doc.securityVerified); // true if all checks passed
|
|
116
|
+
* console.log(doc.steps); // { fetchDigest, verifyCode, verifyEnclave, compareMeasurements }
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @see https://docs.tinfoil.sh/verification/attestation-architecture
|
|
120
|
+
*/
|
|
31
121
|
getVerificationDocument(): Promise<VerificationDocument>;
|
|
32
122
|
get chat(): Chat;
|
|
33
123
|
get files(): Files;
|
|
@@ -56,5 +146,4 @@ export declare namespace TinfoilAI {
|
|
|
56
146
|
export import Uploads = OpenAI.Uploads;
|
|
57
147
|
export import VectorStores = OpenAI.VectorStores;
|
|
58
148
|
}
|
|
59
|
-
export {};
|
|
60
149
|
//# sourceMappingURL=tinfoil-ai.d.ts.map
|
package/dist/tinfoil-ai.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tinfoil-ai.d.ts","sourceRoot":"","sources":["../src/tinfoil-ai.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,EACV,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,KAAK,EACL,UAAU,EACV,MAAM,EACN,MAAM,EACN,WAAW,EACX,SAAS,EACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,EAAE,oBA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AG,MAAM,CAAC,WAAW,CAAC;IAC/C,MAAM,QAAQ,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IAC3C,MAAM,QAAQ,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IACvC,MAAM,QAAQ,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;CAClD"}
|
package/dist/tinfoil-ai.js
CHANGED
|
@@ -24,6 +24,29 @@ function createAsyncProxy(promise) {
|
|
|
24
24
|
},
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Secure OpenAI-compatible client for Tinfoil's verifiably private AI inference.
|
|
29
|
+
*
|
|
30
|
+
* TinfoilAI automatically verifies you're connected to a genuine secure enclave
|
|
31
|
+
* and encrypts all requests end-to-end. The API is fully compatible with OpenAI's client.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { TinfoilAI } from "tinfoil";
|
|
36
|
+
*
|
|
37
|
+
* const client = new TinfoilAI({
|
|
38
|
+
* apiKey: "your-api-key", // or use TINFOIL_API_KEY env var
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* const completion = await client.chat.completions.create({
|
|
42
|
+
* messages: [{ role: "user", content: "Hello!" }],
|
|
43
|
+
* model: "llama3-3-70b",
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @see https://docs.tinfoil.sh/sdk/javascript-sdk - Full documentation
|
|
48
|
+
* @see https://docs.tinfoil.sh/cc/how-it-works - How verification works
|
|
49
|
+
*/
|
|
27
50
|
export class TinfoilAI {
|
|
28
51
|
client;
|
|
29
52
|
clientPromise;
|
|
@@ -35,7 +58,6 @@ export class TinfoilAI {
|
|
|
35
58
|
apiKey;
|
|
36
59
|
bearerToken;
|
|
37
60
|
baseURL;
|
|
38
|
-
enclaveURL;
|
|
39
61
|
constructor(options = {}) {
|
|
40
62
|
const openAIOptions = { ...options };
|
|
41
63
|
// bearerToken is used for browser auth (e.g., JWT from your auth system)
|
|
@@ -50,22 +72,33 @@ export class TinfoilAI {
|
|
|
50
72
|
else if (options.apiKey) {
|
|
51
73
|
openAIOptions.apiKey = options.apiKey;
|
|
52
74
|
}
|
|
53
|
-
else if (!isRealBrowser() && process.env.TINFOIL_API_KEY) {
|
|
75
|
+
else if (!isRealBrowser() && typeof process !== 'undefined' && process.env.TINFOIL_API_KEY) {
|
|
54
76
|
openAIOptions.apiKey = process.env.TINFOIL_API_KEY;
|
|
55
77
|
}
|
|
56
78
|
this.apiKey = options.apiKey;
|
|
57
79
|
this.baseURL = options.baseURL;
|
|
58
|
-
this.enclaveURL = options.enclaveURL;
|
|
59
80
|
this.configRepo = options.configRepo || TINFOIL_CONFIG.DEFAULT_ROUTER_REPO;
|
|
60
81
|
this.secureClient = new SecureClient({
|
|
61
82
|
baseURL: this.baseURL,
|
|
62
|
-
enclaveURL: this.enclaveURL,
|
|
63
83
|
configRepo: this.configRepo,
|
|
64
84
|
transport: options.transport,
|
|
65
85
|
attestationBundleURL: options.attestationBundleURL,
|
|
66
86
|
});
|
|
67
87
|
this.clientPromise = this.createOpenAIClient(openAIOptions);
|
|
68
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Wait for the client to complete verification and be ready for requests.
|
|
91
|
+
*
|
|
92
|
+
* Most methods automatically wait for ready(), but you can call this explicitly
|
|
93
|
+
* in browsers to show loading state during verification.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const client = new TinfoilAI({ bearerToken: jwt });
|
|
98
|
+
* await client.ready(); // Wait for verification
|
|
99
|
+
* // Now make requests
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
69
102
|
async ready() {
|
|
70
103
|
if (!this.readyPromise) {
|
|
71
104
|
this.readyPromise = (async () => {
|
|
@@ -98,6 +131,24 @@ export class TinfoilAI {
|
|
|
98
131
|
await this.ready();
|
|
99
132
|
return this.client;
|
|
100
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Get the verification document containing attestation details.
|
|
136
|
+
*
|
|
137
|
+
* The document includes information about the enclave, code measurements,
|
|
138
|
+
* and the status of each verification step.
|
|
139
|
+
*
|
|
140
|
+
* @returns The verification document with attestation results
|
|
141
|
+
* @throws Error if verification has not completed
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const doc = await client.getVerificationDocument();
|
|
146
|
+
* console.log(doc.securityVerified); // true if all checks passed
|
|
147
|
+
* console.log(doc.steps); // { fetchDigest, verifyCode, verifyEnclave, compareMeasurements }
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @see https://docs.tinfoil.sh/verification/attestation-architecture
|
|
151
|
+
*/
|
|
101
152
|
async getVerificationDocument() {
|
|
102
153
|
await this.ready();
|
|
103
154
|
if (!this.verificationDocument) {
|
package/dist/tinfoil-ai.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tinfoil-ai.js","sourceRoot":"","sources":["../src/tinfoil-ai.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAa5B,OAAO,EAAE,YAAY,EAAsB,MAAM,oBAAoB,CAAC;AAEtE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,SAAS,gBAAgB,CAAmB,OAAmB;IAC7D,OAAO,IAAI,KAAK,CAAC,EAAO,EAAE;QACxB,GAAG,CAAC,MAAM,EAAE,IAAI;YACd,OAAO,IAAI,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE;gBACzB,GAAG,CAAC,CAAC,EAAE,UAAU;oBACf,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE,CACxB,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;wBACnB,MAAM,KAAK,GAAI,GAAW,CAAC,IAAI,CAAC,CAAC,UAA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,CAAC;IAED,IAAI,IAAI;QACN,OAAO,gBAAgB,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5E,CAAC;CACF;AAED,+DAA+D;AAC/D,2DAA2D;AAC3D,WAAiB,SAAS;IACV,cAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IACnB,eAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IACrB,cAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IACnB,iBAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IACzB,qBAAW,GAAG,MAAM,CAAC,WAAW,CAAC;IACjC,oBAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IAC/B,eAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IACrB,oBAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IAC/B,gBAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IACvB,gBAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IACvB,qBAAW,GAAG,MAAM,CAAC,WAAW,CAAC;IACjC,mBAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IAC7B,iBAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IACzB,sBAAY,GAAG,MAAM,CAAC,YAAY,CAAC;AACnD,CAAC,EAfgB,SAAS,KAAT,SAAS,QAezB"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
interface UnverifiedClientOptions {
|
|
2
|
+
/** Base URL for API requests. If not provided, derived from keyOrigin or fetched from router. */
|
|
2
3
|
baseURL?: string;
|
|
3
|
-
|
|
4
|
+
/** Origin URL for fetching the HPKE public key. If not provided, derived from baseURL. */
|
|
5
|
+
keyOrigin?: string;
|
|
4
6
|
}
|
|
5
7
|
export declare class UnverifiedClient {
|
|
6
8
|
private initPromise;
|
|
7
9
|
private _fetch;
|
|
8
10
|
private baseURL?;
|
|
9
|
-
private
|
|
11
|
+
private keyOrigin?;
|
|
10
12
|
constructor(options?: UnverifiedClientOptions);
|
|
11
13
|
ready(): Promise<void>;
|
|
12
14
|
private initUnverifiedClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unverified-client.d.ts","sourceRoot":"","sources":["../src/unverified-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unverified-client.d.ts","sourceRoot":"","sources":["../src/unverified-client.ts"],"names":[],"mappings":"AAaA,UAAU,uBAAuB;IAC/B,iGAAiG;IACjG,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0FAA0F;IAC1F,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,MAAM,CAA6B;IAE3C,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,SAAS,CAAC,CAAS;gBAEf,OAAO,GAAE,uBAA4B;IAUpC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAOrB,oBAAoB;IAgCrB,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC;IAUrD,IAAI,KAAK,IAAI,OAAO,KAAK,CAKxB;CACF"}
|
|
@@ -1,12 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WARNING: THIS CLIENT IS INSECURE.
|
|
3
|
+
*
|
|
4
|
+
* UnverifiedClient fetches the HPKE public key directly from the server without
|
|
5
|
+
* attestation verification. This is vulnerable to man-in-the-middle attacks where
|
|
6
|
+
* a malicious server could provide its own key.
|
|
7
|
+
*
|
|
8
|
+
* This client is useful for testing the EHBP protocol against a local development
|
|
9
|
+
* server that doesn't have attestation set up. For production, use SecureClient
|
|
10
|
+
* or TinfoilAI which verify the key through attestation.
|
|
11
|
+
*/
|
|
1
12
|
import { fetchRouter } from "./atc.js";
|
|
2
13
|
export class UnverifiedClient {
|
|
3
14
|
initPromise = null;
|
|
4
15
|
_fetch = null;
|
|
5
16
|
baseURL;
|
|
6
|
-
|
|
17
|
+
keyOrigin;
|
|
7
18
|
constructor(options = {}) {
|
|
19
|
+
console.warn("[tinfoil] WARNING: UnverifiedClient is insecure. " +
|
|
20
|
+
"The HPKE key is fetched from the server without attestation verification. " +
|
|
21
|
+
"Only use for local development and testing of the EHBP protocol.");
|
|
8
22
|
this.baseURL = options.baseURL;
|
|
9
|
-
this.
|
|
23
|
+
this.keyOrigin = options.keyOrigin;
|
|
10
24
|
}
|
|
11
25
|
async ready() {
|
|
12
26
|
if (!this.initPromise) {
|
|
@@ -15,36 +29,34 @@ export class UnverifiedClient {
|
|
|
15
29
|
return this.initPromise;
|
|
16
30
|
}
|
|
17
31
|
async initUnverifiedClient() {
|
|
18
|
-
// Only fetch router if neither baseURL nor
|
|
19
|
-
if (!this.baseURL && !this.
|
|
32
|
+
// Only fetch router if neither baseURL nor keyOrigin is provided
|
|
33
|
+
if (!this.baseURL && !this.keyOrigin) {
|
|
20
34
|
const routerAddress = await fetchRouter();
|
|
21
|
-
this.
|
|
35
|
+
this.keyOrigin = `https://${routerAddress}`;
|
|
22
36
|
this.baseURL = `https://${routerAddress}/v1/`;
|
|
23
37
|
}
|
|
24
|
-
// Ensure both baseURL and
|
|
38
|
+
// Ensure both baseURL and keyOrigin are initialized
|
|
25
39
|
if (!this.baseURL) {
|
|
26
|
-
if (this.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.baseURL = `${enclaveUrl.origin}/v1/`;
|
|
40
|
+
if (this.keyOrigin) {
|
|
41
|
+
const keyOriginUrl = new URL(this.keyOrigin);
|
|
42
|
+
this.baseURL = `${keyOriginUrl.origin}/v1/`;
|
|
30
43
|
}
|
|
31
44
|
else {
|
|
32
|
-
throw new Error("Unable to determine baseURL: neither baseURL nor
|
|
45
|
+
throw new Error("Unable to determine baseURL: neither baseURL nor keyOrigin provided");
|
|
33
46
|
}
|
|
34
47
|
}
|
|
35
|
-
if (!this.
|
|
48
|
+
if (!this.keyOrigin) {
|
|
36
49
|
if (this.baseURL) {
|
|
37
|
-
// If baseURL is provided but enclaveURL is not, derive enclaveURL from baseURL
|
|
38
50
|
const baseUrl = new URL(this.baseURL);
|
|
39
|
-
this.
|
|
51
|
+
this.keyOrigin = baseUrl.origin;
|
|
40
52
|
}
|
|
41
53
|
else {
|
|
42
|
-
throw new Error("Unable to determine
|
|
54
|
+
throw new Error("Unable to determine keyOrigin: neither baseURL nor keyOrigin provided");
|
|
43
55
|
}
|
|
44
56
|
}
|
|
45
57
|
// Dynamically import to avoid loading ehbp/hpke modules at module load time
|
|
46
|
-
const {
|
|
47
|
-
this._fetch =
|
|
58
|
+
const { createUnverifiedEncryptedBodyFetch } = await import("./encrypted-body-fetch.js");
|
|
59
|
+
this._fetch = createUnverifiedEncryptedBodyFetch(this.baseURL, this.keyOrigin);
|
|
48
60
|
}
|
|
49
61
|
async getVerificationDocument() {
|
|
50
62
|
if (!this.initPromise) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unverified-client.js","sourceRoot":"","sources":["../src/unverified-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"unverified-client.js","sourceRoot":"","sources":["../src/unverified-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AASvC,MAAM,OAAO,gBAAgB;IACnB,WAAW,GAAyB,IAAI,CAAC;IACzC,MAAM,GAAwB,IAAI,CAAC;IAEnC,OAAO,CAAU;IACjB,SAAS,CAAU;IAE3B,YAAY,UAAmC,EAAE;QAC/C,OAAO,CAAC,IAAI,CACV,mDAAmD;YACnD,4EAA4E;YAC5E,kEAAkE,CACnE,CAAC;QACF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IACrC,CAAC;IAEM,KAA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zF,IAAI,CAAC,MAAM,GAAG,kCAAkC,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACjF,CAAC;IAEM,KAAK,CAAC,uBAAuB;QAClC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;QAED,MAAM,IAAI,CAAC,WAAW,CAAC;QAEvB,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;IACjG,CAAC;IAED,IAAI,KAAK;QACP,OAAO,KAAK,EAAE,KAAwB,EAAE,IAAkB,EAAE,EAAE;YAC5D,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC,MAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACnC,CAAC,CAAC;IACJ,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinfoil",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Tinfoil secure OpenAI client wrapper",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@ai-sdk/openai-compatible": "^1.0.10",
|
|
55
55
|
"@freedomofpress/sigstore-browser": "^0.1.11",
|
|
56
|
-
"@tinfoilsh/verifier": "1.0.
|
|
57
|
-
"ehbp": "^0.1.
|
|
56
|
+
"@tinfoilsh/verifier": "1.0.3",
|
|
57
|
+
"ehbp": "^0.1.5",
|
|
58
58
|
"openai": "^5.13.1"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|