session-ios/SignalServiceKit/src/Loki/Crypto/OWSPrimaryStorage+Loki.h

102 lines
3.3 KiB
C
Raw Normal View History

#import "OWSPrimaryStorage.h"
#import <YapDatabase/YapDatabase.h>
2019-05-21 05:06:46 +02:00
@class PreKeyRecord;
@class PreKeyBundle;
NS_ASSUME_NONNULL_BEGIN
@interface OWSPrimaryStorage (Loki)
2019-05-14 02:39:26 +02:00
# pragma mark - Prekey for Contact
/**
2019-05-14 02:39:26 +02:00
Check if we have a `PreKeyRecord` for the given contact.
2019-05-14 02:39:26 +02:00
@param pubKey The hex encoded public key of the contact.
@return Whether we have a prekey or not.
*/
- (BOOL)hasPreKeyForContact:(NSString *)pubKey;
/**
Get the `PreKeyRecord` associated with the given contact.
@param pubKey The hex encoded public key of the contact.
@param transaction A `YapDatabaseReadTransaction`.
2019-05-20 03:20:03 +02:00
@return The record associated with the contact or `nil` if it doesn't exist.
*/
- (PreKeyRecord *_Nullable)getPreKeyForContact:(NSString *)pubKey transaction:(YapDatabaseReadTransaction *)transaction;
/**
2019-05-14 02:39:26 +02:00
Get the `PreKeyRecord` associated with the given contact.
2019-05-14 01:50:28 +02:00
If the record doesn't exist then this will create a new one.
@param pubKey The hex encoded public key of the contact.
@return The record associated with the contact.
*/
2019-05-14 01:50:28 +02:00
- (PreKeyRecord *)getOrCreatePreKeyForContact:(NSString *)pubKey;
# pragma mark - PreKeyBundle
/**
2019-05-14 02:39:26 +02:00
Generate a `PreKeyBundle` for the given contact.
This doesn't store the prekey bundle, and you shouldn't store this bundle.
It's used for generating bundles to send to other users.
@param pubKey The hex encoded public key of the contact.
@return A prekey bundle for the contact.
*/
- (PreKeyBundle *)generatePreKeyBundleForContact:(NSString *)pubKey;
/**
2019-05-14 02:39:26 +02:00
Get the `PreKeyBundle` associated with the given contact.
@param pubKey The hex encoded public key of the contact.
@return The prekey bundle or `nil` if it doesn't exist.
*/
- (PreKeyBundle *_Nullable)getPreKeyBundleForContact:(NSString *)pubKey;
/**
2019-05-14 02:39:26 +02:00
Set the `PreKeyBundle` for the given contact.
@param bundle The prekey bundle.
2019-05-14 04:54:13 +02:00
@param transaction A `YapDatabaseReadWriteTransaction`.
@param pubKey The hex encoded public key of the contact.
*/
- (void)setPreKeyBundle:(PreKeyBundle *)bundle forContact:(NSString *)pubKey transaction:(YapDatabaseReadWriteTransaction *)transaction;
/**
2019-05-14 02:39:26 +02:00
Remove the `PreKeyBundle` for the given contact.
@param pubKey The hex encoded public key of the contact.
2019-05-14 04:54:13 +02:00
@param transaction A `YapDatabaseReadWriteTransaction`.
*/
- (void)removePreKeyBundleForContact:(NSString *)pubKey transaction:(YapDatabaseReadWriteTransaction *)transaction;
2019-05-21 05:06:46 +02:00
# pragma mark - Last Hash
/**
Get the last message hash for the given service node.
2019-05-21 07:21:51 +02:00
This function will check the stored last hash and remove it if the `expiresAt` has already passed.
2019-05-21 05:06:46 +02:00
2019-05-21 07:21:51 +02:00
@param serviceNode The service node ID.
@param transaction A read write transaction.
@return The last hash or `nil` if it doesn't exist.
2019-05-21 05:06:46 +02:00
*/
- (NSString *_Nullable)getLastMessageHashForServiceNode:(NSString *)serviceNode transaction:(YapDatabaseReadWriteTransaction *)transaction;
/**
Set the last message hash for the given service node.
This will override any previous hashes stored for the given service node.
2019-05-21 07:21:51 +02:00
@param serviceNode The service node ID.
@param hash The last message hash.
@param expiresAt The time the message expires on the server.
@param transaction A read write transaction.
2019-05-21 05:06:46 +02:00
*/
2019-05-21 07:21:51 +02:00
- (void)setLastMessageHashForServiceNode:(NSString *)serviceNode hash:(NSString *)hash expiresAt:(u_int64_t)expiresAt transaction:(YapDatabaseReadWriteTransaction *)transaction;
2019-05-21 05:06:46 +02:00
@end
NS_ASSUME_NONNULL_END