2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2023-02-24 19:58:42 +01:00
|
|
|
import log from 'loglevel';
|
2020-02-19 19:24:16 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import AccountListItem from '../../components/app/account-list-item';
|
|
|
|
import Identicon from '../../components/ui/identicon';
|
2023-01-23 16:22:12 +01:00
|
|
|
import { PageContainerFooter } from '../../components/ui/page-container';
|
2020-03-06 22:34:56 +01:00
|
|
|
|
2023-04-03 17:31:04 +02:00
|
|
|
import { MetaMetricsEventCategory } from '../../../shared/constants/metametrics';
|
2022-05-20 16:35:18 +02:00
|
|
|
import SiteOrigin from '../../components/ui/site-origin';
|
2023-01-24 15:44:49 +01:00
|
|
|
import { Numeric } from '../../../shared/modules/Numeric';
|
|
|
|
import { EtherDenomination } from '../../../shared/constants/common';
|
2023-03-08 17:05:55 +01:00
|
|
|
import { formatCurrency } from '../../helpers/utils/confirm-tx.util';
|
|
|
|
import { getValueFromWeiHex } from '../../../shared/modules/conversion.utils';
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
export default class ConfirmEncryptionPublicKey extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func.isRequired,
|
2022-03-29 15:46:24 +02:00
|
|
|
trackEvent: PropTypes.func.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
2020-03-06 22:34:56 +01:00
|
|
|
fromAccount: PropTypes.shape({
|
|
|
|
address: PropTypes.string.isRequired,
|
|
|
|
balance: PropTypes.string,
|
|
|
|
name: PropTypes.string,
|
|
|
|
}).isRequired,
|
2020-02-19 19:24:16 +01:00
|
|
|
clearConfirmTransaction: PropTypes.func.isRequired,
|
|
|
|
cancelEncryptionPublicKey: PropTypes.func.isRequired,
|
|
|
|
encryptionPublicKey: PropTypes.func.isRequired,
|
|
|
|
history: PropTypes.object.isRequired,
|
|
|
|
requesterAddress: PropTypes.string,
|
|
|
|
txData: PropTypes.object,
|
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-07 04:16:49 +01:00
|
|
|
subjectMetadata: PropTypes.object,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
2021-06-10 19:49:14 +02:00
|
|
|
nativeCurrency: PropTypes.string.isRequired,
|
2023-03-08 17:05:55 +01:00
|
|
|
currentCurrency: PropTypes.string.isRequired,
|
|
|
|
conversionRate: PropTypes.number,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
renderHeader = () => {
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__header">
|
|
|
|
<div className="request-encryption-public-key__header-background" />
|
|
|
|
|
|
|
|
<div className="request-encryption-public-key__header__text">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.context.t('encryptionPublicKeyRequest')}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="request-encryption-public-key__header__tip-container">
|
|
|
|
<div className="request-encryption-public-key__header__tip" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
renderAccount = () => {
|
2021-07-20 18:29:38 +02:00
|
|
|
const { fromAccount } = this.props;
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__account">
|
|
|
|
<div className="request-encryption-public-key__account-text">
|
2020-11-03 00:41:28 +01:00
|
|
|
{`${t('account')}:`}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="request-encryption-public-key__account-item">
|
2020-11-03 00:41:28 +01:00
|
|
|
<AccountListItem account={fromAccount} />
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
renderBalance = () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
2023-03-08 17:05:55 +01:00
|
|
|
conversionRate,
|
2021-07-20 18:29:38 +02:00
|
|
|
nativeCurrency,
|
2023-03-08 17:05:55 +01:00
|
|
|
currentCurrency,
|
2020-11-03 00:41:28 +01:00
|
|
|
fromAccount: { balance },
|
2021-07-20 18:29:38 +02:00
|
|
|
} = this.props;
|
|
|
|
const { t } = this.context;
|
2020-02-19 19:24:16 +01:00
|
|
|
|
2023-03-08 17:05:55 +01:00
|
|
|
const nativeCurrencyBalance = conversionRate
|
|
|
|
? formatCurrency(
|
|
|
|
getValueFromWeiHex({
|
|
|
|
value: balance,
|
|
|
|
fromCurrency: nativeCurrency,
|
|
|
|
toCurrency: currentCurrency,
|
|
|
|
conversionRate,
|
|
|
|
numberOfDecimals: 6,
|
|
|
|
toDenomination: EtherDenomination.ETH,
|
|
|
|
}),
|
|
|
|
currentCurrency,
|
|
|
|
)
|
|
|
|
: new Numeric(balance, 16, EtherDenomination.WEI)
|
|
|
|
.toDenomination(EtherDenomination.ETH)
|
|
|
|
.round(6)
|
|
|
|
.toBase(10)
|
|
|
|
.toString();
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__balance">
|
|
|
|
<div className="request-encryption-public-key__balance-text">
|
2020-11-03 00:41:28 +01:00
|
|
|
{`${t('balance')}:`}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
<div className="request-encryption-public-key__balance-value">
|
2023-03-08 17:05:55 +01:00
|
|
|
{`${nativeCurrencyBalance} ${
|
|
|
|
conversionRate ? currentCurrency?.toUpperCase() : nativeCurrency
|
|
|
|
}`}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
renderRequestIcon = () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { requesterAddress } = this.props;
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__request-icon">
|
2020-11-03 00:41:28 +01:00
|
|
|
<Identicon diameter={40} address={requesterAddress} />
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
renderAccountInfo = () => {
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__account-info">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderAccount()}
|
|
|
|
{this.renderRequestIcon()}
|
|
|
|
{this.renderBalance()}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
renderBody = () => {
|
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-07 04:16:49 +01:00
|
|
|
const { subjectMetadata, txData } = this.props;
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
2020-02-19 19:24:16 +01:00
|
|
|
|
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-07 04:16:49 +01:00
|
|
|
const targetSubjectMetadata = subjectMetadata[txData.origin];
|
2022-05-20 16:35:18 +02:00
|
|
|
const notice = t('encryptionPublicKeyNotice', [
|
|
|
|
<SiteOrigin siteOrigin={txData.origin} key={txData.origin} />,
|
|
|
|
]);
|
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-07 04:16:49 +01:00
|
|
|
const name = targetSubjectMetadata?.hostname || txData.origin;
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__body">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderAccountInfo()}
|
|
|
|
<div className="request-encryption-public-key__visual">
|
2020-02-19 19:24:16 +01:00
|
|
|
<section>
|
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-07 04:16:49 +01:00
|
|
|
{targetSubjectMetadata?.iconUrl ? (
|
2020-02-19 19:24:16 +01:00
|
|
|
<img
|
|
|
|
className="request-encryption-public-key__visual-identicon"
|
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-07 04:16:49 +01:00
|
|
|
src={targetSubjectMetadata.iconUrl}
|
2020-11-11 16:38:15 +01:00
|
|
|
alt=""
|
2020-02-19 19:24:16 +01:00
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<i className="request-encryption-public-key__visual-identicon--default">
|
2021-01-13 02:52:58 +01:00
|
|
|
{name.charAt(0).toUpperCase()}
|
2020-02-19 19:24:16 +01:00
|
|
|
</i>
|
|
|
|
)}
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="request-encryption-public-key__notice">
|
|
|
|
{notice}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
renderFooter = () => {
|
2020-06-01 19:54:32 +02:00
|
|
|
const {
|
|
|
|
cancelEncryptionPublicKey,
|
|
|
|
clearConfirmTransaction,
|
|
|
|
encryptionPublicKey,
|
|
|
|
history,
|
|
|
|
mostRecentOverviewPage,
|
|
|
|
txData,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2022-03-29 15:46:24 +02:00
|
|
|
const { t, trackEvent } = this.context;
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
return (
|
2023-01-23 16:22:12 +01:00
|
|
|
<PageContainerFooter
|
|
|
|
cancelText={t('cancel')}
|
|
|
|
submitText={t('provide')}
|
|
|
|
onCancel={async (event) => {
|
|
|
|
await cancelEncryptionPublicKey(txData, event);
|
|
|
|
trackEvent({
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Messages,
|
2023-01-23 16:22:12 +01:00
|
|
|
event: 'Cancel',
|
|
|
|
properties: {
|
|
|
|
action: 'Encryption public key Request',
|
|
|
|
legacy_event: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
clearConfirmTransaction();
|
|
|
|
history.push(mostRecentOverviewPage);
|
|
|
|
}}
|
|
|
|
onSubmit={async (event) => {
|
|
|
|
await encryptionPublicKey(txData, event);
|
|
|
|
this.context.trackEvent({
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Messages,
|
2023-01-23 16:22:12 +01:00
|
|
|
event: 'Confirm',
|
|
|
|
properties: {
|
|
|
|
action: 'Encryption public key Request',
|
|
|
|
legacy_event: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
clearConfirmTransaction();
|
|
|
|
history.push(mostRecentOverviewPage);
|
|
|
|
}}
|
|
|
|
/>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
render = () => {
|
2023-02-24 19:58:42 +01:00
|
|
|
if (!this.props.txData) {
|
|
|
|
log.warn('ConfirmEncryptionPublicKey Page: Missing txData prop.');
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-02-19 19:24:16 +01:00
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__container">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderHeader()}
|
|
|
|
{this.renderBody()}
|
|
|
|
{this.renderFooter()}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
}
|