@zeke-02/tinfoil 0.0.2

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 (65) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +169 -0
  3. package/dist/__tests__/test-utils.d.ts +1 -0
  4. package/dist/__tests__/test-utils.js +44 -0
  5. package/dist/ai-sdk-provider.d.ts +7 -0
  6. package/dist/ai-sdk-provider.js +23 -0
  7. package/dist/config.d.ts +17 -0
  8. package/dist/config.js +20 -0
  9. package/dist/encrypted-body-fetch.d.ts +8 -0
  10. package/dist/encrypted-body-fetch.js +93 -0
  11. package/dist/env.d.ts +5 -0
  12. package/dist/env.js +20 -0
  13. package/dist/esm/__tests__/test-utils.d.ts +1 -0
  14. package/dist/esm/__tests__/test-utils.js +38 -0
  15. package/dist/esm/ai-sdk-provider.d.ts +7 -0
  16. package/dist/esm/ai-sdk-provider.js +20 -0
  17. package/dist/esm/config.d.ts +17 -0
  18. package/dist/esm/config.js +17 -0
  19. package/dist/esm/encrypted-body-fetch.d.ts +8 -0
  20. package/dist/esm/encrypted-body-fetch.js +86 -0
  21. package/dist/esm/env.d.ts +5 -0
  22. package/dist/esm/env.js +17 -0
  23. package/dist/esm/fetch-adapter.d.ts +21 -0
  24. package/dist/esm/fetch-adapter.js +23 -0
  25. package/dist/esm/index.browser.d.ts +7 -0
  26. package/dist/esm/index.browser.js +8 -0
  27. package/dist/esm/index.d.ts +8 -0
  28. package/dist/esm/index.js +12 -0
  29. package/dist/esm/pinned-tls-fetch.d.ts +1 -0
  30. package/dist/esm/pinned-tls-fetch.js +110 -0
  31. package/dist/esm/secure-client.d.ts +20 -0
  32. package/dist/esm/secure-client.js +123 -0
  33. package/dist/esm/secure-fetch.browser.d.ts +1 -0
  34. package/dist/esm/secure-fetch.browser.js +10 -0
  35. package/dist/esm/secure-fetch.d.ts +1 -0
  36. package/dist/esm/secure-fetch.js +22 -0
  37. package/dist/esm/tinfoilai.d.ts +54 -0
  38. package/dist/esm/tinfoilai.js +134 -0
  39. package/dist/esm/unverified-client.d.ts +18 -0
  40. package/dist/esm/unverified-client.js +33 -0
  41. package/dist/esm/verifier.d.ts +141 -0
  42. package/dist/esm/verifier.js +741 -0
  43. package/dist/esm/wasm-exec.js +668 -0
  44. package/dist/fetch-adapter.d.ts +21 -0
  45. package/dist/fetch-adapter.js +27 -0
  46. package/dist/index.browser.d.ts +7 -0
  47. package/dist/index.browser.js +29 -0
  48. package/dist/index.d.ts +8 -0
  49. package/dist/index.js +49 -0
  50. package/dist/pinned-tls-fetch.d.ts +1 -0
  51. package/dist/pinned-tls-fetch.js +116 -0
  52. package/dist/secure-client.d.ts +20 -0
  53. package/dist/secure-client.js +127 -0
  54. package/dist/secure-fetch.browser.d.ts +1 -0
  55. package/dist/secure-fetch.browser.js +13 -0
  56. package/dist/secure-fetch.d.ts +1 -0
  57. package/dist/secure-fetch.js +25 -0
  58. package/dist/tinfoilai.d.ts +54 -0
  59. package/dist/tinfoilai.js +141 -0
  60. package/dist/unverified-client.d.ts +18 -0
  61. package/dist/unverified-client.js +37 -0
  62. package/dist/verifier.d.ts +141 -0
  63. package/dist/verifier.js +781 -0
  64. package/dist/wasm-exec.js +668 -0
  65. package/package.json +97 -0
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Attestation measurement containing platform type and register values
3
+ */
4
+ export interface AttestationMeasurement {
5
+ type: string;
6
+ registers: string[];
7
+ }
8
+ /**
9
+ * Attestation response containing cryptographic keys and measurements
10
+ * At least one of tlsPublicKeyFingerprint or hpkePublicKey must be present
11
+ */
12
+ export interface AttestationResponse {
13
+ tlsPublicKeyFingerprint?: string;
14
+ hpkePublicKey?: string;
15
+ measurement: AttestationMeasurement;
16
+ }
17
+ /**
18
+ * State of an intermediate verification step
19
+ */
20
+ export interface VerificationStepState {
21
+ status: "pending" | "success" | "failed";
22
+ error?: string;
23
+ }
24
+ /**
25
+ * Full verification document produced by a verify() call
26
+ * Includes state tracking for all intermediate steps
27
+ */
28
+ export interface VerificationDocument {
29
+ configRepo: string;
30
+ enclaveHost: string;
31
+ releaseDigest: string;
32
+ codeMeasurement: AttestationMeasurement;
33
+ enclaveMeasurement: AttestationResponse;
34
+ securityVerified: boolean;
35
+ steps: {
36
+ fetchDigest: VerificationStepState;
37
+ verifyCode: VerificationStepState;
38
+ verifyEnclave: VerificationStepState;
39
+ compareMeasurements: VerificationStepState;
40
+ createTransport?: VerificationStepState;
41
+ verifyHPKEKey?: VerificationStepState;
42
+ otherError?: VerificationStepState;
43
+ };
44
+ }
45
+ export interface MeasurementComparisonResult {
46
+ match: boolean;
47
+ error?: Error;
48
+ }
49
+ export declare function compareMeasurementsDetailed(codeMeasurement: AttestationMeasurement, runtimeMeasurement: AttestationMeasurement): MeasurementComparisonResult;
50
+ /**
51
+ * Compare two measurements according to platform-specific rules
52
+ * This is predicate function for comparing attestation measurements
53
+ * taken from https://github.com/tinfoilsh/verifier/blob/main/attestation/attestation.go
54
+ *
55
+ * @param codeMeasurement - Expected measurement from code attestation
56
+ * @param runtimeMeasurement - Actual measurement from runtime attestation
57
+ * @returns true if measurements match according to platform rules
58
+ */
59
+ export declare function compareMeasurements(codeMeasurement: AttestationMeasurement, runtimeMeasurement: AttestationMeasurement): boolean;
60
+ /**
61
+ * Verifier performs attestation verification for Tinfoil enclaves
62
+ *
63
+ * The verifier loads a WebAssembly module that:
64
+ * 1. Fetches the latest code release digest from GitHub
65
+ * 2. Performs runtime attestation against the enclave
66
+ * 3. Performs code attestation using the digest
67
+ * 4. Compares measurements using platform-specific logic
68
+ */
69
+ export declare class Verifier {
70
+ private static goInstance;
71
+ private static initializationPromise;
72
+ private static readonly defaultWasmUrl;
73
+ static originalFsWriteSync: ((fd: number, buf: Uint8Array) => number) | null;
74
+ static wasmLogsSuppressed: boolean;
75
+ static globalsInitialized: boolean;
76
+ private lastVerificationDocument?;
77
+ protected readonly serverURL: string;
78
+ protected readonly configRepo: string;
79
+ constructor(options?: {
80
+ serverURL?: string;
81
+ configRepo?: string;
82
+ });
83
+ /**
84
+ * Execute a function with a fresh WASM instance that auto-cleans up
85
+ * This ensures Go runtime doesn't keep the process alive
86
+ */
87
+ private static executeWithWasm;
88
+ /**
89
+ * Fetch the latest release digest from GitHub
90
+ * @param configRepo - Repository name (e.g., "tinfoilsh/confidential-inference-proxy")
91
+ * @returns The digest hash
92
+ */
93
+ fetchLatestDigest(configRepo?: string): Promise<string>;
94
+ /**
95
+ * Perform runtime attestation on the enclave
96
+ * @param enclaveHost - The enclave hostname
97
+ * @returns Attestation response with measurement and keys
98
+ */
99
+ verifyEnclave(enclaveHost?: string): Promise<AttestationResponse>;
100
+ /**
101
+ * Perform code attestation
102
+ * @param configRepo - Repository name
103
+ * @param digest - Code digest hash
104
+ * @returns Code measurement
105
+ */
106
+ verifyCode(configRepo: string, digest: string): Promise<{
107
+ measurement: AttestationMeasurement;
108
+ }>;
109
+ /**
110
+ * Perform attestation verification
111
+ *
112
+ * This method:
113
+ * 1. Fetches the latest code digest from GitHub releases
114
+ * 2. Calls verifyCode to get the expected measurement for the code
115
+ * 3. Calls verifyEnclave to get the actual runtime measurement
116
+ * 4. Compares measurements using platform-specific logic (see `compareMeasurements()`)
117
+ * 5. Returns the attestation response if verification succeeds
118
+ *
119
+ * The WASM runtime is automatically initialized and cleaned up within this method.
120
+ *
121
+ * @throws Error if measurements don't match or verification fails
122
+ */
123
+ verify(): Promise<AttestationResponse>;
124
+ /**
125
+ * Internal verification logic that runs within WASM context
126
+ */
127
+ private verifyInternal;
128
+ /**
129
+ * Returns the full verification document from the last successful verify() call
130
+ */
131
+ getVerificationDocument(): VerificationDocument | undefined;
132
+ }
133
+ /**
134
+ * Control WASM log output
135
+ *
136
+ * The Go WASM runtime outputs logs through a polyfilled fs.writeSync.
137
+ * This function allows suppressing those logs without affecting other console output.
138
+ *
139
+ * @param suppress - Whether to suppress WASM logs (default: true)
140
+ */
141
+ export declare function suppressWasmLogs(suppress?: boolean): void;