| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.MessageSignatureContent = void 0; |
| 4 |
/* |
| 5 |
Copyright 2023 The Sigstore Authors. |
| 6 |
|
| 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 |
|
| 11 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
|
| 13 |
Unless required by applicable law or agreed to in writing, software |
| 14 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 15 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 |
See the License for the specific language governing permissions and |
| 17 |
limitations under the License. |
| 18 |
*/ |
| 19 |
const core_1 = require("@sigstore/core"); |
| 20 |
const protobuf_specs_1 = require("@sigstore/protobuf-specs"); |
| 21 |
// Map from the Sigstore protobuf HashAlgorithm enum to |
| 22 |
// the string values used by the Node.js crypto module. |
| 23 |
const HASH_ALGORITHM_MAP = { |
| 24 |
[protobuf_specs_1.HashAlgorithm.HASH_ALGORITHM_UNSPECIFIED]: 'sha256', |
| 25 |
[protobuf_specs_1.HashAlgorithm.SHA2_256]: 'sha256', |
| 26 |
[protobuf_specs_1.HashAlgorithm.SHA2_384]: 'sha384', |
| 27 |
[protobuf_specs_1.HashAlgorithm.SHA2_512]: 'sha512', |
| 28 |
[protobuf_specs_1.HashAlgorithm.SHA3_256]: 'sha3-256', |
| 29 |
[protobuf_specs_1.HashAlgorithm.SHA3_384]: 'sha3-384', |
| 30 |
}; |
| 31 |
class MessageSignatureContent { |
| 32 |
signature; |
| 33 |
messageDigest; |
| 34 |
artifact; |
| 35 |
hashAlgorithm; |
| 36 |
constructor(messageSignature, artifact) { |
| 37 |
this.signature = messageSignature.signature; |
| 38 |
this.messageDigest = messageSignature.messageDigest.digest; |
| 39 |
this.artifact = artifact; |
| 40 |
this.hashAlgorithm = |
| 41 |
HASH_ALGORITHM_MAP[messageSignature.messageDigest.algorithm] ?? |
| 42 |
/* istanbul ignore next */ 'sha256'; |
| 43 |
} |
| 44 |
compareSignature(signature) { |
| 45 |
return core_1.crypto.bufferEqual(signature, this.signature); |
| 46 |
} |
| 47 |
compareDigest(digest) { |
| 48 |
return core_1.crypto.bufferEqual(digest, this.messageDigest); |
| 49 |
} |
| 50 |
verifySignature(key) { |
| 51 |
return core_1.crypto.verify(this.artifact, key, this.signature, this.hashAlgorithm); |
| 52 |
} |
| 53 |
} |
| 54 |
exports.MessageSignatureContent = MessageSignatureContent; |