@metamask-previews/multichain-account-service 4.0.0-preview-7334bbce → 4.0.0-preview-e540d3bf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -21
- package/dist/MultichainAccountGroup.cjs +45 -84
- package/dist/MultichainAccountGroup.cjs.map +1 -1
- package/dist/MultichainAccountGroup.d.cts +5 -18
- package/dist/MultichainAccountGroup.d.cts.map +1 -1
- package/dist/MultichainAccountGroup.d.mts +5 -18
- package/dist/MultichainAccountGroup.d.mts.map +1 -1
- package/dist/MultichainAccountGroup.mjs +45 -84
- package/dist/MultichainAccountGroup.mjs.map +1 -1
- package/dist/MultichainAccountService.cjs +113 -126
- package/dist/MultichainAccountService.cjs.map +1 -1
- package/dist/MultichainAccountService.d.cts +20 -36
- package/dist/MultichainAccountService.d.cts.map +1 -1
- package/dist/MultichainAccountService.d.mts +20 -36
- package/dist/MultichainAccountService.d.mts.map +1 -1
- package/dist/MultichainAccountService.mjs +114 -127
- package/dist/MultichainAccountService.mjs.map +1 -1
- package/dist/MultichainAccountWallet.cjs +123 -107
- package/dist/MultichainAccountWallet.cjs.map +1 -1
- package/dist/MultichainAccountWallet.d.cts +4 -5
- package/dist/MultichainAccountWallet.d.cts.map +1 -1
- package/dist/MultichainAccountWallet.d.mts +4 -5
- package/dist/MultichainAccountWallet.d.mts.map +1 -1
- package/dist/MultichainAccountWallet.mjs +124 -108
- package/dist/MultichainAccountWallet.mjs.map +1 -1
- package/dist/providers/AccountProviderWrapper.cjs +0 -18
- package/dist/providers/AccountProviderWrapper.cjs.map +1 -1
- package/dist/providers/AccountProviderWrapper.d.cts +0 -12
- package/dist/providers/AccountProviderWrapper.d.cts.map +1 -1
- package/dist/providers/AccountProviderWrapper.d.mts +0 -12
- package/dist/providers/AccountProviderWrapper.d.mts.map +1 -1
- package/dist/providers/AccountProviderWrapper.mjs +0 -18
- package/dist/providers/AccountProviderWrapper.mjs.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.cjs +20 -45
- package/dist/providers/BaseBip44AccountProvider.cjs.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.d.cts +6 -58
- package/dist/providers/BaseBip44AccountProvider.d.cts.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.d.mts +6 -58
- package/dist/providers/BaseBip44AccountProvider.d.mts.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.mjs +20 -45
- package/dist/providers/BaseBip44AccountProvider.mjs.map +1 -1
- package/dist/providers/BtcAccountProvider.cjs +0 -1
- package/dist/providers/BtcAccountProvider.cjs.map +1 -1
- package/dist/providers/BtcAccountProvider.d.cts.map +1 -1
- package/dist/providers/BtcAccountProvider.d.mts.map +1 -1
- package/dist/providers/BtcAccountProvider.mjs +0 -1
- package/dist/providers/BtcAccountProvider.mjs.map +1 -1
- package/dist/providers/EvmAccountProvider.cjs +5 -39
- package/dist/providers/EvmAccountProvider.cjs.map +1 -1
- package/dist/providers/EvmAccountProvider.d.cts +0 -8
- package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
- package/dist/providers/EvmAccountProvider.d.mts +0 -8
- package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
- package/dist/providers/EvmAccountProvider.mjs +5 -39
- package/dist/providers/EvmAccountProvider.mjs.map +1 -1
- package/dist/providers/SolAccountProvider.cjs +0 -4
- package/dist/providers/SolAccountProvider.cjs.map +1 -1
- package/dist/providers/SolAccountProvider.d.cts.map +1 -1
- package/dist/providers/SolAccountProvider.d.mts.map +1 -1
- package/dist/providers/SolAccountProvider.mjs +0 -4
- package/dist/providers/SolAccountProvider.mjs.map +1 -1
- package/dist/providers/TrxAccountProvider.cjs +0 -1
- package/dist/providers/TrxAccountProvider.cjs.map +1 -1
- package/dist/providers/TrxAccountProvider.d.cts.map +1 -1
- package/dist/providers/TrxAccountProvider.d.mts.map +1 -1
- package/dist/providers/TrxAccountProvider.mjs +0 -1
- package/dist/providers/TrxAccountProvider.mjs.map +1 -1
- package/dist/tests/messenger.cjs +0 -3
- package/dist/tests/messenger.cjs.map +1 -1
- package/dist/tests/messenger.d.cts.map +1 -1
- package/dist/tests/messenger.d.mts.map +1 -1
- package/dist/tests/messenger.mjs +0 -3
- package/dist/tests/messenger.mjs.map +1 -1
- package/dist/tests/providers.cjs +7 -62
- package/dist/tests/providers.cjs.map +1 -1
- package/dist/tests/providers.d.cts +3 -17
- package/dist/tests/providers.d.cts.map +1 -1
- package/dist/tests/providers.d.mts +3 -17
- package/dist/tests/providers.d.mts.map +1 -1
- package/dist/tests/providers.mjs +6 -60
- package/dist/tests/providers.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +3 -3
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +3 -3
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils.cjs +11 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +1 -0
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +1 -0
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +9 -0
- package/dist/utils.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainAccountWallet.cjs","sourceRoot":"","sources":["../src/MultichainAccountWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAOA,uDAM+B;AAE/B,2CAAyC;AACzC,6CAAoC;AAGpC,yCAKkB;AAClB,yEAGkC;AAElC,qDAA4E;AAE5E,uCAA4C;AAmB5C;;;GAGG;AACH,MAAa,uBAAuB;IAsBlC,YAAY,EACV,SAAS,EACT,aAAa,EACb,SAAS,GAKV;;QA1BQ,wCAAQ,IAAI,mBAAK,EAAE,EAAC;QAEpB,8CAA+B;QAE/B,qDAA4C;QAE5C,yDAAgC;QAEhC,yDAA6D;QAE7D,qDAA8C;QAE9C,+CAAa;QAEtB,+CAAe,KAAK,EAAC;QAErB,kDAAuC;QAWrC,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E,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import type {\n AccountGroupId,\n Bip44Account,\n MultichainAccountWalletId,\n MultichainAccountWallet as MultichainAccountWalletDefinition,\n MultichainAccountWalletStatus,\n} from '@metamask/account-api';\nimport {\n AccountWalletType,\n getGroupIndexFromMultichainAccountGroupId,\n isMultichainAccountGroupId,\n toDefaultAccountGroupId,\n toMultichainAccountWalletId,\n} from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { assert } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport type { Logger } from './logger';\nimport {\n createModuleLogger,\n ERROR_PREFIX,\n projectLogger as log,\n WARNING_PREFIX,\n} from './logger';\nimport {\n type GroupState,\n MultichainAccountGroup,\n} from './MultichainAccountGroup';\nimport type { ServiceState, StateKeys } from './MultichainAccountService';\nimport { type Bip44AccountProvider, EvmAccountProvider } from './providers';\nimport type { MultichainAccountServiceMessenger } from './types';\nimport { createSentryError } from './utils';\n\n/**\n * The context for a provider discovery.\n */\ntype AccountProviderDiscoveryContext<\n Account extends Bip44Account<KeyringAccount>,\n> = {\n provider: Bip44AccountProvider<Account>;\n stopped: boolean;\n groupIndex: number;\n accounts: Account[];\n};\n\nexport type WalletState = ServiceState[StateKeys['entropySource']];\n\n// type alias to make clear this state is generated by discovery\ntype DiscoveredGroupsState = WalletState;\n\n/**\n * A multichain account wallet that holds multiple multichain accounts (one multichain account per\n * group index).\n */\nexport class MultichainAccountWallet<\n Account extends Bip44Account<KeyringAccount>,\n> implements MultichainAccountWalletDefinition<Account>\n{\n readonly #lock = new Mutex();\n\n readonly #id: MultichainAccountWalletId;\n\n readonly #providers: Bip44AccountProvider<Account>[];\n\n readonly #entropySource: EntropySourceId;\n\n readonly #accountGroups: Map<number, MultichainAccountGroup<Account>>;\n\n readonly #messenger: MultichainAccountServiceMessenger;\n\n readonly #log: Logger;\n\n #initialized = false;\n\n #status: MultichainAccountWalletStatus;\n\n constructor({\n providers,\n entropySource,\n messenger,\n }: {\n providers: Bip44AccountProvider<Account>[];\n entropySource: EntropySourceId;\n messenger: MultichainAccountServiceMessenger;\n }) {\n this.#id = toMultichainAccountWalletId(entropySource);\n this.#providers = providers;\n this.#entropySource = entropySource;\n this.#messenger = messenger;\n this.#accountGroups = new Map();\n\n this.#log = createModuleLogger(log, `[${this.#id}]`);\n\n // Initial synchronization (don't emit events during initialization).\n this.#status = 'uninitialized';\n }\n\n /**\n * Initialize the wallet and construct the internal representation of multichain account groups.\n *\n * @param walletState - The wallet state.\n */\n init(walletState: WalletState) {\n this.#log('Initializing wallet state...');\n for (const [groupIndexString, groupState] of Object.entries(walletState)) {\n // Have to convert to number because the state keys become strings when we construct the state object in the service\n const groupIndex = Number(groupIndexString);\n const group = new MultichainAccountGroup({\n groupIndex,\n wallet: this,\n providers: this.#providers,\n messenger: this.#messenger,\n });\n\n this.#log(`Creating new group for index ${groupIndex}...`);\n\n group.init(groupState);\n\n this.#accountGroups.set(groupIndex, group);\n }\n if (!this.#initialized) {\n this.#initialized = true;\n this.#status = 'ready';\n }\n\n this.#log('Finished initializing wallet state...');\n }\n\n /**\n * Gets the multichain account wallet ID.\n *\n * @returns The multichain account wallet ID.\n */\n get id(): MultichainAccountWalletId {\n return this.#id;\n }\n\n /**\n * Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.\n *\n * @returns The multichain account wallet type.\n */\n get type(): AccountWalletType.Entropy {\n return AccountWalletType.Entropy;\n }\n\n /**\n * Gets the multichain account wallet entropy source.\n *\n * @returns The multichain account wallet entropy source.\n */\n get entropySource(): EntropySourceId {\n return this.#entropySource;\n }\n\n /**\n * Gets the multichain account wallet current status.\n *\n * @returns The multichain account wallet current status.\n */\n get status(): MultichainAccountWalletStatus {\n return this.#status;\n }\n\n /**\n * Set the wallet status and run the associated operation callback.\n *\n * @param status - Wallet status associated with this operation.\n * @param operation - Operation to run.\n * @returns The operation's result.\n * @throws {Error} If the wallet is already running a mutable operation.\n */\n async #withLock<Return>(\n status: MultichainAccountWalletStatus,\n operation: () => Promise<Return>,\n ) {\n const release = await this.#lock.acquire();\n try {\n this.#log(`Locking wallet with status \"${status}\"...`);\n this.#status = status;\n this.#messenger.publish(\n 'MultichainAccountService:walletStatusChange',\n this.id,\n this.#status,\n );\n return await operation();\n } finally {\n this.#status = 'ready';\n this.#messenger.publish(\n 'MultichainAccountService:walletStatusChange',\n this.id,\n this.#status,\n );\n release();\n this.#log(`Releasing wallet lock (was \"${status}\")`);\n }\n }\n\n /**\n * Create accounts with non‑EVM providers. Optional throttling is managed by each provider internally.\n * When awaitAll is true, waits for all providers and throws if any failed.\n * When false, starts work in background and logs errors without throwing.\n *\n * @param options - Method options.\n * @param options.groupIndex - The group index to create accounts for.\n * @param options.providers - The non‑EVM account providers.\n * @param options.awaitAll - Whether to wait for all providers to finish.\n * @param options.group - The group object pertaining to the group index to create accounts for.\n * @throws If awaitAll is true and any provider fails to create accounts.\n * @returns A promise that resolves when done (if awaitAll is true) or immediately (if false).\n */\n async #createNonEvmAccounts({\n groupIndex,\n providers,\n awaitAll,\n group,\n }: {\n groupIndex: number;\n providers: Bip44AccountProvider<Account>[];\n awaitAll: boolean;\n group: MultichainAccountGroup<Account>;\n }): Promise<void> {\n if (awaitAll) {\n const tasks = providers.map((provider) =>\n provider\n .createAccounts({\n entropySource: this.#entropySource,\n groupIndex,\n })\n .catch((error) => {\n const sentryError = createSentryError(\n `Unable to create account with provider \"${provider.getName()}\"`,\n error,\n {\n groupIndex,\n provider: provider.getName(),\n },\n );\n this.#messenger.call(\n 'ErrorReportingService:captureException',\n sentryError,\n );\n throw error;\n }),\n );\n\n const results = await Promise.allSettled(tasks);\n\n const providerFailures = results.reduce((acc, result, idx) => {\n if (result.status === 'rejected') {\n acc += `\\n- ${providers[idx].getName()}: ${result.reason.message}`;\n }\n return acc;\n }, '');\n\n if (providerFailures.length) {\n // We warn there's failures on some providers and thus misalignment, but we still create the group\n const message = `Unable to create some accounts for group index: ${groupIndex}. Providers threw the following errors:${providerFailures}`;\n console.warn(message);\n this.#log(`${WARNING_PREFIX} ${message}`);\n }\n\n // No need to fetch the accounts list from the AccountsController since we already have the account IDs to be used in the controller\n const groupState = results.reduce<GroupState>((state, result, idx) => {\n if (result.status === 'fulfilled') {\n state[providers[idx].getName()] = result.value.map(\n (account) => account.id,\n );\n }\n return state;\n }, {});\n\n group.update(groupState);\n } else {\n // Create account with other providers in the background\n providers.forEach((provider) => {\n provider\n .createAccounts({\n entropySource: this.#entropySource,\n groupIndex,\n })\n .then((accounts) => {\n const accountIds = accounts.map((account) => account.id);\n group.update({ [provider.getName()]: accountIds });\n return group;\n })\n .catch((error) => {\n // Log errors from background providers but don't fail the operation\n const errorMessage = `Unable to create some accounts for group index: ${groupIndex} with provider \"${provider.getName()}\". Error: ${(error as Error).message}`;\n console.warn(errorMessage);\n this.#log(`${WARNING_PREFIX} ${errorMessage}:`, error);\n const sentryError = createSentryError(\n `Unable to create account with provider \"${provider.getName()}\"`,\n error,\n {\n groupIndex,\n provider: provider.getName(),\n },\n );\n this.#messenger.call(\n 'ErrorReportingService:captureException',\n sentryError,\n );\n });\n });\n }\n }\n\n /**\n * Gets multichain account for a given ID.\n * The default group ID will default to the multichain account with index 0.\n *\n * @param id - Account group ID.\n * @returns Account group.\n */\n getAccountGroup(\n id: AccountGroupId,\n ): MultichainAccountGroup<Account> | undefined {\n // We consider the \"default case\" to be mapped to index 0.\n if (id === toDefaultAccountGroupId(this.id)) {\n return this.#accountGroups.get(0);\n }\n\n // If it is not a valid ID, we cannot extract the group index\n // from it, so we fail fast.\n if (!isMultichainAccountGroupId(id)) {\n return undefined;\n }\n\n const groupIndex = getGroupIndexFromMultichainAccountGroupId(id);\n return this.#accountGroups.get(groupIndex);\n }\n\n /**\n * Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccountGroups}.\n *\n * @returns The multichain accounts.\n */\n getAccountGroups(): MultichainAccountGroup<Account>[] {\n return this.getMultichainAccountGroups();\n }\n\n /**\n * Gets multichain account group for a given index.\n *\n * @param groupIndex - Multichain account index.\n * @returns The multichain account associated with the given index.\n */\n getMultichainAccountGroup(\n groupIndex: number,\n ): MultichainAccountGroup<Account> | undefined {\n return this.#accountGroups.get(groupIndex);\n }\n\n /**\n * Gets all multichain account groups.\n *\n * @returns The multichain accounts.\n */\n getMultichainAccountGroups(): MultichainAccountGroup<Account>[] {\n return Array.from(this.#accountGroups.values()); // TODO: Prevent copy here.\n }\n\n /**\n * Gets next group index for this wallet.\n *\n * @returns The next group index of this wallet.\n */\n getNextGroupIndex(): number {\n // We do not check for gaps.\n return (\n Math.max(\n -1, // So it will default to 0 if no groups.\n ...this.#accountGroups.keys(),\n ) + 1\n );\n }\n\n /**\n * Creates a multichain account group for a given group index.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n *\n * @param groupIndex - The group index to use.\n * @param options - Options to configure the account creation.\n * @param options.waitForAllProvidersToFinishCreatingAccounts - Whether to wait for all\n * account providers to finish creating their accounts before returning. If `false`, only\n * the EVM provider will be awaited, while all other providers will create their accounts\n * in the background. Defaults to `false`.\n * @throws If any of the account providers fails to create their accounts and\n * the `waitForAllProvidersToFinishCreatingAccounts` option is set to `true`. If `false`,\n * errors from non-EVM providers will be logged but ignored, and only errors from the\n * EVM provider will be thrown.\n * @returns The multichain account group for this group index.\n */\n async createMultichainAccountGroup(\n groupIndex: number,\n options: {\n waitForAllProvidersToFinishCreatingAccounts?: boolean;\n } = { waitForAllProvidersToFinishCreatingAccounts: false },\n ): Promise<MultichainAccountGroup<Account>> {\n return await this.#withLock('in-progress:create-accounts', async () => {\n const nextGroupIndex = this.getNextGroupIndex();\n if (groupIndex > nextGroupIndex) {\n throw new Error(\n `You cannot use a group index that is higher than the next available one: expected <=${nextGroupIndex}, got ${groupIndex}`,\n );\n }\n\n let group = this.getMultichainAccountGroup(groupIndex);\n\n if (group) {\n this.#log(\n `Trying to re-create existing group: [${group.id}] (idempotent)`,\n );\n return group;\n }\n\n this.#log(`Creating new group for index ${groupIndex}...`);\n\n // Extract the EVM provider from the list of providers.\n // We always await EVM account creation first.\n const [evmProvider, ...otherProviders] = this.#providers;\n assert(\n evmProvider instanceof EvmAccountProvider,\n 'EVM account provider must be first',\n );\n\n const evmAccounts = await evmProvider\n .createAccounts({\n entropySource: this.#entropySource,\n groupIndex,\n })\n .then((accounts) => accounts.map((account) => account.id))\n .catch((error) => {\n const errorMessage = `Unable to create some accounts for group index: ${groupIndex} with provider \"${evmProvider.getName()}\". Error: ${(error as Error).message}`;\n console.warn(errorMessage);\n this.#log(`${ERROR_PREFIX} ${errorMessage}:`, error);\n const sentryError = createSentryError(\n `Unable to create account with provider \"${evmProvider.getName()}\"`,\n error as Error,\n {\n groupIndex,\n provider: evmProvider.getName(),\n },\n );\n this.#messenger.call(\n 'ErrorReportingService:captureException',\n sentryError,\n );\n throw error;\n });\n\n group = new MultichainAccountGroup({\n wallet: this,\n providers: this.#providers,\n groupIndex,\n messenger: this.#messenger,\n });\n\n group.init({ [evmProvider.getName()]: evmAccounts });\n\n // We then create accounts with other providers (some being throttled if configured).\n // Depending on the options, we either await all providers or run them in background.\n if (options?.waitForAllProvidersToFinishCreatingAccounts) {\n await this.#createNonEvmAccounts({\n groupIndex,\n providers: otherProviders,\n awaitAll: true,\n group,\n });\n } else {\n // eslint-disable-next-line no-void\n void this.#createNonEvmAccounts({\n groupIndex,\n providers: otherProviders,\n awaitAll: false,\n group,\n });\n }\n\n // Register the account(s) to our internal map.\n this.#accountGroups.set(groupIndex, group);\n\n this.#log(`New group created: [${group.id}]`);\n\n if (this.#initialized) {\n this.#messenger.publish(\n 'MultichainAccountService:multichainAccountGroupCreated',\n group,\n );\n }\n\n return group;\n });\n }\n\n /**\n * Creates the next multichain account group.\n *\n * @throws If any of the account providers fails to create their accounts.\n * @returns The multichain account group for the next group index available.\n */\n async createNextMultichainAccountGroup(): Promise<\n MultichainAccountGroup<Account>\n > {\n return this.createMultichainAccountGroup(this.getNextGroupIndex(), {\n waitForAllProvidersToFinishCreatingAccounts: true,\n });\n }\n\n /**\n * Align all multichain account groups.\n *\n * NOTE: This operation WILL NOT lock the wallet's mutex.\n */\n async #alignAccounts(): Promise<void> {\n const groups = this.getMultichainAccountGroups();\n await Promise.all(groups.map((group) => group.alignAccounts()));\n }\n\n /**\n * Align all accounts from each existing multichain account groups.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n */\n async alignAccounts(): Promise<void> {\n await this.#withLock('in-progress:alignment', async () => {\n await this.#alignAccounts();\n });\n }\n\n /**\n * Align a specific multichain account group.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n *\n * @param groupIndex - The group index to align.\n */\n async alignAccountsOf(groupIndex: number): Promise<void> {\n await this.#withLock('in-progress:alignment', async () => {\n const group = this.getMultichainAccountGroup(groupIndex);\n if (group) {\n await group.alignAccounts();\n }\n });\n }\n\n /**\n * Discover and create accounts for all providers.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n *\n * @returns The discovered accounts for each provider.\n */\n async discoverAccounts(): Promise<Account[]> {\n return this.#withLock('in-progress:discovery', async () => {\n // Start with the next available group index (so we can resume the discovery\n // from there).\n let maxGroupIndex = this.getNextGroupIndex();\n const discoveredGroupsState: DiscoveredGroupsState = {};\n\n const addDiscoveryResultToState = (\n result: Account[],\n providerName: string,\n groupIndex: number,\n ) => {\n const accountIds = result.map((account) => account.id);\n discoveredGroupsState[groupIndex] ??= {};\n discoveredGroupsState[groupIndex][providerName] = accountIds;\n };\n\n // One serialized loop per provider; all run concurrently\n const runProviderDiscovery = async (\n context: AccountProviderDiscoveryContext<Account>,\n ) => {\n const providerName = context.provider.getName();\n const message = (stepName: string, groupIndex: number) =>\n `[${providerName}] Discovery ${stepName} for group index: ${groupIndex}`;\n\n while (!context.stopped) {\n // Fast‑forward to current high‑water mark\n const targetGroupIndex = Math.max(context.groupIndex, maxGroupIndex);\n\n log(message('started', targetGroupIndex));\n\n let accounts: Account[] = [];\n try {\n accounts = (await context.provider.discoverAccounts({\n entropySource: this.#entropySource,\n groupIndex: targetGroupIndex,\n })) as Account[];\n } catch (error) {\n context.stopped = true;\n console.error(error);\n log(\n message(\n `failed (with: \"${(error as Error).message}\")`,\n targetGroupIndex,\n ),\n error,\n );\n const sentryError = createSentryError(\n 'Unable to discover accounts',\n error as Error,\n {\n provider: providerName,\n groupIndex: targetGroupIndex,\n },\n );\n this.#messenger.call(\n 'ErrorReportingService:captureException',\n sentryError,\n );\n break;\n }\n\n if (!accounts.length) {\n log(\n message('stopped (no accounts got discovered)', targetGroupIndex),\n );\n context.stopped = true;\n break;\n }\n\n log(message('**succeeded**', targetGroupIndex));\n\n context.accounts = context.accounts.concat(accounts);\n\n addDiscoveryResultToState(accounts, providerName, targetGroupIndex);\n\n const nextGroupIndex = targetGroupIndex + 1;\n context.groupIndex = nextGroupIndex;\n\n if (nextGroupIndex > maxGroupIndex) {\n maxGroupIndex = nextGroupIndex;\n }\n }\n };\n\n const providerContexts: AccountProviderDiscoveryContext<Account>[] =\n this.#providers.map((provider) => ({\n provider,\n stopped: false,\n groupIndex: maxGroupIndex,\n accounts: [],\n }));\n\n // Start discovery for each providers.\n await Promise.all(providerContexts.map(runProviderDiscovery));\n\n // Create discovered groups\n for (const [groupIndexString, groupState] of Object.entries(\n discoveredGroupsState,\n )) {\n const groupIndex = Number(groupIndexString);\n const group = new MultichainAccountGroup({\n wallet: this,\n providers: this.#providers,\n groupIndex,\n messenger: this.#messenger,\n });\n group.init(groupState);\n this.#accountGroups.set(groupIndex, group);\n }\n\n // Align missing accounts from group. This is required to create missing account from non-discovered\n // indexes for some providers.\n await this.#alignAccounts();\n\n return providerContexts.flatMap((context) => context.accounts);\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MultichainAccountWallet.cjs","sourceRoot":"","sources":["../src/MultichainAccountWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAOA,uDAM+B;AAE/B,2CAAyC;AACzC,6CAAoC;AAG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;YACf,MAAM,YAAY,GAAG,wDAAwD,UAAU,oCAAoC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;YAClJ,uBAAA,IAAI,oCAAK,MAAT,IAAI,EAAM,GAAG,uBAAc,IAAI,YAAY,GAAG,EAAE,KAAK,CAAC,CAAC;YACvD,MAAM,WAAW,GAAG,IAAA,yBAAiB,EACnC,2CAA2C,QAAQ,CAAC,OAAO,EAAE,GAAG,EAChE,KAAK,EACL;gBACE,UAAU;gBACV,QAAQ,EAAE,QAAQ,CAAC,OAAO,EAAE;aAC7B,CACF,CAAC;YACF,uBAAA,IAAI,0CAAW,CAAC,IAAI,CAClB,wCAAwC,EACxC,WAAW,CACZ,CAAC;QACJ,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC;AAqOD;;;;GAIG;AACH,KAAK;IACH,MAAM,MAAM,GAAG,IAAI,CAAC,0BAA0B,EAAE,CAAC;IACjD,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import type {\n AccountGroupId,\n Bip44Account,\n MultichainAccountWalletId,\n MultichainAccountWallet as MultichainAccountWalletDefinition,\n MultichainAccountWalletStatus,\n} from '@metamask/account-api';\nimport {\n AccountWalletType,\n getGroupIndexFromMultichainAccountGroupId,\n isMultichainAccountGroupId,\n toDefaultAccountGroupId,\n toMultichainAccountWalletId,\n} from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { assert } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport type { Logger } from './logger';\nimport {\n createModuleLogger,\n ERROR_PREFIX,\n projectLogger as log,\n WARNING_PREFIX,\n} from './logger';\nimport { MultichainAccountGroup } from './MultichainAccountGroup';\nimport { EvmAccountProvider, type Bip44AccountProvider } from './providers';\nimport type { MultichainAccountServiceMessenger } from './types';\nimport { createSentryError, toRejectedErrorMessage } from './utils';\n\n/**\n * The context for a provider discovery.\n */\ntype AccountProviderDiscoveryContext<\n Account extends Bip44Account<KeyringAccount>,\n> = {\n provider: Bip44AccountProvider<Account>;\n stopped: boolean;\n groupIndex: number;\n accounts: Account[];\n};\n\n/**\n * A multichain account wallet that holds multiple multichain accounts (one multichain account per\n * group index).\n */\nexport class MultichainAccountWallet<\n Account extends Bip44Account<KeyringAccount>,\n> implements MultichainAccountWalletDefinition<Account>\n{\n readonly #lock = new Mutex();\n\n readonly #id: MultichainAccountWalletId;\n\n readonly #providers: Bip44AccountProvider<Account>[];\n\n readonly #entropySource: EntropySourceId;\n\n readonly #accountGroups: Map<number, MultichainAccountGroup<Account>>;\n\n readonly #messenger: MultichainAccountServiceMessenger;\n\n readonly #log: Logger;\n\n // eslint-disable-next-line @typescript-eslint/prefer-readonly\n #initialized = false;\n\n #status: MultichainAccountWalletStatus;\n\n constructor({\n providers,\n entropySource,\n messenger,\n }: {\n providers: Bip44AccountProvider<Account>[];\n entropySource: EntropySourceId;\n messenger: MultichainAccountServiceMessenger;\n }) {\n this.#id = toMultichainAccountWalletId(entropySource);\n this.#providers = providers;\n this.#entropySource = entropySource;\n this.#messenger = messenger;\n this.#accountGroups = new Map();\n\n this.#log = createModuleLogger(log, `[${this.#id}]`);\n\n // Initial synchronization (don't emit events during initialization).\n this.#status = 'uninitialized';\n this.sync();\n this.#initialized = true;\n this.#status = 'ready';\n }\n\n /**\n * Force wallet synchronization.\n *\n * This can be used if account providers got new accounts that the wallet\n * doesn't know about.\n */\n sync(): void {\n this.#log('Synchronizing with account providers...');\n for (const provider of this.#providers) {\n for (const account of provider.getAccounts()) {\n const { entropy } = account.options;\n\n // Filter for this wallet only.\n if (entropy.id !== this.entropySource) {\n continue;\n }\n\n // This multichain account might exists already.\n let multichainAccount = this.#accountGroups.get(entropy.groupIndex);\n if (!multichainAccount) {\n multichainAccount = new MultichainAccountGroup<Account>({\n groupIndex: entropy.groupIndex,\n wallet: this,\n providers: this.#providers,\n messenger: this.#messenger,\n });\n\n // This existing multichain account group might differ from the\n // `createMultichainAccountGroup` behavior. When creating a new\n // group, we expect the providers to all succeed. But here, we're\n // just fetching the account lists from them, so this group might\n // not be \"aligned\" yet (e.g having a missing Solana account).\n //\n // Since \"aligning\" is an async operation, it would have to be run\n // after the first-sync.\n // TODO: Implement align mechanism to create \"missing\" accounts.\n\n this.#log(`Found a new group: [${multichainAccount.id}]`);\n this.#accountGroups.set(entropy.groupIndex, multichainAccount);\n }\n }\n }\n\n // Now force-sync all remaining multichain accounts.\n for (const [\n groupIndex,\n multichainAccount,\n ] of this.#accountGroups.entries()) {\n multichainAccount.sync();\n\n // Clean up old multichain accounts.\n if (!multichainAccount.hasAccounts()) {\n this.#log(`Deleting group: [${multichainAccount.id}]`);\n this.#accountGroups.delete(groupIndex);\n }\n }\n\n this.#log('Synchronized');\n }\n\n /**\n * Gets the multichain account wallet ID.\n *\n * @returns The multichain account wallet ID.\n */\n get id(): MultichainAccountWalletId {\n return this.#id;\n }\n\n /**\n * Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.\n *\n * @returns The multichain account wallet type.\n */\n get type(): AccountWalletType.Entropy {\n return AccountWalletType.Entropy;\n }\n\n /**\n * Gets the multichain account wallet entropy source.\n *\n * @returns The multichain account wallet entropy source.\n */\n get entropySource(): EntropySourceId {\n return this.#entropySource;\n }\n\n /**\n * Gets the multichain account wallet current status.\n *\n * @returns The multichain account wallet current status.\n */\n get status(): MultichainAccountWalletStatus {\n return this.#status;\n }\n\n /**\n * Set the wallet status and run the associated operation callback.\n *\n * @param status - Wallet status associated with this operation.\n * @param operation - Operation to run.\n * @returns The operation's result.\n * @throws {Error} If the wallet is already running a mutable operation.\n */\n async #withLock<Return>(\n status: MultichainAccountWalletStatus,\n operation: () => Promise<Return>,\n ) {\n const release = await this.#lock.acquire();\n try {\n this.#log(`Locking wallet with status \"${status}\"...`);\n this.#status = status;\n this.#messenger.publish(\n 'MultichainAccountService:walletStatusChange',\n this.id,\n this.#status,\n );\n return await operation();\n } finally {\n this.#status = 'ready';\n this.#messenger.publish(\n 'MultichainAccountService:walletStatusChange',\n this.id,\n this.#status,\n );\n release();\n this.#log(`Releasing wallet lock (was \"${status}\")`);\n }\n }\n\n /**\n * Create accounts with non‑EVM providers. Optional throttling is managed by each provider internally.\n * When awaitAll is true, waits for all providers and throws if any failed.\n * When false, starts work in background and logs errors without throwing.\n *\n * @param options - Method options.\n * @param options.groupIndex - The group index to create accounts for.\n * @param options.providers - The non‑EVM account providers.\n * @param options.awaitAll - Whether to wait for all providers to finish.\n * @throws If awaitAll is true and any provider fails to create accounts.\n * @returns A promise that resolves when done (if awaitAll is true) or immediately (if false).\n */\n async #createNonEvmAccounts({\n groupIndex,\n providers,\n awaitAll,\n }: {\n groupIndex: number;\n providers: Bip44AccountProvider<Account>[];\n awaitAll: boolean;\n }): Promise<void> {\n if (awaitAll) {\n const tasks = providers.map((provider) =>\n provider\n .createAccounts({\n entropySource: this.#entropySource,\n groupIndex,\n })\n .catch((error) => {\n const sentryError = createSentryError(\n `Unable to create account with provider \"${provider.getName()}\"`,\n error,\n {\n groupIndex,\n provider: provider.getName(),\n },\n );\n this.#messenger.call(\n 'ErrorReportingService:captureException',\n sentryError,\n );\n throw error;\n }),\n );\n\n const results = await Promise.allSettled(tasks);\n if (results.some((r) => r.status === 'rejected')) {\n const errorMessage = toRejectedErrorMessage(\n `Unable to create multichain account group for index: ${groupIndex}`,\n results,\n );\n\n this.#log(`${WARNING_PREFIX} ${errorMessage}`);\n console.warn(errorMessage);\n throw new Error(errorMessage);\n }\n return;\n }\n\n // Background mode: start tasks and log errors.\n // Optional throttling is handled internally by each provider based on its config.\n providers.forEach((provider) => {\n // eslint-disable-next-line no-void\n void provider\n .createAccounts({\n entropySource: this.#entropySource,\n groupIndex,\n })\n .catch((error) => {\n const errorMessage = `Unable to create multichain account group for index: ${groupIndex} (background mode with provider \"${provider.getName()}\")`;\n this.#log(`${WARNING_PREFIX} ${errorMessage}:`, error);\n const sentryError = createSentryError(\n `Unable to create account with provider \"${provider.getName()}\"`,\n error,\n {\n groupIndex,\n provider: provider.getName(),\n },\n );\n this.#messenger.call(\n 'ErrorReportingService:captureException',\n sentryError,\n );\n });\n });\n }\n\n /**\n * Gets multichain account for a given ID.\n * The default group ID will default to the multichain account with index 0.\n *\n * @param id - Account group ID.\n * @returns Account group.\n */\n getAccountGroup(\n id: AccountGroupId,\n ): MultichainAccountGroup<Account> | undefined {\n // We consider the \"default case\" to be mapped to index 0.\n if (id === toDefaultAccountGroupId(this.id)) {\n return this.#accountGroups.get(0);\n }\n\n // If it is not a valid ID, we cannot extract the group index\n // from it, so we fail fast.\n if (!isMultichainAccountGroupId(id)) {\n return undefined;\n }\n\n const groupIndex = getGroupIndexFromMultichainAccountGroupId(id);\n return this.#accountGroups.get(groupIndex);\n }\n\n /**\n * Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccountGroups}.\n *\n * @returns The multichain accounts.\n */\n getAccountGroups(): MultichainAccountGroup<Account>[] {\n return this.getMultichainAccountGroups();\n }\n\n /**\n * Gets multichain account group for a given index.\n *\n * @param groupIndex - Multichain account index.\n * @returns The multichain account associated with the given index.\n */\n getMultichainAccountGroup(\n groupIndex: number,\n ): MultichainAccountGroup<Account> | undefined {\n return this.#accountGroups.get(groupIndex);\n }\n\n /**\n * Gets all multichain account groups.\n *\n * @returns The multichain accounts.\n */\n getMultichainAccountGroups(): MultichainAccountGroup<Account>[] {\n return Array.from(this.#accountGroups.values()); // TODO: Prevent copy here.\n }\n\n /**\n * Gets next group index for this wallet.\n *\n * @returns The next group index of this wallet.\n */\n getNextGroupIndex(): number {\n // We do not check for gaps.\n return (\n Math.max(\n -1, // So it will default to 0 if no groups.\n ...this.#accountGroups.keys(),\n ) + 1\n );\n }\n\n /**\n * Creates a multichain account group for a given group index.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n *\n * @param groupIndex - The group index to use.\n * @param options - Options to configure the account creation.\n * @param options.waitForAllProvidersToFinishCreatingAccounts - Whether to wait for all\n * account providers to finish creating their accounts before returning. If `false`, only\n * the EVM provider will be awaited, while all other providers will create their accounts\n * in the background. Defaults to `false`.\n * @throws If any of the account providers fails to create their accounts and\n * the `waitForAllProvidersToFinishCreatingAccounts` option is set to `true`. If `false`,\n * errors from non-EVM providers will be logged but ignored, and only errors from the\n * EVM provider will be thrown.\n * @returns The multichain account group for this group index.\n */\n async createMultichainAccountGroup(\n groupIndex: number,\n options: {\n waitForAllProvidersToFinishCreatingAccounts?: boolean;\n } = { waitForAllProvidersToFinishCreatingAccounts: false },\n ): Promise<MultichainAccountGroup<Account>> {\n return await this.#withLock('in-progress:create-accounts', async () => {\n const nextGroupIndex = this.getNextGroupIndex();\n if (groupIndex > nextGroupIndex) {\n throw new Error(\n `You cannot use a group index that is higher than the next available one: expected <=${nextGroupIndex}, got ${groupIndex}`,\n );\n }\n\n let group = this.getMultichainAccountGroup(groupIndex);\n if (group) {\n // If the group already exists, we just `sync` it and returns the same\n // reference.\n group.sync();\n\n this.#log(\n `Trying to re-create existing group: [${group.id}] (idempotent)`,\n );\n return group;\n }\n\n this.#log(`Creating new group for index ${groupIndex}...`);\n\n // Extract the EVM provider from the list of providers.\n // We always await EVM account creation first.\n const [evmProvider, ...otherProviders] = this.#providers;\n assert(\n evmProvider instanceof EvmAccountProvider,\n 'EVM account provider must be first',\n );\n\n try {\n await evmProvider.createAccounts({\n entropySource: this.#entropySource,\n groupIndex,\n });\n } catch (error) {\n const errorMessage = `Unable to create multichain account group for index: ${groupIndex} with provider \"${evmProvider.getName()}\". Error: ${(error as Error).message}`;\n this.#log(`${ERROR_PREFIX} ${errorMessage}:`, error);\n const sentryError = createSentryError(\n `Unable to create account with provider \"${evmProvider.getName()}\"`,\n error as Error,\n {\n groupIndex,\n provider: evmProvider.getName(),\n },\n );\n this.#messenger.call(\n 'ErrorReportingService:captureException',\n sentryError,\n );\n throw new Error(errorMessage);\n }\n\n // We then create accounts with other providers (some being throttled if configured).\n // Depending on the options, we either await all providers or run them in background.\n if (options?.waitForAllProvidersToFinishCreatingAccounts) {\n await this.#createNonEvmAccounts({\n groupIndex,\n providers: otherProviders,\n awaitAll: true,\n });\n } else {\n // eslint-disable-next-line no-void\n void this.#createNonEvmAccounts({\n groupIndex,\n providers: otherProviders,\n awaitAll: false,\n });\n }\n\n // --------------------------------------------------------------------------------\n // READ THIS CAREFULLY:\n //\n // Since we're not \"fully supporting multichain\" for now, we still rely on single\n // :accountCreated events to sync multichain account groups and wallets. Which means\n // that even if of the provider fails, some accounts will still be created on some\n // other providers and will become \"available\" on the `AccountsController`, like:\n //\n // 1. Creating a multichain account group for index 1\n // 2. EvmAccountProvider.createAccounts returns the EVM account for index 1\n // * AccountsController WILL fire :accountCreated for this account\n // * This account WILL BE \"available\" on the AccountsController state\n // 3. SolAccountProvider.createAccounts fails to create a Solana account for index 1\n // * AccountsController WON't fire :accountCreated for this account\n // * This account WON'T be \"available\" on the Account\n // 4. MultichainAccountService will receive a :accountCreated for the EVM account from\n // step 2 and will create a new multichain account group for index 1, but it won't\n // receive any event for the Solana account of this group. Thus, this group won't be\n // \"aligned\" (missing \"blockchain account\" on this group).\n //\n // --------------------------------------------------------------------------------\n\n // Because of the :accountAdded automatic sync, we might already have created the\n // group, so we first try to get it.\n group = this.getMultichainAccountGroup(groupIndex);\n if (!group) {\n // If for some reason it's still not created, we're creating it explicitly now:\n group = new MultichainAccountGroup({\n wallet: this,\n providers: this.#providers,\n groupIndex,\n messenger: this.#messenger,\n });\n }\n\n // Register the account to our internal map.\n this.#accountGroups.set(groupIndex, group); // `group` cannot be undefined here.\n this.#log(`New group created: [${group.id}]`);\n\n if (this.#initialized) {\n this.#messenger.publish(\n 'MultichainAccountService:multichainAccountGroupCreated',\n group,\n );\n }\n\n return group;\n });\n }\n\n /**\n * Creates the next multichain account group.\n *\n * @throws If any of the account providers fails to create their accounts.\n * @returns The multichain account group for the next group index available.\n */\n async createNextMultichainAccountGroup(): Promise<\n MultichainAccountGroup<Account>\n > {\n return this.createMultichainAccountGroup(this.getNextGroupIndex(), {\n waitForAllProvidersToFinishCreatingAccounts: true,\n });\n }\n\n /**\n * Align all multichain account groups.\n *\n * NOTE: This operation WILL NOT lock the wallet's mutex.\n */\n async #alignAccounts(): Promise<void> {\n const groups = this.getMultichainAccountGroups();\n await Promise.all(groups.map((group) => group.alignAccounts()));\n }\n\n /**\n * Align all accounts from each existing multichain account groups.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n */\n async alignAccounts(): Promise<void> {\n await this.#withLock('in-progress:alignment', async () => {\n await this.#alignAccounts();\n });\n }\n\n /**\n * Align a specific multichain account group.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n *\n * @param groupIndex - The group index to align.\n */\n async alignAccountsOf(groupIndex: number): Promise<void> {\n await this.#withLock('in-progress:alignment', async () => {\n const group = this.getMultichainAccountGroup(groupIndex);\n if (group) {\n await group.alignAccounts();\n }\n });\n }\n\n /**\n * Discover and create accounts for all providers.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n *\n * @returns The discovered accounts for each provider.\n */\n async discoverAccounts(): Promise<Account[]> {\n return this.#withLock('in-progress:discovery', async () => {\n // Start with the next available group index (so we can resume the discovery\n // from there).\n let maxGroupIndex = this.getNextGroupIndex();\n\n // One serialized loop per provider; all run concurrently\n const runProviderDiscovery = async (\n context: AccountProviderDiscoveryContext<Account>,\n ) => {\n const providerName = context.provider.getName();\n const message = (stepName: string, groupIndex: number) =>\n `[${providerName}] Discovery ${stepName} for group index: ${groupIndex}`;\n\n while (!context.stopped) {\n // Fast‑forward to current high‑water mark\n const targetGroupIndex = Math.max(context.groupIndex, maxGroupIndex);\n\n log(message('started', targetGroupIndex));\n\n let accounts: Account[] = [];\n try {\n accounts = await context.provider.discoverAccounts({\n entropySource: this.#entropySource,\n groupIndex: targetGroupIndex,\n });\n } catch (error) {\n context.stopped = true;\n console.error(error);\n log(\n message(\n `failed (with: \"${(error as Error).message}\")`,\n targetGroupIndex,\n ),\n error,\n );\n const sentryError = createSentryError(\n 'Unable to discover accounts',\n error as Error,\n {\n provider: providerName,\n groupIndex: targetGroupIndex,\n },\n );\n this.#messenger.call(\n 'ErrorReportingService:captureException',\n sentryError,\n );\n break;\n }\n\n if (!accounts.length) {\n log(\n message('stopped (no accounts got discovered)', targetGroupIndex),\n );\n context.stopped = true;\n break;\n }\n\n log(message('**succeeded**', targetGroupIndex));\n\n context.accounts = context.accounts.concat(accounts);\n\n const nextGroupIndex = targetGroupIndex + 1;\n context.groupIndex = nextGroupIndex;\n\n if (nextGroupIndex > maxGroupIndex) {\n maxGroupIndex = nextGroupIndex;\n }\n }\n };\n\n const providerContexts: AccountProviderDiscoveryContext<Account>[] =\n this.#providers.map((provider) => ({\n provider,\n stopped: false,\n groupIndex: maxGroupIndex,\n accounts: [],\n }));\n\n // Start discovery for each providers.\n await Promise.all(providerContexts.map(runProviderDiscovery));\n\n // Sync the wallet after discovery to ensure that the newly added accounts are added into their groups.\n // We can potentially remove this if we know that this race condition is not an issue in practice.\n this.sync();\n\n // Align missing accounts from group. This is required to create missing account from non-discovered\n // indexes for some providers.\n await this.#alignAccounts();\n\n return providerContexts.flatMap((context) => context.accounts);\n });\n }\n}\n"]}
|
|
@@ -2,10 +2,8 @@ import type { AccountGroupId, Bip44Account, MultichainAccountWalletId, Multichai
|
|
|
2
2
|
import { AccountWalletType } from "@metamask/account-api";
|
|
3
3
|
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
4
4
|
import { MultichainAccountGroup } from "./MultichainAccountGroup.cjs";
|
|
5
|
-
import type { ServiceState, StateKeys } from "./MultichainAccountService.cjs";
|
|
6
5
|
import { type Bip44AccountProvider } from "./providers/index.cjs";
|
|
7
6
|
import type { MultichainAccountServiceMessenger } from "./types.cjs";
|
|
8
|
-
export type WalletState = ServiceState[StateKeys['entropySource']];
|
|
9
7
|
/**
|
|
10
8
|
* A multichain account wallet that holds multiple multichain accounts (one multichain account per
|
|
11
9
|
* group index).
|
|
@@ -18,11 +16,12 @@ export declare class MultichainAccountWallet<Account extends Bip44Account<Keyrin
|
|
|
18
16
|
messenger: MultichainAccountServiceMessenger;
|
|
19
17
|
});
|
|
20
18
|
/**
|
|
21
|
-
*
|
|
19
|
+
* Force wallet synchronization.
|
|
22
20
|
*
|
|
23
|
-
*
|
|
21
|
+
* This can be used if account providers got new accounts that the wallet
|
|
22
|
+
* doesn't know about.
|
|
24
23
|
*/
|
|
25
|
-
|
|
24
|
+
sync(): void;
|
|
26
25
|
/**
|
|
27
26
|
* Gets the multichain account wallet ID.
|
|
28
27
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainAccountWallet.d.cts","sourceRoot":"","sources":["../src/MultichainAccountWallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,yBAAyB,EACzB,uBAAuB,IAAI,iCAAiC,EAC5D,6BAA6B,EAC9B,8BAA8B;AAC/B,OAAO,EACL,iBAAiB,EAKlB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAW7E,OAAO,
|
|
1
|
+
{"version":3,"file":"MultichainAccountWallet.d.cts","sourceRoot":"","sources":["../src/MultichainAccountWallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,yBAAyB,EACzB,uBAAuB,IAAI,iCAAiC,EAC5D,6BAA6B,EAC9B,8BAA8B;AAC/B,OAAO,EACL,iBAAiB,EAKlB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAW7E,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAsB,KAAK,oBAAoB,EAAE,8BAAoB;AAC5E,OAAO,KAAK,EAAE,iCAAiC,EAAE,oBAAgB;AAejE;;;GAGG;AACH,qBAAa,uBAAuB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MpC;;;;;;OAMG;IACG,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASxD;;;;;;OAMG;IACG,gBAAgB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CA8F7C"}
|
|
@@ -2,10 +2,8 @@ import type { AccountGroupId, Bip44Account, MultichainAccountWalletId, Multichai
|
|
|
2
2
|
import { AccountWalletType } from "@metamask/account-api";
|
|
3
3
|
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
4
4
|
import { MultichainAccountGroup } from "./MultichainAccountGroup.mjs";
|
|
5
|
-
import type { ServiceState, StateKeys } from "./MultichainAccountService.mjs";
|
|
6
5
|
import { type Bip44AccountProvider } from "./providers/index.mjs";
|
|
7
6
|
import type { MultichainAccountServiceMessenger } from "./types.mjs";
|
|
8
|
-
export type WalletState = ServiceState[StateKeys['entropySource']];
|
|
9
7
|
/**
|
|
10
8
|
* A multichain account wallet that holds multiple multichain accounts (one multichain account per
|
|
11
9
|
* group index).
|
|
@@ -18,11 +16,12 @@ export declare class MultichainAccountWallet<Account extends Bip44Account<Keyrin
|
|
|
18
16
|
messenger: MultichainAccountServiceMessenger;
|
|
19
17
|
});
|
|
20
18
|
/**
|
|
21
|
-
*
|
|
19
|
+
* Force wallet synchronization.
|
|
22
20
|
*
|
|
23
|
-
*
|
|
21
|
+
* This can be used if account providers got new accounts that the wallet
|
|
22
|
+
* doesn't know about.
|
|
24
23
|
*/
|
|
25
|
-
|
|
24
|
+
sync(): void;
|
|
26
25
|
/**
|
|
27
26
|
* Gets the multichain account wallet ID.
|
|
28
27
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainAccountWallet.d.mts","sourceRoot":"","sources":["../src/MultichainAccountWallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,yBAAyB,EACzB,uBAAuB,IAAI,iCAAiC,EAC5D,6BAA6B,EAC9B,8BAA8B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;;OAIG;IACH,gBAAgB,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE;IAIrD;;;;;OAKG;IACH,yBAAyB,CACvB,UAAU,EAAE,MAAM,GACjB,sBAAsB,CAAC,OAAO,CAAC,GAAG,SAAS;IAI9C;;;;OAIG;IACH,0BAA0B,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE;IAI/D;;;;OAIG;IACH,iBAAiB,IAAI,MAAM;IAU3B;;;;;;;;;;;;;;;;OAgBG;IACG,4BAA4B,CAChC,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE;QACP,2CAA2C,CAAC,EAAE,OAAO,CAAC;KACE,GACzD,OAAO,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAyH3C;;;;;OAKG;IACG,gCAAgC,IAAI,OAAO,CAC/C,sBAAsB,CAAC,OAAO,CAAC,CAChC;IAgBD;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAMpC;;;;;;OAMG;IACG,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASxD;;;;;;OAMG;IACG,gBAAgB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CA8F7C"}
|
|
@@ -16,7 +16,7 @@ import { Mutex } from "async-mutex";
|
|
|
16
16
|
import { createModuleLogger, ERROR_PREFIX, projectLogger as log, WARNING_PREFIX } from "./logger.mjs";
|
|
17
17
|
import { MultichainAccountGroup } from "./MultichainAccountGroup.mjs";
|
|
18
18
|
import { EvmAccountProvider } from "./providers/index.mjs";
|
|
19
|
-
import { createSentryError } from "./utils.mjs";
|
|
19
|
+
import { createSentryError, toRejectedErrorMessage } from "./utils.mjs";
|
|
20
20
|
/**
|
|
21
21
|
* A multichain account wallet that holds multiple multichain accounts (one multichain account per
|
|
22
22
|
* group index).
|
|
@@ -31,6 +31,7 @@ export class MultichainAccountWallet {
|
|
|
31
31
|
_MultichainAccountWallet_accountGroups.set(this, void 0);
|
|
32
32
|
_MultichainAccountWallet_messenger.set(this, void 0);
|
|
33
33
|
_MultichainAccountWallet_log.set(this, void 0);
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly
|
|
34
35
|
_MultichainAccountWallet_initialized.set(this, false);
|
|
35
36
|
_MultichainAccountWallet_status.set(this, void 0);
|
|
36
37
|
__classPrivateFieldSet(this, _MultichainAccountWallet_id, toMultichainAccountWalletId(entropySource), "f");
|
|
@@ -41,32 +42,58 @@ export class MultichainAccountWallet {
|
|
|
41
42
|
__classPrivateFieldSet(this, _MultichainAccountWallet_log, createModuleLogger(log, `[${__classPrivateFieldGet(this, _MultichainAccountWallet_id, "f")}]`), "f");
|
|
42
43
|
// Initial synchronization (don't emit events during initialization).
|
|
43
44
|
__classPrivateFieldSet(this, _MultichainAccountWallet_status, 'uninitialized', "f");
|
|
45
|
+
this.sync();
|
|
46
|
+
__classPrivateFieldSet(this, _MultichainAccountWallet_initialized, true, "f");
|
|
47
|
+
__classPrivateFieldSet(this, _MultichainAccountWallet_status, 'ready', "f");
|
|
44
48
|
}
|
|
45
49
|
/**
|
|
46
|
-
*
|
|
50
|
+
* Force wallet synchronization.
|
|
47
51
|
*
|
|
48
|
-
*
|
|
52
|
+
* This can be used if account providers got new accounts that the wallet
|
|
53
|
+
* doesn't know about.
|
|
49
54
|
*/
|
|
50
|
-
|
|
51
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, '
|
|
52
|
-
for (const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
sync() {
|
|
56
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, 'Synchronizing with account providers...');
|
|
57
|
+
for (const provider of __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f")) {
|
|
58
|
+
for (const account of provider.getAccounts()) {
|
|
59
|
+
const { entropy } = account.options;
|
|
60
|
+
// Filter for this wallet only.
|
|
61
|
+
if (entropy.id !== this.entropySource) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
// This multichain account might exists already.
|
|
65
|
+
let multichainAccount = __classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").get(entropy.groupIndex);
|
|
66
|
+
if (!multichainAccount) {
|
|
67
|
+
multichainAccount = new MultichainAccountGroup({
|
|
68
|
+
groupIndex: entropy.groupIndex,
|
|
69
|
+
wallet: this,
|
|
70
|
+
providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
|
|
71
|
+
messenger: __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f"),
|
|
72
|
+
});
|
|
73
|
+
// This existing multichain account group might differ from the
|
|
74
|
+
// `createMultichainAccountGroup` behavior. When creating a new
|
|
75
|
+
// group, we expect the providers to all succeed. But here, we're
|
|
76
|
+
// just fetching the account lists from them, so this group might
|
|
77
|
+
// not be "aligned" yet (e.g having a missing Solana account).
|
|
78
|
+
//
|
|
79
|
+
// Since "aligning" is an async operation, it would have to be run
|
|
80
|
+
// after the first-sync.
|
|
81
|
+
// TODO: Implement align mechanism to create "missing" accounts.
|
|
82
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Found a new group: [${multichainAccount.id}]`);
|
|
83
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").set(entropy.groupIndex, multichainAccount);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
64
86
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
87
|
+
// Now force-sync all remaining multichain accounts.
|
|
88
|
+
for (const [groupIndex, multichainAccount,] of __classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").entries()) {
|
|
89
|
+
multichainAccount.sync();
|
|
90
|
+
// Clean up old multichain accounts.
|
|
91
|
+
if (!multichainAccount.hasAccounts()) {
|
|
92
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Deleting group: [${multichainAccount.id}]`);
|
|
93
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").delete(groupIndex);
|
|
94
|
+
}
|
|
68
95
|
}
|
|
69
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, '
|
|
96
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, 'Synchronized');
|
|
70
97
|
}
|
|
71
98
|
/**
|
|
72
99
|
* Gets the multichain account wallet ID.
|
|
@@ -180,6 +207,9 @@ export class MultichainAccountWallet {
|
|
|
180
207
|
}
|
|
181
208
|
let group = this.getMultichainAccountGroup(groupIndex);
|
|
182
209
|
if (group) {
|
|
210
|
+
// If the group already exists, we just `sync` it and returns the same
|
|
211
|
+
// reference.
|
|
212
|
+
group.sync();
|
|
183
213
|
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Trying to re-create existing group: [${group.id}] (idempotent)`);
|
|
184
214
|
return group;
|
|
185
215
|
}
|
|
@@ -188,30 +218,22 @@ export class MultichainAccountWallet {
|
|
|
188
218
|
// We always await EVM account creation first.
|
|
189
219
|
const [evmProvider, ...otherProviders] = __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f");
|
|
190
220
|
assert(evmProvider instanceof EvmAccountProvider, 'EVM account provider must be first');
|
|
191
|
-
|
|
192
|
-
.createAccounts({
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const errorMessage = `Unable to create
|
|
199
|
-
console.warn(errorMessage);
|
|
221
|
+
try {
|
|
222
|
+
await evmProvider.createAccounts({
|
|
223
|
+
entropySource: __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f"),
|
|
224
|
+
groupIndex,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
const errorMessage = `Unable to create multichain account group for index: ${groupIndex} with provider "${evmProvider.getName()}". Error: ${error.message}`;
|
|
200
229
|
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${ERROR_PREFIX} ${errorMessage}:`, error);
|
|
201
230
|
const sentryError = createSentryError(`Unable to create account with provider "${evmProvider.getName()}"`, error, {
|
|
202
231
|
groupIndex,
|
|
203
232
|
provider: evmProvider.getName(),
|
|
204
233
|
});
|
|
205
234
|
__classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").call('ErrorReportingService:captureException', sentryError);
|
|
206
|
-
throw
|
|
207
|
-
}
|
|
208
|
-
group = new MultichainAccountGroup({
|
|
209
|
-
wallet: this,
|
|
210
|
-
providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
|
|
211
|
-
groupIndex,
|
|
212
|
-
messenger: __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f"),
|
|
213
|
-
});
|
|
214
|
-
group.init({ [evmProvider.getName()]: evmAccounts });
|
|
235
|
+
throw new Error(errorMessage);
|
|
236
|
+
}
|
|
215
237
|
// We then create accounts with other providers (some being throttled if configured).
|
|
216
238
|
// Depending on the options, we either await all providers or run them in background.
|
|
217
239
|
if (options?.waitForAllProvidersToFinishCreatingAccounts) {
|
|
@@ -219,7 +241,6 @@ export class MultichainAccountWallet {
|
|
|
219
241
|
groupIndex,
|
|
220
242
|
providers: otherProviders,
|
|
221
243
|
awaitAll: true,
|
|
222
|
-
group,
|
|
223
244
|
});
|
|
224
245
|
}
|
|
225
246
|
else {
|
|
@@ -228,11 +249,43 @@ export class MultichainAccountWallet {
|
|
|
228
249
|
groupIndex,
|
|
229
250
|
providers: otherProviders,
|
|
230
251
|
awaitAll: false,
|
|
231
|
-
group,
|
|
232
252
|
});
|
|
233
253
|
}
|
|
234
|
-
//
|
|
235
|
-
|
|
254
|
+
// --------------------------------------------------------------------------------
|
|
255
|
+
// READ THIS CAREFULLY:
|
|
256
|
+
//
|
|
257
|
+
// Since we're not "fully supporting multichain" for now, we still rely on single
|
|
258
|
+
// :accountCreated events to sync multichain account groups and wallets. Which means
|
|
259
|
+
// that even if of the provider fails, some accounts will still be created on some
|
|
260
|
+
// other providers and will become "available" on the `AccountsController`, like:
|
|
261
|
+
//
|
|
262
|
+
// 1. Creating a multichain account group for index 1
|
|
263
|
+
// 2. EvmAccountProvider.createAccounts returns the EVM account for index 1
|
|
264
|
+
// * AccountsController WILL fire :accountCreated for this account
|
|
265
|
+
// * This account WILL BE "available" on the AccountsController state
|
|
266
|
+
// 3. SolAccountProvider.createAccounts fails to create a Solana account for index 1
|
|
267
|
+
// * AccountsController WON't fire :accountCreated for this account
|
|
268
|
+
// * This account WON'T be "available" on the Account
|
|
269
|
+
// 4. MultichainAccountService will receive a :accountCreated for the EVM account from
|
|
270
|
+
// step 2 and will create a new multichain account group for index 1, but it won't
|
|
271
|
+
// receive any event for the Solana account of this group. Thus, this group won't be
|
|
272
|
+
// "aligned" (missing "blockchain account" on this group).
|
|
273
|
+
//
|
|
274
|
+
// --------------------------------------------------------------------------------
|
|
275
|
+
// Because of the :accountAdded automatic sync, we might already have created the
|
|
276
|
+
// group, so we first try to get it.
|
|
277
|
+
group = this.getMultichainAccountGroup(groupIndex);
|
|
278
|
+
if (!group) {
|
|
279
|
+
// If for some reason it's still not created, we're creating it explicitly now:
|
|
280
|
+
group = new MultichainAccountGroup({
|
|
281
|
+
wallet: this,
|
|
282
|
+
providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
|
|
283
|
+
groupIndex,
|
|
284
|
+
messenger: __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f"),
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
// Register the account to our internal map.
|
|
288
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").set(groupIndex, group); // `group` cannot be undefined here.
|
|
236
289
|
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `New group created: [${group.id}]`);
|
|
237
290
|
if (__classPrivateFieldGet(this, _MultichainAccountWallet_initialized, "f")) {
|
|
238
291
|
__classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").publish('MultichainAccountService:multichainAccountGroupCreated', group);
|
|
@@ -288,12 +341,6 @@ export class MultichainAccountWallet {
|
|
|
288
341
|
// Start with the next available group index (so we can resume the discovery
|
|
289
342
|
// from there).
|
|
290
343
|
let maxGroupIndex = this.getNextGroupIndex();
|
|
291
|
-
const discoveredGroupsState = {};
|
|
292
|
-
const addDiscoveryResultToState = (result, providerName, groupIndex) => {
|
|
293
|
-
const accountIds = result.map((account) => account.id);
|
|
294
|
-
discoveredGroupsState[groupIndex] ?? (discoveredGroupsState[groupIndex] = {});
|
|
295
|
-
discoveredGroupsState[groupIndex][providerName] = accountIds;
|
|
296
|
-
};
|
|
297
344
|
// One serialized loop per provider; all run concurrently
|
|
298
345
|
const runProviderDiscovery = async (context) => {
|
|
299
346
|
const providerName = context.provider.getName();
|
|
@@ -304,10 +351,10 @@ export class MultichainAccountWallet {
|
|
|
304
351
|
log(message('started', targetGroupIndex));
|
|
305
352
|
let accounts = [];
|
|
306
353
|
try {
|
|
307
|
-
accounts =
|
|
354
|
+
accounts = await context.provider.discoverAccounts({
|
|
308
355
|
entropySource: __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f"),
|
|
309
356
|
groupIndex: targetGroupIndex,
|
|
310
|
-
})
|
|
357
|
+
});
|
|
311
358
|
}
|
|
312
359
|
catch (error) {
|
|
313
360
|
context.stopped = true;
|
|
@@ -327,7 +374,6 @@ export class MultichainAccountWallet {
|
|
|
327
374
|
}
|
|
328
375
|
log(message('**succeeded**', targetGroupIndex));
|
|
329
376
|
context.accounts = context.accounts.concat(accounts);
|
|
330
|
-
addDiscoveryResultToState(accounts, providerName, targetGroupIndex);
|
|
331
377
|
const nextGroupIndex = targetGroupIndex + 1;
|
|
332
378
|
context.groupIndex = nextGroupIndex;
|
|
333
379
|
if (nextGroupIndex > maxGroupIndex) {
|
|
@@ -343,18 +389,9 @@ export class MultichainAccountWallet {
|
|
|
343
389
|
}));
|
|
344
390
|
// Start discovery for each providers.
|
|
345
391
|
await Promise.all(providerContexts.map(runProviderDiscovery));
|
|
346
|
-
//
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const group = new MultichainAccountGroup({
|
|
350
|
-
wallet: this,
|
|
351
|
-
providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
|
|
352
|
-
groupIndex,
|
|
353
|
-
messenger: __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f"),
|
|
354
|
-
});
|
|
355
|
-
group.init(groupState);
|
|
356
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").set(groupIndex, group);
|
|
357
|
-
}
|
|
392
|
+
// Sync the wallet after discovery to ensure that the newly added accounts are added into their groups.
|
|
393
|
+
// We can potentially remove this if we know that this race condition is not an issue in practice.
|
|
394
|
+
this.sync();
|
|
358
395
|
// Align missing accounts from group. This is required to create missing account from non-discovered
|
|
359
396
|
// indexes for some providers.
|
|
360
397
|
await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_alignAccounts).call(this);
|
|
@@ -395,11 +432,10 @@ async function _MultichainAccountWallet_withLock(status, operation) {
|
|
|
395
432
|
* @param options.groupIndex - The group index to create accounts for.
|
|
396
433
|
* @param options.providers - The non‑EVM account providers.
|
|
397
434
|
* @param options.awaitAll - Whether to wait for all providers to finish.
|
|
398
|
-
* @param options.group - The group object pertaining to the group index to create accounts for.
|
|
399
435
|
* @throws If awaitAll is true and any provider fails to create accounts.
|
|
400
436
|
* @returns A promise that resolves when done (if awaitAll is true) or immediately (if false).
|
|
401
437
|
*/
|
|
402
|
-
async function _MultichainAccountWallet_createNonEvmAccounts({ groupIndex, providers, awaitAll,
|
|
438
|
+
async function _MultichainAccountWallet_createNonEvmAccounts({ groupIndex, providers, awaitAll, }) {
|
|
403
439
|
if (awaitAll) {
|
|
404
440
|
const tasks = providers.map((provider) => provider
|
|
405
441
|
.createAccounts({
|
|
@@ -415,53 +451,33 @@ async function _MultichainAccountWallet_createNonEvmAccounts({ groupIndex, provi
|
|
|
415
451
|
throw error;
|
|
416
452
|
}));
|
|
417
453
|
const results = await Promise.allSettled(tasks);
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}, '');
|
|
424
|
-
if (providerFailures.length) {
|
|
425
|
-
// We warn there's failures on some providers and thus misalignment, but we still create the group
|
|
426
|
-
const message = `Unable to create some accounts for group index: ${groupIndex}. Providers threw the following errors:${providerFailures}`;
|
|
427
|
-
console.warn(message);
|
|
428
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${WARNING_PREFIX} ${message}`);
|
|
454
|
+
if (results.some((r) => r.status === 'rejected')) {
|
|
455
|
+
const errorMessage = toRejectedErrorMessage(`Unable to create multichain account group for index: ${groupIndex}`, results);
|
|
456
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${WARNING_PREFIX} ${errorMessage}`);
|
|
457
|
+
console.warn(errorMessage);
|
|
458
|
+
throw new Error(errorMessage);
|
|
429
459
|
}
|
|
430
|
-
|
|
431
|
-
const groupState = results.reduce((state, result, idx) => {
|
|
432
|
-
if (result.status === 'fulfilled') {
|
|
433
|
-
state[providers[idx].getName()] = result.value.map((account) => account.id);
|
|
434
|
-
}
|
|
435
|
-
return state;
|
|
436
|
-
}, {});
|
|
437
|
-
group.update(groupState);
|
|
460
|
+
return;
|
|
438
461
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
462
|
+
// Background mode: start tasks and log errors.
|
|
463
|
+
// Optional throttling is handled internally by each provider based on its config.
|
|
464
|
+
providers.forEach((provider) => {
|
|
465
|
+
// eslint-disable-next-line no-void
|
|
466
|
+
void provider
|
|
467
|
+
.createAccounts({
|
|
468
|
+
entropySource: __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f"),
|
|
469
|
+
groupIndex,
|
|
470
|
+
})
|
|
471
|
+
.catch((error) => {
|
|
472
|
+
const errorMessage = `Unable to create multichain account group for index: ${groupIndex} (background mode with provider "${provider.getName()}")`;
|
|
473
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${WARNING_PREFIX} ${errorMessage}:`, error);
|
|
474
|
+
const sentryError = createSentryError(`Unable to create account with provider "${provider.getName()}"`, error, {
|
|
445
475
|
groupIndex,
|
|
446
|
-
|
|
447
|
-
.then((accounts) => {
|
|
448
|
-
const accountIds = accounts.map((account) => account.id);
|
|
449
|
-
group.update({ [provider.getName()]: accountIds });
|
|
450
|
-
return group;
|
|
451
|
-
})
|
|
452
|
-
.catch((error) => {
|
|
453
|
-
// Log errors from background providers but don't fail the operation
|
|
454
|
-
const errorMessage = `Unable to create some accounts for group index: ${groupIndex} with provider "${provider.getName()}". Error: ${error.message}`;
|
|
455
|
-
console.warn(errorMessage);
|
|
456
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${WARNING_PREFIX} ${errorMessage}:`, error);
|
|
457
|
-
const sentryError = createSentryError(`Unable to create account with provider "${provider.getName()}"`, error, {
|
|
458
|
-
groupIndex,
|
|
459
|
-
provider: provider.getName(),
|
|
460
|
-
});
|
|
461
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").call('ErrorReportingService:captureException', sentryError);
|
|
476
|
+
provider: provider.getName(),
|
|
462
477
|
});
|
|
478
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").call('ErrorReportingService:captureException', sentryError);
|
|
463
479
|
});
|
|
464
|
-
}
|
|
480
|
+
});
|
|
465
481
|
}, _MultichainAccountWallet_alignAccounts =
|
|
466
482
|
/**
|
|
467
483
|
* Align all multichain account groups.
|