I'm new to bitcoin technology, however, I'm trying to develop a web wallet that works like that of blockchain.info. I've gone through the code samples here but couldn't make out the one I could us to create a deterministic wallet.
I intend to make the wallet users enter a long and strong password from which the private key can be generated from.
Any code sample or link would be highly appreciated.
You'll probably want to use https://github.com/bitcoinjs/bip39 coupled with a flow similar to https://github.com/bitcoinjs/bitcoinjs-lib/blob/8e1c69183f74acce06d6e35b614e504b18bb04e1/test/integration/bip32.js#L20.
That should give you enough to start and play with.
@Chibuzo please see https://github.com/bitcoinjs/bitcoinjs-lib/pull/794 - if that is helpful, I'll merge it :+1:
Thank you you @dcousens for the speedy and resourceful reply.
I came across those code samples but couldn't figure out where to put the wallet user passowrd. I copied the snippet below from the second link you posted.
`it('can create a BIP32 wallet external address', function () {
var path = "m/0'/0/0"
var root = bitcoin.HDNode.fromSeedHex('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd')
var child1 = root.derivePath(path)
// option 2, manually
var child2 = root.deriveHardened(0)
.derive(0)
.derive(0)
assert.equal(child1.getAddress(), '1JHyB1oPXufr4FXkfitsjgNB5yRY9jAaa7')
assert.equal(child2.getAddress(), '1JHyB1oPXufr4FXkfitsjgNB5yRY9jAaa7')
})`
I assume the wallet user password would go here:
bitcoin.HDNode.fromSeedHex('wallet user long and strong pssoword')
Is that correct?
Again, this code/hash '1JHyB1oPXufr4FXkfitsjgNB5yRY9jAaa7' used here:
assert.equal(child1.getAddress(), '1JHyB1oPXufr4FXkfitsjgNB5yRY9jAaa7')
is it a constant that I can actually hardcore, or would I have to generate it?
Thank you for your time.
I assume the wallet user password would go here: bitcoin.HDNode.fromSeedHex('wallet user long and strong pssoword')
fromSeedHex expects a base16 hex string, so, no that wouldn't work.
Please see https://github.com/bitcoinjs/bitcoinjs-lib/pull/794 - that example there should give you a few ideas.
I do not recommend you let users create their own mnemonics/seeds.
Again, this code/hash '1JHyB1oPXufr4FXkfitsjgNB5yRY9jAaa7' used here:
assert.equal(child1.getAddress(), '1JHyB1oPXufr4FXkfitsjgNB5yRY9jAaa7')
That is just an example.
Please ensure you have a deep understanding of the implications of whatever software you create; mistakes are often unforgiving.
Thank you. I understand. The issue is the client wants something that works like blockchain.info where users simply supply a password, and the password is then used to generate a private. Any suggestions on that?
I would preserve the ability to change your password without losing your private keys.
Blockchain.info uses the password to encrypt / decrypt a payload that contains the private keys / seed hex, which are generated using multiple sources of random data.
Thanks for the reply @clarkmoody
I'm not strong on cryptography, but a pseduo code or maybe a link to guide me would suffix.
Thank you.
Fundamentally, it looks like this:
payload = receivePayloadFromServer(my_stored_wallet_id)
wallet = decryptPayload(payload, my_password)
// Do stuff with wallet.seed, etc
encrypted = encryptWallet(wallet, my_password)
sendPayloadToServer(encrypted)
I must reiterate @dcousens's admonishment above to please take care to understand what's going on very carefully. Any mistakes with bitcoin wallet encryption will result in permanent loss of funds.
Most helpful comment
I would preserve the ability to change your password without losing your private keys.
Blockchain.info uses the password to encrypt / decrypt a payload that contains the private keys / seed hex, which are generated using multiple sources of random data.