@onekeyfe/hd-transport-web-device 1.2.2-alpha.14 → 1.2.2-alpha.17

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.
@@ -553,14 +553,19 @@ describe('ElectronBleTransport protocol detection', () => {
553
553
  test('fails Protocol V2 acquire immediately when subscribe reports insufficient encryption', async () => {
554
554
  const device = { id: 'stale-bond-pro2-id', name: 'OneKey Pro 2' };
555
555
  const nobleBle = createNobleBle(device);
556
- nobleBle.subscribe.mockRejectedValue(new Error('Encryption is insufficient'));
556
+ nobleBle.subscribe.mockRejectedValue({
557
+ name: 'HardwareError',
558
+ message: 'Bluetooth pairing information is no longer valid',
559
+ errorCode: HardwareErrorCode.BleBondInvalid,
560
+ params: { nativeErrorMessage: 'Encryption is insufficient' },
561
+ });
557
562
  const transport = configureTransport(nobleBle);
558
563
  const probe = jest.spyOn(transport as any, 'probeProtocolV2');
559
564
 
560
565
  await expect(
561
566
  transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
562
567
  ).rejects.toMatchObject({
563
- errorCode: HardwareErrorCode.BleDeviceBondError,
568
+ errorCode: HardwareErrorCode.BleBondInvalid,
564
569
  });
565
570
 
566
571
  expect(probe).not.toHaveBeenCalled();
@@ -568,52 +573,38 @@ describe('ElectronBleTransport protocol detection', () => {
568
573
  expect(nobleBle.disconnect).toHaveBeenCalledWith(device.id);
569
574
  });
570
575
 
571
- test('maps macOS CoreBluetooth peer-removed pairing failures to the precise error', async () => {
572
- const device = { id: 'reset-pro2-macos-id', name: 'OneKey Pro 2' };
576
+ test('rehydrates a structured stale-bond error before the protocol is known', async () => {
577
+ const device = { id: 'reset-unknown-protocol-id', name: 'OneKey Pro 2' };
573
578
  const nobleBle = createNobleBle(device);
574
- nobleBle.connect.mockRejectedValue(
575
- new Error('CBErrorDomain:14 Peer removed pairing information on the device side')
576
- );
577
- const transport = configureTransport(nobleBle);
578
-
579
- await expect(
580
- transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
581
- ).rejects.toMatchObject({
579
+ nobleBle.connect.mockRejectedValue({
580
+ name: 'HardwareError',
581
+ message: 'Bluetooth pairing information is no longer valid',
582
582
  errorCode: HardwareErrorCode.BleBondInvalid,
583
- params: {
584
- nativeErrorMessage: 'CBErrorDomain:14 Peer removed pairing information on the device side',
585
- },
583
+ params: { nativeErrorMessage: 'CBErrorDomain:14 native message' },
586
584
  });
587
- });
588
-
589
- test('rehydrates the native stale-bond code after Electron IPC wraps the error', async () => {
590
- const device = { id: 'reset-pro2-ipc-id', name: 'OneKey Pro 2' };
591
- const nobleBle = createNobleBle(device);
592
- nobleBle.connect.mockRejectedValue(
593
- new Error(
594
- "Error invoking remote method '$onekey-noble-ble-connect': HardwareError: Bluetooth pairing information is no longer valid. Forget the device in system Bluetooth settings and pair it again. (CBErrorDomain:14 Peer removed pairing information on the device side)"
595
- )
596
- );
597
585
  const transport = configureTransport(nobleBle);
598
586
 
599
- await expect(
600
- transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
601
- ).rejects.toMatchObject({
587
+ await expect(transport.acquire({ uuid: device.id })).rejects.toMatchObject({
588
+ name: 'HardwareError',
602
589
  errorCode: HardwareErrorCode.BleBondInvalid,
590
+ params: { nativeErrorMessage: 'CBErrorDomain:14 native message' },
603
591
  });
604
592
  });
605
593
 
606
- test('maps a localized macOS CBATT code 14 failure without relying on its description', async () => {
594
+ test('does not infer hardware errors from native error text in the renderer', async () => {
607
595
  const device = { id: 'reset-pro2-localized-id', name: 'OneKey Pro 2' };
608
596
  const nobleBle = createNobleBle(device);
609
597
  nobleBle.connect.mockRejectedValue(new Error('CBATTErrorDomain:14 localized native message'));
610
598
  const transport = configureTransport(nobleBle);
611
599
 
612
- await expect(
613
- transport.acquire({ uuid: device.id, expectedProtocol: 'V2' })
614
- ).rejects.toMatchObject({
615
- errorCode: HardwareErrorCode.BleBondInvalid,
616
- });
600
+ try {
601
+ await transport.acquire({ uuid: device.id, expectedProtocol: 'V2' });
602
+ throw new Error('Expected acquire to fail');
603
+ } catch (error) {
604
+ expect(error).toBeInstanceOf(Error);
605
+ expect((error as Error).message).toBe('CBATTErrorDomain:14 localized native message');
606
+ expect((error as { errorCode?: unknown }).errorCode).toBeUndefined();
607
+ }
617
608
  });
618
609
 
619
610
  test('does not classify a generic macOS connection failure as a stale bond', async () => {
@@ -41,7 +41,7 @@ export default class ElectronBleTransport {
41
41
  private hostDisconnectCleanup?;
42
42
  private notificationTokens;
43
43
  private nextNotificationToken;
44
- private toStaleBondError;
44
+ private normalizeBluetoothError;
45
45
  private handleBluetoothError;
46
46
  private cleanupDeviceState;
47
47
  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":";AA2BA,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,UAA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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
@@ -242,7 +242,7 @@ declare class ElectronBleTransport {
242
242
  private hostDisconnectCleanup?;
243
243
  private notificationTokens;
244
244
  private nextNotificationToken;
245
- private toStaleBondError;
245
+ private normalizeBluetoothError;
246
246
  private handleBluetoothError;
247
247
  private cleanupDeviceState;
248
248
  init(logger: any, emitter?: EventEmitter): void;
package/dist/index.js CHANGED
@@ -871,45 +871,20 @@ class ElectronBleTransport {
871
871
  this.notificationTokens = new Map();
872
872
  this.nextNotificationToken = 1;
873
873
  }
874
- toStaleBondError(error) {
875
- var _a;
876
- if (hdShared.isBleStaleBondHardwareError(error)) {
877
- return error;
878
- }
879
- const errorMessage = error && typeof error === 'object' && 'message' in error
880
- ? String((_a = error.message) !== null && _a !== void 0 ? _a : '')
881
- : String(error !== null && error !== void 0 ? error : '');
882
- if (!hdShared.isBleStaleBondErrorText(errorMessage)) {
883
- return null;
884
- }
885
- const normalizedErrorMessage = errorMessage.toLowerCase();
886
- if (normalizedErrorMessage.includes('cberrordomain:14') ||
887
- normalizedErrorMessage.includes('cbatterrordomain:14')) {
888
- return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleBondInvalid, undefined, {
889
- nativeErrorMessage: errorMessage,
890
- });
891
- }
892
- return hdShared.ERRORS.TypedError(normalizedErrorMessage.includes('peer removed pairing information')
893
- ? hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation
894
- : hdShared.HardwareErrorCode.BleDeviceBondError, errorMessage);
895
- }
896
- handleBluetoothError(error, mapProtocolV2StaleBond = false) {
897
- if (mapProtocolV2StaleBond) {
898
- const staleBondError = this.toStaleBondError(error);
899
- if (staleBondError) {
900
- throw staleBondError;
901
- }
902
- }
874
+ normalizeBluetoothError(error) {
903
875
  if (error && typeof error === 'object') {
876
+ if (typeof error.errorCode === 'number') {
877
+ return hdShared.ERRORS.TypedError(error.errorCode, typeof error.message === 'string' ? error.message : undefined, error.params);
878
+ }
904
879
  if ('code' in error) {
905
880
  if (error.code === hdShared.HardwareErrorCode.BlePoweredOff) {
906
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePoweredOff);
881
+ return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePoweredOff);
907
882
  }
908
883
  if (error.code === hdShared.HardwareErrorCode.BleUnsupported) {
909
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleUnsupported);
884
+ return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleUnsupported);
910
885
  }
911
886
  if (error.code === hdShared.HardwareErrorCode.BlePermissionError) {
912
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePermissionError);
887
+ return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePermissionError);
913
888
  }
914
889
  }
915
890
  const errorMessage = error.message || String(error);
@@ -917,16 +892,19 @@ class ElectronBleTransport {
917
892
  const unsupportedMessage = hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.BleUnsupported];
918
893
  const permissionMessage = hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.BlePermissionError];
919
894
  if (errorMessage.includes(poweredOffMessage) || errorMessage.includes('poweredOff')) {
920
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePoweredOff);
895
+ return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePoweredOff);
921
896
  }
922
897
  if (errorMessage.includes(unsupportedMessage) || errorMessage.includes('unsupported')) {
923
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleUnsupported);
898
+ return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleUnsupported);
924
899
  }
925
900
  if (errorMessage.includes(permissionMessage) || errorMessage.includes('unauthorized')) {
926
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePermissionError);
901
+ return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePermissionError);
927
902
  }
928
903
  }
929
- throw error;
904
+ return error;
905
+ }
906
+ handleBluetoothError(error) {
907
+ throw this.normalizeBluetoothError(error);
930
908
  }
931
909
  cleanupDeviceState(deviceId) {
932
910
  this.protocolV2Links
@@ -1030,9 +1008,6 @@ class ElectronBleTransport {
1030
1008
  var _a, _b, _c, _d, _e, _f, _g;
1031
1009
  return __awaiter(this, void 0, void 0, function* () {
1032
1010
  const { uuid, forceCleanRunPromise, expectedProtocol } = input;
1033
- const shouldMapProtocolV2StaleBond = expectedProtocol
1034
- ? expectedProtocol === 'V2'
1035
- : this.confirmedProtocolV2.has(uuid);
1036
1011
  if (!uuid) {
1037
1012
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleRequiredUUID);
1038
1013
  }
@@ -1064,7 +1039,7 @@ class ElectronBleTransport {
1064
1039
  this.connectedDevices.add(uuid);
1065
1040
  }
1066
1041
  catch (error) {
1067
- this.handleBluetoothError(error, shouldMapProtocolV2StaleBond);
1042
+ this.handleBluetoothError(error);
1068
1043
  }
1069
1044
  const mtuCleanup = this.createMtuSubscription(uuid);
1070
1045
  if (mtuCleanup) {
@@ -1076,7 +1051,7 @@ class ElectronBleTransport {
1076
1051
  yield window.desktopApi.nobleBle.subscribe(uuid);
1077
1052
  }
1078
1053
  catch (error) {
1079
- this.handleBluetoothError(error, shouldMapProtocolV2StaleBond);
1054
+ this.handleBluetoothError(error);
1080
1055
  }
1081
1056
  yield this.refreshBlePacketCapacity(uuid);
1082
1057
  const cleanup = this.createNotificationSubscription(uuid);
@@ -1103,7 +1078,7 @@ class ElectronBleTransport {
1103
1078
  (_g = this.Log) === null || _g === void 0 ? void 0 : _g.debug('[Electron BLE] acquire cleanup failed:', cleanupError);
1104
1079
  }
1105
1080
  this.cleanupDeviceState(uuid);
1106
- throw error;
1081
+ this.handleBluetoothError(error);
1107
1082
  }
1108
1083
  });
1109
1084
  }
@@ -1307,11 +1282,7 @@ class ElectronBleTransport {
1307
1282
  yield nobleBle.write(uuid, hexData, { pacingDelayMs: 0 });
1308
1283
  }
1309
1284
  catch (error) {
1310
- const staleBondError = this.toStaleBondError(error);
1311
- if (staleBondError) {
1312
- throw staleBondError;
1313
- }
1314
- throw error;
1285
+ this.handleBluetoothError(error);
1315
1286
  }
1316
1287
  });
1317
1288
  }
