Page MenuHomePhabricator

[electrum] refactor: introduce a Wordlist class for seed phrases
ClosedPublic

Authored by PiRK on Tue, Jan 21, 14:04.

Details

Summary

This better encapsulates some optimizations (caching of word lists and better indexing) that were made indepedently on Electron Cash and Electrum:

Now the optimizations apply both to the MnemonicElectrum class and the old_mnemonic module.
And in a following commit it will also apply to the slip39 mnemonic code.

This is a backport of https://github.com/spesmilo/electrum/commit/a0b096dcb2292c2826f7beae173c529d335142f0

Note that the solution of putting this new class in the mnemo module does not work for us because this module import old_mnemonic so this would cause a circular import. So I put it in an independant wordlist module that is now imported in mnemo and old_mnemonic.

Depends on D17570

Test Plan

python test_runner.py

Restore a wallet from seed

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Tue, Jan 21, 14:04

no need for the list conversion. In our codebase bip39_list is already a list because we use Trezor's mnemonic library (so we can support multiple languages for restoring seeds) https://github.com/trezor/python-mnemonic/blob/master/src/mnemonic/mnemonic.py#L56

electrum/electrumabc/wordlist.py
108 ↗(On Diff #52325)

note that we index by filename rather than by full path, which is fine as we don't have files with identical names in different paths.

136 ↗(On Diff #52325)

here we have a divergence with Electrum because of https://github.com/Bitcoin-ABC/ElectrumABC/commit/143782b332a34b2ffb6a08d036bce8850a546c41, which explains why we don't derive the full path

This revision is now accepted and ready to land.Tue, Jan 21, 15:34