@onekeyfe/hd-transport-react-native 1.2.8-alpha.11 → 1.2.8-alpha.110

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as transport from '@onekeyfe/hd-transport';
2
- import transport__default, { ProtocolType, OneKeyDeviceInfoBase, TransportCallOptions } from '@onekeyfe/hd-transport';
2
+ import transport__default, { ProtocolType, OneKeyDeviceInfoBase, OneKeyMobileDeviceInfo, TransportCallOptions } from '@onekeyfe/hd-transport';
3
3
  import { Device, Characteristic, Subscription, BleManager } from 'react-native-ble-plx';
4
4
  import { Deferred } from '@onekeyfe/hd-shared';
5
5
  import EventEmitter from 'events';
@@ -110,7 +110,7 @@ declare const PROTOCOL_REPROBE_FALLBACK_ATTEMPTS = 3;
110
110
  /** BLE setup timeouts since the last successful setup before the manager is recreated. */
111
111
  declare const BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD = 2;
112
112
  declare const BLE_SETUP_WEDGED_MESSAGE = "BLE setup wedged repeatedly";
113
- type IOneKeyDevice = OneKeyDeviceInfoBase & Device;
113
+ type IOneKeyDevice = OneKeyDeviceInfoBase & Device & Pick<OneKeyMobileDeviceInfo, 'bleColorCode'>;
114
114
  declare class ReactNativeBleTransport {
115
115
  blePlxManager: BleManager | undefined;
116
116
  _messages: ReturnType<typeof transport__default.parseConfigure> | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAGL,UAAU,IAAI,aAAa,EAG5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAChB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAI1B,MAAM,wBAAwB,CAAC;AA2BhC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAI1C,OAAO,KAAK,EAAE,QAAQ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AoB;YA2BlB,cAAc;IA0P5B,IAAI;IA8CE,UAAU,CAAC,OAAO,EAAE,MAAM;YAIlB,kBAAkB;YAkFlB,iBAAiB;IAkC/B,OAAO,CAAC,4BAA4B;YAQtB,qBAAqB;IAoB7B,MAAM;YAoBE,mBAAmB;YA4DnB,eAAe;YA6Bf,kBAAkB;YAkDlB,iCAAiC;IA8D/C,OAAO,CAAC,wBAAwB;IAwChC,OAAO,CAAC,yBAAyB;IAMjC,OAAO,CAAC,kBAAkB;YAcZ,cAAc;IA8C5B,OAAO,CAAC,kBAAkB;IA6B1B,OAAO,CAAC,eAAe;IAgEvB,OAAO,CAAC,2BAA2B;IAQnC,OAAO,CAAC,4BAA4B;IAIpC,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,iBAAiB;YAIX,cAAc;YA+Gd,0BAA0B;YAsB1B,iCAAiC;YAoDjC,eAAe;YAsBf,eAAe;IA2B7B,OAAO,CAAC,4BAA4B;IA2BpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,sBAAsB;YAShB,mBAAmB;YAiBnB,qBAAqB;YA8DrB,oBAAoB;YAgCpB,cAAc;YAmFd,iCAAiC;IAsB/C,OAAO,CAAC,8BAA8B;YAQxB,mCAAmC;IAsBjD,OAAO,CAAC,yCAAyC;YAanC,gCAAgC;IAoB9C,OAAO,CAAC,uBAAuB;IAmD/B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
package/dist/index.js CHANGED
@@ -425,6 +425,27 @@ function getProtocolV2BleTuning() {
425
425
  function getDeviceDisplayName(device) {
426
426
  return (device === null || device === void 0 ? void 0 : device.name) || (device === null || device === void 0 ? void 0 : device.localName) || null;
427
427
  }
428
+ const bleColorCodesById = new Map();
429
+ function getManufacturerDataLength(device) {
430
+ return (device === null || device === void 0 ? void 0 : device.manufacturerData) ? buffer.Buffer.from(device.manufacturerData, 'base64').length : 0;
431
+ }
432
+ function rememberBleColorCode(device) {
433
+ if (!(device === null || device === void 0 ? void 0 : device.id) || !device.manufacturerData)
434
+ return;
435
+ const colorCode = hdShared.parseOnekeyBleColorCode(buffer.Buffer.from(device.manufacturerData, 'base64'));
436
+ const key = device.id.toLowerCase();
437
+ if (colorCode && bleColorCodesById.get(key) !== colorCode) {
438
+ bleColorCodesById.set(key, colorCode);
439
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE color code', {
440
+ deviceId: device.id,
441
+ bleColorCode: colorCode,
442
+ });
443
+ }
444
+ }
445
+ function withBleColorCode(device) {
446
+ const bleColorCode = bleColorCodesById.get(device.id.toLowerCase());
447
+ return bleColorCode ? Object.assign(Object.assign({}, device), { bleColorCode }) : device;
448
+ }
428
449
  const IOS_REQUEST_MTU = 247;
