Function Signature

exportPrivateKey(params: {
  accountAddress: string;
  password?: string;
  externalServerKeyShares?: ServerKeyShare[];
}): Promise<{ derivedPrivateKey: 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)

Optional Parameters

  • password (string) - Wallet password (if wallet is password-protected)
  • externalServerKeyShares (ServerKeyShare[]) - Array of external server key shares

Returns

  • Promise<{ derivedPrivateKey: string }> - Object containing the exported private key

Example

import { authenticatedEvmClient } from './client';

const evmClient = await authenticatedEvmClient();

const result = await evmClient.exportPrivateKey({
  accountAddress: '0xYourWalletAddress',
  password: 'optional-password',
  externalServerKeyShares: [
    // ServerKeyShare objects
  ],
});

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

Key Share Format

// ServerKeyShare type from @dynamic-labs-wallet/node
const externalServerKeyShares: ServerKeyShare[] = [
  // ServerKeyShare objects
];

Error Handling

try {
  const result = await evmClient.exportPrivateKey({
    accountAddress: '0xYourWalletAddress',
    password: 'optional-password',
  });
  console.log('Private key exported successfully:', result.derivedPrivateKey);
} 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