How to use the readline-sync.questionNewPassword function in readline-sync

To help you get started, we’ve selected a few readline-sync examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PolymathNetwork / polymath-core / CLI / commands / common / global.js View on Github external
hideEchoBack: true // The typed text on screen is hidden by `*` (default).
    });
    try {
      return web3.eth.accounts.decrypt(keyStore, password);
    } catch (error) {
      console.log(chalk.red('Could not decrypt your key store. Probably your password is wrong, please try again.'));
      return getAccount(filePath);
    }
  } else {
    let privKey = readlineSync.question('Enter your private key to generate your key store file: ', {
      hideEchoBack: true // The typed text on screen is hidden by `*` (default).
    });
    if (privKey.substr(0, 2) !== '0x') {
      privKey = '0x' + privKey;
    }
    const password = readlineSync.questionNewPassword(
      'Enter a password to encrypt your private key: ',
      { confirmMessage: 'Enter the same password to confirm: ', min: 6 }
    );
    const keyStore = web3.eth.accounts.encrypt(privKey, password);
    fs.writeFileSync(filePath, JSON.stringify(keyStore));
    return getAccount(filePath);
  }
}