diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 253071590..c1c50bf36 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -2569,3 +2569,4 @@ "Invalid public key" = "Invalid public key"; "No search results" = "No search results"; "Calculating proof of work" = "Calculating proof of work"; +"Failed to calculate proof of work." = "Failed to calculate proof of work."; diff --git a/SignalServiceKit/src/Loki/ECKeyPair.m b/SignalServiceKit/src/Loki/ECKeyPair.m index bbf77f769..2f42d4087 100644 --- a/SignalServiceKit/src/Loki/ECKeyPair.m +++ b/SignalServiceKit/src/Loki/ECKeyPair.m @@ -16,7 +16,7 @@ extern void curve25519_donna(unsigned char *output, const unsigned char *a, cons } static const uint8_t basepoint[ECCKeyLength] = { 9 }; NSMutableData *publicKey = [NSMutableData dataWithLength:ECCKeyLength]; - if (!publicKey) { OWSFail(@"Could not allocate buffer"); } + if (!publicKey) { OWSFail(@"Couldn't allocate buffer."); } curve25519_donna(publicKey.mutableBytes, privateKey.mutableBytes, basepoint); // Use KVC to access privateKey and publicKey even though they're private ECKeyPair *result = [ECKeyPair new]; diff --git a/SignalServiceKit/src/Loki/LokiMessage.swift b/SignalServiceKit/src/Loki/LokiMessage.swift index 55060e832..e937802ef 100644 --- a/SignalServiceKit/src/Loki/LokiMessage.swift +++ b/SignalServiceKit/src/Loki/LokiMessage.swift @@ -1,6 +1,6 @@ import PromiseKit -@objc public final class LokiMessage : NSObject { +public struct LokiMessage { /// The hex encoded public key of the receiver. let destination: String /// The content of the message. @@ -12,7 +12,7 @@ import PromiseKit /// The base 64 encoded proof of work. let nonce: String - init(destination: String, data: LosslessStringConvertible, ttl: UInt64, timestamp: UInt64, nonce: String) { + public init(destination: String, data: LosslessStringConvertible, ttl: UInt64, timestamp: UInt64, nonce: String) { self.destination = destination self.data = data self.ttl = ttl @@ -37,7 +37,7 @@ import PromiseKit } } - func toJSON() -> [String:String] { + public func toJSON() -> [String:String] { return [ "destination" : destination, "data" : data.description, diff --git a/SignalServiceKit/src/Loki/LokiMessagingAPI.swift b/SignalServiceKit/src/Loki/LokiMessagingAPI.swift index 73567f642..668e31755 100644 --- a/SignalServiceKit/src/Loki/LokiMessagingAPI.swift +++ b/SignalServiceKit/src/Loki/LokiMessagingAPI.swift @@ -2,9 +2,9 @@ import PromiseKit @objc public final class LokiMessagingAPI : NSObject { - private static var baseURL: String { return textSecureServerURL } - private static var port: String { return "8080" } - private static var apiVersion: String { return "v1" } + private static let baseURL = "http://13.238.53.205" + private static let port = "8080" + private static let apiVersion = "v1" public static let defaultTTL: UInt64 = 4 * 24 * 60 * 60 // MARK: Types @@ -34,7 +34,7 @@ import PromiseKit let request = TSRequest(url: url, method: "POST", parameters: [ "method" : method.rawValue, "params" : parameters ]) return TSNetworkManager.shared().makePromise(request: request) } - + public static func sendSignalMessage(_ signalMessage: SignalMessage, to destination: String) -> Promise { return LokiMessage.fromSignalMessage(signalMessage).then(sendMessage) } @@ -50,4 +50,9 @@ import PromiseKit ] return invoke(.retrieveAllMessages, parameters: parameters) } + + // MARK: Obj-C API + @objc public static func sendSignalMessage(_ signalMessage: SignalMessage, to destination: String, completionHandler: @escaping (Any?, NSError?) -> Void) { + sendSignalMessage(signalMessage, to: destination).done { completionHandler($0.responseObject, nil) }.catch { completionHandler(nil, $0 as NSError) } + } }