diff --git a/docs/scripts/floTradeAPI.js b/docs/scripts/floTradeAPI.js index aec8910..654bc4d 100644 --- a/docs/scripts/floTradeAPI.js +++ b/docs/scripts/floTradeAPI.js @@ -1,6 +1,6 @@ 'use strict'; -(function (EXPORTS) { //floTradeAPI v0.9.0 +(function (EXPORTS) { //floTradeAPI v0.9.1 const tradeAPI = EXPORTS; const DEFAULT = { @@ -9,6 +9,8 @@ currency: "BTC" //should come from blockchain config later } + const BTC_DUST_AMT = 546; + /*Kademlia DHT K-bucket implementation as a binary tree.*/ /** * Implementation of a Kademlia DHT k-bucket used for storing @@ -601,7 +603,7 @@ TRADE: "trade" } - tradeAPI.getSink = function (service = serviceList.TRADE) { + const getSink = tradeAPI.getSink = function (service = serviceList.TRADE) { return new Promise((resolve, reject) => { if (!(Object.values(serviceList).includes(service))) return reject(MarketError(MarketError.BAD_REQUEST_CODE, 'service required', errorCode.INVALID_VALUE)); @@ -1034,7 +1036,7 @@ tradeAPI.depositBTC = function (quantity, floID, sinkID, privKey, proxySecret = null) { return new Promise((resolve, reject) => { - if (typeof quantity !== "number" || quantity <= floGlobals.fee) + if (typeof quantity !== "number" || quantity <= BTC_DUST_AMT) return reject(MarketError(MarketError.BAD_REQUEST_CODE, `Invalid quantity (${quantity})`, errorCode.INVALID_NUMBER)); else if (!floCrypto.verifyPrivKey(privKey, floID)) return reject(MarketError(MarketError.BAD_REQUEST_CODE, "Invalid Private Key", errorCode.INVALID_PRIVATE_KEY)); @@ -1371,12 +1373,10 @@ } //container for user ID and proxy private-key + var _userID, _publicKey, _privateKey, _sinkID; const proxy = tradeAPI.proxy = { - user: null, - private: null, - public: null, async lock() { - if (!this.private) + if (!_privateKey) return notify("No proxy key found!", 'error'); getPromptInput("Add password", 'This password applies to this browser only!', { isPassword: true, @@ -1387,7 +1387,7 @@ else if (pwd.length < 4) notify("Password minimum length is 4", 'error'); else { - let tmp = Crypto.AES.encrypt(this.private, pwd); + let tmp = Crypto.AES.encrypt(_privateKey, pwd); localStorage.setItem(_l('proxy_secret'), "?" + tmp); notify("Successfully locked with Password", 'success'); } @@ -1396,35 +1396,37 @@ clear() { localStorage.removeItem(_l('proxy_secret')); localStorage.removeItem(_l('user_ID')); - this.user = null; - this.private = null; - this.public = null; + _userID = null; + _privateKey = null; + _publicKey = null; + }, + set sinkID(id) { + _sinkID = id; }, get sinkID() { - return getRef("sink_id").value; + return _sinkID; }, set userID(id) { localStorage.setItem(_l('user_ID'), id); - this.user = id; + _userID = id; }, get userID() { - if (this.user) - return this.user; + if (_userID) + return _userID; else { let id = localStorage.getItem(_l('user_ID')); - return id ? this.user = id : undefined; + return id ? _userID = id : undefined; } }, set secret(key) { localStorage.setItem(_l('proxy_secret'), key); - this.private = key; - this.public = floCrypto.getPubKeyHex(key); + _privateKey = key; + _publicKey = floCrypto.getPubKeyHex(key); }, get secret() { - const self = this; return new Promise((resolve, reject) => { - if (self.private) - return resolve(self.private); + if (_privateKey) + return resolve(_privateKey); const Reject = reason => { notify(reason, 'error'); @@ -1432,9 +1434,9 @@ } const setValues = priv => { try { - self.private = priv; - self.public = floCrypto.getPubKeyHex(priv); - resolve(self.private); + _privateKey = priv; + _publicKey = floCrypto.getPubKeyHex(priv); + resolve(_privateKey); } catch (error) { Reject("Unable to fetch Proxy secret"); }