tinfoil 0.10.1 → 0.10.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/README.md CHANGED
@@ -69,7 +69,7 @@ const completion = await client.chat.completions.create({
69
69
 
70
70
  ## Verification helpers
71
71
 
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).
72
+ This package exposes verification helpers that load the Go-based WebAssembly verifier and provide end-to-end attestation with structured, stepwise results you can use in applications (e.g., to show progress, log transitions, or gate features).
73
73
 
74
74
  The verification functionality is contained in `verifier.ts`.
75
75
 
@@ -79,51 +79,62 @@ The verification functionality is contained in `verifier.ts`.
79
79
  ```typescript
80
80
  import { Verifier } from "tinfoil";
81
81
 
82
- const verifier = new Verifier();
83
-
84
- // Perform runtime attestation
85
- const runtime = await verifier.verifyEnclave("enclave.host.com");
86
- // Returns: { measurement: AttestationMeasurement, tlsPublicKeyFingerprint: string, hpkePublicKey: string }
87
-
88
- // Perform code attestation
89
- const code = await verifier.verifyCode("tinfoilsh/repo", "digest-hash");
90
- // Returns: { measurement: AttestationMeasurement }
91
-
92
- // Fetch latest digest from GitHub releases
93
- const digest = await verifier.fetchLatestDigest("tinfoilsh/repo");
82
+ const verifier = new Verifier({ serverURL: "https://enclave.host.com" });
83
+
84
+ // Perform full end-to-end verification
85
+ const attestation = await verifier.verify();
86
+ // Returns: AttestationResponse with measurement and cryptographic keys
87
+ // This performs all verification steps atomically:
88
+ // 1. Fetches the latest release digest from GitHub
89
+ // 2. Verifies code provenance using Sigstore
90
+ // 3. Performs runtime attestation against the enclave
91
+ // 4. Verifies hardware measurements (for TDX platforms)
92
+ // 5. Compares code and runtime measurements
93
+
94
+ // Access detailed verification results
95
+ const doc = verifier.getVerificationDocument();
96
+ // Returns: VerificationDocument with step-by-step status including
97
+ // measurements, fingerprints, and cryptographic keys
94
98
  ```
95
99
 
96
100
  ### Verification Document
97
101
 
98
- The `SecureClient` provides access to a comprehensive verification document that tracks all verification steps, including failures:
102
+ The `Verifier` provides access to a comprehensive verification document that tracks all verification steps, including failures:
99
103
 
100
104
  ```typescript
101
- import { SecureClient } from "tinfoil";
105
+ import { Verifier } from "tinfoil";
102
106
 
103
- const client = new SecureClient();
107
+ const verifier = new Verifier({ serverURL: "https://enclave.host.com" });
104
108
 
105
109
  try {
106
- await client.ready();
107
- const response = await client.fetch('https://api.example.com/data');
110
+ const attestation = await verifier.verify();
111
+ const doc = verifier.getVerificationDocument();
112
+ console.log('Security verified:', doc.securityVerified);
113
+ console.log('TLS fingerprint:', attestation.tlsPublicKeyFingerprint);
114
+ console.log('HPKE public key:', attestation.hpkePublicKey);
108
115
  } catch (error) {
109
116
  // Even on error, you can access the verification document
110
- const doc = await client.getVerificationDocument();
117
+ const doc = verifier.getVerificationDocument();
111
118
 
112
119
  // The document contains detailed step information:
113
120
  // - fetchDigest: GitHub release digest retrieval
114
121
  // - verifyCode: Code measurement verification
115
122
  // - verifyEnclave: Runtime attestation verification
116
123
  // - compareMeasurements: Code vs runtime measurement comparison
117
- // - createTransport: Transport initialization (optional)
118
- // - verifyHPKEKey: HPKE key verification (optional)
119
124
  // - otherError: Catch-all for unexpected errors (optional)
120
125
 
121
- console.log('Security verified:', doc.securityVerified);
122
-
123
126
  // Check individual steps
124
127
  if (doc.steps.verifyEnclave.status === 'failed') {
125
128
  console.log('Enclave verification failed:', doc.steps.verifyEnclave.error);
126
129
  }
130
+
131
+ // Error messages are prefixed with the failing step:
132
+ // - "fetchDigest:" - Failed to fetch GitHub release digest
133
+ // - "verifyCode:" - Failed to verify code provenance
134
+ // - "verifyEnclave:" - Failed runtime attestation
135
+ // - "verifyHardware:" - Failed TDX hardware verification
136
+ // - "validateTLS:" - TLS public key validation failed
137
+ // - "measurements:" - Measurement comparison failed
127
138
  }
128
139
  ```
129
140
 
@@ -82,13 +82,21 @@ export class SecureClient {
82
82
  releaseDigest: '',
83
83
  codeMeasurement: { type: '', registers: [] },
84
84
  enclaveMeasurement: { measurement: { type: '', registers: [] } },
85
+ tlsPublicKey: '',
86
+ hpkePublicKey: '',
87
+ hardwareMeasurement: undefined,
88
+ codeFingerprint: '',
89
+ enclaveFingerprint: '',
90
+ selectedRouterEndpoint: new URL(this.enclaveURL).hostname,
85
91
  securityVerified: false,
86
92
  steps: {
87
93
  fetchDigest: { status: 'pending' },
88
94
  verifyCode: { status: 'pending' },
89
95
  verifyEnclave: { status: 'pending' },
90
96
  compareMeasurements: { status: 'pending' },
91
- otherError: { status: 'failed', error: error.message }
97
+ createTransport: undefined,
98
+ verifyHPKEKey: undefined,
99
+ otherError: { status: 'failed', error: error.message },
92
100
  }
93
101
  };
94
102
  }
