How to get the master private key from a Wallet object?

720 views
Skip to first unread message

Yvon Fortier

unread,
Sep 26, 2016, 8:05:53 AM9/26/16
to bitc...@googlegroups.com
Hi people.
I'm trying to dump the master private key from MultibitHD to monitor from other wallet, but I can't get it right.
What I do is restore a wallet and then try to get the private key from the Wallet object:

Code:

NetworkParameters PARAMS = MainNetParams.get();
DeterministicKeyChain kc = wallet.getActiveKeychain();
DeterministicKey rk = kc.getRootKey();
String key = rk.getPrivateKeyAsWiF(PARAMS);

I'm getting an exception saying java.lang.IllegalStateException: Private key bytes not available

Any help would be greatly appreciated.

Alternatively, if someone knows how to properly derive the master key from the seed using a third party tool, that'd help!

Andreas Schildbach

unread,
Sep 27, 2016, 10:13:34 AM9/27/16
to bitc...@googlegroups.com
Afaik MultiBit HD is using a modified version of bitcoinj, so maybe you
should ask there too.

The topic of watching wallets is covered in the docs:

https://bitcoinj.github.io/working-with-the-wallet#watching-wallets

Most important, in order to monitor you don't need any private key. Just
use the public master key ("xpub") like explained in the link.


On 09/26/2016 02:05 PM, Yvon Fortier wrote:
> Hi people.
> I'm trying to dump the master private key from MultibitHD to monitor
> from other wallet, but I can't get it right.
> What I do is restore a wallet and then try to get the private key from
> the Wallet object:
>
> Code:
>
> *NetworkParameters PARAMS = MainNetParams.get();****DeterministicKeyChain kc = wallet.getActiveKeychain();****DeterministicKey rk = kc.getRootKey();****String key = rk.getPrivateKeyAsWiF(PARAMS);*
>
>
> I'm getting an exception saying *java.lang.IllegalStateException:
> Private key bytes not available *
>
> Any help would be greatly appreciated.
>
> Alternatively, if someone knows how to properly derive the master key
> from the seed using a third party tool, that'd help!
>
> --
> You received this message because you are subscribed to the Google
> Groups "bitcoinj" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to bitcoinj+u...@googlegroups.com
> <mailto:bitcoinj+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


Yvon Fortier

unread,
Sep 27, 2016, 1:13:19 PM9/27/16
to bitc...@googlegroups.com

Hi Andreas, thanks for the reply.

The problem is that I had the great idea of sending an onmi token to an address at MultibitHD.

So now, to take it out, I need access to that address' private key.

I tried exporting the deterministic extended private key (master xprv) modifying the source for MultibitHD, can't get it working.
Another option would be finding the correct derivation path for MBHD, but I've been through all the documentation I can find, tried several options and wasn't able to derive addresses I see on MBHD.

I used wallet-tool.jar to get dump the wallet. It gives me the MasterKey in hex, which I don't know how to import.
Full paste here:

http://pastebin.com/3aEDSV4q

    network_identifier: "org.bitcoin.production"
key {
  type: DETERMINISTIC_MNEMONIC
  secret_bytes: "unknown liberty blind legend online wing blush eternal develop category ski please"
  creation_timestamp: 1381276800000
  deterministic_seed: "\310 &b\301\337PX\263\335\337\262@\204\021\333\366Z\315\033\3014jl\001Ub\030\312\357\271\353\267i\211\026\031\331\366\vA\255\025\321\033e\370(\352aa\f<\315\240!R7\252M\227:\372a"
}
key {
  type: DETERMINISTIC_KEY
  secret_bytes: "\267\344\v\335i\364d\360\'\267\265\361P\2121 <\005\342\245\346F\272\302+\315\037o\240\244\2732"
  public_key: "\002\234Q\245\251-\2164~\202\2752a\v}\250k=\375\334\345H\244\230YY\365\'\024\317N\262\352"
  creation_timestamp: 1381276800000
  deterministic_key {
    chain_code: "\025\303\361ms\334[\340\004\236\350%\265\361\021;\240\337T4M\316mcc`\254pT\260t."
  }
}

