UNPKG

@metamask/eth-trezor-keyring

Version:

A MetaMask compatible keyring, for trezor hardware wallets

113 lines 4.39 kB
import type { Bip44Account } from "@metamask/account-api"; import type { KeyringAccount, EntropySourceId } from "@metamask/keyring-api"; import { KeyringType } from "@metamask/keyring-api/v2"; import type { CreateAccountOptions, Keyring } from "@metamask/keyring-api/v2"; import { EthKeyringWrapper } from "@metamask/keyring-sdk/v2"; import type { AccountId, EthKeyring } from "@metamask/keyring-utils"; import type { Json } from "@metamask/utils"; import type { TrezorBridge } from "../trezor-bridge.cjs"; import type { AccountPage, TrezorKeyring as LegacyTrezorKeyring } from "../trezor-keyring.cjs"; /** * BIP-44 standard HD path prefix constant for Ethereum. * Used as default for derive-index operations. */ export declare const BIP44_HD_PATH_PREFIX = "m/44'/60'/0'/0"; /** * SLIP-0044 testnet HD path prefix constant. */ export declare const SLIP0044_TESTNET_PATH_PREFIX = "m/44'/1'/0'/0"; /** * Legacy MEW (MyEtherWallet) HD path prefix constant. */ export declare const LEGACY_MEW_PATH_PREFIX = "m/44'/60'/0'"; /** * Concrete {@link Keyring} adapter for {@link TrezorKeyring}. * * This wrapper exposes the accounts and signing capabilities of the legacy * Trezor keyring via the unified V2 interface. * * All Trezor keyring accounts are BIP-44 derived from the device. */ export type TrezorKeyringOptions = { legacyKeyring: LegacyTrezorKeyring; entropySource: EntropySourceId; type?: KeyringType.Trezor | KeyringType.OneKey; }; type TrezorKeyringAsEthKeyring = LegacyTrezorKeyring & EthKeyring; export declare class TrezorKeyring extends EthKeyringWrapper<TrezorKeyringAsEthKeyring, Bip44Account<KeyringAccount>> implements Keyring { #private; readonly entropySource: EntropySourceId; constructor(options: TrezorKeyringOptions); /** * Hydrate the underlying keyring from a previously serialized state. * * Overrides the base class implementation to avoid calling `getAccounts()` * when the Trezor device is locked. The base class calls `getAccounts()` to * rebuild the registry, but for Trezor keyrings this requires the HDKey to * be initialized (via `unlock()`). Since the device may not be connected * during deserialization, we skip the registry rebuild here. The registry * will be populated on the first call to `getAccounts()` after the device * is unlocked. * * @param state - The serialized keyring state. */ deserialize(state: Json): Promise<void>; getAccounts(): Promise<Bip44Account<KeyringAccount>[]>; createAccounts(options: CreateAccountOptions): Promise<Bip44Account<KeyringAccount>[]>; /** * Delete an account from the keyring. * * @param accountId - The account ID to delete. */ deleteAccount(accountId: AccountId): Promise<void>; /** * @returns The device model reported by the bridge, or `undefined` if no * device is paired. */ getModel(): string | undefined; /** * @returns The current derivation path used by the inner keyring. */ get hdPath(): string; /** * @returns The bridge instance used by the inner keyring to communicate * with the device. */ get bridge(): TrezorBridge; /** * Set the derivation path on the inner keyring. Must be one of the allowed * HD paths supported by the legacy Trezor keyring. * * @param hdPath - The derivation path to set. */ setHdPath(hdPath: Parameters<LegacyTrezorKeyring['setHdPath']>[0]): void; /** * Fetch the first page of candidate addresses from the device. * * @returns The first page of accounts. */ getFirstPage(): Promise<AccountPage>; /** * Fetch the next page of candidate addresses from the device. * * @returns The next page of accounts. */ getNextPage(): Promise<AccountPage>; /** * Fetch the previous page of candidate addresses from the device. * * @returns The previous page of accounts. */ getPreviousPage(): Promise<AccountPage>; /** * Clear the inner keyring's device-pairing state and accounts, and reset * the V2 account registry to keep them in sync. */ forgetDevice(): Promise<void>; /** * @returns Whether the inner keyring has an unlocked HD key. */ isUnlocked(): boolean; } export {}; //# sourceMappingURL=trezor-keyring.d.cts.map