@onekeyfe/hd-core
Advanced tools
Comparing version 0.1.49 to 0.1.50
@@ -6,3 +6,3 @@ /// <reference types="node" /> | ||
import type DeviceConnector from './DeviceConnector'; | ||
import { DeviceCommands } from './DeviceCommands'; | ||
import { DeviceCommands, PassphrasePromptResponse } from './DeviceCommands'; | ||
import type { Features, Device as DeviceTyped, UnavailableCapabilities } from '../types'; | ||
@@ -24,2 +24,3 @@ import { DEVICE, DeviceButtonRequestPayload, DeviceFeaturesPayload } from '../events'; | ||
[DEVICE.FEATURES]: [Device, DeviceFeaturesPayload]; | ||
[DEVICE.PASSPHRASE]: [Device, (response: PassphrasePromptResponse, error?: Error) => void]; | ||
} | ||
@@ -26,0 +27,0 @@ export interface Device { |
@@ -33,2 +33,3 @@ import type { Transport, Messages } from '@onekeyfe/hd-transport'; | ||
_promptPin(type?: Messages.PinMatrixRequestType): Promise<string>; | ||
_promptPassphrase(): Promise<PassphrasePromptResponse>; | ||
} | ||
@@ -35,0 +36,0 @@ export declare type TypedCall = DeviceCommands['typedCall']; |
@@ -10,2 +10,3 @@ import type { PROTO } from '../constants'; | ||
readonly REQUEST_BUTTON: "ui-button"; | ||
readonly REQUEST_PASSPHRASE: "ui-request_passphrase"; | ||
readonly REQUEST_PASSPHRASE_ON_DEVICE: "ui-request_passphrase_on_device"; | ||
@@ -35,2 +36,8 @@ readonly CLOSE_UI_WINDOW: "ui-close_window"; | ||
export interface UiRequestPassphrase { | ||
type: typeof UI_REQUEST.REQUEST_PASSPHRASE; | ||
payload: { | ||
device: Device; | ||
}; | ||
} | ||
export interface UiRequestPassphraseOnDevice { | ||
type: typeof UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE; | ||
@@ -49,3 +56,3 @@ payload: { | ||
} | ||
export declare type UiEvent = UiRequestWithoutPayload | UiRequestDeviceAction | UiRequestButton | UiRequestPassphrase | FirmwareProgress; | ||
export declare type UiEvent = UiRequestWithoutPayload | UiRequestDeviceAction | UiRequestButton | UiRequestPassphraseOnDevice | FirmwareProgress | UiRequestPassphrase; | ||
export declare type UiEventMessage = UiEvent & { | ||
@@ -52,0 +59,0 @@ event: typeof UI_EVENT; |
@@ -5,2 +5,3 @@ import { UI_EVENT } from './ui-request'; | ||
readonly RECEIVE_PIN: "ui-receive_pin"; | ||
readonly RECEIVE_PASSPHRASE: "ui-receive_passphrase"; | ||
}; | ||
@@ -11,3 +12,11 @@ export interface UiResponsePin { | ||
} | ||
export declare type UiResponseEvent = UiResponsePin; | ||
export interface UiResponsePassphrase { | ||
type: typeof UI_RESPONSE.RECEIVE_PASSPHRASE; | ||
payload: { | ||
value: string; | ||
passphraseOnDevice?: boolean; | ||
save?: boolean; | ||
}; | ||
} | ||
export declare type UiResponseEvent = UiResponsePin | UiResponsePassphrase; | ||
export declare type UiResponseMessage = UiResponseEvent & { | ||
@@ -14,0 +23,0 @@ event: typeof UI_EVENT; |
{ | ||
"name": "@onekeyfe/hd-core", | ||
"version": "0.1.49", | ||
"version": "0.1.50", | ||
"description": "> TODO: description", | ||
@@ -27,4 +27,4 @@ "author": "OneKey", | ||
"dependencies": { | ||
"@onekeyfe/hd-shared": "^0.1.49", | ||
"@onekeyfe/hd-transport": "^0.1.49", | ||
"@onekeyfe/hd-shared": "^0.1.50", | ||
"@onekeyfe/hd-transport": "^0.1.50", | ||
"axios": "^0.27.2", | ||
@@ -40,3 +40,3 @@ "bignumber.js": "^9.0.2", | ||
}, | ||
"gitHead": "692944ef9897d6a9b0069fb60eec18d2dfbd6a2b" | ||
"gitHead": "e3e2a8aa77a1bf72d1b26dc9841463a660a2f902" | ||
} |
@@ -135,3 +135,4 @@ import semver from 'semver'; | ||
device.on(DEVICE.BUTTON, onDeviceButtonHandler); | ||
device.on(DEVICE.PASSPHRASE_ON_DEVICE, onDevicePassphraseHandler); | ||
device.on(DEVICE.PASSPHRASE, onDevicePassphraseHandler); | ||
device.on(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler); | ||
device.on(DEVICE.FEATURES, onDeviceFeaturesHandler); | ||
@@ -530,3 +531,4 @@ | ||
device.removeListener(DEVICE.BUTTON, onDeviceButtonHandler); | ||
device.removeListener(DEVICE.PASSPHRASE_ON_DEVICE, onDevicePassphraseHandler); | ||
device.removeListener(DEVICE.PASSPHRASE, onDevicePassphraseHandler); | ||
device.removeListener(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler); | ||
device.removeListener(DEVICE.FEATURES, onDeviceFeaturesHandler); | ||
@@ -592,4 +594,25 @@ DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler); | ||
const onDevicePassphraseHandler = (...[device]: [...DeviceEvents['passphrase_on_device']]) => { | ||
const onDevicePassphraseHandler = async (...[device, callback]: DeviceEvents['passphrase']) => { | ||
Log.debug('onDevicePassphraseHandler'); | ||
const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PASSPHRASE, device); | ||
postMessage( | ||
createUiMessage(UI_REQUEST.REQUEST_PASSPHRASE, { | ||
device: device.toMessageObject() as KnownDevice, | ||
}) | ||
); | ||
// wait for passphrase | ||
const uiResp = await uiPromise.promise; | ||
const { value, passphraseOnDevice, save } = uiResp.payload; | ||
// send as PassphrasePromptResponse | ||
callback({ | ||
passphrase: value.normalize('NFKD'), | ||
passphraseOnDevice, | ||
cache: save, | ||
}); | ||
}; | ||
const onEnterPassphraseOnDeviceHandler = ( | ||
...[device]: [...DeviceEvents['passphrase_on_device']] | ||
) => { | ||
postMessage( | ||
createUiMessage(UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE, { | ||
@@ -630,3 +653,4 @@ device: device.toMessageObject() as KnownDevice, | ||
switch (message.type) { | ||
case UI_RESPONSE.RECEIVE_PIN: { | ||
case UI_RESPONSE.RECEIVE_PIN: | ||
case UI_RESPONSE.RECEIVE_PASSPHRASE: { | ||
const uiPromise = findUiPromise(message.type); | ||
@@ -633,0 +657,0 @@ if (uiPromise) { |
@@ -22,3 +22,3 @@ import EventEmitter from 'events'; | ||
// eslint-disable-next-line import/no-cycle | ||
import { DeviceCommands } from './DeviceCommands'; | ||
import { DeviceCommands, PassphrasePromptResponse } from './DeviceCommands'; | ||
@@ -54,2 +54,3 @@ import type { Features, Device as DeviceTyped, UnavailableCapabilities } from '../types'; | ||
[DEVICE.FEATURES]: [Device, DeviceFeaturesPayload]; | ||
[DEVICE.PASSPHRASE]: [Device, (response: PassphrasePromptResponse, error?: Error) => void]; | ||
} | ||
@@ -56,0 +57,0 @@ |
@@ -219,15 +219,8 @@ import type { Transport, Messages } from '@onekeyfe/hd-transport'; | ||
if (res.type === 'PassphraseRequest') { | ||
/** | ||
* Temporary, do not support passphrase | ||
*/ | ||
// return this._commonCall('PassphraseAck', { passphrase: '' }); | ||
return Promise.reject( | ||
ERRORS.TypedError( | ||
HardwareErrorCode.DeviceNotSupportPassphrase, | ||
'Device not support passphrase', | ||
{ | ||
require: '2.4.0', | ||
} | ||
) | ||
); | ||
return this._promptPassphrase().then(response => { | ||
const { passphrase, passphraseOnDevice } = response; | ||
return !passphraseOnDevice | ||
? this._commonCall('PassphraseAck', { passphrase }) | ||
: this._commonCall('PassphraseAck', { on_device: true }); | ||
}); | ||
} | ||
@@ -270,4 +263,32 @@ | ||
} | ||
_promptPassphrase() { | ||
return new Promise<PassphrasePromptResponse>((resolve, reject) => { | ||
if (this.device.listenerCount(DEVICE.PASSPHRASE) > 0) { | ||
this._cancelableRequest = reject; | ||
this.device.emit( | ||
DEVICE.PASSPHRASE, | ||
this.device, | ||
(response: PassphrasePromptResponse, error?: Error) => { | ||
this._cancelableRequest = undefined; | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(response); | ||
} | ||
} | ||
); | ||
} else { | ||
Log.error('[DeviceCommands] [call] Passphrase callback not configured, cancelling request'); | ||
reject( | ||
ERRORS.TypedError( | ||
HardwareErrorCode.RuntimeError, | ||
'_promptPassphrase: Passphrase callback not configured' | ||
) | ||
); | ||
} | ||
}); | ||
} | ||
} | ||
export type TypedCall = DeviceCommands['typedCall']; |
@@ -33,3 +33,2 @@ import EventEmitter from 'events'; | ||
if (currentDescriptor) { | ||
// return currentDescriptor.debug ? (currentDescriptor.debugSession !== d.debugSession) : (currentDescriptor.session !== d.session); | ||
return currentDescriptor.session !== d.session; | ||
@@ -40,7 +39,3 @@ } | ||
const acquired = changedSessions.filter(d => typeof d.session === 'string'); | ||
const released = changedSessions.filter( | ||
d => | ||
// const session = descriptor.debug ? descriptor.debugSession : descriptor.session; | ||
typeof d.session !== 'string' | ||
); | ||
const released = changedSessions.filter(d => typeof d.session !== 'string'); | ||
@@ -137,3 +132,3 @@ const changedDebugSessions = descriptors.filter(d => { | ||
} | ||
Log.debug('get devices result : ', devices, deviceList); | ||
// Log.debug('get devices result : ', devices, deviceList); | ||
console.log('device poll -> connected: ', this.connectedPool); | ||
@@ -140,0 +135,0 @@ console.log('device poll -> disconnected: ', this.disconnectPool); |
@@ -12,2 +12,3 @@ import type { PROTO } from '../constants'; | ||
REQUEST_BUTTON: 'ui-button', | ||
REQUEST_PASSPHRASE: 'ui-request_passphrase', | ||
REQUEST_PASSPHRASE_ON_DEVICE: 'ui-request_passphrase_on_device', | ||
@@ -49,2 +50,9 @@ | ||
export interface UiRequestPassphrase { | ||
type: typeof UI_REQUEST.REQUEST_PASSPHRASE; | ||
payload: { | ||
device: Device; | ||
}; | ||
} | ||
export interface UiRequestPassphraseOnDevice { | ||
type: typeof UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE; | ||
@@ -69,4 +77,5 @@ payload: { | ||
| UiRequestButton | ||
| UiRequestPassphrase | ||
| FirmwareProgress; | ||
| UiRequestPassphraseOnDevice | ||
| FirmwareProgress | ||
| UiRequestPassphrase; | ||
@@ -73,0 +82,0 @@ export type UiEventMessage = UiEvent & { event: typeof UI_EVENT }; |
@@ -6,2 +6,3 @@ import { UI_EVENT } from './ui-request'; | ||
RECEIVE_PIN: 'ui-receive_pin', | ||
RECEIVE_PASSPHRASE: 'ui-receive_passphrase', | ||
} as const; | ||
@@ -14,4 +15,13 @@ | ||
export type UiResponseEvent = UiResponsePin; | ||
export interface UiResponsePassphrase { | ||
type: typeof UI_RESPONSE.RECEIVE_PASSPHRASE; | ||
payload: { | ||
value: string; | ||
passphraseOnDevice?: boolean; | ||
save?: boolean; | ||
}; | ||
} | ||
export type UiResponseEvent = UiResponsePin | UiResponsePassphrase; | ||
export type UiResponseMessage = UiResponseEvent & { event: typeof UI_EVENT }; | ||
@@ -18,0 +28,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1250753
38215