@premai/reticle 0.3.0

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 ADDED
@@ -0,0 +1,113 @@
1
+ # reticle
2
+
3
+ Hardware attestation SDK for JavaScript and TypeScript. Cryptographically verifies AMD SEV-SNP, Intel TDX, and NVIDIA GPU attestations from an [attestation server](https://github.com/prem-research/reticle) — runs in Node.js, Bun, Deno and the browser via WASM.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @premai/reticle
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```typescript
14
+ import { ClientBuilder } from "@premai/reticle";
15
+
16
+ const client = new ClientBuilder("https://attestation.example.com")
17
+ .build();
18
+
19
+ // End-to-end attestation: discovers modules, generates nonces,
20
+ // verifies cryptographic signatures and certificate chains
21
+ const result = await client.attest();
22
+
23
+ console.log("CPU:", result.modules().cpu()); // CpuModule.Sev or CpuModule.Tdx
24
+ console.log("GPU:", result.modules().gpu()); // GpuModule.Nvidia or undefined
25
+ ```
26
+
27
+ ## API
28
+
29
+ ### `ClientBuilder`
30
+
31
+ Creates and configures a `Client` instance.
32
+
33
+ ```typescript
34
+ const client = new ClientBuilder(url)
35
+ .with_authorization("Bearer <token>") // optional: set Authorization header
36
+ .with_kds(new Kds(kdsUrl)) // optional: custom AMD KDS cache
37
+ .with_pcs(new Pcs(pcsUrl)) // optional: custom Intel PCS cache
38
+ .build();
39
+ ```
40
+
41
+ ### `Client`
42
+
43
+ #### High-level (recommended)
44
+
45
+ These methods handle nonce generation, request, and full cryptographic verification in a single call:
46
+
47
+ | Method | Description |
48
+ |---|---|
49
+ | `client.attest(query?)` | Full attestation of all available modules (CPU + GPU) |
50
+ | `client.attest_sev(query?)` | AMD SEV-SNP attestation only |
51
+ | `client.attest_tdx(query?)` | Intel TDX attestation only |
52
+ | `client.attest_nvidia(query?)` | NVIDIA GPU attestation only |
53
+
54
+ #### Low-level
55
+
56
+ These methods fetch and parse attestation evidence (**discouraged**) — useful when you need to inspect raw data or implement custom validation:
57
+
58
+ | Method | Description |
59
+ |---|---|
60
+ | `client.request_modules(query?)` | List available attestation modules on the server |
61
+ | `client.request_sev(nonce, query)` | Fetch raw SEV-SNP attestation report |
62
+ | `client.request_tdx(nonce, query)` | Fetch raw TDX quote |
63
+ | `client.request_nvidia(nonce, query)` | Fetch raw NVIDIA EAT/JWT token |
64
+
65
+ ### `QueryParams`
66
+
67
+ Pass custom query parameters to the attestation server. The `nonce` key is reserved and will throw if used.
68
+
69
+ ```typescript
70
+ const query = new QueryParams()
71
+ .with("model", "my-model")
72
+ .with("version", "1.0");
73
+
74
+ await client.attest(query);
75
+ ```
76
+
77
+ ### Sub-module access
78
+
79
+ Lower-level types from the attestation modules are available under namespaces:
80
+
81
+ ```typescript
82
+ import { nvidia, sev } from "@premai/reticle";
83
+
84
+ // NVIDIA: manual token parsing and verification
85
+ const keychain = await nvidia.fetch_keychain();
86
+ const token = nvidia.EATToken.parse(rawJwt);
87
+ const claims = token.verify(keychain);
88
+ claims.validate(nonce);
89
+
90
+ // AMD SEV-SNP: manual certificate chain verification
91
+ const kds = new sev.Kds("https://kcds.prem.io");
92
+ const chain = await kds.fetch_certificates(attestation);
93
+ attestation.verify(chain, nonce);
94
+ ```
95
+
96
+ ## Memory management
97
+
98
+ WASM objects are not garbage-collected automatically. Call `.free()` when done, or use `using` (TypeScript 5.2+) for automatic disposal:
99
+
100
+ ```typescript
101
+ using client = new ClientBuilder(url).build();
102
+ using result = await client.attest();
103
+ // automatically freed at end of scope
104
+ ```
105
+
106
+ ## Examples
107
+
108
+ - **[Bun](../examples/bun)** — minimal CLI attestation
109
+ - **[Vite](../examples/vite)** — browser UI with attestation status
110
+
111
+ ## License
112
+
113
+ See [LICENSE](../LICENSE).
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@premai/reticle",
3
+ "type": "module",
4
+ "version": "0.3.0",
5
+ "files": [
6
+ "prem_rs_bg.wasm",
7
+ "prem_rs.js",
8
+ "prem_rs_bg.js",
9
+ "prem_rs.d.ts",
10
+ "prem_rs_bg.js"
11
+ ],
12
+ "main": "prem_rs_main.js",
13
+ "types": "prem_rs.d.ts",
14
+ "sideEffects": [
15
+ "./prem_rs.js",
16
+ "./snippets/*"
17
+ ],
18
+ "exports": {
19
+ ".": {
20
+ "browser": {
21
+ "types": "./prem_rs.d.ts",
22
+ "default": "./prem_rs.js"
23
+ },
24
+ "default": {
25
+ "types": "./prem_rs.d.ts",
26
+ "default": "./prem_rs_main.js"
27
+ }
28
+ }
29
+ }
30
+ }
package/prem_rs.d.ts ADDED
@@ -0,0 +1,327 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class AttestHeaders {
5
+ private constructor();
6
+ free(): void;
7
+ [Symbol.dispose](): void;
8
+ cpu(): ResponseHeaders | undefined;
9
+ gpu(): ResponseHeaders | undefined;
10
+ }
11
+
12
+ export class AttestResult {
13
+ private constructor();
14
+ free(): void;
15
+ [Symbol.dispose](): void;
16
+ headers(): AttestHeaders;
17
+ modules(): Modules;
18
+ }
19
+
20
+ export class Client {
21
+ private constructor();
22
+ free(): void;
23
+ [Symbol.dispose](): void;
24
+ /**
25
+ * Steps:
26
+ * - Gathers modules to attest from attestation server
27
+ * - Iterates through each module and performs end-to-end attestation
28
+ * - Returns the list of attested modules
29
+ */
30
+ attest(query?: QueryParams | null): Promise<AttestResult>;
31
+ /**
32
+ * Completes end-to-end nvidia attestation. Generates nonce and validates claims all in one
33
+ */
34
+ attest_nvidia(query?: QueryParams | null): Promise<ResponseHeaders>;
35
+ /**
36
+ * Performs end-to-end sev-snp attestation. Generates nonce and validates claims all in one
37
+ */
38
+ attest_sev(query?: QueryParams | null): Promise<void>;
39
+ /**
40
+ * Performs end-to-end tdx attestation. Generates nonce and validates claims all in one
41
+ */
42
+ attest_tdx(query?: QueryParams | null): Promise<void>;
43
+ /**
44
+ * Gather available attestable modules from remote attestation endpoint
45
+ */
46
+ request_modules(query?: QueryParams | null): Promise<Modules>;
47
+ /**
48
+ * Requests and parses an Nvidia EATToken attestation from the attestation server
49
+ *
50
+ * ### Warning
51
+ * This method exposes core functionality and does not perform cryptographic
52
+ * or measurement checks on the attestation. If you want to perform end-to-end attestation
53
+ * please refer to [`Self::attest_nvidia`]
54
+ */
55
+ request_nvidia(nonce: NvidiaNonce, query: QueryParams): Promise<NvidiaAttestResult>;
56
+ /**
57
+ * Requests and parses a SEV-SNP attestation from the attestation server.
58
+ *
59
+ * ### Warning
60
+ * This method exposes core functionality and does not perform cryptographic
61
+ * or measurement checks on the attestation. If you want to perform end-to-end attestation
62
+ * please refer to [`Self::attest_sev`]
63
+ */
64
+ request_sev(nonce: SevNonce, query: QueryParams): Promise<ParsedAttestation>;
65
+ /**
66
+ * Requests and parses a TDX quote
67
+ *
68
+ * ### Warning
69
+ * This method exposes core functionality and does not perform cryptographic
70
+ * or measurement checks on the attestation. If you want to perform end-to-end attestation
71
+ * please refer to [`Self::attest_tdx`]
72
+ */
73
+ request_tdx(nonce: TdxNonce, query: QueryParams): Promise<TdxQuote>;
74
+ }
75
+
76
+ export class ClientBuilder {
77
+ free(): void;
78
+ [Symbol.dispose](): void;
79
+ build(): Promise<Client>;
80
+ constructor(url: string);
81
+ /**
82
+ * Sets `Authorization` header
83
+ */
84
+ with_authorization(token: string): ClientBuilder;
85
+ /**
86
+ * Sets custom KDS for AMD collateral server
87
+ */
88
+ with_kds(kds: Kds): ClientBuilder;
89
+ /**
90
+ * Sets custom PCS for Intel collateral server
91
+ */
92
+ with_pcs(pcs: Pcs): ClientBuilder;
93
+ /**
94
+ * sets custom url for OPA policies index
95
+ */
96
+ with_policies_url(url: string): ClientBuilder;
97
+ }
98
+
99
+ export class Collateral {
100
+ private constructor();
101
+ free(): void;
102
+ [Symbol.dispose](): void;
103
+ }
104
+
105
+ export enum CpuModule {
106
+ Sev = 0,
107
+ Tdx = 1,
108
+ }
109
+
110
+ export class GatewayError {
111
+ private constructor();
112
+ free(): void;
113
+ [Symbol.dispose](): void;
114
+ message: string;
115
+ }
116
+
117
+ export enum GpuModule {
118
+ Nvidia = 0,
119
+ }
120
+
121
+ export class Modules {
122
+ private constructor();
123
+ free(): void;
124
+ [Symbol.dispose](): void;
125
+ cpu(): CpuModule;
126
+ gpu(): GpuModule | undefined;
127
+ has_gpu(): boolean;
128
+ }
129
+
130
+ export class NvidiaAttestResult {
131
+ private constructor();
132
+ free(): void;
133
+ [Symbol.dispose](): void;
134
+ }
135
+
136
+ export class Pcs {
137
+ free(): void;
138
+ [Symbol.dispose](): void;
139
+ fetch_collateral(quote: TdxQuote): Promise<Collateral>;
140
+ constructor(base_url: string);
141
+ }
142
+
143
+ /**
144
+ * Generic per-request query parameters.
145
+ *
146
+ * The `nonce` key is reserved and will be rejected.
147
+ */
148
+ export class QueryParams {
149
+ free(): void;
150
+ [Symbol.dispose](): void;
151
+ constructor();
152
+ /**
153
+ * Appends a query parameter.
154
+ *
155
+ * Reserved keywords for specific queries will get overwritten
156
+ */
157
+ with(key: string, value: string): QueryParams;
158
+ }
159
+
160
+ export class QuoteVerifier {
161
+ free(): void;
162
+ [Symbol.dispose](): void;
163
+ constructor(collateral: Collateral, quote: TdxQuote);
164
+ verify(nonce: TdxNonce): void;
165
+ }
166
+
167
+ export class ResponseHeaders {
168
+ private constructor();
169
+ free(): void;
170
+ [Symbol.dispose](): void;
171
+ get(name: string): string | undefined;
172
+ keys(): string[];
173
+ }
174
+
175
+ export class TcbLevels {
176
+ private constructor();
177
+ free(): void;
178
+ [Symbol.dispose](): void;
179
+ }
180
+
181
+ export class TdxNonce {
182
+ free(): void;
183
+ [Symbol.dispose](): void;
184
+ constructor();
185
+ to_hex(): string;
186
+ }
187
+
188
+ export class TdxQuote {
189
+ private constructor();
190
+ free(): void;
191
+ [Symbol.dispose](): void;
192
+ /**
193
+ * Attempts to parse a quote from DCAP bytes.
194
+ */
195
+ static from_bytes(quote: Uint8Array): TdxQuote;
196
+ }
197
+
198
+ declare class DecodedClaims {
199
+ private constructor();
200
+ free(): void;
201
+ [Symbol.dispose](): void;
202
+ }
203
+
204
+ declare class EATToken {
205
+ private constructor();
206
+ free(): void;
207
+ [Symbol.dispose](): void;
208
+ static parse(from: string): EATToken;
209
+ verify(keys: KeyChain, nonce: NvidiaNonce): DecodedClaims;
210
+ }
211
+
212
+ declare class KeyChain {
213
+ private constructor();
214
+ free(): void;
215
+ [Symbol.dispose](): void;
216
+ }
217
+
218
+ declare class NvidiaNonce {
219
+ private constructor();
220
+ free(): void;
221
+ [Symbol.dispose](): void;
222
+ static generate(): NvidiaNonce;
223
+ to_hex(): string;
224
+ }
225
+
226
+ /**
227
+ * Same as [`KeyChain:fetch_keychain`], put in for better wasm compatibility
228
+ */
229
+ declare function fetch_keychain(): Promise<KeyChain>;
230
+
231
+ export let nvidia: {
232
+ DecodedClaims: typeof DecodedClaims,
233
+ EATToken: typeof EATToken,
234
+ KeyChain: typeof KeyChain,
235
+ NvidiaNonce: typeof NvidiaNonce,
236
+ fetch_keychain: typeof fetch_keychain,
237
+ };
238
+
239
+ /**
240
+ * A parsed certificate revocation list
241
+ */
242
+ declare class CRL {
243
+ private constructor();
244
+ free(): void;
245
+ [Symbol.dispose](): void;
246
+ /**
247
+ * Passes if the certificates are not in the certificate revocation list
248
+ * Throws `AttestationError` on fail
249
+ */
250
+ check_chain(chain: VerifiedChain): void;
251
+ /**
252
+ * Parses a certificate revocation list from DER format binary data
253
+ */
254
+ static from_der(list: Uint8Array): CRL;
255
+ }
256
+
257
+ declare class ExportPem {
258
+ private constructor();
259
+ free(): void;
260
+ [Symbol.dispose](): void;
261
+ ark: Uint8Array;
262
+ ask: Uint8Array;
263
+ vek: Uint8Array;
264
+ }
265
+
266
+ declare class Kds {
267
+ free(): void;
268
+ [Symbol.dispose](): void;
269
+ fetch_certificates(attestation: ParsedAttestation): Promise<VerifiedChain>;
270
+ /**
271
+ * Fetches the certificate revocation list from AMD's KDS
272
+ */
273
+ fetch_crl(attestation: ParsedAttestation): Promise<CRL>;
274
+ constructor(cache_url: string);
275
+ }
276
+
277
+ /**
278
+ * Represents a parsed attestation report with some already
279
+ * parsed commonly accessed fields
280
+ */
281
+ declare class ParsedAttestation {
282
+ private constructor();
283
+ free(): void;
284
+ [Symbol.dispose](): void;
285
+ cpu_fam_id(): number;
286
+ cpu_mod_id(): number;
287
+ /**
288
+ * Parses and constructs a new attestation report from a stream of binary data
289
+ */
290
+ static new(bytes: Uint8Array): ParsedAttestation;
291
+ /**
292
+ * Verifies the attestation report against a certificate chain
293
+ */
294
+ verify(chain: VerifiedChain, nonce: SevNonce): void;
295
+ }
296
+
297
+ declare class SevNonce {
298
+ private constructor();
299
+ free(): void;
300
+ [Symbol.dispose](): void;
301
+ static generate(): SevNonce;
302
+ to_hex(): string;
303
+ }
304
+
305
+ /**
306
+ * A chain which has been cryptographically verified
307
+ */
308
+ declare class VerifiedChain {
309
+ private constructor();
310
+ free(): void;
311
+ [Symbol.dispose](): void;
312
+ /**
313
+ * parses a triad of ark, ask and vek certificates in the PEM format,
314
+ * cryptographically verifies the chain is valid, returns a `VerifiedChain` object
315
+ */
316
+ static parse_verify(ark_pem: string, ask_pem: string, vek_pem: string): VerifiedChain;
317
+ to_pem(): ExportPem;
318
+ }
319
+
320
+ export let sev: {
321
+ CRL: typeof CRL,
322
+ ExportPem: typeof ExportPem,
323
+ Kds: typeof Kds,
324
+ ParsedAttestation: typeof ParsedAttestation,
325
+ SevNonce: typeof SevNonce,
326
+ VerifiedChain: typeof VerifiedChain,
327
+ };
package/prem_rs.js ADDED
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./prem_rs.d.ts" */
2
+
3
+ import * as wasm from "./prem_rs_bg.wasm";
4
+ import { __wbg_set_wasm } from "./prem_rs_bg.js";
5
+ __wbg_set_wasm(wasm);
6
+ wasm.__wbindgen_start();
7
+ export {
8
+ AttestHeaders, AttestResult, Client, ClientBuilder, Collateral, CpuModule, GatewayError, GpuModule, Modules, NvidiaAttestResult, Pcs, QueryParams, QuoteVerifier, ResponseHeaders, TcbLevels, TdxNonce, TdxQuote
9
+ } from "./prem_rs_bg.js";