Use wallet recovery to enable your users to create multiple signing shares across their devices.
Once users successfully back up their wallets, they can generate a new set of signing shares irrespective of the SDK in use. Furthermore, both the new and old sets of signing shares can be used simultaneously, thanks to portal.recoverWallet. This provisioning relies on the user already having a successful set of backup shares (in the below example we'll assume they are password backup shares).
While recovering, the wallet fetches the encryption key from the user's cloud storage provider to decrypt the encrypted user backup share. Note that our SDK handles the decryption; you only need to supply the encrypted user backup share that was stored by your API.
For wallet recovery support, consult the recovery documentation to establish the necessary /backup/fetch webhook. Also, ensure the user has successfully completed the backup process.
Here's how to implement portal.recoverWallet:
importPortalSwiftstructCipherTextResult:Codable {var cipherText: String}classViewController:UIViewController {publicvar portal: Portal?publicvar yourApiUrl: String="https://YOUR_API_URL.com"@IBActionfunchandlePasswordRecover(_: UIButton!) {Task {do {guardlet portal = self.portal else {throw PortalExampleAppError.portalNotInitialized() }// Obtain the user's password.guardlet enteredPassword =awaitrequestPassword(), !enteredPassword.isEmptyelse {return }// Set the user's password.try portal.setPassword(enteredPassword)// Run password recover.tryawaitrecover(String(user.exchangeUserId), withBackupMethod: .Password) } catch {// Handle any errors during the recovery process. } } }publicfuncrecover(_userId: String, withBackupMethod: BackupMethods) asyncthrows-> void {guardlet portal else {throw PortalExampleAppError.portalNotInitialized() }guardlet config else {throw PortalExampleAppError.configurationNotSet() }// Obtain your API's URL for retrieving the encrypted user backup share. guard let url = URL(string: "\(yourApiUrl)/users/\(userId)/encrypted-user-backup-shares?backupMethod=\(withBackupMethod.rawValue)") else {
throwURLError(.badURL) }// Retrieve the encrypted user backup share on your API.let yourApiResponse =tryawait requests.get(url)let decodedResponse =try decoder.decode(CipherTextResult.self, from: yourApiResponse)let encryptedUserBackupShare = decodedResponse.encryptedUserBackupShare// Run recover.tryawait portal.recoverWallet(withBackupMethod, withCipherText: encryptedUserBackupShare) { status in// (Optional) Create a progress indicator here in the progress callback. }// ✅ The user has now recovered with their password successfully! }}
And that's it! You're now equipped to support multiple sessions across different devices for your users.