Bitcoin Forum
May 22, 2019, 10:03:19 AM *
News: Latest Bitcoin Core release: 0.18.0 [Torrent] (New!)
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: new tool: hd-wallet-derive -- for deriving private and public keys.  (Read 861 times)
danda
Full Member
***
Offline Offline

Activity: 194
Merit: 139


View Profile WWW
August 04, 2017, 01:09:23 AM
Merited by ETFbitcoin (1)
 #1

I made a tool for deriving bip32 keys.   It shows xprv, xpub, privkey/wif, address all in one output table, or as json, csv, copy/paste, etc.

Here is an example run with all report columns:

Code:
$ ./hd-wallet-derive.php -g --key=xprv9tyUQV64JT5qs3RSTJkXCWKMyUgoQp7F3hA1xzG6ZGu6u6Q9VMNjGr67Lctvy5P8oyaYAL9CAWrUE9i6GoNMKUga5biW6Hx4tws2six3b9c --path=m/1 --cols=all --includeroot --numderive=3

+-------+-----------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+------------------------------------------------------+------------------------------------+-------+
| path  | xprv                                                                                                            | xpub                                                                                                            | privkey                                              | address                            | index |
+-------+-----------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+------------------------------------------------------+------------------------------------+-------+
| m     | xprv9tyUQV64JT5qs3RSTJkXCWKMyUgoQp7F3hA1xzG6ZGu6u6Q9VMNjGr67Lctvy5P8oyaYAL9CAWrUE9i6GoNMKUga5biW6Hx4tws2six3b9c | xpub67xpozcx8pe95XVuZLHXZeG6XWXHpGq6Qv5cmNfi7cS5mtjJ2tgypeQbBs2UAR6KECeeMVKZBPLrtJunSDMstweyLXhRgPxdp14sk9tJPW9 | L1pbvV86crAGoDzqmgY85xURkz3c435Z9nirMt52UbnGjYMzKBUN | 1CHCnCjgMNb6digimckNQ6TBVcTWBAmPHK |       |
| m/1/0 | xprv9yJyMFmJjNAiXqf3yfT6NvWCkXo1PTdYw6x5sj6fH2ePRVL4N4wy8weFYJnMKxNEib9HFyS7pc69rE3tmw7FfWhshBc17wHcKsNHByt4SZC | xpub6CJKkmJCZjj1kKjX5gz6k4SwJZdVnvMQJKsgg7WGqNBNJHfCucGDgjxjPcHY9QZJCne3tubbtucYmpt7a7u1Xx3oNumZRVytpa2UdFjTr47 | KxcccHPiLz7sxUVShX9THgfH6i8D6m3iAkHtgGuB87Tm3maz8Jas | 1qhp7SiuVmxo3WKca7zHMkKjvjkGXs29d  |     0 |
| m/1/1 | xprv9yJyMFmJjNAiZ2NDkwj7Jcjo8AtdJTPYXF5bBLGUYh8NNid9bgAfuhNtSEco35mLrBzPPRTaA5XeezrtPxn59MsYBzjRZt6XqGW2T87JiS4 | xpub6CJKkmJCZjj1mWSgryG7fkgXgCj7hv7PtU1Byig672fMFWxJ9DUvTVhNHVA8ciGkqrwaqDW6Mvmr4ihT3EoqjgNK6s5P6C9X7UBLX5Trzw6 | KyxHznKrz1Y6jmE5fxnHh1e2AZLNCtDjnF86cZzk8F5S8nBxfqfc | 1N3vKW2KGeKocao9eae6kVyYL8GNLzW8yd |     1 |
| m/1/2 | xprv9yJyMFmJjNAibyUzvGgfpk8igy6DpCtjWQ6C5oVmXyUhqak5J2xj6K2y7o3qn22nAvt14cLjRQEXVpGRZoc3ULJHomWmkUTTPJCEaF4rZPr | xpub6CJKkmJCZjj1pTZU2JDgBt5TEzviDfcasd1ntBuP6K1giP5DqaGye7MSy5MYFWoGtVhvK8Ko2XW4JRMtKjMXctpPxcjRMjM47AqeWiZLKKN | L1AFnZ6JJyGRxLG9QoCTDzeLzLV617XtgLy8DrXCyLnPG6L1n7xo | 17XRz7oPJLUNp5uf66BeqTmSDuRwqz3aW4 |     2 |
+-------+-----------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+------------------------------------------------------+------------------------------------+-------+

