Ethers.js: Support BIP39 mnemonic for other languages

Created on 5 Jun 2018  ·  7Comments  ·  Source: ethers-io/ethers.js

Hi, I found BIP39 not only have English mnemonic, but also have Chinese and so on.
Could ethers.js support other language mnemonic?
I found current stage only have English mnemonic.
If yes, I will be happy to submit a PR to add this feature. Thanks.

enhancement

Most helpful comment

French and Spanish have been added, so all official wordlists are now fully supported. :)

Thanks! :)

All 7 comments

This cannot be added to the standard package, as the keyword lists are very large and do not compress well, so it would add 3-4Kb for just that one file.

I can make additional packages though which include the other languages, and add support to extend the mnemonic wordlist library. Perhaps something like:

var zh = require('ethers-bip39-zh');
ethers.HDNode.addWordlist(zh);

Would that work for your purposes? I would also include dist files so they can be easily loaded for websites.

Sounds good! Yes, I think it's very useful for me. Thanks.

If you are adventurous, this has been added to the TypeScript branch.

// Simplified
const langZh = require('./src/wordlists/lang-zh').langZhCn;

// ...or Traditional
//const langZh = require('./src/wordlists/lang-zh').langZhTw;

var w = ethers.Wallet.createRandom({ locale: lang });
console.log(w.mnemonic);
// 轻 赏 衰 站 蜡 撑 席 顾 闭 咨 冲 抱

Tha API may change, since this is for the next major version, but for now this will suffice, and change will be minor. :)

There are also dist files for using this in a browser. Just include script tags for any language you would like after including ethers.min.js.

<html>
    <body>
        <script src="dist/ethers.min.js"></script>
        <script src="dist/wordlist-zh.js"></script>
    </body>
</html>

Currently supported

  • English
  • Italian
  • Japanese
  • Korean
  • Simplified Chinese
  • Traditional Chinese

It's Amazing! I can't wait to use the new version.
So I only have to npm install ethers after the new version publish? Or should I have to install other things?

Yupp, after v4 is released, the npm install ethers will be sufficient. All word lists are available in node.

For the browser, we split them out into individual files, since they add about 6-12kb each.

That's cool. Thanks.

French and Spanish have been added, so all official wordlists are now fully supported. :)

Thanks! :)

Was this page helpful?
0 / 5 - 0 ratings