Embedded Wallets
SDK
Javascript
How to
Account Operation
Recover Wallet by Secret

Recover Wallet By Secret

This method allows you to recover an MPC wallet using a secret file that was generated when creating a new MPC wallet. This is useful when a user loses access to their existing account but has their own secret and wants to recover their existing account to a new account.

Method Signature

async recover(formData: FormData): Promise<RecoverWalletResponse>

Parameters

  • formData: FormData - An object containing the following:
    • file (required): File - The file containing the secret from the end user's device, created when initially creating the wallet.
    • expireDate (optional): string - The expiration date for the JWT token generated from the response.

Returns

Promise<RecoverWalletResponse> - An object containing the following properties:

  • walletToken: string - JWT token used to access the Wallet Operation endpoint.
  • refreshToken: string - Refresh token used to generate a new wallet token.
  • secret0: string - The encrypted secret that users need to save to recover their wallet if they lose access to the account.
  • secret0Link: string - Temporary link to download the recovery file. The value is the same as the secret0 value, but it is already saved in a .xellar file. The link will expire 5 minutes after being created.
  • address: string - User's MPC wallet address.

Example Usage

const formData = new FormData();
formData.append("file", fs.createReadStream("/path/to/secret_file"));
formData.append("expireDate", "2024-10-02");
 
const response = await sdk.account.wallet.recover(formData);
console.log(response);

Response Example

{
  "walletToken": "your_wallet_token_here",
  "refreshToken": "your_refresh_token_here",
  "secret0": "your_secret_here",
  "secret0Link": "temporary_link_to_download_secret0_file",
  "address": "your_address"
}
⚠️

Remember to save the secret0 value from the response data to a file with the .xellar extension. This file will be useful if the user wants to recover their wallet to a new account in the future.

⚠️

The file in the formData must be a file with the .xellar extension, containing the secret0 value from the Create Wallet Endpoint or a previous Recover Wallet By Secret Endpoint.

For more information, see the Xellar Recover Wallet By Secret API Documentation (opens in a new tab).