-
-
Notifications
You must be signed in to change notification settings - Fork 273
feat: make wallet_sendCalls more reliable
#7816
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
base: main
Are you sure you want to change the base?
Conversation
wallet_sendCalls more reliable
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.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
| address: Hex, | ||
| req: JsonRpcRequest, | ||
| { getAccounts }: { getAccounts: (req: JsonRpcRequest) => Promise<string[]> }, | ||
| { getPermittedAccountsForOrigin }: { getPermittedAccountsForOrigin: () => Promise<string[]> }, |
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.
Could we avoid breaking changes for all clients if we kept the current name, but just ensured the hooks check the origin?
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.
Yeah Jiexi and I went back and forth on this a bit, but I think for this case the name change is worth it. The bug this PR fixes happened precisely because getAccounts is ambiguous - it doesn't convey that these must be permitted accounts for the requesting origin. A future developer could reasonably implement getAccounts by returning all accounts or the selected account, not realizing this breaks the security model.
Since this is already a breaking change (the signature changed from (req) => Promise<string[]> to () => Promise<string[]>), we'd prefer to make the API self-documenting and reduce the risk of similar bugs.
| // Ensure that an "unauthorized" error is thrown if the requester | ||
| // does not have the `eth_accounts` permission. | ||
| const accounts = await getAccounts(req); | ||
| const accounts = await getPermittedAccountsForOrigin(); |
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.
How does the client access the origin if we don't provide anything to the hook?
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 hook gets the origin off the request object directly. The 7702 middleware follows the same pattern that I'm hoping to use here
adonesky1
left a comment
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
Improves reliability of wallet_sendCalls.
Changes
getAccountshook togetPermittedAccountsForOriginhook which takes no params and returns the permitted accounts for the origin of the requestReferences
Checklist
Note
Medium Risk
Moderate risk because it changes RPC middleware authorization/account-selection behavior and the hook contract (from
getAccounts(req)togetPermittedAccountsForOrigin()), which could surface newunauthorizederrors if consumers don’t implement the new hook correctly.Overview
Makes
wallet_sendCallsmore reliable by switching account authorization and defaultfromresolution to an origin-scopedgetPermittedAccountsForOrigin()hook, rather than relying on a genericgetAccounts(req)/selected-account lookup.processSendCallsnow defaultsfromto the first permitted account whenfromis omitted and explicitly throwsproviderErrors.unauthorized()when no permitted account is available;wallet_sendCalls,wallet_getCapabilities, andvalidateAndNormalizeKeyholderwere updated accordingly, with tests and the changelog updated to match.Written by Cursor Bugbot for commit 8f310db. This will update automatically on new commits. Configure here.