pontus-x_cli
Version:
Command Line Interface for the Pontus-X Data Space Ecosystem.
27 lines • 1.67 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.exportKeyAsJson = exportKeyAsJson;
const fs_1 = __importDefault(require("fs"));
const readline_sync_1 = __importDefault(require("readline-sync"));
const ethereumjs_wallet_1 = __importDefault(require("ethereumjs-wallet"));
function exportKeyAsJson() {
const pk = readline_sync_1.default.question('\nExporting your private key as a JSON file... \n' +
'First, get a copy of your private key from Metamask.\n' +
'\t 1.) On the upper right menu, select "Account details", then "Show private key". \n' +
'\t 2.) After providing your MetaMask password and revealing, click the button to copy it. \n' +
'\t 3.) Then, please, paste your private key here: ', { hideEchoBack: true });
const pkBuffer = Buffer.from(pk, 'hex');
const account = ethereumjs_wallet_1.default.fromPrivateKey(pkBuffer);
const password = readline_sync_1.default.question('Finally, to securely store your private key, please, enter a password to encrypt it: ', { hideEchoBack: true });
const address = account.getAddress().toString('hex');
console.log(`Generating encrypted file to store your private key, which corresponds to you account ${address}`);
account.toV3(password).then(value => {
const file = `${address}.json`;
fs_1.default.writeFileSync(file, JSON.stringify(value));
console.log(`Your encrypted private key has been saved to ${file}\n`);
});
}
//# sourceMappingURL=index.js.map