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