@metamask-previews/keyring-controller 19.0.2-preview-407f96d → 19.0.2-preview-62a75dc
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/dist/KeyringController.cjs +33 -90
- package/dist/KeyringController.cjs.map +1 -1
- package/dist/KeyringController.d.cts +4 -23
- package/dist/KeyringController.d.cts.map +1 -1
- package/dist/KeyringController.d.mts +4 -23
- package/dist/KeyringController.d.mts.map +1 -1
- package/dist/KeyringController.mjs +33 -90
- package/dist/KeyringController.mjs.map +1 -1
- package/package.json +5 -10
|
@@ -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_keyrings,
|
|
39
|
+
var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_keyrings, _KeyringController_unsupportedKeyrings, _KeyringController_password, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _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_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,10 +48,7 @@ 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");
|
|
53
51
|
const constants_1 = require("./constants.cjs");
|
|
54
|
-
const ulid = (0, ulid_1.monotonicFactory)();
|
|
55
52
|
const name = 'KeyringController';
|
|
56
53
|
/**
|
|
57
54
|
* Available keyring types
|
|
@@ -135,7 +132,6 @@ const getDefaultKeyringState = () => {
|
|
|
135
132
|
return {
|
|
136
133
|
isUnlocked: false,
|
|
137
134
|
keyrings: [],
|
|
138
|
-
keyringsMetadata: [],
|
|
139
135
|
};
|
|
140
136
|
};
|
|
141
137
|
exports.getDefaultKeyringState = getDefaultKeyringState;
|
|
@@ -267,7 +263,6 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
267
263
|
vault: { persist: true, anonymous: false },
|
|
268
264
|
isUnlocked: { persist: false, anonymous: true },
|
|
269
265
|
keyrings: { persist: false, anonymous: false },
|
|
270
|
-
keyringsMetadata: { persist: false, anonymous: false },
|
|
271
266
|
encryptionKey: { persist: false, anonymous: false },
|
|
272
267
|
encryptionSalt: { persist: false, anonymous: false },
|
|
273
268
|
},
|
|
@@ -282,7 +277,6 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
282
277
|
_KeyringController_vaultOperationMutex.set(this, new async_mutex_1.Mutex());
|
|
283
278
|
_KeyringController_keyringBuilders.set(this, void 0);
|
|
284
279
|
_KeyringController_keyrings.set(this, void 0);
|
|
285
|
-
_KeyringController_keyringsMetadata.set(this, void 0);
|
|
286
280
|
_KeyringController_unsupportedKeyrings.set(this, void 0);
|
|
287
281
|
_KeyringController_password.set(this, void 0);
|
|
288
282
|
_KeyringController_encryptor.set(this, void 0);
|
|
@@ -293,7 +287,6 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
293
287
|
: defaultKeyringBuilders, "f");
|
|
294
288
|
__classPrivateFieldSet(this, _KeyringController_encryptor, encryptor, "f");
|
|
295
289
|
__classPrivateFieldSet(this, _KeyringController_keyrings, [], "f");
|
|
296
|
-
__classPrivateFieldSet(this, _KeyringController_keyringsMetadata, [], "f");
|
|
297
290
|
__classPrivateFieldSet(this, _KeyringController_unsupportedKeyrings, [], "f");
|
|
298
291
|
// This option allows the controller to cache an exported key
|
|
299
292
|
// for use in decrypting and encrypting data without password
|
|
@@ -307,20 +300,16 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
307
300
|
* Adds a new account to the default (first) HD seed phrase keyring.
|
|
308
301
|
*
|
|
309
302
|
* @param accountCount - Number of accounts before adding a new one, used to
|
|
310
|
-
* @param keyringId - The id of the keyring to add the account to.
|
|
311
303
|
* make the method idempotent.
|
|
312
304
|
* @returns Promise resolving to the added account address.
|
|
313
305
|
*/
|
|
314
|
-
async addNewAccount(accountCount
|
|
306
|
+
async addNewAccount(accountCount) {
|
|
315
307
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
|
|
316
|
-
|
|
317
|
-
if (
|
|
318
|
-
selectedKeyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringById).call(this, keyringId);
|
|
319
|
-
}
|
|
320
|
-
if (!selectedKeyring) {
|
|
308
|
+
const primaryKeyring = this.getKeyringsByType('HD Key Tree')[0];
|
|
309
|
+
if (!primaryKeyring) {
|
|
321
310
|
throw new Error('No HD keyring found');
|
|
322
311
|
}
|
|
323
|
-
const oldAccounts = await
|
|
312
|
+
const oldAccounts = await primaryKeyring.getAccounts();
|
|
324
313
|
if (accountCount && oldAccounts.length !== accountCount) {
|
|
325
314
|
if (accountCount > oldAccounts.length) {
|
|
326
315
|
throw new Error('Account out of sequence');
|
|
@@ -332,8 +321,8 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
332
321
|
}
|
|
333
322
|
return existingAccount;
|
|
334
323
|
}
|
|
335
|
-
const [addedAccountAddress] = await
|
|
336
|
-
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_verifySeedPhrase).call(this
|
|
324
|
+
const [addedAccountAddress] = await primaryKeyring.addAccounts(1);
|
|
325
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_verifySeedPhrase).call(this);
|
|
337
326
|
return addedAccountAddress;
|
|
338
327
|
});
|
|
339
328
|
}
|
|
@@ -416,7 +405,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
416
405
|
if (type === KeyringTypes.qr) {
|
|
417
406
|
return this.getOrAddQRKeyring();
|
|
418
407
|
}
|
|
419
|
-
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, type, opts
|
|
408
|
+
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, type, opts));
|
|
420
409
|
}
|
|
421
410
|
/**
|
|
422
411
|
* Method to verify a given password validity. Throws an
|
|
@@ -442,21 +431,12 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
442
431
|
* Gets the seed phrase of the HD keyring.
|
|
443
432
|
*
|
|
444
433
|
* @param password - Password of the keyring.
|
|
445
|
-
* @param keyringId - The id of the keyring.
|
|
446
434
|
* @returns Promise resolving to the seed phrase.
|
|
447
435
|
*/
|
|
448
|
-
async exportSeedPhrase(password
|
|
436
|
+
async exportSeedPhrase(password) {
|
|
449
437
|
await this.verifyPassword(password);
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0].mnemonic;
|
|
453
|
-
}
|
|
454
|
-
const selectedKeyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringById).call(this, keyringId);
|
|
455
|
-
if (!selectedKeyring) {
|
|
456
|
-
throw new Error('Keyring not found');
|
|
457
|
-
}
|
|
458
|
-
assertHasUint8ArrayMnemonic(selectedKeyring);
|
|
459
|
-
return selectedKeyring.mnemonic;
|
|
438
|
+
assertHasUint8ArrayMnemonic(__classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0]);
|
|
439
|
+
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0].mnemonic;
|
|
460
440
|
}
|
|
461
441
|
/**
|
|
462
442
|
* Gets the private key from the keyring controlling an address.
|
|
@@ -476,18 +456,9 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
476
456
|
/**
|
|
477
457
|
* Returns the public addresses of all accounts from every keyring.
|
|
478
458
|
*
|
|
479
|
-
* @param keyringId - The id of the keyring to get the accounts from.
|
|
480
459
|
* @returns A promise resolving to an array of addresses.
|
|
481
460
|
*/
|
|
482
|
-
async getAccounts(
|
|
483
|
-
if (keyringId) {
|
|
484
|
-
const keyringIndex = this.state.keyringsMetadata.findIndex((keyring) => keyring.id === keyringId);
|
|
485
|
-
const keyring = this.state.keyrings[keyringIndex];
|
|
486
|
-
if (!keyring) {
|
|
487
|
-
throw new Error('Keyring not found');
|
|
488
|
-
}
|
|
489
|
-
return keyring.accounts;
|
|
490
|
-
}
|
|
461
|
+
async getAccounts() {
|
|
491
462
|
return this.state.keyrings.reduce((accounts, keyring) => accounts.concat(keyring.accounts), []);
|
|
492
463
|
}
|
|
493
464
|
/**
|
|
@@ -627,7 +598,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
627
598
|
}
|
|
628
599
|
const newKeyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, KeyringTypes.simple, [
|
|
629
600
|
privateKey,
|
|
630
|
-
]
|
|
601
|
+
]));
|
|
631
602
|
const accounts = await newKeyring.getAccounts();
|
|
632
603
|
return accounts[0];
|
|
633
604
|
});
|
|
@@ -866,11 +837,10 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
866
837
|
/**
|
|
867
838
|
* Verifies the that the seed phrase restores the current keychain's accounts.
|
|
868
839
|
*
|
|
869
|
-
* @param keyringId - The id of the keyring to verify.
|
|
870
840
|
* @returns Promise resolving to the seed phrase as Uint8Array.
|
|
871
841
|
*/
|
|
872
|
-
async verifySeedPhrase(
|
|
873
|
-
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_verifySeedPhrase).call(this
|
|
842
|
+
async verifySeedPhrase() {
|
|
843
|
+
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_verifySeedPhrase).call(this));
|
|
874
844
|
}
|
|
875
845
|
async withKeyring(selector, operation, options = {
|
|
876
846
|
createIfMissing: false,
|
|
@@ -880,16 +850,12 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
880
850
|
if ('address' in selector) {
|
|
881
851
|
keyring = (await this.getKeyringForAccount(selector.address));
|
|
882
852
|
}
|
|
883
|
-
else
|
|
853
|
+
else {
|
|
884
854
|
keyring = this.getKeyringsByType(selector.type)[selector.index || 0];
|
|
885
855
|
if (!keyring && options.createIfMissing) {
|
|
886
|
-
|
|
887
|
-
keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, selector.type, options.createWithData, newMetadata));
|
|
856
|
+
keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, selector.type, options.createWithData));
|
|
888
857
|
}
|
|
889
858
|
}
|
|
890
|
-
else if ('id' in selector) {
|
|
891
|
-
keyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringById).call(this, selector.id);
|
|
892
|
-
}
|
|
893
859
|
if (!keyring) {
|
|
894
860
|
throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
|
|
895
861
|
}
|
|
@@ -1090,7 +1056,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
1090
1056
|
}
|
|
1091
1057
|
}
|
|
1092
1058
|
exports.KeyringController = KeyringController;
|
|
1093
|
-
_KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(), _KeyringController_keyrings = new WeakMap(),
|
|
1059
|
+
_KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(), _KeyringController_keyrings = new WeakMap(), _KeyringController_unsupportedKeyrings = new WeakMap(), _KeyringController_password = new WeakMap(), _KeyringController_encryptor = new WeakMap(), _KeyringController_cacheEncryptionKey = new WeakMap(), _KeyringController_qrKeyringStateListener = new WeakMap(), _KeyringController_instances = new WeakSet(), _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
|
|
1094
1060
|
this.messagingSystem.registerActionHandler(`${name}:signMessage`, this.signMessage.bind(this));
|
|
1095
1061
|
this.messagingSystem.registerActionHandler(`${name}:signPersonalMessage`, this.signPersonalMessage.bind(this));
|
|
1096
1062
|
this.messagingSystem.registerActionHandler(`${name}:signTypedMessage`, this.signTypedMessage.bind(this));
|
|
@@ -1104,9 +1070,6 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
|
|
|
1104
1070
|
this.messagingSystem.registerActionHandler(`${name}:patchUserOperation`, this.patchUserOperation.bind(this));
|
|
1105
1071
|
this.messagingSystem.registerActionHandler(`${name}:signUserOperation`, this.signUserOperation.bind(this));
|
|
1106
1072
|
this.messagingSystem.registerActionHandler(`${name}:addNewAccount`, this.addNewAccount.bind(this));
|
|
1107
|
-
}, _KeyringController_getKeyringById = function _KeyringController_getKeyringById(keyringId) {
|
|
1108
|
-
const index = __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").findIndex((metadata) => metadata.id === keyringId);
|
|
1109
|
-
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[index];
|
|
1110
1073
|
}, _KeyringController_getKeyringBuilderForType = function _KeyringController_getKeyringBuilderForType(type) {
|
|
1111
1074
|
return __classPrivateFieldGet(this, _KeyringController_keyringBuilders, "f").find((keyringBuilder) => keyringBuilder.type === type);
|
|
1112
1075
|
}, _KeyringController_addQRKeyring =
|
|
@@ -1120,10 +1083,7 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
|
|
|
1120
1083
|
async function _KeyringController_addQRKeyring() {
|
|
1121
1084
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1122
1085
|
// QRKeyring is not yet compatible with Keyring type from @metamask/utils
|
|
1123
|
-
return (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, KeyringTypes.qr
|
|
1124
|
-
id: ulid(),
|
|
1125
|
-
name: '',
|
|
1126
|
-
}));
|
|
1086
|
+
return (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, KeyringTypes.qr));
|
|
1127
1087
|
}, _KeyringController_subscribeToQRKeyringEvents = function _KeyringController_subscribeToQRKeyringEvents(qrKeyring) {
|
|
1128
1088
|
__classPrivateFieldSet(this, _KeyringController_qrKeyringStateListener, (state) => {
|
|
1129
1089
|
this.messagingSystem.publish(`${name}:qrKeyringStateChange`, state);
|
|
@@ -1168,20 +1128,17 @@ async function _KeyringController_createNewVaultWithKeyring(password, keyring) {
|
|
|
1168
1128
|
/**
|
|
1169
1129
|
* Internal non-exclusive method to verify the seed phrase.
|
|
1170
1130
|
*
|
|
1171
|
-
* @param keyringId - The id of the keyring to verify the seed phrase for.
|
|
1172
1131
|
* @returns A promise resolving to the seed phrase as Uint8Array.
|
|
1173
1132
|
*/
|
|
1174
|
-
async function _KeyringController_verifySeedPhrase(
|
|
1133
|
+
async function _KeyringController_verifySeedPhrase() {
|
|
1175
1134
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1176
|
-
const
|
|
1177
|
-
|
|
1178
|
-
: this.getKeyringsByType(KeyringTypes.hd)[0];
|
|
1179
|
-
if (!keyring) {
|
|
1135
|
+
const primaryKeyring = this.getKeyringsByType(KeyringTypes.hd)[0];
|
|
1136
|
+
if (!primaryKeyring) {
|
|
1180
1137
|
throw new Error('No HD keyring found.');
|
|
1181
1138
|
}
|
|
1182
|
-
assertHasUint8ArrayMnemonic(
|
|
1183
|
-
const seedWords =
|
|
1184
|
-
const accounts = await
|
|
1139
|
+
assertHasUint8ArrayMnemonic(primaryKeyring);
|
|
1140
|
+
const seedWords = primaryKeyring.mnemonic;
|
|
1141
|
+
const accounts = await primaryKeyring.getAccounts();
|
|
1185
1142
|
/* istanbul ignore if */
|
|
1186
1143
|
if (accounts.length === 0) {
|
|
1187
1144
|
throw new Error('Cannot verify an empty keyring.');
|
|
@@ -1229,13 +1186,12 @@ async function _KeyringController_getUpdatedKeyrings() {
|
|
|
1229
1186
|
async function _KeyringController_getSerializedKeyrings({ includeUnsupported } = {
|
|
1230
1187
|
includeUnsupported: true,
|
|
1231
1188
|
}) {
|
|
1232
|
-
const serializedKeyrings = await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async (keyring
|
|
1233
|
-
const [type, data
|
|
1189
|
+
const serializedKeyrings = await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async (keyring) => {
|
|
1190
|
+
const [type, data] = await Promise.all([
|
|
1234
1191
|
keyring.type,
|
|
1235
1192
|
keyring.serialize(),
|
|
1236
|
-
__classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f")[index],
|
|
1237
1193
|
]);
|
|
1238
|
-
return { type, data
|
|
1194
|
+
return { type, data };
|
|
1239
1195
|
}));
|
|
1240
1196
|
if (includeUnsupported) {
|
|
1241
1197
|
serializedKeyrings.push(...__classPrivateFieldGet(this, _KeyringController_unsupportedKeyrings, "f"));
|
|
@@ -1310,10 +1266,8 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
|
|
|
1310
1266
|
}
|
|
1311
1267
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_restoreSerializedKeyrings).call(this, vault);
|
|
1312
1268
|
const updatedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getUpdatedKeyrings).call(this);
|
|
1313
|
-
const updatedKeyringsMetadata = __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f");
|
|
1314
1269
|
this.update((state) => {
|
|
1315
1270
|
state.keyrings = updatedKeyrings;
|
|
1316
|
-
state.keyringsMetadata = updatedKeyringsMetadata;
|
|
1317
1271
|
if (updatedState.encryptionKey || updatedState.encryptionSalt) {
|
|
1318
1272
|
state.encryptionKey = updatedState.encryptionKey;
|
|
1319
1273
|
state.encryptionSalt = updatedState.encryptionSalt;
|
|
@@ -1364,11 +1318,9 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
|
|
|
1364
1318
|
throw new Error(constants_1.KeyringControllerError.MissingVaultData);
|
|
1365
1319
|
}
|
|
1366
1320
|
const updatedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getUpdatedKeyrings).call(this);
|
|
1367
|
-
const updatedKeyringsMetadata = __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f");
|
|
1368
1321
|
this.update((state) => {
|
|
1369
1322
|
state.vault = updatedState.vault;
|
|
1370
1323
|
state.keyrings = updatedKeyrings;
|
|
1371
|
-
state.keyringsMetadata = updatedKeyringsMetadata;
|
|
1372
1324
|
if (updatedState.encryptionKey) {
|
|
1373
1325
|
state.encryptionKey = updatedState.encryptionKey;
|
|
1374
1326
|
state.encryptionSalt = JSON.parse(updatedState.vault).salt;
|
|
@@ -1403,15 +1355,11 @@ async function _KeyringController_getAccountsFromKeyrings() {
|
|
|
1403
1355
|
*/
|
|
1404
1356
|
async function _KeyringController_createKeyringWithFirstAccount(type, opts) {
|
|
1405
1357
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1406
|
-
const keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, type, opts
|
|
1407
|
-
id: ulid(),
|
|
1408
|
-
name: '',
|
|
1409
|
-
}));
|
|
1358
|
+
const keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, type, opts));
|
|
1410
1359
|
const [firstAccount] = await keyring.getAccounts();
|
|
1411
1360
|
if (!firstAccount) {
|
|
1412
1361
|
throw new Error(constants_1.KeyringControllerError.NoFirstAccount);
|
|
1413
1362
|
}
|
|
1414
|
-
return firstAccount;
|
|
1415
1363
|
}, _KeyringController_newKeyring =
|
|
1416
1364
|
/**
|
|
1417
1365
|
* Instantiate, initialize and return a new keyring of the given `type`,
|
|
@@ -1421,11 +1369,10 @@ async function _KeyringController_createKeyringWithFirstAccount(type, opts) {
|
|
|
1421
1369
|
*
|
|
1422
1370
|
* @param type - The type of keyring to add.
|
|
1423
1371
|
* @param data - The data to restore a previously serialized keyring.
|
|
1424
|
-
* @param metadata - The metadata to add to the keyring.
|
|
1425
1372
|
* @returns The new keyring.
|
|
1426
1373
|
* @throws If the keyring includes duplicated accounts.
|
|
1427
1374
|
*/
|
|
1428
|
-
async function _KeyringController_newKeyring(type, data
|
|
1375
|
+
async function _KeyringController_newKeyring(type, data) {
|
|
1429
1376
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1430
1377
|
const keyringBuilder = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringBuilderForType).call(this, type);
|
|
1431
1378
|
if (!keyringBuilder) {
|
|
@@ -1457,9 +1404,6 @@ async function _KeyringController_newKeyring(type, data, metadata) {
|
|
|
1457
1404
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_subscribeToQRKeyringEvents).call(this, keyring);
|
|
1458
1405
|
}
|
|
1459
1406
|
__classPrivateFieldGet(this, _KeyringController_keyrings, "f").push(keyring);
|
|
1460
|
-
if (metadata && __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").length < __classPrivateFieldGet(this, _KeyringController_keyrings, "f").length) {
|
|
1461
|
-
__classPrivateFieldSet(this, _KeyringController_keyringsMetadata, [...__classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f"), metadata], "f");
|
|
1462
|
-
}
|
|
1463
1407
|
return keyring;
|
|
1464
1408
|
}, _KeyringController_clearKeyrings =
|
|
1465
1409
|
/**
|
|
@@ -1483,8 +1427,8 @@ async function _KeyringController_clearKeyrings() {
|
|
|
1483
1427
|
async function _KeyringController_restoreKeyring(serialized) {
|
|
1484
1428
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1485
1429
|
try {
|
|
1486
|
-
const { type, data
|
|
1487
|
-
return await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, type, data
|
|
1430
|
+
const { type, data } = serialized;
|
|
1431
|
+
return await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, type, data);
|
|
1488
1432
|
}
|
|
1489
1433
|
catch (_) {
|
|
1490
1434
|
__classPrivateFieldGet(this, _KeyringController_unsupportedKeyrings, "f").push(serialized);
|
|
@@ -1515,14 +1459,13 @@ async function _KeyringController_removeEmptyKeyrings() {
|
|
|
1515
1459
|
// Since getAccounts returns a Promise
|
|
1516
1460
|
// We need to wait to hear back form each keyring
|
|
1517
1461
|
// in order to decide which ones are now valid (accounts.length > 0)
|
|
1518
|
-
await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async (keyring
|
|
1462
|
+
await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async (keyring) => {
|
|
1519
1463
|
const accounts = await keyring.getAccounts();
|
|
1520
1464
|
if (accounts.length > 0) {
|
|
1521
1465
|
validKeyrings.push(keyring);
|
|
1522
1466
|
}
|
|
1523
1467
|
else {
|
|
1524
1468
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring);
|
|
1525
|
-
__classPrivateFieldSet(this, _KeyringController_keyringsMetadata, __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").filter((_, i) => i !== index), "f");
|
|
1526
1469
|
}
|
|
1527
1470
|
}));
|
|
1528
1471
|
__classPrivateFieldSet(this, _KeyringController_keyrings, validKeyrings, "f");
|