UNPKG

@signalapp/mock-server

Version:
42 lines (41 loc) 1.88 kB
"use strict"; // Copyright 2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.load = load; const assert_1 = __importDefault(require("assert")); const promises_1 = __importDefault(require("fs/promises")); const path_1 = __importDefault(require("path")); const CERTS_DIR = path_1.default.join(__dirname, '..', '..', 'certs'); async function loadString(file) { const raw = await promises_1.default.readFile(path_1.default.join(CERTS_DIR, file)); return raw.toString(); } async function loadJSONProperty(file, property) { const raw = await promises_1.default.readFile(path_1.default.join(CERTS_DIR, file)); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const obj = JSON.parse(raw.toString()); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment const value = obj[property]; (0, assert_1.default)(typeof value === 'string', `Expected string at: ${file}/${property}`); return value; } async function load() { const [certificateAuthority, genericServerPublicParams, backupServerPublicParams, serverPublicParams, serverTrustRoot,] = await Promise.all([ loadString('ca-cert.pem'), loadJSONProperty('zk-params.json', 'genericPublicParams'), loadJSONProperty('zk-params.json', 'backupPublicParams'), loadJSONProperty('zk-params.json', 'publicParams'), loadJSONProperty('trust-root.json', 'publicKey'), ]); return { certificateAuthority, genericServerPublicParams, backupServerPublicParams, serverPublicParams, serverTrustRoots: [serverTrustRoot], }; }