-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use @metamask/keyring-controller
#19659
Changes from 6 commits
94170ed
346348e
a5a90e1
251e7d5
1567ae0
608b911
16e373d
9530eed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
diff --git a/dist/KeyringController.d.ts b/dist/KeyringController.d.ts | ||
index 82de83a7bb1ad14bb23f3b6274e0c4d5bb773382..86a09b3f604f6feb26e2c7edbdcb0abebd4bae20 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'; | ||
import type { PersonalMessageParams, TypedMessageParams } from '@metamask/message-manager'; | ||
import type { PreferencesController } from '@metamask/preferences-controller'; | ||
-import { type Hex, type Keyring, type Json } from '@metamask/utils'; | ||
+import type { 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"; | ||
/** | ||
@@ -135,6 +136,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); | ||
+ /** | ||
+ * Gets the internal keyring controller. | ||
+ */ | ||
+ getEthKeyringController(): EthKeyringController; | ||
/** | ||
* Adds a new account to the default (first) HD seed phrase keyring. | ||
* | ||
diff --git a/dist/KeyringController.js b/dist/KeyringController.js | ||
index 54d39d266425b45ed1008cecb16e78cf831c75d7..0ddded415bf71716c27ed3bf7bd1c5a79b11be13 100644 | ||
--- a/dist/KeyringController.js | ||
+++ b/dist/KeyringController.js | ||
@@ -153,6 +153,12 @@ class KeyringController extends base_controller_1.BaseControllerV2 { | ||
this.setSelectedAddress = setSelectedAddress; | ||
this.setAccountLabel = setAccountLabel; | ||
} | ||
+ /** | ||
+ * Gets the internal keyring controller. | ||
+ */ | ||
+ getEthKeyringController() { | ||
+ return __classPrivateFieldGet(this, _KeyringController_keyring, "f"); | ||
+ } | ||
/** | ||
* Adds a new account to the default (first) HD seed phrase keyring. | ||
* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,8 @@ import { JsonRpcEngine } from 'json-rpc-engine'; | |
import { createEngineStream } from 'json-rpc-middleware-stream'; | ||
import { providerAsMiddleware } from '@metamask/eth-json-rpc-middleware'; | ||
import { debounce } from 'lodash'; | ||
import { | ||
KeyringController, | ||
keyringBuilderFactory, | ||
} from '@metamask/eth-keyring-controller'; | ||
import { keyringBuilderFactory } from '@metamask/eth-keyring-controller'; | ||
import { KeyringController } from '@metamask/keyring-controller'; | ||
import createFilterMiddleware from 'eth-json-rpc-filters'; | ||
import createSubscriptionManager from 'eth-json-rpc-filters/subscriptionManager'; | ||
import { errorCodes as rpcErrorCodes, EthereumRpcError } from 'eth-rpc-errors'; | ||
|
@@ -824,13 +822,43 @@ export default class MetamaskController extends EventEmitter { | |
); | ||
///: END:ONLY_INCLUDE_IN | ||
|
||
this.keyringController = new KeyringController({ | ||
const keyringControllerMessenger = this.controllerMessenger.getRestricted({ | ||
name: 'KeyringController', | ||
allowedEvents: [ | ||
'KeyringController:accountRemoved', | ||
'KeyringController:lock', | ||
'KeyringController:stateChange', | ||
'KeyringController:unlock', | ||
], | ||
allowedActions: ['KeyringController:getState'], | ||
}); | ||
|
||
this.coreKeyringController = new KeyringController({ | ||
keyringBuilders: additionalKeyrings, | ||
initState: initState.KeyringController, | ||
state: initState.KeyringController, | ||
encryptor: opts.encryptor || undefined, | ||
cacheEncryptionKey: isManifestV3, | ||
messenger: keyringControllerMessenger, | ||
removeIdentity: this.preferencesController.removeAddress.bind( | ||
this.preferencesController, | ||
), | ||
setAccountLabel: this.preferencesController.setAccountLabel.bind( | ||
this.preferencesController, | ||
), | ||
setSelectedAddress: this.preferencesController.setSelectedAddress.bind( | ||
this.preferencesController, | ||
), | ||
syncIdentities: this.preferencesController.syncAddresses.bind( | ||
this.preferencesController, | ||
), | ||
updateIdentities: this.preferencesController.setAddresses.bind( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can handle this in a later PR, but it will come up once we start using the core keyring controller for creating accounts and keyrings There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can do this as part of #18772 |
||
this.preferencesController, | ||
), | ||
}); | ||
|
||
this.keyringController = | ||
this.coreKeyringController.getEthKeyringController(); | ||
|
||
this.keyringController.memStore.subscribe((state) => | ||
this._onKeyringControllerUpdate(state), | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why these type imports were changed. Was this unintended? Or did the
import { type ___ }
syntax cause problems with the build system?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is intended, but it looks like it breaks only the lint step: https://app.circleci.com/pipelines/github/MetaMask/metamask-extension/51596/workflows/800ab01e-5b6f-44c1-9312-934fdd12c838/jobs/1501250
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. The TypeScript version used here is fairly old, that's probably why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Should we add TypeScript
~4.6.3
as an optional peer dependency to all packages in thecore
repo?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
>=4.6.3
instead? But yes that might be a good idea