Skip to content

Commandline utility to traverse HD Keys from HD Wallet Seed and Extended Key (xprv, xpub) Paths

License

Notifications You must be signed in to change notification settings

dashhive/dashhd-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Commandline utility to traverse HD Keys from HD Wallet Seed and Extended (xprv, xpub) Key Paths.
(compatible with the [Hierarchical Deterministic Keys (BIP-44)][bip-44] and [BIP-32][bip-32] specs)

A fully-functional, production-ready reference implementation of Dash HD - suitable for learning DASH specs and protocols, and porting to other languages.

Overview: Seeds => XKeys => Keys

dashhd <./seed-or-key> [start-hdpath-or-index] [end]

Seed => Extended Key

dashhd ./seed.hex   "m/44'/5'/0'/0"
# XPrv
xprvA2L7qar7dyJNhxnE47gK5J6cc1oEHQuAk8WrZLnLeHTtnkeyP4w6Eo6Tt65trtdkTRtx8opazGnLbpWrkhzNaL6ZsgG3sQmc2yS8AxoMjfZ

# XPub
xpub6FKUF6P1ULrfvSrhA9DKSS3MA3digsd27MSTMjBxCczsfYz7vcFLnbQwjP9CsAfEJsnD4UwtbU43iZaibv4vnzQNZmQAVcufN4r3pva8kTz

Extended Key to Address Key

dashhd ./0-0-0.xprv 0
# WIF
XCGKuZcKDjNhx8DaNKK4xwMMNzspaoToT6CafJAbBfQTi57buhLK

# Address
XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9

Table of Contents

Install

npm install --location=global dashhd-cli@1
dashhd ./seed.hex "0'/0"

Or, use without installing:

npx -p dashhd-cli dashhd ./seed.hex "0'/0"

Usage

Note: Convert Recovery Phrases to Seeds with dashphrase.

Also, all example values below are derived from the Zoomonic Seed:

./seed.hex:

ac27495480225222079d7be181583751e86f571027b0497b5b5d11218e0a8a13332572917f0f8e5a589620c6f15b11c61dee327651a14c34e18231052e48c069

How HD Paths Work

You can use either the full HD Path (required for coins other than DASH), or abbreviate, starting with the HD Account:

m/44'/5'/0'/0    - absolute Extended Key path
         0'/0    - relavite Extended Key path (DASH only)

m/44'/5'/0'/0/0  - absolute Address Key path
         0'/0/0  - relative Address Key path (DASH only)

From Dash HD: HD Path:

The path that defines an HD Key - typically of the BIP-44 variety:

  • a Root (master), ex: m (depth 0, the Wallet Key, straight from the seed)
  • an Coin Key, ex: m/44'/5' (depth 2)
  • an Account, ex: m/44'/5'/0' (depth 3)
  • an X Key (XPrv or XPub), ex: m/44'/5'/0'/0 (depth 4, a.k.a. Use)
  • an Address Key, ex: m/44'/5'/0'/0/0 (depth 5, the end)
  • ' is used for "hardened" (parent) key segments,
    but not for "public" (shareable) child key segments

In general:

m/<purpose>'/<coin-type>'/<account>'/<use>/<index>

For DASH:

m/44'/5'/<account>'/<use>/<index>

(because we always use BIP-44 and our coin type is 5)

See also:

Wallet Seed to Extended Keys

  1. Convert your Recovery Phrase to a Seed with DashPhrase
  2. Derive Extended Keys for Account at index 2:
    # dashhd ./seed.hex       "/<account>'/<use>"
    dashhd ./seed.hex         "/2'/0"
    (the Use index will be 0 for most common use cases)
  3. The output will have an XPrv and XPub, like this:
    # starts with "xprv" (111 characters)
    xprvA1t6Pgks9siC1M6QTqstaDpK7GqJfiDZq4tpD6eKVyVf4iAb3LViw6jk1mp2XUawhpoYCCwrQphPpS9V36VhDLxP6QK5FGx5wR6iF8xMYHc
    # starts with "xpub" (111 characters)
    xpub6EsSoCHkzFGVDqAsZsQtwMm3fJfo5AwRCHpR1V3w4K2dwWVjasoyUu4Ds2XtjE9QY83pdNBtduc17UKQV46iQmAJFQ7NywC4ggdEi1Ki76a

