Commit b7c2567
authored
refactor: decompose rule decoders, and refactor permission decoding (#8730)
## Explanation
Refactor of permission decoding logic in order to:
- clarify terminology (`decoders` rather than `rules` - rule is a highly
overloaded term)
- make rule (as in 7155 rules) more composable, rather than inherently
part of the decoding process
- prepare the permission decoders for potential decomposition into a
separate package
no functional change, therefore no changelog required
<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:
* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->
## References
<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?
For example:
* Fixes #12345
* Related to #67890
-->
## 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](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Refactors the core permission identification/decoding path (rule
matching, validation, and reconstructed output), so subtle mismatches in
enforcer selection or rule extraction could change which permission type
is detected or what `rules`/`expiry` are returned.
>
> **Overview**
> Refactors permission decoding to use **permission decoders**
(terminology change from “rules”) and removes the old
`decodePermission/rules` implementation, including
`findRuleWithMatchingCaveatAddresses`.
>
> Decoding is now driven by `createPermissionDecodersForContracts` +
`findDecodersWithMatchingCaveatAddresses` and disambiguation via
`selectUniqueDecoderAndDecodedPermission`, with rule extraction split
into composable `RuleDecoder`s (new `expiry`, `redeemer`, and
native/ERC20 `payee` decoders).
>
> Adds `EXECUTION_PERMISSION_EXPIRY_RULE_TYPE` and updates tests to
reflect the new decoder APIs and to assert the new rule decoding
behavior (including emitting an `expiry` rule and hoisting its timestamp
to top-level `expiry`).
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
f097d31. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 1142f20 commit b7c2567
35 files changed
Lines changed: 1541 additions & 1155 deletions
File tree
- packages/gator-permissions-controller/src
- decodePermission
- decoders
- rules
Lines changed: 12 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
| 33 | + | |
| 34 | + | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
592 | 592 | | |
593 | 593 | | |
594 | 594 | | |
595 | | - | |
| 595 | + | |
| 596 | + | |
596 | 597 | | |
597 | | - | |
598 | | - | |
599 | | - | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
600 | 601 | | |
601 | | - | |
| 602 | + | |
602 | 603 | | |
603 | 604 | | |
604 | 605 | | |
605 | | - | |
| 606 | + | |
606 | 607 | | |
607 | 608 | | |
608 | 609 | | |
609 | | - | |
610 | | - | |
| 610 | + | |
| 611 | + | |
611 | 612 | | |
612 | 613 | | |
613 | 614 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
0 commit comments