mirror of
https://github.com/lil-org/tokenary.git
synced 2024-12-04 15:26:23 +03:00
Import keystore
This commit is contained in:
parent
f1f4e01c6f
commit
7c1cf0e496
@ -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("}")
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user