@@ -13,26 +13,54 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
- import {
16
+ import { Bundle , HashAlgorithm } from '@sigstore/protobuf-specs' ;
17
+ import { encoding as enc , pem } from '../../util' ;
18
+ import { SignatureMaterial } from '../signature' ;
19
+ import { ValidBundle , assertValidBundle } from './validate' ;
20
+
21
+ import type {
17
22
ArtifactVerificationOptions ,
18
- Bundle ,
19
23
Envelope ,
20
- HashAlgorithm ,
21
24
TimestampVerificationData ,
22
25
TransparencyLogEntry ,
23
26
VerificationMaterial ,
24
27
} from '@sigstore/protobuf-specs' ;
25
- import { encoding as enc , pem } from '../../util' ;
26
- import { x509Certificate } from '../../x509/cert' ;
27
- import { WithRequired } from '../utility' ;
28
- import { ValidBundle , assertValidBundle } from './validate' ;
29
-
30
28
import type { Entry , ProposedEntry } from '../../external/rekor' ;
31
- import type { SignatureMaterial } from '../signature' ;
29
+ import type { WithRequired } from '../utility' ;
30
+ import type { SerializedBundle } from './serialized' ;
32
31
33
- export * from '@sigstore/protobuf-specs' ;
34
- export * from './serialized' ;
35
- export * from './validate' ;
32
+ // Enums from protobuf-specs
33
+ // TODO: Move Envelope to "type" export once @sigstore/sign is a thing
34
+ export {
35
+ Envelope ,
36
+ HashAlgorithm ,
37
+ PublicKeyDetails ,
38
+ SubjectAlternativeNameType ,
39
+ } from '@sigstore/protobuf-specs' ;
40
+ // Types from protobuf-specs
41
+ export type {
42
+ ArtifactVerificationOptions ,
43
+ ArtifactVerificationOptions_CtlogOptions ,
44
+ ArtifactVerificationOptions_TlogOptions ,
45
+ CertificateAuthority ,
46
+ CertificateIdentities ,
47
+ CertificateIdentity ,
48
+ MessageSignature ,
49
+ ObjectIdentifierValuePair ,
50
+ PublicKey ,
51
+ PublicKeyIdentifier ,
52
+ RFC3161SignedTimestamp ,
53
+ Signature ,
54
+ SubjectAlternativeName ,
55
+ TimestampVerificationData ,
56
+ TransparencyLogEntry ,
57
+ TransparencyLogInstance ,
58
+ TrustedRoot ,
59
+ X509Certificate ,
60
+ X509CertificateChain ,
61
+ } from '@sigstore/protobuf-specs' ;
62
+ export type { SerializedBundle , SerializedEnvelope } from './serialized' ;
63
+ export type { ValidBundle as Bundle } ;
36
64
37
65
// eslint-disable-next-line @typescript-eslint/no-explicit-any
38
66
export const bundleFromJSON = ( obj : any ) : ValidBundle => {
@@ -41,26 +69,17 @@ export const bundleFromJSON = (obj: any): ValidBundle => {
41
69
return bundle ;
42
70
} ;
43
71
72
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
+ export const bundleToJSON = ( bundle : ValidBundle ) : SerializedBundle => {
74
+ return Bundle . toJSON ( bundle ) as SerializedBundle ;
75
+ } ;
76
+
44
77
const BUNDLE_MEDIA_TYPE =
45
78
'application/vnd.dev.sigstore.bundle+json;version=0.1' ;
46
79
47
- // Subset of sigstore.Bundle that has verification material as part
48
- // of the bundle
49
- export type BundleWithVerificationMaterial = WithRequired <
50
- Bundle ,
51
- 'verificationMaterial'
52
- > ;
53
-
54
- // Type guard for narrowing a Bundle to a BundleWithVerificationMaterial
55
- export function isBundleWithVerificationMaterial (
56
- bundle : Bundle
57
- ) : bundle is BundleWithVerificationMaterial {
58
- return bundle . verificationMaterial !== undefined ;
59
- }
60
-
61
80
// Subset of sigstore.Bundle that has a certificate chain as part
62
81
// of the verification material (as opposed to a public key)
63
- export type BundleWithCertificateChain = Bundle & {
82
+ export type BundleWithCertificateChain = ValidBundle & {
64
83
verificationMaterial : VerificationMaterial & {
65
84
content : Extract <
66
85
VerificationMaterial [ 'content' ] ,
@@ -71,10 +90,9 @@ export type BundleWithCertificateChain = Bundle & {
71
90
72
91
// Type guard for narrowing a Bundle to a BundleWithCertificateChain
73
92
export function isBundleWithCertificateChain (
74
- bundle : Bundle
93
+ bundle : ValidBundle
75
94
) : bundle is BundleWithCertificateChain {
76
95
return (
77
- isBundleWithVerificationMaterial ( bundle ) &&
78
96
bundle . verificationMaterial . content !== undefined &&
79
97
bundle . verificationMaterial . content . $case === 'x509CertificateChain'
80
98
) ;
@@ -122,6 +140,9 @@ export function isVerifiableTransparencyLogEntry(
122
140
) ;
123
141
}
124
142
143
+ // All of the following functions are used to construct a ValidBundle
144
+ // from various types of input. When this code moves into the
145
+ // @sigstore /sign package, these functions will be exported from there.
125
146
export function toDSSEBundle ( {
126
147
envelope,
127
148
signature,
@@ -132,7 +153,7 @@ export function toDSSEBundle({
132
153
signature : SignatureMaterial ;
133
154
tlogEntry ?: Entry ;
134
155
timestamp ?: Buffer ;
135
- } ) : Bundle {
156
+ } ) : ValidBundle {
136
157
return {
137
158
mediaType : BUNDLE_MEDIA_TYPE ,
138
159
content : { $case : 'dsseEnvelope' , dsseEnvelope : envelope } ,
@@ -154,7 +175,7 @@ export function toMessageSignatureBundle({
154
175
signature : SignatureMaterial ;
155
176
tlogEntry ?: Entry ;
156
177
timestamp ?: Buffer ;
157
- } ) : Bundle {
178
+ } ) : ValidBundle {
158
179
return {
159
180
mediaType : BUNDLE_MEDIA_TYPE ,
160
181
content : {
@@ -210,7 +231,7 @@ function toVerificationMaterial({
210
231
signature : SignatureMaterial ;
211
232
tlogEntry ?: Entry ;
212
233
timestamp ?: Buffer ;
213
- } ) : VerificationMaterial {
234
+ } ) : ValidBundle [ 'verificationMaterial' ] {
214
235
return {
215
236
content : signature . certificates
216
237
? toVerificationMaterialx509CertificateChain ( signature . certificates )
@@ -224,7 +245,7 @@ function toVerificationMaterial({
224
245
225
246
function toVerificationMaterialx509CertificateChain (
226
247
certificates : string [ ]
227
- ) : VerificationMaterial [ 'content' ] {
248
+ ) : ValidBundle [ 'verificationMaterial' ] [ 'content' ] {
228
249
return {
229
250
$case : 'x509CertificateChain' ,
230
251
x509CertificateChain : {
@@ -237,7 +258,7 @@ function toVerificationMaterialx509CertificateChain(
237
258
238
259
function toVerificationMaterialPublicKey (
239
260
hint : string
240
- ) : VerificationMaterial [ 'content' ] {
261
+ ) : ValidBundle [ 'verificationMaterial' ] [ 'content' ] {
241
262
return { $case : 'publicKey' , publicKey : { hint } } ;
242
263
}
243
264
@@ -248,15 +269,3 @@ function toTimestampVerificationData(
248
269
rfc3161Timestamps : [ { signedTimestamp : timestamp } ] ,
249
270
} ;
250
271
}
251
-
252
- export function signingCertificate (
253
- bundle : Bundle
254
- ) : x509Certificate | undefined {
255
- if ( ! isBundleWithCertificateChain ( bundle ) ) {
256
- return undefined ;
257
- }
258
-
259
- const signingCert =
260
- bundle . verificationMaterial . content . x509CertificateChain . certificates [ 0 ] ;
261
- return x509Certificate . parse ( signingCert . rawBytes ) ;
262
- }
0 commit comments