@onekeyfe/hd-transport-react-native 1.2.2-alpha.100 → 1.2.2-alpha.12

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;AAkBvC,eAAO,MAAM,yBAAyB,UAAW,OAAO,KAAG,OAe1D,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,EAAE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AAM,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,CAA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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,38 @@ 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.iosErrorCode === IOS_PEER_REMOVED_PAIRING_INFORMATION) {
211
+ return true;
212
+ }
213
+ return hdShared.isBleStaleBondErrorText(nativeErrorText(nativeError));
214
+ };
215
+ const toBleStaleBondHardwareError = (error) => {
216
+ if (hdShared.isBleStaleBondHardwareError(error)) {
217
+ return error;
218
+ }
219
+ const nativeError = (error !== null && error !== void 0 ? error : {});
220
+ const text = nativeErrorText(nativeError);
221
+ const normalizedText = text.toLowerCase();
222
+ const peerRemoved = nativeError.iosErrorCode === IOS_PEER_REMOVED_PAIRING_INFORMATION ||
223
+ normalizedText.includes('peer removed pairing information');
224
+ return hdShared.ERRORS.TypedError(peerRemoved
225
+ ? hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation
226
+ : hdShared.HardwareErrorCode.BleDeviceBondError, text || undefined);
227
+ };
228
+
197
229
  const isHeaderChunk = (chunk) => {
198
230
  if (chunk.length < 9)
199
231
  return false;
@@ -372,12 +404,11 @@ const requestNegotiatedMtu = (device, stage, attempt) => __awaiter(void 0, void
372
404
  }
373
405
  });
374
406
  const resolveNegotiatedMtu = (device) => requestNegotiatedMtu(device, 'connected', 0);
375
- function remapError(error) {
407
+ function remapError(error, mapProtocolV2StaleBond) {
376
408
  var _a;
377
409
  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);
410
+ if (mapProtocolV2StaleBond && isNativeBleStaleBondError(error)) {
411
+ throw toBleStaleBondHardwareError(error);
381
412
  }
382
413
  if ((error === null || error === void 0 ? void 0 : error.attErrorCode) === 22) {
383
414
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceBondError);
@@ -408,6 +439,8 @@ class ReactNativeBleTransport {
408
439
  this.sessionProtocols = new Map();
409
440
  this.confirmedProtocolV2 = new Set();
410
441
  this.protocolReprobeFailures = new Map();
442
+ this.staleBondErrors = new Map();
443
+ this.acquiringProtocolV2 = new Set();
411
444
  this.protocolV2Assemblers = new Map();
412
445
  this.protocolV2FrameQueues = new Map();
413
446
  this.protocolV2FramePromises = new Map();
@@ -802,19 +835,46 @@ class ReactNativeBleTransport {
802
835
  acquireUnlocked(input) {
803
836
  var _a;
804
837
  return __awaiter(this, void 0, void 0, function* () {
805
- const { uuid, forceCleanRunPromise, expectedProtocol } = input;
838
+ const { uuid, forceCleanRunPromise, expectedProtocol, skipProtocolProbe } = input;
839
+ const shouldMapProtocolV2StaleBond = expectedProtocol
840
+ ? expectedProtocol === 'V2'
841
+ : this.confirmedProtocolV2.has(uuid);
806
842
  const cachedTransport = transportCache[uuid];
843
+ if (skipProtocolProbe && !cachedTransport && this.blePlxManager) {
844
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] refresh uncached BLE connection for firmware install:', uuid);
845
+ const manager = this.blePlxManager;
846
+ yield this.runNativeTeardown(uuid, manager, () => __awaiter(this, void 0, void 0, function* () {
847
+ yield this.runBestEffortNativeOperation('firmware install reconnect: cancel uncached device connection', () => manager.cancelDeviceConnection(uuid));
848
+ }));
849
+ }
807
850
  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 };
851
+ if (skipProtocolProbe) {
852
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] refresh cached BLE connection for firmware install:', uuid);
853
+ const manager = this.blePlxManager;
854
+ yield this.releaseUnlocked(uuid, true);
855
+ yield this.runNativeTeardown(uuid, manager, () => __awaiter(this, void 0, void 0, function* () {
856
+ const operations = [];
857
+ if (manager) {
858
+ operations.push(this.runBestEffortNativeOperation('firmware install reconnect: cancel device connection', () => manager.cancelDeviceConnection(uuid)));
859
+ }
860
+ operations.push(this.runBestEffortNativeOperation('firmware install reconnect: device cancel connection', () => cachedTransport.device.cancelConnection()));
861
+ yield Promise.all(operations);
862
+ }));
863
+ }
864
+ else {
865
+ const cachedProtocol = this.deviceProtocol.get(uuid);
866
+ const isCachedDeviceConnected = yield cachedTransport.device
867
+ .isConnected()
868
+ .catch(() => false);
869
+ if (isCachedDeviceConnected &&
870
+ cachedProtocol &&
871
+ (!expectedProtocol || cachedProtocol === expectedProtocol)) {
872
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] reuse cached BLE transport:', uuid, cachedProtocol);
873
+ return { uuid, protocolType: cachedProtocol };
874
+ }
875
+ Log === null || Log === void 0 ? void 0 : Log.debug('transport not reusable, will release: ', uuid);
876
+ yield this.releaseUnlocked(uuid, true);
815
877
  }
816
- Log === null || Log === void 0 ? void 0 : Log.debug('transport not reusable, will release: ', uuid);
817
- yield this.releaseUnlocked(uuid, true);
818
878
  }
819
879
  let device = null;
820
880
  if (forceCleanRunPromise && this.runPromise) {
@@ -871,7 +931,7 @@ class ReactNativeBleTransport {
871
931
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleAlreadyConnected);
872
932
  }
873
933
  else {
874
- remapError(e);
934
+ remapError(e, shouldMapProtocolV2StaleBond);
875
935
  }
876
936
  }
877
937
  }
@@ -905,7 +965,7 @@ class ReactNativeBleTransport {
905
965
  }
906
966
  }
907
967
  else {
908
- remapError(e);
968
+ remapError(e, shouldMapProtocolV2StaleBond);
909
969
  }
910
970
  }
911
971
  }
@@ -919,11 +979,38 @@ class ReactNativeBleTransport {
919
979
  if (protocolHint) {
920
980
  this.deviceProtocolHints.set(uuid, protocolHint);
921
981
  }
922
- yield this.installTransportForAcquire(uuid, acquiredDevice, {
923
- writeCharacteristic,
924
- notifyCharacteristic,
925
- });
982
+ if (shouldMapProtocolV2StaleBond) {
983
+ this.acquiringProtocolV2.add(uuid);
984
+ }
926
985
  try {
986
+ yield this.installTransportForAcquire(uuid, acquiredDevice, {
987
+ writeCharacteristic,
988
+ notifyCharacteristic,
989
+ });
990
+ if (skipProtocolProbe) {
991
+ if (!expectedProtocol) {
992
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'skipProtocolProbe requires an expected BLE protocol');
993
+ }
994
+ const hasConfirmedProtocol = this.sessionProtocols.get(uuid) === expectedProtocol ||
995
+ (expectedProtocol === 'V2' && this.confirmedProtocolV2.has(uuid));
996
+ if (!hasConfirmedProtocol) {
997
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'skipProtocolProbe requires a previously confirmed protocol for this BLE endpoint');
998
+ }
999
+ this.deviceProtocol.set(uuid, expectedProtocol);
1000
+ this.sessionProtocols.set(uuid, expectedProtocol);
1001
+ this.protocolReprobeFailures.delete(uuid);
1002
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol selected without probe', {
1003
+ deviceId: uuid,
1004
+ protocol: expectedProtocol,
1005
+ source: 'firmware-install-reconnect',
1006
+ });
1007
+ const currentTransport = transportCache[uuid];
1008
+ if (!currentTransport) {
1009
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotFound);
1010
+ }
1011
+ this.attachDisconnectSubscription(currentTransport, currentTransport.device, uuid);
1012
+ return { uuid, protocolType: expectedProtocol };
1013
+ }
927
1014
  const protocolType = yield this.detectProtocol(uuid, expectedProtocol, protocolHint, () => __awaiter(this, void 0, void 0, function* () {
928
1015
  yield this.installTransportForAcquire(uuid, acquiredDevice);
929
1016
  }));
