tinfoil 0.2.3 → 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: () => []
@@ -39,7 +44,8 @@ if (typeof window === 'undefined') {
39
44
  globalThis.window = globalThis;
40
45
  globalThis.document = {
41
46
  createElement: () => ({
42
- setAttribute: () => { }
47
+ setAttribute: () => {
48
+ }
43
49
  })
44
50
  };
45
51
  }
@@ -143,7 +149,7 @@ class SecureClient {
143
149
  throw new Error('Measurements do not match');
144
150
  }
145
151
  return {
146
- certFingerprint: new Uint8Array(Buffer.from(attestationResponse.certificate, 'hex')),
152
+ publicKeyFP: attestationResponse.certificate,
147
153
  measurement: attestationResponse.measurement,
148
154
  };
149
155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinfoil",
3
- "version": "0.2.3",
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",