session-ios/SignalUtilitiesKit/CreatePreKeysOperation.swift

34 lines
955 B
Swift
Raw Normal View History

2020-11-11 00:58:56 +01:00
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
import PromiseKit
@objc(SSKCreatePreKeysOperation)
public class CreatePreKeysOperation: OWSOperation {
2020-11-19 00:37:18 +01:00
private var storage: OWSPrimaryStorage {
2020-11-11 00:58:56 +01:00
return OWSPrimaryStorage.shared()
}
private var identityKeyManager: OWSIdentityManager {
return OWSIdentityManager.shared()
}
public override func run() {
Logger.debug("")
if identityKeyManager.identityKeyPair() == nil {
identityKeyManager.generateNewIdentityKeyPair()
}
2020-11-19 00:37:18 +01:00
let signedPreKeyRecord = storage.generateRandomSignedRecord()
signedPreKeyRecord.markAsAcceptedByService()
storage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord)
storage.setCurrentSignedPrekeyId(signedPreKeyRecord.id)
print("[Loki] Pre keys created successfully.")
2020-11-11 00:58:56 +01:00
reportSuccess()
}
}