@onekeyfe/hd-core 1.0.0-alpha.9 → 1.0.1
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/GetOnekeyFeatures.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts +2 -2
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +2 -2
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/index.d.ts +10 -15
- package/dist/index.js +114 -117
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +0 -1
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +0 -2
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/device.d.ts +7 -2
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +2 -0
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceVersionUtils.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/CheckBootloaderRelease.ts +1 -1
- package/src/api/GetOnekeyFeatures.ts +5 -0
- package/src/api/SearchDevices.ts +16 -5
- package/src/api/device/DeviceUpdateBootloader.ts +20 -27
- package/src/api/firmware/updateBootloader.ts +1 -1
- package/src/api/index.ts +0 -1
- package/src/api/nervos/NervosSignTransaction.ts +3 -2
- package/src/api/sui/SuiSignTransaction.ts +3 -2
- package/src/core/index.ts +6 -1
- package/src/data/messages/messages.json +0 -23
- package/src/device/Device.ts +47 -10
- package/src/inject.ts +0 -2
- package/src/types/api/export.ts +0 -1
- package/src/types/api/index.ts +0 -2
- package/src/types/device.ts +7 -2
- package/src/utils/deviceFeaturesUtils.ts +37 -1
- package/src/utils/deviceInfoUtils.ts +9 -7
- package/src/utils/deviceVersionUtils.ts +6 -6
- package/dist/api/dynex/DnxGetTrackingKey.d.ts +0 -13
- package/dist/api/dynex/DnxGetTrackingKey.d.ts.map +0 -1
- package/dist/types/api/dnxGetTrackingKey.d.ts +0 -10
- package/dist/types/api/dnxGetTrackingKey.d.ts.map +0 -1
- package/src/api/dynex/DnxGetTrackingKey.ts +0 -47
- package/src/types/api/dnxGetTrackingKey.ts +0 -16
package/src/inject.ts
CHANGED
|
@@ -292,8 +292,6 @@ export const createCoreApi = (
|
|
|
292
292
|
|
|
293
293
|
dnxGetAddress: (connectId, deviceId, params) =>
|
|
294
294
|
call({ ...params, connectId, deviceId, method: 'dnxGetAddress' }),
|
|
295
|
-
dnxGetTrackingKey: (connectId, deviceId, params) =>
|
|
296
|
-
call({ ...params, connectId, deviceId, method: 'dnxGetTrackingKey' }),
|
|
297
295
|
dnxSignTransaction: (connectId, deviceId, params) =>
|
|
298
296
|
call({ ...params, connectId, deviceId, method: 'dnxSignTransaction' }),
|
|
299
297
|
});
|
package/src/types/api/export.ts
CHANGED
|
@@ -151,5 +151,4 @@ export type { NervosAddress, NervosGetAddressParams } from './nervosGetAddress';
|
|
|
151
151
|
export type { NervosSignedTx, NervosSignTransactionParams } from './nervosSignTransaction';
|
|
152
152
|
|
|
153
153
|
export type { DnxAddress, DnxGetAddressParams } from './dnxGetAddress';
|
|
154
|
-
export type { DnxTrackingKey, DnxGetTrackingKeyParams } from './dnxGetTrackingKey';
|
|
155
154
|
export type { DnxTxKey, DnxSignTransactionParams, DnxSignature } from './dnxSignTransaction';
|
package/src/types/api/index.ts
CHANGED
|
@@ -124,7 +124,6 @@ import { nervosGetAddress } from './nervosGetAddress';
|
|
|
124
124
|
import { nervosSignTransaction } from './nervosSignTransaction';
|
|
125
125
|
|
|
126
126
|
import { dnxGetAddress } from './dnxGetAddress';
|
|
127
|
-
import { dnxGetTrackingKey } from './dnxGetTrackingKey';
|
|
128
127
|
import { dnxSignTransaction } from './dnxSignTransaction';
|
|
129
128
|
|
|
130
129
|
export * from './export';
|
|
@@ -342,6 +341,5 @@ export type CoreApi = {
|
|
|
342
341
|
* Dnx Network
|
|
343
342
|
*/
|
|
344
343
|
dnxGetAddress: typeof dnxGetAddress;
|
|
345
|
-
dnxGetTrackingKey: typeof dnxGetTrackingKey;
|
|
346
344
|
dnxSignTransaction: typeof dnxSignTransaction;
|
|
347
345
|
};
|
package/src/types/device.ts
CHANGED
|
@@ -3,7 +3,12 @@ import { IVersionArray } from './settings';
|
|
|
3
3
|
|
|
4
4
|
export type DeviceStatus = 'available' | 'occupied' | 'used';
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export enum EOneKeyDeviceMode {
|
|
7
|
+
bootloader = 'bootloader',
|
|
8
|
+
normal = 'normal',
|
|
9
|
+
notInitialized = 'notInitialized',
|
|
10
|
+
backupMode = 'backupMode',
|
|
11
|
+
}
|
|
7
12
|
|
|
8
13
|
export type UnavailableCapability =
|
|
9
14
|
| 'no-capability'
|
|
@@ -23,7 +28,7 @@ export type KnownDevice = {
|
|
|
23
28
|
bleName: string | null;
|
|
24
29
|
name: string;
|
|
25
30
|
error?: typeof undefined;
|
|
26
|
-
mode:
|
|
31
|
+
mode: EOneKeyDeviceMode;
|
|
27
32
|
features: PROTO.Features;
|
|
28
33
|
unavailableCapabilities: UnavailableCapabilities;
|
|
29
34
|
bleFirmwareVersion: IVersionArray | null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import semver from 'semver';
|
|
2
|
+
import { isNaN } from 'lodash';
|
|
2
3
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
3
4
|
import { toHardened } from '../api/helpers/pathUtils';
|
|
4
5
|
import { DeviceCommands } from '../device/DeviceCommands';
|
|
@@ -75,11 +76,19 @@ export const supportNewPassphrase = (features?: Features): SupportFeatureType =>
|
|
|
75
76
|
export const getPassphraseStateWithRefreshDeviceInfo = async (device: Device) => {
|
|
76
77
|
const { features, commands } = device;
|
|
77
78
|
const locked = features?.unlocked === false;
|
|
79
|
+
|
|
78
80
|
const passphraseState = await getPassphraseState(features, commands);
|
|
79
81
|
const isModeT = getDeviceType(features) === 'touch' || getDeviceType(features) === 'pro';
|
|
80
82
|
|
|
83
|
+
// 如果可以获取到 passphraseState,但是设备 features 显示设备未开启 passphrase,需要刷新设备状态
|
|
84
|
+
// if passphraseState can be obtained, but the device features show that the device has not enabled passphrase, the device status needs to be refreshed
|
|
85
|
+
const needRefreshWithPassphrase = passphraseState && features?.passphrase_protection !== true;
|
|
86
|
+
// 如果 Touch/Pro 在之前是锁定状态,刷新设备状态
|
|
81
87
|
// if Touch/Pro was locked before, refresh the device state
|
|
82
|
-
|
|
88
|
+
const needRefreshWithLocked = isModeT && locked;
|
|
89
|
+
|
|
90
|
+
if (needRefreshWithLocked || needRefreshWithPassphrase) {
|
|
91
|
+
// refresh device state
|
|
83
92
|
await device.getFeatures();
|
|
84
93
|
}
|
|
85
94
|
|
|
@@ -167,3 +176,30 @@ export const getFirmwareUpdateField = ({
|
|
|
167
176
|
}
|
|
168
177
|
return 'firmware';
|
|
169
178
|
};
|
|
179
|
+
|
|
180
|
+
export function fixVersion(version: string) {
|
|
181
|
+
let parts = version.split('.');
|
|
182
|
+
|
|
183
|
+
while (parts.length < 3) {
|
|
184
|
+
parts.push('0');
|
|
185
|
+
}
|
|
186
|
+
parts = parts.map(part => (isNaN(parseInt(part, 10)) ? '0' : part));
|
|
187
|
+
|
|
188
|
+
return parts.join('.');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export const fixFeaturesFirmwareVersion = (features: Features): Features => {
|
|
192
|
+
// 修复 Touch、Pro 设备 bootloader 低于 2.5.2 版本时,返回的 features 中没有 firmware_version 错误的问题
|
|
193
|
+
// fix Touch、Pro device when bootloader version is lower than 2.5.2, the features returned do not have firmware_version error
|
|
194
|
+
const tempFeatures = { ...features };
|
|
195
|
+
|
|
196
|
+
if (tempFeatures.onekey_firmware_version && !semver.valid(tempFeatures.onekey_firmware_version)) {
|
|
197
|
+
tempFeatures.onekey_firmware_version = fixVersion(tempFeatures.onekey_firmware_version);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (tempFeatures.onekey_version && !semver.valid(tempFeatures.onekey_version)) {
|
|
201
|
+
tempFeatures.onekey_version = fixVersion(tempFeatures.onekey_version);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return tempFeatures;
|
|
205
|
+
};
|
|
@@ -119,16 +119,18 @@ export const getMethodVersionRange = (
|
|
|
119
119
|
const deviceType = getDeviceType(features);
|
|
120
120
|
let versionRange: IVersionRange | undefined = getVersionRange(deviceType);
|
|
121
121
|
|
|
122
|
-
if (
|
|
122
|
+
if (versionRange) {
|
|
123
123
|
return versionRange;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
126
|
+
const modelFallbacks: IDeviceModel[] = ['model_classic', 'model_mini', 'model_touch'];
|
|
127
|
+
for (const model of modelFallbacks) {
|
|
128
|
+
if (DeviceModelToTypes[model].includes(deviceType)) {
|
|
129
|
+
versionRange = getVersionRange(model);
|
|
130
|
+
if (versionRange) {
|
|
131
|
+
return versionRange;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
132
134
|
}
|
|
133
135
|
|
|
134
136
|
return versionRange;
|
|
@@ -15,11 +15,7 @@ export const getDeviceFirmwareVersion = (features: Features | undefined): IVersi
|
|
|
15
15
|
return features.onekey_version?.split('.') as unknown as IVersionArray;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
return [
|
|
19
|
-
features.major_version ?? '0',
|
|
20
|
-
features.minor_version ?? '0',
|
|
21
|
-
features.patch_version ?? '0',
|
|
22
|
-
];
|
|
18
|
+
return [0, 0, 0];
|
|
23
19
|
};
|
|
24
20
|
|
|
25
21
|
/**
|
|
@@ -53,7 +49,11 @@ export const getDeviceBootloaderVersion = (features: Features | undefined): IVer
|
|
|
53
49
|
// low version hardware
|
|
54
50
|
if (!features.bootloader_version) {
|
|
55
51
|
if (features.bootloader_mode) {
|
|
56
|
-
return [
|
|
52
|
+
return [
|
|
53
|
+
features?.major_version ?? 0,
|
|
54
|
+
features?.minor_version ?? 0,
|
|
55
|
+
features?.patch_version ?? 0,
|
|
56
|
+
];
|
|
57
57
|
}
|
|
58
58
|
return [0, 0, 0];
|
|
59
59
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { DnxGetTrackingKey as HardwareDnxGetTrackingKey } from '@onekeyfe/hd-transport';
|
|
2
|
-
import { BaseMethod } from '../BaseMethod';
|
|
3
|
-
import type { DnxTrackingKey } from '../../types';
|
|
4
|
-
export default class DnxGetTrackingKey extends BaseMethod<HardwareDnxGetTrackingKey> {
|
|
5
|
-
init(): void;
|
|
6
|
-
getVersionRange(): {
|
|
7
|
-
classic: {
|
|
8
|
-
min: string;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
run(): Promise<DnxTrackingKey>;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=DnxGetTrackingKey.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DnxGetTrackingKey.d.ts","sourceRoot":"","sources":["../../../src/api/dynex/DnxGetTrackingKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,IAAI,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAG7F,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,KAAK,EAA2B,cAAc,EAAE,MAAM,aAAa,CAAC;AAE3E,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,UAAU,CAAC,yBAAyB,CAAC;IAClF,IAAI;IAiBJ,eAAe;;;;;IAQT,GAAG,IAAI,OAAO,CAAC,cAAc,CAAC;CAYrC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { CommonParams, Response } from '../params';
|
|
2
|
-
export type DnxTrackingKey = {
|
|
3
|
-
path: string;
|
|
4
|
-
trackingKey: string;
|
|
5
|
-
};
|
|
6
|
-
export type DnxGetTrackingKeyParams = {
|
|
7
|
-
path: string | number[];
|
|
8
|
-
};
|
|
9
|
-
export declare function dnxGetTrackingKey(connectId: string, deviceId: string, params: CommonParams & DnxGetTrackingKeyParams): Response<DnxTrackingKey>;
|
|
10
|
-
//# sourceMappingURL=dnxGetTrackingKey.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dnxGetTrackingKey.d.ts","sourceRoot":"","sources":["../../../src/types/api/dnxGetTrackingKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,YAAY,GAAG,uBAAuB,GAC7C,QAAQ,CAAC,cAAc,CAAC,CAAC"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { DnxGetTrackingKey as HardwareDnxGetTrackingKey } from '@onekeyfe/hd-transport';
|
|
2
|
-
import { UI_REQUEST } from '../../constants/ui-request';
|
|
3
|
-
import { serializedPath, validatePath } from '../helpers/pathUtils';
|
|
4
|
-
import { BaseMethod } from '../BaseMethod';
|
|
5
|
-
import { validateParams } from '../helpers/paramsValidator';
|
|
6
|
-
|
|
7
|
-
import type { DnxGetTrackingKeyParams, DnxTrackingKey } from '../../types';
|
|
8
|
-
|
|
9
|
-
export default class DnxGetTrackingKey extends BaseMethod<HardwareDnxGetTrackingKey> {
|
|
10
|
-
init() {
|
|
11
|
-
this.checkDeviceId = true;
|
|
12
|
-
this.notAllowDeviceMode = [...this.notAllowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
13
|
-
|
|
14
|
-
const payload = this.payload as DnxGetTrackingKeyParams;
|
|
15
|
-
|
|
16
|
-
// check payload
|
|
17
|
-
validateParams(payload, [{ name: 'path', required: true }]);
|
|
18
|
-
|
|
19
|
-
// init params
|
|
20
|
-
const addressN = validatePath(payload.path, 3);
|
|
21
|
-
|
|
22
|
-
this.params = {
|
|
23
|
-
address_n: addressN,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
getVersionRange() {
|
|
28
|
-
return {
|
|
29
|
-
classic: {
|
|
30
|
-
min: '3.8.0',
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async run(): Promise<DnxTrackingKey> {
|
|
36
|
-
const res = await this.device.commands.typedCall('DnxGetTrackingKey', 'DnxTrackingKey', {
|
|
37
|
-
...this.params,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const { tracking_key } = res.message;
|
|
41
|
-
|
|
42
|
-
return Promise.resolve({
|
|
43
|
-
path: serializedPath(this.params.address_n),
|
|
44
|
-
trackingKey: tracking_key,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { CommonParams, Response } from '../params';
|
|
2
|
-
|
|
3
|
-
export type DnxTrackingKey = {
|
|
4
|
-
path: string;
|
|
5
|
-
trackingKey: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type DnxGetTrackingKeyParams = {
|
|
9
|
-
path: string | number[];
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export declare function dnxGetTrackingKey(
|
|
13
|
-
connectId: string,
|
|
14
|
-
deviceId: string,
|
|
15
|
-
params: CommonParams & DnxGetTrackingKeyParams
|
|
16
|
-
): Response<DnxTrackingKey>;
|