From 6a57aa127391ecdad036caaf80b1f7a035e3fecc Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Sun, 15 Oct 2023 15:57:12 +0530 Subject: [PATCH] Update floCrypto.js Added support for ethereum address validation -- floCrypto.validateAddr -- decodeAddress --- src/floCrypto.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/floCrypto.js b/src/floCrypto.js index f1e14d3..27f29d5 100644 --- a/src/floCrypto.js +++ b/src/floCrypto.js @@ -299,6 +299,8 @@ return true; else return false; + } else if (raw.type === 'ethereum') { + return true } else //unknown return false; } @@ -414,7 +416,7 @@ hex: Crypto.util.bytesToHex(bytes), bytes } - } else if (address.length == 42 || address.length == 62) { //bech encoding + } else if (!address.startsWith("0x") && address.length == 42 || address.length == 62) { //bech encoding let decode = coinjs.bech32_decode(address); if (decode) { let bytes = decode.data; @@ -428,6 +430,11 @@ } } else return null; + } else if ((address.length == 42 && address.startsWith("0x")) || (address.length == 40 && !address.startsWith("0x"))) { //Ethereum Address + return { + hex: address, + type: 'ethereum' + } } } @@ -527,4 +534,4 @@ m => String.fromCharCode(parseInt(m.replace(/\\u/g, ''), 16))); } -})('object' === typeof module ? module.exports : window.floCrypto = {}); \ No newline at end of file +})('object' === typeof module ? module.exports : window.floCrypto = {});