diff --git a/browser.js b/browser.js index b339dca..6e6c20c 100644 --- a/browser.js +++ b/browser.js @@ -8,20 +8,14 @@ const MAX_BYTES = 65536 // https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48 const MAX_UINT32 = 4294967295 -function oldBrowser () { - throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11') -} - -const _global = typeof globalThis !== 'undefined' ? globalThis : global -const crypto = _global.crypto || _global.msCrypto +export function randomBytes (size, cb) { + const _global = typeof globalThis !== 'undefined' ? globalThis : global + const crypto = _global.crypto || _global.msCrypto -if (crypto && crypto.getRandomValues) { - module.exports = randomBytes -} else { - module.exports = oldBrowser -} + if (!crypto || !crypto.getRandomValues) { + throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11') + } -function randomBytes (size, cb) { // phantomjs needs to throw if (size > MAX_UINT32) throw new RangeError('requested too many random bytes') @@ -47,4 +41,4 @@ function randomBytes (size, cb) { } return bytes -} \ No newline at end of file +} diff --git a/package.json b/package.json index 2627501..9a639e6 100644 --- a/package.json +++ b/package.json @@ -28,5 +28,6 @@ "tap-spec": "^5.0.0", "tape": "^5.2.2", "zuul": "^3.12.0" - } + }, + "sideEffects": false }