@metamask-previews/account-api
Version:
MetaMask Multichain Account API
1 lines • 3.71 kB
Source Map (JSON)
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../../src/api/multichain/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport type { CaipChainId } from '@metamask/utils';\n\nimport type { MultichainAccountId, MultichainAccountWalletId } from './id';\nimport type { AccountGroup } from '../group';\nimport type { AccountWallet } from '../wallet';\n\nexport type AccountType = string;\n\nexport type AccountMethod = string;\n\nexport type MultichainAccountSelector = {\n id?: AccountId;\n address?: string;\n type?: AccountType;\n methods?: AccountMethod[];\n scopes?: CaipChainId[];\n};\n\nexport type MultichainAccount<Account extends KeyringAccount> =\n AccountGroup<Account> & {\n get id(): MultichainAccountId;\n\n get wallet(): MultichainAccountWallet<Account>;\n\n get index(): number;\n\n /**\n * Gets the \"blockchain\" accounts for this multichain account.\n *\n * @param id - Account ID.\n * @returns The \"blockchain\" accounts.\n */\n getAccounts(): Account[];\n\n /**\n * Gets the \"blockchain\" account for a given account ID.\n *\n * @param id - Account ID.\n * @returns The \"blockchain\" account or undefined if not found.\n */\n getAccount(id: AccountId): Account | undefined;\n\n /**\n * Query a \"blockchain\" account matching the selector.\n *\n * @param selector - Query selector.\n * @returns The \"blockchain\" account matching the selector or undefined if not matching.\n * @throws If multiple accounts match the selector.\n */\n get(selector: MultichainAccountSelector): Account | undefined;\n\n /**\n * Query \"blockchain\" accounts matching the selector.\n *\n * @param selector - Query selector.\n * @returns The \"blockchain\" accounts matching the selector.\n */\n select(selector: MultichainAccountSelector): Account[];\n };\n\nexport type MultichainAccountWallet<Account extends KeyringAccount> =\n AccountWallet<Account> & {\n get id(): MultichainAccountWalletId;\n\n get entropySource(): EntropySourceId;\n\n /**\n * Gets multichain account for a given index.\n *\n * @returns Multichain accounts.\n */\n getMultichainAccount(\n groupIndex: number,\n ): MultichainAccount<Account> | undefined;\n\n /**\n * Gets multichain accounts.\n *\n * @returns Multichain accounts.\n */\n getMultichainAccounts(): MultichainAccount<Account>[];\n\n /**\n * Gets the next available account index (named group index internally).\n *\n * @returns Next available group index.\n */\n getNextGroupIndex(): number;\n\n /**\n * Creates a new multichain account on a given group index.\n *\n * NOTE: This method is idempotent.\n *\n * @param groupIndex - Next available group index.\n * @returns New (or existing) multichain account for the given group index.\n */\n createMultichainAccount(\n groupIndex: number,\n ): Promise<MultichainAccount<Account>>;\n\n /**\n * Creates a new multichain account for the next available group index.\n *\n * @returns Next multichain account.\n */\n createNextMultichainAccount(): Promise<MultichainAccount<Account>>;\n\n /**\n * Discovers and automatically create multichain accounts for that wallet.\n *\n * @returns List of all multichain accounts that got discovered or automatically created.\n */\n discoverAndCreateMultichainAccounts(): Promise<\n MultichainAccount<Account>[]\n >;\n };\n"]}