-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·63 lines (47 loc) · 1.63 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
"use strict";
const promptly = require("promptly");
const crypto = require("crypto");
const { ethers } = require("ethers");
const chalk = require("chalk");
const QRCode = require('qrcode');
const helpString = `
ethbrain transforms a passphrase into a valid Ethereum/BSC/Polygon/... wallet.
Options:
-p Show private key in hex format.
-q Show private key QR code.
--help, -h Show help.
Usage example:
ethbrain -p -q #Show private key in hex format and QR code.
`
async function getPass() {
return await promptly.password("Passphrase:", { replace: "*" })
}
async function main() {
let print_private_key = false;
let print_qrcode = false;
if (process.argv.indexOf("-p") !== -1) {
print_private_key = true;
}
if (process.argv.indexOf("-q") !== -1) {
print_qrcode = true;
}
if (process.argv.indexOf("-h") !== -1 || process.argv.indexOf("--help") !== -1) {
console.log(helpString);
process.exit(0);
}
let pass = await getPass();
let priv = "0x" + crypto.createHash("sha256").update(pass).digest("hex");
let wallet = new ethers.Wallet(priv)
console.log(chalk.yellow("Wallet address: ") + chalk.greenBright(wallet.address));
if (print_private_key) {
console.log(chalk.yellow("Private Key: ") + chalk.grey(wallet.privateKey));
} else {
console.log(chalk.yellowBright("Private key not printed. Use -p flag to print it or -h to see all options"));
}
if (print_qrcode) {
console.log(await QRCode.toString(wallet.privateKey, { type: 'terminal' }));
}
console.log("");
}
main();