automated login process
This commit is contained in:
parent
8c251f889f
commit
50734d962e
@ -38,11 +38,7 @@
|
|||||||
|
|
||||||
<h5>Indexed DB</h5>
|
<h5>Indexed DB</h5>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<label for="ask_flo_addr">Enter Your FLO Address: </label>
|
<div id="reset_flo_keys_div"></div>
|
||||||
<input type="text" id="ask_flo_addr" class="form-control">
|
|
||||||
<input type="button" id="ask_flo_addr_btn" value="Submit">
|
|
||||||
<br>
|
|
||||||
<input type="button" id="reset_flo_keys" value="Reset Keys">
|
|
||||||
<div id="localbitcoinuserdiv"></div>
|
<div id="localbitcoinuserdiv"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -70,24 +66,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h5>Buy--Sell</h5>
|
<h5>Buy--Sell</h5>
|
||||||
<div class="box tradebox" id="tradebox">
|
<div class="box tradebox" id="tradebox"></div>
|
||||||
<!-- <div class="buybox">
|
|
||||||
<strong>Buy BTC</strong>
|
|
||||||
<ul class="panel-box trade_amount_box" id="buyul">
|
|
||||||
<li>CASH 10000</li>
|
|
||||||
<li>CASH 50000</li>
|
|
||||||
<li>CASH 100000</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div class="sellbox">
|
|
||||||
<strong>Sell BTC</strong>
|
|
||||||
<ul class="panel-box trade_amount_box" id="sellul">
|
|
||||||
<li>CASH 10000</li>
|
|
||||||
<li>CASH 50000</li>
|
|
||||||
<li>CASH 100000</li>
|
|
||||||
</ul>
|
|
||||||
</div> -->
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="output_div"></div>
|
<div id="output_div"></div>
|
||||||
|
|
||||||
@ -9230,6 +9209,20 @@
|
|||||||
let withdraw_deposit_table = document.getElementById('withdraw_deposit_table');
|
let withdraw_deposit_table = document.getElementById('withdraw_deposit_table');
|
||||||
withdraw_deposit_table.innerHTML = t;
|
withdraw_deposit_table.innerHTML = t;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
reset_flo_keys: ()=> {
|
||||||
|
const promise1 = updateinDB('localbitcoinUser', {
|
||||||
|
id: "00-01",
|
||||||
|
myLocalFLOAddress: "",
|
||||||
|
myLocalFLOPublicKey: "",
|
||||||
|
myAddressTrustLevel: 1,
|
||||||
|
preferredTradeCurrency: "USD"
|
||||||
|
}, "00-01")
|
||||||
|
|
||||||
|
const promise2 = removeAllinDB('my_supernode_private_key_chunks');
|
||||||
|
|
||||||
|
return Promise.all([promise1, promise2]).then(()=>true).catch(e=>false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -11206,8 +11199,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onOpen(evt) {
|
function onOpen(evt) {
|
||||||
|
doShreeGanesh();
|
||||||
writeToScreen("CONNECTED");
|
writeToScreen("CONNECTED");
|
||||||
doSend("Intial Hello Message: WebSocket rocks");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onClose(evt) {
|
function onClose(evt) {
|
||||||
@ -11684,10 +11677,8 @@
|
|||||||
let data = res_obj.params[0];
|
let data = res_obj.params[0];
|
||||||
let msg = localbitcoinplusplus.encrypt.decryptMessage(data.secret, data.senderPublicKeyString);
|
let msg = localbitcoinplusplus.encrypt.decryptMessage(data.secret, data.senderPublicKeyString);
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -11716,14 +11707,6 @@
|
|||||||
websocket.send(message);
|
websocket.send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SendToSpecificAddress(to, message) {
|
|
||||||
writeToScreen("SENT: " + message);
|
|
||||||
websocket.send(JSON.stringify({
|
|
||||||
to: to,
|
|
||||||
data: message
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
function writeToScreen(message) {
|
function writeToScreen(message) {
|
||||||
var pre = document.createElement("p");
|
var pre = document.createElement("p");
|
||||||
pre.style.wordWrap = "break-word";
|
pre.style.wordWrap = "break-word";
|
||||||
@ -12111,13 +12094,15 @@
|
|||||||
var RM_RPC = new localbitcoinplusplus.rpc;
|
var RM_RPC = new localbitcoinplusplus.rpc;
|
||||||
|
|
||||||
// Fetch configs from Master Key
|
// Fetch configs from Master Key
|
||||||
|
const doShreeGanesh = ()=> {
|
||||||
try {
|
try {
|
||||||
var rm_configs = localbitcoinplusplus.actions.fetch_configs(function (...fetch_configs_res) {
|
var rm_configs = localbitcoinplusplus.actions.fetch_configs(function (...fetch_configs_res) {
|
||||||
dataBaseOperations();
|
dataBaseUIOperations();
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Failed to fetch configurations: ${error}`);
|
throw new Error(`Failed to fetch configurations: ${error}`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Database operations -->
|
<!-- Database operations -->
|
||||||
@ -12140,39 +12125,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// localbitcoinUser Databse
|
const privateKeyBuilder = ()=>{
|
||||||
const dataBaseOperations = function () {
|
return new Promise(async(resolve, reject)=>{
|
||||||
let ask_flo_addr_btn = document.getElementById('ask_flo_addr_btn');
|
|
||||||
let reset_flo_keys_btn = document.getElementById('reset_flo_keys');
|
|
||||||
|
|
||||||
reset_flo_keys_btn.onclick = function() {
|
|
||||||
if (confirm(`This will reset your old keys along with data associated with it.
|
|
||||||
Are you sure you want to continue?`)) {
|
|
||||||
const promise1 = updateinDB('localbitcoinUser', {
|
|
||||||
id: "00-01",
|
|
||||||
myLocalFLOAddress: "",
|
|
||||||
myLocalFLOPublicKey: "",
|
|
||||||
myAddressTrustLevel: 1,
|
|
||||||
preferredTradeCurrency: "USD"
|
|
||||||
}, "00-01")
|
|
||||||
|
|
||||||
const promise2 = removeAllinDB('my_supernode_private_key_chunks');
|
|
||||||
|
|
||||||
Promise.all([promise1, promise2]).then(function(values) {
|
|
||||||
alert(`Your FLO keys have been deleted. Please generate new keys to continue.`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ask_flo_addr_btn.addEventListener('click', async function () {
|
|
||||||
let ask_flo_addr = document.getElementById('ask_flo_addr');
|
|
||||||
let ask_flo_addr_val = ask_flo_addr.value.trim();
|
|
||||||
|
|
||||||
if (ask_flo_addr_val == null || typeof ask_flo_addr_val == undefined || ask_flo_addr_val ==
|
|
||||||
"") {
|
|
||||||
throw new Error('Empty or invalid FLO address.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// rebuild private key
|
|
||||||
let supernode_transaction_key_arr = [];
|
let supernode_transaction_key_arr = [];
|
||||||
const chunks = await readAllDB("my_supernode_private_key_chunks");
|
const chunks = await readAllDB("my_supernode_private_key_chunks");
|
||||||
if (typeof chunks == "object" && chunks.length>0) {
|
if (typeof chunks == "object" && chunks.length>0) {
|
||||||
@ -12188,32 +12142,41 @@
|
|||||||
return c.indexOf(e) === i;
|
return c.indexOf(e) === i;
|
||||||
});
|
});
|
||||||
const TRANSACTION_KEY = localbitcoinplusplus.wallets.supernode_transaction_key = txKey[0][0];
|
const TRANSACTION_KEY = localbitcoinplusplus.wallets.supernode_transaction_key = txKey[0][0];
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
reject("Failed to build the private key.");
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// localbitcoinUser Databse
|
||||||
|
const dataBaseUIOperations = async function () {
|
||||||
|
|
||||||
|
// rebuild private key
|
||||||
|
privateKeyBuilder();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
readDB("localbitcoinUser", "00-01").then(function (idbData) {
|
readDB("localbitcoinUser", "00-01").then(function (idbData) {
|
||||||
if (typeof idbData.myLocalFLOPublicKey == undefined || idbData.myLocalFLOPublicKey
|
if (typeof idbData.myLocalFLOPublicKey == "undefined" || idbData.myLocalFLOPublicKey
|
||||||
.trim() == '') {
|
.trim() == '') {
|
||||||
let user_pvt_key = prompt("Please Enter your private key");
|
let user_pvt_key = prompt("Please Enter your private key");
|
||||||
if (user_pvt_key.trim() !== "") {
|
|
||||||
|
if (user_pvt_key.trim() == "" || user_pvt_key.length<1) user_pvt_key = null;
|
||||||
|
|
||||||
let newKeys = RM_WALLET.generateFloKeys(user_pvt_key);
|
let newKeys = RM_WALLET.generateFloKeys(user_pvt_key);
|
||||||
|
|
||||||
if (typeof newKeys == 'object' && typeof newKeys.address !==
|
if (typeof newKeys == 'object' && typeof newKeys.address !==
|
||||||
undefined) {
|
"undefined") {
|
||||||
localbitcoinplusplusObj.myLocalFLOAddress = newKeys.address;
|
localbitcoinplusplusObj.myLocalFLOAddress = newKeys.address;
|
||||||
localbitcoinplusplusObj.myLocalFLOPublicKey = newKeys.pubKeyHex;
|
localbitcoinplusplusObj.myLocalFLOPublicKey = newKeys.pubKeyHex;
|
||||||
localbitcoinplusplusObj.preferredTradeCurrency = "USD";
|
localbitcoinplusplusObj.preferredTradeCurrency = "USD";
|
||||||
updateinDB("localbitcoinUser", localbitcoinplusplusObj, "00-01");
|
updateinDB("localbitcoinUser", localbitcoinplusplusObj, "00-01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Declare the user flo address
|
// Declare the user flo address
|
||||||
const MY_LOCAL_FLO_ADDRESS = localbitcoinplusplus.wallets.my_local_flo_address = idbData.myLocalFLOAddress;
|
const MY_LOCAL_FLO_ADDRESS = localbitcoinplusplus.wallets.my_local_flo_address = idbData.myLocalFLOAddress;
|
||||||
const MY_LOCAL_FLO_PUBLIC_KEY = localbitcoinplusplus.wallets.my_local_flo_public_key = idbData.myLocalFLOPublicKey;
|
const MY_LOCAL_FLO_PUBLIC_KEY = localbitcoinplusplus.wallets.my_local_flo_public_key = idbData.myLocalFLOPublicKey;
|
||||||
const MY_PREFFERED_TRADE_CURRENCY = localbitcoinplusplus.wallets.my_preferred_trade_currency
|
const MY_PREFFERED_TRADE_CURRENCY = localbitcoinplusplus.wallets.my_preferred_trade_currency = idbData.preferredTradeCurrency;
|
||||||
= typeof idbData.preferredTradeCurrency !=="undefined" ? idbData.preferredTradeCurrency:"USD";
|
|
||||||
|
|
||||||
readDB('userPublicData', MY_LOCAL_FLO_ADDRESS).then(function(pubic_data_response) {
|
readDB('userPublicData', MY_LOCAL_FLO_ADDRESS).then(function(pubic_data_response) {
|
||||||
if (typeof pubic_data_response !== "object") {
|
if (typeof pubic_data_response !== "object") {
|
||||||
@ -12231,8 +12194,60 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* Give user the facillity to trade */
|
||||||
|
buildTradeUI(idbData);
|
||||||
|
|
||||||
|
// Deposit / Withdraw asset
|
||||||
|
depositWithdrawAsset(idbData.myLocalFLOAddress);
|
||||||
|
|
||||||
|
// Upload files to DB
|
||||||
|
uploadFileToDB();
|
||||||
|
|
||||||
|
if (localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(MY_LOCAL_FLO_PUBLIC_KEY)) {
|
||||||
|
localbitcoinplusplus.master_configurations.tradableAsset2.map((assets)=>{
|
||||||
|
if(!localbitcoinplusplus.master_configurations.tradableAsset1.includes(assets))
|
||||||
|
RM_TRADE.resolve_current_btc_price_in_fiat(assets);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
localbitcoinplusplus.actions.sync_with_supernode(MY_LOCAL_FLO_ADDRESS);
|
localbitcoinplusplus.actions.sync_with_supernode(MY_LOCAL_FLO_ADDRESS);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(
|
||||||
|
"ERROR: Failed to initialise the localbitcoinUser database. You are unable to trade at the moment."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Trade functions -->
|
||||||
|
<script>
|
||||||
|
const buildTradeUI =(idbData)=> {
|
||||||
|
|
||||||
|
if(typeof idbData !== "object") return;
|
||||||
|
|
||||||
|
// RESET KEYS
|
||||||
|
const reset_flo_keys_div = document.getElementById('reset_flo_keys_div');
|
||||||
|
const reset_flo_keys_btn = document.createElement('button');
|
||||||
|
const reset_flo_keys_btn_text = document.createTextNode(`Reset FLO Keys`);
|
||||||
|
reset_flo_keys_btn.appendChild(reset_flo_keys_btn_text);
|
||||||
|
reset_flo_keys_div.appendChild(reset_flo_keys_btn);
|
||||||
|
|
||||||
|
reset_flo_keys_btn.onclick = function() {
|
||||||
|
if (confirm(`This will reset your old keys along with data associated with it. Are you sure you want to continue?`)) {
|
||||||
|
localbitcoinplusplus.actions.reset_flo_keys().then(reset_success=>{
|
||||||
|
if(reset_success) {
|
||||||
|
alert("FLO keys have been reset successfully.");
|
||||||
|
} else {
|
||||||
|
alert(`Failed to reset FLO keys.`)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//localbitcoinuserdiv
|
//localbitcoinuserdiv
|
||||||
document.getElementById("localbitcoinuserdiv").innerHTML = `<p>Address: ${idbData.myLocalFLOAddress}<p>`;
|
document.getElementById("localbitcoinuserdiv").innerHTML = `<p>Address: ${idbData.myLocalFLOAddress}<p>`;
|
||||||
|
|
||||||
@ -12241,7 +12256,7 @@
|
|||||||
|
|
||||||
const current_preffered_fiat_h5 = document.createElement("H5");
|
const current_preffered_fiat_h5 = document.createElement("H5");
|
||||||
var current_preffered_fiat_text = document.createTextNode(`
|
var current_preffered_fiat_text = document.createTextNode(`
|
||||||
Current Default Trading Currency: ${MY_PREFFERED_TRADE_CURRENCY}`);
|
Current Default Trading Currency: ${idbData.preferredTradeCurrency}`);
|
||||||
current_preffered_fiat_h5.appendChild(current_preffered_fiat_text);
|
current_preffered_fiat_h5.appendChild(current_preffered_fiat_text);
|
||||||
|
|
||||||
const fiat_currency_select = document.createElement('select');
|
const fiat_currency_select = document.createElement('select');
|
||||||
@ -12273,8 +12288,7 @@
|
|||||||
fiat_currency_select.appendChild(option);
|
fiat_currency_select.appendChild(option);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TRADE BOX
|
||||||
/* Give user the facillity to trade */
|
|
||||||
|
|
||||||
const tradebox = document.getElementById("tradebox");
|
const tradebox = document.getElementById("tradebox");
|
||||||
|
|
||||||
@ -12346,22 +12360,6 @@
|
|||||||
selectListCrypto.value, selectListFiat.value, parseFloat(selectListAmount.value));
|
selectListCrypto.value, selectListFiat.value, parseFloat(selectListAmount.value));
|
||||||
doSend(selltrade);
|
doSend(selltrade);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deposit / Withdraw asset
|
|
||||||
depositWithdrawAsset(idbData.myLocalFLOAddress);
|
|
||||||
|
|
||||||
// Upload files to DB
|
|
||||||
uploadFileToDB();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
throw new Error(
|
|
||||||
"ERROR: Failed to initialise the localbitcoinUser database. You are unable to trade at the moment."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -12505,12 +12503,6 @@
|
|||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// let su_list = localbitcoinplusplus.master_configurations.supernodesPubKeys;
|
|
||||||
|
|
||||||
// if (!su_list.includes(publicKey_for_users_entered_private_key)) {
|
|
||||||
// throw new Error(`The public key ${publicKey_for_users_entered_private_key} is not registered as supernode yet.`);
|
|
||||||
// }
|
|
||||||
|
|
||||||
let pvt_key_shamirs_secret_shares = localbitcoinplusplus.wallets.prototype.createShamirsSecretShares(users_entered_private_key, 10, 5);
|
let pvt_key_shamirs_secret_shares = localbitcoinplusplus.wallets.prototype.createShamirsSecretShares(users_entered_private_key, 10, 5);
|
||||||
if (typeof pvt_key_shamirs_secret_shares=="object" && pvt_key_shamirs_secret_shares.length>0) {
|
if (typeof pvt_key_shamirs_secret_shares=="object" && pvt_key_shamirs_secret_shares.length>0) {
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user