Hardware wallet - recover private keys

Bored Founder
Paweł Nowosielski
|
August 29, 2022

Abstract

I lost one of my Ledger devices, back in 2018. Situation which might be the worst nightmare for many teaches me how to recover my private keys without waiting for a new device.

Please DO NOT follow this advice with your own recovery phrase just to confirm your addresses. There is a reason Ledger and similar security focused companies advise to never input your recovery phrase into internet-connected devices. However, I encourage you to try to replicate my results on the zero-seed which is presented below.

Assumptions

  • This instruction should work for all Hardware wallets as it's based on Bitcoin's standards.
  • I've tested it on Ledger Nano S and Ledger Nano S Plus devices.
  • You have installed a Ledger Live application on your computer and set up Bitcoin and Ethereum accounts on it.
  • You have backed up your wallet's recovery phrase.

Vocabulary

  • Seed phrase, recovery phrase or mnemonic: A phrase containing 12 or 24 words which can be used to generate multiple accounts. There are 2048 carefully chosen words in total that form any mnemonic.
  • Account, address: A single private key or address in a wallet. We can generate millions of private keys from the mnemonic. Each private key corresponds to a single address of the account.
  • Wallet: A collection of accounts we have a private key for. For example Ledger Live allows us to add another account unless we transfer funds to previously added accounts.
  • If you are curious about the technical details, the procedure to generate so-called Hierarchical Deterministic Wallets is described in BIP32 and how to use mnemonic as an entropy to the generator is described in BIP39.

I'll show you how to recover private keys to your accounts using the command-line tool wagyu as I prefer a distraction-free text interface. You will find installation instructions in the wagyu repository.

You may also use the online tool which is Ian Coleman's website which will also work offline. It's easier to use so I'll leave the example accounts recovery to you.

⚠ Please don't use your recovery phrase! I won't show you how to clean your computer after the experiments, so proceed at your own risk.

Time for action!

Zero seed

For the purpose of this experiment, I'll use the "zero" mnemonic which is 24-words 23 x abandon + art. If you have read BIP-39 Mnemonic code for generating deterministic keys you may suspect why I call it "zero".

I will proceed in my terminal, you can also try it in the browser on Ian Coleman's website, but it might require more writing and clicking.

-- CODE language-js -- MNEMONIC="$(yes 'abandon' | head -23 | xargs) art" echo $MNEMONIC

Knowing the path

To make the "Hierarchical Deterministic Wallets" procedure work for many blockchains, the first elements along the hierarchy path have to describe the chain. E.g.

  • m/84'/0' - is the new Bitcoin path
  • m/44'/60'' - is the Ethereum path

You can discover the correct path going for "edit accounts" in the Ledger Live application.

Recovering the accounts

Here I'm using the same paths as the Ledger Live application, so you will be able to recover your own accounts when you need them.

Ethereum

Here are the first 3 addresses derived from our zero-seed. Try to get them by yourself.

  • 0xF278cF59F82eDcf871d630F28EcC8056f25C1cdb path m/44'/60'/0'/0/0
  • 0x94142B4f665316D3304C3a595ec83aC9C8046598 path m/44'/60'/1'/0/0
  • 0xe93E76dFCc3Bb3A6A3A36Bcd9df68cb7C0AD46AA path m/44'/60'/2'/0/0

-- CODE language-js -- wagyu ethereum import-hd \   --mnemonic $MNEMONIC \   --derivation "m/44'/60'/0'/0/0"

Bitcoin (Bech32 format)

  • bc1qyn0ml52dy0udru3nafudt6af7x2kv7ngysfk0k path m/84'/0'/0'/0/1
  • bc1qn3janx3aep39dty3c9q9tj8h74lwchn09rftpx path m/84'/0'/0'/0/2
  • bc1qtjfcy96x0lue5tka6sftq0wjr2wv8v6tg6m3sn path m/84'/0'/0'/0/3

-- CODE language-js -- wagyu bitcoin import-hd \   --mnemonic $MNEMONIC \   --derivation "m/84'/0'/0'/0/1" \   --format bech32‍