@zeke-02/tinfoil 0.0.10 → 0.11.7

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.
Files changed (105) hide show
  1. package/dist/ai-sdk-provider.browser.d.ts +12 -0
  2. package/dist/ai-sdk-provider.browser.d.ts.map +1 -0
  3. package/dist/{esm/ai-sdk-provider.mjs → ai-sdk-provider.browser.js} +9 -5
  4. package/dist/ai-sdk-provider.browser.js.map +1 -0
  5. package/dist/ai-sdk-provider.d.ts +6 -1
  6. package/dist/ai-sdk-provider.d.ts.map +1 -0
  7. package/dist/ai-sdk-provider.js +12 -11
  8. package/dist/ai-sdk-provider.js.map +1 -0
  9. package/dist/config.d.ts +2 -1
  10. package/dist/config.d.ts.map +1 -0
  11. package/dist/config.js +3 -5
  12. package/dist/config.js.map +1 -0
  13. package/dist/encrypted-body-fetch.d.ts +13 -3
  14. package/dist/encrypted-body-fetch.d.ts.map +1 -0
  15. package/dist/encrypted-body-fetch.js +32 -27
  16. package/dist/encrypted-body-fetch.js.map +1 -0
  17. package/dist/env.d.ts +1 -0
  18. package/dist/env.d.ts.map +1 -0
  19. package/dist/env.js +2 -4
  20. package/dist/env.js.map +1 -0
  21. package/dist/index.browser.d.ts +8 -7
  22. package/dist/index.browser.d.ts.map +1 -0
  23. package/dist/index.browser.js +8 -28
  24. package/dist/index.browser.js.map +1 -0
  25. package/dist/index.d.ts +9 -8
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +10 -47
  28. package/dist/index.js.map +1 -0
  29. package/dist/pinned-tls-fetch.d.ts +1 -0
  30. package/dist/pinned-tls-fetch.d.ts.map +1 -0
  31. package/dist/pinned-tls-fetch.js +13 -17
  32. package/dist/pinned-tls-fetch.js.map +1 -0
  33. package/dist/router.d.ts +1 -0
  34. package/dist/router.d.ts.map +1 -0
  35. package/dist/router.js +6 -7
  36. package/dist/router.js.map +1 -0
  37. package/dist/{esm/secure-client.d.ts → secure-client.browser.d.ts} +2 -1
  38. package/dist/secure-client.browser.d.ts.map +1 -0
  39. package/dist/{esm/secure-client.mjs → secure-client.browser.js} +46 -56
  40. package/dist/secure-client.browser.js.map +1 -0
  41. package/dist/secure-client.d.ts +2 -1
  42. package/dist/secure-client.d.ts.map +1 -0
  43. package/dist/secure-client.js +51 -65
  44. package/dist/secure-client.js.map +1 -0
  45. package/dist/secure-fetch.browser.d.ts +1 -0
  46. package/dist/secure-fetch.browser.d.ts.map +1 -0
  47. package/dist/secure-fetch.browser.js +4 -6
  48. package/dist/secure-fetch.browser.js.map +1 -0
  49. package/dist/secure-fetch.d.ts +1 -0
  50. package/dist/secure-fetch.d.ts.map +1 -0
  51. package/dist/secure-fetch.js +16 -8
  52. package/dist/secure-fetch.js.map +1 -0
  53. package/dist/{tinfoilai.d.ts → tinfoil-ai.browser.d.ts} +5 -2
  54. package/dist/tinfoil-ai.browser.d.ts.map +1 -0
  55. package/dist/{tinfoilai.js → tinfoil-ai.browser.js} +50 -39
  56. package/dist/tinfoil-ai.browser.js.map +1 -0
  57. package/dist/{esm/tinfoilai.d.ts → tinfoil-ai.d.ts} +5 -2
  58. package/dist/tinfoil-ai.d.ts.map +1 -0
  59. package/dist/{esm/tinfoilai.mjs → tinfoil-ai.js} +29 -11
  60. package/dist/tinfoil-ai.js.map +1 -0
  61. package/dist/unverified-client.d.ts +1 -2
  62. package/dist/unverified-client.d.ts.map +1 -0
  63. package/dist/unverified-client.js +10 -13
  64. package/dist/unverified-client.js.map +1 -0
  65. package/dist/verifier.d.ts +2 -141
  66. package/dist/verifier.d.ts.map +1 -0
  67. package/dist/verifier.js +2 -570
  68. package/dist/verifier.js.map +1 -0
  69. package/package.json +48 -41
  70. package/LICENSE +0 -661
  71. package/README.md +0 -183
  72. package/dist/__tests__/test-utils.d.ts +0 -1
  73. package/dist/__tests__/test-utils.js +0 -44
  74. package/dist/esm/__tests__/test-utils.d.ts +0 -1
  75. package/dist/esm/__tests__/test-utils.mjs +0 -38
  76. package/dist/esm/ai-sdk-provider.d.ts +0 -7
  77. package/dist/esm/config.d.ts +0 -13
  78. package/dist/esm/config.mjs +0 -13
  79. package/dist/esm/encrypted-body-fetch.d.ts +0 -9
  80. package/dist/esm/encrypted-body-fetch.mjs +0 -101
  81. package/dist/esm/env.d.ts +0 -5
  82. package/dist/esm/env.mjs +0 -17
  83. package/dist/esm/fetch-adapter.d.ts +0 -21
  84. package/dist/esm/fetch-adapter.mjs +0 -23
  85. package/dist/esm/index.browser.d.ts +0 -7
  86. package/dist/esm/index.browser.mjs +0 -8
  87. package/dist/esm/index.d.ts +0 -9
  88. package/dist/esm/index.mjs +0 -13
  89. package/dist/esm/pinned-tls-fetch.d.ts +0 -1
  90. package/dist/esm/pinned-tls-fetch.mjs +0 -110
  91. package/dist/esm/router.d.ts +0 -11
  92. package/dist/esm/router.mjs +0 -33
  93. package/dist/esm/secure-fetch.browser.d.ts +0 -1
  94. package/dist/esm/secure-fetch.browser.mjs +0 -10
  95. package/dist/esm/secure-fetch.d.ts +0 -1
  96. package/dist/esm/secure-fetch.mjs +0 -12
  97. package/dist/esm/unverified-client.d.ts +0 -18
  98. package/dist/esm/unverified-client.mjs +0 -61
  99. package/dist/esm/verifier.d.ts +0 -141
  100. package/dist/esm/verifier.mjs +0 -532
  101. package/dist/esm/wasm-exec.js +0 -668
  102. package/dist/esm/wasm-exec.mjs +0 -668
  103. package/dist/fetch-adapter.d.ts +0 -21
  104. package/dist/fetch-adapter.js +0 -27
  105. package/dist/wasm-exec.js +0 -668