The tool is written in PHP but can be executed from the command-line like any program.

Docs, code, and more examples are on github.

Feedback, comments appreciated.  Please report any bugs on github page.

mybitprices.info - wallet auditing tools
1558519399
Hero Member
*
Offline Offline

Posts: 1558519399

View Profile Personal Message (Offline)

Ignore
1558519399
Reply with quote  #2

1558519399
Report to moderator
1558519399
Hero Member
*
Offline Offline

Posts: 1558519399

View Profile Personal Message (Offline)

Ignore
1558519399
Reply with quote  #2

1558519399
Report to moderator
1558519399
Hero Member
*
Offline Offline

Posts: 1558519399

View Profile Personal Message (Offline)

Ignore
1558519399
Reply with quote  #2

1558519399
Report to moderator
NEW GAME FORMAT
JACKPOT UP TO $8000+
Guess The Symbols Of a Real Ethereum Hash
PLAY NOW
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1558519399
Hero Member
*
Offline Offline

Posts: 1558519399

View Profile Personal Message (Offline)

Ignore
1558519399
Reply with quote  #2

1558519399
Report to moderator
danda
Full Member
***
Offline Offline

Activity: 194
Merit: 139


View Profile WWW
August 05, 2017, 06:04:49 AM
 #2

I added support for deriving from bip39 mnemonic seed words.   cheers!

Code:
$ ./hd-wallet-derive.php --mnemonic="refuse brush romance together undo document tortoise life equal trash sun ask" --path="m/44'/0'/0'/0"  -g --includeroot  --numderive=2 --cols=path,address,privkey,pubkey,xprv

+-----------------+------------------------------------+------------------------------------------------------+--------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+
| path            | address                            | privkey                                              | pubkey                                                             | xprv                                                                                                            |
+-----------------+------------------------------------+------------------------------------------------------+--------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+
| m               | 15UL8r2hkZpwi7RrQzWo6fYxfzdWL8mguG | L4jtNUY2YZfARajhSzq66RCBcfB8ZaXUYVHXD3q2q8SdMGaS7HpX | 03fa47f99f33e208cf46f42bdfc120843808a6558fa77a7806124f3b00be900b4a | xprv9s21ZrQH143K2vBDZaAMUvqS1MBuyNyisggeeGiUdMpi956vyGmkX81BapU6oD2c1qHnQYETcd85Z7i4GfmBz2TCz9PDQrxHjd3W5Ty5ayu |
| m/44'/0'/0'/0/0 | 14QEoz5SwQ5Kfjkhs5QitskgfD5QCqM7RB | L4X3nAcMs63daNUaWoVL6YBRh7GDsyT3mouEKLFhSeYe5PBwJbXe | 024977580921d65487194d2d84744b411cdbc19ec374bdb3fdfcf32e86e3e16830 | xprvA3rUF5RAJPotmYWqWmqEoWweV6CWVwYMA6vSGb6VCjhGFKaPuxHnveqBaBs19GPhp8unUjNBUj2TEFgbUUqsaPzF41w1SHcFUMC9jb8KCcJ |
| m/44'/0'/0'/0/1 | 1B83aj2N1Dxx37C4UdNM4vE5JxVKQV1Hur | L3Ks5PyY6enhjxsevfPYfsDmCtaK6nUymPmaN1Xvszh86urom9nw | 0357e9b058d9cbaece6459537579a6b7a9822f163844cd50f94ab76ad3781f2d4d | xprvA3rUF5RAJPotoshfn98F5SpcbC2vbR2CKtKkFfr8LJ7FwmukaCCN1fbcqqefb51odUrkFxnxxTyBkUM2hQ3ymusqjtEr3CErczzT1UkhERP |
+-----------------+------------------------------------+------------------------------------------------------+--------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+

mybitprices.info - wallet auditing tools
yinoye
Full Member
***
Offline Offline

Activity: 532
Merit: 101



View Profile
August 05, 2017, 06:29:13 AM
 #3

Do you  mean deriving new or existing public / private keys?
mocacinno
Legendary
*
Online Online

Activity: 1596
Merit: 1584


https://unblur.ninja =>lightning network testsite


View Profile WWW
August 05, 2017, 06:36:20 AM
 #4

Usefull stuff... I'll defenately follow your developments when i'm back at the office.

