@onekeyfe/hd-core 1.2.0-alpha.113 → 1.2.0-alpha.114
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,7 +1,6 @@
|
|
|
1
1
|
import * as hdShared from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import FirmwareUpdateV3 from '../../src/api/FirmwareUpdateV3';
|
|
4
|
-
import { DataManager } from '../../src/data-manager';
|
|
5
4
|
import { DevicePool } from '../../src/device/DevicePool';
|
|
6
5
|
|
|
7
6
|
import type { Device } from '../../src/device/Device';
|
|
@@ -113,125 +112,10 @@ describe('FirmwareUpdateV3 reconnect', () => {
|
|
|
113
112
|
})
|
|
114
113
|
).rejects.toBe(reconnectError);
|
|
115
114
|
|
|
116
|
-
expect(commands.typedCall).toHaveBeenCalledWith('GetFeatures', 'Features', {});
|
|
117
115
|
expect(waitForDeviceReconnect).toHaveBeenCalledWith(3 * 60 * 1000);
|
|
118
116
|
} finally {
|
|
119
117
|
jest.clearAllTimers();
|
|
120
118
|
jest.useRealTimers();
|
|
121
119
|
}
|
|
122
120
|
});
|
|
123
|
-
|
|
124
|
-
it('lets Browser WebUSB clean up a timed out install probe before reconnecting', async () => {
|
|
125
|
-
jest.spyOn(hdShared, 'wait').mockResolvedValue(undefined);
|
|
126
|
-
jest.spyOn(DataManager, 'getSettings').mockReturnValue('webusb' as never);
|
|
127
|
-
jest.spyOn(DataManager, 'isBrowserWebUsb').mockReturnValue(true);
|
|
128
|
-
const method = new FirmwareUpdateV3({
|
|
129
|
-
id: 1,
|
|
130
|
-
payload: {
|
|
131
|
-
method: 'firmwareUpdateV3',
|
|
132
|
-
connectId: 'webusb-device',
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
const reconnectError = new Error('stop after WebUSB reconnect assertion');
|
|
136
|
-
const waitForDeviceReconnect = jest
|
|
137
|
-
.spyOn(method, 'waitForDeviceReconnect')
|
|
138
|
-
.mockRejectedValue(reconnectError);
|
|
139
|
-
method.isBleReconnect = jest.fn(() => false);
|
|
140
|
-
method.params = {
|
|
141
|
-
platform: 'web',
|
|
142
|
-
} as any;
|
|
143
|
-
const commands = {
|
|
144
|
-
typedCall: jest.fn().mockRejectedValue(new Error('Protocol V1 read timeout after 3000ms')),
|
|
145
|
-
};
|
|
146
|
-
method.device = {
|
|
147
|
-
features: {},
|
|
148
|
-
getCommands: () => commands,
|
|
149
|
-
} as unknown as Device;
|
|
150
|
-
(method as any).createUpdatesFolderIfNotExists = jest.fn().mockResolvedValue(undefined);
|
|
151
|
-
(method as any).startEmmcFirmwareUpdate = jest.fn().mockResolvedValue(undefined);
|
|
152
|
-
method.postTipMessage = jest.fn();
|
|
153
|
-
method.postProcessingMessage = jest.fn();
|
|
154
|
-
method.postProgressMessage = jest.fn();
|
|
155
|
-
|
|
156
|
-
await expect(
|
|
157
|
-
(method as any).executeUpdate({
|
|
158
|
-
resourceBinary: null,
|
|
159
|
-
resourceEntries: [],
|
|
160
|
-
fwSources: [],
|
|
161
|
-
bootloaderSource: null,
|
|
162
|
-
})
|
|
163
|
-
).rejects.toBe(reconnectError);
|
|
164
|
-
|
|
165
|
-
expect(commands.typedCall).toHaveBeenCalledWith(
|
|
166
|
-
'GetFeatures',
|
|
167
|
-
'Features',
|
|
168
|
-
{},
|
|
169
|
-
{
|
|
170
|
-
timeoutMs: 3000,
|
|
171
|
-
}
|
|
172
|
-
);
|
|
173
|
-
expect(waitForDeviceReconnect).toHaveBeenCalledWith(60 * 1000);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('does not treat cached firmware versions as Browser WebUSB install completion', async () => {
|
|
177
|
-
jest.spyOn(hdShared, 'wait').mockResolvedValue(undefined);
|
|
178
|
-
jest.spyOn(DataManager, 'getSettings').mockReturnValue('webusb' as never);
|
|
179
|
-
jest.spyOn(DataManager, 'isBrowserWebUsb').mockReturnValue(true);
|
|
180
|
-
const method = new FirmwareUpdateV3({
|
|
181
|
-
id: 1,
|
|
182
|
-
payload: {
|
|
183
|
-
method: 'firmwareUpdateV3',
|
|
184
|
-
connectId: 'webusb-device',
|
|
185
|
-
},
|
|
186
|
-
});
|
|
187
|
-
method.params = {
|
|
188
|
-
platform: 'web',
|
|
189
|
-
} as any;
|
|
190
|
-
const commands = {
|
|
191
|
-
typedCall: jest
|
|
192
|
-
.fn()
|
|
193
|
-
.mockResolvedValueOnce({
|
|
194
|
-
type: 'Features',
|
|
195
|
-
message: {
|
|
196
|
-
major_version: 0,
|
|
197
|
-
minor_version: 0,
|
|
198
|
-
patch_version: 0,
|
|
199
|
-
},
|
|
200
|
-
})
|
|
201
|
-
.mockResolvedValueOnce({
|
|
202
|
-
type: 'Features',
|
|
203
|
-
message: {
|
|
204
|
-
major_version: 4,
|
|
205
|
-
minor_version: 21,
|
|
206
|
-
patch_version: 0,
|
|
207
|
-
onekey_ble_version: '2.3.7',
|
|
208
|
-
},
|
|
209
|
-
}),
|
|
210
|
-
};
|
|
211
|
-
method.device = {
|
|
212
|
-
features: {
|
|
213
|
-
firmwareVersion: '4.21.0',
|
|
214
|
-
bleVersion: '2.3.7',
|
|
215
|
-
},
|
|
216
|
-
getCommands: () => commands,
|
|
217
|
-
} as unknown as Device;
|
|
218
|
-
(method as any).createUpdatesFolderIfNotExists = jest.fn().mockResolvedValue(undefined);
|
|
219
|
-
(method as any).startEmmcFirmwareUpdate = jest.fn().mockResolvedValue(undefined);
|
|
220
|
-
method.postTipMessage = jest.fn();
|
|
221
|
-
method.postProcessingMessage = jest.fn();
|
|
222
|
-
method.postProgressMessage = jest.fn();
|
|
223
|
-
|
|
224
|
-
const result = await (method as any).executeUpdate({
|
|
225
|
-
resourceBinary: null,
|
|
226
|
-
resourceEntries: [],
|
|
227
|
-
fwSources: [],
|
|
228
|
-
bootloaderSource: null,
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
expect(commands.typedCall).toHaveBeenCalledTimes(2);
|
|
232
|
-
expect(result).toMatchObject({
|
|
233
|
-
firmwareVersion: '4.21.0',
|
|
234
|
-
bleVersion: '2.3.7',
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
121
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FirmwareUpdateV3.d.ts","sourceRoot":"","sources":["../../src/api/FirmwareUpdateV3.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAc/E,OAAO,KAAK,EAEV,sBAAsB,EACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAiB,MAAM,qBAAqB,CAAC;AAMnE,eAAO,MAAM,gCAAgC,UAAU,CAAC;AAaxD,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,wBAAwB,CAAC,sBAAsB,CAAC;IAC5F,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAE1C,OAAO,CAAC,gBAAgB,CAAS;IAEjC,OAAO,CAAC,eAAe,CAA4B;IAEnD,IAAI;IA8HE,GAAG;;;;;YAQK,aAAa;IA6D3B,OAAO,CAAC,wBAAwB;YAiBlB,kBAAkB;YAelB,oBAAoB;IAKlC,OAAO,CAAC,wBAAwB;YAgBlB,oBAAoB;YA2DpB,uBAAuB;YAuBvB,4BAA4B;YA+E5B,aAAa;
|
|
1
|
+
{"version":3,"file":"FirmwareUpdateV3.d.ts","sourceRoot":"","sources":["../../src/api/FirmwareUpdateV3.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAc/E,OAAO,KAAK,EAEV,sBAAsB,EACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAiB,MAAM,qBAAqB,CAAC;AAMnE,eAAO,MAAM,gCAAgC,UAAU,CAAC;AAaxD,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,wBAAwB,CAAC,sBAAsB,CAAC;IAC5F,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAE1C,OAAO,CAAC,gBAAgB,CAAS;IAEjC,OAAO,CAAC,eAAe,CAA4B;IAEnD,IAAI;IA8HE,GAAG;;;;;YAQK,aAAa;IA6D3B,OAAO,CAAC,wBAAwB;YAiBlB,kBAAkB;YAelB,oBAAoB;IAKlC,OAAO,CAAC,wBAAwB;YAgBlB,oBAAoB;YA2DpB,uBAAuB;YAuBvB,4BAA4B;YA+E5B,aAAa;IAyN3B,OAAO,CAAC,yBAAyB;IAajC,OAAO,CAAC,yBAAyB;IAQjC,OAAO,CAAC,qBAAqB;IAmB7B,OAAO,CAAC,sCAAsC;IAexC,sBAAsB,CAAC,OAAO,EAAE,MAAM;CA+E7C"}
|
package/dist/index.js
CHANGED
|
@@ -51318,27 +51318,18 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
51318
51318
|
try {
|
|
51319
51319
|
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
51320
51320
|
const timeoutMs = 3000;
|
|
51321
|
-
const
|
|
51322
|
-
|
|
51323
|
-
|
|
51324
|
-
|
|
51325
|
-
|
|
51326
|
-
|
|
51327
|
-
: yield Promise.race([
|
|
51328
|
-
getFeaturesPromise,
|
|
51329
|
-
new Promise((_, reject) => {
|
|
51330
|
-
setTimeout(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNotResponse, 'GetFeatures timeout', { method: 'GetFeatures', timeoutMs })), timeoutMs);
|
|
51331
|
-
}),
|
|
51332
|
-
]);
|
|
51321
|
+
const featuresRes = yield Promise.race([
|
|
51322
|
+
typedCall('GetFeatures', 'Features', {}),
|
|
51323
|
+
new Promise((_, reject) => {
|
|
51324
|
+
setTimeout(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNotResponse, 'GetFeatures timeout', { method: 'GetFeatures', timeoutMs })), timeoutMs);
|
|
51325
|
+
}),
|
|
51326
|
+
]);
|
|
51333
51327
|
getFeaturesTimeoutCount = 0;
|
|
51334
51328
|
const features = buildProtocolV1FeaturesPayload(featuresRes.message, this.device.features);
|
|
51335
51329
|
const bootloaderVersion = getDeviceBootloaderVersion(features).join('.');
|
|
51336
51330
|
const bleVersion = getDeviceBLEFirmwareVersion(features).join('.');
|
|
51337
51331
|
const firmwareVersion = getDeviceFirmwareVersion(features).join('.');
|
|
51338
|
-
|
|
51339
|
-
? getDeviceFirmwareVersion(featuresRes.message).join('.')
|
|
51340
|
-
: firmwareVersion;
|
|
51341
|
-
if (completionFirmwareVersion !== '0.0.0') {
|
|
51332
|
+
if (firmwareVersion !== '0.0.0') {
|
|
51342
51333
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.FirmwareUpdateCompleted);
|
|
51343
51334
|
DevicePool.resetState();
|
|
51344
51335
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.114",
|
|
4
4
|
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.114",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.114",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"buffer": "^6.0.3",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/w3c-web-usb": "^1.0.10",
|
|
47
47
|
"@types/web-bluetooth": "^0.0.21"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "7035991e1c0237e375dec03e5b9d99f45d4aa550"
|
|
50
50
|
}
|
|
@@ -609,40 +609,29 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
609
609
|
try {
|
|
610
610
|
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
611
611
|
const timeoutMs = 3000;
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
{ method: 'GetFeatures', timeoutMs }
|
|
629
|
-
)
|
|
630
|
-
),
|
|
631
|
-
timeoutMs
|
|
632
|
-
);
|
|
633
|
-
}),
|
|
634
|
-
]);
|
|
612
|
+
const featuresRes = await Promise.race<TypedResponseMessage<'Features'>>([
|
|
613
|
+
typedCall('GetFeatures', 'Features', {}),
|
|
614
|
+
new Promise<never>((_, reject) => {
|
|
615
|
+
setTimeout(
|
|
616
|
+
() =>
|
|
617
|
+
reject(
|
|
618
|
+
ERRORS.TypedError(
|
|
619
|
+
HardwareErrorCode.CallMethodNotResponse,
|
|
620
|
+
'GetFeatures timeout',
|
|
621
|
+
{ method: 'GetFeatures', timeoutMs }
|
|
622
|
+
)
|
|
623
|
+
),
|
|
624
|
+
timeoutMs
|
|
625
|
+
);
|
|
626
|
+
}),
|
|
627
|
+
]);
|
|
635
628
|
getFeaturesTimeoutCount = 0;
|
|
636
629
|
const features = buildProtocolV1FeaturesPayload(featuresRes.message, this.device.features);
|
|
637
630
|
const bootloaderVersion = getDeviceBootloaderVersion(features).join('.');
|
|
638
631
|
const bleVersion = getDeviceBLEFirmwareVersion(features).join('.');
|
|
639
632
|
const firmwareVersion = getDeviceFirmwareVersion(features).join('.');
|
|
640
|
-
//
|
|
641
|
-
|
|
642
|
-
const completionFirmwareVersion = isBrowserWebUsb
|
|
643
|
-
? getDeviceFirmwareVersion(featuresRes.message).join('.')
|
|
644
|
-
: firmwareVersion;
|
|
645
|
-
if (completionFirmwareVersion !== '0.0.0') {
|
|
633
|
+
// Treat update as complete once firmware version becomes non-zero
|
|
634
|
+
if (firmwareVersion !== '0.0.0') {
|
|
646
635
|
this.postTipMessage(FirmwareUpdateTipMessage.FirmwareUpdateCompleted);
|
|
647
636
|
DevicePool.resetState();
|
|
648
637
|
return {
|
|
@@ -651,6 +640,7 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
651
640
|
firmwareVersion,
|
|
652
641
|
};
|
|
653
642
|
}
|
|
643
|
+
// Still in update mode; continue polling (e.g., iOS may return firmwareVersion 0.0.0 during switches)
|
|
654
644
|
await wait(1000);
|
|
655
645
|
} catch (error) {
|
|
656
646
|
Log.log('getFeatures error', error);
|