-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
feat: make SafeEventEmitterProvider compatible with eth req libraries #4422
feat: make SafeEventEmitterProvider compatible with eth req libraries #4422
Conversation
🚨 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 a deprecated package?The maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed. Research the state of the package and determine if there are non-deprecated versions that can be used, or if it should be replaced with a new, supported solution. What is an install script?Install scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts. Packages should not be running non-essential scripts during install and there are often solutions to problems people solve with install scripts that can be run at publish time instead. 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
|
…ompatible-with-ethereum-request-libraries
…ompatible-with-ethereum-request-libraries
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.
Hey! After reviewing this PR, I realized that we may want to go a little further than using tsd
. Let me know what you think.
packages/eth-json-rpc-provider/src/safe-event-emitter-provider.test.ts
Outdated
Show resolved
Hide resolved
packages/eth-json-rpc-provider/src/safe-event-emitter-provider.test-d.ts
Outdated
Show resolved
Hide resolved
…ompatible-with-ethereum-request-libraries
601d9c8
to
c99a02c
Compare
…ompatible-with-ethereum-request-libraries
@cryptodev-2s Hey! I still think we ought to add smoke tests so that we can be confident that these changes fix the compatibility issues we have with the various Ethereum libraries. I outlined ideas for this in the comment above. What are your thoughts? |
|
…ompatible-with-ethereum-request-libraries
…tEmitterProvider-type-compatible-with-ethereum-request-libraries
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 those smoke tests! This looks good to me.
@@ -48,12 +48,17 @@ | |||
"dependencies": { | |||
"@metamask/json-rpc-engine": "^9.0.0", | |||
"@metamask/safe-event-emitter": "^3.0.0", | |||
"@metamask/utils": "^8.3.0" | |||
"@metamask/utils": "^8.3.0", |
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.
It looks like this is only used for dependencies?
Could the types be re-exported in this package, thus delegating @metamask/utils
to a devDependency
?
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.
To complete it, the types used in exports also have to be exported from packages/eth-json-rpc-provider/src/index.ts
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.
@legobeat I'm not sure I understand the reasoning for this change, based on the criteria for categorizing dep vs. devDep discussed here: #4449 (comment).
The types imported from @metamask/utils
always need to be present for the user, since they are dependencies for the exported types and functions Eip1193Request
, convertEip1193RequestToJsonRpcRequest
, SafeEventEmitterProvider['request']
, SafeEventEmitterProvider['sendAsync']
, SafeEventEmitterProvider['send']
. These exports will always directly reference the imported types, and "any project using this package would need to have the package the types come from as well, or it would be an invalid reference."
The type imports from @metamask/utils
are also present in the built type declaration files for this package, which wouldn't happen if they were only being used internally at build time.
Re-exporting the imports would give the user access to them, but wouldn't it also require the user to manually import the re-exported types in order to use the exports from this package -- even if the re-exported types are not used anywhere else? It seems like that would effectively make @metamask/utils
a package dependency, just with extra steps.
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.
The type imports from
@metamask/utils
are also present in the built type declaration files for this package, which wouldn't happen if they were only being used internally at build time.
I see this as the key criterion for deciding that @metamask/utils
should be in dependencies
and not devDependencies
, so that TypeScript users are able to use the type declarations that ship with this package.
I see that we are exporting Eip1193Request
in this PR. If we were not doing this, then it would be less obvious that the type declaration files referenced types imported from @metamask/utils
, but I believe that even without this, providerFromMiddleware
takes types that reference Json
and JsonRpcParams
. So I believe that @metamask/utils
still needs to be included in dependencies
.
Thoughts?
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.
My suggestion here is that the used types (Json
, JsonRpcParams
) would get re-export
-ed from this package.
This will be equivalent from the TypeScript user perspective (the exact same types are available for them) but without requiring the downstream user to pull in the not-actually used js files. So effectively the built .d.ts
files in @metamask/eth-json-rpc-provider
would include the necessary definitions which would otherwise get pulled in from @metamask/utils
.
TypeScript will transparently see that the types are identical and not distinguish between them when imported from different sources downstream.
This also has a side-benefit that any future otherwise non-breaking module refactors (renaming or moving initial type definitions between different packages, for example) becomes transparent for users of this package.
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.
This will be equivalent from the TypeScript user perspective (the exact same types are available for them) but without requiring the downstream user to pull in the not-actually used js files. So effectively the built
.d.ts
files in@metamask/eth-json-rpc-provider
would include the necessary definitions which would otherwise get pulled in from@metamask/utils
.
Hmm. Is the thought here that if we re-export types from @metamask/utils
, the TypeScript compiler will recognize this and embed those types into the type declarations for @metamask/eth-json-rpc-provider
? If so, I'm not sure it works that way. I believe the type declaration files would still include import
lines from @metamask/utils
, even if those types are being re-exported. Therefore, the consumer would still need @metamask/utils
somewhere in the dependency tree for TypeScript to "see" those types.
One more comment from me above and then I think we may be good to go on this. |
…ompatible-with-ethereum-request-libraries
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 want to make sure we handle errors correctly here. I had some more thoughts on how we can do that. Additionally, I noticed some lack of test coverage.
packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts
Outdated
Show resolved
Hide resolved
packages/eth-json-rpc-provider/src/safe-event-emitter-provider.test.ts
Outdated
Show resolved
Hide resolved
packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts
Outdated
Show resolved
Hide resolved
packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts
Outdated
Show resolved
Hide resolved
packages/eth-json-rpc-provider/src/safe-event-emitter-provider.test.ts
Outdated
Show resolved
Hide resolved
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
🚮 Removed packages: npm/[email protected] |
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.
Two more comments but I think this looks good otherwise!
packages/eth-json-rpc-provider/src/safe-event-emitter-provider.test.ts
Outdated
Show resolved
Hide resolved
packages/eth-json-rpc-provider/src/safe-event-emitter-provider.test.ts
Outdated
Show resolved
Hide resolved
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!
Explanation
request
method and deprecatingsendAsync
(which aren't part of the spec)request
does not requireid
andjsonrpc
to be set, filling them in if they are missingReferences
Fixes #4095
Changelog
@metamask/eth-json-rpc-provider
deprecated
for usage in favor ofrequest
.Checklist