I quickly browsed part of your code
 At first sight, i couldn't detect any backdoors, just some really clean implementation of the bitwasp librarys Smiley

danda
Full Member
***
Offline Offline

Activity: 194
Merit: 139


View Profile WWW
August 05, 2017, 02:44:14 PM
 #5

Do you  mean deriving new or existing public / private keys?

I mean deriving keys deterministically from a seed in accordance with bip32 mechanism.

https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki

mybitprices.info - wallet auditing tools
danda
Full Member
***
Offline Offline

Activity: 194
Merit: 139


View Profile WWW
August 05, 2017, 02:46:52 PM
 #6

thx for code review!

I quickly browsed part of your code
 At first sight, i couldn't detect any backdoors, just some really clean implementation of the bitwasp librarys Smiley

mybitprices.info - wallet auditing tools
danda
Full Member
***
Offline Offline

Activity: 194
Merit: 139


View Profile WWW
July 04, 2018, 02:50:07 PM
Merited by achow101 (4), aliashraf (3), ETFbitcoin (1)
 #7

I just released version 0.3.1.  Some big improvements:

  • Support for deriving keys/addresses of 300+ altcoins, 90+ with bip44 path support.  Mostly bitcoin clones.
  • Added --gen-key flag to generate a new master key, mnemonic, seed, and extended keys for any supported cryptocurrency.
  • Use bip44 path by default when --mnemonic is specified.
  • Added --bch-format flag to display CashAddr format or regular Bitcoin format.

Here's a few examples:

Let's find what altcoins are supported.
Code:
$ ./hd-wallet-derive.php --helpcoins
+--------------------+------------------------------------+
| Symbol             | Coin / Network                     |
+--------------------+------------------------------------+
...
| ZEC                | Zcash - Mainnet                    |
| ZEC-test           | Zcash - Testnet                    |
| ZEC-regtest        | Zcash - Regtest                    |
...
+--------------------+------------------------------------+
(340+ altcoins omitted for brevity)


Derive some Zcash addresses
Code:
$ ./hd-wallet-derive.php --key=xprv9zbB6Xchu2zRkf6jSEnH9vuy7tpBuq2njDRr9efSGBXSYr1QtN8QHRur28QLQvKRqFThCxopdS1UD61a5q6jGyuJPGLDV9XfYHQto72DAE8 --cols=path,address --coin=ZEC --numderive=3 -g

+------+-------------------------------------+
| path | address                             |
+------+-------------------------------------+
| m/0  | t1V1Qp41kbHn159hvVXZL5M1MmVDRe6EdpA |
| m/1  | t1Tw6iqFY1g9dKeAqPDAncaUjha8cn9SZqX |
| m/2  | t1VGTPzBSSYd27GF8p9rGKGdFuWekKRhug4 |
+------+-------------------------------------+


Generate a new random master key, seed and extended keys for any altcoin.
Code:
$ ./hd-wallet-derive.php --coin=DOGE --gen-key --format=jsonpretty -g
[
    {
        "coin": "DOGE",
        "seed": "a3adc3e71ac05b3336422e6506d646e995f7bfcb960e6fca48dc13c93fae8ef3dc37a6013791ad1cfe7fe408de0e7676a9fe29b02413c79b988d54c74515d3db",
        "mnemonic": "arch hover pen regret priority sugar thunder glimpse west diagram path sword divide spread anger vendor century roof agree know treat drastic allow blind advance oil iron gold skate absorb stem shiver can pear twin helmet loan satisfy fragile admit comfort mercy pelican pupil debate tornado rifle desert",
        "master_priv_key": "dgpv51eADS3spNJh8eoSPqujdFPAhBZywAW6KQrR5TqM1Q5NMsrJmFP1hTXvfbUHLQFLmh4jVYZjXtJvKJVakn5YxT48mocEXu7yTNkCYN29cMV",
        "path": "m\/44'\/3'\/0'\/0",
        "ext_priv_key": "dgpv59SfnUBjPvKLfM453bkxJXHRfNvDQ3zAngt3fpKheqR846z9W1QYzoUz5ss4qtvLU7iBd93nw8ZXcXArpdLjuyudR2uUFH4KeV9Nes8eNeJ",
        "ext_pub_key": "dgub8tKh8A7cx4yfxCiE5qNvRNq27wHrEB1t5HfFpvigSxU8cA6qumxKe6tdf7TkUPFBoj6C8eBxofiydXy5hGf471zWZkYiy4tQ6vWqRwETdGA"
    }
]




