@metamask/multichain-account-service 8.0.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -12
- package/dist/MultichainAccountGroup.cjs.map +1 -1
- package/dist/MultichainAccountGroup.d.cts.map +1 -1
- package/dist/MultichainAccountGroup.d.mts.map +1 -1
- package/dist/MultichainAccountGroup.mjs.map +1 -1
- package/dist/MultichainAccountService-method-action-types.cjs.map +1 -1
- package/dist/MultichainAccountService-method-action-types.d.cts +9 -1
- package/dist/MultichainAccountService-method-action-types.d.cts.map +1 -1
- package/dist/MultichainAccountService-method-action-types.d.mts +9 -1
- package/dist/MultichainAccountService-method-action-types.d.mts.map +1 -1
- package/dist/MultichainAccountService-method-action-types.mjs.map +1 -1
- package/dist/MultichainAccountService.cjs +1 -0
- package/dist/MultichainAccountService.cjs.map +1 -1
- package/dist/MultichainAccountService.d.cts.map +1 -1
- package/dist/MultichainAccountService.d.mts.map +1 -1
- package/dist/MultichainAccountService.mjs +1 -0
- package/dist/MultichainAccountService.mjs.map +1 -1
- package/dist/MultichainAccountWallet.cjs.map +1 -1
- package/dist/MultichainAccountWallet.d.cts.map +1 -1
- package/dist/MultichainAccountWallet.d.mts.map +1 -1
- package/dist/MultichainAccountWallet.mjs.map +1 -1
- package/dist/analytics/perf.cjs +1 -1
- package/dist/analytics/perf.cjs.map +1 -1
- package/dist/analytics/perf.mjs +1 -1
- package/dist/analytics/perf.mjs.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +2 -2
- package/dist/errors.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providers/AccountProviderWrapper.cjs.map +1 -1
- package/dist/providers/AccountProviderWrapper.d.cts +3 -2
- package/dist/providers/AccountProviderWrapper.d.cts.map +1 -1
- package/dist/providers/AccountProviderWrapper.d.mts +3 -2
- package/dist/providers/AccountProviderWrapper.d.mts.map +1 -1
- package/dist/providers/AccountProviderWrapper.mjs.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.cjs +29 -0
- package/dist/providers/BaseBip44AccountProvider.cjs.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.d.cts +29 -2
- package/dist/providers/BaseBip44AccountProvider.d.cts.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.d.mts +29 -2
- package/dist/providers/BaseBip44AccountProvider.d.mts.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.mjs +29 -0
- package/dist/providers/BaseBip44AccountProvider.mjs.map +1 -1
- package/dist/providers/BtcAccountProvider.cjs +2 -2
- package/dist/providers/BtcAccountProvider.cjs.map +1 -1
- package/dist/providers/BtcAccountProvider.d.cts +3 -2
- package/dist/providers/BtcAccountProvider.d.cts.map +1 -1
- package/dist/providers/BtcAccountProvider.d.mts +3 -2
- package/dist/providers/BtcAccountProvider.d.mts.map +1 -1
- package/dist/providers/BtcAccountProvider.mjs +2 -2
- package/dist/providers/BtcAccountProvider.mjs.map +1 -1
- package/dist/providers/EvmAccountProvider.cjs +63 -46
- package/dist/providers/EvmAccountProvider.cjs.map +1 -1
- package/dist/providers/EvmAccountProvider.d.cts +3 -2
- package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
- package/dist/providers/EvmAccountProvider.d.mts +3 -2
- package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
- package/dist/providers/EvmAccountProvider.mjs +63 -46
- package/dist/providers/EvmAccountProvider.mjs.map +1 -1
- package/dist/providers/SnapAccountProvider.cjs +2 -2
- package/dist/providers/SnapAccountProvider.cjs.map +1 -1
- package/dist/providers/SnapAccountProvider.d.cts +1 -1
- package/dist/providers/SnapAccountProvider.d.cts.map +1 -1
- package/dist/providers/SnapAccountProvider.d.mts +1 -1
- package/dist/providers/SnapAccountProvider.d.mts.map +1 -1
- package/dist/providers/SnapAccountProvider.mjs +2 -2
- package/dist/providers/SnapAccountProvider.mjs.map +1 -1
- package/dist/providers/SolAccountProvider.cjs +2 -2
- package/dist/providers/SolAccountProvider.cjs.map +1 -1
- package/dist/providers/SolAccountProvider.d.cts +3 -2
- package/dist/providers/SolAccountProvider.d.cts.map +1 -1
- package/dist/providers/SolAccountProvider.d.mts +3 -2
- package/dist/providers/SolAccountProvider.d.mts.map +1 -1
- package/dist/providers/SolAccountProvider.mjs +2 -2
- package/dist/providers/SolAccountProvider.mjs.map +1 -1
- package/dist/providers/TrxAccountProvider.cjs +2 -2
- package/dist/providers/TrxAccountProvider.cjs.map +1 -1
- package/dist/providers/TrxAccountProvider.d.cts +3 -2
- package/dist/providers/TrxAccountProvider.d.cts.map +1 -1
- package/dist/providers/TrxAccountProvider.d.mts +3 -2
- package/dist/providers/TrxAccountProvider.d.mts.map +1 -1
- package/dist/providers/TrxAccountProvider.mjs +2 -2
- package/dist/providers/TrxAccountProvider.mjs.map +1 -1
- package/dist/providers/utils.cjs +13 -1
- package/dist/providers/utils.cjs.map +1 -1
- package/dist/providers/utils.d.cts +7 -0
- package/dist/providers/utils.d.cts.map +1 -1
- package/dist/providers/utils.d.mts +7 -0
- package/dist/providers/utils.d.mts.map +1 -1
- package/dist/providers/utils.mjs +11 -0
- package/dist/providers/utils.mjs.map +1 -1
- package/dist/tests/accounts.cjs +4 -6
- package/dist/tests/accounts.cjs.map +1 -1
- package/dist/tests/accounts.d.cts +8 -21
- package/dist/tests/accounts.d.cts.map +1 -1
- package/dist/tests/accounts.d.mts +8 -21
- package/dist/tests/accounts.d.mts.map +1 -1
- package/dist/tests/accounts.mjs +4 -6
- package/dist/tests/accounts.mjs.map +1 -1
- package/dist/tests/messenger.cjs +1 -0
- 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 +1 -0
- package/dist/tests/messenger.mjs.map +1 -1
- package/dist/tests/providers.cjs.map +1 -1
- package/dist/tests/providers.d.cts +2 -1
- package/dist/tests/providers.d.cts.map +1 -1
- package/dist/tests/providers.d.mts +2 -1
- package/dist/tests/providers.d.mts.map +1 -1
- package/dist/tests/providers.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +4 -4
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +4 -4
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +32 -31
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainAccountWallet.cjs","sourceRoot":"","sources":["../src/MultichainAccountWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAOA,uDAM+B;AAE/B,uDAA4D;AAE5D,2CAAyC;AACzC,6CAAoC;AAEpC,qDAA6E;AAC7E,yCAAuC;AAEvC,yCAKkB;AAElB,yEAAkE;AAGlE,2EAAoE;AAEpE,uCAKiB;AAmBjB;;;GAGG;AACH,MAAa,uBAAuB;IAwBlC,YAAY,EACV,SAAS,EACT,aAAa,EACb,SAAS,EACT,KAAK,GAMN;;QA9BQ,wCAAQ,IAAI,mBAAK,EAAE,EAAC;QAEpB,8CAA+B;QAE/B,qDAA4C;QAE5C,yDAAgC;QAEhC,yDAA6D;QAE7D,qDAA8C;QAE9C,iDAAsB;QAEtB,+CAAa;QAEtB,+CAAe,KAAK,EAAC;QAErB,kDAAuC;QAarC,uBAAA,IAAI,+BAAO,IAAA,yCAA2B,EAAC,aAAa,CAAC,MAAA,CAAC;QACtD,uBAAA,IAAI,sCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;QACpC,uBAAA,IAAI,sCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,0CAAkB,IAAI,GAAG,EAAE,MAAA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KAAK,EAAE,EAAE;YACxC,MAAM,YAAY,GAAG,qDAAqD,IAAI,OAAO,EAAE,EAAE,CAAC;YAC1F,uBAAA,IAAI,oCAAK,MAAT,IAAI,EACF,GAAG,qBAAY,IAAI,YAAY,KAAK,IAAA,sBAAc,EAAC,KAAK,CAAC,SAAS,CACnE,CAAC;YACF,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,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 { TraceCallback, TraceRequest } from '@metamask/controller-utils';\nimport { AccountCreationType } from '@metamask/keyring-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { assert } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport { toProviderDataTraces, traceFallback, TraceName } from './analytics';\nimport { reportError } from './errors';\nimport type { Logger } from './logger';\nimport {\n createModuleLogger,\n ERROR_PREFIX,\n projectLogger as log,\n WARNING_PREFIX,\n} from './logger';\nimport type { GroupState } from './MultichainAccountGroup';\nimport { MultichainAccountGroup } from './MultichainAccountGroup';\nimport type { ServiceState, StateKeys } from './MultichainAccountService';\nimport type { Bip44AccountProvider } from './providers';\nimport { EvmAccountProvider } from './providers/EvmAccountProvider';\nimport type { MultichainAccountServiceMessenger } from './types';\nimport {\n assertGroupIndexIsValid,\n assertGroupIndexRangeIsValid,\n GroupIndexRange,\n toErrorMessage,\n} 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 #trace: TraceCallback;\n\n readonly #log: Logger;\n\n #initialized = false;\n\n #status: MultichainAccountWalletStatus;\n\n constructor({\n providers,\n entropySource,\n messenger,\n trace,\n }: {\n providers: Bip44AccountProvider<Account>[];\n entropySource: EntropySourceId;\n messenger: MultichainAccountServiceMessenger;\n trace?: TraceCallback;\n }) {\n this.#id = toMultichainAccountWalletId(entropySource);\n this.#providers = providers;\n this.#entropySource = entropySource;\n this.#messenger = messenger;\n this.#accountGroups = new Map();\n this.#trace = trace ?? traceFallback;\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): void {\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 ): Promise<Return> {\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 * Gets the providers and ensure the EVM provider is located at index 0.\n *\n * @returns The account providers.\n */\n #getProviders(): Bip44AccountProvider<Account>[] {\n const [evmProvider, ...otherProviders] = this.#providers;\n assert(\n evmProvider instanceof EvmAccountProvider,\n 'EVM account provider must be first',\n );\n\n return [evmProvider, ...otherProviders];\n }\n\n /**\n * Create accounts for a given provider and group index range.\n *\n * @param provider - The provider to create accounts for.\n * @param from - The starting group index (inclusive).\n * @param to - The ending group index (inclusive).\n * @returns The created accounts.\n */\n async #createAccountsRangeForProvider(\n provider: Bip44AccountProvider<Account>,\n from: number,\n to: number,\n ): Promise<Bip44Account<Account>[]> {\n const isBatching = to > from;\n\n try {\n return await provider.createAccounts({\n type: AccountCreationType.Bip44DeriveIndexRange,\n entropySource: this.#entropySource,\n range: {\n from,\n to,\n },\n });\n } catch (error) {\n reportError(\n this.#messenger,\n `Unable to create ${isBatching ? 'some accounts (batch)' : 'some accounts'} with provider \"${provider.getName()}\"`,\n error,\n {\n range: { from, to },\n provider: provider.getName(),\n isBatching,\n },\n );\n throw error;\n }\n }\n\n /**\n * Create or update a multichain account group state for a given group index and group state.\n *\n * @param groupIndex The group's index.\n * @param groupState The group's state to create or update the group with.\n * @returns The created or updated multichain account group.\n */\n #createOrUpdateMultichainAccountGroup(\n groupIndex: number,\n groupState: GroupState,\n ): MultichainAccountGroup<Account> {\n let group = this.#accountGroups.get(groupIndex);\n if (group) {\n // NOTE: This will publish an update event automatically.\n group.update(groupState);\n\n this.#log(`Group updated: [${group.id}]`);\n } else {\n group = new MultichainAccountGroup({\n wallet: this,\n providers: this.#providers,\n groupIndex,\n messenger: this.#messenger,\n });\n group.init(groupState);\n\n this.#accountGroups.set(groupIndex, group);\n\n this.#log(`Group created: [${group.id}]`);\n\n if (this.#initialized) {\n this.#messenger.publish(\n 'MultichainAccountService:multichainAccountGroupCreated',\n group,\n );\n }\n }\n\n return group;\n }\n\n /**\n * Build group state for a range of group indices by calling all providers in parallel.\n *\n * This is a non-locking shared core used by both creation and alignment paths.\n *\n * @param from - Starting group index (inclusive).\n * @param to - Ending group index (inclusive).\n * @param providers - The providers to create accounts for.\n * @returns The collected group state and any provider failure messages.\n */\n async #buildGroupStateForRange(\n from: number,\n to: number,\n providers: Bip44AccountProvider<Account>[],\n ): Promise<{\n groupStateByGroupIndex: Map<number, GroupState>;\n failures: string[];\n }> {\n const groupStateByGroupIndex = new Map<number, GroupState>();\n\n const results = await Promise.allSettled(\n providers.map(async (provider) => {\n const providerName = provider.getName();\n const accounts = await this.#createAccountsRangeForProvider(\n provider,\n from,\n to,\n );\n accounts.forEach((account) => {\n const { groupIndex } = account.options.entropy;\n let groupState = groupStateByGroupIndex.get(groupIndex);\n if (!groupState) {\n groupState = {};\n groupStateByGroupIndex.set(groupIndex, groupState);\n }\n if (!groupState[providerName]) {\n groupState[providerName] = [];\n }\n groupState[providerName].push(account.id);\n });\n }),\n );\n\n const failures = providers.reduce((messages: string[], provider, index) => {\n const result = results[index];\n if (result?.status === 'rejected') {\n messages.push(\n `[${provider.getName()}] ${toErrorMessage(result.reason)}`,\n );\n }\n return messages;\n }, []);\n\n return { groupStateByGroupIndex, failures };\n }\n\n /**\n * Internal method to create a range of multichain account groups.\n *\n * This method acquires the wallet lock internally and creates accounts for all\n * given providers synchronously. Callers decide which providers to pass.\n *\n * @param range - The range of group indices to create.\n * @param range.from - Starting group index to create (inclusive).\n * @param range.to - Maximum group index to create (inclusive).\n * @param providers - The providers to create accounts for.\n * @returns Array of created multichain account groups.\n */\n async #createMultichainAccountGroupsRange(\n { from: rangeFrom, to }: Required<GroupIndexRange>,\n providers: Bip44AccountProvider<Account>[],\n ): Promise<MultichainAccountGroup<Account>[]> {\n return await this.#withLock('in-progress:create-accounts', async () => {\n const groups: MultichainAccountGroup<Account>[] = [];\n\n // Get existing groups (fromGroupIndex to nextGroupIndex - 1).\n let from = rangeFrom;\n for (; from <= to; from++) {\n const group = this.getMultichainAccountGroup(from);\n if (group) {\n groups.push(group);\n } else {\n break; // Assuming we have no gap, if the group does not exist, we can stop and create the remaining ones.\n }\n }\n\n // Create new groups now.\n if (from <= to) {\n this.#log(`Creating groups from index ${from} to ${to}...`);\n\n const { groupStateByGroupIndex, failures } =\n await this.#buildGroupStateForRange(from, to, providers);\n\n // Check for provider failures — always treated as hard errors.\n if (failures.length) {\n throw new Error(\n failures.reduce(\n (message, failure) => `${message}\\n- ${failure}`,\n 'Unable to create some accounts. Providers threw the following errors:',\n ),\n );\n }\n\n // Create or update groups from the collected state.\n for (let groupIndex = from; groupIndex <= to; groupIndex++) {\n const groupState = groupStateByGroupIndex.get(groupIndex);\n\n if (groupState) {\n const group = this.#createOrUpdateMultichainAccountGroup(\n groupIndex,\n groupState,\n );\n\n groups.push(group);\n } else {\n this.#log(\n `${WARNING_PREFIX} Failed to create new group for group index: ${groupIndex} because no accounts were created for it`,\n );\n }\n }\n }\n\n return groups;\n });\n }\n\n /**\n * Align accounts for a range of group indices (non-locking).\n *\n * Calls all providers in parallel via the batch API. Provider failures are\n * logged as warnings (best-effort); no error is thrown.\n *\n * @param range - The range of group indices to align.\n * @param range.from - Starting group index (inclusive).\n * @param range.to - Ending group index (inclusive).\n * @param providers - The providers to align accounts for.\n * @param options - Options.\n * @param options.trace - Trace options.\n * @param options.trace.data - Optional trace data.\n */\n async #alignAccountsForRange(\n { from, to }: Required<GroupIndexRange>,\n providers: Bip44AccountProvider<Account>[],\n options: { trace?: { data?: TraceRequest['data'] } } = {},\n ): Promise<void> {\n await this.#trace(\n {\n name: TraceName.WalletAlignment,\n data: {\n from,\n to,\n ...toProviderDataTraces(providers),\n ...options.trace?.data,\n },\n },\n async () => {\n const { groupStateByGroupIndex, failures } =\n await this.#buildGroupStateForRange(from, to, providers);\n\n if (failures.length) {\n const error = failures.reduce(\n (message, failure) => `${message}\\n- ${failure}`,\n 'Unable to align some accounts. Providers threw the following errors:',\n );\n console.warn(error);\n this.#log(`${WARNING_PREFIX} ${error}`);\n }\n\n for (let groupIndex = from; groupIndex <= to; groupIndex++) {\n const groupState = groupStateByGroupIndex.get(groupIndex);\n if (groupState) {\n this.#createOrUpdateMultichainAccountGroup(groupIndex, groupState);\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 is used and non-EVM account creation is deferred via\n * {@link MultichainAccountWallet.alignAccountsOf}. Defaults to `false`.\n * @throws If groupIndex is greater than the next available group index.\n * @throws If any account provider fails to create accounts.\n * @returns The multichain account group for this group index.\n */\n async createMultichainAccountGroup(\n groupIndex: number,\n options: {\n waitForAllProvidersToFinishCreatingAccounts?: boolean;\n } = {},\n ): Promise<MultichainAccountGroup<Account>> {\n // Use this to avoid having it as `boolean | undefined`.\n const waitForAllProvidersToFinishCreatingAccounts =\n options.waitForAllProvidersToFinishCreatingAccounts ?? false;\n\n return await this.#trace(\n {\n name: TraceName.WalletCreateMultichainAccountGroup,\n data: {\n groupIndex,\n waitForAllProvidersToFinishCreatingAccounts,\n },\n },\n async () => {\n assertGroupIndexIsValid(groupIndex, this.getNextGroupIndex());\n\n // If the group already exists, return it.\n const existingGroup = this.getMultichainAccountGroup(groupIndex);\n if (existingGroup) {\n this.#log(\n `Trying to re-create existing group: [${existingGroup.id}] (idempotent)`,\n );\n return existingGroup;\n }\n\n // Create a single group with a range of 1 (so we can reuse the batch creation logic) for the\n // given group index.\n const groups = await this.#createMultichainAccountGroups(\n { from: groupIndex, to: groupIndex },\n options,\n );\n\n const group = groups[0];\n assert(group, `Expected group at index ${groupIndex} to exist`);\n return group;\n },\n );\n }\n\n /**\n * Creates multiple multichain account groups up to maxGroupIndex.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n *\n * @param range - The range of group indices to create.\n * @param range.from - Starting group index to create (inclusive) (defaults to 0).\n * @param range.to - Maximum group index to create (inclusive).\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 is used and non-EVM account creation is deferred via\n * {@link MultichainAccountWallet.alignAccounts}. Defaults to false.\n * @throws If range is invalid (e.g. from is greater than to, from or to is negative, etc.).\n * @returns Array of created multichain account groups.\n */\n async createMultichainAccountGroups(\n { from = 0, to }: GroupIndexRange,\n options: {\n waitForAllProvidersToFinishCreatingAccounts?: boolean;\n } = {},\n ): Promise<MultichainAccountGroup<Account>[]> {\n // Use this to avoid having it as `boolean | undefined`.\n const waitForAllProvidersToFinishCreatingAccounts =\n options.waitForAllProvidersToFinishCreatingAccounts ?? false;\n\n return await this.#trace(\n {\n name: TraceName.WalletCreateMultichainAccountGroups,\n data: {\n from,\n to,\n waitForAllProvidersToFinishCreatingAccounts,\n },\n },\n async () =>\n await this.#createMultichainAccountGroups({ from, to }, options),\n );\n }\n\n /**\n * Creates multiple multichain account groups up to maxGroupIndex.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n *\n * @param range - The range of group indices to create.\n * @param range.from - Starting group index to create (inclusive).\n * @param range.to - Maximum group index to create (inclusive).\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 is used and non-EVM account creation is deferred via\n * {@link MultichainAccountWallet.alignAccounts}. Defaults to false.\n * @throws If range is invalid (e.g. from is greater than to, from or to is negative, etc.).\n * @returns Array of created multichain account groups.\n */\n async #createMultichainAccountGroups(\n { from, to }: Required<GroupIndexRange>,\n options: {\n waitForAllProvidersToFinishCreatingAccounts?: boolean;\n },\n ): Promise<MultichainAccountGroup<Account>[]> {\n assertGroupIndexRangeIsValid({ from, to });\n assertGroupIndexIsValid(from, this.getNextGroupIndex());\n\n const waitForAllProvidersToFinishCreatingAccounts =\n options.waitForAllProvidersToFinishCreatingAccounts ?? false;\n\n const [evmProvider, ...otherProviders] = this.#getProviders();\n const providers = waitForAllProvidersToFinishCreatingAccounts\n ? this.#providers\n : [evmProvider];\n\n const groups = await this.#createMultichainAccountGroupsRange(\n { from, to },\n providers,\n );\n\n // We need to run a post-alignment since non-EVM accounts have not\n // been created yet.\n if (!waitForAllProvidersToFinishCreatingAccounts) {\n const alignOtherAccounts = async (): Promise<void> => {\n this.#log(`Aligning accounts... (post)`);\n\n await this.#withLock('in-progress:alignment', async () => {\n await this.#alignAccountsForRange({ from, to }, otherProviders, {\n trace: {\n data: {\n post: true, // Tag to identify post-alignment traces in analytics.\n },\n },\n });\n });\n\n this.#log('Aligned accounts! (post)');\n };\n\n // eslint-disable-next-line no-void\n void alignOtherAccounts().catch((error) => {\n const errorMessage = `Unable to align non-EVM accounts from group index ${from} to ${to}`;\n this.#log(\n `${ERROR_PREFIX} ${errorMessage}: ${toErrorMessage(error)} (post)`,\n );\n console.error(errorMessage, error);\n });\n }\n\n return groups;\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 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 const nextGroupIndex = this.getNextGroupIndex();\n\n if (nextGroupIndex > 0) {\n this.#log('Aligning accounts...');\n\n const from = 0;\n const to = nextGroupIndex - 1;\n\n await this.#withLock(\n 'in-progress:alignment',\n async () =>\n await this.#alignAccountsForRange({ from, to }, this.#providers),\n );\n\n this.#log('Aligned!');\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 const group = this.getMultichainAccountGroup(groupIndex);\n\n if (group) {\n this.#log(`Aligning accounts for group \"${group.id}\"...`);\n\n await this.#withLock(\n 'in-progress:alignment',\n async () =>\n await this.#alignAccountsForRange(\n { from: groupIndex, to: groupIndex },\n this.#providers,\n { trace: { data: { groupIndex } } },\n ),\n );\n\n this.#log(`Aligned accounts for group \"${group.id}\"!`);\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 ): Promise<void> => {\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\n log(\n message(\n `failed (with: \"${toErrorMessage(error)}\")`,\n targetGroupIndex,\n ),\n );\n\n reportError(\n this.#messenger,\n `Unable to discover accounts with provider \"${providerName}\"`,\n error,\n {\n provider: providerName,\n groupIndex: targetGroupIndex,\n },\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 const nextGroupIndex = this.getNextGroupIndex();\n if (nextGroupIndex > 0) {\n await this.#alignAccountsForRange(\n { from: 0, to: nextGroupIndex - 1 },\n this.#providers,\n {\n trace: {\n data: {\n discovery: true, // Tag to identify discovery-alignment traces in analytics.\n },\n },\n },\n );\n }\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,uDAA4D;AAE5D,2CAAyC;AACzC,6CAAoC;AAEpC,qDAA6E;AAC7E,yCAAuC;AAEvC,yCAKkB;AAElB,yEAAkE;AAGlE,2EAAoE;AAEpE,uCAKiB;AAmBjB;;;GAGG;AACH,MAAa,uBAAuB;IAuBlC,YAAY,EACV,SAAS,EACT,aAAa,EACb,SAAS,EACT,KAAK,GAMN;;QA9BQ,wCAAQ,IAAI,mBAAK,EAAE,EAAC;QAEpB,8CAA+B;QAE/B,qDAA4C;QAE5C,yDAAgC;QAEhC,yDAA6D;QAE7D,qDAA8C;QAE9C,iDAAsB;QAEtB,+CAAa;QAEtB,+CAAe,KAAK,EAAC;QAErB,kDAAuC;QAarC,uBAAA,IAAI,+BAAO,IAAA,yCAA2B,EAAC,aAAa,CAAC,MAAA,CAAC;QACtD,uBAAA,IAAI,sCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;QACpC,uBAAA,IAAI,sCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,0CAAkB,IAAI,GAAG,EAAE,MAAA,CAAC;QAChC,uBAAA,IAAI,kCAAU,KAAK,IAAI,yBAAa,MAAA,CAAC;QAErC,uBAAA,IAAI,gCAAQ,IAAA,2BAAkB,EAAC,sBAAG,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EACF,GAAG,qBAAY,IAAI,YAAY,KAAK,IAAA,sBAAc,EAAC,KAAK,CAAC,SAAS,CACnE,CAAC;YACF,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,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 { TraceCallback, TraceRequest } from '@metamask/controller-utils';\nimport { AccountCreationType } from '@metamask/keyring-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { assert } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport { toProviderDataTraces, traceFallback, TraceName } from './analytics';\nimport { reportError } from './errors';\nimport type { Logger } from './logger';\nimport {\n createModuleLogger,\n ERROR_PREFIX,\n projectLogger as log,\n WARNING_PREFIX,\n} from './logger';\nimport type { GroupState } from './MultichainAccountGroup';\nimport { MultichainAccountGroup } from './MultichainAccountGroup';\nimport type { ServiceState, StateKeys } from './MultichainAccountService';\nimport type { Bip44AccountProvider } from './providers';\nimport { EvmAccountProvider } from './providers/EvmAccountProvider';\nimport type { MultichainAccountServiceMessenger } from './types';\nimport {\n assertGroupIndexIsValid,\n assertGroupIndexRangeIsValid,\n GroupIndexRange,\n toErrorMessage,\n} 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 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 #trace: TraceCallback;\n\n readonly #log: Logger;\n\n #initialized = false;\n\n #status: MultichainAccountWalletStatus;\n\n constructor({\n providers,\n entropySource,\n messenger,\n trace,\n }: {\n providers: Bip44AccountProvider<Account>[];\n entropySource: EntropySourceId;\n messenger: MultichainAccountServiceMessenger;\n trace?: TraceCallback;\n }) {\n this.#id = toMultichainAccountWalletId(entropySource);\n this.#providers = providers;\n this.#entropySource = entropySource;\n this.#messenger = messenger;\n this.#accountGroups = new Map();\n this.#trace = trace ?? traceFallback;\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): void {\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 ): Promise<Return> {\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 * Gets the providers and ensure the EVM provider is located at index 0.\n *\n * @returns The account providers.\n */\n #getProviders(): Bip44AccountProvider<Account>[] {\n const [evmProvider, ...otherProviders] = this.#providers;\n assert(\n evmProvider instanceof EvmAccountProvider,\n 'EVM account provider must be first',\n );\n\n return [evmProvider, ...otherProviders];\n }\n\n /**\n * Create accounts for a given provider and group index range.\n *\n * @param provider - The provider to create accounts for.\n * @param from - The starting group index (inclusive).\n * @param to - The ending group index (inclusive).\n * @returns The created accounts.\n */\n async #createAccountsRangeForProvider(\n provider: Bip44AccountProvider<Account>,\n from: number,\n to: number,\n ): Promise<Bip44Account<Account>[]> {\n const isBatching = to > from;\n\n try {\n return await provider.createAccounts({\n type: AccountCreationType.Bip44DeriveIndexRange,\n entropySource: this.#entropySource,\n range: {\n from,\n to,\n },\n });\n } catch (error) {\n reportError(\n this.#messenger,\n `Unable to create ${isBatching ? 'some accounts (batch)' : 'some accounts'} with provider \"${provider.getName()}\"`,\n error,\n {\n range: { from, to },\n provider: provider.getName(),\n isBatching,\n },\n );\n throw error;\n }\n }\n\n /**\n * Create or update a multichain account group state for a given group index and group state.\n *\n * @param groupIndex The group's index.\n * @param groupState The group's state to create or update the group with.\n * @returns The created or updated multichain account group.\n */\n #createOrUpdateMultichainAccountGroup(\n groupIndex: number,\n groupState: GroupState,\n ): MultichainAccountGroup<Account> {\n let group = this.#accountGroups.get(groupIndex);\n if (group) {\n // NOTE: This will publish an update event automatically.\n group.update(groupState);\n\n this.#log(`Group updated: [${group.id}]`);\n } else {\n group = new MultichainAccountGroup({\n wallet: this,\n providers: this.#providers,\n groupIndex,\n messenger: this.#messenger,\n });\n group.init(groupState);\n\n this.#accountGroups.set(groupIndex, group);\n\n this.#log(`Group created: [${group.id}]`);\n\n if (this.#initialized) {\n this.#messenger.publish(\n 'MultichainAccountService:multichainAccountGroupCreated',\n group,\n );\n }\n }\n\n return group;\n }\n\n /**\n * Build group state for a range of group indices by calling all providers in parallel.\n *\n * This is a non-locking shared core used by both creation and alignment paths.\n *\n * @param from - Starting group index (inclusive).\n * @param to - Ending group index (inclusive).\n * @param providers - The providers to create accounts for.\n * @returns The collected group state and any provider failure messages.\n */\n async #buildGroupStateForRange(\n from: number,\n to: number,\n providers: Bip44AccountProvider<Account>[],\n ): Promise<{\n groupStateByGroupIndex: Map<number, GroupState>;\n failures: string[];\n }> {\n const groupStateByGroupIndex = new Map<number, GroupState>();\n\n const results = await Promise.allSettled(\n providers.map(async (provider) => {\n const providerName = provider.getName();\n const accounts = await this.#createAccountsRangeForProvider(\n provider,\n from,\n to,\n );\n accounts.forEach((account) => {\n const { groupIndex } = account.options.entropy;\n let groupState = groupStateByGroupIndex.get(groupIndex);\n if (!groupState) {\n groupState = {};\n groupStateByGroupIndex.set(groupIndex, groupState);\n }\n if (!groupState[providerName]) {\n groupState[providerName] = [];\n }\n groupState[providerName].push(account.id);\n });\n }),\n );\n\n const failures = providers.reduce((messages: string[], provider, index) => {\n const result = results[index];\n if (result?.status === 'rejected') {\n messages.push(\n `[${provider.getName()}] ${toErrorMessage(result.reason)}`,\n );\n }\n return messages;\n }, []);\n\n return { groupStateByGroupIndex, failures };\n }\n\n /**\n * Internal method to create a range of multichain account groups.\n *\n * This method acquires the wallet lock internally and creates accounts for all\n * given providers synchronously. Callers decide which providers to pass.\n *\n * @param range - The range of group indices to create.\n * @param range.from - Starting group index to create (inclusive).\n * @param range.to - Maximum group index to create (inclusive).\n * @param providers - The providers to create accounts for.\n * @returns Array of created multichain account groups.\n */\n async #createMultichainAccountGroupsRange(\n { from: rangeFrom, to }: Required<GroupIndexRange>,\n providers: Bip44AccountProvider<Account>[],\n ): Promise<MultichainAccountGroup<Account>[]> {\n return await this.#withLock('in-progress:create-accounts', async () => {\n const groups: MultichainAccountGroup<Account>[] = [];\n\n // Get existing groups (fromGroupIndex to nextGroupIndex - 1).\n let from = rangeFrom;\n for (; from <= to; from++) {\n const group = this.getMultichainAccountGroup(from);\n if (group) {\n groups.push(group);\n } else {\n break; // Assuming we have no gap, if the group does not exist, we can stop and create the remaining ones.\n }\n }\n\n // Create new groups now.\n if (from <= to) {\n this.#log(`Creating groups from index ${from} to ${to}...`);\n\n const { groupStateByGroupIndex, failures } =\n await this.#buildGroupStateForRange(from, to, providers);\n\n // Check for provider failures — always treated as hard errors.\n if (failures.length) {\n throw new Error(\n failures.reduce(\n (message, failure) => `${message}\\n- ${failure}`,\n 'Unable to create some accounts. Providers threw the following errors:',\n ),\n );\n }\n\n // Create or update groups from the collected state.\n for (let groupIndex = from; groupIndex <= to; groupIndex++) {\n const groupState = groupStateByGroupIndex.get(groupIndex);\n\n if (groupState) {\n const group = this.#createOrUpdateMultichainAccountGroup(\n groupIndex,\n groupState,\n );\n\n groups.push(group);\n } else {\n this.#log(\n `${WARNING_PREFIX} Failed to create new group for group index: ${groupIndex} because no accounts were created for it`,\n );\n }\n }\n }\n\n return groups;\n });\n }\n\n /**\n * Align accounts for a range of group indices (non-locking).\n *\n * Calls all providers in parallel via the batch API. Provider failures are\n * logged as warnings (best-effort); no error is thrown.\n *\n * @param range - The range of group indices to align.\n * @param range.from - Starting group index (inclusive).\n * @param range.to - Ending group index (inclusive).\n * @param providers - The providers to align accounts for.\n * @param options - Options.\n * @param options.trace - Trace options.\n * @param options.trace.data - Optional trace data.\n */\n async #alignAccountsForRange(\n { from, to }: Required<GroupIndexRange>,\n providers: Bip44AccountProvider<Account>[],\n options: { trace?: { data?: TraceRequest['data'] } } = {},\n ): Promise<void> {\n await this.#trace(\n {\n name: TraceName.WalletAlignment,\n data: {\n from,\n to,\n ...toProviderDataTraces(providers),\n ...options.trace?.data,\n },\n },\n async () => {\n const { groupStateByGroupIndex, failures } =\n await this.#buildGroupStateForRange(from, to, providers);\n\n if (failures.length) {\n const error = failures.reduce(\n (message, failure) => `${message}\\n- ${failure}`,\n 'Unable to align some accounts. Providers threw the following errors:',\n );\n console.warn(error);\n this.#log(`${WARNING_PREFIX} ${error}`);\n }\n\n for (let groupIndex = from; groupIndex <= to; groupIndex++) {\n const groupState = groupStateByGroupIndex.get(groupIndex);\n if (groupState) {\n this.#createOrUpdateMultichainAccountGroup(groupIndex, groupState);\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 is used and non-EVM account creation is deferred via\n * {@link MultichainAccountWallet.alignAccountsOf}. Defaults to `false`.\n * @throws If groupIndex is greater than the next available group index.\n * @throws If any account provider fails to create accounts.\n * @returns The multichain account group for this group index.\n */\n async createMultichainAccountGroup(\n groupIndex: number,\n options: {\n waitForAllProvidersToFinishCreatingAccounts?: boolean;\n } = {},\n ): Promise<MultichainAccountGroup<Account>> {\n // Use this to avoid having it as `boolean | undefined`.\n const waitForAllProvidersToFinishCreatingAccounts =\n options.waitForAllProvidersToFinishCreatingAccounts ?? false;\n\n return await this.#trace(\n {\n name: TraceName.WalletCreateMultichainAccountGroup,\n data: {\n groupIndex,\n waitForAllProvidersToFinishCreatingAccounts,\n },\n },\n async () => {\n assertGroupIndexIsValid(groupIndex, this.getNextGroupIndex());\n\n // If the group already exists, return it.\n const existingGroup = this.getMultichainAccountGroup(groupIndex);\n if (existingGroup) {\n this.#log(\n `Trying to re-create existing group: [${existingGroup.id}] (idempotent)`,\n );\n return existingGroup;\n }\n\n // Create a single group with a range of 1 (so we can reuse the batch creation logic) for the\n // given group index.\n const groups = await this.#createMultichainAccountGroups(\n { from: groupIndex, to: groupIndex },\n options,\n );\n\n const group = groups[0];\n assert(group, `Expected group at index ${groupIndex} to exist`);\n return group;\n },\n );\n }\n\n /**\n * Creates multiple multichain account groups up to maxGroupIndex.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n *\n * @param range - The range of group indices to create.\n * @param range.from - Starting group index to create (inclusive) (defaults to 0).\n * @param range.to - Maximum group index to create (inclusive).\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 is used and non-EVM account creation is deferred via\n * {@link MultichainAccountWallet.alignAccounts}. Defaults to false.\n * @throws If range is invalid (e.g. from is greater than to, from or to is negative, etc.).\n * @returns Array of created multichain account groups.\n */\n async createMultichainAccountGroups(\n { from = 0, to }: GroupIndexRange,\n options: {\n waitForAllProvidersToFinishCreatingAccounts?: boolean;\n } = {},\n ): Promise<MultichainAccountGroup<Account>[]> {\n // Use this to avoid having it as `boolean | undefined`.\n const waitForAllProvidersToFinishCreatingAccounts =\n options.waitForAllProvidersToFinishCreatingAccounts ?? false;\n\n return await this.#trace(\n {\n name: TraceName.WalletCreateMultichainAccountGroups,\n data: {\n from,\n to,\n waitForAllProvidersToFinishCreatingAccounts,\n },\n },\n async () =>\n await this.#createMultichainAccountGroups({ from, to }, options),\n );\n }\n\n /**\n * Creates multiple multichain account groups up to maxGroupIndex.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n *\n * @param range - The range of group indices to create.\n * @param range.from - Starting group index to create (inclusive).\n * @param range.to - Maximum group index to create (inclusive).\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 is used and non-EVM account creation is deferred via\n * {@link MultichainAccountWallet.alignAccounts}. Defaults to false.\n * @throws If range is invalid (e.g. from is greater than to, from or to is negative, etc.).\n * @returns Array of created multichain account groups.\n */\n async #createMultichainAccountGroups(\n { from, to }: Required<GroupIndexRange>,\n options: {\n waitForAllProvidersToFinishCreatingAccounts?: boolean;\n },\n ): Promise<MultichainAccountGroup<Account>[]> {\n assertGroupIndexRangeIsValid({ from, to });\n assertGroupIndexIsValid(from, this.getNextGroupIndex());\n\n const waitForAllProvidersToFinishCreatingAccounts =\n options.waitForAllProvidersToFinishCreatingAccounts ?? false;\n\n const [evmProvider, ...otherProviders] = this.#getProviders();\n const providers = waitForAllProvidersToFinishCreatingAccounts\n ? this.#providers\n : [evmProvider];\n\n const groups = await this.#createMultichainAccountGroupsRange(\n { from, to },\n providers,\n );\n\n // We need to run a post-alignment since non-EVM accounts have not\n // been created yet.\n if (!waitForAllProvidersToFinishCreatingAccounts) {\n const alignOtherAccounts = async (): Promise<void> => {\n this.#log(`Aligning accounts... (post)`);\n\n await this.#withLock('in-progress:alignment', async () => {\n await this.#alignAccountsForRange({ from, to }, otherProviders, {\n trace: {\n data: {\n post: true, // Tag to identify post-alignment traces in analytics.\n },\n },\n });\n });\n\n this.#log('Aligned accounts! (post)');\n };\n\n // eslint-disable-next-line no-void\n void alignOtherAccounts().catch((error) => {\n const errorMessage = `Unable to align non-EVM accounts from group index ${from} to ${to}`;\n this.#log(\n `${ERROR_PREFIX} ${errorMessage}: ${toErrorMessage(error)} (post)`,\n );\n console.error(errorMessage, error);\n });\n }\n\n return groups;\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 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 const nextGroupIndex = this.getNextGroupIndex();\n\n if (nextGroupIndex > 0) {\n this.#log('Aligning accounts...');\n\n const from = 0;\n const to = nextGroupIndex - 1;\n\n await this.#withLock(\n 'in-progress:alignment',\n async () =>\n await this.#alignAccountsForRange({ from, to }, this.#providers),\n );\n\n this.#log('Aligned!');\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 const group = this.getMultichainAccountGroup(groupIndex);\n\n if (group) {\n this.#log(`Aligning accounts for group \"${group.id}\"...`);\n\n await this.#withLock(\n 'in-progress:alignment',\n async () =>\n await this.#alignAccountsForRange(\n { from: groupIndex, to: groupIndex },\n this.#providers,\n { trace: { data: { groupIndex } } },\n ),\n );\n\n this.#log(`Aligned accounts for group \"${group.id}\"!`);\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 ): Promise<void> => {\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\n log(\n message(\n `failed (with: \"${toErrorMessage(error)}\")`,\n targetGroupIndex,\n ),\n );\n\n reportError(\n this.#messenger,\n `Unable to discover accounts with provider \"${providerName}\"`,\n error,\n {\n provider: providerName,\n groupIndex: targetGroupIndex,\n },\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 const nextGroupIndex = this.getNextGroupIndex();\n if (nextGroupIndex > 0) {\n await this.#alignAccountsForRange(\n { from: 0, to: nextGroupIndex - 1 },\n this.#providers,\n {\n trace: {\n data: {\n discovery: true, // Tag to identify discovery-alignment traces in analytics.\n },\n },\n },\n );\n }\n\n return providerContexts.flatMap((context) => context.accounts);\n });\n }\n}\n"]}
|
|
@@ -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,aAAa,EAAgB,mCAAmC;AAE9E,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAc7E,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,uCAAmC;AAC1E,OAAO,KAAK,EAAE,oBAAoB,EAAE,8BAAoB;AAExD,OAAO,KAAK,EAAE,iCAAiC,EAAE,oBAAgB;AACjE,OAAO,EAGL,eAAe,EAEhB,oBAAgB;AAcjB,MAAM,MAAM,WAAW,GAAG,YAAY,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC;AAKnE;;;GAGG;AACH,qBAAa,uBAAuB,CAClC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,CAC5C,YAAW,iCAAiC,CAAC,OAAO,CAAC;;
|
|
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,8BAA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EAAE;4BACJ,IAAI,EAAE,IAAI,EAAE,sDAAsD;yBACnE;qBACF;iBACF,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,uBAAA,IAAI,oCAAK,MAAT,IAAI,EAAM,0BAA0B,CAAC,CAAC;QACxC,CAAC,CAAC;QAEF,mCAAmC;QACnC,KAAK,kBAAkB,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACxC,MAAM,YAAY,GAAG,qDAAqD,IAAI,OAAO,EAAE,EAAE,CAAC;YAC1F,uBAAA,IAAI,oCAAK,MAAT,IAAI,EACF,GAAG,YAAY,IAAI,YAAY,KAAK,cAAc,CAAC,KAAK,CAAC,SAAS,CACnE,CAAC;YACF,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,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 { TraceCallback, TraceRequest } from '@metamask/controller-utils';\nimport { AccountCreationType } from '@metamask/keyring-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { assert } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport { toProviderDataTraces, traceFallback, TraceName } from './analytics';\nimport { reportError } from './errors';\nimport type { Logger } from './logger';\nimport {\n createModuleLogger,\n ERROR_PREFIX,\n projectLogger as log,\n WARNING_PREFIX,\n} from './logger';\nimport type { GroupState } from './MultichainAccountGroup';\nimport { MultichainAccountGroup } from './MultichainAccountGroup';\nimport type { ServiceState, StateKeys } from './MultichainAccountService';\nimport type { Bip44AccountProvider } from './providers';\nimport { EvmAccountProvider } from './providers/EvmAccountProvider';\nimport type { MultichainAccountServiceMessenger } from './types';\nimport {\n assertGroupIndexIsValid,\n assertGroupIndexRangeIsValid,\n GroupIndexRange,\n toErrorMessage,\n} 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 #trace: TraceCallback;\n\n readonly #log: Logger;\n\n #initialized = false;\n\n #status: MultichainAccountWalletStatus;\n\n constructor({\n providers,\n entropySource,\n messenger,\n trace,\n }: {\n providers: Bip44AccountProvider<Account>[];\n entropySource: EntropySourceId;\n messenger: MultichainAccountServiceMessenger;\n trace?: TraceCallback;\n }) {\n this.#id = toMultichainAccountWalletId(entropySource);\n this.#providers = providers;\n this.#entropySource = entropySource;\n this.#messenger = messenger;\n this.#accountGroups = new Map();\n this.#trace = trace ?? traceFallback;\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): void {\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 ): Promise<Return> {\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 * Gets the providers and ensure the EVM provider is located at index 0.\n *\n * @returns The account providers.\n */\n #getProviders(): Bip44AccountProvider<Account>[] {\n const [evmProvider, ...otherProviders] = this.#providers;\n assert(\n evmProvider instanceof EvmAccountProvider,\n 'EVM account provider must be first',\n );\n\n return [evmProvider, ...otherProviders];\n }\n\n /**\n * Create accounts for a given provider and group index range.\n *\n * @param provider - The provider to create accounts for.\n * @param from - The starting group index (inclusive).\n * @param to - The ending group index (inclusive).\n * @returns The created accounts.\n */\n async #createAccountsRangeForProvider(\n provider: Bip44AccountProvider<Account>,\n from: number,\n to: number,\n ): Promise<Bip44Account<Account>[]> {\n const isBatching = to > from;\n\n try {\n return await provider.createAccounts({\n type: AccountCreationType.Bip44DeriveIndexRange,\n entropySource: this.#entropySource,\n range: {\n from,\n to,\n },\n });\n } catch (error) {\n reportError(\n this.#messenger,\n `Unable to create ${isBatching ? 'some accounts (batch)' : 'some accounts'} with provider \"${provider.getName()}\"`,\n error,\n {\n range: { from, to },\n provider: provider.getName(),\n isBatching,\n },\n );\n throw error;\n }\n }\n\n /**\n * Create or update a multichain account group state for a given group index and group state.\n *\n * @param groupIndex The group's index.\n * @param groupState The group's state to create or update the group with.\n * @returns The created or updated multichain account group.\n */\n #createOrUpdateMultichainAccountGroup(\n groupIndex: number,\n groupState: GroupState,\n ): MultichainAccountGroup<Account> {\n let group = this.#accountGroups.get(groupIndex);\n if (group) {\n // NOTE: This will publish an update event automatically.\n group.update(groupState);\n\n this.#log(`Group updated: [${group.id}]`);\n } else {\n group = new MultichainAccountGroup({\n wallet: this,\n providers: this.#providers,\n groupIndex,\n messenger: this.#messenger,\n });\n group.init(groupState);\n\n this.#accountGroups.set(groupIndex, group);\n\n this.#log(`Group created: [${group.id}]`);\n\n if (this.#initialized) {\n this.#messenger.publish(\n 'MultichainAccountService:multichainAccountGroupCreated',\n group,\n );\n }\n }\n\n return group;\n }\n\n /**\n * Build group state for a range of group indices by calling all providers in parallel.\n *\n * This is a non-locking shared core used by both creation and alignment paths.\n *\n * @param from - Starting group index (inclusive).\n * @param to - Ending group index (inclusive).\n * @param providers - The providers to create accounts for.\n * @returns The collected group state and any provider failure messages.\n */\n async #buildGroupStateForRange(\n from: number,\n to: number,\n providers: Bip44AccountProvider<Account>[],\n ): Promise<{\n groupStateByGroupIndex: Map<number, GroupState>;\n failures: string[];\n }> {\n const groupStateByGroupIndex = new Map<number, GroupState>();\n\n const results = await Promise.allSettled(\n providers.map(async (provider) => {\n const providerName = provider.getName();\n const accounts = await this.#createAccountsRangeForProvider(\n provider,\n from,\n to,\n );\n accounts.forEach((account) => {\n const { groupIndex } = account.options.entropy;\n let groupState = groupStateByGroupIndex.get(groupIndex);\n if (!groupState) {\n groupState = {};\n groupStateByGroupIndex.set(groupIndex, groupState);\n }\n if (!groupState[providerName]) {\n groupState[providerName] = [];\n }\n groupState[providerName].push(account.id);\n });\n }),\n );\n\n const failures = providers.reduce((messages: string[], provider, index) => {\n const result = results[index];\n if (result?.status === 'rejected') {\n messages.push(\n `[${provider.getName()}] ${toErrorMessage(result.reason)}`,\n );\n }\n return messages;\n }, []);\n\n return { groupStateByGroupIndex, failures };\n }\n\n /**\n * Internal method to create a range of multichain account groups.\n *\n * This method acquires the wallet lock internally and creates accounts for all\n * given providers synchronously. Callers decide which providers to pass.\n *\n * @param range - The range of group indices to create.\n * @param range.from - Starting group index to create (inclusive).\n * @param range.to - Maximum group index to create (inclusive).\n * @param providers - The providers to create accounts for.\n * @returns Array of created multichain account groups.\n */\n async #createMultichainAccountGroupsRange(\n { from: rangeFrom, to }: Required<GroupIndexRange>,\n providers: Bip44AccountProvider<Account>[],\n ): Promise<MultichainAccountGroup<Account>[]> {\n return await this.#withLock('in-progress:create-accounts', async () => {\n const groups: MultichainAccountGroup<Account>[] = [];\n\n // Get existing groups (fromGroupIndex to nextGroupIndex - 1).\n let from = rangeFrom;\n for (; from <= to; from++) {\n const group = this.getMultichainAccountGroup(from);\n if (group) {\n groups.push(group);\n } else {\n break; // Assuming we have no gap, if the group does not exist, we can stop and create the remaining ones.\n }\n }\n\n // Create new groups now.\n if (from <= to) {\n this.#log(`Creating groups from index ${from} to ${to}...`);\n\n const { groupStateByGroupIndex, failures } =\n await this.#buildGroupStateForRange(from, to, providers);\n\n // Check for provider failures — always treated as hard errors.\n if (failures.length) {\n throw new Error(\n failures.reduce(\n (message, failure) => `${message}\\n- ${failure}`,\n 'Unable to create some accounts. Providers threw the following errors:',\n ),\n );\n }\n\n // Create or update groups from the collected state.\n for (let groupIndex = from; groupIndex <= to; groupIndex++) {\n const groupState = groupStateByGroupIndex.get(groupIndex);\n\n if (groupState) {\n const group = this.#createOrUpdateMultichainAccountGroup(\n groupIndex,\n groupState,\n );\n\n groups.push(group);\n } else {\n this.#log(\n `${WARNING_PREFIX} Failed to create new group for group index: ${groupIndex} because no accounts were created for it`,\n );\n }\n }\n }\n\n return groups;\n });\n }\n\n /**\n * Align accounts for a range of group indices (non-locking).\n *\n * Calls all providers in parallel via the batch API. Provider failures are\n * logged as warnings (best-effort); no error is thrown.\n *\n * @param range - The range of group indices to align.\n * @param range.from - Starting group index (inclusive).\n * @param range.to - Ending group index (inclusive).\n * @param providers - The providers to align accounts for.\n * @param options - Options.\n * @param options.trace - Trace options.\n * @param options.trace.data - Optional trace data.\n */\n async #alignAccountsForRange(\n { from, to }: Required<GroupIndexRange>,\n providers: Bip44AccountProvider<Account>[],\n options: { trace?: { data?: TraceRequest['data'] } } = {},\n ): Promise<void> {\n await this.#trace(\n {\n name: TraceName.WalletAlignment,\n data: {\n from,\n to,\n ...toProviderDataTraces(providers),\n ...options.trace?.data,\n },\n },\n async () => {\n const { groupStateByGroupIndex, failures } =\n await this.#buildGroupStateForRange(from, to, providers);\n\n if (failures.length) {\n const error = failures.reduce(\n (message, failure) => `${message}\\n- ${failure}`,\n 'Unable to align some accounts. Providers threw the following errors:',\n );\n console.warn(error);\n this.#log(`${WARNING_PREFIX} ${error}`);\n }\n\n for (let groupIndex = from; groupIndex <= to; groupIndex++) {\n const groupState = groupStateByGroupIndex.get(groupIndex);\n if (groupState) {\n this.#createOrUpdateMultichainAccountGroup(groupIndex, groupState);\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 is used and non-EVM account creation is deferred via\n * {@link MultichainAccountWallet.alignAccountsOf}. Defaults to `false`.\n * @throws If groupIndex is greater than the next available group index.\n * @throws If any account provider fails to create accounts.\n * @returns The multichain account group for this group index.\n */\n async createMultichainAccountGroup(\n groupIndex: number,\n options: {\n waitForAllProvidersToFinishCreatingAccounts?: boolean;\n } = {},\n ): Promise<MultichainAccountGroup<Account>> {\n // Use this to avoid having it as `boolean | undefined`.\n const waitForAllProvidersToFinishCreatingAccounts =\n options.waitForAllProvidersToFinishCreatingAccounts ?? false;\n\n return await this.#trace(\n {\n name: TraceName.WalletCreateMultichainAccountGroup,\n data: {\n groupIndex,\n waitForAllProvidersToFinishCreatingAccounts,\n },\n },\n async () => {\n assertGroupIndexIsValid(groupIndex, this.getNextGroupIndex());\n\n // If the group already exists, return it.\n const existingGroup = this.getMultichainAccountGroup(groupIndex);\n if (existingGroup) {\n this.#log(\n `Trying to re-create existing group: [${existingGroup.id}] (idempotent)`,\n );\n return existingGroup;\n }\n\n // Create a single group with a range of 1 (so we can reuse the batch creation logic) for the\n // given group index.\n const groups = await this.#createMultichainAccountGroups(\n { from: groupIndex, to: groupIndex },\n options,\n );\n\n const group = groups[0];\n assert(group, `Expected group at index ${groupIndex} to exist`);\n return group;\n },\n );\n }\n\n /**\n * Creates multiple multichain account groups up to maxGroupIndex.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n *\n * @param range - The range of group indices to create.\n * @param range.from - Starting group index to create (inclusive) (defaults to 0).\n * @param range.to - Maximum group index to create (inclusive).\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 is used and non-EVM account creation is deferred via\n * {@link MultichainAccountWallet.alignAccounts}. Defaults to false.\n * @throws If range is invalid (e.g. from is greater than to, from or to is negative, etc.).\n * @returns Array of created multichain account groups.\n */\n async createMultichainAccountGroups(\n { from = 0, to }: GroupIndexRange,\n options: {\n waitForAllProvidersToFinishCreatingAccounts?: boolean;\n } = {},\n ): Promise<MultichainAccountGroup<Account>[]> {\n // Use this to avoid having it as `boolean | undefined`.\n const waitForAllProvidersToFinishCreatingAccounts =\n options.waitForAllProvidersToFinishCreatingAccounts ?? false;\n\n return await this.#trace(\n {\n name: TraceName.WalletCreateMultichainAccountGroups,\n data: {\n from,\n to,\n waitForAllProvidersToFinishCreatingAccounts,\n },\n },\n async () =>\n await this.#createMultichainAccountGroups({ from, to }, options),\n );\n }\n\n /**\n * Creates multiple multichain account groups up to maxGroupIndex.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n *\n * @param range - The range of group indices to create.\n * @param range.from - Starting group index to create (inclusive).\n * @param range.to - Maximum group index to create (inclusive).\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 is used and non-EVM account creation is deferred via\n * {@link MultichainAccountWallet.alignAccounts}. Defaults to false.\n * @throws If range is invalid (e.g. from is greater than to, from or to is negative, etc.).\n * @returns Array of created multichain account groups.\n */\n async #createMultichainAccountGroups(\n { from, to }: Required<GroupIndexRange>,\n options: {\n waitForAllProvidersToFinishCreatingAccounts?: boolean;\n },\n ): Promise<MultichainAccountGroup<Account>[]> {\n assertGroupIndexRangeIsValid({ from, to });\n assertGroupIndexIsValid(from, this.getNextGroupIndex());\n\n const waitForAllProvidersToFinishCreatingAccounts =\n options.waitForAllProvidersToFinishCreatingAccounts ?? false;\n\n const [evmProvider, ...otherProviders] = this.#getProviders();\n const providers = waitForAllProvidersToFinishCreatingAccounts\n ? this.#providers\n : [evmProvider];\n\n const groups = await this.#createMultichainAccountGroupsRange(\n { from, to },\n providers,\n );\n\n // We need to run a post-alignment since non-EVM accounts have not\n // been created yet.\n if (!waitForAllProvidersToFinishCreatingAccounts) {\n const alignOtherAccounts = async (): Promise<void> => {\n this.#log(`Aligning accounts... (post)`);\n\n await this.#withLock('in-progress:alignment', async () => {\n await this.#alignAccountsForRange({ from, to }, otherProviders, {\n trace: {\n data: {\n post: true, // Tag to identify post-alignment traces in analytics.\n },\n },\n });\n });\n\n this.#log('Aligned accounts! (post)');\n };\n\n // eslint-disable-next-line no-void\n void alignOtherAccounts().catch((error) => {\n const errorMessage = `Unable to align non-EVM accounts from group index ${from} to ${to}`;\n this.#log(\n `${ERROR_PREFIX} ${errorMessage}: ${toErrorMessage(error)} (post)`,\n );\n console.error(errorMessage, error);\n });\n }\n\n return groups;\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 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 const nextGroupIndex = this.getNextGroupIndex();\n\n if (nextGroupIndex > 0) {\n this.#log('Aligning accounts...');\n\n const from = 0;\n const to = nextGroupIndex - 1;\n\n await this.#withLock(\n 'in-progress:alignment',\n async () =>\n await this.#alignAccountsForRange({ from, to }, this.#providers),\n );\n\n this.#log('Aligned!');\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 const group = this.getMultichainAccountGroup(groupIndex);\n\n if (group) {\n this.#log(`Aligning accounts for group \"${group.id}\"...`);\n\n await this.#withLock(\n 'in-progress:alignment',\n async () =>\n await this.#alignAccountsForRange(\n { from: groupIndex, to: groupIndex },\n this.#providers,\n { trace: { data: { groupIndex } } },\n ),\n );\n\n this.#log(`Aligned accounts for group \"${group.id}\"!`);\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 ): Promise<void> => {\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\n log(\n message(\n `failed (with: \"${toErrorMessage(error)}\")`,\n targetGroupIndex,\n ),\n );\n\n reportError(\n this.#messenger,\n `Unable to discover accounts with provider \"${providerName}\"`,\n error,\n {\n provider: providerName,\n groupIndex: targetGroupIndex,\n },\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 const nextGroupIndex = this.getNextGroupIndex();\n if (nextGroupIndex > 0) {\n await this.#alignAccountsForRange(\n { from: 0, to: nextGroupIndex - 1 },\n this.#providers,\n {\n trace: {\n data: {\n discovery: true, // Tag to identify discovery-alignment traces in analytics.\n },\n },\n },\n );\n }\n\n return providerContexts.flatMap((context) => context.accounts);\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MultichainAccountWallet.mjs","sourceRoot":"","sources":["../src/MultichainAccountWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;AAOA,OAAO,EACL,iBAAiB,EACjB,yCAAyC,EACzC,0BAA0B,EAC1B,uBAAuB,EACvB,2BAA2B,EAC5B,8BAA8B;AAE/B,OAAO,EAAE,mBAAmB,EAAE,8BAA8B;AAE5D,OAAO,EAAE,MAAM,EAAE,wBAAwB;AACzC,OAAO,EAAE,KAAK,EAAE,oBAAoB;AAEpC,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,SAAS,EAAE,8BAAoB;AAC7E,OAAO,EAAE,WAAW,EAAE,qBAAiB;AAEvC,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,aAAa,IAAI,GAAG,EACpB,cAAc,EACf,qBAAiB;AAElB,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAGlE,OAAO,EAAE,kBAAkB,EAAE,2CAAuC;AAEpE,OAAO,EACL,uBAAuB,EACvB,4BAA4B,EAE5B,cAAc,EACf,oBAAgB;AAmBjB;;;GAGG;AACH,MA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gBACvD,MAAM,uBAAA,IAAI,0FAAuB,MAA3B,IAAI,EAAwB,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,cAAc,EAAE;oBAC9D,KAAK,EAAE;wBACL,IAAI,EAAE;4BACJ,IAAI,EAAE,IAAI,EAAE,sDAAsD;yBACnE;qBACF;iBACF,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,uBAAA,IAAI,oCAAK,MAAT,IAAI,EAAM,0BAA0B,CAAC,CAAC;QACxC,CAAC,CAAC;QAEF,mCAAmC;QACnC,KAAK,kBAAkB,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACxC,MAAM,YAAY,GAAG,qDAAqD,IAAI,OAAO,EAAE,EAAE,CAAC;YAC1F,uBAAA,IAAI,oCAAK,MAAT,IAAI,EACF,GAAG,YAAY,IAAI,YAAY,KAAK,cAAc,CAAC,KAAK,CAAC,SAAS,CACnE,CAAC;YACF,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,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 { TraceCallback, TraceRequest } from '@metamask/controller-utils';\nimport { AccountCreationType } from '@metamask/keyring-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { assert } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport { toProviderDataTraces, traceFallback, TraceName } from './analytics';\nimport { reportError } from './errors';\nimport type { Logger } from './logger';\nimport {\n createModuleLogger,\n ERROR_PREFIX,\n projectLogger as log,\n WARNING_PREFIX,\n} from './logger';\nimport type { GroupState } from './MultichainAccountGroup';\nimport { MultichainAccountGroup } from './MultichainAccountGroup';\nimport type { ServiceState, StateKeys } from './MultichainAccountService';\nimport type { Bip44AccountProvider } from './providers';\nimport { EvmAccountProvider } from './providers/EvmAccountProvider';\nimport type { MultichainAccountServiceMessenger } from './types';\nimport {\n assertGroupIndexIsValid,\n assertGroupIndexRangeIsValid,\n GroupIndexRange,\n toErrorMessage,\n} 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 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 #trace: TraceCallback;\n\n readonly #log: Logger;\n\n #initialized = false;\n\n #status: MultichainAccountWalletStatus;\n\n constructor({\n providers,\n entropySource,\n messenger,\n trace,\n }: {\n providers: Bip44AccountProvider<Account>[];\n entropySource: EntropySourceId;\n messenger: MultichainAccountServiceMessenger;\n trace?: TraceCallback;\n }) {\n this.#id = toMultichainAccountWalletId(entropySource);\n this.#providers = providers;\n this.#entropySource = entropySource;\n this.#messenger = messenger;\n this.#accountGroups = new Map();\n this.#trace = trace ?? traceFallback;\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): void {\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 ): Promise<Return> {\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 * Gets the providers and ensure the EVM provider is located at index 0.\n *\n * @returns The account providers.\n */\n #getProviders(): Bip44AccountProvider<Account>[] {\n const [evmProvider, ...otherProviders] = this.#providers;\n assert(\n evmProvider instanceof EvmAccountProvider,\n 'EVM account provider must be first',\n );\n\n return [evmProvider, ...otherProviders];\n }\n\n /**\n * Create accounts for a given provider and group index range.\n *\n * @param provider - The provider to create accounts for.\n * @param from - The starting group index (inclusive).\n * @param to - The ending group index (inclusive).\n * @returns The created accounts.\n */\n async #createAccountsRangeForProvider(\n provider: Bip44AccountProvider<Account>,\n from: number,\n to: number,\n ): Promise<Bip44Account<Account>[]> {\n const isBatching = to > from;\n\n try {\n return await provider.createAccounts({\n type: AccountCreationType.Bip44DeriveIndexRange,\n entropySource: this.#entropySource,\n range: {\n from,\n to,\n },\n });\n } catch (error) {\n reportError(\n this.#messenger,\n `Unable to create ${isBatching ? 'some accounts (batch)' : 'some accounts'} with provider \"${provider.getName()}\"`,\n error,\n {\n range: { from, to },\n provider: provider.getName(),\n isBatching,\n },\n );\n throw error;\n }\n }\n\n /**\n * Create or update a multichain account group state for a given group index and group state.\n *\n * @param groupIndex The group's index.\n * @param groupState The group's state to create or update the group with.\n * @returns The created or updated multichain account group.\n */\n #createOrUpdateMultichainAccountGroup(\n groupIndex: number,\n groupState: GroupState,\n ): MultichainAccountGroup<Account> {\n let group = this.#accountGroups.get(groupIndex);\n if (group) {\n // NOTE: This will publish an update event automatically.\n group.update(groupState);\n\n this.#log(`Group updated: [${group.id}]`);\n } else {\n group = new MultichainAccountGroup({\n wallet: this,\n providers: this.#providers,\n groupIndex,\n messenger: this.#messenger,\n });\n group.init(groupState);\n\n this.#accountGroups.set(groupIndex, group);\n\n this.#log(`Group created: [${group.id}]`);\n\n if (this.#initialized) {\n this.#messenger.publish(\n 'MultichainAccountService:multichainAccountGroupCreated',\n group,\n );\n }\n }\n\n return group;\n }\n\n /**\n * Build group state for a range of group indices by calling all providers in parallel.\n *\n * This is a non-locking shared core used by both creation and alignment paths.\n *\n * @param from - Starting group index (inclusive).\n * @param to - Ending group index (inclusive).\n * @param providers - The providers to create accounts for.\n * @returns The collected group state and any provider failure messages.\n */\n async #buildGroupStateForRange(\n from: number,\n to: number,\n providers: Bip44AccountProvider<Account>[],\n ): Promise<{\n groupStateByGroupIndex: Map<number, GroupState>;\n failures: string[];\n }> {\n const groupStateByGroupIndex = new Map<number, GroupState>();\n\n const results = await Promise.allSettled(\n providers.map(async (provider) => {\n const providerName = provider.getName();\n const accounts = await this.#createAccountsRangeForProvider(\n provider,\n from,\n to,\n );\n accounts.forEach((account) => {\n const { groupIndex } = account.options.entropy;\n let groupState = groupStateByGroupIndex.get(groupIndex);\n if (!groupState) {\n groupState = {};\n groupStateByGroupIndex.set(groupIndex, groupState);\n }\n if (!groupState[providerName]) {\n groupState[providerName] = [];\n }\n groupState[providerName].push(account.id);\n });\n }),\n );\n\n const failures = providers.reduce((messages: string[], provider, index) => {\n const result = results[index];\n if (result?.status === 'rejected') {\n messages.push(\n `[${provider.getName()}] ${toErrorMessage(result.reason)}`,\n );\n }\n return messages;\n }, []);\n\n return { groupStateByGroupIndex, failures };\n }\n\n /**\n * Internal method to create a range of multichain account groups.\n *\n * This method acquires the wallet lock internally and creates accounts for all\n * given providers synchronously. Callers decide which providers to pass.\n *\n * @param range - The range of group indices to create.\n * @param range.from - Starting group index to create (inclusive).\n * @param range.to - Maximum group index to create (inclusive).\n * @param providers - The providers to create accounts for.\n * @returns Array of created multichain account groups.\n */\n async #createMultichainAccountGroupsRange(\n { from: rangeFrom, to }: Required<GroupIndexRange>,\n providers: Bip44AccountProvider<Account>[],\n ): Promise<MultichainAccountGroup<Account>[]> {\n return await this.#withLock('in-progress:create-accounts', async () => {\n const groups: MultichainAccountGroup<Account>[] = [];\n\n // Get existing groups (fromGroupIndex to nextGroupIndex - 1).\n let from = rangeFrom;\n for (; from <= to; from++) {\n const group = this.getMultichainAccountGroup(from);\n if (group) {\n groups.push(group);\n } else {\n break; // Assuming we have no gap, if the group does not exist, we can stop and create the remaining ones.\n }\n }\n\n // Create new groups now.\n if (from <= to) {\n this.#log(`Creating groups from index ${from} to ${to}...`);\n\n const { groupStateByGroupIndex, failures } =\n await this.#buildGroupStateForRange(from, to, providers);\n\n // Check for provider failures — always treated as hard errors.\n if (failures.length) {\n throw new Error(\n failures.reduce(\n (message, failure) => `${message}\\n- ${failure}`,\n 'Unable to create some accounts. Providers threw the following errors:',\n ),\n );\n }\n\n // Create or update groups from the collected state.\n for (let groupIndex = from; groupIndex <= to; groupIndex++) {\n const groupState = groupStateByGroupIndex.get(groupIndex);\n\n if (groupState) {\n const group = this.#createOrUpdateMultichainAccountGroup(\n groupIndex,\n groupState,\n );\n\n groups.push(group);\n } else {\n this.#log(\n `${WARNING_PREFIX} Failed to create new group for group index: ${groupIndex} because no accounts were created for it`,\n );\n }\n }\n }\n\n return groups;\n });\n }\n\n /**\n * Align accounts for a range of group indices (non-locking).\n *\n * Calls all providers in parallel via the batch API. Provider failures are\n * logged as warnings (best-effort); no error is thrown.\n *\n * @param range - The range of group indices to align.\n * @param range.from - Starting group index (inclusive).\n * @param range.to - Ending group index (inclusive).\n * @param providers - The providers to align accounts for.\n * @param options - Options.\n * @param options.trace - Trace options.\n * @param options.trace.data - Optional trace data.\n */\n async #alignAccountsForRange(\n { from, to }: Required<GroupIndexRange>,\n providers: Bip44AccountProvider<Account>[],\n options: { trace?: { data?: TraceRequest['data'] } } = {},\n ): Promise<void> {\n await this.#trace(\n {\n name: TraceName.WalletAlignment,\n data: {\n from,\n to,\n ...toProviderDataTraces(providers),\n ...options.trace?.data,\n },\n },\n async () => {\n const { groupStateByGroupIndex, failures } =\n await this.#buildGroupStateForRange(from, to, providers);\n\n if (failures.length) {\n const error = failures.reduce(\n (message, failure) => `${message}\\n- ${failure}`,\n 'Unable to align some accounts. Providers threw the following errors:',\n );\n console.warn(error);\n this.#log(`${WARNING_PREFIX} ${error}`);\n }\n\n for (let groupIndex = from; groupIndex <= to; groupIndex++) {\n const groupState = groupStateByGroupIndex.get(groupIndex);\n if (groupState) {\n this.#createOrUpdateMultichainAccountGroup(groupIndex, groupState);\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 is used and non-EVM account creation is deferred via\n * {@link MultichainAccountWallet.alignAccountsOf}. Defaults to `false`.\n * @throws If groupIndex is greater than the next available group index.\n * @throws If any account provider fails to create accounts.\n * @returns The multichain account group for this group index.\n */\n async createMultichainAccountGroup(\n groupIndex: number,\n options: {\n waitForAllProvidersToFinishCreatingAccounts?: boolean;\n } = {},\n ): Promise<MultichainAccountGroup<Account>> {\n // Use this to avoid having it as `boolean | undefined`.\n const waitForAllProvidersToFinishCreatingAccounts =\n options.waitForAllProvidersToFinishCreatingAccounts ?? false;\n\n return await this.#trace(\n {\n name: TraceName.WalletCreateMultichainAccountGroup,\n data: {\n groupIndex,\n waitForAllProvidersToFinishCreatingAccounts,\n },\n },\n async () => {\n assertGroupIndexIsValid(groupIndex, this.getNextGroupIndex());\n\n // If the group already exists, return it.\n const existingGroup = this.getMultichainAccountGroup(groupIndex);\n if (existingGroup) {\n this.#log(\n `Trying to re-create existing group: [${existingGroup.id}] (idempotent)`,\n );\n return existingGroup;\n }\n\n // Create a single group with a range of 1 (so we can reuse the batch creation logic) for the\n // given group index.\n const groups = await this.#createMultichainAccountGroups(\n { from: groupIndex, to: groupIndex },\n options,\n );\n\n const group = groups[0];\n assert(group, `Expected group at index ${groupIndex} to exist`);\n return group;\n },\n );\n }\n\n /**\n * Creates multiple multichain account groups up to maxGroupIndex.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n *\n * @param range - The range of group indices to create.\n * @param range.from - Starting group index to create (inclusive) (defaults to 0).\n * @param range.to - Maximum group index to create (inclusive).\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 is used and non-EVM account creation is deferred via\n * {@link MultichainAccountWallet.alignAccounts}. Defaults to false.\n * @throws If range is invalid (e.g. from is greater than to, from or to is negative, etc.).\n * @returns Array of created multichain account groups.\n */\n async createMultichainAccountGroups(\n { from = 0, to }: GroupIndexRange,\n options: {\n waitForAllProvidersToFinishCreatingAccounts?: boolean;\n } = {},\n ): Promise<MultichainAccountGroup<Account>[]> {\n // Use this to avoid having it as `boolean | undefined`.\n const waitForAllProvidersToFinishCreatingAccounts =\n options.waitForAllProvidersToFinishCreatingAccounts ?? false;\n\n return await this.#trace(\n {\n name: TraceName.WalletCreateMultichainAccountGroups,\n data: {\n from,\n to,\n waitForAllProvidersToFinishCreatingAccounts,\n },\n },\n async () =>\n await this.#createMultichainAccountGroups({ from, to }, options),\n );\n }\n\n /**\n * Creates multiple multichain account groups up to maxGroupIndex.\n *\n * NOTE: This operation WILL lock the wallet's mutex.\n *\n * @param range - The range of group indices to create.\n * @param range.from - Starting group index to create (inclusive).\n * @param range.to - Maximum group index to create (inclusive).\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 is used and non-EVM account creation is deferred via\n * {@link MultichainAccountWallet.alignAccounts}. Defaults to false.\n * @throws If range is invalid (e.g. from is greater than to, from or to is negative, etc.).\n * @returns Array of created multichain account groups.\n */\n async #createMultichainAccountGroups(\n { from, to }: Required<GroupIndexRange>,\n options: {\n waitForAllProvidersToFinishCreatingAccounts?: boolean;\n },\n ): Promise<MultichainAccountGroup<Account>[]> {\n assertGroupIndexRangeIsValid({ from, to });\n assertGroupIndexIsValid(from, this.getNextGroupIndex());\n\n const waitForAllProvidersToFinishCreatingAccounts =\n options.waitForAllProvidersToFinishCreatingAccounts ?? false;\n\n const [evmProvider, ...otherProviders] = this.#getProviders();\n const providers = waitForAllProvidersToFinishCreatingAccounts\n ? this.#providers\n : [evmProvider];\n\n const groups = await this.#createMultichainAccountGroupsRange(\n { from, to },\n providers,\n );\n\n // We need to run a post-alignment since non-EVM accounts have not\n // been created yet.\n if (!waitForAllProvidersToFinishCreatingAccounts) {\n const alignOtherAccounts = async (): Promise<void> => {\n this.#log(`Aligning accounts... (post)`);\n\n await this.#withLock('in-progress:alignment', async () => {\n await this.#alignAccountsForRange({ from, to }, otherProviders, {\n trace: {\n data: {\n post: true, // Tag to identify post-alignment traces in analytics.\n },\n },\n });\n });\n\n this.#log('Aligned accounts! (post)');\n };\n\n // eslint-disable-next-line no-void\n void alignOtherAccounts().catch((error) => {\n const errorMessage = `Unable to align non-EVM accounts from group index ${from} to ${to}`;\n this.#log(\n `${ERROR_PREFIX} ${errorMessage}: ${toErrorMessage(error)} (post)`,\n );\n console.error(errorMessage, error);\n });\n }\n\n return groups;\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 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 const nextGroupIndex = this.getNextGroupIndex();\n\n if (nextGroupIndex > 0) {\n this.#log('Aligning accounts...');\n\n const from = 0;\n const to = nextGroupIndex - 1;\n\n await this.#withLock(\n 'in-progress:alignment',\n async () =>\n await this.#alignAccountsForRange({ from, to }, this.#providers),\n );\n\n this.#log('Aligned!');\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 const group = this.getMultichainAccountGroup(groupIndex);\n\n if (group) {\n this.#log(`Aligning accounts for group \"${group.id}\"...`);\n\n await this.#withLock(\n 'in-progress:alignment',\n async () =>\n await this.#alignAccountsForRange(\n { from: groupIndex, to: groupIndex },\n this.#providers,\n { trace: { data: { groupIndex } } },\n ),\n );\n\n this.#log(`Aligned accounts for group \"${group.id}\"!`);\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 ): Promise<void> => {\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\n log(\n message(\n `failed (with: \"${toErrorMessage(error)}\")`,\n targetGroupIndex,\n ),\n );\n\n reportError(\n this.#messenger,\n `Unable to discover accounts with provider \"${providerName}\"`,\n error,\n {\n provider: providerName,\n groupIndex: targetGroupIndex,\n },\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 const nextGroupIndex = this.getNextGroupIndex();\n if (nextGroupIndex > 0) {\n await this.#alignAccountsForRange(\n { from: 0, to: nextGroupIndex - 1 },\n this.#providers,\n {\n trace: {\n data: {\n discovery: true, // Tag to identify discovery-alignment traces in analytics.\n },\n },\n },\n );\n }\n\n return providerContexts.flatMap((context) => context.accounts);\n });\n }\n}\n"]}
|
package/dist/analytics/perf.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withLocalPerfTrace = exports.tick = exports.isPerfEnabled = exports.log = void 0;
|
|
4
|
-
const timer_1 = require("./timer.cjs");
|
|
5
4
|
const logger_1 = require("../logger.cjs");
|
|
5
|
+
const timer_1 = require("./timer.cjs");
|
|
6
6
|
exports.log = (0, logger_1.createModuleLogger)(logger_1.projectLogger, 'perf');
|
|
7
7
|
/**
|
|
8
8
|
* Returns true when DEBUG=metamask:multichain-account-service, DEBUG=metamask:multichain-account-service:perf
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perf.cjs","sourceRoot":"","sources":["../../src/analytics/perf.ts"],"names":[],"mappings":";;;AAMA,
|
|
1
|
+
{"version":3,"file":"perf.cjs","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AAC;QAClC,CAAC;gBAAS,CAAC;YACT,IAAI,EAAE,CAAC;QACT,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAhBD,gDAgBC","sourcesContent":["import type {\n TraceCallback,\n TraceContext,\n TraceRequest,\n} from '@metamask/controller-utils';\n\nimport { createModuleLogger, projectLogger } from '../logger';\nimport { now } from './timer';\n\nexport const log = createModuleLogger(projectLogger, 'perf');\n\n/**\n * Returns true when DEBUG=metamask:multichain-account-service, DEBUG=metamask:multichain-account-service:perf\n * or a matching glob is set.\n * Re-uses the same enable/disable logic as the rest of the package loggers.\n *\n * @returns True if performance logging is enabled, false otherwise.\n */\nexport function isPerfEnabled(): boolean {\n return projectLogger.enabled || log.enabled;\n}\n\n/**\n * Starts a local performance timer. Returns a `tock` function that, when called,\n * logs the elapsed time for `label`.\n *\n * @example\n * ```ts\n * const tock = tick(request);\n * await createAccounts(...);\n * tock(); // logs: \"${request.name}: 123.45ms\"\n * ```\n *\n * @param request - A trace request object containing the name and optional data.\n * @returns A function that, when called, logs the elapsed time since `tick` was called.\n */\nexport function tick(request: TraceRequest): () => void {\n if (!isPerfEnabled()) {\n return () => undefined;\n }\n\n const start = now();\n return function tock(): void {\n const duration = now() - start;\n\n const context = request.data ? ` (${JSON.stringify(request.data)})` : '';\n\n log(`${request.name}${context}: ${duration.toFixed(2)}ms`);\n };\n}\n\n/**\n * Wraps a trace callback with local performance logging.\n *\n * @param trace - The original trace callback to wrap.\n * @returns A new trace callback that logs the duration of the traced operation.\n */\nexport function withLocalPerfTrace(trace: TraceCallback): TraceCallback {\n return async <ReturnType>(\n request: TraceRequest,\n fn?: (context?: TraceContext) => ReturnType,\n ): Promise<ReturnType> => {\n if (!isPerfEnabled()) {\n return await trace(request, fn);\n }\n\n const tock = tick(request);\n try {\n return await trace(request, fn);\n } finally {\n tock();\n }\n };\n}\n"]}
|
package/dist/analytics/perf.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { now } from "./timer.mjs";
|
|
2
1
|
import { createModuleLogger, projectLogger } from "../logger.mjs";
|
|
2
|
+
import { now } from "./timer.mjs";
|
|
3
3
|
export const log = createModuleLogger(projectLogger, 'perf');
|
|
4
4
|
/**
|
|
5
5
|
* Returns true when DEBUG=metamask:multichain-account-service, DEBUG=metamask:multichain-account-service:perf
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perf.mjs","sourceRoot":"","sources":["../../src/analytics/perf.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"perf.mjs","sourceRoot":"","sources":["../../src/analytics/perf.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,sBAAkB;AAC9D,OAAO,EAAE,GAAG,EAAE,oBAAgB;AAE9B,MAAM,CAAC,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;AAE7D;;;;;;GAMG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,aAAa,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC;AAC9C,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,IAAI,CAAC,OAAqB;IACxC,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;QACrB,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC;IACzB,CAAC;IAED,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC;IACpB,OAAO,SAAS,IAAI;QAClB,MAAM,QAAQ,GAAG,GAAG,EAAE,GAAG,KAAK,CAAC;QAE/B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAEzE,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,GAAG,OAAO,KAAK,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC7D,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAoB;IACrD,OAAO,KAAK,EACV,OAAqB,EACrB,EAA2C,EACtB,EAAE;QACvB,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;YACrB,OAAO,MAAM,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAClC,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3B,IAAI,CAAC;YACH,OAAO,MAAM,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAClC,CAAC;gBAAS,CAAC;YACT,IAAI,EAAE,CAAC;QACT,CAAC;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type {\n TraceCallback,\n TraceContext,\n TraceRequest,\n} from '@metamask/controller-utils';\n\nimport { createModuleLogger, projectLogger } from '../logger';\nimport { now } from './timer';\n\nexport const log = createModuleLogger(projectLogger, 'perf');\n\n/**\n * Returns true when DEBUG=metamask:multichain-account-service, DEBUG=metamask:multichain-account-service:perf\n * or a matching glob is set.\n * Re-uses the same enable/disable logic as the rest of the package loggers.\n *\n * @returns True if performance logging is enabled, false otherwise.\n */\nexport function isPerfEnabled(): boolean {\n return projectLogger.enabled || log.enabled;\n}\n\n/**\n * Starts a local performance timer. Returns a `tock` function that, when called,\n * logs the elapsed time for `label`.\n *\n * @example\n * ```ts\n * const tock = tick(request);\n * await createAccounts(...);\n * tock(); // logs: \"${request.name}: 123.45ms\"\n * ```\n *\n * @param request - A trace request object containing the name and optional data.\n * @returns A function that, when called, logs the elapsed time since `tick` was called.\n */\nexport function tick(request: TraceRequest): () => void {\n if (!isPerfEnabled()) {\n return () => undefined;\n }\n\n const start = now();\n return function tock(): void {\n const duration = now() - start;\n\n const context = request.data ? ` (${JSON.stringify(request.data)})` : '';\n\n log(`${request.name}${context}: ${duration.toFixed(2)}ms`);\n };\n}\n\n/**\n * Wraps a trace callback with local performance logging.\n *\n * @param trace - The original trace callback to wrap.\n * @returns A new trace callback that logs the duration of the traced operation.\n */\nexport function withLocalPerfTrace(trace: TraceCallback): TraceCallback {\n return async <ReturnType>(\n request: TraceRequest,\n fn?: (context?: TraceContext) => ReturnType,\n ): Promise<ReturnType> => {\n if (!isPerfEnabled()) {\n return await trace(request, fn);\n }\n\n const tock = tick(request);\n try {\n return await trace(request, fn);\n } finally {\n tock();\n }\n };\n}\n"]}
|
package/dist/errors.cjs
CHANGED
|
@@ -17,7 +17,7 @@ const utils_2 = require("./utils.cjs");
|
|
|
17
17
|
* @param context - Optional context to attach to the Sentry error.
|
|
18
18
|
*/
|
|
19
19
|
function reportError(messenger, message, error, context) {
|
|
20
|
-
if ((0, utils_1.isTimeoutError)(error)) {
|
|
20
|
+
if ((0, utils_1.isTimeoutError)(error) || (0, utils_1.isKeyringControllerLockedError)(error)) {
|
|
21
21
|
(0, logger_1.logErrorAs)('warn', message, error);
|
|
22
22
|
console.warn(message, error);
|
|
23
23
|
}
|
package/dist/errors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AACtC,
|
|
1
|
+
{"version":3,"file":"errors.cjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AACtC,iDAG2B;AAC3B,uCAA4C;AAE5C;;;;;;;;;;;GAWG;AACH,SAAgB,WAAW,CACzB,SAAwD,EACxD,OAAe,EACf,KAAc,EACd,OAAiC;IAEjC,IAAI,IAAA,sBAAc,EAAC,KAAK,CAAC,IAAI,IAAA,sCAA8B,EAAC,KAAK,CAAC,EAAE,CAAC;QACnE,IAAA,mBAAU,EAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACnC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC;SAAM,CAAC;QACN,IAAA,mBAAU,EAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACpC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAE9B,MAAM,WAAW,GAAG,IAAA,yBAAiB,EAAC,OAAO,EAAE,KAAc,EAAE,OAAO,CAAC,CAAC;QACxE,SAAS,CAAC,gBAAgB,EAAE,CAAC,WAAW,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC;AAhBD,kCAgBC","sourcesContent":["import { logErrorAs } from './logger';\nimport {\n isKeyringControllerLockedError,\n isTimeoutError,\n} from './providers/utils';\nimport { createSentryError } from './utils';\n\n/**\n * Reports an error by logging it and optionally capturing it in Sentry.\n *\n * Timeout errors are treated as warnings (not reported to Sentry). All other\n * errors are logged as errors and captured via `captureException`.\n *\n * @param messenger - Object with an optional `captureException` method.\n * @param messenger.captureException - Optional method to capture exceptions in Sentry.\n * @param message - The static message describing what failed.\n * @param error - The caught error.\n * @param context - Optional context to attach to the Sentry error.\n */\nexport function reportError(\n messenger: { captureException?: (error: Error) => void },\n message: string,\n error: unknown,\n context?: Record<string, unknown>,\n): void {\n if (isTimeoutError(error) || isKeyringControllerLockedError(error)) {\n logErrorAs('warn', message, error);\n console.warn(message, error);\n } else {\n logErrorAs('error', message, error);\n console.error(message, error);\n\n const sentryError = createSentryError(message, error as Error, context);\n messenger.captureException?.(sentryError);\n }\n}\n"]}
|
package/dist/errors.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.cts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.d.cts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE;IAAE,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;CAAE,EACxD,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,IAAI,CAWN"}
|
package/dist/errors.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.mts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.d.mts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE;IAAE,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;CAAE,EACxD,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,IAAI,CAWN"}
|
package/dist/errors.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logErrorAs } from "./logger.mjs";
|
|
2
|
-
import { isTimeoutError } from "./providers/utils.mjs";
|
|
2
|
+
import { isKeyringControllerLockedError, isTimeoutError } from "./providers/utils.mjs";
|
|
3
3
|
import { createSentryError } from "./utils.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* Reports an error by logging it and optionally capturing it in Sentry.
|
|
@@ -14,7 +14,7 @@ import { createSentryError } from "./utils.mjs";
|
|
|
14
14
|
* @param context - Optional context to attach to the Sentry error.
|
|
15
15
|
*/
|
|
16
16
|
export function reportError(messenger, message, error, context) {
|
|
17
|
-
if (isTimeoutError(error)) {
|
|
17
|
+
if (isTimeoutError(error) || isKeyringControllerLockedError(error)) {
|
|
18
18
|
logErrorAs('warn', message, error);
|
|
19
19
|
console.warn(message, error);
|
|
20
20
|
}
|