-
-
Notifications
You must be signed in to change notification settings - Fork 244
Add method to decode permission to GatorPermissionsController #6556
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
Conversation
e5e5d20
to
56b2f73
Compare
15794d8
to
4bc812a
Compare
4ebe1b2
to
3328cf2
Compare
…missionsController - rejects any request from an origin other than the gator permission snap - attempts to identify the permission type, and decode the data - rejects any request where a unique permission is unable to be decoded Also renames GatorPermissionsController.test.ts
3328cf2
to
fa1a139
Compare
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
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 not seeing a strong justification for exposing decodePermissionFromPermissionContextForOrigin()
via the GatorPermissionsController
.
As mentioned in the inline comment, we should consider decoupling it entirely and exposing it as a utility function directly from @metamask/gator-permissions-controller
.
- fix incorrect type of periodDuration in native-token-periodic-permission was Hex, now number - removed unnecessary type assertions - add necessary type assertion to test
029ee5f
to
2036df5
Compare
df4a94d
to
6f2a2c8
Compare
Explanation
When signing a permission, MetaMask must present the permission in a way that is easily comprehensible to the user. Based on the design shared here, the permission must be decoded from the
eth_signTypedData_v4
request.This PR adds that functionality to the
GatorPermissionsController
.Introduce
decodePermissionFromPermissionContextForOrigin
toGatorPermissionsController
and register a new action handler. It:Validates the caller origin matches
permissionsProviderSnapId
(throwsOriginNotAllowedError
otherwise).Resolves enforcer contract addresses per chain via
@metamask/delegation-deployments
. Throws if contracts are missing for the chain.Identifies the permission type from caveats via
identifyPermissionByEnforcers
, extracts expiry and permission-specific data viagetPermissionDataAndExpiry
, and builds aDecodedPermission
viareconstructDecodedPermission
.Non-obvious pieces:
@metamask/delegation-core
for terms helpers likecreateTimestampTerms
andcreateNativeTokenStreamingTerms
, andROOT_AUTHORITY
.@metamask/delegation-deployments
to source enforcer addresses andCHAIN_ID
.utils.ts
to facilitate low level unit testing, without polluting the interface that is exposed to theGatorPermissionsController
with these functions.References
Architecture design https://www.notion.so/metamask-consensys/SignTypedData-with-Metadata-Specification-22bf86d67d688023be67e2ee06e3a56a#22bf86d67d688023be67e2ee06e3a56a
Checklist