import { Buffer } from 'buffer';
import * as bip39 from 'bip39';
import { BIP32Factory } from 'bip32';
import * as ecc from 'tiny-secp256k1';

const bip32 = BIP32Factory(ecc);

export function getWalletFingerprint(mnemonic: string): string {
  const seed = bip39.mnemonicToSeedSync(mnemonic);
  const root = bip32.fromSeed(Buffer.from(seed));
  const fingerprint = root.fingerprint;
  return Array.from(fingerprint).map(b => b.toString(16).padStart(2, '0')).join('');
}