Add functions to handle unique prefix mnemonics#99
Add functions to handle unique prefix mnemonics#99gwillen wants to merge 1 commit intoElementsProject:masterfrom
Conversation
Common practice with bip39 mnemonics is to use unique four-character prefixes of wordlist words. In some cases (e.g. "steel" storage devices) there is not space to store more than four characters. So, enable users to enter unique prefixes instead of whole words.
|
(to avoid duplication, it might actually make sense to change the original interface instead of adding another one, if you like this approach -- but adding an interface is certainly more backwards-compatible. I think making this the main interface should be okay though. It would eliminate the use of bsearch, but as mentioned above, the amount of time this takes should be absolutely negligible, and it should never be getting called in a tight loop anyway.) |
|
concept ack, looking good to add tests IMHO I think the new function approach is preferable here because of backwards compatibility - if it was something we had just added or that we were still iterating a bit on like liquid there'd be a stronger argument to break ABI but not so much in this case and not without leaving the prior function as deprecated but around for a while (which we can still do later if we decide that's the way forward). |
| return found ? found - w->indices + 1u : 0u; | ||
| } | ||
|
|
||
| size_t wordlist_lookup_prefix(const struct words *w, const char *prefix) |
There was a problem hiding this comment.
this breaks with act versus actual/actress/actor/etc mnemonic words, since act prefix matches for 2+ entries.
I think we should restrict the prefix input to length 3 or 4, and if length 3 it must be an exact match.
|
suggested fix and test here: https://github.com/instagibbs/libwally-core/tree/prefix_fix also good to know at least SLIP39 doesn't allow 3 letter words |
Common practice with bip39 mnemonics is to use unique four-character prefixes
of wordlist words. In some cases (e.g. "steel" storage devices) there is not
space to store more than four characters. So, enable users to enter unique
prefixes instead of whole words.
This is an alternative to #91 for fixing #89 . If you like the approach, I can add tests and so forth. Unfortunately I forgot that C doesn't have default parameters, which makes this slightly messier than it would have been in C++. I also couldn't take advantage of bsearch due to the interface, which is slightly annoying but shouldn't be a big deal (wordlists are very short, time to search them should be negligible.)