From b1366f852511f20591d356e2d0ebb11f7b0140e3 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Thu, 20 Jan 2022 14:56:24 -0700 Subject: [PATCH] feat: remove optional crypto dependency --- lib/core/utils/uuid.js | 9 --------- test/node/uuid.js | 19 ------------------- 2 files changed, 28 deletions(-) delete mode 100644 test/node/uuid.js diff --git a/lib/core/utils/uuid.js b/lib/core/utils/uuid.js index cf2d2e5f9b..de8a9eb66e 100644 --- a/lib/core/utils/uuid.js +++ b/lib/core/utils/uuid.js @@ -23,15 +23,6 @@ if (!_rng && _crypto && _crypto.getRandomValues) { }; } -try { - if (!_rng) { - const nodeCrypto = require('crypto'); - _rng = () => nodeCrypto.randomBytes(16); - } -} catch (e) { - /* do nothing */ -} - if (!_rng) { // Math.random()-based (RNG) // diff --git a/test/node/uuid.js b/test/node/uuid.js deleted file mode 100644 index 905a114722..0000000000 --- a/test/node/uuid.js +++ /dev/null @@ -1,19 +0,0 @@ -var assert = require('chai').assert; -var sinon = require('sinon'); -var proxyquire = require('proxyquire'); -var crypto = require('crypto'); // Node package - -// 16 byte array, all 0's -var returnVal = new Array(16).fill(0); -var cryptoStub = sinon.stub(crypto, 'randomBytes').returns(returnVal); - -describe('uuid.v4', function() { - var axe = proxyquire('../../', { crypto: cryptoStub }); - var uuidV4 = axe.utils.uuid.v4; - - it('uses node crypto', function() { - var uuid = uuidV4(); - assert.isTrue(cryptoStub.randomBytes.called); - assert.deepEqual(uuid, '00000000-0000-4000-8000-000000000000'); - }); -});