import type { AccountGroupId, AccountWalletId, AccountSelector } from "@metamask/account-api"; import type { AccountId } from "@metamask/accounts-controller"; import { BaseController } from "@metamask/base-controller"; import type { InternalAccount } from "@metamask/keyring-internal-api"; import type { AccountGroupObject, AccountTypeOrderKey } from "./group.mjs"; import { ACCOUNT_TYPE_TO_SORT_ORDER } from "./group.mjs"; import type { AccountTreeControllerConfig, AccountTreeControllerMessenger, AccountTreeControllerState } from "./types.mjs"; import type { AccountWalletObject } from "./wallet.mjs"; export declare const controllerName = "AccountTreeController"; /** * Gets default state of the `AccountTreeController`. * * @returns The default state of the `AccountTreeController`. */ export declare function getDefaultAccountTreeControllerState(): AccountTreeControllerState; /** * Context for an account. */ export type AccountContext = { /** * Wallet ID associated to that account. */ walletId: AccountWalletObject['id']; /** * Account group ID associated to that account. */ groupId: AccountGroupObject['id']; /** * Sort order of the account. */ sortOrder: (typeof ACCOUNT_TYPE_TO_SORT_ORDER)[AccountTypeOrderKey]; }; export declare class AccountTreeController extends BaseController { #private; /** * Constructor for AccountTreeController. * * @param options - The controller options. * @param options.messenger - The messenger object. * @param options.state - Initial state to set on this controller * @param options.config - Optional configuration for the controller. */ constructor({ messenger, state, config, }: { messenger: AccountTreeControllerMessenger; state?: Partial; config?: AccountTreeControllerConfig; }); /** * Initialize the controller's state. * * It constructs the initial state of the account tree (tree nodes, nodes * names, metadata, etc..) and will automatically update the controller's * state with it. */ init(): void; /** * Re-initialize the controller's state. * * This is done in one single (atomic) `update` block to avoid having a temporary * cleared state. Use this when you need to force a full re-init even if already initialized. */ reinit(): void; /** * Gets the account wallet object from its ID. * * @param walletId - Account wallet ID. * @returns The account wallet object if found, undefined otherwise. */ getAccountWalletObject(walletId: AccountWalletId): AccountWalletObject | undefined; /** * Gets all account wallet objects. * * @returns All account wallet objects. */ getAccountWalletObjects(): AccountWalletObject[]; /** * Gets all underlying accounts from the currently selected account * group. * * It also support account selector, which allows to filter specific * accounts given some criterias (account type, address, scopes, etc...). * * @param selector - Optional account selector. * @returns Underlying accounts for the currently selected account (filtered * by the selector if provided). */ getAccountsFromSelectedAccountGroup(selector?: AccountSelector): { type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "stellar:account" | "any:account"; id: string; options: Record & { entropy?: { type: "mnemonic"; id: string; derivationPath: string; groupIndex: number; } | { type: "private-key"; } | { type: "custom"; } | undefined; exportable?: boolean | undefined; }; /** * Handles "AccountsController:accountsRemoved" event to remove * given accounts from the tree in a single state update. * * @param accountIds - Removed account IDs. */ metadata: { name: string; importTime: number; keyring: { type: string; }; snap?: { id: string; } | undefined; nameLastUpdatedAt?: number | undefined; lastSelected?: number | undefined; }; address: string; scopes: `${string}:${string}`[]; methods: string[]; }[]; /** * Gets the account group object from its ID. * * @param groupId - Account group ID. * @returns The account group object if found, undefined otherwise. */ getAccountGroupObject(groupId: AccountGroupId): AccountGroupObject | undefined; /** * Gets the account's context which contains its wallet ID, group ID, and sort order. * * @param accountId - Account ID. * @returns The account context if found, undefined otherwise. */ getAccountContext(accountId: AccountId): AccountContext | undefined; /** * Gets the currently selected account group ID. * * @returns The selected account group ID or empty string if none selected. */ getSelectedAccountGroup(): AccountGroupId | ''; /** * Sets the selected account group and updates the AccountsController selectedAccount accordingly. * * @param groupId - The account group ID to select. */ setSelectedAccountGroup(groupId: AccountGroupId): void; /** * Sets a custom name for an account group. * * @param groupId - The account group ID. * @param name - The custom name to set. * @param autoHandleConflict - If true, automatically resolves name conflicts by adding a suffix. If false, throws on conflicts. * @throws If the account group ID is not found in the current tree. * @throws If the account group name already exists and autoHandleConflict is false. */ setAccountGroupName(groupId: AccountGroupId, name: string, autoHandleConflict?: boolean): void; /** * Sets a custom name for an account wallet. * * @param walletId - The account wallet ID. * @param name - The custom name to set. * @throws If the account wallet ID is not found in the current tree. */ setAccountWalletName(walletId: AccountWalletId, name: string): void; /** * Toggles the pinned state of an account group. * * @param groupId - The account group ID. * @param pinned - Whether the group should be pinned. * @throws If the account group ID is not found in the current tree. */ setAccountGroupPinned(groupId: AccountGroupId, pinned: boolean): void; /** * Toggles the hidden state of an account group. * * @param groupId - The account group ID. * @param hidden - Whether the group should be hidden. * @throws If the account group ID is not found in the current tree. */ setAccountGroupHidden(groupId: AccountGroupId, hidden: boolean): void; /** * Clears the controller state and resets to default values. * Also clears the backup and sync service state. */ clearState(): void; /** * Bi-directionally syncs the account tree with user storage. * This will perform a full sync, including both pulling updates * from user storage and pushing local changes to user storage. * This also performs legacy account syncing if needed. * * IMPORTANT: * If a full sync is already in progress, it will return the ongoing promise. * * @returns A promise that resolves when the sync is complete. */ syncWithUserStorage(): Promise; /** * Bi-directionally syncs the account tree with user storage. * This will ensure at least one full sync is ran, including both pulling updates * from user storage and pushing local changes to user storage. * This also performs legacy account syncing if needed. * * IMPORTANT: * If the first ever full sync is already in progress, it will return the ongoing promise. * If the first ever full sync was previously completed, it will NOT start a new sync, and will resolve immediately. * * @returns A promise that resolves when the first ever full sync is complete. */ syncWithUserStorageAtLeastOnce(): Promise; } //# sourceMappingURL=AccountTreeController.d.mts.map