More examples:

# Absolute HD Path
dashhd ./seed.hex "m/44'/5'/2'/0"

# Absolute HD Path with Relative Range
dashhd ./seed.hex "m/44'/5'/0'/0" "5'/0"

# Same as above, but with relative HD Path
dashhd ./seed.hex          "0'/0" "5'/0"

Wallet Seed to Address Keys

  1. Convert your Recovery Phrase to a Seed with DashPhrase
  2. Derive Address Keys for Address 3 of Account 2 (0-indexed):
    # dashhd ./seed.hex       "/<account>'/<use>/<index>"
    dashhd ./seed.hex         "/2'/0/3"
    (the Use index will be 0 for most common use cases)
  3. The output will have a WIF (longer) and Address, like this:
    # WIF (51 characters)
    HjSuSQ7F2dVqmzB4BLzEaLNrptzzVUBCXjo76us7AWQY954CWe3
    # Address (34 characters)
    XyvDv4Jz3cfXrbTvecymTe2MmXryokCEHi

More examples:

# Absolute HD Path
dashhd ./seed.hex "m/44'/5'/2'/0/3"

# Absolute HD Path with Relative Address Ranges
dashhd ./seed.hex "m/44'/5'/2'/0/3" "2'/0/5"

# Absolute HD Path with Relative Account + Address Ranges
dashhd ./seed.hex "m/44'/5'/0'/0/0" "2'/0/3"

# Same as above, but with relative HD Path
dashhd ./seed.hex          "2'/0/3" "2'/0/5"
dashhd ./seed.hex          "0'/0/0" "2'/0/3"

Extended Keys to Address Keys

Extended Keys come in a pair:

  • the person receiving payment generates the pair
    (they keep the XPrv to themselves)
  • the person paying accepts the XPub from the other
    (each payment will go incrementally to the next unused address)

Pay a Contact

If Alice wants to pay Bob, and the next unused is at index 3:

# dashhd ./payee.xpub <index>
dashhd   ./bob.xpub   3
# Address
XyvDv4Jz3cfXrbTvecymTe2MmXryokCEHi

Check & Spend a Payment

Bob must use the WIF (first, longer) to spend a a payment.
Before doing so he can check teh account with the Address (shorter).

# dashhd ./payer.xprv <index>
dashhd   ./alice.xprv 3
# WIF
HjSuSQ7F2dVqmzB4BLzEaLNrptzzVUBCXjo76us7AWQY954CWe3
# Address
XyvDv4Jz3cfXrbTvecymTe2MmXryokCEHi

Working with Ranges

You can specify a range to generate multiple Extended Keys or Address Keys at once.

Extended Key Ranges

# Absolute HD Path
dashhd ./seed.hex "m/44'/5'/0'/0" "m/44'/5'/2'/0"

# Absolute HD Path with Relative Range
dashhd ./seed.hex "m/44'/5'/0'/0"          "2'/0"

# Same as above, but with relative HD Path
dashhd ./seed.hex          "0'/0"          "2'/0"

The output will include the HD Path for easy identification:

m/44'/5'/2'/0:
xprvA1t6Pgks9siC1M6QTqstaDpK7GqJfiDZq4tpD6eKVyVf4iAb3LViw6jk1mp2XUawhpoYCCwrQphPpS9V36VhDLxP6QK5FGx5wR6iF8xMYHc
xpub6EsSoCHkzFGVDqAsZsQtwMm3fJfo5AwRCHpR1V3w4K2dwWVjasoyUu4Ds2XtjE9QY83pdNBtduc17UKQV46iQmAJFQ7NywC4ggdEi1Ki76a

Address Key Ranges

# Absolute HD Path
dashhd ./seed.hex "m/44'/5'/2'/0/0" "m/44'/5'/2'/0/5"

# Absolute HD Path with Relative Address Ranges
dashhd ./seed.hex "m/44'/5'/2'/0/2"          "2'/0/5"

# Absolute HD Path with Relative Account + Address Ranges
dashhd ./seed.hex          "0'/0/0"          "2'/0/2"

# Same as above, but with relative HD Path
dashhd ./seed.hex          "2'/0/2"          "2'/0/5"
dashhd ./seed.hex          "0'/0/0"          "2'/0/2"

