From 4b29a61065ee4d74296a43a9a7a66e011d45282b Mon Sep 17 00:00:00 2001 From: Matt C Date: Mon, 18 Dec 2017 09:53:23 +0000 Subject: [PATCH 1/2] Fixes UUID incompatibility with webworkers --- src/core/operations/UUID.js | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/core/operations/UUID.js b/src/core/operations/UUID.js index 761f245a..b6335e24 100755 --- a/src/core/operations/UUID.js +++ b/src/core/operations/UUID.js @@ -1,3 +1,4 @@ +import crypto from "crypto"; /** * UUID operations. * @@ -17,25 +18,17 @@ const UUID = { * @returns {string} */ runGenerateV4: function(input, args) { - if (window && typeof(window.crypto) !== "undefined" && typeof(window.crypto.getRandomValues) !== "undefined") { - let buf = new Uint32Array(4), - i = 0; - window.crypto.getRandomValues(buf); - return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) { - let r = (buf[i >> 3] >> ((i % 8) * 4)) & 0xf, - v = c === "x" ? r : (r & 0x3 | 0x8); - i++; - return v.toString(16); - }); - } else { - return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) { - let r = Math.random() * 16 | 0, - v = c === "x" ? r : (r & 0x3 | 0x8); - return v.toString(16); - }); - } - }, - + const buf = new Uint32Array(4).map(() => { + return crypto.randomBytes(4).readUInt32BE(0, true); + }); + let i = 0; + return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) { + let r = (buf[i >> 3] >> ((i % 8) * 4)) & 0xf, + v = c === "x" ? r : (r & 0x3 | 0x8); + i++; + return v.toString(16); + }); + } }; export default UUID; From 049fc66785418a2b1b771112152ecf56bd9cc2c6 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Tue, 19 Dec 2017 14:24:47 +0000 Subject: [PATCH 2/2] Added note to Default.js to show that crypto is included in that module. --- src/core/config/modules/Default.js | 1 + src/core/operations/UUID.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/core/config/modules/Default.js b/src/core/config/modules/Default.js index 19d6c803..8e0c8872 100644 --- a/src/core/config/modules/Default.js +++ b/src/core/config/modules/Default.js @@ -39,6 +39,7 @@ import UUID from "../../operations/UUID.js"; * - Utils.js * - CryptoJS * - otp + * - crypto * * @author n1474335 [n1474335@gmail.com] * @copyright Crown Copyright 2017 diff --git a/src/core/operations/UUID.js b/src/core/operations/UUID.js index b6335e24..7b485579 100755 --- a/src/core/operations/UUID.js +++ b/src/core/operations/UUID.js @@ -1,4 +1,6 @@ import crypto from "crypto"; + + /** * UUID operations. *