tinfoil 1.1.8 → 1.1.9
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/LICENSE +201 -0
- package/dist/ai-sdk-provider.d.ts +7 -0
- package/dist/ai-sdk-provider.d.ts.map +1 -1
- package/dist/ai-sdk-provider.js +1 -0
- package/dist/ai-sdk-provider.js.map +1 -1
- package/dist/encrypted-body-fetch.d.ts +1 -1
- package/dist/encrypted-body-fetch.d.ts.map +1 -1
- package/dist/encrypted-body-fetch.js +6 -2
- package/dist/encrypted-body-fetch.js.map +1 -1
- package/dist/secure-client.d.ts +15 -0
- package/dist/secure-client.d.ts.map +1 -1
- package/dist/secure-client.js +9 -2
- package/dist/secure-client.js.map +1 -1
- package/dist/secure-fetch.d.ts +5 -1
- package/dist/secure-fetch.d.ts.map +1 -1
- package/dist/secure-fetch.js +10 -3
- package/dist/secure-fetch.js.map +1 -1
- package/dist/tinfoil-ai.d.ts +9 -0
- package/dist/tinfoil-ai.d.ts.map +1 -1
- package/dist/tinfoil-ai.js +1 -0
- package/dist/tinfoil-ai.js.map +1 -1
- package/dist/user-cache-secret-store.browser.d.ts +7 -0
- package/dist/user-cache-secret-store.browser.d.ts.map +1 -0
- package/dist/user-cache-secret-store.browser.js +9 -0
- package/dist/user-cache-secret-store.browser.js.map +1 -0
- package/dist/user-cache-secret-store.d.ts +19 -0
- package/dist/user-cache-secret-store.d.ts.map +1 -0
- package/dist/user-cache-secret-store.js +161 -0
- package/dist/user-cache-secret-store.js.map +1 -0
- package/dist/user-cache-secret.d.ts +67 -0
- package/dist/user-cache-secret.d.ts.map +1 -0
- package/dist/user-cache-secret.js +259 -0
- package/dist/user-cache-secret.js.map +1 -0
- package/package.json +5 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work, excluding
|
|
103
|
+
those notices that do not pertain to any part of the Derivative
|
|
104
|
+
Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one of
|
|
111
|
+
the following places: within a NOTICE text file distributed as
|
|
112
|
+
part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and do
|
|
117
|
+
not modify the License. You may add Your own attribution notices
|
|
118
|
+
within Derivative Works that You distribute, alongside or as an
|
|
119
|
+
addendum to the NOTICE text from the Work, provided that such
|
|
120
|
+
additional attribution notices cannot be construed as modifying
|
|
121
|
+
the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions for
|
|
125
|
+
use, reproduction, or distribution of Your modifications, or for any
|
|
126
|
+
such Derivative Works as a whole, provided Your use, reproduction,
|
|
127
|
+
and distribution of the Work otherwise complies with the conditions
|
|
128
|
+
stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Tinfoil
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -11,6 +11,13 @@ export interface CreateTinfoilAIOptions {
|
|
|
11
11
|
configRepo?: string;
|
|
12
12
|
/** URL to fetch the attestation bundle from. */
|
|
13
13
|
attestationBundleURL?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Secret scoping the router's prompt cache for this provider's requests.
|
|
16
|
+
* Defaults to the TINFOIL_USER_CACHE_SECRET environment variable, otherwise
|
|
17
|
+
* to a generated secret persisted at `~/.tinfoil/user_cache_secret`. Pass
|
|
18
|
+
* an empty string to disable prompt-cache scoping (tenant-wide caching).
|
|
19
|
+
*/
|
|
20
|
+
userCacheSecret?: string;
|
|
14
21
|
}
|
|
15
22
|
/**
|
|
16
23
|
* Create a Tinfoil provider for the Vercel AI SDK.
|
|
@@ -1 +1 @@
|
|
|
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,gDAAgD;IAChD,oBAAoB,CAAC,EAAE,MAAM,CAAC;
|
|
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,gDAAgD;IAChD,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,eAAe,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B,yGAyB1F"}
|
package/dist/ai-sdk-provider.js
CHANGED
|
@@ -45,6 +45,7 @@ export async function createTinfoilAI(apiKey, options = {}) {
|
|
|
45
45
|
baseURL: options.baseURL,
|
|
46
46
|
configRepo: options.configRepo,
|
|
47
47
|
attestationBundleURL: options.attestationBundleURL,
|
|
48
|
+
userCacheSecret: options.userCacheSecret,
|
|
48
49
|
});
|
|
49
50
|
await secureClient.ready();
|
|
50
51
|
return createOpenAICompatible({
|
|
@@ -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,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,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,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AA2BnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,kBAAkB,CAAC,4FAA4F,CAAC,CAAC;IAC7H,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC;QACpC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,oBAAoB,EAAE,OAAO,CAAC,oBAAoB;QAClD,eAAe,EAAE,OAAO,CAAC,eAAe;KACzC,CAAC,CAAC;IAEH,MAAM,YAAY,CAAC,KAAK,EAAE,CAAC;IAE3B,OAAO,sBAAsB,CAAC;QAC5B,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,YAAY,CAAC,UAAU,EAAG;QACnC,MAAM,EAAE,cAAc;QACtB,KAAK,EAAE,YAAY,CAAC,KAAK;KAC1B,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -15,7 +15,7 @@ export declare function normalizeEncryptedBodyRequestArgs(input: RequestInfo | U
|
|
|
15
15
|
init?: RequestInit;
|
|
16
16
|
};
|
|
17
17
|
export declare function encryptedBodyRequest(input: RequestInfo | URL, hpkePublicKey: string, init?: RequestInit, transportInstance?: Transport): Promise<Response>;
|
|
18
|
-
export declare function createEncryptedBodyFetch(baseURL: string, hpkePublicKey: string, enclaveURL?: string): SecureTransport;
|
|
18
|
+
export declare function createEncryptedBodyFetch(baseURL: string, hpkePublicKey: string, enclaveURL?: string, userCacheSecret?: string): SecureTransport;
|
|
19
19
|
/**
|
|
20
20
|
* WARNING: THIS FUNCTION IS INSECURE.
|
|
21
21
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encrypted-body-fetch.d.ts","sourceRoot":"","sources":["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eAAe,CA2CvG"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Identity, Transport, PROTOCOL } from "ehbp";
|
|
2
2
|
import { ConfigurationError, FetchError } from "./verifier.js";
|
|
3
|
+
import { injectUserCacheSecretIntoRequestInit } from "./user-cache-secret.js";
|
|
3
4
|
export { decryptResponseWithToken } from "ehbp";
|
|
4
5
|
/**
|
|
5
6
|
* Create an Identity from a raw public key hex string.
|
|
@@ -58,7 +59,7 @@ export async function encryptedBodyRequest(input, hpkePublicKey, init, transport
|
|
|
58
59
|
return actualTransport.request(requestUrl, requestInit);
|
|
59
60
|
}
|
|
60
61
|
const ENCLAVE_URL_HEADER = 'X-Tinfoil-Enclave-Url';
|
|
61
|
-
export function createEncryptedBodyFetch(baseURL, hpkePublicKey, enclaveURL) {
|
|
62
|
+
export function createEncryptedBodyFetch(baseURL, hpkePublicKey, enclaveURL, userCacheSecret = "") {
|
|
62
63
|
const base = new URL(baseURL);
|
|
63
64
|
const baseOrigin = base.origin;
|
|
64
65
|
const needsEnclaveHeader = !!enclaveURL && new URL(enclaveURL).origin !== baseOrigin;
|
|
@@ -87,7 +88,10 @@ export function createEncryptedBodyFetch(baseURL, hpkePublicKey, enclaveURL) {
|
|
|
87
88
|
if (needsEnclaveHeader) {
|
|
88
89
|
headers.set(ENCLAVE_URL_HEADER, enclaveURL);
|
|
89
90
|
}
|
|
90
|
-
|
|
91
|
+
// The prompt-cache scoping field is added here — inside the origin
|
|
92
|
+
// guard and before the EHBP transport seals the body — so it is
|
|
93
|
+
// encrypted with the rest of the request.
|
|
94
|
+
const initWithHeader = await injectUserCacheSecretIntoRequestInit({ ...normalized.init, headers }, targetUrl.pathname, userCacheSecret);
|
|
91
95
|
const transportInstance = await getOrCreateTransport();
|
|
92
96
|
return encryptedBodyRequest(targetUrl.toString(), hpkePublicKey, initWithHeader, transportInstance);
|
|
93
97
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encrypted-body-fetch.js","sourceRoot":"","sources":["../src/encrypted-body-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAA6B,MAAM,MAAM,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"encrypted-body-fetch.js","sourceRoot":"","sources":["../src/encrypted-body-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAA6B,MAAM,MAAM,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,oCAAoC,EAAE,MAAM,wBAAwB,CAAC;AAG9E,OAAO,EAAE,wBAAwB,EAAE,MAAM,MAAM,CAAC;AAOhD;;;GAGG;AACH,KAAK,UAAU,8BAA8B,CAAC,YAAoB;IAChE,OAAO,QAAQ,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,UAAkB;IACxD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAExD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAEjD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,UAAU,CAAC,sDAAsD,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAChG,CAAC;IAED,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACzD,IAAI,WAAW,KAAK,QAAQ,CAAC,eAAe,EAAE,CAAC;QAC7C,MAAM,IAAI,UAAU,CAAC,mEAAmE,QAAQ,CAAC,eAAe,WAAW,WAAW,GAAG,CAAC,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tB,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;YACxF,CAAC;YACD,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC;YACzC,OAAO,SAAS,CAAC,uBAAuB,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,+BAA+B,CAAC,MAAc,EAAE,SAAiB;IAC9E,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC1D,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;IACzC,OAAO,IAAI,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;AACpD,CAAC;AAED,KAAK,UAAU,qBAAqB,CAAC,MAAc,EAAE,gBAAwB;IAC3E,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/secure-client.d.ts
CHANGED
|
@@ -40,6 +40,21 @@ export interface SecureClientOptions {
|
|
|
40
40
|
transport?: TransportMode;
|
|
41
41
|
/** URL to fetch the attestation bundle from. */
|
|
42
42
|
attestationBundleURL?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Secret scoping the router's prompt cache for this client's requests.
|
|
45
|
+
* Requests carrying the same secret share cached prompt prefixes; requests
|
|
46
|
+
* carrying different secrets cannot observe each other's cache timing. The
|
|
47
|
+
* router consumes the secret to derive the cache namespace and strips it —
|
|
48
|
+
* it never reaches the model.
|
|
49
|
+
*
|
|
50
|
+
* Defaults to the TINFOIL_USER_CACHE_SECRET environment variable when set,
|
|
51
|
+
* otherwise to a generated secret persisted at `~/.tinfoil/user_cache_secret`
|
|
52
|
+
* (shared with the other Tinfoil SDKs on the same machine). Pass an empty
|
|
53
|
+
* string to disable prompt-cache scoping entirely (tenant-wide caching).
|
|
54
|
+
* A `user_cache_secret` field already present in a request body always
|
|
55
|
+
* wins over this option.
|
|
56
|
+
*/
|
|
57
|
+
userCacheSecret?: string;
|
|
43
58
|
}
|
|
44
59
|
/**
|
|
45
60
|
* Low-level secure client providing a verified fetch function for custom HTTP requests.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secure-client.d.ts","sourceRoot":"","sources":["../src/secure-client.ts"],"names":[],"mappings":"AACA,OAAO,EAA8D,KAAK,oBAAoB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"secure-client.d.ts","sourceRoot":"","sources":["../src/secure-client.ts"],"names":[],"mappings":"AACA,OAAO,EAA8D,KAAK,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAMtH,OAAO,KAAK,EAAmB,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,KAAK,KAAK,EAAE,MAAM,IAAI,CAAC;AAG9B,YAAY,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAK7D;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,KAAK,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,0FAA0F;IAC1F,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B,gDAAgD;IAChD,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;;;;;;;;;;;;OAaG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAwBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,YAAY;IAEvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAOrB;IAGF,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,oBAAoB,CAAuB;IACnD,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,kBAAkB,CAAC,CAAS;IACpC,OAAO,CAAC,eAAe,CAAC,CAAS;IACjC,OAAO,CAAC,+BAA+B,CAAC,CAAS;gBAErC,OAAO,GAAE,mBAAwB;IAwC7C;;;;;;;OAOG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBnC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAQzB;;;;;;;;;;;;;;;;;;;OAmBG;IACI,KAAK,IAAI,IAAI;YAKN,gBAAgB;IAqC9B;;;;;OAKG;IACI,uBAAuB,IAAI,oBAAoB;IAItD;;;;OAIG;IACI,UAAU,IAAI,MAAM,GAAG,SAAS;IAIvC;;OAEG;IACI,aAAa,IAAI,MAAM,GAAG,SAAS;IAI1C;;OAEG;IACI,iBAAiB,IAAI,MAAM,GAAG,SAAS;YAIhC,eAAe;IAc7B;;;;;;;;;;;;;;;;;;OAkBG;IACH,IAAI,KAAK,IAAI,OAAO,KAAK,CAgBxB;IAED;;;;;;OAMG;IACU,uBAAuB,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAOrE;;;;;;;;OAQG;YACW,0BAA0B;IAexC;;;;;;OAMG;IACU,yBAAyB,IAAI,OAAO,CAAC,EAAE,CAAC,aAAa,CAAC;IAMnE;;;;;;;;;;;;;;;;;;;;;OAqBG;IACU,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,EAAE,CAAC,SAAS,CAAC;CAgCpG"}
|
package/dist/secure-client.js
CHANGED
|
@@ -2,6 +2,7 @@ import { KeyConfigMismatchError } from "ehbp";
|
|
|
2
2
|
import { Verifier, ConfigurationError, FetchError, AttestationError } from "./verifier.js";
|
|
3
3
|
import { TINFOIL_CONFIG } from "./config.js";
|
|
4
4
|
import { createSecureFetch } from "./secure-fetch.js";
|
|
5
|
+
import { resolveUserCacheSecret } from "./user-cache-secret.js";
|
|
5
6
|
import { fetchAttestationBundle } from "./atc.js";
|
|
6
7
|
import { isRealBrowser } from "./env.js";
|
|
7
8
|
/** Delay before retrying init on transient failure (ms). */
|
|
@@ -104,6 +105,7 @@ export class SecureClient {
|
|
|
104
105
|
configRepo: options.configRepo ?? TINFOIL_CONFIG.DEFAULT_ROUTER_REPO,
|
|
105
106
|
transport: options.transport || 'ehbp',
|
|
106
107
|
attestationBundleURL: options.attestationBundleURL,
|
|
108
|
+
userCacheSecret: options.userCacheSecret,
|
|
107
109
|
};
|
|
108
110
|
this.verificationDocument = createPendingVerificationDocument(this.config.configRepo);
|
|
109
111
|
}
|
|
@@ -228,10 +230,15 @@ export class SecureClient {
|
|
|
228
230
|
return this.resolvedEnclaveURL ? `${this.resolvedEnclaveURL}/v1/` : undefined;
|
|
229
231
|
}
|
|
230
232
|
async createTransport(hpkePublicKey, tlsPublicKeyFingerprint) {
|
|
233
|
+
// The prompt-cache scoping secret: the userCacheSecret option wins, then
|
|
234
|
+
// the TINFOIL_USER_CACHE_SECRET environment variable, then the secret
|
|
235
|
+
// persisted at ~/.tinfoil/user_cache_secret (generated on first use).
|
|
236
|
+
// Empty means disabled; resolution never throws.
|
|
237
|
+
const userCacheSecret = await resolveUserCacheSecret(this.config.userCacheSecret);
|
|
231
238
|
if (this.config.transport === 'tls') {
|
|
232
|
-
return await createSecureFetch(this.resolvedBaseURL, undefined, tlsPublicKeyFingerprint, this.resolvedEnclaveURL);
|
|
239
|
+
return await createSecureFetch(this.resolvedBaseURL, undefined, tlsPublicKeyFingerprint, this.resolvedEnclaveURL, userCacheSecret);
|
|
233
240
|
}
|
|
234
|
-
return await createSecureFetch(this.resolvedBaseURL, hpkePublicKey, undefined, this.resolvedEnclaveURL);
|
|
241
|
+
return await createSecureFetch(this.resolvedBaseURL, hpkePublicKey, undefined, this.resolvedEnclaveURL, userCacheSecret);
|
|
235
242
|
}
|
|
236
243
|
/**
|
|
237
244
|
* Secure fetch function that encrypts request bodies end-to-end.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secure-client.js","sourceRoot":"","sources":["../src/secure-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,UAAU,EAAE,gBAAgB,EAA6B,MAAM,eAAe,CAAC;AAEtH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAIlD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzC,4DAA4D;AAC5D,MAAM,mBAAmB,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"secure-client.js","sourceRoot":"","sources":["../src/secure-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,UAAU,EAAE,gBAAgB,EAA6B,MAAM,eAAe,CAAC;AAEtH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAIlD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzC,4DAA4D;AAC5D,MAAM,mBAAmB,GAAG,IAAI,CAAC;AA8DjC,SAAS,iCAAiC,CAAC,UAAkB;IAC3D,OAAO;QACL,UAAU;QACV,WAAW,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CAAC;IAChB,CAAC;CACF"}
|
package/dist/secure-fetch.d.ts
CHANGED
|
@@ -6,7 +6,11 @@ import { type SecureTransport } from "./encrypted-body-fetch.js";
|
|
|
6
6
|
* - In browsers: Only HPKE encryption is supported (requires hpkePublicKey)
|
|
7
7
|
* - In Node.js/Bun: Also supports TLS certificate pinning when configured
|
|
8
8
|
*
|
|
9
|
+
* A non-empty userCacheSecret is injected into eligible request bodies inside
|
|
10
|
+
* the sealing boundary (EHBP body encryption or the pinned TLS connection),
|
|
11
|
+
* so the secret never travels outside the protected channel.
|
|
12
|
+
*
|
|
9
13
|
* The pinned-tls-fetch import is dynamic to keep Node.js-only code out of browser bundles.
|
|
10
14
|
*/
|
|
11
|
-
export declare function createSecureFetch(baseURL: string, hpkePublicKey?: string, tlsPublicKeyFingerprint?: string, enclaveURL?: string): Promise<SecureTransport>;
|
|
15
|
+
export declare function createSecureFetch(baseURL: string, hpkePublicKey?: string, tlsPublicKeyFingerprint?: string, enclaveURL?: string, userCacheSecret?: string): Promise<SecureTransport>;
|
|
12
16
|
//# 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,OAAO,EAA4B,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"secure-fetch.d.ts","sourceRoot":"","sources":["../src/secure-fetch.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAG3F;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,MAAM,EACtB,uBAAuB,CAAC,EAAE,MAAM,EAChC,UAAU,CAAC,EAAE,MAAM,EACnB,eAAe,GAAE,MAAW,GAC3B,OAAO,CAAC,eAAe,CAAC,CA6B1B"}
|
package/dist/secure-fetch.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isRealBrowser } from "./env.js";
|
|
2
2
|
import { ConfigurationError } from "./verifier.js";
|
|
3
3
|
import { createEncryptedBodyFetch } from "./encrypted-body-fetch.js";
|
|
4
|
+
import { withUserCacheSecret } from "./user-cache-secret.js";
|
|
4
5
|
/**
|
|
5
6
|
* Creates a secure fetch function with either HPKE encryption or TLS pinning.
|
|
6
7
|
*
|
|
@@ -8,11 +9,15 @@ import { createEncryptedBodyFetch } from "./encrypted-body-fetch.js";
|
|
|
8
9
|
* - In browsers: Only HPKE encryption is supported (requires hpkePublicKey)
|
|
9
10
|
* - In Node.js/Bun: Also supports TLS certificate pinning when configured
|
|
10
11
|
*
|
|
12
|
+
* A non-empty userCacheSecret is injected into eligible request bodies inside
|
|
13
|
+
* the sealing boundary (EHBP body encryption or the pinned TLS connection),
|
|
14
|
+
* so the secret never travels outside the protected channel.
|
|
15
|
+
*
|
|
11
16
|
* The pinned-tls-fetch import is dynamic to keep Node.js-only code out of browser bundles.
|
|
12
17
|
*/
|
|
13
|
-
export async function createSecureFetch(baseURL, hpkePublicKey, tlsPublicKeyFingerprint, enclaveURL) {
|
|
18
|
+
export async function createSecureFetch(baseURL, hpkePublicKey, tlsPublicKeyFingerprint, enclaveURL, userCacheSecret = "") {
|
|
14
19
|
if (hpkePublicKey) {
|
|
15
|
-
return createEncryptedBodyFetch(baseURL, hpkePublicKey, enclaveURL);
|
|
20
|
+
return createEncryptedBodyFetch(baseURL, hpkePublicKey, enclaveURL, userCacheSecret);
|
|
16
21
|
}
|
|
17
22
|
if (isRealBrowser()) {
|
|
18
23
|
throw new ConfigurationError("HPKE public key not available and TLS-only verification is not supported in browsers. " +
|
|
@@ -25,7 +30,9 @@ export async function createSecureFetch(baseURL, hpkePublicKey, tlsPublicKeyFing
|
|
|
25
30
|
const { createPinnedTlsFetch } = await import("./pinned-tls-fetch.js");
|
|
26
31
|
const pinnedFetch = await createPinnedTlsFetch(baseURL, tlsPublicKeyFingerprint);
|
|
27
32
|
return {
|
|
28
|
-
fetch
|
|
33
|
+
// The cache-secret layer wraps the pinned fetch, so the field it injects
|
|
34
|
+
// only ever travels over the connection pinned to the attested key.
|
|
35
|
+
fetch: withUserCacheSecret(pinnedFetch, baseURL, userCacheSecret),
|
|
29
36
|
async getSessionRecoveryToken() {
|
|
30
37
|
throw new Error('Session recovery tokens are only available in EHBP transport mode');
|
|
31
38
|
},
|
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;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAwB,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"secure-fetch.js","sourceRoot":"","sources":["../src/secure-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAwB,MAAM,2BAA2B,CAAC;AAC3F,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAe,EACf,aAAsB,EACtB,uBAAgC,EAChC,UAAmB,EACnB,kBAA0B,EAAE;IAE5B,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,wBAAwB,CAAC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC;IACvF,CAAC;IAED,IAAI,aAAa,EAAE,EAAE,CAAC;QACpB,MAAM,IAAI,kBAAkB,CAC1B,wFAAwF;YACxF,iEAAiE,CAClE,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC7B,MAAM,IAAI,kBAAkB,CAC1B,mFAAmF,CACpF,CAAC;IACJ,CAAC;IAED,6EAA6E;IAC7E,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC;IACvE,MAAM,WAAW,GAAG,MAAM,oBAAoB,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;IACjF,OAAO;QACL,yEAAyE;QACzE,oEAAoE;QACpE,KAAK,EAAE,mBAAmB,CAAC,WAAW,EAAE,OAAO,EAAE,eAAe,CAAC;QACjE,KAAK,CAAC,uBAAuB;YAC3B,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;QACvF,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/tinfoil-ai.d.ts
CHANGED
|
@@ -53,6 +53,15 @@ export interface TinfoilAIOptions {
|
|
|
53
53
|
transport?: TransportMode;
|
|
54
54
|
/** URL to fetch the attestation bundle from. */
|
|
55
55
|
attestationBundleURL?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Secret scoping the router's prompt cache for this client's requests
|
|
58
|
+
* (e.g. one stable value per end user). Defaults to the
|
|
59
|
+
* TINFOIL_USER_CACHE_SECRET environment variable, otherwise to a generated
|
|
60
|
+
* secret persisted at `~/.tinfoil/user_cache_secret`. Pass an empty string
|
|
61
|
+
* to disable prompt-cache scoping (tenant-wide caching). A
|
|
62
|
+
* `user_cache_secret` field set in a request body always wins.
|
|
63
|
+
*/
|
|
64
|
+
userCacheSecret?: string;
|
|
56
65
|
/** Additional OpenAI client options (passed through to underlying client) */
|
|
57
66
|
[key: string]: any;
|
|
58
67
|
}
|
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,C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AAO,gBAAgB,CACrB,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CACxD,CAAC;IACJ,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"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser build of the user-cache-secret store. Browsers have no filesystem
|
|
3
|
+
* to persist the secret in, so resolution always falls back to the
|
|
4
|
+
* process-lifetime in-memory secret.
|
|
5
|
+
*/
|
|
6
|
+
export declare function loadOrPersistUserCacheSecret(_generateSecret: () => string): string | null;
|
|
7
|
+
//# sourceMappingURL=user-cache-secret-store.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-cache-secret-store.browser.d.ts","sourceRoot":"","sources":["../src/user-cache-secret-store.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,wBAAgB,4BAA4B,CAAC,eAAe,EAAE,MAAM,MAAM,GAAG,MAAM,GAAG,IAAI,CAEzF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser build of the user-cache-secret store. Browsers have no filesystem
|
|
3
|
+
* to persist the secret in, so resolution always falls back to the
|
|
4
|
+
* process-lifetime in-memory secret.
|
|
5
|
+
*/
|
|
6
|
+
export function loadOrPersistUserCacheSecret(_generateSecret) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=user-cache-secret-store.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-cache-secret-store.browser.js","sourceRoot":"","sources":["../src/user-cache-secret-store.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,UAAU,4BAA4B,CAAC,eAA6B;IACxE,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js persistence for the user cache secret. The other Tinfoil SDKs use
|
|
3
|
+
* the same file, so one machine gets one cache namespace across tools. The
|
|
4
|
+
* browser build swaps this module for a stub (see package.json's `browser`
|
|
5
|
+
* field) — browsers have no filesystem, so resolution falls back to the
|
|
6
|
+
* process-lifetime in-memory secret.
|
|
7
|
+
*/
|
|
8
|
+
/** Directory under the home directory holding the secret file (mode 0700). */
|
|
9
|
+
export declare const USER_CACHE_SECRET_DIR_NAME = ".tinfoil";
|
|
10
|
+
/** Secret file name under the directory (mode 0600). */
|
|
11
|
+
export declare const USER_CACHE_SECRET_FILE_NAME = "user_cache_secret";
|
|
12
|
+
/**
|
|
13
|
+
* Returns the secret persisted under the user's home directory, generating
|
|
14
|
+
* (via `generateSecret`) and persisting one on first use. Returns null when
|
|
15
|
+
* the home directory is unavailable or unwritable — the caller falls back to
|
|
16
|
+
* a process-lifetime in-memory secret. Never throws.
|
|
17
|
+
*/
|
|
18
|
+
export declare function loadOrPersistUserCacheSecret(generateSecret: () => string): string | null;
|
|
19
|
+
//# sourceMappingURL=user-cache-secret-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-cache-secret-store.d.ts","sourceRoot":"","sources":["../src/user-cache-secret-store.ts"],"names":[],"mappings":"AAgBA;;;;;;GAMG;AAEH,8EAA8E;AAC9E,eAAO,MAAM,0BAA0B,aAAa,CAAC;AAErD,wDAAwD;AACxD,eAAO,MAAM,2BAA2B,sBAAsB,CAAC;AAiE/D;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,cAAc,EAAE,MAAM,MAAM,GAAG,MAAM,GAAG,IAAI,CAgFxF"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { closeSync, constants, fstatSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
/**
|
|
6
|
+
* Node.js persistence for the user cache secret. The other Tinfoil SDKs use
|
|
7
|
+
* the same file, so one machine gets one cache namespace across tools. The
|
|
8
|
+
* browser build swaps this module for a stub (see package.json's `browser`
|
|
9
|
+
* field) — browsers have no filesystem, so resolution falls back to the
|
|
10
|
+
* process-lifetime in-memory secret.
|
|
11
|
+
*/
|
|
12
|
+
/** Directory under the home directory holding the secret file (mode 0700). */
|
|
13
|
+
export const USER_CACHE_SECRET_DIR_NAME = ".tinfoil";
|
|
14
|
+
/** Secret file name under the directory (mode 0600). */
|
|
15
|
+
export const USER_CACHE_SECRET_FILE_NAME = "user_cache_secret";
|
|
16
|
+
const HAS_POSIX_PERMISSIONS = process.platform !== "win32";
|
|
17
|
+
function posixReadFlags() {
|
|
18
|
+
return constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK;
|
|
19
|
+
}
|
|
20
|
+
function trimPersistenceWhitespace(value) {
|
|
21
|
+
return value.replace(/^\p{White_Space}+|\p{White_Space}+$/gu, "");
|
|
22
|
+
}
|
|
23
|
+
function isExpectedWindowsPath(path, expectedType) {
|
|
24
|
+
try {
|
|
25
|
+
const stats = lstatSync(path);
|
|
26
|
+
if (stats.isSymbolicLink()) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return expectedType === "directory" ? stats.isDirectory() : stats.isFile();
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
return err?.code === "ENOENT" ? undefined : false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Reads the secret file, distinguishing a missing file from unusable state. */
|
|
36
|
+
function readSecretFile(path) {
|
|
37
|
+
let fd;
|
|
38
|
+
try {
|
|
39
|
+
if (!HAS_POSIX_PERMISSIONS) {
|
|
40
|
+
const pathState = isExpectedWindowsPath(path, "file");
|
|
41
|
+
if (pathState !== true) {
|
|
42
|
+
return pathState === undefined ? undefined : null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
fd = openSync(path, HAS_POSIX_PERMISSIONS ? posixReadFlags() : "r");
|
|
46
|
+
if (HAS_POSIX_PERMISSIONS) {
|
|
47
|
+
if (!fstatSync(fd).isFile()) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
let secret;
|
|
52
|
+
try {
|
|
53
|
+
secret = trimPersistenceWhitespace(new TextDecoder("utf-8", { fatal: true }).decode(readFileSync(fd)));
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return secret === "" ? null : secret;
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
return err?.code === "ENOENT" ? undefined : null;
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
if (fd !== undefined) {
|
|
65
|
+
try {
|
|
66
|
+
closeSync(fd);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Best-effort cleanup after the read has completed.
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Returns the secret persisted under the user's home directory, generating
|
|
76
|
+
* (via `generateSecret`) and persisting one on first use. Returns null when
|
|
77
|
+
* the home directory is unavailable or unwritable — the caller falls back to
|
|
78
|
+
* a process-lifetime in-memory secret. Never throws.
|
|
79
|
+
*/
|
|
80
|
+
export function loadOrPersistUserCacheSecret(generateSecret) {
|
|
81
|
+
let home;
|
|
82
|
+
try {
|
|
83
|
+
home = homedir();
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
if (!home) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
const dir = join(home, USER_CACHE_SECRET_DIR_NAME);
|
|
92
|
+
const path = join(dir, USER_CACHE_SECRET_FILE_NAME);
|
|
93
|
+
try {
|
|
94
|
+
if (!HAS_POSIX_PERMISSIONS && isExpectedWindowsPath(dir, "directory") === false) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
98
|
+
if (HAS_POSIX_PERMISSIONS) {
|
|
99
|
+
let dirFd;
|
|
100
|
+
try {
|
|
101
|
+
dirFd = openSync(dir, posixReadFlags() | constants.O_DIRECTORY);
|
|
102
|
+
if (!fstatSync(dirFd).isDirectory()) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
if (dirFd !== undefined) {
|
|
108
|
+
closeSync(dirFd);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (isExpectedWindowsPath(dir, "directory") !== true) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
const existing = readSecretFile(path);
|
|
120
|
+
if (existing === null) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
if (existing !== undefined) {
|
|
124
|
+
return existing;
|
|
125
|
+
}
|
|
126
|
+
const secret = generateSecret();
|
|
127
|
+
if (secret === "") {
|
|
128
|
+
// CSPRNG failure (the generator already warned): tenant-wide caching,
|
|
129
|
+
// nothing worth persisting.
|
|
130
|
+
return "";
|
|
131
|
+
}
|
|
132
|
+
const candidatePath = join(dir, `${USER_CACHE_SECRET_FILE_NAME}.${process.pid}.${randomUUID()}.tmp`);
|
|
133
|
+
try {
|
|
134
|
+
// A complete temporary file is linked directly to the destination.
|
|
135
|
+
// Hard-link creation is atomic, so concurrent first users either win or
|
|
136
|
+
// adopt the complete destination created by another process.
|
|
137
|
+
writeFileSync(candidatePath, secret, { encoding: "utf8", flag: "wx", mode: 0o600 });
|
|
138
|
+
try {
|
|
139
|
+
linkSync(candidatePath, path);
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
if (err?.code !== "EEXIST") {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const persisted = readSecretFile(path);
|
|
147
|
+
return persisted ?? null;
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
try {
|
|
154
|
+
unlinkSync(candidatePath);
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// Best-effort cleanup: the candidate is never the persisted file.
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=user-cache-secret-store.js.map
|
|
@@ -0,0 +1 @@
|
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;YACH,UAAU,CAAC,aAAa,CAAC,CAAC;QAC5B,CAAC;QAAC,MAAM,CAAC;YACP,kEAAkE;QACpE,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `user_cache_secret` provisions the per-user prompt-cache secret defined by
|
|
3
|
+
* the secure prompt caching contract. The router derives the request's
|
|
4
|
+
* prefix-cache namespace from it: requests carrying the same secret (under
|
|
5
|
+
* the same API identity) share cached prompt prefixes, requests carrying
|
|
6
|
+
* different secrets cannot observe each other's cache timing. The secret
|
|
7
|
+
* itself is stripped by the router and never reaches the model.
|
|
8
|
+
*
|
|
9
|
+
* Resolution order, mirroring the other Tinfoil clients:
|
|
10
|
+
*
|
|
11
|
+
* 1. an explicit per-request `user_cache_secret` field in the body (never
|
|
12
|
+
* overwritten here),
|
|
13
|
+
* 2. the `userCacheSecret` client option,
|
|
14
|
+
* 3. the TINFOIL_USER_CACHE_SECRET environment variable,
|
|
15
|
+
* 4. a generated secret persisted at ~/.tinfoil/user_cache_secret (0600),
|
|
16
|
+
* shared with the other Tinfoil SDKs on the same machine. Runtimes
|
|
17
|
+
* without a filesystem (browsers, edge runtimes) fall back to a
|
|
18
|
+
* process-lifetime in-memory secret.
|
|
19
|
+
*
|
|
20
|
+
* Injection happens inside the secure transport — before the EHBP transport
|
|
21
|
+
* encrypts the body, or on the way into the TLS connection pinned to the
|
|
22
|
+
* attested key — so the secret is only ever visible to the verified enclave.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* The router-only request-body field. A non-empty string scopes the prompt
|
|
26
|
+
* cache to that secret; an absent or empty value leaves the request in the
|
|
27
|
+
* tenant-wide namespace.
|
|
28
|
+
*/
|
|
29
|
+
export declare const USER_CACHE_SECRET_FIELD = "user_cache_secret";
|
|
30
|
+
/**
|
|
31
|
+
* Provisions the secret via the environment. Setting it to an empty string
|
|
32
|
+
* disables generation entirely (tenant-wide caching), which is the right
|
|
33
|
+
* call for pooled multi-user deployments that would otherwise mint a fresh
|
|
34
|
+
* namespace per container.
|
|
35
|
+
*/
|
|
36
|
+
export declare const USER_CACHE_SECRET_ENV = "TINFOIL_USER_CACHE_SECRET";
|
|
37
|
+
/**
|
|
38
|
+
* Resolves the client-level secret: the explicit option wins (an explicit
|
|
39
|
+
* empty string disables provisioning), then the environment, then the
|
|
40
|
+
* persisted (or generated) secret. An empty result means injection is
|
|
41
|
+
* disabled. Never throws.
|
|
42
|
+
*/
|
|
43
|
+
export declare function resolveUserCacheSecret(explicit?: string): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Adds the field to a JSON-object body. Returns null — forward the original
|
|
46
|
+
* body untouched — for non-object bodies, trailing data, or a body that
|
|
47
|
+
* already carries the field (an explicit per-request value, including an
|
|
48
|
+
* explicit empty string, always wins).
|
|
49
|
+
*/
|
|
50
|
+
export declare function injectUserCacheSecret(raw: string, secret: string): string | null;
|
|
51
|
+
/**
|
|
52
|
+
* Injects the client-level secret into an eligible request: a POST with a
|
|
53
|
+
* JSON-object body to one of the supported endpoints. Anything else — other
|
|
54
|
+
* endpoints, non-object bodies, or a body that already carries the field —
|
|
55
|
+
* passes through untouched. Never throws. The caller
|
|
56
|
+
* runs this inside the sealing boundary, so retries and redirects below the
|
|
57
|
+
* transport replay the injected body, not the caller's original.
|
|
58
|
+
*/
|
|
59
|
+
export declare function injectUserCacheSecretIntoRequestInit(init: RequestInit | undefined, pathname: string, secret: string): Promise<RequestInit | undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* Wraps a fetch function so eligible request bodies carry the secret. The
|
|
62
|
+
* wrapper sits directly above the sealing fetch (the TLS connection pinned
|
|
63
|
+
* to the attested key), so the injected field never travels outside the
|
|
64
|
+
* protected channel. An empty secret disables injection entirely.
|
|
65
|
+
*/
|
|
66
|
+
export declare function withUserCacheSecret(inner: typeof fetch, baseURL: string, secret: string): typeof fetch;
|
|
67
|
+
//# sourceMappingURL=user-cache-secret.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-cache-secret.d.ts","sourceRoot":"","sources":["../src/user-cache-secret.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAE3D;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,8BAA8B,CAAC;AAejE;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAW/E;AAgED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAyBhF;AAwCD;;;;;;;GAOG;AACH,wBAAsB,oCAAoC,CACxD,IAAI,EAAE,WAAW,GAAG,SAAS,EAC7B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAuBlC;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,KAAK,EACnB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,KAAK,CAsBd"}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { isRealBrowser } from "./env.js";
|
|
2
|
+
/**
|
|
3
|
+
* `user_cache_secret` provisions the per-user prompt-cache secret defined by
|
|
4
|
+
* the secure prompt caching contract. The router derives the request's
|
|
5
|
+
* prefix-cache namespace from it: requests carrying the same secret (under
|
|
6
|
+
* the same API identity) share cached prompt prefixes, requests carrying
|
|
7
|
+
* different secrets cannot observe each other's cache timing. The secret
|
|
8
|
+
* itself is stripped by the router and never reaches the model.
|
|
9
|
+
*
|
|
10
|
+
* Resolution order, mirroring the other Tinfoil clients:
|
|
11
|
+
*
|
|
12
|
+
* 1. an explicit per-request `user_cache_secret` field in the body (never
|
|
13
|
+
* overwritten here),
|
|
14
|
+
* 2. the `userCacheSecret` client option,
|
|
15
|
+
* 3. the TINFOIL_USER_CACHE_SECRET environment variable,
|
|
16
|
+
* 4. a generated secret persisted at ~/.tinfoil/user_cache_secret (0600),
|
|
17
|
+
* shared with the other Tinfoil SDKs on the same machine. Runtimes
|
|
18
|
+
* without a filesystem (browsers, edge runtimes) fall back to a
|
|
19
|
+
* process-lifetime in-memory secret.
|
|
20
|
+
*
|
|
21
|
+
* Injection happens inside the secure transport — before the EHBP transport
|
|
22
|
+
* encrypts the body, or on the way into the TLS connection pinned to the
|
|
23
|
+
* attested key — so the secret is only ever visible to the verified enclave.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* The router-only request-body field. A non-empty string scopes the prompt
|
|
27
|
+
* cache to that secret; an absent or empty value leaves the request in the
|
|
28
|
+
* tenant-wide namespace.
|
|
29
|
+
*/
|
|
30
|
+
export const USER_CACHE_SECRET_FIELD = "user_cache_secret";
|
|
31
|
+
/**
|
|
32
|
+
* Provisions the secret via the environment. Setting it to an empty string
|
|
33
|
+
* disables generation entirely (tenant-wide caching), which is the right
|
|
34
|
+
* call for pooled multi-user deployments that would otherwise mint a fresh
|
|
35
|
+
* namespace per container.
|
|
36
|
+
*/
|
|
37
|
+
export const USER_CACHE_SECRET_ENV = "TINFOIL_USER_CACHE_SECRET";
|
|
38
|
+
/**
|
|
39
|
+
* The OpenAI-compatible endpoints whose bodies carry the field. Matched by
|
|
40
|
+
* path suffix with no /v1 prefix required, so custom base URLs
|
|
41
|
+
* (path-prefixed proxies or /v1-less roots) still qualify. Other endpoints
|
|
42
|
+
* (embeddings, audio, files) are excluded: their engines do not prefix-cache
|
|
43
|
+
* and may reject unknown fields.
|
|
44
|
+
*/
|
|
45
|
+
const USER_CACHE_SECRET_PATHS = [
|
|
46
|
+
"/chat/completions",
|
|
47
|
+
"/completions",
|
|
48
|
+
"/responses",
|
|
49
|
+
];
|
|
50
|
+
/**
|
|
51
|
+
* Resolves the client-level secret: the explicit option wins (an explicit
|
|
52
|
+
* empty string disables provisioning), then the environment, then the
|
|
53
|
+
* persisted (or generated) secret. An empty result means injection is
|
|
54
|
+
* disabled. Never throws.
|
|
55
|
+
*/
|
|
56
|
+
export async function resolveUserCacheSecret(explicit) {
|
|
57
|
+
if (explicit !== undefined) {
|
|
58
|
+
return explicit;
|
|
59
|
+
}
|
|
60
|
+
// A set-but-empty variable counts as set: it disables generation, which is
|
|
61
|
+
// what pooled multi-user deployments want. Browser bundles have no process.
|
|
62
|
+
const env = typeof process !== "undefined" ? process.env?.[USER_CACHE_SECRET_ENV] : undefined;
|
|
63
|
+
if (env !== undefined) {
|
|
64
|
+
return env;
|
|
65
|
+
}
|
|
66
|
+
return loadOrGenerateUserCacheSecret();
|
|
67
|
+
}
|
|
68
|
+
/** Returns a fresh 256-bit random secret, hex-encoded. */
|
|
69
|
+
function newUserCacheSecret() {
|
|
70
|
+
try {
|
|
71
|
+
const bytes = new Uint8Array(32);
|
|
72
|
+
crypto.getRandomValues(bytes);
|
|
73
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Never fall back to a weak secret: no secret means tenant-wide caching,
|
|
77
|
+
// which is safe.
|
|
78
|
+
console.warn("[tinfoil] could not generate a user cache secret; requests stay in the tenant-wide cache namespace");
|
|
79
|
+
return "";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The process-lifetime fallback for when the secret cannot be persisted. An
|
|
84
|
+
* unpersisted secret still isolates this process's cache namespace, but
|
|
85
|
+
* continuity is lost on restart — like a session ID, it silently resets the
|
|
86
|
+
* namespace every deploy — so the fallback warns once per process.
|
|
87
|
+
*/
|
|
88
|
+
let ephemeralUserCacheSecret;
|
|
89
|
+
function getEphemeralUserCacheSecret() {
|
|
90
|
+
if (ephemeralUserCacheSecret === undefined) {
|
|
91
|
+
ephemeralUserCacheSecret = newUserCacheSecret();
|
|
92
|
+
if (ephemeralUserCacheSecret !== "") {
|
|
93
|
+
console.warn("[tinfoil] could not persist the user cache secret; using an in-memory secret, " +
|
|
94
|
+
"so prompt-cache continuity resets when this process exits " +
|
|
95
|
+
`(set ${USER_CACHE_SECRET_ENV} or the userCacheSecret option to pin one)`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return ephemeralUserCacheSecret;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns the secret persisted under the user's home directory, generating
|
|
102
|
+
* and persisting one on first use. Without a usable filesystem (browsers,
|
|
103
|
+
* edge runtimes, an unwritable home directory) it falls back to the
|
|
104
|
+
* process-lifetime in-memory secret.
|
|
105
|
+
*/
|
|
106
|
+
async function loadOrGenerateUserCacheSecret() {
|
|
107
|
+
if (!isRealBrowser()) {
|
|
108
|
+
try {
|
|
109
|
+
// Dynamic import to keep Node.js fs/os modules out of browser bundles;
|
|
110
|
+
// package.json's browser field maps the store to a stub, the same way
|
|
111
|
+
// pinned-tls-fetch is gated.
|
|
112
|
+
const { loadOrPersistUserCacheSecret } = await import("./user-cache-secret-store.js");
|
|
113
|
+
const secret = loadOrPersistUserCacheSecret(newUserCacheSecret);
|
|
114
|
+
if (secret !== null) {
|
|
115
|
+
return secret;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// No usable filesystem in this runtime: fall through.
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return getEphemeralUserCacheSecret();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Adds the field to a JSON-object body. Returns null — forward the original
|
|
126
|
+
* body untouched — for non-object bodies, trailing data, or a body that
|
|
127
|
+
* already carries the field (an explicit per-request value, including an
|
|
128
|
+
* explicit empty string, always wins).
|
|
129
|
+
*/
|
|
130
|
+
export function injectUserCacheSecret(raw, secret) {
|
|
131
|
+
let parsed;
|
|
132
|
+
try {
|
|
133
|
+
// JSON.parse enforces exactly the framing we need: a single
|
|
134
|
+
// value followed by nothing but whitespace. Trailing data ('{...}}',
|
|
135
|
+
// '{...} garbage') throws, so a body the server would reject is forwarded
|
|
136
|
+
// as-is instead of being quietly rewritten into one it accepts.
|
|
137
|
+
parsed = JSON.parse(raw);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
if (Object.prototype.hasOwnProperty.call(parsed, USER_CACHE_SECRET_FIELD)) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
// Splice the field into the original text instead of re-serializing the
|
|
149
|
+
// parsed object: parsing round-trips numbers through float64, which would
|
|
150
|
+
// corrupt int64-range values such as `"seed": 9007199254740993`. The last
|
|
151
|
+
// '}' is the object's closing brace — only whitespace may follow it.
|
|
152
|
+
const end = raw.lastIndexOf("}");
|
|
153
|
+
const field = `${JSON.stringify(USER_CACHE_SECRET_FIELD)}:${JSON.stringify(secret)}`;
|
|
154
|
+
const separator = Object.keys(parsed).length > 0 ? "," : "";
|
|
155
|
+
return raw.slice(0, end) + separator + field + raw.slice(end);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Decodes supported replayable in-memory bodies. Other representations are
|
|
159
|
+
* forwarded unchanged, so callers using them must provide the field.
|
|
160
|
+
*/
|
|
161
|
+
function bodyText(body) {
|
|
162
|
+
if (typeof body === "string") {
|
|
163
|
+
return body;
|
|
164
|
+
}
|
|
165
|
+
if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) {
|
|
166
|
+
try {
|
|
167
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(body);
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Rewrites a caller-supplied Content-Length header to describe the injected
|
|
177
|
+
* body. Fetch implementations compute the length themselves when the header
|
|
178
|
+
* is absent, so it is only touched when the caller set one.
|
|
179
|
+
*/
|
|
180
|
+
function headersWithUpdatedBodyMetadata(headers, body) {
|
|
181
|
+
if (headers === undefined) {
|
|
182
|
+
return headers;
|
|
183
|
+
}
|
|
184
|
+
const updated = new Headers(headers);
|
|
185
|
+
if (updated.has("content-length")) {
|
|
186
|
+
updated.set("content-length", String(new TextEncoder().encode(body).byteLength));
|
|
187
|
+
return updated;
|
|
188
|
+
}
|
|
189
|
+
return headers;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Injects the client-level secret into an eligible request: a POST with a
|
|
193
|
+
* JSON-object body to one of the supported endpoints. Anything else — other
|
|
194
|
+
* endpoints, non-object bodies, or a body that already carries the field —
|
|
195
|
+
* passes through untouched. Never throws. The caller
|
|
196
|
+
* runs this inside the sealing boundary, so retries and redirects below the
|
|
197
|
+
* transport replay the injected body, not the caller's original.
|
|
198
|
+
*/
|
|
199
|
+
export async function injectUserCacheSecretIntoRequestInit(init, pathname, secret) {
|
|
200
|
+
if (secret === "" || init === undefined) {
|
|
201
|
+
return init;
|
|
202
|
+
}
|
|
203
|
+
if ((init.method ?? "GET").toUpperCase() !== "POST") {
|
|
204
|
+
return init;
|
|
205
|
+
}
|
|
206
|
+
if (!USER_CACHE_SECRET_PATHS.some((path) => pathname.endsWith(path))) {
|
|
207
|
+
return init;
|
|
208
|
+
}
|
|
209
|
+
const raw = bodyText(init.body);
|
|
210
|
+
if (raw === null || raw === "") {
|
|
211
|
+
return init;
|
|
212
|
+
}
|
|
213
|
+
const injected = injectUserCacheSecret(raw, secret);
|
|
214
|
+
if (injected === null) {
|
|
215
|
+
return init;
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
...init,
|
|
219
|
+
body: injected,
|
|
220
|
+
headers: headersWithUpdatedBodyMetadata(init.headers, injected),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Wraps a fetch function so eligible request bodies carry the secret. The
|
|
225
|
+
* wrapper sits directly above the sealing fetch (the TLS connection pinned
|
|
226
|
+
* to the attested key), so the injected field never travels outside the
|
|
227
|
+
* protected channel. An empty secret disables injection entirely.
|
|
228
|
+
*/
|
|
229
|
+
export function withUserCacheSecret(inner, baseURL, secret) {
|
|
230
|
+
if (secret === "") {
|
|
231
|
+
return inner;
|
|
232
|
+
}
|
|
233
|
+
return (async (input, init) => {
|
|
234
|
+
let pathname;
|
|
235
|
+
try {
|
|
236
|
+
pathname = requestPathname(input, baseURL);
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
// An unresolvable URL is the inner fetch's error to raise.
|
|
240
|
+
return inner(input, init);
|
|
241
|
+
}
|
|
242
|
+
const normalized = input instanceof Request && init?.body !== undefined
|
|
243
|
+
? { method: input.method, headers: input.headers, ...init }
|
|
244
|
+
: init;
|
|
245
|
+
const injected = await injectUserCacheSecretIntoRequestInit(normalized, pathname, secret);
|
|
246
|
+
return inner(input, injected);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
/** Resolves the request path the same way the pinned TLS fetch does. */
|
|
250
|
+
function requestPathname(input, baseURL) {
|
|
251
|
+
if (typeof input === "string") {
|
|
252
|
+
return new URL(input, baseURL).pathname;
|
|
253
|
+
}
|
|
254
|
+
if (input instanceof URL) {
|
|
255
|
+
return input.pathname;
|
|
256
|
+
}
|
|
257
|
+
return new URL(input.url, baseURL).pathname;
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=user-cache-secret.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-cache-secret.js","sourceRoot":"","sources":["../src/user-cache-secret.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAA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3D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinfoil",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Tinfoil secure OpenAI client wrapper",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"./dist/pinned-tls-fetch.js": "./dist/pinned-tls-fetch.browser.js",
|
|
12
12
|
"./dist/pinned-ws.js": "./dist/pinned-ws.browser.js",
|
|
13
13
|
"./dist/realtime.js": "./dist/realtime.browser.js",
|
|
14
|
-
"./dist/unsafe.js": "./dist/unsafe.browser.js"
|
|
14
|
+
"./dist/unsafe.js": "./dist/unsafe.browser.js",
|
|
15
|
+
"./dist/user-cache-secret-store.js": "./dist/user-cache-secret-store.browser.js"
|
|
15
16
|
},
|
|
16
17
|
"exports": {
|
|
17
18
|
".": {
|
|
@@ -42,7 +43,6 @@
|
|
|
42
43
|
},
|
|
43
44
|
"files": [
|
|
44
45
|
"dist",
|
|
45
|
-
"README.md",
|
|
46
46
|
"LICENSE"
|
|
47
47
|
],
|
|
48
48
|
"repository": {
|
|
@@ -56,14 +56,14 @@
|
|
|
56
56
|
"tinfoil"
|
|
57
57
|
],
|
|
58
58
|
"author": "Tinfoil",
|
|
59
|
-
"license": "
|
|
59
|
+
"license": "Apache-2.0",
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=20"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@ai-sdk/openai-compatible": "^2.0.41",
|
|
65
65
|
"@freedomofpress/sigstore-browser": "^0.1.13",
|
|
66
|
-
"@tinfoilsh/verifier": "1.1.
|
|
66
|
+
"@tinfoilsh/verifier": "1.1.9",
|
|
67
67
|
"@types/ws": "^8.18.1",
|
|
68
68
|
"ehbp": "^0.2.0",
|
|
69
69
|
"openai": "^6.34.0",
|