mybitprices.info - wallet auditing tools
danda
Full Member
***
Offline Offline

Activity: 194
Merit: 139


View Profile WWW
July 08, 2018, 11:50:49 AM
Merited by achow101 (2), aliashraf (2)
 #8

I just released version 0.3.2 with support for deriving ethereum addresses, as well as generating random HD master keys.  enjoy!

Code:
$ ./hd-wallet-derive.php --coin=ETH --mnemonic="athlete alone tent cherry motor able gym lobster mad ahead peanut anger congress segment horn hidden crater host thumb audit sugar casino produce garment tag rose planet law gather human drop analyst tank cabbage casino hybrid fun science wheel bring insect helmet million guide survey grace save top" --cols=path,address --numderive=3 -g

+------------------+--------------------------------------------+
| path             | address                                    |
+------------------+--------------------------------------------+
| m/44'/60'/0'/0/0 | 0x92C4210c2fbC3237efb8a93611d0E61c3936E84b |
| m/44'/60'/0'/0/1 | 0x4b7A3CFc314D92447a8F2Ebe3F7b93D469bC195b |
| m/44'/60'/0'/0/2 | 0x1702ebaA4cD9AD453ea45569e27B877338d48862 |
+------------------+--------------------------------------------+




mybitprices.info - wallet auditing tools
danda
Full Member
***
Offline Offline

Activity: 194
Merit: 139


View Profile WWW
July 18, 2018, 01:00:36 PM
 #9

I just released version 0.4.0 of hd-wallet-derive.

This is a big release. The major new things are:

  • segwit support for bitcoin and most btc derived coins. (segwit keys for other coins is super highly experimental)
  • both p2sh (y) and bech32 (z) segwit addresses are supported.
  • support for LTC Ltub/Mtub style keys in addition to xpub/xpriv
  • support for LTC new style p2sh 'M' addresses.
  • lots of test cases
  • various bug fixes and enhancements.

At this moment, I believe this tool will generate keys/addresses for more blockchains (including testnets, regtest) and in more variations than any other tool on the planet.

See the readme for details and examples of using segwit keys.

mybitprices.info - wallet auditing tools
danda
Full Member
***
Offline Offline

Activity: 194
Merit: 139


View Profile WWW
July 21, 2018, 04:20:16 AM
 #10

bitcoin-core implements hd-wallet key derivation differently from most 3rd party wallets.

This release adds support for bitcoin-core style key derivation with these two features:

  • new flag --addr-type=[legacy|p2sh-segwit|bech32|auto]. Allows to override automatic address-type detection based on key-type.
  • x' in bip32 path to request hardened key for derived addresses. ex: --path="m/0'/0'/x'".

Here's an example:

Code:
$ /home/websites/hd-wallet-derive/hd-wallet-derive.php --path="m/0'/0'/x'" --addr-type=p2sh-segwit --cols=path,address,pubkey --numderive=3 --key=xprv9s21ZrQH143K3KeCJ5DMac7XqmriV7xVDDCV5MNE564bKUF6piF7JK6RWHVJMzQMUBbzxLaV9kNaRMHyjVnjNiLAq2SyvJJBs7ZUg4c9kcy -g

+------------+------------------------------------+--------------------------------------------------------------------+
| path       | address                            | pubkey                                                             |
+------------+------------------------------------+--------------------------------------------------------------------+
| m/0'/0'/0' | 3LTKKaLjr83nSCEE5gUfLzRhavU3wAdMtu | 0236ac3d8df99023e259d24754fd022af696542e25ff237bc9c835d52468b538ae |
| m/0'/0'/1' | 34dCyjA9rEtjDEZ1AUViTGxYvmNAFA3gFH | 0365d31a6168e1187202ffb30bc80b4a788d68e87909024b624d4963ff2426b339 |
| m/0'/0'/2' | 3FzQckSqoQNnzdGgn5sLRUgaE8Vxt4g4eo | 02446804c9bd85f0f782a0f4e52baa7398005b0ee54dc4eed23aeef64363a7ea99 |
+------------+------------------------------------+--------------------------------------------------------------------+

Details here.

mybitprices.info - wallet auditing tools
danda
Full Member
***
Offline Offline

Activity: 194
Merit: 139


View Profile WWW
May 13, 2019, 12:24:28 AM
Merited by HCP (2), ETFbitcoin (1), mocacinno (1)
 #11

