2020-03-04 07:14:38 +00:00
|
|
|
import Foundation
|
|
|
|
import SecretKit
|
2020-03-17 06:39:34 +00:00
|
|
|
import SecretAgentKit
|
2020-03-04 07:14:38 +00:00
|
|
|
import UserNotifications
|
|
|
|
|
|
|
|
class Notifier {
|
|
|
|
|
|
|
|
func prompt() {
|
|
|
|
let notificationCenter = UNUserNotificationCenter.current()
|
|
|
|
notificationCenter.requestAuthorization(options: .alert) { _, _ in
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 07:56:55 +00:00
|
|
|
func notify(accessTo secret: AnySecret, by provenance: SigningRequestProvenance) {
|
2020-03-04 07:14:38 +00:00
|
|
|
let notificationCenter = UNUserNotificationCenter.current()
|
|
|
|
let notificationContent = UNMutableNotificationContent()
|
|
|
|
notificationContent.title = "Signed Request"
|
2020-03-17 07:56:55 +00:00
|
|
|
notificationContent.body = "\(secret.name) was used to sign a request from \(provenance.origin.name)."
|
2020-03-04 07:14:38 +00:00
|
|
|
let request = UNNotificationRequest(identifier: UUID().uuidString, content: notificationContent, trigger: nil)
|
|
|
|
notificationCenter.add(request, withCompletionHandler: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-03-17 06:39:34 +00:00
|
|
|
|
|
|
|
extension Notifier: SigningWitness {
|
|
|
|
|
2020-03-19 03:04:24 +00:00
|
|
|
func speakNowOrForeverHoldYourPeace(forAccessTo secret: AnySecret, by provenance: SigningRequestProvenance) throws {
|
|
|
|
}
|
|
|
|
|
2020-03-17 07:56:55 +00:00
|
|
|
func witness(accessTo secret: AnySecret, by provenance: SigningRequestProvenance) throws {
|
|
|
|
notify(accessTo: secret, by: provenance)
|
2020-03-17 06:39:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|