@metamask-previews/multichain-account-service 5.0.0-preview-cb897e9 → 5.0.0-preview-6a568504

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 (96) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/MultichainAccountGroup.cjs +84 -45
  3. package/dist/MultichainAccountGroup.cjs.map +1 -1
  4. package/dist/MultichainAccountGroup.d.cts +17 -4
  5. package/dist/MultichainAccountGroup.d.cts.map +1 -1
  6. package/dist/MultichainAccountGroup.d.mts +17 -4
  7. package/dist/MultichainAccountGroup.d.mts.map +1 -1
  8. package/dist/MultichainAccountGroup.mjs +84 -45
  9. package/dist/MultichainAccountGroup.mjs.map +1 -1
  10. package/dist/MultichainAccountService.cjs +144 -113
  11. package/dist/MultichainAccountService.cjs.map +1 -1
  12. package/dist/MultichainAccountService.d.cts +48 -20
  13. package/dist/MultichainAccountService.d.cts.map +1 -1
  14. package/dist/MultichainAccountService.d.mts +48 -20
  15. package/dist/MultichainAccountService.d.mts.map +1 -1
  16. package/dist/MultichainAccountService.mjs +145 -114
  17. package/dist/MultichainAccountService.mjs.map +1 -1
  18. package/dist/MultichainAccountWallet.cjs +108 -123
  19. package/dist/MultichainAccountWallet.cjs.map +1 -1
  20. package/dist/MultichainAccountWallet.d.cts +5 -4
  21. package/dist/MultichainAccountWallet.d.cts.map +1 -1
  22. package/dist/MultichainAccountWallet.d.mts +5 -4
  23. package/dist/MultichainAccountWallet.d.mts.map +1 -1
  24. package/dist/MultichainAccountWallet.mjs +108 -123
  25. package/dist/MultichainAccountWallet.mjs.map +1 -1
  26. package/dist/providers/AccountProviderWrapper.cjs +18 -0
  27. package/dist/providers/AccountProviderWrapper.cjs.map +1 -1
  28. package/dist/providers/AccountProviderWrapper.d.cts +12 -0
  29. package/dist/providers/AccountProviderWrapper.d.cts.map +1 -1
  30. package/dist/providers/AccountProviderWrapper.d.mts +12 -0
  31. package/dist/providers/AccountProviderWrapper.d.mts.map +1 -1
  32. package/dist/providers/AccountProviderWrapper.mjs +18 -0
  33. package/dist/providers/AccountProviderWrapper.mjs.map +1 -1
  34. package/dist/providers/BaseBip44AccountProvider.cjs +45 -20
  35. package/dist/providers/BaseBip44AccountProvider.cjs.map +1 -1
  36. package/dist/providers/BaseBip44AccountProvider.d.cts +58 -6
  37. package/dist/providers/BaseBip44AccountProvider.d.cts.map +1 -1
  38. package/dist/providers/BaseBip44AccountProvider.d.mts +58 -6
  39. package/dist/providers/BaseBip44AccountProvider.d.mts.map +1 -1
  40. package/dist/providers/BaseBip44AccountProvider.mjs +45 -20
  41. package/dist/providers/BaseBip44AccountProvider.mjs.map +1 -1
  42. package/dist/providers/BtcAccountProvider.cjs +1 -0
  43. package/dist/providers/BtcAccountProvider.cjs.map +1 -1
  44. package/dist/providers/BtcAccountProvider.d.cts.map +1 -1
  45. package/dist/providers/BtcAccountProvider.d.mts.map +1 -1
  46. package/dist/providers/BtcAccountProvider.mjs +1 -0
  47. package/dist/providers/BtcAccountProvider.mjs.map +1 -1
  48. package/dist/providers/EvmAccountProvider.cjs +39 -5
  49. package/dist/providers/EvmAccountProvider.cjs.map +1 -1
  50. package/dist/providers/EvmAccountProvider.d.cts +8 -0
  51. package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
  52. package/dist/providers/EvmAccountProvider.d.mts +8 -0
  53. package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
  54. package/dist/providers/EvmAccountProvider.mjs +39 -5
  55. package/dist/providers/EvmAccountProvider.mjs.map +1 -1
  56. package/dist/providers/SolAccountProvider.cjs +4 -0
  57. package/dist/providers/SolAccountProvider.cjs.map +1 -1
  58. package/dist/providers/SolAccountProvider.d.cts.map +1 -1
  59. package/dist/providers/SolAccountProvider.d.mts.map +1 -1
  60. package/dist/providers/SolAccountProvider.mjs +4 -0
  61. package/dist/providers/SolAccountProvider.mjs.map +1 -1
  62. package/dist/providers/TrxAccountProvider.cjs +1 -0
  63. package/dist/providers/TrxAccountProvider.cjs.map +1 -1
  64. package/dist/providers/TrxAccountProvider.d.cts.map +1 -1
  65. package/dist/providers/TrxAccountProvider.d.mts.map +1 -1
  66. package/dist/providers/TrxAccountProvider.mjs +1 -0
  67. package/dist/providers/TrxAccountProvider.mjs.map +1 -1
  68. package/dist/tests/messenger.cjs +4 -0
  69. package/dist/tests/messenger.cjs.map +1 -1
  70. package/dist/tests/messenger.d.cts.map +1 -1
  71. package/dist/tests/messenger.d.mts.map +1 -1
  72. package/dist/tests/messenger.mjs +4 -0
  73. package/dist/tests/messenger.mjs.map +1 -1
  74. package/dist/tests/providers.cjs +62 -7
  75. package/dist/tests/providers.cjs.map +1 -1
  76. package/dist/tests/providers.d.cts +17 -3
  77. package/dist/tests/providers.d.cts.map +1 -1
  78. package/dist/tests/providers.d.mts +17 -3
  79. package/dist/tests/providers.d.mts.map +1 -1
  80. package/dist/tests/providers.mjs +60 -6
  81. package/dist/tests/providers.mjs.map +1 -1
  82. package/dist/types.cjs.map +1 -1
  83. package/dist/types.d.cts +8 -4
  84. package/dist/types.d.cts.map +1 -1
  85. package/dist/types.d.mts +8 -4
  86. package/dist/types.d.mts.map +1 -1
  87. package/dist/types.mjs.map +1 -1
  88. package/dist/utils.cjs +1 -11
  89. package/dist/utils.cjs.map +1 -1
  90. package/dist/utils.d.cts +0 -1
  91. package/dist/utils.d.cts.map +1 -1
  92. package/dist/utils.d.mts +0 -1
  93. package/dist/utils.d.mts.map +1 -1
  94. package/dist/utils.mjs +0 -9
  95. package/dist/utils.mjs.map +1 -1
  96. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"MultichainAccountService.mjs","sourceRoot":"","sources":["../src/MultichainAccountService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,cAAc,EACd,2BAA2B,EAC5B,8BAA8B;AAM/B,OAAO,EAAE,qBAAqB,EAAE,2BAA2B;AAE3D,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAC5D,OAAO,EAAE,mBA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AE,oBAAoB,EAAE,eAAe,CACzE,CAAC;QACF,MAAM,CAAC,IAAI,EAAE,CAAC;IAChB,CAAC;IAED,6EAA6E;IAC7E,uBAAA,IAAI,oDAAoB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACtC,CAAC,qFAGC,aAA8B;IAE9B,MAAM,MAAM,GAAG,uBAAA,IAAI,yCAAS,CAAC,GAAG,CAC9B,2BAA2B,CAAC,aAAa,CAAC,CAC3C,CAAC;IAEF,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import {\n isBip44Account,\n toMultichainAccountWalletId,\n} from '@metamask/account-api';\nimport type {\n MultichainAccountWalletId,\n Bip44Account,\n} from '@metamask/account-api';\nimport type { HdKeyring } from '@metamask/eth-hd-keyring';\nimport { mnemonicPhraseToBytes } from '@metamask/key-tree';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport { areUint8ArraysEqual } from '@metamask/utils';\n\nimport { traceFallback } from './analytics';\nimport { projectLogger as log } from './logger';\nimport type { MultichainAccountGroup } from './MultichainAccountGroup';\nimport { MultichainAccountWallet } from './MultichainAccountWallet';\nimport {\n EvmAccountProviderConfig,\n Bip44AccountProvider,\n EVM_ACCOUNT_PROVIDER_NAME,\n} from './providers';\nimport {\n AccountProviderWrapper,\n isAccountProviderWrapper,\n} from './providers/AccountProviderWrapper';\nimport { EvmAccountProvider } from './providers/EvmAccountProvider';\nimport { SolAccountProvider } from './providers/SolAccountProvider';\nimport {\n SOL_ACCOUNT_PROVIDER_NAME,\n SolAccountProviderConfig,\n} from './providers/SolAccountProvider';\nimport { SnapPlatformWatcher } from './snaps/SnapPlatformWatcher';\nimport type {\n MultichainAccountServiceConfig,\n MultichainAccountServiceMessenger,\n} from './types';\nimport { createSentryError } from './utils';\n\nexport const serviceName = 'MultichainAccountService';\n\n/**\n * The options that {@link MultichainAccountService} takes.\n */\nexport type MultichainAccountServiceOptions = {\n messenger: MultichainAccountServiceMessenger;\n providers?: Bip44AccountProvider[];\n providerConfigs?: {\n [EVM_ACCOUNT_PROVIDER_NAME]?: EvmAccountProviderConfig;\n [SOL_ACCOUNT_PROVIDER_NAME]?: SolAccountProviderConfig;\n };\n config?: MultichainAccountServiceConfig;\n};\n\n/** Reverse mapping object used to map account IDs and their wallet/multichain account. */\ntype AccountContext<Account extends Bip44Account<KeyringAccount>> = {\n wallet: MultichainAccountWallet<Account>;\n group: MultichainAccountGroup<Account>;\n};\n\n/**\n * Service to expose multichain accounts capabilities.\n */\nexport class MultichainAccountService {\n readonly #messenger: MultichainAccountServiceMessenger;\n\n readonly #watcher: SnapPlatformWatcher;\n\n readonly #providers: Bip44AccountProvider[];\n\n readonly #wallets: Map<\n MultichainAccountWalletId,\n MultichainAccountWallet<Bip44Account<KeyringAccount>>\n >;\n\n readonly #accountIdToContext: Map<\n Bip44Account<KeyringAccount>['id'],\n AccountContext<Bip44Account<KeyringAccount>>\n >;\n\n /**\n * The name of the service.\n */\n name: typeof serviceName = serviceName;\n\n /**\n * Constructs a new MultichainAccountService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited to this\n * MultichainAccountService.\n * @param options.providers - Optional list of account\n * @param options.providerConfigs - Optional provider configs\n * @param options.config - Optional config.\n */\n constructor({\n messenger,\n providers = [],\n providerConfigs,\n config,\n }: MultichainAccountServiceOptions) {\n this.#messenger = messenger;\n this.#wallets = new Map();\n this.#accountIdToContext = new Map();\n\n // Pass trace callback directly to preserve original 'this' context\n // This avoids binding the callback to the MultichainAccountService instance\n const traceCallback = config?.trace ?? traceFallback;\n\n // TODO: Rely on keyring capabilities once the keyring API is used by all keyrings.\n this.#providers = [\n new EvmAccountProvider(\n this.#messenger,\n providerConfigs?.[EVM_ACCOUNT_PROVIDER_NAME],\n traceCallback,\n ),\n new AccountProviderWrapper(\n this.#messenger,\n new SolAccountProvider(\n this.#messenger,\n providerConfigs?.[SOL_ACCOUNT_PROVIDER_NAME],\n traceCallback,\n ),\n ),\n // Custom account providers that can be provided by the MetaMask client.\n ...providers,\n ];\n\n this.#watcher = new SnapPlatformWatcher(messenger);\n\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountGroup',\n (...args) => this.getMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountGroups',\n (...args) => this.getMultichainAccountGroups(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountWallet',\n (...args) => this.getMultichainAccountWallet(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountWallets',\n (...args) => this.getMultichainAccountWallets(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:createNextMultichainAccountGroup',\n (...args) => this.createNextMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:createMultichainAccountGroup',\n (...args) => this.createMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:setBasicFunctionality',\n (...args) => this.setBasicFunctionality(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:alignWallets',\n (...args) => this.alignWallets(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:alignWallet',\n (...args) => this.alignWallet(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:createMultichainAccountWallet',\n (...args) => this.createMultichainAccountWallet(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:resyncAccounts',\n (...args) => this.resyncAccounts(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:ensureCanUseSnapPlatform',\n (...args) => this.ensureCanUseSnapPlatform(...args),\n );\n\n this.#messenger.subscribe('AccountsController:accountAdded', (account) =>\n this.#handleOnAccountAdded(account),\n );\n this.#messenger.subscribe('AccountsController:accountRemoved', (id) =>\n this.#handleOnAccountRemoved(id),\n );\n }\n\n /**\n * Initialize the service and constructs the internal reprensentation of\n * multichain accounts and wallets.\n */\n async init(): Promise<void> {\n log('Initializing...');\n\n this.#wallets.clear();\n this.#accountIdToContext.clear();\n\n // Create initial wallets.\n const { keyrings } = this.#messenger.call('KeyringController:getState');\n for (const keyring of keyrings) {\n if (keyring.type === (KeyringTypes.hd as string)) {\n // Only HD keyrings have an entropy source/SRP.\n const entropySource = keyring.metadata.id;\n\n log(`Adding new wallet for entropy: \"${entropySource}\"`);\n\n // This will automatically \"associate\" all multichain accounts for that wallet\n // (based on the accounts owned by each account providers).\n const wallet = new MultichainAccountWallet({\n entropySource,\n providers: this.#providers,\n messenger: this.#messenger,\n });\n this.#wallets.set(wallet.id, wallet);\n\n // Reverse mapping between account ID and their multichain wallet/account:\n for (const group of wallet.getMultichainAccountGroups()) {\n for (const account of group.getAccounts()) {\n this.#accountIdToContext.set(account.id, {\n wallet,\n group,\n });\n }\n }\n }\n }\n\n log('Initialized');\n }\n\n /**\n * Re-synchronize MetaMask accounts and the providers accounts if needed.\n *\n * NOTE: This is mostly required if one of the providers (keyrings or Snaps)\n * have different sets of accounts. This method would ensure that both are\n * in-sync and use the same accounts (and same IDs).\n *\n * READ THIS CAREFULLY (State inconsistency bugs/de-sync)\n * We've seen some problems were keyring accounts on some Snaps were not synchronized\n * with the accounts on MM side. This causes problems where we cannot interact with\n * those accounts because the Snap does know about them.\n * To \"workaround\" this de-sync problem for now, we make sure that both parties are\n * in-sync when the service boots up.\n * ----------------------------------------------------------------------------------\n */\n async resyncAccounts(): Promise<void> {\n log('Re-sync provider accounts if needed...');\n const accounts = this.#messenger\n .call('AccountsController:listMultichainAccounts')\n .filter(isBip44Account);\n // We use `Promise.all` + `try-catch` combo, since we don't wanna block the wallet\n // from being used even if some accounts are not sync (best-effort).\n await Promise.all(\n this.#providers.map(async (provider) => {\n try {\n await provider.resyncAccounts(accounts);\n } catch (error) {\n const errorMessage = `Unable to re-sync provider \"${provider.getName()}\"`;\n log(errorMessage);\n console.error(errorMessage);\n\n const sentryError = createSentryError(errorMessage, error as Error, {\n provider: provider.getName(),\n });\n this.#messenger.captureException?.(sentryError);\n }\n }),\n );\n log('Providers got re-synced!');\n }\n\n ensureCanUseSnapPlatform(): Promise<void> {\n return this.#watcher.ensureCanUseSnapPlatform();\n }\n\n #handleOnAccountAdded(account: KeyringAccount): void {\n // We completely omit non-BIP-44 accounts!\n if (!isBip44Account(account)) {\n return;\n }\n\n let sync = true;\n\n let wallet = this.#wallets.get(\n toMultichainAccountWalletId(account.options.entropy.id),\n );\n if (!wallet) {\n log(\n `Adding new wallet for entropy: \"${account.options.entropy.id}\" (for account: \"${account.id}\")`,\n );\n\n // That's a new wallet.\n wallet = new MultichainAccountWallet({\n entropySource: account.options.entropy.id,\n providers: this.#providers,\n messenger: this.#messenger,\n });\n this.#wallets.set(wallet.id, wallet);\n\n // If that's a new wallet wallet. There's nothing to \"force-sync\".\n sync = false;\n }\n\n let group = wallet.getMultichainAccountGroup(\n account.options.entropy.groupIndex,\n );\n if (!group) {\n // This new account is a new multichain account, let the wallet know\n // it has to re-sync with its providers.\n if (sync) {\n wallet.sync();\n }\n\n group = wallet.getMultichainAccountGroup(\n account.options.entropy.groupIndex,\n );\n\n // If that's a new multichain account. There's nothing to \"force-sync\".\n sync = false;\n }\n\n // We have to check against `undefined` in case `getMultichainAccount` is\n // not able to find this multichain account (which should not be possible...)\n if (group) {\n if (sync) {\n group.sync();\n }\n\n // Same here, this account should have been already grouped in that\n // multichain account.\n this.#accountIdToContext.set(account.id, {\n wallet,\n group,\n });\n }\n }\n\n #handleOnAccountRemoved(id: KeyringAccount['id']): void {\n // Force sync of the appropriate wallet if an account got removed.\n const found = this.#accountIdToContext.get(id);\n if (found) {\n const { wallet } = found;\n\n log(\n `Re-synchronize wallet [${wallet.id}] since account \"${id}\" got removed`,\n );\n wallet.sync();\n }\n\n // Safe to call delete even if the `id` was not referencing a BIP-44 account.\n this.#accountIdToContext.delete(id);\n }\n\n #getWallet(\n entropySource: EntropySourceId,\n ): MultichainAccountWallet<Bip44Account<KeyringAccount>> {\n const wallet = this.#wallets.get(\n toMultichainAccountWalletId(entropySource),\n );\n\n if (!wallet) {\n throw new Error('Unknown wallet, no wallet matching this entropy source');\n }\n\n return wallet;\n }\n\n /**\n * Gets the account's context which contains its multichain wallet and\n * multichain account group references.\n *\n * @param id - Account ID.\n * @returns The account context if any, undefined otherwise.\n */\n getAccountContext(\n id: KeyringAccount['id'],\n ): AccountContext<Bip44Account<KeyringAccount>> | undefined {\n return this.#accountIdToContext.get(id);\n }\n\n /**\n * Gets a reference to the multichain account wallet matching this entropy source.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source of the multichain account.\n * @throws If none multichain account match this entropy.\n * @returns A reference to the multichain account wallet.\n */\n getMultichainAccountWallet({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccountWallet<Bip44Account<KeyringAccount>> {\n return this.#getWallet(entropySource);\n }\n\n /**\n * Gets an array of all multichain account wallets.\n *\n * @returns An array of all multichain account wallets.\n */\n getMultichainAccountWallets(): MultichainAccountWallet<\n Bip44Account<KeyringAccount>\n >[] {\n return Array.from(this.#wallets.values());\n }\n\n /**\n * Creates a new multichain account wallet with the given mnemonic.\n *\n * NOTE: This method should only be called in client code where a mutex lock is acquired.\n * `discoverAndCreateAccounts` should be called after this method to discover and create accounts.\n *\n * @param options - Options.\n * @param options.mnemonic - The mnemonic to use to create the new wallet.\n * @throws If the mnemonic has already been imported.\n * @returns The new multichain account wallet.\n */\n async createMultichainAccountWallet({\n mnemonic,\n }: {\n mnemonic: string;\n }): Promise<MultichainAccountWallet<Bip44Account<KeyringAccount>>> {\n const existingKeyrings = this.#messenger.call(\n 'KeyringController:getKeyringsByType',\n KeyringTypes.hd,\n ) as HdKeyring[];\n\n const mnemonicAsBytes = mnemonicPhraseToBytes(mnemonic);\n\n const alreadyHasImportedSrp = existingKeyrings.some((keyring) => {\n if (!keyring.mnemonic) {\n return false;\n }\n return areUint8ArraysEqual(keyring.mnemonic, mnemonicAsBytes);\n });\n\n if (alreadyHasImportedSrp) {\n throw new Error('This Secret Recovery Phrase has already been imported.');\n }\n\n log(`Creating new wallet...`);\n\n const result = await this.#messenger.call(\n 'KeyringController:addNewKeyring',\n KeyringTypes.hd,\n { mnemonic },\n );\n\n const wallet = new MultichainAccountWallet({\n providers: this.#providers,\n entropySource: result.id,\n messenger: this.#messenger,\n });\n\n this.#wallets.set(wallet.id, wallet);\n\n log(`Wallet created: [${wallet.id}]`);\n\n return wallet;\n }\n\n /**\n * Gets a reference to the multichain account group matching this entropy source\n * and a group index.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source of the multichain account.\n * @param options.groupIndex - The group index of the multichain account.\n * @throws If none multichain account match this entropy source and group index.\n * @returns A reference to the multichain account.\n */\n getMultichainAccountGroup({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): MultichainAccountGroup<Bip44Account<KeyringAccount>> {\n const multichainAccount =\n this.#getWallet(entropySource).getMultichainAccountGroup(groupIndex);\n\n if (!multichainAccount) {\n throw new Error(`No multichain account for index: ${groupIndex}`);\n }\n\n return multichainAccount;\n }\n\n /**\n * Gets all multichain account groups for a given entropy source.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source to query.\n * @throws If no multichain accounts match this entropy source.\n * @returns A list of all multichain accounts.\n */\n getMultichainAccountGroups({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccountGroup<Bip44Account<KeyringAccount>>[] {\n return this.#getWallet(entropySource).getMultichainAccountGroups();\n }\n\n /**\n * Creates the next multichain account group.\n *\n * @param options - Options.\n * @param options.entropySource - The wallet's entropy source.\n * @returns The next multichain account group.\n */\n async createNextMultichainAccountGroup({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): Promise<MultichainAccountGroup<Bip44Account<KeyringAccount>>> {\n return await this.#getWallet(\n entropySource,\n ).createNextMultichainAccountGroup();\n }\n\n /**\n * Creates a multichain account group.\n *\n * @param options - Options.\n * @param options.groupIndex - The group index to use.\n * @param options.entropySource - The wallet's entropy source.\n * @returns The multichain account group for this group index.\n */\n async createMultichainAccountGroup({\n groupIndex,\n entropySource,\n }: {\n groupIndex: number;\n entropySource: EntropySourceId;\n }): Promise<MultichainAccountGroup<Bip44Account<KeyringAccount>>> {\n return await this.#getWallet(entropySource).createMultichainAccountGroup(\n groupIndex,\n );\n }\n\n /**\n * Set basic functionality state and trigger alignment if enabled.\n * When basic functionality is disabled, snap-based providers are disabled.\n * When enabled, all snap providers are enabled and wallet alignment is triggered.\n * EVM providers are never disabled as they're required for basic wallet functionality.\n *\n * @param enabled - Whether basic functionality is enabled.\n */\n async setBasicFunctionality(enabled: boolean): Promise<void> {\n log(`Turning basic functionality: ${enabled ? 'ON' : 'OFF'}`);\n\n // Loop through providers and enable/disable only wrapped ones when basic functionality changes\n for (const provider of this.#providers) {\n if (isAccountProviderWrapper(provider)) {\n log(\n `${enabled ? 'Enabling' : 'Disabling'} account provider: \"${provider.getName()}\"`,\n );\n provider.setEnabled(enabled);\n }\n // Regular providers (like EVM) are never disabled for basic functionality\n }\n\n // Trigger alignment only when basic functionality is enabled\n if (enabled) {\n await this.alignWallets();\n }\n }\n\n /**\n * Align all multichain account wallets.\n */\n async alignWallets(): Promise<void> {\n log(`Triggering alignment on all wallets...`);\n\n const wallets = this.getMultichainAccountWallets();\n await Promise.all(wallets.map((w) => w.alignAccounts()));\n\n log(`Wallets aligned`);\n }\n\n /**\n * Align a specific multichain account wallet.\n *\n * @param entropySource - The entropy source of the multichain account wallet.\n */\n async alignWallet(entropySource: EntropySourceId): Promise<void> {\n const wallet = this.getMultichainAccountWallet({ entropySource });\n\n log(`Triggering alignment for wallet: [${wallet.id}]`);\n await wallet.alignAccounts();\n log(`Wallet [${wallet.id}] aligned`);\n }\n}\n"]}
