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