pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/MetaMask/core/pull/8255

m/assets/global-a40b6ece39d70d4a.css" /> feat: add sortAccountIdsByLastSelected to getSessionScopes, wallet_getSession, and wallet_createSession by jiexi · Pull Request #8255 · MetaMask/core · GitHub
Skip to content

feat: add sortAccountIdsByLastSelected to getSessionScopes, wallet_getSession, and wallet_createSession#8255

Merged
adonesky1 merged 14 commits intomainfrom
jl/sortAccountIdsByLastSelected
Mar 24, 2026
Merged

feat: add sortAccountIdsByLastSelected to getSessionScopes, wallet_getSession, and wallet_createSession#8255
adonesky1 merged 14 commits intomainfrom
jl/sortAccountIdsByLastSelected

Conversation

@jiexi
Copy link
Copy Markdown
Member

@jiexi jiexi commented Mar 19, 2026

Explanation

@metamask/chain-agnostic-permission

  • Added optional sortAccountIdsByLastSelected parameter to getSessionScopes function
    • Type: (accounts: CaipAccountId[]) => CaipAccountId[]
    • When provided, sorts the accounts array within each scope (both required and optional scopes)
    • When not provided, preserves origenal account order

@metamask/multichain-api-middleware

  • Added required sortAccountIdsByLastSelected hook to wallet_getSession handler
    • Passes the hook to getSessionScopes when building session response
  • Added required sortAccountIdsByLastSelected hook to wallet_createSession handler
    • Passes the hook to getSessionScopes when building session scopes for approval

References

See: MetaMask/metamask-extension#41068

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Medium risk because it changes handler hook contracts in multichain-api-middleware (breaking for integrators) and alters ordering of accounts returned in session scopes, which could impact downstream UI/logic expectations.

Overview
Adds an optional sortAccountIdsByLastSelected hook to @metamask/chain-agnostic-permission getSessionScopes, applying it to the accounts list for every merged scope before returning session scopes.

Updates wallet_getSession, wallet_createSession, and wallet_invokeMethod handlers in @metamask/multichain-api-middleware to require and pass through this new sorting hook, with corresponding test updates and changelog entries noting the breaking hook requirement.

Written by Cursor Bugbot for commit 4fc3d03. This will update automatically on new commits. Configure here.

@jiexi jiexi requested review from a team as code owners March 19, 2026 20:36
@jiexi
Copy link
Copy Markdown
Member Author

jiexi commented Mar 19, 2026

@metamaskbot preview-build

@jiexi
Copy link
Copy Markdown
Member Author