The output will include the HD Path for easy identification:

m/44'/5'/2'/0/3:
XHjSuSQ7F2dVqmzB4BLzEaLNrptzzVUBCXjo76us7AWQY954CWe3
XyvDv4Jz3cfXrbTvecymTe2MmXryokCEHi

Fixtures

These are for testing and debugging HD Key libraries and HD wallets.

Libraries should support Recovery Phrase "secret"s - also known as salt or (misnomer) password.

However, in practice, most wallets don't ask the user and simply put an empty string as the secret.

Also, in practice, the XPrv and XPub Use is always designated as Receiving (External), not Change (internal).

For completeness, we offer fixtures for all of those features below.

Catmonic (empty secret)

Recovery Phrase:

cat swing flag economy stadium alone churn speed unique patch report train

Secret (Salt):

(empty string)

XPrvs, XPubs, WIFs, and Addresses:

See ./examples/ and ./FIXTURES.md.

Zoomonic (with secret salt)

Recovery Phrase:

zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong

Secret (Salt):

TREZOR

XPrvs, XPubs, WIFs, and Addresses:

m/44'/5'/0'/0   XPrv & XPub

                xprvA2L7qar7dyJNhxnE47gK5J6cc1oEHQuAk8WrZLnLeHTtnkeyP4w6Eo
                    6Tt65trtdkTRtx8opazGnLbpWrkhzNaL6ZsgG3sQmc2yS8AxoMjfZ
                xpub6FKUF6P1ULrfvSrhA9DKSS3MA3digsd27MSTMjBxCczsfYz7vcFLnb
                    QwjP9CsAfEJsnD4UwtbU43iZaibv4vnzQNZmQAVcufN4r3pva8kTz

m/44'/5'/0'/0/0 WIF & Address

                XCGKuZcKDjNhx8DaNKK4xwMMNzspaoToT6CafJAbBfQTi57buhLK
                XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9
m/44'/5'/1'/1   XPrv & XPub

                xprvA2ACWaqwADRtbkLsM6oQHzeWtqZVviBmKMKNRBFcwKGGRBgWHNeoZS
                    KzduFMFkqvNsV5LaqRT9XRibzgSAweAAsfMF35PWy6beK3aL1BwTU
                xpub6F9Yv6NpzazBpERLT8LQf8bFSsPzLAucgaEyDZfEVeoFHz1epuy47E
                    eUVCRTNVToM1zgFZMxiGs2AFc9cNqZE2UVwJod2zPkG7W4ZGRuwJJ

m/44'/5'/1'/1/1 WIF & Address
                XF9murLtNpJaZXbwMxqJ6BhigEtu9NxfBCJDBokCJcqFkYkz3itz
                XueHW2ELMxoXzXcaHMxmwVWhcADE1W5s8c
m/44'/5'/2'/0   XPrv & XPub

                xprvA1t6Pgks9siC1M6QTqstaDpK7GqJfiDZq4tpD6eKVyVf4iAb3LViw6
                    jk1mp2XUawhpoYCCwrQphPpS9V36VhDLxP6QK5FGx5wR6iF8xMYHc
                xpub6EsSoCHkzFGVDqAsZsQtwMm3fJfo5AwRCHpR1V3w4K2dwWVjasoyUu
                    4Ds2XtjE9QY83pdNBtduc17UKQV46iQmAJFQ7NywC4ggdEi1Ki76a

m/44'/5'/2'/0/3 WIF & Address

                XHjSuSQ7F2dVqmzB4BLzEaLNrptzzVUBCXjo76us7AWQY954CWe3
                XyvDv4Jz3cfXrbTvecymTe2MmXryokCEHi

m/44'/5'/2'/0/5 WIF & Address

                XCcWUUGUkCeYLteuYmocSy9UbSwbCZD2nNCxXW5DKSN3YKHEE6xx
                XgBR52CgtFEdvrbN7YdwUVP5HCxDMyWKqk

More Fixtures

See also:

Glossary

If you're new to all this, check out these glossaries:

LICENSE

MIT License

Copyright 2023 Dash Incubator
Copyright 2023 AJ ONeal

About

Commandline utility to traverse HD Keys from HD Wallet Seed and Extended Key (xprv, xpub) Paths

Topics

Resources

License

Stars

Watchers

Forks