@metamask-previews/account-tree-controller 4.1.0-preview-7aeef9dd1 → 4.1.0-preview-bc3c2ef97
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
CHANGED
|
@@ -7,11 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Changed
|
|
11
|
-
|
|
12
|
-
- Bump `@metamask/account-api` from `^0.12.0` to `^1.0.0` ([#7857](https://github.com/MetaMask/core/pull/7857))
|
|
13
|
-
- Bump `@metamask/keyring-api` from `^21.0.0` to `^21.5.0` ([#7857](https://github.com/MetaMask/core/pull/7857))
|
|
14
|
-
|
|
15
10
|
## [4.1.0]
|
|
16
11
|
|
|
17
12
|
### Added
|
|
@@ -24,7 +24,7 @@ exports.getLocalEntropyWallets = getLocalEntropyWallets;
|
|
|
24
24
|
const getLocalGroupForEntropyWallet = (context, entropySourceId, groupIndex) => {
|
|
25
25
|
const walletId = (0, account_api_1.toMultichainAccountWalletId)(entropySourceId);
|
|
26
26
|
const wallet = context.controller.state.accountTree.wallets[walletId];
|
|
27
|
-
if (
|
|
27
|
+
if (wallet?.type !== account_api_1.AccountWalletType.Entropy) {
|
|
28
28
|
(0, logger_1.backupAndSyncLogger)(`Wallet ${walletId} not found or is not an entropy wallet`);
|
|
29
29
|
return undefined;
|
|
30
30
|
}
|
|
@@ -41,7 +41,7 @@ exports.getLocalGroupForEntropyWallet = getLocalGroupForEntropyWallet;
|
|
|
41
41
|
*/
|
|
42
42
|
function getLocalGroupsForEntropyWallet(context, walletId) {
|
|
43
43
|
const wallet = context.controller.state.accountTree.wallets[walletId];
|
|
44
|
-
if (
|
|
44
|
+
if (wallet?.type !== account_api_1.AccountWalletType.Entropy) {
|
|
45
45
|
(0, logger_1.backupAndSyncLogger)(`Wallet ${walletId} not found or is not an entropy wallet`);
|
|
46
46
|
return [];
|
|
47
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.cjs","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/controller.ts"],"names":[],"mappings":";;;AAAA,uDAI+B;AAI/B,6CAAmD;AAKnD;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,OAA6B;IAE7B,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CACvE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,+BAAiB,CAAC,OAAO,CACtB,CAAC;AACpC,CAAC;AAND,wDAMC;AAED;;;;;;;GAOG;AACI,MAAM,6BAA6B,GAAG,CAC3C,OAA6B,EAC7B,eAAuB,EACvB,UAAkB,EAC+B,EAAE;IACnD,MAAM,QAAQ,GAAG,IAAA,yCAA2B,EAAC,eAAe,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEtE,IAAI,
|
|
1
|
+
{"version":3,"file":"controller.cjs","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/controller.ts"],"names":[],"mappings":";;;AAAA,uDAI+B;AAI/B,6CAAmD;AAKnD;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,OAA6B;IAE7B,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CACvE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,+BAAiB,CAAC,OAAO,CACtB,CAAC;AACpC,CAAC;AAND,wDAMC;AAED;;;;;;;GAOG;AACI,MAAM,6BAA6B,GAAG,CAC3C,OAA6B,EAC7B,eAAuB,EACvB,UAAkB,EAC+B,EAAE;IACn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C,sBAAsB,CAAC,CAChE;QACD,oBAAoB,EAClB,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,oBAAoB;QAC3D,kBAAkB,EAAE,IAAI,CAAC,KAAK,CAC5B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAC7D;KACF,CAAC;AACJ,CAAC;AAhBD,kDAgBC;AAED;;;;;;;GAOG;AACH,SAAgB,wBAAwB,CACtC,OAA6B,EAC7B,QAAuB;IAEvB,OAAO,CAAC,uBAAuB,CAAC,CAAC,KAAK,EAAE,EAAE;QACxC,KAAK,CAAC,qBAAqB,GAAG,QAAQ,CAAC,qBAAqB,CAAC;QAC7D,KAAK,CAAC,sBAAsB,GAAG,QAAQ,CAAC,sBAAsB,CAAC;QAC/D,KAAK,CAAC,WAAW,CAAC,oBAAoB,GAAG,QAAQ,CAAC,oBAAoB,CAAC;QACvE,KAAK,CAAC,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC,kBAAkB,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,+EAA+E;IAC/E,mFAAmF;IACnF,sEAAsE;IACtE,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;AAC5B,CAAC;AAfD,4DAeC","sourcesContent":["import {\n AccountWalletType,\n toMultichainAccountGroupId,\n toMultichainAccountWalletId,\n} from '@metamask/account-api';\nimport type { AccountWalletId } from '@metamask/account-api';\n\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport { backupAndSyncLogger } from '../../logger';\nimport type { AccountTreeControllerState } from '../../types';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type { BackupAndSyncContext } from '../types';\n\n/**\n * Gets all local entropy wallets that can be synced.\n *\n * @param context - The backup and sync context.\n * @returns Array of entropy wallet objects.\n */\nexport function getLocalEntropyWallets(\n context: BackupAndSyncContext,\n): AccountWalletEntropyObject[] {\n return Object.values(context.controller.state.accountTree.wallets).filter(\n (wallet) => wallet.type === AccountWalletType.Entropy,\n ) as AccountWalletEntropyObject[];\n}\n\n/**\n * Gets the local group for a specific entropy wallet by its source ID and group index.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @param groupIndex - The group index.\n * @returns The local group object if it exists, undefined otherwise.\n */\nexport const getLocalGroupForEntropyWallet = (\n context: BackupAndSyncContext,\n entropySourceId: string,\n groupIndex: number,\n): AccountGroupMultichainAccountObject | undefined => {\n const walletId = toMultichainAccountWalletId(entropySourceId);\n const wallet = context.controller.state.accountTree.wallets[walletId];\n\n if (wallet?.type !== AccountWalletType.Entropy) {\n backupAndSyncLogger(\n `Wallet ${walletId} not found or is not an entropy wallet`,\n );\n return undefined;\n }\n\n const groupId = toMultichainAccountGroupId(walletId, groupIndex);\n\n return wallet.groups[groupId];\n};\n\n/**\n * Gets all groups for a specific entropy wallet.\n *\n * @param context - The backup and sync context.\n * @param walletId - The wallet ID to get groups for.\n * @returns Array of multichain account group objects.\n */\nexport function getLocalGroupsForEntropyWallet(\n context: BackupAndSyncContext,\n walletId: AccountWalletId,\n): AccountGroupMultichainAccountObject[] {\n const wallet = context.controller.state.accountTree.wallets[walletId];\n if (wallet?.type !== AccountWalletType.Entropy) {\n backupAndSyncLogger(\n `Wallet ${walletId} not found or is not an entropy wallet`,\n );\n return [];\n }\n\n return Object.values(wallet.groups);\n}\n\n/**\n * State snapshot type for rollback operations.\n * Captures all the state that needs to be restored in case of sync failures.\n */\nexport type StateSnapshot = {\n accountGroupsMetadata: AccountTreeControllerState['accountGroupsMetadata'];\n accountWalletsMetadata: AccountTreeControllerState['accountWalletsMetadata'];\n selectedAccountGroup: AccountTreeControllerState['accountTree']['selectedAccountGroup'];\n accountTreeWallets: AccountTreeControllerState['accountTree']['wallets'];\n};\n\n/**\n * Creates a snapshot of the current controller state for rollback purposes.\n * Captures all state including the account tree structure.\n *\n * @param context - The backup and sync context containing controller and messenger.\n * @returns A deep copy of relevant state that can be restored later.\n */\nexport function createStateSnapshot(\n context: BackupAndSyncContext,\n): StateSnapshot {\n return {\n accountGroupsMetadata: JSON.parse(\n JSON.stringify(context.controller.state.accountGroupsMetadata),\n ),\n accountWalletsMetadata: JSON.parse(\n JSON.stringify(context.controller.state.accountWalletsMetadata),\n ),\n selectedAccountGroup:\n context.controller.state.accountTree.selectedAccountGroup,\n accountTreeWallets: JSON.parse(\n JSON.stringify(context.controller.state.accountTree.wallets),\n ),\n };\n}\n\n/**\n * Restores state using an update callback.\n * Restores both persisted metadata and the complete account tree structure.\n * Uses the controller's init() method to rebuild internal maps correctly.\n *\n * @param context - The backup and sync context containing controller and messenger.\n * @param snapshot - The state snapshot to restore.\n */\nexport function restoreStateFromSnapshot(\n context: BackupAndSyncContext,\n snapshot: StateSnapshot,\n): void {\n context.controllerStateUpdateFn((state) => {\n state.accountGroupsMetadata = snapshot.accountGroupsMetadata;\n state.accountWalletsMetadata = snapshot.accountWalletsMetadata;\n state.accountTree.selectedAccountGroup = snapshot.selectedAccountGroup;\n state.accountTree.wallets = snapshot.accountTreeWallets;\n });\n\n // Use init() to rebuild the internal maps from the restored account tree state\n // This ensures that the internal maps (#accountIdToContext and #groupIdToWalletId)\n // are correctly synchronized with the restored account tree structure\n context.controller.init();\n}\n"]}
|
|
@@ -20,7 +20,7 @@ export function getLocalEntropyWallets(context) {
|
|
|
20
20
|
export const getLocalGroupForEntropyWallet = (context, entropySourceId, groupIndex) => {
|
|
21
21
|
const walletId = toMultichainAccountWalletId(entropySourceId);
|
|
22
22
|
const wallet = context.controller.state.accountTree.wallets[walletId];
|
|
23
|
-
if (
|
|
23
|
+
if (wallet?.type !== AccountWalletType.Entropy) {
|
|
24
24
|
backupAndSyncLogger(`Wallet ${walletId} not found or is not an entropy wallet`);
|
|
25
25
|
return undefined;
|
|
26
26
|
}
|
|
@@ -36,7 +36,7 @@ export const getLocalGroupForEntropyWallet = (context, entropySourceId, groupInd
|
|
|
36
36
|
*/
|
|
37
37
|
export function getLocalGroupsForEntropyWallet(context, walletId) {
|
|
38
38
|
const wallet = context.controller.state.accountTree.wallets[walletId];
|
|
39
|
-
if (
|
|
39
|
+
if (wallet?.type !== AccountWalletType.Entropy) {
|
|
40
40
|
backupAndSyncLogger(`Wallet ${walletId} not found or is not an entropy wallet`);
|
|
41
41
|
return [];
|
|
42
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.mjs","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,2BAA2B,EAC5B,8BAA8B;AAI/B,OAAO,EAAE,mBAAmB,EAAE,yBAAqB;AAKnD;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAA6B;IAE7B,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CACvE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,iBAAiB,CAAC,OAAO,CACtB,CAAC;AACpC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,OAA6B,EAC7B,eAAuB,EACvB,UAAkB,EAC+B,EAAE;IACnD,MAAM,QAAQ,GAAG,2BAA2B,CAAC,eAAe,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEtE,IAAI,
|
|
1
|
+
{"version":3,"file":"controller.mjs","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,2BAA2B,EAC5B,8BAA8B;AAI/B,OAAO,EAAE,mBAAmB,EAAE,yBAAqB;AAKnD;;;;;GAKG;AACH,MAAM,UAAU,sBA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;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAA6B;IAE7B,OAAO;QACL,qBAAqB,EAAE,IAAI,CAAC,KAAK,CAC/B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAC/D;QACD,sBAAsB,EAAE,IAAI,CAAC,KAAK,CAChC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAChE;QACD,oBAAoB,EAClB,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,oBAAoB;QAC3D,kBAAkB,EAAE,IAAI,CAAC,KAAK,CAC5B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAC7D;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAA6B,EAC7B,QAAuB;IAEvB,OAAO,CAAC,uBAAuB,CAAC,CAAC,KAAK,EAAE,EAAE;QACxC,KAAK,CAAC,qBAAqB,GAAG,QAAQ,CAAC,qBAAqB,CAAC;QAC7D,KAAK,CAAC,sBAAsB,GAAG,QAAQ,CAAC,sBAAsB,CAAC;QAC/D,KAAK,CAAC,WAAW,CAAC,oBAAoB,GAAG,QAAQ,CAAC,oBAAoB,CAAC;QACvE,KAAK,CAAC,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC,kBAAkB,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,+EAA+E;IAC/E,mFAAmF;IACnF,sEAAsE;IACtE,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;AAC5B,CAAC","sourcesContent":["import {\n AccountWalletType,\n toMultichainAccountGroupId,\n toMultichainAccountWalletId,\n} from '@metamask/account-api';\nimport type { AccountWalletId } from '@metamask/account-api';\n\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport { backupAndSyncLogger } from '../../logger';\nimport type { AccountTreeControllerState } from '../../types';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type { BackupAndSyncContext } from '../types';\n\n/**\n * Gets all local entropy wallets that can be synced.\n *\n * @param context - The backup and sync context.\n * @returns Array of entropy wallet objects.\n */\nexport function getLocalEntropyWallets(\n context: BackupAndSyncContext,\n): AccountWalletEntropyObject[] {\n return Object.values(context.controller.state.accountTree.wallets).filter(\n (wallet) => wallet.type === AccountWalletType.Entropy,\n ) as AccountWalletEntropyObject[];\n}\n\n/**\n * Gets the local group for a specific entropy wallet by its source ID and group index.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @param groupIndex - The group index.\n * @returns The local group object if it exists, undefined otherwise.\n */\nexport const getLocalGroupForEntropyWallet = (\n context: BackupAndSyncContext,\n entropySourceId: string,\n groupIndex: number,\n): AccountGroupMultichainAccountObject | undefined => {\n const walletId = toMultichainAccountWalletId(entropySourceId);\n const wallet = context.controller.state.accountTree.wallets[walletId];\n\n if (wallet?.type !== AccountWalletType.Entropy) {\n backupAndSyncLogger(\n `Wallet ${walletId} not found or is not an entropy wallet`,\n );\n return undefined;\n }\n\n const groupId = toMultichainAccountGroupId(walletId, groupIndex);\n\n return wallet.groups[groupId];\n};\n\n/**\n * Gets all groups for a specific entropy wallet.\n *\n * @param context - The backup and sync context.\n * @param walletId - The wallet ID to get groups for.\n * @returns Array of multichain account group objects.\n */\nexport function getLocalGroupsForEntropyWallet(\n context: BackupAndSyncContext,\n walletId: AccountWalletId,\n): AccountGroupMultichainAccountObject[] {\n const wallet = context.controller.state.accountTree.wallets[walletId];\n if (wallet?.type !== AccountWalletType.Entropy) {\n backupAndSyncLogger(\n `Wallet ${walletId} not found or is not an entropy wallet`,\n );\n return [];\n }\n\n return Object.values(wallet.groups);\n}\n\n/**\n * State snapshot type for rollback operations.\n * Captures all the state that needs to be restored in case of sync failures.\n */\nexport type StateSnapshot = {\n accountGroupsMetadata: AccountTreeControllerState['accountGroupsMetadata'];\n accountWalletsMetadata: AccountTreeControllerState['accountWalletsMetadata'];\n selectedAccountGroup: AccountTreeControllerState['accountTree']['selectedAccountGroup'];\n accountTreeWallets: AccountTreeControllerState['accountTree']['wallets'];\n};\n\n/**\n * Creates a snapshot of the current controller state for rollback purposes.\n * Captures all state including the account tree structure.\n *\n * @param context - The backup and sync context containing controller and messenger.\n * @returns A deep copy of relevant state that can be restored later.\n */\nexport function createStateSnapshot(\n context: BackupAndSyncContext,\n): StateSnapshot {\n return {\n accountGroupsMetadata: JSON.parse(\n JSON.stringify(context.controller.state.accountGroupsMetadata),\n ),\n accountWalletsMetadata: JSON.parse(\n JSON.stringify(context.controller.state.accountWalletsMetadata),\n ),\n selectedAccountGroup:\n context.controller.state.accountTree.selectedAccountGroup,\n accountTreeWallets: JSON.parse(\n JSON.stringify(context.controller.state.accountTree.wallets),\n ),\n };\n}\n\n/**\n * Restores state using an update callback.\n * Restores both persisted metadata and the complete account tree structure.\n * Uses the controller's init() method to rebuild internal maps correctly.\n *\n * @param context - The backup and sync context containing controller and messenger.\n * @param snapshot - The state snapshot to restore.\n */\nexport function restoreStateFromSnapshot(\n context: BackupAndSyncContext,\n snapshot: StateSnapshot,\n): void {\n context.controllerStateUpdateFn((state) => {\n state.accountGroupsMetadata = snapshot.accountGroupsMetadata;\n state.accountWalletsMetadata = snapshot.accountWalletsMetadata;\n state.accountTree.selectedAccountGroup = snapshot.selectedAccountGroup;\n state.accountTree.wallets = snapshot.accountTreeWallets;\n });\n\n // Use init() to rebuild the internal maps from the restored account tree state\n // This ensures that the internal maps (#accountIdToContext and #groupIdToWalletId)\n // are correctly synchronized with the restored account tree structure\n context.controller.init();\n}\n"]}
|
package/package.json
CHANGED