libbitcoin / libbitcoin-explorer

Bitcoin Command Line Tool
Other
600 stars 176 forks source link

BIP44: Derive P2SH Addresses from mnemonic phrase #670

Closed cryptonik closed 4 years ago

cryptonik commented 4 years ago

I am trying to generate a P2SH payment address from a mnemonic phrase, using the below command.

echo "naive friend purse visual holiday era island provide emerge convince next hazard problem mirror typical"  \
  | bx mnemonic-to-seed                                         \ # Step_0: Generate the seed from the mnemonic string
  | bx hd-new -v 77428856                                       \ # Step_1: Generate the master private key
  | bx hd-private -d -i 49                                      \ # Step_2: Purpose node
  | bx hd-private -d -i 0                                       \ # Step_3: Coin node
  | bx hd-private -d -i 0                                       \ # Step_4: Account node
  | bx hd-private -i 0                                          \ # Step_5: External/internal node - private
  | bx hd-to-public -v 77429938                                 \ # Step_6: External/internal node - public
  | bx hd-public -i 0 -p 77429938                               \ # Step_7: Generate child index 0
  | bx hd-to-ec -p 77429938                                     \ # Step_8: Convert the extended public key to it's Elliptic Curve public key equivalent
  | bx ec-to-address -v 5                                         # Step_9: Generate P2SH payment address

Validating the generated results with this site, we can observe that:

  1. The generated intermediate results match perfectly up-to the point were we are generating the EC public key (Step_8)
  2. There is a mismatch at the very last step (Step_9) when converting from EC public key to P2SH address

Can someone explain the reason behind the said mismatch and how can I correctly generate P2SH payment address, please?


bx version 3.6.0 (built from source) os version: Ubuntu 20.04 LTS

evoskuil commented 4 years ago

ec-to-address does not generate a P2SH address. See script-to-address.