Skip to content

refactor: Use permission decoders from @metamask/7715-permission-types#9164

Open
jeffsmale90 wants to merge 8 commits into
mainfrom
chore/permission_decoding_externalised_permissions
Open

refactor: Use permission decoders from @metamask/7715-permission-types#9164
jeffsmale90 wants to merge 8 commits into
mainfrom
chore/permission_decoding_externalised_permissions

Conversation

@jeffsmale90

@jeffsmale90 jeffsmale90 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Explanation

MetaMask/smart-accounts-kit#259 adds permission decoder definitions to @metamask/7715-permission-types released in 0.8.0.

This PR updates @metamask/gator-permissions-controller to consume these permission definitions instead of defining the permission decoders directly in the controller.

Note: erc20-token-revocation permission type is no longer supported.

References

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

High Risk
Breaking removal of erc20-token-revocation and a large shift of delegation decode logic to an external dependency affect how permissions are interpreted—a security-sensitive path for wallet users.

Overview
Delegates permission decoding to @metamask/7715-permission-types (^1.0.0) instead of maintaining per-type decoders and rule helpers inside gator-permissions-controller. createPermissionDecodersForContracts now builds decoders from makePermissionDecoderConfigs, and chain enforcer addresses are normalized via new enforcerAddresses mapping before decode runs in GatorPermissionsController.

Breaking: erc20-token-revocation is removed from supported types, docs, and tests. Local decoder/rule implementations and their exhaustive unit tests are deleted; controller-level integration tests cover decode for the remaining permission types.

makePermissionDecoder is kept as a thin adapter over shared PermissionDecoderConfig, with checksummed enforcer handling aligned to the external package.

Reviewed by Cursor Bugbot for commit 7cbbc65. Bugbot is set up for automated code reviews on this repo. Configure here.

@jeffsmale90 jeffsmale90 changed the title Chore/permission decoding externalised permissions refactor: @metamask/gator-permissions-controller consumes Advanced Permission definitions from @metamask/7715-permission-types Jun 17, 2026
@jeffsmale90
jeffsmale90 force-pushed the chore/permission_decoding_externalised_permissions branch from 7a4724f to 7eda56a Compare July 14, 2026 02:29
@socket-security

socket-security Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​metamask/​7715-permission-types@​0.7.1 ⏵ 1.0.010010079 +896 +6100

View full report

@jeffsmale90 jeffsmale90 changed the title refactor: @metamask/gator-permissions-controller consumes Advanced Permission definitions from @metamask/7715-permission-types refactor: @metamask/gator-permissions-controller consumes Advanced Permission definitions from @metamask/7715-permission-types Jul 14, 2026
@jeffsmale90
jeffsmale90 force-pushed the chore/permission_decoding_externalised_permissions branch from cb23bf0 to c3fbd8e Compare July 14, 2026 02:54
@jeffsmale90
jeffsmale90 marked this pull request as ready for review July 14, 2026 02:54
@jeffsmale90
jeffsmale90 requested review from a team as code owners July 14, 2026 02:54
@jeffsmale90 jeffsmale90 changed the title refactor: @metamask/gator-permissions-controller consumes Advanced Permission definitions from @metamask/7715-permission-types refactor: Use permission decoders from @metamask/7715-permission-types Jul 14, 2026
@jeffsmale90
jeffsmale90 marked this pull request as draft July 14, 2026 21:25
@jeffsmale90
jeffsmale90 force-pushed the chore/permission_decoding_externalised_permissions branch from 2719213 to c436c43 Compare July 15, 2026 01:57
@jeffsmale90
jeffsmale90 marked this pull request as ready for review July 15, 2026 01:57
@jeffsmale90
jeffsmale90 force-pushed the chore/permission_decoding_externalised_permissions branch from c436c43 to 174d64e Compare July 15, 2026 02:02

