-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but again deferring to @jpuri as this is her domain
| JsonRpcSuccess<Json> | ||
| (Omit<JsonRpcFailure, 'error'> & { error: unknown }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes here make sense to me, although I will also defer to @jpuri for final approval.
jest.config.js
Outdated
@@ -39,10 +39,10 @@ module.exports = { | |||
// An object that configures minimum threshold enforcement for coverage results | |||
coverageThreshold: { | |||
global: { | |||
branches: 100, | |||
branches: 98.18, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to not reduce the test coverage here 😭 What caused this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export type PPOMControllerEvents = | ||
| PPOMControllerInitialisationStateChangeEvent | ||
| NetworkControllerStateChangeEvent; | ||
export type PPOMControllerEvents = PPOMControllerInitialisationStateChangeEvent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 | ||
>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
e358aa5
to
2d2a2de
Compare
Added Changelog with breaking changes highlighted. |
CHANGELOG.md
Outdated
@@ -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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
any
count to 1 (excluding test files).provider
variables using theProvider
type from@metamask/network-controller
.Provider
type 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/utils
as a dependency.PPOM
variables with provisional skeleton type.any
usageReferences
any
with proper types (non-test files only) #144Changelog
Changed
@metamask/utils
^8.3.0 as a dependency. (#89)Removed
NetworkControllerStateChangeEvent
is removed from thePPOMControllerEvents
union type. (#89)Fixed
PPOMController
class constructor option types are narrowed fromany
. (#89)provider
to be theProvider
type from@metamask/network-controller
(equivalent toSafeEventEmitterProvider
from@metamask/eth-json-rpc-provider
).onPreferencesChange
to be(callback: (preferencesState: { securityAlertsEnabled: boolean } & Record<string, Json>) => void) => void
.UsePPOM
type replacesany
with thePPOM
type in its definition. (#89)PPOM
class instance makes JSON-RPC requests to the provider, theparams
type is now widened fromRecord<string, unknown>
toJsonRpcParams
, and the response type is narrowed fromany
toJsonRpcSuccess<Json>
. (#89)