美文网首页
以太坊 生成 带有助记词 地址 (eth-lightwalle

以太坊 生成 带有助记词 地址 (eth-lightwalle

作者: 徐亮亮2333 | 来源:发表于2018-08-31 13:24 被阅读0次

    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!
        });
      });
    

    相关文章

      网友评论

          本文标题:以太坊 生成 带有助记词 地址 (eth-lightwalle

          本文链接:https://www.haomeiwen.com/subject/ryuswftx.html