[Ethereum] Get Private and Public Key from BIP44 Master Private Key

accountsblockchainhd-walletswallets

I am confused about getting the private key corresponding to the address for derivation path m/44'/60'/0'/0'/0'

Question 1: Is the following code correct in getting the address and private key? Why is the private key obtained a Buffer object?

<Buffer fd 5f 63 c0 6b 5a 99 c4 c6 9a 05 07 01 c7 fd 04 cd b5 39 b6 2e 58 4e 63 98 c4 7c 28 5e b8 31 fa>

If I understand correctly the various depth of the path:

  • 44' means BIP44
  • 60' means Ethereum
  • 0' means wallet #0
  • 0 means public, 1 means private?? What does public and private means?
  • 0 means index 0

Question 2: Why is there a ' behind some of the numbers?

Code:

var bitcore = require('bitcore-lib');
var EthereumBip44 = require('ethereum-bip44');

var seed = 'xprv9s21ZrQH143K2uRcdeb2VJAEwhJQCtAjTCgx9JQt5NGhSkG4xGiuXvea8yN3tz3Q4LwPoP8j2cwERYNyw959ed9yqCrHGT1oDxJhNWoobqf'
var hdKey = new bitcore.HDPrivateKey(seed);
console.log('HD Key: ', hdKey.toString())

console.log('---')

var derivationPath = "m/44'/60'/0'/0'";
var derivedPrivKey = hdKey.derive(derivationPath)
var derivedPubKey = hdKey.derive(derivationPath).hdPublicKey

console.log('Derivation Path: ', derivationPath)
console.log('Extended Private Key: ', derivedPrivKey.toString())
console.log('Extended Public Key:  ', derivedPubKey.toString())

console.log('---')

var wallet = new EthereumBip44.fromPrivateSeed(derivedPrivKey)
console.log('Wallet (0) Address: ', wallet.getAddress(0))
// 0x10ea551752f7ba9fd73d19baa16b234585e2c45d

console.log('Wallet (0) Private Key: ', wallet.getPrivateKey(0))
// <Buffer fd 5f 63 c0 6b 5a 99 c4 c6 9a 05 07 01 c7 fd 04 cd b5 39 b6 2e 58 4e 63 98 c4 7c 28 5e b8 31 fa>

Output

HD Key:  xprv9s21ZrQH143K2uRcdeb2VJAEwhJQCtAjTCgx9JQt5NGhSkG4xGiuXvea8yN3tz3Q4LwPoP8j2cwERYNyw959ed9yqCrHGT1oDxJhNWoobqf
---
Derivation Path:  m/44'/60'/0'/0'
Extended Private Key:  xprvA1Q3FUbfXYKGzLiE9FgpgiBC4yrBkZm2eEQvBCtF95gvF6RQ1c1tWqeeemMDXczBwEi76wKrRR7oJPBQCsn9ghBSdigGdo5ZXE8WpX68t57
Extended Public Key:   xpub6EPPez8ZMusaCpnhFHDq3r7vd1ggA2Ut1TLWybHrhRDu7tkYZ9L94dy8VzvGNYjxiCFjpK4xbaBzaXkmWiU4Bj3q3SgwYrqJLKJP9SiQ2t1
---
Wallet (0) Address:  0x10ea551752f7ba9fd73d19baa16b234585e2c45d
Wallet (0) Private Key:  <Buffer fd 5f 63 c0 6b 5a 99 c4 c6 9a 05 07 01 c7 fd 04 cd b5 39 b6 2e 58 4e 63 98 c4 7c 28 5e b8 31 fa>   

Best Answer

BIP 44 path is represented as m / purpose' / coin_type' / account' / change / address_index, Purpose is a constant set to 44' (or 0x8000002C) following the BIP43 recommendation. Apostrophe in the path indicates that BIP32 hardened derivation is used. coin_type is 60 for Eth, 0 for BTC, 2 for LTC etc.

Based on the coin type, you can generate public and private keys of any registered coin. List of registered coins( https://github.com/satoshilabs/slips/blob/master/slip-0044.md )

You can read more at https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki