UNPKG

eth-onekey-bridge-keyring

Version:

A MetaMask compatible keyring, for onekey hardware wallets

109 lines (108 loc) 3.85 kB
/// <reference types="node" /> import { TypedTransaction } from '@ethereumjs/tx'; import type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util'; import { SignTypedDataVersion } from '@metamask/eth-sig-util'; import type { ConnectSettings } from '@onekeyfe/hd-core'; import type OldEthJsTransaction from 'ethereumjs-tx'; import { EventEmitter } from 'events'; import { OneKeyBridge } from './onekey-bridge'; declare enum NetworkApiUrls { Ropsten = "https://api-ropsten.etherscan.io", Kovan = "https://api-kovan.etherscan.io", Rinkeby = "https://api-rinkeby.etherscan.io", Mainnet = "https://api.etherscan.io" } export declare type AccountDetails = { index?: number; hdPath: string; passphraseState?: string; }; export declare type OneKeyControllerOptions = { hdPath?: string; accounts?: string[]; accountDetails?: Readonly<Record<string, AccountDetails>>; page?: number; passphraseState?: string; }; export declare type OneKeyControllerState = { hdPath: string; accounts: readonly string[]; accountDetails: Readonly<Record<string, AccountDetails>>; page: number; passphraseState?: string; }; export declare class OneKeyKeyring extends EventEmitter { #private; readonly type: string; static type: string; page: number; perPage: number; unlockedAccount: number; accounts: readonly string[]; accountDetails: Record<string, AccountDetails>; passphraseState: string | undefined; needResetPassphraseState: boolean; hdPath: string; network: NetworkApiUrls; implementFullBIP44: boolean; bridge: OneKeyBridge; passphraseEnabled: boolean; constructor({ bridge }: { bridge: OneKeyBridge; }); init(settings: Partial<ConnectSettings>): Promise<void>; destroy(): Promise<void>; serialize(): Promise<OneKeyControllerState>; deserialize(opts?: OneKeyControllerOptions): Promise<void>; getModel(): string | undefined; setAccountToUnlock(index: number): void; setHdPath(hdPath: string): void; isUnlocked(): boolean; unlock(): Promise<string>; addAccounts(n?: number): Promise<readonly string[]>; getName(): string; getFirstPage(): Promise<{ address: string; balance: number | null; index: number; }[]>; getNextPage(): Promise<{ address: string; balance: number | null; index: number; }[]>; getPreviousPage(): Promise<{ address: string; balance: number | null; index: number; }[]>; getAccounts(): Promise<string[]>; removeAccount(address: string): void; updateTransportMethod(transportType: ConnectSettings['env']): Promise<void>; /** * Signs a transaction using OneKey. * * 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: string, tx: TypedTransaction | OldEthJsTransaction): Promise<TypedTransaction | OldEthJsTransaction>; signMessage(withAccount: string, data: string): Promise<unknown>; signPersonalMessage(withAccount: string, message: string): Promise<unknown>; /** * EIP-712 Sign Typed Data */ signTypedData<T extends MessageTypes>(address: string, data: TypedMessage<T>, { version }: { version: SignTypedDataVersion; }): Promise<string>; exportAccount(): void; forgetDevice(): void; enablePassphrase(): Promise<void>; resetPassphraseState(): Promise<void>; getPassphraseState(_index: number, _hdPath: string): Promise<undefined>; } export {};