diff --git a/packages/core/src/polyfills/crypto.js b/packages/core/src/polyfills/crypto.js index 798b89f..976875c 100644 --- a/packages/core/src/polyfills/crypto.js +++ b/packages/core/src/polyfills/crypto.js @@ -1,11 +1,19 @@ import crypto from 'crypto'; // should have webcrypto.getRandomValues defined -if (typeof global.crypto !== 'object') { - global.crypto = crypto; +let context; + +if (typeof global !== 'undefined') { + context = global; +} else if (typeof window !== 'undefined') { + context = window; +} + +if (typeof context.crypto !== 'object') { + context.crypto = crypto; } -if (typeof global.crypto.getRandomValues !== 'function') { - global.crypto.getRandomValues = getRandomValues; +if (typeof context.crypto.getRandomValues !== 'function') { + context.crypto.getRandomValues = getRandomValues; } function getRandomValues(array) {