@metamask-previews/keyring-controller 7.5.0-preview.56ca173 → 8.0.2-preview.26b130a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -2
- package/dist/KeyringController.d.ts +17 -9
- package/dist/KeyringController.d.ts.map +1 -1
- package/dist/KeyringController.js +63 -16
- package/dist/KeyringController.js.map +1 -1
- package/package.json +10 -9
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [8.0.2]
|
|
10
|
+
### Changed
|
|
11
|
+
- Bump dependency on `@metamask/utils` to ^8.1.0 ([#1639](https://github.com/MetaMask/core/pull/1639))
|
|
12
|
+
- Bump dependency on `@metamask/base-controller` to ^3.2.3
|
|
13
|
+
- Bump dependency on `@metamask/message-manager` to ^7.3.5
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- Update `removeAccount` to remove call to `PreferencesController.removeIdentity` as `PreferencesController` already handles account removal side effects through messenger events ([#1759](https://github.com/MetaMask/core/pull/1759))
|
|
17
|
+
|
|
18
|
+
## [8.0.1]
|
|
19
|
+
### Changed
|
|
20
|
+
- Update TypeScript to v4.8.x ([#1718](https://github.com/MetaMask/core/pull/1718))
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
- Removed `keyringTypes` from `memStore` ([#1710](https://github.com/MetaMask/core/pull/1710))
|
|
24
|
+
- This property was accidentally getting copied into the memstore from the internal keyring controller. It was causing errors because there is no metadata for this state property.
|
|
25
|
+
|
|
26
|
+
## [8.0.0]
|
|
27
|
+
### Added
|
|
28
|
+
- Add `getQRKeyring(): QRKeyring | undefined` method
|
|
29
|
+
- Add `KeyringController:qrKeyringStateChange` messenger event
|
|
30
|
+
- The event emits updates from the internal `QRKeyring` instance, if there's one
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
- **BREAKING:** addNewKeyring(type) return type changed from Promise<Keyring<Json>> to Promise<unknown>
|
|
34
|
+
- When calling with QRKeyring type the keyring instance is retrieved or created (no multiple QRKeyring instances possible)
|
|
35
|
+
- Bump dependency on `@metamask/message-manager` to ^7.3.3
|
|
36
|
+
- Bump dependency on `@metamask/preferences-controller` to ^4.4.1
|
|
37
|
+
|
|
38
|
+
### Fixed
|
|
39
|
+
- Fix `addNewAccountForKeyring` for `CustodyKeyring` ([#1694](https://github.com/MetaMask/core/pull/1694))
|
|
40
|
+
|
|
9
41
|
## [7.5.0]
|
|
10
42
|
### Added
|
|
11
43
|
- Add `KeyringController` messenger actions ([#1691](https://github.com/MetaMask/core/pull/1691))
|
|
@@ -20,7 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
20
52
|
### Added
|
|
21
53
|
- Add `KeyringController` messenger actions ([#1654](https://github.com/MetaMask/core/pull/1654))
|
|
22
54
|
- `KeyringController:signMessage`
|
|
23
|
-
- `KeyringController:signPersonalMessage`
|
|
55
|
+
- `KeyringController:signPersonalMessage`
|
|
24
56
|
- `KeyringController:signTypedMessage`
|
|
25
57
|
- `KeyringController:decryptMessage`
|
|
26
58
|
- `KeyringController:getEncryptionPublicKey`
|
|
@@ -181,7 +213,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
181
213
|
|
|
182
214
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
183
215
|
|
|
184
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@
|
|
216
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@8.0.2...HEAD
|
|
217
|
+
[8.0.2]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@8.0.1...@metamask/keyring-controller@8.0.2
|
|
218
|
+
[8.0.1]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@8.0.0...@metamask/keyring-controller@8.0.1
|
|
219
|
+
[8.0.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@7.5.0...@metamask/keyring-controller@8.0.0
|
|
185
220
|
[7.5.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@7.4.0...@metamask/keyring-controller@7.5.0
|
|
186
221
|
[7.4.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@7.3.0...@metamask/keyring-controller@7.4.0
|
|
187
222
|
[7.3.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@7.2.0...@metamask/keyring-controller@7.3.0
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TxData, TypedTransaction } from '@ethereumjs/tx';
|
|
2
|
-
import {
|
|
2
|
+
import type { MetaMaskKeyring as QRKeyring, IKeyringState as IQRKeyringState } from '@keystonehq/metamask-airgapped-keyring';
|
|
3
3
|
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
4
4
|
import { BaseControllerV2 } from '@metamask/base-controller';
|
|
5
5
|
import type { PersonalMessageParams, TypedMessageParams } from '@metamask/message-manager';
|
|
@@ -86,11 +86,14 @@ export declare type KeyringControllerUnlockEvent = {
|
|
|
86
86
|
type: `${typeof name}:unlock`;
|
|
87
87
|
payload: [];
|
|
88
88
|
};
|
|
89
|
+
export declare type KeyringControllerQRKeyringStateChangeEvent = {
|
|
90
|
+
type: `${typeof name}:qrKeyringStateChange`;
|
|
91
|
+
payload: [ReturnType<IQRKeyringState['getState']>];
|
|
92
|
+
};
|
|
89
93
|
export declare type KeyringControllerActions = KeyringControllerGetStateAction | KeyringControllerSignMessageAction | KeyringControllerSignPersonalMessageAction | KeyringControllerSignTypedMessageAction | KeyringControllerDecryptMessageAction | KeyringControllerGetEncryptionPublicKeyAction | KeyringControllerGetAccountsAction | KeyringControllerGetKeyringsByTypeAction | KeyringControllerGetKeyringForAccountAction;
|
|
90
|
-
export declare type KeyringControllerEvents = KeyringControllerStateChangeEvent | KeyringControllerLockEvent | KeyringControllerUnlockEvent | KeyringControllerAccountRemovedEvent;
|
|
94
|
+
export declare type KeyringControllerEvents = KeyringControllerStateChangeEvent | KeyringControllerLockEvent | KeyringControllerUnlockEvent | KeyringControllerAccountRemovedEvent | KeyringControllerQRKeyringStateChangeEvent;
|
|
91
95
|
export declare type KeyringControllerMessenger = RestrictedControllerMessenger<typeof name, KeyringControllerActions, KeyringControllerEvents, string, string>;
|
|
92
96
|
export declare type KeyringControllerOptions = {
|
|
93
|
-
removeIdentity: PreferencesController['removeIdentity'];
|
|
94
97
|
syncIdentities: PreferencesController['syncIdentities'];
|
|
95
98
|
updateIdentities: PreferencesController['updateIdentities'];
|
|
96
99
|
setSelectedAddress: PreferencesController['setSelectedAddress'];
|
|
@@ -146,7 +149,6 @@ export declare enum SignTypedDataVersion {
|
|
|
146
149
|
export declare class KeyringController extends BaseControllerV2<typeof name, KeyringControllerState, KeyringControllerMessenger> {
|
|
147
150
|
#private;
|
|
148
151
|
private readonly mutex;
|
|
149
|
-
private readonly removeIdentity;
|
|
150
152
|
private readonly syncIdentities;
|
|
151
153
|
private readonly updateIdentities;
|
|
152
154
|
private readonly setSelectedAddress;
|
|
@@ -155,7 +157,6 @@ export declare class KeyringController extends BaseControllerV2<typeof name, Key
|
|
|
155
157
|
* Creates a KeyringController instance.
|
|
156
158
|
*
|
|
157
159
|
* @param opts - Initial options used to configure this controller
|
|
158
|
-
* @param opts.removeIdentity - Remove the identity with the given address.
|
|
159
160
|
* @param opts.syncIdentities - Sync identities with the given list of addresses.
|
|
160
161
|
* @param opts.updateIdentities - Generate an identity for each address given that doesn't already have an identity.
|
|
161
162
|
* @param opts.setSelectedAddress - Set the selected address.
|
|
@@ -166,7 +167,7 @@ export declare class KeyringController extends BaseControllerV2<typeof name, Key
|
|
|
166
167
|
* @param opts.messenger - A restricted controller messenger.
|
|
167
168
|
* @param opts.state - Initial state to set on this controller.
|
|
168
169
|
*/
|
|
169
|
-
constructor({
|
|
170
|
+
constructor({ syncIdentities, updateIdentities, setSelectedAddress, setAccountLabel, encryptor, keyringBuilders, cacheEncryptionKey, messenger, state, }: KeyringControllerOptions);
|
|
170
171
|
/**
|
|
171
172
|
* Adds a new account to the default (first) HD seed phrase keyring.
|
|
172
173
|
*
|
|
@@ -218,7 +219,7 @@ export declare class KeyringController extends BaseControllerV2<typeof name, Key
|
|
|
218
219
|
* @throws If a builder for the given `type` does not exist.
|
|
219
220
|
* @returns Promise resolving to the added keyring.
|
|
220
221
|
*/
|
|
221
|
-
addNewKeyring(type: KeyringTypes | string, opts?: unknown): Promise<
|
|
222
|
+
addNewKeyring(type: KeyringTypes | string, opts?: unknown): Promise<unknown>;
|
|
222
223
|
/**
|
|
223
224
|
* Method to verify a given password validity. Throws an
|
|
224
225
|
* error if the password is invalid.
|
|
@@ -357,9 +358,10 @@ export declare class KeyringController extends BaseControllerV2<typeof name, Key
|
|
|
357
358
|
*
|
|
358
359
|
* @param transaction - Transaction object to sign. Must be a `ethereumjs-tx` transaction instance.
|
|
359
360
|
* @param from - Address to sign from, should be in keychain.
|
|
361
|
+
* @param opts - An optional options object.
|
|
360
362
|
* @returns Promise resolving to a signed transaction string.
|
|
361
363
|
*/
|
|
362
|
-
signTransaction(transaction: TypedTransaction, from: string): Promise<TxData>;
|
|
364
|
+
signTransaction(transaction: TypedTransaction, from: string, opts?: Record<string, unknown>): Promise<TxData>;
|
|
363
365
|
/**
|
|
364
366
|
* Attempts to decrypt the current vault and load its keyrings,
|
|
365
367
|
* using the given encryption key and salt.
|
|
@@ -384,7 +386,13 @@ export declare class KeyringController extends BaseControllerV2<typeof name, Key
|
|
|
384
386
|
*/
|
|
385
387
|
verifySeedPhrase(): Promise<Uint8Array>;
|
|
386
388
|
/**
|
|
387
|
-
* Get
|
|
389
|
+
* Get QR Hardware keyring.
|
|
390
|
+
*
|
|
391
|
+
* @returns The QR Keyring if defined, otherwise undefined
|
|
392
|
+
*/
|
|
393
|
+
getQRKeyring(): QRKeyring | undefined;
|
|
394
|
+
/**
|
|
395
|
+
* Get QR hardware keyring. If it doesn't exist, add it.
|
|
388
396
|
*
|
|
389
397
|
* @returns The added keyring
|
|
390
398
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyringController.d.ts","sourceRoot":"","sources":["../src/KeyringController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,
|
|
1
|
+
{"version":3,"file":"KeyringController.d.ts","sourceRoot":"","sources":["../src/KeyringController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,KAAK,EACV,eAAe,IAAI,SAAS,EAC5B,aAAa,IAAI,eAAe,EACjC,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,KAAK,EAAE,oBAAoB,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAYhF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAEnC,QAAA,MAAM,IAAI,sBAAsB,CAAC;AAEjC;;GAEG;AACH,oBAAY,YAAY;IACtB,MAAM,oBAAoB;IAC1B,EAAE,gBAAgB;IAClB,EAAE,8BAA8B;CACjC;AAED;;;;;;;;;;GAUG;AACH,oBAAY,sBAAsB,GAAG;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,aAAa,CAAC,EAAE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eAAe,iBAAiB,CAAC"}
|
|
@@ -42,7 +42,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
42
42
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
43
43
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
44
44
|
};
|
|
45
|
-
var _KeyringController_instances, _KeyringController_keyring, _KeyringController_registerMessageHandlers, _KeyringController_addQRKeyring, _KeyringController_fullUpdate, _KeyringController_handleLock, _KeyringController_handleUnlock, _KeyringController_getMemState;
|
|
45
|
+
var _KeyringController_instances, _KeyringController_keyring, _KeyringController_qrKeyringStateListener, _KeyringController_registerMessageHandlers, _KeyringController_addQRKeyring, _KeyringController_subscribeToQRKeyringEvents, _KeyringController_unsubscribeFromQRKeyringsEvents, _KeyringController_fullUpdate, _KeyringController_handleLock, _KeyringController_handleUnlock, _KeyringController_getMemState;
|
|
46
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
47
|
exports.KeyringController = exports.SignTypedDataVersion = exports.AccountImportStrategy = exports.KeyringTypes = void 0;
|
|
48
48
|
const base_controller_1 = require("@metamask/base-controller");
|
|
@@ -110,7 +110,6 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
|
|
|
110
110
|
* Creates a KeyringController instance.
|
|
111
111
|
*
|
|
112
112
|
* @param opts - Initial options used to configure this controller
|
|
113
|
-
* @param opts.removeIdentity - Remove the identity with the given address.
|
|
114
113
|
* @param opts.syncIdentities - Sync identities with the given list of addresses.
|
|
115
114
|
* @param opts.updateIdentities - Generate an identity for each address given that doesn't already have an identity.
|
|
116
115
|
* @param opts.setSelectedAddress - Set the selected address.
|
|
@@ -121,7 +120,7 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
|
|
|
121
120
|
* @param opts.messenger - A restricted controller messenger.
|
|
122
121
|
* @param opts.state - Initial state to set on this controller.
|
|
123
122
|
*/
|
|
124
|
-
constructor({
|
|
123
|
+
constructor({ syncIdentities, updateIdentities, setSelectedAddress, setAccountLabel, encryptor, keyringBuilders, cacheEncryptionKey = false, messenger, state, }) {
|
|
125
124
|
super({
|
|
126
125
|
name,
|
|
127
126
|
metadata: {
|
|
@@ -137,6 +136,7 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
|
|
|
137
136
|
_KeyringController_instances.add(this);
|
|
138
137
|
this.mutex = new async_mutex_1.Mutex();
|
|
139
138
|
_KeyringController_keyring.set(this, void 0);
|
|
139
|
+
_KeyringController_qrKeyringStateListener.set(this, void 0);
|
|
140
140
|
__classPrivateFieldSet(this, _KeyringController_keyring, new eth_keyring_controller_1.KeyringController({
|
|
141
141
|
initState: state,
|
|
142
142
|
encryptor,
|
|
@@ -147,7 +147,6 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
|
|
|
147
147
|
__classPrivateFieldGet(this, _KeyringController_keyring, "f").store.subscribe(__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_fullUpdate).bind(this));
|
|
148
148
|
__classPrivateFieldGet(this, _KeyringController_keyring, "f").on('lock', __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_handleLock).bind(this));
|
|
149
149
|
__classPrivateFieldGet(this, _KeyringController_keyring, "f").on('unlock', __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_handleUnlock).bind(this));
|
|
150
|
-
this.removeIdentity = removeIdentity;
|
|
151
150
|
this.syncIdentities = syncIdentities;
|
|
152
151
|
this.updateIdentities = updateIdentities;
|
|
153
152
|
this.setSelectedAddress = setSelectedAddress;
|
|
@@ -202,15 +201,17 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
|
|
|
202
201
|
*/
|
|
203
202
|
addNewAccountForKeyring(keyring, accountCount) {
|
|
204
203
|
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
-
const oldAccounts = yield
|
|
204
|
+
const oldAccounts = yield this.getAccounts();
|
|
206
205
|
if (accountCount && oldAccounts.length !== accountCount) {
|
|
207
206
|
if (accountCount > oldAccounts.length) {
|
|
208
207
|
throw new Error('Account out of sequence');
|
|
209
208
|
}
|
|
210
|
-
|
|
209
|
+
const existingAccount = oldAccounts[accountCount];
|
|
210
|
+
(0, utils_1.assertIsStrictHexString)(existingAccount);
|
|
211
|
+
return existingAccount;
|
|
211
212
|
}
|
|
212
213
|
yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").addNewAccount(keyring);
|
|
213
|
-
const addedAccountAddress = (yield
|
|
214
|
+
const addedAccountAddress = (yield this.getAccounts()).find((selectedAddress) => !oldAccounts.includes(selectedAddress));
|
|
214
215
|
(0, utils_1.assertIsStrictHexString)(addedAccountAddress);
|
|
215
216
|
this.updateIdentities(yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts());
|
|
216
217
|
return addedAccountAddress;
|
|
@@ -291,6 +292,9 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
|
|
|
291
292
|
*/
|
|
292
293
|
addNewKeyring(type, opts) {
|
|
293
294
|
return __awaiter(this, void 0, void 0, function* () {
|
|
295
|
+
if (type === KeyringTypes.qr) {
|
|
296
|
+
return this.getOrAddQRKeyring();
|
|
297
|
+
}
|
|
294
298
|
return __classPrivateFieldGet(this, _KeyringController_keyring, "f").addNewKeyring(type, opts);
|
|
295
299
|
});
|
|
296
300
|
}
|
|
@@ -480,7 +484,6 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
|
|
|
480
484
|
*/
|
|
481
485
|
removeAccount(address) {
|
|
482
486
|
return __awaiter(this, void 0, void 0, function* () {
|
|
483
|
-
this.removeIdentity(address);
|
|
484
487
|
yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").removeAccount(address);
|
|
485
488
|
this.messagingSystem.publish(`${name}:accountRemoved`, address);
|
|
486
489
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getMemState).call(this);
|
|
@@ -493,6 +496,7 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
|
|
|
493
496
|
*/
|
|
494
497
|
setLocked() {
|
|
495
498
|
return __awaiter(this, void 0, void 0, function* () {
|
|
499
|
+
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_unsubscribeFromQRKeyringsEvents).call(this);
|
|
496
500
|
yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").setLocked();
|
|
497
501
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getMemState).call(this);
|
|
498
502
|
});
|
|
@@ -554,10 +558,11 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
|
|
|
554
558
|
*
|
|
555
559
|
* @param transaction - Transaction object to sign. Must be a `ethereumjs-tx` transaction instance.
|
|
556
560
|
* @param from - Address to sign from, should be in keychain.
|
|
561
|
+
* @param opts - An optional options object.
|
|
557
562
|
* @returns Promise resolving to a signed transaction string.
|
|
558
563
|
*/
|
|
559
|
-
signTransaction(transaction, from) {
|
|
560
|
-
return __classPrivateFieldGet(this, _KeyringController_keyring, "f").signTransaction(transaction, from);
|
|
564
|
+
signTransaction(transaction, from, opts) {
|
|
565
|
+
return __classPrivateFieldGet(this, _KeyringController_keyring, "f").signTransaction(transaction, from, opts);
|
|
561
566
|
}
|
|
562
567
|
/**
|
|
563
568
|
* Attempts to decrypt the current vault and load its keyrings,
|
|
@@ -570,6 +575,12 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
|
|
|
570
575
|
submitEncryptionKey(encryptionKey, encryptionSalt) {
|
|
571
576
|
return __awaiter(this, void 0, void 0, function* () {
|
|
572
577
|
yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").submitEncryptionKey(encryptionKey, encryptionSalt);
|
|
578
|
+
const qrKeyring = this.getQRKeyring();
|
|
579
|
+
if (qrKeyring) {
|
|
580
|
+
// if there is a QR keyring, we need to subscribe
|
|
581
|
+
// to its events after unlocking the vault
|
|
582
|
+
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_subscribeToQRKeyringEvents).call(this, qrKeyring);
|
|
583
|
+
}
|
|
573
584
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getMemState).call(this);
|
|
574
585
|
});
|
|
575
586
|
}
|
|
@@ -584,6 +595,12 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
|
|
|
584
595
|
return __awaiter(this, void 0, void 0, function* () {
|
|
585
596
|
yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").submitPassword(password);
|
|
586
597
|
const accounts = yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts();
|
|
598
|
+
const qrKeyring = this.getQRKeyring();
|
|
599
|
+
if (qrKeyring) {
|
|
600
|
+
// if there is a QR keyring, we need to subscribe
|
|
601
|
+
// to its events after unlocking the vault
|
|
602
|
+
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_subscribeToQRKeyringEvents).call(this, qrKeyring);
|
|
603
|
+
}
|
|
587
604
|
yield this.syncIdentities(accounts);
|
|
588
605
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getMemState).call(this);
|
|
589
606
|
});
|
|
@@ -633,14 +650,22 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
|
|
|
633
650
|
}
|
|
634
651
|
// QR Hardware related methods
|
|
635
652
|
/**
|
|
636
|
-
* Get
|
|
653
|
+
* Get QR Hardware keyring.
|
|
654
|
+
*
|
|
655
|
+
* @returns The QR Keyring if defined, otherwise undefined
|
|
656
|
+
*/
|
|
657
|
+
getQRKeyring() {
|
|
658
|
+
// QRKeyring is not yet compatible with Keyring type from @metamask/utils
|
|
659
|
+
return __classPrivateFieldGet(this, _KeyringController_keyring, "f").getKeyringsByType(KeyringTypes.qr)[0];
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Get QR hardware keyring. If it doesn't exist, add it.
|
|
637
663
|
*
|
|
638
664
|
* @returns The added keyring
|
|
639
665
|
*/
|
|
640
666
|
getOrAddQRKeyring() {
|
|
641
667
|
return __awaiter(this, void 0, void 0, function* () {
|
|
642
|
-
|
|
643
|
-
return keyring;
|
|
668
|
+
return this.getQRKeyring() || (yield __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_addQRKeyring).call(this));
|
|
644
669
|
});
|
|
645
670
|
}
|
|
646
671
|
restoreQRKeyring(serialized) {
|
|
@@ -756,7 +781,7 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
|
|
|
756
781
|
}
|
|
757
782
|
}
|
|
758
783
|
exports.KeyringController = KeyringController;
|
|
759
|
-
_KeyringController_keyring = new WeakMap(), _KeyringController_instances = new WeakSet(), _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
|
|
784
|
+
_KeyringController_keyring = new WeakMap(), _KeyringController_qrKeyringStateListener = new WeakMap(), _KeyringController_instances = new WeakSet(), _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
|
|
760
785
|
this.messagingSystem.registerActionHandler(`${name}:signMessage`, this.signMessage.bind(this));
|
|
761
786
|
this.messagingSystem.registerActionHandler(`${name}:signPersonalMessage`, this.signPersonalMessage.bind(this));
|
|
762
787
|
this.messagingSystem.registerActionHandler(`${name}:signTypedMessage`, this.signTypedMessage.bind(this));
|
|
@@ -768,10 +793,32 @@ _KeyringController_keyring = new WeakMap(), _KeyringController_instances = new W
|
|
|
768
793
|
}, _KeyringController_addQRKeyring = function _KeyringController_addQRKeyring() {
|
|
769
794
|
return __awaiter(this, void 0, void 0, function* () {
|
|
770
795
|
// QRKeyring is not yet compatible with Keyring type from @metamask/utils
|
|
771
|
-
|
|
796
|
+
const qrKeyring = (yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").addNewKeyring(KeyringTypes.qr));
|
|
797
|
+
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_subscribeToQRKeyringEvents).call(this, qrKeyring);
|
|
798
|
+
return qrKeyring;
|
|
799
|
+
});
|
|
800
|
+
}, _KeyringController_subscribeToQRKeyringEvents = function _KeyringController_subscribeToQRKeyringEvents(qrKeyring) {
|
|
801
|
+
__classPrivateFieldSet(this, _KeyringController_qrKeyringStateListener, (state) => {
|
|
802
|
+
this.messagingSystem.publish(`${name}:qrKeyringStateChange`, state);
|
|
803
|
+
}, "f");
|
|
804
|
+
qrKeyring.getMemStore().subscribe(__classPrivateFieldGet(this, _KeyringController_qrKeyringStateListener, "f"));
|
|
805
|
+
}, _KeyringController_unsubscribeFromQRKeyringsEvents = function _KeyringController_unsubscribeFromQRKeyringsEvents() {
|
|
806
|
+
const qrKeyrings = __classPrivateFieldGet(this, _KeyringController_keyring, "f").getKeyringsByType(KeyringTypes.qr);
|
|
807
|
+
qrKeyrings.forEach((qrKeyring) => {
|
|
808
|
+
if (__classPrivateFieldGet(this, _KeyringController_qrKeyringStateListener, "f")) {
|
|
809
|
+
qrKeyring.getMemStore().unsubscribe(__classPrivateFieldGet(this, _KeyringController_qrKeyringStateListener, "f"));
|
|
810
|
+
}
|
|
772
811
|
});
|
|
773
812
|
}, _KeyringController_fullUpdate = function _KeyringController_fullUpdate() {
|
|
774
|
-
|
|
813
|
+
const { vault } = __classPrivateFieldGet(this, _KeyringController_keyring, "f").store.getState();
|
|
814
|
+
const { keyrings, isUnlocked, encryptionKey, encryptionSalt } = __classPrivateFieldGet(this, _KeyringController_keyring, "f").memStore.getState();
|
|
815
|
+
this.update(() => ({
|
|
816
|
+
vault,
|
|
817
|
+
keyrings,
|
|
818
|
+
isUnlocked,
|
|
819
|
+
encryptionKey,
|
|
820
|
+
encryptionSalt,
|
|
821
|
+
}));
|
|
775
822
|
}, _KeyringController_handleLock = function _KeyringController_handleLock() {
|
|
776
823
|
this.messagingSystem.publish(`${name}:lock`);
|
|
777
824
|
}, _KeyringController_handleUnlock = function _KeyringController_handleUnlock() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyringController.js","sourceRoot":"","sources":["../src/KeyringController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,+DAA6D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ourcesContent":["import type { TxData, TypedTransaction } from '@ethereumjs/tx';\nimport {\n type MetaMaskKeyring as QRKeyring,\n type IKeyringState as IQRKeyringState,\n} from '@keystonehq/metamask-airgapped-keyring';\nimport type { RestrictedControllerMessenger } from '@metamask/base-controller';\nimport { BaseControllerV2 } from '@metamask/base-controller';\nimport { KeyringController as EthKeyringController } from '@metamask/eth-keyring-controller';\nimport type {\n PersonalMessageParams,\n TypedMessageParams,\n} from '@metamask/message-manager';\nimport type { PreferencesController } from '@metamask/preferences-controller';\nimport type { Eip1024EncryptedData, Hex, Keyring, Json } from '@metamask/utils';\nimport { assertIsStrictHexString, hasProperty } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport {\n addHexPrefix,\n bufferToHex,\n isValidPrivate,\n toBuffer,\n stripHexPrefix,\n getBinarySize,\n} from 'ethereumjs-util';\nimport Wallet, { thirdparty as importers } from 'ethereumjs-wallet';\nimport type { Patch } from 'immer';\n\nconst name = 'KeyringController';\n\n/**\n * Available keyring types\n */\nexport enum KeyringTypes {\n simple = 'Simple Key Pair',\n hd = 'HD Key Tree',\n qr = 'QR Hardware Wallet Device',\n}\n\n/**\n * @type KeyringControllerState\n *\n * Keyring controller state\n * @property vault - Encrypted string representing keyring data\n * @property isUnlocked - Whether vault is unlocked\n * @property keyringTypes - Account types\n * @property keyrings - Group of accounts\n * @property encryptionKey - Keyring encryption key\n * @property encryptionSalt - Keyring encryption salt\n */\nexport type KeyringControllerState = {\n vault?: string;\n isUnlocked: boolean;\n keyrings: KeyringObject[];\n encryptionKey?: string;\n encryptionSalt?: string;\n};\n\nexport type KeyringControllerMemState = Omit<\n KeyringControllerState,\n 'vault' | 'encryptionKey' | 'encryptionSalt'\n>;\n\nexport type KeyringControllerGetStateAction = {\n type: `${typeof name}:getState`;\n handler: () => KeyringControllerState;\n};\n\nexport type KeyringControllerSignMessageAction = {\n type: `${typeof name}:signMessage`;\n handler: KeyringController['signMessage'];\n};\n\nexport type KeyringControllerSignPersonalMessageAction = {\n type: `${typeof name}:signPersonalMessage`;\n handler: KeyringController['signPersonalMessage'];\n};\n\nexport type KeyringControllerSignTypedMessageAction = {\n type: `${typeof name}:signTypedMessage`;\n handler: KeyringController['signTypedMessage'];\n};\n\nexport type KeyringControllerDecryptMessageAction = {\n type: `${typeof name}:decryptMessage`;\n handler: KeyringController['decryptMessage'];\n};\n\nexport type KeyringControllerGetEncryptionPublicKeyAction = {\n type: `${typeof name}:getEncryptionPublicKey`;\n handler: KeyringController['getEncryptionPublicKey'];\n};\n\nexport type KeyringControllerGetKeyringsByTypeAction = {\n type: `${typeof name}:getKeyringsByType`;\n handler: KeyringController['getKeyringsByType'];\n};\n\nexport type KeyringControllerGetKeyringForAccountAction = {\n type: `${typeof name}:getKeyringForAccount`;\n handler: KeyringController['getKeyringForAccount'];\n};\n\nexport type KeyringControllerGetAccountsAction = {\n type: `${typeof name}:getAccounts`;\n handler: KeyringController['getAccounts'];\n};\n\nexport type KeyringControllerStateChangeEvent = {\n type: `${typeof name}:stateChange`;\n payload: [KeyringControllerState, Patch[]];\n};\n\nexport type KeyringControllerAccountRemovedEvent = {\n type: `${typeof name}:accountRemoved`;\n payload: [string];\n};\n\nexport type KeyringControllerLockEvent = {\n type: `${typeof name}:lock`;\n payload: [];\n};\n\nexport type KeyringControllerUnlockEvent = {\n type: `${typeof name}:unlock`;\n payload: [];\n};\n\nexport type KeyringControllerActions =\n | KeyringControllerGetStateAction\n | KeyringControllerSignMessageAction\n | KeyringControllerSignPersonalMessageAction\n | KeyringControllerSignTypedMessageAction\n | KeyringControllerDecryptMessageAction\n | KeyringControllerGetEncryptionPublicKeyAction\n | KeyringControllerGetAccountsAction\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerGetKeyringForAccountAction;\n\nexport type KeyringControllerEvents =\n | KeyringControllerStateChangeEvent\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent\n | KeyringControllerAccountRemovedEvent;\n\nexport type KeyringControllerMessenger = RestrictedControllerMessenger<\n typeof name,\n KeyringControllerActions,\n KeyringControllerEvents,\n string,\n string\n>;\n\nexport type KeyringControllerOptions = {\n removeIdentity: PreferencesController['removeIdentity'];\n syncIdentities: PreferencesController['syncIdentities'];\n updateIdentities: PreferencesController['updateIdentities'];\n setSelectedAddress: PreferencesController['setSelectedAddress'];\n setAccountLabel?: PreferencesController['setAccountLabel'];\n encryptor?: any;\n keyringBuilders?: { (): Keyring<Json>; type: string }[];\n cacheEncryptionKey?: boolean;\n messenger: KeyringControllerMessenger;\n state?: { vault?: string };\n};\n\n/**\n * @type KeyringObject\n *\n * Keyring object to return in fullUpdate\n * @property type - Keyring type\n * @property accounts - Associated accounts\n */\nexport type KeyringObject = {\n accounts: string[];\n type: string;\n};\n\n/**\n * A strategy for importing an account\n */\nexport enum AccountImportStrategy {\n privateKey = 'privateKey',\n json = 'json',\n}\n\n/**\n * The `signTypedMessage` version\n *\n * @see https://docs.metamask.io/guide/signing-data.html\n */\nexport enum SignTypedDataVersion {\n V1 = 'V1',\n V3 = 'V3',\n V4 = 'V4',\n}\n\nconst defaultState: KeyringControllerState = {\n isUnlocked: false,\n keyrings: [],\n};\n\n/**\n * Assert that the given keyring has an exportable\n * mnemonic.\n *\n * @param keyring - The keyring to check\n * @throws When the keyring does not have a mnemonic\n */\nfunction assertHasUint8ArrayMnemonic(\n keyring: Keyring<Json>,\n): asserts keyring is Keyring<Json> & { mnemonic: Uint8Array } {\n if (\n !(\n hasProperty(keyring, 'mnemonic') && keyring.mnemonic instanceof Uint8Array\n )\n ) {\n throw new Error(\"Can't get mnemonic bytes from keyring\");\n }\n}\n\n/**\n * Controller responsible for establishing and managing user identity.\n *\n * This class is a wrapper around the `eth-keyring-controller` package. The\n * `eth-keyring-controller` manages the \"vault\", which is an encrypted store of private keys, and\n * it manages the wallet \"lock\" state. This wrapper class has convenience methods for interacting\n * with the internal keyring controller and handling certain complex operations that involve the\n * keyrings.\n */\nexport class KeyringController extends BaseControllerV2<\n typeof name,\n KeyringControllerState,\n KeyringControllerMessenger\n> {\n private readonly mutex = new Mutex();\n\n private readonly removeIdentity: PreferencesController['removeIdentity'];\n\n private readonly syncIdentities: PreferencesController['syncIdentities'];\n\n private readonly updateIdentities: PreferencesController['updateIdentities'];\n\n private readonly setSelectedAddress: PreferencesController['setSelectedAddress'];\n\n private readonly setAccountLabel?: PreferencesController['setAccountLabel'];\n\n #keyring: EthKeyringController;\n\n /**\n * Creates a KeyringController instance.\n *\n * @param opts - Initial options used to configure this controller\n * @param opts.removeIdentity - Remove the identity with the given address.\n * @param opts.syncIdentities - Sync identities with the given list of addresses.\n * @param opts.updateIdentities - Generate an identity for each address given that doesn't already have an identity.\n * @param opts.setSelectedAddress - Set the selected address.\n * @param opts.setAccountLabel - Set a new name for account.\n * @param opts.encryptor - An optional object for defining encryption schemes.\n * @param opts.keyringBuilders - Set a new name for account.\n * @param opts.cacheEncryptionKey - Whether to cache or not encryption key.\n * @param opts.messenger - A restricted controller messenger.\n * @param opts.state - Initial state to set on this controller.\n */\n constructor({\n removeIdentity,\n syncIdentities,\n updateIdentities,\n setSelectedAddress,\n setAccountLabel,\n encryptor,\n keyringBuilders,\n cacheEncryptionKey = false,\n messenger,\n state,\n }: KeyringControllerOptions) {\n super({\n name,\n metadata: {\n vault: { persist: true, anonymous: false },\n isUnlocked: { persist: false, anonymous: true },\n keyrings: { persist: false, anonymous: false },\n encryptionKey: { persist: false, anonymous: false },\n encryptionSalt: { persist: false, anonymous: false },\n },\n messenger,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n this.#keyring = new EthKeyringController({\n initState: state,\n encryptor,\n keyringBuilders,\n cacheEncryptionKey,\n });\n this.#keyring.memStore.subscribe(this.#fullUpdate.bind(this));\n this.#keyring.store.subscribe(this.#fullUpdate.bind(this));\n this.#keyring.on('lock', this.#handleLock.bind(this));\n this.#keyring.on('unlock', this.#handleUnlock.bind(this));\n\n this.removeIdentity = removeIdentity;\n this.syncIdentities = syncIdentities;\n this.updateIdentities = updateIdentities;\n this.setSelectedAddress = setSelectedAddress;\n this.setAccountLabel = setAccountLabel;\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Adds a new account to the default (first) HD seed phrase keyring.\n *\n * @param accountCount - Number of accounts before adding a new one, used to\n * make the method idempotent.\n * @returns Promise resolving to keyring current state and added account\n * address.\n */\n async addNewAccount(accountCount?: number): Promise<{\n keyringState: KeyringControllerMemState;\n addedAccountAddress: string;\n }> {\n const primaryKeyring = this.#keyring.getKeyringsByType('HD Key Tree')[0];\n /* istanbul ignore if */\n if (!primaryKeyring) {\n throw new Error('No HD keyring found');\n }\n const oldAccounts = await this.#keyring.getAccounts();\n\n if (accountCount && oldAccounts.length !== accountCount) {\n if (accountCount > oldAccounts.length) {\n throw new Error('Account out of sequence');\n }\n // we return the account already existing at index `accountCount`\n const primaryKeyringAccounts = await primaryKeyring.getAccounts();\n return {\n keyringState: this.#getMemState(),\n addedAccountAddress: primaryKeyringAccounts[accountCount],\n };\n }\n\n await this.#keyring.addNewAccount(primaryKeyring);\n const newAccounts = await this.#keyring.getAccounts();\n\n await this.verifySeedPhrase();\n\n this.updateIdentities(newAccounts);\n const addedAccountAddress = newAccounts.find(\n (selectedAddress: string) => !oldAccounts.includes(selectedAddress),\n );\n\n assertIsStrictHexString(addedAccountAddress);\n return {\n keyringState: this.#getMemState(),\n addedAccountAddress,\n };\n }\n\n /**\n * Adds a new account to the specified keyring.\n *\n * @param keyring - Keyring to add the account to.\n * @param accountCount - Number of accounts before adding a new one, used to make the method idempotent.\n * @returns Promise resolving to keyring current state and added account\n */\n async addNewAccountForKeyring(\n keyring: Keyring<Json>,\n accountCount?: number,\n ): Promise<Hex> {\n const oldAccounts = await keyring.getAccounts();\n\n if (accountCount && oldAccounts.length !== accountCount) {\n if (accountCount > oldAccounts.length) {\n throw new Error('Account out of sequence');\n }\n return oldAccounts[accountCount];\n }\n\n await this.#keyring.addNewAccount(keyring);\n const addedAccountAddress = (await keyring.getAccounts()).find(\n (selectedAddress) => !oldAccounts.includes(selectedAddress),\n );\n assertIsStrictHexString(addedAccountAddress);\n\n this.updateIdentities(await this.#keyring.getAccounts());\n\n return addedAccountAddress;\n }\n\n /**\n * Adds a new account to the default (first) HD seed phrase keyring without updating identities in preferences.\n *\n * @returns Promise resolving to current state when the account is added.\n */\n async addNewAccountWithoutUpdate(): Promise<KeyringControllerMemState> {\n const primaryKeyring = this.#keyring.getKeyringsByType('HD Key Tree')[0];\n /* istanbul ignore if */\n if (!primaryKeyring) {\n throw new Error('No HD keyring found');\n }\n await this.#keyring.addNewAccount(primaryKeyring);\n await this.verifySeedPhrase();\n return this.#getMemState();\n }\n\n /**\n * Effectively the same as creating a new keychain then populating it\n * using the given seed phrase.\n *\n * @param password - Password to unlock keychain.\n * @param seed - A BIP39-compliant seed phrase as Uint8Array,\n * either as a string or an array of UTF-8 bytes that represent the string.\n * @returns Promise resolving to the restored keychain object.\n */\n async createNewVaultAndRestore(\n password: string,\n seed: Uint8Array,\n ): Promise<KeyringControllerMemState> {\n const releaseLock = await this.mutex.acquire();\n if (!password || !password.length) {\n throw new Error('Invalid password');\n }\n\n try {\n this.updateIdentities([]);\n await this.#keyring.createNewVaultAndRestore(password, seed);\n this.updateIdentities(await this.#keyring.getAccounts());\n return this.#getMemState();\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Create a new primary keychain and wipe any previous keychains.\n *\n * @param password - Password to unlock the new vault.\n * @returns Newly-created keychain object.\n */\n async createNewVaultAndKeychain(password: string) {\n const releaseLock = await this.mutex.acquire();\n try {\n const accounts = await this.getAccounts();\n if (!accounts.length) {\n await this.#keyring.createNewVaultAndKeychain(password);\n this.updateIdentities(await this.getAccounts());\n }\n return this.#getMemState();\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Adds a new keyring of the given `type`.\n *\n * @param type - Keyring type name.\n * @param opts - Keyring options.\n * @throws If a builder for the given `type` does not exist.\n * @returns Promise resolving to the added keyring.\n */\n async addNewKeyring(\n type: KeyringTypes | string,\n opts?: unknown,\n ): Promise<Keyring<Json>> {\n return this.#keyring.addNewKeyring(type, opts);\n }\n\n /**\n * Method to verify a given password validity. Throws an\n * error if the password is invalid.\n *\n * @param password - Password of the keyring.\n */\n async verifyPassword(password: string) {\n await this.#keyring.verifyPassword(password);\n }\n\n /**\n * Returns the status of the vault.\n *\n * @returns Boolean returning true if the vault is unlocked.\n */\n isUnlocked(): boolean {\n return this.state.isUnlocked;\n }\n\n /**\n * Gets the seed phrase of the HD keyring.\n *\n * @param password - Password of the keyring.\n * @returns Promise resolving to the seed phrase.\n */\n async exportSeedPhrase(password: string): Promise<Uint8Array> {\n await this.verifyPassword(password);\n assertHasUint8ArrayMnemonic(this.#keyring.keyrings[0]);\n return this.#keyring.keyrings[0].mnemonic;\n }\n\n /**\n * Gets the private key from the keyring controlling an address.\n *\n * @param password - Password of the keyring.\n * @param address - Address to export.\n * @returns Promise resolving to the private key for an address.\n */\n async exportAccount(password: string, address: string): Promise<string> {\n await this.verifyPassword(password);\n return this.#keyring.exportAccount(address);\n }\n\n /**\n * Returns the public addresses of all accounts for the current keyring.\n *\n * @returns A promise resolving to an array of addresses.\n */\n getAccounts(): Promise<string[]> {\n return this.#keyring.getAccounts();\n }\n\n /**\n * Get encryption public key.\n *\n * @param account - An account address.\n * @param opts - Additional encryption options.\n * @throws If the `account` does not exist or does not support the `getEncryptionPublicKey` method\n * @returns Promise resolving to encyption public key of the `account` if one exists.\n */\n async getEncryptionPublicKey(\n account: string,\n opts?: Record<string, unknown>,\n ): Promise<string> {\n return this.#keyring.getEncryptionPublicKey(account, opts);\n }\n\n /**\n * Attempts to decrypt the provided message parameters.\n *\n * @param messageParams - The decryption message parameters.\n * @param messageParams.from - The address of the account you want to use to decrypt the message.\n * @param messageParams.data - The encrypted data that you want to decrypt.\n * @returns The raw decryption result.\n */\n async decryptMessage(messageParams: {\n from: string;\n data: Eip1024EncryptedData;\n }): Promise<string> {\n return this.#keyring.decryptMessage(messageParams);\n }\n\n /**\n * Returns the currently initialized keyring that manages\n * the specified `address` if one exists.\n *\n * @deprecated Use of this method is discouraged as actions executed directly on\n * keyrings are not being reflected in the KeyringController state and not\n * persisted in the vault.\n * @param account - An account address.\n * @returns Promise resolving to keyring of the `account` if one exists.\n */\n async getKeyringForAccount(account: string): Promise<unknown> {\n return this.#keyring.getKeyringForAccount(account);\n }\n\n /**\n * Returns all keyrings of the given type.\n *\n * @deprecated Use of this method is discouraged as actions executed directly on\n * keyrings are not being reflected in the KeyringController state and not\n * persisted in the vault.\n * @param type - Keyring type name.\n * @returns An array of keyrings of the given type.\n */\n getKeyringsByType(type: KeyringTypes | string): unknown[] {\n return this.#keyring.getKeyringsByType(type);\n }\n\n /**\n * Persist all serialized keyrings in the vault.\n *\n * @returns Promise resolving with `true` value when the\n * operation completes.\n */\n async persistAllKeyrings(): Promise<boolean> {\n return this.#keyring.persistAllKeyrings();\n }\n\n /**\n * Imports an account with the specified import strategy.\n *\n * @param strategy - Import strategy name.\n * @param args - Array of arguments to pass to the underlying stategy.\n * @throws Will throw when passed an unrecognized strategy.\n * @returns Promise resolving to keyring current state and imported account\n * address.\n */\n async importAccountWithStrategy(\n strategy: AccountImportStrategy,\n args: any[],\n ): Promise<{\n keyringState: KeyringControllerMemState;\n importedAccountAddress: string;\n }> {\n let privateKey;\n switch (strategy) {\n case 'privateKey':\n const [importedKey] = args;\n if (!importedKey) {\n throw new Error('Cannot import an empty key.');\n }\n const prefixed = addHexPrefix(importedKey);\n\n let bufferedPrivateKey;\n try {\n bufferedPrivateKey = toBuffer(prefixed);\n } catch {\n throw new Error('Cannot import invalid private key.');\n }\n\n /* istanbul ignore if */\n if (\n !isValidPrivate(bufferedPrivateKey) ||\n // ensures that the key is 64 bytes long\n getBinarySize(prefixed) !== 64 + '0x'.length\n ) {\n throw new Error('Cannot import invalid private key.');\n }\n\n privateKey = stripHexPrefix(prefixed);\n break;\n case 'json':\n let wallet;\n const [input, password] = args;\n try {\n wallet = importers.fromEtherWallet(input, password);\n } catch (e) {\n wallet = wallet || (await Wallet.fromV3(input, password, true));\n }\n privateKey = bufferToHex(wallet.getPrivateKey());\n break;\n default:\n throw new Error(`Unexpected import strategy: '${strategy}'`);\n }\n const newKeyring = await this.#keyring.addNewKeyring(KeyringTypes.simple, [\n privateKey,\n ]);\n const accounts = await newKeyring.getAccounts();\n const allAccounts = await this.#keyring.getAccounts();\n this.updateIdentities(allAccounts);\n return {\n keyringState: this.#getMemState(),\n importedAccountAddress: accounts[0],\n };\n }\n\n /**\n * Removes an account from keyring state.\n *\n * @param address - Address of the account to remove.\n * @fires KeyringController:accountRemoved\n * @returns Promise resolving current state when this account removal completes.\n */\n async removeAccount(address: Hex): Promise<KeyringControllerMemState> {\n this.removeIdentity(address);\n await this.#keyring.removeAccount(address);\n this.messagingSystem.publish(`${name}:accountRemoved`, address);\n return this.#getMemState();\n }\n\n /**\n * Deallocates all secrets and locks the wallet.\n *\n * @returns Promise resolving to current state.\n */\n async setLocked(): Promise<KeyringControllerMemState> {\n await this.#keyring.setLocked();\n return this.#getMemState();\n }\n\n /**\n * Signs message by calling down into a specific keyring.\n *\n * @param messageParams - PersonalMessageParams object to sign.\n * @returns Promise resolving to a signed message string.\n */\n signMessage(messageParams: PersonalMessageParams) {\n if (!messageParams.data) {\n throw new Error(\"Can't sign an empty message\");\n }\n return this.#keyring.signMessage(messageParams);\n }\n\n /**\n * Signs personal message by calling down into a specific keyring.\n *\n * @param messageParams - PersonalMessageParams object to sign.\n * @returns Promise resolving to a signed message string.\n */\n signPersonalMessage(messageParams: PersonalMessageParams) {\n return this.#keyring.signPersonalMessage(messageParams);\n }\n\n /**\n * Signs typed message by calling down into a specific keyring.\n *\n * @param messageParams - TypedMessageParams object to sign.\n * @param version - Compatibility version EIP712.\n * @throws Will throw when passed an unrecognized version.\n * @returns Promise resolving to a signed message string or an error if any.\n */\n async signTypedMessage(\n messageParams: TypedMessageParams,\n version: SignTypedDataVersion,\n ): Promise<string> {\n try {\n if (\n ![\n SignTypedDataVersion.V1,\n SignTypedDataVersion.V3,\n SignTypedDataVersion.V4,\n ].includes(version)\n ) {\n throw new Error(`Unexpected signTypedMessage version: '${version}'`);\n }\n\n return await this.#keyring.signTypedMessage(\n {\n from: messageParams.from,\n data:\n version !== SignTypedDataVersion.V1 &&\n typeof messageParams.data === 'string'\n ? JSON.parse(messageParams.data)\n : messageParams.data,\n },\n { version },\n );\n } catch (error) {\n throw new Error(`Keyring Controller signTypedMessage: ${error}`);\n }\n }\n\n /**\n * Signs a transaction by calling down into a specific keyring.\n *\n * @param transaction - Transaction object to sign. Must be a `ethereumjs-tx` transaction instance.\n * @param from - Address to sign from, should be in keychain.\n * @returns Promise resolving to a signed transaction string.\n */\n signTransaction(\n transaction: TypedTransaction,\n from: string,\n ): Promise<TxData> {\n return this.#keyring.signTransaction(transaction, from);\n }\n\n /**\n * Attempts to decrypt the current vault and load its keyrings,\n * using the given encryption key and salt.\n *\n * @param encryptionKey - Key to unlock the keychain.\n * @param encryptionSalt - Salt to unlock the keychain.\n * @returns Promise resolving to the current state.\n */\n async submitEncryptionKey(\n encryptionKey: string,\n encryptionSalt: string,\n ): Promise<KeyringControllerMemState> {\n await this.#keyring.submitEncryptionKey(encryptionKey, encryptionSalt);\n return this.#getMemState();\n }\n\n /**\n * Attempts to decrypt the current vault and load its keyrings,\n * using the given password.\n *\n * @param password - Password to unlock the keychain.\n * @returns Promise resolving to the current state.\n */\n async submitPassword(password: string): Promise<KeyringControllerMemState> {\n await this.#keyring.submitPassword(password);\n const accounts = await this.#keyring.getAccounts();\n await this.syncIdentities(accounts);\n return this.#getMemState();\n }\n\n /**\n * Verifies the that the seed phrase restores the current keychain's accounts.\n *\n * @returns Promise resolving to the seed phrase as Uint8Array.\n */\n async verifySeedPhrase(): Promise<Uint8Array> {\n const primaryKeyring = this.#keyring.getKeyringsByType(KeyringTypes.hd)[0];\n /* istanbul ignore if */\n if (!primaryKeyring) {\n throw new Error('No HD keyring found.');\n }\n\n assertHasUint8ArrayMnemonic(primaryKeyring);\n\n const seedWords = primaryKeyring.mnemonic;\n const accounts = await primaryKeyring.getAccounts();\n /* istanbul ignore if */\n if (accounts.length === 0) {\n throw new Error('Cannot verify an empty keyring.');\n }\n\n // The HD Keyring Builder is a default keyring builder\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const hdKeyringBuilder = this.#keyring.getKeyringBuilderForType(\n KeyringTypes.hd,\n )!;\n\n const hdKeyring = hdKeyringBuilder();\n // @ts-expect-error @metamask/eth-hd-keyring correctly handles\n // Uint8Array seed phrases in the `deserialize` method.\n hdKeyring.deserialize({\n mnemonic: seedWords,\n numberOfAccounts: accounts.length,\n });\n const testAccounts = await hdKeyring.getAccounts();\n /* istanbul ignore if */\n if (testAccounts.length !== accounts.length) {\n throw new Error('Seed phrase imported incorrect number of accounts.');\n }\n\n testAccounts.forEach((account: string, i: number) => {\n /* istanbul ignore if */\n if (account.toLowerCase() !== accounts[i].toLowerCase()) {\n throw new Error('Seed phrase imported different accounts.');\n }\n });\n\n return seedWords;\n }\n\n // QR Hardware related methods\n\n /**\n * Get qr hardware keyring.\n *\n * @returns The added keyring\n */\n async getOrAddQRKeyring(): Promise<QRKeyring> {\n const keyring =\n (this.#keyring.getKeyringsByType(\n KeyringTypes.qr,\n )[0] as unknown as QRKeyring) || (await this.#addQRKeyring());\n return keyring;\n }\n\n async restoreQRKeyring(serialized: any): Promise<void> {\n (await this.getOrAddQRKeyring()).deserialize(serialized);\n await this.#keyring.persistAllKeyrings();\n this.updateIdentities(await this.#keyring.getAccounts());\n }\n\n async resetQRKeyringState(): Promise<void> {\n (await this.getOrAddQRKeyring()).resetStore();\n }\n\n async getQRKeyringState(): Promise<IQRKeyringState> {\n return (await this.getOrAddQRKeyring()).getMemStore();\n }\n\n async submitQRCryptoHDKey(cryptoHDKey: string): Promise<void> {\n (await this.getOrAddQRKeyring()).submitCryptoHDKey(cryptoHDKey);\n }\n\n async submitQRCryptoAccount(cryptoAccount: string): Promise<void> {\n (await this.getOrAddQRKeyring()).submitCryptoAccount(cryptoAccount);\n }\n\n async submitQRSignature(\n requestId: string,\n ethSignature: string,\n ): Promise<void> {\n (await this.getOrAddQRKeyring()).submitSignature(requestId, ethSignature);\n }\n\n async cancelQRSignRequest(): Promise<void> {\n (await this.getOrAddQRKeyring()).cancelSignRequest();\n }\n\n /**\n * Cancels qr keyring sync.\n */\n async cancelQRSynchronization(): Promise<void> {\n // eslint-disable-next-line n/no-sync\n (await this.getOrAddQRKeyring()).cancelSync();\n }\n\n async connectQRHardware(\n page: number,\n ): Promise<{ balance: string; address: string; index: number }[]> {\n try {\n const keyring = await this.getOrAddQRKeyring();\n let accounts;\n switch (page) {\n case -1:\n accounts = await keyring.getPreviousPage();\n break;\n case 1:\n accounts = await keyring.getNextPage();\n break;\n default:\n accounts = await keyring.getFirstPage();\n }\n return accounts.map((account: any) => {\n return {\n ...account,\n balance: '0x0',\n };\n });\n } catch (e) {\n // TODO: Add test case for when keyring throws\n /* istanbul ignore next */\n throw new Error(`Unspecified error when connect QR Hardware, ${e}`);\n }\n }\n\n async unlockQRHardwareWalletAccount(index: number): Promise<void> {\n const keyring = await this.getOrAddQRKeyring();\n\n keyring.setAccountToUnlock(index);\n const oldAccounts = await this.#keyring.getAccounts();\n // QRKeyring is not yet compatible with Keyring from\n // @metamask/utils, but we can use the `addNewAccount` method\n // as it internally calls `addAccounts` from on the keyring instance,\n // which is supported by QRKeyring API.\n await this.#keyring.addNewAccount(keyring as unknown as Keyring<Json>);\n const newAccounts = await this.#keyring.getAccounts();\n this.updateIdentities(newAccounts);\n newAccounts.forEach((address: string) => {\n if (!oldAccounts.includes(address)) {\n if (this.setAccountLabel) {\n this.setAccountLabel(address, `${keyring.getName()} ${index}`);\n }\n this.setSelectedAddress(address);\n }\n });\n await this.#keyring.persistAllKeyrings();\n }\n\n async getAccountKeyringType(account: string): Promise<string> {\n return (await this.#keyring.getKeyringForAccount(account)).type;\n }\n\n async forgetQRDevice(): Promise<void> {\n const keyring = await this.getOrAddQRKeyring();\n keyring.forgetDevice();\n const accounts = (await this.#keyring.getAccounts()) as string[];\n accounts.forEach((account) => {\n this.setSelectedAddress(account);\n });\n await this.#keyring.persistAllKeyrings();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${name}:signMessage`,\n this.signMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:signPersonalMessage`,\n this.signPersonalMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:signTypedMessage`,\n this.signTypedMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:decryptMessage`,\n this.decryptMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getEncryptionPublicKey`,\n this.getEncryptionPublicKey.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getAccounts`,\n this.getAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getKeyringsByType`,\n this.getKeyringsByType.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getKeyringForAccount`,\n this.getKeyringForAccount.bind(this),\n );\n }\n\n /**\n * Add qr hardware keyring.\n *\n * @returns The added keyring\n * @throws If a QRKeyring builder is not provided\n * when initializing the controller\n */\n async #addQRKeyring(): Promise<QRKeyring> {\n // QRKeyring is not yet compatible with Keyring type from @metamask/utils\n return this.#keyring.addNewKeyring(KeyringTypes.qr) as unknown as QRKeyring;\n }\n\n /**\n * Sync controller state with current keyring store\n * and memStore states.\n *\n * @fires KeyringController:stateChange\n */\n #fullUpdate() {\n this.update(() => ({\n ...this.#keyring.store.getState(),\n ...this.#keyring.memStore.getState(),\n }));\n }\n\n /**\n * Handle keyring lock event.\n *\n * @fires KeyringController:lock\n */\n #handleLock() {\n this.messagingSystem.publish(`${name}:lock`);\n }\n\n /**\n * Handle keyring unlock event.\n *\n * @fires KeyringController:unlock\n */\n #handleUnlock() {\n this.messagingSystem.publish(`${name}:unlock`);\n }\n\n #getMemState(): KeyringControllerMemState {\n return {\n isUnlocked: this.state.isUnlocked,\n keyrings: this.state.keyrings,\n };\n }\n}\n\nexport default KeyringController;\n"]}
|
|
1
|
+
{"version":3,"file":"KeyringController.js","sourceRoot":"","sources":["../src/KeyringController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,+DAA6D;AAC7D,6EAA6F;AAO7F,2CAAuE;AACvE,6CAAoC;AACpC,qDAOyB;AACzB,uEAAoE;AAGpE,MAAM,IAAI,GAAG,mBAAmB,CAAC;AAEjC;;GAEG;AACH,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,0CAA0B,CAAA;IAC1B,kCAAkB,CAAA;IAClB,gDAAgC,CAAA;AAClC,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAkJD;;GAEG;AACH,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,kDAAyB,CAAA;IACzB,sCAAa,CAAA;AACf,CAAC,EAHW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAGhC;AAED;;;;GAIG;AACH,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC9B,iCAAS,CAAA;IACT,iCAAS,CAAA;IACT,iCAAS,CAAA;AACX,CAAC,EAJW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAI/B;AAED,MAAM,YAAY,GAA2B;IAC3C,UAAU,EAAE,KAAK;IACjB,QAAQ,EAAE,EAAE;CACb,CAAC;AAEF;;;;;;GAMG;AACH,SAAS,2BAA2B,CAClC,OAAsB;IAEtB,IACE,CAAC,CACC,IAAA,mBAAW,EAAC,OAAO,EAAE,UAAU,CAAC,IAAI,OAAO,CAAC,QAAQ,YAAY,UAAU,CAC3E,EACD;QACA,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;KAC1D;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAa,iBAAkB,S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QAAQ,CAAC,QAAQ,EAAE,CAAC;IAEpC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QACjB,KAAK;QACL,QAAQ;QACR,UAAU;QACV,aAAa;QACb,cAAc;KACf,CAAC,CAAC,CAAC;AACN,CAAC;IAQC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,CAAC;AAC/C,CAAC;IAQC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,IAAI,SAAS,CAAC,CAAC;AACjD,CAAC;IAGC,OAAO;QACL,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU;QACjC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ;KAC9B,CAAC;AACJ,CAAC;AAGH,kBAAe,iBAAiB,CAAC","sourcesContent":["import type { TxData, TypedTransaction } from '@ethereumjs/tx';\nimport type {\n MetaMaskKeyring as QRKeyring,\n IKeyringState as IQRKeyringState,\n} from '@keystonehq/metamask-airgapped-keyring';\nimport type { RestrictedControllerMessenger } from '@metamask/base-controller';\nimport { BaseControllerV2 } from '@metamask/base-controller';\nimport { KeyringController as EthKeyringController } from '@metamask/eth-keyring-controller';\nimport type {\n PersonalMessageParams,\n TypedMessageParams,\n} from '@metamask/message-manager';\nimport type { PreferencesController } from '@metamask/preferences-controller';\nimport type { Eip1024EncryptedData, Hex, Keyring, Json } from '@metamask/utils';\nimport { assertIsStrictHexString, hasProperty } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport {\n addHexPrefix,\n bufferToHex,\n isValidPrivate,\n toBuffer,\n stripHexPrefix,\n getBinarySize,\n} from 'ethereumjs-util';\nimport Wallet, { thirdparty as importers } from 'ethereumjs-wallet';\nimport type { Patch } from 'immer';\n\nconst name = 'KeyringController';\n\n/**\n * Available keyring types\n */\nexport enum KeyringTypes {\n simple = 'Simple Key Pair',\n hd = 'HD Key Tree',\n qr = 'QR Hardware Wallet Device',\n}\n\n/**\n * @type KeyringControllerState\n *\n * Keyring controller state\n * @property vault - Encrypted string representing keyring data\n * @property isUnlocked - Whether vault is unlocked\n * @property keyringTypes - Account types\n * @property keyrings - Group of accounts\n * @property encryptionKey - Keyring encryption key\n * @property encryptionSalt - Keyring encryption salt\n */\nexport type KeyringControllerState = {\n vault?: string;\n isUnlocked: boolean;\n keyrings: KeyringObject[];\n encryptionKey?: string;\n encryptionSalt?: string;\n};\n\nexport type KeyringControllerMemState = Omit<\n KeyringControllerState,\n 'vault' | 'encryptionKey' | 'encryptionSalt'\n>;\n\nexport type KeyringControllerGetStateAction = {\n type: `${typeof name}:getState`;\n handler: () => KeyringControllerState;\n};\n\nexport type KeyringControllerSignMessageAction = {\n type: `${typeof name}:signMessage`;\n handler: KeyringController['signMessage'];\n};\n\nexport type KeyringControllerSignPersonalMessageAction = {\n type: `${typeof name}:signPersonalMessage`;\n handler: KeyringController['signPersonalMessage'];\n};\n\nexport type KeyringControllerSignTypedMessageAction = {\n type: `${typeof name}:signTypedMessage`;\n handler: KeyringController['signTypedMessage'];\n};\n\nexport type KeyringControllerDecryptMessageAction = {\n type: `${typeof name}:decryptMessage`;\n handler: KeyringController['decryptMessage'];\n};\n\nexport type KeyringControllerGetEncryptionPublicKeyAction = {\n type: `${typeof name}:getEncryptionPublicKey`;\n handler: KeyringController['getEncryptionPublicKey'];\n};\n\nexport type KeyringControllerGetKeyringsByTypeAction = {\n type: `${typeof name}:getKeyringsByType`;\n handler: KeyringController['getKeyringsByType'];\n};\n\nexport type KeyringControllerGetKeyringForAccountAction = {\n type: `${typeof name}:getKeyringForAccount`;\n handler: KeyringController['getKeyringForAccount'];\n};\n\nexport type KeyringControllerGetAccountsAction = {\n type: `${typeof name}:getAccounts`;\n handler: KeyringController['getAccounts'];\n};\n\nexport type KeyringControllerStateChangeEvent = {\n type: `${typeof name}:stateChange`;\n payload: [KeyringControllerState, Patch[]];\n};\n\nexport type KeyringControllerAccountRemovedEvent = {\n type: `${typeof name}:accountRemoved`;\n payload: [string];\n};\n\nexport type KeyringControllerLockEvent = {\n type: `${typeof name}:lock`;\n payload: [];\n};\n\nexport type KeyringControllerUnlockEvent = {\n type: `${typeof name}:unlock`;\n payload: [];\n};\n\nexport type KeyringControllerQRKeyringStateChangeEvent = {\n type: `${typeof name}:qrKeyringStateChange`;\n payload: [ReturnType<IQRKeyringState['getState']>];\n};\n\nexport type KeyringControllerActions =\n | KeyringControllerGetStateAction\n | KeyringControllerSignMessageAction\n | KeyringControllerSignPersonalMessageAction\n | KeyringControllerSignTypedMessageAction\n | KeyringControllerDecryptMessageAction\n | KeyringControllerGetEncryptionPublicKeyAction\n | KeyringControllerGetAccountsAction\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerGetKeyringForAccountAction;\n\nexport type KeyringControllerEvents =\n | KeyringControllerStateChangeEvent\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent\n | KeyringControllerAccountRemovedEvent\n | KeyringControllerQRKeyringStateChangeEvent;\n\nexport type KeyringControllerMessenger = RestrictedControllerMessenger<\n typeof name,\n KeyringControllerActions,\n KeyringControllerEvents,\n string,\n string\n>;\n\nexport type KeyringControllerOptions = {\n syncIdentities: PreferencesController['syncIdentities'];\n updateIdentities: PreferencesController['updateIdentities'];\n setSelectedAddress: PreferencesController['setSelectedAddress'];\n setAccountLabel?: PreferencesController['setAccountLabel'];\n encryptor?: any;\n keyringBuilders?: { (): Keyring<Json>; type: string }[];\n cacheEncryptionKey?: boolean;\n messenger: KeyringControllerMessenger;\n state?: { vault?: string };\n};\n\n/**\n * @type KeyringObject\n *\n * Keyring object to return in fullUpdate\n * @property type - Keyring type\n * @property accounts - Associated accounts\n */\nexport type KeyringObject = {\n accounts: string[];\n type: string;\n};\n\n/**\n * A strategy for importing an account\n */\nexport enum AccountImportStrategy {\n privateKey = 'privateKey',\n json = 'json',\n}\n\n/**\n * The `signTypedMessage` version\n *\n * @see https://docs.metamask.io/guide/signing-data.html\n */\nexport enum SignTypedDataVersion {\n V1 = 'V1',\n V3 = 'V3',\n V4 = 'V4',\n}\n\nconst defaultState: KeyringControllerState = {\n isUnlocked: false,\n keyrings: [],\n};\n\n/**\n * Assert that the given keyring has an exportable\n * mnemonic.\n *\n * @param keyring - The keyring to check\n * @throws When the keyring does not have a mnemonic\n */\nfunction assertHasUint8ArrayMnemonic(\n keyring: Keyring<Json>,\n): asserts keyring is Keyring<Json> & { mnemonic: Uint8Array } {\n if (\n !(\n hasProperty(keyring, 'mnemonic') && keyring.mnemonic instanceof Uint8Array\n )\n ) {\n throw new Error(\"Can't get mnemonic bytes from keyring\");\n }\n}\n\n/**\n * Controller responsible for establishing and managing user identity.\n *\n * This class is a wrapper around the `eth-keyring-controller` package. The\n * `eth-keyring-controller` manages the \"vault\", which is an encrypted store of private keys, and\n * it manages the wallet \"lock\" state. This wrapper class has convenience methods for interacting\n * with the internal keyring controller and handling certain complex operations that involve the\n * keyrings.\n */\nexport class KeyringController extends BaseControllerV2<\n typeof name,\n KeyringControllerState,\n KeyringControllerMessenger\n> {\n private readonly mutex = new Mutex();\n\n private readonly syncIdentities: PreferencesController['syncIdentities'];\n\n private readonly updateIdentities: PreferencesController['updateIdentities'];\n\n private readonly setSelectedAddress: PreferencesController['setSelectedAddress'];\n\n private readonly setAccountLabel?: PreferencesController['setAccountLabel'];\n\n #keyring: EthKeyringController;\n\n #qrKeyringStateListener?: (\n state: ReturnType<IQRKeyringState['getState']>,\n ) => void;\n\n /**\n * Creates a KeyringController instance.\n *\n * @param opts - Initial options used to configure this controller\n * @param opts.syncIdentities - Sync identities with the given list of addresses.\n * @param opts.updateIdentities - Generate an identity for each address given that doesn't already have an identity.\n * @param opts.setSelectedAddress - Set the selected address.\n * @param opts.setAccountLabel - Set a new name for account.\n * @param opts.encryptor - An optional object for defining encryption schemes.\n * @param opts.keyringBuilders - Set a new name for account.\n * @param opts.cacheEncryptionKey - Whether to cache or not encryption key.\n * @param opts.messenger - A restricted controller messenger.\n * @param opts.state - Initial state to set on this controller.\n */\n constructor({\n syncIdentities,\n updateIdentities,\n setSelectedAddress,\n setAccountLabel,\n encryptor,\n keyringBuilders,\n cacheEncryptionKey = false,\n messenger,\n state,\n }: KeyringControllerOptions) {\n super({\n name,\n metadata: {\n vault: { persist: true, anonymous: false },\n isUnlocked: { persist: false, anonymous: true },\n keyrings: { persist: false, anonymous: false },\n encryptionKey: { persist: false, anonymous: false },\n encryptionSalt: { persist: false, anonymous: false },\n },\n messenger,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n this.#keyring = new EthKeyringController({\n initState: state,\n encryptor,\n keyringBuilders,\n cacheEncryptionKey,\n });\n this.#keyring.memStore.subscribe(this.#fullUpdate.bind(this));\n this.#keyring.store.subscribe(this.#fullUpdate.bind(this));\n this.#keyring.on('lock', this.#handleLock.bind(this));\n this.#keyring.on('unlock', this.#handleUnlock.bind(this));\n\n this.syncIdentities = syncIdentities;\n this.updateIdentities = updateIdentities;\n this.setSelectedAddress = setSelectedAddress;\n this.setAccountLabel = setAccountLabel;\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Adds a new account to the default (first) HD seed phrase keyring.\n *\n * @param accountCount - Number of accounts before adding a new one, used to\n * make the method idempotent.\n * @returns Promise resolving to keyring current state and added account\n * address.\n */\n async addNewAccount(accountCount?: number): Promise<{\n keyringState: KeyringControllerMemState;\n addedAccountAddress: string;\n }> {\n const primaryKeyring = this.#keyring.getKeyringsByType('HD Key Tree')[0];\n /* istanbul ignore if */\n if (!primaryKeyring) {\n throw new Error('No HD keyring found');\n }\n const oldAccounts = await this.#keyring.getAccounts();\n\n if (accountCount && oldAccounts.length !== accountCount) {\n if (accountCount > oldAccounts.length) {\n throw new Error('Account out of sequence');\n }\n // we return the account already existing at index `accountCount`\n const primaryKeyringAccounts = await primaryKeyring.getAccounts();\n return {\n keyringState: this.#getMemState(),\n addedAccountAddress: primaryKeyringAccounts[accountCount],\n };\n }\n\n await this.#keyring.addNewAccount(primaryKeyring);\n const newAccounts = await this.#keyring.getAccounts();\n\n await this.verifySeedPhrase();\n\n this.updateIdentities(newAccounts);\n const addedAccountAddress = newAccounts.find(\n (selectedAddress: string) => !oldAccounts.includes(selectedAddress),\n );\n\n assertIsStrictHexString(addedAccountAddress);\n return {\n keyringState: this.#getMemState(),\n addedAccountAddress,\n };\n }\n\n /**\n * Adds a new account to the specified keyring.\n *\n * @param keyring - Keyring to add the account to.\n * @param accountCount - Number of accounts before adding a new one, used to make the method idempotent.\n * @returns Promise resolving to keyring current state and added account\n */\n async addNewAccountForKeyring(\n keyring: Keyring<Json>,\n accountCount?: number,\n ): Promise<Hex> {\n const oldAccounts = await this.getAccounts();\n\n if (accountCount && oldAccounts.length !== accountCount) {\n if (accountCount > oldAccounts.length) {\n throw new Error('Account out of sequence');\n }\n\n const existingAccount = oldAccounts[accountCount];\n assertIsStrictHexString(existingAccount);\n\n return existingAccount;\n }\n\n await this.#keyring.addNewAccount(keyring);\n const addedAccountAddress = (await this.getAccounts()).find(\n (selectedAddress) => !oldAccounts.includes(selectedAddress),\n );\n assertIsStrictHexString(addedAccountAddress);\n\n this.updateIdentities(await this.#keyring.getAccounts());\n\n return addedAccountAddress;\n }\n\n /**\n * Adds a new account to the default (first) HD seed phrase keyring without updating identities in preferences.\n *\n * @returns Promise resolving to current state when the account is added.\n */\n async addNewAccountWithoutUpdate(): Promise<KeyringControllerMemState> {\n const primaryKeyring = this.#keyring.getKeyringsByType('HD Key Tree')[0];\n /* istanbul ignore if */\n if (!primaryKeyring) {\n throw new Error('No HD keyring found');\n }\n await this.#keyring.addNewAccount(primaryKeyring);\n await this.verifySeedPhrase();\n return this.#getMemState();\n }\n\n /**\n * Effectively the same as creating a new keychain then populating it\n * using the given seed phrase.\n *\n * @param password - Password to unlock keychain.\n * @param seed - A BIP39-compliant seed phrase as Uint8Array,\n * either as a string or an array of UTF-8 bytes that represent the string.\n * @returns Promise resolving to the restored keychain object.\n */\n async createNewVaultAndRestore(\n password: string,\n seed: Uint8Array,\n ): Promise<KeyringControllerMemState> {\n const releaseLock = await this.mutex.acquire();\n if (!password || !password.length) {\n throw new Error('Invalid password');\n }\n\n try {\n this.updateIdentities([]);\n await this.#keyring.createNewVaultAndRestore(password, seed);\n this.updateIdentities(await this.#keyring.getAccounts());\n return this.#getMemState();\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Create a new primary keychain and wipe any previous keychains.\n *\n * @param password - Password to unlock the new vault.\n * @returns Newly-created keychain object.\n */\n async createNewVaultAndKeychain(password: string) {\n const releaseLock = await this.mutex.acquire();\n try {\n const accounts = await this.getAccounts();\n if (!accounts.length) {\n await this.#keyring.createNewVaultAndKeychain(password);\n this.updateIdentities(await this.getAccounts());\n }\n return this.#getMemState();\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Adds a new keyring of the given `type`.\n *\n * @param type - Keyring type name.\n * @param opts - Keyring options.\n * @throws If a builder for the given `type` does not exist.\n * @returns Promise resolving to the added keyring.\n */\n async addNewKeyring(\n type: KeyringTypes | string,\n opts?: unknown,\n ): Promise<unknown> {\n if (type === KeyringTypes.qr) {\n return this.getOrAddQRKeyring();\n }\n\n return this.#keyring.addNewKeyring(type, opts);\n }\n\n /**\n * Method to verify a given password validity. Throws an\n * error if the password is invalid.\n *\n * @param password - Password of the keyring.\n */\n async verifyPassword(password: string) {\n await this.#keyring.verifyPassword(password);\n }\n\n /**\n * Returns the status of the vault.\n *\n * @returns Boolean returning true if the vault is unlocked.\n */\n isUnlocked(): boolean {\n return this.state.isUnlocked;\n }\n\n /**\n * Gets the seed phrase of the HD keyring.\n *\n * @param password - Password of the keyring.\n * @returns Promise resolving to the seed phrase.\n */\n async exportSeedPhrase(password: string): Promise<Uint8Array> {\n await this.verifyPassword(password);\n assertHasUint8ArrayMnemonic(this.#keyring.keyrings[0]);\n return this.#keyring.keyrings[0].mnemonic;\n }\n\n /**\n * Gets the private key from the keyring controlling an address.\n *\n * @param password - Password of the keyring.\n * @param address - Address to export.\n * @returns Promise resolving to the private key for an address.\n */\n async exportAccount(password: string, address: string): Promise<string> {\n await this.verifyPassword(password);\n return this.#keyring.exportAccount(address);\n }\n\n /**\n * Returns the public addresses of all accounts for the current keyring.\n *\n * @returns A promise resolving to an array of addresses.\n */\n getAccounts(): Promise<string[]> {\n return this.#keyring.getAccounts();\n }\n\n /**\n * Get encryption public key.\n *\n * @param account - An account address.\n * @param opts - Additional encryption options.\n * @throws If the `account` does not exist or does not support the `getEncryptionPublicKey` method\n * @returns Promise resolving to encyption public key of the `account` if one exists.\n */\n async getEncryptionPublicKey(\n account: string,\n opts?: Record<string, unknown>,\n ): Promise<string> {\n return this.#keyring.getEncryptionPublicKey(account, opts);\n }\n\n /**\n * Attempts to decrypt the provided message parameters.\n *\n * @param messageParams - The decryption message parameters.\n * @param messageParams.from - The address of the account you want to use to decrypt the message.\n * @param messageParams.data - The encrypted data that you want to decrypt.\n * @returns The raw decryption result.\n */\n async decryptMessage(messageParams: {\n from: string;\n data: Eip1024EncryptedData;\n }): Promise<string> {\n return this.#keyring.decryptMessage(messageParams);\n }\n\n /**\n * Returns the currently initialized keyring that manages\n * the specified `address` if one exists.\n *\n * @deprecated Use of this method is discouraged as actions executed directly on\n * keyrings are not being reflected in the KeyringController state and not\n * persisted in the vault.\n * @param account - An account address.\n * @returns Promise resolving to keyring of the `account` if one exists.\n */\n async getKeyringForAccount(account: string): Promise<unknown> {\n return this.#keyring.getKeyringForAccount(account);\n }\n\n /**\n * Returns all keyrings of the given type.\n *\n * @deprecated Use of this method is discouraged as actions executed directly on\n * keyrings are not being reflected in the KeyringController state and not\n * persisted in the vault.\n * @param type - Keyring type name.\n * @returns An array of keyrings of the given type.\n */\n getKeyringsByType(type: KeyringTypes | string): unknown[] {\n return this.#keyring.getKeyringsByType(type);\n }\n\n /**\n * Persist all serialized keyrings in the vault.\n *\n * @returns Promise resolving with `true` value when the\n * operation completes.\n */\n async persistAllKeyrings(): Promise<boolean> {\n return this.#keyring.persistAllKeyrings();\n }\n\n /**\n * Imports an account with the specified import strategy.\n *\n * @param strategy - Import strategy name.\n * @param args - Array of arguments to pass to the underlying stategy.\n * @throws Will throw when passed an unrecognized strategy.\n * @returns Promise resolving to keyring current state and imported account\n * address.\n */\n async importAccountWithStrategy(\n strategy: AccountImportStrategy,\n args: any[],\n ): Promise<{\n keyringState: KeyringControllerMemState;\n importedAccountAddress: string;\n }> {\n let privateKey;\n switch (strategy) {\n case 'privateKey':\n const [importedKey] = args;\n if (!importedKey) {\n throw new Error('Cannot import an empty key.');\n }\n const prefixed = addHexPrefix(importedKey);\n\n let bufferedPrivateKey;\n try {\n bufferedPrivateKey = toBuffer(prefixed);\n } catch {\n throw new Error('Cannot import invalid private key.');\n }\n\n /* istanbul ignore if */\n if (\n !isValidPrivate(bufferedPrivateKey) ||\n // ensures that the key is 64 bytes long\n getBinarySize(prefixed) !== 64 + '0x'.length\n ) {\n throw new Error('Cannot import invalid private key.');\n }\n\n privateKey = stripHexPrefix(prefixed);\n break;\n case 'json':\n let wallet;\n const [input, password] = args;\n try {\n wallet = importers.fromEtherWallet(input, password);\n } catch (e) {\n wallet = wallet || (await Wallet.fromV3(input, password, true));\n }\n privateKey = bufferToHex(wallet.getPrivateKey());\n break;\n default:\n throw new Error(`Unexpected import strategy: '${strategy}'`);\n }\n const newKeyring = await this.#keyring.addNewKeyring(KeyringTypes.simple, [\n privateKey,\n ]);\n const accounts = await newKeyring.getAccounts();\n const allAccounts = await this.#keyring.getAccounts();\n this.updateIdentities(allAccounts);\n return {\n keyringState: this.#getMemState(),\n importedAccountAddress: accounts[0],\n };\n }\n\n /**\n * Removes an account from keyring state.\n *\n * @param address - Address of the account to remove.\n * @fires KeyringController:accountRemoved\n * @returns Promise resolving current state when this account removal completes.\n */\n async removeAccount(address: Hex): Promise<KeyringControllerMemState> {\n await this.#keyring.removeAccount(address);\n this.messagingSystem.publish(`${name}:accountRemoved`, address);\n return this.#getMemState();\n }\n\n /**\n * Deallocates all secrets and locks the wallet.\n *\n * @returns Promise resolving to current state.\n */\n async setLocked(): Promise<KeyringControllerMemState> {\n this.#unsubscribeFromQRKeyringsEvents();\n await this.#keyring.setLocked();\n return this.#getMemState();\n }\n\n /**\n * Signs message by calling down into a specific keyring.\n *\n * @param messageParams - PersonalMessageParams object to sign.\n * @returns Promise resolving to a signed message string.\n */\n signMessage(messageParams: PersonalMessageParams) {\n if (!messageParams.data) {\n throw new Error(\"Can't sign an empty message\");\n }\n return this.#keyring.signMessage(messageParams);\n }\n\n /**\n * Signs personal message by calling down into a specific keyring.\n *\n * @param messageParams - PersonalMessageParams object to sign.\n * @returns Promise resolving to a signed message string.\n */\n signPersonalMessage(messageParams: PersonalMessageParams) {\n return this.#keyring.signPersonalMessage(messageParams);\n }\n\n /**\n * Signs typed message by calling down into a specific keyring.\n *\n * @param messageParams - TypedMessageParams object to sign.\n * @param version - Compatibility version EIP712.\n * @throws Will throw when passed an unrecognized version.\n * @returns Promise resolving to a signed message string or an error if any.\n */\n async signTypedMessage(\n messageParams: TypedMessageParams,\n version: SignTypedDataVersion,\n ): Promise<string> {\n try {\n if (\n ![\n SignTypedDataVersion.V1,\n SignTypedDataVersion.V3,\n SignTypedDataVersion.V4,\n ].includes(version)\n ) {\n throw new Error(`Unexpected signTypedMessage version: '${version}'`);\n }\n\n return await this.#keyring.signTypedMessage(\n {\n from: messageParams.from,\n data:\n version !== SignTypedDataVersion.V1 &&\n typeof messageParams.data === 'string'\n ? JSON.parse(messageParams.data)\n : messageParams.data,\n },\n { version },\n );\n } catch (error) {\n throw new Error(`Keyring Controller signTypedMessage: ${error}`);\n }\n }\n\n /**\n * Signs a transaction by calling down into a specific keyring.\n *\n * @param transaction - Transaction object to sign. Must be a `ethereumjs-tx` transaction instance.\n * @param from - Address to sign from, should be in keychain.\n * @param opts - An optional options object.\n * @returns Promise resolving to a signed transaction string.\n */\n signTransaction(\n transaction: TypedTransaction,\n from: string,\n opts?: Record<string, unknown>,\n ): Promise<TxData> {\n return this.#keyring.signTransaction(transaction, from, opts);\n }\n\n /**\n * Attempts to decrypt the current vault and load its keyrings,\n * using the given encryption key and salt.\n *\n * @param encryptionKey - Key to unlock the keychain.\n * @param encryptionSalt - Salt to unlock the keychain.\n * @returns Promise resolving to the current state.\n */\n async submitEncryptionKey(\n encryptionKey: string,\n encryptionSalt: string,\n ): Promise<KeyringControllerMemState> {\n await this.#keyring.submitEncryptionKey(encryptionKey, encryptionSalt);\n\n const qrKeyring = this.getQRKeyring();\n if (qrKeyring) {\n // if there is a QR keyring, we need to subscribe\n // to its events after unlocking the vault\n this.#subscribeToQRKeyringEvents(qrKeyring);\n }\n\n return this.#getMemState();\n }\n\n /**\n * Attempts to decrypt the current vault and load its keyrings,\n * using the given password.\n *\n * @param password - Password to unlock the keychain.\n * @returns Promise resolving to the current state.\n */\n async submitPassword(password: string): Promise<KeyringControllerMemState> {\n await this.#keyring.submitPassword(password);\n const accounts = await this.#keyring.getAccounts();\n\n const qrKeyring = this.getQRKeyring();\n if (qrKeyring) {\n // if there is a QR keyring, we need to subscribe\n // to its events after unlocking the vault\n this.#subscribeToQRKeyringEvents(qrKeyring);\n }\n\n await this.syncIdentities(accounts);\n return this.#getMemState();\n }\n\n /**\n * Verifies the that the seed phrase restores the current keychain's accounts.\n *\n * @returns Promise resolving to the seed phrase as Uint8Array.\n */\n async verifySeedPhrase(): Promise<Uint8Array> {\n const primaryKeyring = this.#keyring.getKeyringsByType(KeyringTypes.hd)[0];\n /* istanbul ignore if */\n if (!primaryKeyring) {\n throw new Error('No HD keyring found.');\n }\n\n assertHasUint8ArrayMnemonic(primaryKeyring);\n\n const seedWords = primaryKeyring.mnemonic;\n const accounts = await primaryKeyring.getAccounts();\n /* istanbul ignore if */\n if (accounts.length === 0) {\n throw new Error('Cannot verify an empty keyring.');\n }\n\n // The HD Keyring Builder is a default keyring builder\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const hdKeyringBuilder = this.#keyring.getKeyringBuilderForType(\n KeyringTypes.hd,\n )!;\n\n const hdKeyring = hdKeyringBuilder();\n // @ts-expect-error @metamask/eth-hd-keyring correctly handles\n // Uint8Array seed phrases in the `deserialize` method.\n hdKeyring.deserialize({\n mnemonic: seedWords,\n numberOfAccounts: accounts.length,\n });\n const testAccounts = await hdKeyring.getAccounts();\n /* istanbul ignore if */\n if (testAccounts.length !== accounts.length) {\n throw new Error('Seed phrase imported incorrect number of accounts.');\n }\n\n testAccounts.forEach((account: string, i: number) => {\n /* istanbul ignore if */\n if (account.toLowerCase() !== accounts[i].toLowerCase()) {\n throw new Error('Seed phrase imported different accounts.');\n }\n });\n\n return seedWords;\n }\n\n // QR Hardware related methods\n\n /**\n * Get QR Hardware keyring.\n *\n * @returns The QR Keyring if defined, otherwise undefined\n */\n getQRKeyring(): QRKeyring | undefined {\n // QRKeyring is not yet compatible with Keyring type from @metamask/utils\n return this.#keyring.getKeyringsByType(\n KeyringTypes.qr,\n )[0] as unknown as QRKeyring;\n }\n\n /**\n * Get QR hardware keyring. If it doesn't exist, add it.\n *\n * @returns The added keyring\n */\n async getOrAddQRKeyring(): Promise<QRKeyring> {\n return this.getQRKeyring() || (await this.#addQRKeyring());\n }\n\n async restoreQRKeyring(serialized: any): Promise<void> {\n (await this.getOrAddQRKeyring()).deserialize(serialized);\n await this.#keyring.persistAllKeyrings();\n this.updateIdentities(await this.#keyring.getAccounts());\n }\n\n async resetQRKeyringState(): Promise<void> {\n (await this.getOrAddQRKeyring()).resetStore();\n }\n\n async getQRKeyringState(): Promise<IQRKeyringState> {\n return (await this.getOrAddQRKeyring()).getMemStore();\n }\n\n async submitQRCryptoHDKey(cryptoHDKey: string): Promise<void> {\n (await this.getOrAddQRKeyring()).submitCryptoHDKey(cryptoHDKey);\n }\n\n async submitQRCryptoAccount(cryptoAccount: string): Promise<void> {\n (await this.getOrAddQRKeyring()).submitCryptoAccount(cryptoAccount);\n }\n\n async submitQRSignature(\n requestId: string,\n ethSignature: string,\n ): Promise<void> {\n (await this.getOrAddQRKeyring()).submitSignature(requestId, ethSignature);\n }\n\n async cancelQRSignRequest(): Promise<void> {\n (await this.getOrAddQRKeyring()).cancelSignRequest();\n }\n\n /**\n * Cancels qr keyring sync.\n */\n async cancelQRSynchronization(): Promise<void> {\n // eslint-disable-next-line n/no-sync\n (await this.getOrAddQRKeyring()).cancelSync();\n }\n\n async connectQRHardware(\n page: number,\n ): Promise<{ balance: string; address: string; index: number }[]> {\n try {\n const keyring = await this.getOrAddQRKeyring();\n let accounts;\n switch (page) {\n case -1:\n accounts = await keyring.getPreviousPage();\n break;\n case 1:\n accounts = await keyring.getNextPage();\n break;\n default:\n accounts = await keyring.getFirstPage();\n }\n return accounts.map((account: any) => {\n return {\n ...account,\n balance: '0x0',\n };\n });\n } catch (e) {\n // TODO: Add test case for when keyring throws\n /* istanbul ignore next */\n throw new Error(`Unspecified error when connect QR Hardware, ${e}`);\n }\n }\n\n async unlockQRHardwareWalletAccount(index: number): Promise<void> {\n const keyring = await this.getOrAddQRKeyring();\n\n keyring.setAccountToUnlock(index);\n const oldAccounts = await this.#keyring.getAccounts();\n // QRKeyring is not yet compatible with Keyring from\n // @metamask/utils, but we can use the `addNewAccount` method\n // as it internally calls `addAccounts` from on the keyring instance,\n // which is supported by QRKeyring API.\n await this.#keyring.addNewAccount(keyring as unknown as Keyring<Json>);\n const newAccounts = await this.#keyring.getAccounts();\n this.updateIdentities(newAccounts);\n newAccounts.forEach((address: string) => {\n if (!oldAccounts.includes(address)) {\n if (this.setAccountLabel) {\n this.setAccountLabel(address, `${keyring.getName()} ${index}`);\n }\n this.setSelectedAddress(address);\n }\n });\n await this.#keyring.persistAllKeyrings();\n }\n\n async getAccountKeyringType(account: string): Promise<string> {\n return (await this.#keyring.getKeyringForAccount(account)).type;\n }\n\n async forgetQRDevice(): Promise<void> {\n const keyring = await this.getOrAddQRKeyring();\n keyring.forgetDevice();\n const accounts = (await this.#keyring.getAccounts()) as string[];\n accounts.forEach((account) => {\n this.setSelectedAddress(account);\n });\n await this.#keyring.persistAllKeyrings();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${name}:signMessage`,\n this.signMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:signPersonalMessage`,\n this.signPersonalMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:signTypedMessage`,\n this.signTypedMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:decryptMessage`,\n this.decryptMessage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getEncryptionPublicKey`,\n this.getEncryptionPublicKey.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getAccounts`,\n this.getAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getKeyringsByType`,\n this.getKeyringsByType.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${name}:getKeyringForAccount`,\n this.getKeyringForAccount.bind(this),\n );\n }\n\n /**\n * Add qr hardware keyring.\n *\n * @returns The added keyring\n * @throws If a QRKeyring builder is not provided\n * when initializing the controller\n */\n async #addQRKeyring(): Promise<QRKeyring> {\n // QRKeyring is not yet compatible with Keyring type from @metamask/utils\n const qrKeyring = (await this.#keyring.addNewKeyring(\n KeyringTypes.qr,\n )) as unknown as QRKeyring;\n\n this.#subscribeToQRKeyringEvents(qrKeyring);\n\n return qrKeyring;\n }\n\n /**\n * Subscribe to a QRKeyring state change events and\n * forward them through the messaging system.\n *\n * @param qrKeyring - The QRKeyring instance to subscribe to\n */\n #subscribeToQRKeyringEvents(qrKeyring: QRKeyring) {\n this.#qrKeyringStateListener = (state) => {\n this.messagingSystem.publish(`${name}:qrKeyringStateChange`, state);\n };\n\n qrKeyring.getMemStore().subscribe(this.#qrKeyringStateListener);\n }\n\n #unsubscribeFromQRKeyringsEvents() {\n const qrKeyrings = this.#keyring.getKeyringsByType(\n KeyringTypes.qr,\n ) as unknown as QRKeyring[];\n\n qrKeyrings.forEach((qrKeyring) => {\n if (this.#qrKeyringStateListener) {\n qrKeyring.getMemStore().unsubscribe(this.#qrKeyringStateListener);\n }\n });\n }\n\n /**\n * Sync controller state with current keyring store\n * and memStore states.\n *\n * @fires KeyringController:stateChange\n */\n #fullUpdate() {\n const { vault } = this.#keyring.store.getState();\n const { keyrings, isUnlocked, encryptionKey, encryptionSalt } =\n this.#keyring.memStore.getState();\n\n this.update(() => ({\n vault,\n keyrings,\n isUnlocked,\n encryptionKey,\n encryptionSalt,\n }));\n }\n\n /**\n * Handle keyring lock event.\n *\n * @fires KeyringController:lock\n */\n #handleLock() {\n this.messagingSystem.publish(`${name}:lock`);\n }\n\n /**\n * Handle keyring unlock event.\n *\n * @fires KeyringController:unlock\n */\n #handleUnlock() {\n this.messagingSystem.publish(`${name}:unlock`);\n }\n\n #getMemState(): KeyringControllerMemState {\n return {\n isUnlocked: this.state.isUnlocked,\n keyrings: this.state.keyrings,\n };\n }\n}\n\nexport default KeyringController;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/keyring-controller",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.2-preview.26b130a",
|
|
4
4
|
"description": "Stores identities seen in the wallet and manages interactions such as signing",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -25,15 +25,16 @@
|
|
|
25
25
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/keyring-controller",
|
|
26
26
|
"publish:preview": "yarn npm publish --tag preview",
|
|
27
27
|
"test": "jest",
|
|
28
|
+
"test:clean": "jest --clearCache",
|
|
28
29
|
"test:watch": "jest --watch"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
32
|
"@keystonehq/metamask-airgapped-keyring": "^0.13.1",
|
|
32
|
-
"@metamask/base-controller": "^3.2.
|
|
33
|
+
"@metamask/base-controller": "^3.2.3",
|
|
33
34
|
"@metamask/eth-keyring-controller": "^13.0.1",
|
|
34
|
-
"@metamask/message-manager": "^7.3.
|
|
35
|
-
"@metamask/preferences-controller": "^4.4.
|
|
36
|
-
"@metamask/utils": "^
|
|
35
|
+
"@metamask/message-manager": "^7.3.5",
|
|
36
|
+
"@metamask/preferences-controller": "^4.4.2",
|
|
37
|
+
"@metamask/utils": "^8.1.0",
|
|
37
38
|
"async-mutex": "^0.2.6",
|
|
38
39
|
"ethereumjs-util": "^7.0.10",
|
|
39
40
|
"ethereumjs-wallet": "^1.0.1",
|
|
@@ -51,13 +52,13 @@
|
|
|
51
52
|
"jest": "^27.5.1",
|
|
52
53
|
"sinon": "^9.2.4",
|
|
53
54
|
"ts-jest": "^27.1.4",
|
|
54
|
-
"typedoc": "^0.
|
|
55
|
-
"typedoc-plugin-missing-exports": "^0.
|
|
56
|
-
"typescript": "~4.
|
|
55
|
+
"typedoc": "^0.24.8",
|
|
56
|
+
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
57
|
+
"typescript": "~4.8.4",
|
|
57
58
|
"uuid": "^8.3.2"
|
|
58
59
|
},
|
|
59
60
|
"peerDependencies": {
|
|
60
|
-
"@metamask/preferences-controller": "^4.4.
|
|
61
|
+
"@metamask/preferences-controller": "^4.4.2"
|
|
61
62
|
},
|
|
62
63
|
"engines": {
|
|
63
64
|
"node": ">=16.0.0"
|