Skip to content

Commit

Permalink
Merge branch 'develop' into ppom_updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri authored Jul 24, 2023
2 parents 8ed0d6b + 737173e commit 0449ff1
Show file tree
Hide file tree
Showing 162 changed files with 2,969 additions and 2,712 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/dist/SignatureController.js b/dist/SignatureController.js
index a2f064efa2a2700db00767daa4ce6bd22b1932c4..17edb51b6c526f27fb4c19f2d2fda3d7140c66b4 100644
--- a/dist/SignatureController.js
+++ b/dist/SignatureController.js
@@ -283,8 +283,11 @@ _SignatureController_keyringController = new WeakMap(), _SignatureController_isE
resultCallbacks = acceptResult.resultCallbacks;
}
catch (_a) {
+ signaturePromise.catch(() => {
+ // Expecting reject error but throwing manually rather than waiting
+ });
__classPrivateFieldGet(this, _SignatureController_instances, "m", _SignatureController_cancelAbstractMessage).call(this, messageManager, messageId);
- throw eth_rpc_errors_1.ethErrors.provider.userRejectedRequest('User rejected the request.');
+ throw eth_rpc_errors_1.ethErrors.provider.userRejectedRequest(`MetaMask ${messageName} Signature: User denied message signature.`);
}
yield signMessage(messageParamsWithId, signingOpts);
const signatureResult = yield signaturePromise;
@@ -305,7 +308,7 @@ _SignatureController_keyringController = new WeakMap(), _SignatureController_isE
return __awaiter(this, void 0, void 0, function* () {
return yield __classPrivateFieldGet(this, _SignatureController_instances, "m", _SignatureController_signAbstractMessage).call(this, __classPrivateFieldGet(this, _SignatureController_personalMessageManager, "f"), controller_utils_1.ApprovalType.PersonalSign, msgParams, (cleanMsgParams) => __awaiter(this, void 0, void 0, function* () { return yield __classPrivateFieldGet(this, _SignatureController_keyringController, "f").signPersonalMessage(cleanMsgParams); }));
});
-}, _SignatureController_signTypedMessage = function _SignatureController_signTypedMessage(msgParams,
+}, _SignatureController_signTypedMessage = function _SignatureController_signTypedMessage(msgParams,
/* istanbul ignore next */
opts = { parseJsonData: true }) {
return __awaiter(this, void 0, void 0, function* () {
31 changes: 31 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 55 additions & 19 deletions app/scripts/controllers/mmi-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import EventEmitter from 'events';
import log from 'loglevel';
import { captureException } from '@sentry/browser';
import { isEqual } from 'lodash';
import {
PersonalMessageManager,
TypedMessageManager,
} from '@metamask/message-manager';
import { CUSTODIAN_TYPES } from '@metamask-institutional/custody-keyring';
import {
updateCustodianTransactions,
Expand Down Expand Up @@ -48,20 +44,10 @@ export default class MMIController extends EventEmitter {
this.metaMetricsController = opts.metaMetricsController;
this.networkController = opts.networkController;
this.permissionController = opts.permissionController;
this.signatureController = opts.signatureController;
this.platform = opts.platform;
this.extension = opts.extension;

this.personalMessageManager = new PersonalMessageManager(
undefined,
undefined,
this.securityProviderRequest,
);
this.typedMessageManager = new TypedMessageManager(
undefined,
undefined,
this.securityProviderRequest,
);

// Prepare event listener after transactionUpdateController gets initiated
this.transactionUpdateController.prepareEventListener(
this.custodianEventHandlerFactory.bind(this),
Expand All @@ -87,6 +73,20 @@ export default class MMIController extends EventEmitter {
await this.prepareMmiPortfolio();
}, this.preferencesController.store.getState()),
);

this.signatureController.hub.on(
'personal_sign:signed',
async ({ signature, messageId }) => {
await this.handleSigningEvents(signature, messageId, 'personal');
},
);

this.signatureController.hub.on(
'eth_signTypedData:signed',
async ({ signature, messageId }) => {
await this.handleSigningEvents(signature, messageId, 'v4');
},
);
} // End of constructor

async persistKeyringsAfterRefreshTokenChange() {
Expand All @@ -111,8 +111,7 @@ export default class MMIController extends EventEmitter {
getState: () => this.getState(),
getPendingNonce: (address) => this.getPendingNonce(address),
setTxHash: (txId, txHash) => this.txController.setTxHash(txId, txHash),
typedMessageManager: this.typedMessageManager,
personalMessageManager: this.personalMessageManager,
signatureController: this.signatureController,
txStateManager: this.txController.txStateManager,
custodyController: this.custodyController,
trackTransactionEvent:
Expand Down Expand Up @@ -185,9 +184,10 @@ export default class MMIController extends EventEmitter {
keyring,
type,
txList,
getPendingNonce: this.getPendingNonce.bind(this),
getPendingNonce: (address) => this.getPendingNonce(address),
setTxHash: (txId, txHash) =>
this.txController.setTxHash(txId, txHash),
txStateManager: this.txController.txStateManager,
setTxHash: this.txController.setTxHash.bind(this.txController),
custodyController: this.custodyController,
transactionUpdateController: this.transactionUpdateController,
});
Expand Down Expand Up @@ -572,6 +572,42 @@ export default class MMIController extends EventEmitter {
}
}

async newUnsignedMessage(msgParams, req, version) {
const updatedMsgParams = { ...msgParams, deferSetAsSigned: true };

if (req.method.includes('eth_signTypedData')) {
return await this.signatureController.newUnsignedTypedMessage(
updatedMsgParams,
req,
version,
);
} else if (req.method.includes('personal_sign')) {
return await this.signatureController.newUnsignedPersonalMessage(
updatedMsgParams,
req,
);
}
return await this.signatureController.newUnsignedMessage(
updatedMsgParams,
req,
);
}

async handleSigningEvents(signature, messageId, signOperation) {
if (signature.custodian_transactionId) {
this.transactionUpdateController.addTransactionToWatchList(
signature.custodian_transactionId,
signature.from,
signOperation,
true,
);
}

this.signatureController.setMessageMetadata(messageId, signature);

return this.getState();
}

async setAccountAndNetwork(origin, address, chainId) {
await this.appStateController.getUnlockPromise(true);
const selectedAddress = this.preferencesController.getSelectedAddress();
Expand Down
15 changes: 15 additions & 0 deletions app/scripts/controllers/mmi-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { KeyringController } from '@metamask/eth-keyring-controller';
import { MmiConfigurationController } from '@metamask-institutional/custody-keyring';
import { TransactionUpdateController } from '@metamask-institutional/transaction-update';
import { SignatureController } from '@metamask/signature-controller';

import MMIController from './mmi-controller';
import TransactionController from './transactions';
Expand Down Expand Up @@ -33,6 +34,20 @@ describe('MMIController', function () {
getNetworkId: jest.fn(),
onNetworkStateChange: jest.fn(),
}),
signatureController: new SignatureController({
messenger: {
registerActionHandler: jest.fn(),
publish: jest.fn(),
call: jest.fn(),
},
keyringController: new KeyringController({
initState: {},
}),
isEthSignEnabled: jest.fn(),
getAllState: jest.fn(),
securityProviderRequest: jest.fn(),
getCurrentChainId: jest.fn(),
}),
preferencesController: new PreferencesController({
initState: {},
onInfuraIsBlocked: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/lib/setupSentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,6 @@ function toMetamaskUrl(origUrl) {
if (!filePath) {
return origUrl;
}
const metamaskUrl = `metamask${filePath}`;
const metamaskUrl = `/metamask${filePath}`;
return metamaskUrl;
}
72 changes: 45 additions & 27 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,16 +499,14 @@ export default class MetamaskController extends EventEmitter {
this.metaMetricsController.trackEvent({
event: MetaMetricsEventName.NftAdded,
category: MetaMetricsEventCategory.Wallet,
properties: {
sensitiveProperties: {
token_contract_address: address,
token_symbol: symbol,
asset_type: AssetType.NFT,
token_id: tokenId,
token_standard: standard,
asset_type: AssetType.NFT,
source,
},
sensitiveProperties: {
tokenId,
},
}),
},
{},
Expand Down Expand Up @@ -1196,28 +1194,6 @@ export default class MetamaskController extends EventEmitter {
}),
});

///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
this.mmiController = new MMIController({
mmiConfigurationController: this.mmiConfigurationController,
keyringController: this.keyringController,
txController: this.txController,
securityProviderRequest: this.securityProviderRequest.bind(this),
preferencesController: this.preferencesController,
appStateController: this.appStateController,
transactionUpdateController: this.transactionUpdateController,
custodyController: this.custodyController,
institutionalFeaturesController: this.institutionalFeaturesController,
getState: this.getState.bind(this),
getPendingNonce: this.getPendingNonce.bind(this),
accountTracker: this.accountTracker,
metaMetricsController: this.metaMetricsController,
networkController: this.networkController,
permissionController: this.permissionController,
platform: this.platform,
extension: this.extension,
});
///: END:ONLY_INCLUDE_IN

this.txController.on(`tx:status-update`, async (txId, status) => {
if (
status === TransactionStatus.confirmed ||
Expand Down Expand Up @@ -1379,6 +1355,29 @@ export default class MetamaskController extends EventEmitter {
},
);

///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
this.mmiController = new MMIController({
mmiConfigurationController: this.mmiConfigurationController,
keyringController: this.keyringController,
txController: this.txController,
securityProviderRequest: this.securityProviderRequest.bind(this),
preferencesController: this.preferencesController,
appStateController: this.appStateController,
transactionUpdateController: this.transactionUpdateController,
custodyController: this.custodyController,
institutionalFeaturesController: this.institutionalFeaturesController,
getState: this.getState.bind(this),
getPendingNonce: this.getPendingNonce.bind(this),
accountTracker: this.accountTracker,
metaMetricsController: this.metaMetricsController,
networkController: this.networkController,
permissionController: this.permissionController,
signatureController: this.signatureController,
platform: this.platform,
extension: this.extension,
});
///: END:ONLY_INCLUDE_IN

this.swapsController = new SwapsController(
{
getBufferedGasLimit:
Expand Down Expand Up @@ -1496,6 +1495,7 @@ export default class MetamaskController extends EventEmitter {
// tx signing
processTransaction: this.newUnapprovedTransaction.bind(this),
// msg signing
///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask)
processEthSignMessage: this.signatureController.newUnsignedMessage.bind(
this.signatureController,
),
Expand All @@ -1515,8 +1515,25 @@ export default class MetamaskController extends EventEmitter {
this.signatureController.newUnsignedPersonalMessage.bind(
this.signatureController,
),
///: END:ONLY_INCLUDE_IN

///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
/* eslint-disable no-dupe-keys */
processEthSignMessage: this.mmiController.newUnsignedMessage.bind(
this.mmiController,
),
processTypedMessage: this.mmiController.newUnsignedMessage.bind(
this.mmiController,
),
processTypedMessageV3: this.mmiController.newUnsignedMessage.bind(
this.mmiController,
),
processTypedMessageV4: this.mmiController.newUnsignedMessage.bind(
this.mmiController,
),
processPersonalMessage: this.mmiController.newUnsignedMessage.bind(
this.mmiController,
),
setTypedMessageInProgress:
this.signatureController.setTypedMessageInProgress.bind(
this.signatureController,
Expand All @@ -1525,6 +1542,7 @@ export default class MetamaskController extends EventEmitter {
this.signatureController.setPersonalMessageInProgress.bind(
this.signatureController,
),
/* eslint-enable no-dupe-keys */
///: END:ONLY_INCLUDE_IN

processEncryptionPublicKey:
Expand Down
2 changes: 2 additions & 0 deletions development/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ async function defineAndRunBuildTasks() {
'navigator',
'harden',
'console',
'WeakSet',
'Event',
'Image', // Used by browser to generate notifications
// globals chromedriver needs to function
/cdc_[a-zA-Z0-9]+_[a-zA-Z]+/iu,
Expand Down
2 changes: 1 addition & 1 deletion development/sentry-upload-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function upload_sourcemaps {
local release="${1}"; shift
local dist_directory="${1}"; shift

sentry-cli releases files "${release}" upload-sourcemaps "${dist_directory}"/chrome/*.js "${dist_directory}"/sourcemaps/ --rewrite --url-prefix 'metamask'
sentry-cli releases files "${release}" upload-sourcemaps "${dist_directory}"/chrome/*.js "${dist_directory}"/sourcemaps/ --rewrite --url-prefix '/metamask'
}

function main {
Expand Down
Loading

0 comments on commit 0449ff1

Please sign in to comment.