Update cloud.js

Added ethereum address handling for decodeID function
This commit is contained in:
sairaj mote 2023-10-15 18:11:48 +05:30 committed by GitHub
parent 6a57aa1273
commit 36d15bd7f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {