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, 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.

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 page 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 records that the encrypted client backup share is stored:
  • Portal-Managed Backups: Portal stores it during backupWallet(), which resolves once the backup is complete.
  • Self-Managed Backups: your app stores it and then calls the storageCallback that backupWallet() returned. See Run a self-managed backup again.
Whether the previous backup can still be decrypted until then depends on where its encryption key is stored:
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 in two browsers. 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.
With Portal-Managed Backups, if backupWallet() rejects, the new backup may still have completed: when the connection drops after Portal records it, Portal makes the new backup the active one and deletes the previous backup’s share pairs, but backupWallet() can’t tell. (With Self-Managed Backups, backupWallet() doesn’t complete the backup, so a rejection leaves the previous backup active. For storageCallback() rejections, see Run a self-managed backup again.) So after a rejection:
  • Run the backup again before relying on recovery. Once a backup completes, it becomes the active one and the wallet can be recovered from it.
  • Password: until a backup completes, keep both passwords. Recovery may need the new one.
  • Google Drive, Passkey, Firebase: nothing to keep. Both keys are stored, and recovery finds the one that decrypts the active backup (apart from the limitations above).
  • Passkey PRF: nothing to keep. Every backup uses the same passkey.
  • Custom (BackupMethods.custom) and generateBackupShare() with Portal-Managed Backups: the new key is returned only when the call resolves. If it rejects after Portal completed the backup, that key is lost and the previous backup no longer recovers the wallet. Run the backup again right away.
Starting in 5.0.0, recoverWallet() checks that the backup it decrypts is the client’s active backup, and so do eject() and ejectPrivateKeys() with Portal-Managed Backups. A cipherText from a backup that never completed is rejected with an error whose id is BACKUP_SHARE_PAIR_NOT_ACTIVE when its key still decrypts it (Google Drive, Passkey PRF, Custom). With Passkey and Firebase, the key service returns the active backup’s key, so such a cipherText fails with Failed to decrypt (error code 407) instead. Portal would also refuse to recover from that backup. Password backups are not checked, and neither are ejects with Self-Managed Backups, which run on the cipherText and organization share your app supplies.
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.
Passkey backups that store the key from your page complete at different points:
  • generateBackupShare() (Custom Domain Passkeys): with Portal-Managed Backups, the new backup is complete when generateBackupShare() resolves, before authenticatePasskeyAndWriteKey() stores its key. If storing the key fails, run the backup again.
  • backupWithPasskey({ usePopup: false }): starting in 5.0.0, the new backup completes only after the passkey service has stored its key, so a failed key write leaves the previous backup active. The progress callback reports Done only once the backup is complete. This flow requires Portal-Managed Backups: with Self-Managed Backups it rejects before starting a backup, so use generateBackupShare() and store the cipherText yourself.
In both, the key service keeps the previous backup’s key, so recovery gets the key of whichever backup is active, as described for Passkey above.

Run a self-managed backup again

With Self-Managed Backups, your app stores the encrypted client backup share (cipherText) in your own infrastructure and then tells Portal it did. backupWallet() resolves before the new backup is complete, so keep the previous cipherText until it is:
  1. Run the backup. backupWallet() resolves with { cipherText, storageCallback }. 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. Portal then makes the new backup the active one and deletes the previous backup’s pairs.
  4. Make the pending cipherText the current one. Identify it by the cipherText itself, not only by backup method: two backups running at once, for example in two tabs, each store their own pending share.
  • 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 stored stay as they are. Never discard the pending cipherText after a rejection. If the page closes before a call resolves, keep both: if recovery with the current one fails with BACKUP_SHARE_PAIR_NOT_ACTIVE, with Failed to decrypt (error code 407) for Passkey or Firebase, or, for Password, with BackupSharePair Does Not Exist or Cannot run recovery, backup was not completed successfully. Try running backup again., recover with the pending one and make it current. If a newer backup with the same method has started since, it replaced this backup’s pairs, and storageCallback() rejects without changing anything.
  • 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.
portal.storedClientBackupShare(true, method) also completes a backup, but it completes the most recent backup for that backup method, which may not be the one whose cipherText you stored. Prefer storageCallback(). The exception is generateBackupShare() (Custom Domain Passkeys), which returns no storageCallback, so that flow completes with storedClientBackupShare(true, BackupMethods.passkey). portal.storedClientBackupShare(false, method) doesn’t change anything. 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

