pull/26/head
Niels Andriesse 5 years ago
parent b20ac237b2
commit b2f114cd94

@ -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 {

@ -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

Loading…
Cancel
Save