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

feat: import wallet account via mnemonic #233

Merged
merged 1 commit into from Jul 25, 2021

Conversation

emizzle
Copy link

@emizzle emizzle commented Jul 22, 2021

Closes: #224.

Allows a user to import a wallet account via 12-word mnemonic seed.

The account is first imported in the account generator. Then a wallet account is derived at the root wallet path (m/44'/60’/0’/0/0) from the master key of the mnemonic. This account is then stored in the Accounts table of the user’s db.

@@ -190,6 +190,49 @@ proc addWalletPrivateKey*(name: string, privateKey: string, password: string)
trace "task sent event to host", event=eventEnc, task
asyncSpawn chanSendToHost.send(eventEnc.safe)

proc addWalletSeed*(name: string, mnemonic: string, password: string,
Copy link
Member

Choose a reason for hiding this comment

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

Styling: consider removing superfluous string type specifiers

Copy link
Contributor

Choose a reason for hiding this comment

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

Like this?

proc addWalletSeed*(name, mnemonic, password, bip39Passphrase: string)

Copy link
Member

Choose a reason for hiding this comment

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

Yes!

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, I just wanted to make sure I understood you correctly. I often forget to take advantage of that shortcut, thanks for the tip!

Copy link
Member

Choose a reason for hiding this comment

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

I myself noticed it in other parts of @emizzle 's code, so all kudos are his :) Didn't think it's possible in Nim.

Copy link
Author

Choose a reason for hiding this comment

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

After trying to make this change, I remember now why I didn't do this perviously for tasks. When combining same-typed parameters in the signature of a task proc, the compiler barfs with this error:

/Users/emizzle/repos/status-im/nim-status/examples/chat/client/tasks.nim(193, 37) Error: initialization not allowed here

I really don't know why, but I'm assuming it has something to do with the task macro.


let
walletAccount = walletAccountResult.get
walletName = if walletAccount.name.isNone: "" else: walletAccount.name.get
Copy link
Member

Choose a reason for hiding this comment

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

There is an overloaded Option.get with a default parameter: https://nim-lang.org/docs/options.html#get,Option[T],T

Copy link
Author

@emizzle emizzle Jul 23, 2021

Choose a reason for hiding this comment

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

This is awesome, great look! Updated.

Copy link
Member

@vitvly vitvly left a comment

Choose a reason for hiding this comment

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

Nice!

Closes: #224.

Allows a user to import a wallet account via 12-word mnemonic seed.

The account is first imported in the account generator. Then a wallet account is derived at the root wallet path (m/44'/60’/0’/0/0) from the master key of the mnemonic. This account is then stored in the Accounts table of the user’s db.
@emizzle emizzle force-pushed the feat/import-wallet-mnemonic branch from ff3eb50 to 5c49188 Compare July 23, 2021 07:03
@emizzle emizzle merged commit dde6957 into master Jul 25, 2021
@emizzle emizzle deleted the feat/import-wallet-mnemonic branch July 25, 2021 06:55
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.

Generate new wallet account given mnemonic
3 participants