0

Can someone please explain how to get Master Seed when a new HD keys is created using Bitcore APIs?

My purpose is to implement wallet service in my application using Bitcore APIs.

Refer this link here

  • Please elaborate your question. Are you asking to derive HD private keys from a newly generated public key or address? If so, it is not possible. Which specific function in Bitcore API you are referring to? – Abhishek Sinha Jul 16 '18 at 12:18
  • Hi Abhishek, no. I want to implement HD wallets into my application. According to my understanding there must be a master seed for each new wallet. Each wallet is simply a pair of HD private and public key, right? And we can create more public keys(addresses) using HD private key. My question is how will I get this master seed at first place? – Gagan Jul 16 '18 at 12:44
  • Are you talking about 12 or 24 words mnemonic seed or recovery phrase? – Abhishek Sinha Jul 16 '18 at 13:07
  • I would really appreciate if you could also mention the difference between them in your answer. I want to give my users master seeds for their wallets so that in future if they lose their wallets they can recover using the master seed they possess. – Gagan Jul 17 '18 at 5:14
  • Give them the mnemonics. That's enough. They can recover their funds in any standard wallet if they have the mnemonics that represent the correct private keys of their wallet. – Abhishek Sinha Jul 17 '18 at 5:57
1

In case you are talking about mnemonic seed use this -

Install bitcore-mnemonic

npm install bitcore-mnemonic
bower install bitcore-mnemonic

Then use it to generate mnemonic seed -

var Mnemonic = require('bitcore-mnemonic');
var code = new Mnemonic(Mnemonic.Words.ENGLISH);
code.toString(); 
// army van defense carry jealous true garbage claim echo media make crunch...

var xpriv = code.toHDPrivateKey();

If you just want to generate a private from bitcore api you can use this function -

var bitcore = require('bitcore');
var HDPrivateKey = bitcore.HDPrivateKey;

Please note there is no rule to generate a private key. A private key is just a random string. It could even be your name or a whole article. But you must create a private key that is 'random' in nature. Also never use programming language functions like md5 hash or something to generate a private key because they are not truly random.

Bitcore api, however, provides an easy way to generate a private key using the above method. From there you can proceed as usual.

var bitcore = require('bitcore');
var HDPrivateKey = bitcore.HDPrivateKey;

var hdPrivateKey = new HDPrivateKey();
var retrieved = new HDPrivateKey('xpriv...');
var derived = hdPrivateKey.derive("m/0'");
var derivedByNumber = hdPrivateKey.derive(1).derive(2, true);
var derivedByArgument = hdPrivateKey.derive("m/1/2'");
assert(derivedByNumber.xprivkey === derivedByArgument.xprivkey);

var address = derived.privateKey.toAddress();

// obtain HDPublicKey
var hdPublicKey = hdPrivateKey.hdPublicKey;
  • Hi Abhishek, thanks for your answer. Can you please also confirm if mnemonic seed is used at the time of recovering wallets when lost? – Gagan Jul 17 '18 at 5:11
  • Yes, you can easily use mnemonics, in fact, in any standard wallet like trezor to recover back your funds. Mnemonics are actually created from private keys itself. You can learn about the process here - github.com/bitcoinbook/bitcoinbook/blob/develop/ch05.asciidoc When you use var code = new Mnemonic(Mnemonic.Words.ENGLISH); bitcore api selects the private key for you and generates the mnemonics from it doing all the hard work for you. So you can think these mnemonics represents your private keys and you can use them to recover your funds. – Abhishek Sinha Jul 17 '18 at 5:55
  • Glad to help you. If my answer meets your requirement please mark it as the accepted answer. Thanks – Abhishek Sinha Jul 17 '18 at 6:39
  • Done! Abhishek, I have a quick question for you. Mnemonic Seed will be created after a new wallet is created. Is that right? And if so, does it mean the created mnemonic seed will represent this wallet? Or do I need to do something to link the seed with my wallet?? – Gagan Jul 17 '18 at 7:01
  • Because as per my research so far, mnemonic is generated from a random string. So I'm confused how it will represent my wallet. – Gagan Jul 17 '18 at 7:27

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.