Skip to content

Commit

Permalink
Merge branch 'develop' into feat/address-book-petnames-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwalsh0 authored Oct 2, 2023
2 parents 1bdbece + b7ad9f6 commit ab443a3
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 @@ -858,14 +858,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 @@ -931,9 +929,6 @@ export default class MetamaskController extends EventEmitter {
},
);

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

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

Expand All @@ -955,8 +950,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 @@ -1253,8 +1248,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 @@ -1440,9 +1435,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 @@ -1744,7 +1743,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 @@ -1796,7 +1795,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 @@ -2306,11 +2305,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 @@ -2958,7 +2960,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 @@ -3055,18 +3057,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 @@ -3307,7 +3304,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 @@ -3387,7 +3384,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 @@ -3441,7 +3438,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 @@ -3557,9 +3554,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 @@ -3708,7 +3707,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 @@ -4666,7 +4665,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 ab443a3

Please sign in to comment.