Your Portal clients can create a passkey to authenticate and manage the private encryption key within a secure enclave.

Implementation Requirements

  1. Initialize the Portal class with a passkey object.
  2. Call backup with the Passkey backup method argument.

Custom Domain Passkeys

By default, Portal handles passkey operations through our hosted domain (portalhq.io). If you want passkeys to be associated with your own domain (e.g., yourapp.com), you can configure a custom relying party. Benefits of using your own domain:
  • Passkey prompts display your domain name instead of Portal’s
  • Users see a consistent brand experience
  • Passkeys are portable across your applications that share the same relying party
Setup Requirements
To use your own domain for passkeys, you’ll need to:
  1. Configure DNS - Point your passkey subdomain (e.g., passkeys.yourapp.com) to Portal’s infrastructure
  2. Provision a TLS certificate - Create a certificate for your subdomain that Portal will store in our secure enclave
  3. Configure CORS - Allowlist your application origins
Getting Started: Reach out to the Portal team for instructions on setting up a custom domain, including TLS certificate provisioning for our enclave.
Configuration
Once your custom domain is set up, configure your passkey options:
Step 1: Create a Passkey
Create a passkey for your user. This can be done separately from the backup flow:
Step 2: Create a Backup
Once a passkey exists, you can create a backup and store the encryption key with it:

Password/PIN

Your Portal clients can create a password/PIN. They 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 the user forgets their password, there are no additional recovery options.

Google Drive

Your Portal clients can store the encryption key in their own Google Drive. When a backup or recovery needs Drive access, the SDK asks the user to choose a Google account and grant the Drive scopes your configuration needs.

Implementation Requirements

  1. Set up Google Drive in a Google Cloud project and create an OAuth client ID of type Web application. Google sign-in runs in the Portal iframe, so Google checks the iframe’s origin, not your app’s: under Authorized JavaScript origins, add https://web.portalhq.io, or your custom subdomain, such as https://portal.yourdomain.com, if you set host.
  2. Initialize the Portal class with a gdrive object containing the OAuth clientId and, optionally, a backupOption.
  3. Once the SDK is ready, call backup with the Google Drive backup method argument from a user action, such as a button click.

Choose where backups are stored

Starting in 4.2.0, backupOption decides where the SDK writes backups and where it looks for them: The scopes are https://www.googleapis.com/auth/drive.file and https://www.googleapis.com/auth/drive.appdata. Omitting backupOption keeps the behavior of earlier SDK versions. Any other value throws from the Portal constructor. appDataFolderWithFallback reads the user-visible Drive only when the app data folder has no backup. Starting in 5.0.0, recovery also reads it when no file in the app data folder decrypts the backup (see Run a backup again). If Drive returns an error while the SDK looks for the backup, recovery fails with that error instead of falling back.

Share backups with your iOS and Android apps

To recover on one platform a backup made on another, every platform needs OAuth clients from one Google Cloud project, the same backup location and the same Google account. Share backups across platforms in the GDrive setup guide explains why and lists the equivalent option on each platform. On the web:
  • Create your web OAuth client in the same Google Cloud project as your iOS and Android OAuth clients, whichever backupOption you use.
  • Match the location your other apps use. The Web SDK defaults to the user-visible folder, while the iOS and Android guides use the app data folder. With those settings, a backup made on iOS or Android is not found on the web. To share backups with those apps, set backupOption to 'appDataFolder', or to 'appDataFolderWithFallback' if your users already have web backups and won’t later recover with an option or app that reads only the user-visible folder (see Change the backup location for existing users). The React Native SDK only uses the user-visible folder, so keep 'gdriveFolder' to share backups with a React Native app.

Change the backup location for existing users

