<p>I'm doing something similar but using segwit addresses (BIP49). If you are using BIP32 with a standard derivation of m/0'/0/0 you could do something like this - See: <a href="https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js#L35" rel="nofollow noreferrer">https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js#L35</a>
</p>

<pre><code>//get a mnemonic, then seed, then root.
var mnemonic = bip39.generateMnemonic();
var seed = bip39.mnemonicToSeed(mnemonic);
var root = bitcoin.HDNode.fromSeedBuffer(seed);

//root can be transformed to your xpub and xprv
var xprv = root.toBase58();
var xpub = root.neutered().toBase58();

//You can then create the address with a derivation of m/0'/0/0
var change = 0; //0 for external (receive), 1 for internal (change)
var index = 0; //the index of the address you want to generate
var keypair = root.deriveHardened(0).derive(change).derive(index);
//or keypair = root.derivePath("m/0'/" + change + "/" + index);
var address = keypair.getAddress();
</code></pre>

<p>If your derivation for your addresses is m/0' (then external, then the index) Then you have the xpub for the parent m and can store xpub of m/0'/0 on the server. On the server when a user clicks the button it generates the address n/0, where n = your xpub of m/0'/0.</p>

CC BY-SA 3.0
2017-09-06T16:44:26.873Z
I have one question for you. Scenario : If bitcoin address on x level down offline on web browser using parent hdXpublickey  which i donot know  because of offline then i retrieve bitcoin from child address using extended private key without knowing path on server when sender sends its fund.
rahul
CC BY-SA 3.0
2017-09-07T15:09:24.607Z
If you're building an HD implementation you should have the parent xprv stored on your computer. Using that you can derive the private keys for all child accounts. You shouldn't be generating addresses from a random derivation on the user-side, it would take you forever to iterate over all the possible derviations.
wmpedersen
CC BY-SA 3.0
2017-09-07T15:20:03.733Z
See my edit of the main for a little more explanation
wmpedersen
CC BY-SA 3.0
2017-09-11T06:25:40.600Z
storing private key on server it question of security. One more thing how Tezos work. Its a big question in my mind.Do you have any idea?
rahul
CC BY-SA 3.0
2017-09-11T06:40:18.023Z
Is bitcoinjs lib can br used  for bitcoin cash?
rahul
CC BY-SA 3.0
2017-09-21T01:31:49.653Z
I don't know Tezos, I don't really do ICOs. I'm not entirely sure if it can be used with Bitcoin Cash, I know the address hashing format hasn't changed, but there may be other differences in the bare public/private keys that I'm not aware of.
wmpedersen
CC BY-SA 3.0
2017-09-06T05:15:53.523Z
2017-09-07T15:18:01.290Z
2017-09-07T15:18:01.290Z
wmpedersen
<p>I want to create public addresses in offline browser from master public key so that owner of master private can access the funds available in child address.
but I am not able to understand how to use this bitcoinjs-lib. how to create master private key, master public key and every time i click on button it generate new child bitcoin address.</p>

<p>Help is appreciated</p>

<bitcoinj><bip32-hd-wallets><bitcoinjs><mnemonic-seed>
HD wallet implementation
rahul
# HD wallet implementation

(Asked by: username_0 on 2017-08-28)

I want to create public addresses in offline browser from master public key so that owner of master private can access the funds available in child address.
but I am not able to understand how to use this bitcoinjs-lib. how to create master private key, master public key and every time i click on button it generate new child bitcoin address.

Help is appreciated

**Tags:** bitcoinj, bip32-hd-wallets, bitcoinjs, mnemonic-seed


---

## 1 answers

### Answer by username_1 on 2017-09-06. Score: 2

I'm doing something similar but using segwit addresses (BIP49). If you are using BIP32 with a standard derivation of m/0'/0/0 you could do something like this - See: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.js#L35

//get a mnemonic, then seed, then root.
var mnemonic = bip39.generateMnemonic();
var seed = bip39.mnemonicToSeed(mnemonic);
var root = bitcoin.HDNode.fromSeedBuffer(seed);

//root can be transformed to your xpub and xprv
var xprv = root.toBase58();
var xpub = root.neutered().toBase58();

//You can then create the address with a derivation of m/0'/0/0
var change = 0; //0 for external (receive), 1 for internal (change)
var index = 0; //the index of the address you want to generate
var keypair = root.deriveHardened(0).derive(change).derive(index);
//or keypair = root.derivePath("m/0'/" + change + "/" + index);
var address = keypair.getAddress();

If your derivation for your addresses is m/0' (then external, then the index) Then you have the xpub for the parent m and can store xpub of m/0'/0 on the server. On the server when a user clicks the button it generates the address n/0, where n = your xpub of m/0'/0.

> **Comments:**
> **username_0**: I have one question for you. Scenario : If bitcoin address on x level down offline on web browser using parent hdXpublickey  which i donot know  because of offline then i retrieve bitcoin from child address using extended private key without knowing path on server when sender sends its fund.  
> **username_1**: If you're building an HD implementation you should have the parent xprv stored on your computer. Using that you can derive the private keys for all child accounts. You shouldn't be generating addresses from a random derivation on the user-side, it would take you forever to iterate over all the possible derviations.  
> **username_1**: See my edit of the main for a little more explanation  
> **username_0**: storing private key on server it question of security. One more thing how Tezos work. Its a big question in my mind.Do you have any idea?  
> **username_0**: Is bitcoinjs lib can br used  for bitcoin cash?  
> **username_1**: I don't know Tezos, I don't really do ICOs. I'm not entirely sure if it can be used with Bitcoin Cash, I know the address hashing format hasn't changed, but there may be other differences in the bare public/private keys that I'm not aware of.  

---

