1

I'm trying to create a BIP32 storefront that uses Electrum's key derivation path. The user passes me their MPK, and with every order I generate a new address based on the MPK. I'm able to generate addresses, but they don't match the one's created by Electrum. I'm using Electrum 2.2.

This is my code (I'm using pybitcointools command line). To keep thinks legible, I'm swapping out the actual values for $variables.

> Using $xpub which is the MPK I copied from Electrum:
./pybtctools bip32_ckd $xpub 0
> $xpub0

./pybtctools bip32_ckd $xpub0 0
> $xpub00

./pybtctools pubtoaddr $xpub00
> $addr

My expectation is that the$addr I end up with should match the the first address of my "receiving" addresses in Electrum. However, they don't match. Any thoughts on why that might be?

For reference the xpub I start with xpub661MyMwAqRbcGK5eE2eSWmnU4Pg6knZZqZEmREAgZ4vj6z3B5soecps7UJj37NF9aWhjEMQoyH9xgcC14KUgEGX9avagrdv9rcN56wjwXR2 and I get an address of 17VzXFqo6Kg7vMxNLWD5hhwgsdCV6XL9RT (which is not in my Receiving addresses list).

3

You're very close.

bip32_ckd returns a BIP-32 extended public key, however pubtoaddr expects as input a "normal" non-extended public key in either raw or hex-encoded form (and it doesn't check if the public key appears valid). Here's what you want:

./pybtctools bip32_ckd $xpub 0
> $xpub0

./pybtctools bip32_ckd $xpub0 0
> $xpub00

./pybtctools bip32_extract_key $xpub00
> $pub00

./pybtctools pubtoaddr $pub00
> $addr
  • Great answer. Helped me understand how Electrum derives the keys it uses from the extended private keys. It drives me nuts when all these other wallets (trezor, mycelium, etc) all use different formulas to derive addresses. – Aaron Vallance Aug 8 '15 at 3:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.