Custom privKeyInput is made promisified

privKeyInput now uses given key when resolved and generates random key when rejected
This commit is contained in:
sairajzero 2020-02-06 13:38:09 +05:30
parent cdeab33c20
commit 7a6a2dc9ea

View File

@ -8490,8 +8490,13 @@ Bitcoin.Util = {
}, },
privKeyInput: function(){ privKeyInput: function(){
var privKey = prompt("Enter Private Key: ") return new Promise((resolve, reject) => {
return privKey var privKey = prompt("Enter Private Key: ")
if(privKey === null)
reject(null)
else
resolve(privKey)
})
}, },
startUpFunctions:{ startUpFunctions:{
@ -8597,27 +8602,33 @@ Bitcoin.Util = {
.then(result => resolve(result)) .then(result => resolve(result))
.catch(error => reject(error)) .catch(error => reject(error))
}else{ }else{
try{ var privKey;
var privKey = floDapps.util.privKeyInput(); floDapps.util.privKeyInput().then(result => {
if(!privKey) try{
privKey = floCrypto.generateNewID().privKey if(!result)
var floID = floCrypto.getFloIDfromPubkeyHex(floCrypto.getPubKeyHex(privKey)) return reject("Empty Private Key")
console.log(floID) var floID = floCrypto.getFloIDfromPubkeyHex(floCrypto.getPubKeyHex(result))
}catch(error){ console.log(floID)
console.error(error) }catch(error){
return reject("Invalid Private Key") console.error(error)
} return reject("Invalid Private Key")
var threshold = floCrypto.randInt(10,20) }
writeSharesToIDB(floCrypto.createShamirsSecretShares(privKey, threshold, threshold)).then(resultIndexes =>{ }).catch(error => {
//store index keys in localStorage console.log(error, "Generating Random Keys")
localStorage.setItem(`${floGlobals.application}#privKey`, JSON.stringify(resultIndexes)) privKey = floCrypto.generateNewID().privKey
//also add a dummy privatekey to the IDB }).finally(_ => {
var randomPrivKey = floCrypto.generateNewID().privKey var threshold = floCrypto.randInt(10,20)
var randomThreshold = floCrypto.randInt(10,20) writeSharesToIDB(floCrypto.createShamirsSecretShares(privKey, threshold, threshold)).then(resultIndexes =>{
writeSharesToIDB(floCrypto.createShamirsSecretShares(randomPrivKey, randomThreshold, randomThreshold)) //store index keys in localStorage
//resolve private Key localStorage.setItem(`${floGlobals.application}#privKey`, JSON.stringify(resultIndexes))
resolve(privKey) //also add a dummy privatekey to the IDB
}).catch(error => reject(error)) var randomPrivKey = floCrypto.generateNewID().privKey
var randomThreshold = floCrypto.randInt(10,20)
writeSharesToIDB(floCrypto.createShamirsSecretShares(randomPrivKey, randomThreshold, randomThreshold))
//resolve private Key
resolve(privKey)
}).catch(error => reject(error))
})
} }
}) })
} }