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

Recovery using only the first four letters of each word #158

Closed
paulyoung opened this issue Jun 13, 2021 · 1 comment
Closed

Recovery using only the first four letters of each word #158

paulyoung opened this issue Jun 13, 2021 · 1 comment

Comments

@paulyoung
Copy link

Some backup solutions only allow storing the first 4 letters in accordance with the BIP39 protocol.

My understanding is that the first-four-letter combinations are unique and sufficient to recover the full word.

Does this package support that?

It’s something I’m trying to figure out for dfinity/internet-identity#335

@junderw
Copy link
Member

junderw commented Jun 13, 2021

No. This is easily done with 1 line. Maybe a couple extra lines to check inputs.

function findFirstFour(firstFour, wordlist) {
  if (typeof firstFour !== 'string' || firstFour.length !== 4) throw new Error('Need 4 characters')
  if (!Array.isArray(wordlist) || wordlist.length !== 2048 || wordlist[1353] !== 'powder') throw new Error('Use bip39 English wordlist')

  return wordlist.filter(s => s.startsWith(firstFour))[0]
}

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

No branches or pull requests

2 participants