1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00
metamask-extension/ui/pages
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
..
add-collectible Revert "Feat/collectibles display (#12873)" (#12934) 2021-12-01 17:46:26 -06:00
asset Revert "Feat/collectibles display (#12873)" (#12934) 2021-12-01 17:46:26 -06:00
confirm-add-suggested-token Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
confirm-approve Permission System 2.0 (#12243) 2021-12-06 19:16:49 -08:00
confirm-decrypt-message Permission System 2.0 (#12243) 2021-12-06 19:16:49 -08:00
confirm-deploy-contract Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
confirm-encryption-public-key Permission System 2.0 (#12243) 2021-12-06 19:16:49 -08:00
confirm-import-token Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
confirm-send-ether Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
confirm-send-token Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
confirm-token-transaction-base Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
confirm-transaction Hardening property check for stopPropagation in ConfirmTxScreen (#12158) 2021-09-21 11:58:39 -07:00
confirm-transaction-base Remove redundant EIP_1559_V2_ENABLED comparison (#12954) 2021-12-06 11:23:02 -03:30
confirm-transaction-switch Replace hardcoded sent ether label on confirm screen (#11802) 2021-09-15 16:54:51 -05:00
confirmation Permission System 2.0 (#12243) 2021-12-06 19:16:49 -08:00
connected-accounts Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
connected-sites Permission System 2.0 (#12243) 2021-12-06 19:16:49 -08:00
create-account Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
error remove the ui/app and ui/lib folders (#10911) 2021-04-28 14:53:59 -05:00
first-time-flow Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
home Permission System 2.0 (#12243) 2021-12-06 19:16:49 -08:00
import-token Fix isMainnet propType error (#12951) 2021-12-02 14:46:46 -03:30
keychains Clear the clipboard after seed phrase is pasted (Restore vault) (#12987) 2021-12-06 12:17:56 -07:00
lock remove the ui/app and ui/lib folders (#10911) 2021-04-28 14:53:59 -05:00
mobile-sync Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
onboarding-flow Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
permissions-connect Permission System 2.0 (#12243) 2021-12-06 19:16:49 -08:00
routes Revert "Feat/collectibles display (#12873)" (#12934) 2021-12-01 17:46:26 -06:00
send Adding validations for advance gas fee input fields (#12879) 2021-12-07 00:17:26 +05:30
settings Latest update conversion date - issue #10741 (#12422) 2021-12-02 08:48:09 -03:30
swaps Organizing storybook to echo app folder structure (#12796) 2021-12-01 11:27:57 -08:00
unlock-page Fix unlock-page component for new Storybook format (#12894) 2021-12-06 15:08:13 -08:00
index.js remove the ui/app and ui/lib folders (#10911) 2021-04-28 14:53:59 -05:00
pages.scss Eip1559 v2 12593 (#12719) 2021-11-23 23:48:44 +05:30