1"use strict"; 2Object.defineProperty(exports, "__esModule", { value: true }); 3exports.toDSSEBundle = exports.toMessageSignatureBundle = void 0; 4/* 5Copyright 2023 The Sigstore Authors. 6 7Licensed under the Apache License, Version 2.0 (the "License"); 8you may not use this file except in compliance with the License. 9You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13Unless required by applicable law or agreed to in writing, software 14distributed under the License is distributed on an "AS IS" BASIS, 15WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16See the License for the specific language governing permissions and 17limitations under the License. 18*/ 19const protobuf_specs_1 = require("@sigstore/protobuf-specs"); 20const bundle_1 = require("./bundle"); 21// Message signature bundle - $case: 'messageSignature' 22function toMessageSignatureBundle(options) { 23 return { 24 mediaType: bundle_1.BUNDLE_V02_MEDIA_TYPE, 25 content: { 26 $case: 'messageSignature', 27 messageSignature: { 28 messageDigest: { 29 algorithm: protobuf_specs_1.HashAlgorithm.SHA2_256, 30 digest: options.digest, 31 }, 32 signature: options.signature, 33 }, 34 }, 35 verificationMaterial: toVerificationMaterial(options), 36 }; 37} 38exports.toMessageSignatureBundle = toMessageSignatureBundle; 39// DSSE envelope bundle - $case: 'dsseEnvelope' 40function toDSSEBundle(options) { 41 return { 42 mediaType: bundle_1.BUNDLE_V02_MEDIA_TYPE, 43 content: { 44 $case: 'dsseEnvelope', 45 dsseEnvelope: toEnvelope(options), 46 }, 47 verificationMaterial: toVerificationMaterial(options), 48 }; 49} 50exports.toDSSEBundle = toDSSEBundle; 51function toEnvelope(options) { 52 return { 53 payloadType: options.artifactType, 54 payload: options.artifact, 55 signatures: [toSignature(options)], 56 }; 57} 58function toSignature(options) { 59 return { 60 keyid: options.keyHint || '', 61 sig: options.signature, 62 }; 63} 64// Verification material 65function toVerificationMaterial(options) { 66 return { 67 content: toKeyContent(options), 68 tlogEntries: [], 69 timestampVerificationData: { rfc3161Timestamps: [] }, 70 }; 71} 72function toKeyContent(options) { 73 if (options.certificate) { 74 return { 75 $case: 'x509CertificateChain', 76 x509CertificateChain: { 77 certificates: [{ rawBytes: options.certificate }], 78 }, 79 }; 80 } 81 else { 82 return { 83 $case: 'publicKey', 84 publicKey: { 85 hint: options.keyHint || '', 86 }, 87 }; 88 } 89} 90