bundle.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. Licensed under the Apache License, Version 2.0 (the "License");
  41. you may not use this file except in compliance with the License.
  42. You may obtain a copy of the License at
  43. http://www.apache.org/licenses/LICENSE-2.0
  44. Unless required by applicable law or agreed to in writing, software
  45. distributed under the License is distributed on an "AS IS" BASIS,
  46. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  47. See the License for the specific language governing permissions and
  48. limitations under the License.
  49. */
  50. const sigstore = __importStar(require("@sigstore/bundle"));
  51. const util_1 = require("../util");
  52. // Helper functions for assembling the parts of a Sigstore bundle
  53. // Message signature bundle - $case: 'messageSignature'
  54. function toMessageSignatureBundle(artifact, signature) {
  55. const digest = util_1.crypto.digest('sha256', artifact.data);
  56. return sigstore.toMessageSignatureBundle({
  57. digest,
  58. signature: signature.signature,
  59. certificate: signature.key.$case === 'x509Certificate'
  60. ? util_1.pem.toDER(signature.key.certificate)
  61. : undefined,
  62. keyHint: signature.key.$case === 'publicKey' ? signature.key.hint : undefined,
  63. certificateChain: true,
  64. });
  65. }
  66. // DSSE envelope bundle - $case: 'dsseEnvelope'
  67. function toDSSEBundle(artifact, signature, certificateChain) {
  68. return sigstore.toDSSEBundle({
  69. artifact: artifact.data,
  70. artifactType: artifact.type,
  71. signature: signature.signature,
  72. certificate: signature.key.$case === 'x509Certificate'
  73. ? util_1.pem.toDER(signature.key.certificate)
  74. : undefined,
  75. keyHint: signature.key.$case === 'publicKey' ? signature.key.hint : undefined,
  76. certificateChain,
  77. });
  78. }