Skip to content
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

CAIP Multichain API with permission refactor changes #4961

Merged

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Nov 21, 2024

Explanation

This diff is a bit messy since it also brings in the core PR that refactors the CAIP-25 permission which the caip-multichain-api branch doesn't have yet.

The main thing this PR does is adds getSessionScopes() which massages the new CAIP-25 permission into a NormalizedScopesObject

References

Changelog

@metamask/package-a

  • : Your change here
  • : Your change here

@metamask/package-b

  • : Your change here
  • : Your change here

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 highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

jiexi and others added 30 commits November 20, 2024 10:32
Co-authored-by: Alex Donesky <adonesky@gmail.com>
…ccounts.ts

Co-authored-by: Alex Donesky <adonesky@gmail.com>
Co-authored-by: Alex Donesky <adonesky@gmail.com>
Co-authored-by: Alex Donesky <adonesky@gmail.com>
Co-authored-by: Alex Donesky <adonesky@gmail.com>
Co-authored-by: Alex Donesky <adonesky@gmail.com>
Co-authored-by: Alex Donesky <adonesky@gmail.com>
Comment on lines 65 to 67
const scopeObject = getSessionScopes(caveat.value)[
scope as InternalScopeString
];
Copy link
Contributor

@adonesky1 adonesky1 Nov 21, 2024

Choose a reason for hiding this comment

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

Hmmm when I first read this I thought it was a bit strange to rehydrate this and then have a method authorization check since our permissions are really not method oriented now... But hmmm maybe its still correct since we still need to validate that the requested method is supported

Copy link
Contributor Author

@jiexi jiexi Nov 21, 2024

Choose a reason for hiding this comment

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

Yeah, we still need to keep the interface consistent. I.e. trying to call a scope/method via wallet_invokeMethod that wasn't returned to you via wallet_createSession / wallet_sessionChanged should throw an unauthorized error rather than a method not found error

* e.g. We flatten each reference into its own scopeObject before storing them in a `endowment:caip25` permission.
* we resolve the `references` property into a scopeObject per reference and
* assign an empty array to the `accounts` property if not already defined
* to more easily read chain specific permissions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like we should call out how/why this type is used since we have 3 of them now 🤣 .

  • return type for getSession
  • type used for validation pre-serialization?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

e672262 maybe?

@jiexi
Copy link
Contributor Author

jiexi commented Nov 21, 2024

@metamaskbot publish-preview

@jiexi jiexi marked this pull request as ready for review November 21, 2024 22:25
@jiexi jiexi requested a review from a team as a code owner November 21, 2024 22:25
@jiexi jiexi merged commit 0d167a3 into caip-multichain-api Nov 21, 2024
96 of 119 checks passed
@jiexi jiexi deleted the caip-multichain-api-with-permission-refactor branch November 21, 2024 22:26
Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "20.0.0-preview-e6722625",
  "@metamask-previews/address-book-controller": "6.0.1-preview-e6722625",
  "@metamask-previews/announcement-controller": "7.0.1-preview-e6722625",
  "@metamask-previews/approval-controller": "7.1.1-preview-e6722625",
  "@metamask-previews/assets-controllers": "45.0.0-preview-e6722625",
  "@metamask-previews/base-controller": "7.0.2-preview-e6722625",
  "@metamask-previews/build-utils": "3.0.1-preview-e6722625",
  "@metamask-previews/chain-controller": "0.2.0-preview-e6722625",
  "@metamask-previews/composable-controller": "9.0.1-preview-e6722625",
  "@metamask-previews/controller-utils": "11.4.3-preview-e6722625",
  "@metamask-previews/ens-controller": "15.0.0-preview-e6722625",
  "@metamask-previews/eth-json-rpc-provider": "4.1.6-preview-e6722625",
  "@metamask-previews/gas-fee-controller": "22.0.1-preview-e6722625",
  "@metamask-previews/json-rpc-engine": "10.0.1-preview-e6722625",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.5-preview-e6722625",
  "@metamask-previews/keyring-controller": "19.0.0-preview-e6722625",
  "@metamask-previews/logging-controller": "6.0.2-preview-e6722625",
  "@metamask-previews/message-manager": "11.0.1-preview-e6722625",
  "@metamask-previews/multichain": "1.0.0-preview-e6722625",
  "@metamask-previews/name-controller": "8.0.1-preview-e6722625",
  "@metamask-previews/network-controller": "22.0.2-preview-e6722625",
  "@metamask-previews/notification-controller": "7.0.0-preview-e6722625",
  "@metamask-previews/notification-services-controller": "0.14.0-preview-e6722625",
  "@metamask-previews/permission-controller": "11.0.3-preview-e6722625",
  "@metamask-previews/permission-log-controller": "3.0.1-preview-e6722625",
  "@metamask-previews/phishing-controller": "12.3.0-preview-e6722625",
  "@metamask-previews/polling-controller": "12.0.1-preview-e6722625",
  "@metamask-previews/preferences-controller": "15.0.0-preview-e6722625",
  "@metamask-previews/profile-sync-controller": "2.0.0-preview-e6722625",
  "@metamask-previews/queued-request-controller": "7.0.1-preview-e6722625",
  "@metamask-previews/rate-limit-controller": "6.0.1-preview-e6722625",
  "@metamask-previews/selected-network-controller": "19.0.0-preview-e6722625",
  "@metamask-previews/signature-controller": "23.0.0-preview-e6722625",
  "@metamask-previews/transaction-controller": "40.0.0-preview-e6722625",
  "@metamask-previews/user-operation-controller": "19.0.0-preview-e6722625"
}

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.

2 participants