@metamask/multichain-account-service
Version:
Service to manage multichain accounts
163 lines • 7.02 kB
text/typescript
import type { AccountGroupId, Bip44Account, MultichainAccountWalletId, MultichainAccountWallet as MultichainAccountWalletDefinition, MultichainAccountWalletStatus } from "@metamask/account-api";
import { AccountWalletType } from "@metamask/account-api";
import type { TraceCallback } from "@metamask/controller-utils";
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
import { MultichainAccountGroup } from "./MultichainAccountGroup.cjs";
import type { ServiceState, StateKeys } from "./MultichainAccountService.cjs";
import type { Bip44AccountProvider } from "./providers/index.cjs";
import type { MultichainAccountServiceMessenger } from "./types.cjs";
import { GroupIndexRange } from "./utils.cjs";
export type WalletState = ServiceState[StateKeys['entropySource']];
/**
* A multichain account wallet that holds multiple multichain accounts (one multichain account per
* group index).
*/
export declare class MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>> implements MultichainAccountWalletDefinition<Account> {
#private;
constructor({ providers, entropySource, messenger, trace, }: {
providers: Bip44AccountProvider<Account>[];
entropySource: EntropySourceId;
messenger: MultichainAccountServiceMessenger;
trace?: TraceCallback;
});
/**
* Initialize the wallet and construct the internal representation of multichain account groups.
*
* @param walletState - The wallet state.
*/
init(walletState: WalletState): void;
/**
* Gets the multichain account wallet ID.
*
* @returns The multichain account wallet ID.
*/
get id(): MultichainAccountWalletId;
/**
* Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
*
* @returns The multichain account wallet type.
*/
get type(): AccountWalletType.Entropy;
/**
* Gets the multichain account wallet entropy source.
*
* @returns The multichain account wallet entropy source.
*/
get entropySource(): EntropySourceId;
/**
* Gets the multichain account wallet current status.
*
* @returns The multichain account wallet current status.
*/
get status(): MultichainAccountWalletStatus;
/**
* Gets multichain account for a given ID.
* The default group ID will default to the multichain account with index 0.
*
* @param id - Account group ID.
* @returns Account group.
*/
getAccountGroup(id: AccountGroupId): MultichainAccountGroup<Account> | undefined;
/**
* Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccountGroups}.
*
* @returns The multichain accounts.
*/
getAccountGroups(): MultichainAccountGroup<Account>[];
/**
* Gets multichain account group 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 account groups.
*
* @returns The multichain accounts.
*/
getMultichainAccountGroups(): MultichainAccountGroup<Account>[];
/**
* Gets next group index for this wallet.
*
* @returns The next group index of this wallet.
*/
getNextGroupIndex(): number;
/**
* Creates a multichain account group for a given group index.
*
* NOTE: This operation WILL lock the wallet's mutex.
*
* @param groupIndex - The group index to use.
* @param options - Options to configure the account creation.
* @param options.waitForAllProvidersToFinishCreatingAccounts - Whether to wait for all
* account providers to finish creating their accounts before returning. If `false`, only
* the EVM provider is used and non-EVM account creation is deferred via
* {@link MultichainAccountWallet.alignAccountsOf}. Defaults to `false`.
* @throws If groupIndex is greater than the next available group index.
* @throws If any account provider fails to create accounts.
* @returns The multichain account group for this group index.
*/
createMultichainAccountGroup(groupIndex: number, options?: {
waitForAllProvidersToFinishCreatingAccounts?: boolean;
}): Promise<MultichainAccountGroup<Account>>;
/**
* Creates multiple multichain account groups up to maxGroupIndex.
*
* NOTE: This operation WILL lock the wallet's mutex.
*
* @param range - The range of group indices to create.
* @param range.from - Starting group index to create (inclusive) (defaults to 0).
* @param range.to - Maximum group index to create (inclusive).
* @param options - Options to configure the account creation.
* @param options.waitForAllProvidersToFinishCreatingAccounts - Whether to wait for all
* account providers to finish creating their accounts before returning. If `false`, only
* the EVM provider is used and non-EVM account creation is deferred via
* {@link MultichainAccountWallet.alignAccounts}. Defaults to false.
* @throws If range is invalid (e.g. from is greater than to, from or to is negative, etc.).
* @returns Array of created multichain account groups.
*/
createMultichainAccountGroups({ from, to }: GroupIndexRange, options?: {
waitForAllProvidersToFinishCreatingAccounts?: boolean;
}): Promise<MultichainAccountGroup<Account>[]>;
/**
* Creates the next multichain account group.
*
* @throws If any of the account providers fails to create their accounts.
* @returns The multichain account group for the next group index available.
*/
createNextMultichainAccountGroup(): Promise<MultichainAccountGroup<Account>>;
/**
* Align all accounts from each existing multichain account groups.
*
* NOTE: This operation WILL lock the wallet's mutex.
*/
alignAccounts(): Promise<void>;
/**
* Check whether every group in this wallet is aligned.
*
* A wallet is aligned when every multichain account group reports that all
* of its registered providers have contributed at least one account.
* Returns `true` if the wallet has no groups.
*
* @returns `true` when all groups are aligned.
*/
isAligned(): boolean;
/**
* Align a specific multichain account group.
*
* NOTE: This operation WILL lock the wallet's mutex.
*
* @param groupIndex - The group index to align.
*/
alignAccountsOf(groupIndex: number): Promise<void>;
/**
* Discover and create accounts for all providers.
*
* NOTE: This operation WILL lock the wallet's mutex.
*
* @returns The discovered accounts for each provider.
*/
discoverAccounts(): Promise<Account[]>;
}
//# sourceMappingURL=MultichainAccountWallet.d.cts.map