Apps: Add Ledger seed import mode

Created on 17 Sep 2020  路  13Comments  路  Source: polkadot-js/apps

Because the derivation path is different in Ledger devices, recovering a Ledger seed into Polkadot JS Apps or the extension from the seed won't produce the same account as if the Ledger device were queried. In other words, Account 0, Path 0 on Add Ledger does not produce the same address as an import from seed with derivation paths //0, //1, /0/0, or /1/1. A switch "importing from Ledger" or a heads up on which derivation path to use during importing from seed would be useful, so people can use their Ledger wallets even when the Ledger app is not functioning correctly.

-size-m @app-accounts

Most helpful comment

Have a sample as to how it works from Ledger https://github.com/jacogr/sample-ledger-ed25519

Took "some" time to figure out.

All 13 comments

Derivation in Substrate is very different (to say the least). Not against the idea, so PRs are welcome to utils/keyring for this type of support provided it has a no additional dependency overhead and a low maintenance overhead. Once that is available, can re-visit the UI aspects.

Needs some info at https://github.com/Zondax/ledger-polkadot/issues/61

Been playing a bit and really cannot figure it out by myself here :)

The issue is obviously that users should really only use this as a last resort, i.e. I was without my Ledger for a couple of weeks (and luckily didn't need access). S there are def. recovery reasons, but certainly users should keep as much t the HW as possible.

Anyway, If I understand how, can pull it in.

@Swader I think it would be great, and very important to couple this feature with a wiki page on polkadot.wiki, explaining what users should do if they ever enter their ledger mnemonic on an online device. I'm not a heavy ledger user so you'll know better, but I guess this involves:

  • transfering the funds asap to another account (suggest Signer?, at least on the extension?)
  • Make sure there are no other coin associated with the ledger mnemonic that just went online, if any -> transfer elsewhere
  • create a new mnemonic from the ledger itself and make sure to never use the old one again
  • transfer back all the funds

It applies to stuff like the QR signer as well - anything where you store the keys in an offline device. So we actually have that issue already where people can actually take cold keys and move it hot - so some guidance generally is actually a really good idea.

Indeed, this could be framed more generally. But something comprehensive for the less technical users would be very valuable. Users ending up in a situation where they don't understand why they can't access their funds and fear loosing them become a particularly good target for scammer pretending to help them.

Yeah we'll handle that, no worries 馃憣

Have a sample as to how it works from Ledger https://github.com/jacogr/sample-ledger-ed25519

Took "some" time to figure out.

So just an update -

So with the command line tool you can extract the seed, the README has usage instructions for it on the above link. Once you have it run with your mnemonic and account/address indexes and you have the ed25519 seed...

  • add an account in the apps UI
  • select the type dropdown to Raw (changing it from mnemonic)
  • Past the ed25519 seed hex as retrieved from the tool
  • click "advanced options" and select ed25519
  • check that the addresses do match with expectation
  • create account

@jacogr Thank you! I just got the KSM back via offline computer. Would you mind sharing the gist of https://github.com/jacogr/sample-ledger-ed25519? I can't say I understand the code.

Well, thanks to you since I ended up in a dead-end with 3 other approaches :)

So the Ledger uses bip32+ed25519 derivation. So what it does in general terms is the following (it is a bit messy, it actually has been cleaned up but not pushed there) -

  • starts off by path construction, which is m/44'/{0x0162 or 0x01b2}'/{account}'/0'/{address}' (the second cointype is either for Kusama or Polkadot)
  • then it gets the master key, which is actually translated from the Ledger Python code
  • now it goes through each segment of the derivation path (excluding m) and applies the hard derivation using that value (this I struggled a bit with the Python translation, but Cardano extraction code helped to make it more translatable)
  • lastly it takes the output from the previous and feeds it into the ed25519 to create a pair (the from seed function uses the first 32 bytes of the output of the previous step)

... lastly, I tested this against my Ledger...

That's great. Thanks for the info. I was running the Python code directly after changing path and mnemonic inside the Python code, but had no idea what the tool was printing there.

Sounds like this task wasn't easy, so much appreciated, thanks again.

It was more of a relief than anything else - I've been playing with it for the last 2 weeks now (on the back of this and my Ledger going MIA) and couldn't figure it out with Google as my tool.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chevdor picture chevdor  路  8Comments

soc1c picture soc1c  路  5Comments

laurogripa picture laurogripa  路  6Comments

jacogr picture jacogr  路  5Comments

illlefr4u picture illlefr4u  路  5Comments