@mj-kiwi mj-kiwi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Solid refactor, just a few minor notes.

},
"dependencies": {
"@metamask/7715-permission-types": "^0.7.1",
"@metamask/7715-permission-types": "^0.8.0",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we pump the version to 0.9.0?

## [Unreleased]

### Changed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Small suggestion — the Unreleased entries currently just say "Changed" for switching to package decoders / bumping the dependency, but don't mention that erc20-token-revocation support seems to have been dropped along the way (see the comment on types.ts). If that drop is intentional, might be worth calling it out explicitly (possibly with a BREAKING: prefix per our changelog convention), so consumers relying on that permission type aren't caught off guard after upgrading.

@@ -26,7 +26,6 @@ const gatorPermissionsController = new GatorPermissionsController({
'native-token-periodic',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor doc nit — the example supportedPermissionTypes array dropped erc20-token-revocation but doesn't seem to have added token-approval-revocation in its place, even though that type still looks supported. Might just need one line added back so the example stays accurate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think this example needs to include all implemented permission types - this is showing how the controller may be instantiated with a list of permission types that should be supported.

This list can be incomplete - it's actually highlighting the capability to restrict supported permissions, but also we probably don't want to update this every time we add permission types to the dependency.

@@ -1,11 +1,9 @@
import type { DeployedContractsByName } from '@metamask/7715-permission-types';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Noticed DeployedContractsByName moved from the precise local alias (typeof DELEGATOR_CONTRACTS)[number][number] to the package's Record<string, Hex>. Not a big deal, but it does mean a typo'd contract name would only surface at runtime (via the Contract not found throw) rather than at compile time like before. Wanted to flag in case that tradeoff wasn't deliberate.

@@ -9,12 +9,8 @@ import type {
ApprovalRevocationTerms,
Caveat,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

While in here — it looks like Erc20TokenAllowancePermission, NativeTokenAllowancePermission, and TokenApprovalRevocationPermission (lines 23, 40, 53 below) are still declared locally with a "not yet defined in the package" comment, but @metamask/7715-permission-types@^0.8.0 seems to export all three now (worth double-checking, since the local TokenApprovalRevocationPermission shape looks slightly different from the package's version). If the package really does cover these now, importing them directly would avoid future drift.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call - I've removed the 3 locally defined permission types, along with ExtendedPermissionTypes

import { makeErc20TokenPeriodicDecoderConfig } from './erc20TokenPeriodic';
import { makeErc20TokenRevocationDecoderConfig } from './erc20TokenRevocation';
import { makeErc20TokenStreamDecoderConfig } from './erc20TokenStream';
import { makePermissionDecoderConfigs } from '@metamask/7715-permission-types';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just flagging for awareness — with per-type validation logic now living in @metamask/7715-permission-types, this package's tests only exercise a synthetic specified-permission-type rather than the real permission types end-to-end. Might be worth a lightweight integration test here (or confirming coverage exists upstream) so a future bump of the dependency that loosens a validation rule wouldn't slip by unnoticed.

@@ -1,45 +1,22 @@
import type { Rule } from '@metamask/7715-permission-types';
import type {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Small one — enforcer addresses look like they get checksummed once for matching, then re-checksummed again per candidate decoder inside validateAndDecodePermission on the ambiguous-type path. Probably not costly today, but could be worth reusing the already-checksummed set if this path gets exercised more.

@@ -9,12 +9,8 @@ import type {
ApprovalRevocationTerms,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

RuleDecoder looks like it's only referenced from a test file now, not from any production decoder — the real shape seems to live in the package's PermissionDecoderConfig. If that's right, might be simpler to move it into the test file (or drop it) so it doesn't read as something production code still relies on.

import type { ChecksumEnforcersByChainId } from './types';

/**
* The names of the enforcer contracts for each permission type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit — ENFORCER_CONTRACT_NAMES maps each key to an identical string value, so getChecksumEnforcersByChainId ends up repeating the same 3-line pattern 12 times. Could probably just use the string literals directly and drop the map, but totally optional.

@jeffsmale90
jeffsmale90 force-pushed the chore/permission_decoding_externalised_permissions branch 3 times, most recently from a4ef722 to 7bc7040 Compare July 21, 2026 02:26
@jeffsmale90
jeffsmale90 force-pushed the chore/permission_decoding_externalised_permissions branch from 7bc7040 to 7cbbc65 Compare July 21, 2026 02:46
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