UNPKG

@metamask/eth-trezor-keyring

Version:

A MetaMask compatible keyring, for trezor hardware wallets

104 lines 3.67 kB
import type { TypedTransaction } from "@ethereumjs/tx"; import { TypedMessage, SignTypedDataVersion, MessageTypes } from "@metamask/eth-sig-util"; import type { Keyring } from "@metamask/keyring-utils"; import { Hex } from "@metamask/utils"; import type OldEthJsTransaction from "ethereumjs-tx"; import HDKey from "hdkey"; import { TrezorBridge } from "./trezor-bridge.mjs"; declare const ALLOWED_HD_PATHS: { readonly "m/44'/60'/0'/0": true; readonly "m/44'/60'/0'": true; readonly "m/44'/1'/0'/0": true; }; export declare const TREZOR_CONNECT_MANIFEST: { appName: string; email: string; appUrl: string; }; export type AccountPageEntry = { address: Hex; balance: number | null; index: number; }; export type AccountPage = AccountPageEntry[]; export type TrezorControllerOptions = { hdPath?: string; accounts?: Hex[]; page?: number; perPage?: number; }; export type TrezorControllerState = { hdPath: string; accounts: Hex[]; page: number; paths: Record<Hex, number>; perPage: number; unlockedAccount: number; }; export declare class TrezorKeyring implements Keyring { #private; static type: string; readonly type: string; accounts: readonly Hex[]; hdk: HDKey; hdPath: string; page: number; perPage: number; unlockedAccount: number; paths: Record<string, number>; bridge: TrezorBridge; constructor({ bridge }: { bridge: TrezorBridge; }); /** * Gets the model, if known. * This may be `undefined` if the model hasn't been loaded yet. * * @returns */ getModel(): string | undefined; init(): Promise<void>; destroy(): Promise<void>; serialize(): Promise<TrezorControllerState>; deserialize(opts: TrezorControllerOptions): Promise<void>; isUnlocked(): boolean; unlock(): Promise<string>; setAccountToUnlock(index: number | string): void; addAccounts(numberOfAccounts: number): Promise<Hex[]>; getFirstPage(): Promise<AccountPage>; getNextPage(): Promise<AccountPage>; getPreviousPage(): Promise<AccountPage>; getAccounts(): Promise<Hex[]>; removeAccount(address: string): void; /** * Signs a transaction using Trezor. * * Accepts either an ethereumjs-tx or @ethereumjs/tx transaction, and returns * the same type. * * @param address - Hex string address. * @param tx - Instance of either new-style or old-style ethereumjs transaction. * @returns The signed transaction, an instance of either new-style or old-style * ethereumjs transaction. */ signTransaction(address: Hex, tx: TypedTransaction | OldEthJsTransaction): Promise<TypedTransaction | OldEthJsTransaction>; signMessage(withAccount: Hex, data: string): Promise<string>; signPersonalMessage(withAccount: Hex, message: string): Promise<string>; signTypedData<Version extends SignTypedDataVersion.V3 | SignTypedDataVersion.V4, Types extends MessageTypes, Options extends { version?: Version; }>(address: Hex, data: TypedMessage<Types>, options?: Options): Promise<string>; forgetDevice(): void; /** * Set the HD path to be used by the keyring. Only known supported HD paths are allowed. * * If the given HD path is already the current HD path, nothing happens. Otherwise the new HD * path is set, and the wallet state is completely reset. * * @throws {Error] Throws if the HD path is not supported. * * @param hdPath - The HD path to set. */ setHdPath(hdPath: keyof typeof ALLOWED_HD_PATHS): void; } export {}; //# sourceMappingURL=trezor-keyring.d.mts.map