@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.
@@ -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: 'stale-bond-id', name: 'OneKey Pro 2' };
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 pairing information is no longer valid',
194
- errorCode: HardwareErrorCode.BleBondInvalid,
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.BleBondInvalid,
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.toThrow(
551
- /Unable to detect BLE protocol/
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.RuntimeError,
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.RuntimeError,
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.RuntimeError,
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 insufficient encryption', async () => {
646
- const device = { id: 'stale-bond-pro2-id', name: 'OneKey Pro 2' };
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 pairing information is no longer valid',
651
- errorCode: HardwareErrorCode.BleBondInvalid,
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.BleBondInvalid,
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 stale-bond error before the protocol is known', async () => {
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 pairing information is no longer valid',
674
- errorCode: HardwareErrorCode.BleBondInvalid,
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.BleBondInvalid,
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('does not classify a generic macOS connection failure as a stale bond', async () => {
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('keeps stale-bond subscribe mapping out of Protocol V1 acquire', async () => {
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.RuntimeError,
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 stale-bond error during an expected Protocol V2 probe', async () => {
784
- const device = { id: 'stale-bond-probe-id', name: 'OneKey Pro 2' };
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 pairing information is no longer valid',
789
- errorCode: HardwareErrorCode.BleBondInvalid,
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.BleBondInvalid });
810
+ ).rejects.toMatchObject({ errorCode: HardwareErrorCode.BleConnectedError });
796
811
 
797
812
  expect(nobleBle.unsubscribe).toHaveBeenCalledWith(device.id);
798
813
  expect(nobleBle.disconnect).toHaveBeenCalledWith(device.id);