Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Dispose or destroy keyrings on reference drop #233

Merged
merged 7 commits into from
Jun 15, 2023

Conversation

mikesposito
Copy link
Member

@mikesposito mikesposito commented Jun 5, 2023

Description

This PR calls the optional methods destroy and dispose on keyrings that support them (Trezor and Ledger) whenever the reference to the keyring is dropped: when locked and when the last account from a keyring is removed.

To avoid introducing one of the two (Trezor or Ledger) keyrings just to be used on tests, I extended the HDKeyring prototype to also present a destroy and a dispose method, in order to be spied on.

Changes

  • CHANGED: When defined, Keyring.dispose or Keyring.destroy methods are called on any keyring reference drop

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation for new or updated code as appropriate (note: this will usually be JSDoc)
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@mikesposito mikesposito marked this pull request as ready for review June 5, 2023 09:10
@mikesposito mikesposito requested a review from a team as a code owner June 5, 2023 09:10
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.

Looks great! Left a few comments/suggestions

}

if ('destroy' in keyring && typeof keyring.destroy === 'function') {
keyring.destroy();
Copy link
Member

Choose a reason for hiding this comment

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

Between the two names, I'm slightly more inclined to use destroy because we already use this method name for some controllers and middleware.

Perhaps we could align on this name? Not a blocker, but renaming the method on Trezor might be fairly easy (that package had a recent release)

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you suggesting removing the dispose call, then changing the method name on Trezor Keyring after this PR has been merged, or should we do it before this PR?

Copy link
Member

Choose a reason for hiding this comment

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

Either before or after; as long as that change gets included in core and in the clients prior to this one.

But this was a non-blocking suggestion, so whatever you'd prefer to do here is fine

Copy link
Member Author

Choose a reason for hiding this comment

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

@Gudahtt I created this issue to track this work

src/KeyringController.ts Outdated Show resolved Hide resolved
src/KeyringController.test.ts Outdated Show resolved Hide resolved
src/KeyringController.ts Outdated Show resolved Hide resolved
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!

@mikesposito mikesposito merged commit c111e49 into main Jun 15, 2023
@mikesposito mikesposito deleted the feat/dispose-on-keyring-removal branch June 15, 2023 10:42
@Gudahtt Gudahtt mentioned this pull request Jul 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EthKeyringController: call destroy when a keyring reference is dropped
2 participants