2018-01-11 06:44:13 +00:00
|
|
|
import { IFullWallet, fromPrivateKey } from 'ethereumjs-wallet';
|
|
|
|
import { toBuffer } from 'ethereumjs-util';
|
2018-02-02 06:01:30 +00:00
|
|
|
import Worker from 'worker-loader!./workers/fromV3.worker.ts';
|
2018-01-11 06:44:13 +00:00
|
|
|
|
2018-02-02 06:01:30 +00:00
|
|
|
export default function fromV3(
|
2018-01-11 06:44:13 +00:00
|
|
|
keystore: string,
|
|
|
|
password: string,
|
|
|
|
nonStrict: boolean
|
2018-02-02 06:01:30 +00:00
|
|
|
): Promise<IFullWallet> {
|
2018-01-11 06:44:13 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2018-02-02 06:01:30 +00:00
|
|
|
const worker = new Worker();
|
|
|
|
worker.postMessage({ keystore, password, nonStrict });
|
|
|
|
worker.onmessage = (ev: MessageEvent) => {
|
|
|
|
const data = ev.data;
|
2018-01-11 06:44:13 +00:00
|
|
|
try {
|
|
|
|
const wallet = fromPrivateKey(toBuffer(data));
|
|
|
|
resolve(wallet);
|
|
|
|
} catch (e) {
|
|
|
|
reject(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2018-02-02 06:01:30 +00:00
|
|
|
}
|