react-native-bip39种子短语生成语言

时间:2019-09-13 03:23:03

标签: react-native

我在wordlist文件夹中添加了简体中文和繁体中文的json,如何告诉它生成具有特定语言的种子短语?

https://github.com/novalabio/react-native-bip39

_generate12SeedPhase = async(callback) => { 
await bip39.generateMnemonic().then((mnemonic)=>{
  callback(mnemonic); // output is other language i want
});

}

1 个答案:

答案 0 :(得分:1)

将json文件放入变量中,然后将其放入函数参数中。

var DEFAULT_WORDLIST = require('./wordlists/cn.json')

_generate12SeedPhase = async(callback) => { 
await bip39.generateMnemonic(undefined, undefined,DEFAULT_WORDLIST).then((mnemonic)=>{
  callback(mnemonic); // output is other language i want

react-native-bip39中的generateMnemonic函数

function generateMnemonic(strength, rng, wordlist) {
  return new Promise((resolve, reject) => {
    strength = strength || 128
    rng = rng || randomBytes

    rng(strength / 8, (error, randomBytesBuffer) => {
      if (error) {
        reject(error)
      } else {
        resolve(entropyToMnemonic(randomBytesBuffer.toString('hex'), wordlist))
      }
    })
  })
}