///
import EventEmitter from 'events';
import { DeviceRebootType, DeviceSessionPinType } from '@onekeyfe/hd-transport';
import { EFirmwareType } from '@onekeyfe/hd-shared';
import { DeviceCommands } from './DeviceCommands';
import { type DeviceFirmwareRange, type DeviceStateEvent, type DeviceStatePatch, type DeviceStateUpdateSource, type Device as DeviceTyped, EOneKeyDeviceMode, type Features, type IDeviceModel, type IDeviceType, type IVersionRange, type SupportFeatureType, type UnavailableCapabilities } from '../types';
import { DEVICE } from '../events';
import { type ProtocolV2RuntimeMode } from '../protocols/protocol-v2/features';
import type { PROTO } from '../constants';
import type { DeviceStateReadOptions } from '../types/api/getDeviceState';
import type { DeviceButtonRequestPayload, DeviceFeaturesPayload, HardwareUiInteractionMeta, PassphraseRequestPayload, ProtocolV2UiEventMetadata } from '../events';
import type { PassphrasePromptResponse } from './DeviceCommands';
import type { Deferred, HardwareConnectProtocol } from '@onekeyfe/hd-shared';
import type { OneKeyDeviceInfo as DeviceDescriptor, DeviceStatus, ProtocolInfo, ProtocolV2DeviceInfo, Success } from '@onekeyfe/hd-transport';
import type DeviceConnector from './DeviceConnector';
export type InitOptions = {
initSession?: boolean;
deviceId?: string;
passphraseState?: string;
deriveCardano?: boolean;
connectProtocol?: HardwareConnectProtocol;
forceProtocolDetection?: boolean;
protocolV2DeviceInfoTimeoutMs?: number;
refreshRuntimeState?: boolean;
timeoutMs?: number;
};
export type RunOptions = {
keepSession?: boolean;
skipInitialize?: boolean;
} & InitOptions;
export interface DeviceEvents {
[DEVICE.PIN]: [Device, PROTO.PinMatrixRequestType | undefined, (err: any, pin: string) => void];
[DEVICE.PIN_ON_DEVICE]: [Device, DeviceSessionPinType, ProtocolV2UiEventMetadata?];
[DEVICE.PIN_ON_DEVICE_COMPLETE]: [Device, HardwareUiInteractionMeta];
[DEVICE.PASSPHRASE_ON_DEVICE]: [Device, PassphraseRequestPayload?];
[DEVICE.ATTACH_PIN_ON_DEVICE]: [Device, PassphraseRequestPayload?];
[DEVICE.BUTTON]: [Device, DeviceButtonRequestPayload];
[DEVICE.FEATURES]: [Device, DeviceFeaturesPayload];
[DEVICE.STATE]: [Device, DeviceStateEvent];
[DEVICE.PASSPHRASE]: [
Device,
PassphraseRequestPayload,
(response: PassphrasePromptResponse, error?: Error) => void
];
[DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE]: [
Device,
(err: any, deviceId: string) => void
];
[DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE]: [
Device,
(err: any, deviceId: string) => void
];
}
export interface Device {
on(type: K, listener: (...event: DeviceEvents[K]) => void): this;
off(type: K, listener: (...event: DeviceEvents[K]) => void): this;
emit(type: K, ...args: DeviceEvents[K]): boolean;
}
export declare function preloadSessionCache(deviceId: string, passphraseState: string, sessionId: string): void;
export declare class Device extends EventEmitter {
originalDescriptor: DeviceDescriptor;
sdkInstanceId?: string;
instanceId: string;
createdAt: number;
mainId?: string | null;
deviceConnector?: DeviceConnector | null;
commands: DeviceCommands;
private cancelableAction?;
private deviceAcquired;
private connectionAttempt;
private interruptedAttempt;
private stateStore;
private protocolV2StateNeedsReload;
private protocolV2RuntimeContext?;
private protocolV2RuntimeContextPromise?;
private protocolV2RuntimeContextRequestToken?;
private protocolV2UiInteraction?;
private protocolV2UiInteractionCounter;
get state(): (import("../types").DeviceState & {
raw?: import("../types").DeviceFeaturesRaw | undefined;
}) | undefined;
get features(): Features | undefined;
set features(features: Features | undefined);
runPromise?: Deferred | null;
private runCleanupPromise?;
private userInterruption?;
externalState: string[];
unavailableCapabilities: UnavailableCapabilities;
instance: number;
internalState: string[];
needReloadDevice: boolean;
keepSession: boolean;
passphraseState: string | undefined;
pendingCallbackPromise?: Deferred;
private preInitializedAt?;
private preInitializeMeta?;
private lastInitializeDurationMs?;
constructor(descriptor: DeviceDescriptor, sdkInstanceId?: string);
static fromDescriptor(originalDescriptor: DeviceDescriptor, sdkInstanceId?: string): Device;
toMessageObject(): DeviceTyped | null;
connect(connectProtocol?: HardwareConnectProtocol, options?: {
forceProtocolDetection?: boolean;
}): Promise;
acquire(expectedProtocol?: HardwareConnectProtocol, options?: {
throwOnRunPromiseError?: boolean;
forceProtocolDetection?: boolean;
}): Promise;
release(): Promise;
preInitialize(initOptions?: InitOptions): Promise;
markPreInitialized(meta?: {
passphraseState?: string;
}): void;
clearPreInitialized(): void;
isPreInitializeMetaMatch(payload?: {
passphraseState?: string;
}): boolean;
isPreInitializedValid(ttlMs: number): boolean;
setLastInitializeDuration(durationMs: number): void;
getLastInitializeDuration(): number | undefined;
getCommands(): DeviceCommands;
getProtocol(): 'V1' | 'V2';
isProtocolV2(): boolean;
getCurrentDeviceType(): IDeviceType;
getCurrentDeviceId(): string | undefined;
getCurrentSerialNo(): string;
getConnectId(): string;
getCurrentBleName(): string | null;
getCurrentLabel(): string | null;
getCurrentDisplayName(): string | null;
getCurrentPassphraseProtection(): boolean | null | undefined;
getCurrentFirmwareType(): EFirmwareType;
getCurrentFirmwareVersionString(): string;
getCurrentBLEFirmwareVersionString(): string | undefined;
getCurrentBootloaderVersionString(): string | undefined;
getCurrentSafetyChecks(): import("@onekeyfe/hd-transport").Enum_SafetyCheckLevel | null | undefined;
getCurrentMethodVersionRange(getVersionRange: (deviceModel: IDeviceType | IDeviceModel) => IVersionRange | undefined): IVersionRange | undefined;
supportNewPassphrase(): SupportFeatureType;
supportInputPinOnSoftware(): SupportFeatureType;
supportModifyHomescreen(): SupportFeatureType;
private getSessionCacheDeviceKey;
private reconcileSessionCacheDeviceIdentity;
getInternalState(_deviceId?: string): string | undefined;
getStandardInternalState(_deviceId?: string): {
passphraseState: string;
sessionId: string;
} | undefined;
updateInternalState(enablePassphrase: boolean, passphraseState: string | undefined, deviceId: string | undefined, sessionId?: string | null, featuresSessionId?: string | null, walletType?: 'standard' | 'hidden'): void;
private setInternalState;
clearInternalState(_deviceId?: string): void;
clearStandardInternalState(_deviceId?: string): void;
initialize(options?: InitOptions): Promise;
private _initializeProtocolV2;
getFeatures(): Promise;
getDeviceState(params?: DeviceStateReadOptions): Promise;
refreshProtocolV2SettingsAfterMutation(): Promise;
_updateFeatures(protoFeatures: PROTO.Features | Features, initSession?: boolean): void;
updateState(patch: DeviceStatePatch, source: DeviceStateUpdateSource): import("../types").DeviceState & {
raw?: import("../types").DeviceFeaturesRaw | undefined;
};
updateFeaturesPatch(patch: Partial, source: DeviceStateUpdateSource): Features | undefined;
ensureProtocolV2RuntimeContext(timeoutMs?: number, options?: {
forceRefresh?: boolean;
}): Promise;
probeProtocolV2RuntimeState(deviceInfo?: ProtocolV2DeviceInfo, timeoutMs?: number, options?: {
forceRuntimeContextRefresh?: boolean;
}): Promise;
updateProtocolV2Features(deviceInfo?: ProtocolV2DeviceInfo, deviceStatus?: DeviceStatus | null, runtimeMode?: ProtocolV2RuntimeMode, protocolInfo?: ProtocolInfo): Features;
updateProtocolV2Status(status: DeviceStatus): Features;
private invalidateProtocolV2RuntimeState;
markTransportDisconnected(): void;
invalidateAfterWipe(): void;
markProtocolV2Reboot(rebootType: DeviceRebootType): void;
updateDescriptor(descriptor: DeviceDescriptor, forceUpdate?: boolean): void;
updateFromCache(device: Device): void;
waitForRunCleanup(): Promise;
run(fn?: () => Promise, options?: RunOptions): Promise;
_runInner(fn: (() => Promise) | undefined, options: RunOptions, runPromise: Deferred): Promise;
interruptionFromOutside(): Promise;
interruptionFromUser(): Promise;
setCancelableAction(callback: (err?: Error) => Promise): void;
clearCancelableAction(): void;
getMode(): EOneKeyDeviceMode;
getStatus(): "available" | "occupied" | "used";
getFirmwareVersion(): import("../types").IVersionArray | null;
getBLEFirmwareVersion(): import("../types").IVersionArray | null;
isUsed(): boolean;
beginConnectionAttempt(): number;
wasInterruptedByUser(): boolean;
private throwIfInterruptedByUser;
private shouldSendFallbackProtocolCancel;
hasDeviceAcquire(): boolean;
isUsedHere(): boolean;
isUsedElsewhere(): boolean;
isBootloader(): boolean | undefined;
isRomloader(): boolean | undefined;
isInitialized(): boolean | undefined;
isSeedless(): boolean | undefined;
isUnacquired(): boolean;
hasUnexpectedMode(allow: string[], require: string[]): "ui-device_bootloader_mode" | "ui-device_not_in_bootloader_mode" | "ui-device_not_initialized" | "ui-device_seedless" | null;
hasUsePassphrase(): boolean;
checkDeviceId(deviceId: string): boolean;
lockDevice(): Promise;
beginProtocolV2UiInteraction(): void;
createProtocolV2UiPhaseMetadata(phase: HardwareUiInteractionMeta['phase'], transition: HardwareUiInteractionMeta['transition'], options?: {
phaseId?: string;
outcome?: HardwareUiInteractionMeta['outcome'];
}): HardwareUiInteractionMeta | undefined;
completeProtocolV2UiPhase(phase: HardwareUiInteractionMeta, outcome?: HardwareUiInteractionMeta['outcome']): HardwareUiInteractionMeta | undefined;
finishProtocolV2UiInteraction(outcome?: HardwareUiInteractionMeta['outcome'], options?: {
ensureMetadata?: boolean;
}): HardwareUiInteractionMeta | undefined;
hasOpenProtocolV2UiInteraction(): boolean;
supportUnlockVersionRange(): DeviceFirmwareRange;
unlockDevice(pinType?: DeviceSessionPinType, options?: ProtocolV2UiEventMetadata & {
emitUiEvent?: boolean;
}): Promise;
checkPassphraseStateSafety(passphraseState?: string, useEmptyPassphrase?: boolean, skipPassphraseCheck?: boolean, deriveCardano?: boolean, mainPinSelected?: boolean): Promise;
}
export default Device;
//# sourceMappingURL=Device.d.ts.map