build.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.toMessageSignatureBundle = toMessageSignatureBundle;
  4. exports.toDSSEBundle = toDSSEBundle;
  5. /*
  6. Copyright 2023 The Sigstore Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing, software
  12. distributed under the License is distributed on an "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. See the License for the specific language governing permissions and
  15. limitations under the License.
  16. */
  17. const protobuf_specs_1 = require("@sigstore/protobuf-specs");
  18. const bundle_1 = require("./bundle");
  19. // Message signature bundle - $case: 'messageSignature'
  20. function toMessageSignatureBundle(options) {
  21. return {
  22. mediaType: options.certificateChain
  23. ? bundle_1.BUNDLE_V02_MEDIA_TYPE
  24. : bundle_1.BUNDLE_V03_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. }
  38. // DSSE envelope bundle - $case: 'dsseEnvelope'
  39. function toDSSEBundle(options) {
  40. return {
  41. mediaType: options.certificateChain
  42. ? bundle_1.BUNDLE_V02_MEDIA_TYPE
  43. : bundle_1.BUNDLE_V03_MEDIA_TYPE,
  44. content: {
  45. $case: 'dsseEnvelope',
  46. dsseEnvelope: toEnvelope(options),
  47. },
  48. verificationMaterial: toVerificationMaterial(options),
  49. };
  50. }
  51. function toEnvelope(options) {
  52. return {
  53. payloadType: options.artifactType,
  54. payload: options.artifact,
  55. signatures: [toSignature(options)],
  56. };
  57. }
  58. function toSignature(options) {
  59. return {
  60. keyid: options.keyHint || '',
  61. sig: options.signature,
  62. };
  63. }
  64. // Verification material
  65. function toVerificationMaterial(options) {
  66. return {
  67. content: toKeyContent(options),
  68. tlogEntries: [],
  69. timestampVerificationData: { rfc3161Timestamps: [] },
  70. };
  71. }
  72. function toKeyContent(options) {
  73. if (options.certificate) {
  74. if (options.certificateChain) {
  75. return {
  76. $case: 'x509CertificateChain',
  77. x509CertificateChain: {
  78. certificates: [{ rawBytes: options.certificate }],
  79. },
  80. };
  81. }
  82. else {
  83. return {
  84. $case: 'certificate',
  85. certificate: { rawBytes: options.certificate },
  86. };
  87. }
  88. }
  89. else {
  90. return {
  91. $case: 'publicKey',
  92. publicKey: {
  93. hint: options.keyHint || '',
  94. },
  95. };
  96. }
  97. }