Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getDecryptedKeystore(password?: string): EthereumjsWallet {
if (this.keystore instanceof EthereumjsWallet) {
return this.keystore
}
if (isUndefined(password)) {
password = window.prompt(`Enter password for Ethereum account ${this.getAddress()}`)
}
if (!isString(password)) {
throw new Error(`Invalid password of type ${typeof password}`)
}
return EthereumjsWallet.fromV3(this.keystore, password, true)
}
const UtcWallet = (keystore, password) => fromV3(keystore, password, true);
function fromKeystore(keystore, pw) {
if (!pw)
throw new Error('Keystore requires password.');
if (_.isObject(keystore))
keystore = JSON.stringify(keystore);
const wallet = ethwallet.fromV3(keystore, pw, true);
return ethjs.bufferToHex(wallet.getPrivateKey());
}
static fromV3(input, password) {
return Wallet.fromV3(input, password);
}
if (!importedKey) {
throw new Error('Cannot import an empty key.');
}
const prefixed = ethUtil.addHexPrefix(importedKey);
if (!ethUtil.isValidPrivate(ethUtil.toBuffer(prefixed))) {
throw new Error('Cannot import invalid private key.');
}
privateKey = ethUtil.stripHexPrefix(prefixed);
break;
case 'json':
let wallet;
const [input, password] = args;
try {
wallet = importers.fromEtherWallet(input, password);
} catch (e) {
wallet = wallet || Wallet.fromV3(input, password, true);
}
privateKey = ethUtil.bufferToHex(wallet.getPrivateKey());
break;
}
const newKeyring = await privates.get(this).keyring.addNewKeyring(KeyringTypes.simple, [privateKey]);
const accounts = await newKeyring.getAccounts();
const allAccounts = await privates.get(this).keyring.getAccounts();
preferences.updateIdentities(allAccounts);
preferences.update({ selectedAddress: accounts[0] });
return this.fullUpdate();
}
require('babel-register');
require('babel-polyfill');
const WalletProvider = require("truffle-wallet-provider");
const keystore = require('fs').readFileSync('./UTC--2018-01-26T17-50-04Z--074bf411-7666-c662-f1a0-d6a93f5d8719').toString();
const pass = require('fs').readFileSync('./password1.txt').toString();
const wallet = require('ethereumjs-wallet').fromV3(keystore, pass);
const config = {
networks: {
development: {
host: 'localhost',
port: 8545,
gas: 15e6,
gasPrice: 0x01,
network_id: '*',
},
ropsten: {
provider: new WalletProvider(wallet, "https://ropsten.infura.io/"),
network_id: 3,
gas: 4.5e6,
gasPrice: 0x50,
},
export function decryptUtcKeystoreToPkey (keystore, password)
{
return fromV3(keystore, password, true).getPrivateKey();
}
private runtimeKeystoreCheck(): boolean {
const { wallet, password, secretKey } = this.state;
if (wallet) {
const keystore = wallet.toV3(password, { n: N_FACTOR });
const backToWallet = fromV3(keystore, password, true);
if (stripHexPrefix(backToWallet.getPrivateKeyString()) === secretKey) {
return true;
}
}
return false;
}