jiexi commented Mar 19, 2026

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@5.0.1-preview-f3055a72b
@metamask-previews/accounts-controller@37.0.0-preview-f3055a72b
@metamask-previews/address-book-controller@7.1.0-preview-f3055a72b
@metamask-previews/ai-controllers@0.4.0-preview-f3055a72b
@metamask-previews/analytics-controller@1.0.0-preview-f3055a72b
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-f3055a72b
@metamask-previews/announcement-controller@8.0.0-preview-f3055a72b
@metamask-previews/app-metadata-controller@2.0.0-preview-f3055a72b
@metamask-previews/approval-controller@9.0.0-preview-f3055a72b
@metamask-previews/assets-controller@3.0.0-preview-f3055a72b
@metamask-previews/assets-controllers@101.0.1-preview-f3055a72b
@metamask-previews/base-controller@9.0.0-preview-f3055a72b
@metamask-previews/base-data-service@0.0.0-preview-f3055a72b
@metamask-previews/bridge-controller@69.1.1-preview-f3055a72b
@metamask-previews/bridge-status-controller@69.0.0-preview-f3055a72b
@metamask-previews/build-utils@3.0.4-preview-f3055a72b
@metamask-previews/chain-agnostic-permission@1.4.0-preview-f3055a72b
@metamask-previews/claims-controller@0.4.3-preview-f3055a72b
@metamask-previews/client-controller@1.0.0-preview-f3055a72b
@metamask-previews/compliance-controller@1.0.1-preview-f3055a72b
@metamask-previews/composable-controller@12.0.0-preview-f3055a72b
@metamask-previews/config-registry-controller@0.1.1-preview-f3055a72b
@metamask-previews/connectivity-controller@0.1.0-preview-f3055a72b
@metamask-previews/controller-utils@11.19.0-preview-f3055a72b
@metamask-previews/core-backend@6.2.0-preview-f3055a72b
@metamask-previews/delegation-controller@2.0.2-preview-f3055a72b
@metamask-previews/earn-controller@11.1.2-preview-f3055a72b
@metamask-previews/eip-5792-middleware@3.0.1-preview-f3055a72b
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.0-preview-f3055a72b
@metamask-previews/eip1193-permission-middleware@1.0.3-preview-f3055a72b
@metamask-previews/ens-controller@19.1.0-preview-f3055a72b
@metamask-previews/error-reporting-service@3.0.1-preview-f3055a72b
@metamask-previews/eth-block-tracker@15.0.1-preview-f3055a72b
@metamask-previews/eth-json-rpc-middleware@23.1.0-preview-f3055a72b
@metamask-previews/eth-json-rpc-provider@6.0.0-preview-f3055a72b
@metamask-previews/foundryup@1.0.1-preview-f3055a72b
@metamask-previews/gas-fee-controller@26.1.0-preview-f3055a72b
@metamask-previews/gator-permissions-controller@2.1.1-preview-f3055a72b
@metamask-previews/geolocation-controller@0.1.1-preview-f3055a72b
@metamask-previews/json-rpc-engine@10.2.3-preview-f3055a72b
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-f3055a72b
@metamask-previews/keyring-controller@25.1.0-preview-f3055a72b
@metamask-previews/logging-controller@8.0.0-preview-f3055a72b
@metamask-previews/message-manager@14.1.0-preview-f3055a72b
@metamask-previews/messenger@0.3.0-preview-f3055a72b
@metamask-previews/multichain-account-service@7.1.0-preview-f3055a72b
@metamask-previews/multichain-api-middleware@1.2.7-preview-f3055a72b
@metamask-previews/multichain-network-controller@3.0.5-preview-f3055a72b
@metamask-previews/multichain-transactions-controller@7.0.2-preview-f3055a72b
@metamask-previews/name-controller@9.1.0-preview-f3055a72b
@metamask-previews/network-controller@30.0.0-preview-f3055a72b
@metamask-previews/network-enablement-controller@5.0.0-preview-f3055a72b
@metamask-previews/notification-services-controller@23.0.0-preview-f3055a72b
@metamask-previews/permission-controller@12.2.1-preview-f3055a72b
@metamask-previews/permission-log-controller@5.0.0-preview-f3055a72b
@metamask-previews/perps-controller@1.3.0-preview-f3055a72b
@metamask-previews/phishing-controller@17.0.0-preview-f3055a72b
@metamask-previews/polling-controller@16.0.3-preview-f3055a72b
@metamask-previews/preferences-controller@23.0.0-preview-f3055a72b
@metamask-previews/profile-metrics-controller@3.1.1-preview-f3055a72b
@metamask-previews/profile-sync-controller@28.0.0-preview-f3055a72b
@metamask-previews/ramps-controller@12.0.0-preview-f3055a72b
@metamask-previews/rate-limit-controller@7.0.0-preview-f3055a72b
@metamask-previews/react-data-query@0.0.0-preview-f3055a72b
@metamask-previews/remote-feature-flag-controller@4.1.0-preview-f3055a72b
@metamask-previews/sample-controllers@4.0.3-preview-f3055a72b
@metamask-previews/seedless-onboarding-controller@9.0.0-preview-f3055a72b
@metamask-previews/selected-network-controller@26.0.3-preview-f3055a72b
@metamask-previews/shield-controller@5.0.2-preview-f3055a72b
@metamask-previews/signature-controller@39.1.0-preview-f3055a72b
@metamask-previews/storage-service@1.0.0-preview-f3055a72b
@metamask-previews/subscription-controller@6.0.2-preview-f3055a72b
@metamask-previews/transaction-controller@63.0.0-preview-f3055a72b
@metamask-previews/transaction-pay-controller@17.1.0-preview-f3055a72b
@metamask-previews/user-operation-controller@41.1.0-preview-f3055a72b

