Skip to main content

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”):
  1. 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.
  2. 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.
Both the client backup share and the custodian backup share are necessary to recover a Portal wallet.
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 When backupWallet() rejects.
  • Self-Managed Backups: your app confirms that it stored the encrypted client backup share. See Self-Managed Backups.
What happens to the encryption key of the previous backup depends on the backup method:
iCloud limitations. The original iCloud key, which the iOS SDK and React Native SDK versions before 6.0.0 read, is updated only right after this SDK reads the client back and Portal lists the new backup as active: in backupWallet() with Portal-Managed Backups, in storageCallback(), or in portal.api.storedClientBackupShare(true, 'ICLOUD') when it completes a backup that the same running app made. Until it’s updated, those apps still read the previous backup’s key and can’t recover the new backup. That happens when:
  • The app closes between the backup completing and the key update. It’s fixed by the next iCloud backup that completes with 6.0.0 or later.
  • Portal accepted the backup but the SDK couldn’t read the client back. backupWallet() or storageCallback() still resolves. It’s fixed the same way.
  • The backup is completed another way, for example from your server or after the app restarted.
Also:
  • Interrupted backups leave their key behind. The SDK deletes a key only once Portal reports that its backup share pairs no longer exist, and Portal doesn’t list a backup that never completed. Each leftover is one small key in the app’s iCloud key-value store, which holds at most 1,024 keys and 1 MB per app.
  • Backups made with the iOS SDK or earlier React Native versions aren’t protected. Those SDKs overwrite the original key before the backup completes.
Passkey and Firebase limitations. The key service identifies the active backup’s key by when each key was written. In two cases it can return a key that doesn’t decrypt the active backup, and recovery fails:
  • Two backups with the same method run at about the same time, for example on two devices. Run the backup again from a device that still has the wallet. Once it completes, recovery works.
  • The key service can’t reach Portal during recovery. It then returns the most recent key, which after an interrupted re-backup belongs to the backup that didn’t complete. Try the recovery again later.

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.
If Portal accepted the share but the SDK can’t read the client back to check, 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.
With every method, it’s safe to run the backup again, and that’s how to recover: once a backup completes, it becomes the active backup and the wallet can be recovered from it. Only one backup, storageCallback(), recovery or private-key ejection runs at a time: starting another while one is running rejects with WALLET_MODIFICATION_ALREADY_IN_PROGRESS.
Custodian backup shares stored with backup hooks. If Portal sends the custodian backup share to your server through the /backup hook, the previous backup stays recoverable only if your server keeps the earlier shares and returns them from /backup/fetch. A server that replaces the stored share on each /backup call loses the previous backup’s custodian share as soon as a re-backup starts, so an interrupted re-backup leaves no backup that can be recovered. See Self-Managed Backups.

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.
  1. 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.
  2. Store cipherText as pending, next to the current one. Don’t replace the current one yet: until the new backup completes, recovery still needs it.
  3. 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.
  4. Make the pending cipherText the current one.
  • If storageCallback() rejects, the backup may still have completed, for example when the response was lost. Keep both the previous and the pending cipherText, and call storageCallback() again until it resolves. Calling it more than once is safe: pairs that are already complete stay as they are. Never discard the pending cipherText after a rejection. It rejects without changing anything if a newer backup has replaced this one.
  • Store the backupSharePairIds with the pending cipherText. If the app restarts before storageCallback() resolves, the pending one is active when portal.api.getClient() lists those IDs as completed for the method: make it current.
  • Once storageCallback() resolves, the previous cipherText no longer recovers the wallet. If promoting the pending cipherText fails, retry it, and never discard the pending 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

  1. Install react-native-passkeys and @portal-hq/passkey-storage
  2. Initialize passkey storage as a backup option in the Portal Config Object.
  3. 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 use portalhq.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

  1. Add portalhq.io as a web credential domain in your app.
  2. Share your app bundle id and team id with the Portal Team.

Use your own relying party

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

  1. Create a UI for password input.
  2. Enforce password requirements. Customer can choose between password, PIN code, passcode, or any other text-based input.
  3. If user forgets password there are no additional recovery options.
This example uses Self-Managed Backups: your app stores the encrypted client backup share. It follows the steps in Self-Managed Backups.

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

  1. Install @portal-hq/firebase-storage and integrate Firebase Authentication in your app (for example with @react-native-firebase/auth).
  2. Add a FirebaseStorage instance to the backup object on your Portal constructor options, with a getToken function that returns a valid Firebase ID token string or null when no user is signed in.

Configure Firebase storage

Register Firebase alongside your other backup adapters when you construct Portal. 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.
The user must be signed in to Firebase before running backup or recovery. If there is no signed-in user, getToken should return null and the operation will fail.
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.
Related Documentation