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

Add method for setting the hdpath #107

Merged
merged 11 commits into from
Nov 17, 2021
Merged

Add method for setting the hdpath #107

merged 11 commits into from
Nov 17, 2021

Conversation

danjm
Copy link
Contributor

@danjm danjm commented Nov 8, 2021

Currently, the trezor keyring controller cannot easily have it's hdpath updated. Making it hard to connect wallets on other chains or which were generated with different hdpaths in other wallets. This PR adds a method, the same as the method we have in the ledger keyring, that allows the client to set the hd path after class instantiation.

@danjm danjm requested a review from a team as a code owner November 8, 2021 10:50
index.js Outdated
if (this.hdPath !== hdPath) {
this.hdk = new HDKey()
}
this.hdPath = hdPath
Copy link
Member

Choose a reason for hiding this comment

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

Did you consider resetting the other instance variables? (e.g. account).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 88c1db4

Copy link
Member

Choose a reason for hiding this comment

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

The instance variables paths and unlockedAccount are still not being reset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Fixed in latest commit

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

Could you add unit tests for this? Also a JSDoc comment would be great, as we will be migrating this to our new lint config eventually with requires JSDoc comments for all functions.

A cautionary note might be warranted for this method as well, as this could be an extremely dangerous method. With the Ledger equivalent, we found that calling it with HD paths not supported by Ledger would result in accounts getting generated incorrectly, leaving the user with an account they can't actually sign on behalf of. We never got to the bottom of why that happened, opting instead to stop using it in that manner, but it's a good example of why we should only use this with HD paths that we are confident are supported by Trezor. Thoroughly QA'd.

@danjm
Copy link
Contributor Author

danjm commented Nov 9, 2021

@Gudahtt

I have added tests and a documentation comment.

Also, given the sensitivity of this method, I updated it so that it only allows setting the hdPath to ones that we explicitly allow. The two paths that are currently allowed are the current default path, and the path for ethereum testnets as defined by the Slip-0044 spec. This gives us a path to allowing users to selecting that hdPath, while the default behaviour can still be to use the same (mainnet) hdPath on all networks by default. I am here thinking of addressing this issue: MetaMask/metamask-extension#10450, and also making it easier for us to QA trezor.

index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
@Gudahtt
Copy link
Member

Gudahtt commented Nov 10, 2021

Good idea! Having a list of allowed HD paths makes sense.

danjm and others added 5 commits November 11, 2021 10:53
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@danjm danjm merged commit c6cb014 into main Nov 17, 2021
@danjm danjm deleted the add-setHdPath-method branch November 17, 2021 16:07
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.

2 participants