429
450
  const ANDROID_REQUEST_MTU = 517;
430
451
  const ANDROID_HIGH_PRIORITY_IDLE_MS = 1000;
@@ -881,7 +902,7 @@ class ReactNativeBleTransport {
881
902
  if (error)
882
903
  reject(error);
883
904
  else
884
- resolve(deviceList);
905
+ resolve(deviceList.map(withBleColorCode));
885
906
  });
886
907
  return scanCleanup;
887
908
  };
@@ -921,6 +942,7 @@ class ReactNativeBleTransport {
921
942
  }
922
943
  return;
923
944
  }
945
+ rememberBleColorCode(device);
924
946
  const displayName = getDeviceDisplayName(device);
925
947
  const isUnnamedIOSPeripheral = reactNative.Platform.OS === 'ios' && !(displayName === null || displayName === void 0 ? void 0 : displayName.trim());
926
948
  const isOneKey = !isUnnamedIOSPeripheral &&
@@ -970,6 +992,8 @@ class ReactNativeBleTransport {
970
992
  deviceId: device.id,
971
993
  name: displayName,
972
994
  serviceUUIDs: device.serviceUUIDs,
995
+ manufacturerDataLength: getManufacturerDataLength(device),
996
+ bleColorCode: bleColorCodesById.get(device.id.toLowerCase()),
973
997
  });
974
998
  }
975
999
  };
@@ -2196,10 +2220,12 @@ class ReactNativeBleTransport {
2196
2220
  });
2197
2221
  }
