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

create random accounts in memory for onboarding #1464

Merged
merged 15 commits into from
Jun 26, 2019
Merged

Conversation

gravityblast
Copy link
Member

@gravityblast gravityblast commented May 16, 2019

Implementation of Onboarding Generate 5 accounts and store one with the password.

closes #1491

Important changes:

  • Add NewOnboarding method to account.Manager
  • Add ImportOnboardingAccount to account.Manager
  • Add ResetOnboarding to account.Manager
  • Add NewOnboarding to lib and mobile
  • Add ImportOnboardingAccount to lib and mobile
  • Add ResetOnboarding to lib and mobile
  • Reset onboarding on Login in case it has been started previously
  • increase version number

Closes #1456

@status-github-bot
Copy link

status-github-bot bot commented May 16, 2019

Pull Request Checklist

  • Have you updated the documentation, if impacted (e.g. docs.status.im)?

@status-im-auto
Copy link
Member

status-im-auto commented May 16, 2019

Jenkins Builds

Click to see older builds (45)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 9d7ba55 #1 2019-05-16 09:47:48 ~54 sec linux 📦 zip
✔️ 9d7ba55 #1 2019-05-16 09:50:26 ~3 min ios 📦 zip
✔️ 9d7ba55 #1 2019-05-16 09:53:28 ~6 min android 📦 aar
✔️ 6893135 #2 2019-05-16 09:55:45 ~29 sec linux 📦 zip
✔️ 6893135 #2 2019-05-16 09:59:02 ~3 min ios 📦 zip
✔️ 6893135 #2 2019-05-16 10:00:33 ~5 min android 📦 aar
✔️ 1a06d1e #3 2019-05-16 10:01:33 ~52 sec linux 📦 zip
✔️ 1a06d1e #3 2019-05-16 10:03:37 ~2 min ios 📦 zip
✔️ 1a06d1e #3 2019-05-16 10:06:02 ~5 min android 📦 aar
✔️ 4e7346a #4 2019-05-16 10:26:34 ~35 sec linux 📦 zip
✔️ 4e7346a #4 2019-05-16 10:28:56 ~2 min ios 📦 zip
✔️ 4e7346a #4 2019-05-16 10:31:16 ~5 min android 📦 aar
✔️ bea0ac3 #5 2019-05-16 10:50:47 ~31 sec linux 📦 zip
✔️ bea0ac3 #5 2019-05-16 10:53:20 ~3 min ios 📦 zip
✔️ bea0ac3 #5 2019-05-16 10:55:54 ~5 min android 📦 aar
487110c #6 2019-06-11 12:55:13 ~16 sec ios 📄 log
6e011e7 #7 2019-06-11 12:55:38 ~8.9 sec ios 📄 log
6e011e7 #7 2019-06-11 13:16:33 ~10 min android 📄 log
6e011e7 #7 2019-06-11 13:17:13 ~11 min linux 📄 log
6e011e7 #8 2019-06-11 13:30:25 ~11 sec ios 📄 log
✔️ 881bbe7 #8 2019-06-12 11:35:46 ~1 min linux 📦 zip
✔️ 881bbe7 #9 2019-06-12 11:38:16 ~3 min ios 📦 zip
✔️ 881bbe7 #8 2019-06-12 11:41:15 ~6 min android 📦 aar
✔️ 7188e7f #9 2019-06-26 10:18:59 ~47 sec linux 📦 zip
✔️ 7188e7f #10 2019-06-26 10:22:13 ~4 min ios 📦 zip
✔️ 7188e7f #9 2019-06-26 10:24:21 ~6 min android 📦 aar
✔️ 4e3a1b0 #10 2019-06-26 10:21:34 ~41 sec linux 📦 zip
✔️ 4e3a1b0 #11 2019-06-26 10:24:39 ~36 sec linux 📦 zip
✔️ 4e3a1b0 #11 2019-06-26 10:24:46 ~2 min ios 📦 zip
✔️ 4e3a1b0 #12 2019-06-26 10:27:26 ~2 min ios 📦 zip
✔️ 4e3a1b0 #10 2019-06-26 10:29:52 ~5 min android 📦 aar
07a0989 #13 2019-06-26 13:55:58 ~32 sec ios 📄 log
✔️ 07a0989 #12 2019-06-26 13:56:12 ~45 sec linux 📦 zip
07a0989 #11 2019-06-26 13:56:44 ~1 min android 📄 log
✔️ da5466c #13 2019-06-26 17:41:06 ~40 sec linux 📦 zip
✔️ da5466c #14 2019-06-26 17:42:54 ~2 min ios 📦 zip
✔️ da5466c #12 2019-06-26 17:45:48 ~5 min android 📦 aar
✔️ 51c5fb9 #14 2019-06-26 18:05:59 ~38 sec linux 📦 zip
✔️ 51c5fb9 #15 2019-06-26 18:07:56 ~2 min ios 📦 zip
✔️ 51c5fb9 #13 2019-06-26 18:10:39 ~5 min android 📦 aar
✔️ 5974f0e #15 2019-06-26 21:36:34 ~35 sec linux 📦 zip
✔️ 5974f0e #16 2019-06-26 21:38:24 ~2 min ios 📦 zip
✔️ 5974f0e #14 2019-06-26 21:41:35 ~5 min android 📦 aar
✔️ b238cfe #16 2019-06-26 21:38:40 ~41 sec linux 📦 zip
✔️ b238cfe #17 2019-06-26 21:41:28 ~3 min ios 📦 zip
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 25bd8ab #17 2019-06-26 21:40:15 ~32 sec linux 📦 zip
✔️ 25bd8ab #18 2019-06-26 21:44:07 ~2 min ios 📦 zip
✔️ 25bd8ab #15 2019-06-26 21:47:05 ~5 min android 📦 aar
✔️ d891c7c #18 2019-06-26 22:05:55 ~58 sec linux 📦 zip
✔️ d891c7c #19 2019-06-26 22:07:26 ~2 min ios 📦 zip
✔️ d891c7c #16 2019-06-26 22:10:04 ~5 min android 📦 aar

