@onekeyfe/hd-core 0.3.5-alpha.0 → 0.3.6
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploadFirmware.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/uploadFirmware.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAU,WAAW,EAA+B,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAwB,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"uploadFirmware.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/uploadFirmware.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAU,WAAW,EAA+B,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAwB,MAAM,6BAA6B,CAAC;AA6CnF,eAAO,MAAM,cAAc,eAAsB,MAAM,kBAKtD,CAAC;AAEF,eAAO,MAAM,cAAc,eACb,UAAU,GAAG,KAAK,aACnB,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM,eACD,MAAM,cAAc,kEAqElC,CAAC;AAuJF,eAAO,MAAM,cAAc,cAAqB,SAAS,YAAY,MAAM,QAAQ,WAAW,qBAY7F,CAAC;AAEF,eAAO,MAAM,eAAe,cACf,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM,UACN,WAAW,qBAwBpB,CAAC;AAEF,eA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AC,aAAa,EAAE,OAAO;IAU9B,IAAI,CACR,IAAI,EAAE,UAAU,EAChB,GAAG,GAAE,sBAAsB,CAAC,SAAS,CAAM,GAC1C,OAAO,CAAC,sBAAsB,CAAC;IA6BlC,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAAE,EACpD,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,CAAC,EACV,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAE3C,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAClD,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,CAAC,EACV,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAuC7B,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,sBAAsB,CAAC,SAAS,CAAC;IAK3E,kBAAkB,CAChB,GAAG,EAAE,sBAAsB,EAC3B,QAAQ,EAAE,UAAU,GACnB,OAAO,CAAC,sBAAsB,CAAC;IA0HlC,UAAU,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,oBAAoB;IAwB/C,iBAAiB;CA2BlB;AAED,oBAAY,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -12402,7 +12402,7 @@ class DeviceCommands {
|
|
|
12402
12402
|
});
|
|
12403
12403
|
}
|
|
12404
12404
|
call(type, msg = {}) {
|
|
12405
|
-
var _a, _b, _c, _d, _e, _f;
|
|
12405
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
12406
12406
|
return __awaiter(this, void 0, void 0, function* () {
|
|
12407
12407
|
Log$6.debug('[DeviceCommands] [call] Sending', type);
|
|
12408
12408
|
try {
|
|
@@ -12421,7 +12421,12 @@ class DeviceCommands {
|
|
|
12421
12421
|
return { type: 'BridgeNetworkError', message: {} };
|
|
12422
12422
|
}
|
|
12423
12423
|
if (((_f = (_e = (_d = error === null || error === void 0 ? void 0 : error.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.error) === null || _f === void 0 ? void 0 : _f.indexOf('Request failed with status code')) !== -1) {
|
|
12424
|
-
return {
|
|
12424
|
+
return {
|
|
12425
|
+
type: 'CallMethodError',
|
|
12426
|
+
message: {
|
|
12427
|
+
error: (_g = error === null || error === void 0 ? void 0 : error.response.data) !== null && _g !== void 0 ? _g : '',
|
|
12428
|
+
},
|
|
12429
|
+
};
|
|
12425
12430
|
}
|
|
12426
12431
|
throw error;
|
|
12427
12432
|
}
|
|
@@ -13964,6 +13969,7 @@ const getInfo = ({ features, updateType, targetVersion }) => {
|
|
|
13964
13969
|
};
|
|
13965
13970
|
|
|
13966
13971
|
const NEW_BOOT_UPRATE_FIRMWARE_VERSION = '2.4.2';
|
|
13972
|
+
const SESSION_ERROR = 'session not found';
|
|
13967
13973
|
const postConfirmationMessage = (device) => {
|
|
13968
13974
|
var _a;
|
|
13969
13975
|
if ((_a = device.features) === null || _a === void 0 ? void 0 : _a.firmware_present) {
|
|
@@ -14015,7 +14021,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload })
|
|
|
14015
14021
|
if (device.features) {
|
|
14016
14022
|
const bootloaderVersion = getDeviceBootloaderVersion(device.features);
|
|
14017
14023
|
if (semver__default["default"].gte(bootloaderVersion.join('.'), NEW_BOOT_UPRATE_FIRMWARE_VERSION)) {
|
|
14018
|
-
const response = yield newTouchUpdateProcess(updateType,
|
|
14024
|
+
const response = yield newTouchUpdateProcess(updateType, postMessage, device, {
|
|
14019
14025
|
payload,
|
|
14020
14026
|
});
|
|
14021
14027
|
return response.message;
|
|
@@ -14046,10 +14052,13 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload })
|
|
|
14046
14052
|
}
|
|
14047
14053
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown device model');
|
|
14048
14054
|
});
|
|
14049
|
-
const newTouchUpdateProcess = (updateType,
|
|
14055
|
+
const newTouchUpdateProcess = (updateType, postMessage, device, { payload }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14056
|
+
let typedCall = device.getCommands().typedCall.bind(device.getCommands());
|
|
14050
14057
|
postProgressTip(device, 'StartTransferData', postMessage);
|
|
14051
14058
|
const filePath = `0:${updateType === 'ble' ? 'ble-' : ''}firmware.bin`;
|
|
14052
|
-
const
|
|
14059
|
+
const env = DataManager.getSettings('env');
|
|
14060
|
+
const perPackageSize = env === 'react-native' ? 16 : 128;
|
|
14061
|
+
const chunkSize = 1024 * perPackageSize;
|
|
14053
14062
|
const totalChunks = Math.ceil(payload.byteLength / chunkSize);
|
|
14054
14063
|
let offset = 0;
|
|
14055
14064
|
for (let i = 0; i < totalChunks; i++) {
|
|
@@ -14059,15 +14068,14 @@ const newTouchUpdateProcess = (updateType, typedCall, postMessage, device, { pay
|
|
|
14059
14068
|
const chunk = payload.slice(chunkStart, chunkEnd);
|
|
14060
14069
|
const overwrite = i === 0;
|
|
14061
14070
|
const progress = Math.round((i / totalChunks) * 100);
|
|
14062
|
-
const writeRes = yield emmcFileWriteWithRetry(
|
|
14071
|
+
const writeRes = yield emmcFileWriteWithRetry(device, filePath, chunkLength, offset, chunk, overwrite, progress);
|
|
14063
14072
|
offset += writeRes.message.processed_byte;
|
|
14064
14073
|
postProgressMessage(device, progress, postMessage);
|
|
14065
14074
|
}
|
|
14066
14075
|
postConfirmationMessage(device);
|
|
14067
14076
|
postProgressTip(device, 'ConfirmOnDevice', postMessage);
|
|
14068
|
-
|
|
14069
|
-
|
|
14070
|
-
}, 1000);
|
|
14077
|
+
postProgressTip(device, 'InstallingFirmware', postMessage);
|
|
14078
|
+
typedCall = device.getCommands().typedCall.bind(device.getCommands());
|
|
14071
14079
|
const response = yield typedCall('FirmwareUpdateEmmc', 'Success', {
|
|
14072
14080
|
path: filePath,
|
|
14073
14081
|
force_erease: true,
|
|
@@ -14075,8 +14083,11 @@ const newTouchUpdateProcess = (updateType, typedCall, postMessage, device, { pay
|
|
|
14075
14083
|
});
|
|
14076
14084
|
return response;
|
|
14077
14085
|
});
|
|
14078
|
-
const emmcFileWriteWithRetry = (
|
|
14086
|
+
const emmcFileWriteWithRetry = (device, filePath, chunkLength, offset, chunk, overwrite, progress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14087
|
+
var _a, _b, _c, _d, _e, _f;
|
|
14079
14088
|
const writeFunc = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
14089
|
+
var _g;
|
|
14090
|
+
const typedCall = device.getCommands().typedCall.bind(device.getCommands());
|
|
14080
14091
|
const writeRes = yield typedCall('EmmcFileWrite', 'EmmcFile', {
|
|
14081
14092
|
file: {
|
|
14082
14093
|
path: filePath,
|
|
@@ -14089,11 +14100,16 @@ const emmcFileWriteWithRetry = (typedCall, filePath, chunkLength, offset, chunk,
|
|
|
14089
14100
|
ui_percentage: progress,
|
|
14090
14101
|
});
|
|
14091
14102
|
if (writeRes.type !== 'EmmcFile') {
|
|
14103
|
+
if (writeRes.type === 'CallMethodError') {
|
|
14104
|
+
if (((_g = writeRes.message.error) !== null && _g !== void 0 ? _g : '').indexOf(SESSION_ERROR) > -1) {
|
|
14105
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, SESSION_ERROR);
|
|
14106
|
+
}
|
|
14107
|
+
}
|
|
14092
14108
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'emmc file write chunk once error');
|
|
14093
14109
|
}
|
|
14094
14110
|
return writeRes;
|
|
14095
14111
|
});
|
|
14096
|
-
let retryCount =
|
|
14112
|
+
let retryCount = 10;
|
|
14097
14113
|
while (retryCount > 0) {
|
|
14098
14114
|
try {
|
|
14099
14115
|
const result = yield writeFunc();
|
|
@@ -14105,6 +14121,22 @@ const emmcFileWriteWithRetry = (typedCall, filePath, chunkLength, offset, chunk,
|
|
|
14105
14121
|
if (retryCount === 0) {
|
|
14106
14122
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'emmc file write firmware error');
|
|
14107
14123
|
}
|
|
14124
|
+
const env = DataManager.getSettings('env');
|
|
14125
|
+
if (env === 'react-native') {
|
|
14126
|
+
yield wait(3000);
|
|
14127
|
+
yield ((_a = device.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(device.originalDescriptor.id, null, true));
|
|
14128
|
+
yield device.initialize();
|
|
14129
|
+
}
|
|
14130
|
+
else if (error.message.indexOf(SESSION_ERROR) > -1) {
|
|
14131
|
+
const deviceDiff = yield ((_b = device.deviceConnector) === null || _b === void 0 ? void 0 : _b.enumerate());
|
|
14132
|
+
const devicesDescriptor = (_c = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _c !== void 0 ? _c : [];
|
|
14133
|
+
const { deviceList } = yield DevicePool.getDevices(devicesDescriptor, undefined);
|
|
14134
|
+
if (deviceList.length === 1 && ((_e = (_d = deviceList[0]) === null || _d === void 0 ? void 0 : _d.features) === null || _e === void 0 ? void 0 : _e.bootloader_mode)) {
|
|
14135
|
+
device.updateFromCache(deviceList[0]);
|
|
14136
|
+
yield device.acquire();
|
|
14137
|
+
device.getCommands().mainId = (_f = device.mainId) !== null && _f !== void 0 ? _f : '';
|
|
14138
|
+
}
|
|
14139
|
+
}
|
|
14108
14140
|
yield wait(3000);
|
|
14109
14141
|
}
|
|
14110
14142
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@onekeyfe/hd-shared": "^0.3.
|
|
28
|
-
"@onekeyfe/hd-transport": "^0.3.
|
|
27
|
+
"@onekeyfe/hd-shared": "^0.3.6",
|
|
28
|
+
"@onekeyfe/hd-transport": "^0.3.6",
|
|
29
29
|
"axios": "^0.27.2",
|
|
30
30
|
"bignumber.js": "^9.0.2",
|
|
31
31
|
"bytebuffer": "^5.0.1",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"@types/semver": "^7.3.9",
|
|
44
44
|
"ripple-keypairs": "^1.1.4"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "e0ea70bfa9176a2ec88e4391622a99a84c4841ed"
|
|
47
47
|
}
|
|
@@ -11,8 +11,11 @@ import type { TypedCall, TypedResponseMessage } from '../../device/DeviceCommand
|
|
|
11
11
|
import { KnownDevice } from '../../types';
|
|
12
12
|
import { bytesToHex } from '../helpers/hexUtils';
|
|
13
13
|
import { getDeviceBootloaderVersion, getDeviceModel } from '../../utils/deviceFeaturesUtils';
|
|
14
|
+
import { DataManager } from '../../data-manager';
|
|
15
|
+
import { DevicePool } from '../../device/DevicePool';
|
|
14
16
|
|
|
15
17
|
const NEW_BOOT_UPRATE_FIRMWARE_VERSION = '2.4.2';
|
|
18
|
+
const SESSION_ERROR = 'session not found';
|
|
16
19
|
|
|
17
20
|
const postConfirmationMessage = (device: Device) => {
|
|
18
21
|
// only if firmware is already installed. fresh device does not require button confirmation
|
|
@@ -90,7 +93,7 @@ export const uploadFirmware = async (
|
|
|
90
93
|
if (device.features) {
|
|
91
94
|
const bootloaderVersion = getDeviceBootloaderVersion(device.features);
|
|
92
95
|
if (semver.gte(bootloaderVersion.join('.'), NEW_BOOT_UPRATE_FIRMWARE_VERSION)) {
|
|
93
|
-
const response = await newTouchUpdateProcess(updateType,
|
|
96
|
+
const response = await newTouchUpdateProcess(updateType, postMessage, device, {
|
|
94
97
|
payload,
|
|
95
98
|
});
|
|
96
99
|
return response.message;
|
|
@@ -134,15 +137,17 @@ export const uploadFirmware = async (
|
|
|
134
137
|
|
|
135
138
|
const newTouchUpdateProcess = async (
|
|
136
139
|
updateType: 'firmware' | 'ble',
|
|
137
|
-
typedCall: TypedCall,
|
|
138
140
|
postMessage: (message: CoreMessage) => void,
|
|
139
141
|
device: Device,
|
|
140
142
|
{ payload }: PROTO.FirmwareUpload
|
|
141
143
|
) => {
|
|
144
|
+
let typedCall = device.getCommands().typedCall.bind(device.getCommands());
|
|
142
145
|
postProgressTip(device, 'StartTransferData', postMessage);
|
|
143
146
|
// Write File
|
|
144
147
|
const filePath = `0:${updateType === 'ble' ? 'ble-' : ''}firmware.bin`;
|
|
145
|
-
const
|
|
148
|
+
const env = DataManager.getSettings('env');
|
|
149
|
+
const perPackageSize = env === 'react-native' ? 16 : 128;
|
|
150
|
+
const chunkSize = 1024 * perPackageSize;
|
|
146
151
|
const totalChunks = Math.ceil(payload.byteLength / chunkSize);
|
|
147
152
|
let offset = 0;
|
|
148
153
|
for (let i = 0; i < totalChunks; i++) {
|
|
@@ -153,7 +158,7 @@ const newTouchUpdateProcess = async (
|
|
|
153
158
|
const overwrite = i === 0;
|
|
154
159
|
const progress = Math.round((i / totalChunks) * 100);
|
|
155
160
|
const writeRes = await emmcFileWriteWithRetry(
|
|
156
|
-
|
|
161
|
+
device,
|
|
157
162
|
filePath,
|
|
158
163
|
chunkLength,
|
|
159
164
|
offset,
|
|
@@ -168,9 +173,8 @@ const newTouchUpdateProcess = async (
|
|
|
168
173
|
|
|
169
174
|
postConfirmationMessage(device);
|
|
170
175
|
postProgressTip(device, 'ConfirmOnDevice', postMessage);
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}, 1000);
|
|
176
|
+
postProgressTip(device, 'InstallingFirmware', postMessage);
|
|
177
|
+
typedCall = device.getCommands().typedCall.bind(device.getCommands());
|
|
174
178
|
// Firmware Update
|
|
175
179
|
// @ts-expect-error
|
|
176
180
|
const response = await typedCall('FirmwareUpdateEmmc', 'Success', {
|
|
@@ -182,7 +186,7 @@ const newTouchUpdateProcess = async (
|
|
|
182
186
|
};
|
|
183
187
|
|
|
184
188
|
const emmcFileWriteWithRetry = async (
|
|
185
|
-
|
|
189
|
+
device: Device,
|
|
186
190
|
filePath: string,
|
|
187
191
|
chunkLength: number,
|
|
188
192
|
offset: number,
|
|
@@ -191,6 +195,7 @@ const emmcFileWriteWithRetry = async (
|
|
|
191
195
|
progress: number
|
|
192
196
|
) => {
|
|
193
197
|
const writeFunc = async () => {
|
|
198
|
+
const typedCall = device.getCommands().typedCall.bind(device.getCommands());
|
|
194
199
|
// @ts-expect-error
|
|
195
200
|
const writeRes = await typedCall('EmmcFileWrite', 'EmmcFile', {
|
|
196
201
|
file: {
|
|
@@ -204,12 +209,18 @@ const emmcFileWriteWithRetry = async (
|
|
|
204
209
|
ui_percentage: progress,
|
|
205
210
|
});
|
|
206
211
|
if (writeRes.type !== 'EmmcFile') {
|
|
212
|
+
// @ts-expect-error
|
|
213
|
+
if (writeRes.type === 'CallMethodError') {
|
|
214
|
+
if (((writeRes as any).message.error ?? '').indexOf(SESSION_ERROR) > -1) {
|
|
215
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, SESSION_ERROR);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
207
218
|
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'emmc file write chunk once error');
|
|
208
219
|
}
|
|
209
220
|
return writeRes;
|
|
210
221
|
};
|
|
211
222
|
|
|
212
|
-
let retryCount =
|
|
223
|
+
let retryCount = 10;
|
|
213
224
|
while (retryCount > 0) {
|
|
214
225
|
try {
|
|
215
226
|
const result = await writeFunc();
|
|
@@ -220,6 +231,21 @@ const emmcFileWriteWithRetry = async (
|
|
|
220
231
|
if (retryCount === 0) {
|
|
221
232
|
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'emmc file write firmware error');
|
|
222
233
|
}
|
|
234
|
+
const env = DataManager.getSettings('env');
|
|
235
|
+
if (env === 'react-native') {
|
|
236
|
+
await wait(3000);
|
|
237
|
+
await device.deviceConnector?.acquire(device.originalDescriptor.id, null, true);
|
|
238
|
+
await device.initialize();
|
|
239
|
+
} else if (error.message.indexOf(SESSION_ERROR) > -1) {
|
|
240
|
+
const deviceDiff = await device.deviceConnector?.enumerate();
|
|
241
|
+
const devicesDescriptor = deviceDiff?.descriptors ?? [];
|
|
242
|
+
const { deviceList } = await DevicePool.getDevices(devicesDescriptor, undefined);
|
|
243
|
+
if (deviceList.length === 1 && deviceList[0]?.features?.bootloader_mode) {
|
|
244
|
+
device.updateFromCache(deviceList[0]);
|
|
245
|
+
await device.acquire();
|
|
246
|
+
device.getCommands().mainId = device.mainId ?? '';
|
|
247
|
+
}
|
|
248
|
+
}
|
|
223
249
|
await wait(3000);
|
|
224
250
|
}
|
|
225
251
|
}
|
|
@@ -86,7 +86,12 @@ export class DeviceCommands {
|
|
|
86
86
|
return { type: 'BridgeNetworkError', message: {} } as any;
|
|
87
87
|
}
|
|
88
88
|
if (error?.response?.data?.error?.indexOf('Request failed with status code') !== -1) {
|
|
89
|
-
return {
|
|
89
|
+
return {
|
|
90
|
+
type: 'CallMethodError',
|
|
91
|
+
message: {
|
|
92
|
+
error: error?.response.data ?? '',
|
|
93
|
+
},
|
|
94
|
+
} as any;
|
|
90
95
|
}
|
|
91
96
|
throw error;
|
|
92
97
|
}
|