mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Merge approaches
This commit is contained in:
parent
62141ce952
commit
ad896a1275
8 changed files with 38 additions and 51 deletions
|
@ -17,7 +17,7 @@ public final class LokiStorageAPI : NSObject {
|
|||
notImplemented()
|
||||
}
|
||||
|
||||
public static func getOtherAccounts(for hexEncodedPublicKey: String) -> Promise<[String]> {
|
||||
public static func getAssociatedAccounts(for hexEncodedPublicKey: String) -> Promise<[String]> {
|
||||
// Gets the accounts associated with the given hex encoded public key from the server
|
||||
notImplemented()
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import PromiseKit
|
||||
|
||||
@objc(LKLongPoller)
|
||||
public final class LokiLongPoller : NSObject {
|
||||
public final class LongPoller : NSObject {
|
||||
private let onMessagesReceived: ([SSKProtoEnvelope]) -> Void
|
||||
private let storage = OWSPrimaryStorage.shared()
|
||||
private var hasStarted = false
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
public struct LokiDeviceLink {
|
||||
public let master: Device
|
||||
public let slave: Device
|
||||
|
||||
public var isAuthorized: Bool { return master.signature != nil }
|
||||
|
||||
// MARK: Types
|
||||
public struct Device {
|
||||
public let hexEncodedPublicKey: String
|
||||
public let signature: Data?
|
||||
|
||||
public init(hexEncodedPublicKey: String, signature: Data? = nil) {
|
||||
self.hexEncodedPublicKey = hexEncodedPublicKey
|
||||
self.signature = signature
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Lifecycle
|
||||
public init(between master: Device, and slave: Device) {
|
||||
self.master = master
|
||||
self.slave = slave
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
import PromiseKit
|
||||
|
||||
@objc(LKDeviceLinkingAPI)
|
||||
final class LokiDeviceLinkingSession : NSObject {
|
||||
private let delegate: LokiDeviceLinkingSessionDelegate
|
||||
private var timer: Timer?
|
||||
|
@ -24,19 +23,18 @@ final class LokiDeviceLinkingSession : NSObject {
|
|||
}
|
||||
}
|
||||
|
||||
public func processLinkingRequest(from slaveHexEncodedPublicKey: String, with slaveSignature: Data) {
|
||||
guard isListeningForLinkingRequests else { return }
|
||||
stopListeningForLinkingRequests()
|
||||
let master = LokiDeviceLink.Device(hexEncodedPublicKey: OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey)
|
||||
let slave = LokiDeviceLink.Device(hexEncodedPublicKey: slaveHexEncodedPublicKey, signature: slaveSignature)
|
||||
let deviceLink = LokiDeviceLink(between: master, and: slave)
|
||||
delegate.authorizeDeviceLinkIfValid(deviceLink)
|
||||
}
|
||||
|
||||
public func stopListeningForLinkingRequests() {
|
||||
timer?.invalidate()
|
||||
timer = nil
|
||||
isListeningForLinkingRequests = false
|
||||
}
|
||||
|
||||
public func processLinkingRequest(with signature: String) {
|
||||
guard isListeningForLinkingRequests else { return }
|
||||
stopListeningForLinkingRequests()
|
||||
delegate.handleDeviceLinkingRequestReceived(with: signature)
|
||||
}
|
||||
|
||||
public func authorizeLinkingRequest(with signature: String) {
|
||||
// TODO: Authorize the linking request with the given signature
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
public protocol LokiDeviceLinkingSessionDelegate {
|
||||
|
||||
func handleDeviceLinkingRequestReceived(with signature: String)
|
||||
func authorizeDeviceLinkIfValid(_ deviceLink: LokiDeviceLink)
|
||||
func handleDeviceLinkingSessionTimeout()
|
||||
}
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
@objc(LKPairingAuthorisation)
|
||||
public final class LokiPairingAuthorisation : NSObject, NSCoding {
|
||||
@objc public let primaryDevicePubKey: String
|
||||
@objc public let secondaryDevicePubKey: String
|
||||
@objc public let requestSignature: Data?
|
||||
@objc public let grantSignature: Data?
|
||||
|
||||
@objc public var isGranted: Bool {
|
||||
return grantSignature != nil
|
||||
}
|
||||
|
||||
@objc public init(primaryDevicePubKey: String, secondaryDevicePubKey: String, requestSignature: Data? = nil, grantSignature: Data? = nil) {
|
||||
self.primaryDevicePubKey = primaryDevicePubKey
|
||||
self.secondaryDevicePubKey = secondaryDevicePubKey
|
||||
self.requestSignature = requestSignature
|
||||
self.grantSignature = grantSignature
|
||||
}
|
||||
|
||||
public convenience init?(coder aDecoder: NSCoder) {
|
||||
guard let primaryDevicePubKey = aDecoder.decodeObject(forKey: "primaryDevicePubKey") as? String,
|
||||
let secondaryDevicePubKey = aDecoder.decodeObject(forKey: "secondaryDevicePubKey") as? String else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let requestSignature = aDecoder.decodeObject(forKey: "requestSignature") as? Data
|
||||
let grantSignature = aDecoder.decodeObject(forKey: "grantSignature") as? Data
|
||||
|
||||
self.init(primaryDevicePubKey: primaryDevicePubKey, secondaryDevicePubKey: secondaryDevicePubKey, requestSignature: requestSignature, grantSignature: grantSignature)
|
||||
}
|
||||
|
||||
public func encode(with aCoder: NSCoder) {
|
||||
aCoder.encode(primaryDevicePubKey, forKey: "primaryDevicePubKey")
|
||||
aCoder.encode(secondaryDevicePubKey, forKey: "secondaryDevicePubKey")
|
||||
aCoder.encode(requestSignature, forKey: "requestSignature")
|
||||
aCoder.encode(grantSignature, forKey: "grantSignature")
|
||||
}
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
extension OWSPrimaryStorage {
|
||||
|
||||
private func getCollection(for primaryDevice: String) -> String {
|
||||
return "LokiMultiDevice-\(primaryDevice)"
|
||||
}
|
Loading…
Reference in a new issue