Skip to content

Commit

Permalink
Merge branch 'develop' into feat/external-name-sources-toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwalsh0 committed Oct 2, 2023
2 parents d70efc7 + b7ad9f6 commit bad1b19
Show file tree
Hide file tree
Showing 24 changed files with 490 additions and 566 deletions.
6 changes: 0 additions & 6 deletions .storybook/test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,12 +1062,6 @@ const state = {
unapprovedEncryptionPublicKeyMsgCount: 0,
unapprovedTypedMessages: {},
unapprovedTypedMessagesCount: 0,
keyringTypes: [
KeyringType.imported,
KeyringType.hdKeyTree,
KeyringType.trezor,
KeyringType.ledger,
],
keyrings: [
{
type: KeyringType.hdKeyTree,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/dist/SignatureController.js b/dist/SignatureController.js
index 46d4b4d0553f86d368d30b7e90a9dc2e03d26ef9..e7063a3753bc3821e661c11132e33304b4fce416 100644
--- a/dist/SignatureController.js
+++ b/dist/SignatureController.js
@@ -280,8 +280,11 @@ _SignatureController_isEthSignEnabled = new WeakMap(), _SignatureController_getA
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;
1 change: 0 additions & 1 deletion app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ browser.runtime.onConnectExternal.addListener(async (...args) => {
* @property {object} unapprovedTypedMsgs - An object of messages pending approval, mapping a unique ID to the options.
* @property {number} unapprovedTypedMsgCount - The number of messages in unapprovedTypedMsgs.
* @property {number} pendingApprovalCount - The number of pending request in the approval controller.
* @property {string[]} keyringTypes - An array of unique keyring identifying strings, representing available strategies for creating accounts.
* @property {Keyring[]} keyrings - An array of keyring descriptions, summarizing the accounts that are available for use, and what keyrings they belong to.
* @property {string} selectedAddress - A lower case hex string of the currently selected address.
* @property {string} currentCurrency - A string identifying the user's preferred display currency, for use in showing conversion rates.
Expand Down
1 change: 0 additions & 1 deletion app/scripts/lib/setupSentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export const SENTRY_BACKGROUND_STATE = {
KeyringController: {
isUnlocked: true,
keyrings: false,
keyringTypes: false,
},
LoggingController: {
logs: false,
Expand Down
8 changes: 3 additions & 5 deletions app/scripts/lib/snap-keyring/snap-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export const getAccountsBySnapId = async (
*
* @param getSnapController - A function that retrieves the Snap Controller instance.
* @param getApprovalController - A function that retrieves the Approval Controller instance.
* @param getKeyringController - A function that retrieves the Keyring Controller instance.
* @param getCoreKeyringController - A function that retrieves the Core Keyring Controller instance.
* @param removeAccountHelper - A function to help remove an account based on its address.
* @returns The constructed SnapKeyring builder instance with the following methods:
Expand All @@ -40,7 +39,6 @@ export const getAccountsBySnapId = async (
export const snapKeyringBuilder = (
getSnapController: () => SnapController,
getApprovalController: () => ApprovalController,
getKeyringController: () => KeyringController,
getCoreKeyringController: () => KeyringController,
removeAccountHelper: (address: string) => Promise<any>,
) => {
Expand All @@ -51,7 +49,7 @@ export const snapKeyringBuilder = (
return addresses.includes(address.toLowerCase());
},
saveState: async () => {
await getKeyringController().persistAllKeyrings();
await getCoreKeyringController().persistAllKeyrings();
},
addAccount: async (
_address: string,
Expand All @@ -77,7 +75,7 @@ export const snapKeyringBuilder = (
if (confirmationResult) {
try {
await handleUserInput(confirmationResult);
await getKeyringController().persistAllKeyrings();
await getCoreKeyringController().persistAllKeyrings();
await getApprovalController().success({
message: t('snapAccountCreated') ?? 'Your account is ready!',
header: [snapAuthorshipHeader],
Expand Down Expand Up @@ -129,7 +127,7 @@ export const snapKeyringBuilder = (
try {
await removeAccountHelper(address);
await handleUserInput(confirmationResult);
await getKeyringController().persistAllKeyrings();
await getCoreKeyringController().persistAllKeyrings();
await getApprovalController().success({
message: t('snapAccountRemoved') ?? 'Account removed',
header: [snapAuthorshipHeader],
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/metamask-controller.actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ describe('MetaMaskController', function () {
]),
Promise.resolve(1).then(() => {
keyringControllerState1 = JSON.stringify(
metamaskController.keyringController.memStore.getState(),
metamaskController.coreKeyringController.state,
);
metamaskController.importAccountWithStrategy('privateKey', [
importPrivkey,
]);
}),
Promise.resolve(2).then(() => {
keyringControllerState2 = JSON.stringify(
metamaskController.keyringController.memStore.getState(),
metamaskController.coreKeyringController.state,
);
}),
]);
Expand Down
69 changes: 34 additions & 35 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,14 +857,12 @@ export default class MetamaskController extends EventEmitter {
///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps)
const getSnapController = () => this.snapController;
const getApprovalController = () => this.approvalController;
const getKeyringController = () => this.keyringController;
const getCoreKeyringController = () => this.coreKeyringController;

additionalKeyrings.push(
snapKeyringBuilder(
getSnapController,
getApprovalController,
getKeyringController,
getCoreKeyringController,
(address) => this.removeAccount(address),
),
Expand Down Expand Up @@ -930,9 +928,6 @@ export default class MetamaskController extends EventEmitter {
},
);

this.keyringController =
this.coreKeyringController.getEthKeyringController();

const getIdentities = () =>
this.preferencesController.store.getState().identities;

Expand All @@ -954,8 +949,8 @@ export default class MetamaskController extends EventEmitter {
permissionSpecifications: {
...getPermissionSpecifications({
getIdentities,
getAllAccounts: this.keyringController.getAccounts.bind(
this.keyringController,
getAllAccounts: this.coreKeyringController.getAccounts.bind(
this.coreKeyringController,
),
captureKeyringTypesWithMissingIdentities: (
identities = {},
Expand Down Expand Up @@ -1252,8 +1247,8 @@ export default class MetamaskController extends EventEmitter {
this.networkController.state.providerConfig.chainId,
preferencesStore: this.preferencesController.store,
txHistoryLimit: 60,
signTransaction: this.keyringController.signTransaction.bind(
this.keyringController,
signTransaction: this.coreKeyringController.signTransaction.bind(
this.coreKeyringController,
),
provider: this.provider,
blockTracker: this.blockTracker,
Expand Down Expand Up @@ -1439,9 +1434,13 @@ export default class MetamaskController extends EventEmitter {
this.signatureController = new SignatureController({
messenger: this.controllerMessenger.getRestricted({
name: 'SignatureController',
allowedActions: [`${this.approvalController.name}:addRequest`],
allowedActions: [
`${this.approvalController.name}:addRequest`,
`${this.coreKeyringController.name}:signMessage`,
`${this.coreKeyringController.name}:signPersonalMessage`,
`${this.coreKeyringController.name}:signTypedMessage`,
],
}),
keyringController: this.keyringController,
isEthSignEnabled: () =>
this.preferencesController.store.getState()
?.disabledRpcMethodPreferences?.eth_sign,
Expand Down Expand Up @@ -1737,7 +1736,7 @@ export default class MetamaskController extends EventEmitter {
AppStateController: this.appStateController.store,
AppMetadataController: this.appMetadataController.store,
TransactionController: this.txController.store,
KeyringController: this.keyringController.store,
KeyringController: this.coreKeyringController,
PreferencesController: this.preferencesController.store,
MetaMetricsController: this.metaMetricsController.store,
AddressBookController: this.addressBookController,
Expand Down Expand Up @@ -1789,7 +1788,7 @@ export default class MetamaskController extends EventEmitter {
AppMetadataController: this.appMetadataController.store,
NetworkController: this.networkController,
CachedBalancesController: this.cachedBalancesController.store,
KeyringController: this.keyringController.memStore,
KeyringController: this.coreKeyringController,
PreferencesController: this.preferencesController.store,
MetaMetricsController: this.metaMetricsController.store,
AddressBookController: this.addressBookController,
Expand Down Expand Up @@ -2299,11 +2298,14 @@ export default class MetamaskController extends EventEmitter {
* @returns {object} status
*/
getState() {
const { vault } = this.keyringController.store.getState();
const { vault } = this.coreKeyringController.state;
const isInitialized = Boolean(vault);

const flatState = this.memStore.getFlatState();

// The vault should not be exposed to the UI
delete flatState.vault;

return {
isInitialized,
...flatState,
Expand Down Expand Up @@ -2957,7 +2959,7 @@ export default class MetamaskController extends EventEmitter {

async exportAccount(address, password) {
await this.verifyPassword(password);
return this.keyringController.exportAccount(address, password);
return this.coreKeyringController.exportAccount(password, address);
}

async getTokenStandardAndDetails(address, userAddress, tokenId) {
Expand Down Expand Up @@ -3054,18 +3056,13 @@ export default class MetamaskController extends EventEmitter {
async createNewVaultAndKeychain(password) {
const releaseLock = await this.createVaultMutex.acquire();
try {
let vault;
const accounts = await this.keyringController.getAccounts();
if (accounts.length > 0) {
vault = await this.keyringController.fullUpdate();
} else {
vault = await this.keyringController.createNewVaultAndKeychain(
password,
);
const addresses = await this.keyringController.getAccounts();
this.preferencesController.setAddresses(addresses);
this.selectFirstIdentity();
}
const vault = await this.coreKeyringController.createNewVaultAndKeychain(
password,
);

const accounts = await this.coreKeyringController.getAccounts();
this.preferencesController.setAddresses(accounts);
this.selectFirstIdentity();

return vault;
} finally {
Expand Down Expand Up @@ -3306,7 +3303,7 @@ export default class MetamaskController extends EventEmitter {
* @param {string} password - The user's password
*/
async verifyPassword(password) {
await this.keyringController.verifyPassword(password);
await this.coreKeyringController.verifyPassword(password);
}

/**
Expand Down Expand Up @@ -3386,7 +3383,7 @@ export default class MetamaskController extends EventEmitter {
keyringName,
);
if (!keyring) {
keyring = await this.keyringController.addNewKeyring(keyringName);
keyring = await this.coreKeyringController.addNewKeyring(keyringName);
}
if (hdPath && keyring.setHdPath) {
keyring.setHdPath(hdPath);
Expand Down Expand Up @@ -3440,7 +3437,7 @@ export default class MetamaskController extends EventEmitter {

// Merge with existing accounts
// and make sure addresses are not repeated
const oldAccounts = await this.keyringController.getAccounts();
const oldAccounts = await this.coreKeyringController.getAccounts();
const accountsToTrack = [
...new Set(
oldAccounts.concat(accounts.map((a) => a.address.toLowerCase())),
Expand Down Expand Up @@ -3556,9 +3553,11 @@ export default class MetamaskController extends EventEmitter {
const keyring = await this.getKeyringForDevice(deviceName, hdPath);

keyring.setAccountToUnlock(index);
const oldAccounts = await this.keyringController.getAccounts();
const keyState = await this.keyringController.addNewAccount(keyring);
const newAccounts = await this.keyringController.getAccounts();
const oldAccounts = await this.coreKeyringController.getAccounts();
const keyState = await this.coreKeyringController.addNewAccountForKeyring(
keyring,
);
const newAccounts = await this.coreKeyringController.getAccounts();
this.preferencesController.setAddresses(newAccounts);
newAccounts.forEach((address) => {
if (!oldAccounts.includes(address)) {
Expand Down Expand Up @@ -3707,7 +3706,7 @@ export default class MetamaskController extends EventEmitter {
address,
);
// Remove account from the keyring
await this.keyringController.removeAccount(address);
await this.coreKeyringController.removeAccount(address);
const updatedKeyringAccounts = keyring ? await keyring.getAccounts() : {};
if (updatedKeyringAccounts?.length === 0) {
keyring.destroy?.();
Expand Down Expand Up @@ -4665,7 +4664,7 @@ export default class MetamaskController extends EventEmitter {
* @returns {boolean} Whether the extension is unlocked.
*/
isUnlocked() {
return this.keyringController.memStore.getState().isUnlocked;
return this.coreKeyringController.state.isUnlocked;
}

//=============================================================================
Expand Down
Loading

0 comments on commit bad1b19

Please sign in to comment.