@onekeyfe/hd-core 0.1.53 → 0.1.55
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/CheckBLEFirmwareRelease.d.ts +1 -1
- package/dist/api/CheckFirmwareRelease.d.ts +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +19 -0
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -0
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/aptos/AptosGetAddress.d.ts +7 -1
- package/dist/api/aptos/AptosGetAddress.d.ts.map +1 -1
- package/dist/api/aptos/AptosGetPublicKey.d.ts +18 -0
- package/dist/api/aptos/AptosGetPublicKey.d.ts.map +1 -0
- package/dist/api/device/DeviceUpdateReboot.d.ts +2 -2
- package/dist/api/device/DeviceUpdateReboot.d.ts.map +1 -1
- package/dist/api/device/DeviceUploadResource.d.ts +18 -0
- package/dist/api/device/DeviceUploadResource.d.ts.map +1 -0
- package/dist/api/device/DeviceVerify.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +3 -11
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/releaseHelper.d.ts +2 -2
- package/dist/api/firmware/uploadFirmware.d.ts +5 -1
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/index.d.ts +3 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/constants/ui-request.d.ts +1 -0
- package/dist/constants/ui-request.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +3 -2
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +3 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +11 -1
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +56 -26
- package/dist/index.js +620 -131
- package/dist/types/api/aptosGetPublicKey.d.ts +14 -0
- package/dist/types/api/aptosGetPublicKey.d.ts.map +1 -0
- package/dist/types/api/confluxSignTransaction.d.ts +1 -1
- package/dist/types/api/confluxSignTransaction.d.ts.map +1 -1
- package/dist/types/api/deviceUploadResource.d.ts +11 -0
- package/dist/types/api/deviceUploadResource.d.ts.map +1 -0
- package/dist/types/api/export.d.ts +3 -0
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +5 -5
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +5 -2
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/settings.d.ts +1 -0
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/release.d.ts +4 -1
- package/dist/utils/release.d.ts.map +1 -1
- package/package.json +9 -6
- package/src/api/FirmwareUpdateV2.ts +218 -0
- package/src/api/GetPassphraseState.ts +3 -0
- package/src/api/aptos/AptosGetAddress.ts +16 -8
- package/src/api/aptos/AptosGetPublicKey.ts +60 -0
- package/src/api/aptos/AptosSignTransaction.ts +1 -1
- package/src/api/conflux/ConfluxSignMessage.ts +1 -1
- package/src/api/conflux/ConfluxSignMessageCIP23.ts +1 -1
- package/src/api/conflux/ConfluxSignTransaction.ts +2 -2
- package/src/api/device/DeviceUpdateReboot.ts +3 -3
- package/src/api/device/DeviceUploadResource.ts +104 -0
- package/src/api/device/DeviceVerify.ts +3 -2
- package/src/api/firmware/getBinary.ts +17 -7
- package/src/api/firmware/releaseHelper.ts +2 -2
- package/src/api/firmware/uploadFirmware.ts +119 -1
- package/src/api/helpers/hexUtils.ts +1 -1
- package/src/api/index.ts +3 -1
- package/src/constants/ui-request.ts +2 -0
- package/src/core/index.ts +6 -1
- package/src/data/coins/bitcoin.json +1 -0
- package/src/data/messages/messages.json +115 -13
- package/src/data-manager/DataManager.ts +35 -5
- package/src/device/Device.ts +30 -14
- package/src/device/DeviceCommands.ts +5 -2
- package/src/events/ui-request.ts +11 -1
- package/src/inject.ts +6 -6
- package/src/types/api/aptosGetPublicKey.ts +23 -0
- package/src/types/api/confluxSignTransaction.ts +1 -1
- package/src/types/api/deviceUploadResource.ts +15 -0
- package/src/types/api/export.ts +3 -0
- package/src/types/api/firmwareUpdate.ts +5 -5
- package/src/types/api/index.ts +5 -2
- package/src/types/settings.ts +2 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/release.ts +18 -1
- package/dist/api/BatchGetPublicKey.d.ts +0 -11
- package/dist/api/BatchGetPublicKey.d.ts.map +0 -1
- package/dist/types/api/batchGetPublicKey.d.ts +0 -11
- package/dist/types/api/batchGetPublicKey.d.ts.map +0 -1
- package/src/api/BatchGetPublicKey.ts +0 -40
- package/src/types/api/batchGetPublicKey.ts +0 -18
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
import { blake2s } from '@noble/hashes/blake2s';
|
|
2
|
+
import JSZip from 'jszip';
|
|
1
3
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
4
|
+
import { Success } from '@onekeyfe/hd-transport';
|
|
5
|
+
import { wait, getLogger, LoggerNames } from '../../utils/index';
|
|
2
6
|
import { DEVICE, CoreMessage, createUiMessage, UI_REQUEST } from '../../events';
|
|
3
7
|
import { PROTO } from '../../constants';
|
|
4
8
|
import type { Device } from '../../device/Device';
|
|
5
|
-
import type { TypedCall } from '../../device/DeviceCommands';
|
|
9
|
+
import type { TypedCall, TypedResponseMessage } from '../../device/DeviceCommands';
|
|
6
10
|
import { KnownDevice } from '../../types';
|
|
11
|
+
import { bytesToHex } from '../helpers/hexUtils';
|
|
12
|
+
|
|
13
|
+
const Log = getLogger(LoggerNames.Device);
|
|
7
14
|
|
|
8
15
|
const postConfirmationMessage = (device: Device) => {
|
|
9
16
|
// only if firmware is already installed. fresh device does not require button confirmation
|
|
@@ -25,6 +32,28 @@ const postProgressMessage = (
|
|
|
25
32
|
);
|
|
26
33
|
};
|
|
27
34
|
|
|
35
|
+
const postProgressTip = (
|
|
36
|
+
device: Device,
|
|
37
|
+
message: string,
|
|
38
|
+
postMessage: (message: CoreMessage) => void
|
|
39
|
+
) => {
|
|
40
|
+
postMessage(
|
|
41
|
+
createUiMessage(UI_REQUEST.FIRMWARE_TIP, {
|
|
42
|
+
device: device.toMessageObject() as KnownDevice,
|
|
43
|
+
data: {
|
|
44
|
+
message,
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const waitBleInstall = async (updateType: string) => {
|
|
51
|
+
if (updateType === 'ble') {
|
|
52
|
+
// wait for device install
|
|
53
|
+
await wait(10 * 1000);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
28
57
|
export const uploadFirmware = async (
|
|
29
58
|
updateType: 'firmware' | 'ble',
|
|
30
59
|
typedCall: TypedCall,
|
|
@@ -34,21 +63,27 @@ export const uploadFirmware = async (
|
|
|
34
63
|
) => {
|
|
35
64
|
if (device.features?.major_version === 1) {
|
|
36
65
|
postConfirmationMessage(device);
|
|
66
|
+
postProgressTip(device, 'ConfirmOnDevice', postMessage);
|
|
37
67
|
const eraseCommand = updateType === 'firmware' ? 'FirmwareErase' : 'FirmwareErase_ex';
|
|
38
68
|
await typedCall(eraseCommand as unknown as any, 'Success', {});
|
|
69
|
+
postProgressTip(device, 'FirmwareEraseSuccess', postMessage);
|
|
39
70
|
postProgressMessage(device, 0, postMessage);
|
|
40
71
|
const { message } = await typedCall('FirmwareUpload', 'Success', {
|
|
41
72
|
payload,
|
|
42
73
|
});
|
|
43
74
|
postProgressMessage(device, 100, postMessage);
|
|
75
|
+
|
|
76
|
+
await waitBleInstall(updateType);
|
|
44
77
|
return message;
|
|
45
78
|
}
|
|
46
79
|
|
|
47
80
|
if (device.features?.major_version === 2) {
|
|
48
81
|
postConfirmationMessage(device);
|
|
82
|
+
postProgressTip(device, 'ConfirmOnDevice', postMessage);
|
|
49
83
|
const length = payload.byteLength;
|
|
50
84
|
|
|
51
85
|
let response = await typedCall('FirmwareErase', ['FirmwareRequest', 'Success'], { length });
|
|
86
|
+
postProgressTip(device, 'FirmwareEraseSuccess', postMessage);
|
|
52
87
|
while (response.type !== 'Success') {
|
|
53
88
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
54
89
|
const start = response.message.offset!;
|
|
@@ -66,8 +101,91 @@ export const uploadFirmware = async (
|
|
|
66
101
|
}
|
|
67
102
|
|
|
68
103
|
postProgressMessage(device, 100, postMessage);
|
|
104
|
+
|
|
105
|
+
await waitBleInstall(updateType);
|
|
69
106
|
return response.message;
|
|
70
107
|
}
|
|
71
108
|
|
|
72
109
|
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown major_version');
|
|
73
110
|
};
|
|
111
|
+
|
|
112
|
+
const processResourceRequest = async (
|
|
113
|
+
typedCall: TypedCall,
|
|
114
|
+
res: TypedResponseMessage<'ResourceRequest'> | TypedResponseMessage<'Success'>,
|
|
115
|
+
data: ArrayBuffer
|
|
116
|
+
): Promise<Success> => {
|
|
117
|
+
if (res.type === 'Success') {
|
|
118
|
+
return res.message;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const { offset, data_length } = res.message;
|
|
122
|
+
|
|
123
|
+
if (offset === undefined) {
|
|
124
|
+
throw new Error('offset is undefined');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const payload = new Uint8Array(
|
|
128
|
+
data.slice(offset, Math.min(offset + data_length, data.byteLength))
|
|
129
|
+
);
|
|
130
|
+
const digest = blake2s(payload);
|
|
131
|
+
|
|
132
|
+
const resourceAckParams = {
|
|
133
|
+
data_chunk: bytesToHex(payload),
|
|
134
|
+
hash: bytesToHex(digest),
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const response = await typedCall('ResourceAck', ['ResourceRequest', 'Success'], {
|
|
138
|
+
...resourceAckParams,
|
|
139
|
+
});
|
|
140
|
+
return processResourceRequest(typedCall, response, data);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// Fixed size
|
|
144
|
+
const INIT_DATA_CHUNK_SIZE = 16 * 1024;
|
|
145
|
+
export const updateResource = async (typedCall: TypedCall, fileName: string, data: ArrayBuffer) => {
|
|
146
|
+
const chunk = new Uint8Array(data.slice(0, Math.min(INIT_DATA_CHUNK_SIZE, data.byteLength)));
|
|
147
|
+
const digest = blake2s(chunk);
|
|
148
|
+
|
|
149
|
+
const res = await typedCall('ResourceUpdate', ['ResourceRequest', 'Success'], {
|
|
150
|
+
file_name: fileName,
|
|
151
|
+
data_length: data.byteLength,
|
|
152
|
+
initial_data_chunk: bytesToHex(chunk),
|
|
153
|
+
hash: bytesToHex(digest),
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
return processResourceRequest(typedCall, res, data);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const updateResources = async (
|
|
160
|
+
typedCall: TypedCall,
|
|
161
|
+
postMessage: (message: CoreMessage) => void,
|
|
162
|
+
device: Device,
|
|
163
|
+
source: ArrayBuffer
|
|
164
|
+
) => {
|
|
165
|
+
postProgressTip(device, 'UpdateSysResource', postMessage);
|
|
166
|
+
|
|
167
|
+
const zipData = await JSZip.loadAsync(source);
|
|
168
|
+
const files = Object.entries(zipData.files);
|
|
169
|
+
|
|
170
|
+
let progress = 0;
|
|
171
|
+
const stepProgress = 100 / files.length;
|
|
172
|
+
|
|
173
|
+
for (const [fileName, file] of files) {
|
|
174
|
+
const name = fileName.split('/').pop();
|
|
175
|
+
if (!file.dir && fileName.indexOf('__MACOSX') === -1 && name) {
|
|
176
|
+
const data = await file.async('arraybuffer');
|
|
177
|
+
try {
|
|
178
|
+
await updateResource(typedCall, name, data);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
Log.error(error);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
progress += stepProgress;
|
|
185
|
+
postProgressMessage(device, Math.floor(progress), postMessage);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
postProgressMessage(device, 100, postMessage);
|
|
189
|
+
postProgressTip(device, 'UpdateSysResourceSuccess', postMessage);
|
|
190
|
+
return true;
|
|
191
|
+
};
|
|
@@ -48,7 +48,7 @@ export const formatAnyHex: (value: any) => any = value => {
|
|
|
48
48
|
return value;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
const hexes = Array.from({ length: 256 }, (
|
|
51
|
+
const hexes = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
|
|
52
52
|
/**
|
|
53
53
|
* @example bytesToHex(Uint8Array.from([0xde, 0xad, 0xbe, 0xef]))
|
|
54
54
|
*/
|
package/src/api/index.ts
CHANGED
|
@@ -14,13 +14,14 @@ export { default as deviceRecovery } from './device/DeviceRecovery';
|
|
|
14
14
|
export { default as deviceReset } from './device/DeviceReset';
|
|
15
15
|
export { default as deviceSettings } from './device/DeviceSettings';
|
|
16
16
|
export { default as deviceUpdateReboot } from './device/DeviceUpdateReboot';
|
|
17
|
+
export { default as deviceUploadResource } from './device/DeviceUploadResource';
|
|
17
18
|
export { default as deviceSupportFeatures } from './device/DeviceSupportFeatures';
|
|
18
19
|
export { default as deviceVerify } from './device/DeviceVerify';
|
|
19
20
|
export { default as deviceWipe } from './device/DeviceWipe';
|
|
20
21
|
export { default as firmwareUpdate } from './FirmwareUpdate';
|
|
22
|
+
export { default as firmwareUpdateV2 } from './FirmwareUpdateV2';
|
|
21
23
|
export { default as requestWebUsbDevice } from './RequestWebUsbDevice';
|
|
22
24
|
|
|
23
|
-
export { default as batchGetPublicKey } from './BatchGetPublicKey';
|
|
24
25
|
export { default as cipherKeyValue } from './CipherKeyValue';
|
|
25
26
|
|
|
26
27
|
export { default as btcGetAddress } from './btc/BTCGetAddress';
|
|
@@ -65,4 +66,5 @@ export { default as nearGetAddress } from './near/NearGetAddress';
|
|
|
65
66
|
export { default as nearSignTransaction } from './near/NearSignTransaction';
|
|
66
67
|
|
|
67
68
|
export { default as aptosGetAddress } from './aptos/AptosGetAddress';
|
|
69
|
+
export { default as aptosGetPublicKey } from './aptos/AptosGetPublicKey';
|
|
68
70
|
export { default as aptosSignTransaction } from './aptos/AptosSignTransaction';
|
|
@@ -9,4 +9,6 @@ export const UI_REQUEST = {
|
|
|
9
9
|
FIRMWARE_NOT_COMPATIBLE: 'ui-device_firmware_not_compatible',
|
|
10
10
|
FIRMWARE_NOT_INSTALLED: 'ui-device_firmware_not_installed',
|
|
11
11
|
NOT_USE_ONEKEY_DEVICE: 'ui-device_please_use_onekey_device',
|
|
12
|
+
|
|
13
|
+
FIRMWARE_TIP: 'ui-firmware-tip',
|
|
12
14
|
} as const;
|
package/src/core/index.ts
CHANGED
|
@@ -345,7 +345,11 @@ function initDevice(method: BaseMethod) {
|
|
|
345
345
|
} else if (allDevices.length === 1) {
|
|
346
346
|
[device] = allDevices;
|
|
347
347
|
} else if (allDevices.length > 1) {
|
|
348
|
-
throw ERRORS.TypedError(
|
|
348
|
+
throw ERRORS.TypedError(
|
|
349
|
+
method.name === 'firmwareUpdateV2'
|
|
350
|
+
? HardwareErrorCode.FirmwareUpdateLimitOneDevice
|
|
351
|
+
: HardwareErrorCode.SelectDevice
|
|
352
|
+
);
|
|
349
353
|
}
|
|
350
354
|
|
|
351
355
|
if (!device) {
|
|
@@ -463,6 +467,7 @@ const ensureConnected = async (method: BaseMethod, pollingId: number) => {
|
|
|
463
467
|
HardwareErrorCode.BleCharacteristicNotifyError,
|
|
464
468
|
HardwareErrorCode.BleWriteCharacteristicError,
|
|
465
469
|
HardwareErrorCode.BleAlreadyConnected,
|
|
470
|
+
HardwareErrorCode.FirmwareUpdateLimitOneDevice,
|
|
466
471
|
].includes(error.errorCode)
|
|
467
472
|
) {
|
|
468
473
|
reject(error);
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
{ "name": "Testnet", "label": "TEST", "slip44": 1 },
|
|
5
5
|
{ "name": "Actinium", "label": "ACM", "slip44": 228 },
|
|
6
6
|
{ "name": "Axe", "label": "AXE", "slip44": 4242 },
|
|
7
|
+
{ "name": "Bcash", "label": "BCH", "slip44": 145 },
|
|
7
8
|
{ "name": "Bitcore", "label": "BTX", "slip44": 160 },
|
|
8
9
|
{ "name": "Dash", "label": "DASH", "slip44": 5 },
|
|
9
10
|
{ "name": "Dash Testnet", "label": "tDASH", "slip44": 1 },
|
|
@@ -5011,7 +5011,7 @@
|
|
|
5011
5011
|
}
|
|
5012
5012
|
}
|
|
5013
5013
|
},
|
|
5014
|
-
"
|
|
5014
|
+
"DeviceBackToBoot": {
|
|
5015
5015
|
"fields": {}
|
|
5016
5016
|
},
|
|
5017
5017
|
"BixinBackupRequest": {
|
|
@@ -5281,6 +5281,104 @@
|
|
|
5281
5281
|
}
|
|
5282
5282
|
}
|
|
5283
5283
|
},
|
|
5284
|
+
"ResourceUpload": {
|
|
5285
|
+
"fields": {
|
|
5286
|
+
"extension": {
|
|
5287
|
+
"rule": "required",
|
|
5288
|
+
"type": "string",
|
|
5289
|
+
"id": 1
|
|
5290
|
+
},
|
|
5291
|
+
"data_length": {
|
|
5292
|
+
"rule": "required",
|
|
5293
|
+
"type": "uint32",
|
|
5294
|
+
"id": 2
|
|
5295
|
+
},
|
|
5296
|
+
"res_type": {
|
|
5297
|
+
"rule": "required",
|
|
5298
|
+
"type": "ResourceType",
|
|
5299
|
+
"id": 3
|
|
5300
|
+
},
|
|
5301
|
+
"zoom_data_length": {
|
|
5302
|
+
"rule": "required",
|
|
5303
|
+
"type": "uint32",
|
|
5304
|
+
"id": 5
|
|
5305
|
+
},
|
|
5306
|
+
"nft_meta_data": {
|
|
5307
|
+
"type": "bytes",
|
|
5308
|
+
"id": 4
|
|
5309
|
+
}
|
|
5310
|
+
},
|
|
5311
|
+
"nested": {
|
|
5312
|
+
"ResourceType": {
|
|
5313
|
+
"values": {
|
|
5314
|
+
"WallPaper": 0,
|
|
5315
|
+
"Nft": 1
|
|
5316
|
+
}
|
|
5317
|
+
}
|
|
5318
|
+
}
|
|
5319
|
+
},
|
|
5320
|
+
"ZoomRequest": {
|
|
5321
|
+
"fields": {
|
|
5322
|
+
"offset": {
|
|
5323
|
+
"type": "uint32",
|
|
5324
|
+
"id": 1
|
|
5325
|
+
},
|
|
5326
|
+
"data_length": {
|
|
5327
|
+
"rule": "required",
|
|
5328
|
+
"type": "uint32",
|
|
5329
|
+
"id": 2
|
|
5330
|
+
}
|
|
5331
|
+
}
|
|
5332
|
+
},
|
|
5333
|
+
"ResourceRequest": {
|
|
5334
|
+
"fields": {
|
|
5335
|
+
"offset": {
|
|
5336
|
+
"type": "uint32",
|
|
5337
|
+
"id": 1
|
|
5338
|
+
},
|
|
5339
|
+
"data_length": {
|
|
5340
|
+
"rule": "required",
|
|
5341
|
+
"type": "uint32",
|
|
5342
|
+
"id": 2
|
|
5343
|
+
}
|
|
5344
|
+
}
|
|
5345
|
+
},
|
|
5346
|
+
"ResourceAck": {
|
|
5347
|
+
"fields": {
|
|
5348
|
+
"data_chunk": {
|
|
5349
|
+
"rule": "required",
|
|
5350
|
+
"type": "bytes",
|
|
5351
|
+
"id": 1
|
|
5352
|
+
},
|
|
5353
|
+
"hash": {
|
|
5354
|
+
"type": "bytes",
|
|
5355
|
+
"id": 2
|
|
5356
|
+
}
|
|
5357
|
+
}
|
|
5358
|
+
},
|
|
5359
|
+
"ResourceUpdate": {
|
|
5360
|
+
"fields": {
|
|
5361
|
+
"file_name": {
|
|
5362
|
+
"rule": "required",
|
|
5363
|
+
"type": "string",
|
|
5364
|
+
"id": 1
|
|
5365
|
+
},
|
|
5366
|
+
"data_length": {
|
|
5367
|
+
"rule": "required",
|
|
5368
|
+
"type": "uint32",
|
|
5369
|
+
"id": 2
|
|
5370
|
+
},
|
|
5371
|
+
"initial_data_chunk": {
|
|
5372
|
+
"rule": "required",
|
|
5373
|
+
"type": "bytes",
|
|
5374
|
+
"id": 3
|
|
5375
|
+
},
|
|
5376
|
+
"hash": {
|
|
5377
|
+
"type": "bytes",
|
|
5378
|
+
"id": 4
|
|
5379
|
+
}
|
|
5380
|
+
}
|
|
5381
|
+
},
|
|
5284
5382
|
"NFTWriteInfo": {
|
|
5285
5383
|
"fields": {
|
|
5286
5384
|
"index": {
|
|
@@ -6277,6 +6375,7 @@
|
|
|
6277
6375
|
}
|
|
6278
6376
|
},
|
|
6279
6377
|
"raw_tx": {
|
|
6378
|
+
"rule": "required",
|
|
6280
6379
|
"type": "bytes",
|
|
6281
6380
|
"id": 2
|
|
6282
6381
|
}
|
|
@@ -8405,16 +8504,6 @@
|
|
|
8405
8504
|
"MessageType_StarcoinSignMessage": 10306,
|
|
8406
8505
|
"MessageType_StarcoinMessageSignature": 10307,
|
|
8407
8506
|
"MessageType_StarcoinVerifyMessage": 10308,
|
|
8408
|
-
"MessageType_ConfluxGetAddress": 10401,
|
|
8409
|
-
"MessageType_ConfluxAddress": 10402,
|
|
8410
|
-
"MessageType_ConfluxSignTx": 10403,
|
|
8411
|
-
"MessageType_ConfluxTxRequest": 10404,
|
|
8412
|
-
"MessageType_ConfluxTxAck": 10405,
|
|
8413
|
-
"MessageType_ConfluxSignMessage": 10406,
|
|
8414
|
-
"MessageType_ConfluxSignMessageCIP23": 10407,
|
|
8415
|
-
"MessageType_ConfluxMessageSignature": 10408,
|
|
8416
|
-
"MessageType_ConfluxVerifyMessage": 10409,
|
|
8417
|
-
"MessageType_ConfluxVerifyMessageCIP23": 10410,
|
|
8418
8507
|
"MessageType_AptosGetAddress": 10600,
|
|
8419
8508
|
"MessageType_AptosAddress": 10601,
|
|
8420
8509
|
"MessageType_AptosSignTx": 10602,
|
|
@@ -8425,7 +8514,6 @@
|
|
|
8425
8514
|
"MessageType_WebAuthnRemoveResidentCredential": 803,
|
|
8426
8515
|
"MessageType_BixinSeedOperate": 901,
|
|
8427
8516
|
"MessageType_BixinMessageSE": 902,
|
|
8428
|
-
"MessageType_BixinReboot": 903,
|
|
8429
8517
|
"MessageType_BixinOutMessageSE": 904,
|
|
8430
8518
|
"MessageType_BixinBackupRequest": 905,
|
|
8431
8519
|
"MessageType_BixinBackupAck": 906,
|
|
@@ -8442,6 +8530,14 @@
|
|
|
8442
8530
|
"MessageType_EthereumSignMessageEIP712": 10200,
|
|
8443
8531
|
"MessageType_GetPublicKeyMultiple": 10210,
|
|
8444
8532
|
"MessageType_PublicKeyMultiple": 10211,
|
|
8533
|
+
"MessageType_ConfluxGetAddress": 10112,
|
|
8534
|
+
"MessageType_ConfluxAddress": 10113,
|
|
8535
|
+
"MessageType_ConfluxSignTx": 10114,
|
|
8536
|
+
"MessageType_ConfluxTxRequest": 10115,
|
|
8537
|
+
"MessageType_ConfluxTxAck": 10116,
|
|
8538
|
+
"MessageType_ConfluxSignMessage": 10117,
|
|
8539
|
+
"MessageType_ConfluxSignMessageCIP23": 10118,
|
|
8540
|
+
"MessageType_ConfluxMessageSignature": 10119,
|
|
8445
8541
|
"MessageType_TronGetAddress": 10501,
|
|
8446
8542
|
"MessageType_TronAddress": 10502,
|
|
8447
8543
|
"MessageType_TronSignTx": 10503,
|
|
@@ -8452,6 +8548,7 @@
|
|
|
8452
8548
|
"MessageType_NearAddress": 10702,
|
|
8453
8549
|
"MessageType_NearSignTx": 10703,
|
|
8454
8550
|
"MessageType_NearSignedTx": 10704,
|
|
8551
|
+
"MessageType_DeviceBackToBoot": 903,
|
|
8455
8552
|
"MessageType_DeviceInfoSettings": 10001,
|
|
8456
8553
|
"MessageType_GetDeviceInfo": 10002,
|
|
8457
8554
|
"MessageType_DeviceInfo": 10003,
|
|
@@ -8466,7 +8563,12 @@
|
|
|
8466
8563
|
"MessageType_SESignMessage": 10012,
|
|
8467
8564
|
"MessageType_SEMessageSignature": 10013,
|
|
8468
8565
|
"MessageType_NFTWriteInfo": 10014,
|
|
8469
|
-
"MessageType_NFTWriteData": 10015
|
|
8566
|
+
"MessageType_NFTWriteData": 10015,
|
|
8567
|
+
"MessageType_ResourceUpload": 10018,
|
|
8568
|
+
"MessageType_ZoomRequest": 10019,
|
|
8569
|
+
"MessageType_ResourceRequest": 10020,
|
|
8570
|
+
"MessageType_ResourceAck": 10021,
|
|
8571
|
+
"MessageType_ResourceUpdate": 10022
|
|
8470
8572
|
}
|
|
8471
8573
|
},
|
|
8472
8574
|
"google": {
|
|
@@ -18,7 +18,7 @@ import type {
|
|
|
18
18
|
IDeviceBLEFirmwareStatus,
|
|
19
19
|
ITransportStatus,
|
|
20
20
|
} from '../types';
|
|
21
|
-
import { getReleaseChangelog, getReleaseStatus } from '../utils/release';
|
|
21
|
+
import { getReleaseChangelog, getReleaseStatus, findLatestRelease } from '../utils/release';
|
|
22
22
|
|
|
23
23
|
export default class DataManager {
|
|
24
24
|
static deviceMap: DeviceTypeMap = {
|
|
@@ -64,6 +64,25 @@ export default class DataManager {
|
|
|
64
64
|
return getReleaseStatus(targetDeviceConfigList, currentVersion);
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Touch、Pro System UI Resource Update
|
|
69
|
+
* ** Interval upgrade is not considered **
|
|
70
|
+
*/
|
|
71
|
+
static getSysResourcesLatestRelease = (features: Features) => {
|
|
72
|
+
const deviceType = getDeviceType(features);
|
|
73
|
+
const deviceFirmwareVersion = getDeviceFirmwareVersion(features);
|
|
74
|
+
|
|
75
|
+
if (deviceType !== 'pro' && deviceType !== 'touch') return undefined;
|
|
76
|
+
|
|
77
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.firmware ?? [];
|
|
78
|
+
const currentVersion = deviceFirmwareVersion.join('.');
|
|
79
|
+
const targetDeviceConfig = targetDeviceConfigList.filter(
|
|
80
|
+
item => semver.gt(item.version.join('.'), currentVersion) && !!item.resource
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
return findLatestRelease(targetDeviceConfig)?.resource;
|
|
84
|
+
};
|
|
85
|
+
|
|
67
86
|
static getFirmwareChangelog = (features: Features) => {
|
|
68
87
|
const deviceType = getDeviceType(features);
|
|
69
88
|
const deviceFirmwareVersion = getDeviceFirmwareVersion(features);
|
|
@@ -80,10 +99,21 @@ export default class DataManager {
|
|
|
80
99
|
return getReleaseChangelog(targetDeviceConfigList, currentVersion);
|
|
81
100
|
};
|
|
82
101
|
|
|
83
|
-
static
|
|
102
|
+
static getFirmwareLatestRelease = (features: Features) => {
|
|
84
103
|
const deviceType = getDeviceType(features);
|
|
85
104
|
const targetDeviceConfigList = this.deviceMap[deviceType]?.firmware ?? [];
|
|
86
|
-
|
|
105
|
+
|
|
106
|
+
const target = findLatestRelease(targetDeviceConfigList);
|
|
107
|
+
if (!target) return target;
|
|
108
|
+
|
|
109
|
+
if (!target.resource) {
|
|
110
|
+
const resource = this.getSysResourcesLatestRelease(features);
|
|
111
|
+
return {
|
|
112
|
+
...target,
|
|
113
|
+
resource,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return target;
|
|
87
117
|
};
|
|
88
118
|
|
|
89
119
|
static getBLEFirmwareStatus = (features: Features): IDeviceBLEFirmwareStatus => {
|
|
@@ -113,10 +143,10 @@ export default class DataManager {
|
|
|
113
143
|
return getReleaseChangelog(targetDeviceConfigList, currentVersion);
|
|
114
144
|
};
|
|
115
145
|
|
|
116
|
-
static
|
|
146
|
+
static getBleFirmwareLatestRelease = (features: Features) => {
|
|
117
147
|
const deviceType = getDeviceType(features);
|
|
118
148
|
const targetDeviceConfigList = this.deviceMap[deviceType]?.ble ?? [];
|
|
119
|
-
return targetDeviceConfigList
|
|
149
|
+
return findLatestRelease(targetDeviceConfigList);
|
|
120
150
|
};
|
|
121
151
|
|
|
122
152
|
static getTransportStatus = (localVersion: string): ITransportStatus => {
|
package/src/device/Device.ts
CHANGED
|
@@ -251,6 +251,13 @@ export class Device extends EventEmitter {
|
|
|
251
251
|
return this.commands;
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
private generateStateKey(deviceId: string, passphraseState?: string) {
|
|
255
|
+
if (passphraseState) {
|
|
256
|
+
return `${deviceId}@${passphraseState}`;
|
|
257
|
+
}
|
|
258
|
+
return deviceId;
|
|
259
|
+
}
|
|
260
|
+
|
|
254
261
|
getInternalState(_deviceId?: string) {
|
|
255
262
|
Log.debug(
|
|
256
263
|
'getInternalState session param: ',
|
|
@@ -264,19 +271,27 @@ export class Device extends EventEmitter {
|
|
|
264
271
|
if (!deviceId) return undefined;
|
|
265
272
|
if (!this.passphraseState) return undefined;
|
|
266
273
|
|
|
267
|
-
const usePassKey =
|
|
274
|
+
const usePassKey = this.generateStateKey(deviceId, this.passphraseState);
|
|
275
|
+
return deviceSessionCache[usePassKey];
|
|
276
|
+
}
|
|
268
277
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
278
|
+
tryFixInternalState(state: string, deviceId: string) {
|
|
279
|
+
Log.debug(
|
|
280
|
+
'tryFixInternalState session param: ',
|
|
281
|
+
`device_id: ${deviceId}`,
|
|
282
|
+
`passphraseState: ${state}`
|
|
283
|
+
);
|
|
275
284
|
|
|
276
|
-
|
|
285
|
+
const key = `${deviceId}`;
|
|
286
|
+
const session = deviceSessionCache[key];
|
|
287
|
+
if (session) {
|
|
288
|
+
deviceSessionCache[this.generateStateKey(deviceId, state)] = session;
|
|
289
|
+
delete deviceSessionCache[key];
|
|
290
|
+
}
|
|
291
|
+
Log.debug('tryFixInternalState session cache: ', deviceSessionCache);
|
|
277
292
|
}
|
|
278
293
|
|
|
279
|
-
setInternalState(state: string, initSession?: boolean) {
|
|
294
|
+
private setInternalState(state: string, initSession?: boolean) {
|
|
280
295
|
Log.debug(
|
|
281
296
|
'setInternalState session param: ',
|
|
282
297
|
`state: ${state}`,
|
|
@@ -288,10 +303,11 @@ export class Device extends EventEmitter {
|
|
|
288
303
|
if (!this.features) return;
|
|
289
304
|
if (!this.passphraseState && !initSession) return;
|
|
290
305
|
|
|
291
|
-
|
|
292
|
-
if (
|
|
293
|
-
|
|
294
|
-
|
|
306
|
+
const deviceId = this.features?.device_id;
|
|
307
|
+
if (!deviceId) return;
|
|
308
|
+
|
|
309
|
+
const key = this.generateStateKey(deviceId, this.passphraseState);
|
|
310
|
+
|
|
295
311
|
if (state) {
|
|
296
312
|
deviceSessionCache[key] = state;
|
|
297
313
|
}
|
|
@@ -307,7 +323,7 @@ export class Device extends EventEmitter {
|
|
|
307
323
|
delete deviceSessionCache[key];
|
|
308
324
|
|
|
309
325
|
if (this.passphraseState) {
|
|
310
|
-
const usePassKey =
|
|
326
|
+
const usePassKey = this.generateStateKey(deviceId, this.passphraseState);
|
|
311
327
|
delete deviceSessionCache[usePassKey];
|
|
312
328
|
}
|
|
313
329
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Transport, Messages } from '@onekeyfe/hd-transport';
|
|
1
|
+
import type { Transport, Messages, FailureType } from '@onekeyfe/hd-transport';
|
|
2
2
|
import { ERRORS, HardwareError, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
3
3
|
import TransportManager from '../data-manager/TransportManager';
|
|
4
4
|
import DataManager from '../data-manager/DataManager';
|
|
@@ -146,7 +146,10 @@ export class DeviceCommands {
|
|
|
146
146
|
): Promise<DefaultMessageResponse> {
|
|
147
147
|
Log.debug('_filterCommonTypes: ', res);
|
|
148
148
|
if (res.type === 'Failure') {
|
|
149
|
-
const { code, message } = res.message
|
|
149
|
+
const { code, message } = res.message as {
|
|
150
|
+
code?: string | FailureType;
|
|
151
|
+
message?: string;
|
|
152
|
+
};
|
|
150
153
|
let error: HardwareError | null = null;
|
|
151
154
|
// Model One does not send any message in firmware update
|
|
152
155
|
if (code === 'Failure_FirmwareError' && !message) {
|
package/src/events/ui-request.ts
CHANGED
|
@@ -19,6 +19,7 @@ export const UI_REQUEST = {
|
|
|
19
19
|
LOCATION_SERVICE_PERMISSION: 'ui-location_service_permission',
|
|
20
20
|
|
|
21
21
|
FIRMWARE_PROGRESS: 'ui-firmware-progress',
|
|
22
|
+
FIRMWARE_TIP: 'ui-firmware-tip',
|
|
22
23
|
|
|
23
24
|
NOT_IN_BOOTLOADER: 'ui-device_not_in_bootloader_mode',
|
|
24
25
|
} as const;
|
|
@@ -69,13 +70,22 @@ export interface FirmwareProgress {
|
|
|
69
70
|
};
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
export interface FirmwareTip {
|
|
74
|
+
type: typeof UI_REQUEST.FIRMWARE_TIP;
|
|
75
|
+
payload: {
|
|
76
|
+
device: Device;
|
|
77
|
+
data: { message: string };
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
72
81
|
export type UiEvent =
|
|
73
82
|
| UiRequestWithoutPayload
|
|
74
83
|
| UiRequestDeviceAction
|
|
75
84
|
| UiRequestButton
|
|
76
85
|
| UiRequestPassphraseOnDevice
|
|
86
|
+
| UiRequestPassphrase
|
|
77
87
|
| FirmwareProgress
|
|
78
|
-
|
|
|
88
|
+
| FirmwareTip;
|
|
79
89
|
|
|
80
90
|
export type UiEventMessage = UiEvent & { event: typeof UI_EVENT };
|
|
81
91
|
|
package/src/inject.ts
CHANGED
|
@@ -53,12 +53,6 @@ export const inject = ({
|
|
|
53
53
|
*/
|
|
54
54
|
getFeatures: connectId => call({ connectId, method: 'getFeatures' }),
|
|
55
55
|
|
|
56
|
-
/**
|
|
57
|
-
* 批量获取公钥
|
|
58
|
-
*/
|
|
59
|
-
batchGetPublicKey: (connectId, deviceId, params) =>
|
|
60
|
-
call({ ...params, connectId, deviceId, method: 'batchGetPublicKey' }),
|
|
61
|
-
|
|
62
56
|
/**
|
|
63
57
|
* 检查固件版本
|
|
64
58
|
*/
|
|
@@ -91,6 +85,8 @@ export const inject = ({
|
|
|
91
85
|
deviceReset: (connectId, params) => call({ ...params, connectId, method: 'deviceReset' }),
|
|
92
86
|
deviceSettings: (connectId, params) => call({ ...params, connectId, method: 'deviceSettings' }),
|
|
93
87
|
deviceUpdateReboot: connectId => call({ connectId, method: 'deviceUpdateReboot' }),
|
|
88
|
+
deviceUploadResource: (connectId, params) =>
|
|
89
|
+
call({ ...params, connectId, method: 'deviceUploadResource' }),
|
|
94
90
|
deviceSupportFeatures: connectId => call({ connectId, method: 'deviceSupportFeatures' }),
|
|
95
91
|
deviceVerify: (connectId, params) => call({ ...params, connectId, method: 'deviceVerify' }),
|
|
96
92
|
deviceWipe: connectId => call({ connectId, method: 'deviceWipe' }),
|
|
@@ -150,6 +146,8 @@ export const inject = ({
|
|
|
150
146
|
call({ ...params, connectId, deviceId, method: 'stellarSignTransaction' }),
|
|
151
147
|
|
|
152
148
|
firmwareUpdate: (connectId, params) => call({ ...params, connectId, method: 'firmwareUpdate' }),
|
|
149
|
+
firmwareUpdateV2: (connectId, params) =>
|
|
150
|
+
call({ ...params, connectId, method: 'firmwareUpdateV2' }),
|
|
153
151
|
requestWebUsbDevice: () => call({ method: 'requestWebUsbDevice' }),
|
|
154
152
|
|
|
155
153
|
tronGetAddress: (connectId, deviceId, params) =>
|
|
@@ -175,6 +173,8 @@ export const inject = ({
|
|
|
175
173
|
|
|
176
174
|
aptosGetAddress: (connectId, deviceId, params) =>
|
|
177
175
|
call({ ...params, connectId, deviceId, method: 'aptosGetAddress' }),
|
|
176
|
+
aptosGetPublicKey: (connectId, deviceId, params) =>
|
|
177
|
+
call({ ...params, connectId, deviceId, method: 'aptosGetPublicKey' }),
|
|
178
178
|
aptosSignTransaction: (connectId, deviceId, params) =>
|
|
179
179
|
call({ ...params, connectId, deviceId, method: 'aptosSignTransaction' }),
|
|
180
180
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CommonParams, Response } from '../params';
|
|
2
|
+
|
|
3
|
+
export type AptosPublicKey = {
|
|
4
|
+
path: string;
|
|
5
|
+
publicKey: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type AptosGetPublicKeyParams = {
|
|
9
|
+
path: string | number[];
|
|
10
|
+
showOnOneKey?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export declare function aptosGetPublicKey(
|
|
14
|
+
connectId: string,
|
|
15
|
+
deviceId: string,
|
|
16
|
+
params: CommonParams & AptosGetPublicKeyParams
|
|
17
|
+
): Response<AptosPublicKey>;
|
|
18
|
+
|
|
19
|
+
export declare function aptosGetPublicKey(
|
|
20
|
+
connectId: string,
|
|
21
|
+
deviceId: string,
|
|
22
|
+
params: CommonParams & { bundle?: AptosGetPublicKeyParams[] }
|
|
23
|
+
): Response<Array<AptosPublicKey>>;
|