{"size": 2044, "ext": "js", "max_stars_repo_path": "node_modules/blockstack/lib/encryption/cryptoUtils.js", "max_stars_repo_name": "FhilF/radiks-a", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/blockstack/lib/encryption/cryptoUtils.js", "max_issues_repo_name": "FhilF/radiks-a", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/blockstack/lib/encryption/cryptoUtils.js", "max_forks_repo_name": "FhilF/radiks-a", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 35.2413793103, "max_line_length": 140, "alphanum_fraction": 0.5968688845}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
function isSubtleCryptoAvailable() {
    return typeof crypto !== 'undefined' && typeof crypto.subtle !== 'undefined';
}
exports.isSubtleCryptoAvailable = isSubtleCryptoAvailable;
function isNodeCryptoAvailable(withFeature) {
    try {
        const resolvedResult = require.resolve('crypto');
        if (!resolvedResult) {
            return false;
        }
        // eslint-disable-next-line import/no-nodejs-modules,no-restricted-modules,global-require
        const cryptoModule = require('crypto');
        if (!cryptoModule) {
            return false;
        }
        if (withFeature) {
            const features = withFeature(cryptoModule);
            return features;
        }
        return true;
    }
    catch (error) {
        return false;
    }
}
exports.isNodeCryptoAvailable = isNodeCryptoAvailable;
exports.NO_CRYPTO_LIB = 'Crypto lib not found. Either the WebCrypto "crypto.subtle" or Node.js "crypto" module must be available.';
// Make async for future version which may lazy load.
// eslint-disable-next-line @typescript-eslint/require-await
function getCryptoLib() {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        if (isSubtleCryptoAvailable()) {
            return {
                lib: crypto.subtle,
                name: 'subtleCrypto'
            };
        }
        else {
            try {
                // eslint-disable-next-line max-len
                // eslint-disable-next-line import/no-nodejs-modules,no-restricted-modules,global-require,@typescript-eslint/no-var-requires
                const nodeCrypto = require('crypto');
                return {
                    lib: nodeCrypto,
                    name: 'nodeCrypto'
                };
            }
            catch (error) {
                throw new Error(exports.NO_CRYPTO_LIB);
            }
        }
    });
}
exports.getCryptoLib = getCryptoLib;
//# sourceMappingURL=cryptoUtils.js.map