From 71c431c4093bf269cbf086650fe201137bc23e14 Mon Sep 17 00:00:00 2001 From: Trung0246 Date: Sun, 19 Nov 2023 14:19:07 -0800 Subject: [PATCH] Remove `crypto.subtle` api due to tls --- web/js/nodes.js | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/web/js/nodes.js b/web/js/nodes.js index 50ed431..f837ec0 100644 --- a/web/js/nodes.js +++ b/web/js/nodes.js @@ -28,22 +28,8 @@ function removeElements(array, isValid) { array.length -= shift; } -async function randomSHA256() { - // Generate a random array of bytes - const randomValues = new Uint8Array(32); - window.crypto.getRandomValues(randomValues); - - // Convert the random bytes to a string - const randomString = Array.from(randomValues).map(b => String.fromCharCode(b)).join(''); - - // Hash the string using SHA-256 - const msgBuffer = new TextEncoder().encode(randomString); // encode as (utf-8) Uint8Array - const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer); // hash the message - - // Convert the buffer to hex string - const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array - const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string - return hashHex; +function randomID() { + return Date.now().toString(36) + Math.random().toString(36).substring(2); } ///////////////////////////////////////////////////////////////////////// @@ -66,7 +52,7 @@ function init_update(node, name) { if (node.widgets[i].name === name) { node.widgets[i].serializeValue = async function (inner_node, index_str) { if (node.__update || !node.__hash_update) - node.__hash_update = await randomSHA256(); + node.__hash_update = randomID(); node.__update = false; return { data: this.value, @@ -534,4 +520,4 @@ app.registerExtension({ } } }, -}); \ No newline at end of file +});