UNPKG

@metamask/account-api

Version:
126 lines 4.4 kB
import { type EntropySourceId, type KeyringAccount } from "@metamask/keyring-api"; import type { MultichainAccountGroup } from "./group.mjs"; import type { Bip44Account } from "../bip44.mjs"; import type { AccountGroup, AccountGroupId } from "../group.mjs"; import type { AccountWalletStatus, BaseAccountWallet } from "../wallet.mjs"; import { AccountWalletType } from "../wallet.mjs"; /** * Multichain account wallet ID. */ export type MultichainAccountWalletId = `${AccountWalletType.Entropy}:${EntropySourceId}`; /** * Regex to validate a valid multichain account wallet ID. */ export declare const MULTICHAIN_ACCOUNT_WALLET_ID_REGEX: RegExp; /** * Parsed multichain account wallet ID with its wallet type and sub-ID. */ export type ParsedMultichainAccountWalletId = { type: AccountWalletType.Entropy; subId: string; }; /** * Wallet status. * * Those status are used to report in which "state" the wallet is currently * in. All of those operations cannot run concurrently, thus, the wallet * cannot have multiple status at once. */ export type MultichainAccountWalletStatus = AccountWalletStatus /** * Discovery is in progress for this wallet. New account groups will be * automatically added based on the account provider discovery result. */ | 'in-progress:discovery' /** * Alignment is in progress for this wallet. Account groups will be * automatically updated based on the active account providers. */ | 'in-progress:alignment' /** * The wallet is creating new accounts. New account groups will be * added to the wallet automatically. */ | 'in-progress:create-accounts'; /** * A multichain account wallet that holds multiple multichain accounts (one multichain account per * group index). */ export type MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>> = BaseAccountWallet<Account> & { /** * Multichain account wallet ID. */ get id(): MultichainAccountWalletId; /** * Multichain account wallet type, which is always {@link AccountWalletType.Entropy}. */ get type(): AccountWalletType.Entropy; /** * Multichain account wallet entropy source. */ get entropySource(): EntropySourceId; /** * Multichain account wallet status. */ get status(): MultichainAccountWalletStatus; /** * Gets account group for a given ID. * * @param id - Account group ID. * @returns Account group. */ getAccountGroup(id: AccountGroupId): AccountGroup<Account> | undefined; /** * Gets all account groups. * * @returns Account groups. */ getAccountGroups(): AccountGroup<Account>[]; /** * Gets multichain account for a given index. * * @param groupIndex - Multichain account index. * @returns The multichain account associated with the given index. */ getMultichainAccountGroup(groupIndex: number): MultichainAccountGroup<Account> | undefined; /** * Gets all multichain accounts. * * @returns The multichain accounts. */ getMultichainAccountGroups(): MultichainAccountGroup<Account>[]; /** * Discover and create accounts. * * @returns The discovered accounts. */ discoverAccounts(): Promise<Account[]>; /** * Align all accounts accross existing multichain account groups. */ alignAccounts(): Promise<void>; }; /** * Gets the multichain account wallet ID from its entropy source. * * @param entropySource - Entropy source ID of that wallet. * @returns The multichain account wallet ID. */ export declare function toMultichainAccountWalletId(entropySource: EntropySourceId): MultichainAccountWalletId; /** * Checks if the given value is {@link MultichainAccountWalletId}. * * @param value - The value to check. * @returns Whether the value is a {@link MultichainAccountWalletId}. */ export declare function isMultichainAccountWalletId(value: string): value is MultichainAccountWalletId; /** * Parse a multichain account wallet ID to an object containing wallet ID * information (wallet type and sub-ID). * * @param walletId - The account wallet ID to validate and parse. * @returns The parsed account wallet ID. * @throws When the wallet ID format is invalid. */ export declare function parseMultichainAccountWalletId(walletId: string): ParsedMultichainAccountWalletId; //# sourceMappingURL=wallet.d.mts.map