Portal-Managed Backups
Portal lets you securely back up your users’ MPC wallets so they can recover their wallets even if their device is lost or damaged. By default, Portal encrypts and stores both backup shares (“Portal-Managed Backups”):- The client backup share is encrypted on the user’s device, with the encryption key stored using their chosen backup method (Google Drive, iCloud, Password, Passkey, or Firebase Auth). The encrypted share is then stored by Portal.
- The custodian backup share is encrypted and stored by Portal, with the encryption key stored in our KMS infrastructure.
By default, Portal manages storing both the encrypted client backup share and the custodian backup share for you. If you prefer to store and manage the backup shares in your own infrastructure instead of using Portal-Managed Backups, see our Self-Managed Backups guide.
The re-backup behavior on this page requires
@portal-hq/core 6.0.0 or later.Run a backup again
You can run a backup again at any time, for example when the user changes their password. Portal keeps the previous backup as the active one until the new backup completes. If the app closes or a request fails before then, recovery still uses the previous backup. Once every wallet’s new backup share pair is complete, Portal deletes the previous backup’s pairs for that backup method. Backups made with other methods are not affected. A backup completes when:- Portal-Managed Backups: Portal has stored the encrypted client backup share.
backupWallet()resolves once Portal has accepted it. See WhenbackupWallet()rejects. - Self-Managed Backups: your app confirms that it stored the encrypted client backup share. See Self-Managed Backups.
When backupWallet() rejects
With Portal-Managed Backups, backupWallet() rejects with an MpcError in two cases:
- The request that stores the encrypted client backup share fails, for example after a dropped connection, and the SDK can’t confirm that Portal stored it and lists the new backup as active.
- Portal lists the new backup’s share pairs as not active after accepting the share.
backupWallet() resolves, and the SDK keeps the previous backup’s keys. With iCloud, that leaves the original key on the previous backup (see the iCloud limitations above).
A rejection doesn’t prove the new backup is inactive: Portal may have completed it. Portal still has an active backup for the method: the previous one, or this one. Whether the previous backup can still be decrypted depends on the backup method (see the table above):
- Google Drive, iCloud: the previous backup’s key is kept, so it can still be recovered.
- Password: until a backup completes, keep both passwords: the new backup may already be active.
- Passkey PRF: every backup uses the same passkey, so it can still be recovered.
- Passkey, Firebase: the key service keeps the previous backup’s key, so it can still be recovered, apart from the limitations above.
- Custom storage: it depends on whether your adapter keeps the previous key.
storageCallback(), recovery or private-key ejection runs at a time: starting another while one is running rejects with WALLET_MODIFICATION_ALREADY_IN_PROGRESS.
Self-Managed Backups
With Self-Managed Backups, your app stores the encrypted client backup share (cipherText) in your own infrastructure and then tells Portal it did. Use backupWalletWithResult(). It runs the same backup as backupWallet() and also returns a storageCallback that completes exactly this backup.
- Run the backup.
backupWalletWithResult()resolves with{ cipherText, backupSharePairIds, storageCallback }. The new backup isn’t complete yet, and the previous backup is still the active one. - Store
cipherTextas pending, next to the current one. Don’t replace the current one yet: until the new backup completes, recovery still needs it. - Call
storageCallback(). It marks exactly this backup’s share pairs as stored, then reads the client back to check that Portal lists the backup as active. With iCloud, it then updates the original iCloud key and deletes the previous backup’s key, as described in Run a backup again. If the pairs were marked stored but the client can’t be read back, it resolves and keeps the previous backup’s key. - Make the pending
cipherTextthe current one.
With Portal-Managed Backups, the backup is already complete when
backupWalletWithResult() resolves. storageCallback() then only confirms it again, so you don’t need to call it.backupWallet() followed by portal.api.storedClientBackupShare(true, method) still works: it completes the most recent backup for that backup method. With iCloud, if that backup is the one the same running app made, the SDK also updates the original iCloud key and deletes the previous backup’s key. Prefer backupWalletWithResult(), which completes exactly the backup whose cipherText you stored. On a dropped connection, storedClientBackupShare() can resolve without reaching Portal, which leaves the backup pending: keep the previous cipherText until portal.api.getClient() lists the new backup as completed. For the custodian backup share, see Self-Managed Backups.
Backup Methods
You can choose one or more backup methods for storing the encryption key for the client backup share.Passkey + Enclave
Allow customers to create a native passkey on their device that is used to authenticate into a secure enclave that holds the encryption key for the user. Customer’s passkeys are backed up to the native cloud storage for their device.Implementation Requirements
- Install
react-native-passkeysand@portal-hq/passkey-storage - Initialize passkey storage as a backup option in the Portal Config Object.
- Configuring the relying party
Relying party
A relying party is a trusted domain that is tied to the public key credentials of your users for their passkey . We offer the option to useportalhq.io as your relying party domain. It requires you to add portalhq.io as an Associated Domain in your iOS application and share your team id + application bundle id. If you already have your domain as a webcredential for your application then you can simply pass in your domain as the relying party and everything should work.
Use Portal as your relying party
- iOS
- Android
- Add
portalhq.ioas a web credential domain in your app. - Share your app bundle id and team id with the Portal Team.
Use your own relying party
- iOS
- Android
Ensure you have set up your associate domain correctly in your app and that you are serving an aasa file from your relying party domain. You will need to be sure you have the
webcredential field set properly for your app in your aasa file.Resources from apple:Relying Party Origins
Regardless of the relying party decision you make above, you will need to set the relying party origin to:Read more info here on how to get the SHA256 hash of the apk signing cert.
Password/PIN
Allow users to create a password/pin. Users can either remember the password or store it in a password storage manager.Implementation Requirements
- Create a UI for password input.
- Enforce password requirements. Customer can choose between password, PIN code, passcode, or any other text-based input.
- If user forgets password there are no additional recovery options.
iCloud
See the docs on how to set up iCloud.Google Drive
See the docs on how to set up Google Drive.Firebase Auth Backup
Allow customers to use their existing Firebase Authentication to authenticate into a secure enclave that holds the encryption key for the user. The Portal SDK leverages Firebase ID tokens to securely store and retrieve encryption keys from the secure enclave. This is ideal if your app already uses Firebase Auth — no additional authentication method is required from your users. See the Firebase Auth Backup setup guide for prerequisites and Firebase project configuration.Implementation requirements
- Install
@portal-hq/firebase-storageand integrate Firebase Authentication in your app (for example with@react-native-firebase/auth). - Add a
FirebaseStorageinstance to thebackupobject on yourPortalconstructor options, with agetTokenfunction that returns a valid Firebase ID token string ornullwhen no user is signed in.
Configure Firebase storage
Register Firebase alongside your other backup adapters when you constructPortal. The SDK assigns your Portal API client to each storage adapter automatically, which FirebaseStorage needs for requests to Portal’s Trustless Backup Service (TBS).
FirebaseStorage accepts an optional tbsHost if you need a non-default TBS URL; otherwise it uses the production host.- Portal-Managed Backups
- Self-Managed Backups
Ensure the user is signed in to Firebase, then run backup. With Portal-Managed Backups (the default), Portal stores the encrypted client backup share for you.