Import keystore

This commit is contained in:
Ivan Grachev 2021-07-15 00:09:13 +03:00
parent f1f4e01c6f
commit 7c1cf0e496

View File

@ -11,7 +11,7 @@ struct AccountsService {
} else if let data = Data(hexString: input) {
return PrivateKey.isValid(data: data, curve: CoinType.ethereum.curve)
} else {
return false
return input.maybeJSON
}
}
@ -21,6 +21,12 @@ struct AccountsService {
key = HDWallet(mnemonic: input, passphrase: "").getKeyForCoin(coin: .ethereum)
} else if let data = Data(hexString: input), let privateKey = PrivateKey(data: data) {
key = privateKey
} else if input.maybeJSON,
let json = input.data(using: .utf8),
let jsonKey = StoredKey.importJSON(json: json),
let data = jsonKey.decryptPrivateKey(password: Data("1234".utf8)), // TODO: get password from user
let privateKey = PrivateKey(data: data) {
key = privateKey
} else {
return nil
}
@ -51,3 +57,11 @@ struct AccountsService {
}
}
private extension String {
var maybeJSON: Bool {
return hasPrefix("{") && hasSuffix("}")
}
}