iancoleman / bip39

A web tool for converting BIP39 mnemonic codes
https://iancoleman.io/bip39/
MIT License
3.57k stars 1.45k forks source link

BIP-84 "calculating" never finishes for LTC (fine for BTC) #223

Closed aleqx closed 6 years ago

aleqx commented 6 years ago

I used my Coinomi mnemonic, selected BTC, and the default BIP-44 works fine. Clicking on the BIP-84 tab, it also works fine. I can see the receiving addresses for the wallet both legacy (44) and segwit (84).

However, when I choose LTC, it works fine for BIP-44, but when clicking on the BIP-84 tab it says "Calculating" and it never finishes ... or at least it didn't finish in 30 minutes on a 5GHz machine. Any clues?

Problem exists for any mnemonic. Steps to reproduce:

Gif proof: https://i.gyazo.com/703336223ed9d54f62c94bad7d38d53d.gif

iancoleman commented 6 years ago

Litecoin did not have bech32 parameters, see https://github.com/iancoleman/bip39/commit/bda303dd533def617087827183aa9129450d6cfa for the fix. I'll be making a new release today with this change included. I'll also add a test for this to prevent regression.

aleqx commented 6 years ago

Looking forward to your release (I presume you'll deploy it on https://iancoleman.com/bip39/ as well)

What's more interesting is that the official Electrum LTC wallet v3.1.3.1 has the same problem! It gets stuck at "Synchronizing" and never finishes.

iancoleman commented 6 years ago

Also related to https://github.com/iancoleman/bip39/issues/197

BIP84 is bech32 / p2wpkh but this tool only has litecoin parameters for p2wpkh-in-p2sh. Until those parameters are added to segwit-parameters.js this will remain broken unfortunately. I'll try to find them.

Thanks for reporting this.

aleqx commented 6 years ago

You're very welcome.

However, I just tried src/index.html from a freshly cloned master, which is calling your updated segwit-parameters.js, and it still hangs ... am I missing something?

iancoleman commented 6 years ago

Litecoin will currently only work with bip49 (not bip84), because there are only p2wpkh-in-p2sh parameters for segwit (not p2wpkh which bip84 requires).

Litecoin has segwit support, but the encoding of the bip32 keys is only defined for some parts of segwit.

See the code for litecoin segwit params here: https://github.com/iancoleman/bip39/blob/370e201901290916e6cd6a2b1cd8d6caf0a71ce5/src/js/segwit-parameters.js#L59-L70

aleqx commented 6 years ago

Got it. Will wait for the patch.

iancoleman commented 6 years ago

See

Note that p2wpkh is still not working with litecoin due to no parameters being found for this, but there is a message shown for this rather than 'hanging' forever on calculating.

If p2wpkh parameters can be found I'll be glad to add them.

Released in the current release 0.3.7 and published to iancoleman.io/bip39

aleqx commented 6 years ago

Note that p2wpkh is still not working with litecoin due to no parameters being found for this, [...]

If p2wpkh parameters can be found I'll be glad to add them.

I'm not an expert, but what exactly do you mean by "no parameters can be found"? Are you saying it cannot be implemented at this time? Surely that must be possible given that the Electrum LTC wallet is able to import a BIP39 mnemonic for a BIP84 native segwit wallet. Isn't the Electrum LTC wallet performing the same operations, and hence must have those parameters you seek? What am I missing? You made me curious and I'd be grateful for an explanation (more high level) to understand the issue.

iancoleman commented 6 years ago

@prusnak do you know the p2wpkh parameters for litecoin? (I ask because you provided the p2wpkh-in-p2sh parameters in #125)

The parameters from #125 don't appear in ltc-electrum constants. They come from https://github.com/iancoleman/bip39/issues/125

I looked online at various litecoin projects to find parameters for segwit-parameters.js - bitcoinjs.bitcoin.networks.litecoin.p2wpkh but couldn't find what the values are. My looking-and-finding skills are not good enough.

There are these parameters in litecoin electrum but they're for bitcoin https://github.com/pooler/electrum-ltc/blob/48996679e198dab0839a2613289af8ba250b4f34/lib/constants.py

These are the electrum docs for it but again all bitcoin http://docs.electrum.org/en/latest/xpub_version_bytes.html

I searched the litecoin-project/litecoin repo but couldn't find what I needed.

bip84 for litecoin can be implemented (actually already is implemented as a general p2wpkh feature for all coins but only shows addresses if the coin has p2wpkh parameters). Without the parameters for litecoin-p2wpkh the tool can't base58encode the keys in the correct way.

aleqx commented 6 years ago

Just a small gif showing the Electrum LTC wallet importing a BIP39 seed (generated by your tool) and generating the corresponding BIP84 native segwit wallet: https://i.gyazo.com/0feac207c6fd7e6ada83f86635580248.gif

The params thus must exist somewhere in the Electrum LTC code, right?

I'm sure you'll figure it out ... too many people depend on your tool :)

I can confirm that the above Electrum wallet is a valid native segwit LTC wallet, because I did the same for my own wallet (Coinomi's BIP39 seed) and could see my funds in the native segwit addresses (I had previously upgraded my Coinomi LTC wallet to segwit, and it used native segwit addresses as change addresses).

iancoleman commented 6 years ago

I had a go with importing to electrum-ltc and found that the bitcoin parameters are being used for p2wpkh. I've added those to the tool and will be included in the next release.

See https://github.com/iancoleman/bip39/commit/9369eaa6d56500061c952927691e31cd503ae11c

aleqx commented 6 years ago

Can confirm that master now works and is corrrect. The addresses and private keys of my BIP84 wallet as shown by Electrum LTC (which I have used to send and receive LTC) are the same as the one generated by your tool from the same BIP39 seed.

Great work.