@metamask-previews/keyring-controller 19.0.7-preview-862b5dac → 19.1.0-preview-cb58d7d1
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 +12 -1
- package/dist/KeyringController.cjs +70 -20
- package/dist/KeyringController.cjs.map +1 -1
- package/dist/KeyringController.d.cts +25 -2
- package/dist/KeyringController.d.cts.map +1 -1
- package/dist/KeyringController.d.mts +25 -2
- package/dist/KeyringController.d.mts.map +1 -1
- package/dist/KeyringController.mjs +70 -20
- package/dist/KeyringController.mjs.map +1 -1
- package/dist/constants.cjs +3 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +4 -1
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +4 -1
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +3 -0
- package/dist/constants.mjs.map +1 -1
- package/package.json +8 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [19.1.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add new keyring type for OneKey ([#5216](https://github.com/MetaMask/core/pull/5216))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- A specific error message is thrown when any operation is attempted while the controller is locked ([#5172](https://github.com/MetaMask/core/pull/5172))
|
|
19
|
+
|
|
10
20
|
## [19.0.7]
|
|
11
21
|
|
|
12
22
|
### Changed
|
|
@@ -660,7 +670,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
660
670
|
|
|
661
671
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
662
672
|
|
|
663
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@19.0
|
|
673
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@19.1.0...HEAD
|
|
674
|
+
[19.1.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@19.0.7...@metamask/keyring-controller@19.1.0
|
|
664
675
|
[19.0.7]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@19.0.6...@metamask/keyring-controller@19.0.7
|
|
665
676
|
[19.0.6]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@19.0.5...@metamask/keyring-controller@19.0.6
|
|
666
677
|
[19.0.5]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@19.0.4...@metamask/keyring-controller@19.0.5
|
|
@@ -36,7 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
36
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
38
|
};
|
|
39
|
-
var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_unsupportedKeyrings, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_keyrings, _KeyringController_password, _KeyringController_qrKeyringStateListener, _KeyringController_registerMessageHandlers, _KeyringController_getKeyringBuilderForType, _KeyringController_addQRKeyring, _KeyringController_subscribeToQRKeyringEvents, _KeyringController_unsubscribeFromQRKeyringsEvents, _KeyringController_createNewVaultWithKeyring, _KeyringController_verifySeedPhrase, _KeyringController_getUpdatedKeyrings, _KeyringController_getSerializedKeyrings, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_getAccountsFromKeyrings, _KeyringController_createKeyringWithFirstAccount, _KeyringController_newKeyring, _KeyringController_clearKeyrings, _KeyringController_restoreKeyring, _KeyringController_destroyKeyring, _KeyringController_removeEmptyKeyrings, _KeyringController_checkForDuplicate, _KeyringController_setUnlocked, _KeyringController_assertIsUnlocked, _KeyringController_persistOrRollback, _KeyringController_withRollback, _KeyringController_assertControllerMutexIsLocked, _KeyringController_withControllerLock, _KeyringController_withVaultLock;
|
|
39
|
+
var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_unsupportedKeyrings, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_keyrings, _KeyringController_keyringsMetadata, _KeyringController_password, _KeyringController_qrKeyringStateListener, _KeyringController_registerMessageHandlers, _KeyringController_getKeyringByIdOrDefault, _KeyringController_getKeyringBuilderForType, _KeyringController_addQRKeyring, _KeyringController_subscribeToQRKeyringEvents, _KeyringController_unsubscribeFromQRKeyringsEvents, _KeyringController_createNewVaultWithKeyring, _KeyringController_verifySeedPhrase, _KeyringController_getUpdatedKeyrings, _KeyringController_getSerializedKeyrings, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_getAccountsFromKeyrings, _KeyringController_createKeyringWithFirstAccount, _KeyringController_newKeyring, _KeyringController_clearKeyrings, _KeyringController_restoreKeyring, _KeyringController_destroyKeyring, _KeyringController_removeEmptyKeyrings, _KeyringController_checkForDuplicate, _KeyringController_setUnlocked, _KeyringController_assertIsUnlocked, _KeyringController_persistOrRollback, _KeyringController_withRollback, _KeyringController_assertControllerMutexIsLocked, _KeyringController_withControllerLock, _KeyringController_withVaultLock;
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
41
|
exports.KeyringController = exports.getDefaultKeyringState = exports.keyringBuilderFactory = exports.SignTypedDataVersion = exports.AccountImportStrategy = exports.isCustodyKeyring = exports.KeyringTypes = void 0;
|
|
42
42
|
const util_1 = require("@ethereumjs/util");
|
|
@@ -48,6 +48,8 @@ const eth_simple_keyring_1 = __importDefault(require("@metamask/eth-simple-keyri
|
|
|
48
48
|
const utils_1 = require("@metamask/utils");
|
|
49
49
|
const async_mutex_1 = require("async-mutex");
|
|
50
50
|
const ethereumjs_wallet_1 = __importStar(require("ethereumjs-wallet"));
|
|
51
|
+
// When generating a ULID within the same millisecond, monotonicFactory provides some guarantees regarding sort order.
|
|
52
|
+
const ulid_1 = require("ulid");
|
|
51
53
|
const constants_1 = require("./constants.cjs");
|
|
52
54
|
const name = 'KeyringController';
|
|
53
55
|
/**
|
|
@@ -59,6 +61,7 @@ var KeyringTypes;
|
|
|
59
61
|
KeyringTypes["hd"] = "HD Key Tree";
|
|
60
62
|
KeyringTypes["qr"] = "QR Hardware Wallet Device";
|
|
61
63
|
KeyringTypes["trezor"] = "Trezor Hardware";
|
|
64
|
+
KeyringTypes["oneKey"] = "OneKey Hardware";
|
|
62
65
|
KeyringTypes["ledger"] = "Ledger Hardware";
|
|
63
66
|
KeyringTypes["lattice"] = "Lattice Hardware";
|
|
64
67
|
KeyringTypes["snap"] = "Snap Keyring";
|
|
@@ -115,6 +118,7 @@ const getDefaultKeyringState = () => {
|
|
|
115
118
|
return {
|
|
116
119
|
isUnlocked: false,
|
|
117
120
|
keyrings: [],
|
|
121
|
+
keyringsMetadata: [],
|
|
118
122
|
};
|
|
119
123
|
};
|
|
120
124
|
exports.getDefaultKeyringState = getDefaultKeyringState;
|
|
@@ -246,6 +250,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
246
250
|
vault: { persist: true, anonymous: false },
|
|
247
251
|
isUnlocked: { persist: false, anonymous: true },
|
|
248
252
|
keyrings: { persist: false, anonymous: false },
|
|
253
|
+
keyringsMetadata: { persist: true, anonymous: false },
|
|
249
254
|
encryptionKey: { persist: false, anonymous: false },
|
|
250
255
|
encryptionSalt: { persist: false, anonymous: false },
|
|
251
256
|
},
|
|
@@ -263,6 +268,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
263
268
|
_KeyringController_encryptor.set(this, void 0);
|
|
264
269
|
_KeyringController_cacheEncryptionKey.set(this, void 0);
|
|
265
270
|
_KeyringController_keyrings.set(this, void 0);
|
|
271
|
+
_KeyringController_keyringsMetadata.set(this, void 0);
|
|
266
272
|
_KeyringController_password.set(this, void 0);
|
|
267
273
|
_KeyringController_qrKeyringStateListener.set(this, void 0);
|
|
268
274
|
__classPrivateFieldSet(this, _KeyringController_keyringBuilders, keyringBuilders
|
|
@@ -270,6 +276,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
270
276
|
: defaultKeyringBuilders, "f");
|
|
271
277
|
__classPrivateFieldSet(this, _KeyringController_encryptor, encryptor, "f");
|
|
272
278
|
__classPrivateFieldSet(this, _KeyringController_keyrings, [], "f");
|
|
279
|
+
__classPrivateFieldSet(this, _KeyringController_keyringsMetadata, state?.keyringsMetadata ?? [], "f");
|
|
273
280
|
__classPrivateFieldSet(this, _KeyringController_unsupportedKeyrings, [], "f");
|
|
274
281
|
// This option allows the controller to cache an exported key
|
|
275
282
|
// for use in decrypting and encrypting data without password
|
|
@@ -418,13 +425,18 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
418
425
|
* Gets the seed phrase of the HD keyring.
|
|
419
426
|
*
|
|
420
427
|
* @param password - Password of the keyring.
|
|
428
|
+
* @param keyringId - The id of the keyring.
|
|
421
429
|
* @returns Promise resolving to the seed phrase.
|
|
422
430
|
*/
|
|
423
|
-
async exportSeedPhrase(password) {
|
|
431
|
+
async exportSeedPhrase(password, keyringId) {
|
|
424
432
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
425
433
|
await this.verifyPassword(password);
|
|
426
|
-
|
|
427
|
-
|
|
434
|
+
const selectedKeyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringByIdOrDefault).call(this, keyringId);
|
|
435
|
+
if (!selectedKeyring) {
|
|
436
|
+
throw new Error('Keyring not found');
|
|
437
|
+
}
|
|
438
|
+
assertHasUint8ArrayMnemonic(selectedKeyring);
|
|
439
|
+
return selectedKeyring.mnemonic;
|
|
428
440
|
}
|
|
429
441
|
/**
|
|
430
442
|
* Gets the private key from the keyring controlling an address.
|
|
@@ -609,6 +621,13 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
609
621
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
610
622
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
|
|
611
623
|
const keyring = (await this.getKeyringForAccount(address));
|
|
624
|
+
const keyringIndex = this.state.keyrings.findIndex((kr) => kr.accounts.includes(address));
|
|
625
|
+
const isPrimaryKeyring = keyringIndex === 0;
|
|
626
|
+
const shouldRemoveKeyring = (await keyring.getAccounts()).length === 1;
|
|
627
|
+
// Primary keyring should never be removed, so we need to keep at least one account in it
|
|
628
|
+
if (isPrimaryKeyring && shouldRemoveKeyring) {
|
|
629
|
+
throw new Error(constants_1.KeyringControllerError.LastAccountInPrimaryKeyring);
|
|
630
|
+
}
|
|
612
631
|
// Not all the keyrings support this, so we have to check
|
|
613
632
|
if (!keyring.removeAccount) {
|
|
614
633
|
throw new Error(constants_1.KeyringControllerError.UnsupportedRemoveAccount);
|
|
@@ -619,9 +638,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
619
638
|
// because `Keyring<State>.removeAccount` requires address to be `Hex`. Those
|
|
620
639
|
// type would need to be updated for a full non-EVM support.
|
|
621
640
|
keyring.removeAccount(address);
|
|
622
|
-
|
|
623
|
-
// Check if this was the last/only account
|
|
624
|
-
if (accounts.length === 0) {
|
|
641
|
+
if (shouldRemoveKeyring) {
|
|
625
642
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_removeEmptyKeyrings).call(this);
|
|
626
643
|
}
|
|
627
644
|
});
|
|
@@ -838,11 +855,12 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
838
855
|
/**
|
|
839
856
|
* Verifies the that the seed phrase restores the current keychain's accounts.
|
|
840
857
|
*
|
|
858
|
+
* @param keyringId - The id of the keyring to verify.
|
|
841
859
|
* @returns Promise resolving to the seed phrase as Uint8Array.
|
|
842
860
|
*/
|
|
843
|
-
async verifySeedPhrase() {
|
|
861
|
+
async verifySeedPhrase(keyringId) {
|
|
844
862
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
845
|
-
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_verifySeedPhrase).call(this));
|
|
863
|
+
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_verifySeedPhrase).call(this, keyringId));
|
|
846
864
|
}
|
|
847
865
|
async withKeyring(selector, operation, options = {
|
|
848
866
|
createIfMissing: false,
|
|
@@ -853,12 +871,16 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
853
871
|
if ('address' in selector) {
|
|
854
872
|
keyring = (await this.getKeyringForAccount(selector.address));
|
|
855
873
|
}
|
|
856
|
-
else {
|
|
874
|
+
else if ('type' in selector) {
|
|
857
875
|
keyring = this.getKeyringsByType(selector.type)[selector.index || 0];
|
|
858
876
|
if (!keyring && options.createIfMissing) {
|
|
859
877
|
keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, selector.type, options.createWithData));
|
|
860
878
|
}
|
|
861
879
|
}
|
|
880
|
+
else if ('id' in selector) {
|
|
881
|
+
const index = this.state.keyringsMetadata.findIndex((metadata) => metadata.id === selector.id);
|
|
882
|
+
keyring = __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[index];
|
|
883
|
+
}
|
|
862
884
|
if (!keyring) {
|
|
863
885
|
throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
|
|
864
886
|
}
|
|
@@ -1072,7 +1094,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
1072
1094
|
}
|
|
1073
1095
|
}
|
|
1074
1096
|
exports.KeyringController = KeyringController;
|
|
1075
|
-
_KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(), _KeyringController_unsupportedKeyrings = new WeakMap(), _KeyringController_encryptor = new WeakMap(), _KeyringController_cacheEncryptionKey = new WeakMap(), _KeyringController_keyrings = new WeakMap(), _KeyringController_password = new WeakMap(), _KeyringController_qrKeyringStateListener = new WeakMap(), _KeyringController_instances = new WeakSet(), _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
|
|
1097
|
+
_KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(), _KeyringController_unsupportedKeyrings = new WeakMap(), _KeyringController_encryptor = new WeakMap(), _KeyringController_cacheEncryptionKey = new WeakMap(), _KeyringController_keyrings = new WeakMap(), _KeyringController_keyringsMetadata = new WeakMap(), _KeyringController_password = new WeakMap(), _KeyringController_qrKeyringStateListener = new WeakMap(), _KeyringController_instances = new WeakSet(), _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
|
|
1076
1098
|
this.messagingSystem.registerActionHandler(`${name}:signMessage`, this.signMessage.bind(this));
|
|
1077
1099
|
this.messagingSystem.registerActionHandler(`${name}:signPersonalMessage`, this.signPersonalMessage.bind(this));
|
|
1078
1100
|
this.messagingSystem.registerActionHandler(`${name}:signTypedMessage`, this.signTypedMessage.bind(this));
|
|
@@ -1086,6 +1108,12 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
|
|
|
1086
1108
|
this.messagingSystem.registerActionHandler(`${name}:patchUserOperation`, this.patchUserOperation.bind(this));
|
|
1087
1109
|
this.messagingSystem.registerActionHandler(`${name}:signUserOperation`, this.signUserOperation.bind(this));
|
|
1088
1110
|
this.messagingSystem.registerActionHandler(`${name}:addNewAccount`, this.addNewAccount.bind(this));
|
|
1111
|
+
}, _KeyringController_getKeyringByIdOrDefault = function _KeyringController_getKeyringByIdOrDefault(keyringId) {
|
|
1112
|
+
if (!keyringId) {
|
|
1113
|
+
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0];
|
|
1114
|
+
}
|
|
1115
|
+
const index = this.state.keyringsMetadata.findIndex((metadata) => metadata.id === keyringId);
|
|
1116
|
+
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[index];
|
|
1089
1117
|
}, _KeyringController_getKeyringBuilderForType = function _KeyringController_getKeyringBuilderForType(type) {
|
|
1090
1118
|
return __classPrivateFieldGet(this, _KeyringController_keyringBuilders, "f").find((keyringBuilder) => keyringBuilder.type === type);
|
|
1091
1119
|
}, _KeyringController_addQRKeyring =
|
|
@@ -1138,23 +1166,29 @@ async function _KeyringController_createNewVaultWithKeyring(password, keyring) {
|
|
|
1138
1166
|
});
|
|
1139
1167
|
__classPrivateFieldSet(this, _KeyringController_password, password, "f");
|
|
1140
1168
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_clearKeyrings).call(this);
|
|
1169
|
+
__classPrivateFieldSet(this, _KeyringController_keyringsMetadata, [], "f");
|
|
1141
1170
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyringWithFirstAccount).call(this, keyring.type, keyring.opts);
|
|
1142
1171
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_setUnlocked).call(this);
|
|
1143
1172
|
}, _KeyringController_verifySeedPhrase =
|
|
1144
1173
|
/**
|
|
1145
1174
|
* Internal non-exclusive method to verify the seed phrase.
|
|
1146
1175
|
*
|
|
1176
|
+
* @param keyringId - The id of the keyring to verify the seed phrase for.
|
|
1147
1177
|
* @returns A promise resolving to the seed phrase as Uint8Array.
|
|
1148
1178
|
*/
|
|
1149
|
-
async function _KeyringController_verifySeedPhrase() {
|
|
1179
|
+
async function _KeyringController_verifySeedPhrase(keyringId) {
|
|
1150
1180
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1151
|
-
const
|
|
1152
|
-
if (!
|
|
1153
|
-
throw new Error(
|
|
1181
|
+
const keyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringByIdOrDefault).call(this, keyringId);
|
|
1182
|
+
if (!keyring) {
|
|
1183
|
+
throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
|
|
1184
|
+
}
|
|
1185
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
1186
|
+
if (keyring.type !== KeyringTypes.hd) {
|
|
1187
|
+
throw new Error(constants_1.KeyringControllerError.UnsupportedVerifySeedPhrase);
|
|
1154
1188
|
}
|
|
1155
|
-
assertHasUint8ArrayMnemonic(
|
|
1156
|
-
const seedWords =
|
|
1157
|
-
const accounts = await
|
|
1189
|
+
assertHasUint8ArrayMnemonic(keyring);
|
|
1190
|
+
const seedWords = keyring.mnemonic;
|
|
1191
|
+
const accounts = await keyring.getAccounts();
|
|
1158
1192
|
/* istanbul ignore if */
|
|
1159
1193
|
if (accounts.length === 0) {
|
|
1160
1194
|
throw new Error('Cannot verify an empty keyring.');
|
|
@@ -1334,9 +1368,13 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
|
|
|
1334
1368
|
throw new Error(constants_1.KeyringControllerError.MissingVaultData);
|
|
1335
1369
|
}
|
|
1336
1370
|
const updatedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getUpdatedKeyrings).call(this);
|
|
1371
|
+
if (updatedKeyrings.length !== __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").length) {
|
|
1372
|
+
throw new Error(constants_1.KeyringControllerError.KeyringMetadataLengthMismatch);
|
|
1373
|
+
}
|
|
1337
1374
|
this.update((state) => {
|
|
1338
1375
|
state.vault = updatedState.vault;
|
|
1339
1376
|
state.keyrings = updatedKeyrings;
|
|
1377
|
+
state.keyringsMetadata = __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").slice();
|
|
1340
1378
|
if (updatedState.encryptionKey) {
|
|
1341
1379
|
state.encryptionKey = updatedState.encryptionKey;
|
|
1342
1380
|
state.encryptionSalt = JSON.parse(updatedState.vault).salt;
|
|
@@ -1376,13 +1414,13 @@ async function _KeyringController_createKeyringWithFirstAccount(type, opts) {
|
|
|
1376
1414
|
if (!firstAccount) {
|
|
1377
1415
|
throw new Error(constants_1.KeyringControllerError.NoFirstAccount);
|
|
1378
1416
|
}
|
|
1417
|
+
return firstAccount;
|
|
1379
1418
|
}, _KeyringController_newKeyring =
|
|
1380
1419
|
/**
|
|
1381
1420
|
* Instantiate, initialize and return a new keyring of the given `type`,
|
|
1382
1421
|
* using the given `opts`. The keyring is built using the keyring builder
|
|
1383
1422
|
* registered for the given `type`.
|
|
1384
1423
|
*
|
|
1385
|
-
*
|
|
1386
1424
|
* @param type - The type of keyring to add.
|
|
1387
1425
|
* @param data - The data to restore a previously serialized keyring.
|
|
1388
1426
|
* @returns The new keyring.
|
|
@@ -1390,6 +1428,10 @@ async function _KeyringController_createKeyringWithFirstAccount(type, opts) {
|
|
|
1390
1428
|
*/
|
|
1391
1429
|
async function _KeyringController_newKeyring(type, data) {
|
|
1392
1430
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1431
|
+
const newKeyringMetadata = {
|
|
1432
|
+
id: (0, ulid_1.ulid)(),
|
|
1433
|
+
name: '',
|
|
1434
|
+
};
|
|
1393
1435
|
const keyringBuilder = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringBuilderForType).call(this, type);
|
|
1394
1436
|
if (!keyringBuilder) {
|
|
1395
1437
|
throw new Error(`${constants_1.KeyringControllerError.NoKeyringBuilder}. Keyring type: ${type}`);
|
|
@@ -1417,6 +1459,9 @@ async function _KeyringController_newKeyring(type, data) {
|
|
|
1417
1459
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_subscribeToQRKeyringEvents).call(this, keyring);
|
|
1418
1460
|
}
|
|
1419
1461
|
__classPrivateFieldGet(this, _KeyringController_keyrings, "f").push(keyring);
|
|
1462
|
+
if (__classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").length < __classPrivateFieldGet(this, _KeyringController_keyrings, "f").length) {
|
|
1463
|
+
__classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").push(newKeyringMetadata);
|
|
1464
|
+
}
|
|
1420
1465
|
return keyring;
|
|
1421
1466
|
}, _KeyringController_clearKeyrings =
|
|
1422
1467
|
/**
|
|
@@ -1469,19 +1514,22 @@ async function _KeyringController_destroyKeyring(keyring) {
|
|
|
1469
1514
|
async function _KeyringController_removeEmptyKeyrings() {
|
|
1470
1515
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1471
1516
|
const validKeyrings = [];
|
|
1517
|
+
const validKeyringMetadata = [];
|
|
1472
1518
|
// Since getAccounts returns a Promise
|
|
1473
1519
|
// We need to wait to hear back form each keyring
|
|
1474
1520
|
// in order to decide which ones are now valid (accounts.length > 0)
|
|
1475
|
-
await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async (keyring) => {
|
|
1521
|
+
await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async (keyring, index) => {
|
|
1476
1522
|
const accounts = await keyring.getAccounts();
|
|
1477
1523
|
if (accounts.length > 0) {
|
|
1478
1524
|
validKeyrings.push(keyring);
|
|
1525
|
+
validKeyringMetadata.push(__classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f")[index]);
|
|
1479
1526
|
}
|
|
1480
1527
|
else {
|
|
1481
1528
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring);
|
|
1482
1529
|
}
|
|
1483
1530
|
}));
|
|
1484
1531
|
__classPrivateFieldSet(this, _KeyringController_keyrings, validKeyrings, "f");
|
|
1532
|
+
__classPrivateFieldSet(this, _KeyringController_keyringsMetadata, validKeyringMetadata, "f");
|
|
1485
1533
|
}, _KeyringController_checkForDuplicate =
|
|
1486
1534
|
/**
|
|
1487
1535
|
* Checks for duplicate keypairs, using the the first account in the given
|
|
@@ -1547,6 +1595,7 @@ async function _KeyringController_withRollback(callback) {
|
|
|
1547
1595
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async ({ releaseLock }) => {
|
|
1548
1596
|
const currentSerializedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSerializedKeyrings).call(this);
|
|
1549
1597
|
const currentPassword = __classPrivateFieldGet(this, _KeyringController_password, "f");
|
|
1598
|
+
const currentKeyringsMetadata = __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").slice();
|
|
1550
1599
|
try {
|
|
1551
1600
|
return await callback({ releaseLock });
|
|
1552
1601
|
}
|
|
@@ -1554,6 +1603,7 @@ async function _KeyringController_withRollback(callback) {
|
|
|
1554
1603
|
// Keyrings and password are restored to their previous state
|
|
1555
1604
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_restoreSerializedKeyrings).call(this, currentSerializedKeyrings);
|
|
1556
1605
|
__classPrivateFieldSet(this, _KeyringController_password, currentPassword, "f");
|
|
1606
|
+
__classPrivateFieldSet(this, _KeyringController_keyringsMetadata, currentKeyringsMetadata, "f");
|
|
1557
1607
|
throw e;
|
|
1558
1608
|
}
|
|
1559
1609
|
});
|