Eject a wallet

The eject feature allows a user to construct a private key that can be imported into another wallet manager, such as MetaMask.

Warning: Providing the custodian backup share to the client device puts both MPC shares on a single device, removing the multi-party security benefits of MPC. This operation should only be done for users who want to move off of MPC and into a single private key. Use portal.eject() at your own risk!

Ejecting Your User's Wallets

To eject the private keys for your users' wallets, their two matching backup shares need to be combined. This requires providing the following two shares to portal.eject():

  • User Backup Share - Encrypted backup share received from portal.backup().

  • Custodian Backup Share - Raw backup share received from the POST /backup webhook.

Note that a user can have multiple wallets (unique by curve). This means when the user calls portal.eject(), they can potentially receive multiple private keys. Here's an example implementation:

import { BackupMethods } from '@portal-hq/web'
import { BackupConfigs } from '@portal-hq/web/types'

// Create a backup config for portal.eject().
const backupConfig: BackupConfigs = {
  passwordStorage: {
    password: 'USERS_PASSWORD',
  }
}

// Fetch the user's backup share from your API.
const userBackupShare = await fetchUserBackupShare(userId)

// Fetch the custodian backup share for the user from your API.
const custodianBackupShare = await fetchCustodianBackupShare(userId)

// Obtain the private keys for the user's various wallets.
const { SECP256K1, ED25519 } = await portal.eject(
    userBackupShare, 
    BackupMethods.password, 
    backupConfig, 
    custodianBackupShare,
)

SECP256K1 is the curve used by Ethereum.

ED25519 is the curve used by Solana.

You can learn more about signing algorithms and curves here.

And that's it! Now your users can obtain a private key to import their wallet into another wallet manager.

Last updated