dsse.js 1.7 KB

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