Skip to content

Commit

Permalink
refactor: use keyring-controller v8
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesposito committed Sep 26, 2023
1 parent b7bbcec commit 971bb2b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
diff --git a/dist/KeyringController.d.ts b/dist/KeyringController.d.ts
index d6d70eea2de56310b49fa9dcf1e90afae3ddb202..4518aed8e03376d76e5ab6ef0971529e65563fd3 100644
index 44c6427ec774475b87f60995738f736611875194..d359269ad413a0a626d06e44a84eb0cbbdb8c7b0 100644
--- a/dist/KeyringController.d.ts
+++ b/dist/KeyringController.d.ts
@@ -1,10 +1,11 @@
import type { TxData, TypedTransaction } from '@ethereumjs/tx';
-import { type MetaMaskKeyring as QRKeyring, type IKeyringState as IQRKeyringState } from '@keystonehq/metamask-airgapped-keyring';
+import type { MetaMaskKeyring as QRKeyring, IKeyringState as IQRKeyringState } from '@keystonehq/metamask-airgapped-keyring';
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
import { BaseControllerV2 } from '@metamask/base-controller';
@@ -5,6 +5,7 @@ import { BaseControllerV2 } from '@metamask/base-controller';
import type { PersonalMessageParams, TypedMessageParams } from '@metamask/message-manager';
import type { PreferencesController } from '@metamask/preferences-controller';
import type { Eip1024EncryptedData, Hex, Keyring, Json } from '@metamask/utils';
+import type { KeyringController as EthKeyringController } from '@metamask/eth-keyring-controller';
import type { Patch } from 'immer';
declare const name = "KeyringController";
/**
@@ -155,6 +156,10 @@ export declare class KeyringController extends BaseControllerV2<typeof name, Key
@@ -171,6 +172,10 @@ export declare class KeyringController extends BaseControllerV2<typeof name, Key
* @param opts.state - Initial state to set on this controller.
*/
constructor({ removeIdentity, syncIdentities, updateIdentities, setSelectedAddress, setAccountLabel, encryptor, keyringBuilders, cacheEncryptionKey, messenger, state, }: KeyringControllerOptions);
Expand All @@ -27,10 +22,10 @@ index d6d70eea2de56310b49fa9dcf1e90afae3ddb202..4518aed8e03376d76e5ab6ef0971529e
* Adds a new account to the default (first) HD seed phrase keyring.
*
diff --git a/dist/KeyringController.js b/dist/KeyringController.js
index bce9884ea54bf8e24274dee3876db95ed862abf0..471a06b30f2275de821c33b7d94cb1de85b074c7 100644
index d8b1e1b8da74d1647e6fbe50cf94f63bf9fd28cf..e3790cef6f1a93c6624db5f49cf53e54d4d1c702 100644
--- a/dist/KeyringController.js
+++ b/dist/KeyringController.js
@@ -154,6 +154,12 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
@@ -155,6 +155,12 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
this.setAccountLabel = setAccountLabel;
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_registerMessageHandlers).call(this);
}
Expand Down
5 changes: 5 additions & 0 deletions app/scripts/controllers/app-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ export default class AppStateController extends EventEmitter {
}
});

messenger.subscribe(
'KeyringController:qrKeyringStateChange',
this.updateQRHardware.bind(this),
);

const { preferences } = preferencesStore.getState();
this._setInactiveTimeout(preferences.autoLockTimeLimit);

