tinfoil 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -96,8 +96,7 @@ class TinfoilAI {
96
96
  catch (error) {
97
97
  throw new Error(`Failed to verify enclave: ${error}`);
98
98
  }
99
- // Convert the expected fingerprint to hex string for comparison
100
- const expectedFingerprint = Buffer.from(this.groundTruth.certFingerprint).toString('hex');
99
+ const expectedFingerprint = this.groundTruth.publicKeyFP;
101
100
  // Create a custom HTTPS agent that verifies certificate fingerprints
102
101
  const httpsAgent = new https_1.default.Agent({
103
102
  rejectUnauthorized: true,
@@ -105,11 +104,15 @@ class TinfoilAI {
105
104
  if (!cert || !cert.raw) {
106
105
  throw new Error('No certificate found');
107
106
  }
108
- // Calculate the SHA-256 fingerprint of the certificate and convert to hex
109
- const certFingerprint = (0, crypto_1.createHash)('sha256').update(cert.raw).digest('hex');
110
- // Compare hex strings
111
- if (certFingerprint !== expectedFingerprint) {
112
- throw new Error('Certificate fingerprint mismatch');
107
+ if (!cert.pubkey) {
108
+ throw new Error('No public key found');
109
+ }
110
+ const pemCert = `-----BEGIN CERTIFICATE-----\n${cert.raw.toString('base64')}\n-----END CERTIFICATE-----`;
111
+ const x509Cert = new crypto_1.X509Certificate(pemCert);
112
+ const publicKey = x509Cert.publicKey.export({ format: 'der', type: 'spki' });
113
+ const publicKeyHash = (0, crypto_1.createHash)('sha256').update(publicKey).digest('hex');
114
+ if (publicKeyHash !== expectedFingerprint) {
115
+ throw new Error(`Certificate fingerprint mismatch. Got ${publicKeyHash}, expected ${expectedFingerprint}`);
113
116
  }
114
117
  return undefined; // Validation successful
115
118
  }
@@ -1,17 +1,8 @@
1
- declare global {
2
- var Go: any;
3
- var verifyEnclave: (enclaveHostname: string) => Promise<{
4
- certificate: string;
5
- measurement: string;
6
- certFingerprint: string;
7
- }>;
8
- var verifyCode: (repo: string, digest: string) => Promise<string>;
9
- }
10
1
  /**
11
2
  * Ground truth measurements from verification
12
3
  */
13
4
  export interface GroundTruth {
14
- certFingerprint: Uint8Array;
5
+ publicKeyFP: string;
15
6
  measurement: string;
16
7
  }
17
8
  /**
@@ -11,11 +11,16 @@ const globalThis = global;
11
11
  // Performance API
12
12
  globalThis.performance = {
13
13
  now: () => Date.now(),
14
- markResourceTiming: () => { },
15
- mark: () => { },
16
- measure: () => { },
17
- clearMarks: () => { },
18
- clearMeasures: () => { },
14
+ markResourceTiming: () => {
15
+ },
16
+ mark: () => {
17
+ },
18
+ measure: () => {
19
+ },
20
+ clearMarks: () => {
21
+ },
22
+ clearMeasures: () => {
23
+ },
19
24
  getEntriesByName: () => [],
20
25
  getEntriesByType: () => [],
21
26
  getEntries: () => []
@@ -33,13 +38,17 @@ if (!globalThis.crypto) {
33
38
  }
34
39
  };
35
40
  }
36
- // Additional browser polyfills that might be needed
37
- globalThis.window = globalThis;
38
- globalThis.document = {
39
- createElement: () => ({
40
- setAttribute: () => { }
41
- })
42
- };
41
+ // Modified secure-client.ts
42
+ if (typeof window === 'undefined') {
43
+ // Node.js environment
44
+ globalThis.window = globalThis;
45
+ globalThis.document = {
46
+ createElement: () => ({
47
+ setAttribute: () => {
48
+ }
49
+ })
50
+ };
51
+ }
43
52
  // Force process to stay running (prevent Go from exiting Node process)
44
53
  // This is a common issue with Go WASM in Node - it calls process.exit()
45
54
  const originalExit = process.exit;
@@ -140,7 +149,7 @@ class SecureClient {
140
149
  throw new Error('Measurements do not match');
141
150
  }
142
151
  return {
143
- certFingerprint: new Uint8Array(Buffer.from(attestationResponse.certificate, 'hex')),
152
+ publicKeyFP: attestationResponse.certificate,
144
153
  measurement: attestationResponse.measurement,
145
154
  };
146
155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinfoil",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "Official Tinfoil secure OpenAI client wrapper",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",