derive bip44 hardened addresses from xpub key
See original GitHub issueIt got my issues with deriving addresses from xpub keys answered very well: #584
Unfortunately, I run into problems when deriving addresses from xpub keys with hardened indexes. I checked the unit tests (https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js#L50) which work great, however not with only a xpub as an input.
This triggers error: TypeError: Could not derive hardened child key
bitcoin.HDNode.fromBase58('xpub...').derivePath("m/44'/0'/0/0").getAddress();
This works without problems
bitcoin.HDNode.fromBase58('xpub...').derivePath("m/0/0").getAddress();
Strangely with testnet it doesn’t work, first line triggers the error: Error: Not a master node
, second line works correctly
bitcoin.HDNode.fromBase58('tpub...', [bitcoin.networks.testnet]).derivePath("m/0/0").getAddress()
bitcoin.HDNode.fromBase58('tpub...', [bitcoin.networks.testnet]).derive(0).derive(0).getAddress()
My goal is to derive addresses from xpub keys exported from bip44 wallets. Testnet should also be supported. Can somebody give me an answer how this can be done? Referring to issue #584, is it only possible for non-hardened indexes?
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Just to give you an idea of how the library works… here’s how:
Edit: xpubs (neutered HDNodes) can not derive a ’ path, any number with a ’ after it will throw the error you got.
@coinables From my earlier post (with extra comments to explain your use case):
The xpubString does not contain any private info, BUT it can derive unlimited addresses (and public keys) that can then be signed using private keys derived from the someMnemonicObject (aka your mnemonic)