Skip to content

Latest commit

 

History

History
265 lines (202 loc) · 6.36 KB

README.md

File metadata and controls

265 lines (202 loc) · 6.36 KB

CLI Reference Tools for converting and validating DASH Private Keys and Payment Addresses

Features

  • Validate Base58Check addresses
    • WIF (Wallet Import Format for Private Keys)
    • PayAddr
  • WIF to Addr
  • Addr (Base58Check) to PubKeyHash (PKH)
  • Output as text or JSON
  • API

See Dash HD for Extended Private Key (xprv) and Extended Public Key (xpub) features.

Install

  1. Install node.js
    # Mac, Linux
    curl -sS https://webi.sh/node | sh
    # Windows 10+
    curl.exe https://webi.ms/node | powershell
  2. Install dashkeys-cli via npm
    npm install --location=global dashkeys-cli

Usage

See dashkeys help for the most up-to-date info:

dashkkeys help

Usage:
    dashkeys address <./file.wif>    convert WIF to Pay Addr
    dashkeys generate                create WIF [DEV TOOL]
    dashkeys inspect <addr-or-file>  decode base58check
    dashkeys verify <addr-or-file>   validate checksum

    dashkeys help     show this menu
    dashkeys version  show version

Global Flags:
    --json             machine-friendly json to stdout
    --unsafe           no private key mask, accept as string

Convert WIF to Payment Address

From a file:

# File contents: XCGKuZcKDjNhx8DaNKK4xwMMNzspaoToT6CafJAbBfQTi57buhLK
dashkeys address ./XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9.wif
Pay Addr is XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9

From a string (unsafe), as JSON:

dashkeys address --json --unsafe 'XCGKuZcKDjNhx8DaNKK4xwMMNzspaoToT6CafJAbBfQTi57buhLK'
{
  "address": "XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9"
}

Verify an Addr (string) or WIF (file)

Verify a PubKeyHash:

dashkeys verify 'XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9'
Pay Addr string is valid
(Pub Key Hash: ae14c8728915b492d9d77813bd8fddd91ce70948)

Verify a WIF file:

# File contents: XCGKuZcKDjNhx8DaNKK4xwMMNzspaoToT6CafJAbBfQTi57buhLK
dashkeys verify ./XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9.wif
Private Key file valid

Inspect a Key

Inspect a PubKeyHash (as json):

dashkeys inspect --json 'XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9'
{
  "valid": true,
  "version": "4c",
  "pubKeyHash": "ae14c8728915b492d9d77813bd8fddd91ce70948",
  "check": "ce08541e",
  "compressed": true
}

Inspect a WIF (masked):

# File contents: XCGKuZcKDjNhx8DaNKK4xwMMNzspaoToT6CafJAbBfQTi57buhLK
dashkeys inspect --json ./XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9.wif
{
  "address": "XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9",
  "valid": true,
  "version": "cc",
  "privateKey": "1d************************************************************50",
  "compressed": true,
  "check": "ec533f80",
  "publicKey": "0245ddd5edaa25313bb88ee0abd359f6f58ac38ed597d33a981f1799903633d902",
  "pubKeyHash": "ae14c8728915b492d9d77813bd8fddd91ce70948",
  "pubKeySha256": "8e5abfc42a6d7529b860ce2b4b8889380db893438dc96430f597ddb455e85fdd"
}

Inspect a WIF (unmasked):

# File contents: XCGKuZcKDjNhx8DaNKK4xwMMNzspaoToT6CafJAbBfQTi57buhLK
dashkeys inspect --json --unmask ./XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9.wif
{
  "address": "XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9",
  "valid": true,
  "version": "cc",
  "privateKey": "1d2a6b22fcb5a29a5357eaf27b1444c623e5e580b66ac5f1109e2778a0ffb950",
  "compressed": true,
  "check": "ec533f80",
  "publicKey": "0245ddd5edaa25313bb88ee0abd359f6f58ac38ed597d33a981f1799903633d902",
  "pubKeyHash": "ae14c8728915b492d9d77813bd8fddd91ce70948",
  "pubKeySha256": "8e5abfc42a6d7529b860ce2b4b8889380db893438dc96430f597ddb455e85fdd"
}

note: the _xy* debug fields show incorrect values that are common mistakes - to help those developing their own PubKeyHash or Base58Check key library in other languages.

Generate a Key

Note: This is just for DEVELOPMENT. Generally speaking, you should use generate recoverable keys using Dash Wallet or Dash HD instead.

(there's nothing wrong with these keys - they're fully tested, they're just not HD keys)

dashkeys generate
Saved new private key to './XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9.wif'

The name of the file is the Pay Addr (Base58Check-encoded Public Key Hash) and the contents are the WIF (private key).

The leading X for each is because they are base58check-encoded.

API

See DashKeys.js.

Fixtures

For troubleshooting, debugging, etc, the keys used in this example come from the canonical Dash "Zoomonic":

Passphrase (Mnemonic)  :  zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong
Secret (Salt Password) :  TREZOR
HD Path                :  m/44'/5'/0'/0/0:
WIF                    :  XCGKuZcKDjNhx8DaNKK4xwMMNzspaoToT6CafJAbBfQTi57buhLK
Addr                   :  XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9

Correct PubKeyHash Values

dashkeys inspect --unmask ./examples/m44_5_0_0-0.wif
    Version:     cc
    Private Key: 1d2a6b22fcb5a29a5357eaf27b1444c623e5e580b66ac5f1109e2778a0ffb950
    Compressed:  01
    Pay Addr:    XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9
    Check:       ec533f80
    Valid:       true

Private Key (Debug Info):

PrivateKey:   cc011d2a6b22fcb5a29a5357eaf27b1444c623e5e580b66ac5f1109e2778a0ffb950
  --------
  Version:    cc
  Comp Flag:  01 (Compressed)
  Priv Key:   1d2a6b22fcb5a29a5357eaf27b1444c623e5e580b66ac5f1109e2778a0ffb950
  --------
WIF:          XCGKuZcKDjNhx8DaNKK4xwMMNzspaoToT6CafJAbBfQTi57buhLK

Public Key Hash (Debug Info):

PubKey:       0245ddd5edaa25313bb88ee0abd359f6f58ac38ed597d33a981f1799903633d902
  --------
  Comp Flag:  02 (Quadrant 2)
  X:          45ddd5edaa25313bb88ee0abd359f6f58ac38ed597d33a981f1799903633d902
  SHA256:     8e5abfc42a6d7529b860ce2b4b8889380db893438dc96430f597ddb455e85fdd
  *RMD160:    54408a877b83cb9706373918a430728f72f3d001 (*not used)
  PubKeyHash: ae14c8728915b492d9d77813bd8fddd91ce70948
  Check:      ce08541e
  Version:    4c
  --------
Pay Address:    XrZJJfEKRNobcuwWKTD3bDu8ou7XSWPbc9

LICENSE

Copyright (c) 2023 Dash Incubator
Copyright (c) 2023 AJ ONeal

MIT License