@onekeyfe/hd-transport-react-native 1.2.0-alpha.160 → 1.2.0-alpha.161
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 +0 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -94
- package/package.json +5 -5
- package/src/__tests__/protocolV2Link.test.ts +0 -34
- package/src/index.ts +17 -62
- package/dist/bleStaleBond.d.ts +0 -5
- package/dist/bleStaleBond.d.ts.map +0 -1
- package/src/__tests__/bleStaleBond.test.ts +0 -31
- package/src/bleStaleBond.ts +0 -63
package/dist/index.d.ts
CHANGED
|
@@ -126,12 +126,6 @@ declare class ReactNativeBleTransport {
|
|
|
126
126
|
private confirmedProtocolV2;
|
|
127
127
|
/** Consecutive detections that failed while trusting sessionProtocols. */
|
|
128
128
|
private protocolReprobeFailures;
|
|
129
|
-
/**
|
|
130
|
-
* Native encryption/pairing failures seen before Protocol V2 probe starts.
|
|
131
|
-
* Pro2/Neo GATT connect can succeed on a stale iOS bond; the CCCD write then
|
|
132
|
-
* fails with ATT 14/15. Remember it so detectProtocol fails immediately.
|
|
133
|
-
*/
|
|
134
|
-
private staleBondErrors;
|
|
135
129
|
private protocolV2Assemblers;
|
|
136
130
|
private protocolV2FrameQueues;
|
|
137
131
|
private protocolV2FramePromises;
|
|
@@ -222,8 +216,6 @@ declare class ReactNativeBleTransport {
|
|
|
222
216
|
private resolveProtocolV2Frame;
|
|
223
217
|
private resetProtocolV2Frames;
|
|
224
218
|
private rejectProtocolV2Frames;
|
|
225
|
-
private rememberStaleBondError;
|
|
226
|
-
private throwIfStaleBondError;
|
|
227
219
|
private readProtocolV2Frame;
|
|
228
220
|
private writeProtocolV2Packet;
|
|
229
221
|
private writeProtocolV2Frame;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AA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O,CAAC,4BAA4B;YAQtB,qBAAqB;IAoBnC,MAAM;YAUQ,kBAAkB;YAwClB,iCAAiC;IA+C/C,OAAO,CAAC,wBAAwB;IAkChC,OAAO,CAAC,yBAAyB;IAMjC,OAAO,CAAC,kBAAkB;YAcZ,cAAc;IA8C5B,OAAO,CAAC,kBAAkB;IA6B1B,OAAO,CAAC,eAAe;IAmDvB,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,iBAAiB;YAIX,cAAc;YA0Gd,iCAAiC;YAoDjC,eAAe;YAwBf,eAAe;IA0B7B,OAAO,CAAC,4BAA4B;IA2BpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,sBAAsB;YAShB,mBAAmB;YAiBnB,qBAAqB;YA2DrB,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
|
@@ -194,40 +194,6 @@ 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_UNLIKELY_ERROR = 14;
|
|
199
|
-
const ATT_INSUFFICIENT_ENCRYPTION = 15;
|
|
200
|
-
const IOS_PEER_REMOVED_PAIRING_INFORMATION = 14;
|
|
201
|
-
const nativeErrorText = (error) => [error.reason, error.message]
|
|
202
|
-
.filter((value) => typeof value === 'string')
|
|
203
|
-
.join(' ');
|
|
204
|
-
const isNativeBleStaleBondError = (error) => {
|
|
205
|
-
if (!error || typeof error !== 'object') {
|
|
206
|
-
return typeof error === 'string' ? hdShared.isBleStaleBondErrorText(error) : false;
|
|
207
|
-
}
|
|
208
|
-
const nativeError = error;
|
|
209
|
-
if (nativeError.attErrorCode === ATT_INSUFFICIENT_AUTHENTICATION ||
|
|
210
|
-
nativeError.attErrorCode === ATT_UNLIKELY_ERROR ||
|
|
211
|
-
nativeError.attErrorCode === 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 peerRemoved = nativeError.iosErrorCode === IOS_PEER_REMOVED_PAIRING_INFORMATION ||
|
|
224
|
-
nativeError.attErrorCode === ATT_UNLIKELY_ERROR ||
|
|
225
|
-
text.includes('Peer removed pairing information');
|
|
226
|
-
return hdShared.ERRORS.TypedError(peerRemoved
|
|
227
|
-
? hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation
|
|
228
|
-
: hdShared.HardwareErrorCode.BleDeviceBondError, text || undefined);
|
|
229
|
-
};
|
|
230
|
-
|
|
231
197
|
const isHeaderChunk = (chunk) => {
|
|
232
198
|
if (chunk.length < 9)
|
|
233
199
|
return false;
|
|
@@ -409,8 +375,9 @@ const resolveNegotiatedMtu = (device) => requestNegotiatedMtu(device, 'connected
|
|
|
409
375
|
function remapError(error) {
|
|
410
376
|
var _a;
|
|
411
377
|
if (error instanceof reactNativeBlePlx.BleError) {
|
|
412
|
-
if (
|
|
413
|
-
|
|
378
|
+
if (error.iosErrorCode === reactNativeBlePlx.BleATTErrorCode.UnlikelyError ||
|
|
379
|
+
error.reason === 'Peer removed pairing information') {
|
|
380
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation);
|
|
414
381
|
}
|
|
415
382
|
if ((error === null || error === void 0 ? void 0 : error.attErrorCode) === 22) {
|
|
416
383
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceBondError);
|
|
@@ -441,7 +408,6 @@ class ReactNativeBleTransport {
|
|
|
441
408
|
this.sessionProtocols = new Map();
|
|
442
409
|
this.confirmedProtocolV2 = new Set();
|
|
443
410
|
this.protocolReprobeFailures = new Map();
|
|
444
|
-
this.staleBondErrors = new Map();
|
|
445
411
|
this.protocolV2Assemblers = new Map();
|
|
446
412
|
this.protocolV2FrameQueues = new Map();
|
|
447
413
|
this.protocolV2FramePromises = new Map();
|
|
@@ -969,7 +935,7 @@ class ReactNativeBleTransport {
|
|
|
969
935
|
return { uuid, protocolType };
|
|
970
936
|
}
|
|
971
937
|
catch (error) {
|
|
972
|
-
if (
|
|
938
|
+
if ((error === null || error === void 0 ? void 0 : error.errorCode) === hdShared.HardwareErrorCode.BleDeviceBondError) {
|
|
973
939
|
yield this.disconnectUnlocked(uuid);
|
|
974
940
|
}
|
|
975
941
|
else {
|
|
@@ -983,7 +949,7 @@ class ReactNativeBleTransport {
|
|
|
983
949
|
let bufferLength = 0;
|
|
984
950
|
let buffer$1 = [];
|
|
985
951
|
const subscription = characteristic.monitor((error, c) => {
|
|
986
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
952
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
987
953
|
const isCurrentMonitor = this.monitorTokens.get(uuid) === monitorToken;
|
|
988
954
|
if (error) {
|
|
989
955
|
Log === null || Log === void 0 ? void 0 : Log.debug(`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${error}`);
|
|
@@ -995,20 +961,19 @@ class ReactNativeBleTransport {
|
|
|
995
961
|
Log === null || Log === void 0 ? void 0 : Log.debug('monitor error ignored for stale transport: ', uuid, notifyTransactionId);
|
|
996
962
|
return;
|
|
997
963
|
}
|
|
998
|
-
if (isNativeBleStaleBondError(error)) {
|
|
999
|
-
this.rememberStaleBondError(uuid, toBleStaleBondHardwareError(error));
|
|
1000
|
-
return;
|
|
1001
|
-
}
|
|
1002
964
|
if (this.getActiveProtocol(uuid) === 'V2') {
|
|
1003
965
|
let errorCode = hdShared.HardwareErrorCode.BleCharacteristicNotifyError;
|
|
1004
966
|
if ((_a = error.reason) === null || _a === void 0 ? void 0 : _a.includes('The connection has timed out unexpectedly')) {
|
|
1005
967
|
errorCode = hdShared.HardwareErrorCode.BleTimeoutError;
|
|
1006
968
|
}
|
|
1007
|
-
else if ((
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
((
|
|
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'))) {
|
|
1012
977
|
errorCode = hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure;
|
|
1013
978
|
}
|
|
1014
979
|
this.rejectProtocolV2Frames(uuid, hdShared.ERRORS.TypedError(errorCode));
|
|
@@ -1016,14 +981,17 @@ class ReactNativeBleTransport {
|
|
|
1016
981
|
}
|
|
1017
982
|
if (this.runPromise && this.runPromiseDeviceId === uuid) {
|
|
1018
983
|
let ERROR = hdShared.HardwareErrorCode.BleCharacteristicNotifyError;
|
|
1019
|
-
if ((
|
|
984
|
+
if ((_h = error.reason) === null || _h === void 0 ? void 0 : _h.includes('The connection has timed out unexpectedly')) {
|
|
1020
985
|
ERROR = hdShared.HardwareErrorCode.BleTimeoutError;
|
|
1021
986
|
}
|
|
1022
|
-
if ((
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
((
|
|
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'))) {
|
|
1027
995
|
const notifyError = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure);
|
|
1028
996
|
this.runPromise.reject(notifyError);
|
|
1029
997
|
Log === null || Log === void 0 ? void 0 : Log.debug(`${hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure} ${error.message} ${error.reason}`);
|
|
@@ -1065,7 +1033,7 @@ class ReactNativeBleTransport {
|
|
|
1065
1033
|
bufferLength = 0;
|
|
1066
1034
|
buffer$1 = [];
|
|
1067
1035
|
if (this.runPromiseDeviceId === uuid) {
|
|
1068
|
-
(
|
|
1036
|
+
(_q = this.runPromise) === null || _q === void 0 ? void 0 : _q.resolve(value.toString('hex'));
|
|
1069
1037
|
}
|
|
1070
1038
|
}
|
|
1071
1039
|
}
|
|
@@ -1076,7 +1044,7 @@ class ReactNativeBleTransport {
|
|
|
1076
1044
|
this.rejectProtocolV2Frames(uuid, notifyError);
|
|
1077
1045
|
}
|
|
1078
1046
|
else if (this.runPromiseDeviceId === uuid) {
|
|
1079
|
-
(
|
|
1047
|
+
(_r = this.runPromise) === null || _r === void 0 ? void 0 : _r.reject(notifyError);
|
|
1080
1048
|
}
|
|
1081
1049
|
}
|
|
1082
1050
|
}, notifyTransactionId);
|
|
@@ -1130,7 +1098,6 @@ class ReactNativeBleTransport {
|
|
|
1130
1098
|
this.protocolV2HighVolumeLogSignatures.delete(uuid);
|
|
1131
1099
|
this.deviceProtocol.delete(uuid);
|
|
1132
1100
|
this.probingProtocols.delete(uuid);
|
|
1133
|
-
this.staleBondErrors.delete(uuid);
|
|
1134
1101
|
(_e = this.protocolV2Assemblers.get(uuid)) === null || _e === void 0 ? void 0 : _e.reset();
|
|
1135
1102
|
this.protocolV2Assemblers.delete(uuid);
|
|
1136
1103
|
this.resetProtocolV2Frames(uuid);
|
|
@@ -1224,9 +1191,6 @@ class ReactNativeBleTransport {
|
|
|
1224
1191
|
if (isWedgedWriteError(e)) {
|
|
1225
1192
|
throw e;
|
|
1226
1193
|
}
|
|
1227
|
-
if (isNativeBleStaleBondError(e) || hdShared.isBleStaleBondHardwareError(e)) {
|
|
1228
|
-
throw toBleStaleBondHardwareError(e);
|
|
1229
|
-
}
|
|
1230
1194
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleWriteCharacteristicError);
|
|
1231
1195
|
}
|
|
1232
1196
|
}
|
|
@@ -1257,9 +1221,6 @@ class ReactNativeBleTransport {
|
|
|
1257
1221
|
if (isWedgedWriteError(e)) {
|
|
1258
1222
|
throw e;
|
|
1259
1223
|
}
|
|
1260
|
-
if (isNativeBleStaleBondError(e) || hdShared.isBleStaleBondHardwareError(e)) {
|
|
1261
|
-
throw toBleStaleBondHardwareError(e);
|
|
1262
|
-
}
|
|
1263
1224
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleWriteCharacteristicError);
|
|
1264
1225
|
}
|
|
1265
1226
|
}
|
|
@@ -1325,11 +1286,6 @@ class ReactNativeBleTransport {
|
|
|
1325
1286
|
if (isWedgedWriteError(e)) {
|
|
1326
1287
|
throw e;
|
|
1327
1288
|
}
|
|
1328
|
-
if (isNativeBleStaleBondError(e) || hdShared.isBleStaleBondHardwareError(e)) {
|
|
1329
|
-
const bondError = toBleStaleBondHardwareError(e);
|
|
1330
|
-
this.rememberStaleBondError(uuid, bondError);
|
|
1331
|
-
throw bondError;
|
|
1332
|
-
}
|
|
1333
1289
|
if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceDisconnected) {
|
|
1334
1290
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded);
|
|
1335
1291
|
}
|
|
@@ -1427,7 +1383,6 @@ class ReactNativeBleTransport {
|
|
|
1427
1383
|
}
|
|
1428
1384
|
this.deviceProtocol.delete(session);
|
|
1429
1385
|
this.probingProtocols.delete(session);
|
|
1430
|
-
this.staleBondErrors.delete(session);
|
|
1431
1386
|
this.deviceProtocolHints.delete(session);
|
|
1432
1387
|
this.sessionProtocols.delete(session);
|
|
1433
1388
|
this.protocolReprobeFailures.delete(session);
|
|
@@ -1606,7 +1561,6 @@ class ReactNativeBleTransport {
|
|
|
1606
1561
|
}
|
|
1607
1562
|
this.deviceProtocol.delete(uuid);
|
|
1608
1563
|
this.probingProtocols.delete(uuid);
|
|
1609
|
-
this.staleBondErrors.delete(uuid);
|
|
1610
1564
|
this.protocolV2Assemblers.delete(uuid);
|
|
1611
1565
|
this.resetProtocolV2Frames(uuid);
|
|
1612
1566
|
if (timeouts >= BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD) {
|
|
@@ -1676,7 +1630,6 @@ class ReactNativeBleTransport {
|
|
|
1676
1630
|
}
|
|
1677
1631
|
this.deviceProtocol.delete(uuid);
|
|
1678
1632
|
this.probingProtocols.delete(uuid);
|
|
1679
|
-
this.staleBondErrors.delete(uuid);
|
|
1680
1633
|
this.protocolV2Assemblers.delete(uuid);
|
|
1681
1634
|
this.resetProtocolV2Frames(uuid);
|
|
1682
1635
|
if (timeouts >= BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD) {
|
|
@@ -1719,7 +1672,6 @@ class ReactNativeBleTransport {
|
|
|
1719
1672
|
});
|
|
1720
1673
|
this.deviceProtocol.clear();
|
|
1721
1674
|
this.probingProtocols.clear();
|
|
1722
|
-
this.staleBondErrors.clear();
|
|
1723
1675
|
this.sessionProtocols.clear();
|
|
1724
1676
|
this.confirmedProtocolV2.clear();
|
|
1725
1677
|
this.protocolReprobeFailures.clear();
|
|
@@ -1765,7 +1717,6 @@ class ReactNativeBleTransport {
|
|
|
1765
1717
|
});
|
|
1766
1718
|
return expectedProtocol;
|
|
1767
1719
|
}
|
|
1768
|
-
this.throwIfStaleBondError(uuid);
|
|
1769
1720
|
if (expectedProtocol === 'V1') {
|
|
1770
1721
|
if (yield this.probeProtocolV1(uuid)) {
|
|
1771
1722
|
this.deviceProtocol.set(uuid, 'V1');
|
|
@@ -1894,7 +1845,7 @@ class ReactNativeBleTransport {
|
|
|
1894
1845
|
catch (error) {
|
|
1895
1846
|
this.clearProbeProtocol(uuid, 'V1');
|
|
1896
1847
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V1 GetFeatures probe failed:', error);
|
|
1897
|
-
if (isWedgedWriteError(error)
|
|
1848
|
+
if (isWedgedWriteError(error)) {
|
|
1898
1849
|
throw error;
|
|
1899
1850
|
}
|
|
1900
1851
|
return false;
|
|
@@ -1909,7 +1860,6 @@ class ReactNativeBleTransport {
|
|
|
1909
1860
|
}
|
|
1910
1861
|
this.probingProtocols.set(uuid, 'V2');
|
|
1911
1862
|
(_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
|
|
1912
|
-
this.throwIfStaleBondError(uuid);
|
|
1913
1863
|
const detected = yield transport.probeProtocolV2({
|
|
1914
1864
|
call: (name, data, options) => this.callProtocolV2(uuid, name, data, options),
|
|
1915
1865
|
timeoutMs: PROTOCOL_V2_PROBE_TIMEOUT_MS,
|
|
@@ -1920,7 +1870,6 @@ class ReactNativeBleTransport {
|
|
|
1920
1870
|
(_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
|
|
1921
1871
|
this.resetProtocolV2Frames(uuid);
|
|
1922
1872
|
},
|
|
1923
|
-
shouldRethrow: hdShared.isBleStaleBondHardwareError,
|
|
1924
1873
|
});
|
|
1925
1874
|
if (!detected) {
|
|
1926
1875
|
this.clearProbeProtocol(uuid, 'V2');
|
|
@@ -1981,19 +1930,6 @@ class ReactNativeBleTransport {
|
|
|
1981
1930
|
framePromise.reject(error);
|
|
1982
1931
|
}
|
|
1983
1932
|
}
|
|
1984
|
-
rememberStaleBondError(uuid, error) {
|
|
1985
|
-
this.staleBondErrors.set(uuid, error);
|
|
1986
|
-
this.rejectProtocolV2Frames(uuid, error);
|
|
1987
|
-
if (this.runPromise && this.runPromiseDeviceId === uuid) {
|
|
1988
|
-
this.runPromise.reject(error);
|
|
1989
|
-
}
|
|
1990
|
-
}
|
|
1991
|
-
throwIfStaleBondError(uuid) {
|
|
1992
|
-
const error = this.staleBondErrors.get(uuid);
|
|
1993
|
-
if (error) {
|
|
1994
|
-
throw error;
|
|
1995
|
-
}
|
|
1996
|
-
}
|
|
1997
1933
|
readProtocolV2Frame(uuid) {
|
|
1998
1934
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1999
1935
|
const queuedFrame = this.getProtocolV2FrameQueue(uuid).shift();
|
|
@@ -2042,11 +1978,6 @@ class ReactNativeBleTransport {
|
|
|
2042
1978
|
return;
|
|
2043
1979
|
}
|
|
2044
1980
|
catch (error) {
|
|
2045
|
-
if (isNativeBleStaleBondError(error) || hdShared.isBleStaleBondHardwareError(error)) {
|
|
2046
|
-
const bondError = toBleStaleBondHardwareError(error);
|
|
2047
|
-
this.rememberStaleBondError(uuid, bondError);
|
|
2048
|
-
throw bondError;
|
|
2049
|
-
}
|
|
2050
1981
|
if (getFirmwareUploadWriteRetryType(error) !== 'congested' ||
|
|
2051
1982
|
attempt >= FIRMWARE_UPLOAD_WRITE_MAX_RETRIES) {
|
|
2052
1983
|
throw error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.161",
|
|
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.0-alpha.
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
23
|
+
"@onekeyfe/hd-core": "1.2.0-alpha.161",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.161",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.161",
|
|
26
26
|
"@onekeyfe/react-native-ble-utils": "^0.1.6",
|
|
27
27
|
"react-native-ble-plx": "3.5.1"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "06316117fc9a7ebaecea1ca583b2d105709361bf"
|
|
30
30
|
}
|
|
@@ -109,11 +109,9 @@ const schemas = {
|
|
|
109
109
|
const createHarness = ({
|
|
110
110
|
deviceName = 'OneKey Pro 2',
|
|
111
111
|
isWritableWithResponse = true,
|
|
112
|
-
monitorError,
|
|
113
112
|
}: {
|
|
114
113
|
deviceName?: string;
|
|
115
114
|
isWritableWithResponse?: boolean;
|
|
116
|
-
monitorError?: (Error & { reason?: string; attErrorCode?: number; iosErrorCode?: number }) | null;
|
|
117
115
|
} = {}) => {
|
|
118
116
|
const uuid = 'rn-pro2-id';
|
|
119
117
|
const sentSeqs: number[] = [];
|
|
@@ -132,9 +130,6 @@ const createHarness = ({
|
|
|
132
130
|
isNotifiable: true,
|
|
133
131
|
monitor: jest.fn(callback => {
|
|
134
132
|
notifyCallback = callback;
|
|
135
|
-
if (monitorError) {
|
|
136
|
-
queueMicrotask(() => callback(monitorError, null));
|
|
137
|
-
}
|
|
138
133
|
return { remove: jest.fn() };
|
|
139
134
|
}),
|
|
140
135
|
};
|
|
@@ -464,35 +459,6 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
464
459
|
}
|
|
465
460
|
);
|
|
466
461
|
|
|
467
|
-
test.each([
|
|
468
|
-
[
|
|
469
|
-
'Encryption is insufficient',
|
|
470
|
-
{ reason: 'Encryption is insufficient', attErrorCode: 15 },
|
|
471
|
-
HardwareErrorCode.BleDeviceBondError,
|
|
472
|
-
],
|
|
473
|
-
[
|
|
474
|
-
'Peer removed pairing information',
|
|
475
|
-
{ reason: 'Peer removed pairing information', iosErrorCode: 14 },
|
|
476
|
-
HardwareErrorCode.BlePeerRemovedPairingInformation,
|
|
477
|
-
],
|
|
478
|
-
] as const)(
|
|
479
|
-
'fails Protocol V2 acquire immediately on %s instead of waiting for Ping',
|
|
480
|
-
async (_label, nativeError, errorCode) => {
|
|
481
|
-
const { transport, uuid, device } = createHarness({
|
|
482
|
-
monitorError: Object.assign(new Error(nativeError.reason), nativeError),
|
|
483
|
-
});
|
|
484
|
-
const probe = jest.spyOn(transport as any, 'probeProtocolV2');
|
|
485
|
-
|
|
486
|
-
await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
|
|
487
|
-
errorCode,
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
expect(probe).not.toHaveBeenCalled();
|
|
491
|
-
expect(device.cancelConnection).toHaveBeenCalled();
|
|
492
|
-
expect(transport.getProtocolType(uuid)).toBeUndefined();
|
|
493
|
-
}
|
|
494
|
-
);
|
|
495
|
-
|
|
496
462
|
test.each(['ios', 'android'] as const)(
|
|
497
463
|
'reports a stale bond on %s when a previously confirmed Protocol V2 device stops responding',
|
|
498
464
|
async platform => {
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PermissionsAndroid, Platform } from 'react-native';
|
|
2
2
|
import { Buffer } from 'buffer';
|
|
3
3
|
import {
|
|
4
|
+
BleATTErrorCode,
|
|
4
5
|
BleError,
|
|
5
6
|
BleErrorCode,
|
|
6
7
|
BleManager as BlePlxManager,
|
|
@@ -47,11 +48,6 @@ import {
|
|
|
47
48
|
getInfosForServiceUuid,
|
|
48
49
|
isSameBleUuid,
|
|
49
50
|
} from './constants';
|
|
50
|
-
import {
|
|
51
|
-
isBleStaleBondHardwareError,
|
|
52
|
-
isNativeBleStaleBondError,
|
|
53
|
-
toBleStaleBondHardwareError,
|
|
54
|
-
} from './bleStaleBond';
|
|
55
51
|
import { isHeaderChunk } from './utils/validateNotify';
|
|
56
52
|
import BleTransport from './BleTransport';
|
|
57
53
|
import timer from './utils/timer';
|
|
@@ -313,8 +309,13 @@ type IOBleErrorRemap = Error | BleError | null | undefined;
|
|
|
313
309
|
|
|
314
310
|
function remapError(error: IOBleErrorRemap) {
|
|
315
311
|
if (error instanceof BleError) {
|
|
316
|
-
if (
|
|
317
|
-
|
|
312
|
+
if (
|
|
313
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
314
|
+
// @ts-expect-error
|
|
315
|
+
error.iosErrorCode === BleATTErrorCode.UnlikelyError ||
|
|
316
|
+
error.reason === 'Peer removed pairing information'
|
|
317
|
+
) {
|
|
318
|
+
throw ERRORS.TypedError(HardwareErrorCode.BlePeerRemovedPairingInformation);
|
|
318
319
|
}
|
|
319
320
|
|
|
320
321
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -389,13 +390,6 @@ export default class ReactNativeBleTransport {
|
|
|
389
390
|
/** Consecutive detections that failed while trusting sessionProtocols. */
|
|
390
391
|
private protocolReprobeFailures: Map<string, number> = new Map();
|
|
391
392
|
|
|
392
|
-
/**
|
|
393
|
-
* Native encryption/pairing failures seen before Protocol V2 probe starts.
|
|
394
|
-
* Pro2/Neo GATT connect can succeed on a stale iOS bond; the CCCD write then
|
|
395
|
-
* fails with ATT 14/15. Remember it so detectProtocol fails immediately.
|
|
396
|
-
*/
|
|
397
|
-
private staleBondErrors: Map<string, Error> = new Map();
|
|
398
|
-
|
|
399
393
|
private protocolV2Assemblers: Map<string, ProtocolV2FrameAssembler> = new Map();
|
|
400
394
|
|
|
401
395
|
private protocolV2FrameQueues: Map<string, Uint8Array[]> = new Map();
|
|
@@ -1052,7 +1046,7 @@ export default class ReactNativeBleTransport {
|
|
|
1052
1046
|
this.attachDisconnectSubscription(currentTransport, currentTransport.device, uuid);
|
|
1053
1047
|
return { uuid, protocolType };
|
|
1054
1048
|
} catch (error) {
|
|
1055
|
-
if (
|
|
1049
|
+
if ((error as { errorCode?: unknown })?.errorCode === HardwareErrorCode.BleDeviceBondError) {
|
|
1056
1050
|
await this.disconnectUnlocked(uuid);
|
|
1057
1051
|
} else {
|
|
1058
1052
|
await this.releaseUnlocked(uuid, true);
|
|
@@ -1085,18 +1079,17 @@ export default class ReactNativeBleTransport {
|
|
|
1085
1079
|
Log?.debug('monitor error ignored for stale transport: ', uuid, notifyTransactionId);
|
|
1086
1080
|
return;
|
|
1087
1081
|
}
|
|
1088
|
-
if (isNativeBleStaleBondError(error)) {
|
|
1089
|
-
this.rememberStaleBondError(uuid, toBleStaleBondHardwareError(error));
|
|
1090
|
-
return;
|
|
1091
|
-
}
|
|
1092
1082
|
if (this.getActiveProtocol(uuid) === 'V2') {
|
|
1093
1083
|
let errorCode:
|
|
1084
|
+
| typeof HardwareErrorCode.BleDeviceBondError
|
|
1094
1085
|
| typeof HardwareErrorCode.BleCharacteristicNotifyError
|
|
1095
1086
|
| typeof HardwareErrorCode.BleCharacteristicNotifyChangeFailure
|
|
1096
1087
|
| typeof HardwareErrorCode.BleTimeoutError =
|
|
1097
1088
|
HardwareErrorCode.BleCharacteristicNotifyError;
|
|
1098
1089
|
if (error.reason?.includes('The connection has timed out unexpectedly')) {
|
|
1099
1090
|
errorCode = HardwareErrorCode.BleTimeoutError;
|
|
1091
|
+
} else if (error.reason?.includes('Encryption is insufficient')) {
|
|
1092
|
+
errorCode = HardwareErrorCode.BleDeviceBondError;
|
|
1100
1093
|
} else if (
|
|
1101
1094
|
error.reason?.includes('Cannot write client characteristic config descriptor') ||
|
|
1102
1095
|
error.reason?.includes('Cannot find client characteristic config descriptor') ||
|
|
@@ -1111,12 +1104,16 @@ export default class ReactNativeBleTransport {
|
|
|
1111
1104
|
}
|
|
1112
1105
|
if (this.runPromise && this.runPromiseDeviceId === uuid) {
|
|
1113
1106
|
let ERROR:
|
|
1107
|
+
| typeof HardwareErrorCode.BleDeviceBondError
|
|
1114
1108
|
| typeof HardwareErrorCode.BleCharacteristicNotifyError
|
|
1115
1109
|
| typeof HardwareErrorCode.BleTimeoutError =
|
|
1116
1110
|
HardwareErrorCode.BleCharacteristicNotifyError;
|
|
1117
1111
|
if (error.reason?.includes('The connection has timed out unexpectedly')) {
|
|
1118
1112
|
ERROR = HardwareErrorCode.BleTimeoutError;
|
|
1119
1113
|
}
|
|
1114
|
+
if (error.reason?.includes('Encryption is insufficient')) {
|
|
1115
|
+
ERROR = HardwareErrorCode.BleDeviceBondError;
|
|
1116
|
+
}
|
|
1120
1117
|
if (
|
|
1121
1118
|
error.reason?.includes('Cannot write client characteristic config descriptor') ||
|
|
1122
1119
|
error.reason?.includes('Cannot find client characteristic config descriptor') || // pro firmware 2.3.0 upgrade
|
|
@@ -1251,7 +1248,6 @@ export default class ReactNativeBleTransport {
|
|
|
1251
1248
|
|
|
1252
1249
|
this.deviceProtocol.delete(uuid);
|
|
1253
1250
|
this.probingProtocols.delete(uuid);
|
|
1254
|
-
this.staleBondErrors.delete(uuid);
|
|
1255
1251
|
// Confirmed protocol and caller hints stay in deviceProtocol / protocolHint.
|
|
1256
1252
|
this.protocolV2Assemblers.get(uuid)?.reset();
|
|
1257
1253
|
this.protocolV2Assemblers.delete(uuid);
|
|
@@ -1389,9 +1385,6 @@ export default class ReactNativeBleTransport {
|
|
|
1389
1385
|
if (isWedgedWriteError(e)) {
|
|
1390
1386
|
throw e;
|
|
1391
1387
|
}
|
|
1392
|
-
if (isNativeBleStaleBondError(e) || isBleStaleBondHardwareError(e)) {
|
|
1393
|
-
throw toBleStaleBondHardwareError(e);
|
|
1394
|
-
}
|
|
1395
1388
|
throw ERRORS.TypedError(HardwareErrorCode.BleWriteCharacteristicError);
|
|
1396
1389
|
}
|
|
1397
1390
|
}
|
|
@@ -1426,9 +1419,6 @@ export default class ReactNativeBleTransport {
|
|
|
1426
1419
|
if (isWedgedWriteError(e)) {
|
|
1427
1420
|
throw e;
|
|
1428
1421
|
}
|
|
1429
|
-
if (isNativeBleStaleBondError(e) || isBleStaleBondHardwareError(e)) {
|
|
1430
|
-
throw toBleStaleBondHardwareError(e);
|
|
1431
|
-
}
|
|
1432
1422
|
throw ERRORS.TypedError(HardwareErrorCode.BleWriteCharacteristicError);
|
|
1433
1423
|
}
|
|
1434
1424
|
}
|
|
@@ -1521,11 +1511,6 @@ export default class ReactNativeBleTransport {
|
|
|
1521
1511
|
if (isWedgedWriteError(e)) {
|
|
1522
1512
|
throw e;
|
|
1523
1513
|
}
|
|
1524
|
-
if (isNativeBleStaleBondError(e) || isBleStaleBondHardwareError(e)) {
|
|
1525
|
-
const bondError = toBleStaleBondHardwareError(e);
|
|
1526
|
-
this.rememberStaleBondError(uuid, bondError);
|
|
1527
|
-
throw bondError;
|
|
1528
|
-
}
|
|
1529
1514
|
if (e.errorCode === BleErrorCode.DeviceDisconnected) {
|
|
1530
1515
|
throw ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded);
|
|
1531
1516
|
} else if (e.errorCode === BleErrorCode.OperationStartFailed) {
|
|
@@ -1635,7 +1620,6 @@ export default class ReactNativeBleTransport {
|
|
|
1635
1620
|
}
|
|
1636
1621
|
this.deviceProtocol.delete(session);
|
|
1637
1622
|
this.probingProtocols.delete(session);
|
|
1638
|
-
this.staleBondErrors.delete(session);
|
|
1639
1623
|
this.deviceProtocolHints.delete(session);
|
|
1640
1624
|
this.sessionProtocols.delete(session);
|
|
1641
1625
|
this.protocolReprobeFailures.delete(session);
|
|
@@ -1859,7 +1843,6 @@ export default class ReactNativeBleTransport {
|
|
|
1859
1843
|
}
|
|
1860
1844
|
this.deviceProtocol.delete(uuid);
|
|
1861
1845
|
this.probingProtocols.delete(uuid);
|
|
1862
|
-
this.staleBondErrors.delete(uuid);
|
|
1863
1846
|
this.protocolV2Assemblers.delete(uuid);
|
|
1864
1847
|
this.resetProtocolV2Frames(uuid);
|
|
1865
1848
|
|
|
@@ -1956,7 +1939,6 @@ export default class ReactNativeBleTransport {
|
|
|
1956
1939
|
}
|
|
1957
1940
|
this.deviceProtocol.delete(uuid);
|
|
1958
1941
|
this.probingProtocols.delete(uuid);
|
|
1959
|
-
this.staleBondErrors.delete(uuid);
|
|
1960
1942
|
this.protocolV2Assemblers.delete(uuid);
|
|
1961
1943
|
this.resetProtocolV2Frames(uuid);
|
|
1962
1944
|
|
|
@@ -2007,7 +1989,6 @@ export default class ReactNativeBleTransport {
|
|
|
2007
1989
|
});
|
|
2008
1990
|
this.deviceProtocol.clear();
|
|
2009
1991
|
this.probingProtocols.clear();
|
|
2010
|
-
this.staleBondErrors.clear();
|
|
2011
1992
|
this.sessionProtocols.clear();
|
|
2012
1993
|
this.confirmedProtocolV2.clear();
|
|
2013
1994
|
this.protocolReprobeFailures.clear();
|
|
@@ -2072,10 +2053,6 @@ export default class ReactNativeBleTransport {
|
|
|
2072
2053
|
return expectedProtocol;
|
|
2073
2054
|
}
|
|
2074
2055
|
|
|
2075
|
-
// iOS Classic/Touch/Pro skip probing above. Pro2/Neo still probe, and a stale
|
|
2076
|
-
// OS bond must not wait for Ping/GetFeatures timeouts after ATT 14/15.
|
|
2077
|
-
this.throwIfStaleBondError(uuid);
|
|
2078
|
-
|
|
2079
2056
|
if (expectedProtocol === 'V1') {
|
|
2080
2057
|
if (await this.probeProtocolV1(uuid)) {
|
|
2081
2058
|
this.deviceProtocol.set(uuid, 'V1');
|
|
@@ -2232,7 +2209,7 @@ export default class ReactNativeBleTransport {
|
|
|
2232
2209
|
Log?.debug('[ReactNativeBleTransport] Protocol V1 GetFeatures probe failed:', error);
|
|
2233
2210
|
// A wedged write already dropped the link, so probing another protocol on it
|
|
2234
2211
|
// would only fail against a torn-down transport: surface the real cause.
|
|
2235
|
-
if (isWedgedWriteError(error)
|
|
2212
|
+
if (isWedgedWriteError(error)) {
|
|
2236
2213
|
throw error;
|
|
2237
2214
|
}
|
|
2238
2215
|
return false;
|
|
@@ -2246,7 +2223,6 @@ export default class ReactNativeBleTransport {
|
|
|
2246
2223
|
|
|
2247
2224
|
this.probingProtocols.set(uuid, 'V2');
|
|
2248
2225
|
this.protocolV2Assemblers.get(uuid)?.reset();
|
|
2249
|
-
this.throwIfStaleBondError(uuid);
|
|
2250
2226
|
const detected = await probeProtocolV2Helper({
|
|
2251
2227
|
call: (name: string, data: Record<string, unknown>, options?: TransportCallOptions) =>
|
|
2252
2228
|
this.callProtocolV2(uuid, name, data, options),
|
|
@@ -2257,7 +2233,6 @@ export default class ReactNativeBleTransport {
|
|
|
2257
2233
|
this.protocolV2Assemblers.get(uuid)?.reset();
|
|
2258
2234
|
this.resetProtocolV2Frames(uuid);
|
|
2259
2235
|
},
|
|
2260
|
-
shouldRethrow: isBleStaleBondHardwareError,
|
|
2261
2236
|
});
|
|
2262
2237
|
if (!detected) {
|
|
2263
2238
|
this.clearProbeProtocol(uuid, 'V2');
|
|
@@ -2326,21 +2301,6 @@ export default class ReactNativeBleTransport {
|
|
|
2326
2301
|
}
|
|
2327
2302
|
}
|
|
2328
2303
|
|
|
2329
|
-
private rememberStaleBondError(uuid: string, error: Error) {
|
|
2330
|
-
this.staleBondErrors.set(uuid, error);
|
|
2331
|
-
this.rejectProtocolV2Frames(uuid, error);
|
|
2332
|
-
if (this.runPromise && this.runPromiseDeviceId === uuid) {
|
|
2333
|
-
this.runPromise.reject(error);
|
|
2334
|
-
}
|
|
2335
|
-
}
|
|
2336
|
-
|
|
2337
|
-
private throwIfStaleBondError(uuid: string) {
|
|
2338
|
-
const error = this.staleBondErrors.get(uuid);
|
|
2339
|
-
if (error) {
|
|
2340
|
-
throw error;
|
|
2341
|
-
}
|
|
2342
|
-
}
|
|
2343
|
-
|
|
2344
2304
|
private async readProtocolV2Frame(uuid: string) {
|
|
2345
2305
|
const queuedFrame = this.getProtocolV2FrameQueue(uuid).shift();
|
|
2346
2306
|
if (queuedFrame) {
|
|
@@ -2399,11 +2359,6 @@ export default class ReactNativeBleTransport {
|
|
|
2399
2359
|
assertCurrentGeneration();
|
|
2400
2360
|
return;
|
|
2401
2361
|
} catch (error) {
|
|
2402
|
-
if (isNativeBleStaleBondError(error) || isBleStaleBondHardwareError(error)) {
|
|
2403
|
-
const bondError = toBleStaleBondHardwareError(error);
|
|
2404
|
-
this.rememberStaleBondError(uuid, bondError);
|
|
2405
|
-
throw bondError;
|
|
2406
|
-
}
|
|
2407
2362
|
if (
|
|
2408
2363
|
getFirmwareUploadWriteRetryType(error) !== 'congested' ||
|
|
2409
2364
|
attempt >= FIRMWARE_UPLOAD_WRITE_MAX_RETRIES
|
package/dist/bleStaleBond.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,OAgB1D,CAAC;AAEF,eAAO,MAAM,2BAA2B,UAAW,OAAO,UAkBzD,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
{ attErrorCode: 14, reason: 'Unlikely error' },
|
|
21
|
-
HardwareErrorCode.BlePeerRemovedPairingInformation,
|
|
22
|
-
],
|
|
23
|
-
])('maps %j to %s', (nativeError, errorCode) => {
|
|
24
|
-
expect(isNativeBleStaleBondError(nativeError)).toBe(true);
|
|
25
|
-
expect(toBleStaleBondHardwareError(nativeError)).toMatchObject({ errorCode });
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('does not treat a generic disconnect as a stale bond', () => {
|
|
29
|
-
expect(isNativeBleStaleBondError({ reason: 'Device disconnected' })).toBe(false);
|
|
30
|
-
});
|
|
31
|
-
});
|
package/src/bleStaleBond.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ERRORS,
|
|
3
|
-
HardwareErrorCode,
|
|
4
|
-
isBleStaleBondErrorText,
|
|
5
|
-
isBleStaleBondHardwareError,
|
|
6
|
-
} from '@onekeyfe/hd-shared';
|
|
7
|
-
|
|
8
|
-
export { isBleStaleBondHardwareError };
|
|
9
|
-
|
|
10
|
-
const ATT_INSUFFICIENT_AUTHENTICATION = 5;
|
|
11
|
-
const ATT_UNLIKELY_ERROR = 14;
|
|
12
|
-
const ATT_INSUFFICIENT_ENCRYPTION = 15;
|
|
13
|
-
const IOS_PEER_REMOVED_PAIRING_INFORMATION = 14;
|
|
14
|
-
|
|
15
|
-
type NativeBleErrorFields = {
|
|
16
|
-
attErrorCode?: unknown;
|
|
17
|
-
iosErrorCode?: unknown;
|
|
18
|
-
reason?: unknown;
|
|
19
|
-
message?: unknown;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const nativeErrorText = (error: NativeBleErrorFields) =>
|
|
23
|
-
[error.reason, error.message]
|
|
24
|
-
.filter((value): value is string => typeof value === 'string')
|
|
25
|
-
.join(' ');
|
|
26
|
-
|
|
27
|
-
export const isNativeBleStaleBondError = (error: unknown): boolean => {
|
|
28
|
-
if (!error || typeof error !== 'object') {
|
|
29
|
-
return typeof error === 'string' ? isBleStaleBondErrorText(error) : false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const nativeError = error as NativeBleErrorFields;
|
|
33
|
-
if (
|
|
34
|
-
nativeError.attErrorCode === ATT_INSUFFICIENT_AUTHENTICATION ||
|
|
35
|
-
nativeError.attErrorCode === ATT_UNLIKELY_ERROR ||
|
|
36
|
-
nativeError.attErrorCode === ATT_INSUFFICIENT_ENCRYPTION ||
|
|
37
|
-
nativeError.iosErrorCode === IOS_PEER_REMOVED_PAIRING_INFORMATION
|
|
38
|
-
) {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return isBleStaleBondErrorText(nativeErrorText(nativeError));
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const toBleStaleBondHardwareError = (error: unknown) => {
|
|
46
|
-
if (isBleStaleBondHardwareError(error)) {
|
|
47
|
-
return error as Error;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const nativeError = (error ?? {}) as NativeBleErrorFields;
|
|
51
|
-
const text = nativeErrorText(nativeError);
|
|
52
|
-
const peerRemoved =
|
|
53
|
-
nativeError.iosErrorCode === IOS_PEER_REMOVED_PAIRING_INFORMATION ||
|
|
54
|
-
nativeError.attErrorCode === ATT_UNLIKELY_ERROR ||
|
|
55
|
-
text.includes('Peer removed pairing information');
|
|
56
|
-
|
|
57
|
-
return ERRORS.TypedError(
|
|
58
|
-
peerRemoved
|
|
59
|
-
? HardwareErrorCode.BlePeerRemovedPairingInformation
|
|
60
|
-
: HardwareErrorCode.BleDeviceBondError,
|
|
61
|
-
text || undefined
|
|
62
|
-
);
|
|
63
|
-
};
|