diff --git a/floAuthenticator.html b/floAuthenticator.html
index 083a82a..84860d3 100644
--- a/floAuthenticator.html
+++ b/floAuthenticator.html
@@ -7544,6 +7544,65 @@ Bitcoin.Util = {
myFloID = floCrypto.getFloIDfromPubkeyHex(myPubKey)
}
+ function retriveCredentials(pinInput) {
+
+ if (typeof pinInput !== "function") {
+ pinInput = function () {
+ return new Promise((resolve, reject) => {
+ var input = prompt("Enter PIN")
+ if (input !== null)
+ resolve(input)
+ else
+ reject(null)
+ })
+ }
+ }
+
+ const readSharesFromIDB = function (pin, indexArr) {
+ return new Promise((resolve, reject) => {
+ var tableArr = []
+ for (var i = 0; i < indexArr.length; i++)
+ tableArr[i] = pin[i % pin.length]
+ var promises = []
+ for (var i = 0; i < indexArr.length; i++)
+ promises.push(compactIDB.readData(tableArr[i], indexArr[i], floGlobals.application))
+ Promise.all(promises).then(shares => {
+ var secret = floCrypto.retrieveShamirSecret(shares)
+ if (secret)
+ resolve(secret)
+ else
+ reject("Incorrect PIN or Insufficient Shares")
+ }).catch(error => reject(error))
+ })
+ }
+
+ const retrivePrivKey = function () {
+ return new Promise((resolve, reject) => {
+ let indexArr = localStorage.getItem(`${floGlobals.application}#privKey`)
+ if (indexArr) {
+ pinInput().then(pin => {
+ if (!pin)
+ return reject("Empty PIN")
+ if (!isNaN(pin))
+ return reject("Invalid PIN")
+ readSharesFromIDB(pin, JSON.parse(indexArr))
+ .then(result => resolve(result))
+ .catch(error => reject(error))
+ }).catch(error => reject("PIN not entered"))
+ } else
+ reject("No Credentials Stored")
+ })
+ }
+
+ return new Promise((resolve, reject) => {
+ retrivePrivKey().then(privKey => {
+ myPrivKey = privKey
+ myPubKey = floCrypto.getPubKeyHex(myPrivKey)
+ myFloID = floCrypto.getFloIDfromPubkeyHex(myPubKey)
+ resolve('Login Credentials loaded successful')
+ }).catch(error => reject(error))
+ })
+ }