diff --git a/SignalServiceKit/src/Loki/API/LokiAPI+Message.swift b/SignalServiceKit/src/Loki/API/LokiAPI+Message.swift index 188a965bc..2d280d2d2 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPI+Message.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPI+Message.swift @@ -40,8 +40,7 @@ public extension LokiAPI { if isPoWRequired { // The storage server takes a time interval in milliseconds let now = NSDate.ows_millisecondTimeStamp() - let ttlInSeconds = ttl / 1000 - if let nonce = ProofOfWork.calculate(data: data, pubKey: destination, timestamp: now, ttl: ttlInSeconds) { + if let nonce = ProofOfWork.calculate(data: data, pubKey: destination, timestamp: now, ttl: ttl) { let result = Message(destination: destination, data: data, ttl: ttl, timestamp: now, nonce: nonce) seal.fulfill(result) } else { diff --git a/SignalServiceKit/src/Loki/Crypto/ProofOfWork.swift b/SignalServiceKit/src/Loki/Crypto/ProofOfWork.swift index ccebf790e..4e69db3f7 100644 --- a/SignalServiceKit/src/Loki/Crypto/ProofOfWork.swift +++ b/SignalServiceKit/src/Loki/Crypto/ProofOfWork.swift @@ -63,7 +63,7 @@ public enum ProofOfWork { /// - data: The message data /// - pubKey: The message recipient /// - timestamp: The timestamp - /// - ttl: The message time to live, in **seconds** + /// - ttl: The message time to live /// - Returns: A nonce string or `nil` if it failed public static func calculate(data: String, pubKey: String, timestamp: UInt64, ttl: UInt64) -> String? { let payload = createPayload(pubKey: pubKey, data: data, timestamp: timestamp, ttl: ttl) @@ -103,7 +103,8 @@ public enum ProofOfWork { // Do all the calculations let totalLength = UInt64(payloadLength + nonceLength) - let ttlMult = ttl * totalLength + let ttlInSeconds = ttl / 1000 + let ttlMult = ttlInSeconds * totalLength // UInt64 values let innerFrac = ttlMult / two16