Recover a wallet
This guide will walk you through how to use your users' backups to recover their wallet.
With Portal-managed Backups
When using Portal-managed backups, you can simply call the portal.recoverWallet()
function passing an empty string for the cipherText
parameter. Portal will then fetch the cipherText
from our backend and complete the recovery process.
Copy
WARNING: To recover a wallet with the Portal SDK, your device must be configured to use passcode authentication. Please note that if you disable your passcode authentication after executing the recover
function, you will need to run the recover
function again to continue using your Portal wallet.
With Backups from your server
Using portal.recoverWallet()
allows your users to recover their wallets in the event that their device is lost, broken, or stolen.
The MPC recovery process uses both the user backup shares and custodian backup shares (read about backups in the previous section before reading this) to create a new set of signing shares.
Recovery creates a new set of signing shares, and stores them on the user's device. Before we proceed, please be sure to review our recommendation for your database schema.
User Backup Share Recovery
At this point, a user will have already run portal.backupWallet()
and you will have stored their encrypted user backup share in your database. You now need to retrieve this user backup share in order to provide it to portal.recoverWallet()
. Behind the scenes our SDK retrieves the encryption key from the user's cloud storage provider and decrypts the encrypted user backup share to be used in the recovery process.
In order to support the user backup share portion of recovery, two dependencies must be met:
You must retrieve the correct user backup share by backup method from your API.
Your app must initiate the recovery process by passing in that encrypted user backup share.
Retrieving the user backup share
Create an API endpoint to get the user backup share, so that the user can start the recovery process.
Call portal.recoverWallet()
with the user backup share
portal.recoverWallet()
with the user backup shareSo now you have the user backup share from your API. The next step is to call portal.recoverWallet()
with it. Here's an example of how that might look in your Kotlin code:
WARNING: To recover a wallet with the Portal SDK, your device must be configured to use passcode authentication. Please note that if you disable your passcode authentication after executing the recover
function, you will need to run the recover
function again to continue using your Portal wallet.
Status Flow
Custodian Backup Share Recovery
Recovering your custodian backup share is done after you call portal.recoverWallet()
. Portal will attempt to retrieve all of the custodian backup shares for the user via the /backup/fetch
webhook.
To support custodian backup share recovery, two dependencies must be met:
Your webhook is configured in the Portal Admin Dashboard.
Your server must support the
POST
[webhookBaseURL]/backup/fetch
webhook endpoint to provide Portal the existing custodian backup shares for the client.
Implementing the /backup/fetch
Webhook
/backup/fetch
WebhookPortal will request the existing custodian backup shares with a POST
request to [webhookBaseURL]/backup/fetch
.
The request body of this POST
request will contain one field:
clientId
- The Portal Id of the user.
Next steps
Amazing! Your users now have multiple backups and can easily recover their wallet as a result. Next let's dive into handling sessions across multiple devices for your users.
Last updated