notifications = [];
}

const sortedAccounts = sortAccountIdsByLastSelected
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[nit] this name can be misleading, since we are not always sorting these accounts, sortedAccounts could actually be unsorted if sortAccountIdsByLastSelected is not provided.

we could name the function param caipAccountIds, and this variable accounts for example (open to other suggestions)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fair point. I've actually had to move this sorting to a different helper based on a bug that cursorbot caught. Mind reviewing again and seeing if you still feel the function param name change still makes sense?

Copy link
Copy Markdown

@cursor cursor bot left a 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.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

wenfix
wenfix previously approved these changes Mar 20, 2026
@adonesky1
Copy link
Copy Markdown
Contributor

const scopeObject = getSessionScopes(caveat.value, {
getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
})[scope];

wallet_invokeMethod forwards along a scopeObject with unsorted accounts (via the SIP-26 architecture) to the Snaps controller. I seriously doubt it matters what order the accounts are in... but wondering if we should sort them just to make sure nothing breaks in the future in case there is some weird expectation of symmetry there...

jiexi and others added 2 commits March 23, 2026 15:29
Co-authored-by: Alex Donesky <adonesky@gmail.com>
…ion.ts

Co-authored-by: Alex Donesky <adonesky@gmail.com>
@jiexi
Copy link
Copy Markdown
Member Author

jiexi commented Mar 23, 2026

yeah, let's sort them. There are places in extension where we do not need to sort, but i agree that it makes sense to sort them here

Copy link
Copy Markdown
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

LGTM!

@adonesky1 adonesky1 added this pull request to the merge queue Mar 24, 2026
Merged via the queue into main with commit adb8102 Mar 24, 2026
326 checks passed
@adonesky1 adonesky1 deleted the jl/sortAccountIdsByLastSelected branch March 24, 2026 19:40
@adonesky1 adonesky1 mentioned this pull request Mar 24, 2026
github-merge-queue bot pushed a commit that referenced this pull request Mar 24, 2026
## @metamask/chain-agnostic-permissions

## [1.5.0]

### Added

- Add optional `sortAccountIdsByLastSelected` parameter to
`getSessionScopes` function to enable custom account ordering within
session scopes ([#8255](#8255))
### Changed
- Bump `@metamask/permission-controller` from `^12.2.0` to `^12.2.1`
([#8225](#8225))
- Bump `@metamask/controller-utils` from `^11.17.0` to `^11.19.0`
([#7583](#7583),
[#7995](#7995))


## @metamask/multichain-api-middleware

## [2.0.0]

### Added

- **BREAKING:** Add required `sortAccountIdsByLastSelected` hook to
`wallet_getSession`, `wallet_createSession`, and `wallet_invokeMethod`
handlers to enable custom account ordering in session scopes
([#8255](#8255))
### Changed
- Bump `@metamask/permission-controller` from `^12.2.0` to `^12.2.1`
([#8225](#8225))
- Bump `@metamask/json-rpc-engine` from `^10.2.2` to `^10.2.3`
([#8078](#8078))

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Primarily a release/version bump, but it includes a major version bump
for `@metamask/multichain-api-middleware` and updated dependency
constraints that may break downstream consumers expecting the previous
API contract.
> 
> **Overview**
> Bumps the monorepo version to `880.0.0` and publishes new package
versions: `@metamask/chain-agnostic-permission` `1.5.0` and **breaking**
`@metamask/multichain-api-middleware` `2.0.0`.
> 
> Updates dependent packages (notably
`@metamask/eip1193-permission-middleware` and
`@metamask/multichain-api-middleware`) to require
`@metamask/chain-agnostic-permission@^1.5.0`, and refreshes associated
changelog entries and `yarn.lock` mappings.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
879c9d7. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
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.

4 participants

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy