[Ethereum] How to generate address from an Extended Public key

addressespublic-keywallets

How can I generate a wallet address when given an Extended Public Key?

For example, an xpub key from Electrum?

I know this can be done with bitcoin and litecoin, is there a way to do it with Ethereum?

Thank you

Best Answer

ethereumjs-wallet does support HDWallet and let you calculate the address corresponding to an extended public key

var hdkey = require('ethereumjs-wallet/hdkey');

var extPubKey = 'xpub6ERoQFMqiUoTXAL56JpQYLq5FyXaZypJiKdsAbHKzMUQsSiJTNSMnBtYYRXxda9C6fUx6mMMqatUDNFSKxxXcpBcpPkTqVwyethpWiQN8p5';

var hdwallet = hdkey.fromExtendedKey(extPubKey);
var wallet = hdwallet.getWallet();
var address = wallet.getAddress();

console.log(`Address: 0x${address.toString('hex')}`);