line_push/node_modules/js-crypto-env/dist/index.js
2022-07-21 03:28:35 +00:00

81 lines
2.2 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getRootWebCryptoAll = exports.getWebCryptoAll = exports.getMsCrypto = exports.getWebCrypto = exports.getNodeCrypto = exports.default = void 0;
/**
* index.js
**/
/**
* Obtain require(crypto) in Node.js environment.
* @return {undefined|Object} - Node.js crypto object
*/
var getNodeCrypto = function getNodeCrypto() {
if (typeof window !== 'undefined') return undefined;else return require('crypto');
};
/**
* Obtain window.crypto.subtle object in browser environments.
* @return {undefined|Object} - WebCrypto API object
*/
exports.getNodeCrypto = getNodeCrypto;
var getWebCrypto = function getWebCrypto() {
if (typeof window === 'undefined') return undefined;
if (window.crypto) return window.crypto.subtle;
};
/**
* Obtain window.crypto.subtle or window.msCrypto.subtle object in browser environments.
* @return {undefined|Object} - WebCrypto API object
*/
exports.getWebCrypto = getWebCrypto;
var getWebCryptoAll = function getWebCryptoAll() {
if (typeof window === 'undefined') return undefined;else {
if (window.msCrypto) return window.msCrypto.subtle;
if (window.crypto) return window.crypto.subtle;
}
};
/**
* Obtain window.crypto or window.msCrypto object in browser environments.
* @return {undefined|Object} - WebCrypto API object
*/
exports.getWebCryptoAll = getWebCryptoAll;
var getRootWebCryptoAll = function getRootWebCryptoAll() {
if (typeof window === 'undefined') return undefined;else {
if (window.msCrypto) return window.msCrypto;
if (window.crypto) return window.crypto;
}
};
/**
* Retrieve MsCryptoObject, i.e., window.msCrypto.subtle
* @return {undefined|Object}
*/
exports.getRootWebCryptoAll = getRootWebCryptoAll;
var getMsCrypto = function getMsCrypto() {
if (typeof window === 'undefined') return undefined;
if (window.crypto) return undefined;
if (window.msCrypto) return window.msCrypto.subtle;
};
exports.getMsCrypto = getMsCrypto;
var _default = {
getNodeCrypto: getNodeCrypto,
getWebCrypto: getWebCrypto,
getMsCrypto: getMsCrypto,
getWebCryptoAll: getWebCryptoAll,
getRootWebCryptoAll: getRootWebCryptoAll
};
exports.default = _default;