session-ios/SignalServiceKit/src/Account/TSAccountManager.h

145 lines
4.3 KiB
C
Raw Normal View History

2015-12-07 03:31:43 +01:00
//
2018-01-23 19:58:45 +01:00
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
2015-12-07 03:31:43 +01:00
//
#import "TSConstants.h"
NS_ASSUME_NONNULL_BEGIN
2017-04-08 03:28:34 +02:00
extern NSString *const TSRegistrationErrorDomain;
extern NSString *const TSRegistrationErrorUserInfoHTTPStatus;
2017-12-04 18:38:44 +01:00
extern NSString *const RegistrationStateDidChangeNotification;
extern NSString *const DeregistrationStateDidChangeNotification;
extern NSString *const kNSNotificationName_LocalNumberDidChange;
2015-12-07 03:31:43 +01:00
@class OWSPrimaryStorage;
@class TSNetworkManager;
2018-01-23 19:58:45 +01:00
@class YapDatabaseReadWriteTransaction;
2015-12-07 03:31:43 +01:00
@interface TSAccountManager : NSObject
2018-06-18 17:10:09 +02:00
// This property is exposed for testing purposes only.
#ifdef DEBUG
@property (nonatomic, nullable) NSString *phoneNumberAwaitingVerification;
#endif
2018-05-30 21:28:03 +02:00
#pragma mark - Initializers
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithNetworkManager:(TSNetworkManager *)networkManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage NS_DESIGNATED_INITIALIZER;
+ (instancetype)sharedInstance;
@property (nonatomic, strong, readonly) TSNetworkManager *networkManager;
2015-12-07 03:31:43 +01:00
/**
* Returns if a user is registered or not
*
* @return registered or not
*/
+ (BOOL)isRegistered;
- (BOOL)isRegistered;
2015-12-07 03:31:43 +01:00
/**
2017-01-03 22:32:53 +01:00
* Returns current phone number for this device, which may not yet have been registered.
2015-12-07 03:31:43 +01:00
*
* @return E164 formatted phone number
*/
+ (nullable NSString *)localNumber;
- (nullable NSString *)localNumber;
2015-12-07 03:31:43 +01:00
/**
* Symmetric key that's used to encrypt message payloads from the server,
*
* @return signaling key
*/
+ (nullable NSString *)signalingKey;
- (nullable NSString *)signalingKey;
/**
* The server auth token allows the Signal client to connect to the Signal server
*
* @return server authentication token
*/
+ (nullable NSString *)serverAuthToken;
- (nullable NSString *)serverAuthToken;
2015-12-07 03:31:43 +01:00
/**
* The registration ID is unique to an installation of TextSecure, it allows to know if the app was reinstalled
*
* @return registrationID;
*/
+ (uint32_t)getOrGenerateRegistrationId;
2018-01-23 19:58:45 +01:00
+ (uint32_t)getOrGenerateRegistrationId:(YapDatabaseReadWriteTransaction *)transaction;
2015-12-07 03:31:43 +01:00
#pragma mark - Register with phone number
+ (void)registerWithPhoneNumber:(NSString *)phoneNumber
2017-11-08 20:04:51 +01:00
success:(void (^)(void))successBlock
failure:(void (^)(NSError *error))failureBlock
2015-12-07 03:31:43 +01:00
smsVerification:(BOOL)isSMS;
2017-11-08 20:04:51 +01:00
+ (void)rerequestSMSWithSuccess:(void (^)(void))successBlock failure:(void (^)(NSError *error))failureBlock;
2015-12-07 03:31:43 +01:00
2017-11-08 20:04:51 +01:00
+ (void)rerequestVoiceWithSuccess:(void (^)(void))successBlock failure:(void (^)(NSError *error))failureBlock;
2015-12-07 03:31:43 +01:00
- (void)verifyAccountWithCode:(NSString *)verificationCode
2018-03-01 20:42:54 +01:00
pin:(nullable NSString *)pin
2017-11-08 20:04:51 +01:00
success:(void (^)(void))successBlock
failure:(void (^)(NSError *error))failureBlock;
2015-12-07 03:31:43 +01:00
// Called once registration is complete - meaning the following have succeeded:
// - obtained signal server credentials
// - uploaded pre-keys
// - uploaded push tokens
- (void)didRegister;
2015-12-07 03:31:43 +01:00
#if TARGET_OS_IPHONE
/**
* Register's the device's push notification token with the server
*
* @param pushToken Apple's Push Token
*/
- (void)registerForPushNotificationsWithPushToken:(NSString *)pushToken
voipToken:(NSString *)voipToken
2017-11-08 20:04:51 +01:00
success:(void (^)(void))successHandler
failure:(void (^)(NSError *error))failureHandler
2017-11-08 20:25:21 +01:00
NS_SWIFT_NAME(registerForPushNotifications(pushToken:voipToken:success:failure:));
2015-12-07 03:31:43 +01:00
#endif
2017-11-08 20:04:51 +01:00
+ (void)unregisterTextSecureWithSuccess:(void (^)(void))success failure:(void (^)(NSError *error))failureBlock;
2015-12-07 03:31:43 +01:00
2018-06-18 16:54:06 +02:00
#pragma mark - De-Registration
2018-06-18 17:10:09 +02:00
// De-registration reflects whether or not the "last known contact"
// with the service was:
//
// * A 403 from the service, indicating de-registration.
// * A successful auth'd request _or_ websocket connection indicating
// valid registration.
- (BOOL)isDeregistered;
- (void)setIsDeregistered:(BOOL)isDeregistered;
2018-06-18 16:54:06 +02:00
#pragma mark - Re-registration
// Re-registration is the process of re-registering _with the same phone number_.
// Returns YES on success.
- (BOOL)resetForReregistration;
- (NSString *)reregisterationPhoneNumber;
- (BOOL)isReregistering;
#pragma mark - Manual Message Fetch
- (BOOL)isManualMessageFetchEnabled;
- (void)setIsManualMessageFetchEnabled:(BOOL)value;
2015-12-07 03:31:43 +01:00
@end
NS_ASSUME_NONNULL_END