"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ensureMultisigKeySecurity = exports.getMultisigPublicKey = exports.getMultisigPublicKeys = exports.getDevPublicKeyMaxLevel = exports.getDevPublicKey = exports.ensureKeySecurity = exports.getDevPublicKeys = exports.getHashedDevKey = exports.isServiceMode = exports.isDebugModeAnd = exports.isDebugMode = void 0;
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);
}
exports.isDebugMode = isDebugMode;
function isDebugModeAnd(predicate) {
    return isDebugMode() && !!predicate(Context_1.config.debug || {});
}
exports.isDebugModeAnd = isDebugModeAnd;
function isServiceMode() {
    return Context_1.config && Context_1.config.features && Context_1.config.features.startInServiceMode;
}
exports.isServiceMode = isServiceMode;
function getHashedDevKey() {
    return Context_1.config?.debug?.hashedDevAuth || '';
}
exports.getHashedDevKey = getHashedDevKey;
function getDevPublicKeys() {
    return Context_1.config?.debug?.devPublicKeys || {};
}
exports.getDevPublicKeys = getDevPublicKeys;
function ensureKeySecurity(pubKey, level) {
    const devPublicKeys = getDevPublicKeys();
    // eslint-disable-next-line security/detect-object-injection
    const pkClearance = devPublicKeys[pubKey];
    return pkClearance !== undefined && pkClearance >= level;
}
exports.ensureKeySecurity = ensureKeySecurity;
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;
}
exports.getDevPublicKey = getDevPublicKey;
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;
}
exports.getDevPublicKeyMaxLevel = getDevPublicKeyMaxLevel;
function getMultisigPublicKeys() {
    return Context_1.config?.debug?.multisigKeys || {};
}
exports.getMultisigPublicKeys = getMultisigPublicKeys;
function getMultisigPublicKey(key) {
    // eslint-disable-next-line security/detect-object-injection
    return getMultisigPublicKeys()[key] !== undefined ? key : null;
}
exports.getMultisigPublicKey = getMultisigPublicKey;
function ensureMultisigKeySecurity(pubKey, level) {
    // eslint-disable-next-line security/detect-object-injection
    const pkClearance = getMultisigPublicKeys()[pubKey];
    return pkClearance !== undefined && pkClearance >= level;
}
exports.ensureMultisigKeySecurity = ensureMultisigKeySecurity;
//# sourceMappingURL=config.js.map