mirror of
https://github.com/lil-org/wallet.git
synced 2024-12-28 23:14:11 +03:00
clean up mnemonic inputs of extra spaces
This commit is contained in:
parent
fc78b1125f
commit
0635215d80
@ -49,4 +49,10 @@ extension String {
|
||||
return prefix + String(value, radix: 16)
|
||||
}
|
||||
|
||||
var singleSpaced: String {
|
||||
let trimmedString = self.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let singleSpacedString = trimmedString.replacingOccurrences(of: "\\s+", with: " ", options: .regularExpression, range: nil)
|
||||
return singleSpacedString
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,9 +26,10 @@ final class WalletsManager {
|
||||
}
|
||||
|
||||
func validateWalletInput(_ input: String) -> InputValidationResult {
|
||||
if Mnemonic.isValid(mnemonic: input) {
|
||||
let trimmedInput = input.singleSpaced
|
||||
if Mnemonic.isValid(mnemonic: trimmedInput) {
|
||||
return .valid
|
||||
} else if let data = Data(hexString: input) {
|
||||
} else if let data = Data(hexString: trimmedInput) {
|
||||
return PrivateKey.isValid(data: data, curve: CoinType.ethereum.curve) ? .valid : .invalid
|
||||
} else {
|
||||
return input.maybeJSON ? .requiresPassword : .invalid
|
||||
@ -48,9 +49,10 @@ final class WalletsManager {
|
||||
guard let password = keychain.password else { throw Error.keychainAccessFailure }
|
||||
let name = defaultWalletName
|
||||
let defaultCoin = CoinType.ethereum
|
||||
if Mnemonic.isValid(mnemonic: input) {
|
||||
return try importMnemonic(input, name: name, encryptPassword: password)
|
||||
} else if let data = Data(hexString: input), PrivateKey.isValid(data: data, curve: defaultCoin.curve), let privateKey = PrivateKey(data: data) {
|
||||
let trimmedInput = input.singleSpaced
|
||||
if Mnemonic.isValid(mnemonic: trimmedInput) {
|
||||
return try importMnemonic(trimmedInput, name: name, encryptPassword: password)
|
||||
} else if let data = Data(hexString: trimmedInput), PrivateKey.isValid(data: data, curve: defaultCoin.curve), let privateKey = PrivateKey(data: data) {
|
||||
return try importPrivateKey(privateKey, name: name, password: password, coin: defaultCoin, onlyToKeychain: false)
|
||||
} else if input.maybeJSON, let inputPassword = inputPassword, let json = input.data(using: .utf8) {
|
||||
return try importJSON(json, name: name, password: inputPassword, newPassword: password, coin: defaultCoin, onlyToKeychain: false)
|
||||
|
Loading…
Reference in New Issue
Block a user