| 1 |
"use strict"; |
| 2 |
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { |
| 3 |
if (k2 === undefined) k2 = k; |
| 4 |
var desc = Object.getOwnPropertyDescriptor(m, k); |
| 5 |
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { |
| 6 |
desc = { enumerable: true, get: function() { return m[k]; } }; |
| 7 |
} |
| 8 |
Object.defineProperty(o, k2, desc); |
| 9 |
}) : (function(o, m, k, k2) { |
| 10 |
if (k2 === undefined) k2 = k; |
| 11 |
o[k2] = m[k]; |
| 12 |
})); |
| 13 |
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { |
| 14 |
Object.defineProperty(o, "default", { enumerable: true, value: v }); |
| 15 |
}) : function(o, v) { |
| 16 |
o["default"] = v; |
| 17 |
}); |
| 18 |
var __importStar = (this && this.__importStar) || (function () { |
| 19 |
var ownKeys = function(o) { |
| 20 |
ownKeys = Object.getOwnPropertyNames || function (o) { |
| 21 |
var ar = []; |
| 22 |
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; |
| 23 |
return ar; |
| 24 |
}; |
| 25 |
return ownKeys(o); |
| 26 |
}; |
| 27 |
return function (mod) { |
| 28 |
if (mod && mod.__esModule) return mod; |
| 29 |
var result = {}; |
| 30 |
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); |
| 31 |
__setModuleDefault(result, mod); |
| 32 |
return result; |
| 33 |
}; |
| 34 |
})(); |
| 35 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 36 |
exports.toMessageSignatureBundle = toMessageSignatureBundle; |
| 37 |
exports.toDSSEBundle = toDSSEBundle; |
| 38 |
/* |
| 39 |
Copyright 2023 The Sigstore Authors. |
| 40 |
|
| 41 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 42 |
you may not use this file except in compliance with the License. |
| 43 |
You may obtain a copy of the License at |
| 44 |
|
| 45 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 46 |
|
| 47 |
Unless required by applicable law or agreed to in writing, software |
| 48 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 49 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 50 |
See the License for the specific language governing permissions and |
| 51 |
limitations under the License. |
| 52 |
*/ |
| 53 |
const sigstore = __importStar(require("@sigstore/bundle")); |
| 54 |
const util_1 = require("../util"); |
| 55 |
// Helper functions for assembling the parts of a Sigstore bundle |
| 56 |
// Message signature bundle - $case: 'messageSignature' |
| 57 |
function toMessageSignatureBundle(artifact, signature) { |
| 58 |
const digest = util_1.crypto.digest('sha256', artifact.data); |
| 59 |
return sigstore.toMessageSignatureBundle({ |
| 60 |
digest, |
| 61 |
signature: signature.signature, |
| 62 |
certificate: signature.key.$case === 'x509Certificate' |
| 63 |
? util_1.pem.toDER(signature.key.certificate) |
| 64 |
: undefined, |
| 65 |
keyHint: signature.key.$case === 'publicKey' ? signature.key.hint : undefined, |
| 66 |
certificateChain: true, |
| 67 |
}); |
| 68 |
} |
| 69 |
// DSSE envelope bundle - $case: 'dsseEnvelope' |
| 70 |
function toDSSEBundle(artifact, signature, certificateChain) { |
| 71 |
return sigstore.toDSSEBundle({ |
| 72 |
artifact: artifact.data, |
| 73 |
artifactType: artifact.type, |
| 74 |
signature: signature.signature, |
| 75 |
certificate: signature.key.$case === 'x509Certificate' |
| 76 |
? util_1.pem.toDER(signature.key.certificate) |
| 77 |
: undefined, |
| 78 |
keyHint: signature.key.$case === 'publicKey' ? signature.key.hint : undefined, |
| 79 |
certificateChain, |
| 80 |
}); |
| 81 |
} |