| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.EphemeralSigner = 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 crypto_1 = require("crypto"); |
| 20 |
const EC_KEYPAIR_TYPE = 'ec'; |
| 21 |
const P256_CURVE = 'P-256'; |
| 22 |
// Signer implementation which uses an ephemeral keypair to sign artifacts. |
| 23 |
// The private key lives only in memory and is tied to the lifetime of the |
| 24 |
// EphemeralSigner instance. |
| 25 |
class EphemeralSigner { |
| 26 |
keypair; |
| 27 |
constructor() { |
| 28 |
this.keypair = (0, crypto_1.generateKeyPairSync)(EC_KEYPAIR_TYPE, { |
| 29 |
namedCurve: P256_CURVE, |
| 30 |
}); |
| 31 |
} |
| 32 |
async sign(data) { |
| 33 |
const signature = (0, crypto_1.sign)('sha256', data, this.keypair.privateKey); |
| 34 |
const publicKey = this.keypair.publicKey |
| 35 |
.export({ format: 'pem', type: 'spki' }) |
| 36 |
.toString('ascii'); |
| 37 |
return { |
| 38 |
signature: signature, |
| 39 |
key: { $case: 'publicKey', publicKey }, |
| 40 |
}; |
| 41 |
} |
| 42 |
} |
| 43 |
exports.EphemeralSigner = EphemeralSigner; |