| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.DSSEBundleBuilder = void 0; |
| 4 |
/* |
| 5 |
Copyright 2023 The Sigstore Authors. |
| 6 |
|
| 7 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 |
you may not use this file except in compliance with the License. |
| 9 |
You may obtain a copy of the License at |
| 10 |
|
| 11 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
|
| 13 |
Unless required by applicable law or agreed to in writing, software |
| 14 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 15 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 |
See the License for the specific language governing permissions and |
| 17 |
limitations under the License. |
| 18 |
*/ |
| 19 |
const util_1 = require("../util"); |
| 20 |
const base_1 = require("./base"); |
| 21 |
const bundle_1 = require("./bundle"); |
| 22 |
// BundleBuilder implementation for DSSE wrapped attestations |
| 23 |
class DSSEBundleBuilder extends base_1.BaseBundleBuilder { |
| 24 |
certificateChain; |
| 25 |
constructor(options) { |
| 26 |
super(options); |
| 27 |
this.certificateChain = options.certificateChain ?? false; |
| 28 |
} |
| 29 |
// DSSE requires the artifact to be pre-encoded with the payload type |
| 30 |
// before the signature is generated. |
| 31 |
async prepare(artifact) { |
| 32 |
const a = artifactDefaults(artifact); |
| 33 |
return util_1.dsse.preAuthEncoding(a.type, a.data); |
| 34 |
} |
| 35 |
// Packages the artifact and signature into a DSSE bundle |
| 36 |
async package(artifact, signature) { |
| 37 |
return (0, bundle_1.toDSSEBundle)(artifactDefaults(artifact), signature, this.certificateChain); |
| 38 |
} |
| 39 |
} |
| 40 |
exports.DSSEBundleBuilder = DSSEBundleBuilder; |
| 41 |
// Defaults the artifact type to an empty string if not provided |
| 42 |
function artifactDefaults(artifact) { |
| 43 |
return { |
| 44 |
...artifact, |
| 45 |
type: artifact.type ?? '', |
| 46 |
}; |
| 47 |
} |