| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.DSSESignatureContent = 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 |
class DSSESignatureContent { |
| 21 |
env; |
| 22 |
constructor(env) { |
| 23 |
this.env = env; |
| 24 |
} |
| 25 |
compareDigest(digest) { |
| 26 |
return core_1.crypto.bufferEqual(digest, core_1.crypto.digest('sha256', this.env.payload)); |
| 27 |
} |
| 28 |
compareSignature(signature) { |
| 29 |
return core_1.crypto.bufferEqual(signature, this.signature); |
| 30 |
} |
| 31 |
verifySignature(key) { |
| 32 |
return core_1.crypto.verify(this.preAuthEncoding, key, this.signature); |
| 33 |
} |
| 34 |
get signature() { |
| 35 |
return this.env.signatures.length > 0 |
| 36 |
? this.env.signatures[0].sig |
| 37 |
: Buffer.from(''); |
| 38 |
} |
| 39 |
// DSSE Pre-Authentication Encoding |
| 40 |
get preAuthEncoding() { |
| 41 |
return core_1.dsse.preAuthEncoding(this.env.payloadType, this.env.payload); |
| 42 |
} |
| 43 |
} |
| 44 |
exports.DSSESignatureContent = DSSESignatureContent; |