tinfoil 0.9.0 → 0.9.1
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 +7 -42
- package/dist/encrypted-body-fetch.d.ts +2 -2
- package/dist/encrypted-body-fetch.js +5 -3
- package/dist/esm/encrypted-body-fetch.d.ts +2 -2
- package/dist/esm/encrypted-body-fetch.js +5 -3
- package/dist/esm/index.browser.d.ts +1 -0
- package/dist/esm/index.browser.js +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/unverified-client.d.ts +18 -0
- package/dist/esm/unverified-client.js +33 -0
- package/dist/index.browser.d.ts +1 -0
- package/dist/index.browser.js +3 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/unverified-client.d.ts +18 -0
- package/dist/unverified-client.js +37 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
[](https://github.com/tinfoilsh/tinfoil-node/actions)
|
|
4
4
|
[](https://npmjs.org/package/tinfoil)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
This client library provides secure and convenient access to the Tinfoil Priavate Inference endpoints from TypeScript or JavaScript.
|
|
7
|
+
|
|
8
|
+
It is a wrapper around the OpenAI client that verifies enclave attestation and routes traffic to the Tinfoil Private Inference endpoints through an [EHBP](https://github.com/tinfoilsh/encrypted-http-body-protocol)-secured transport. EHBP encrypts all payloads directly to an attested enclave using [HPKE (RFC 9180)](https://www.rfc-editor.org/rfc/rfc9180.html).
|
|
7
9
|
|
|
8
10
|
## Installation
|
|
9
11
|
|
|
@@ -54,7 +56,7 @@ const client = new TinfoilAI({
|
|
|
54
56
|
await client.ready();
|
|
55
57
|
|
|
56
58
|
const completion = await client.chat.completions.create({
|
|
57
|
-
model: '
|
|
59
|
+
model: 'llama3-3-70b',
|
|
58
60
|
messages: [{ role: 'user', content: 'Hello!' }]
|
|
59
61
|
});
|
|
60
62
|
```
|
|
@@ -63,18 +65,13 @@ const completion = await client.chat.completions.create({
|
|
|
63
65
|
|
|
64
66
|
- Modern browsers with ES2020 support
|
|
65
67
|
- WebAssembly support for enclave verification
|
|
66
|
-
- Secure context (HTTPS or localhost) with WebCrypto SubtleCrypto (required by EHBP)
|
|
67
|
-
|
|
68
|
-
> **Note**
|
|
69
|
-
> The EHBP transport now accepts `http://` origins (for example when developing against a `localhost` proxy). Payloads remain HPKE-encrypted end to end, while TLS-only fallback logic continues to require HTTPS because it relies on certificate pinning.
|
|
70
68
|
|
|
71
69
|
|
|
72
70
|
## Verification helpers
|
|
73
71
|
|
|
74
72
|
This package exposes verification helpers that load the Go-based WebAssembly verifier once per process and provide structured, stepwise attestation results you can use in applications (e.g., to show progress, log transitions, or gate features).
|
|
75
73
|
|
|
76
|
-
The verification functionality is
|
|
77
|
-
- `verifier.ts`: Core verification logic with low-level attestation methods
|
|
74
|
+
The verification functionality is contained in `verifier.ts`.
|
|
78
75
|
|
|
79
76
|
|
|
80
77
|
### Core Verifier API
|
|
@@ -106,8 +103,6 @@ The project includes both unit tests and integration tests:
|
|
|
106
103
|
npm test
|
|
107
104
|
```
|
|
108
105
|
|
|
109
|
-
This runs the test suite with unit tests and mocked components. These tests don't require network access and run quickly.
|
|
110
|
-
|
|
111
106
|
### Running Integration Tests
|
|
112
107
|
|
|
113
108
|
```bash
|
|
@@ -121,39 +116,9 @@ This runs the full test suite including integration tests that:
|
|
|
121
116
|
|
|
122
117
|
Integration tests are skipped by default to keep the test suite fast and avoid network dependencies during development.
|
|
123
118
|
|
|
124
|
-
## Running
|
|
125
|
-
|
|
126
|
-
The chat example demonstrates both streaming chat completions and real-time attestation verification with a visual progress UI.
|
|
127
|
-
|
|
128
|
-
1. Clone the repository
|
|
129
|
-
|
|
130
|
-
2. Install dependencies:
|
|
131
|
-
|
|
132
|
-
```bash
|
|
133
|
-
npm install
|
|
134
|
-
npm run build
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
3. Optionally create a `.env` file with your configuration:
|
|
138
|
-
|
|
139
|
-
```bash
|
|
140
|
-
TINFOIL_API_KEY=<YOUR_API_KEY>
|
|
141
|
-
# Optional: Enable WASM debug logs
|
|
142
|
-
# TINFOIL_ENABLE_WASM_LOGS=true
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
4. Run the example:
|
|
146
|
-
|
|
147
|
-
```bash
|
|
148
|
-
cd examples/chat
|
|
149
|
-
npx ts-node main.ts
|
|
150
|
-
```
|
|
119
|
+
## Running examples
|
|
151
120
|
|
|
152
|
-
|
|
153
|
-
- Display a real-time verification progress showing each attestation step
|
|
154
|
-
- Verify the enclave's runtime and code measurements
|
|
155
|
-
- Compare measurements using platform-specific logic
|
|
156
|
-
- Stream chat completions through the verified secure channel
|
|
121
|
+
See [examples/README.md](https://github.com/tinfoilsh/tinfoil-node/blob/main/examples/README.md).
|
|
157
122
|
|
|
158
123
|
## API Documentation
|
|
159
124
|
|
|
@@ -4,8 +4,8 @@ export declare function normalizeEncryptedBodyRequestArgs(input: RequestInfo | U
|
|
|
4
4
|
url: string;
|
|
5
5
|
init?: RequestInit;
|
|
6
6
|
};
|
|
7
|
-
export declare function encryptedBodyRequest(input: RequestInfo | URL, hpkePublicKey
|
|
8
|
-
export declare function createEncryptedBodyFetch(baseURL: string, hpkePublicKey
|
|
7
|
+
export declare function encryptedBodyRequest(input: RequestInfo | URL, hpkePublicKey?: string, init?: RequestInit, enclaveURL?: string): Promise<Response>;
|
|
8
|
+
export declare function createEncryptedBodyFetch(baseURL: string, hpkePublicKey?: string, enclaveURL?: string): typeof fetch;
|
|
9
9
|
export declare function __setEhbpModuleForTests(module: EhbpModule | undefined): void;
|
|
10
10
|
export declare function __resetEhbpModuleStateForTests(): void;
|
|
11
11
|
export {};
|
|
@@ -92,9 +92,11 @@ async function encryptedBodyRequest(input, hpkePublicKey, init, enclaveURL) {
|
|
|
92
92
|
transport = getTransportForOrigin(origin, keyOrigin);
|
|
93
93
|
}
|
|
94
94
|
const transportInstance = await transport;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
if (hpkePublicKey) {
|
|
96
|
+
const transportKeyHash = await transportInstance.getServerPublicKeyHex();
|
|
97
|
+
if (transportKeyHash !== hpkePublicKey) {
|
|
98
|
+
throw new Error(`HPKE public key mismatch. Expected: ${hpkePublicKey}, Got: ${transportKeyHash}`);
|
|
99
|
+
}
|
|
98
100
|
}
|
|
99
101
|
return transportInstance.request(requestUrl, requestInit);
|
|
100
102
|
}
|
|
@@ -4,8 +4,8 @@ export declare function normalizeEncryptedBodyRequestArgs(input: RequestInfo | U
|
|
|
4
4
|
url: string;
|
|
5
5
|
init?: RequestInit;
|
|
6
6
|
};
|
|
7
|
-
export declare function encryptedBodyRequest(input: RequestInfo | URL, hpkePublicKey
|
|
8
|
-
export declare function createEncryptedBodyFetch(baseURL: string, hpkePublicKey
|
|
7
|
+
export declare function encryptedBodyRequest(input: RequestInfo | URL, hpkePublicKey?: string, init?: RequestInit, enclaveURL?: string): Promise<Response>;
|
|
8
|
+
export declare function createEncryptedBodyFetch(baseURL: string, hpkePublicKey?: string, enclaveURL?: string): typeof fetch;
|
|
9
9
|
export declare function __setEhbpModuleForTests(module: EhbpModule | undefined): void;
|
|
10
10
|
export declare function __resetEhbpModuleStateForTests(): void;
|
|
11
11
|
export {};
|
|
@@ -51,9 +51,11 @@ export async function encryptedBodyRequest(input, hpkePublicKey, init, enclaveUR
|
|
|
51
51
|
transport = getTransportForOrigin(origin, keyOrigin);
|
|
52
52
|
}
|
|
53
53
|
const transportInstance = await transport;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
if (hpkePublicKey) {
|
|
55
|
+
const transportKeyHash = await transportInstance.getServerPublicKeyHex();
|
|
56
|
+
if (transportKeyHash !== hpkePublicKey) {
|
|
57
|
+
throw new Error(`HPKE public key mismatch. Expected: ${hpkePublicKey}, Got: ${transportKeyHash}`);
|
|
58
|
+
}
|
|
57
59
|
}
|
|
58
60
|
return transportInstance.request(requestUrl, requestInit);
|
|
59
61
|
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ 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";
|
|
7
8
|
export { type Uploadable, toFile, APIPromise, PagePromise, OpenAIError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "openai";
|
package/dist/esm/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./verifier";
|
|
|
6
6
|
export * from "./ai-sdk-provider";
|
|
7
7
|
export * from "./config";
|
|
8
8
|
export { SecureClient } from "./secure-client";
|
|
9
|
+
export { UnverifiedClient } from "./unverified-client";
|
|
9
10
|
// Re-export OpenAI utility types and classes that users might need
|
|
10
11
|
// Using public exports from the main OpenAI package instead of deep imports
|
|
11
12
|
export { toFile, APIPromise, PagePromise, OpenAIError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "openai";
|
|
@@ -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 readonly baseURL;
|
|
10
|
+
private readonly 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,33 @@
|
|
|
1
|
+
import { TINFOIL_CONFIG } from "./config";
|
|
2
|
+
import { createEncryptedBodyFetch } from "./encrypted-body-fetch";
|
|
3
|
+
export class UnverifiedClient {
|
|
4
|
+
constructor(options = {}) {
|
|
5
|
+
this.initPromise = null;
|
|
6
|
+
this._fetch = null;
|
|
7
|
+
this.baseURL = options.baseURL || TINFOIL_CONFIG.INFERENCE_BASE_URL;
|
|
8
|
+
this.enclaveURL = options.enclaveURL || TINFOIL_CONFIG.ENCLAVE_URL;
|
|
9
|
+
this.configRepo = options.configRepo || TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
|
|
10
|
+
}
|
|
11
|
+
async ready() {
|
|
12
|
+
if (!this.initPromise) {
|
|
13
|
+
this.initPromise = this.initUnverifiedClient();
|
|
14
|
+
}
|
|
15
|
+
return this.initPromise;
|
|
16
|
+
}
|
|
17
|
+
async initUnverifiedClient() {
|
|
18
|
+
this._fetch = createEncryptedBodyFetch(this.baseURL, undefined, this.enclaveURL);
|
|
19
|
+
}
|
|
20
|
+
async getVerificationDocument() {
|
|
21
|
+
if (!this.initPromise) {
|
|
22
|
+
await this.ready();
|
|
23
|
+
}
|
|
24
|
+
await this.initPromise;
|
|
25
|
+
throw new Error("Verification document unavailable: this version of the client is unverified");
|
|
26
|
+
}
|
|
27
|
+
get fetch() {
|
|
28
|
+
return async (input, init) => {
|
|
29
|
+
await this.ready();
|
|
30
|
+
return this._fetch(input, init);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
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,5 @@ 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";
|
|
7
8
|
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.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,8 @@ __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; } });
|
|
29
31
|
// Re-export OpenAI utility types and classes that users might need
|
|
30
32
|
// Using public exports from the main OpenAI package instead of deep imports
|
|
31
33
|
var openai_1 = require("openai");
|
|
@@ -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 readonly baseURL;
|
|
10
|
+
private readonly 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,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnverifiedClient = void 0;
|
|
4
|
+
const config_1 = require("./config");
|
|
5
|
+
const encrypted_body_fetch_1 = require("./encrypted-body-fetch");
|
|
6
|
+
class UnverifiedClient {
|
|
7
|
+
constructor(options = {}) {
|
|
8
|
+
this.initPromise = null;
|
|
9
|
+
this._fetch = null;
|
|
10
|
+
this.baseURL = options.baseURL || config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL;
|
|
11
|
+
this.enclaveURL = options.enclaveURL || config_1.TINFOIL_CONFIG.ENCLAVE_URL;
|
|
12
|
+
this.configRepo = options.configRepo || config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
|
|
13
|
+
}
|
|
14
|
+
async ready() {
|
|
15
|
+
if (!this.initPromise) {
|
|
16
|
+
this.initPromise = this.initUnverifiedClient();
|
|
17
|
+
}
|
|
18
|
+
return this.initPromise;
|
|
19
|
+
}
|
|
20
|
+
async initUnverifiedClient() {
|
|
21
|
+
this._fetch = (0, encrypted_body_fetch_1.createEncryptedBodyFetch)(this.baseURL, undefined, this.enclaveURL);
|
|
22
|
+
}
|
|
23
|
+
async getVerificationDocument() {
|
|
24
|
+
if (!this.initPromise) {
|
|
25
|
+
await this.ready();
|
|
26
|
+
}
|
|
27
|
+
await this.initPromise;
|
|
28
|
+
throw new Error("Verification document unavailable: this version of the client is unverified");
|
|
29
|
+
}
|
|
30
|
+
get fetch() {
|
|
31
|
+
return async (input, init) => {
|
|
32
|
+
await this.ready();
|
|
33
|
+
return this._fetch(input, init);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.UnverifiedClient = UnverifiedClient;
|