Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/lnwallet: add new wallet utility #2373

Closed
wants to merge 1 commit into from

Conversation

guggero
Copy link
Collaborator

@guggero guggero commented Dec 25, 2018

In this PR we add a new command line utility program that allows us to inspect/dump a wallet.db file.

Without this tool, there is currently no way to dump the private keys generated by lnd or even find out how many on-chain addresses have been generated (which is important to know when restoring a wallet from a seed).

There are two sub-commands available:

  • dumpwallet prints a bitcoind compatible dump wallet file to standard out (including all used addresses and their private keys).
    • Example: lnwallet --testnet dumpwallet --wallet_file example.db
    • Output:
# Wallet dump created by lnwallet 0.5.1-beta commit=v0.5.1-beta-253-g1838b64c6d0104a0e3eafd5607bfd368ced46de5-dirty
# * Created on 2018-12-25 17:30:57.063592003 +0000 UTC
# * Best block at time of backup was 395537 (00000000d6d7a72d0bb864ef8a76400944ab8a4dd7bd5618298ec4040e7e4160),
#   mined on 2042-07-14 01:04:00 +0000 UTC# * Total balance: 0.00000000

cNftcFWKK7XS9EYnC1rhwo9sG8gY1fSuFFYzEdPH72ArysSm8EMF 1970-01-01T00:00:01Z label= # addr=tb1q85u3d2ajetr5u9hslypelpz8y3c3nc87l3vptc
cVW9Qtximxk9fx5V53N4Bc4yt3R1HUVY3neLDTa6Uavg8xK3WtNu 1970-01-01T00:00:01Z label= # addr=tb1qfwfhfvrw6npxs6e82sdmwzj2dftyptqnlg07jl
...
  • walletinfo prints the node's identity pubkey, the number of addresses used and, if requested, the BIP32 extended root key to standard out.
    • Example: lnwallet --testnet walletinfo --wallet_file example.db --with_root_key
    • Output:
Identity Pubkey: 0322...
Scope: m/49'/0'
  Number of internal (change) np2wkh addresses: 0
  Number of external np2wkh addresses: 0
Scope: m/84'/0'
  Number of internal (change) p2wkh addresses: 0
  Number of external p2wkh addresses: 166
Scope: m/1017'/1'
  Number of internal (change) p2wkh addresses: 0
  Number of external p2wkh addresses: 82
BIP32 extended root key: tprv8ZgxMBicQK...

@guggero guggero force-pushed the lnwallet branch 3 times, most recently from d4f609f to 3f86caa Compare December 29, 2018 13:26
@Sowiedu
Copy link

Sowiedu commented Jan 2, 2019

Can you extend it to also dump a mnemonic phrase?

@guggero
Copy link
Collaborator Author

guggero commented Jan 2, 2019

That's not possible. The mnemonic phrase/seed is hashed to create the extended root key. The process cannot be reversed and only the BIP32 extended root key is stored in the wallet.db file.

@Roasbeef Roasbeef added enhancement Improvements to existing features / behaviour wallet The wallet (lnwallet) which LND uses safety General label for issues/PRs related to the safety of using the software recovery Related to the backup/restoration of LND data (e.g. wallet seeds) P3 might get fixed, nice to have labels Jan 2, 2019
@slush0
Copy link

slush0 commented Jan 5, 2019

@guggero Please add possibility to export also extended root key (xpriv). It is major piece of information for many tools for handling with wallets.

@guggero
Copy link
Collaborator Author

guggero commented Jan 6, 2019

@slush0 That's what you do with --with_root_key:

...
BIP32 extended root key: tprv8ZgxMBicQK...

It just says tprv because the example is from testnet.

Copy link

@Kukks Kukks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add COPY --from=builder /go/bin/lnwallet /bin/ to the Dockerfile

Kukks added a commit to Kukks/lnd that referenced this pull request May 14, 2019
@guggero guggero force-pushed the lnwallet branch 2 times, most recently from 26d9e9a to 2bd1017 Compare May 26, 2019 12:46
@guggero
Copy link
Collaborator Author

guggero commented May 26, 2019

@Kukks you're right, thanks. At the time I probably thought that it wasn't really needed in the docker image but for consistency it's probably best to add it anyway.

@guggero
Copy link
Collaborator Author

guggero commented Feb 2, 2020

Closing this in favor of https://github.com/guggero/chantools which now contains both functionalities of this PR (and more).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements to existing features / behaviour P3 might get fixed, nice to have recovery Related to the backup/restoration of LND data (e.g. wallet seeds) safety General label for issues/PRs related to the safety of using the software wallet The wallet (lnwallet) which LND uses
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants