@onekeyfe/hd-transport-react-native 1.2.2-alpha.100 → 1.2.2-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.
@@ -0,0 +1,5 @@
1
+ import { isBleStaleBondHardwareError } from '@onekeyfe/hd-shared';
2
+ export { isBleStaleBondHardwareError };
3
+ export declare const isNativeBleStaleBondError: (error: unknown) => boolean;
4
+ export declare const toBleStaleBondHardwareError: (error: unknown) => Error;
5
+ //# sourceMappingURL=bleStaleBond.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bleStaleBond.d.ts","sourceRoot":"","sources":["../src/bleStaleBond.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,2BAA2B,EAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,2BAA2B,EAAE,CAAC;AAmBvC,eAAO,MAAM,yBAAyB,UAAW,OAAO,KAAG,OAiB1D,CAAC;AAEF,eAAO,MAAM,2BAA2B,UAAW,OAAO,UAkBzD,CAAC"}
@@ -11,7 +11,7 @@ export declare function resolveProtocolV2PacketCapacity({ platform, iosPacketLen
11
11
  mtu?: number | null;
12
12
  }): number;
13
13
  export declare function shouldRefreshNegotiatedMtu(mtu?: number | null): boolean;
14
- export declare function shouldWriteProtocolV2WithResponse({ platform, highThroughput, requestedWithResponse, characteristic, }: {
14
+ export declare function shouldWriteProtocolV2WithResponse({ requestedWithResponse, characteristic, }: {
15
15
  platform: BlePlatform;
16
16
  highThroughput: boolean;
17
17
  requestedWithResponse?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"bleStrategy.d.ts","sourceRoot":"","sources":["../src/bleStrategy.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC;AAErD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,sBAAsB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACxC,yBAAyB,CAAC,EAA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MAAM,GAAG,IAAI,CAAC;CACrB,UAMA;AAED,wBAAgB,0BAA0B,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,WAE7D;AAED,wBAAgB,iCAAiC,CAAC,EAChD,qBAAqB,EACrB,cAAc,GACf,EAAE;IACD,QAAQ,EAAE,WAAW,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,cAAc,EAAE,kBAAkB,CAAC;CACpC,WAIA"}
package/dist/index.d.ts CHANGED
@@ -38,6 +38,14 @@ type BleAcquireInput = {
38
38
  protocolHint?: ProtocolType;
39
39
  };
40
40
 
41
+ type FirmwareInstallBleAcquireInput = BleAcquireInput & {
42
+ /**
43
+ * Reuse the already-verified protocol after an expected firmware-install
44
+ * disconnect. The install loader accepts status requests but may not answer
45
+ * the generic protocol probe used by a normal acquire.
46
+ */
47
+ skipProtocolProbe?: boolean;
48
+ };
41
49
  type FirmwareUploadWriteRetryType = 'congested';
42
50
  type ResolvedBleCharacteristics = {
43
51
  writeCharacteristic: Characteristic;
@@ -126,6 +134,14 @@ declare class ReactNativeBleTransport {
126
134
  private confirmedProtocolV2;
127
135
  /** Consecutive detections that failed while trusting sessionProtocols. */
128
136
  private protocolReprobeFailures;
137
+ /**
138
+ * Native encryption/pairing failures seen before Protocol V2 probe starts.
139
+ * Pro2/Neo GATT connect can succeed on a stale iOS bond; the CCCD write then
140
+ * fails with ATT 5/15. Remember it so detectProtocol fails immediately.
141
+ */
142
+ private staleBondErrors;
143
+ /** Strict or previously confirmed V2 target while acquire installs notifications. */
144
+ private acquiringProtocolV2;
129
145
  private protocolV2Assemblers;
130
146
  private protocolV2FrameQueues;
131
147
  private protocolV2FramePromises;
@@ -155,7 +171,7 @@ declare class ReactNativeBleTransport {
155
171
  */
156
172
  enumerate(): Promise<IOneKeyDevice[]>;
157
173
  private installTransportForAcquire;
158
- acquire(input: BleAcquireInput): Promise<{
174
+ acquire(input: FirmwareInstallBleAcquireInput): Promise<{
159
175
  uuid: string;
160
176
  protocolType: ProtocolType;
161
177
  }>;
@@ -216,6 +232,8 @@ declare class ReactNativeBleTransport {
216
232
  private resolveProtocolV2Frame;
217
233
  private resetProtocolV2Frames;
218
234
  private rejectProtocolV2Frames;
235
+ private rememberStaleBondError;
236
+ private throwIfStaleBondError;
219
237
  private readProtocolV2Frame;
220
238
  private writeProtocolV2Packet;
221
239
  private writeProtocolV2Frame;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAIL,UAAU,IAAI,aAAa,EAG5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAChB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAI1B,MAAM,wBAAwB,CAAC;AA0BhC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAI1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAgBjE,KAAK,4BAA4B,GAAG,WAAW,CAAC;AAChD,KAAK,0BAA0B,GAAG;IAChC,mBAAmB,EAAE,cAAc,CAAC;IACpC,oBAAoB,EAAE,cAAc,CAAC;CACtC,CAAC;AAkCF,eAAO,MAAM,+BAA+B,UACnC,OAAO,KACb,4BAA4B,GAAG,IAsBjC,CAAC;AAcF,eAAO,MAAM,2BAA2B,QAAS,CAAC;AAClD,eAAO,MAAM,8BAA8B,OAAQ,CAAC;AAOpD,eAAO,MAAM,yCAAyC,IAAI,CAAC;AAI3D,MAAM,MAAM,mBAAmB,GAAG;IAChC,eAAe,CAAC,EAAE,MAAM,CA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AC,4BAA4B;YAQtB,qBAAqB;IAoBnC,MAAM;YAUQ,kBAAkB;YAwClB,iCAAiC;IA+C/C,OAAO,CAAC,wBAAwB;IAoChC,OAAO,CAAC,yBAAyB;IAMjC,OAAO,CAAC,kBAAkB;YAcZ,cAAc;IA8C5B,OAAO,CAAC,kBAAkB;IA+B1B,OAAO,CAAC,eAAe;IAsDvB,OAAO,CAAC,2BAA2B;IASnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,iBAAiB;YAIX,cAAc;YAuGd,iCAAiC;YAoDjC,eAAe;YAwBf,eAAe;IA4B7B,OAAO,CAAC,4BAA4B;IA2BpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,sBAAsB;IAS9B,OAAO,CAAC,sBAAsB;IAQ9B,OAAO,CAAC,qBAAqB;YAOf,mBAAmB;YAiBnB,qBAAqB;YAgErB,oBAAoB;YAgCpB,cAAc;YAqEd,iCAAiC;IAiB/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
@@ -144,12 +144,12 @@ function resolveProtocolV2PacketCapacity({ platform, iosPacketLength = IOS_PROTO
144
144
  function shouldRefreshNegotiatedMtu(mtu) {
145
145
  return typeof mtu !== 'number' || !Number.isFinite(mtu) || mtu <= 23;
146
146
  }
147
- function shouldWriteProtocolV2WithResponse({ platform, highThroughput, requestedWithResponse, characteristic, }) {
147
+ function shouldWriteProtocolV2WithResponse({ requestedWithResponse, characteristic, }) {
148
148
  if (!characteristic.isWritableWithResponse)
149
149
  return false;
150
150
  if (!characteristic.isWritableWithoutResponse)
151
151
  return true;
152
- return requestedWithResponse === true || (platform === 'ios' && !highThroughput);
152
+ return requestedWithResponse === true;
153
153
  }
154
154
 
155
155
  const timer = process.env.NODE_ENV === 'development'
@@ -194,6 +194,40 @@ const subscribeBleOn = (bleManager, ms = 1000) => new Promise((resolve, reject)
194
194
  }, ms);
195
195
  });
196
196
 
197
+ const ATT_INSUFFICIENT_AUTHENTICATION = 5;
198
+ const ATT_INSUFFICIENT_ENCRYPTION = 15;
199
+ const IOS_PEER_REMOVED_PAIRING_INFORMATION = 14;
200
+ const nativeErrorText = (error) => [error.reason, error.message]
201
+ .filter((value) => typeof value === 'string')
202
+ .join(' ');
203
+ const isNativeBleStaleBondError = (error) => {
204
+ if (!error || typeof error !== 'object') {
205
+ return typeof error === 'string' ? hdShared.isBleStaleBondErrorText(error) : false;
206
+ }
207
+ const nativeError = error;
208
+ if (nativeError.attErrorCode === ATT_INSUFFICIENT_AUTHENTICATION ||
209
+ nativeError.attErrorCode === ATT_INSUFFICIENT_ENCRYPTION ||
210
+ nativeError.androidErrorCode === ATT_INSUFFICIENT_AUTHENTICATION ||
211
+ nativeError.androidErrorCode === ATT_INSUFFICIENT_ENCRYPTION ||
212
+ nativeError.iosErrorCode === IOS_PEER_REMOVED_PAIRING_INFORMATION) {
213
+ return true;
214
+ }
215
+ return hdShared.isBleStaleBondErrorText(nativeErrorText(nativeError));
216
+ };
217
+ const toBleStaleBondHardwareError = (error) => {
218
+ if (hdShared.isBleStaleBondHardwareError(error)) {
219
+ return error;
220
+ }
221
+ const nativeError = (error !== null && error !== void 0 ? error : {});
222
+ const text = nativeErrorText(nativeError);
223
+ const normalizedText = text.toLowerCase();
224
+ const peerRemoved = nativeError.iosErrorCode === IOS_PEER_REMOVED_PAIRING_INFORMATION ||
225
+ normalizedText.includes('peer removed pairing information');
226
+ return hdShared.ERRORS.TypedError(peerRemoved
227
+ ? hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation
228
+ : hdShared.HardwareErrorCode.BleDeviceBondError, text || undefined);
229
+ };
230
+
197
231
  const isHeaderChunk = (chunk) => {
198
232
  if (chunk.length < 9)
199
233
  return false;
@@ -375,9 +409,8 @@ const resolveNegotiatedMtu = (device) => requestNegotiatedMtu(device, 'connected
375
409
  function remapError(error) {
376
410
  var _a;
377
411
  if (error instanceof reactNativeBlePlx.BleError) {
378
- if (error.iosErrorCode === reactNativeBlePlx.BleATTErrorCode.UnlikelyError ||
379
- error.reason === 'Peer removed pairing information') {
380
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation);
412
+ if (isNativeBleStaleBondError(error)) {
413
+ throw toBleStaleBondHardwareError(error);
381
414
  }
382
415
  if ((error === null || error === void 0 ? void 0 : error.attErrorCode) === 22) {
383
416
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceBondError);
@@ -408,6 +441,8 @@ class ReactNativeBleTransport {
408
441
  this.sessionProtocols = new Map();
409
442
  this.confirmedProtocolV2 = new Set();
410
443
  this.protocolReprobeFailures = new Map();
444
+ this.staleBondErrors = new Map();
445
+ this.acquiringProtocolV2 = new Set();
411
446
  this.protocolV2Assemblers = new Map();
412
447
  this.protocolV2FrameQueues = new Map();
413
448
  this.protocolV2FramePromises = new Map();
@@ -802,19 +837,46 @@ class ReactNativeBleTransport {
802
837
  acquireUnlocked(input) {
803
838
  var _a;
804
839
  return __awaiter(this, void 0, void 0, function* () {
805
- const { uuid, forceCleanRunPromise, expectedProtocol } = input;
840
+ const { uuid, forceCleanRunPromise, expectedProtocol, skipProtocolProbe } = input;
841
+ const shouldMapProtocolV2StaleBond = expectedProtocol
842
+ ? expectedProtocol === 'V2'
843
+ : this.confirmedProtocolV2.has(uuid);
806
844
  const cachedTransport = transportCache[uuid];
845
+ if (skipProtocolProbe && !cachedTransport && this.blePlxManager) {
846
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] refresh uncached BLE connection for firmware install:', uuid);
847
+ const manager = this.blePlxManager;
848
+ yield this.runNativeTeardown(uuid, manager, () => __awaiter(this, void 0, void 0, function* () {
849
+ yield this.runBestEffortNativeOperation('firmware install reconnect: cancel uncached device connection', () => manager.cancelDeviceConnection(uuid));
850
+ }));
851
+ }
807
852
  if (cachedTransport) {
808
- const cachedProtocol = this.deviceProtocol.get(uuid);
809
- const isCachedDeviceConnected = yield cachedTransport.device.isConnected().catch(() => false);
810
- if (isCachedDeviceConnected &&
811
- cachedProtocol &&
812
- (!expectedProtocol || cachedProtocol === expectedProtocol)) {
813
- Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] reuse cached BLE transport:', uuid, cachedProtocol);
814
- return { uuid, protocolType: cachedProtocol };
853
+ if (skipProtocolProbe) {
854
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] refresh cached BLE connection for firmware install:', uuid);
855
+ const manager = this.blePlxManager;
856
+ yield this.releaseUnlocked(uuid, true);
857
+ yield this.runNativeTeardown(uuid, manager, () => __awaiter(this, void 0, void 0, function* () {
858
+ const operations = [];
859
+ if (manager) {
860
+ operations.push(this.runBestEffortNativeOperation('firmware install reconnect: cancel device connection', () => manager.cancelDeviceConnection(uuid)));
861
+ }
862
+ operations.push(this.runBestEffortNativeOperation('firmware install reconnect: device cancel connection', () => cachedTransport.device.cancelConnection()));
863
+ yield Promise.all(operations);
864
+ }));
865
+ }
866
+ else {
867
+ const cachedProtocol = this.deviceProtocol.get(uuid);
868
+ const isCachedDeviceConnected = yield cachedTransport.device
869
+ .isConnected()
870
+ .catch(() => false);
871
+ if (isCachedDeviceConnected &&
872
+ cachedProtocol &&
873
+ (!expectedProtocol || cachedProtocol === expectedProtocol)) {
874
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] reuse cached BLE transport:', uuid, cachedProtocol);
875
+ return { uuid, protocolType: cachedProtocol };
876
+ }
877
+ Log === null || Log === void 0 ? void 0 : Log.debug('transport not reusable, will release: ', uuid);
878
+ yield this.releaseUnlocked(uuid, true);
815
879
  }
816
- Log === null || Log === void 0 ? void 0 : Log.debug('transport not reusable, will release: ', uuid);
817
- yield this.releaseUnlocked(uuid, true);
818
880
  }
819
881
  let device = null;
820
882
  if (forceCleanRunPromise && this.runPromise) {
@@ -832,15 +894,6 @@ class ReactNativeBleTransport {
832
894
  Log === null || Log === void 0 ? void 0 : Log.debug('subscribeBleOn error: ', error);
833
895
  throw error;
834
896
  }
835
- if (reactNative.Platform.OS === 'android') {
836
- const bondState = yield pairDevice(uuid);
837
- if (bondState.bonding) {
838
- yield onDeviceBondState(uuid);
839
- }
840
- else if (!bondState.bonded) {
841
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
842
- }
843
- }
844
897
  if (!device) {
845
898
  const devices = yield blePlxManager.devices([uuid]);
846
899
  [device] = devices;
@@ -909,6 +962,27 @@ class ReactNativeBleTransport {
909
962
  }
910
963
  }
911
964
  }
965
+ if (reactNative.Platform.OS === 'android') {
966
+ const connectedDevice = device;
967
+ try {
968
+ const bondState = yield pairDevice(uuid);
969
+ if (bondState.bonding) {
970
+ yield onDeviceBondState(uuid);
971
+ }
972
+ else if (!bondState.bonded) {
973
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
974
+ }
975
+ }
976
+ catch (error) {
977
+ yield this.runNativeTeardown(uuid, blePlxManager, () => __awaiter(this, void 0, void 0, function* () {
978
+ yield Promise.all([
979
+ this.runBestEffortNativeOperation('bond failure: cancel manager connection', () => blePlxManager.cancelDeviceConnection(uuid)),
980
+ this.runBestEffortNativeOperation('bond failure: cancel device connection', () => connectedDevice.cancelConnection()),
981
+ ]);
982
+ }));
983
+ throw error;
984
+ }
985
+ }
912
986
  device = yield resolveNegotiatedMtu(device);
913
987
  const acquiredDevice = device;
914
988
  const { writeCharacteristic, notifyCharacteristic } = yield this.resolveCharacteristicsWithTimeout(uuid, acquiredDevice);
@@ -919,11 +993,38 @@ class ReactNativeBleTransport {
919
993
  if (protocolHint) {
920
994
  this.deviceProtocolHints.set(uuid, protocolHint);
921
995
  }
922
- yield this.installTransportForAcquire(uuid, acquiredDevice, {
923
- writeCharacteristic,
924
- notifyCharacteristic,
925
- });
996
+ if (shouldMapProtocolV2StaleBond) {
997
+ this.acquiringProtocolV2.add(uuid);
998
+ }
926
999
  try {
1000
+ yield this.installTransportForAcquire(uuid, acquiredDevice, {
1001
+ writeCharacteristic,
1002
+ notifyCharacteristic,
1003
+ });
1004
+ if (skipProtocolProbe) {
1005
+ if (!expectedProtocol) {
1006
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'skipProtocolProbe requires an expected BLE protocol');
1007
+ }
1008
+ const hasConfirmedProtocol = this.sessionProtocols.get(uuid) === expectedProtocol ||
1009
+ (expectedProtocol === 'V2' && this.confirmedProtocolV2.has(uuid));
1010
+ if (!hasConfirmedProtocol) {
1011
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'skipProtocolProbe requires a previously confirmed protocol for this BLE endpoint');
1012
+ }
1013
+ this.deviceProtocol.set(uuid, expectedProtocol);
1014
+ this.sessionProtocols.set(uuid, expectedProtocol);
1015
+ this.protocolReprobeFailures.delete(uuid);
1016
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol selected without probe', {
1017
+ deviceId: uuid,
1018
+ protocol: expectedProtocol,
1019
+ source: 'firmware-install-reconnect',
1020
+ });
1021
+ const currentTransport = transportCache[uuid];
1022
+ if (!currentTransport) {
1023
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotFound);
1024
+ }
1025
+ this.attachDisconnectSubscription(currentTransport, currentTransport.device, uuid);
1026
+ return { uuid, protocolType: expectedProtocol };
1027
+ }
927
1028
  const protocolType = yield this.detectProtocol(uuid, expectedProtocol, protocolHint, () => __awaiter(this, void 0, void 0, function* () {
928
1029
  yield this.installTransportForAcquire(uuid, acquiredDevice);
929
1030
  }));
@@ -935,7 +1036,7 @@ class ReactNativeBleTransport {
935
1036
  return { uuid, protocolType };
936
1037
  }
937
1038
  catch (error) {
938
- if ((error === null || error === void 0 ? void 0 : error.errorCode) === hdShared.HardwareErrorCode.BleDeviceBondError) {
1039
+ if (hdShared.isBleStaleBondHardwareError(error)) {
939
1040
  yield this.disconnectUnlocked(uuid);
940
1041
  }
941
1042
  else {
@@ -943,13 +1044,16 @@ class ReactNativeBleTransport {
943
1044
  }
944
1045
  throw error;
945
1046
  }
1047
+ finally {
1048
+ this.acquiringProtocolV2.delete(uuid);
1049
+ }
946
1050
  });
947
1051
  }
948
1052
  _monitorCharacteristic(characteristic, uuid, monitorToken, notifyTransactionId) {
949
1053
  let bufferLength = 0;
950
1054
  let buffer$1 = [];
951
1055
  const subscription = characteristic.monitor((error, c) => {
952
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
1056
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
953
1057
  const isCurrentMonitor = this.monitorTokens.get(uuid) === monitorToken;
954
1058
  if (error) {
955
1059
  Log === null || Log === void 0 ? void 0 : Log.debug(`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${error}`);
@@ -961,19 +1065,21 @@ class ReactNativeBleTransport {
961
1065
  Log === null || Log === void 0 ? void 0 : Log.debug('monitor error ignored for stale transport: ', uuid, notifyTransactionId);
962
1066
  return;
963
1067
  }
1068
+ if ((this.getActiveProtocol(uuid) === 'V2' || this.acquiringProtocolV2.has(uuid)) &&
1069
+ isNativeBleStaleBondError(error)) {
1070
+ this.rememberStaleBondError(uuid, toBleStaleBondHardwareError(error));
1071
+ return;
1072
+ }
964
1073
  if (this.getActiveProtocol(uuid) === 'V2') {
965
1074
  let errorCode = hdShared.HardwareErrorCode.BleCharacteristicNotifyError;
966
1075
  if ((_a = error.reason) === null || _a === void 0 ? void 0 : _a.includes('The connection has timed out unexpectedly')) {
967
1076
  errorCode = hdShared.HardwareErrorCode.BleTimeoutError;
968
1077
  }
969
- else if ((_b = error.reason) === null || _b === void 0 ? void 0 : _b.includes('Encryption is insufficient')) {
970
- errorCode = hdShared.HardwareErrorCode.BleDeviceBondError;
971
- }
972
- else if (((_c = error.reason) === null || _c === void 0 ? void 0 : _c.includes('Cannot write client characteristic config descriptor')) ||
973
- ((_d = error.reason) === null || _d === void 0 ? void 0 : _d.includes('Cannot find client characteristic config descriptor')) ||
974
- ((_e = error.reason) === null || _e === void 0 ? void 0 : _e.includes('The handle is invalid')) ||
975
- ((_f = error.reason) === null || _f === void 0 ? void 0 : _f.includes('Writing is not permitted')) ||
976
- ((_g = error.reason) === null || _g === void 0 ? void 0 : _g.includes('notify change failed for device'))) {
1078
+ else if (((_b = error.reason) === null || _b === void 0 ? void 0 : _b.includes('Cannot write client characteristic config descriptor')) ||
1079
+ ((_c = error.reason) === null || _c === void 0 ? void 0 : _c.includes('Cannot find client characteristic config descriptor')) ||
1080
+ ((_d = error.reason) === null || _d === void 0 ? void 0 : _d.includes('The handle is invalid')) ||
1081
+ ((_e = error.reason) === null || _e === void 0 ? void 0 : _e.includes('Writing is not permitted')) ||
1082
+ ((_f = error.reason) === null || _f === void 0 ? void 0 : _f.includes('notify change failed for device'))) {
977
1083
  errorCode = hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure;
978
1084
  }
979
1085
  this.rejectProtocolV2Frames(uuid, hdShared.ERRORS.TypedError(errorCode));
@@ -981,17 +1087,14 @@ class ReactNativeBleTransport {
981
1087
  }
982
1088
  if (this.runPromise && this.runPromiseDeviceId === uuid) {
983
1089
  let ERROR = hdShared.HardwareErrorCode.BleCharacteristicNotifyError;
984
- if ((_h = error.reason) === null || _h === void 0 ? void 0 : _h.includes('The connection has timed out unexpectedly')) {
1090
+ if ((_g = error.reason) === null || _g === void 0 ? void 0 : _g.includes('The connection has timed out unexpectedly')) {
985
1091
  ERROR = hdShared.HardwareErrorCode.BleTimeoutError;
986
1092
  }
987
- if ((_j = error.reason) === null || _j === void 0 ? void 0 : _j.includes('Encryption is insufficient')) {
988
- ERROR = hdShared.HardwareErrorCode.BleDeviceBondError;
989
- }
990
- if (((_k = error.reason) === null || _k === void 0 ? void 0 : _k.includes('Cannot write client characteristic config descriptor')) ||
991
- ((_l = error.reason) === null || _l === void 0 ? void 0 : _l.includes('Cannot find client characteristic config descriptor')) ||
992
- ((_m = error.reason) === null || _m === void 0 ? void 0 : _m.includes('The handle is invalid')) ||
993
- ((_o = error.reason) === null || _o === void 0 ? void 0 : _o.includes('Writing is not permitted')) ||
994
- ((_p = error.reason) === null || _p === void 0 ? void 0 : _p.includes('notify change failed for device'))) {
1093
+ if (((_h = error.reason) === null || _h === void 0 ? void 0 : _h.includes('Cannot write client characteristic config descriptor')) ||
1094
+ ((_j = error.reason) === null || _j === void 0 ? void 0 : _j.includes('Cannot find client characteristic config descriptor')) ||
1095
+ ((_k = error.reason) === null || _k === void 0 ? void 0 : _k.includes('The handle is invalid')) ||
1096
+ ((_l = error.reason) === null || _l === void 0 ? void 0 : _l.includes('Writing is not permitted')) ||
1097
+ ((_m = error.reason) === null || _m === void 0 ? void 0 : _m.includes('notify change failed for device'))) {
995
1098
  const notifyError = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure);
996
1099
  this.runPromise.reject(notifyError);
997
1100
  Log === null || Log === void 0 ? void 0 : Log.debug(`${hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure} ${error.message} ${error.reason}`);
@@ -1033,7 +1136,7 @@ class ReactNativeBleTransport {
1033
1136
  bufferLength = 0;
1034
1137
  buffer$1 = [];
1035
1138
  if (this.runPromiseDeviceId === uuid) {
1036
- (_q = this.runPromise) === null || _q === void 0 ? void 0 : _q.resolve(value.toString('hex'));
1139
+ (_o = this.runPromise) === null || _o === void 0 ? void 0 : _o.resolve(value.toString('hex'));
1037
1140
  }
1038
1141
  }
1039
1142
  }
@@ -1044,7 +1147,7 @@ class ReactNativeBleTransport {
1044
1147
  this.rejectProtocolV2Frames(uuid, notifyError);
1045
1148
  }
1046
1149
  else if (this.runPromiseDeviceId === uuid) {
1047
- (_r = this.runPromise) === null || _r === void 0 ? void 0 : _r.reject(notifyError);
1150
+ (_p = this.runPromise) === null || _p === void 0 ? void 0 : _p.reject(notifyError);
1048
1151
  }
1049
1152
  }
1050
1153
  }, notifyTransactionId);
@@ -1098,6 +1201,8 @@ class ReactNativeBleTransport {
1098
1201
  this.protocolV2HighVolumeLogSignatures.delete(uuid);
1099
1202
  this.deviceProtocol.delete(uuid);
1100
1203
  this.probingProtocols.delete(uuid);
1204
+ this.staleBondErrors.delete(uuid);
1205
+ this.acquiringProtocolV2.delete(uuid);
1101
1206
  (_e = this.protocolV2Assemblers.get(uuid)) === null || _e === void 0 ? void 0 : _e.reset();
1102
1207
  this.protocolV2Assemblers.delete(uuid);
1103
1208
  this.resetProtocolV2Frames(uuid);
@@ -1383,6 +1488,7 @@ class ReactNativeBleTransport {
1383
1488
  }
1384
1489
  this.deviceProtocol.delete(session);
1385
1490
  this.probingProtocols.delete(session);
1491
+ this.staleBondErrors.delete(session);
1386
1492
  this.deviceProtocolHints.delete(session);
1387
1493
  this.sessionProtocols.delete(session);
1388
1494
  this.protocolReprobeFailures.delete(session);
@@ -1561,6 +1667,8 @@ class ReactNativeBleTransport {
1561
1667
  }
1562
1668
  this.deviceProtocol.delete(uuid);
1563
1669
  this.probingProtocols.delete(uuid);
1670
+ this.staleBondErrors.delete(uuid);
1671
+ this.acquiringProtocolV2.delete(uuid);
1564
1672
  this.protocolV2Assemblers.delete(uuid);
1565
1673
  this.resetProtocolV2Frames(uuid);
1566
1674
  if (timeouts >= BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD) {
@@ -1630,6 +1738,8 @@ class ReactNativeBleTransport {
1630
1738
  }
1631
1739
  this.deviceProtocol.delete(uuid);
1632
1740
  this.probingProtocols.delete(uuid);
1741
+ this.staleBondErrors.delete(uuid);
1742
+ this.acquiringProtocolV2.delete(uuid);
1633
1743
  this.protocolV2Assemblers.delete(uuid);
1634
1744
  this.resetProtocolV2Frames(uuid);
1635
1745
  if (timeouts >= BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD) {
@@ -1672,8 +1782,9 @@ class ReactNativeBleTransport {
1672
1782
  });
1673
1783
  this.deviceProtocol.clear();
1674
1784
  this.probingProtocols.clear();
1785
+ this.staleBondErrors.clear();
1786
+ this.acquiringProtocolV2.clear();
1675
1787
  this.sessionProtocols.clear();
1676
- this.confirmedProtocolV2.clear();
1677
1788
  this.protocolReprobeFailures.clear();
1678
1789
  this.writeTimeoutCounts.clear();
1679
1790
  this.connectionSetupTimeoutCounts.clear();
@@ -1686,9 +1797,8 @@ class ReactNativeBleTransport {
1686
1797
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE manager destroy failed (ignored):', error);
1687
1798
  }
1688
1799
  }
1689
- createProtocolMismatchError(expected, uuid) {
1690
- const isStaleV2Bond = expected === 'V2' && this.confirmedProtocolV2.has(uuid);
1691
- return hdShared.ERRORS.TypedError(isStaleV2Bond ? hdShared.HardwareErrorCode.BleDeviceBondError : hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`);
1800
+ createProtocolMismatchError(expected) {
1801
+ return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`);
1692
1802
  }
1693
1803
  createProtocolDetectionError() {
1694
1804
  return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, 'Unable to detect BLE protocol: device did not respond to Protocol V1 GetFeatures or Protocol V2 Ping');
@@ -1708,27 +1818,17 @@ class ReactNativeBleTransport {
1708
1818
  detectProtocol(uuid, expectedProtocol, protocolHint, rebuildTransport) {
1709
1819
  var _a;
1710
1820
  return __awaiter(this, void 0, void 0, function* () {
1711
- if (reactNative.Platform.OS === 'ios' && expectedProtocol === 'V1') {
1712
- this.deviceProtocol.set(uuid, expectedProtocol);
1821
+ if (expectedProtocol === 'V1') {
1822
+ this.deviceProtocol.set(uuid, 'V1');
1713
1823
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol selected', {
1714
1824
  deviceId: uuid,
1715
- protocol: expectedProtocol,
1825
+ protocol: 'V1',
1716
1826
  source: 'expected',
1717
1827
  });
1718
- return expectedProtocol;
1828
+ return 'V1';
1719
1829
  }
1720
- if (expectedProtocol === 'V1') {
1721
- if (yield this.probeProtocolV1(uuid)) {
1722
- this.deviceProtocol.set(uuid, 'V1');
1723
- this.sessionProtocols.set(uuid, 'V1');
1724
- Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
1725
- deviceId: uuid,
1726
- protocol: 'V1',
1727
- source: 'expected',
1728
- });
1729
- return 'V1';
1730
- }
1731
- throw this.createProtocolMismatchError(expectedProtocol, uuid);
1830
+ if (expectedProtocol === 'V2' || this.acquiringProtocolV2.has(uuid)) {
1831
+ this.throwIfStaleBondError(uuid);
1732
1832
  }
1733
1833
  if (expectedProtocol === 'V2') {
1734
1834
  if (yield this.probeProtocolV2(uuid)) {
@@ -1742,7 +1842,7 @@ class ReactNativeBleTransport {
1742
1842
  });
1743
1843
  return 'V2';
1744
1844
  }
1745
- throw this.createProtocolMismatchError(expectedProtocol, uuid);
1845
+ throw this.createProtocolMismatchError(expectedProtocol);
1746
1846
  }
1747
1847
  const sessionProtocol = this.sessionProtocols.get(uuid);
1748
1848
  const reprobeFailures = (_a = this.protocolReprobeFailures.get(uuid)) !== null && _a !== void 0 ? _a : 0;
@@ -1860,6 +1960,7 @@ class ReactNativeBleTransport {
1860
1960
  }
1861
1961
  this.probingProtocols.set(uuid, 'V2');
1862
1962
  (_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
1963
+ this.throwIfStaleBondError(uuid);
1863
1964
  const detected = yield transport.probeProtocolV2({
1864
1965
  call: (name, data, options) => this.callProtocolV2(uuid, name, data, options),
1865
1966
  timeoutMs: PROTOCOL_V2_PROBE_TIMEOUT_MS,
@@ -1870,6 +1971,7 @@ class ReactNativeBleTransport {
1870
1971
  (_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
1871
1972
  this.resetProtocolV2Frames(uuid);
1872
1973
  },
1974
+ shouldRethrow: hdShared.isBleStaleBondHardwareError,
1873
1975
  });
1874
1976
  if (!detected) {
1875
1977
  this.clearProbeProtocol(uuid, 'V2');
@@ -1930,6 +2032,19 @@ class ReactNativeBleTransport {
1930
2032
  framePromise.reject(error);
1931
2033
  }
1932
2034
  }
2035
+ rememberStaleBondError(uuid, error) {
2036
+ this.staleBondErrors.set(uuid, error);
2037
+ this.rejectProtocolV2Frames(uuid, error);
2038
+ if (this.runPromise && this.runPromiseDeviceId === uuid) {
2039
+ this.runPromise.reject(error);
2040
+ }
2041
+ }
2042
+ throwIfStaleBondError(uuid) {
2043
+ const error = this.staleBondErrors.get(uuid);
2044
+ if (error) {
2045
+ throw error;
2046
+ }
2047
+ }
1933
2048
  readProtocolV2Frame(uuid) {
1934
2049
  return __awaiter(this, void 0, void 0, function* () {
1935
2050
  const queuedFrame = this.getProtocolV2FrameQueue(uuid).shift();
@@ -1978,6 +2093,11 @@ class ReactNativeBleTransport {
1978
2093
  return;
1979
2094
  }
1980
2095
  catch (error) {
2096
+ if (isNativeBleStaleBondError(error) || hdShared.isBleStaleBondHardwareError(error)) {
2097
+ const bondError = toBleStaleBondHardwareError(error);
2098
+ this.rememberStaleBondError(uuid, bondError);
2099
+ throw bondError;
2100
+ }
1981
2101
  if (getFirmwareUploadWriteRetryType(error) !== 'congested' ||
1982
2102
  attempt >= FIRMWARE_UPLOAD_WRITE_MAX_RETRIES) {
1983
2103
  throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "1.2.2-alpha.100",
3
+ "version": "1.2.2-alpha.101",
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.2-alpha.100",
24
- "@onekeyfe/hd-shared": "1.2.2-alpha.100",
25
- "@onekeyfe/hd-transport": "1.2.2-alpha.100",
23
+ "@onekeyfe/hd-core": "1.2.2-alpha.101",
24
+ "@onekeyfe/hd-shared": "1.2.2-alpha.101",
25
+ "@onekeyfe/hd-transport": "1.2.2-alpha.101",
26
26
  "@onekeyfe/react-native-ble-utils": "^0.1.6",
27
27
  "react-native-ble-plx": "3.5.1"
28
28
  },
29
- "gitHead": "c40dad085297b0e3cc2020bd218c146dff6ed3e1"
29
+ "gitHead": "b9a5ca0c73e5e2cc979c91c007ace476e442718c"
30
30
  }
@@ -0,0 +1,47 @@
1
+ import { HardwareErrorCode } from '@onekeyfe/hd-shared';
2
+
3
+ import { isNativeBleStaleBondError, toBleStaleBondHardwareError } from '../bleStaleBond';
4
+
5
+ describe('native BLE stale bond mapping', () => {
6
+ test.each([
7
+ [
8
+ { attErrorCode: 15, reason: 'Encryption is insufficient' },
9
+ HardwareErrorCode.BleDeviceBondError,
10
+ ],
11
+ [
12
+ { attErrorCode: 5, reason: 'GATT_INSUF_AUTHENTICATION' },
13
+ HardwareErrorCode.BleDeviceBondError,
14
+ ],
15
+ [
16
+ { androidErrorCode: 5, reason: 'Connection state changed with status 5' },
17
+ HardwareErrorCode.BleDeviceBondError,
18
+ ],
19
+ [
20
+ { androidErrorCode: 15, reason: 'Connection state changed with status 15' },
21
+ HardwareErrorCode.BleDeviceBondError,
22
+ ],
23
+ [
24
+ { iosErrorCode: 14, reason: 'Peer removed pairing information' },
25
+ HardwareErrorCode.BlePeerRemovedPairingInformation,
26
+ ],
27
+ [
28
+ { reason: 'peer removed pairing information' },
29
+ HardwareErrorCode.BlePeerRemovedPairingInformation,
30
+ ],
31
+ [
32
+ { message: 'PEER REMOVED PAIRING INFORMATION' },
33
+ HardwareErrorCode.BlePeerRemovedPairingInformation,
34
+ ],
35
+ ])('maps %j to %s', (nativeError, errorCode) => {
36
+ expect(isNativeBleStaleBondError(nativeError)).toBe(true);
37
+ expect(toBleStaleBondHardwareError(nativeError)).toMatchObject({ errorCode });
38
+ });
39
+
40
+ test('does not treat the generic ATT unlikely error as a stale bond', () => {
41
+ expect(isNativeBleStaleBondError({ attErrorCode: 14, reason: 'Unlikely error' })).toBe(false);
42
+ });
43
+
44
+ test('does not treat a generic disconnect as a stale bond', () => {
45
+ expect(isNativeBleStaleBondError({ reason: 'Device disconnected' })).toBe(false);
46
+ });
47
+ });