Changing backupOption doesn’t move or delete existing backups. The SDK only looks where the new option tells it to: Web SDK versions earlier than 4.2.0 only use the user-visible folder, so they can’t read backups written to the app data folder. A new backup also replaces the user’s previous one without deleting its file: after a user with a user-visible backup backs up in the app data folder, the older user-visible file holds a key that no longer matches their wallet. Recovery that reads only the user-visible folder, with 'gdriveFolder' or a Web SDK earlier than 4.2.0, can find that file and fail with Failed to decrypt (error code 407), and other apps that only use the user-visible folder, such as a React Native app, can find it too. So once users have backed up with 'appDataFolder' or 'appDataFolderWithFallback', don’t move them back to 'gdriveFolder' or to an earlier Web SDK version.
Recovery fails with [GDriveStorage] File could not be found. when there is no backup file where the configured backupOption looks, even if a backup exists elsewhere: in the user-visible folder while you use 'appDataFolder', in the app data folder while you use 'gdriveFolder' or a Web SDK earlier than 4.2.0, in the app data folder of a different Google Cloud project, or in a different Google account. If it finds an older user-visible file instead, recovery fails with Failed to decrypt (error code 407).

Google sign-in and sessions

  • Pop-ups: Google sign-in opens in a pop-up window. The Portal iframe opens it, not your page, so browsers can block it even when the backup or recovery starts from a click. Chrome blocks it with its default settings; allowing pop-ups for your site, then reloading the page, lets it open. A blocked pop-up isn’t reported: backupWallet or recoverWallet fails only when the SDK’s request times out, after 90 seconds.
  • Declined scopes: Google’s consent screen lets users untick individual scopes. If a scope the backupOption needs is not granted, the backup or recovery fails with [GoogleAuth] The user did not grant the required Google Drive scopes: followed by the scope URLs. Starting in 4.2.0 this applies to every backupOption, including the default.
  • Sessions: an open page keeps using the Google access token it already has. After a page reload, Google sign-in can be reused for up to five minutes when the Portal iframe is on the same site as your app, for example with a custom subdomain. The SDK keeps that session in cookies on the iframe’s origin. With the default iframe host, which is on a different site from your app, browsers may not keep these cookies, so users may be asked to choose their Google account again after a reload.
  • Signing out and switching users (Client Auth): starting in 5.0.0, the Google Drive session belongs to the Portal end user who was signed in when Google access was granted. After portal.auth.clearSession(), or when a different end user signs in, the next backup or recovery opens Google sign-in again so the user can choose their account. This includes the same end user signing back in after clearSession(), and reloading the page or creating a new Portal iframe in between doesn’t skip it. See Pop-ups above. If you sign out or sign in a different end user during a Google Drive backup or recovery, the change takes effect once it finishes. Signing out ends the Google Drive session only inside the Portal iframe: it doesn’t sign the user out of their Google account or revoke the access they granted.
  • Scope changes: a saved session is reused only if it covers the scopes the current backupOption needs, so after you change backupOption the user may be asked to sign in again. A Google session saved by 4.2.0 or earlier isn’t reused after upgrading to 5.0.0.

Drive errors

Starting in 4.2.0, if Google Drive returns an error while the SDK looks up, creates or uploads the backup file, backupWallet rejects with Drive’s error code and message, for example [GDriveStorage] Error writing file: 403 …, and the backup is not recorded as stored. Earlier versions could report a backup as complete even though the upload failed.

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 Web SDK uses Firebase ID tokens to store and retrieve encryption keys from Portal’s Trustless Backup Service (TBS). This is ideal if your web app already uses Firebase Auth, since your users need no additional authentication method. See the Firebase Auth Backup setup guide for prerequisites and Firebase project configuration.

Implementation requirements

  1. Integrate Firebase Authentication in your web app (for example with the Firebase JavaScript SDK).
  2. Call portal.configureFirebaseStorage with a getToken callback that returns a Firebase ID token for the signed-in user, or null when no user is signed in.
  3. Run backup with BackupMethods.firebase only after Firebase storage is configured and the user is signed in.
Unlike React Native, the Web SDK does not use a separate @portal-hq/firebase-storage package. Firebase backup is built into @portal-hq/web via configureFirebaseStorage. Your app supplies Firebase Auth; the Portal iframe requests ID tokens from the parent page through a secure postMessage bridge.

Configure Firebase storage

Call configureFirebaseStorage before backupWallet or recoverWallet with BackupMethods.firebase. You typically do this immediately before the backup or recovery flow, or once after the user signs in to Firebase.
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.
The tab examples below assume a portal instance and configureFirebaseForPortal helper from the Configure Firebase storage section above.
Ensure the user is signed in to Firebase, configure storage, then run backup. With Portal-Managed Backups (the default), Portal stores the encrypted client backup share for you.
Related documentation