@onekeyfe/hd-transport-react-native 1.2.2-alpha.10 → 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.
- package/dist/bleStaleBond.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -13
- package/package.json +5 -5
- package/src/__tests__/bleStaleBond.test.ts +8 -0
- package/src/__tests__/protocolV2Link.test.ts +81 -0
- package/src/bleStaleBond.ts +3 -0
- package/src/index.ts +30 -13
|
@@ -1 +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;
|
|
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"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAGL,UAAU,IAAI,aAAa,EAG5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAChB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAI1B,MAAM,wBAAwB,CAAC;AA+BhC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAI1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACp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AoB;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
|
@@ -207,6 +207,8 @@ const isNativeBleStaleBondError = (error) => {
|
|
|
207
207
|
const nativeError = error;
|
|
208
208
|
if (nativeError.attErrorCode === ATT_INSUFFICIENT_AUTHENTICATION ||
|
|
209
209
|
nativeError.attErrorCode === ATT_INSUFFICIENT_ENCRYPTION ||
|
|
210
|
+
nativeError.androidErrorCode === ATT_INSUFFICIENT_AUTHENTICATION ||
|
|
211
|
+
nativeError.androidErrorCode === ATT_INSUFFICIENT_ENCRYPTION ||
|
|
210
212
|
nativeError.iosErrorCode === IOS_PEER_REMOVED_PAIRING_INFORMATION) {
|
|
211
213
|
return true;
|
|
212
214
|
}
|
|
@@ -404,10 +406,10 @@ const requestNegotiatedMtu = (device, stage, attempt) => __awaiter(void 0, void
|
|
|
404
406
|
}
|
|
405
407
|
});
|
|
406
408
|
const resolveNegotiatedMtu = (device) => requestNegotiatedMtu(device, 'connected', 0);
|
|
407
|
-
function remapError(error
|
|
409
|
+
function remapError(error) {
|
|
408
410
|
var _a;
|
|
409
411
|
if (error instanceof reactNativeBlePlx.BleError) {
|
|
410
|
-
if (
|
|
412
|
+
if (isNativeBleStaleBondError(error)) {
|
|
411
413
|
throw toBleStaleBondHardwareError(error);
|
|
412
414
|
}
|
|
413
415
|
if ((error === null || error === void 0 ? void 0 : error.attErrorCode) === 22) {
|
|
@@ -892,15 +894,6 @@ class ReactNativeBleTransport {
|
|
|
892
894
|
Log === null || Log === void 0 ? void 0 : Log.debug('subscribeBleOn error: ', error);
|
|
893
895
|
throw error;
|
|
894
896
|
}
|
|
895
|
-
if (reactNative.Platform.OS === 'android') {
|
|
896
|
-
const bondState = yield pairDevice(uuid);
|
|
897
|
-
if (bondState.bonding) {
|
|
898
|
-
yield onDeviceBondState(uuid);
|
|
899
|
-
}
|
|
900
|
-
else if (!bondState.bonded) {
|
|
901
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
897
|
if (!device) {
|
|
905
898
|
const devices = yield blePlxManager.devices([uuid]);
|
|
906
899
|
[device] = devices;
|
|
@@ -931,7 +924,7 @@ class ReactNativeBleTransport {
|
|
|
931
924
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleAlreadyConnected);
|
|
932
925
|
}
|
|
933
926
|
else {
|
|
934
|
-
remapError(e
|
|
927
|
+
remapError(e);
|
|
935
928
|
}
|
|
936
929
|
}
|
|
937
930
|
}
|
|
@@ -965,8 +958,29 @@ class ReactNativeBleTransport {
|
|
|
965
958
|
}
|
|
966
959
|
}
|
|
967
960
|
else {
|
|
968
|
-
remapError(e
|
|
961
|
+
remapError(e);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
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);
|
|
969
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;
|
|
970
984
|
}
|
|
971
985
|
}
|
|
972
986
|
device = yield resolveNegotiatedMtu(device);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.2.2-alpha.
|
|
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.
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.2-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.2-alpha.
|
|
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": "
|
|
29
|
+
"gitHead": "b9a5ca0c73e5e2cc979c91c007ace476e442718c"
|
|
30
30
|
}
|
|
@@ -12,6 +12,14 @@ describe('native BLE stale bond mapping', () => {
|
|
|
12
12
|
{ attErrorCode: 5, reason: 'GATT_INSUF_AUTHENTICATION' },
|
|
13
13
|
HardwareErrorCode.BleDeviceBondError,
|
|
14
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
|
+
],
|
|
15
23
|
[
|
|
16
24
|
{ iosErrorCode: 14, reason: 'Peer removed pairing information' },
|
|
17
25
|
HardwareErrorCode.BlePeerRemovedPairingInformation,
|
|
@@ -360,6 +360,87 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
360
360
|
expect(new ReactNativeBleTransport({}).scanTimeout).toBe(3000);
|
|
361
361
|
});
|
|
362
362
|
|
|
363
|
+
test('connects the Android GATT link before starting system bonding', async () => {
|
|
364
|
+
setPlatformOS('android');
|
|
365
|
+
const { transport, uuid, device } = createHarness();
|
|
366
|
+
const operationOrder: string[] = [];
|
|
367
|
+
const pairDeviceMock = jest.requireMock('../BleManager').pairDevice as jest.Mock;
|
|
368
|
+
|
|
369
|
+
device.isConnected.mockResolvedValueOnce(false);
|
|
370
|
+
device.connect = jest.fn(() => {
|
|
371
|
+
operationOrder.push('connect');
|
|
372
|
+
return Promise.resolve(device);
|
|
373
|
+
});
|
|
374
|
+
pairDeviceMock.mockImplementationOnce(() => {
|
|
375
|
+
operationOrder.push('bond');
|
|
376
|
+
return Promise.resolve({ bonded: true, bonding: false });
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).resolves.toEqual({
|
|
380
|
+
uuid,
|
|
381
|
+
protocolType: 'V2',
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
expect(operationOrder).toEqual(['connect', 'bond']);
|
|
385
|
+
await transport.release(uuid, true);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
test.each([
|
|
389
|
+
[
|
|
390
|
+
'ios',
|
|
391
|
+
'OneKey Neo',
|
|
392
|
+
{
|
|
393
|
+
iosErrorCode: 14,
|
|
394
|
+
reason: 'Peer removed pairing information',
|
|
395
|
+
},
|
|
396
|
+
HardwareErrorCode.BlePeerRemovedPairingInformation,
|
|
397
|
+
],
|
|
398
|
+
[
|
|
399
|
+
'android',
|
|
400
|
+
'OneKey Pro 2',
|
|
401
|
+
{
|
|
402
|
+
androidErrorCode: 5,
|
|
403
|
+
reason: 'Connection state changed with status 5',
|
|
404
|
+
},
|
|
405
|
+
HardwareErrorCode.BleDeviceBondError,
|
|
406
|
+
],
|
|
407
|
+
] as const)(
|
|
408
|
+
'maps a %s %s stale bond during connect before protocol detection',
|
|
409
|
+
async (platform, deviceName, nativeError, errorCode) => {
|
|
410
|
+
setPlatformOS(platform);
|
|
411
|
+
const { transport, uuid, device } = createHarness({ deviceName });
|
|
412
|
+
const BleErrorMock = jest.requireMock('react-native-ble-plx').BleError as new (
|
|
413
|
+
message: string
|
|
414
|
+
) => Error;
|
|
415
|
+
const pairDeviceMock = jest.requireMock('../BleManager').pairDevice as jest.Mock;
|
|
416
|
+
pairDeviceMock.mockClear();
|
|
417
|
+
|
|
418
|
+
device.isConnected.mockResolvedValueOnce(false);
|
|
419
|
+
device.connect = jest
|
|
420
|
+
.fn()
|
|
421
|
+
.mockRejectedValue(Object.assign(new BleErrorMock(nativeError.reason), nativeError));
|
|
422
|
+
|
|
423
|
+
await expect(transport.acquire({ uuid })).rejects.toMatchObject({ errorCode });
|
|
424
|
+
expect(pairDeviceMock).not.toHaveBeenCalled();
|
|
425
|
+
expect(transport.getProtocolType(uuid)).toBeUndefined();
|
|
426
|
+
}
|
|
427
|
+
);
|
|
428
|
+
|
|
429
|
+
test('closes the Android GATT link when system bonding fails', async () => {
|
|
430
|
+
setPlatformOS('android');
|
|
431
|
+
const { transport, uuid, device, bleManager } = createHarness();
|
|
432
|
+
const pairDeviceMock = jest.requireMock('../BleManager').pairDevice as jest.Mock;
|
|
433
|
+
|
|
434
|
+
pairDeviceMock.mockRejectedValueOnce(new Error('bonding canceled'));
|
|
435
|
+
|
|
436
|
+
await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toThrow(
|
|
437
|
+
'bonding canceled'
|
|
438
|
+
);
|
|
439
|
+
|
|
440
|
+
expect(bleManager.cancelDeviceConnection).toHaveBeenCalledWith(uuid);
|
|
441
|
+
expect(device.cancelConnection).toHaveBeenCalledTimes(1);
|
|
442
|
+
});
|
|
443
|
+
|
|
363
444
|
test('uses withResponse for consecutive iOS Protocol V1 control commands without releasing', async () => {
|
|
364
445
|
const { transport, uuid, writeCharacteristic } = createV1Harness({
|
|
365
446
|
respondOnWriteCount: [1, 2],
|
package/src/bleStaleBond.ts
CHANGED
|
@@ -13,6 +13,7 @@ const IOS_PEER_REMOVED_PAIRING_INFORMATION = 14;
|
|
|
13
13
|
|
|
14
14
|
type NativeBleErrorFields = {
|
|
15
15
|
attErrorCode?: unknown;
|
|
16
|
+
androidErrorCode?: unknown;
|
|
16
17
|
iosErrorCode?: unknown;
|
|
17
18
|
reason?: unknown;
|
|
18
19
|
message?: unknown;
|
|
@@ -32,6 +33,8 @@ export const isNativeBleStaleBondError = (error: unknown): boolean => {
|
|
|
32
33
|
if (
|
|
33
34
|
nativeError.attErrorCode === ATT_INSUFFICIENT_AUTHENTICATION ||
|
|
34
35
|
nativeError.attErrorCode === ATT_INSUFFICIENT_ENCRYPTION ||
|
|
36
|
+
nativeError.androidErrorCode === ATT_INSUFFICIENT_AUTHENTICATION ||
|
|
37
|
+
nativeError.androidErrorCode === ATT_INSUFFICIENT_ENCRYPTION ||
|
|
35
38
|
nativeError.iosErrorCode === IOS_PEER_REMOVED_PAIRING_INFORMATION
|
|
36
39
|
) {
|
|
37
40
|
return true;
|
package/src/index.ts
CHANGED
|
@@ -320,9 +320,9 @@ const resolveNegotiatedMtu = (device: Device) => requestNegotiatedMtu(device, 'c
|
|
|
320
320
|
|
|
321
321
|
type IOBleErrorRemap = Error | BleError | null | undefined;
|
|
322
322
|
|
|
323
|
-
function remapError(error: IOBleErrorRemap
|
|
323
|
+
function remapError(error: IOBleErrorRemap) {
|
|
324
324
|
if (error instanceof BleError) {
|
|
325
|
-
if (
|
|
325
|
+
if (isNativeBleStaleBondError(error)) {
|
|
326
326
|
throw toBleStaleBondHardwareError(error);
|
|
327
327
|
}
|
|
328
328
|
|
|
@@ -980,15 +980,6 @@ export default class ReactNativeBleTransport {
|
|
|
980
980
|
throw error;
|
|
981
981
|
}
|
|
982
982
|
|
|
983
|
-
if (Platform.OS === 'android') {
|
|
984
|
-
const bondState = await pairDevice(uuid);
|
|
985
|
-
if (bondState.bonding) {
|
|
986
|
-
await onDeviceBondState(uuid);
|
|
987
|
-
} else if (!bondState.bonded) {
|
|
988
|
-
throw ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
|
|
992
983
|
if (!device) {
|
|
993
984
|
const devices = await blePlxManager.devices([uuid]);
|
|
994
985
|
[device] = devices;
|
|
@@ -1024,7 +1015,7 @@ export default class ReactNativeBleTransport {
|
|
|
1024
1015
|
Log?.debug('device already connected');
|
|
1025
1016
|
throw ERRORS.TypedError(HardwareErrorCode.BleAlreadyConnected);
|
|
1026
1017
|
} else {
|
|
1027
|
-
remapError(e
|
|
1018
|
+
remapError(e);
|
|
1028
1019
|
}
|
|
1029
1020
|
}
|
|
1030
1021
|
}
|
|
@@ -1068,11 +1059,37 @@ export default class ReactNativeBleTransport {
|
|
|
1068
1059
|
}
|
|
1069
1060
|
}
|
|
1070
1061
|
} else {
|
|
1071
|
-
remapError(e
|
|
1062
|
+
remapError(e);
|
|
1072
1063
|
}
|
|
1073
1064
|
}
|
|
1074
1065
|
}
|
|
1075
1066
|
|
|
1067
|
+
if (Platform.OS === 'android') {
|
|
1068
|
+
// Establish the LE link before createBond(). Without an existing LE ACL,
|
|
1069
|
+
// Android TRANSPORT_AUTO can choose BR/EDR for a BLE-only device.
|
|
1070
|
+
const connectedDevice = device;
|
|
1071
|
+
try {
|
|
1072
|
+
const bondState = await pairDevice(uuid);
|
|
1073
|
+
if (bondState.bonding) {
|
|
1074
|
+
await onDeviceBondState(uuid);
|
|
1075
|
+
} else if (!bondState.bonded) {
|
|
1076
|
+
throw ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
|
|
1077
|
+
}
|
|
1078
|
+
} catch (error) {
|
|
1079
|
+
await this.runNativeTeardown(uuid, blePlxManager, async () => {
|
|
1080
|
+
await Promise.all([
|
|
1081
|
+
this.runBestEffortNativeOperation('bond failure: cancel manager connection', () =>
|
|
1082
|
+
blePlxManager.cancelDeviceConnection(uuid)
|
|
1083
|
+
),
|
|
1084
|
+
this.runBestEffortNativeOperation('bond failure: cancel device connection', () =>
|
|
1085
|
+
connectedDevice.cancelConnection()
|
|
1086
|
+
),
|
|
1087
|
+
]);
|
|
1088
|
+
});
|
|
1089
|
+
throw error;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1076
1093
|
device = await resolveNegotiatedMtu(device);
|
|
1077
1094
|
const acquiredDevice = device;
|
|
1078
1095
|
const { writeCharacteristic, notifyCharacteristic } =
|