Ethers.js: Discussion: Can I actually generate mnemonic using ethers itself

Created on 26 Jan 2018  路  5Comments  路  Source: ethers-io/ethers.js

I checked hdnode.js code, and found wordlist (through it small), can I actually use ethers to generate mnemonics?
Basically I have input where I can set mnemonic now, but I plan to add generate button, to put fresh generated mnemonics in that field also, to make in functional in two ways.
The question is can I actually generate mnemonic using ethers itself?
I know, there many libraries just to generate mnemonics, but I don't like extra dependencies in the project, there for I need to actually check new library source before using it.
So, could you give suggestion how to use ethers to generate mnemonic, and is it good idea in the first place? Also, in case thats a bad idea, mb you can recommend some libraries for mnemonics generations...

discussion

Most helpful comment

I'm working on a new feature described in https://github.com/ethers-io/ethers.js/issues/47 right now, which should be ready soon, but in the meantime you can use:

mainnet> var mnemonic = ethers.HDNode.entropyToMnemonic(ethers.utils.randomBytes(16))
mainnet> wallet = new ethers.Wallet.fromMnemonic(mnemonic);
Wallet {
  privateKey: '0xa3ac6c8f0768f583d414c1dd818543f816c6eb3921a292e76e79f418bf929cd7',
  provider: [Getter/Setter],
  defaultGasLimit: [Getter/Setter],
  address: '0x47339cEebC2cCCEB05D2E0f17eF20489f4D06835',
  sign: [Function],
  mnemonic: 'clown pig outdoor bulb exist only then wrist brand copper nuclear ranch',
  path: 'm/44\'/60\'/0\'/0/0' }

Once I'm done the above issue, Wallet.createWallet will create wallets with a mnemonic.

All 5 comments

I'm working on a new feature described in https://github.com/ethers-io/ethers.js/issues/47 right now, which should be ready soon, but in the meantime you can use:

mainnet> var mnemonic = ethers.HDNode.entropyToMnemonic(ethers.utils.randomBytes(16))
mainnet> wallet = new ethers.Wallet.fromMnemonic(mnemonic);
Wallet {
  privateKey: '0xa3ac6c8f0768f583d414c1dd818543f816c6eb3921a292e76e79f418bf929cd7',
  provider: [Getter/Setter],
  defaultGasLimit: [Getter/Setter],
  address: '0x47339cEebC2cCCEB05D2E0f17eF20489f4D06835',
  sign: [Function],
  mnemonic: 'clown pig outdoor bulb exist only then wrist brand copper nuclear ranch',
  path: 'm/44\'/60\'/0\'/0/0' }

Once I'm done the above issue, Wallet.createWallet will create wallets with a mnemonic.

And in your UI, you can of course, just use the first line to generate and show the mnemonic, and create the wallet once they have signed off on it (backed it up or whatever your UI enforces).

Actually, as I implement this, I see createWallet already generates a BIP39 + BIP32 + BIP44 wallet, it just doesn't store it in the encrypted Secret Storage JSON, which is what I'm adding now.

So, you could just create a random wallet and use wallet.mnemonic to the user.

So, you could just create a random wallet and use wallet.mnemonic to the user.

Woh, thats sounds cool.
I made secret saving in secret storage functionality myself (nothing hard here), but yes its hardcoded to musicoin, now.

In case its interesting, after all I decided not to use mnemonic field for mnemonic wallet creation, but just ask for password to store wallet in Secret Storage. But show automatically generated mnemonic at the end, if creation was successful, and ask user to save mnemonic in the safe place.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dagogodboss picture dagogodboss  路  3Comments

jochenonline picture jochenonline  路  3Comments

crazyrabbitLTC picture crazyrabbitLTC  路  3Comments

thegostep picture thegostep  路  3Comments

thegostep picture thegostep  路  3Comments