以太坊 生成 带有助记词 地址 (eth-lightwallet)与 web3.js 创建的 完全匹配

node.js https://nodejs.org/en/

npm install eth-lightwallet

https://www.npmjs.com/package/browserless-eth-lightwallet

https://github.com/ConsenSys/eth-lightwallet


let 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!
    });
  });
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1 Node.js安装与配置 1.1 Windows平台下的Node.js安装 在过去,Node.js一直不支持在...
    七寸知架构阅读 4,071评论 0 50
  • 大家好,我是IT修真院深圳分院第3期的学员,一枚正直纯洁善良的前端程序员,今天给大家分享一下,修真院官网前端工程师...
    大大头大阅读 3,078评论 0 1
  • 1、 阿尔泰山山系,天山以北最美的地方。置身于广褒雄浑的阿尔泰山下,看那大片的草原一直伸向山脚,状若棉絮的白云与山...
    清萩阅读 2,756评论 0 1
  • 最近索儿总是眉头紧锁,闷闷不乐的样子,每天坐在办公室,好像总是没有办法打起精神来一样,于是我跑去问她到底发生什么事...
    鯊魚小姐阅读 387评论 8 16
  • “王你想怎样,才能放过他们” “只要你留下,嫁我为妃,我立刻放他们走” “好,我留下,嫁给你” “你们走吧,不要惦...
    YC瞳孔中只有那凉的记忆阅读 207评论 0 0

友情链接更多精彩内容