1"use strict"; 2Object.defineProperty(exports, "__esModule", { value: true }); 3exports.TSAClient = void 0; 4/* 5Copyright 2022 The Sigstore Authors. 6 7Licensed under the Apache License, Version 2.0 (the "License"); 8you may not use this file except in compliance with the License. 9You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13Unless required by applicable law or agreed to in writing, software 14distributed under the License is distributed on an "AS IS" BASIS, 15WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16See the License for the specific language governing permissions and 17limitations under the License. 18*/ 19const error_1 = require("../error"); 20const external_1 = require("../external"); 21const util_1 = require("../util"); 22class TSAClient { 23 constructor(options) { 24 this.tsa = new external_1.TimestampAuthority({ 25 baseURL: options.tsaBaseURL, 26 retry: options.retry, 27 timeout: options.timeout, 28 }); 29 } 30 async createTimestamp(signature) { 31 const request = { 32 artifactHash: util_1.crypto.hash(signature).toString('base64'), 33 hashAlgorithm: 'sha256', 34 }; 35 try { 36 return await this.tsa.createTimestamp(request); 37 } 38 catch (err) { 39 throw new error_1.InternalError({ 40 code: 'TSA_CREATE_TIMESTAMP_ERROR', 41 message: 'error creating timestamp', 42 cause: err, 43 }); 44 } 45 } 46} 47exports.TSAClient = TSAClient; 48