@onekeyfe/hd-core 1.2.8-alpha.128 → 1.2.8-alpha.129
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/__tests__/device-lifecycle-events.test.ts +96 -0
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +11 -0
- package/__tests__/protocol-v2-resources.test.ts +14 -0
- package/__tests__/protocol-v2.test.ts +306 -14
- package/__tests__/protocolV2FileWrite.test.ts +434 -7
- package/dist/api/FileWrite.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +0 -1
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +5 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/device/Device.d.ts +1 -0
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +1 -0
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +616 -382
- package/dist/protocols/protocol-v2/resources.d.ts +1 -0
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FileWrite.ts +7 -1
- package/src/api/FirmwareUpdateV4.ts +56 -30
- package/src/api/firmware/FirmwareArtifactSource.ts +12 -3
- package/src/api/helpers/protocolV2FileWrite.ts +375 -111
- package/src/api/protocol-v2/DeviceUploadNft.ts +6 -1
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +15 -1
- package/src/device/Device.ts +18 -2
- package/src/events/ui-request.ts +1 -0
- package/src/protocols/protocol-v2/resources.ts +6 -1
package/src/device/Device.ts
CHANGED
|
@@ -236,6 +236,9 @@ export class Device extends EventEmitter {
|
|
|
236
236
|
*/
|
|
237
237
|
private deviceAcquired = false;
|
|
238
238
|
|
|
239
|
+
/** A completed BLE release left the physical link available for the next call. */
|
|
240
|
+
private releasedBleConnection = false;
|
|
241
|
+
|
|
239
242
|
/**
|
|
240
243
|
* Connection-attempt generation. interruptionFromUser() pins the current
|
|
241
244
|
* attempt so a late acquire cannot finish, while the next public connect
|
|
@@ -452,6 +455,7 @@ export class Device extends EventEmitter {
|
|
|
452
455
|
) {
|
|
453
456
|
const attempt = this.connectionAttempt;
|
|
454
457
|
this.throwIfInterruptedByUser();
|
|
458
|
+
this.releasedBleConnection = false;
|
|
455
459
|
const env = DataManager.getSettings('env');
|
|
456
460
|
const mainIdKey = DataManager.isBleConnect(env) ? 'id' : 'session';
|
|
457
461
|
const previousProtocol = this.originalDescriptor.protocolType;
|
|
@@ -562,6 +566,7 @@ export class Device extends EventEmitter {
|
|
|
562
566
|
(this.isUsedHere() && !this.keepSession && this.mainId) ||
|
|
563
567
|
(this.mainId && DataManager.isBleConnect(env))
|
|
564
568
|
) {
|
|
569
|
+
this.releasedBleConnection = false;
|
|
565
570
|
// wait for callback tasks to complete before releasing device
|
|
566
571
|
if (this.pendingCallbackPromise) {
|
|
567
572
|
try {
|
|
@@ -585,8 +590,18 @@ export class Device extends EventEmitter {
|
|
|
585
590
|
}
|
|
586
591
|
}
|
|
587
592
|
try {
|
|
593
|
+
const deviceType = this.getCurrentDeviceType();
|
|
594
|
+
const keepBleConnection =
|
|
595
|
+
(env === 'react-native' || env === 'desktop-web-ble') &&
|
|
596
|
+
this.isProtocolV2() &&
|
|
597
|
+
(deviceType === EDeviceType.Pro2 || deviceType === EDeviceType.Neo);
|
|
588
598
|
// BLE releases even when keepSession is set, so forward the intent.
|
|
589
|
-
await this.deviceConnector?.release(
|
|
599
|
+
await this.deviceConnector?.release(
|
|
600
|
+
this.mainId,
|
|
601
|
+
false,
|
|
602
|
+
this.keepSession || keepBleConnection
|
|
603
|
+
);
|
|
604
|
+
this.releasedBleConnection = keepBleConnection;
|
|
590
605
|
} catch (err) {
|
|
591
606
|
Log.error('[Device] release error: ', err);
|
|
592
607
|
} finally {
|
|
@@ -1371,6 +1386,7 @@ export class Device extends EventEmitter {
|
|
|
1371
1386
|
|
|
1372
1387
|
markTransportDisconnected() {
|
|
1373
1388
|
this.deviceAcquired = false;
|
|
1389
|
+
this.releasedBleConnection = false;
|
|
1374
1390
|
this.invalidateProtocolV2RuntimeState();
|
|
1375
1391
|
}
|
|
1376
1392
|
|
|
@@ -1633,7 +1649,7 @@ export class Device extends EventEmitter {
|
|
|
1633
1649
|
await commands?.cancelDevice?.().catch(cancelError => {
|
|
1634
1650
|
Log.debug('Protocol V2 fallback cancel error', cancelError);
|
|
1635
1651
|
});
|
|
1636
|
-
} else if (!acquired) {
|
|
1652
|
+
} else if (!acquired && !this.releasedBleConnection) {
|
|
1637
1653
|
// Abort setup without acquiring a session just to send Cancel.
|
|
1638
1654
|
if (mainId && deviceConnector?.disconnect) {
|
|
1639
1655
|
// The connector drops the link silently, so without this line a
|
package/src/events/ui-request.ts
CHANGED
|
@@ -7,6 +7,8 @@ export const PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH =
|
|
|
7
7
|
export const PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH = `${PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH}.staging`;
|
|
8
8
|
export const PROTOCOL_V2_ROM_PARAMS_PACKAGE_PATH = 'vol0:/loaders/rom/params.okpkg';
|
|
9
9
|
export const PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE = 0x5f90;
|
|
10
|
+
// Installed-package comparison only needs the prefix through the header hash.
|
|
11
|
+
export const PROTOCOL_V2_RESOURCE_PACKAGE_COMPARE_SIZE = 0x280;
|
|
10
12
|
|
|
11
13
|
const PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_VERSION = 1;
|
|
12
14
|
const PROTOCOL_V2_RESOURCE_PACKAGE_FLEXIBLE_OFFSET = 0x6c;
|
|
@@ -123,7 +125,7 @@ export function parseProtocolV2ResourcePackageHeader(
|
|
|
123
125
|
bytes: Uint8Array,
|
|
124
126
|
packageSize: number
|
|
125
127
|
): ProtocolV2ResourcePackageHeader {
|
|
126
|
-
if (bytes.byteLength <
|
|
128
|
+
if (bytes.byteLength < PROTOCOL_V2_RESOURCE_PACKAGE_COMPARE_SIZE) {
|
|
127
129
|
throw new Error('Pro2 RESOURCE package is shorter than its header');
|
|
128
130
|
}
|
|
129
131
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
@@ -169,5 +171,8 @@ export function parseProtocolV2ResourcePackage(
|
|
|
169
171
|
binary: ArrayBuffer | Uint8Array
|
|
170
172
|
): ProtocolV2ResourcePackageHeader {
|
|
171
173
|
const bytes = binary instanceof Uint8Array ? binary : new Uint8Array(binary);
|
|
174
|
+
if (bytes.byteLength < PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE) {
|
|
175
|
+
throw new Error('Pro2 RESOURCE package is shorter than its header');
|
|
176
|
+
}
|
|
172
177
|
return parseProtocolV2ResourcePackageHeader(bytes, bytes.byteLength);
|
|
173
178
|
}
|