@metamask/accounts-controller 30.0.0 → 32.0.0
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 +26 -1
- package/dist/AccountsController.cjs +125 -134
- package/dist/AccountsController.cjs.map +1 -1
- package/dist/AccountsController.d.cts.map +1 -1
- package/dist/AccountsController.d.mts.map +1 -1
- package/dist/AccountsController.mjs +128 -136
- package/dist/AccountsController.mjs.map +1 -1
- package/dist/tests/mocks.cjs +12 -2
- package/dist/tests/mocks.cjs.map +1 -1
- package/dist/tests/mocks.d.cts +13 -3
- package/dist/tests/mocks.d.cts.map +1 -1
- package/dist/tests/mocks.d.mts +13 -3
- package/dist/tests/mocks.d.mts.map +1 -1
- package/dist/tests/mocks.mjs +13 -3
- package/dist/tests/mocks.mjs.map +1 -1
- package/dist/utils.cjs +80 -5
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +56 -4
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +56 -4
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +74 -3
- package/dist/utils.mjs.map +1 -1
- package/package.json +16 -13
package/CHANGELOG.md
CHANGED
@@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [32.0.0]
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- Use new typed `KeyringAccount.options` for BIP-44 compatible accounts ([#6122](https://github.com/MetaMask/core/pull/6122)), ([#6147](https://github.com/MetaMask/core/pull/6147))
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
|
18
|
+
- **BREAKING:** Bump peer dependency `@metamask/snaps-controllers` from `^12.0.0` to `^14.0.0` ([#6035](https://github.com/MetaMask/core/pull/6035))
|
19
|
+
- Bump `@metamask/snaps-sdk` from `^7.1.0` to `^9.0.0` ([#6035](https://github.com/MetaMask/core/pull/6035))
|
20
|
+
- Bump `@metamask/snaps-utils` from `^9.4.0` to `^11.0.0` ([#6035](https://github.com/MetaMask/core/pull/6035))
|
21
|
+
- Bump `@metamask/keyring-api` from `^18.0.0` to `^19.0.0` ([#6146](https://github.com/MetaMask/core/pull/6146))
|
22
|
+
- Bump `@metamask/keyring-internal-api` from `^6.2.0` to `^7.0.0` ([#6146](https://github.com/MetaMask/core/pull/6146))
|
23
|
+
- Bump `@metamask/keyring-utils` from `^3.0.0` to `^3.1.0` ([#6146](https://github.com/MetaMask/core/pull/6146))
|
24
|
+
- Bump `@metamask/eth-snap-keyring` from `^13.0.0` to `^14.0.0` ([#6146](https://github.com/MetaMask/core/pull/6146))
|
25
|
+
- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))
|
26
|
+
|
27
|
+
## [31.0.0]
|
28
|
+
|
29
|
+
### Changed
|
30
|
+
|
31
|
+
- **BREAKING:** Bump peer dependency `@metamask/network-controller` to `^24.0.0` ([#5999](https://github.com/MetaMask/core/pull/5999))
|
32
|
+
|
10
33
|
## [30.0.0]
|
11
34
|
|
12
35
|
### Changed
|
@@ -549,7 +572,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
549
572
|
|
550
573
|
- Initial release ([#1637](https://github.com/MetaMask/core/pull/1637))
|
551
574
|
|
552
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@
|
575
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@32.0.0...HEAD
|
576
|
+
[32.0.0]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@31.0.0...@metamask/accounts-controller@32.0.0
|
577
|
+
[31.0.0]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@30.0.0...@metamask/accounts-controller@31.0.0
|
553
578
|
[30.0.0]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@29.0.1...@metamask/accounts-controller@30.0.0
|
554
579
|
[29.0.1]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@29.0.0...@metamask/accounts-controller@29.0.1
|
555
580
|
[29.0.0]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@28.0.0...@metamask/accounts-controller@29.0.0
|
@@ -4,7 +4,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
4
4
|
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");
|
5
5
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
6
6
|
};
|
7
|
-
var _AccountsController_instances, _AccountsController_assertAccountCanBeRenamed,
|
7
|
+
var _AccountsController_instances, _AccountsController_assertAccountCanBeRenamed, _AccountsController_getInternalAccountForNonSnapAccount, _AccountsController_getSnapKeyring, _AccountsController_handleOnSnapKeyringAccountEvent, _AccountsController_handleOnKeyringStateChange, _AccountsController_update, _AccountsController_handleOnSnapStateChange, _AccountsController_getAccountsByKeyringType, _AccountsController_getLastSelectedAccount, _AccountsController_getLastSelectedIndex, _AccountsController_getInternalAccountFromAddressAndType, _AccountsController_handleOnMultichainNetworkDidChange, _AccountsController_subscribeToMessageEvents, _AccountsController_registerMessageHandlers;
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
9
9
|
exports.AccountsController = exports.EMPTY_ACCOUNT = void 0;
|
10
10
|
const base_controller_1 = require("@metamask/base-controller");
|
@@ -13,6 +13,7 @@ const keyring_api_1 = require("@metamask/keyring-api");
|
|
13
13
|
const keyring_controller_1 = require("@metamask/keyring-controller");
|
14
14
|
const keyring_utils_1 = require("@metamask/keyring-utils");
|
15
15
|
const utils_1 = require("@metamask/utils");
|
16
|
+
const lodash_1 = require("lodash");
|
16
17
|
const utils_2 = require("./utils.cjs");
|
17
18
|
const controllerName = 'AccountsController';
|
18
19
|
const accountsControllerMetadata = {
|
@@ -269,38 +270,41 @@ class AccountsController extends base_controller_1.BaseController {
|
|
269
270
|
* @returns A Promise that resolves when the accounts have been updated.
|
270
271
|
*/
|
271
272
|
async updateAccounts() {
|
272
|
-
const
|
273
|
-
const
|
274
|
-
|
275
|
-
const
|
276
|
-
const
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
273
|
+
const keyringAccountIndexes = new Map();
|
274
|
+
const existingInternalAccounts = this.state.internalAccounts.accounts;
|
275
|
+
const internalAccounts = {};
|
276
|
+
const { keyrings } = this.messagingSystem.call('KeyringController:getState');
|
277
|
+
for (const keyring of keyrings) {
|
278
|
+
const keyringTypeName = (0, utils_2.keyringTypeToName)(keyring.type);
|
279
|
+
for (const address of keyring.accounts) {
|
280
|
+
const internalAccount = __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getInternalAccountFromAddressAndType).call(this, address, keyring);
|
281
|
+
// This should never really happen, but if for some reason we're not
|
282
|
+
// able to get the Snap keyring reference, this would return an
|
283
|
+
// undefined account.
|
284
|
+
// So we just skip it, even though, this should not really happen.
|
285
|
+
if (!internalAccount) {
|
286
|
+
continue;
|
287
|
+
}
|
288
|
+
// Get current index for this keyring (we use human indexing, so start at 1).
|
289
|
+
const keyringAccountIndex = keyringAccountIndexes.get(keyringTypeName) ?? 1;
|
290
|
+
const existingAccount = existingInternalAccounts[internalAccount.id];
|
291
|
+
internalAccounts[internalAccount.id] = {
|
292
|
+
...internalAccount,
|
293
|
+
metadata: {
|
294
|
+
...internalAccount.metadata,
|
295
|
+
// Re-use existing metadata if any.
|
296
|
+
name: existingAccount?.metadata.name ??
|
297
|
+
`${keyringTypeName} ${keyringAccountIndex}`,
|
298
|
+
importTime: existingAccount?.metadata.importTime ?? Date.now(),
|
299
|
+
lastSelected: existingAccount?.metadata.lastSelected ?? 0,
|
300
|
+
},
|
301
|
+
};
|
302
|
+
// Increment the account index for this keyring.
|
303
|
+
keyringAccountIndexes.set(keyringTypeName, keyringAccountIndex + 1);
|
288
304
|
}
|
289
|
-
|
290
|
-
internalAccountMap[internalAccount.id] = {
|
291
|
-
...internalAccount,
|
292
|
-
metadata: {
|
293
|
-
...internalAccount.metadata,
|
294
|
-
name: __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_populateExistingMetadata).call(this, existingAccount?.id, 'name') ??
|
295
|
-
`${keyringTypeName} ${keyringAccountIndex + 1}`,
|
296
|
-
importTime: __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_populateExistingMetadata).call(this, existingAccount?.id, 'importTime') ?? Date.now(),
|
297
|
-
lastSelected: __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_populateExistingMetadata).call(this, existingAccount?.id, 'lastSelected') ?? 0,
|
298
|
-
},
|
299
|
-
};
|
300
|
-
return internalAccountMap;
|
301
|
-
}, {});
|
305
|
+
}
|
302
306
|
__classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_update).call(this, (state) => {
|
303
|
-
state.internalAccounts.accounts =
|
307
|
+
state.internalAccounts.accounts = internalAccounts;
|
304
308
|
});
|
305
309
|
}
|
306
310
|
/**
|
@@ -349,11 +353,63 @@ _AccountsController_instances = new WeakSet(), _AccountsController_assertAccount
|
|
349
353
|
internalAccount.id !== account.id)) {
|
350
354
|
throw new Error('Account name already exists');
|
351
355
|
}
|
352
|
-
},
|
356
|
+
}, _AccountsController_getInternalAccountForNonSnapAccount = function _AccountsController_getInternalAccountForNonSnapAccount(address, keyring) {
|
357
|
+
const id = (0, utils_2.getUUIDFromAddressOfNormalAccount)(address);
|
358
|
+
// We might have an account for this ID already, so we'll just re-use
|
359
|
+
// the same metadata
|
360
|
+
const account = this.getAccount(id);
|
361
|
+
const metadata = {
|
362
|
+
name: account?.metadata.name ?? '',
|
363
|
+
...(account?.metadata.nameLastUpdatedAt
|
364
|
+
? {
|
365
|
+
nameLastUpdatedAt: account?.metadata.nameLastUpdatedAt,
|
366
|
+
}
|
367
|
+
: {}),
|
368
|
+
importTime: account?.metadata.importTime ?? Date.now(),
|
369
|
+
lastSelected: account?.metadata.lastSelected ?? 0,
|
370
|
+
keyring: {
|
371
|
+
type: keyring.type,
|
372
|
+
},
|
373
|
+
};
|
374
|
+
let options = {};
|
375
|
+
if ((0, utils_2.isHdKeyringType)(keyring.type)) {
|
376
|
+
// We need to find the account index from its HD keyring.
|
377
|
+
const groupIndex = (0, utils_2.getEvmGroupIndexFromAddressIndex)(keyring, address);
|
378
|
+
// If for some reason, we cannot find this address, then the caller made a mistake
|
379
|
+
// and it did not use the proper keyring object. For now, we do not fail and just
|
380
|
+
// consider this account as "simple account".
|
381
|
+
if (groupIndex !== undefined) {
|
382
|
+
// NOTE: We are not using the `hdPath` from the associated keyring here and
|
383
|
+
// getting the keyring instance here feels a bit overkill.
|
384
|
+
// This will be naturally fixed once every keyring start using `KeyringAccount` and implement the keyring API.
|
385
|
+
const derivationPath = (0, utils_2.getEvmDerivationPathForIndex)(groupIndex);
|
386
|
+
// Those are "legacy options" and they were used before `KeyringAccount` added
|
387
|
+
// support for type options. We keep those temporarily until we update everything
|
388
|
+
// to use the new typed options.
|
389
|
+
const legacyOptions = {
|
390
|
+
entropySource: keyring.metadata.id,
|
391
|
+
derivationPath,
|
392
|
+
groupIndex,
|
393
|
+
};
|
394
|
+
// New typed entropy options. This is required for multichain accounts.
|
395
|
+
const entropyOptions = {
|
396
|
+
entropy: {
|
397
|
+
type: keyring_api_1.KeyringAccountEntropyTypeOption.Mnemonic,
|
398
|
+
id: keyring.metadata.id,
|
399
|
+
derivationPath,
|
400
|
+
groupIndex,
|
401
|
+
},
|
402
|
+
};
|
403
|
+
options = {
|
404
|
+
...legacyOptions,
|
405
|
+
...entropyOptions,
|
406
|
+
};
|
407
|
+
}
|
408
|
+
}
|
353
409
|
return {
|
354
|
-
id
|
410
|
+
id,
|
355
411
|
address,
|
356
|
-
options
|
412
|
+
options,
|
357
413
|
methods: [
|
358
414
|
keyring_api_1.EthMethod.PersonalSign,
|
359
415
|
keyring_api_1.EthMethod.Sign,
|
@@ -364,88 +420,13 @@ _AccountsController_instances = new WeakSet(), _AccountsController_assertAccount
|
|
364
420
|
],
|
365
421
|
scopes: [keyring_api_1.EthScope.Eoa],
|
366
422
|
type: keyring_api_1.EthAccountType.Eoa,
|
367
|
-
metadata
|
368
|
-
name: '',
|
369
|
-
importTime: Date.now(),
|
370
|
-
keyring: {
|
371
|
-
type,
|
372
|
-
},
|
373
|
-
},
|
423
|
+
metadata,
|
374
424
|
};
|
375
425
|
}, _AccountsController_getSnapKeyring = function _AccountsController_getSnapKeyring() {
|
376
426
|
const [snapKeyring] = this.messagingSystem.call('KeyringController:getKeyringsByType', eth_snap_keyring_1.SnapKeyring.type);
|
377
427
|
// Snap keyring is not available until the first account is created in the keyring
|
378
428
|
// controller, so this might be undefined.
|
379
429
|
return snapKeyring;
|
380
|
-
}, _AccountsController_listSnapAccounts =
|
381
|
-
/**
|
382
|
-
* Returns a list of internal accounts created using the SnapKeyring.
|
383
|
-
*
|
384
|
-
* @returns A promise that resolves to an array of InternalAccount objects.
|
385
|
-
*/
|
386
|
-
async function _AccountsController_listSnapAccounts() {
|
387
|
-
const keyring = __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getSnapKeyring).call(this);
|
388
|
-
if (!keyring) {
|
389
|
-
return [];
|
390
|
-
}
|
391
|
-
return keyring.listAccounts();
|
392
|
-
}, _AccountsController_listNormalAccounts =
|
393
|
-
/**
|
394
|
-
* Returns a list of normal accounts.
|
395
|
-
* Note: listNormalAccounts is a temporary method until the keyrings all implement the InternalAccount interface.
|
396
|
-
* Once all keyrings implement the InternalAccount interface, this method can be removed and getAccounts can be used instead.
|
397
|
-
*
|
398
|
-
* @returns A Promise that resolves to an array of InternalAccount objects.
|
399
|
-
*/
|
400
|
-
async function _AccountsController_listNormalAccounts() {
|
401
|
-
const internalAccounts = [];
|
402
|
-
const { keyrings } = this.messagingSystem.call('KeyringController:getState');
|
403
|
-
for (const keyring of keyrings) {
|
404
|
-
const keyringType = keyring.type;
|
405
|
-
if (!(0, utils_2.isNormalKeyringType)(keyringType)) {
|
406
|
-
// We only consider "normal accounts" here, so keep looping
|
407
|
-
continue;
|
408
|
-
}
|
409
|
-
for (const [accountIndex, address] of keyring.accounts.entries()) {
|
410
|
-
const id = (0, utils_2.getUUIDFromAddressOfNormalAccount)(address);
|
411
|
-
let options = {};
|
412
|
-
if ((0, utils_2.isHdKeyringType)(keyring.type)) {
|
413
|
-
options = {
|
414
|
-
entropySource: keyring.metadata.id,
|
415
|
-
// NOTE: We are not using the `hdPath` from the associated keyring here and
|
416
|
-
// getting the keyring instance here feels a bit overkill.
|
417
|
-
// This will be naturally fixed once every keyring start using `KeyringAccount` and implement the keyring API.
|
418
|
-
derivationPath: (0, utils_2.getDerivationPathForIndex)(accountIndex),
|
419
|
-
};
|
420
|
-
}
|
421
|
-
const nameLastUpdatedAt = __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_populateExistingMetadata).call(this, id, 'nameLastUpdatedAt');
|
422
|
-
internalAccounts.push({
|
423
|
-
id,
|
424
|
-
address,
|
425
|
-
options,
|
426
|
-
methods: [
|
427
|
-
keyring_api_1.EthMethod.PersonalSign,
|
428
|
-
keyring_api_1.EthMethod.Sign,
|
429
|
-
keyring_api_1.EthMethod.SignTransaction,
|
430
|
-
keyring_api_1.EthMethod.SignTypedDataV1,
|
431
|
-
keyring_api_1.EthMethod.SignTypedDataV3,
|
432
|
-
keyring_api_1.EthMethod.SignTypedDataV4,
|
433
|
-
],
|
434
|
-
scopes: [keyring_api_1.EthScope.Eoa],
|
435
|
-
type: keyring_api_1.EthAccountType.Eoa,
|
436
|
-
metadata: {
|
437
|
-
name: __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_populateExistingMetadata).call(this, id, 'name') ?? '',
|
438
|
-
...(nameLastUpdatedAt && { nameLastUpdatedAt }),
|
439
|
-
importTime: __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_populateExistingMetadata).call(this, id, 'importTime') ?? Date.now(),
|
440
|
-
lastSelected: __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_populateExistingMetadata).call(this, id, 'lastSelected') ?? 0,
|
441
|
-
keyring: {
|
442
|
-
type: keyringType,
|
443
|
-
},
|
444
|
-
},
|
445
|
-
});
|
446
|
-
}
|
447
|
-
}
|
448
|
-
return internalAccounts;
|
449
430
|
}, _AccountsController_handleOnSnapKeyringAccountEvent = function _AccountsController_handleOnSnapKeyringAccountEvent(event, ...payload) {
|
450
431
|
this.messagingSystem.publish(event, ...payload);
|
451
432
|
}, _AccountsController_handleOnKeyringStateChange = function _AccountsController_handleOnKeyringStateChange({ isUnlocked, keyrings, }) {
|
@@ -472,7 +453,7 @@ async function _AccountsController_listNormalAccounts() {
|
|
472
453
|
// Gets the patch object based on the keyring type (since Snap accounts and other accounts
|
473
454
|
// are handled differently).
|
474
455
|
const patchOf = (type) => {
|
475
|
-
if (
|
456
|
+
if ((0, utils_2.isSnapKeyringType)(type)) {
|
476
457
|
return patches.snap;
|
477
458
|
}
|
478
459
|
return patches.normal;
|
@@ -499,11 +480,7 @@ async function _AccountsController_listNormalAccounts() {
|
|
499
480
|
// Otherwise, that's a new account.
|
500
481
|
patch.added.push({
|
501
482
|
address,
|
502
|
-
|
503
|
-
// Automatically injects `entropySource` for HD accounts only.
|
504
|
-
options: keyring.type === keyring_controller_1.KeyringTypes.hd
|
505
|
-
? { entropySource: keyring.metadata.id }
|
506
|
-
: {},
|
483
|
+
keyring,
|
507
484
|
});
|
508
485
|
}
|
509
486
|
// Keep track of those address to check for removed accounts later.
|
@@ -533,7 +510,7 @@ async function _AccountsController_listNormalAccounts() {
|
|
533
510
|
diff.removed.push(account.id);
|
534
511
|
}
|
535
512
|
for (const added of patch.added) {
|
536
|
-
const account = __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getInternalAccountFromAddressAndType).call(this, added.address, added.
|
513
|
+
const account = __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getInternalAccountFromAddressAndType).call(this, added.address, added.keyring);
|
537
514
|
if (account) {
|
538
515
|
// Re-compute the list of accounts everytime, so we can make sure new names
|
539
516
|
// are also considered.
|
@@ -550,10 +527,6 @@ async function _AccountsController_listNormalAccounts() {
|
|
550
527
|
importTime: Date.now(),
|
551
528
|
lastSelected,
|
552
529
|
},
|
553
|
-
options: {
|
554
|
-
...account.options,
|
555
|
-
...added.options,
|
556
|
-
},
|
557
530
|
};
|
558
531
|
diff.added.push(internalAccounts.accounts[account.id]);
|
559
532
|
}
|
@@ -638,10 +611,9 @@ async function _AccountsController_listNormalAccounts() {
|
|
638
611
|
return (accounts ?? this.listMultichainAccounts()).filter((internalAccount) => {
|
639
612
|
// We do consider `hd` and `simple` keyrings to be of same type. So we check those 2 types
|
640
613
|
// to group those accounts together!
|
641
|
-
if (keyringType
|
642
|
-
|
643
|
-
|
644
|
-
internalAccount.metadata.keyring.type === keyring_controller_1.KeyringTypes.simple);
|
614
|
+
if ((0, utils_2.isHdKeyringType)(keyringType) || (0, utils_2.isSimpleKeyringType)(keyringType)) {
|
615
|
+
return ((0, utils_2.isHdKeyringType)(internalAccount.metadata.keyring.type) ||
|
616
|
+
(0, utils_2.isSimpleKeyringType)(internalAccount.metadata.keyring.type));
|
645
617
|
}
|
646
618
|
return internalAccount.metadata.keyring.type === keyringType;
|
647
619
|
});
|
@@ -656,18 +628,40 @@ async function _AccountsController_listNormalAccounts() {
|
|
656
628
|
// NOTE: For now we use the current date, since we know this value
|
657
629
|
// will always be higher than any already selected account index.
|
658
630
|
return Date.now();
|
659
|
-
}, _AccountsController_getInternalAccountFromAddressAndType = function _AccountsController_getInternalAccountFromAddressAndType(address,
|
660
|
-
if (
|
661
|
-
const
|
631
|
+
}, _AccountsController_getInternalAccountFromAddressAndType = function _AccountsController_getInternalAccountFromAddressAndType(address, keyring) {
|
632
|
+
if ((0, utils_2.isSnapKeyringType)(keyring.type)) {
|
633
|
+
const snapKeyring = __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getSnapKeyring).call(this);
|
662
634
|
// We need the Snap keyring to retrieve the account from its address.
|
663
|
-
if (!
|
635
|
+
if (!snapKeyring) {
|
664
636
|
return undefined;
|
665
637
|
}
|
666
638
|
// This might be undefined if the Snap deleted the account before
|
667
639
|
// reaching that point.
|
668
|
-
|
640
|
+
let account = snapKeyring.getAccountByAddress(address);
|
641
|
+
if (account) {
|
642
|
+
// We force the copy here, to avoid mutating the reference returned by the Snap keyring.
|
643
|
+
account = (0, lodash_1.cloneDeep)(account);
|
644
|
+
// MIGRATION: To avoid any existing Snap account migration, we are
|
645
|
+
// just "adding" the new typed options that we need for multichain
|
646
|
+
// accounts. Ultimately, we would need a real Snap account migrations
|
647
|
+
// (being handled by each Snaps).
|
648
|
+
if ((0, utils_2.isHdSnapKeyringAccount)(account)) {
|
649
|
+
const options = {
|
650
|
+
...account.options,
|
651
|
+
entropy: {
|
652
|
+
type: keyring_api_1.KeyringAccountEntropyTypeOption.Mnemonic,
|
653
|
+
id: account.options.entropySource,
|
654
|
+
groupIndex: account.options.index,
|
655
|
+
derivationPath: account.options.derivationPath,
|
656
|
+
},
|
657
|
+
};
|
658
|
+
// Inject the new typed options to the internal account copy.
|
659
|
+
account.options = options;
|
660
|
+
}
|
661
|
+
}
|
662
|
+
return account;
|
669
663
|
}
|
670
|
-
return __classPrivateFieldGet(this, _AccountsController_instances, "m",
|
664
|
+
return __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getInternalAccountForNonSnapAccount).call(this, address, keyring);
|
671
665
|
}, _AccountsController_handleOnMultichainNetworkDidChange = function _AccountsController_handleOnMultichainNetworkDidChange(id) {
|
672
666
|
let accountId;
|
673
667
|
// We only support non-EVM Caip chain IDs at the moment. Ex Solana and Bitcoin
|
@@ -689,9 +683,6 @@ async function _AccountsController_listNormalAccounts() {
|
|
689
683
|
currentState.internalAccounts.selectedAccount = accountId;
|
690
684
|
});
|
691
685
|
// DO NOT publish AccountsController:setSelectedAccount to prevent circular listener loops
|
692
|
-
}, _AccountsController_populateExistingMetadata = function _AccountsController_populateExistingMetadata(accountId, metadataKey, account) {
|
693
|
-
const internalAccount = account ?? this.getAccount(accountId);
|
694
|
-
return internalAccount ? internalAccount.metadata[metadataKey] : undefined;
|
695
686
|
}, _AccountsController_subscribeToMessageEvents = function _AccountsController_subscribeToMessageEvents() {
|
696
687
|
this.messagingSystem.subscribe('SnapController:stateChange', (snapStateState) => __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_handleOnSnapStateChange).call(this, snapStateState));
|
697
688
|
this.messagingSystem.subscribe('KeyringController:stateChange', (keyringState) => __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_handleOnKeyringStateChange).call(this, keyringState));
|