• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.TSAWitness = void 0;
4/*
5Copyright 2023 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 client_1 = require("./client");
20class TSAWitness {
21    constructor(options) {
22        this.tsa = new client_1.TSAClient({
23            tsaBaseURL: options.tsaBaseURL,
24            retry: options.retry,
25            timeout: options.timeout,
26        });
27    }
28    async testify(content) {
29        const signature = extractSignature(content);
30        const timestamp = await this.tsa.createTimestamp(signature);
31        return {
32            rfc3161Timestamps: [{ signedTimestamp: timestamp }],
33        };
34    }
35}
36exports.TSAWitness = TSAWitness;
37function extractSignature(content) {
38    switch (content.$case) {
39        case 'dsseEnvelope':
40            return content.dsseEnvelope.signatures[0].sig;
41        case 'messageSignature':
42            return content.messageSignature.signature;
43    }
44}
45