1
+ {"version":3,"file":"MultichainAccountService.mjs","sourceRoot":"","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C,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,KAAK,0DACH,QAAgB,EAChB,QAAoB;IAEpB,GAAG,CAAC,uDAAuD,CAAC,CAAC;IAC7D,MAAM,uBAAA,IAAI,2CAAW,CAAC,IAAI,CACxB,4CAA4C,EAC5C,QAAQ,EACR,QAAQ,CACT,CAAC;IAEF,MAAM,eAAe,GAAG,uBAAA,IAAI,gGAA2B,MAA/B,IAAI,CAA6B,CAAC;IAE1D,mCAAmC;IACnC,OAAO,IAAI,uBAAuB,CAAC;QACjC,SAAS,EAAE,uBAAA,IAAI,2CAAW;QAC1B,aAAa,EAAE,eAAe;QAC9B,SAAS,EAAE,uBAAA,IAAI,2CAAW;KAC3B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n isBip44Account,\n toMultichainAccountWalletId,\n} from '@metamask/account-api';\nimport type {\n MultichainAccountWalletId,\n Bip44Account,\n} from '@metamask/account-api';\nimport type { HdKeyring } from '@metamask/eth-hd-keyring';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { areUint8ArraysEqual, assert } from '@metamask/utils';\n\nimport { traceFallback } from './analytics';\nimport { projectLogger as log } from './logger';\nimport type { MultichainAccountGroup } from './MultichainAccountGroup';\nimport { MultichainAccountWallet } from './MultichainAccountWallet';\nimport {\n EvmAccountProviderConfig,\n Bip44AccountProvider,\n EVM_ACCOUNT_PROVIDER_NAME,\n} from './providers';\nimport {\n AccountProviderWrapper,\n isAccountProviderWrapper,\n} from './providers/AccountProviderWrapper';\nimport { EvmAccountProvider } from './providers/EvmAccountProvider';\nimport { SolAccountProvider } from './providers/SolAccountProvider';\nimport {\n SOL_ACCOUNT_PROVIDER_NAME,\n SolAccountProviderConfig,\n} from './providers/SolAccountProvider';\nimport { SnapPlatformWatcher } from './snaps/SnapPlatformWatcher';\nimport type {\n MultichainAccountServiceConfig,\n MultichainAccountServiceMessenger,\n} from './types';\nimport { createSentryError } from './utils';\n\nexport const serviceName = 'MultichainAccountService';\n\n/**\n * The options that {@link MultichainAccountService} takes.\n */\nexport type MultichainAccountServiceOptions = {\n messenger: MultichainAccountServiceMessenger;\n providers?: Bip44AccountProvider[];\n providerConfigs?: {\n [EVM_ACCOUNT_PROVIDER_NAME]?: EvmAccountProviderConfig;\n [SOL_ACCOUNT_PROVIDER_NAME]?: SolAccountProviderConfig;\n };\n config?: MultichainAccountServiceConfig;\n};\n\n/**\n * The keys used to identify an account in the service state.\n */\nexport type StateKeys = {\n entropySource: EntropySourceId;\n groupIndex: number;\n providerName: string;\n};\n\n/**\n * The service state.\n */\nexport type ServiceState = {\n [entropySource: StateKeys['entropySource']]: {\n [groupIndex: string]: {\n [\n providerName: StateKeys['providerName']\n ]: Bip44Account<KeyringAccount>['id'][];\n };\n };\n};\n\nexport type CreateWalletParams =\n | {\n type: 'restore';\n password: string;\n mnemonic: Uint8Array;\n }\n | {\n type: 'import';\n mnemonic: Uint8Array;\n }\n | {\n type: 'create';\n password: string;\n };\n\n/**\n * Service to expose multichain accounts capabilities.\n */\nexport class MultichainAccountService {\n readonly #messenger: MultichainAccountServiceMessenger;\n\n readonly #watcher: SnapPlatformWatcher;\n\n readonly #providers: Bip44AccountProvider[];\n\n readonly #wallets: Map<\n MultichainAccountWalletId,\n MultichainAccountWallet<Bip44Account<KeyringAccount>>\n >;\n\n /**\n * The name of the service.\n */\n name: typeof serviceName = serviceName;\n\n /**\n * Constructs a new MultichainAccountService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited to this\n * MultichainAccountService.\n * @param options.providers - Optional list of account\n * @param options.providerConfigs - Optional provider configs\n * @param options.config - Optional config.\n */\n constructor({\n messenger,\n providers = [],\n providerConfigs,\n config,\n }: MultichainAccountServiceOptions) {\n this.#messenger = messenger;\n this.#wallets = new Map();\n\n // Pass trace callback directly to preserve original 'this' context\n // This avoids binding the callback to the MultichainAccountService instance\n const traceCallback = config?.trace ?? traceFallback;\n\n // TODO: Rely on keyring capabilities once the keyring API is used by all keyrings.\n this.#providers = [\n new EvmAccountProvider(\n this.#messenger,\n providerConfigs?.[EVM_ACCOUNT_PROVIDER_NAME],\n traceCallback,\n ),\n new AccountProviderWrapper(\n this.#messenger,\n new SolAccountProvider(\n this.#messenger,\n providerConfigs?.[SOL_ACCOUNT_PROVIDER_NAME],\n traceCallback,\n ),\n ),\n // Custom account providers that can be provided by the MetaMask client.\n ...providers,\n ];\n\n this.#watcher = new SnapPlatformWatcher(messenger);\n\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountGroup',\n (...args) => this.getMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountGroups',\n (...args) => this.getMultichainAccountGroups(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountWallet',\n (...args) => this.getMultichainAccountWallet(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:getMultichainAccountWallets',\n (...args) => this.getMultichainAccountWallets(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:createNextMultichainAccountGroup',\n (...args) => this.createNextMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:createMultichainAccountGroup',\n (...args) => this.createMultichainAccountGroup(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:setBasicFunctionality',\n (...args) => this.setBasicFunctionality(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:alignWallets',\n (...args) => this.alignWallets(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:alignWallet',\n (...args) => this.alignWallet(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:createMultichainAccountWallet',\n (...args) => this.createMultichainAccountWallet(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:resyncAccounts',\n (...args) => this.resyncAccounts(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:removeMultichainAccountWallet',\n (...args) => this.removeMultichainAccountWallet(...args),\n );\n this.#messenger.registerActionHandler(\n 'MultichainAccountService:ensureCanUseSnapPlatform',\n (...args) => this.ensureCanUseSnapPlatform(...args),\n );\n }\n\n /**\n * Get the keys used to identify an account in the service state.\n *\n * @param account - The account to get the keys for.\n * @returns The keys used to identify an account in the service state.\n * Returns null if the account is not compatible with any provider.\n */\n #getStateKeys(account: InternalAccount): StateKeys | null {\n for (const provider of this.#providers) {\n if (isBip44Account(account) && provider.isAccountCompatible(account)) {\n return {\n entropySource: account.options.entropy.id,\n groupIndex: account.options.entropy.groupIndex,\n providerName: provider.getName(),\n };\n }\n }\n return null;\n }\n\n /**\n * Construct the service and provider state.\n *\n * @returns The service and provider state.\n */\n #constructServiceState(): {\n serviceState: ServiceState;\n providerState: Record<string, Bip44Account<KeyringAccount>['id'][]>;\n } {\n const accounts = this.#messenger.call(\n 'AccountsController:listMultichainAccounts',\n );\n\n const serviceState: ServiceState = {};\n\n const providerState: Record<string, Bip44Account<KeyringAccount>['id'][]> =\n {};\n\n for (const account of accounts) {\n const keys = this.#getStateKeys(account);\n if (keys) {\n const { entropySource, groupIndex, providerName } = keys;\n serviceState[entropySource] ??= {};\n serviceState[entropySource][groupIndex] ??= {};\n serviceState[entropySource][groupIndex][providerName] ??= [];\n serviceState[entropySource][groupIndex][providerName].push(account.id);\n providerState[providerName] ??= [];\n providerState[providerName].push(account.id);\n }\n }\n return { serviceState, providerState };\n }\n\n /**\n * Initialize the service and constructs the internal reprensentation of\n * multichain accounts and wallets.\n */\n async init(): Promise<void> {\n log('Initializing...');\n\n this.#wallets.clear();\n\n const { serviceState, providerState } = this.#constructServiceState();\n\n for (const provider of this.#providers) {\n const providerName = provider.getName();\n // Initialize providers even if there are no accounts yet.\n // Passing an empty array ensures providers start in a valid state.\n const state = providerState[providerName] ?? [];\n provider.init(state);\n }\n\n for (const entropySource of Object.keys(serviceState)) {\n const wallet = new MultichainAccountWallet({\n entropySource,\n providers: this.#providers,\n messenger: this.#messenger,\n });\n wallet.init(serviceState[entropySource]);\n this.#wallets.set(wallet.id, wallet);\n }\n\n log('Initialized');\n }\n\n /**\n * Re-synchronize MetaMask accounts and the providers accounts if needed.\n *\n * NOTE: This is mostly required if one of the providers (keyrings or Snaps)\n * have different sets of accounts. This method would ensure that both are\n * in-sync and use the same accounts (and same IDs).\n *\n * READ THIS CAREFULLY (State inconsistency bugs/de-sync)\n * We've seen some problems were keyring accounts on some Snaps were not synchronized\n * with the accounts on MM side. This causes problems where we cannot interact with\n * those accounts because the Snap does know about them.\n * To \"workaround\" this de-sync problem for now, we make sure that both parties are\n * in-sync when the service boots up.\n * ----------------------------------------------------------------------------------\n */\n async resyncAccounts(): Promise<void> {\n log('Re-sync provider accounts if needed...');\n const accounts = this.#messenger\n .call('AccountsController:listMultichainAccounts')\n .filter(isBip44Account);\n // We use `Promise.all` + `try-catch` combo, since we don't wanna block the wallet\n // from being used even if some accounts are not sync (best-effort).\n await Promise.all(\n this.#providers.map(async (provider) => {\n try {\n await provider.resyncAccounts(accounts);\n } catch (error) {\n const errorMessage = `Unable to re-sync provider \"${provider.getName()}\"`;\n log(errorMessage);\n console.error(errorMessage);\n\n const sentryError = createSentryError(errorMessage, error as Error, {\n provider: provider.getName(),\n });\n this.#messenger.captureException?.(sentryError);\n }\n }),\n );\n log('Providers got re-synced!');\n }\n\n ensureCanUseSnapPlatform(): Promise<void> {\n return this.#watcher.ensureCanUseSnapPlatform();\n }\n\n /**\n * Get the wallet matching the given entropy source.\n *\n * @param entropySource - The entropy source of the wallet.\n * @returns The wallet matching the given entropy source.\n * @throws If no wallet matches the given entropy source.\n */\n #getWallet(\n entropySource: EntropySourceId,\n ): MultichainAccountWallet<Bip44Account<KeyringAccount>> {\n const wallet = this.#wallets.get(\n toMultichainAccountWalletId(entropySource),\n );\n\n if (!wallet) {\n throw new Error('Unknown wallet, no wallet matching this entropy source');\n }\n\n return wallet;\n }\n\n /**\n * Gets a reference to the multichain account wallet matching this entropy source.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source of the multichain account.\n * @throws If none multichain account match this entropy.\n * @returns A reference to the multichain account wallet.\n */\n getMultichainAccountWallet({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccountWallet<Bip44Account<KeyringAccount>> {\n return this.#getWallet(entropySource);\n }\n\n /**\n * Gets an array of all multichain account wallets.\n *\n * @returns An array of all multichain account wallets.\n */\n getMultichainAccountWallets(): MultichainAccountWallet<\n Bip44Account<KeyringAccount>\n >[] {\n return Array.from(this.#wallets.values());\n }\n\n #getPrimaryEntropySourceId(): EntropySourceId {\n const { keyrings } = this.#messenger.call('KeyringController:getState');\n const primaryKeyring = keyrings.find(\n (keyring) => keyring.type === 'HD Key Tree',\n );\n assert(primaryKeyring, 'Primary keyring not found');\n return primaryKeyring.metadata.id;\n }\n\n /**\n * Creates a new multichain account wallet by importing an existing mnemonic.\n *\n * @param mnemonic - The mnemonic to use to create the new wallet.\n * @returns The new multichain account wallet.\n */\n async #createWalletByImport(\n mnemonic: Uint8Array,\n ): Promise<MultichainAccountWallet<Bip44Account<KeyringAccount>>> {\n log(`Creating new wallet by importing an existing mnemonic...`);\n const existingKeyrings = this.#messenger.call(\n 'KeyringController:getKeyringsByType',\n KeyringTypes.hd,\n ) as HdKeyring[];\n\n const alreadyHasImportedSrp = existingKeyrings.some((keyring) => {\n if (!keyring.mnemonic) {\n return false;\n }\n return areUint8ArraysEqual(keyring.mnemonic, mnemonic);\n });\n\n if (alreadyHasImportedSrp) {\n throw new Error('This Secret Recovery Phrase has already been imported.');\n }\n\n const result = await this.#messenger.call(\n 'KeyringController:addNewKeyring',\n KeyringTypes.hd,\n { mnemonic },\n );\n\n // The wallet is ripe for discovery\n return new MultichainAccountWallet({\n providers: this.#providers,\n entropySource: result.id,\n messenger: this.#messenger,\n });\n }\n\n /**\n * Creates a new multichain account wallet by creating a new vault and keychain.\n *\n * @param password - The password to encrypt the vault with.\n * @returns The new multichain account wallet.\n */\n async #createWalletByNewVault(\n password: string,\n ): Promise<MultichainAccountWallet<Bip44Account<KeyringAccount>>> {\n log(`Creating new wallet by creating a new vault and keychain...`);\n await this.#messenger.call(\n 'KeyringController:createNewVaultAndKeychain',\n password,\n );\n\n const entropySourceId = this.#getPrimaryEntropySourceId();\n\n // The wallet is ripe for discovery\n return new MultichainAccountWallet({\n providers: this.#providers,\n entropySource: entropySourceId,\n messenger: this.#messenger,\n });\n }\n\n /**\n * Creates a new multichain account wallet by restoring a vault and keyring.\n *\n * @param password - The password to encrypt the vault with.\n * @param mnemonic - The mnemonic to use to restore the new wallet.\n * @returns The new multichain account wallet.\n */\n async #createWalletByRestore(\n password: string,\n mnemonic: Uint8Array,\n ): Promise<MultichainAccountWallet<Bip44Account<KeyringAccount>>> {\n log(`Creating new wallet by restoring vault and keyring...`);\n await this.#messenger.call(\n 'KeyringController:createNewVaultAndRestore',\n password,\n mnemonic,\n );\n\n const entropySourceId = this.#getPrimaryEntropySourceId();\n\n // The wallet is ripe for discovery\n return new MultichainAccountWallet({\n providers: this.#providers,\n entropySource: entropySourceId,\n messenger: this.#messenger,\n });\n }\n\n /**\n * Creates a new multichain account wallet by either importing an existing mnemonic,\n * creating a new vault and keychain, or restoring a vault and keyring.\n *\n * NOTE: This method should only be called in client code where a mutex lock is acquired.\n * `discoverAccounts` should be called after this method to discover and create accounts.\n *\n * @param params - The parameters to use to create the new wallet.\n * @param params.mnemonic - The mnemonic to use to create the new wallet.\n * @param params.password - The password to encrypt the vault with.\n * @param params.type - The flow type to use to create the new wallet.\n * @throws If the mnemonic has already been imported.\n * @returns The new multichain account wallet.\n */\n async createMultichainAccountWallet(\n params: CreateWalletParams,\n ): Promise<MultichainAccountWallet<Bip44Account<KeyringAccount>>> {\n let wallet:\n | MultichainAccountWallet<Bip44Account<KeyringAccount>>\n | undefined;\n\n if (params.type === 'import') {\n wallet = await this.#createWalletByImport(params.mnemonic);\n } else if (params.type === 'create') {\n wallet = await this.#createWalletByNewVault(params.password);\n } else if (params.type === 'restore') {\n wallet = await this.#createWalletByRestore(\n params.password,\n params.mnemonic,\n );\n }\n\n assert(wallet, 'Failed to create wallet.');\n\n wallet.init({});\n\n this.#wallets.set(wallet.id, wallet);\n\n log(`Wallet created: [${wallet.id}]`);\n\n return wallet;\n }\n\n /**\n * Removes a multichain account wallet.\n *\n * NOTE: This method should only be called in client code as a revert mechanism.\n * At the point that this code is called, discovery shouldn't have been triggered.\n * This is meant to be used in the scenario where a seed phrase backup is not successful.\n *\n * @param entropySource - The entropy source of the multichain account wallet.\n * @param accountAddress - The address of the account to remove.\n * @returns The removed multichain account wallet.\n */\n async removeMultichainAccountWallet(\n entropySource: EntropySourceId,\n accountAddress: string,\n ): Promise<void> {\n const wallet = this.#getWallet(entropySource);\n\n await this.#messenger.call(\n 'KeyringController:removeAccount',\n accountAddress,\n );\n\n this.#wallets.delete(wallet.id);\n }\n\n /**\n * Gets a reference to the multichain account group matching this entropy source\n * and a group index.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source of the multichain account.\n * @param options.groupIndex - The group index of the multichain account.\n * @throws If none multichain account match this entropy source and group index.\n * @returns A reference to the multichain account.\n */\n getMultichainAccountGroup({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): MultichainAccountGroup<Bip44Account<KeyringAccount>> {\n const multichainAccount =\n this.#getWallet(entropySource).getMultichainAccountGroup(groupIndex);\n\n if (!multichainAccount) {\n throw new Error(`No multichain account for index: ${groupIndex}`);\n }\n\n return multichainAccount;\n }\n\n /**\n * Gets all multichain account groups for a given entropy source.\n *\n * @param options - Options.\n * @param options.entropySource - The entropy source to query.\n * @throws If no multichain accounts match this entropy source.\n * @returns A list of all multichain accounts.\n */\n getMultichainAccountGroups({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): MultichainAccountGroup<Bip44Account<KeyringAccount>>[] {\n return this.#getWallet(entropySource).getMultichainAccountGroups();\n }\n\n /**\n * Creates the next multichain account group.\n *\n * @param options - Options.\n * @param options.entropySource - The wallet's entropy source.\n * @returns The next multichain account group.\n */\n async createNextMultichainAccountGroup({\n entropySource,\n }: {\n entropySource: EntropySourceId;\n }): Promise<MultichainAccountGroup<Bip44Account<KeyringAccount>>> {\n return await this.#getWallet(\n entropySource,\n ).createNextMultichainAccountGroup();\n }\n\n /**\n * Creates a multichain account group.\n *\n * @param options - Options.\n * @param options.groupIndex - The group index to use.\n * @param options.entropySource - The wallet's entropy source.\n * @returns The multichain account group for this group index.\n */\n async createMultichainAccountGroup({\n groupIndex,\n entropySource,\n }: {\n groupIndex: number;\n entropySource: EntropySourceId;\n }): Promise<MultichainAccountGroup<Bip44Account<KeyringAccount>>> {\n return await this.#getWallet(entropySource).createMultichainAccountGroup(\n groupIndex,\n );\n }\n\n /**\n * Set basic functionality state and trigger alignment if enabled.\n * When basic functionality is disabled, snap-based providers are disabled.\n * When enabled, all snap providers are enabled and wallet alignment is triggered.\n * EVM providers are never disabled as they're required for basic wallet functionality.\n *\n * @param enabled - Whether basic functionality is enabled.\n */\n async setBasicFunctionality(enabled: boolean): Promise<void> {\n log(`Turning basic functionality: ${enabled ? 'ON' : 'OFF'}`);\n\n // Loop through providers and enable/disable only wrapped ones when basic functionality changes\n for (const provider of this.#providers) {\n if (isAccountProviderWrapper(provider)) {\n log(\n `${enabled ? 'Enabling' : 'Disabling'} account provider: \"${provider.getName()}\"`,\n );\n provider.setEnabled(enabled);\n }\n // Regular providers (like EVM) are never disabled for basic functionality\n }\n\n // Trigger alignment only when basic functionality is enabled\n if (enabled) {\n await this.alignWallets();\n }\n }\n\n /**\n * Align all multichain account wallets.\n */\n async alignWallets(): Promise<void> {\n log(`Triggering alignment on all wallets...`);\n\n const wallets = this.getMultichainAccountWallets();\n await Promise.all(wallets.map((w) => w.alignAccounts()));\n\n log(`Wallets aligned`);\n }\n\n /**\n * Align a specific multichain account wallet.\n *\n * @param entropySource - The entropy source of the multichain account wallet.\n */\n async alignWallet(entropySource: EntropySourceId): Promise<void> {\n const wallet = this.getMultichainAccountWallet({ entropySource });\n\n log(`Triggering alignment for wallet: [${wallet.id}]`);\n await wallet.alignAccounts();\n log(`Wallet [${wallet.id}] aligned`);\n }\n}\n"]}
@@ -18,7 +18,7 @@ const utils_1 = require("@metamask/utils");
18
18
  const async_mutex_1 = require("async-mutex");