2198
2222
  createProtocolMismatchError(expected) {
2199
- return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`);
2223
+ return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportProtocolProbeFailed, undefined, {
2224
+ expectedProtocol: expected,
2225
+ });
2200
2226
  }
2201
2227
  createProtocolDetectionError() {
2202
- return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, 'Unable to detect BLE protocol: device did not respond to Protocol V1 GetFeatures or Protocol V2 Ping');
2228
+ return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportProtocolProbeFailed);
2203
2229
  }
2204
2230
  clearProbeProtocol(uuid, protocol) {
2205
2231
  if (this.probingProtocols.get(uuid) === protocol) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "1.2.8-alpha.11",
3
+ "version": "1.2.8-alpha.110",
4
4
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -20,11 +20,11 @@
20
20
  "lint:fix": "eslint . --fix"
21
21
  },
22
22
  "dependencies": {
23
- "@onekeyfe/hd-core": "1.2.8-alpha.11",
24
- "@onekeyfe/hd-shared": "1.2.8-alpha.11",
25
- "@onekeyfe/hd-transport": "1.2.8-alpha.11",
23
+ "@onekeyfe/hd-core": "1.2.8-alpha.110",
24
+ "@onekeyfe/hd-shared": "1.2.8-alpha.110",
25
+ "@onekeyfe/hd-transport": "1.2.8-alpha.110",
26
26
  "@onekeyfe/react-native-ble-utils": "0.1.9",
27
27
  "react-native-ble-plx": "3.5.1"
28
28
  },
29
- "gitHead": "b605c09bab7bf26b969c73820a73b5cf257ce1dc"
29
+ "gitHead": "21cb80c9df5289d5da3ac56d693ed8f3caa2aaf7"
30
30
  }
@@ -214,3 +214,142 @@ describe('ReactNativeBleTransport iOS discovery', () => {
214
214
  expect(devices.map(device => device.id)).toEqual(['wallet-peripheral']);
215
215
  });
216
216
  });
217
+
218
+ describe('ReactNativeBleTransport advertisement color', () => {
219
+ const PRO2_SERVICE_UUIDS = [
220
+ '0000180a-0000-1000-8000-00805f9b34fb',
221
+ '0000180f-0000-1000-8000-00805f9b34fb',
222
+ '0000fffd-0000-1000-8000-00805f9b34fb',
223
+ ONEKEY_SERVICE_UUID,
224
+ ];
225
+ const manufacturerData = (bytes: number[]) => Buffer.from(bytes).toString('base64');
226
+
227
+ const scanOnce = async (advertisements: Record<string, unknown>[]) => {
228
+ const blePlxManager = {
229
+ startDeviceScan: jest.fn((_serviceUUIDs, _options, listener) => {
230
+ queueMicrotask(() => {
231
+ advertisements.forEach(advertisement => listener(null, advertisement));
232
+ });
233
+ }),
234
+ stopDeviceScan: jest.fn(),
235
+ };
236
+ const transport = new ReactNativeBleTransport({ scanTimeout: 1 });
237
+ transport.blePlxManager = blePlxManager as never;
238
+ transport.init({ debug: jest.fn(), error: jest.fn() }, new EventEmitter());
239
+ return transport.enumerate();
240
+ };
241
+
242
+ beforeEach(() => {
243
+ jest.clearAllMocks();
244
+ jest.mocked(getConnectedDeviceIds).mockResolvedValue([]);
245
+ });
246
+
247
+ afterEach(() => {
248
+ Object.assign(Platform, { OS: 'ios', Version: undefined });
249
+ });
250
+
251
+ test('keeps the color from an unnamed iOS advertisement for the named device', async () => {
252
+ const devices = await scanOnce([
253
+ {
254
+ id: 'COLOR-UNNAMED',
255
+ name: null,
256
+ localName: null,
257
+ serviceUUIDs: PRO2_SERVICE_UUIDS,
258
+ manufacturerData: manufacturerData([0x42, 0, 0, 0, 0]),
259
+ },
260
+ {
261
+ id: 'COLOR-UNNAMED',
262
+ name: 'Pro 2 769D',
263
+ localName: 'Pro 2 769D',
264
+ serviceUUIDs: PRO2_SERVICE_UUIDS,
265
+ manufacturerData: null,
266
+ },
267
+ ]);
268
+
269
+ expect(devices).toHaveLength(1);
270
+ expect(devices[0]).toMatchObject({ id: 'COLOR-UNNAMED', bleColorCode: 'B' });
271
+ });
272
+
273
+ test('fills a later color without letting a legacy payload clear it', async () => {
274
+ Object.assign(Platform, { OS: 'android', Version: 30 });
275
+
276
+ const devices = await scanOnce([
277
+ {
278
+ id: 'AA:BB:CC:00:00:01',
279
+ name: 'Neo 1A2B',
280
+ serviceUUIDs: PRO2_SERVICE_UUIDS,
281
+ manufacturerData: null,
282
+ },
283
+ {
284
+ id: 'AA:BB:CC:00:00:01',
285
+ name: 'Neo 1A2B',
286
+ serviceUUIDs: PRO2_SERVICE_UUIDS,
287
+ manufacturerData: manufacturerData([0x45, 0, 0, 0, 0]),
288
+ },
289
+ {
290
+ id: 'AA:BB:CC:00:00:01',
291
+ name: 'Neo 1A2B',
292
+ serviceUUIDs: PRO2_SERVICE_UUIDS,
293
+ manufacturerData: manufacturerData([0, 0, 0, 0]),
294
+ },
295
+ ]);
296
+
297
+ expect(devices).toHaveLength(1);
298
+ expect(devices[0]).toMatchObject({ id: 'AA:BB:CC:00:00:01', bleColorCode: 'E' });
299
+ });
300
+
301
+ test('reports no color for legacy, unset or undecodable payloads', async () => {
302
+ const devices = await scanOnce([
303
+ {
304
+ id: 'LEGACY-NONCE',
305
+ name: 'Pro 2 0001',
306
+ serviceUUIDs: PRO2_SERVICE_UUIDS,
307
+ manufacturerData: manufacturerData([0, 0, 0, 0]),
308
+ },
309
+ {
310
+ id: 'SN-NOT-SYNCED',
311
+ name: 'Pro 2 0002',
312
+ serviceUUIDs: PRO2_SERVICE_UUIDS,
313
+ manufacturerData: manufacturerData([0, 0, 0, 0, 0]),
314
+ },
315
+ {
316
+ id: 'INVALID-BASE64',
317
+ name: 'Pro 2 0003',
318
+ serviceUUIDs: PRO2_SERVICE_UUIDS,
319
+ manufacturerData: '%%%',
320
+ },
321
+ ]);
322
+
323
+ expect(devices.map(device => device.id)).toEqual([
324
+ 'LEGACY-NONCE',
325
+ 'SN-NOT-SYNCED',
326
+ 'INVALID-BASE64',
327
+ ]);
328
+ devices.forEach(device => expect(device).not.toHaveProperty('bleColorCode'));
329
+ });
330
+
331
+ test('reuses an earlier color for a connected peripheral that no longer advertises', async () => {
332
+ await scanOnce([
333
+ {
334
+ id: 'CONNECTED-NEO',
335
+ name: 'Neo 3C4D',
336
+ serviceUUIDs: PRO2_SERVICE_UUIDS,
337
+ manufacturerData: manufacturerData([0x46, 0, 0, 0, 0]),
338
+ },
339
+ ]);
340
+ // iOS reports already-connected peripherals with lowercased ids.
341
+ jest.mocked(getConnectedDeviceIds).mockResolvedValueOnce([
342
+ {
343
+ id: 'connected-neo',
344
+ name: 'Neo 3C4D',
345
+ localName: null,
346
+ serviceUUIDs: [ONEKEY_SERVICE_UUID],
347
+ },
348
+ ] as never);
349
+
350
+ const devices = await scanOnce([]);
351
+
352
+ expect(devices).toHaveLength(1);
353
+ expect(devices[0]).toMatchObject({ id: 'connected-neo', bleColorCode: 'F' });
354
+ });
355
+ });
@@ -821,7 +821,7 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
821
821
 
822
822
  const acquiring = transport.acquire({ uuid });
823
823
  const failure = expect(acquiring).rejects.toMatchObject({
824
- errorCode: HardwareErrorCode.BleTimeoutError,
824
+ errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
825
825
  });
826
826
  const reconnecting = transport.acquire({ uuid, expectedProtocol: 'V2' });
827
827
 
@@ -860,7 +860,8 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
860
860
  jest.spyOn(transport as any, 'probeProtocolV2').mockResolvedValue(false);
861
861
 
862
862
  await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
863
- errorCode: HardwareErrorCode.RuntimeError,
863
+ errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
864
+ params: { expectedProtocol: 'V2' },
864
865
  });
865
866
 
866
867
  expect(device.cancelConnection).toHaveBeenCalledTimes(1);
@@ -876,10 +877,12 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
876
877
  jest.spyOn(transport as any, 'probeProtocolV2').mockResolvedValue(false);
877
878
 
878
879
  await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
879
- errorCode: HardwareErrorCode.RuntimeError,
880
+ errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
881
+ params: { expectedProtocol: 'V2' },
880
882
  });
881
883
  await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
882
- errorCode: HardwareErrorCode.RuntimeError,
884
+ errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
885
+ params: { expectedProtocol: 'V2' },
883
886
  });
884
887
 
885
888
  expect(device.cancelConnection).toHaveBeenCalledTimes(2);
@@ -897,7 +900,8 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
897
900
  jest.spyOn(transport as any, 'probeProtocolV2').mockResolvedValue(false);
898
901
 
899
902
  await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
900
- errorCode: HardwareErrorCode.RuntimeError,
903
+ errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
904
+ params: { expectedProtocol: 'V2' },
901
905
  });
902
906
 
903
907
  expect(device.cancelConnection).toHaveBeenCalledTimes(1);
@@ -1732,7 +1736,7 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
1732
1736
 
1733
1737
  await expect(transport.acquire({ uuid })).rejects.toBeDefined();
1734
1738
  await expect(transport.acquire({ uuid })).rejects.toMatchObject({
1735
- errorCode: HardwareErrorCode.BleTimeoutError,
1739
+ errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
1736
1740
  });
1737
1741
  await transport.disconnect(uuid);
1738
1742
  await transport.stop();
@@ -1840,7 +1844,7 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
1840
1844
  jest.spyOn(transport as any, 'probeProtocolV1').mockResolvedValue(false);
1841
1845
 
1842
1846
  await expect(transport.acquire({ uuid, protocolHint: 'V2' })).rejects.toMatchObject({
1843
- errorCode: HardwareErrorCode.BleTimeoutError,
1847
+ errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
1844
1848
  });
1845
1849
 
1846
1850
  expect(device.onDisconnected).not.toHaveBeenCalled();
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  import ByteBuffer from 'bytebuffer';
11
11
  import transport, {
12
12
  type OneKeyDeviceInfoBase,
13
+ type OneKeyMobileDeviceInfo,
13
14
  PROTOCOL_V1_MESSAGE_HEADER_SIZE,
14
15
  PROTOCOL_V2_BLE_FRAME_MAX_BYTES,
15
16
  PROTOCOL_V2_CHANNEL_BLE_UART,
@@ -28,6 +29,7 @@ import {
28
29
  HardwareErrorCode,
29
30
  createDeferred,
30
31
  isOnekeyBluetoothDevice,
32
+ parseOnekeyBleColorCode,
31
33
  } from '@onekeyfe/hd-shared';
32
34
 
33
35
  import { getConnectedDeviceIds, onDeviceBondState, pairDevice } from './BleManager';
@@ -234,6 +236,34 @@ function getDeviceDisplayName(device?: Device | null) {
234
236
  return device?.name || device?.localName || null;
235
237
  }
236
238
 
239
+ // The color is only in the primary advertisement, and the name only in the scan
240
+ // response, so the callback a scan keeps may not carry it. A connected device stops
241
+ // advertising. Keep the last valid color per device for the life of the process.
242
+ // iOS reports connected peripherals with lowercased ids, so key case-insensitively.
243
+ const bleColorCodesById = new Map<string, string>();
244
+
245
+ function getManufacturerDataLength(device?: Device | null) {
246
+ return device?.manufacturerData ? Buffer.from(device.manufacturerData, 'base64').length : 0;
247
+ }
248
+
249
+ function rememberBleColorCode(device?: Device | null) {
250
+ if (!device?.id || !device.manufacturerData) return;
251
+ const colorCode = parseOnekeyBleColorCode(Buffer.from(device.manufacturerData, 'base64'));
252
+ const key = device.id.toLowerCase();
253
+ if (colorCode && bleColorCodesById.get(key) !== colorCode) {
254
+ bleColorCodesById.set(key, colorCode);
255
+ Log?.debug('[ReactNativeBleTransport] BLE color code', {
256
+ deviceId: device.id,
257
+ bleColorCode: colorCode,
258
+ });
259
+ }
260
+ }
261
+
262
+ function withBleColorCode(device: IOneKeyDevice): IOneKeyDevice {
263
+ const bleColorCode = bleColorCodesById.get(device.id.toLowerCase());
264
+ return bleColorCode ? ({ ...device, bleColorCode } as IOneKeyDevice) : device;
265
+ }
266
+
237
267
  const IOS_REQUEST_MTU = 247;
238
268
  const ANDROID_REQUEST_MTU = 517;
239
269
  const ANDROID_HIGH_PRIORITY_IDLE_MS = 1000;
@@ -356,7 +386,9 @@ const isMtuOrCancelledConnectError = (error: unknown): boolean => {
356
386
 
357
387
  type NegotiatedMtuResult = { device: Device; timedOut: boolean };
358
388
 
359
- export type IOneKeyDevice = OneKeyDeviceInfoBase & Device;
389
+ export type IOneKeyDevice = OneKeyDeviceInfoBase &
390
+ Device &
391
+ Pick<OneKeyMobileDeviceInfo, 'bleColorCode'>;
360
392
 
361
393
  const tryToGetConfiguration = (device: Device) => {
362
394
  if (!device || !device.serviceUUIDs) return null;
@@ -855,7 +887,7 @@ export default class ReactNativeBleTransport {
855
887
  }).then(() => {
856
888
  this.scanCleanups.delete(cancelScan);
857
889
  if (error) reject(error);
858
- else resolve(deviceList);
890
+ else resolve(deviceList.map(withBleColorCode));
859
891
  });
860
892
  return scanCleanup;
861
893
  };
@@ -900,6 +932,9 @@ export default class ReactNativeBleTransport {
900
932
  return;
901
933
  }
902
934
 
935
+ // The native scan is filtered to the OneKey communication service, so an
936
+ // unnamed iOS advertisement rejected below can still carry the color.
937
+ rememberBleColorCode(device);
903
938
  const displayName = getDeviceDisplayName(device);
904
939
  // iOS may report a service-only advertisement before the named scan response.
905
940
  // Do not cache that incomplete advertisement as an unknown device.
@@ -965,6 +1000,9 @@ export default class ReactNativeBleTransport {
965
1000
  deviceId: device.id,
966
1001
  name: displayName,
967
1002
  serviceUUIDs: device.serviceUUIDs,
1003
+ // 5 = advertises a color slot; 4 = BLE firmware before 1.0.23.
1004
+ manufacturerDataLength: getManufacturerDataLength(device),
1005
+ bleColorCode: bleColorCodesById.get(device.id.toLowerCase()),
968
1006
  });
969
1007
  }
970
1008
  };
@@ -2520,17 +2558,13 @@ export default class ReactNativeBleTransport {
2520
2558
  private createProtocolMismatchError(expected: ProtocolType) {
2521
2559
  // A protocol probe miss alone does not prove that the OS bond is stale.
2522
2560
  // Native authentication/encryption failures are mapped separately.
2523
- return ERRORS.TypedError(
2524
- HardwareErrorCode.RuntimeError,
2525
- `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`
2526
- );
2561
+ return ERRORS.TypedError(HardwareErrorCode.TransportProtocolProbeFailed, undefined, {
2562
+ expectedProtocol: expected,
2563
+ });
2527
2564
  }
2528
2565
 
2529
2566
  private createProtocolDetectionError() {
2530
- return ERRORS.TypedError(
2531
- HardwareErrorCode.BleTimeoutError,
2532
- 'Unable to detect BLE protocol: device did not respond to Protocol V1 GetFeatures or Protocol V2 Ping'
2533
- );
2567
+ return ERRORS.TypedError(HardwareErrorCode.TransportProtocolProbeFailed);
2534
2568
  }
2535
2569
 
2536
2570
  private clearProbeProtocol(uuid: string, protocol: ProtocolType) {