Typing fixes for provider, ppom and other any usage#89
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
6a5a04a to
39e9f8c
Compare
This comment was marked as outdated.
This comment was marked as outdated.
39e9f8c to
934940f
Compare
|
🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎ To accept the risk, merge this PR and you will not be notified again.
Next stepsWhat is network access?This module accesses the network. Packages should remove all network access that is functionally unnecessary. Consumers should audit network access to ensure legitimate use. What is shell access?This module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code. Packages should avoid accessing the shell which can reduce portability, and make it easier for malicious shell access to be introduced. Take a deeper look at the dependencyTake 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 packageIf 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 riskTo ignore an alert, reply with a comment starting with
|
8812de5 to
4d84e41
Compare
d03e901 to
f413c9d
Compare
f413c9d to
46c8936
Compare
provider, ppom and other any usage
| export type { | ||
| NativeCrypto, | ||
| PPOMState, | ||
| UsePPOM, | ||
| UpdatePPOM, | ||
| PPOMInitialisationStatusType, | ||
| PPOMControllerActions, | ||
| PPOMControllerInitialisationStateChangeEvent, | ||
| PPOMControllerEvents, | ||
| PPOMControllerMessenger, | ||
| } from './ppom-controller'; | ||
| export { | ||
| REFRESH_TIME_INTERVAL, | ||
| NETWORK_CACHE_DURATION, | ||
| PPOMInitialisationStatus, | ||
| PPOMController, | ||
| } from './ppom-controller'; |
There was a problem hiding this comment.
There should be no breaking changes here. This is the list of existing package-level exports from the ppom-controller file.
Explicit enumeration of exports is safer, and also allows sharing exports internally, which comes in handy with e.g. AllowedEvents, controllerName for test files.
9f5c709 to
da5a54f
Compare
| | JsonRpcSuccess<Json> | ||
| | (Omit<JsonRpcFailure, 'error'> & { error: unknown }) |
There was a problem hiding this comment.
I used the JsonRpcResponse<Json> type here instead of unknown, even though this technically narrows the response type in the sendAsync callback compared to any (see line 1059).
This is because JsonRpcEngine is where the callback passed into sendAsync actually gets invoked, and that class consistently uses the JsonRpcResponse type for responses.
The error type in JsonRpcFailure is widened to unknown since that's the only type accepted by sendAsync. See https://github.com/MetaMask/ppom-validator/pull/89/files#r1470601394 for a discussion on this point.
Note: sendAsync is set to be deprecated in favor of request in a new EIP1193-compliant provider class. request will use JsonRpcResponse<Json>.
jest.config.js
Outdated
| coverageThreshold: { | ||
| global: { | ||
| branches: 100, | ||
| branches: 98.18, |
There was a problem hiding this comment.
Would be nice to not reduce the test coverage here 😭 What caused this?
| export type PPOMControllerEvents = | ||
| | PPOMControllerInitialisationStateChangeEvent | ||
| | NetworkControllerStateChangeEvent; | ||
| export type PPOMControllerEvents = PPOMControllerInitialisationStateChangeEvent; |
There was a problem hiding this comment.
For context, these changes align with changes we've been making to controllers in the core repo. For instance, see SelectedNetworkController: https://github.com/MetaMask/core/blob/d3861d03df0ff3f4cf2b479f746b46e602065d76/packages/selected-network-controller/src/SelectedNetworkController.ts#L71-L89
There was a problem hiding this comment.
Thanks for adding context here. To be clear, I didn't use the ControllerGetStateAction and ControllerStateChangeEvent types since those were introduced in base-controller v4, and this package is using v3.
There was a problem hiding this comment.
Thanks a lot @MajorLift for these improvements 🙏
| // Provisional skeleton type for PPOM class | ||
| // TODO: Replace with actual PPOM class | ||
| type PPOM = { | ||
| new: (...args: unknown[]) => PPOM; | ||
| validateJsonRpc: () => Promise<unknown>; | ||
| free: () => void; | ||
| } & Record<string, unknown>; |
There was a problem hiding this comment.
Wrote temporary PPOM type that expresses a minimal interface. Added TODO so this would be eventually replaced with a full type.
| // TOOD: Replace with `PreferencesState` from `@metamask/preferences-controller` | ||
| preferencesState: { securityAlertsEnabled: boolean } & Record< | ||
| string, | ||
| Json | ||
| >, |
There was a problem hiding this comment.
Wrote temporary PreferencesState surrogate to avoid introducing @metamask/preferences-controller as a dependency. Added TODO so this would be eventually replaced with the full type.
| // TOOD: Replace with `PreferencesState` from `@metamask/preferences-controller` | ||
| preferenceControllerState: { securityAlertsEnabled: boolean } & Record< | ||
| string, | ||
| Json | ||
| >, |
e358aa5 to
2d2a2de
Compare
|
Added Changelog with breaking changes highlighted. |
| @@ -5,6 +5,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | |||
| and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | |||
|
|
|||
| ## [Unreleased] | |||
There was a problem hiding this comment.
I'm curious about the Changelog changes. Typically the changelog only includes user-facing changes and it is generated with the update-changelog script during the RC phase 🤔 for this reason I think we should not include these changes here?
There was a problem hiding this comment.
I removed some entries that weren't user-facing. Thanks for pointing that out!
All of the remaining entries are major changes for package-level exports. See our documentation on reviewing release PRs for how these qualify as breaking changes.
As for why these are in the changelog file, the shared libraries team has been recording changelog entries for new PRs under the "Unreleased" heading, so that they're immediately available for reference when the next release is being created.
update-changelog auto-populates a list of unreleased commits to changelog, but these are only intended as starting points. Recording under "Unreleased" streamlines the process of retrieving the full changelog entries by making it unnecessary to visit each linked PR and check the changelog section of the PR description.
There was a problem hiding this comment.
That said, I've realized our team won't be creating releases for this repo, and introducing a new practice like this will be confusing.
I've removed the additions to the changelog file: 3d957cd. The changelog entries can be found in the PR description!
7cdd21f to
5fc353e
Compare
5fc353e to
9af9e41
Compare
Explanation
Reduces repo-wide
anycount to 1 (excluding test files).providervariables using theProvidertype from@metamask/network-controller.Providertype is now safe to use, with its recent alignment issues resolved as of Align types with @metamask/eth-json-rpc-provider eth-query#21.@metamask/utilsas a dependency.PPOMvariables with provisional skeleton type.anyusageReferences
anywith proper types (non-test files only) #144Changelog
Changed
@metamask/utils^8.3.0 as a dependency. (#89)Removed
NetworkControllerStateChangeEventis removed from thePPOMControllerEventsunion type. (#89)Fixed
PPOMControllerclass constructor option types are narrowed fromany. (#89)providerto be theProvidertype from@metamask/network-controller(equivalent toSafeEventEmitterProviderfrom@metamask/eth-json-rpc-provider).onPreferencesChangeto be(callback: (preferencesState: { securityAlertsEnabled: boolean } & Record<string, Json>) => void) => void.UsePPOMtype replacesanywith thePPOMtype in its definition. (#89)PPOMclass instance makes JSON-RPC requests to the provider, theparamstype is now widened fromRecord<string, unknown>toJsonRpcParams, and the response type is narrowed fromanytoJsonRpcSuccess<Json>. (#89)