It's been a while. This release adds:
  • Path presets for common wallet software, hardware wallets, and Bip standards such as Bip44, Bip49, Bip84.
  • Variables in paths for insertion of coin, account, and change values.
  • Iteration can now occur at any path level, not only the deepest level. (needed by Ledger-Live)
  • added --gen-words flag to control how many mnemonic words are created. [12..48]
    corrected ethereum private key serialization
  • minor bug fixes

Examples

Let's say we want to derive addresses for bitcoin-core software.  First, we need to find out the preset identifier for this software.

Code:
$ ./hd-wallet-derive.php --help-presets | head -n 7
+-------------------------+----------------------+-------------------------+------------------+---------------------------+
| id                      | path                 | wallet                  | version          | note                      |
+-------------------------+----------------------+-------------------------+------------------+---------------------------+
| bip44                   | m/44'/c'/a'/v/x      | Bip44 Compat            | n/a              | Bip44                     |
| bip49                   | m/49'/c'/a'/v/x      | Bip49 Compat            | n/a              | Bip49                     |
| bip84                   | m/84'/c'/a'/v/x      | Bip84 Compat            | n/a              | Bip84                     |
| bitcoincore             | m/a'/v'/x'           | Bitcoin Core            | v0.13 and above. | Bip32 fully hardened      |

If we want only the ids, we could use the command:

Code:
$ ./hd-wallet-derive.php --help-presets --format=list
bip44
bip49
bip84
bitcoincore
bither
breadwallet
coinomi
coinomi_bech32
coinomi_p2sh
copay
copay_hardware_multisig
copay_legacy
electrum
electrum_legacy
electrum_legacy_multi
hive
jaxx
ledgerlive
multibit_hd
multibit_hd_44
mycelium
samourai
samourai_bech32
samourai_p2sh
trezor
wasabi
   
Deriving addresses for bitcoin-core using preset path.

Using a preset means that we do not need to know the bip32 path.  We can do:

Code:
$ ./hd-wallet-derive.php -g --key=xprv9tyUQV64JT5qs3RSTJkXCWKMyUgoQp7F3hA1xzG6ZGu6u6Q9VMNjGr67Lctvy5P8oyaYAL9CAWrUE9i6GoNMKUga5biW6Hx4tws2six3b9c --numderive=3 --preset=bitcoincore --cols=path,address

+------------+------------------------------------+
| path       | address                            |
+------------+------------------------------------+
| m/0'/0'/0' | 1JsH5tzm2bphJySSLJ13AbFGP8KqJBYvG7 |
| m/0'/0'/1' | 19in8KwQy2waqzogwnVRvh2gt7EkHDGtwg |
| m/0'/0'/2' | 1CMc7jzi6ewKRzBNSCMkYzY3PU13ck6bxQ |
+------------+------------------------------------+

Deriving Change addresses for bitcoin-core using preset path.

We can use the --path-change flag for this.  requires a preset
with variable 'v' present in the path.

Code:
$ ./hd-wallet-derive.php -g --key=xprv9tyUQV64JT5qs3RSTJkXCWKMyUgoQp7F3hA1xzG6ZGu6u6Q9VMNjGr67Lctvy5P8oyaYAL9CAWrUE9i6GoNMKUga5biW6Hx4tws2six3b9c --numderive=3 --preset=bitcoincore --cols=path,address --path-change

+------------+------------------------------------+
| path       | address                            |
+------------+------------------------------------+
| m/0'/1'/0' | 1B6q1KTyaa9yLHV2HTZC1rZaSKMG8KNqsp |
| m/0'/1'/1' | 15RF1R9ZaSqgtaTVBDm1ySU5MQ6dZeTpZf |
| m/0'/1'/2' | 1DpzhgrgWuRSnQjvLiZHMG2TAjs86znvjj |
+------------+------------------------------------+

Notice that that 2nd field has changed from 0' to 1'.

Similarly, the coin and account fields of a Bip44 path (or any custom path) can hold variables so that a single path preset works for various situations.

mybitprices.info - wallet auditing tools
bob123
Hero Member
*****
Offline Offline

Activity: 896
Merit: 1014



View Profile WWW
May 14, 2019, 09:15:11 AM
 #12

Hello guys! Im noob, need a help!

Start a new topic in the correct sub of this forum and briefly explain your issue.
Make sure to include all information which might be necessary for us to help you.

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!