1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/components/app
Erik Marks 31cf7c10a4
Permission System 2.0 (#12243)
# Permission System 2.0

## Background

This PR migrates the extension permission system to [the new `PermissionController`](https://github.com/MetaMask/snaps-skunkworks/tree/main/packages/controllers/src/permissions).
The original permission system, based on [`rpc-cap`](https://github.com/MetaMask/rpc-cap), introduced [`ZCAP-LD`](https://w3c-ccg.github.io/zcap-ld/)-like permissions to our JSON-RPC stack.
We used it to [implement](https://github.com/MetaMask/metamask-extension/pull/7004) what we called "LoginPerSite" in [version 7.7.0](https://github.com/MetaMask/metamask-extension/releases/tag/v7.7.0) of the extension, which enabled the user to choose which accounts, if any, should be exposed to each dapp.
While that was a worthwhile feature in and of itself, we wanted a permission _system_ in order to enable everything we are going to with Snaps.
Unfortunately, the original permission system was difficult to use, and necessitated the creation of the original `PermissionsController` (note the "s"), which was more or less a wrapper for `rpc-cap`.

With this PR, we shake off the yoke of the original permission system, in favor of the modular, self-contained, ergonomic, and more mature permission system 2.0.

Note that [the `PermissionController` readme](https://github.com/MetaMask/snaps-skunkworks/tree/main/packages/controllers/src/permissions/README.md) explains how the new permission system works.

The `PermissionController` and `SubjectMetadataController` are currently shipped via `@metamask/snap-controllers`. This is a temporary state of affairs, and we'll move them to `@metamask/controllers` once they've landed in prod.

## Changes in Detail

First, the changes in this PR are not as big as they seem. Roughly half of the additions in this PR are fixtures in the test for the new migration (number 68), and a significant portion of the remaining ~2500 lines are due to find-and-replace changes in other test fixtures and UI files.

- The extension `PermissionsController` has been deleted, and completely replaced with the new `PermissionController` from [`@metamask/snap-controllers`](https://www.npmjs.com/package/@metamask/snap-controllers).
- The original `PermissionsController` "domain metadata" functionality is now managed by the new `SubjectMetadataController`, also from [`@metamask/snap-controllers`](https://www.npmjs.com/package/@metamask/snap-controllers).
- The permission activity and history log controller has been renamed `PermissionLogController` and has its own top-level state key, but is otherwise functionally equivalent to the existing implementation.
- Migration number 68 has been added to account for the new state changes.
- The tests in `app/scripts/controllers/permissions` have been migrated from `mocha` to `jest`.

Reviewers should focus their attention on the following files:

- `app/scripts/`
  - `metamask-controller.js`
    - This is where most of the integration work for the new `PermissionController` occurs.
      Some functions that were internal to the original controller were moved here.
  - `controllers/permissions/`
    - `selectors.js`
      - These selectors are for `ControllerMessenger` selector subscriptions. The actual subscriptions occur in `metamask-controller.js`. See the `ControllerMessenger` implementation for details.
    - `specifications.js`
      - The caveat and permission specifications are required by the new `PermissionController`, and are used to specify the `eth_accounts` permission and its JSON-RPC method implementation.
        See the `PermissionController` readme for details.
  - `migrations/068.js`
    - The new state should be cross-referenced with the controllers that manage it.
      The accompanying tests should also be thoroughly reviewed.

Some files may appear new but have just moved and/or been renamed:

- `app/scripts/lib/rpc-method-middleware/handlers/request-accounts.js`
  - This was previously implemented in `controllers/permissions/permissionsMethodMiddleware.js`.
- `test/mocks/permissions.js`
  - A truncated version of `test/mocks/permission-controller.js`.

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2021-12-06 19:16:49 -08:00
..
account-list-item Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
account-menu Permission System 2.0 (#12243) 2021-12-06 19:16:49 -08:00
advanced-gas-controls Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
advanced-gas-fee-popover Adding validations for advance gas fee input fields (#12879) 2021-12-07 00:17:26 +05:30
alerts Permission System 2.0 (#12243) 2021-12-06 19:16:49 -08:00
app-header Remove the partially-applied dark mode styles used for beta (#12489) 2021-10-28 17:29:20 -02:30
asset-list Hiding refresh list on non-Mainnet networks (#12210) 2021-09-27 13:42:51 -04:00
asset-list-item Using design system breakpoint values across ui/ 2021-09-11 11:00:46 -07:00
cancel-button UX Papercuts Epic: Create a consistent representation of the Buttons (#12096) 2021-10-05 15:20:42 -04:00
collectibles-items Revert "Feat/collectibles display (#12873)" (#12934) 2021-12-01 17:46:26 -06:00
collectibles-tab Revert "Feat/collectibles display (#12873)" (#12934) 2021-12-01 17:46:26 -06:00
confirm-page-container Feature: Transaction Insights (#12881) 2021-12-01 13:52:08 -03:30
connected-accounts-list remove the ui/app and ui/lib folders (#10911) 2021-04-28 14:53:59 -05:00
connected-accounts-permissions remove the ui/app and ui/lib folders (#10911) 2021-04-28 14:53:59 -05:00
connected-sites-list Permission System 2.0 (#12243) 2021-12-06 19:16:49 -08:00
connected-status-indicator Permission System 2.0 (#12243) 2021-12-06 19:16:49 -08:00
contact-list Use ternary conditionals instead of && (#12406) 2021-10-21 11:11:31 -05:00
dropdowns Ensure one and only one localhost option appears in network list (#12786) 2021-11-22 12:54:42 -03:30
edit-gas-display Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
edit-gas-display-education Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
edit-gas-fee-button Using EIP-1559 V2 for approve transaction flow (#12906) 2021-12-06 22:09:35 +05:30
edit-gas-fee-popover Adding validations for advance gas fee input fields (#12879) 2021-12-07 00:17:26 +05:30
edit-gas-popover Fix isMainnet propType error (#12951) 2021-12-02 14:46:46 -03:30
flask Adding snaps authorship pill (#12740) 2021-12-01 17:45:55 -05:00
gas-customization Support for Layer 2 networks with transaction fees on both layers (#12658) 2021-11-11 13:16:45 -03:30
gas-timing Adding gas limit section on advance gas fee modal (#12865) 2021-12-03 21:29:48 +05:30
home-notification UX Papercuts Epic: Create a consistent representation of the Buttons (#12096) 2021-10-05 15:20:42 -04:00
import-token-link Hiding refresh list on non-Mainnet networks (#12210) 2021-09-27 13:42:51 -04:00
info-box remove the ui/app and ui/lib folders (#10911) 2021-04-28 14:53:59 -05:00
ledger-instruction-field Check if ledger was successfully able to establish transport on confirm screen mount (#12535) 2021-11-04 15:49:53 -02:30
loading-network-screen UX Papercuts Epic: Create a consistent representation of the Buttons (#12096) 2021-10-05 15:20:42 -04:00
menu-bar changed the order of items (#12384) 2021-10-18 12:27:59 -02:30
metamask-template-renderer Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
metamask-translation Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
modal Use ternary conditionals instead of && (#12406) 2021-10-21 11:11:31 -05:00
modals Feature: Transaction Insights (#12881) 2021-12-01 13:52:08 -03:30
multilayer-fee-message Adds multilayer fee display to erc20 token approval screen (#12824) 2021-11-29 13:23:37 -03:30
multiple-notifications Fixing breakpoint fallthroughs 2021-09-11 11:13:36 -07:00
network-display Implement Network Switcher designs (#12260) 2021-10-28 23:31:05 +04:00
new-collectibles-notice Adding new nfts detected notice (#12721) 2021-11-18 11:30:56 -07:00
permission-page-container Permission System 2.0 (#12243) 2021-12-06 19:16:49 -08:00
permissions-connect-footer Updating dapp learn more link (#12515) 2021-10-28 12:18:48 -07:00
permissions-connect-header Added SiteOrigin and PermissionList components (#12832) 2021-12-02 18:22:18 +01:00
permissions-connect-permission-list Added SiteOrigin and PermissionList components (#12832) 2021-12-02 18:22:18 +01:00
qr-hardware-popover Introduce QR based signer into MetaMask (#12065) 2021-11-23 13:58:39 -03:30
recovery-phrase-reminder UX Papercuts Epic: Create a consistent representation of the Buttons (#12096) 2021-10-05 15:20:42 -04:00
selected-account Fixing address truncation papercuts (#12330) 2021-10-13 12:54:48 -05:00
signature-request Fix signature request propTypes (#12952) 2021-12-02 14:39:18 -03:30
signature-request-original Permission System 2.0 (#12243) 2021-12-06 19:16:49 -08:00
step-progress-bar Onboarding V2 Cleanups (#12417) 2021-10-20 13:55:59 -05:00
tab-bar Update icons on the settings page (#12359) 2021-10-29 09:25:23 -02:30
token-cell Integrate TokensController (#11552) 2021-09-10 12:37:19 -05:00
token-list Integrate TokensController (#11552) 2021-09-10 12:37:19 -05:00
transaction-activity-log Support for Layer 2 networks with transaction fees on both layers (#12658) 2021-11-11 13:16:45 -03:30
transaction-breakdown Feature: Transaction Insights (#12881) 2021-12-01 13:52:08 -03:30
transaction-decoding Feature: Transaction Insights (#12881) 2021-12-01 13:52:08 -03:30
transaction-detail Using EIP-1559 V2 for approve transaction flow (#12906) 2021-12-06 22:09:35 +05:30
transaction-detail-item Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
transaction-icon Adding method to capture one-time Sentry exceptions (#11553) 2021-07-22 16:13:40 -07:00
transaction-list Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
transaction-list-item Feature: Transaction Insights (#12881) 2021-12-01 13:52:08 -03:30
transaction-list-item-details Feature: Transaction Insights (#12881) 2021-12-01 13:52:08 -03:30
transaction-status Feature: Transaction Insights (#12881) 2021-12-01 13:52:08 -03:30
transaction-total-banner Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
user-preferenced-currency-display Add Approval Confirmation Screen component to Storybook (#10998) 2021-05-25 08:20:09 +08:00
user-preferenced-currency-input remove the ui/app and ui/lib folders (#10911) 2021-04-28 14:53:59 -05:00
user-preferenced-token-input remove the ui/app and ui/lib folders (#10911) 2021-04-28 14:53:59 -05:00
wallet-overview Create function for hardware keyring checking (#12457) 2021-10-27 18:54:18 -05:00
whats-new-popup Ledger WebHID What's New popup (#12501) 2021-11-03 20:05:39 -02:30
app-components.scss Using EIP-1559 V2 for approve transaction flow (#12906) 2021-12-06 22:09:35 +05:30
menu-droppo.js remove the ui/app and ui/lib folders (#10911) 2021-04-28 14:53:59 -05:00