HD wallet implementation

0

1

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

rahul

Posted 2017-08-28T10:38:27.413

Reputation: 131

Answers

1

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.

wmpedersen

Posted 2017-08-28T10:38:27.413

Reputation: 11

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 2017-09-06T16:44:26.873

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 2017-09-07T15:09:24.607

See my edit of the main for a little more explanationwmpedersen 2017-09-07T15:20:03.733

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 2017-09-11T06:25:40.600

Is bitcoinjs lib can br used for bitcoin cash?rahul 2017-09-11T06:40:18.023

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 2017-09-21T01:31:49.653