From d19acbeb0e507db2f00703dd3bcdb4ddb85fa986 Mon Sep 17 00:00:00 2001 From: szacskesz <36171948+szacskesz@users.noreply.github.com> Date: Tue, 22 Jul 2025 21:03:12 +0200 Subject: [PATCH 1/3] Mark package as side effect free --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 } From fc0ccb76c32bc17867e5f69f1e5a1552e8c93ec7 Mon Sep 17 00:00:00 2001 From: Szacsuri Norbert Date: Tue, 22 Jul 2025 23:36:25 +0200 Subject: [PATCH 2/3] Convert to ES module syntax --- browser.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/browser.js b/browser.js index b339dca..6e7049b 100644 --- a/browser.js +++ b/browser.js @@ -8,20 +8,15 @@ 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') -} +export function randomBytes (size, cb) { + const _global = typeof globalThis !== 'undefined' ? globalThis : global + const crypto = _global.crypto || _global.msCrypto -const _global = typeof globalThis !== 'undefined' ? globalThis : global -const crypto = _global.crypto || _global.msCrypto + if (!crypto || !crypto.getRandomValues) { + throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11') + } -if (crypto && crypto.getRandomValues) { - module.exports = randomBytes -} else { - module.exports = oldBrowser -} -function randomBytes (size, cb) { // phantomjs needs to throw if (size > MAX_UINT32) throw new RangeError('requested too many random bytes') From fdeeb9442d72e6ce8bd82ca8320bbdc414b2d8a0 Mon Sep 17 00:00:00 2001 From: Szacsuri Norbert Date: Wed, 23 Jul 2025 19:47:42 +0200 Subject: [PATCH 3/3] Lint fixes --- browser.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/browser.js b/browser.js index 6e7049b..6e6c20c 100644 --- a/browser.js +++ b/browser.js @@ -16,7 +16,6 @@ export function randomBytes (size, cb) { throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11') } - // phantomjs needs to throw if (size > MAX_UINT32) throw new RangeError('requested too many random bytes') @@ -42,4 +41,4 @@ export function randomBytes (size, cb) { } return bytes -} \ No newline at end of file +}