@@ -1574,7 +1545,7 @@ class ElectronBleTransport {
1574
1545
  yield this.releaseNative(uuid);
1575
1546
  }
1576
1547
  }
1577
- throw e;
1548
+ throw this.normalizeBluetoothError(e);
1578
1549
  }
1579
1550
  finally {
1580
1551
  if (timeout)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-web-device",
3
- "version": "1.2.2-alpha.14",
3
+ "version": "1.2.2-alpha.17",
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.2-alpha.14",
25
- "@onekeyfe/hd-transport": "1.2.2-alpha.14"
24
+ "@onekeyfe/hd-shared": "1.2.2-alpha.17",
25
+ "@onekeyfe/hd-transport": "1.2.2-alpha.17"
26
26
  },
27
27
  "devDependencies": {
28
- "@onekeyfe/hd-transport-electron": "1.2.2-alpha.14",
28
+ "@onekeyfe/hd-transport-electron": "1.2.2-alpha.17",
29
29
  "@types/w3c-web-usb": "^1.0.6",
30
30
  "@types/web-bluetooth": "^0.0.17"
31
31
  },
32
- "gitHead": "1b3bf0576a53bedbc5f4a82308c48e11ffc00b16"
32
+ "gitHead": "b6c48b842d1c325dcd5ce42c03a07ee4377002dd"
33
33
  }
