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 types for store and fix type discrepancies #247

Merged
merged 8 commits into from
Jul 18, 2023
Merged

Conversation

mikesposito
Copy link
Member

@mikesposito mikesposito commented Jul 17, 2023

Description

This PR updates obs-store to @metamask/obs-store and fixes some type discrepancies with the actual states

Changes

  • BREAKING: constructor opts KeyringControllerArgs properties types changed
    • Simplified type for keyringBuilders, now is an optional { (): Keyring<Json>; type: string }[]
    • initState now accepts only an optional persistent state, of type KeyringControllerPersistentState
  • BREAKING: type of store and memStore public properties changed
    • KeyringController.store is now an ObservableStore<KeyringControllerPersistentState>
    • KeyringController.memStore is now an ObservableStore<KeyringControllerState>
  • BREAKING: updateMemStoreKeyrings method return type changed to Promise<void>
  • BREAKING: KeyringControllerState type changed to include only non-persistent state:
    • Now undefined is used instead of null when encryptionKey and encryptionSalt are unset
    • keyrings is now of type KeyringObject[] instead of Keyring<Json>
    • password, store, memStore have been removed - note that in practice this change only affects types
    • This changes cause the following methods also to change the return type:
      • createNewVaultAndKeychain
      • createNewVaultAndRestore
      • setLocked
      • submitPassword
      • submitEncryptionKey
      • addNewAccount
      • removeAccount
      • fullUpdate
  • ADDED: KeyringControllerPersistentState type which includes only persistent state, an optional string property with key vault
  • ADDED: KeyringObject type for how keyrings are represented in memStore

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

@socket-security
Copy link

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@metamask/obs-store 8.1.0 None +1 37.6 kB gudahtt

🚮 Removed packages: obs-store@4.0.3

@socket-security
Copy link

socket-security bot commented Jul 17, 2023

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring: @metamask/obs-store@8.1.0, @metamask/safe-event-emitter@2.0.0

Next steps

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore foo@1.0.0 bar@* or ignore all packages with @SocketSecurity ignore-all

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

Looks great! Let me know when the description is ready so that I can review the list of changes. Lots of changes here.

@Gudahtt
Copy link
Member

Gudahtt commented Jul 17, 2023

I spotted a few more type errors caused by the types/@metamask/eth-sig-util file overriding the types from that package. Perhaps that can wait for a separate PR though.

@Gudahtt
Copy link
Member

Gudahtt commented Jul 17, 2023

@SocketSecurity ignore @metamask/obs-store@8.1.0
@SocketSecurity ignore @metamask/safe-event-emitter@2.0.0

These are our packages

@mikesposito
Copy link
Member Author

The description should now be ready, I hope I mentioned everything 😄

@Gudahtt
Copy link
Member

Gudahtt commented Jul 17, 2023

I have created a few extra PRs for the problems I found related to signTypedMessage:

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Did a quick pass on this and had a couple of suggestions/questions. Will do another pass tomorrow to make sure I understand how these types are changing.

src/KeyringController.ts Outdated Show resolved Hide resolved
src/KeyringController.test.ts Outdated Show resolved Hide resolved
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
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! Description of changes looks great too

@mikesposito mikesposito merged commit f0baaac into main Jul 18, 2023
16 checks passed
@mikesposito mikesposito deleted the fix/store-types branch July 18, 2023 11:57
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