@onekeyfe/hd-transport-web-device 1.2.8-alpha.2 → 1.2.8-alpha.21
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__/electron-ble-transport.test.ts +25 -7
- package/__tests__/webusb-identity-probe.test.ts +887 -0
- package/__tests__/webusb-protocol-v2-timeout.test.ts +18 -5
- package/dist/electron-ble-transport.d.ts.map +1 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +301 -29
- package/dist/webusb.d.ts +17 -1
- package/dist/webusb.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/electron-ble-transport.ts +9 -10
- package/src/webusb.ts +290 -32
|
@@ -182,6 +182,20 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
182
182
|
jest.clearAllMocks();
|
|
183
183
|
});
|
|
184
184
|
|
|
185
|
+
test.each([
|
|
186
|
+
{ errorCode: HardwareErrorCode.BleLocationError, message: 'Permission denied' },
|
|
187
|
+
{ code: HardwareErrorCode.BleLocationError },
|
|
188
|
+
{ message: 'Bluetooth unauthorized' },
|
|
189
|
+
])('preserves Bluetooth permission failures from the native bridge: %j', async error => {
|
|
190
|
+
const nobleBle = createNobleBle();
|
|
191
|
+
nobleBle.enumerate.mockRejectedValueOnce(error);
|
|
192
|
+
const bleTransport = configureTransport(nobleBle);
|
|
193
|
+
|
|
194
|
+
await expect(bleTransport.enumerate()).rejects.toMatchObject({
|
|
195
|
+
errorCode: HardwareErrorCode.BleLocationError,
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
185
199
|
test('does not treat an error envelope from a legacy preload as a successful connect', async () => {
|
|
186
200
|
const device = { id: 'legacy-error-id', name: 'OneKey Pro 2' };
|
|
187
201
|
const nobleBle = createNobleBle(device);
|
|
@@ -547,9 +561,9 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
547
561
|
|
|
548
562
|
const transport = configureTransport(nobleBle);
|
|
549
563
|
|
|
550
|
-
await expect(transport.acquire({ uuid: device.id })).rejects.
|
|
551
|
-
|
|
552
|
-
);
|
|
564
|
+
await expect(transport.acquire({ uuid: device.id })).rejects.toMatchObject({
|
|
565
|
+
errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
|
|
566
|
+
});
|
|
553
567
|
expect(nobleBle.unsubscribe).toHaveBeenCalledWith(device.id);
|
|
554
568
|
expect(nobleBle.disconnect).toHaveBeenCalledWith(device.id);
|
|
555
569
|
expect(transport.getProtocolType(device.id)).toBeUndefined();
|
|
@@ -615,7 +629,8 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
615
629
|
await expect(
|
|
616
630
|
transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
|
|
617
631
|
).rejects.toMatchObject({
|
|
618
|
-
errorCode: HardwareErrorCode.
|
|
632
|
+
errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
|
|
633
|
+
params: { expectedProtocol: 'V2' },
|
|
619
634
|
});
|
|
620
635
|
|
|
621
636
|
expect(nobleBle.connect).toHaveBeenCalledTimes(1);
|
|
@@ -631,12 +646,14 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
631
646
|
await expect(
|
|
632
647
|
transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
|
|
633
648
|
).rejects.toMatchObject({
|
|
634
|
-
errorCode: HardwareErrorCode.
|
|
649
|
+
errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
|
|
650
|
+
params: { expectedProtocol: 'V2' },
|
|
635
651
|
});
|
|
636
652
|
await expect(
|
|
637
653
|
transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
|
|
638
654
|
).rejects.toMatchObject({
|
|
639
|
-
errorCode: HardwareErrorCode.
|
|
655
|
+
errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
|
|
656
|
+
params: { expectedProtocol: 'V2' },
|
|
640
657
|
});
|
|
641
658
|
|
|
642
659
|
expect(transport.getProtocolType(device.id)).toBeUndefined();
|
|
@@ -741,7 +758,8 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
741
758
|
await expect(
|
|
742
759
|
transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
|
|
743
760
|
).rejects.toMatchObject({
|
|
744
|
-
errorCode: HardwareErrorCode.
|
|
761
|
+
errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
|
|
762
|
+
params: { expectedProtocol: 'V2' },
|
|
745
763
|
});
|
|
746
764
|
|
|
747
765
|
expect(nobleBle.unsubscribe).toHaveBeenCalledWith(device.id);
|