19
19
  const logger_1 = require("./logger.cjs");
20
20
  const MultichainAccountGroup_1 = require("./MultichainAccountGroup.cjs");
21
- const providers_1 = require("./providers/index.cjs");
21
+ const EvmAccountProvider_1 = require("./providers/EvmAccountProvider.cjs");
22
22
  const utils_2 = require("./utils.cjs");
23
23
  /**
24
24
  * A multichain account wallet that holds multiple multichain accounts (one multichain account per
@@ -34,7 +34,6 @@ class MultichainAccountWallet {
34
34
  _MultichainAccountWallet_accountGroups.set(this, void 0);
35
35
  _MultichainAccountWallet_messenger.set(this, void 0);
36
36
  _MultichainAccountWallet_log.set(this, void 0);
37
- // eslint-disable-next-line @typescript-eslint/prefer-readonly
38
37
  _MultichainAccountWallet_initialized.set(this, false);
39
38
  _MultichainAccountWallet_status.set(this, void 0);
40
39
  __classPrivateFieldSet(this, _MultichainAccountWallet_id, (0, account_api_1.toMultichainAccountWalletId)(entropySource), "f");
@@ -45,58 +44,32 @@ class MultichainAccountWallet {
45
44
  __classPrivateFieldSet(this, _MultichainAccountWallet_log, (0, logger_1.createModuleLogger)(logger_1.projectLogger, `[${__classPrivateFieldGet(this, _MultichainAccountWallet_id, "f")}]`), "f");
46
45
  // Initial synchronization (don't emit events during initialization).
47
46
  __classPrivateFieldSet(this, _MultichainAccountWallet_status, 'uninitialized', "f");
48
- this.sync();
49
- __classPrivateFieldSet(this, _MultichainAccountWallet_initialized, true, "f");
50
- __classPrivateFieldSet(this, _MultichainAccountWallet_status, 'ready', "f");
51
47
  }
52
48
  /**
53
- * Force wallet synchronization.
49
+ * Initialize the wallet and construct the internal representation of multichain account groups.
54
50
  *
55
- * This can be used if account providers got new accounts that the wallet
56
- * doesn't know about.
51
+ * @param walletState - The wallet state.
57
52
  */
