libwally-core icon indicating copy to clipboard operation
libwally-core copied to clipboard

Add functions to handle unique prefix mnemonics

Open gwillen opened this issue 5 years ago • 3 comments

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

gwillen avatar May 15 '19 21:05 gwillen

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

gwillen avatar May 15 '19 21:05 gwillen

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

greenaddress avatar May 20 '19 17:05 greenaddress

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

instagibbs avatar Jul 16 '19 20:07 instagibbs