v1.0.8
- Added secure privatekey feature. Secure PrivateKey: replaces the stored privatekey with encrypted variant. (Requires PIN/Password). - If user enables secure private key, user must enter the PIN/Password from next signIn. - User can remove account of securely stored privatekey (incase the user forgets the PIN/Password). (Requires Private key to login next time). - Added getPromptInput to UI script: Promisified custom prompt to get input from user.
This commit is contained in:
parent
4a38699442
commit
1764a90912
390
index.html
390
index.html
@ -184,7 +184,7 @@
|
|||||||
font: italic bold 1.5rem Georgia, serif;
|
font: italic bold 1.5rem Georgia, serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
#sign-in-box input,
|
#sign-in-box input[type="password"],
|
||||||
#sign-in-box button {
|
#sign-in-box button {
|
||||||
margin: 1rem;
|
margin: 1rem;
|
||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
@ -197,21 +197,25 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#sign-in-box input,
|
#sign-in-box input[type="password"],
|
||||||
#sign-in-box button:first-child {
|
#sign-in-box button:first-child {
|
||||||
text-shadow: 0 0 0 var(--accent-dark);
|
text-shadow: 0 0 0 var(--accent-dark);
|
||||||
border-color: var(--accent-dark);
|
border-color: var(--accent-dark);
|
||||||
}
|
}
|
||||||
|
|
||||||
#sign-in-box input {
|
#sign-in-box input[type="password"] {
|
||||||
height: 2.5rem;
|
height: 2.5rem;
|
||||||
width: 20rem;
|
width: 20rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#sign-in-box input:focus {
|
#sign-in-box input[type="password"]:focus {
|
||||||
box-shadow: -0.1rem -0.1rem var(--accent-dark)
|
box-shadow: -0.1rem -0.1rem var(--accent-dark)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#sign-in-box input[type="password"]::placeholder {
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
#sign-in-box button {
|
#sign-in-box button {
|
||||||
height: 5rem;
|
height: 5rem;
|
||||||
width: 9rem;
|
width: 9rem;
|
||||||
@ -222,6 +226,17 @@
|
|||||||
border-color: var(--alt-dark);
|
border-color: var(--alt-dark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#sign-in-box input[type="button"] {
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
color: var(--alt-dark);
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sign-in-box input[type="button"]:hover {
|
||||||
|
color: var(--alt-color);
|
||||||
|
}
|
||||||
|
|
||||||
.loader {
|
.loader {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@ -1070,26 +1085,33 @@
|
|||||||
]
|
]
|
||||||
elementsToReset.forEach(e => clearElement(document.getElementById(e)))
|
elementsToReset.forEach(e => clearElement(document.getElementById(e)))
|
||||||
//set the custom Privkey input
|
//set the custom Privkey input
|
||||||
floDapps.setCustomPrivKeyInput(() => {
|
floDapps.setCustomPrivKeyInput((type) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let signInBox = document.getElementById("sign-in-box")
|
let signInBox = document.forms["sign-in-box"]
|
||||||
signInBox.classList.remove('hide')
|
signInBox.classList.remove('hide')
|
||||||
let buttons = signInBox.getElementsByTagName('button');
|
signInBox["sign-in"].onclick = () => {
|
||||||
buttons[0].onclick = () => {
|
let key = signInBox["key"].value;
|
||||||
let keyInput = signInBox.getElementsByTagName('input')[0];
|
signInBox["key"].value = '';
|
||||||
let key = keyInput.value;
|
signInBox["sign-in"].onclick = null;
|
||||||
keyInput.value = '';
|
signInBox["guest-login"].onclick = null;
|
||||||
buttons[0].onclick = null;
|
|
||||||
buttons[1].onclick = null;
|
|
||||||
signInBox.classList.add('hide')
|
signInBox.classList.add('hide')
|
||||||
resolve(key)
|
resolve(key)
|
||||||
}
|
}
|
||||||
buttons[1].onclick = () => {
|
if (type === "PRIVATE_KEY") {
|
||||||
signInBox.getElementsByTagName('input')[0].value = '';
|
signInBox["key"].setAttribute("placeholder", "Private Key")
|
||||||
buttons[0].onclick = null;
|
signInBox["guest-login"].classList.remove("hide");
|
||||||
buttons[1].onclick = null;
|
signInBox["remove-account"].classList.add("hide");
|
||||||
signInBox.classList.add('hide')
|
signInBox["guest-login"].onclick = () => {
|
||||||
reject(null)
|
signInBox["key"].value = '';
|
||||||
|
signInBox["sign-in"].onclick = null;
|
||||||
|
signInBox["guest-login"].onclick = null;
|
||||||
|
signInBox.classList.add('hide')
|
||||||
|
reject(null)
|
||||||
|
}
|
||||||
|
} else if (type === "PIN/Password") {
|
||||||
|
signInBox["key"].setAttribute("placeholder", "Password")
|
||||||
|
signInBox["guest-login"].classList.add("hide");
|
||||||
|
signInBox["remove-account"].classList.remove("hide");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -1170,15 +1192,16 @@
|
|||||||
<div></div>
|
<div></div>
|
||||||
<div></div>
|
<div></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="sign-in-box" class="hide">
|
<form id="sign-in-box" onsubmit="return false;" class="hide">
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<span>SIGN IN</span>
|
<span>SIGN IN</span>
|
||||||
</div>
|
</div>
|
||||||
<div><input type="password"></div>
|
<div><input type="password" name="key"></div>
|
||||||
<div><button>🔑 Sign In</button><button>👤 Guest</button></div>
|
<div><button name="sign-in">🔑 Sign In</button><button name="guest-login">👤 Guest</button></div>
|
||||||
|
<input type="button" name="remove-account" value="Remove Account"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
<div id="startup-load-msg"></div>
|
<div id="startup-load-msg"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -1232,6 +1255,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<input type="text" id="view-privkey" title="Click to Copy" placeholder="◉ View Private Key" readonly/>
|
<input type="text" id="view-privkey" title="Click to Copy" placeholder="◉ View Private Key" readonly/>
|
||||||
|
<input type="button" id="secure-key" value="⚿ Secure Private Key" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
<input type="button" id="sign-out" value="↚ Sign Out" />
|
<input type="button" id="sign-out" value="↚ Sign Out" />
|
||||||
<input type="button" id="clear-data" value="☠ Clear Data" />
|
<input type="button" id="clear-data" value="☠ Clear Data" />
|
||||||
</div>
|
</div>
|
||||||
@ -1251,6 +1277,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="popup-overlay hide">
|
||||||
|
<div id="prompt-input" class="popup-container">
|
||||||
|
<fieldset>
|
||||||
|
<legend></legend>
|
||||||
|
<div class="input-container i-1">
|
||||||
|
<input type="text" placeholder="Value" />
|
||||||
|
</div>
|
||||||
|
<div class="input-container i-2">
|
||||||
|
<input type="submit" value="Ok" />
|
||||||
|
<input type="reset" value="Cancel" />
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div id="show-message" class="hide">
|
<div id="show-message" class="hide">
|
||||||
<span>Message</span>
|
<span>Message</span>
|
||||||
@ -1347,7 +1388,7 @@
|
|||||||
floID = e.target.parentNode.getAttribute("name");
|
floID = e.target.parentNode.getAttribute("name");
|
||||||
let toInput = document.forms["new-mail-form"]["to"]
|
let toInput = document.forms["new-mail-form"]["to"]
|
||||||
let tmp = toInput.value.trim();
|
let tmp = toInput.value.trim();
|
||||||
if(!tmp.includes(floID)){
|
if (!tmp.includes(floID)) {
|
||||||
if (tmp == '')
|
if (tmp == '')
|
||||||
tmp = floID;
|
tmp = floID;
|
||||||
else
|
else
|
||||||
@ -1360,23 +1401,42 @@
|
|||||||
|
|
||||||
document.getElementById("sign-out").addEventListener('click', function (e) {
|
document.getElementById("sign-out").addEventListener('click', function (e) {
|
||||||
getConfirmation('Sign Out?',
|
getConfirmation('Sign Out?',
|
||||||
'**Remember to store your PRIVATE-KEY** \nAre you sure you want to Sign out?', "Sign-Out", "Stay Signed-In").then(
|
'**Remember to store your PRIVATE-KEY** \nAre you sure you want to Sign out?', "Sign-Out",
|
||||||
|
"Stay Signed-In").then(
|
||||||
result => {
|
result => {
|
||||||
floDapps.logout().then(result => {
|
floDapps.logout().then(result => {
|
||||||
showMessage("Successfully Signed out")
|
showMessage("Successfully Signed out")
|
||||||
document.getElementById("settings-screen").parentNode.classList.add("hide");
|
|
||||||
setTimeout(onLoadStartUp, 2000)
|
setTimeout(onLoadStartUp, 2000)
|
||||||
}).catch(error => showMessage(error, "error"))
|
}).catch(error => showMessage("Signout Unsuccessful", "error", error))
|
||||||
}).catch(error => {})
|
}).catch(error => {})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.forms["sign-in-box"]["remove-account"].addEventListener('click', function (e) {
|
||||||
|
getConfirmation('Remove Account?',
|
||||||
|
'**Remember to store your PRIVATE-KEY**\*Private-Key will be needed to signIn again*\nAre you sure you want to remove account?',
|
||||||
|
"Remove").then(result => {
|
||||||
|
floDapps.logout().then(result => {
|
||||||
|
showMessage("Removed Account")
|
||||||
|
setTimeout(onLoadStartUp, 2000)
|
||||||
|
}).catch(error => showMessage("Remove Unsuccessful", "error", error))
|
||||||
|
}).catch(error => {})
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("secure-key").addEventListener('click', function (e) {
|
||||||
|
getPromptInput("Secure Private-Key", 'Enter Password', false).then(value => {
|
||||||
|
floDapps.securePrivKey(value)
|
||||||
|
.then(result => showMessage("Private Key secured"))
|
||||||
|
.catch(error => showMessage("Securing Failed", "error", error))
|
||||||
|
}).catch(error => {})
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById("clear-data").addEventListener('click', function (e) {
|
document.getElementById("clear-data").addEventListener('click', function (e) {
|
||||||
getConfirmation('Clear Data?',
|
getConfirmation('Clear Data?',
|
||||||
`Are you sure you want to clear stored data from the browser? \n**This can't be undone**\nMake sure you have stored the PRIVATE-KEY and Backuped the data.`, "Clear").then(
|
`Are you sure you want to clear stored data from the browser? \n**This can't be undone**\nMake sure you have stored the PRIVATE-KEY and Backuped the data.`,
|
||||||
|
"Clear").then(
|
||||||
result => {
|
result => {
|
||||||
floDapps.clearUserData().then(result => {
|
floDapps.clearUserData().then(result => {
|
||||||
showMessage("Successfully Cleared local data")
|
showMessage("Successfully Cleared local data")
|
||||||
document.getElementById("settings-screen").parentNode.classList.add("hide");
|
|
||||||
setTimeout(onLoadStartUp, 2000)
|
setTimeout(onLoadStartUp, 2000)
|
||||||
}).catch(error => showMessage(error, "error"))
|
}).catch(error => showMessage(error, "error"))
|
||||||
}).catch(error => {})
|
}).catch(error => {})
|
||||||
@ -1407,15 +1467,15 @@
|
|||||||
document.getElementById("settings-screen").parentNode.classList.remove('hide')
|
document.getElementById("settings-screen").parentNode.classList.remove('hide')
|
||||||
})
|
})
|
||||||
|
|
||||||
document.getElementById("view-privkey").addEventListener("mouseover", function(e){
|
document.getElementById("view-privkey").addEventListener("mouseover", function (e) {
|
||||||
this.value = myPrivKey;
|
this.value = myPrivKey;
|
||||||
})
|
})
|
||||||
|
|
||||||
document.getElementById("view-privkey").addEventListener("mouseout", function(e){
|
document.getElementById("view-privkey").addEventListener("mouseout", function (e) {
|
||||||
this.value = "";
|
this.value = "";
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("view-privkey").addEventListener("click", function(e){
|
document.getElementById("view-privkey").addEventListener("click", function (e) {
|
||||||
this.select();
|
this.select();
|
||||||
this.setSelectionRange(0, 52);
|
this.setSelectionRange(0, 52);
|
||||||
document.execCommand("copy");
|
document.execCommand("copy");
|
||||||
@ -1454,7 +1514,8 @@
|
|||||||
}
|
}
|
||||||
messenger.parseBackup(file).then(data => {
|
messenger.parseBackup(file).then(data => {
|
||||||
getConfirmation('Restore Data?',
|
getConfirmation('Restore Data?',
|
||||||
`Found:\n ${Object.keys(data.contacts).length} Contacts,\n ${Object.keys(data.messages).length} Messages,\n ${Object.keys(data.mails).length} Mails\nRestore Data?`, "Restore"
|
`Found:\n ${Object.keys(data.contacts).length} Contacts,\n ${Object.keys(data.messages).length} Messages,\n ${Object.keys(data.mails).length} Mails\nRestore Data?`,
|
||||||
|
"Restore"
|
||||||
).then(result => {
|
).then(result => {
|
||||||
restoreInfoText.textContent = `Restoring data! Please wait...`;
|
restoreInfoText.textContent = `Restoring data! Please wait...`;
|
||||||
messenger.restoreData(data).then(result => {
|
messenger.restoreData(data).then(result => {
|
||||||
@ -1528,6 +1589,42 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPromptInput(title, message, showText = true, trueBtn = "Ok", falseBtn = "Cancel") {
|
||||||
|
let promptInput = document.getElementById("prompt-input");
|
||||||
|
promptInput.getElementsByTagName("legend")[0].textContent = title;
|
||||||
|
promptInput.parentNode.classList.remove("hide");
|
||||||
|
let inputs = promptInput.getElementsByTagName("input");
|
||||||
|
inputs[0].setAttribute("placeholder", message)
|
||||||
|
if (showText)
|
||||||
|
inputs[0].setAttribute("type", "text")
|
||||||
|
else
|
||||||
|
inputs[0].setAttribute("type", "password")
|
||||||
|
inputs[1].value = trueBtn;
|
||||||
|
inputs[2].value = falseBtn;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let interval = setInterval(() => {
|
||||||
|
if (promptInput.parentNode.classList.contains("hide")) {
|
||||||
|
inputs[1].onclick = null;
|
||||||
|
inputs[2].onclick = null;
|
||||||
|
clearInterval(interval);
|
||||||
|
reject(false);
|
||||||
|
}
|
||||||
|
}, 1000)
|
||||||
|
inputs[1].onclick = () => {
|
||||||
|
clearInterval(interval);
|
||||||
|
let value = inputs[0].value;
|
||||||
|
inputs[0].value = '';
|
||||||
|
promptInput.parentNode.classList.add("hide")
|
||||||
|
resolve(value)
|
||||||
|
}
|
||||||
|
inputs[2].onclick = () => {
|
||||||
|
clearInterval(interval);
|
||||||
|
promptInput.parentNode.classList.add("hide")
|
||||||
|
reject(true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function showMessage(message, mode = "normal", log = "") {
|
function showMessage(message, mode = "normal", log = "") {
|
||||||
if (mode === "error")
|
if (mode === "error")
|
||||||
console.error(message, log)
|
console.error(message, log)
|
||||||
@ -1602,8 +1699,8 @@
|
|||||||
getConversationElement(floID).appendChild(msgBox)
|
getConversationElement(floID).appendChild(msgBox)
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderMarked(data){
|
function renderMarked(data) {
|
||||||
for(let d in data){
|
for (let d in data) {
|
||||||
let element = document.getElementsByName(d)[0]
|
let element = document.getElementsByName(d)[0]
|
||||||
data[d].forEach(mark => element.classList.add(mark))
|
data[d].forEach(mark => element.classList.add(mark))
|
||||||
}
|
}
|
||||||
@ -1668,7 +1765,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderMailList(mails, markUnread = true) {
|
function renderMailList(mails, markUnread = true) {
|
||||||
for (m in mails){
|
for (m in mails) {
|
||||||
renderMailCard(mails[m].ref, mails[m].subject, mails[m].time, mails[m].category, mails[m].floID);
|
renderMailCard(mails[m].ref, mails[m].subject, mails[m].time, mails[m].category, mails[m].floID);
|
||||||
if (markUnread)
|
if (markUnread)
|
||||||
document.getElementsByName(mails[m].ref)[0].classList.add("unread");
|
document.getElementsByName(mails[m].ref)[0].classList.add("unread");
|
||||||
@ -1681,58 +1778,58 @@
|
|||||||
clearElement(document.getElementById("mail-container")).parentNode.parentNode.classList.remove("hide");
|
clearElement(document.getElementById("mail-container")).parentNode.parentNode.classList.remove("hide");
|
||||||
|
|
||||||
messenger.getMail(mailRef).then(result => {
|
messenger.getMail(mailRef).then(result => {
|
||||||
//create mail content
|
//create mail content
|
||||||
let mailContent = document.createElement("div");
|
let mailContent = document.createElement("div");
|
||||||
mailContent.setAttribute("class", "mail-content");
|
mailContent.setAttribute("class", "mail-content");
|
||||||
//add subject
|
//add subject
|
||||||
let subjectTag = document.createElement("span");
|
let subjectTag = document.createElement("span");
|
||||||
subjectTag.textContent = result.subject;
|
subjectTag.textContent = result.subject;
|
||||||
mailContent.appendChild(subjectTag);
|
mailContent.appendChild(subjectTag);
|
||||||
//add category
|
//add category
|
||||||
let categoryTag = document.createElement("span");
|
let categoryTag = document.createElement("span");
|
||||||
categoryTag.textContent = result.category;
|
categoryTag.textContent = result.category;
|
||||||
mailContent.appendChild(categoryTag);
|
mailContent.appendChild(categoryTag);
|
||||||
//add name (if available)
|
//add name (if available)
|
||||||
if (Array.isArray(result.floID))
|
if (Array.isArray(result.floID))
|
||||||
result.floID = result.floID.join(", ")
|
result.floID = result.floID.join(", ")
|
||||||
let nameTag = document.createElement("span");
|
let nameTag = document.createElement("span");
|
||||||
nameTag.textContent = floGlobals.contacts[result.floID] || ' ';
|
nameTag.textContent = floGlobals.contacts[result.floID] || ' ';
|
||||||
mailContent.appendChild(nameTag);
|
mailContent.appendChild(nameTag);
|
||||||
//add floID
|
//add floID
|
||||||
let floIDTag = document.createElement("span");
|
let floIDTag = document.createElement("span");
|
||||||
floIDTag.textContent = `<${result.floID}>`;
|
floIDTag.textContent = `<${result.floID}>`;
|
||||||
mailContent.appendChild(floIDTag);
|
mailContent.appendChild(floIDTag);
|
||||||
//add data n time
|
//add data n time
|
||||||
let timeTag = document.createElement("span");
|
let timeTag = document.createElement("span");
|
||||||
timeTag.textContent = new Date(result.time).toString().slice(4, 21);
|
timeTag.textContent = new Date(result.time).toString().slice(4, 21);
|
||||||
mailContent.appendChild(timeTag);
|
mailContent.appendChild(timeTag);
|
||||||
//add mail content
|
//add mail content
|
||||||
let contentTag = document.createElement("p");
|
let contentTag = document.createElement("p");
|
||||||
contentTag.textContent = result.content;
|
contentTag.textContent = result.content;
|
||||||
mailContent.appendChild(contentTag);
|
mailContent.appendChild(contentTag);
|
||||||
//append the contents to mail container
|
//append the contents to mail container
|
||||||
document.getElementById("mail-container").appendChild(mailContent);
|
document.getElementById("mail-container").appendChild(mailContent);
|
||||||
//add prop for previous mail (if available)
|
//add prop for previous mail (if available)
|
||||||
let prevMail = document.getElementById("prev-mail");
|
let prevMail = document.getElementById("prev-mail");
|
||||||
prevMail.dataset["value"] = result.prevRef;
|
prevMail.dataset["value"] = result.prevRef;
|
||||||
prevMail.style.display = result.prevRef ? 'block' : 'none';
|
prevMail.style.display = result.prevRef ? 'block' : 'none';
|
||||||
//set values for reply mail form if new view
|
//set values for reply mail form if new view
|
||||||
if (newView) {
|
if (newView) {
|
||||||
if (result.floID.includes(','))
|
if (result.floID.includes(','))
|
||||||
document.getElementById("reply-mail").classList.add("hide");
|
document.getElementById("reply-mail").classList.add("hide");
|
||||||
else {
|
else {
|
||||||
let replyForm = document.forms["reply-mail-form"];
|
let replyForm = document.forms["reply-mail-form"];
|
||||||
replyForm.reset();
|
replyForm.reset();
|
||||||
replyForm.dataset["to"] = result.floID;
|
replyForm.dataset["to"] = result.floID;
|
||||||
replyForm.dataset["prevRef"] = mailRef;
|
replyForm.dataset["prevRef"] = mailRef;
|
||||||
replyForm["subject"].value = result.subject.startsWith("Re: ") ? result
|
replyForm["subject"].value = result.subject.startsWith("Re: ") ? result
|
||||||
.subject : `Re: ${result.subject}`;
|
.subject : `Re: ${result.subject}`;
|
||||||
document.getElementById("reply-mail").classList.remove("hide");
|
document.getElementById("reply-mail").classList.remove("hide");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
document.getElementsByName(mailRef)[0].classList.remove("unread");
|
}
|
||||||
messenger.removeMark(mailRef, "unread");
|
document.getElementsByName(mailRef)[0].classList.remove("unread");
|
||||||
}).catch(error => showMessage("Unable to read mail", "error", error))
|
messenger.removeMark(mailRef, "unread");
|
||||||
|
}).catch(error => showMessage("Unable to read mail", "error", error))
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendMail() {
|
function sendMail() {
|
||||||
@ -10118,16 +10215,6 @@ Bitcoin.Util = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
privKeyInput: function () {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
var privKey = prompt("Enter Private Key: ")
|
|
||||||
if (privKey === null)
|
|
||||||
reject(null)
|
|
||||||
else
|
|
||||||
resolve(privKey)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
startUpFunctions: {
|
startUpFunctions: {
|
||||||
|
|
||||||
readSupernodeListFromAPI: function () {
|
readSupernodeListFromAPI: function () {
|
||||||
@ -10181,7 +10268,19 @@ Bitcoin.Util = {
|
|||||||
|
|
||||||
getCredentials: function () {
|
getCredentials: function () {
|
||||||
|
|
||||||
var readSharesFromIDB = function (indexArr) {
|
const defaultInput = function (type) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let inputVal = prompt(`Enter ${type}: `)
|
||||||
|
if (inputVal === null)
|
||||||
|
reject(null)
|
||||||
|
else
|
||||||
|
resolve(inputVal)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputFn = this.getCredentials.privKeyInput || defaultInput;
|
||||||
|
|
||||||
|
const readSharesFromIDB = function (indexArr) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var promises = []
|
var promises = []
|
||||||
for (var i = 0; i < indexArr.length; i++)
|
for (var i = 0; i < indexArr.length; i++)
|
||||||
@ -10196,7 +10295,7 @@ Bitcoin.Util = {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var writeSharesToIDB = function (shares, i = 0, resultIndexes = []) {
|
const writeSharesToIDB = function (shares, i = 0, resultIndexes = []) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (i >= shares.length)
|
if (i >= shares.length)
|
||||||
return resolve(resultIndexes)
|
return resolve(resultIndexes)
|
||||||
@ -10212,17 +10311,16 @@ Bitcoin.Util = {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var getPrivateKeyCredentials = function () {
|
const getPrivateKeyCredentials = function () {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var indexArr = localStorage.getItem(
|
var indexArr = localStorage.getItem(`${floGlobals.application}#privKey`)
|
||||||
`${floGlobals.application}#privKey`)
|
|
||||||
if (indexArr) {
|
if (indexArr) {
|
||||||
readSharesFromIDB(JSON.parse(indexArr))
|
readSharesFromIDB(JSON.parse(indexArr))
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
} else {
|
} else {
|
||||||
var privKey;
|
var privKey;
|
||||||
floDapps.util.privKeyInput().then(result => {
|
inputFn("PRIVATE_KEY").then(result => {
|
||||||
try {
|
try {
|
||||||
if (!result)
|
if (!result)
|
||||||
return reject("Empty Private Key")
|
return reject("Empty Private Key")
|
||||||
@ -10238,9 +10336,8 @@ Bitcoin.Util = {
|
|||||||
privKey = floCrypto.generateNewID().privKey
|
privKey = floCrypto.generateNewID().privKey
|
||||||
}).finally(_ => {
|
}).finally(_ => {
|
||||||
var threshold = floCrypto.randInt(10, 20)
|
var threshold = floCrypto.randInt(10, 20)
|
||||||
writeSharesToIDB(floCrypto
|
writeSharesToIDB(floCrypto.createShamirsSecretShares(
|
||||||
.createShamirsSecretShares(
|
privKey, threshold, threshold)).then(
|
||||||
privKey, threshold, threshold)).then(
|
|
||||||
resultIndexes => {
|
resultIndexes => {
|
||||||
//store index keys in localStorage
|
//store index keys in localStorage
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
@ -10249,13 +10346,11 @@ Bitcoin.Util = {
|
|||||||
//also add a dummy privatekey to the IDB
|
//also add a dummy privatekey to the IDB
|
||||||
var randomPrivKey = floCrypto
|
var randomPrivKey = floCrypto
|
||||||
.generateNewID().privKey
|
.generateNewID().privKey
|
||||||
var randomThreshold = floCrypto.randInt(
|
var randomThreshold = floCrypto.randInt(10,
|
||||||
10,
|
|
||||||
20)
|
20)
|
||||||
writeSharesToIDB(floCrypto
|
writeSharesToIDB(floCrypto
|
||||||
.createShamirsSecretShares(
|
.createShamirsSecretShares(
|
||||||
randomPrivKey,
|
randomPrivKey, randomThreshold,
|
||||||
randomThreshold,
|
|
||||||
randomThreshold))
|
randomThreshold))
|
||||||
//resolve private Key
|
//resolve private Key
|
||||||
resolve(privKey)
|
resolve(privKey)
|
||||||
@ -10265,12 +10360,36 @@ Bitcoin.Util = {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const checkIfPinRequired = function (key) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (key.length == 52)
|
||||||
|
resolve(key)
|
||||||
|
else {
|
||||||
|
inputFn("PIN/Password").then(pwd => {
|
||||||
|
try {
|
||||||
|
let privKey = Crypto.AES.decrypt(key, pwd);
|
||||||
|
resolve(privKey)
|
||||||
|
} catch (error) {
|
||||||
|
reject("Access Denied: Incorrect PIN/Password")
|
||||||
|
}
|
||||||
|
}).catch(error => reject(
|
||||||
|
"Access Denied: PIN/Password required"))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
getPrivateKeyCredentials().then(privKey => {
|
getPrivateKeyCredentials().then(key => {
|
||||||
myPrivKey = privKey
|
checkIfPinRequired(key).then(privKey => {
|
||||||
myPubKey = floCrypto.getPubKeyHex(myPrivKey)
|
try {
|
||||||
myFloID = floCrypto.getFloIDfromPubkeyHex(myPubKey)
|
myPrivKey = privKey
|
||||||
resolve('Login Credentials loaded successful')
|
myPubKey = floCrypto.getPubKeyHex(myPrivKey)
|
||||||
|
myFloID = floCrypto.getFloIDfromPubkeyHex(myPubKey)
|
||||||
|
resolve('Login Credentials loaded successful')
|
||||||
|
} catch (error) {
|
||||||
|
reject("Corrupted Private Key")
|
||||||
|
}
|
||||||
|
}).catch(error => reject(error))
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -10330,28 +10449,39 @@ Bitcoin.Util = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setCustomPrivKeyInput: function (customFn) {
|
setCustomPrivKeyInput: function (customFn) {
|
||||||
this.util.privKeyInput = customFn
|
this.util.startUpFunctions.getCredentials.privKeyInput = customFn
|
||||||
},
|
},
|
||||||
|
|
||||||
logout: function () {
|
logout: function () {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
compactIDB.openDB(floGlobals.application).then(db => {
|
compactIDB.clearData("credentials", floGlobals.application).then(result => {
|
||||||
var obs = db.transaction("credentials", "readwrite").objectStore(
|
localStorage.removeItem(`${floGlobals.application}#privKey`);
|
||||||
"credentials");
|
floGlobals.appendix = floGlobals.contacts = floGlobals.pubKeys = undefined;
|
||||||
let clearReq = obs.clear();
|
myPrivKey = myPubKey = myFloID = undefined;
|
||||||
clearReq.onsuccess = evt => {
|
resolve(`Successfully logged out!`);
|
||||||
localStorage.removeItem(`${floGlobals.application}#privKey`);
|
}).catch(error => reject(error))
|
||||||
//clear memory data
|
|
||||||
floGlobals.appendix = floGlobals.contacts = floGlobals.pubKeys =
|
|
||||||
undefined;
|
|
||||||
myPrivKey = myPubKey = myFloID = undefined;
|
|
||||||
resolve(`Successfully logged out!`);
|
|
||||||
};
|
|
||||||
clearReq.onerror = evt => reject(evt.target.error);
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
securePrivKey: function (pwd) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let indexArr = localStorage.getItem(`${floGlobals.application}#privKey`)
|
||||||
|
if (!indexArr)
|
||||||
|
return reject("PrivKey not found");
|
||||||
|
indexArr = JSON.parse(indexArr)
|
||||||
|
let encryptedKey = Crypto.AES.encrypt(myPrivKey, pwd);
|
||||||
|
let threshold = indexArr.length;
|
||||||
|
let shares = floCrypto.createShamirsSecretShares(encryptedKey, threshold, threshold)
|
||||||
|
let promises = [];
|
||||||
|
for (var i = 0; i < threshold; i++)
|
||||||
|
promises.push(compactIDB.writeData("credentials", shares[i], indexArr[i], floGlobals
|
||||||
|
.application));
|
||||||
|
Promise.all(promises)
|
||||||
|
.then(results => resolve("Private Key Secured"))
|
||||||
|
.catch(error => reject(error))
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
clearUserData: function () {
|
clearUserData: function () {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let promises = [compactIDB.deleteDB(), this.logout()]
|
let promises = [compactIDB.deleteDB(), this.logout()]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user