Function Signature

exportPrivateKey(params: {
  accountAddress: string;
  externalServerKeyShares: any[];
  password?: string;
}): Promise<string>

Description

Exports the private key for a specific wallet address. This function requires external server key shares and authentication. The private key is reconstructed from the distributed key shares.

Parameters

Required Parameters

  • accountAddress (string) - The wallet address to export private key for (must include 0x prefix)
  • externalServerKeyShares (any[]) - Array of external server key shares

Optional Parameters

  • password (string) - Wallet password (if wallet is password-protected)

Returns

  • Promise<string> - The exported private key as a hex string

Example

import { authenticatedEvmClient } from './client';

const evmClient = await authenticatedEvmClient();

const privateKey = await evmClient.exportPrivateKey({
  accountAddress: '0xYourWalletAddress',
  externalServerKeyShares: [
    {
      chainName: 'base-sepolia',
      keyShare: '0x1234567890',
    },
  ],
  password: 'optional-password',
});

console.log('Private key exported:', privateKey);

Key Share Format

interface KeyShare {
  chainName: string;
  keyShare: string;
}

const externalServerKeyShares: KeyShare[] = [
  {
    chainName: 'base-sepolia', // or your specific chain
    keyShare: '0x1234567890', // the actual key share
  },
];

Error Handling

try {
  const privateKey = await evmClient.exportPrivateKey({
    accountAddress: '0xYourWalletAddress',
    externalServerKeyShares,
  });
  console.log('Private key exported successfully');
} catch (error) {
  console.error('Failed to export private key:', error);
}

Security Considerations

  • Private Key Security: Never store private keys in plain text
  • Key Share Security: Keep external server key shares secure
  • Session Management: Implement proper session management
  • Password Protection: Use strong passwords for wallet encryption