Skip to content

Commit

Permalink
Accept SignController approval request from frontend (MetaMask#19184)
Browse files Browse the repository at this point in the history
  • Loading branch information
OGPoyraz authored Jun 20, 2023
1 parent b247f27 commit 39089e0
Show file tree
Hide file tree
Showing 25 changed files with 281 additions and 848 deletions.

This file was deleted.

2 changes: 1 addition & 1 deletion app/scripts/controllers/decrypt-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type CoreMessage = AbstractMessage & {
};

export type StateMessage = Required<
Omit<AbstractMessage, 'securityProviderResponse' | 'metadata'>
Omit<AbstractMessage, 'securityProviderResponse' | 'metadata' | 'error'>
>;

export type DecryptMessageControllerState = {
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/controllers/encryption-public-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type CoreMessage = AbstractMessage & {
};

export type StateMessage = Required<
Omit<AbstractMessage, 'securityProviderResponse' | 'metadata'>
Omit<AbstractMessage, 'securityProviderResponse' | 'metadata' | 'error'>
> & {
msgParams: string;
};
Expand Down
27 changes: 1 addition & 26 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1268,11 +1268,7 @@ export default class MetamaskController extends EventEmitter {
this.signatureController = new SignatureController({
messenger: this.controllerMessenger.getRestricted({
name: 'SignatureController',
allowedActions: [
`${this.approvalController.name}:addRequest`,
`${this.approvalController.name}:acceptRequest`,
`${this.approvalController.name}:rejectRequest`,
],
allowedActions: [`${this.approvalController.name}:addRequest`],
}),
keyringController: this.keyringController,
isEthSignEnabled: () =>
Expand Down Expand Up @@ -2258,27 +2254,6 @@ export default class MetamaskController extends EventEmitter {
updatePreviousGasParams:
txController.updatePreviousGasParams.bind(txController),

// signatureController
signMessage: this.signatureController.signMessage.bind(
this.signatureController,
),
cancelMessage: this.signatureController.cancelMessage.bind(
this.signatureController,
),
signPersonalMessage: this.signatureController.signPersonalMessage.bind(
this.signatureController,
),
cancelPersonalMessage:
this.signatureController.cancelPersonalMessage.bind(
this.signatureController,
),
signTypedMessage: this.signatureController.signTypedMessage.bind(
this.signatureController,
),
cancelTypedMessage: this.signatureController.cancelTypedMessage.bind(
this.signatureController,
),

// decryptMessageController
decryptMessage: this.decryptMessageController.decryptMessage.bind(
this.decryptMessageController,
Expand Down
3 changes: 2 additions & 1 deletion lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,8 @@
"browserify>buffer": true,
"browserify>events": true,
"eth-rpc-errors": true,
"ethereumjs-util": true
"ethereumjs-util": true,
"lodash": true
}
},
"@metamask/smart-transactions-controller": {
Expand Down
3 changes: 2 additions & 1 deletion lavamoat/browserify/desktop/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,8 @@
"browserify>buffer": true,
"browserify>events": true,
"eth-rpc-errors": true,
"ethereumjs-util": true
"ethereumjs-util": true,
"lodash": true
}
},
"@metamask/smart-transactions-controller": {
Expand Down
3 changes: 2 additions & 1 deletion lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,8 @@
"browserify>buffer": true,
"browserify>events": true,
"eth-rpc-errors": true,
"ethereumjs-util": true
"ethereumjs-util": true,
"lodash": true
}
},
"@metamask/smart-transactions-controller": {
Expand Down
3 changes: 2 additions & 1 deletion lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,8 @@
"browserify>buffer": true,
"browserify>events": true,
"eth-rpc-errors": true,
"ethereumjs-util": true
"ethereumjs-util": true,
"lodash": true
}
},
"@metamask/smart-transactions-controller": {
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@
"fast-json-patch@^3.1.1": "patch:fast-json-patch@npm%3A3.1.1#./.yarn/patches/fast-json-patch-npm-3.1.1-7e8bb70a45.patch",
"request@^2.83.0": "patch:request@npm%3A2.88.2#./.yarn/patches/request-npm-2.88.2-f4a57c72c4.patch",
"request@^2.88.2": "patch:request@npm%3A2.88.2#./.yarn/patches/request-npm-2.88.2-f4a57c72c4.patch",
"request@^2.85.0": "patch:request@npm%3A2.88.2#./.yarn/patches/request-npm-2.88.2-f4a57c72c4.patch",
"@metamask/signature-controller@^3.0.0": "patch:@metamask/signature-controller@npm%3A3.0.0#./.yarn/patches/@metamask-signature-controller-npm-3.0.0-8771b6885e.patch"
"request@^2.85.0": "patch:request@npm%3A2.88.2#./.yarn/patches/request-npm-2.88.2-f4a57c72c4.patch"
},
"dependencies": {
"@actions/core": "^1.10.0",
Expand Down Expand Up @@ -249,7 +248,7 @@
"@metamask/jazzicon": "^2.0.0",
"@metamask/key-tree": "^7.0.0",
"@metamask/logo": "^3.1.1",
"@metamask/message-manager": "^6.0.0",
"@metamask/message-manager": "^7.0.0",
"@metamask/metamask-eth-abis": "^3.0.0",
"@metamask/notification-controller": "^3.0.0",
"@metamask/obs-store": "^8.1.0",
Expand All @@ -262,7 +261,7 @@
"@metamask/rpc-methods-flask": "npm:@metamask/[email protected]",
"@metamask/safe-event-emitter": "^2.0.0",
"@metamask/scure-bip39": "^2.0.3",
"@metamask/signature-controller": "^3.0.0",
"@metamask/signature-controller": "^4.0.1",
"@metamask/slip44": "^3.0.0",
"@metamask/smart-transactions-controller": "^3.1.0",
"@metamask/snaps-controllers": "^0.32.2",
Expand Down
32 changes: 9 additions & 23 deletions ui/components/app/qr-hardware-popover/qr-hardware-popover.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import React, { useCallback, useMemo, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { ethErrors, serializeError } from 'eth-rpc-errors';
import { getCurrentQRHardwareState } from '../../../selectors';
import Popover from '../../ui/popover';
import { useI18nContext } from '../../../hooks/useI18nContext';
import {
cancelSyncQRHardware as cancelSyncQRHardwareAction,
cancelQRHardwareSignRequest as cancelQRHardwareSignRequestAction,
cancelTx,
cancelPersonalMsg,
cancelMsg,
cancelTypedMsg,
rejectPendingApproval,
} from '../../../store/actions';
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
import QRHardwareWalletImporter from './qr-hardware-wallet-importer';
import QRHardwareSignRequest from './qr-hardware-sign-request';

Expand Down Expand Up @@ -43,25 +41,13 @@ const QRHardwarePopover = () => {
);

const signRequestCancel = useCallback(() => {
let action = cancelTx;
switch (_txData.type) {
case MESSAGE_TYPE.PERSONAL_SIGN: {
action = cancelPersonalMsg;
break;
}
case MESSAGE_TYPE.ETH_SIGN: {
action = cancelMsg;
break;
}
case MESSAGE_TYPE.ETH_SIGN_TYPED_DATA: {
action = cancelTypedMsg;
break;
}
default: {
action = cancelTx;
}
}
dispatch(action(_txData));
dispatch(
rejectPendingApproval(
_txData.id,
serializeError(ethErrors.provider.userRejectedRequest()),
),
);
dispatch(cancelTx(_txData));
dispatch(cancelQRHardwareSignRequestAction());
}, [dispatch, _txData]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const SignatureRequestOriginalWarning = ({
<Button
className="signature-request-warning__footer__sign-button"
type="danger-primary"
data-testid="signature-warning-sign-button"
onClick={onSubmit}
>
{t('sign')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { ObjectInspector } from 'react-inspector';
import { ethErrors, serializeError } from 'eth-rpc-errors';
import LedgerInstructionField from '../ledger-instruction-field';
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
import {
Expand Down Expand Up @@ -49,18 +50,19 @@ export default class SignatureRequestOriginal extends Component {
address: PropTypes.string.isRequired,
name: PropTypes.string,
}).isRequired,
cancel: PropTypes.func.isRequired,
clearConfirmTransaction: PropTypes.func.isRequired,
history: PropTypes.object.isRequired,
mostRecentOverviewPage: PropTypes.string.isRequired,
sign: PropTypes.func.isRequired,
txData: PropTypes.object.isRequired,
subjectMetadata: PropTypes.object,
hardwareWalletRequiresConnection: PropTypes.bool,
isLedgerWallet: PropTypes.bool,
messagesCount: PropTypes.number,
showRejectTransactionsConfirmationModal: PropTypes.func.isRequired,
cancelAll: PropTypes.func.isRequired,
cancelAllApprovals: PropTypes.func.isRequired,
rejectPendingApproval: PropTypes.func.isRequired,
resolvePendingApproval: PropTypes.func.isRequired,
completedTx: PropTypes.func.isRequired,
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
selectedAccount: PropTypes.object,
///: END:ONLY_INCLUDE_IN
Expand Down Expand Up @@ -230,50 +232,68 @@ export default class SignatureRequestOriginal extends Component {
);
};

onSubmit = async (event) => {
const { clearConfirmTransaction, history, mostRecentOverviewPage, sign } =
this.props;
onSubmit = async () => {
const {
clearConfirmTransaction,
history,
mostRecentOverviewPage,
resolvePendingApproval,
completedTx,
txData: { id },
} = this.props;

await sign(event);
await resolvePendingApproval(id);
completedTx(id);
clearConfirmTransaction();
history.push(mostRecentOverviewPage);
};

onCancel = async (event) => {
const { clearConfirmTransaction, history, mostRecentOverviewPage, cancel } =
this.props;
onCancel = async () => {
const {
clearConfirmTransaction,
history,
mostRecentOverviewPage,
rejectPendingApproval,
txData: { id },
} = this.props;

await cancel(event);
await rejectPendingApproval(
id,
serializeError(ethErrors.provider.userRejectedRequest()),
);
clearConfirmTransaction();
history.push(mostRecentOverviewPage);
};

renderFooter = () => {
const {
cancel,
sign,
clearConfirmTransaction,
history,
mostRecentOverviewPage,
txData: { type },
txData: { type, id },
hardwareWalletRequiresConnection,
rejectPendingApproval,
resolvePendingApproval,
} = this.props;
const { t } = this.context;

return (
<PageContainerFooter
cancelText={t('reject')}
submitText={t('sign')}
onCancel={async (event) => {
await cancel(event);
onCancel={async () => {
await rejectPendingApproval(
id,
serializeError(ethErrors.provider.userRejectedRequest()),
);
clearConfirmTransaction();
history.push(mostRecentOverviewPage);
}}
onSubmit={async (event) => {
onSubmit={async () => {
if (type === MESSAGE_TYPE.ETH_SIGN) {
this.setState({ showSignatureRequestWarning: true });
} else {
await sign(event);
await resolvePendingApproval(id);
clearConfirmTransaction();
history.push(mostRecentOverviewPage);
}
Expand All @@ -285,19 +305,19 @@ export default class SignatureRequestOriginal extends Component {

handleCancelAll = () => {
const {
cancelAll,
clearConfirmTransaction,
history,
mostRecentOverviewPage,
showRejectTransactionsConfirmationModal,
messagesCount,
cancelAllApprovals,
} = this.props;
const unapprovedTxCount = messagesCount;

showRejectTransactionsConfirmationModal({
unapprovedTxCount,
onSubmit: async () => {
await cancelAll();
await cancelAllApprovals();
clearConfirmTransaction();
history.push(mostRecentOverviewPage);
},
Expand Down
Loading

0 comments on commit 39089e0

Please sign in to comment.