Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for abbreviated bip39 mnemonic elements #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mword
Copy link

@mword mword commented Feb 28, 2019

Here's a simple set of changes that allow for the support of 4 (and greater) character bip39 mnemonic elements. It does this by implementing a uft8_strncmp() function that tries to account for utf8 multibyte characters (counting characters encoded in multiple bytes as a single character). Some characters are actually composed of two characters - for example in Hiragana (Japanese) sounds mark characters can be added to a preceding character - in which case only a single character should be counted. In any case, the utf8_strncmp() function should work on the character sets supported by libwally-core as of this PR but might need to be updated of other character sets are added.

One caveat with these changes is that it assumes that wordlist is only intended to handle 4 significant character words. If it's intended to be more general then the number of significant characters should be parameterized.

May resolve #89

@mword mword force-pushed the mikes-support_4_char_mnemonic_words branch from 20f77ef to 3e0a46b Compare April 9, 2019 19:44
@greenaddress
Copy link
Contributor

Rather than changing the current code, I think it would be best if all we did was adding a new function that, provided a 4 characters words, returns the matching full word - then users of wally can easily convert from the short form to the full form.

@mword
Copy link
Author

mword commented Apr 23, 2019

@greenaddress I can see a were a tool to convert short-form to full-form mnemonic strings might be useful but the two step process of 1. converting short-form to full-form string and then 2. doing full word string compares on the full words seems unnecessarily inefficient (as opposed to just 1. doing 4 character compares on any-form mnemonic. Maybe I'm missing something?

Also, with the changes I made, to get a full-form mnemonic string from a short-form string one need only do a mnemonic_to_bytes followed by a mnemonic_from_bytes. In fact, along with cloning wordlist_lookup_word (as wordlist_lookup_abbreviated_word?) I'd probably want to do just that to do the conversion.

Your call.

@mword mword force-pushed the mikes-support_4_char_mnemonic_words branch from 3e0a46b to 3d3c092 Compare May 9, 2019 17:43
@gwillen
Copy link

gwillen commented May 15, 2019

@greenaddress I have a counterproposal -- can we add a "unique_prefix" flag to wordlist_lookup_word, default false, which enables the following behavior: if there is exactly one word in the wordlist with "word" as a prefix, return that word, otherwise fail. (Alternatively this could be a new wordlist_lookup_word_unique_prefix function.) Then add the same flag to mnemonic_to_bytes and pass it through.

This doesn't require any special handling for unicode, doesn't require hardcoding the four-character prefix rule for bip39 wordlists (but works with any correct use of four-letter truncated mnemonics), and generally does exactly what we want with minimal changes.

Fix for utf8 multibyte characters
@mword mword force-pushed the mikes-support_4_char_mnemonic_words branch from 3d3c092 to 58b4f9a Compare July 18, 2019 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support use of abbreviated 4-letter BIP39 words
3 participants