"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDebugMode = isDebugMode;
exports.isDebugModeAnd = isDebugModeAnd;
exports.isServiceMode = isServiceMode;
exports.getHashedDevKey = getHashedDevKey;
exports.getDevPublicKeys = getDevPublicKeys;
exports.ensureKeySecurity = ensureKeySecurity;
exports.getDevPublicKey = getDevPublicKey;
exports.getDevPublicKeyMaxLevel = getDevPublicKeyMaxLevel;
exports.getMultisigPublicKeys = getMultisigPublicKeys;
exports.getMultisigPublicKey = getMultisigPublicKey;
exports.ensureMultisigKeySecurity = ensureMultisigKeySecurity;
const shardus_types_1 = require("../shardus/shardus-types");
const Context_1 = require("../p2p/Context");
function isDebugMode() {
    return !!(Context_1.config && Context_1.config.mode && Context_1.config.mode.toLowerCase && Context_1.config.mode.toLowerCase() === shardus_types_1.ServerMode.Debug);
}
function isDebugModeAnd(predicate) {
    return isDebugMode() && !!predicate(Context_1.config.debug || {});
}
function isServiceMode() {
    return Context_1.config && Context_1.config.features && Context_1.config.features.startInServiceMode;
}
function getHashedDevKey() {
    return Context_1.config?.debug?.hashedDevAuth || '';
}
function getDevPublicKeys() {
    return Context_1.config?.debug?.devPublicKeys || {};
}
function ensureKeySecurity(pubKey, level) {
    const devPublicKeys = getDevPublicKeys();
    // eslint-disable-next-line security/detect-object-injection
    const pkClearance = devPublicKeys[pubKey];
    return pkClearance !== undefined && pkClearance >= level;
}
function getDevPublicKey(key) {
    const devPublicKeys = getDevPublicKeys();
    // eslint-disable-next-line security/detect-object-injection
    const pkClearance = devPublicKeys[key];
    if (pkClearance !== undefined)
        return key;
    return null;
}
function getDevPublicKeyMaxLevel(clearance) {
    const devPublicKeys = getDevPublicKeys();
    let maxLevel = -Infinity;
    let maxKey = null;
    for (const key in devPublicKeys) {
        // eslint-disable-next-line security/detect-object-injection
        if (devPublicKeys[key]) {
            // eslint-disable-next-line security/detect-object-injection
            if (clearance && devPublicKeys[key] >= clearance)
                return key;
            else {
                // eslint-disable-next-line security/detect-object-injection
                const level = devPublicKeys[key];
                if (level > maxLevel) {
                    maxLevel = level;
                    maxKey = key;
                }
            }
        }
    }
    return maxKey;
}
function getMultisigPublicKeys() {
    return Context_1.config?.debug?.multisigKeys || {};
}
function getMultisigPublicKey(key) {
    // eslint-disable-next-line security/detect-object-injection
    return getMultisigPublicKeys()[key] !== undefined ? key : null;
}
function ensureMultisigKeySecurity(pubKey, level) {
    // eslint-disable-next-line security/detect-object-injection
    const pkClearance = getMultisigPublicKeys()[pubKey];
    return pkClearance !== undefined && pkClearance >= level;
}
//# sourceMappingURL=config.js.map