Recover a wallet from backup
Overview
This guide describes how to retrieve a backup of the user's client key shard stored in the Sky Mavis's key management service.
The backup is essential for accessing the user's wallet on a new device or client. The recovery process involves fetching the encrypted client key shard from the Sky Mavis server and decrypting it using the user's recovery kit.
Prerequisites
- Complete the steps in Create a keyless wallet
- Complete the steps in Send a transaction
Steps
Step 1. Verify wallet creation
Form a request to the Sky Mavis Account service to verify the wallet creation.
Request:
GET https://api-gateway.skymavis.com/account/userinfo
X-API-Key: {YOUR_API_KEY} // API key from the Developer Console
Authorization: Bearer {ACCESS_TOKEN} // User's access token
Response:
{
"ronin_address": "<string>",
"wallet_type": "mpc"
}
The ronin_address
field must match the wallet public key. The wallet_type
field must be equal to mpc
.
Step 2. Get client shard backup from Sky Mavis
- Web
- Unity
Function signature:
async function getBackupClientShard()
Result:
Name | Type | Description |
---|---|---|
key | String | Encrypted client key shard from an existing backup. |
updatedAt | String | Latest time update. |
Example:
const result = await lockbox.getBackupClientShard();
console.log("Encrypted client shard: ", result.key);
//...
Task<(string, MPCError)> MPC.GetBackupKey()
Example:
var (encryptedKey, error) = await MPC.GetBackupKey();
if (error != null) {
Debug.LogError($"Error when getting backup of private key shard: {error.message}");
}
else {
Debug.Log($"Key backup retrieved from server: {encryptedKey}");
}
Step 3. Decrypt the client shard
During the wallet creation process, you asked the user to create a passphrase to encrypt the private key shard. At this step, collect this passphrase from the user to decrypt the shard.
- Web
- Unity
Lockbox generates a recovery kit that users can enter to decrypt the key in case of a passphrase loss.
Function signature:
async function decryptClientShard(encryptedClientShard: string, passphrase? : string, recoveryPhrase? : string)
Parameters:
Name | Type | Required | Description |
---|---|---|---|
encryptedClientShard | String | Required | The client shard encrypted with the passphrase. |
passphrase | String | Optional | The passphrase used to encrypt the client shard. |
recoveryPhrase | String | Optional | The set of words generated when encrypting the client shard during wallet creation. Default is 8 words. |
Result:
Name | Type | Description |
---|---|---|
key | String | The decrypted client shard. |
Example:
const clientShard = await lockbox.decryptClientShard(
encryptedClientShard,
passphrase,
recoveryPhrase
);
console.log("Client shard: ", clientShard);
Task<(string, MPCError)> MPC.DecryptData(string encryptedKey, string passphrase);
Example:
string encryptedKey = $"{ENCRYPTED_KEY}";
string passphrase = $"{RECOVERY_PASSWORD}";
var (privateKeyShard, error) = await MPC.DecryptData(encryptedKey, passphrase);
if (error != null) {
Debug.LogError($"Error when getting decrypted data: {error.message}");
}
else {
Debug.Log($"Decrypted private key shard: {privateKeyShard}");
}