Getting bx to create a private key from known chain code and a private EC WIF key?

1

I was trying to get strong feedback that I really understood a portion of the Mastering Bitcoin Book concerning HD wallets. The picture below is the reference for the question.

HD Private Child Key Derivation

I checked out the functionality exposed by a Javascript Brain Wallet. By entering "123" (is a very poor secret) into a field for a HD brainwallet and the following extended private key emerged: xprv9s21ZrQH143K2hYgcmBxsUfRw3Kbu3eEGXFJrM8Cqtewuqa6Y6nXbB7tv9HnrBajqjptPsRjL9FmnwLa317jHWJ5dpwTc99C2AiPztPRaxk.

Clicking the button to the right of the private key got me to another page indicating the master private chain code is 40675733fc35303c1c75bc598716f24af225528da686192ceb567c88313f8885 and the master private key is L4h3ZSQ3yfFNbovQjTGumvUGEfB1a7oFAhbkhMMFGsdDKoTSwwU8.

Given these last two pieces of information and an index of 0, is it possible to issue a number a number of bx commands and concatenate their output results to feed a HMAC-SHA512 hash to arrive at private WIF key of KwMsDozFYQG7SZFwfvFRwWDhfuMJjkE669WxP6SqrpDPsCBrPV4p public address 15jbcT7wE81s8n2dbEGRFGf65zp7PHrjxh? If so, how is this accomplished or does bx need to be complemented by some other command that renders HMAC-SHA512 functionality?

skaht

Posted 2015-07-09T05:14:28.860

Reputation: 2 588

% echo "L4h3ZSQ3yfFNbovQjTGumvUGEfB1a7oFAhbkhMMFGsdDKoTSwwU8" | bx wif-to-ec deec675df1bc1d395c6098ee63eacb45036fad781717548f4b8cc00709f5d834skaht 2015-07-09T13:00:50.567

% echo "L4h3ZSQ3yfFNbovQjTGumvUGEfB1a7oFAhbkhMMFGsdDKoTSwwU8" | bx wif-to-ec | bx ec-to-public 02430aca0779d7ca52441ee9de2f7b73408ee8229d6c2e42a5c81b65028efc803fskaht 2015-07-09T13:09:18.333

Answers

2

No need for an external program at all:

$ KEY=xprv9s21ZrQH143K2hYgcmBxsUfRw3Kbu3eEGXFJrM8Cqtewuqa6Y6nXbB7tv9HnrBajqjptPsRjL9FmnwLa317jHWJ5dpwTc99C2AiPztPRaxk
$ echo $KEY | bx hd-public -i 0 | bx hd-to-address
15jbcT7wE81s8n2dbEGRFGf65zp7PHrjxh

Or, because this is non-hardened, you can use the extended public key:

$ KEY=xpub661MyMwAqRbcFBd9iniyEccAV5A6JWN5dkAuejXpQEBvnduF5e6n8ySNmP8uWeqNbwFXLHEQkV1shXbNtBV8YCUJPMSuE7bGCvDaZJfUBuP
$ echo $KEY | bx hd-public -i 0 | bx hd-to-address
15jbcT7wE81s8n2dbEGRFGf65zp7PHrjxh

Nick ODell

Posted 2015-07-09T05:14:28.860

Reputation: 26 536

Most excellent...skaht 2015-07-10T01:42:32.577