@enactprotocol/trust 2.0.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.
@@ -0,0 +1,613 @@
1
+ /**
2
+ * Sigstore-related type definitions for attestation and verification
3
+ */
4
+
5
+ // Import the actual sigstore bundle type (exported as Bundle from sigstore)
6
+ import type { Bundle } from "sigstore";
7
+
8
+ // Re-export for use - sigstore exports SerializedBundle as Bundle
9
+ export type SigstoreBundle = Bundle;
10
+
11
+ // ============================================================================
12
+ // OIDC Identity Types
13
+ // ============================================================================
14
+
15
+ /**
16
+ * Supported OIDC providers for keyless signing
17
+ */
18
+ export type OIDCProvider = "github" | "google" | "microsoft" | "gitlab" | "custom";
19
+
20
+ /**
21
+ * OIDC identity information extracted from tokens
22
+ */
23
+ export interface OIDCIdentity {
24
+ /** OIDC provider that issued the token */
25
+ provider: OIDCProvider;
26
+ /** Subject identifier (e.g., email or user ID) */
27
+ subject: string;
28
+ /** Issuer URL */
29
+ issuer: string;
30
+ /** Email address if available */
31
+ email?: string;
32
+ /** Username for the provider (e.g., GitHub username) */
33
+ username?: string;
34
+ /** GitHub-specific: workflow repository */
35
+ workflowRepository?: string;
36
+ /** GitHub-specific: workflow ref (branch/tag) */
37
+ workflowRef?: string;
38
+ /** GitHub-specific: workflow trigger event */
39
+ workflowTrigger?: string;
40
+ /** Raw OIDC token claims */
41
+ claims?: Record<string, unknown>;
42
+ }
43
+
44
+ /**
45
+ * Options for OIDC authentication
46
+ */
47
+ export interface OIDCOptions {
48
+ /** OIDC provider to use */
49
+ provider: OIDCProvider;
50
+ /** Custom issuer URL (for custom provider) */
51
+ issuerURL?: string;
52
+ /** Client ID for OIDC flow */
53
+ clientId?: string;
54
+ /** Redirect URI for OAuth flow */
55
+ redirectUri?: string;
56
+ /** Pre-obtained OIDC token (for CI/CD environments) */
57
+ token?: string;
58
+ }
59
+
60
+ // ============================================================================
61
+ // Fulcio Certificate Types
62
+ // ============================================================================
63
+
64
+ /**
65
+ * Fulcio certificate information
66
+ */
67
+ export interface FulcioCertificate {
68
+ /** PEM-encoded certificate chain */
69
+ certificateChain: string[];
70
+ /** Certificate serial number */
71
+ serialNumber: string;
72
+ /** Certificate not before time */
73
+ notBefore: Date;
74
+ /** Certificate not after time */
75
+ notAfter: Date;
76
+ /** Subject common name */
77
+ subject: string;
78
+ /** Certificate issuer */
79
+ issuer: string;
80
+ /** OIDC identity embedded in certificate */
81
+ identity: OIDCIdentity;
82
+ /** Raw certificate bytes (DER encoded) */
83
+ raw?: Uint8Array;
84
+ }
85
+
86
+ /**
87
+ * Options for requesting a Fulcio certificate
88
+ */
89
+ export interface FulcioCertificateOptions {
90
+ /** Fulcio server URL (default: public Fulcio instance) */
91
+ fulcioURL?: string;
92
+ /** OIDC identity token */
93
+ identityToken: string;
94
+ /** Public key to certify */
95
+ publicKey: string;
96
+ /** Proof of possession signature */
97
+ proofOfPossession: string;
98
+ }
99
+
100
+ // ============================================================================
101
+ // Rekor Transparency Log Types
102
+ // ============================================================================
103
+
104
+ /**
105
+ * Rekor transparency log entry
106
+ */
107
+ export interface RekorEntry {
108
+ /** Log entry UUID */
109
+ uuid: string;
110
+ /** Log entry index */
111
+ logIndex: number;
112
+ /** Integrated time (Unix timestamp) */
113
+ integratedTime: number;
114
+ /** Log ID */
115
+ logID: string;
116
+ /** Entry body (base64 encoded) */
117
+ body: string;
118
+ /** Signed Entry Timestamp (SET) */
119
+ signedEntryTimestamp: string;
120
+ /** Inclusion proof */
121
+ inclusionProof?: RekorInclusionProof;
122
+ }
123
+
124
+ /**
125
+ * Inclusion proof for a Rekor entry
126
+ */
127
+ export interface RekorInclusionProof {
128
+ /** Log index */
129
+ logIndex: number;
130
+ /** Root hash of the tree at the time of inclusion */
131
+ rootHash: string;
132
+ /** Tree size at time of inclusion */
133
+ treeSize: number;
134
+ /** Hashes for the inclusion proof */
135
+ hashes: string[];
136
+ }
137
+
138
+ /**
139
+ * Options for creating a Rekor entry
140
+ */
141
+ export interface RekorEntryOptions {
142
+ /** Rekor server URL (default: public Rekor instance) */
143
+ rekorURL?: string;
144
+ /** Artifact hash */
145
+ artifactHash: string;
146
+ /** Signature over the artifact */
147
+ signature: string;
148
+ /** Signing certificate */
149
+ certificate: string;
150
+ }
151
+
152
+ // ============================================================================
153
+ // Attestation Types (in-toto / SLSA)
154
+ // ============================================================================
155
+
156
+ /**
157
+ * in-toto Statement (attestation envelope)
158
+ * @see https://github.com/in-toto/attestation/blob/main/spec/v1/statement.md
159
+ */
160
+ export interface InTotoStatement<T = unknown> {
161
+ /** Statement type identifier */
162
+ _type: "https://in-toto.io/Statement/v1";
163
+ /** Subjects (artifacts) this attestation covers */
164
+ subject: InTotoSubject[];
165
+ /** Predicate type URI */
166
+ predicateType: string;
167
+ /** Predicate content */
168
+ predicate: T;
169
+ }
170
+
171
+ /**
172
+ * Subject of an in-toto statement
173
+ */
174
+ export interface InTotoSubject {
175
+ /** Subject name (e.g., file path or artifact identifier) */
176
+ name: string;
177
+ /** Digest of the subject in various algorithms */
178
+ digest: {
179
+ sha256?: string;
180
+ sha512?: string;
181
+ [algorithm: string]: string | undefined;
182
+ };
183
+ }
184
+
185
+ /**
186
+ * SLSA Provenance predicate v1.0
187
+ * @see https://slsa.dev/spec/v1.0/provenance
188
+ */
189
+ export interface SLSAProvenancePredicate {
190
+ /** Build definition */
191
+ buildDefinition: {
192
+ /** Build type URI */
193
+ buildType: string;
194
+ /** External parameters */
195
+ externalParameters: Record<string, unknown>;
196
+ /** Internal parameters */
197
+ internalParameters?: Record<string, unknown>;
198
+ /** Resolved dependencies */
199
+ resolvedDependencies?: SLSAResourceDescriptor[];
200
+ };
201
+ /** Run details */
202
+ runDetails: {
203
+ /** Builder information */
204
+ builder: {
205
+ /** Builder ID */
206
+ id: string;
207
+ /** Builder dependencies */
208
+ builderDependencies?: SLSAResourceDescriptor[];
209
+ /** Builder version */
210
+ version?: Record<string, string>;
211
+ };
212
+ /** Build metadata */
213
+ metadata?: {
214
+ /** Invocation ID */
215
+ invocationId?: string;
216
+ /** Start time */
217
+ startedOn?: string;
218
+ /** End time */
219
+ finishedOn?: string;
220
+ };
221
+ /** Byproducts of the build */
222
+ byproducts?: SLSAResourceDescriptor[];
223
+ };
224
+ }
225
+
226
+ /**
227
+ * SLSA Resource Descriptor
228
+ */
229
+ export interface SLSAResourceDescriptor {
230
+ /** Resource URI */
231
+ uri?: string;
232
+ /** Resource digest */
233
+ digest?: {
234
+ sha256?: string;
235
+ sha512?: string;
236
+ [algorithm: string]: string | undefined;
237
+ };
238
+ /** Resource name */
239
+ name?: string;
240
+ /** Download location */
241
+ downloadLocation?: string;
242
+ /** Media type */
243
+ mediaType?: string;
244
+ /** Content (for inline resources) */
245
+ content?: string;
246
+ /** Annotations */
247
+ annotations?: Record<string, unknown>;
248
+ }
249
+
250
+ // ============================================================================
251
+ // Sigstore Bundle Types
252
+ // ============================================================================
253
+
254
+ // Note: SigstoreBundle is imported from sigstore and re-exported at the top of this file.
255
+ // The following interface provides additional type information for transparency log entries
256
+ // that we may extract from bundles for our own processing.
257
+
258
+ /**
259
+ * Transparency log entry in bundle format (for reference/extraction)
260
+ */
261
+ export interface TransparencyLogEntry {
262
+ /** Log index */
263
+ logIndex: string;
264
+ /** Log ID */
265
+ logId: {
266
+ keyId: string; // base64
267
+ };
268
+ /** Entry kind and version */
269
+ kindVersion: {
270
+ kind: "hashedrekord" | "intoto" | "dsse";
271
+ version: string;
272
+ };
273
+ /** Integrated time (Unix timestamp) */
274
+ integratedTime: string;
275
+ /** Inclusion promise */
276
+ inclusionPromise?: {
277
+ signedEntryTimestamp: string; // base64
278
+ };
279
+ /** Inclusion proof */
280
+ inclusionProof?: {
281
+ logIndex: string;
282
+ rootHash: string; // base64
283
+ treeSize: string;
284
+ hashes: string[]; // base64
285
+ checkpoint: {
286
+ envelope: string;
287
+ };
288
+ };
289
+ /** Canonicalized body */
290
+ canonicalizedBody: string; // base64
291
+ }
292
+
293
+ // ============================================================================
294
+ // Signing and Verification Types
295
+ // ============================================================================
296
+
297
+ /**
298
+ * Options for signing an artifact
299
+ */
300
+ export interface SigningOptions {
301
+ /** OIDC options for keyless signing */
302
+ oidc?: OIDCOptions;
303
+ /** Use public Sigstore infrastructure (default: true) */
304
+ usePublicInstance?: boolean;
305
+ /** Custom Fulcio URL */
306
+ fulcioURL?: string;
307
+ /** Custom Rekor URL */
308
+ rekorURL?: string;
309
+ /** Custom TSA (Timestamp Authority) URL */
310
+ tsaURL?: string;
311
+ /** Timeout in milliseconds */
312
+ timeout?: number;
313
+ }
314
+
315
+ /**
316
+ * Result of a signing operation
317
+ */
318
+ export interface SigningResult {
319
+ /** The signed bundle */
320
+ bundle: SigstoreBundle;
321
+ /** Signing certificate (if keyless signing used) */
322
+ certificate?: FulcioCertificate;
323
+ /** Rekor log entry */
324
+ rekorEntry?: RekorEntry;
325
+ /** Timestamp of signing */
326
+ timestamp: Date;
327
+ }
328
+
329
+ /**
330
+ * Options for verifying an artifact
331
+ */
332
+ export interface VerificationOptions {
333
+ /** Trust root to use (default: public Sigstore TUF root) */
334
+ trustRoot?: TrustRoot;
335
+ /** Expected identity to verify against */
336
+ expectedIdentity?: ExpectedIdentity;
337
+ /** Use public Sigstore infrastructure (default: true) */
338
+ usePublicInstance?: boolean;
339
+ /** Verify certificate transparency (default: true) */
340
+ verifyCertificateTransparency?: boolean;
341
+ /** Verify timestamp (default: true) */
342
+ verifyTimestamp?: boolean;
343
+ /** Timeout in milliseconds */
344
+ timeout?: number;
345
+ }
346
+
347
+ /**
348
+ * Expected identity for verification
349
+ */
350
+ export interface ExpectedIdentity {
351
+ /** Expected certificate subject (email or URI) */
352
+ subjectAlternativeName?: string;
353
+ /** Expected OIDC issuer */
354
+ issuer?: string;
355
+ /** Expected GitHub workflow repository */
356
+ workflowRepository?: string;
357
+ /** Expected GitHub workflow ref */
358
+ workflowRef?: string;
359
+ }
360
+
361
+ /**
362
+ * Result of a verification operation
363
+ */
364
+ export interface VerificationResult {
365
+ /** Whether verification succeeded */
366
+ verified: boolean;
367
+ /** Error message if verification failed */
368
+ error?: string;
369
+ /** Details about verification checks */
370
+ details: VerificationDetails;
371
+ /** Extracted identity from certificate */
372
+ identity?: OIDCIdentity;
373
+ /** Timestamp of artifact creation (from Rekor) */
374
+ timestamp?: Date;
375
+ }
376
+
377
+ /**
378
+ * Detailed verification check results
379
+ */
380
+ export interface VerificationDetails {
381
+ /** Signature verification passed */
382
+ signatureValid: boolean;
383
+ /** Certificate chain valid */
384
+ certificateValid: boolean;
385
+ /** Certificate within validity period (at signing time) */
386
+ certificateWithinValidity: boolean;
387
+ /** Rekor entry found and valid */
388
+ rekorEntryValid: boolean;
389
+ /** Inclusion proof verified */
390
+ inclusionProofValid: boolean;
391
+ /** Identity matches expected (if specified) */
392
+ identityMatches?: boolean;
393
+ /** Individual check errors */
394
+ errors: string[];
395
+ }
396
+
397
+ // ============================================================================
398
+ // Trust Root Types
399
+ // ============================================================================
400
+
401
+ /**
402
+ * Trust root for Sigstore verification
403
+ */
404
+ export interface TrustRoot {
405
+ /** Trusted certificate authorities (for Fulcio) */
406
+ certificateAuthorities: CertificateAuthority[];
407
+ /** Trusted transparency logs (for Rekor) */
408
+ transparencyLogs: TransparencyLog[];
409
+ /** Timestamp authorities */
410
+ timestampAuthorities?: TimestampAuthority[];
411
+ }
412
+
413
+ /**
414
+ * Certificate authority configuration
415
+ */
416
+ export interface CertificateAuthority {
417
+ /** CA subject */
418
+ subject: {
419
+ organization?: string;
420
+ commonName?: string;
421
+ };
422
+ /** Root certificate (PEM or DER) */
423
+ rootCertificate: string;
424
+ /** Certificate chain (if intermediate CAs) */
425
+ certificateChain?: string[];
426
+ /** Validity period */
427
+ validFor: {
428
+ start: Date;
429
+ end?: Date;
430
+ };
431
+ }
432
+
433
+ /**
434
+ * Transparency log configuration
435
+ */
436
+ export interface TransparencyLog {
437
+ /** Log ID */
438
+ logId: string;
439
+ /** Log public key */
440
+ publicKey: string;
441
+ /** Log URL */
442
+ baseUrl: string;
443
+ /** Hash algorithm used */
444
+ hashAlgorithm: "sha256" | "sha384" | "sha512";
445
+ /** Validity period */
446
+ validFor: {
447
+ start: Date;
448
+ end?: Date;
449
+ };
450
+ }
451
+
452
+ /**
453
+ * Timestamp authority configuration
454
+ */
455
+ export interface TimestampAuthority {
456
+ /** TSA subject */
457
+ subject: {
458
+ organization?: string;
459
+ commonName?: string;
460
+ };
461
+ /** TSA certificate chain */
462
+ certificateChain: string[];
463
+ /** Validity period */
464
+ validFor: {
465
+ start: Date;
466
+ end?: Date;
467
+ };
468
+ }
469
+
470
+ // ============================================================================
471
+ // Trust Policy Types
472
+ // ============================================================================
473
+
474
+ /**
475
+ * Trust policy for evaluating attestations
476
+ */
477
+ export interface TrustPolicy {
478
+ /** Policy name */
479
+ name: string;
480
+ /** Policy version */
481
+ version: string;
482
+ /** Trusted publishers (by identity) */
483
+ trustedPublishers: TrustedIdentityRule[];
484
+ /** Trusted auditors (can vouch for tools) */
485
+ trustedAuditors: TrustedIdentityRule[];
486
+ /** Required attestation types */
487
+ requiredAttestations?: string[];
488
+ /** Minimum SLSA level required */
489
+ minimumSLSALevel?: 0 | 1 | 2 | 3 | 4;
490
+ /** Allow unsigned tools (default: false) */
491
+ allowUnsigned?: boolean;
492
+ /** Cache verification results */
493
+ cacheResults?: boolean;
494
+ }
495
+
496
+ /**
497
+ * Rule for matching trusted identities
498
+ */
499
+ export interface TrustedIdentityRule {
500
+ /** Rule name/description */
501
+ name: string;
502
+ /** Identity type */
503
+ type: "email" | "github-workflow" | "gitlab-pipeline" | "uri";
504
+ /** Pattern to match (supports glob) */
505
+ pattern: string;
506
+ /** Expected OIDC issuer */
507
+ issuer?: string;
508
+ /** Required claims */
509
+ requiredClaims?: Record<string, string | string[]>;
510
+ }
511
+
512
+ /**
513
+ * Result of trust policy evaluation
514
+ */
515
+ export interface TrustPolicyResult {
516
+ /** Whether the artifact is trusted */
517
+ trusted: boolean;
518
+ /** Trust level (0 = unsigned, 1-4 = SLSA levels) */
519
+ trustLevel: 0 | 1 | 2 | 3 | 4;
520
+ /** Matched publisher rule (if any) */
521
+ matchedPublisher?: TrustedIdentityRule;
522
+ /** Matched auditor rules (if any) */
523
+ matchedAuditors: TrustedIdentityRule[];
524
+ /** Policy evaluation details */
525
+ details: {
526
+ /** All verified attestations */
527
+ attestations: VerifiedAttestation[];
528
+ /** Policy violations */
529
+ violations: string[];
530
+ /** Warnings */
531
+ warnings: string[];
532
+ };
533
+ }
534
+
535
+ /**
536
+ * A verified attestation with metadata
537
+ */
538
+ export interface VerifiedAttestation {
539
+ /** Attestation type */
540
+ type: string;
541
+ /** Predicate type */
542
+ predicateType: string;
543
+ /** Signer identity */
544
+ signer: OIDCIdentity;
545
+ /** Verification timestamp */
546
+ verifiedAt: Date;
547
+ /** Full attestation content */
548
+ attestation: InTotoStatement;
549
+ }
550
+
551
+ // ============================================================================
552
+ // Enact-specific Types
553
+ // ============================================================================
554
+
555
+ /**
556
+ * Enact tool attestation predicate
557
+ */
558
+ export interface EnactToolPredicate {
559
+ /** Enact-specific predicate type */
560
+ type: "https://enact.tools/attestation/tool/v1";
561
+ /** Tool metadata */
562
+ tool: {
563
+ /** Tool name */
564
+ name: string;
565
+ /** Tool version */
566
+ version: string;
567
+ /** Tool publisher */
568
+ publisher: string;
569
+ /** Tool description */
570
+ description?: string;
571
+ /** Tool repository */
572
+ repository?: string;
573
+ };
574
+ /** Build information */
575
+ build?: {
576
+ /** Build timestamp */
577
+ timestamp: string;
578
+ /** Build environment */
579
+ environment?: Record<string, string>;
580
+ /** Source commit */
581
+ sourceCommit?: string;
582
+ };
583
+ /** Security audit information */
584
+ audit?: {
585
+ /** Auditor identity */
586
+ auditor: string;
587
+ /** Audit timestamp */
588
+ timestamp: string;
589
+ /** Audit result */
590
+ result: "passed" | "passed-with-warnings" | "failed";
591
+ /** Audit notes */
592
+ notes?: string;
593
+ };
594
+ }
595
+
596
+ /**
597
+ * Enact attestation bundle (tool manifest + attestations)
598
+ */
599
+ export interface EnactAttestationBundle {
600
+ /** Bundle format version */
601
+ version: "1.0";
602
+ /** Tool manifest hash */
603
+ manifestHash: {
604
+ algorithm: "sha256";
605
+ digest: string;
606
+ };
607
+ /** Publisher attestation (required) */
608
+ publisherAttestation: SigstoreBundle;
609
+ /** Auditor attestations (optional) */
610
+ auditorAttestations?: SigstoreBundle[];
611
+ /** Provenance attestation (optional) */
612
+ provenanceAttestation?: SigstoreBundle;
613
+ }