๐ŸŒCross-device sessions

Use wallet provisioning 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.provisionWallet. This provisioning relies on the user already having a successful set of backup shares.

While provisioning, the wallet fetches the encryption key from the user's cloud storage provider to decrypt the encrypted client backup share. Note that our SDK handles the decryption; you only need to supply the encrypted client backup share.

For wallet provisioning 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.provisionWallet:

import PortalSwift

struct CipherTextResult: Codable {
    var cipherText: String
}

class ViewController: UIViewController {
    public var portal: Portal?
    public var yourApiUrl: String = "https://YOUR_API_URL.com"
    public var clientId: String = "YOUR_CLIENT_ID"
    
    @IBAction func handleRecover(_ sender: UIButton!) {
        // Get the existing encrypted client backup share from your API.
        let request = HttpRequest<CipherTextResult, [String : String]>(
            url: "\(yourApiUrl)clients/\(clientId)/backup",
            method: "GET",
            body: [:],
            headers: ["Content-Type": "application/json"]
        )
    
        // Send the request.
        request.send() { (result: Result<Any>) in
            if let error = result.error {
                // โŒ Handle errors retrieving the backup share.
                print("Error fetching backup share: \(error.localizedDescription)")
                return
            }
    
            guard let response = result.data as? Dictionary<String, String>,
                  let backupShare = response["backupShare"] else {
                // Handle unexpected data format or backupShare missing.
                print("Unexpected data format or backupShare missing.")
                return
            }
    
            // Provide the encrypted client backup share and the backup method to provisionWallet.
            self.portal?.provisionWallet(
                cipherText: backupShare,
                method: BackupMethods.iCloud.rawValue
            ) { (result: Result<String>) -> Void in
                if let error = result.error {
                    // โŒ Handle provisionWallet errors.
                    print("Error provisioning the wallet: \(error.localizedDescription)")
                    return
                }

                // Success, maybe update the UI or navigate elsewhere.
            } progress: { status in
                print("Provision Wallet Status: ", status)
            }
        }
    }
}

And that's it! You're now equipped to support multiple sessions across different devices for your users.

Last updated