@metamask/multichain-account-service
Version:
Service to manage multichain accounts
128 lines • 5.53 kB
text/typescript
import type { Bip44Account } from "@metamask/account-api";
import type { CreateAccountOptions, EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
import type { KeyringCapabilities } from "@metamask/keyring-api/v2";
import type { InternalAccount } from "@metamask/keyring-internal-api";
import type { MultichainAccountServiceMessenger } from "../types.mjs";
import { BaseBip44AccountProvider } from "./BaseBip44AccountProvider.mjs";
/**
* A simple wrapper that adds disable functionality to any BaseBip44AccountProvider.
* When disabled, the provider will not create new accounts and return empty results.
*/
export declare class AccountProviderWrapper extends BaseBip44AccountProvider {
private isEnabled;
private readonly provider;
constructor(messenger: MultichainAccountServiceMessenger, provider: BaseBip44AccountProvider);
getName(): string;
get capabilities(): KeyringCapabilities;
/**
* Forward initialization to the wrapped provider to ensure both
* instances share the same visible account IDs.
*
* @param accounts - Account IDs to initialize with.
*/
init(accounts: Bip44Account<KeyringAccount>['id'][]): void;
/**
* Returns the underlying (unwrapped) provider.
*
* Most callers should go through the wrapper's public surface so that the
* `disabled` gating is respected. This escape hatch is reserved for
* cleanup flows (e.g. wallet removal) that must see the wrapped
* provider's accounts regardless of enabled state, so that snap-backed
* accounts created while the provider was enabled can still be deleted
* after it has been disabled.
*
* @returns The wrapped provider instance.
*/
unwrap(): BaseBip44AccountProvider;
/**
* Set the enabled state for this provider.
*
* @param enabled - Whether the provider should be enabled.
*/
setEnabled(enabled: boolean): void;
/**
* Check if the provider is disabled.
*
* @returns True if the provider is disabled, false otherwise.
*/
isDisabled(): boolean;
/**
* Override resyncAccounts to not execute it when disabled.
*
* @param accounts - List of local accounts.
*/
resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;
/**
* Override getAccounts to return empty array when disabled.
*
* @returns Array of accounts, or empty array if disabled.
*/
getAccounts(): Bip44Account<KeyringAccount>[];
/**
* Override getAccount to throw when disabled.
*
* @param id - The account ID to retrieve.
* @returns The account with the specified ID.
* @throws When disabled or account not found.
*/
getAccount(id: Bip44Account<KeyringAccount>['id']): Bip44Account<KeyringAccount>;
/**
* Returns true immediately when disabled (a disabled provider is considered
* aligned by definition). Delegates to the wrapped provider otherwise.
*
* @param context - The entropy source and group index to check.
* @param context.entropySource - The entropy source to check against.
* @param context.groupIndex - The group index to check against.
* @param accountIds - Account IDs pre-filtered by the caller.
* @returns Whether the provider is aligned for the given context.
*/
isAligned(context: {
entropySource: EntropySourceId;
groupIndex: number;
}, accountIds: Bip44Account<KeyringAccount>['id'][]): boolean;
/**
* Implement abstract method: Check if account is compatible.
* Delegates directly to wrapped provider - no runtime checks needed!
*
* @param account - The account to check.
* @returns True if the account is compatible.
*/
isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;
/**
* Implement abstract method: Create accounts, returns empty array when disabled.
*
* @param options - Account creation options.
* @returns Promise resolving to created accounts, or empty array if disabled.
*/
createAccounts(options: CreateAccountOptions): Promise<Bip44Account<KeyringAccount>[]>;
/**
* Forwards to the wrapped provider unconditionally, because deletion must run even
* when the wrapper is disabled, so that wallet-removal flows can clean up
* snap-backed accounts that were created while the provider was previously
* enabled.
*
* @param id - The id of the account to delete.
* @returns A promise that resolves when the account is deleted.
*/
deleteAccount(id: Bip44Account<KeyringAccount>['id']): Promise<void>;
/**
* Implement abstract method: Discover and create accounts, returns empty array when disabled.
*
* @param options - Account discovery options.
* @param options.entropySource - The entropy source to use.
* @param options.groupIndex - The group index to use.
* @returns Promise resolving to discovered accounts, or empty array if disabled.
*/
discoverAccounts(options: {
entropySource: EntropySourceId;
groupIndex: number;
}): Promise<Bip44Account<KeyringAccount>[]>;
}
/**
* Simple type guard to check if a provider is wrapped.
*
* @param provider - The provider to check.
* @returns True if the provider is an AccountProviderWrapper.
*/
export declare function isAccountProviderWrapper(provider: unknown): provider is AccountProviderWrapper;
//# sourceMappingURL=AccountProviderWrapper.d.mts.map