| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.TUFError = exports.DEFAULT_MIRROR_URL = void 0; |
| 4 |
exports.getTrustedRoot = getTrustedRoot; |
| 5 |
exports.initTUF = initTUF; |
| 6 |
/* |
| 7 |
Copyright 2023 The Sigstore Authors. |
| 8 |
|
| 9 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 |
you may not use this file except in compliance with the License. |
| 11 |
You may obtain a copy of the License at |
| 12 |
|
| 13 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 14 |
|
| 15 |
Unless required by applicable law or agreed to in writing, software |
| 16 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 17 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 |
See the License for the specific language governing permissions and |
| 19 |
limitations under the License. |
| 20 |
*/ |
| 21 |
const protobuf_specs_1 = require("@sigstore/protobuf-specs"); |
| 22 |
const appdata_1 = require("./appdata"); |
| 23 |
const client_1 = require("./client"); |
| 24 |
exports.DEFAULT_MIRROR_URL = 'https://tuf-repo-cdn.sigstore.dev'; |
| 25 |
const DEFAULT_CACHE_DIR = 'sigstore-js'; |
| 26 |
const DEFAULT_RETRY = { retries: 2 }; |
| 27 |
const DEFAULT_TIMEOUT = 5000; |
| 28 |
const TRUSTED_ROOT_TARGET = 'trusted_root.json'; |
| 29 |
async function getTrustedRoot( |
| 30 |
/* istanbul ignore next */ |
| 31 |
options = {}) { |
| 32 |
const client = createClient(options); |
| 33 |
const trustedRoot = await client.getTarget(TRUSTED_ROOT_TARGET); |
| 34 |
return protobuf_specs_1.TrustedRoot.fromJSON(JSON.parse(trustedRoot)); |
| 35 |
} |
| 36 |
async function initTUF( |
| 37 |
/* istanbul ignore next */ |
| 38 |
options = {}) { |
| 39 |
const client = createClient(options); |
| 40 |
return client.refresh().then(() => client); |
| 41 |
} |
| 42 |
// Create a TUF client with default options |
| 43 |
function 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 |
} |
| 55 |
var error_1 = require("./error"); |
| 56 |
Object.defineProperty(exports, "TUFError", { enumerable: true, get: function () { return error_1.TUFError; } }); |