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

Add Ledger seed import mode #3703

Closed
Swader opened this issue Sep 17, 2020 · 13 comments · Fixed by #4529
Closed

Add Ledger seed import mode #3703

Swader opened this issue Sep 17, 2020 · 13 comments · Fixed by #4529

Comments

@Swader
Copy link
Contributor

Swader commented Sep 17, 2020

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.

@jacogr
Copy link
Member

jacogr commented Sep 17, 2020

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.

@jacogr
Copy link
Member

jacogr commented Jan 27, 2021

Needs some info at Zondax/ledger-polkadot#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.

This was referenced Jan 28, 2021
@Tbaut
Copy link
Contributor

Tbaut commented Jan 29, 2021

@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

@jacogr
Copy link
Member

jacogr commented Jan 29, 2021

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.

@Tbaut
Copy link
Contributor

Tbaut commented Jan 29, 2021

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.

@Swader
Copy link
Contributor Author

Swader commented Jan 29, 2021

Yeah we'll handle that, no worries 👌

@jacogr
Copy link
Member

jacogr commented Jan 30, 2021

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

Took "some" time to figure out.

@jacogr
Copy link
Member

jacogr commented Jan 30, 2021

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

@gorgos
Copy link

gorgos commented Jan 30, 2021

@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.

@jacogr
Copy link
Member

jacogr commented Jan 30, 2021

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...

@gorgos
Copy link

gorgos commented Jan 30, 2021

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.

@jacogr
Copy link
Member

jacogr commented Jan 30, 2021

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.

@polkadot-js-bot
Copy link

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.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Jun 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants