Implement all signatures on iOS

This commit is contained in:
Ivan Grachyov 2021-12-13 17:11:23 +03:00
parent d7fea70986
commit d7618495ce
2 changed files with 47 additions and 1 deletions

View File

@ -83,6 +83,34 @@ class AccountsListViewController: UIViewController, DataStateContainer {
self?.respondTo(request: request, response: response)
}
presentForSafariRequest(selectAccountViewController.inNavigationController)
case .signTypedMessage:
guard let raw = request.raw,
let wallet = walletsManager.getWallet(address: request.address),
let address = wallet.ethereumAddress else {
respondTo(request: request, error: Strings.somethingWentWrong)
return
}
showApprove(subject: .signTypedData, address: address, meta: raw, peerMeta: peerMeta) { [weak self] approved in
if approved {
self?.signTypedData(wallet: wallet, raw: raw, request: request)
} else {
self?.respondTo(request: request, error: Strings.failedToSign)
}
}
case .signMessage:
guard let data = request.message,
let wallet = walletsManager.getWallet(address: request.address),
let address = wallet.ethereumAddress else {
respondTo(request: request, error: Strings.somethingWentWrong)
return
}
showApprove(subject: .signMessage, address: address, meta: data.hexString, peerMeta: peerMeta) { [weak self] approved in
if approved {
self?.signMessage(wallet: wallet, data: data, request: request)
} else {
self?.respondTo(request: request, error: Strings.failedToSign)
}
}
case .signPersonalMessage:
guard let data = request.message,
let wallet = walletsManager.getWallet(address: request.address),
@ -365,6 +393,24 @@ class AccountsListViewController: UIViewController, DataStateContainer {
}
}
private func signTypedData(wallet: TokenaryWallet, raw: String, request: SafariRequest) {
if let signed = try? ethereum.sign(typedData: raw, wallet: wallet) {
let response = ResponseToExtension(name: request.name, result: signed)
respondTo(request: request, response: response)
} else {
respondTo(request: request, error: Strings.failedToSign)
}
}
private func signMessage(wallet: TokenaryWallet, data: Data, request: SafariRequest) {
if let signed = try? ethereum.sign(data: data, wallet: wallet) {
let response = ResponseToExtension(name: request.name, result: signed)
respondTo(request: request, response: response)
} else {
respondTo(request: request, error: Strings.failedToSign)
}
}
}
extension AccountsListViewController: UITableViewDelegate {

View File

@ -15,7 +15,7 @@ class ApproveViewController: UIViewController {
tableView.dataSource = self
tableView.registerReusableCell(type: MultilineLabelTableViewCell.self)
tableView.registerReusableCell(type: ImageWithLabelTableViewCell.self)
tableView.contentInset.bottom = 56
tableView.contentInset.bottom = 20
}
}