diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 2330c0081..797da1447 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -915,39 +915,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; return deviceMessages; } -- (AnyPromise *)calculateProofOfWorkForDeviceMessages:(NSArray *)deviceMessages - ttl:(NSNumber *)ttl -{ - // Loki: Calculate the proof of work for each device message - NSMutableArray *promises = [NSMutableArray new]; - for (NSDictionary *deviceMessage in deviceMessages) { - AnyPromise *promise = [AnyPromise promiseWithValue:deviceMessage] - .thenOn(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(NSDictionary *message) { - NSTimeInterval timestampInterval = [[NSDate new] timeIntervalSince1970]; - NSNumber *timestamp = [NSNumber numberWithDouble:timestampInterval]; - - NSString *destination = message[@"destination"]; - NSString *data = message[@"content"]; - - NSString *nonce = [ProofOfWork calculateWithData:data pubKey:destination timestamp:timestamp.unsignedIntegerValue ttl:ttl.integerValue]; - - - // Return our timestamp along with the nonce - // These will help us identify which nonce belongs to which message - return @{ - @"destination" : destination, - @"deviceId" : message[@"destinationDeviceId"], - @"timestamp" : timestamp, - @"nonce" : nonce - }; - }); - [promises addObject:promise]; - } - - // Wait for all the PoW calculations to finish - return PMKWhen(promises); -} - - (void)sendMessageToRecipient:(OWSMessageSend *)messageSend { OWSAssertDebug(messageSend); diff --git a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.h b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.h index 3056b30ad..a83c9f7ef 100644 --- a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.h +++ b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.h @@ -59,11 +59,6 @@ typedef NS_ENUM(NSUInteger, TSVerificationTransport) { TSVerificationTransportVo captchaToken:(nullable NSString *)captchaToken transport:(TSVerificationTransport)transport; -+ (TSRequest *)submitLokiMessageRequestWithRecipient:(NSString *)recipientId - messages:(NSArray *)messages - nonceArray:(NSArray *)nonceArray - ttl:(NSNumber *)ttl; - + (TSRequest *)submitMessageRequestWithRecipient:(NSString *)recipientId messages:(NSArray *)messages timeStamp:(uint64_t)timeStamp diff --git a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m index 72d1fd5bf..68214a7d7 100644 --- a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m +++ b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m @@ -354,60 +354,6 @@ NS_ASSUME_NONNULL_BEGIN return [accountAttributes copy]; } -// Loki: Convert Signal JSON messages to Loki messages -// Refer to OWSMessageServiceParams for the Signal JSON params -+ (NSArray *)lokiMessagesFromMessages:(NSArray *)messages - nonceArray:(NSArray *)nonceArray - ttl:(NSNumber *)ttl { - NSMutableArray *modifiedMessages = [NSMutableArray new]; - for (NSDictionary *message in messages) { - NSMutableDictionary *lokiMessage = [NSMutableDictionary new]; - - // Params for our message server - lokiMessage[@"pubKey"] = message[@"destination"]; - lokiMessage[@"data"] = message[@"content"]; - lokiMessage[@"ttl"] = [ttl stringValue]; - - NSDictionary *_Nullable nonce = [self getNonceFromArray:nonceArray forMessage:message]; - if (nonce) { - lokiMessage[@"timestamp"] = nonce[@"timestmap"]; - lokiMessage[@"nonce"] = nonce[@"nonce"]; - } - - [modifiedMessages addObject:lokiMessage]; - } - - return modifiedMessages; -} - -+ (NSDictionary *_Nullable)getNonceFromArray:(NSArray *)nonceArray forMessage:(NSDictionary *)message { - NSPredicate *predicate = [NSPredicate predicateWithFormat:@"destination == %@ AND deviceId == %d", message[@"destination"], message[@"destinationDeviceId"]]; - NSArray *filtered = [nonceArray filteredArrayUsingPredicate:predicate]; - return filtered.count > 0 ? [filtered objectAtIndex:0] : nil; -} - -// Loki: This is the function below with our changes -+ (TSRequest *)submitLokiMessageRequestWithRecipient:(NSString *)recipientId - messages:(NSArray *)messages - nonceArray:(NSArray *)nonceArray - ttl:(NSNumber *)ttl -{ - // Messages may be empty; see comments in OWSDeviceManager. - // This doesn't apply to Loki since we don't have linked device support. - OWSAssertDebug(recipientId.length > 0); - OWSAssertDebug(messages.count > 0); - - // Convert to Loki JSON format - NSArray *lokiMessages = [self lokiMessagesFromMessages:messages nonceArray:nonceArray ttl:ttl]; - OWSAssertDebug(lokiMessages.count > 0); - - // Loki: Just send the first message - NSString *path = [textSecureMessagesAPI stringByAppendingString:recipientId]; - NSDictionary *parameters = [lokiMessages objectAtIndex:0]; - - return [TSRequest new]; // TODO: Just here to make things build -} - + (TSRequest *)submitMessageRequestWithRecipient:(NSString *)recipientId messages:(NSArray *)messages timeStamp:(uint64_t)timeStamp