mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			44 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			44 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Swift
		
	
| 
											5 years ago
										 | import PromiseKit | ||
| 
											5 years ago
										 | 
 | ||
|  | extension Storage { | ||
|  |      | ||
| 
											5 years ago
										 |     static func prepareForV2KeyPairMigration() { | ||
| 
											5 years ago
										 |         let userDefaults = UserDefaults.standard | ||
| 
											5 years ago
										 |         let isUsingAPNs = userDefaults[.isUsingFullAPNs] | ||
|  |         if isUsingAPNs, let hexEncodedToken = userDefaults[.deviceToken] { | ||
| 
											5 years ago
										 |             let token = Data(hex: hexEncodedToken) | ||
|  |             PushNotificationAPI.unregister(token).retainUntilComplete() // TODO: Wait for this to complete? | ||
|  |         } | ||
| 
											5 years ago
										 |         let displayName = OWSProfileManager.shared().localProfileName() | ||
| 
											5 years ago
										 |         let appDelegate = UIApplication.shared.delegate as! AppDelegate | ||
|  |         appDelegate.stopPoller() | ||
|  |         appDelegate.stopClosedGroupPoller() | ||
|  |         appDelegate.stopOpenGroupPollers() | ||
|  |         OWSStorage.resetAllStorage() | ||
|  |         OWSUserProfile.resetProfileStorage() | ||
|  |         Environment.shared.preferences.clear() | ||
|  |         AppEnvironment.shared.notificationPresenter.clearAllNotifications() | ||
| 
											5 years ago
										 |         userDefaults[.isUsingFullAPNs] = isUsingAPNs | ||
|  |         userDefaults[.displayName] = displayName | ||
|  |         userDefaults[.isMigratingToV2KeyPair] = true | ||
| 
											5 years ago
										 |         exit(0) | ||
|  |     } | ||
| 
											5 years ago
										 |      | ||
|  |     static func finishV2KeyPairMigration(navigationController: UINavigationController) { | ||
|  |         let seed = Data.getSecureRandomData(ofSize: 16)! | ||
|  |         let (ed25519KeyPair, x25519KeyPair) = KeyPairUtilities.generate(from: seed) | ||
|  |         KeyPairUtilities.store(seed: seed, ed25519KeyPair: ed25519KeyPair, x25519KeyPair: x25519KeyPair) | ||
|  |         TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = x25519KeyPair.hexEncodedPublicKey | ||
|  |         OWSPrimaryStorage.shared().setRestorationTime(0) | ||
|  |         UserDefaults.standard[.hasViewedSeed] = false | ||
|  |         let displayName = UserDefaults.standard[.displayName]! // Checked earlier | ||
|  |         OWSProfileManager.shared().updateLocalProfileName(displayName, avatarImage: nil, success: { }, failure: { _ in }, requiresSync: false) | ||
|  |         TSAccountManager.sharedInstance().didRegister() | ||
|  |         let homeVC = HomeVC() | ||
|  |         navigationController.setViewControllers([ homeVC ], animated: true) | ||
|  |         let syncTokensJob = SyncPushTokensJob(accountManager: AppEnvironment.shared.accountManager, preferences: Environment.shared.preferences) | ||
|  |         syncTokensJob.uploadOnlyIfStale = false | ||
|  |         let _: Promise<Void> = syncTokensJob.run() | ||
|  |     } | ||
| 
											5 years ago
										 | } |