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C,IAAI,EAAE,EAAE,KAAK,MAAM,CAAC;AAC9C,CAAC","sourcesContent":["import type { SnapId } from '@metamask/snaps-sdk';\nimport type { Json, CaipAccountId, CaipChainId } from '@metamask/utils';\nimport { KnownCaipNamespace, parseCaipChainId } from '@metamask/utils';\n\n/**\n * Copy of the original type from\n * https://github.com/MetaMask/accounts/blob/main/packages/keyring-internal-api/src/types.ts\n */\nexport type InternalAccount = {\n  id: string;\n  type: string;\n  address: string;\n  options: Record<string, Json>;\n  methods: string[];\n  scopes: CaipChainId[];\n  metadata: {\n    name: string;\n    snap?: { id: SnapId; enabled: boolean; name: string };\n  };\n};\n\n/**\n * Create a list of CAIP account IDs from an address and a list of scopes.\n *\n * @param address - The address to create the account IDs from.\n * @param scopes - The scopes to create the account IDs from.\n * @returns The list of CAIP account IDs.\n */\nexport function createAccountList(\n  address: string,\n  scopes: CaipChainId[],\n): CaipAccountId[] {\n  return scopes.map((scope) => `${scope}:${address}`) as CaipAccountId[];\n}\n\n/**\n * Create a list of CAIP chain IDs from a list of account scopes and a list of requested chain IDs.\n *\n * @param accountScopes - The account scopes to create the chain ID list from.\n * @param requestedChainIds - The requested chain IDs to filter the account scopes by.\n * @returns The list of CAIP chain IDs.\n */\nexport function createChainIdList(\n  accountScopes: CaipChainId[],\n  requestedChainIds?: CaipChainId[],\n) {\n  // If there are no requested chain IDs, return all account scopes.\n  if (!requestedChainIds || requestedChainIds.length === 0) {\n    return accountScopes;\n  }\n\n  return accountScopes.reduce<CaipChainId[]>((acc, scope) => {\n    // If the scope represents all EVM compatible chains, return all requested chain IDs.\n    if (scope === 'eip155:0') {\n      const evmChainIds = requestedChainIds.filter((chainId) => {\n        const { namespace } = parseCaipChainId(chainId);\n\n        return namespace === KnownCaipNamespace.Eip155;\n      });\n\n      acc.push(...evmChainIds);\n    }\n\n    // If the scope is not in the requested chain IDs, skip it.\n    else if (requestedChainIds.includes(scope)) {\n      acc.push(scope);\n    }\n\n    return acc;\n  }, []);\n}\n\n/**\n * Whether if the snap owns the account.\n *\n * @param snapId - The snap id.\n * @param account - The account.\n * @returns True if the snap owns the account, otherwise false.\n */\nexport function snapOwnsAccount(snapId: SnapId, account: InternalAccount) {\n  return account.metadata.snap?.id === snapId;\n}\n"]}