floDapps_v2.0.1c
- Added verifyPin: function to verify the pin of login credentials without logging in (ie, not storing the keys in memory) - 'pin' argument can be ignored to check if private key is secured or not.
This commit is contained in:
parent
dd59c25d73
commit
836f359cf2
@ -8713,7 +8713,7 @@ Bitcoin.Util = {
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script id="floDapps" version="2.0.1b">
|
||||
<script id="floDapps" version="2.0.1c">
|
||||
/* General functions for FLO Dapps*/
|
||||
const floDapps = {
|
||||
|
||||
@ -9222,6 +9222,49 @@ Bitcoin.Util = {
|
||||
})
|
||||
},
|
||||
|
||||
verifyPin: function(pin = null) {
|
||||
const readSharesFromIDB = function(indexArr) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var promises = []
|
||||
for (var i = 0; i < indexArr.length; i++)
|
||||
promises.push(compactIDB.readData('credentials', indexArr[i]))
|
||||
Promise.all(promises).then(shares => {
|
||||
var secret = floCrypto.retrieveShamirSecret(shares)
|
||||
console.info(shares, secret)
|
||||
if (secret)
|
||||
resolve(secret)
|
||||
else
|
||||
reject("Shares are insufficient or incorrect")
|
||||
}).catch(error => reject(error))
|
||||
})
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
var indexArr = localStorage.getItem(`${floGlobals.application}#privKey`)
|
||||
console.info(indexArr)
|
||||
if (!indexArr)
|
||||
reject('No login credentials found')
|
||||
readSharesFromIDB(JSON.parse(indexArr)).then(key => {
|
||||
if (key.length == 52) {
|
||||
if (pin === null)
|
||||
resolve("Private key not secured")
|
||||
else
|
||||
reject("Private key not secured")
|
||||
} else {
|
||||
if (pin === null)
|
||||
return reject("PIN/Password required")
|
||||
try {
|
||||
let privKey = Crypto.AES.decrypt(key, pin);
|
||||
resolve("PIN/Password verified")
|
||||
} catch (error) {
|
||||
reject("Incorrect PIN/Password")
|
||||
}
|
||||
}
|
||||
}).catch(error => reject(error))
|
||||
})
|
||||
|
||||
|
||||
},
|
||||
|
||||
getNextGeneralData: function(type, vectorClock = null, options = {}) {
|
||||
var fk = floCloudAPI.util.filterKey(type, options)
|
||||
vectorClock = vectorClock || this.getNextGeneralData[fk] || '0';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user