Author

Topic: Wrong derived public address? (Read 697 times)

HCP
legendary
Activity: 2086
Merit: 4361
April 24, 2017, 12:43:15 AM
#4
I would think the part you're looking for is here: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#master-key-generation
and possibly the section above: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions

Electrum uses "m/0/n" doesn't it for BIP32 HD wallets and addresses: https://bitcointalksearch.org/topic/bip32-wallet-structure-for-electrum-274182

So, I would think that the first derive(0) puts you at m/0 in the tree... and then the 2nd one starts generating the child keys that match up to the addresses.
sr. member
Activity: 1344
Merit: 307
April 23, 2017, 11:02:57 PM
#3
It looks like you are not actually deriving any addresses but rather getting the address associated with the xpub itself.

Yea. After experimenting a little I did update the code which does give me the correct address, but kind of confused on why I need to do it two times. Will be rereading bip32 on github in a bit.
staff
Activity: 3458
Merit: 6793
Just writing some code
April 23, 2017, 10:56:44 PM
#2
It looks like you are not actually deriving any addresses but rather getting the address associated with the xpub itself.
sr. member
Activity: 1344
Merit: 307
April 23, 2017, 10:51:00 PM
#1
Tonight I was messing around with bitcoin.js and decided to see if I can generate addresses using xpub only. So far, the code works, but the address it generated doesnt show up on electrum. I decided to send a couple of cents to the address and it have been received by the address but still have yet to show up in electrum or the ledger bitcoin app and dont know what went wrong. I did check blockchain.info to see if the address is listed there with the xpub but no luck either. Maybe someone can point out where I went wrong.

Code:
var bitcoin = require('bitcoinjs-lib');
var HDNode = bitcoin.HDNode;
var xpub = HDNode.fromBase58("xpub...");

for(i = 0;i<5;i++){
    console.log(xpub.derive(0).derive(i).getAddress());
}

I am mainly trying to figure this out so I do not have to worry about having an electrum daemon running to handle it.

EDIT: I think I figured it out... need to use xpub.derive when getting the address. Someone can correct me though if im wrong.

EDIT: Updated Code. I did compare it against the list of addresses listed on electrum and so far they match. Any reason why I must use "derive(0).derive(...)" instead of just "derive(...)"? I may go back and reread the document I saw earlier since I couldve missed something.
Jump to: