Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
generateKeyRand() {
if (!this.encryptionKey) {
// KeyContainer not unlocked
console.error('Error: KeyContainer not unlocked');
return undefined;
}
const w = ethWallet.generate();
const privK = w._privKey;
const address = ethUtil.privateToAddress(privK);
const addressHex = utils.bytesToHex(address);
const privKHex = utils.bytesToHex(privK);
const privKHexEncrypted = kcUtils.encrypt(this.encryptionKey, privKHex);
this.db.insert(this.prefix + addressHex, privKHexEncrypted);
return addressHex;
}
function ensureAccounts(personas) {
// Generate missing accounts
for (let persona of personas) {
let wallet
if (accounts[persona] === undefined) {
console.log(persona, 'unknown, generating account...')
wallet = ethwallet.generate()
// keyfileName = wallet.getV3Filename(new Date().getTime())
} else {
wallet = ethwallet.fromV3(JSON.stringify(accounts[persona].keyfile), password)
console.log(persona, `wallet valid (address: ${wallet.getAddressString()})`)
// keyfileName = accounts[persona].keyfileName
}
accounts[persona] = {
address: wallet.getAddressString(),
privkey: wallet.getPrivateKeyString(),
keyfile: JSON.parse(wallet.toV3String(password)),
// keyfileName: persona,
}
}
fs.writeFileSync(path.join(accountDirPath(), 'accounts.json'), JSON.stringify(accounts, null, 4))
// Write keyfiles
function createSignKey() {
const wallet = generate();
return {
privateKey: wallet.privKey,
address: ethUtil.toChecksumAddress(ethUtil.bufferToHex(wallet.getAddress())),
};
}
function makeWallets(): IFullWallet[] {
const wallets: IFullWallet[] = [];
let i = 0;
while (i < derivationRounds) {
const privKeyWallet = generate();
wallets.push(privKeyWallet);
i += 1;
}
return wallets;
}
worker.onmessage = (event: MessageEvent) => {
const info: GenerateParameters = event.data;
const wallet = generate();
const filename = wallet.getV3Filename();
const privateKey = wallet.getPrivateKeyString();
const keystore = wallet.toV3(info.password, { n: info.N_FACTOR });
worker.postMessage({ keystore, filename, privateKey });
};
export const generateETHWallet = (keychain = v4()) => {
const pk = eth.generate();
return {
privateKey: pk.getPrivateKeyString(),
address: pk.getAddressString(),
wid: v4(),
alias: generateRandomPair(curNames.ETH),
type: curNames.ETH,
created: new Date(),
readOnly: false,
balance: 0
};
};
newAccount(passphrase: string, name: string, description: string, chain: string): Promise {
const newAccount = Wallet.generate();
const address = `0x${newAccount.getAddress().toString('hex')}`;
const accountData = {
address,
name,
description,
V3: newAccount.toV3(passphrase),
hidden: false,
hardware: false,
};
this.accounts[chain] = this.accounts[chain] || [];
this.accounts[chain].push(accountData);
return Promise.resolve(address);
}