@gravityblast
Copy link
Member Author

@flexsurfer @siphiuel
I added 2 new functions in lib and mobile. You can call NewOnboarding(accountsCount, mnemonicPhraseLength int) when you start the onboarding, and ImportOnboardingAccount(id string, password string) to select one and import it.

We still need to finish and merge this PR but you can start using the artifact you can find in CI.
Please let me know if you start testing it and you have have any feedback.

@gravityblast
Copy link
Member Author

@flexsurfer @siphiuel did you have time to try it? Just to understand if the API is fine for status-react so that I can continue with this and start the reviews.

@gravityblast
Copy link
Member Author

gravityblast commented May 27, 2019

hey @flexsurfer @siphiuel @hesterbruikman @guylouis
any news on this feature? just to understand if the API is good and if it makes sense to merge it, thank you!

@vitvly
Copy link
Contributor

vitvly commented May 27, 2019

@gravityblast sorry for delayed response. Yes the API is good, I'm integrating it now into the setup flow.

@gravityblast
Copy link
Member Author

awesome! no problem thank you @siphiuel !!

@@ -365,6 +370,53 @@ func (m *Manager) Accounts() ([]gethcommon.Address, error) {
return filtered, nil
}

// NewOnboarding starts the onboarding process generating accountsCount accounts and returns a slice of OnboardingAccount.
func (m *Manager) NewOnboarding(accountsCount, mnemonicPhraseLength int) ([]*OnboardingAccount, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to do:

Suggested change
func (m *Manager) NewOnboarding(accountsCount, mnemonicPhraseLength int) ([]*OnboardingAccount, error) {
func (m *Manager) SetOnboarding(onboarding *Onboarding) {


m.onboarding = onboarding

return m.onboarding.Accounts(), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

It's odd that NewOnboarding returns accounts.

}

// ResetOnboarding reset the current onboarding struct setting it to nil and deleting the accounts from memory.
func (m *Manager) ResetOnboarding() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (m *Manager) ResetOnboarding() {
func (m *Manager) RemoveOnboarding() {

because reset suggest that this object is still available just its state got reset.


// ImportOnboardingAccount imports the account specified by id and encrypts it with password.
func (m *Manager) ImportOnboardingAccount(id string, password string) (Info, string, error) {
m.mu.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

In order to avoid repeating Info{} you can do var info Info{} at the top and return info.

}

for i := 0; i < n; i++ {
account, err := onboarding.generateAccount(mnemonicPhraseLength)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think generateAccount could assign an ID.


// Accounts return the list of OnboardingAccount generated.
func (o *Onboarding) Accounts() []*OnboardingAccount {
accounts := make([]*OnboardingAccount, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
accounts := make([]*OnboardingAccount, 0)
accounts := make([]*OnboardingAccount, len(o.accounts))

Copy link
Member Author

Choose a reason for hiding this comment

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

@adambabik I put it back as it was. I forgot I was transforming from hash to slice, so there wasn't a clean way to get the index.


func mnemonicPhraseLengthToEntropyStrenght(length int) (extkeys.EntropyStrength, error) {
if length < 12 || length > 24 || length%3 != 0 {
return 0, errInvalidMnemonicPhraseLength
Copy link
Contributor

Choose a reason for hiding this comment

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

This error is finally returned to the caller so it should be exported. In the description of this error, there should be information when a mnemonic is valid.

expectedStrength extkeys.EntropyStrength
expectedError error
}{
{12, 128, nil},
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommend https://golang.org/pkg/testing/quick/ for this test.

@gravityblast
Copy link
Member Author

thank you for the review @adambabik !
I updated the code, the only thing I have't change is the test where we could use the quick package,
I think I'll refactor it later in the multi-account PR to do it better if it's good for you.

@gravityblast
Copy link
Member Author

@adambabik there's a warning from code climate becuase we have duplicate code in lib and mobile, but I think it's better to keep it like this for now. Is that blocking the merge?

Copy link
Contributor

@adambabik adambabik left a comment

Choose a reason for hiding this comment

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

One last question -- do we want to rely on bindings or move to JSON-RPC?

return info, "", err
}

m.onboarding = nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we reset it?

Copy link
Member Author

Choose a reason for hiding this comment

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

@adambabik just to remove everything related to the keys and the keys themselves

errString = err.Error()
}

out := struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion it's a bit confusing. I would declare out at the top of the function and if an error is detected, I would do out.Error = errString.

Finally, it would be something like this:

out := struct {
    // ...
}

if err != nil {
    fmt.Fprintln(os.Stderr, err)
    out.Error = errString
} else {
    for _, account := range accounts {
      // ...
    }
}

outBytes, _ := json.Marshal(out)
return C.CString(string(outBytes))

Copy link
Member Author

Choose a reason for hiding this comment

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

thank you @adambabik , it makes sense, I updated the code

@gravityblast gravityblast changed the title [WIP] create random accounts in memory for onboarding create random accounts in memory for onboarding Jun 26, 2019
@gravityblast gravityblast removed the request for review from pedropombeiro June 26, 2019 13:40
@gravityblast
Copy link
Member Author

One last question -- do we want to rely on bindings or move to JSON-RPC?

@adambabik , yes I'm migrating the account management to rpc call in the multi-account PR, still WIP but if you want you can start taking a look here:

#1500

@gravityblast
Copy link
Member Author

@siphiuel I'm merging it!

@gravityblast gravityblast merged commit dd17860 into develop Jun 26, 2019
@delete-merged-branch delete-merged-branch bot deleted the onboarding branch June 26, 2019 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants