@vostokplatform/crypto-gost-js
Version:
Pure Javascript implementation of WebCrypto API interfaces and Public Key Infrastructure for GOST algorithms (Russian Cryptographic Standards)
29 lines (23 loc) • 696 B
JavaScript
export function getRoot() {
return isInNode() ? global : self;
}
export function getCryptoModule() {
const root = getRoot();
if (getRoot().hasOwnProperty('crypto')) {
return root.crypto;
} else if (root.hasOwnProperty('msCrypto')) {
return root.msCrypto;
} else if (isInNode()) {
return require('crypto');
}
throw new Error('Your environment does not have сrypto module');
}
export function isInNode() {
return typeof exports === 'object' && typeof module !== 'undefined';
}
export function isBrowser() {
return typeof window !== 'undefined';
}
export function isInWebWorker() {
return typeof importScripts !== 'undefined';
}