@onekeyfe/hd-transport-web-device 1.2.0-alpha.160 → 1.2.0-alpha.161
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.
|
@@ -500,24 +500,6 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
500
500
|
expect(transport.getProtocolType(device.id)).toBeUndefined();
|
|
501
501
|
});
|
|
502
502
|
|
|
503
|
-
test('fails Protocol V2 acquire immediately when subscribe reports insufficient encryption', async () => {
|
|
504
|
-
const device = { id: 'stale-bond-pro2-id', name: 'OneKey Pro 2' };
|
|
505
|
-
const nobleBle = createNobleBle(device);
|
|
506
|
-
nobleBle.subscribe.mockRejectedValue(new Error('Encryption is insufficient'));
|
|
507
|
-
const transport = configureTransport(nobleBle);
|
|
508
|
-
const probe = jest.spyOn(transport as any, 'probeProtocolV2');
|
|
509
|
-
|
|
510
|
-
await expect(
|
|
511
|
-
transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
|
|
512
|
-
).rejects.toMatchObject({
|
|
513
|
-
errorCode: HardwareErrorCode.BleDeviceBondError,
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
expect(probe).not.toHaveBeenCalled();
|
|
517
|
-
expect(nobleBle.unsubscribe).toHaveBeenCalledWith(device.id);
|
|
518
|
-
expect(nobleBle.disconnect).toHaveBeenCalledWith(device.id);
|
|
519
|
-
});
|
|
520
|
-
|
|
521
503
|
test('reports a stale bond when a previously confirmed Protocol V2 device stops responding', async () => {
|
|
522
504
|
const device = { id: 'reset-pro2-id', name: 'OneKey Pro 2' };
|
|
523
505
|
const nobleBle = createNobleBle(device);
|
|
@@ -41,7 +41,6 @@ export default class ElectronBleTransport {
|
|
|
41
41
|
private hostDisconnectCleanup?;
|
|
42
42
|
private notificationTokens;
|
|
43
43
|
private nextNotificationToken;
|
|
44
|
-
private toStaleBondError;
|
|
45
44
|
private handleBluetoothError;
|
|
46
45
|
private cleanupDeviceState;
|
|
47
46
|
init(logger: any, emitter?: EventEmitter): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"electron-ble-transport.d.ts","sourceRoot":"","sources":["../src/electron-ble-transport.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"electron-ble-transport.d.ts","sourceRoot":"","sources":["../src/electron-ble-transport.ts"],"names":[],"mappings":";AAuBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EAEZ,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAIvC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,CAAC,EAAE,UAAU,CAAC;KACzB;CACF;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,gBAAgB,CAAC,EAAE,YAAY,CAAC;IAChC,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;AAiCF,MAAM,CAAC,OAAO,OAAO,oBAAoB;IACvC,OAAO,CAAC,SAAS,CAA0D;IAE3E,OAAO,CAAC,WAAW,CAA0D;IAE7E,OAAO,CAAC,6BAA6B,CAAqB;IAE1D,IAAI,SAA0B;IAE9B,UAAU,UAAS;IAEnB,UAAU,EAAE,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,GAAG,IAAI,CAAQ;IAExD,OAAO,CAAC,kBAAkB,CAAuB;IAEjD,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;IAEvB,OAAO,CAAC,gBAAgB,CAA0B;IAElD,OAAO,CAAC,cAAc,CAAwC;IAE9D,OAAO,CAAC,mBAAmB,CAAwC;IAGnE,OAAO,CAAC,mBA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oB;IAqB5B,OAAO,CAAC,kBAAkB;IAwB1B,OAAO,CAAC,4BAA4B;IAkBpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,sBAAsB;YAShB,mBAAmB;IAiBjC,OAAO,CAAC,4BAA4B;IAqB9B,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,oBAAoB;IAuB1B,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;YAatD,cAAc;YAqFd,cAAc;IA0B5B,OAAO,CAAC,uBAAuB;IAyC/B,OAAO,CAAC,6BAA6B;IA4CrC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -240,7 +240,6 @@ declare class ElectronBleTransport {
|
|
|
240
240
|
private hostDisconnectCleanup?;
|
|
241
241
|
private notificationTokens;
|
|
242
242
|
private nextNotificationToken;
|
|
243
|
-
private toStaleBondError;
|
|
244
243
|
private handleBluetoothError;
|
|
245
244
|
private cleanupDeviceState;
|
|
246
245
|
init(logger: any, emitter?: EventEmitter): void;
|
package/dist/index.js
CHANGED
|
@@ -852,26 +852,7 @@ class ElectronBleTransport {
|
|
|
852
852
|
this.notificationTokens = new Map();
|
|
853
853
|
this.nextNotificationToken = 1;
|
|
854
854
|
}
|
|
855
|
-
toStaleBondError(error) {
|
|
856
|
-
var _a;
|
|
857
|
-
if (hdShared.isBleStaleBondHardwareError(error)) {
|
|
858
|
-
return error;
|
|
859
|
-
}
|
|
860
|
-
const errorMessage = error && typeof error === 'object' && 'message' in error
|
|
861
|
-
? String((_a = error.message) !== null && _a !== void 0 ? _a : '')
|
|
862
|
-
: String(error !== null && error !== void 0 ? error : '');
|
|
863
|
-
if (!hdShared.isBleStaleBondErrorText(errorMessage)) {
|
|
864
|
-
return null;
|
|
865
|
-
}
|
|
866
|
-
return hdShared.ERRORS.TypedError(errorMessage.includes('Peer removed pairing information')
|
|
867
|
-
? hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation
|
|
868
|
-
: hdShared.HardwareErrorCode.BleDeviceBondError, errorMessage);
|
|
869
|
-
}
|
|
870
855
|
handleBluetoothError(error) {
|
|
871
|
-
const staleBondError = this.toStaleBondError(error);
|
|
872
|
-
if (staleBondError) {
|
|
873
|
-
throw staleBondError;
|
|
874
|
-
}
|
|
875
856
|
if (error && typeof error === 'object') {
|
|
876
857
|
if ('code' in error) {
|
|
877
858
|
if (error.code === hdShared.HardwareErrorCode.BlePoweredOff) {
|
|
@@ -1041,12 +1022,7 @@ class ElectronBleTransport {
|
|
|
1041
1022
|
}
|
|
1042
1023
|
this.v1Buffers.set(uuid, { buffer: [], bufferLength: 0 });
|
|
1043
1024
|
this.v2Assemblers.set(uuid, new transport.ProtocolV2FrameAssembler(transport.PROTOCOL_V2_BLE_FRAME_MAX_BYTES));
|
|
1044
|
-
|
|
1045
|
-
yield window.desktopApi.nobleBle.subscribe(uuid);
|
|
1046
|
-
}
|
|
1047
|
-
catch (error) {
|
|
1048
|
-
this.handleBluetoothError(error);
|
|
1049
|
-
}
|
|
1025
|
+
yield window.desktopApi.nobleBle.subscribe(uuid);
|
|
1050
1026
|
yield this.refreshBlePacketCapacity(uuid);
|
|
1051
1027
|
const cleanup = this.createNotificationSubscription(uuid);
|
|
1052
1028
|
this.notificationCleanups.set(uuid, cleanup);
|
|
@@ -1235,9 +1211,6 @@ class ElectronBleTransport {
|
|
|
1235
1211
|
catch (error) {
|
|
1236
1212
|
this.clearProbeProtocol(uuid, 'V1');
|
|
1237
1213
|
(_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[Electron BLE] Protocol V1 GetFeatures probe failed:', error);
|
|
1238
|
-
if (hdShared.isBleStaleBondHardwareError(error)) {
|
|
1239
|
-
throw error;
|
|
1240
|
-
}
|
|
1241
1214
|
return false;
|
|
1242
1215
|
}
|
|
1243
1216
|
});
|
|
@@ -1260,7 +1233,6 @@ class ElectronBleTransport {
|
|
|
1260
1233
|
(_a = this.v2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
|
|
1261
1234
|
this.resetProtocolV2Frames(uuid);
|
|
1262
1235
|
},
|
|
1263
|
-
shouldRethrow: hdShared.isBleStaleBondHardwareError,
|
|
1264
1236
|
});
|
|
1265
1237
|
if (!detected) {
|
|
1266
1238
|
this.clearProbeProtocol(uuid, 'V2');
|
|
@@ -1275,16 +1247,7 @@ class ElectronBleTransport {
|
|
|
1275
1247
|
if (!nobleBle) {
|
|
1276
1248
|
throw new Error('Noble BLE API not available');
|
|
1277
1249
|
}
|
|
1278
|
-
|
|
1279
|
-
yield nobleBle.write(uuid, hexData, { pacingDelayMs: 0 });
|
|
1280
|
-
}
|
|
1281
|
-
catch (error) {
|
|
1282
|
-
const staleBondError = this.toStaleBondError(error);
|
|
1283
|
-
if (staleBondError) {
|
|
1284
|
-
throw staleBondError;
|
|
1285
|
-
}
|
|
1286
|
-
throw error;
|
|
1287
|
-
}
|
|
1250
|
+
yield nobleBle.write(uuid, hexData, { pacingDelayMs: 0 });
|
|
1288
1251
|
});
|
|
1289
1252
|
}
|
|
1290
1253
|
refreshBlePacketCapacity(uuid) {
|
|
@@ -1494,16 +1457,7 @@ class ElectronBleTransport {
|
|
|
1494
1457
|
if (hexString.length === 0) {
|
|
1495
1458
|
throw new Error(`Buffer ${i + 1} is empty`);
|
|
1496
1459
|
}
|
|
1497
|
-
|
|
1498
|
-
yield window.desktopApi.nobleBle.write(uuid, hexString);
|
|
1499
|
-
}
|
|
1500
|
-
catch (error) {
|
|
1501
|
-
const staleBondError = this.toStaleBondError(error);
|
|
1502
|
-
if (staleBondError) {
|
|
1503
|
-
throw staleBondError;
|
|
1504
|
-
}
|
|
1505
|
-
throw error;
|
|
1506
|
-
}
|
|
1460
|
+
yield window.desktopApi.nobleBle.write(uuid, hexString);
|
|
1507
1461
|
}
|
|
1508
1462
|
const response = yield Promise.race([
|
|
1509
1463
|
runPromise.promise,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-web-device",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.161",
|
|
4
4
|
"author": "OneKey",
|
|
5
5
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"lint:fix": "eslint . --fix"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.161",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.161"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@onekeyfe/hd-transport-electron": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-transport-electron": "1.2.0-alpha.161",
|
|
29
29
|
"@types/w3c-web-usb": "^1.0.6",
|
|
30
30
|
"@types/web-bluetooth": "^0.0.17"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "06316117fc9a7ebaecea1ca583b2d105709361bf"
|
|
33
33
|
}
|
|
@@ -16,8 +16,6 @@ import {
|
|
|
16
16
|
HardwareErrorCode,
|
|
17
17
|
HardwareErrorCodeMessage,
|
|
18
18
|
createDeferred,
|
|
19
|
-
isBleStaleBondErrorText,
|
|
20
|
-
isBleStaleBondHardwareError,
|
|
21
19
|
isHeaderChunk,
|
|
22
20
|
} from '@onekeyfe/hd-shared';
|
|
23
21
|
|
|
@@ -161,30 +159,7 @@ export default class ElectronBleTransport {
|
|
|
161
159
|
|
|
162
160
|
private nextNotificationToken = 1;
|
|
163
161
|
|
|
164
|
-
private toStaleBondError(error: unknown): Error | null {
|
|
165
|
-
if (isBleStaleBondHardwareError(error)) {
|
|
166
|
-
return error as Error;
|
|
167
|
-
}
|
|
168
|
-
const errorMessage =
|
|
169
|
-
error && typeof error === 'object' && 'message' in error
|
|
170
|
-
? String((error as { message?: unknown }).message ?? '')
|
|
171
|
-
: String(error ?? '');
|
|
172
|
-
if (!isBleStaleBondErrorText(errorMessage)) {
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
return ERRORS.TypedError(
|
|
176
|
-
errorMessage.includes('Peer removed pairing information')
|
|
177
|
-
? HardwareErrorCode.BlePeerRemovedPairingInformation
|
|
178
|
-
: HardwareErrorCode.BleDeviceBondError,
|
|
179
|
-
errorMessage
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
162
|
private handleBluetoothError(error: any): never {
|
|
184
|
-
const staleBondError = this.toStaleBondError(error);
|
|
185
|
-
if (staleBondError) {
|
|
186
|
-
throw staleBondError;
|
|
187
|
-
}
|
|
188
163
|
if (error && typeof error === 'object') {
|
|
189
164
|
if ('code' in error) {
|
|
190
165
|
if (error.code === HardwareErrorCode.BlePoweredOff) {
|
|
@@ -392,11 +367,7 @@ export default class ElectronBleTransport {
|
|
|
392
367
|
this.v1Buffers.set(uuid, { buffer: [], bufferLength: 0 });
|
|
393
368
|
this.v2Assemblers.set(uuid, new ProtocolV2FrameAssembler(PROTOCOL_V2_BLE_FRAME_MAX_BYTES));
|
|
394
369
|
|
|
395
|
-
|
|
396
|
-
await window.desktopApi.nobleBle.subscribe(uuid);
|
|
397
|
-
} catch (error) {
|
|
398
|
-
this.handleBluetoothError(error);
|
|
399
|
-
}
|
|
370
|
+
await window.desktopApi.nobleBle.subscribe(uuid);
|
|
400
371
|
await this.refreshBlePacketCapacity(uuid);
|
|
401
372
|
|
|
402
373
|
const cleanup = this.createNotificationSubscription(uuid);
|
|
@@ -617,9 +588,6 @@ export default class ElectronBleTransport {
|
|
|
617
588
|
} catch (error) {
|
|
618
589
|
this.clearProbeProtocol(uuid, 'V1');
|
|
619
590
|
this.Log?.debug('[Electron BLE] Protocol V1 GetFeatures probe failed:', error);
|
|
620
|
-
if (isBleStaleBondHardwareError(error)) {
|
|
621
|
-
throw error;
|
|
622
|
-
}
|
|
623
591
|
return false;
|
|
624
592
|
}
|
|
625
593
|
}
|
|
@@ -640,7 +608,6 @@ export default class ElectronBleTransport {
|
|
|
640
608
|
this.v2Assemblers.get(uuid)?.reset();
|
|
641
609
|
this.resetProtocolV2Frames(uuid);
|
|
642
610
|
},
|
|
643
|
-
shouldRethrow: isBleStaleBondHardwareError,
|
|
644
611
|
});
|
|
645
612
|
if (!detected) {
|
|
646
613
|
this.clearProbeProtocol(uuid, 'V2');
|
|
@@ -654,15 +621,7 @@ export default class ElectronBleTransport {
|
|
|
654
621
|
throw new Error('Noble BLE API not available');
|
|
655
622
|
}
|
|
656
623
|
|
|
657
|
-
|
|
658
|
-
await nobleBle.write(uuid, hexData, { pacingDelayMs: 0 });
|
|
659
|
-
} catch (error) {
|
|
660
|
-
const staleBondError = this.toStaleBondError(error);
|
|
661
|
-
if (staleBondError) {
|
|
662
|
-
throw staleBondError;
|
|
663
|
-
}
|
|
664
|
-
throw error;
|
|
665
|
-
}
|
|
624
|
+
await nobleBle.write(uuid, hexData, { pacingDelayMs: 0 });
|
|
666
625
|
}
|
|
667
626
|
|
|
668
627
|
private async refreshBlePacketCapacity(uuid: string): Promise<void> {
|
|
@@ -904,15 +863,7 @@ export default class ElectronBleTransport {
|
|
|
904
863
|
if (hexString.length === 0) {
|
|
905
864
|
throw new Error(`Buffer ${i + 1} is empty`);
|
|
906
865
|
}
|
|
907
|
-
|
|
908
|
-
await window.desktopApi.nobleBle.write(uuid, hexString);
|
|
909
|
-
} catch (error) {
|
|
910
|
-
const staleBondError = this.toStaleBondError(error);
|
|
911
|
-
if (staleBondError) {
|
|
912
|
-
throw staleBondError;
|
|
913
|
-
}
|
|
914
|
-
throw error;
|
|
915
|
-
}
|
|
866
|
+
await window.desktopApi.nobleBle.write(uuid, hexString);
|
|
916
867
|
}
|
|
917
868
|
|
|
918
869
|
const response = await Promise.race([
|