MyCrypto/common/libs/web-workers/workers/generateKeystore.worker.ts
William O'Beirne 174dea8a29 MEW-01-004 - Stronger Keystores (#981)
* Add better password checking, confirm password, feedback, and up the minimum to 12.

* Move wallet generation off to a web worker, and bump up the n value to 8192. Refactor workers a wee bit.

* tscheck cleanup

* Make keystore password a form. Replace text with spinner on load.

* Center align again.

* Hard code n factor of test wallet, fix some misspelled type definitions for IV3Wallet.
2018-02-02 00:01:30 -06:00

20 lines
615 B
TypeScript

import { generate } from 'ethereumjs-wallet';
import { toChecksumAddress } from 'ethereumjs-util';
const worker: Worker = self as any;
interface GenerateParameters {
password: string;
N_FACTOR: number;
}
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 });
keystore.address = toChecksumAddress(keystore.address);
worker.postMessage({ keystore, filename, privateKey });
};