@onekeyfe/hd-core 1.0.39-alpha.0 → 1.0.39-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +2 -0
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +2 -3
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +3 -1
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +13 -10
- package/dist/index.js +116 -62
- package/dist/types/settings.d.ts +1 -1
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/capabilitieUtils.d.ts +5 -0
- package/dist/utils/capabilitieUtils.d.ts.map +1 -0
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts +2 -0
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +2 -0
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdate.ts +1 -1
- package/src/api/FirmwareUpdateV3.ts +2 -0
- package/src/api/GetPassphraseState.ts +1 -17
- package/src/api/device/DeviceUnlock.ts +33 -0
- package/src/api/stellar/StellarSignTransaction.ts +0 -3
- package/src/core/index.ts +17 -7
- package/src/data/messages/messages.json +23 -6
- package/src/data-manager/DataManager.ts +1 -1
- package/src/data-manager/TransportManager.ts +3 -0
- package/src/device/Device.ts +34 -37
- package/src/device/DeviceCommands.ts +0 -1
- package/src/events/ui-request.ts +5 -0
- package/src/types/settings.ts +10 -1
- package/src/utils/capabilitieUtils.ts +12 -0
- package/src/utils/deviceFeaturesUtils.ts +12 -18
- package/src/utils/deviceInfoUtils.ts +17 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/logger.ts +2 -0
package/src/device/Device.ts
CHANGED
|
@@ -298,13 +298,13 @@ export class Device extends EventEmitter {
|
|
|
298
298
|
}
|
|
299
299
|
|
|
300
300
|
getInternalState(_deviceId?: string) {
|
|
301
|
+
Log.debug('getInternalState session cache: ', deviceSessionCache);
|
|
301
302
|
Log.debug(
|
|
302
303
|
'getInternalState session param: ',
|
|
303
304
|
`device_id: ${_deviceId}`,
|
|
304
305
|
`features.device_id: ${this.features?.device_id}`,
|
|
305
306
|
`passphraseState: ${this.passphraseState}`
|
|
306
307
|
);
|
|
307
|
-
Log.debug('getInternalState session cache: ', deviceSessionCache);
|
|
308
308
|
|
|
309
309
|
const deviceId = _deviceId || this.features?.device_id;
|
|
310
310
|
if (!deviceId) return undefined;
|
|
@@ -314,42 +314,38 @@ export class Device extends EventEmitter {
|
|
|
314
314
|
return deviceSessionCache[usePassKey];
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
-
tryFixInternalState(state: string, deviceId: string, sessionId: string | null = null) {
|
|
318
|
-
Log.debug(
|
|
319
|
-
'tryFixInternalState session param: ',
|
|
320
|
-
`device_id: ${deviceId}`,
|
|
321
|
-
`passphraseState: ${state}`,
|
|
322
|
-
`sessionId: ${sessionId}`
|
|
323
|
-
);
|
|
324
|
-
|
|
325
|
-
const key = `${deviceId}`;
|
|
326
|
-
const session = deviceSessionCache[key];
|
|
327
|
-
if (session) {
|
|
328
|
-
deviceSessionCache[this.generateStateKey(deviceId, state)] = session;
|
|
329
|
-
delete deviceSessionCache[key];
|
|
330
|
-
} else if (sessionId) {
|
|
331
|
-
deviceSessionCache[this.generateStateKey(deviceId, state)] = sessionId;
|
|
332
|
-
}
|
|
333
|
-
Log.debug('tryFixInternalState session cache: ', deviceSessionCache);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
317
|
// attach to pin to fix internal state
|
|
337
|
-
updateInternalState(
|
|
318
|
+
updateInternalState(
|
|
319
|
+
enablePassphrase: boolean,
|
|
320
|
+
passphraseState: string | undefined,
|
|
321
|
+
deviceId: string,
|
|
322
|
+
sessionId: string | null = null,
|
|
323
|
+
featuresSessionId: string | null = null
|
|
324
|
+
) {
|
|
338
325
|
Log.debug(
|
|
339
326
|
'updateInternalState session param: ',
|
|
340
327
|
`device_id: ${deviceId}`,
|
|
341
|
-
`
|
|
342
|
-
`
|
|
328
|
+
`enablePassphrase: ${enablePassphrase}`,
|
|
329
|
+
`passphraseState: ${passphraseState}`,
|
|
330
|
+
`sessionId: ${sessionId}`,
|
|
331
|
+
`featuresSessionId: ${featuresSessionId}`
|
|
343
332
|
);
|
|
344
333
|
|
|
345
|
-
if (
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
if (
|
|
350
|
-
|
|
334
|
+
if (enablePassphrase) {
|
|
335
|
+
// update the sessionId
|
|
336
|
+
if (sessionId) {
|
|
337
|
+
deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = sessionId;
|
|
338
|
+
} else if (featuresSessionId) {
|
|
339
|
+
deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = featuresSessionId;
|
|
351
340
|
}
|
|
352
341
|
}
|
|
342
|
+
|
|
343
|
+
// delete the old sessionId
|
|
344
|
+
const oldKey = `${deviceId}`;
|
|
345
|
+
if (deviceSessionCache[oldKey]) {
|
|
346
|
+
delete deviceSessionCache[oldKey];
|
|
347
|
+
}
|
|
348
|
+
|
|
353
349
|
Log.debug('updateInternalState session cache: ', deviceSessionCache);
|
|
354
350
|
}
|
|
355
351
|
|
|
@@ -409,12 +405,13 @@ export class Device extends EventEmitter {
|
|
|
409
405
|
payload.derive_cardano = true;
|
|
410
406
|
}
|
|
411
407
|
payload.passphrase_state = options?.passphraseState;
|
|
408
|
+
payload.is_contains_attach = true;
|
|
412
409
|
|
|
413
|
-
|
|
414
|
-
console.log('=====>>>>>> initialize device begin: ', payload, {
|
|
410
|
+
Log.debug('Initialize device begin:', {
|
|
415
411
|
deviceId: options?.deviceId,
|
|
416
412
|
passphraseState: options?.passphraseState,
|
|
417
413
|
initSession: options?.initSession,
|
|
414
|
+
InitializePayload: payload,
|
|
418
415
|
});
|
|
419
416
|
|
|
420
417
|
try {
|
|
@@ -429,7 +426,7 @@ export class Device extends EventEmitter {
|
|
|
429
426
|
}),
|
|
430
427
|
]);
|
|
431
428
|
|
|
432
|
-
|
|
429
|
+
Log.debug('Initialize device end: ', message);
|
|
433
430
|
this._updateFeatures(message, options?.initSession);
|
|
434
431
|
await TransportManager.reconfigure(this.features);
|
|
435
432
|
} catch (error) {
|
|
@@ -737,14 +734,14 @@ export class Device extends EventEmitter {
|
|
|
737
734
|
|
|
738
735
|
async checkPassphraseStateSafety(
|
|
739
736
|
passphraseState?: string,
|
|
740
|
-
|
|
737
|
+
useEmptyPassphrase?: boolean,
|
|
741
738
|
skipPassphraseCheck?: boolean
|
|
742
739
|
) {
|
|
743
740
|
if (!this.features) return false;
|
|
744
741
|
const { passphraseState: newPassphraseState, unlockedAttachPin } =
|
|
745
742
|
await getPassphraseStateWithRefreshDeviceInfo(this, {
|
|
746
743
|
expectPassphraseState: passphraseState,
|
|
747
|
-
onlyMainPin:
|
|
744
|
+
onlyMainPin: useEmptyPassphrase,
|
|
748
745
|
});
|
|
749
746
|
|
|
750
747
|
if (skipPassphraseCheck) {
|
|
@@ -752,15 +749,15 @@ export class Device extends EventEmitter {
|
|
|
752
749
|
}
|
|
753
750
|
|
|
754
751
|
// Main wallet and unlock Attach Pin, throw safe error
|
|
755
|
-
const mainWalletUseAttachPin = unlockedAttachPin &&
|
|
752
|
+
const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
|
|
756
753
|
const useErrorAttachPin =
|
|
757
754
|
unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
|
|
758
755
|
|
|
759
|
-
|
|
756
|
+
Log.debug('Check passphrase state safety: ', {
|
|
760
757
|
passphraseState,
|
|
761
758
|
newPassphraseState,
|
|
762
759
|
unlockedAttachPin,
|
|
763
|
-
|
|
760
|
+
useEmptyPassphrase,
|
|
764
761
|
});
|
|
765
762
|
|
|
766
763
|
if (mainWalletUseAttachPin || useErrorAttachPin) {
|
|
@@ -218,7 +218,6 @@ export class DeviceCommands {
|
|
|
218
218
|
this.callPromise = promise;
|
|
219
219
|
const res = await promise;
|
|
220
220
|
Log.debug('[DeviceCommands] [call] Received', res.type);
|
|
221
|
-
console.log('[DeviceCommands] [call] Received', res.type);
|
|
222
221
|
return res;
|
|
223
222
|
} catch (error) {
|
|
224
223
|
Log.debug('[DeviceCommands] [call] Received error', error);
|
package/src/events/ui-request.ts
CHANGED
|
@@ -18,6 +18,9 @@ export const UI_REQUEST = {
|
|
|
18
18
|
DEVICE_PROGRESS: 'ui-device_progress',
|
|
19
19
|
|
|
20
20
|
BLUETOOTH_PERMISSION: 'ui-bluetooth_permission',
|
|
21
|
+
BLUETOOTH_UNSUPPORTED: 'ui-bluetooth_unsupported',
|
|
22
|
+
BLUETOOTH_POWERED_OFF: 'ui-bluetooth_powered_off',
|
|
23
|
+
|
|
21
24
|
BLUETOOTH_CHARACTERISTIC_NOTIFY_CHANGE_FAILURE:
|
|
22
25
|
'ui-bluetooth_characteristic_notify_change_failure',
|
|
23
26
|
LOCATION_PERMISSION: 'ui-location_permission',
|
|
@@ -47,6 +50,8 @@ export interface UiRequestWithoutPayload {
|
|
|
47
50
|
type:
|
|
48
51
|
| typeof UI_REQUEST.CLOSE_UI_WINDOW
|
|
49
52
|
| typeof UI_REQUEST.BLUETOOTH_PERMISSION
|
|
53
|
+
| typeof UI_REQUEST.BLUETOOTH_UNSUPPORTED
|
|
54
|
+
| typeof UI_REQUEST.BLUETOOTH_POWERED_OFF
|
|
50
55
|
| typeof UI_REQUEST.BLUETOOTH_CHARACTERISTIC_NOTIFY_CHANGE_FAILURE
|
|
51
56
|
| typeof UI_REQUEST.LOCATION_PERMISSION
|
|
52
57
|
| typeof UI_REQUEST.LOCATION_SERVICE_PERMISSION
|
package/src/types/settings.ts
CHANGED
|
@@ -14,7 +14,16 @@ export type ConnectSettings = {
|
|
|
14
14
|
priority: number;
|
|
15
15
|
trustedHost: boolean;
|
|
16
16
|
supportedBrowser?: boolean;
|
|
17
|
-
env:
|
|
17
|
+
env:
|
|
18
|
+
| 'node'
|
|
19
|
+
| 'web'
|
|
20
|
+
| 'webextension'
|
|
21
|
+
| 'electron'
|
|
22
|
+
| 'react-native'
|
|
23
|
+
| 'webusb'
|
|
24
|
+
| 'emulator'
|
|
25
|
+
| 'desktop-web-ble'
|
|
26
|
+
| 'lowlevel';
|
|
18
27
|
timestamp: number;
|
|
19
28
|
isFrame?: boolean;
|
|
20
29
|
preRelease?: boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Enum_Capability } from '@onekeyfe/hd-transport';
|
|
2
|
+
import { Features } from '../types/device';
|
|
3
|
+
|
|
4
|
+
export const existCapability = (features: Features, capability: Enum_Capability) =>
|
|
5
|
+
// @ts-expect-error
|
|
6
|
+
features?.capabilities?.includes(capability);
|
|
7
|
+
|
|
8
|
+
export const requireCapability = (features: Features, capability: Enum_Capability) => {
|
|
9
|
+
if (!existCapability(features, capability)) {
|
|
10
|
+
throw new Error(`Capability ${capability} is required`);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
@@ -91,12 +91,6 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
91
91
|
}
|
|
92
92
|
);
|
|
93
93
|
|
|
94
|
-
// Attach to pin try to fix internal state
|
|
95
|
-
if (newSession && passphraseState && features?.device_id) {
|
|
96
|
-
console.log('=====>>>>>> run updateInternalState newSession:', newSession);
|
|
97
|
-
device.updateInternalState(passphraseState, features.device_id, newSession);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
94
|
const isModeT =
|
|
101
95
|
getDeviceType(features) === EDeviceType.Touch || getDeviceType(features) === EDeviceType.Pro;
|
|
102
96
|
|
|
@@ -112,6 +106,17 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
112
106
|
await device.getFeatures();
|
|
113
107
|
}
|
|
114
108
|
|
|
109
|
+
// Attach to pin try to fix internal state
|
|
110
|
+
if (features?.device_id) {
|
|
111
|
+
device.updateInternalState(
|
|
112
|
+
device.features?.passphrase_protection ?? false,
|
|
113
|
+
passphraseState,
|
|
114
|
+
device.features?.device_id ?? '',
|
|
115
|
+
newSession,
|
|
116
|
+
device.features?.session_id
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
115
120
|
return { passphraseState, newSession, unlockedAttachPin };
|
|
116
121
|
};
|
|
117
122
|
|
|
@@ -121,7 +126,6 @@ export const getPassphraseState = async (
|
|
|
121
126
|
options?: {
|
|
122
127
|
expectPassphraseState?: string;
|
|
123
128
|
onlyMainPin?: boolean;
|
|
124
|
-
// createAttachPinWallet?: boolean;
|
|
125
129
|
}
|
|
126
130
|
): Promise<{
|
|
127
131
|
passphraseState: string | undefined;
|
|
@@ -134,21 +138,11 @@ export const getPassphraseState = async (
|
|
|
134
138
|
const firmwareVersion = getDeviceFirmwareVersion(features);
|
|
135
139
|
const deviceType = getDeviceType(features);
|
|
136
140
|
|
|
137
|
-
if (deviceType === EDeviceType.Pro && semver.gte(firmwareVersion.join('.'), '4.
|
|
138
|
-
console.log(
|
|
139
|
-
'=====>>>>>> getPassphraseState begin: ',
|
|
140
|
-
options?.onlyMainPin,
|
|
141
|
-
options?.expectPassphraseState
|
|
142
|
-
);
|
|
143
|
-
|
|
141
|
+
if (deviceType === EDeviceType.Pro && semver.gte(firmwareVersion.join('.'), '4.15.0')) {
|
|
144
142
|
const { message, type } = await commands.typedCall('GetPassphraseState', 'PassphraseState', {
|
|
145
143
|
passphrase_state: options?.onlyMainPin ? undefined : options?.expectPassphraseState,
|
|
146
|
-
// allow_create_attach_pin: options?.createAttachPinWallet,
|
|
147
|
-
// _only_main_pin: options?.onlyMainPin,
|
|
148
144
|
});
|
|
149
145
|
|
|
150
|
-
console.log('=====>>>>>> getPassphraseState end: result ', message);
|
|
151
|
-
|
|
152
146
|
// @ts-expect-error
|
|
153
147
|
if (type === 'CallMethodError') {
|
|
154
148
|
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { isEmpty } from 'lodash';
|
|
2
|
-
import { EDeviceType } from '@onekeyfe/hd-shared';
|
|
2
|
+
import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
3
|
+
import { Enum_Capability } from '@onekeyfe/hd-transport';
|
|
3
4
|
import { DeviceModelToTypes } from '../types';
|
|
4
5
|
|
|
5
6
|
import type { Features, IDeviceModel, IDeviceType, IVersionRange } from '../types';
|
|
7
|
+
import { existCapability } from './capabilitieUtils';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* get device type by features
|
|
@@ -148,3 +150,17 @@ export const getMethodVersionRange = (
|
|
|
148
150
|
|
|
149
151
|
return versionRange;
|
|
150
152
|
};
|
|
153
|
+
|
|
154
|
+
export const getFirmwareType = (features: Features | undefined) => {
|
|
155
|
+
if (!features) {
|
|
156
|
+
return EFirmwareType.Universal;
|
|
157
|
+
}
|
|
158
|
+
if (features.fw_vendor === 'OneKey Bitcoin-only') {
|
|
159
|
+
return EFirmwareType.BitcoinOnly;
|
|
160
|
+
}
|
|
161
|
+
// old firmware
|
|
162
|
+
return features?.capabilities?.length > 0 &&
|
|
163
|
+
!existCapability(features, Enum_Capability.Capability_Bitcoin_like)
|
|
164
|
+
? EFirmwareType.BitcoinOnly
|
|
165
|
+
: EFirmwareType.Universal;
|
|
166
|
+
};
|
package/src/utils/index.ts
CHANGED
package/src/utils/logger.ts
CHANGED
|
@@ -157,6 +157,7 @@ export enum LoggerNames {
|
|
|
157
157
|
HdTransportHttp = '@onekey/hd-transport-http',
|
|
158
158
|
HdTransportLowLevel = '@onekey/hd-transport-lowlevel',
|
|
159
159
|
HdBleTransport = '@onekey/hd-ble-transport',
|
|
160
|
+
HdWebBleTransport = '@onekey/hd-web-ble-transport',
|
|
160
161
|
Connect = '@onekey/connect',
|
|
161
162
|
Iframe = 'IFrame',
|
|
162
163
|
SendMessage = '[SendMessage]',
|
|
@@ -174,6 +175,7 @@ export const LoggerMap = {
|
|
|
174
175
|
[LoggerNames.HdBleSdk]: initLog(LoggerNames.HdBleSdk),
|
|
175
176
|
[LoggerNames.HdTransportHttp]: initLog(LoggerNames.HdTransportHttp),
|
|
176
177
|
[LoggerNames.HdBleTransport]: initLog(LoggerNames.HdBleTransport),
|
|
178
|
+
[LoggerNames.HdWebBleTransport]: initLog(LoggerNames.HdWebBleTransport),
|
|
177
179
|
[LoggerNames.HdTransportLowLevel]: initLog(LoggerNames.HdTransportLowLevel),
|
|
178
180
|
[LoggerNames.Connect]: initLog(LoggerNames.Connect),
|
|
179
181
|
[LoggerNames.Iframe]: initLog(LoggerNames.Iframe),
|