mycelium-com / wallet-android

Mycelium Bitcoin Wallet for Android
http://mycelium.com
Other
658 stars 319 forks source link

App fails to decode SegWit BIP38 #581

Closed ValleZ closed 3 years ago

ValleZ commented 3 years ago

When you feed BIP38 encrypted private key 6PYU3LqtkXznTNiyvHw6ZRinCoaAKVF2k1Pfe9bHC1sATDNe6uzH3MLj7Z with password 123 Mycelium app says that password is incorrect. In fact the password is correct and the key corresponds to bc1qx9plqn4kqsmnuj0ek52xhp2cscejmg2ukvn7s4 address.

It fails to decode because this line has hardcoded address type to P2PKH while in fact it is P2WPKH:

https://github.com/mycelium-com/wallet-android/blob/7cd091508e2b70b52adc7548e067a1cedd61b63e/bitlib/src/main/java/com/mrd/bitlib/crypto/Bip38.java#L377

Giszmo commented 3 years ago

Thank you for your detailed and actionable report! We will look into it.

Giszmo commented 3 years ago

I implemented a fix and it will be released soon.

Screenshot from 2021-01-23 14-25-17

Giszmo commented 3 years ago

May I ask where you have this test vector from? Mycelium does not encrypt this way as the private key is agnostic to the addresses derived from it and we allow all three supported address types, we never changed the backup to use anything but P2PKH for the salt. It makes no sense to have 3 backups for the same private key.

ValleZ commented 3 years ago

Thanks for updating it! I generated key in my app https://play.google.com/store/apps/details?id=ru.valle.btc&hl=en_US&gl=US