Skip to main content

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

Steps

Step 1. Verify wallet creation

Form a request to the 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

Function signature:

async function getBackupClientShard()

Result:

NameTypeDescription
keyStringEncrypted client key shard from an existing backup.
updatedAtStringLatest time update.

Example:

const result = await lockbox.getBackupClientShard();
console.log("Encrypted client shard: ", result.key);
//...

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.

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:

NameTypeRequiredDescription
encryptedClientShardStringRequiredThe client shard encrypted with the passphrase.
passphraseStringOptionalThe passphrase used to encrypt the client shard.
recoveryPhraseStringOptionalThe set of words generated when encrypting the client shard during wallet creation. Default is 8 words.

Result:

NameTypeDescription
keyStringThe decrypted client shard.

Example:

const clientShard = await lockbox.decryptClientShard(
encryptedClientShard,
passphrase,
recoveryPhrase
);
console.log("Client shard: ", clientShard);

Next steps

Create a transaction