58
- sync() {
59
- __classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, 'Synchronizing with account providers...');
60
- for (const provider of __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f")) {
61
- for (const account of provider.getAccounts()) {
62
- const { entropy } = account.options;
63
- // Filter for this wallet only.
64
- if (entropy.id !== this.entropySource) {
65
- continue;
66
- }
67
- // This multichain account might exists already.
68
- let multichainAccount = __classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").get(entropy.groupIndex);
69
- if (!multichainAccount) {
70
- multichainAccount = new MultichainAccountGroup_1.MultichainAccountGroup({
71
- groupIndex: entropy.groupIndex,
72
- wallet: this,
73
- providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
74
- messenger: __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f"),
75
- });
76
- // This existing multichain account group might differ from the
77
- // `createMultichainAccountGroup` behavior. When creating a new
78
- // group, we expect the providers to all succeed. But here, we're
79
- // just fetching the account lists from them, so this group might
80
- // not be "aligned" yet (e.g having a missing Solana account).
81
- //
82
- // Since "aligning" is an async operation, it would have to be run
83
- // after the first-sync.
84
- // TODO: Implement align mechanism to create "missing" accounts.
85
- __classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Found a new group: [${multichainAccount.id}]`);
86
- __classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").set(entropy.groupIndex, multichainAccount);
87
- }
88
- }
53
+ init(walletState) {
54
+ __classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, 'Initializing wallet state...');
55
+ for (const [groupIndexString, groupState] of Object.entries(walletState)) {
56
+ // Have to convert to number because the state keys become strings when we construct the state object in the service
57
+ const groupIndex = Number(groupIndexString);
58
+ const group = new MultichainAccountGroup_1.MultichainAccountGroup({
59
+ groupIndex,
60
+ wallet: this,
61
+ providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
62
+ messenger: __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f"),
63
+ });
64
+ __classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Creating new group for index ${groupIndex}...`);
65
+ group.init(groupState);
66
+ __classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").set(groupIndex, group);
89
67
  }
90
- // Now force-sync all remaining multichain accounts.
91
- for (const [groupIndex, multichainAccount,] of __classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").entries()) {
92
- multichainAccount.sync();
93
- // Clean up old multichain accounts.
94
- if (!multichainAccount.hasAccounts()) {
95
- __classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Deleting group: [${multichainAccount.id}]`);
96
- __classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").delete(groupIndex);
97
- }
68
+ if (!__classPrivateFieldGet(this, _MultichainAccountWallet_initialized, "f")) {
69
+ __classPrivateFieldSet(this, _MultichainAccountWallet_initialized, true, "f");
70
+ __classPrivateFieldSet(this, _MultichainAccountWallet_status, 'ready', "f");
98
71
  }
99
- __classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, 'Synchronized');
72
+ __classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, 'Finished initializing wallet state...');
100
73
  }
101
74
  /**
102
75
  * Gets the multichain account wallet ID.
@@ -210,9 +183,6 @@ class MultichainAccountWallet {
210
183
  }
211
184
  let group = this.getMultichainAccountGroup(groupIndex);
212
185
  if (group) {
213
- // If the group already exists, we just `sync` it and returns the same
214
- // reference.
215
- group.sync();
216
186
  __classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Trying to re-create existing group: [${group.id}] (idempotent)`);
217
187
  return group;
218
188
  }
@@ -220,23 +190,31 @@ class MultichainAccountWallet {
220
190
  // Extract the EVM provider from the list of providers.
221
191
  // We always await EVM account creation first.
222
192
  const [evmProvider, ...otherProviders] = __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f");
223
- (0, utils_1.assert)(evmProvider instanceof providers_1.EvmAccountProvider, 'EVM account provider must be first');
224
- try {
225
- await evmProvider.createAccounts({
226
- entropySource: __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f"),
227
- groupIndex,
228
- });
229
- }
230
- catch (error) {
231
- const errorMessage = `Unable to create multichain account group for index: ${groupIndex} with provider "${evmProvider.getName()}". Error: ${error.message}`;
193
+ (0, utils_1.assert)(evmProvider instanceof EvmAccountProvider_1.EvmAccountProvider, 'EVM account provider must be first');
194
+ const evmAccounts = await evmProvider
195
+ .createAccounts({
196
+ entropySource: __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f"),
197
+ groupIndex,
198
+ })
199
+ .then((accounts) => accounts.map((account) => account.id))
200
+ .catch((error) => {
201
+ const errorMessage = `Unable to create some accounts for group index: ${groupIndex} with provider "${evmProvider.getName()}". Error: ${error.message}`;
202
+ console.warn(errorMessage);
232
203
  __classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${logger_1.ERROR_PREFIX} ${errorMessage}:`, error);
233
204
  const sentryError = (0, utils_2.createSentryError)(`Unable to create account with provider "${evmProvider.getName()}"`, error, {
234
205
  groupIndex,
235
206
  provider: evmProvider.getName(),
236
207
  });
237
208
  __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").captureException?.(sentryError);
238
- throw new Error(errorMessage);
239
- }
209
+ throw error;
210
+ });
211
+ group = new MultichainAccountGroup_1.MultichainAccountGroup({
212
+ wallet: this,
213
+ providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
214
+ groupIndex,
215
+ messenger: __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f"),
216
+ });
217
+ group.init({ [evmProvider.getName()]: evmAccounts });
240
218
  // We then create accounts with other providers (some being throttled if configured).
241
219
  // Depending on the options, we either await all providers or run them in background.
242
220
  if (options?.waitForAllProvidersToFinishCreatingAccounts) {
@@ -244,6 +222,7 @@ class MultichainAccountWallet {
244
222
  groupIndex,
245
223
  providers: otherProviders,
246
224
  awaitAll: true,
225
+ group,
247
226
  });
248
227
  }
249
228
  else {
@@ -252,43 +231,11 @@ class MultichainAccountWallet {
252
231
  groupIndex,
253
232
  providers: otherProviders,
254
233
  awaitAll: false,
234
+ group,
255
235
  });
256
236
  }
257
- // --------------------------------------------------------------------------------
258
- // READ THIS CAREFULLY:
259
- //
260
- // Since we're not "fully supporting multichain" for now, we still rely on single
261
- // :accountCreated events to sync multichain account groups and wallets. Which means
262
- // that even if of the provider fails, some accounts will still be created on some
263
- // other providers and will become "available" on the `AccountsController`, like:
264
- //
265
- // 1. Creating a multichain account group for index 1
266
- // 2. EvmAccountProvider.createAccounts returns the EVM account for index 1
267
- // * AccountsController WILL fire :accountCreated for this account
268
- // * This account WILL BE "available" on the AccountsController state
269
- // 3. SolAccountProvider.createAccounts fails to create a Solana account for index 1
270
- // * AccountsController WON't fire :accountCreated for this account
271
- // * This account WON'T be "available" on the Account
272
- // 4. MultichainAccountService will receive a :accountCreated for the EVM account from
273
- // step 2 and will create a new multichain account group for index 1, but it won't
274
- // receive any event for the Solana account of this group. Thus, this group won't be
275
- // "aligned" (missing "blockchain account" on this group).
276
- //
277
- // --------------------------------------------------------------------------------
278
- // Because of the :accountAdded automatic sync, we might already have created the
279
- // group, so we first try to get it.
280
- group = this.getMultichainAccountGroup(groupIndex);
281
- if (!group) {
282
- // If for some reason it's still not created, we're creating it explicitly now:
283
- group = new MultichainAccountGroup_1.MultichainAccountGroup({
284
- wallet: this,
285
- providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
286
- groupIndex,
287
- messenger: __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f"),
288
- });
289
- }
290
- // Register the account to our internal map.
291
- __classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").set(groupIndex, group); // `group` cannot be undefined here.
237
+ // Register the account(s) to our internal map.
238
+ __classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").set(groupIndex, group);
292
239
  __classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `New group created: [${group.id}]`);
293
240
  if (__classPrivateFieldGet(this, _MultichainAccountWallet_initialized, "f")) {
294
241
  __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").publish('MultichainAccountService:multichainAccountGroupCreated', group);
@@ -344,6 +291,12 @@ class MultichainAccountWallet {
344
291
  // Start with the next available group index (so we can resume the discovery
345
292
  // from there).
346
293
  let maxGroupIndex = this.getNextGroupIndex();
294
+ const discoveredGroupsState = {};
295
+ const addDiscoveryResultToState = (result, providerName, groupIndex) => {
296
+ const accountIds = result.map((account) => account.id);
297
+ discoveredGroupsState[groupIndex] ?? (discoveredGroupsState[groupIndex] = {});
298
+ discoveredGroupsState[groupIndex][providerName] = accountIds;
299
+ };
347
300
  // One serialized loop per provider; all run concurrently
348
301
  const runProviderDiscovery = async (context) => {
349
302
  const providerName = context.provider.getName();
@@ -377,6 +330,7 @@ class MultichainAccountWallet {
377
330
  }
378
331
  (0, logger_1.projectLogger)(message('**succeeded**', targetGroupIndex));
379
332
  context.accounts = context.accounts.concat(accounts);
333
+ addDiscoveryResultToState(accounts, providerName, targetGroupIndex);
380
334
  const nextGroupIndex = targetGroupIndex + 1;
381
335
  context.groupIndex = nextGroupIndex;
382
336
  if (nextGroupIndex > maxGroupIndex) {
@@ -392,9 +346,18 @@ class MultichainAccountWallet {
392
346
  }));
393
347
  // Start discovery for each providers.
394
348
  await Promise.all(providerContexts.map(runProviderDiscovery));
395
- // Sync the wallet after discovery to ensure that the newly added accounts are added into their groups.
396
- // We can potentially remove this if we know that this race condition is not an issue in practice.
397
- this.sync();
349
+ // Create discovered groups
350
+ for (const [groupIndexString, groupState] of Object.entries(discoveredGroupsState)) {
351
+ const groupIndex = Number(groupIndexString);
352
+ const group = new MultichainAccountGroup_1.MultichainAccountGroup({
353
+ wallet: this,
354
+ providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
355
+ groupIndex,
356
+ messenger: __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f"),
357
+ });
358
+ group.init(groupState);
359
+ __classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").set(groupIndex, group);
360
+ }
398
361
  // Align missing accounts from group. This is required to create missing account from non-discovered
399
362
  // indexes for some providers.
400
363
  await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_alignAccounts).call(this);
@@ -436,10 +399,11 @@ async function _MultichainAccountWallet_withLock(status, operation) {
436
399
  * @param options.groupIndex - The group index to create accounts for.
437
400
  * @param options.providers - The non‑EVM account providers.
438
401
  * @param options.awaitAll - Whether to wait for all providers to finish.
402
+ * @param options.group - The group object pertaining to the group index to create accounts for.
439
403
  * @throws If awaitAll is true and any provider fails to create accounts.
440
404
  * @returns A promise that resolves when done (if awaitAll is true) or immediately (if false).
441
405
  */
442
- async function _MultichainAccountWallet_createNonEvmAccounts({ groupIndex, providers, awaitAll, }) {
406
+ async function _MultichainAccountWallet_createNonEvmAccounts({ groupIndex, providers, awaitAll, group, }) {
443
407
  if (awaitAll) {
444
408
  const tasks = providers.map((provider) => provider
445
409
  .createAccounts({
@@ -455,33 +419,54 @@ async function _MultichainAccountWallet_createNonEvmAccounts({ groupIndex, provi
455
419
  throw error;
456
420
  }));
457
421
  const results = await Promise.allSettled(tasks);
458
- if (results.some((r) => r.status === 'rejected')) {
459
- const errorMessage = (0, utils_2.toRejectedErrorMessage)(`Unable to create multichain account group for index: ${groupIndex}`, results);
460
- __classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${logger_1.WARNING_PREFIX} ${errorMessage}`);
461
- console.warn(errorMessage);
462
- throw new Error(errorMessage);
422
+ const providerFailures = results.reduce((acc, result, idx) => {
423
+ let newAcc = acc;
424
+ if (result.status === 'rejected') {
425
+ newAcc += `\n- ${providers[idx].getName()}: ${result.reason.message}`;
426
+ }
427
+ return newAcc;
428
+ }, '');
429
+ if (providerFailures.length) {
430
+ // We warn there's failures on some providers and thus misalignment, but we still create the group
431
+ const message = `Unable to create some accounts for group index: ${groupIndex}. Providers threw the following errors:${providerFailures}`;
432
+ console.warn(message);
433
+ __classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${logger_1.WARNING_PREFIX} ${message}`);
463
434
  }
464
- return;
435
+ // No need to fetch the accounts list from the AccountsController since we already have the account IDs to be used in the controller
436
+ const groupState = results.reduce((state, result, idx) => {
437
+ if (result.status === 'fulfilled') {
438
+ state[providers[idx].getName()] = result.value.map((account) => account.id);
439
+ }
440
+ return state;
441
+ }, {});
442
+ group.update(groupState);
465
443
  }
466
- // Background mode: start tasks and log errors.
467
- // Optional throttling is handled internally by each provider based on its config.
468
- providers.forEach((provider) => {
469
- // eslint-disable-next-line no-void
470
- void provider
471
- .createAccounts({
472
- entropySource: __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f"),
473
- groupIndex,
474
- })
475
- .catch((error) => {
476
- const errorMessage = `Unable to create multichain account group for index: ${groupIndex} (background mode with provider "${provider.getName()}")`;
477
- __classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${logger_1.WARNING_PREFIX} ${errorMessage}:`, error);
478
- const sentryError = (0, utils_2.createSentryError)(`Unable to create account with provider "${provider.getName()}"`, error, {
444
+ else {
445
+ // Create account with other providers in the background
446
+ providers.forEach((provider) => {
447
+ provider
448
+ .createAccounts({
449
+ entropySource: __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f"),
479
450
  groupIndex,
480
- provider: provider.getName(),
451
+ })
452
+ .then((accounts) => {
453
+ const accountIds = accounts.map((account) => account.id);
454
+ group.update({ [provider.getName()]: accountIds });
455
+ return group;
456
+ })
457
+ .catch((error) => {
458
+ // Log errors from background providers but don't fail the operation
459
+ const errorMessage = `Unable to create some accounts for group index: ${groupIndex} with provider "${provider.getName()}". Error: ${error.message}`;
460
+ console.warn(errorMessage);
461
+ __classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${logger_1.WARNING_PREFIX} ${errorMessage}:`, error);
462
+ const sentryError = (0, utils_2.createSentryError)(`Unable to create account with provider "${provider.getName()}"`, error, {
463
+ groupIndex,
464
+ provider: provider.getName(),
465
+ });
466
+ __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").captureException?.(sentryError);
481
467
  });
482
- __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").captureException?.(sentryError);
483
468
  });
484
- });
469
+ }
485
470
  }, _MultichainAccountWallet_alignAccounts =
486
471
  /**
487
472
  * Align all multichain account groups.