UNPKG

@metamask/multichain-account-service

Version:
120 lines 4.47 kB
import { AccountGroupType } from "@metamask/account-api"; import type { MultichainAccountGroupId, MultichainAccountGroup as MultichainAccountGroupDefinition } from "@metamask/account-api"; import type { Bip44Account } from "@metamask/account-api"; import type { AccountSelector } from "@metamask/account-api"; import type { KeyringAccount } from "@metamask/keyring-api"; import type { ServiceState, StateKeys } from "./MultichainAccountService.mjs"; import type { MultichainAccountWallet } from "./MultichainAccountWallet.mjs"; import type { Bip44AccountProvider } from "./providers/index.mjs"; import type { MultichainAccountServiceMessenger } from "./types.mjs"; export type GroupState = ServiceState[StateKeys['entropySource']][StateKeys['groupIndex']]; /** * A multichain account group that holds multiple accounts. */ export declare class MultichainAccountGroup<Account extends Bip44Account<KeyringAccount>> implements MultichainAccountGroupDefinition<Account> { #private; constructor({ groupIndex, wallet, providers, messenger, }: { groupIndex: number; wallet: MultichainAccountWallet<Account>; providers: Bip44AccountProvider<Account>[]; messenger: MultichainAccountServiceMessenger; }); /** * Initialize the multichain account group and construct the internal representation of accounts. * * @param groupState - The group state. */ init(groupState: GroupState): void; /** * Update the group state. * * @param groupState - The group state. */ update(groupState: GroupState): void; /** * Gets the multichain account group ID. * * @returns The multichain account group ID. */ get id(): MultichainAccountGroupId; /** * Gets the multichain account group type. * * @returns The multichain account type. */ get type(): AccountGroupType.MultichainAccount; /** * Gets the multichain account's wallet reference (parent). * * @returns The multichain account's wallet. */ get wallet(): MultichainAccountWallet<Account>; /** * Gets the multichain account group index. * * @returns The multichain account group index. */ get groupIndex(): number; /** * Checks if there's any underlying accounts for this multichain accounts. * * @returns True if there's any underlying accounts, false otherwise. */ hasAccounts(): boolean; /** * Gets the accounts for this multichain account. * * @returns The accounts. */ getAccounts(): Account[]; /** * Gets the account IDs for this multichain account. * * @returns The account IDs. */ getAccountIds(): Account['id'][]; /** * Gets the account for a given account ID. * * @param id - Account ID. * @returns The account or undefined if not found. */ getAccount(id: Account['id']): Account | undefined; /** * Query an account matching the selector. * * @param selector - Query selector. * @returns The account matching the selector or undefined if not matching. * @throws If multiple accounts match the selector. */ get(selector: AccountSelector<Account>): Account | undefined; /** * Query accounts matching the selector. * * @param selector - Query selector. * @returns The accounts matching the selector. */ select(selector: AccountSelector<Account>): Account[]; /** * Check whether every provider has an aligned account in this group. * * A group is aligned when every registered provider reports that the * account IDs it contributed to this group are non-empty and owned by it. * Disabled {@link AccountProviderWrapper} instances always report `true`. * * @returns `true` when all providers are aligned for this group. */ isAligned(): boolean; /** * Check whether a single provider has an aligned account in this group. * * A provider is aligned when the account IDs it contributed to this group are * non-empty and owned by it. Disabled {@link AccountProviderWrapper} instances * always report `true`. * * @param provider - The provider to check. * @returns `true` when the provider is aligned for this group. */ isProviderAligned(provider: Bip44AccountProvider<Account>): boolean; } //# sourceMappingURL=MultichainAccountGroup.d.mts.map