From 4bb40aa43d88f116c80b8708e2b43ef6a4015ac1 Mon Sep 17 00:00:00 2001 From: Emil Bay Date: Wed, 24 Jun 2020 13:37:07 +0200 Subject: [PATCH] Clean up random bytes --- randombytes.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/randombytes.js b/randombytes.js index f23eefe..33d67f2 100644 --- a/randombytes.js +++ b/randombytes.js @@ -1,7 +1,8 @@ var assert = require('nanoassert') + var randombytes = (function () { var QUOTA = 65536 // limit for QuotaExceededException - var crypto = typeof global !== 'undefined' ? crypto = (global.crypto || global.msCrypto) : null + var crypto = global.crypto || global.msCrypto function browserBytes (out, n) { for (var i = 0; i < n; i += QUOTA) { @@ -17,19 +18,18 @@ var randombytes = (function () { throw new Error('No secure random number generator available') } - if (crypto && crypto.getRandomValues) { - return browserBytes - } else if (typeof require !== 'undefined') { - // Node.js. crypto = require('crypto') - if (crypto && crypto.randomBytes) { - return nodeBytes - } + if (crypto && crypto.getRandomValues) return browserBytes + + if (require != null) { + // Node.js. Bust Browserify + crypto = require('cry' + 'pto') } return noImpl })() +// Make non enumerable as this is an internal function Object.defineProperty(module.exports, 'randombytes', { value: randombytes })