1"use strict"; 2Object.defineProperty(exports, "__esModule", { value: true }); 3exports.TUFError = exports.initTUF = exports.getTrustedRoot = 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 protobuf_specs_1 = require("@sigstore/protobuf-specs"); 20const appdata_1 = require("./appdata"); 21const client_1 = require("./client"); 22const DEFAULT_CACHE_DIR = 'sigstore-js'; 23const DEFAULT_MIRROR_URL = 'https://tuf-repo-cdn.sigstore.dev'; 24const DEFAULT_TUF_ROOT_PATH = '../store/public-good-instance-root.json'; 25const DEFAULT_RETRY = { retries: 2 }; 26const DEFAULT_TIMEOUT = 5000; 27const TRUSTED_ROOT_TARGET = 'trusted_root.json'; 28async function getTrustedRoot( 29/* istanbul ignore next */ 30options = {}) { 31 const client = createClient(options); 32 const trustedRoot = await client.getTarget(TRUSTED_ROOT_TARGET); 33 return protobuf_specs_1.TrustedRoot.fromJSON(JSON.parse(trustedRoot)); 34} 35exports.getTrustedRoot = getTrustedRoot; 36async function initTUF( 37/* istanbul ignore next */ 38options = {}) { 39 const client = createClient(options); 40 return client.refresh().then(() => client); 41} 42exports.initTUF = initTUF; 43// Create a TUF client with default options 44function createClient(options) { 45 /* istanbul ignore next */ 46 return new client_1.TUFClient({ 47 cachePath: options.cachePath || (0, appdata_1.appDataPath)(DEFAULT_CACHE_DIR), 48 rootPath: options.rootPath || require.resolve(DEFAULT_TUF_ROOT_PATH), 49 mirrorURL: options.mirrorURL || DEFAULT_MIRROR_URL, 50 retry: options.retry ?? DEFAULT_RETRY, 51 timeout: options.timeout ?? DEFAULT_TIMEOUT, 52 }); 53} 54var error_1 = require("./error"); 55Object.defineProperty(exports, "TUFError", { enumerable: true, get: function () { return error_1.TUFError; } }); 56