@metamask-previews/account-tree-controller 7.6.1-preview-4e64b66e8 → 7.6.1-preview-ea8763e0c

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +0 -13
  2. package/dist/AccountTreeController-method-action-types.cjs.map +1 -1
  3. package/dist/AccountTreeController-method-action-types.d.cts +1 -34
  4. package/dist/AccountTreeController-method-action-types.d.cts.map +1 -1
  5. package/dist/AccountTreeController-method-action-types.d.mts +1 -34
  6. package/dist/AccountTreeController-method-action-types.d.mts.map +1 -1
  7. package/dist/AccountTreeController-method-action-types.mjs.map +1 -1
  8. package/dist/AccountTreeController.cjs +1 -53
  9. package/dist/AccountTreeController.cjs.map +1 -1
  10. package/dist/AccountTreeController.d.cts +0 -29
  11. package/dist/AccountTreeController.d.cts.map +1 -1
  12. package/dist/AccountTreeController.d.mts +0 -29
  13. package/dist/AccountTreeController.d.mts.map +1 -1
  14. package/dist/AccountTreeController.mjs +1 -53
  15. package/dist/AccountTreeController.mjs.map +1 -1
  16. package/dist/index.cjs +1 -10
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +2 -6
  19. package/dist/index.d.cts.map +1 -1
  20. package/dist/index.d.mts +2 -6
  21. package/dist/index.d.mts.map +1 -1
  22. package/dist/index.mjs +0 -3
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/state/payload.cjs.map +1 -1
  25. package/dist/state/payload.d.cts +1 -1
  26. package/dist/state/payload.d.cts.map +1 -1
  27. package/dist/state/payload.d.mts +1 -1
  28. package/dist/state/payload.d.mts.map +1 -1
  29. package/dist/state/payload.mjs.map +1 -1
  30. package/dist/types.cjs.map +1 -1
  31. package/dist/types.d.cts +4 -23
  32. package/dist/types.d.cts.map +1 -1
  33. package/dist/types.d.mts +4 -23
  34. package/dist/types.d.mts.map +1 -1
  35. package/dist/types.mjs.map +1 -1
  36. package/package.json +1 -2
  37. package/dist/state/export.cjs +0 -221
  38. package/dist/state/export.cjs.map +0 -1
  39. package/dist/state/export.d.cts +0 -40
  40. package/dist/state/export.d.cts.map +0 -1
  41. package/dist/state/export.d.mts +0 -40
  42. package/dist/state/export.d.mts.map +0 -1
  43. package/dist/state/export.mjs +0 -215
  44. package/dist/state/export.mjs.map +0 -1
  45. package/dist/state/import.cjs +0 -285
  46. package/dist/state/import.cjs.map +0 -1
  47. package/dist/state/import.d.cts +0 -29
  48. package/dist/state/import.d.cts.map +0 -1
  49. package/dist/state/import.d.mts +0 -29
  50. package/dist/state/import.d.mts.map +0 -1
  51. package/dist/state/import.mjs +0 -281
  52. package/dist/state/import.mjs.map +0 -1
