Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gh 716 push notifications #730

Merged
merged 8 commits into from Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -17,7 +17,7 @@ struct RegisterNotificationTokenRequest: JSONRequest {
let version: String
let deviceType: String = "IOS"
let buildNumber: String
let timestamp: String
let timestamp: String?
let signatures: [String]?

var httpMethod: String { return "POST" }
Expand All @@ -31,7 +31,7 @@ struct RegisterNotificationTokenRequest: JSONRequest {
bundle: String,
version: String,
buildNumber: String,
timestamp: String = String(Int(Date().timeIntervalSince1970 * 1_000))) throws {
timestamp: String?) throws {

self.uuid = deviceID.uuidString.lowercased()
self.safes = safes.map { $0.checksummed }
Expand All @@ -50,11 +50,14 @@ struct RegisterNotificationTokenRequest: JSONRequest {
self.version,
self.deviceType,
self.buildNumber,
self.timestamp
self.timestamp ?? ""
]
.joined()

if let signature = try? Signer.sign(string).value {
guard timestamp != nil else {
throw "'timestamp' parameter is required if signing key exists"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe preconditionFailure() is better because this would be a programmer's error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

}
self.signatures = [signature]
} else {
self.signatures = nil
DmitryBespalov marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -80,15 +83,16 @@ extension SafeTransactionService {
token: String,
bundle: String,
version: String,
buildNumber: String) throws -> RegisterNotificationTokenRequest.Response {

buildNumber: String,
timestamp: String?) throws -> RegisterNotificationTokenRequest.Response {
return try execute(
request: try RegisterNotificationTokenRequest(deviceID: deviceID,
safes: safes,
token: token,
bundle: bundle,
version: version,
buildNumber: buildNumber)
buildNumber: buildNumber,
timestamp: timestamp)
)
}
}
8 changes: 7 additions & 1 deletion Multisig/UI/App/RemoteNotificationHandler.swift
Expand Up @@ -173,14 +173,20 @@ class RemoteNotificationHandler {
guard let token = self.token else { return }
queue.async { [unowned self] in
let appConfig = App.configuration.app
var timestamp: String?
if let _ = try? App.shared.keychainService.data(forKey: KeychainKey.ownerPrivateKey.rawValue) {
// add timestamp if there is a signing key
timestamp = String(Int(Date().timeIntervalSince1970 * 1_000))
}
do {
try App.shared.safeTransactionService
.register(deviceID: self.deviceID,
safes: addresses,
token: token,
bundle: appConfig.bundleIdentifier,
version: appConfig.marketingVersion,
buildNumber: appConfig.buildVersion)
buildNumber: appConfig.buildVersion,
timestamp: timestamp)
} catch {
logError("Failed to register device", error)
}
Expand Down