Generate list of Bitcoin Addresses from a HDPublicKey

Hi

I am attempting to generate a list of bitcoin addresses from a known HDPublic Key.

This is what i have so far

var HDPrivateKey = bitcore.HDPrivateKey.fromSeed(XXXHexGoesHere, bitcore.Networks.livenet);
var hdPublicKey = HDPrivateKey.hdPublicKey;
var parent = new bitcore.HDPublicKey(hdPublicKey);
var copy_of_child_0_0_1 = parent.derive(“m/0’/0/1”);
var address = new bitcore.Address(copy_of_child_0_0_1.publicKey, bitcore.Networks.livenet);
console.log("address : " + address);

It is however failing when I am trying to use the derivation path of “m/0’/0/1”, any ideas? It only works if I am using “m/0/0/1” (without the apostrophe)

Thank you

Can you paste the error you’re getting, please?

From chrome console:

Uncaught TypeError: undefined is not a function
bitcore.min.js:2
r._deriveFromString
bitcore.min.js:2
r.derive

HDPublicKeys can’t derive hardened indexes, though I believe there should be a better error message, similar to: https://github.com/bitpay/bitcore/blob/master/lib/hdpublickey.js#L120

Sort of suspected that :frowning: … So this means its not possible to create a “watch only” address list by using a hardended xpub… key?

No, it’s not possible. See: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#public-parent-key--public-child-key

Thank you for the answer and support

Would there be a way by using a non-hardened index below a hardended index?

Yes, if you have the a public node in the tree, you can derive any non-hardened public child node from it.