@signalapp/mock-server
Version:
Mock Signal Server for writing tests
41 lines (40 loc) • 1.7 kB
JavaScript
;
// 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 = void 0;
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));
const obj = JSON.parse(raw.toString());
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,
serverTrustRoot,
};
}
exports.load = load;