From e16d41f8e193967244e0fe0292e29fa403361677 Mon Sep 17 00:00:00 2001 From: buzzcode2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Sun, 23 Mar 2025 07:46:38 +0000 Subject: [PATCH] import modules hash.js from https://codeberg.org/buzzcode2007/ShopAI-Extension/src/branch/development-chromium/src/scripts/utils/hash.js --- scripts/utilities/hash.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 scripts/utilities/hash.js diff --git a/scripts/utilities/hash.js b/scripts/utilities/hash.js new file mode 100644 index 0000000..9dbad2d --- /dev/null +++ b/scripts/utilities/hash.js @@ -0,0 +1,24 @@ +class HashTools { + static async digest (DATA, OPTIONS) { + DATA = {"raw": DATA}; + DATA[`hashed`] = await(crypto.subtle.digest(((OPTIONS != null && (typeof OPTIONS).includes(`obj`) && !Array.isArray(OPTIONS)) ? OPTIONS[`digestion`] : false) ? OPTIONS[`digestion`] : "SHA-512", (new TextEncoder()).encode(DATA[`raw`]))); + + if ((OPTIONS != null && (typeof OPTIONS).includes(`obj`) && !Array.isArray(OPTIONS)) ? OPTIONS[`output`] : false) { + switch (OPTIONS[`output`]) { + case `Uint8Array`: + DATA[`converted`] = new Uint8Array(DATA[`hashed`]); + break; + case `Array`: + DATA[`converted`] = Array.from(new Uint8Array(DATA[`hashed`])); + break; + case `Number`: + DATA[`converted`] = parseInt((Array.from(new Uint8Array(DATA[`hashed`]))).join()); + break; + }; + } + + return ((DATA[`converted`]) ? DATA[`converted`] : DATA[`hashed`]); + }; +} + +module.exports = {HashTools}; \ No newline at end of file