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AChD,2BAA2B,CAAC,OAAO,CAAC,CAAC;QAErC,MAAM,aAAa,GAAG,CAAC,OAAO,CAAC,CAAC;QAChC,IAAA,4CAAsB,EAAC,aAAa,CAAC,CAAC;QAEtC,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,CAG/B;QACC,OAAO,EAAE,CAAC,CAAC,qCAAqC;IAClD,CAAC;CACF;AAvDD,gDAuDC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport { EthAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type {\n  EthKeyring,\n  InternalAccount,\n} from '@metamask/keyring-internal-api';\nimport type { Hex } from '@metamask/utils';\n\nimport {\n  assertAreBip44Accounts,\n  BaseAccountProvider,\n} from './BaseAccountProvider';\n\n/**\n * Asserts an internal account exists.\n *\n * @param account - The internal account to check.\n * @throws An error if the internal account does not exist.\n */\nfunction assertInternalAccountExists(\n  account: InternalAccount | undefined,\n): asserts account is InternalAccount {\n  if (!account) {\n    throw new Error('Internal account does not exist');\n  }\n}\n\nexport class EvmAccountProvider extends BaseAccountProvider {\n  isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n    return (\n      account.type === EthAccountType.Eoa &&\n      account.metadata.keyring.type === (KeyringTypes.hd as string)\n    );\n  }\n\n  async createAccounts({\n    entropySource,\n    groupIndex,\n  }: {\n    entropySource: EntropySourceId;\n    groupIndex: number;\n  }) {\n    const [address] = await this.withKeyring<EthKeyring, Hex[]>(\n      { id: entropySource },\n      async ({ keyring }) => {\n        const accounts = await keyring.getAccounts();\n        if (groupIndex < accounts.length) {\n          // Nothing new to create, we just re-use the existing accounts here,\n          return [accounts[groupIndex]];\n        }\n\n        // For now, we don't allow for gap, so if we need to create a new\n        // account, this has to be the next one.\n        if (groupIndex !== accounts.length) {\n          throw new Error('Trying to create too many accounts');\n        }\n\n        // Create next account (and returns their addresses).\n        return await keyring.addAccounts(1);\n      },\n    );\n\n    const account = this.messenger.call(\n      'AccountsController:getAccountByAddress',\n      address,\n    );\n\n    // We MUST have the associated internal account.\n    assertInternalAccountExists(account);\n\n    const accountsArray = [account];\n    assertAreBip44Accounts(accountsArray);\n\n    return accountsArray;\n  }\n\n  async discoverAndCreateAccounts(_: {\n    entropySource: EntropySourceId;\n    groupIndex: number;\n  }) {\n    return []; // TODO: Implement account discovery.\n  }\n}\n"]}