@@ -18,7 +18,6 @@ import {
18
18
  HardwareErrorCode,
19
19
  HardwareErrorCodeMessage,
20
20
  createDeferred,
21
- isBleStaleBondErrorText,
22
21
  isBleStaleBondHardwareError,
23
22
  isHeaderChunk,
24
23
  } from '@onekeyfe/hd-shared';
@@ -163,51 +162,24 @@ export default class ElectronBleTransport {
163
162
 
164
163
  private nextNotificationToken = 1;
165
164
 
166
- private toStaleBondError(error: unknown): Error | null {
167
- if (isBleStaleBondHardwareError(error)) {
168
- return error as Error;
169
- }
170
- const errorMessage =
171
- error && typeof error === 'object' && 'message' in error
172
- ? String((error as { message?: unknown }).message ?? '')
173
- : String(error ?? '');
174
- if (!isBleStaleBondErrorText(errorMessage)) {
175
- return null;
176
- }
177
- const normalizedErrorMessage = errorMessage.toLowerCase();
178
- if (
179
- normalizedErrorMessage.includes('cberrordomain:14') ||
180
- normalizedErrorMessage.includes('cbatterrordomain:14')
181
- ) {
182
- return ERRORS.TypedError(HardwareErrorCode.BleBondInvalid, undefined, {
183
- nativeErrorMessage: errorMessage,
184
- });
185
- }
186
- return ERRORS.TypedError(
187
- normalizedErrorMessage.includes('peer removed pairing information')
188
- ? HardwareErrorCode.BlePeerRemovedPairingInformation
189
- : HardwareErrorCode.BleDeviceBondError,
190
- errorMessage
191
- );
192
- }
193
-
194
- private handleBluetoothError(error: any, mapProtocolV2StaleBond = false): never {
195
- if (mapProtocolV2StaleBond) {
196
- const staleBondError = this.toStaleBondError(error);
197
- if (staleBondError) {
198
- throw staleBondError;
199
- }
200
- }
165
+ private normalizeBluetoothError(error: any): any {
201
166
  if (error && typeof error === 'object') {
167
+ if (typeof error.errorCode === 'number') {
168
+ return ERRORS.TypedError(
169
+ error.errorCode,
170
+ typeof error.message === 'string' ? error.message : undefined,
171
+ error.params
172
+ );
173
+ }
202
174
  if ('code' in error) {
203
175
  if (error.code === HardwareErrorCode.BlePoweredOff) {
204
- throw ERRORS.TypedError(HardwareErrorCode.BlePoweredOff);
176
+ return ERRORS.TypedError(HardwareErrorCode.BlePoweredOff);
205
177
  }
206
178
  if (error.code === HardwareErrorCode.BleUnsupported) {
207
- throw ERRORS.TypedError(HardwareErrorCode.BleUnsupported);
179
+ return ERRORS.TypedError(HardwareErrorCode.BleUnsupported);
208
180
  }
209
181
  if (error.code === HardwareErrorCode.BlePermissionError) {
210
- throw ERRORS.TypedError(HardwareErrorCode.BlePermissionError);
182
+ return ERRORS.TypedError(HardwareErrorCode.BlePermissionError);
211
183
  }
212
184
  }
213
185
  const errorMessage = error.message || String(error);
@@ -216,16 +188,20 @@ export default class ElectronBleTransport {
216
188
  const permissionMessage = HardwareErrorCodeMessage[HardwareErrorCode.BlePermissionError];
217
189
 
218
190
  if (errorMessage.includes(poweredOffMessage) || errorMessage.includes('poweredOff')) {
219
- throw ERRORS.TypedError(HardwareErrorCode.BlePoweredOff);
191
+ return ERRORS.TypedError(HardwareErrorCode.BlePoweredOff);
220
192
  }
221
193
  if (errorMessage.includes(unsupportedMessage) || errorMessage.includes('unsupported')) {
222
- throw ERRORS.TypedError(HardwareErrorCode.BleUnsupported);
194
+ return ERRORS.TypedError(HardwareErrorCode.BleUnsupported);
223
195
  }
224
196
  if (errorMessage.includes(permissionMessage) || errorMessage.includes('unauthorized')) {
225
- throw ERRORS.TypedError(HardwareErrorCode.BlePermissionError);
197
+ return ERRORS.TypedError(HardwareErrorCode.BlePermissionError);
226
198
  }
227
199
  }
228
- throw error;
200
+ return error;
201
+ }
202
+
203
+ private handleBluetoothError(error: any): never {
204
+ throw this.normalizeBluetoothError(error);
229
205
  }
230
206
 
231
207
  private cleanupDeviceState(deviceId: string): void {
@@ -358,9 +334,6 @@ export default class ElectronBleTransport {
358
334
 
359
335
  async acquire(input: BleAcquireInput) {
360
336
  const { uuid, forceCleanRunPromise, expectedProtocol } = input;
361
- const shouldMapProtocolV2StaleBond = expectedProtocol
362
- ? expectedProtocol === 'V2'
363
- : this.confirmedProtocolV2.has(uuid);
364
337
 
365
338
  if (!uuid) {
366
339
  throw ERRORS.TypedError(HardwareErrorCode.BleRequiredUUID);
@@ -397,7 +370,7 @@ export default class ElectronBleTransport {
397
370
  await window.desktopApi.nobleBle.connect(uuid);
398
371
  this.connectedDevices.add(uuid);
399
372
  } catch (error) {
400
- this.handleBluetoothError(error, shouldMapProtocolV2StaleBond);
373
+ this.handleBluetoothError(error);
401
374
  }
402
375
 
403
376
  const mtuCleanup = this.createMtuSubscription(uuid);
@@ -411,7 +384,7 @@ export default class ElectronBleTransport {
411
384
  try {
412
385
  await window.desktopApi.nobleBle.subscribe(uuid);
413
386
  } catch (error) {
414
- this.handleBluetoothError(error, shouldMapProtocolV2StaleBond);
387
+ this.handleBluetoothError(error);
415
388
  }
416
389
  await this.refreshBlePacketCapacity(uuid);
417
390
 
@@ -442,7 +415,7 @@ export default class ElectronBleTransport {
442
415
  this.Log?.debug('[Electron BLE] acquire cleanup failed:', cleanupError);
443
416
  }
444
417
  this.cleanupDeviceState(uuid);
445
- throw error;
418
+ this.handleBluetoothError(error);
446
419
  }
447
420
  }
448
421
 
@@ -681,11 +654,7 @@ export default class ElectronBleTransport {
681
654
  try {
682
655
  await nobleBle.write(uuid, hexData, { pacingDelayMs: 0 });
683
656
  } catch (error) {
684
- const staleBondError = this.toStaleBondError(error);
685
- if (staleBondError) {
686
- throw staleBondError;
687
- }
688
- throw error;
657
+ this.handleBluetoothError(error);
689
658
  }
690
659
  }
691
660
 
@@ -986,7 +955,7 @@ export default class ElectronBleTransport {
986
955
  await this.releaseNative(uuid);
987
956
  }
988
957
  }
989
- throw e;
958
+ throw this.normalizeBluetoothError(e);
990
959
  } finally {
991
960
  if (timeout) clearTimeout(timeout);
992
961
  if (this.runPromise === runPromise) {