In my case, the private key is being created from the derive function of the HDPrivateKey class. How can I specify the network I want the private key to be part of?
But I’m using the HDPrivate key to derive different altcoins via BIP44. I don’t know what altcoin I’m going to want until after the HDPrivateKey is already created.
xpriv = "xprv9s21ZrQH143K3aJbLkzezYvgq2SFRagANzXoDTmEejYuWt7QvQAN4qSUAQEyx1ML9WTjXVajF4y224zeCzizx1312ZXcagyfzxC4FqiB88V"; // this has already been generated a long time ago and may be saved to paper
hd = new bitcore.HDPrivateKey(xpriv, 'ltc')
>>> hd.privateKey.toWIF();
L43ihVjtWAwpibmBUTF5tHBZrvq18z1snMwAzNZe51VZ7HzPDbAs // wrong WIF, should start with "T"
By the way, when I try your example, I get this error:
hdkey = bitcore.HDPrivateKey(‘ltc’);
bitcore-lib.min.js:5 Uncaught r {message: “Invalid Argument for integer, expected number but got undefined”, stack: “Invalid Argument for integer, expected number but …tcore-lib.min.js:2:14542)↵ at :1:17”}
I’ve also tried “litecoin” but it doesn’t work either. “testnet” and “livenet” do work.
Great, I was thinking something similar, and thought there may be a toPrivateKey() method, that would have a network argument, however there is just .privateKey.
Also, it doesn’t look like there is a second argument for the network option for:
var hd = new bitcore.HDPrivateKey(xpriv, 'networkname');
I think the problem is that a HDPrivateKey should be network agnostic. I don’t think any altcoins define different magic bytes for them anyways. It especially causes problems when you’re deriving multiple coins from the same root, ala BIP44.