Expand Down
30 changes: 17 additions & 13 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,9 @@ export default class MetamaskController extends EventEmitter {
`${this.approvalController.name}:addRequest`,
`${this.approvalController.name}:acceptRequest`,
],
allowedEvents: [
`${this.coreKeyringController.name}:qrKeyringStateChange`,
],
}),
extension: this.extension,
});
Expand Down Expand Up @@ -869,13 +872,24 @@ export default class MetamaskController extends EventEmitter {

const keyringControllerMessenger = this.controllerMessenger.getRestricted({
name: 'KeyringController',
allowedActions: [
'KeyringController:getState',
'KeyringController:signMessage',
'KeyringController:signPersonalMessage',
'KeyringController:signTypedMessage',
'KeyringController:decryptMessage',
'KeyringController:getEncryptionPublicKey',
'KeyringController:getKeyringsByType',
'KeyringController:getKeyringForAccount',
'KeyringController:getAccounts',
],
allowedEvents: [
'KeyringController:accountRemoved',
'KeyringController:lock',
'KeyringController:stateChange',
'KeyringController:lock',
'KeyringController:unlock',
'KeyringController:accountRemoved',
'KeyringController:qrKeyringStateChange',
],
allowedActions: ['KeyringController:getState'],
});

this.coreKeyringController = new KeyringController({
Expand Down Expand Up @@ -3382,16 +3396,6 @@ export default class MetamaskController extends EventEmitter {
async connectHardware(deviceName, page, hdPath) {
const keyring = await this.getKeyringForDevice(deviceName, hdPath);

if (deviceName === HardwareDeviceNames.qr) {
keyring
.getMemStore()
.subscribe(
this.appStateController.updateQRHardware.bind(
this.appStateController,
),
);
}

let accounts = [];
switch (page) {
case -1:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
"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",
"lavamoat-core@npm:^14.4.1": "patch:lavamoat-core@npm%3A14.4.1#~/.yarn/patches/lavamoat-core-npm-14.4.1-c4e8bbb016.patch",
"@metamask/keyring-controller@^7.4.0": "patch:@metamask/keyring-controller@npm%3A7.4.0#~/.yarn/patches/@metamask-keyring-controller-npm-7.4.0-5dd5df31c7.patch",
"@metamask/keyring-controller@^8.0.0": "patch:@metamask/keyring-controller@npm%3A8.0.0#~/.yarn/patches/@metamask-keyring-controller-npm-8.0.0-806630ae4e.patch",
"@metamask/signature-controller@^5.3.0": "patch:@metamask/signature-controller@npm%3A5.3.0#./.yarn/patches/@metamask-signature-controller-npm-5.3.0-225628460b.patch",
"[email protected]": "^7.5.4",
"[email protected]": "^7.5.4"
Expand Down Expand Up @@ -254,7 +254,7 @@
"@metamask/gas-fee-controller": "^6.0.1",
"@metamask/jazzicon": "^2.0.0",
"@metamask/key-tree": "^9.0.0",
"@metamask/keyring-controller": "^7.4.0",
"@metamask/keyring-controller": "^8.0.0",
"@metamask/logging-controller": "^1.0.1",
"@metamask/logo": "^3.1.1",
"@metamask/message-manager": "^7.3.0",
Expand Down
82 changes: 49 additions & 33 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3920,6 +3920,22 @@ __metadata:
languageName: node
linkType: hard

"@metamask/controller-utils@npm:^5.0.0":
version: 5.0.0
resolution: "@metamask/controller-utils@npm:5.0.0"
dependencies:
"@metamask/eth-query": "npm:^3.0.1"
"@metamask/utils": "npm:^6.2.0"
"@spruceid/siwe-parser": "npm:1.1.3"
eth-ens-namehash: "npm:^2.0.8"
eth-rpc-errors: "npm:^4.0.2"
ethereumjs-util: "npm:^7.0.10"
ethjs-unit: "npm:^0.1.6"
fast-deep-equal: "npm:^3.1.3"
checksum: 4fbefc1affa9aee110fcb1b7fc95a96f29fc6d41d6fa6b92bd691d541833cf8531a282d7866daeb7585741533b50a5d9e8d0564071fc1abf09769c9fe039845b
languageName: node
linkType: hard

"@metamask/design-tokens@npm:^1.12.0, @metamask/design-tokens@npm:^1.6.0":
version: 1.12.0
resolution: "@metamask/design-tokens@npm:1.12.0"
Expand Down Expand Up @@ -4070,18 +4086,18 @@ __metadata:
languageName: node
linkType: hard

"@metamask/eth-keyring-controller@npm:^13.0.0":
version: 13.0.0
resolution: "@metamask/eth-keyring-controller@npm:13.0.0"
"@metamask/eth-keyring-controller@npm:^13.0.1":
version: 13.0.1
resolution: "@metamask/eth-keyring-controller@npm:13.0.1"
dependencies:
"@ethereumjs/tx": "npm:^4.2.0"
"@metamask/browser-passworder": "npm:^4.1.0"
"@metamask/eth-hd-keyring": "npm:^6.0.0"
"@metamask/eth-sig-util": "npm:^6.0.0"
"@metamask/eth-simple-keyring": "npm:^5.0.0"
"@metamask/obs-store": "npm:^8.1.0"
"@metamask/utils": "npm:^6.2.0"
checksum: 25bf7477e5db366119b31135d1be3181ee3e73ec58c27e619d036c311feb148e972323556f38f94c94b2f37c6bd1b6a1eeab813a3bc2f284ec6c16124b9afeeb
"@metamask/utils": "npm:^8.1.0"
checksum: 7b5026ed3bd7a3b536b7e743122431a551a19d2a0113099d30bfbff44162d4fac99013665cf92fb419dde12b1497597750ea9d94d270a93b4f6706279b6cba01
languageName: node
linkType: hard

Expand Down Expand Up @@ -4308,43 +4324,43 @@ __metadata:
languageName: node
linkType: hard

"@metamask/keyring-controller@npm:7.4.0":
version: 7.4.0
resolution: "@metamask/keyring-controller@npm:7.4.0"
"@metamask/keyring-controller@npm:8.0.0":
version: 8.0.0
resolution: "@metamask/keyring-controller@npm:8.0.0"
dependencies:
"@keystonehq/metamask-airgapped-keyring": "npm:^0.13.1"
"@metamask/base-controller": "npm:^3.2.1"
"@metamask/eth-keyring-controller": "npm:^13.0.0"
"@metamask/message-manager": "npm:^7.3.1"
"@metamask/preferences-controller": "npm:^4.4.0"
"@metamask/eth-keyring-controller": "npm:^13.0.1"
"@metamask/message-manager": "npm:^7.3.3"
"@metamask/preferences-controller": "npm:^4.4.1"
"@metamask/utils": "npm:^6.2.0"
async-mutex: "npm:^0.2.6"
ethereumjs-util: "npm:^7.0.10"
ethereumjs-wallet: "npm:^1.0.1"
immer: "npm:^9.0.6"
peerDependencies:
"@metamask/preferences-controller": ^4.4.0
checksum: 17b3f24d57dc79689ee6c0159f931ba71b10cbb728cecce6595ec69c46bc706289e90e22b9e7709fef8719ff99594adccd842a3a687fcc651a55cd873f2bc219
"@metamask/preferences-controller": ^4.4.1
checksum: 2cd0173d210c634357aa8be0c3fc2472939e6919f69b4d375ebc6c464d116928603b3b917a4fa6120e75870bc2288553a23f5659a6719c84902d982e0aa376a4
languageName: node
linkType: hard

"@metamask/keyring-controller@patch:@metamask/keyring-controller@npm%3A7.4.0#~/.yarn/patches/@metamask-keyring-controller-npm-7.4.0-5dd5df31c7.patch":
version: 7.4.0
resolution: "@metamask/keyring-controller@patch:@metamask/keyring-controller@npm%3A7.4.0#~/.yarn/patches/@metamask-keyring-controller-npm-7.4.0-5dd5df31c7.patch::version=7.4.0&hash=4a7ca3"
"@metamask/keyring-controller@patch:@metamask/keyring-controller@npm%3A8.0.0#~/.yarn/patches/@metamask-keyring-controller-npm-8.0.0-806630ae4e.patch":
version: 8.0.0
resolution: "@metamask/keyring-controller@patch:@metamask/keyring-controller@npm%3A8.0.0#~/.yarn/patches/@metamask-keyring-controller-npm-8.0.0-806630ae4e.patch::version=8.0.0&hash=65339a"
dependencies:
"@keystonehq/metamask-airgapped-keyring": "npm:^0.13.1"
"@metamask/base-controller": "npm:^3.2.1"
"@metamask/eth-keyring-controller": "npm:^13.0.0"
"@metamask/message-manager": "npm:^7.3.1"
"@metamask/preferences-controller": "npm:^4.4.0"
"@metamask/eth-keyring-controller": "npm:^13.0.1"
"@metamask/message-manager": "npm:^7.3.3"
"@metamask/preferences-controller": "npm:^4.4.1"
"@metamask/utils": "npm:^6.2.0"
async-mutex: "npm:^0.2.6"
ethereumjs-util: "npm:^7.0.10"
ethereumjs-wallet: "npm:^1.0.1"
immer: "npm:^9.0.6"
peerDependencies:
"@metamask/preferences-controller": ^4.4.0
checksum: d6965c9e3f7fe00481ed544fae172aa04f8212e570ccea4c1d16f52f42c775759df59a1009c52937e1f6c6a764c16b80b89c457a4765009ff9bb1d454aab42ab
"@metamask/preferences-controller": ^4.4.1
checksum: f9a4f8eaec927b5c2fdc91f12066254a90b4358e79dcf01ff4c380414cdb53f37914cb9e5dd71a9758fd67ffe7346fcb181f2124e6d6f1fca8c21af5bb5b1920
languageName: node
linkType: hard

Expand All @@ -4369,19 +4385,19 @@ __metadata:
languageName: node
linkType: hard

"@metamask/message-manager@npm:^7.2.0, @metamask/message-manager@npm:^7.3.0, @metamask/message-manager@npm:^7.3.1":
version: 7.3.1
resolution: "@metamask/message-manager@npm:7.3.1"
"@metamask/message-manager@npm:^7.2.0, @metamask/message-manager@npm:^7.3.0, @metamask/message-manager@npm:^7.3.3":
version: 7.3.3
resolution: "@metamask/message-manager@npm:7.3.3"
dependencies:
"@metamask/base-controller": "npm:^3.2.1"
"@metamask/controller-utils": "npm:^4.3.2"
"@metamask/eth-sig-util": "npm:^6.0.0"
"@metamask/controller-utils": "npm:^5.0.0"
"@metamask/eth-sig-util": "npm:^7.0.0"
"@metamask/utils": "npm:^6.2.0"
"@types/uuid": "npm:^8.3.0"
ethereumjs-util: "npm:^7.0.10"
jsonschema: "npm:^1.2.4"
uuid: "npm:^8.3.2"
checksum: 9ba3893a2a739906f63b9b51eceab798cad0f26657d58959cac8620122e80c9ae9007c6f0502a3eb7875398b774c5a59f00adde028cf80a1aa75502f53ef5740
checksum: 1f9175c3ce44bf8d8ee80e391f1d36f559cef31e883a6ba7e3032d06c0263cc8e1d5fe15a591583bd415bbb01d113750ff6de99220d99ef71b4057985e34406e
languageName: node
linkType: hard

Expand Down Expand Up @@ -4604,13 +4620,13 @@ __metadata:
languageName: node
linkType: hard

"@metamask/preferences-controller@npm:^4.1.0, @metamask/preferences-controller@npm:^4.4.0":
version: 4.4.0
resolution: "@metamask/preferences-controller@npm:4.4.0"
"@metamask/preferences-controller@npm:^4.1.0, @metamask/preferences-controller@npm:^4.4.1":
version: 4.4.1
resolution: "@metamask/preferences-controller@npm:4.4.1"
dependencies:
"@metamask/base-controller": "npm:^3.2.1"
"@metamask/controller-utils": "npm:^4.3.2"
checksum: b22372f85e672f3843427a76aca8b675273136f01e68739e81cb2eb391e6d960ccc79473af23b63b22237b5093fcaca41224c1ca4a98582606f4b14b0a9ccd54
"@metamask/controller-utils": "npm:^5.0.0"
checksum: 2404cf4c6f207316af7fd8cf9a7ae2ff3f38766bedde67103143d964ad4e253c8cf228da692a80644e65f072306bfaa807895771e45e93797ab879b9645744a7
languageName: node
linkType: hard

Expand Down Expand Up @@ -24020,7 +24036,7 @@ __metadata:
"@metamask/gas-fee-controller": "npm:^6.0.1"
"@metamask/jazzicon": "npm:^2.0.0"
"@metamask/key-tree": "npm:^9.0.0"
"@metamask/keyring-controller": "npm:^7.4.0"
"@metamask/keyring-controller": "npm:^8.0.0"
"@metamask/logging-controller": "npm:^1.0.1"
"@metamask/logo": "npm:^3.1.1"
"@metamask/message-manager": "npm:^7.3.0"
Expand Down

0 comments on commit 971bb2b

Please sign in to comment.