@@ -1,33 +0,0 @@
1
- import { TINFOIL_CONFIG } from "./config.mjs";
2
- /**
3
- * Router utilities for fetching available Tinfoil routers
4
- */
5
- /**
6
- * Fetches the list of available routers from the ATC API
7
- * and returns a randomly selected address.
8
- *
9
- * @returns Promise<string> A randomly selected router address
10
- * @throws Error if no routers are found or if the request fails
11
- */
12
- export async function fetchRouter() {
13
- const routersUrl = TINFOIL_CONFIG.ATC_API_URL;
14
- try {
15
- const response = await fetch(routersUrl);
16
- if (!response.ok) {
17
- throw new Error(`Failed to fetch routers: ${response.status} ${response.statusText}`);
18
- }
19
- const routers = await response.json();
20
- if (!Array.isArray(routers) || routers.length === 0) {
21
- throw new Error("No routers found in the response");
22
- }
23
- // Return a randomly selected router
24
- const randomIndex = Math.floor(Math.random() * routers.length);
25
- return routers[randomIndex];
26
- }
27
- catch (error) {
28
- if (error instanceof Error) {
29
- throw new Error(`Failed to fetch router: ${error.message}`);
30
- }
31
- throw new Error("Failed to fetch router: Unknown error");
32
- }
33
- }
@@ -1 +0,0 @@
1
- export declare function createSecureFetch(baseURL: string, enclaveURL?: string, hpkePublicKey?: string, tlsPublicKeyFingerprint?: string): typeof fetch;
@@ -1,10 +0,0 @@
1
- import { createEncryptedBodyFetch } from "./encrypted-body-fetch.mjs";
2
- export function createSecureFetch(baseURL, enclaveURL, hpkePublicKey, tlsPublicKeyFingerprint) {
3
- if (hpkePublicKey) {
4
- return createEncryptedBodyFetch(baseURL, hpkePublicKey, enclaveURL);
5
- }
6
- else {
7
- throw new Error("HPKE public key not available and TLS-only verification is not supported in browsers. " +
8
- "Only HPKE-enabled enclaves can be used in browser environments.");
9
- }
10
- }
@@ -1 +0,0 @@
1
- export declare function createSecureFetch(baseURL: string, enclaveURL?: string, hpkePublicKey?: string, tlsPublicKeyFingerprint?: string): typeof fetch;
@@ -1,12 +0,0 @@
1
- import { createEncryptedBodyFetch } from "./encrypted-body-fetch.mjs";
2
- export function createSecureFetch(baseURL, enclaveURL, hpkePublicKey, tlsPublicKeyFingerprint) {
3
- let fetchFunction;
4
- if (hpkePublicKey) {
5
- fetchFunction = createEncryptedBodyFetch(baseURL, hpkePublicKey, enclaveURL);
6
- }
7
- else {
8
- throw new Error("HPKE public key not available and TLS-only verification is not supported in browsers. " +
9
- "Only HPKE-enabled enclaves can be used in browser environments.");
10
- }
11
- return fetchFunction;
12
- }
@@ -1,18 +0,0 @@
1
- interface UnverifiedClientOptions {
2
- baseURL?: string;
3
- enclaveURL?: string;
4
- configRepo?: string;
5
- }
6
- export declare class UnverifiedClient {
7
- private initPromise;
8
- private _fetch;
9
- private baseURL?;
10
- private enclaveURL?;
11
- private readonly configRepo;
12
- constructor(options?: UnverifiedClientOptions);
13
- ready(): Promise<void>;
14
- private initUnverifiedClient;
15
- getVerificationDocument(): Promise<void>;
16
- get fetch(): typeof fetch;
17
- }
18
- export {};
@@ -1,61 +0,0 @@
1
- import { TINFOIL_CONFIG } from "./config.mjs";
2
- import { createEncryptedBodyFetch } from "./encrypted-body-fetch.mjs";
3
- import { fetchRouter } from "./router.mjs";
4
- export class UnverifiedClient {
5
- constructor(options = {}) {
6
- this.initPromise = null;
7
- this._fetch = null;
8
- this.baseURL = options.baseURL;
9
- this.enclaveURL = options.enclaveURL;
10
- this.configRepo = options.configRepo || TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
11
- }
12
- async ready() {
13
- if (!this.initPromise) {
14
- this.initPromise = this.initUnverifiedClient();
15
- }
16
- return this.initPromise;
17
- }
18
- async initUnverifiedClient() {
19
- // Only fetch router if neither baseURL nor enclaveURL is provided
20
- if (!this.baseURL && !this.enclaveURL) {
21
- const routerAddress = await fetchRouter();
22
- this.enclaveURL = `https://${routerAddress}`;
23
- this.baseURL = `https://${routerAddress}/v1/`;
24
- }
25
- // Ensure both baseURL and enclaveURL are initialized
26
- if (!this.baseURL) {
27
- if (this.enclaveURL) {
28
- // If enclaveURL is provided but baseURL is not, derive baseURL from enclaveURL
29
- const enclaveUrl = new URL(this.enclaveURL);
30
- this.baseURL = `${enclaveUrl.origin}/v1/`;
31
- }
32
- else {
33
- throw new Error("Unable to determine baseURL: neither baseURL nor enclaveURL provided");
34
- }
35
- }
36
- if (!this.enclaveURL) {
37
- if (this.baseURL) {
38
- // If baseURL is provided but enclaveURL is not, derive enclaveURL from baseURL
39
- const baseUrl = new URL(this.baseURL);
40
- this.enclaveURL = baseUrl.origin;
41
- }
42
- else {
43
- throw new Error("Unable to determine enclaveURL: neither baseURL nor enclaveURL provided");
44
- }
45
- }
46
- this._fetch = createEncryptedBodyFetch(this.baseURL, undefined, this.enclaveURL);
47
- }
48
- async getVerificationDocument() {
49
- if (!this.initPromise) {
50
- await this.ready();
51
- }
52
- await this.initPromise;
53
- throw new Error("Verification document unavailable: this version of the client is unverified");
54
- }
55
- get fetch() {
56
- return async (input, init) => {
57
- await this.ready();
58
- return this._fetch(input, init);
59
- };
60
- }
61
- }
@@ -1,141 +0,0 @@
1
- /**
2
- * Attestation measurement containing platform type and register values
3
- */
4
- export interface AttestationMeasurement {
5
- type: string;
6
- registers: string[];
7
- }
8
- /**
9
- * Hardware measurement from TDX platform verification
10
- */
11
- export interface HardwareMeasurement {
12
- ID: string;
13
- MRTD: string;
14
- RTMR0: string;
15
- }
16
- /**
17
- * Attestation response containing cryptographic keys and measurements
18
- * At least one of tlsPublicKeyFingerprint or hpkePublicKey must be present
19
- */
20
- export interface AttestationResponse {
21
- tlsPublicKeyFingerprint?: string;
22
- hpkePublicKey?: string;
23
- measurement: AttestationMeasurement;
24
- }
25
- /**
26
- * State of an intermediate verification step
27
- */
28
- export interface VerificationStepState {
29
- status: "pending" | "success" | "failed";
30
- error?: string;
31
- }
32
- /**
33
- * Full verification document produced by a verify() call
34
- * Includes state tracking for all intermediate steps
35
- */
36
- export interface VerificationDocument {
37
- configRepo: string;
38
- enclaveHost: string;
39
- releaseDigest: string;
40
- codeMeasurement: AttestationMeasurement;
41
- enclaveMeasurement: AttestationResponse;
42
- tlsPublicKey: string;
43
- hpkePublicKey: string;
44
- hardwareMeasurement?: HardwareMeasurement;
45
- codeFingerprint: string;
46
- enclaveFingerprint: string;
47
- selectedRouterEndpoint: string;
48
- securityVerified: boolean;
49
- steps: {
50
- fetchDigest: VerificationStepState;
51
- verifyCode: VerificationStepState;
52
- verifyEnclave: VerificationStepState;
53
- compareMeasurements: VerificationStepState;
54
- createTransport?: VerificationStepState;
55
- verifyHPKEKey?: VerificationStepState;
56
- otherError?: VerificationStepState;
57
- };
58
- }
59
- /**
60
- * Verifier performs attestation verification for Tinfoil enclaves
61
- *
62
- * The verifier loads a WebAssembly module (compiled from Go) that performs
63
- * end-to-end attestation verification:
64
- * 1. Fetches the latest code release digest from GitHub
65
- * 2. Verifies code provenance using Sigstore/Rekor
66
- * 3. Performs runtime attestation against the enclave
67
- * 4. Verifies hardware measurements (for TDX platforms)
68
- * 5. Compares code and runtime measurements using platform-specific logic
69
- *
70
- * Primary method: verify() - Returns AttestationResponse with cryptographic keys
71
- * Verification details: getVerificationDocument() - Returns step-by-step results
72
- */
73
- export declare class Verifier {
74
- private static goInstance;
75
- private static initializationPromise;
76
- private static readonly defaultWasmUrl;
77
- static originalFsWriteSync: ((fd: number, buf: Uint8Array) => number) | null;
78
- static wasmLogsSuppressed: boolean;
79
- static globalsInitialized: boolean;
80
- private lastVerificationDocument?;
81
- protected readonly serverURL: string;
82
- protected readonly configRepo: string;
83
- constructor(options?: {
84
- serverURL?: string;
85
- configRepo?: string;
86
- });
87
- /**
88
- * Execute a function with a fresh WASM instance that auto-cleans up
89
- * This ensures Go runtime doesn't keep the process alive
90
- */
91
- private static executeWithWasm;
92
- /**
93
- * Perform end-to-end attestation verification
94
- *
95
- * This method performs all verification steps atomically via the Go WASM verify() function:
96
- * 1. Fetches the latest code digest from GitHub releases
97
- * 2. Verifies code provenance using Sigstore/Rekor
98
- * 3. Performs runtime attestation against the enclave
99
- * 4. Verifies hardware measurements (for TDX platforms)
100
- * 5. Compares code and runtime measurements using platform-specific logic
101
- *
102
- * The WASM runtime is automatically initialized and cleaned up within this method.
103
- * A detailed verification document is saved and can be accessed via getVerificationDocument().
104
- *
105
- * @returns AttestationResponse containing cryptographic keys (TLS/HPKE) and enclave measurement
106
- * @throws Error if measurements don't match or verification fails at any step
107
- */
108
- verify(): Promise<AttestationResponse>;
109
- /**
110
- * Save a failed verification document
111
- */
112
- private saveFailedVerificationDocument;
113
- /**
114
- * Internal verification logic that runs within WASM context
115
- */
116
- private verifyInternal;
117
- /**
118
- * Returns the verification document from the last verify() call
119
- *
120
- * The document contains detailed step-by-step verification results including:
121
- * - Step status (pending/success/failed) for each verification phase
122
- * - Measurements, fingerprints, and cryptographic keys
123
- * - Error messages for any failed steps
124
- *
125
- * Available even if verification failed, allowing inspection of which step failed.
126
- *
127
- * @returns VerificationDocument with complete verification details, or undefined if verify() hasn't been called
128
- */
129
- getVerificationDocument(): VerificationDocument | undefined;
130
- }
131
- /**
132
- * Control WASM log output
133
- *
134
- * The Go WASM runtime outputs logs (stdout/stderr) through a polyfilled fs.writeSync.
135
- * This function allows suppressing those logs without affecting other console output.
136
- * By default, WASM logs are suppressed to reduce noise.
137
- *
138
- * @param suppress - Whether to suppress WASM logs (default: true)
139
- * @returns void
140
- */
141
- export declare function suppressWasmLogs(suppress?: boolean): void;