@@ -5,6 +5,14 @@ export interface AttestationMeasurement {
5
5
  type: string;
6
6
  registers: string[];
7
7
  }
8
+ /**
9
+ * Hardware measurement from TDX platform verification
10
+ */
11
+ export interface HardwareMeasurement {
12
+ ID: string;
13
+ MRTD: string;
14
+ RTMR0: string;
15
+ }
8
16
  /**
9
17
  * Attestation response containing cryptographic keys and measurements
10
18
  * At least one of tlsPublicKeyFingerprint or hpkePublicKey must be present
@@ -31,6 +39,12 @@ export interface VerificationDocument {
31
39
  releaseDigest: string;
32
40
  codeMeasurement: AttestationMeasurement;
33
41
  enclaveMeasurement: AttestationResponse;
42
+ tlsPublicKey: string;
43
+ hpkePublicKey: string;
44
+ hardwareMeasurement?: HardwareMeasurement;
45
+ codeFingerprint: string;
46
+ enclaveFingerprint: string;
47
+ selectedRouterEndpoint: string;
34
48
  securityVerified: boolean;
35
49
  steps: {
36
50
  fetchDigest: VerificationStepState;
@@ -42,29 +56,19 @@ export interface VerificationDocument {
42
56
  otherError?: VerificationStepState;
43
57
  };
44
58
  }
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
59
  /**
61
60
  * Verifier performs attestation verification for Tinfoil enclaves
62
61
  *
63
- * The verifier loads a WebAssembly module that:
62
+ * The verifier loads a WebAssembly module (compiled from Go) that performs
63
+ * end-to-end attestation verification:
64
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
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
68
72
  */
69
73
  export declare class Verifier {
70
74
  private static goInstance;
@@ -86,56 +90,52 @@ export declare class Verifier {
86
90
  */
87
91
  private static executeWithWasm;
88
92
  /**
89
- * Fetch the latest release digest from GitHub
90
- * @param configRepo - Repository name (e.g., "tinfoilsh/confidential-model-router")
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
93
+ * Perform end-to-end attestation verification
111
94
  *
112
- * This method:
95
+ * This method performs all verification steps atomically via the Go WASM verify() function:
113
96
  * 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
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
118
101
  *
119
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().
120
104
  *
121
- * @throws Error if measurements don't match or verification fails
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
122
107
  */
123
108
  verify(): Promise<AttestationResponse>;
109
+ /**
110
+ * Save a failed verification document
111
+ */
112
+ private saveFailedVerificationDocument;
124
113
  /**
125
114
  * Internal verification logic that runs within WASM context
126
115
  */
127
116
  private verifyInternal;
128
117
  /**
129
- * Returns the full verification document from the last successful verify() call
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
130
128
  */
131
129
  getVerificationDocument(): VerificationDocument | undefined;
132
130
  }
133
131
  /**
134
132
  * Control WASM log output
135
133
  *
136
- * The Go WASM runtime outputs logs through a polyfilled fs.writeSync.
134
+ * The Go WASM runtime outputs logs (stdout/stderr) through a polyfilled fs.writeSync.
137
135
  * This function allows suppressing those logs without affecting other console output.
136
+ * By default, WASM logs are suppressed to reduce noise.
138
137
  *
139
138
  * @param suppress - Whether to suppress WASM logs (default: true)
139
+ * @returns void
140
140
  */
141
141
  export declare function suppressWasmLogs(suppress?: boolean): void;