@@ -1,281 +0,0 @@
1
- import { AccountWalletType, toAccountGroupId, toAccountWalletId, toMultichainAccountGroupId } from "@metamask/account-api";
2
- import { getUUIDFromAddressOfNormalAccount } from "@metamask/accounts-controller";
3
- import { HdKeyring } from "@metamask/eth-hd-keyring/v2";
4
- import { EthAccountType } from "@metamask/keyring-api";
5
- import { KeyringTypes } from "@metamask/keyring-controller";
6
- import { isMnemonicWalletObject } from "./export.mjs";
7
- import { AccountWalletPayloadType, parsePayloadGroupId, toWalletPayloadId } from "./payload.mjs";
8
- import { decodeBytes } from "./utils.mjs";
9
- /**
10
- * Searches the local wallet tree for an entropy wallet whose stable payload ID
11
- * matches `payloadWalletId`. The entropy source ID is derived on-the-fly via
12
- * `KeyringController:withKeyringV2Unsafe` rather than relying on cached metadata.
13
- *
14
- * @param context - Import context.
15
- * @param payloadWalletId - Payload wallet ID to match against.
16
- * @returns The matching local entropy wallet, or `undefined` if not found.
17
- */
18
- async function findLocalWalletMnemonicFromPayloadId(context, payloadWalletId) {
19
- const wallets = Object.values(context.getState().accountTree.wallets);
20
- for (const wallet of wallets) {
21
- if (isMnemonicWalletObject(wallet)) {
22
- const result = await context.messenger.call('KeyringController:withKeyringV2Unsafe', { id: wallet.metadata.entropy.id }, async ({ keyring }) => {
23
- const hdKeyring = keyring;
24
- return toWalletPayloadId(await hdKeyring.toEntropySourceId());
25
- });
26
- const localPayloadId = result;
27
- if (localPayloadId === payloadWalletId) {
28
- return wallet;
29
- }
30
- }
31
- }
32
- return undefined;
33
- }
34
- /**
35
- * Returns the local entropy wallet for the given ID.
36
- *
37
- * @param context - Import context.
38
- * @param id - Local wallet ID.
39
- * @returns The entropy wallet object.
40
- * @throws If the wallet is not found or is not an entropy wallet.
41
- */
42
- function findLocalWalletMnemonicFromId(context, id) {
43
- const localWallets = context.getState().accountTree.wallets;
44
- const localWallet = localWallets[id];
45
- if (!localWallet) {
46
- throw new Error(`Failed to import mnemonic wallet: wallet not found after creation`);
47
- }
48
- if (!isMnemonicWalletObject(localWallet)) {
49
- throw new Error(`Failed to import mnemonic wallet: wallet is not of type 'mnemonic'`);
50
- }
51
- return localWallet;
52
- }
53
- /**
54
- * Returns the local simple-keyring wallet, or `undefined` if none exists yet.
55
- *
56
- * The private-key wallet ID is static (derived solely from {@link KeyringTypes.simple}),
57
- * so no runtime argument is needed to locate it.
58
- *
59
- * @param context - Import context.
60
- * @returns The keyring wallet object, or `undefined` if not present in state.
61
- */
62
- function findLocalWalletPrivateKey(context) {
63
- const localWalletId = toAccountWalletId(AccountWalletType.Keyring, KeyringTypes.simple);
64
- const localWallet = context.getState().accountTree.wallets[localWalletId];
65
- return localWallet?.type === AccountWalletType.Keyring
66
- ? localWallet
67
- : undefined;
68
- }
69
- /**
70
- * Returns `true` if the given payload group is already present in the local simple-keyring wallet.
71
- *
72
- * @param localWallet - The local simple-keyring wallet, or `undefined` if none exists yet.
73
- * @param group - The payload group entry to check.
74
- * @returns Whether the group's account is already tracked locally.
75
- */
76
- function hasLocalGroupPrivateKey(localWallet, group) {
77
- const address = parsePayloadGroupId(group.id).subId;
78
- const localWalletId = toAccountWalletId(AccountWalletType.Keyring, KeyringTypes.simple);
79
- const localGroupId = toAccountGroupId(localWalletId, address);
80
- const localGroup = localWallet?.groups[localGroupId];
81
- const accountId = getUUIDFromAddressOfNormalAccount(address);
82
- return localGroup?.accounts.some((id) => id === accountId) ?? false;
83
- }
84
- /**
85
- * Applies name, pinned, and hidden metadata from a payload group entry to a local group.
86
- *
87
- * @param context - Import context providing the metadata setters.
88
- * @param localGroupId - Local group ID to update.
89
- * @param payloadGroupMetadata - Metadata from the payload group entry.
90
- */
91
- function setGroupMetadata(context, localGroupId, payloadGroupMetadata) {
92
- context.setAccountGroupName(localGroupId, payloadGroupMetadata.name);
93
- context.setAccountGroupPinned(localGroupId, payloadGroupMetadata.pinned);
94
- context.setAccountGroupHidden(localGroupId, payloadGroupMetadata.hidden);
95
- }
96
- /**
97
- * Computes the contiguous ranges of group indices that are present in the payload
98
- * but absent from the local wallet, so they can be created in batches.
99
- *
100
- * @param localWallet - The local entropy wallet to check existing groups against.
101
- * @param payloadGroups - Ordered group entries from the payload.
102
- * @returns An array of `[fromGroupIndex, toGroupIndex]` ranges to create.
103
- */
104
- function getRangesFromPayloadGroups(localWallet, payloadGroups) {
105
- let rangeIndex;
106
- const ranges = [];
107
- // Keep track of the last payload group so we can close the final range if needed.
108
- let lastPayloadGroup;
109
- for (const payloadGroup of payloadGroups) {
110
- const localGroupId = toMultichainAccountGroupId(localWallet.id, payloadGroup.groupIndex);
111
- if (localWallet.groups[localGroupId]) {
112
- if (rangeIndex !== undefined) {
113
- ranges.push([rangeIndex, payloadGroup.groupIndex - 1]);
114
- rangeIndex = undefined;
115
- }
116
- continue;
117
- }
118
- rangeIndex ?? (rangeIndex = payloadGroup.groupIndex);
119
- lastPayloadGroup = payloadGroup;
120
- }
121
- if (rangeIndex !== undefined && lastPayloadGroup !== undefined) {
122
- ranges.push([rangeIndex, lastPayloadGroup.groupIndex]);
123
- }
124
- return ranges;
125
- }
126
- /**
127
- * Applies a mnemonic wallet payload entry to the local state.
128
- *
129
- * If no local wallet with the same entropy source ID exists and a mnemonic is
130
- * present in the payload, a new HD wallet is created via
131
- * `MultichainAccountService:createMultichainAccountWallet`. Missing groups are
132
- * created in batches via `MultichainAccountService:createMultichainAccountGroups`.
133
- * Metadata (name, pinned, hidden) is applied to all groups afterward.
134
- *
135
- * @param context - Import context.
136
- * @param payloadWallet - The mnemonic wallet entry from the payload.
137
- */
138
- async function importMnemonicWallet(context, payloadWallet) {
139
- // Find the local wallet with the same entropy source ID if it exists.
140
- let localWallet = await findLocalWalletMnemonicFromPayloadId(context, payloadWallet.id);
141
- if (!localWallet) {
142
- if (!payloadWallet.value) {
143
- // No mnemonic in payload and wallet doesn't exist locally -- nothing to do.
144
- return;
145
- }
146
- // Import the mnemonic as a new HD wallet.
147
- const mnemonic = decodeBytes(payloadWallet.value);
148
- const { id } = await context.messenger.call('MultichainAccountService:createMultichainAccountWallet', { type: 'import', mnemonic });
149
- // Event handlers fire synchronously, so the wallet is in the tree now.
150
- localWallet = findLocalWalletMnemonicFromId(context, id);
151
- }
152
- context.setWalletName(localWallet.id, payloadWallet.metadata.name);
153
- // Apply metadata to groups that are already present locally before attempting
154
- // to create missing ones. If createMultichainAccountGroups throws partway
155
- // through, these groups would otherwise be left without their payload metadata.
156
- const localExistingGroupIds = new Set(Object.keys(localWallet.groups));
157
- for (const payloadGroup of payloadWallet.groups) {
158
- const localGroupId = toMultichainAccountGroupId(localWallet.id, payloadGroup.groupIndex);
159
- if (localExistingGroupIds.has(localGroupId)) {
160
- setGroupMetadata(context, localGroupId, payloadGroup.metadata);
161
- }
162
- }
163
- for (const range of getRangesFromPayloadGroups(localWallet, payloadWallet.groups)) {
164
- await context.messenger.call('MultichainAccountService:createMultichainAccountGroups', {
165
- entropySource: localWallet.metadata.entropy.id,
166
- fromGroupIndex: range[0],
167
- toGroupIndex: range[1],
168
- });
169
- }
170
- // Re-read wallet after groups creation.
171
- localWallet = findLocalWalletMnemonicFromId(context, localWallet.id);
172
- // Apply metadata to newly created groups. Skip groups that were already
173
- // handled above, and guard against groups that failed to be created so a
174
- // partial failure doesn't throw and abort the rest of the snapshot import.
175
- for (const payloadGroup of payloadWallet.groups) {
176
- const localGroupId = toMultichainAccountGroupId(localWallet.id, payloadGroup.groupIndex);
177
- if (localExistingGroupIds.has(localGroupId) ||
178
- !localWallet.groups[localGroupId]) {
179
- continue;
180
- }
181
- setGroupMetadata(context, localGroupId, payloadGroup.metadata);
182
- }
183
- }
184
- /**
185
- * Applies private-key wallet group entries from the payload to the local state.
186
- *
187
- * For each group the account address is derived from the payload group ID. If the
188
- * account does not yet exist locally and a private key is provided, it is imported
189
- * via `KeyringController:withKeyringV2` using the `'private-key:import'` constructor.
190
- * Metadata (name, pinned, hidden) is then applied to the local group.
191
- *
192
- * @param context - Import context.
193
- * @param payloadGroups - Private-key group entries from the payload.
194
- */
195
- async function importPrivateKeyWallet(context, payloadGroups) {
196
- const localWalletId = toAccountWalletId(AccountWalletType.Keyring, KeyringTypes.simple);
197
- // Only EVM EOA accounts are supported for now. Non-EVM private keys require
198
- // Snap-based import routing (ADR-0007), which is not yet implemented. Skip the
199
- // entire entry so payloads from future clients are accepted without crashing.
200
- // In the same pass, collect groups whose key is not yet present locally.
201
- const localWallet = findLocalWalletPrivateKey(context);
202
- const supportedGroups = [];
203
- const missingGroups = [];
204
- for (const group of payloadGroups) {
205
- const type = group.value?.type;
206
- if (type !== undefined && type !== EthAccountType.Eoa) {
207
- continue;
208
- }
209
- supportedGroups.push(group);
210
- if (!hasLocalGroupPrivateKey(localWallet, group) &&
211
- group.value !== undefined) {
212
- missingGroups.push(group);
213
- }
214
- }
215
- // Import all missing keys in a single :withController call to avoid
216
- // triggering multiple `KeyringController:stateChanged` events.
217
- if (missingGroups.length > 0) {
218
- await context.messenger.call('KeyringController:withController', async (controller) => {
219
- // Find the existing simple keyring or create one if this is the
220
- // first private-key import (e.g. during onboarding).
221
- const existing = controller.keyrings.find(({ keyring }) => keyring.type === KeyringTypes.simple);
222
- const { keyringV2 } = existing ?? (await controller.addNewKeyring(KeyringTypes.simple));
223
- if (!keyringV2) {
224
- throw new Error('Simple keyring has no v2 interface');
225
- }
226
- for (const group of missingGroups) {
227
- // Safe to assert `group.value` is present because we filtered out groups
228
- // without a `value` above.
229
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
230
- const { privateKey: privateKeyBytes, encoding } = group.value;
231
- const privateKey = new TextDecoder().decode(decodeBytes(privateKeyBytes));
232
- const [account] = await keyringV2.createAccounts({
233
- type: 'private-key:import',
234
- accountType: EthAccountType.Eoa,
235
- privateKey,
236
- encoding,
237
- });
238
- if (!account) {
239
- throw new Error('Failed to import private key for account');
240
- }
241
- }
242
- });
243
- }
244
- // Re-read state once after all imports, then apply metadata to every group
245
- // that now exists locally.
246
- for (const group of supportedGroups) {
247
- const address = parsePayloadGroupId(group.id).subId;
248
- const localGroupId = toAccountGroupId(localWalletId, address);
249
- const localGroup = findLocalWalletPrivateKey(context)?.groups[localGroupId];
250
- if (!localGroup) {
251
- continue;
252
- }
253
- setGroupMetadata(context, localGroup.id, group.metadata);
254
- }
255
- }
256
- /**
257
- * Applies an {@link AccountTreeSnapshot} to the current controller state.
258
- *
259
- * The snapshot must already have been validated — typically via
260
- * {@link AccountTreeSnapshot.deserialize}. For each retained wallet:
261
- *
262
- * - `'mnemonic'`: imports the mnemonic when provided and not already present,
263
- * then applies metadata to all groups.
264
- * - `'private-key'`: imports each retained group's key when provided and not
265
- * already present, then applies metadata.
266
- *
267
- * @param context - Import context providing state, messenger, and setters.
268
- * @param snapshot - The validated snapshot to import.
269
- */
270
- export async function importState(context, snapshot) {
271
- const payload = snapshot.serialize();
272
- for (const wallet of payload.wallets) {
273
- if (wallet.type === AccountWalletPayloadType.Mnemonic) {
274
- await importMnemonicWallet(context, wallet);
275
- }
276
- else {
277
- await importPrivateKeyWallet(context, wallet.groups);
278
- }
279
- }
280
- }
281
- //# sourceMappingURL=import.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"import.mjs","sourceRoot":"","sources":["../../src/state/import.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,0BAA0B,EAC3B,8BAA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CAAC;AACH,CAAC","sourcesContent":["import {\n AccountWalletType,\n toAccountGroupId,\n toAccountWalletId,\n toMultichainAccountGroupId,\n} from '@metamask/account-api';\nimport type { AccountGroupId, AccountWalletId } from '@metamask/account-api';\nimport { getUUIDFromAddressOfNormalAccount } from '@metamask/accounts-controller';\nimport { HdKeyring } from '@metamask/eth-hd-keyring/v2';\nimport { EthAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\n\nimport type {\n AccountTreeControllerMessenger,\n AccountTreeControllerState,\n} from '../types.js';\nimport type {\n AccountWalletEntropyObject,\n AccountWalletKeyringObject,\n} from '../wallet.js';\nimport { isMnemonicWalletObject } from './export.js';\nimport type {\n AccountWalletMnemonicGroupEntry,\n AccountWalletMnemonicPayload,\n AccountWalletPayloadId,\n AccountWalletPrivateKeyGroupEntry,\n} from './payload.js';\nimport {\n AccountWalletPayloadType,\n parsePayloadGroupId,\n toWalletPayloadId,\n} from './payload.js';\nimport type { AccountTreeSnapshot } from './snapshot.js';\nimport { decodeBytes } from './utils.js';\n\n/** Context required by {@link importState}. */\nexport type ImportContext = {\n getState: () => AccountTreeControllerState;\n messenger: AccountTreeControllerMessenger;\n setWalletName: (walletId: AccountWalletId, name: string) => void;\n /** Sets a group name. Implementations must resolve name conflicts automatically. */\n setAccountGroupName: (groupId: AccountGroupId, name: string) => void;\n setAccountGroupPinned: (groupId: AccountGroupId, pinned: boolean) => void;\n setAccountGroupHidden: (groupId: AccountGroupId, hidden: boolean) => void;\n};\n\n/**\n * Searches the local wallet tree for an entropy wallet whose stable payload ID\n * matches `payloadWalletId`. The entropy source ID is derived on-the-fly via\n * `KeyringController:withKeyringV2Unsafe` rather than relying on cached metadata.\n *\n * @param context - Import context.\n * @param payloadWalletId - Payload wallet ID to match against.\n * @returns The matching local entropy wallet, or `undefined` if not found.\n */\nasync function findLocalWalletMnemonicFromPayloadId(\n context: ImportContext,\n payloadWalletId: AccountWalletPayloadId,\n): Promise<AccountWalletEntropyObject | undefined> {\n const wallets = Object.values(context.getState().accountTree.wallets);\n\n for (const wallet of wallets) {\n if (isMnemonicWalletObject(wallet)) {\n const result = await context.messenger.call(\n 'KeyringController:withKeyringV2Unsafe',\n { id: wallet.metadata.entropy.id },\n async ({ keyring }) => {\n const hdKeyring = keyring as HdKeyring;\n\n return toWalletPayloadId(await hdKeyring.toEntropySourceId());\n },\n );\n\n const localPayloadId = result as AccountWalletPayloadId;\n if (localPayloadId === payloadWalletId) {\n return wallet;\n }\n }\n }\n\n return undefined;\n}\n\n/**\n * Returns the local entropy wallet for the given ID.\n *\n * @param context - Import context.\n * @param id - Local wallet ID.\n * @returns The entropy wallet object.\n * @throws If the wallet is not found or is not an entropy wallet.\n */\nfunction findLocalWalletMnemonicFromId(\n context: ImportContext,\n id: AccountWalletId,\n): AccountWalletEntropyObject {\n const localWallets = context.getState().accountTree.wallets;\n const localWallet = localWallets[id];\n\n if (!localWallet) {\n throw new Error(\n `Failed to import mnemonic wallet: wallet not found after creation`,\n );\n }\n if (!isMnemonicWalletObject(localWallet)) {\n throw new Error(\n `Failed to import mnemonic wallet: wallet is not of type 'mnemonic'`,\n );\n }\n return localWallet;\n}\n\n/**\n * Returns the local simple-keyring wallet, or `undefined` if none exists yet.\n *\n * The private-key wallet ID is static (derived solely from {@link KeyringTypes.simple}),\n * so no runtime argument is needed to locate it.\n *\n * @param context - Import context.\n * @returns The keyring wallet object, or `undefined` if not present in state.\n */\nfunction findLocalWalletPrivateKey(\n context: ImportContext,\n): AccountWalletKeyringObject | undefined {\n const localWalletId = toAccountWalletId(\n AccountWalletType.Keyring,\n KeyringTypes.simple,\n );\n const localWallet = context.getState().accountTree.wallets[localWalletId];\n return localWallet?.type === AccountWalletType.Keyring\n ? localWallet\n : undefined;\n}\n\n/**\n * Returns `true` if the given payload group is already present in the local simple-keyring wallet.\n *\n * @param localWallet - The local simple-keyring wallet, or `undefined` if none exists yet.\n * @param group - The payload group entry to check.\n * @returns Whether the group's account is already tracked locally.\n */\nfunction hasLocalGroupPrivateKey(\n localWallet: AccountWalletKeyringObject | undefined,\n group: AccountWalletPrivateKeyGroupEntry,\n): boolean {\n const address = parsePayloadGroupId(group.id).subId;\n\n const localWalletId = toAccountWalletId(\n AccountWalletType.Keyring,\n KeyringTypes.simple,\n );\n const localGroupId = toAccountGroupId(localWalletId, address);\n const localGroup = localWallet?.groups[localGroupId];\n\n const accountId = getUUIDFromAddressOfNormalAccount(address);\n\n return localGroup?.accounts.some((id) => id === accountId) ?? false;\n}\n\n/**\n * Applies name, pinned, and hidden metadata from a payload group entry to a local group.\n *\n * @param context - Import context providing the metadata setters.\n * @param localGroupId - Local group ID to update.\n * @param payloadGroupMetadata - Metadata from the payload group entry.\n */\nfunction setGroupMetadata(\n context: ImportContext,\n localGroupId: AccountGroupId,\n payloadGroupMetadata: AccountWalletMnemonicGroupEntry['metadata'],\n): void {\n context.setAccountGroupName(localGroupId, payloadGroupMetadata.name);\n context.setAccountGroupPinned(localGroupId, payloadGroupMetadata.pinned);\n context.setAccountGroupHidden(localGroupId, payloadGroupMetadata.hidden);\n}\n\n/**\n * Computes the contiguous ranges of group indices that are present in the payload\n * but absent from the local wallet, so they can be created in batches.\n *\n * @param localWallet - The local entropy wallet to check existing groups against.\n * @param payloadGroups - Ordered group entries from the payload.\n * @returns An array of `[fromGroupIndex, toGroupIndex]` ranges to create.\n */\nfunction getRangesFromPayloadGroups(\n localWallet: AccountWalletEntropyObject,\n payloadGroups: AccountWalletMnemonicGroupEntry[],\n): [number, number][] {\n let rangeIndex: number | undefined;\n const ranges: [number, number][] = [];\n\n // Keep track of the last payload group so we can close the final range if needed.\n let lastPayloadGroup: AccountWalletMnemonicGroupEntry | undefined;\n for (const payloadGroup of payloadGroups) {\n const localGroupId = toMultichainAccountGroupId(\n localWallet.id,\n payloadGroup.groupIndex,\n );\n\n if (localWallet.groups[localGroupId]) {\n if (rangeIndex !== undefined) {\n ranges.push([rangeIndex, payloadGroup.groupIndex - 1]);\n rangeIndex = undefined;\n }\n continue;\n }\n\n rangeIndex ??= payloadGroup.groupIndex;\n lastPayloadGroup = payloadGroup;\n }\n\n if (rangeIndex !== undefined && lastPayloadGroup !== undefined) {\n ranges.push([rangeIndex, lastPayloadGroup.groupIndex]);\n }\n\n return ranges;\n}\n\n/**\n * Applies a mnemonic wallet payload entry to the local state.\n *\n * If no local wallet with the same entropy source ID exists and a mnemonic is\n * present in the payload, a new HD wallet is created via\n * `MultichainAccountService:createMultichainAccountWallet`. Missing groups are\n * created in batches via `MultichainAccountService:createMultichainAccountGroups`.\n * Metadata (name, pinned, hidden) is applied to all groups afterward.\n *\n * @param context - Import context.\n * @param payloadWallet - The mnemonic wallet entry from the payload.\n */\nasync function importMnemonicWallet(\n context: ImportContext,\n payloadWallet: AccountWalletMnemonicPayload,\n): Promise<void> {\n // Find the local wallet with the same entropy source ID if it exists.\n let localWallet = await findLocalWalletMnemonicFromPayloadId(\n context,\n payloadWallet.id,\n );\n\n if (!localWallet) {\n if (!payloadWallet.value) {\n // No mnemonic in payload and wallet doesn't exist locally -- nothing to do.\n return;\n }\n\n // Import the mnemonic as a new HD wallet.\n const mnemonic = decodeBytes(payloadWallet.value);\n const { id } = await context.messenger.call(\n 'MultichainAccountService:createMultichainAccountWallet',\n { type: 'import', mnemonic },\n );\n\n // Event handlers fire synchronously, so the wallet is in the tree now.\n localWallet = findLocalWalletMnemonicFromId(context, id);\n }\n\n context.setWalletName(localWallet.id, payloadWallet.metadata.name);\n\n // Apply metadata to groups that are already present locally before attempting\n // to create missing ones. If createMultichainAccountGroups throws partway\n // through, these groups would otherwise be left without their payload metadata.\n const localExistingGroupIds = new Set(Object.keys(localWallet.groups));\n for (const payloadGroup of payloadWallet.groups) {\n const localGroupId = toMultichainAccountGroupId(\n localWallet.id,\n payloadGroup.groupIndex,\n );\n if (localExistingGroupIds.has(localGroupId)) {\n setGroupMetadata(context, localGroupId, payloadGroup.metadata);\n }\n }\n\n for (const range of getRangesFromPayloadGroups(\n localWallet,\n payloadWallet.groups,\n )) {\n await context.messenger.call(\n 'MultichainAccountService:createMultichainAccountGroups',\n {\n entropySource: localWallet.metadata.entropy.id,\n fromGroupIndex: range[0],\n toGroupIndex: range[1],\n },\n );\n }\n\n // Re-read wallet after groups creation.\n localWallet = findLocalWalletMnemonicFromId(context, localWallet.id);\n\n // Apply metadata to newly created groups. Skip groups that were already\n // handled above, and guard against groups that failed to be created so a\n // partial failure doesn't throw and abort the rest of the snapshot import.\n for (const payloadGroup of payloadWallet.groups) {\n const localGroupId = toMultichainAccountGroupId(\n localWallet.id,\n payloadGroup.groupIndex,\n );\n if (\n localExistingGroupIds.has(localGroupId) ||\n !localWallet.groups[localGroupId]\n ) {\n continue;\n }\n setGroupMetadata(context, localGroupId, payloadGroup.metadata);\n }\n}\n\n/**\n * Applies private-key wallet group entries from the payload to the local state.\n *\n * For each group the account address is derived from the payload group ID. If the\n * account does not yet exist locally and a private key is provided, it is imported\n * via `KeyringController:withKeyringV2` using the `'private-key:import'` constructor.\n * Metadata (name, pinned, hidden) is then applied to the local group.\n *\n * @param context - Import context.\n * @param payloadGroups - Private-key group entries from the payload.\n */\nasync function importPrivateKeyWallet(\n context: ImportContext,\n payloadGroups: AccountWalletPrivateKeyGroupEntry[],\n): Promise<void> {\n const localWalletId = toAccountWalletId(\n AccountWalletType.Keyring,\n KeyringTypes.simple,\n );\n\n // Only EVM EOA accounts are supported for now. Non-EVM private keys require\n // Snap-based import routing (ADR-0007), which is not yet implemented. Skip the\n // entire entry so payloads from future clients are accepted without crashing.\n // In the same pass, collect groups whose key is not yet present locally.\n const localWallet = findLocalWalletPrivateKey(context);\n const supportedGroups: AccountWalletPrivateKeyGroupEntry[] = [];\n const missingGroups: AccountWalletPrivateKeyGroupEntry[] = [];\n\n for (const group of payloadGroups) {\n const type = group.value?.type;\n if (type !== undefined && type !== EthAccountType.Eoa) {\n continue;\n }\n\n supportedGroups.push(group);\n\n if (\n !hasLocalGroupPrivateKey(localWallet, group) &&\n group.value !== undefined\n ) {\n missingGroups.push(group);\n }\n }\n\n // Import all missing keys in a single :withController call to avoid\n // triggering multiple `KeyringController:stateChanged` events.\n if (missingGroups.length > 0) {\n await context.messenger.call(\n 'KeyringController:withController',\n async (controller) => {\n // Find the existing simple keyring or create one if this is the\n // first private-key import (e.g. during onboarding).\n const existing = controller.keyrings.find(\n ({ keyring }) => keyring.type === KeyringTypes.simple,\n );\n const { keyringV2 } =\n existing ?? (await controller.addNewKeyring(KeyringTypes.simple));\n\n if (!keyringV2) {\n throw new Error('Simple keyring has no v2 interface');\n }\n\n for (const group of missingGroups) {\n // Safe to assert `group.value` is present because we filtered out groups\n // without a `value` above.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { privateKey: privateKeyBytes, encoding } = group.value!;\n const privateKey = new TextDecoder().decode(\n decodeBytes(privateKeyBytes),\n );\n const [account] = await keyringV2.createAccounts({\n type: 'private-key:import',\n accountType: EthAccountType.Eoa,\n privateKey,\n encoding,\n });\n\n if (!account) {\n throw new Error('Failed to import private key for account');\n }\n }\n },\n );\n }\n\n // Re-read state once after all imports, then apply metadata to every group\n // that now exists locally.\n for (const group of supportedGroups) {\n const address = parsePayloadGroupId(group.id).subId;\n const localGroupId = toAccountGroupId(localWalletId, address);\n const localGroup = findLocalWalletPrivateKey(context)?.groups[localGroupId];\n if (!localGroup) {\n continue;\n }\n setGroupMetadata(context, localGroup.id, group.metadata);\n }\n}\n\n/**\n * Applies an {@link AccountTreeSnapshot} to the current controller state.\n *\n * The snapshot must already have been validated — typically via\n * {@link AccountTreeSnapshot.deserialize}. For each retained wallet:\n *\n * - `'mnemonic'`: imports the mnemonic when provided and not already present,\n * then applies metadata to all groups.\n * - `'private-key'`: imports each retained group's key when provided and not\n * already present, then applies metadata.\n *\n * @param context - Import context providing state, messenger, and setters.\n * @param snapshot - The validated snapshot to import.\n */\nexport async function importState(\n context: ImportContext,\n snapshot: AccountTreeSnapshot,\n): Promise<void> {\n const payload = snapshot.serialize();\n\n for (const wallet of payload.wallets) {\n if (wallet.type === AccountWalletPayloadType.Mnemonic) {\n await importMnemonicWallet(context, wallet);\n } else {\n await importPrivateKeyWallet(context, wallet.groups);\n }\n }\n}\n"]}