bitcoinjs / bip39

JavaScript implementation of Bitcoin BIP39: Mnemonic code for generating deterministic keys
ISC License
1.11k stars 447 forks source link

Allow matching prefixes of 4 characters #161

Closed hansl closed 3 years ago

hansl commented 3 years ago

BIP-39 specifies that the wordlist should only contains words that are different on their first 4 characters, for all words. This allows to only check the prefixes if the length of a word is 4. Otherwise the behaviour is unchanged.

This does not seem to impact the performance significantly (I noticed less than 1% change in runtime of npm run unit).

junderw commented 3 years ago
  1. That is meant to make it easier to create auto-complete functionality.
  2. Not all wordlists follow 4 letter rule. Some are less or more. Chinese is literally one character per word. etc. So this PR would break for any non-English wordlist.
  3. This is out of scope for this library.
hansl commented 3 years ago

I don't follow #1, and I thought the goal of the library was to comply with BIP39 which allows for matches of 4 characters prefixes. Would it help if I made it an optional argument that defaults to the previous behavior?

junderw commented 3 years ago

The 4 letter thing is not a property of the BIP itself. It is a property of the wordlist for English.

Anyone who wants to implement an auto-complete feature based on that property is free to do it on their own. There is no where in the BIP that states you MUST validate a phrase where all the words are only the first 4 letters.

I thought the goal of the library was to comply with BIP39

This library is BIP39 compliant.