I could try using those secret bytes to import into NBitcoin, which I know how to use, but I can't convert them to hex.

Thanks for any help.

Andreas Schildbach

unread,
Sep 28, 2016, 9:43:08 AM9/28/16
to bitc...@googlegroups.com
Have you tried wallet-tool? Use it like this to output all the private
keys in WIF format too:

./wallet-tool dump --wallet=your.wallet --dump-privkeys


On 09/27/2016 07:13 PM, Yvon Fortier wrote:
> Hi Andreas, thanks for the reply.
>
> The problem is that I had the great idea of sending an onmi token to an
> address at MultibitHD.
>
> So now, to take it out, I need access to that address' private key.
>
> I tried exporting the deterministic extended private key (master xprv)
> modifying the source for MultibitHD, can't get it working.
> Another option would be finding the correct derivation path for MBHD,
> but I've been through all the documentation I can find, tried several
> options and wasn't able to derive addresses I see on MBHD.
>
> I used wallet-tool.jar to get dump the wallet. It gives me the MasterKey
> in hex, which I don't know how to import.
> Full paste here:
> *
> *http://pastebin.com/3aEDSV4q*
> *
> * network_identifier: "org.bitcoin.production"*
> **
> *key {*
> **
> * type: DETERMINISTIC_MNEMONIC*
> **
> * secret_bytes: "unknown liberty blind legend online wing blush eternal
> develop category ski please"*
> **
> * creation_timestamp: 1381276800000*
> **
> * deterministic_seed: "\310
> &b\301\337PX\263\335\337\262@\204\021\333\366Z\315\033\3014jl\001Ub\030\312\357\271\353\267i\211\026\031\331\366\vA\255\025\321\033e\370(\352aa\f<\315\240!R7\252M\227:\372a"*
> **
> *}*
> **
> *key {*
> **
> * type: DETERMINISTIC_KEY*
> **
> * secret_bytes: "\267\344\v\335i\364d\360\'\267\265\361P\2121
> <\005\342\245\346F\272\302+\315\037o\240\244\2732"*
> **
> * public_key:
> "\002\234Q\245\251-\2164~\202\2752a\v}\250k=\375\334\345H\244\230YY\365\'\024\317N\262\352"*
> **
> * creation_timestamp: 1381276800000*
> **
> * deterministic_key {*
> **
> * chain_code:
> "\025\303\361ms\334[\340\004\236\350%\265\361\021;\240\337T4M\316mcc`\254pT\260t."*
> **
> * }*
> *}
>
> *I could try using those secret bytes to import into NBitcoin, which I
> know how to use, but I can't convert them to hex.
>
> Thanks for any help.
> **

Yvon Fortier

unread,
Sep 28, 2016, 1:05:00 PM9/28/16
to bitc...@googlegroups.com
Hi! Yes, tried that, but I get the WIF in hex in a weird format, do you
know what's the format?

secret_bytes: "\267\344\v\335i\364d\360\'\267\265\361P\2121
<\005\342\245\346F\272\302+\315\037o\240\244\2732"


Andreas Schildbach

unread,
Oct 1, 2016, 4:40:00 AM10/1/16
to bitc...@googlegroups.com
No, I don't. That's not an output from wallet-tool.

Stefano Pieri

unread,
Nov 6, 2017, 10:18:39 AM11/6/17
to bitcoinj
it's a 'raw-dump' format, you need a home made "translator"...

- the slash \ before a number delimits the string and then you have to hex-convert that string e.g. '\267'=b7, 
- the \ before a letter or simbol is a command with unilateral value e.g. '\r' = 0d

online you can't find too much, but I've got mine ;)

Stefano
Reply all
Reply to author
Forward
0 new messages