Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web Worker Decrypt #680

Merged
merged 12 commits into from
Jan 11, 2018
Merged

Web Worker Decrypt #680

merged 12 commits into from
Jan 11, 2018

Conversation

aitrean
Copy link
Contributor

@aitrean aitrean commented Dec 28, 2017

Closes MyEtherWallet/MyEtherWallet#423, MyEtherWallet/MyEtherWallet#219

This PR includes three solutions.

  1. Attempt an empty password every time a keystore is uploaded.
  2. Delegate scrypt decryption (ie ethereumjs-wallet.fromV3) to its own web worker and interface with it through an async typescript function that gets handled in the wallet saga. This keeps the UI unblocked when scrypt takes a long time to decrypt.
  3. Add logic to show a spinner x number of milliseconds after file upload so the user will understand when a wallet is being decrypted.

onChange(value: KeystoreValue): void;
onUnlock(): void;
};

public render() {
const { file, password } = this.props.value;
const isWalletLoading = this.props.isWalletLoading;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not de-structure?

@dternyak
Copy link
Contributor

Impressive work! Going to leave it open a bit more and solicit feedback from @HenryNguyen5 and @wbobeirne who participated in design.

@dternyak
Copy link
Contributor

Here's an encrypted Keystore with no password for testing purposes:
UTC--2017-12-30T16-45-58.340Z--80965bfdbb6c44c8ed652add058bf372e2b9dc86.zip

nonStrict: boolean;
}

onmessage = event => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

event could use typing

Copy link
Contributor

@wbobeirne wbobeirne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some minor code feedback, but the experience is a little weird for me. It pops up with a password prompt, but then continues to unlock the wallet:

no-pw-unlock

package.json Outdated
@@ -110,7 +110,8 @@
"webpack": "3.10.0",
"webpack-dev-middleware": "2.0.3",
"webpack-hot-middleware": "2.21.0",
"webpack-sources": "1.0.1"
"webpack-sources": "1.0.1",
"worker-loader": "^1.1.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lock down version # (We try to avoid ^ versions to keep builds consistent.)

@@ -0,0 +1,22 @@
import { IFullWallet, fromPrivateKey } from 'ethereumjs-wallet';
import { toBuffer } from 'ethereumjs-util';
const Worker = require('worker-loader!./workers/scrypt-worker.worker.ts');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should setup typing for this, as outlined here: https://github.com/webpack-contrib/worker-loader#integrating-with-typescript. Right now it's an implicit any.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still typed as any, but

import Worker from 'worker-loader!./workers/scrypt-worker.worker.ts';

seems to fix it!

@@ -43,6 +43,13 @@ export function setWallet(value: IWallet): types.SetWalletAction {
};
}

export function setWalletLoading(loadingStatus: boolean): types.SetWalletLoadingAction {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing nomenclature would be setWalletPending

@@ -57,6 +60,7 @@ export default class KeystoreDecrypt extends Component {
type="password"
/>
</div>
{isWalletLoading ? <Spinner /> : ''}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but you can simplify these boolean checks to {isWalletLoading && <Spinner />}

@@ -0,0 +1,18 @@
import { fromV3, IFullWallet } from 'ethereumjs-wallet';

declare var postMessage: any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://github.com/webpack-contrib/worker-loader#integrating-with-typescript:

const ctx: Worker = self as any;
ctx.postMessage({ foo: "foo" });

for typing

@@ -141,18 +146,43 @@ export function* unlockPrivateKey(action: UnlockPrivateKeyAction): SagaIterator
yield put(setWallet(wallet));
}

export function* startLoadingSpinner(): SagaIterator {
yield call(delay, 1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably shorten this to 300-500, a full second before having the site respond is a little long.

wbobeirne
wbobeirne previously approved these changes Jan 10, 2018
Copy link
Contributor

@wbobeirne wbobeirne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User experience feeling much better. I just had one note about typing, if you can get that change in this all looks good to me!

@dternyak dternyak changed the title Attempt empty pass, implement decryption web workers Decrypt via Web Workers Jan 11, 2018
@dternyak dternyak changed the title Decrypt via Web Workers Web Worker Decrypt Jan 11, 2018
@dternyak dternyak merged commit af2e0b6 into MyCryptoHQ:develop Jan 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants