From 36d15bd7f83d9563560a6a56319f375290e35403 Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Sun, 15 Oct 2023 18:11:48 +0530 Subject: [PATCH] Update cloud.js Added ethereum address handling for decodeID function --- src/cloud.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cloud.js b/src/cloud.js index 99739a6..2764bc7 100644 --- a/src/cloud.js +++ b/src/cloud.js @@ -2,7 +2,9 @@ function K_Bucket(masterID, nodeList) { - const decodeID = function(floID) { + const decodeID = function (floID) { + if (floID.startsWith("0x") || floID.length === '40') + floID = proxyID(floID); let k = bitjs.Base58.decode(floID); k.shift(); k.splice(-4, 4); @@ -110,7 +112,7 @@ function proxyID(address) { }); hash[0] != checksum[0] || hash[1] != checksum[1] || hash[2] != checksum[2] || hash[3] != checksum[3] ? bytes = undefined : bytes.shift(); - } else if (address.length == 42 || address.length == 62) { //bech encoding + } else if (!address.startsWith("0x") && (address.length == 42 || address.length == 62)) { //bech encoding if (typeof coinjs !== 'function') throw "library missing (lib_btc.js)"; let decode = coinjs.bech32_decode(address); @@ -125,11 +127,11 @@ function proxyID(address) { bytes = ripemd160(Crypto.SHA256(Crypto.util.hexToBytes(address), { asBytes: true })); - } else if ((address.length == 42 && address.startsWith("0x")) || (address.length == 40 && !address.startsWith("0x"))){ //Ethereum Address - if (address.startsWith("0x")) { address = address.substring(2);} + } else if ((address.length == 42 && address.startsWith("0x")) || (address.length == 40 && !address.startsWith("0x"))) { //Ethereum Address + if (address.startsWith("0x")) { address = address.substring(2); } bytes = Crypto.util.hexToBytes(address); } - + if (!bytes) throw "Invalid address: " + address; else {