Debian Codegraph @

node_modules/@sigstore/sign/dist/external/rekor.js

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.Rekor = 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 fetch_1 = require("./fetch");
20 /**
21 * Rekor API client.
22 */
23 class Rekor {
24 options;
25 constructor(options) {
26 this.options = options;
27 }
28 /**
29 * Create a new entry in the Rekor log.
30 * @param propsedEntry {ProposedEntry} Data to create a new entry
31 * @returns {Promise<Entry>} The created entry
32 */
33 async createEntry(propsedEntry) {
34 const { baseURL, timeout, retry } = this.options;
35 const url = `${baseURL}/api/v1/log/entries`;
36 const response = await (0, fetch_1.fetchWithRetry)(url, {
37 headers: {
38 'Content-Type': 'application/json',
39 Accept: 'application/json',
40 },
41 body: JSON.stringify(propsedEntry),
42 timeout,
43 retry,
44 });
45 const data = await response.json();
46 return entryFromResponse(data);
47 }
48 /**
49 * Get an entry from the Rekor log.
50 * @param uuid {string} The UUID of the entry to retrieve
51 * @returns {Promise<Entry>} The retrieved entry
52 */
53 async getEntry(uuid) {
54 const { baseURL, timeout, retry } = this.options;
55 const url = `${baseURL}/api/v1/log/entries/${uuid}`;
56 const response = await (0, fetch_1.fetchWithRetry)(url, {
57 method: 'GET',
58 headers: {
59 Accept: 'application/json',
60 },
61 timeout,
62 retry,
63 });
64 const data = await response.json();
65 return entryFromResponse(data);
66 }
67 }
68 exports.Rekor = Rekor;
69 // Unpack the response from the Rekor API into a more convenient format.
70 function entryFromResponse(data) {
71 const entries = Object.entries(data);
72 if (entries.length != 1) {
73 throw new Error('Received multiple entries in Rekor response');
74 }
75 // Grab UUID and entry data from the response
76 const [uuid, entry] = entries[0];
77 return {
78 ...entry,
79 uuid,
80 };
81 }