From 2b8e77b5f783d24e47ccdf23e94dcdde66328f88 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Tue, 26 Jul 2022 15:16:22 +0530 Subject: [PATCH] Bug fixes - floCrypto.validateAddr: bech default=true - floCloudAPI: proxyID - commented coinjs api vars --- README.md | 2 +- floCloudAPI.js | 20 ++++++++++---------- floCrypto.js | 4 ++-- lib.js | 5 +++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index da60c69..17ff13a 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ In addition, we have these system variables outside FLO Globals but used globall `validateAddr` check if the given Address (any blockchain) is valid or not 1. address - address to validate 2. std - checks for legacy version (optional, default=true) (true: allow any, array: list of versions, value: one version only, false: allow none) -3. bech - checks for bech version (optional, default=false) (true: allow any, array: list of versions, value: one version only, false: allow none) [requires additional library: [btc_api](https://ranchimall.github.io/btc-webwallet/lib_btc.js)] +3. bech - checks for bech version (optional, default=true) (true: allow any, array: list of versions, value: one version only, false: allow none) * Returns : boolen (true or false) #### Validate FLO ID diff --git a/floCloudAPI.js b/floCloudAPI.js index 3a06e0b..7d2dad2 100644 --- a/floCloudAPI.js +++ b/floCloudAPI.js @@ -1,4 +1,4 @@ -(function(EXPORTS) { //floCloudAPI v2.4.2 +(function(EXPORTS) { //floCloudAPI v2.4.2a /* FLO Cloud operations to send/request application data*/ 'use strict'; const floCloudAPI = EXPORTS; @@ -217,7 +217,7 @@ if (_inactive.size === kBucket.list.length) return reject('Cloud offline'); if (!(snID in supernodes)) - snID = kBucket.closestNode(snID); + snID = kBucket.closestNode(proxyID(snID)); ws_connect(snID) .then(node => resolve(node)) .catch(error => { @@ -255,7 +255,7 @@ if (_inactive.size === kBucket.list.length) return reject('Cloud offline'); if (!(snID in supernodes)) - snID = kBucket.closestNode(snID); + snID = kBucket.closestNode(proxyID(snID)); fetch_API(snID, data) .then(result => resolve(result)) .catch(error => { @@ -370,11 +370,11 @@ const filterKey = util.filterKey = function(type, options) { return type + (options.comment ? ':' + options.comment : '') + - '|' + (options.group || toFloID(options.receiverID) || DEFAULT.adminID) + + '|' + (options.group || options.receiverID || DEFAULT.adminID) + '|' + (options.application || DEFAULT.application); } - const toFloID = util.toFloID = function(address) { + const proxyID = util.proxyID = function(address) { if (!address) return; var bytes; @@ -390,7 +390,7 @@ 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 - if (!(coinjs instanceof Object)) + if (typeof coinjs !== 'function') throw "library missing (lib_btc.js)"; let decode = coinjs.bech32_decode(address); if (decode) { @@ -519,7 +519,7 @@ return new Promise((resolve, reject) => { var data = { senderID: user.id, - receiverID: toFloID(options.receiverID) || DEFAULT.adminID, + receiverID: options.receiverID || DEFAULT.adminID, pubKey: user.public, message: encodeMessage(message), time: Date.now(), @@ -540,7 +540,7 @@ const requestApplicationData = floCloudAPI.requestApplicationData = function(type, options = {}) { return new Promise((resolve, reject) => { var request = { - receiverID: toFloID(options.receiverID) || DEFAULT.adminID, + receiverID: options.receiverID || DEFAULT.adminID, senderID: options.senderID || undefined, application: options.application || DEFAULT.application, type: type, @@ -645,7 +645,7 @@ if (!floGlobals.subAdmins.includes(user.id)) return reject("Only subAdmins can tag data") var request = { - receiverID: toFloID(options.receiverID) || DEFAULT.adminID, + receiverID: options.receiverID || DEFAULT.adminID, requestorID: user.id, pubKey: user.public, time: Date.now(), @@ -664,7 +664,7 @@ floCloudAPI.noteApplicationData = function(vectorClock, note, options = {}) { return new Promise((resolve, reject) => { var request = { - receiverID: toFloID(options.receiverID) || DEFAULT.adminID, + receiverID: options.receiverID || DEFAULT.adminID, requestorID: user.id, pubKey: user.public, time: Date.now(), diff --git a/floCrypto.js b/floCrypto.js index 064c060..e32882e 100644 --- a/floCrypto.js +++ b/floCrypto.js @@ -1,4 +1,4 @@ -(function(EXPORTS) { //floCrypto v2.3.2a +(function(EXPORTS) { //floCrypto v2.3.2b /* FLO Crypto Operators */ 'use strict'; const floCrypto = EXPORTS; @@ -209,7 +209,7 @@ } //Check if the given address (any blockchain) is valid or not - floCrypto.validateAddr = function(address, std = true, bech = false) { + floCrypto.validateAddr = function(address, std = true, bech = true) { if (address.length == 34) { //legacy or segwit encoding if (std === false) return false; diff --git a/lib.js b/lib.js index a7e41fe..b55a81c 100644 --- a/lib.js +++ b/lib.js @@ -1,4 +1,4 @@ -(function(GLOBAL) { //lib v1.3.0 +(function(GLOBAL) { //lib v1.3.0a 'use strict'; /* Utility Libraries required for Standard operations * All credits for these codes belong to their respective creators, moderators and owners. @@ -6312,11 +6312,12 @@ /* other vars */ coinjs.developer = '33tht1bKDgZVxb39MnZsWa8oxHXHvUYE4G'; //bitcoin - /* bit(coinb.in) api vars */ + /* bit(coinb.in) api vars coinjs.hostname = ((document.location.hostname.split(".")[(document.location.hostname.split(".")).length - 1]) == 'onion') ? 'coinbin3ravkwb24f7rmxx6w3snkjw45jhs5lxbh3yfeg3vpt6janwqd.onion' : 'coinb.in'; coinjs.host = ('https:' == document.location.protocol ? 'https://' : 'http://') + coinjs.hostname + '/api/'; coinjs.uid = '1'; coinjs.key = '12345678901234567890123456789012'; + */ /* start of address functions */