fix: validate mnemonic format when importing a existing key

This commit is contained in:
Richard Ramos 2020-07-27 11:11:24 -04:00 committed by Jakub
parent ea000310de
commit e91cd9e610
4 changed files with 17 additions and 6 deletions

View File

@ -86,14 +86,14 @@ QtObject:
proc importMnemonic(self: OnboardingView, mnemonic: string): string {.slot.} =
try:
let importResult = self.status.accounts.importMnemonic(mnemonic)
let importResult = self.status.accounts.importMnemonic(mnemonic.strip())
result = importResult.toJson
self.currentAccount.setAccount(importResult)
except StatusGoException as e:
result = StatusGoError(error: e.msg).toJson
proc validateMnemonic*(self: OnboardingView, mnemonic: string): string {.slot.} =
result = self.status.wallet.validateMnemonic(mnemonic)
result = self.status.wallet.validateMnemonic(mnemonic.strip())
proc storeDerivedAndLogin(self: OnboardingView, password: string): string {.slot.} =
try:

View File

@ -140,7 +140,7 @@ QtObject:
result = self.status.wallet.generateNewAccount(password, accountName, color)
proc addAccountsFromSeed*(self: WalletView, seed: string, password: string, accountName: string, color: string): string {.slot.} =
result = self.status.wallet.addAccountsFromSeed(seed, password, accountName, color)
result = self.status.wallet.addAccountsFromSeed(seed.strip(), password, accountName, color)
proc addAccountsFromPrivateKey*(self: WalletView, privateKey: string, password: string, accountName: string, color: string): string {.slot.} =
result = self.status.wallet.addAccountsFromPrivateKey(privateKey, password, accountName, color)

View File

@ -30,8 +30,11 @@ QtObject {
}
function isMnemonic(value) {
// Do we support other length than 12?
return value.split(/\s|,/).length === 12
if(!value.match(/^([a-z\s]+)$/)){
return false;
}
var len = value.split(/\s|,/).length;
return len >= 12 && len <= 24 && len % 3 == 0;
}
function compactAddress(addr, numberOfChars) {

View File

@ -1,5 +1,6 @@
import QtQuick 2.13
import QtQuick.Controls 2.13
import "../imports"
Item {
property var onClosed: function () {}
@ -14,7 +15,14 @@ Item {
property bool wentNext: false
id: enterSeedPhraseModal
onConfirmSeedClick: function (mnemonic) {
let error = onboardingModel.validateMnemonic(mnemonic)
let error = "";
if(!Utils.isMnemonic(mnemonic)){
error = qsTr("Invalid mnemonic")
} else {
error = onboardingModel.validateMnemonic(mnemonic)
}
if (error != "") {
errorSound.play()
invalidSeedPhraseModal.error = error