@@ -935,7 +1022,7 @@ class ReactNativeBleTransport {
935
1022
  return { uuid, protocolType };
936
1023
  }
937
1024
  catch (error) {
938
- if ((error === null || error === void 0 ? void 0 : error.errorCode) === hdShared.HardwareErrorCode.BleDeviceBondError) {
1025
+ if (hdShared.isBleStaleBondHardwareError(error)) {
939
1026
  yield this.disconnectUnlocked(uuid);
940
1027
  }
941
1028
  else {
@@ -943,13 +1030,16 @@ class ReactNativeBleTransport {
943
1030
  }
944
1031
  throw error;
945
1032
  }
1033
+ finally {
1034
+ this.acquiringProtocolV2.delete(uuid);
1035
+ }
946
1036
  });
947
1037
  }
948
1038
  _monitorCharacteristic(characteristic, uuid, monitorToken, notifyTransactionId) {
949
1039
  let bufferLength = 0;
950
1040
  let buffer$1 = [];
951
1041
  const subscription = characteristic.monitor((error, c) => {
952
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
1042
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
953
1043
  const isCurrentMonitor = this.monitorTokens.get(uuid) === monitorToken;
954
1044
  if (error) {
955
1045
  Log === null || Log === void 0 ? void 0 : Log.debug(`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${error}`);
@@ -961,19 +1051,21 @@ class ReactNativeBleTransport {
961
1051
  Log === null || Log === void 0 ? void 0 : Log.debug('monitor error ignored for stale transport: ', uuid, notifyTransactionId);
962
1052
  return;
963
1053
  }
1054
+ if ((this.getActiveProtocol(uuid) === 'V2' || this.acquiringProtocolV2.has(uuid)) &&
1055
+ isNativeBleStaleBondError(error)) {
1056
+ this.rememberStaleBondError(uuid, toBleStaleBondHardwareError(error));
1057
+ return;
1058
+ }
964
1059
  if (this.getActiveProtocol(uuid) === 'V2') {
965
1060
  let errorCode = hdShared.HardwareErrorCode.BleCharacteristicNotifyError;
966
1061
  if ((_a = error.reason) === null || _a === void 0 ? void 0 : _a.includes('The connection has timed out unexpectedly')) {
967
1062
  errorCode = hdShared.HardwareErrorCode.BleTimeoutError;
968
1063
  }
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'))) {
1064
+ else if (((_b = error.reason) === null || _b === void 0 ? void 0 : _b.includes('Cannot write client characteristic config descriptor')) ||
1065
+ ((_c = error.reason) === null || _c === void 0 ? void 0 : _c.includes('Cannot find client characteristic config descriptor')) ||
1066
+ ((_d = error.reason) === null || _d === void 0 ? void 0 : _d.includes('The handle is invalid')) ||
1067
+ ((_e = error.reason) === null || _e === void 0 ? void 0 : _e.includes('Writing is not permitted')) ||
1068
+ ((_f = error.reason) === null || _f === void 0 ? void 0 : _f.includes('notify change failed for device'))) {
977
1069
  errorCode = hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure;
978
1070
  }
979
1071
  this.rejectProtocolV2Frames(uuid, hdShared.ERRORS.TypedError(errorCode));
@@ -981,17 +1073,14 @@ class ReactNativeBleTransport {
981
1073
  }
982
1074
  if (this.runPromise && this.runPromiseDeviceId === uuid) {
983
1075
  let ERROR = hdShared.HardwareErrorCode.BleCharacteristicNotifyError;
984
- if ((_h = error.reason) === null || _h === void 0 ? void 0 : _h.includes('The connection has timed out unexpectedly')) {
1076
+ if ((_g = error.reason) === null || _g === void 0 ? void 0 : _g.includes('The connection has timed out unexpectedly')) {
985
1077
  ERROR = hdShared.HardwareErrorCode.BleTimeoutError;
986
1078
  }
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'))) {
1079
+ if (((_h = error.reason) === null || _h === void 0 ? void 0 : _h.includes('Cannot write client characteristic config descriptor')) ||
1080
+ ((_j = error.reason) === null || _j === void 0 ? void 0 : _j.includes('Cannot find client characteristic config descriptor')) ||
1081
+ ((_k = error.reason) === null || _k === void 0 ? void 0 : _k.includes('The handle is invalid')) ||
1082
+ ((_l = error.reason) === null || _l === void 0 ? void 0 : _l.includes('Writing is not permitted')) ||
1083
+ ((_m = error.reason) === null || _m === void 0 ? void 0 : _m.includes('notify change failed for device'))) {
995
1084
  const notifyError = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure);
996
1085
  this.runPromise.reject(notifyError);
997
1086
  Log === null || Log === void 0 ? void 0 : Log.debug(`${hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure} ${error.message} ${error.reason}`);
@@ -1033,7 +1122,7 @@ class ReactNativeBleTransport {
1033
1122
  bufferLength = 0;
1034
1123
  buffer$1 = [];
1035
1124
  if (this.runPromiseDeviceId === uuid) {
1036
- (_q = this.runPromise) === null || _q === void 0 ? void 0 : _q.resolve(value.toString('hex'));
1125
+ (_o = this.runPromise) === null || _o === void 0 ? void 0 : _o.resolve(value.toString('hex'));
1037
1126
  }
1038
1127
  }
1039
1128
  }
@@ -1044,7 +1133,7 @@ class ReactNativeBleTransport {
1044
1133
  this.rejectProtocolV2Frames(uuid, notifyError);
1045
1134
  }
1046
1135
  else if (this.runPromiseDeviceId === uuid) {
1047
- (_r = this.runPromise) === null || _r === void 0 ? void 0 : _r.reject(notifyError);
1136
+ (_p = this.runPromise) === null || _p === void 0 ? void 0 : _p.reject(notifyError);
1048
1137
  }
1049
1138
  }
1050
1139
  }, notifyTransactionId);
@@ -1098,6 +1187,8 @@ class ReactNativeBleTransport {
1098
1187
  this.protocolV2HighVolumeLogSignatures.delete(uuid);
1099
1188
  this.deviceProtocol.delete(uuid);
1100
1189
  this.probingProtocols.delete(uuid);
1190
+ this.staleBondErrors.delete(uuid);
1191
+ this.acquiringProtocolV2.delete(uuid);
1101
1192
  (_e = this.protocolV2Assemblers.get(uuid)) === null || _e === void 0 ? void 0 : _e.reset();
1102
1193
  this.protocolV2Assemblers.delete(uuid);
1103
1194
  this.resetProtocolV2Frames(uuid);
@@ -1383,6 +1474,7 @@ class ReactNativeBleTransport {
1383
1474
  }
1384
1475
  this.deviceProtocol.delete(session);
1385
1476
  this.probingProtocols.delete(session);
1477
+ this.staleBondErrors.delete(session);
1386
1478
  this.deviceProtocolHints.delete(session);
1387
1479
  this.sessionProtocols.delete(session);
1388
1480
  this.protocolReprobeFailures.delete(session);
@@ -1561,6 +1653,8 @@ class ReactNativeBleTransport {
1561
1653
  }
1562
1654
  this.deviceProtocol.delete(uuid);
1563
1655
  this.probingProtocols.delete(uuid);
1656
+ this.staleBondErrors.delete(uuid);
1657
+ this.acquiringProtocolV2.delete(uuid);
1564
1658
  this.protocolV2Assemblers.delete(uuid);
1565
1659
  this.resetProtocolV2Frames(uuid);
1566
1660
  if (timeouts >= BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD) {
@@ -1630,6 +1724,8 @@ class ReactNativeBleTransport {
1630
1724
  }
1631
1725
  this.deviceProtocol.delete(uuid);
1632
1726
  this.probingProtocols.delete(uuid);
1727
+ this.staleBondErrors.delete(uuid);
1728
+ this.acquiringProtocolV2.delete(uuid);
1633
1729
  this.protocolV2Assemblers.delete(uuid);
1634
1730
  this.resetProtocolV2Frames(uuid);
1635
1731
  if (timeouts >= BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD) {
@@ -1672,8 +1768,9 @@ class ReactNativeBleTransport {
1672
1768
  });
1673
1769
  this.deviceProtocol.clear();
1674
1770
  this.probingProtocols.clear();
1771
+ this.staleBondErrors.clear();
1772
+ this.acquiringProtocolV2.clear();
1675
1773
  this.sessionProtocols.clear();
1676
- this.confirmedProtocolV2.clear();
1677
1774
  this.protocolReprobeFailures.clear();
1678
1775
  this.writeTimeoutCounts.clear();
1679
1776
  this.connectionSetupTimeoutCounts.clear();
@@ -1686,9 +1783,8 @@ class ReactNativeBleTransport {
1686
1783
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE manager destroy failed (ignored):', error);
1687
1784
  }
1688
1785
  }
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`);
1786
+ createProtocolMismatchError(expected) {
1787
+ return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`);
1692
1788
  }
1693
1789
  createProtocolDetectionError() {
1694
1790
  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 +1804,17 @@ class ReactNativeBleTransport {
1708
1804
  detectProtocol(uuid, expectedProtocol, protocolHint, rebuildTransport) {
1709
1805
  var _a;
1710
1806
  return __awaiter(this, void 0, void 0, function* () {
1711
- if (reactNative.Platform.OS === 'ios' && expectedProtocol === 'V1') {
1712
- this.deviceProtocol.set(uuid, expectedProtocol);
1807
+ if (expectedProtocol === 'V1') {
1808
+ this.deviceProtocol.set(uuid, 'V1');
1713
1809
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol selected', {
1714
1810
  deviceId: uuid,
1715
- protocol: expectedProtocol,
1811
+ protocol: 'V1',
1716
1812
  source: 'expected',
1717
1813
  });
1718
- return expectedProtocol;
1814
+ return 'V1';
1719
1815
  }
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);
1816
+ if (expectedProtocol === 'V2' || this.acquiringProtocolV2.has(uuid)) {
1817
+ this.throwIfStaleBondError(uuid);
1732
1818
  }
1733
1819
  if (expectedProtocol === 'V2') {
1734
1820
  if (yield this.probeProtocolV2(uuid)) {
@@ -1742,7 +1828,7 @@ class ReactNativeBleTransport {
1742
1828
  });
1743
1829
  return 'V2';
1744
1830
  }
1745
- throw this.createProtocolMismatchError(expectedProtocol, uuid);
1831
+ throw this.createProtocolMismatchError(expectedProtocol);
1746
1832
  }
1747
1833
  const sessionProtocol = this.sessionProtocols.get(uuid);
1748
1834
  const reprobeFailures = (_a = this.protocolReprobeFailures.get(uuid)) !== null && _a !== void 0 ? _a : 0;
@@ -1860,6 +1946,7 @@ class ReactNativeBleTransport {
1860
1946
  }
1861
1947
  this.probingProtocols.set(uuid, 'V2');
1862
1948
  (_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
1949
+ this.throwIfStaleBondError(uuid);
1863
1950
  const detected = yield transport.probeProtocolV2({
1864
1951
  call: (name, data, options) => this.callProtocolV2(uuid, name, data, options),
1865
1952
  timeoutMs: PROTOCOL_V2_PROBE_TIMEOUT_MS,
@@ -1870,6 +1957,7 @@ class ReactNativeBleTransport {
1870
1957
  (_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
1871
1958
  this.resetProtocolV2Frames(uuid);
1872
1959
  },
1960
+ shouldRethrow: hdShared.isBleStaleBondHardwareError,
1873
1961
  });
1874
1962
  if (!detected) {
1875
1963
  this.clearProbeProtocol(uuid, 'V2');
@@ -1930,6 +2018,19 @@ class ReactNativeBleTransport {
1930
2018
  framePromise.reject(error);
1931
2019
  }
1932
2020
  }
2021
+ rememberStaleBondError(uuid, error) {
2022
+ this.staleBondErrors.set(uuid, error);
2023
+ this.rejectProtocolV2Frames(uuid, error);
2024
+ if (this.runPromise && this.runPromiseDeviceId === uuid) {
2025
+ this.runPromise.reject(error);
2026
+ }
2027
+ }
2028
+ throwIfStaleBondError(uuid) {
2029
+ const error = this.staleBondErrors.get(uuid);
2030
+ if (error) {
2031
+ throw error;
2032
+ }
2033
+ }
1933
2034
  readProtocolV2Frame(uuid) {
1934
2035
  return __awaiter(this, void 0, void 0, function* () {
1935
2036
  const queuedFrame = this.getProtocolV2FrameQueue(uuid).shift();
@@ -1978,6 +2079,11 @@ class ReactNativeBleTransport {
1978
2079
  return;
1979
2080
  }
1980
2081
  catch (error) {
2082
+ if (isNativeBleStaleBondError(error) || hdShared.isBleStaleBondHardwareError(error)) {
2083
+ const bondError = toBleStaleBondHardwareError(error);
2084
+ this.rememberStaleBondError(uuid, bondError);
2085
+ throw bondError;
2086
+ }
1981
2087
  if (getFirmwareUploadWriteRetryType(error) !== 'congested' ||
1982
2088
  attempt >= FIRMWARE_UPLOAD_WRITE_MAX_RETRIES) {
1983
2089
  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.12",
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.12",
24
+ "@onekeyfe/hd-shared": "1.2.2-alpha.12",
25
+ "@onekeyfe/hd-transport": "1.2.2-alpha.12",
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": "9b5a45bc55819d22ed752899b4c40aad70de4527"
30
30
  }
@@ -0,0 +1,39 @@
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
+ { iosErrorCode: 14, reason: 'Peer removed pairing information' },
17
+ HardwareErrorCode.BlePeerRemovedPairingInformation,
18
+ ],
19
+ [
20
+ { reason: 'peer removed pairing information' },
21
+ HardwareErrorCode.BlePeerRemovedPairingInformation,
22
+ ],
23
+ [
24
+ { message: 'PEER REMOVED PAIRING INFORMATION' },
25
+ HardwareErrorCode.BlePeerRemovedPairingInformation,
26
+ ],
27
+ ])('maps %j to %s', (nativeError, errorCode) => {
28
+ expect(isNativeBleStaleBondError(nativeError)).toBe(true);
29
+ expect(toBleStaleBondHardwareError(nativeError)).toMatchObject({ errorCode });
30
+ });
31
+
32
+ test('does not treat the generic ATT unlikely error as a stale bond', () => {
33
+ expect(isNativeBleStaleBondError({ attErrorCode: 14, reason: 'Unlikely error' })).toBe(false);
34
+ });
35
+
36
+ test('does not treat a generic disconnect as a stale bond', () => {
37
+ expect(isNativeBleStaleBondError({ reason: 'Device disconnected' })).toBe(false);
38
+ });
39
+ });
@@ -90,7 +90,7 @@ describe('React Native BLE strategy', () => {
90
90
  ).toBe(182);
91
91
  });
92
92
 
93
- test('uses withoutResponse for a high-volume write unless explicitly overridden', () => {
93
+ test('uses withoutResponse by default unless explicitly overridden', () => {
94
94
  const characteristic = {
95
95
  isWritableWithResponse: true,
96
96
  isWritableWithoutResponse: true,
@@ -99,8 +99,7 @@ describe('React Native BLE strategy', () => {
99
99
  expect(
100
100
  shouldWriteProtocolV2WithResponse({
101
101
  platform: 'ios',
102
- highThroughput: true,
103
- requestedWithResponse: false,
102
+ highThroughput: false,
104
103
  characteristic,
105
104
  })
106
105
  ).toBe(false);