以太坊 生成 带有助记词 地址 (eth-lightwallet)web3结合使用

以太坊 生成 带有助记词 地址 (eth-lightwallet)web3结合使用

node.js

npm install eth-lightwallet -S

browserless-eth-lightwallet

eth-lightwallet

const lightwallet = require( eth-lightwallet )
let address =   , // 地址
    privateKey =   , // 私钥
    randomSeed =   , // 助记词
    hdPathString =  m/44 /60 /0 /0 
    // hdPathString =  m/0/0/0 
  lightwallet.keystore.createVault({
    password:  xxxxxxxxxxxxxx<密码> ,
    // seedPhrase: seedPhrase, // Optionally provide a 12-word seed phrase    // 导入 时 这里 可以传入 助记词
    // salt: fixture.salt,     // Optionally provide a salt.
    // A unique salt will be generated otherwise.
     hdPathString: hdPathString   // Optional custom HD Path String
  }, function (err, ks) {
    // Some methods will require providing the `pwDerivedKey`,
    // Allowing you to only decrypt private keys on an as-needed basis.
    // You can generate that value with this convenient method:
    ks.keyFromPassword( xxxxxxxxxxxxxx<密码> , function (err, pwDerivedKey) {
      if (err) throw err
      // generate five new address/private key pairs
      // the corresponding private keys are also encrypted
      ks.generateNewAddress(pwDerivedKey, 1)
      address = ks.getAddresses()[0]
      console.log( 0x +address)  // 地址
      privateKey = ks.exportPrivateKey(address, pwDerivedKey)
      console.log( 0x +privateKey) // 私钥
      randomSeed = ks.getSeed(pwDerivedKey)
      console.log(randomSeed) // 助记词
      // Now set ks as transaction_signer in the hooked web3 provider
      // and you can start using web3 using the keys/addresses in ks!
    })
  })

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
none
暂无评论...