diff --git a/supernode/index.html b/supernode/index.html index b8dc6e1..89ef886 100644 --- a/supernode/index.html +++ b/supernode/index.html @@ -8476,6 +8476,207 @@ })(typeof module !== 'undefined' && module['exports'] ? module['exports'] : (window['shamirSecretShare'] = {}), typeof global !== 'undefined' ? global : window); + + @@ -9326,10 +9534,8 @@ case "deposit_asset_request": localbitcoinplusplus.rpc.prototype.filter_legit_requests(function (is_valid_request) { - if (is_valid_request !== true) { - return false; - } - + if (is_valid_request !== true) return false; + // This code will only run for supernodes if (typeof params.product !== "undefined" && localbitcoinplusplus.master_configurations .validAssets.includes(params.product) && @@ -9340,7 +9546,14 @@ typeof params.trader_flo_address == "string" && params.trader_flo_address.length > 0 ) { - if (params.product == "BTC") { + localbitcoinplusplus.wallets.prototype.getUserPublicKey(params.trader_flo_address, + function(requester_public_key) { + if (requester_public_key==undefined||requester_public_key==null) { + throw new Error('Failed to get public key of the user.'); + } + params.depositor_public_key = requester_public_key; + + if (params.product == "BTC") { /************************************************************************** // YOU HAVE TO PROVIDE BTC KEYS HERE. CHANGE IT LATER ****************************************************************************/ @@ -9476,8 +9689,7 @@ } else if (params.product == "INR") { params.id = helper_functions.unique_id(); params.status = 1; - let receivedTradeInfo = { ...params - }; + let receivedTradeInfo = { ...params }; readDB("localbitcoinUser", "00-01", function (su_data) { if (typeof su_data == "object" && typeof su_data.myLocalFLOPublicKey == @@ -9497,7 +9709,7 @@ receivedTradeInfo["order_validator_public_key"] = su_data.myLocalFLOPublicKey; - // YOU NEED TO DETERMINE A BANK ACCOUNT HERE IF NOONE IS WITHDRAWING + // YOU NEED TO DETERMINE A BANK ACCOUNT HERE IF NO ONE IS WITHDRAWING try { addDB("deposit", receivedTradeInfo); readDBbyIndex("withdraw_cash", "status", 1, @@ -9592,6 +9804,8 @@ } }); } + }); + } else { console.log("deposit asset request error"); } @@ -9914,6 +10128,27 @@ }); break; + + case "superNodeSignedAddUserPublicData": + if (typeof params=="object" && typeof params.data=="object") { + if (typeof params.su_pubKey=="string" && localbitcoinplusplus + .master_configurations.supernodesPubKeys.includes(params.su_pubKey)) { + let res_data_obj = { + trader_flo_address: params.data.trader_flo_address, + trader_flo_pubKey: params.data.trader_flo_pubKey, + trader_status: params.data.trader_status, + timestamp: params.data.timestamp + }; + let res_data_hash = Crypto.SHA256(JSON.stringify(res_data_obj)); + let res_data_verification = localbitcoinplusplus.wallets.prototype + .verify(res_data_hash, params.sign, params.su_pubKey); + if ((res_data_verification==true) && res_data_hash==params.data_hash) { + addDB('userPublicData', params.data); + return true; + } + } + } + break; default: alert("Unknown method called for execution."); @@ -10165,6 +10400,8 @@ throw new Error("Invalid amount error."); } else if (userFLOaddress.length < 0) { throw new Error("User address required."); + } else if (userFloPublicKey.length < 0) { + throw new Error("User address required."); } let deposit_request_object = { @@ -11252,6 +11489,58 @@ return false; } break; + + case "add_user_public_data": + localbitcoinplusplus.rpc.prototype.filter_legit_requests(function (is_valid_request) { + if (is_valid_request !== true) return false; + + if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") { + let req_data = res_obj.params[0].public_data; + try { + //let flo_address = localbitcoinplusplus.publicKey.getBitcoinAddressFromByteArray(req_data.trader_flo_pubKey); + + if (req_data.trader_flo_address.length) { + + let public_req_object = { + trader_flo_address: req_data.trader_flo_address, + trader_flo_pubKey: req_data.trader_flo_pubKey, + trader_status: 0, + timestamp: + new Date() + } + + addDB('userPublicData', public_req_object); + + let public_req_object_str = JSON.stringify(public_req_object); + let public_req_object_hash = Crypto.SHA256(public_req_object_str); + let public_req_object_sign = localbitcoinplusplus.wallets.prototype.sign(public_req_object_hash, localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY); + + let userPublicDataResponseObject = { + data: public_req_object, + data_hash: public_req_object_hash, + sign: public_req_object_sign, + su_pubKey: localbitcoinplusplus.wallets.my_local_flo_public_key + } + + let send_pvtkey_req = localbitcoinplusplus.rpc.prototype + .send_rpc + .call(this, "superNodeSignedAddUserPublicData", + userPublicDataResponseObject); + + doSend(send_pvtkey_req); + + } + } catch (error) { + throw new Error('Invalid public key and flo address combination.'); + } + } + }); + break; + + case "superNodeSignedAddUserPublicData": + response_from_sever = localbitcoinplusplus.rpc.prototype.receive_rpc_response.call(this, + JSON.stringify(res_obj)); + doSend(JSON.stringify(response_from_sever)); // send response to client + break; default: break; @@ -11317,6 +11606,13 @@ myAddressTrustLevel: 1 }; + const userPublicData = { + trader_flo_address: null, + trader_flo_pubKey: null, + trader_status: null, + timestamp: null + }; + const deposit = { id: "", trader_flo_address: null, @@ -11379,7 +11675,7 @@ var db; const DBName = "localbitcoinDB"; - var request = window.indexedDB.open(DBName, 1); + var request = window.indexedDB.open(DBName, 3); request.onerror = function (event) { //https://stackoverflow.com/questions/13972385/invalidstateerror-while-opening-indexeddb-in-firefox @@ -11489,6 +11785,17 @@ unique: false }); } + if (!db.objectStoreNames.contains('userPublicData')) { + var objectStore = db.createObjectStore("userPublicData", { + keyPath: 'trader_flo_address' + }); + objectStore.createIndex('trader_flo_pubKey', 'trader_flo_pubKey', { + unique: true + }); + objectStore.createIndex('trader_status', 'trader_status', { + unique: false + }); + } } @@ -11625,6 +11932,13 @@ } + + +