@onekeyfe/hd-transport-web-device 1.2.8-alpha.10 → 1.2.8-alpha.101
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 +45 -30
- package/__tests__/webusb-identity-probe.test.ts +887 -0
- package/__tests__/webusb-protocol-cache.test.ts +121 -0
- package/__tests__/webusb-protocol-v2-timeout.test.ts +27 -8
- package/dist/electron-ble-transport.d.ts.map +1 -1
- package/dist/index.d.ts +24 -3
- package/dist/index.js +405 -35
- package/dist/webusb.d.ts +24 -3
- package/dist/webusb.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/electron-ble-transport.ts +10 -15
- package/src/webusb.ts +400 -35
|
@@ -182,16 +182,30 @@ 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
|
-
const device = { id: '
|
|
200
|
+
const device = { id: 'legacy-error-id', name: 'OneKey Pro 2' };
|
|
187
201
|
const nobleBle = createNobleBle(device);
|
|
188
202
|
nobleBle.connect.mockResolvedValue({
|
|
189
203
|
type: 'NobleBleIpcError',
|
|
190
204
|
success: false,
|
|
191
205
|
error: {
|
|
192
206
|
name: 'HardwareError',
|
|
193
|
-
message: 'Bluetooth
|
|
194
|
-
errorCode: HardwareErrorCode.
|
|
207
|
+
message: 'Bluetooth connection failed',
|
|
208
|
+
errorCode: HardwareErrorCode.BleConnectedError,
|
|
195
209
|
},
|
|
196
210
|
} as never);
|
|
197
211
|
const bleTransport = configureTransport(nobleBle);
|
|
@@ -199,7 +213,7 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
199
213
|
await expect(
|
|
200
214
|
bleTransport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
|
|
201
215
|
).rejects.toMatchObject({
|
|
202
|
-
errorCode: HardwareErrorCode.
|
|
216
|
+
errorCode: HardwareErrorCode.BleConnectedError,
|
|
203
217
|
});
|
|
204
218
|
expect(nobleBle.subscribe).not.toHaveBeenCalled();
|
|
205
219
|
expect(nobleBle.disconnect).toHaveBeenCalledWith(device.id);
|
|
@@ -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,25 +646,26 @@ 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();
|
|
643
660
|
});
|
|
644
661
|
|
|
645
|
-
test('fails Protocol V2 acquire immediately when subscribe reports
|
|
646
|
-
const device = { id: '
|
|
662
|
+
test('fails Protocol V2 acquire immediately when subscribe reports a connection error', async () => {
|
|
663
|
+
const device = { id: 'subscribe-error-pro2-id', name: 'OneKey Pro 2' };
|
|
647
664
|
const nobleBle = createNobleBle(device);
|
|
648
665
|
nobleBle.subscribe.mockRejectedValue({
|
|
649
666
|
name: 'HardwareError',
|
|
650
|
-
message: 'Bluetooth
|
|
651
|
-
errorCode: HardwareErrorCode.
|
|
652
|
-
params: { nativeErrorMessage: 'Encryption is insufficient' },
|
|
667
|
+
message: 'Bluetooth connection failed',
|
|
668
|
+
errorCode: HardwareErrorCode.BleConnectedError,
|
|
653
669
|
});
|
|
654
670
|
const transport = configureTransport(nobleBle);
|
|
655
671
|
const probe = jest.spyOn(transport as any, 'probeProtocolV2');
|
|
@@ -657,7 +673,7 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
657
673
|
await expect(
|
|
658
674
|
transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
|
|
659
675
|
).rejects.toMatchObject({
|
|
660
|
-
errorCode: HardwareErrorCode.
|
|
676
|
+
errorCode: HardwareErrorCode.BleConnectedError,
|
|
661
677
|
});
|
|
662
678
|
|
|
663
679
|
expect(probe).not.toHaveBeenCalled();
|
|
@@ -665,21 +681,19 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
665
681
|
expect(nobleBle.disconnect).toHaveBeenCalledWith(device.id);
|
|
666
682
|
});
|
|
667
683
|
|
|
668
|
-
test('rehydrates a structured
|
|
684
|
+
test('rehydrates a structured connection error before the protocol is known', async () => {
|
|
669
685
|
const device = { id: 'reset-unknown-protocol-id', name: 'OneKey Pro 2' };
|
|
670
686
|
const nobleBle = createNobleBle(device);
|
|
671
687
|
nobleBle.connect.mockRejectedValue({
|
|
672
688
|
name: 'HardwareError',
|
|
673
|
-
message: 'Bluetooth
|
|
674
|
-
errorCode: HardwareErrorCode.
|
|
675
|
-
params: { nativeErrorMessage: 'CBErrorDomain:14 native message' },
|
|
689
|
+
message: 'Bluetooth connection failed',
|
|
690
|
+
errorCode: HardwareErrorCode.BleConnectedError,
|
|
676
691
|
});
|
|
677
692
|
const transport = configureTransport(nobleBle);
|
|
678
693
|
|
|
679
694
|
await expect(transport.acquire({ uuid: device.id })).rejects.toMatchObject({
|
|
680
695
|
name: 'HardwareError',
|
|
681
|
-
errorCode: HardwareErrorCode.
|
|
682
|
-
params: { nativeErrorMessage: 'CBErrorDomain:14 native message' },
|
|
696
|
+
errorCode: HardwareErrorCode.BleConnectedError,
|
|
683
697
|
});
|
|
684
698
|
});
|
|
685
699
|
|
|
@@ -699,7 +713,7 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
699
713
|
}
|
|
700
714
|
});
|
|
701
715
|
|
|
702
|
-
test('
|
|
716
|
+
test('preserves a generic macOS connection failure', async () => {
|
|
703
717
|
const device = { id: 'offline-pro2-macos-id', name: 'OneKey Pro 2' };
|
|
704
718
|
const nobleBle = createNobleBle(device);
|
|
705
719
|
nobleBle.connect.mockRejectedValue(new Error('connection failed'));
|
|
@@ -715,7 +729,7 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
715
729
|
}
|
|
716
730
|
});
|
|
717
731
|
|
|
718
|
-
test('
|
|
732
|
+
test('preserves a native subscribe failure during Protocol V1 acquire', async () => {
|
|
719
733
|
const device = { id: 'classic-v1-id', name: 'OneKey Classic' };
|
|
720
734
|
const nobleBle = createNobleBle(device);
|
|
721
735
|
nobleBle.subscribe.mockRejectedValue(new Error('Encryption is insufficient'));
|
|
@@ -744,7 +758,8 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
744
758
|
await expect(
|
|
745
759
|
transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
|
|
746
760
|
).rejects.toMatchObject({
|
|
747
|
-
errorCode: HardwareErrorCode.
|
|
761
|
+
errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
|
|
762
|
+
params: { expectedProtocol: 'V2' },
|
|
748
763
|
});
|
|
749
764
|
|
|
750
765
|
expect(nobleBle.unsubscribe).toHaveBeenCalledWith(device.id);
|
|
@@ -780,19 +795,19 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
780
795
|
}
|
|
781
796
|
);
|
|
782
797
|
|
|
783
|
-
test('preserves a native
|
|
784
|
-
const device = { id: '
|
|
798
|
+
test('preserves a native connection error during an expected Protocol V2 probe', async () => {
|
|
799
|
+
const device = { id: 'connection-error-probe-id', name: 'OneKey Pro 2' };
|
|
785
800
|
const nobleBle = createNobleBle(device);
|
|
786
801
|
nobleBle.write.mockRejectedValue({
|
|
787
802
|
name: 'HardwareError',
|
|
788
|
-
message: 'Bluetooth
|
|
789
|
-
errorCode: HardwareErrorCode.
|
|
803
|
+
message: 'Bluetooth connection failed',
|
|
804
|
+
errorCode: HardwareErrorCode.BleConnectedError,
|
|
790
805
|
});
|
|
791
806
|
const transport = configureTransport(nobleBle);
|
|
792
807
|
|
|
793
808
|
await expect(
|
|
794
809
|
transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
|
|
795
|
-
).rejects.toMatchObject({ errorCode: HardwareErrorCode.
|
|
810
|
+
).rejects.toMatchObject({ errorCode: HardwareErrorCode.BleConnectedError });
|
|
796
811
|
|
|
797
812
|
expect(nobleBle.unsubscribe).toHaveBeenCalledWith(device.id);
|
|
798
813
|
expect(nobleBle.disconnect).toHaveBeenCalledWith(device.id);
|