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

Uncaught Error: KeyStore: Invalid mnemonic #182

Open
DalderupMaurice opened this issue Jan 18, 2018 · 9 comments
Open

Uncaught Error: KeyStore: Invalid mnemonic #182

DalderupMaurice opened this issue Jan 18, 2018 · 9 comments

Comments

@DalderupMaurice
Copy link

DalderupMaurice commented Jan 18, 2018

Upgrading from eth-lightwallet 2.5.4 to 3.0.x I am having the issue that I am unable to catch the error whenever a wrong mnemonic is passed to lightwallet.keystore.createVault.

Example:

  lightwallet.keystore.createVault({
    password: password,
    seedPhrase: seed, // Optionally provide a 12-word seed phrase
    hdPathString: "m/44'/60'/0'/0" // Optional custom HD Path String
  }, (err, ks) => {
    // Any code here is NEVER executed when the mnemonic is invalid
    if (err) throw new Error("Wrong password"); // Not triggered on invalid mnemonic
    console.log('test'); // Not triggered on invalid mnemonic
  });

In this example, whenever the password is wrong, the callback does not retrieve an error keystore. It just displays an uncaught error in the console of the browser. I also tried placing a try - catch around it, but it still does not work.

This is the error shown in the browser:

Uncaught Error: KeyStore: Invalid mnemonic
    at KeyStore.init (keystore.js:75)
    at keystore.js:114
    at cb (keystore.js:352)
    at scrypt-async.js:518
    at scrypt-async.js:481
    at run (setImmediate.js:40)
    at runIfPresent (setImmediate.js:69)
    at onGlobalMessage (setImmediate.js:109)
@pdanysz
Copy link

pdanysz commented Mar 1, 2018

I believe there is some kind of problem in:

#FILE: lightwallet.js / Line: 250
KeyStore.prototype.init = function (mnemonic, pwDerivedKey, hdPathString, salt) {
...
    if (!Mnemonic.isValid(mnemonic, Mnemonic.Words.ENGLISH) || words.length !== 12) {
      throw new Error('KeyStore: Invalid mnemonic');
    }

So, I checked and problem probably is on library
var Mnemonic = require('bitcore-mnemonic');

I have my own 12-word seed and it fails anytime. And I used this below, and Validation was OK.
select scout crash enforce riot rival spring whale hollow radar rule sentence

I still try to find where problem is ;/

@pdanysz
Copy link

pdanysz commented Mar 1, 2018

OK, I can confirm that problem is with "12 word seed" , or I'm doing something wrong with the words.

This seed work:

select scout crash enforce riot rival spring whale hollow radar rule sentence

this not:

select scout crash road riot rival spring whale hollow radar rule sentence

I changed enforce => road, and I got error about wrong mnemonic.

@coder5876
Copy link
Contributor

@pdanysz Not every 12 words is a valid mnemonic, the mnemonic contains a checksum, so if you just change one word it will not be a valid mnemonic.

@pdanysz
Copy link

pdanysz commented Mar 12, 2018

@christianlundkvist yes, correct, thank you!

@DalderupMaurice
Copy link
Author

Well, my problem persists. Whenever an invalid password is matched with the given mnemonic, I am unable to catch the error. That was the essence of this topic, not the generation of a mnemonic :)

abhiramhatolkar pushed a commit to abhiramhatolkar/eth-lightwallet that referenced this issue Apr 10, 2018
@abhiramhatolkar
Copy link

abhiramhatolkar commented Apr 10, 2018

Hi @DalderupMaurice , this is due to the fact that init function throws error if invalid mnemonic appears. But that error is not caught by it's calling function viz. createVault function. I have created a pull request for this (#193).

For now, you can import "bitcore-mnemonic" library and prior to calling createVault, you can check if your mnemonic is correct using isValid function of this library.

@DalderupMaurice
Copy link
Author

Thanks man, really appreciate the effort :D

@360disrupt
Copy link

360disrupt commented Sep 7, 2018

@christianlundkvist can you explain this:

Not every 12 words is a valid mnemonic, the mnemonic contains a checksum, so if you just change one word it will not be a valid mnemonic.

So I cannot use any 12 words, is there a schema to follow? Are only certain words allowed, is there a good resource for this?

E.g. can I use any combination of those:
https://gist.github.com/fogleman/c4a1f69f34c7e8a00da8
https://github.com/sindresorhus/mnemonic-words

I'm not getting this explanation:
https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki

EDIT: this library makes it easier:
https://github.com/ggozad/mnemonic.js/tree/master
But I still get invalid mnemonic with the generated seed phrase:
cousin,gun,muscle,radio,total,rhythm,written,built,compare,rip,child,knowledge

@abhiramhatolkar
Copy link

@360disrupt Not any 12 random words make a correct mnemonic (not at least for Ethereum and Bitcoin chains). You can view the wordlist here. Again, you cannot arrange these words randomly yourself to make a valid mnemonic. This has steps to create one. You can visit https://iancoleman.io/bip39/ to generate mnemonic for yourself. Or include this in your codebase to create wallets. Here you can see that eth-lightwallet uses it as well ;)

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

5 participants