Skip to content

Commit

Permalink
Enforce password for all imported
Browse files Browse the repository at this point in the history
  • Loading branch information
vncoelho committed Dec 27, 2023
1 parent f338b62 commit da6b739
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
34 changes: 21 additions & 13 deletions assets/eco-scripts/wallet_addNewAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@ function togglePasswordSwal() {
passwordField.attr('type', passwordFieldType === 'password' ? 'text' : 'password');
}

//Function to generated label to imported account
function makeid(length) {
let id = '';
const labelCharacters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let counter = 0;
while (counter < length) {
id += labelCharacters.charAt(Math.floor(Math.random() * labelCharacters.length));
counter += 1;
}
return id;
}

//First verifications for adding new wallet
function addWalletFromForm() {
var type = $("#type_to_register")[0].value;
var keyToAdd = $("#accountToAddInfo")[0].value;
var labelToAdd = $("#accountLabelToAddInfo")[0].value;

if (labelToAdd === "")
labelToAdd = "ImportedWallet_From_" + type;
labelToAdd = makeid(5) + "_From_" + type;

if (keyToAdd == "") {
swal2Simple("Error when adding " + type, "Empty key", 5500, "error");
return false;
}

if (type == 'address' && !Neon.wallet.isAddress(keyToAdd)) {
swal2Simple("Error when adding " + type, "Not valid", 5500, "error");
return false;
Expand All @@ -41,20 +55,14 @@ function addWalletFromForm() {
return false;
}

if (["publickey", "address", "scripthash"].includes(type)) {
if (["publickey", "address", "scripthash", "privatekey", "wif"].includes(type)) {
var accountToAdd = new Neon.wallet.Account(keyToAdd);
addAccountAndDraw(accountToAdd, labelToAdd);
addSafeAccount(accountToAdd, labelToAdd);
}

if (type == 'multisig') {
var accountToAdd = getAccountFromMultiSigVerification(keyToAdd);
addAccountAndDraw(accountToAdd, labelToAdd);
}

// These are more complex because requires encrypting data and setting a master key
if (["privatekey", "wif"].includes(type)) {
var accountToAdd = new Neon.wallet.Account(keyToAdd);
addSafeAccount(accountToAdd, labelToAdd)
addSafeAccount(accountToAdd, labelToAdd);
}

// Even more complex because requires first decrypting
Expand All @@ -71,12 +79,12 @@ function addAccountAndDraw(accountToAdd, labelToAdd) {
function addSafeAccount(accountToAdd, labelToAdd) {
//Asks for password if privatekey or wif or encrypted
if (MASTER_KEY_WALLET != "") {
swal2Simple("Your master key isalready defined", "This account will be linked to your password.\n Remember it!", 5500, "success");
swal2Simple("Your master key is already defined", "This account will be linked to your password.\n Remember it!", 5500, "success");
addAccountAndDraw(accountToAdd, labelToAdd);
} else {
setMasterKey(() => {
addAccountAndDraw(accountToAdd, labelToAdd);
}, "Restoring account from WIF/PrivateKey/EncryptedKey");
}, "Importing new account");
}
}

Expand Down Expand Up @@ -131,7 +139,7 @@ function setMasterKey(callback, labelToAdd, loading = false) {
$("#btnAddNewAccount")[0].disabled = true;
$("#btnLoadSavedAccount")[0].disabled = false;
}
swal2Simple("Nothing will happen!!", "A password is needed for this action.", 0, "error");
swal2Simple("You are blocked from importing new accounts!", "A MasterKey is needed for continuing.", 0, "error");
//callback();
}
});
Expand Down
4 changes: 4 additions & 0 deletions assets/eco-scripts/wallet_localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ function btnWalletClean() {
ECO_EXTRA_ACCOUNTS = [];
localStorage.removeItem("mySafeEncryptedExtraAccounts");
drawPopulateAllWalletAccountsInfo();

$("#btnAddNewAccount")[0].disabled = false;
$("#btnLoadSavedAccount")[0].disabled = true;

swal2Simple("Deleted!", "All saved addresses were delete", 0, "success");
} else {
swal2Simple("Safe!", "Your local storage for accounts is preserved", 0, "success");
Expand Down

0 comments on commit da6b739

Please sign in to comment.