@onekeyfe/hd-transport-react-native 1.2.0-alpha.143 → 1.2.0-alpha.144
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 +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -4
- package/package.json +5 -5
- package/src/__tests__/protocolV2Link.test.ts +38 -1
- package/src/index.ts +29 -6
package/dist/index.d.ts
CHANGED
|
@@ -121,6 +121,10 @@ declare class ReactNativeBleTransport {
|
|
|
121
121
|
private deviceProtocolHints;
|
|
122
122
|
/** Protocol this device actually answered on, kept across reconnects of one session. */
|
|
123
123
|
private sessionProtocols;
|
|
124
|
+
/** Endpoints that answered a V2 probe in this transport lifetime. Survives disconnect. */
|
|
125
|
+
private confirmedProtocolV2;
|
|
126
|
+
/** First expected-V2 miss for an unconfirmed endpoint; the next miss is a stale bond. */
|
|
127
|
+
private retryableV2Mismatch;
|
|
124
128
|
/** Consecutive detections that failed while trusting sessionProtocols. */
|
|
125
129
|
private protocolReprobeFailures;
|
|
126
130
|
private protocolV2Assemblers;
|
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,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,EAA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AC,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
|
@@ -404,6 +404,8 @@ class ReactNativeBleTransport {
|
|
|
404
404
|
this.connectionSetupTimeoutCounts = new Map();
|
|
405
405
|
this.deviceProtocolHints = new Map();
|
|
406
406
|
this.sessionProtocols = new Map();
|
|
407
|
+
this.confirmedProtocolV2 = new Set();
|
|
408
|
+
this.retryableV2Mismatch = new Set();
|
|
407
409
|
this.protocolReprobeFailures = new Map();
|
|
408
410
|
this.protocolV2Assemblers = new Map();
|
|
409
411
|
this.protocolV2FrameQueues = new Map();
|
|
@@ -1664,6 +1666,8 @@ class ReactNativeBleTransport {
|
|
|
1664
1666
|
this.deviceProtocol.clear();
|
|
1665
1667
|
this.probingProtocols.clear();
|
|
1666
1668
|
this.sessionProtocols.clear();
|
|
1669
|
+
this.confirmedProtocolV2.clear();
|
|
1670
|
+
this.retryableV2Mismatch.clear();
|
|
1667
1671
|
this.protocolReprobeFailures.clear();
|
|
1668
1672
|
this.writeTimeoutCounts.clear();
|
|
1669
1673
|
this.connectionSetupTimeoutCounts.clear();
|
|
@@ -1676,8 +1680,16 @@ class ReactNativeBleTransport {
|
|
|
1676
1680
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE manager destroy failed (ignored):', error);
|
|
1677
1681
|
}
|
|
1678
1682
|
}
|
|
1679
|
-
createProtocolMismatchError(expected) {
|
|
1680
|
-
|
|
1683
|
+
createProtocolMismatchError(expected, uuid) {
|
|
1684
|
+
const isStaleV2Bond = expected === 'V2' &&
|
|
1685
|
+
(this.confirmedProtocolV2.has(uuid) || this.retryableV2Mismatch.has(uuid));
|
|
1686
|
+
if (expected === 'V2' && !isStaleV2Bond) {
|
|
1687
|
+
this.retryableV2Mismatch.add(uuid);
|
|
1688
|
+
}
|
|
1689
|
+
else if (isStaleV2Bond) {
|
|
1690
|
+
this.retryableV2Mismatch.delete(uuid);
|
|
1691
|
+
}
|
|
1692
|
+
return hdShared.ERRORS.TypedError(isStaleV2Bond ? hdShared.HardwareErrorCode.BleDeviceBondError : hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`);
|
|
1681
1693
|
}
|
|
1682
1694
|
createProtocolDetectionError() {
|
|
1683
1695
|
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, 'Unable to detect BLE protocol: device did not respond to Protocol V1 GetFeatures or Protocol V2 Ping');
|
|
@@ -1717,12 +1729,14 @@ class ReactNativeBleTransport {
|
|
|
1717
1729
|
});
|
|
1718
1730
|
return 'V1';
|
|
1719
1731
|
}
|
|
1720
|
-
throw this.createProtocolMismatchError(expectedProtocol);
|
|
1732
|
+
throw this.createProtocolMismatchError(expectedProtocol, uuid);
|
|
1721
1733
|
}
|
|
1722
1734
|
if (expectedProtocol === 'V2') {
|
|
1723
1735
|
if (yield this.probeProtocolV2(uuid)) {
|
|
1724
1736
|
this.deviceProtocol.set(uuid, 'V2');
|
|
1725
1737
|
this.sessionProtocols.set(uuid, 'V2');
|
|
1738
|
+
this.confirmedProtocolV2.add(uuid);
|
|
1739
|
+
this.retryableV2Mismatch.delete(uuid);
|
|
1726
1740
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1727
1741
|
deviceId: uuid,
|
|
1728
1742
|
protocol: 'V2',
|
|
@@ -1730,7 +1744,7 @@ class ReactNativeBleTransport {
|
|
|
1730
1744
|
});
|
|
1731
1745
|
return 'V2';
|
|
1732
1746
|
}
|
|
1733
|
-
throw this.createProtocolMismatchError(expectedProtocol);
|
|
1747
|
+
throw this.createProtocolMismatchError(expectedProtocol, uuid);
|
|
1734
1748
|
}
|
|
1735
1749
|
const sessionProtocol = this.sessionProtocols.get(uuid);
|
|
1736
1750
|
const reprobeFailures = (_a = this.protocolReprobeFailures.get(uuid)) !== null && _a !== void 0 ? _a : 0;
|
|
@@ -1754,6 +1768,10 @@ class ReactNativeBleTransport {
|
|
|
1754
1768
|
if (detected) {
|
|
1755
1769
|
this.deviceProtocol.set(uuid, protocol);
|
|
1756
1770
|
this.sessionProtocols.set(uuid, protocol);
|
|
1771
|
+
if (protocol === 'V2') {
|
|
1772
|
+
this.confirmedProtocolV2.add(uuid);
|
|
1773
|
+
this.retryableV2Mismatch.delete(uuid);
|
|
1774
|
+
}
|
|
1757
1775
|
this.protocolReprobeFailures.delete(uuid);
|
|
1758
1776
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1759
1777
|
deviceId: uuid,
|
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.144",
|
|
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.144",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.144",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.144",
|
|
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": "6240fc52a40bcad467fece58183a54f1af2631fb"
|
|
30
30
|
}
|
|
@@ -425,12 +425,31 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
425
425
|
});
|
|
426
426
|
|
|
427
427
|
test.each(['ios', 'android'] as const)(
|
|
428
|
-
'
|
|
428
|
+
'keeps a first expected Protocol V2 probe miss retryable on %s',
|
|
429
|
+
async platform => {
|
|
430
|
+
setPlatformOS(platform);
|
|
431
|
+
const { transport, uuid, device } = createHarness();
|
|
432
|
+
jest.spyOn(transport as any, 'probeProtocolV2').mockResolvedValue(false);
|
|
433
|
+
|
|
434
|
+
await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
|
|
435
|
+
errorCode: HardwareErrorCode.RuntimeError,
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
expect(device.cancelConnection).not.toHaveBeenCalled();
|
|
439
|
+
expect(transport.getProtocolType(uuid)).toBeUndefined();
|
|
440
|
+
}
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
test.each(['ios', 'android'] as const)(
|
|
444
|
+
'reports a stale bond on %s after a second expected Protocol V2 probe miss',
|
|
429
445
|
async platform => {
|
|
430
446
|
setPlatformOS(platform);
|
|
431
447
|
const { transport, uuid, device } = createHarness();
|
|
432
448
|
jest.spyOn(transport as any, 'probeProtocolV2').mockResolvedValue(false);
|
|
433
449
|
|
|
450
|
+
await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
|
|
451
|
+
errorCode: HardwareErrorCode.RuntimeError,
|
|
452
|
+
});
|
|
434
453
|
await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
|
|
435
454
|
errorCode: HardwareErrorCode.BleDeviceBondError,
|
|
436
455
|
});
|
|
@@ -440,6 +459,24 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
440
459
|
}
|
|
441
460
|
);
|
|
442
461
|
|
|
462
|
+
test.each(['ios', 'android'] as const)(
|
|
463
|
+
'reports a stale bond on %s when a previously confirmed Protocol V2 device stops responding',
|
|
464
|
+
async platform => {
|
|
465
|
+
setPlatformOS(platform);
|
|
466
|
+
const { transport, uuid, device } = createHarness();
|
|
467
|
+
await transport.acquire({ uuid, expectedProtocol: 'V2' });
|
|
468
|
+
await transport.release(uuid, true);
|
|
469
|
+
jest.spyOn(transport as any, 'probeProtocolV2').mockResolvedValue(false);
|
|
470
|
+
|
|
471
|
+
await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
|
|
472
|
+
errorCode: HardwareErrorCode.BleDeviceBondError,
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
expect(device.cancelConnection).toHaveBeenCalled();
|
|
476
|
+
expect(transport.getProtocolType(uuid)).toBeUndefined();
|
|
477
|
+
}
|
|
478
|
+
);
|
|
479
|
+
|
|
443
480
|
test('waits for an in-flight release before reacquiring the same device', async () => {
|
|
444
481
|
const { transport, uuid } = createHarness();
|
|
445
482
|
await transport.acquire({ uuid, expectedProtocol: 'V2' });
|
package/src/index.ts
CHANGED
|
@@ -381,6 +381,12 @@ export default class ReactNativeBleTransport {
|
|
|
381
381
|
/** Protocol this device actually answered on, kept across reconnects of one session. */
|
|
382
382
|
private sessionProtocols: Map<string, ProtocolType> = new Map();
|
|
383
383
|
|
|
384
|
+
/** Endpoints that answered a V2 probe in this transport lifetime. Survives disconnect. */
|
|
385
|
+
private confirmedProtocolV2 = new Set<string>();
|
|
386
|
+
|
|
387
|
+
/** First expected-V2 miss for an unconfirmed endpoint; the next miss is a stale bond. */
|
|
388
|
+
private retryableV2Mismatch = new Set<string>();
|
|
389
|
+
|
|
384
390
|
/** Consecutive detections that failed while trusting sessionProtocols. */
|
|
385
391
|
private protocolReprobeFailures: Map<string, number> = new Map();
|
|
386
392
|
|
|
@@ -1969,6 +1975,8 @@ export default class ReactNativeBleTransport {
|
|
|
1969
1975
|
this.deviceProtocol.clear();
|
|
1970
1976
|
this.probingProtocols.clear();
|
|
1971
1977
|
this.sessionProtocols.clear();
|
|
1978
|
+
this.confirmedProtocolV2.clear();
|
|
1979
|
+
this.retryableV2Mismatch.clear();
|
|
1972
1980
|
this.protocolReprobeFailures.clear();
|
|
1973
1981
|
this.writeTimeoutCounts.clear();
|
|
1974
1982
|
this.connectionSetupTimeoutCounts.clear();
|
|
@@ -1981,11 +1989,20 @@ export default class ReactNativeBleTransport {
|
|
|
1981
1989
|
}
|
|
1982
1990
|
}
|
|
1983
1991
|
|
|
1984
|
-
private createProtocolMismatchError(expected: ProtocolType) {
|
|
1985
|
-
//
|
|
1986
|
-
//
|
|
1992
|
+
private createProtocolMismatchError(expected: ProtocolType, uuid: string) {
|
|
1993
|
+
// Caller `expectedProtocol: 'V2'` is not proof this endpoint already answered.
|
|
1994
|
+
// A first-connect or flaky Ping must stay retryable. A later miss after a
|
|
1995
|
+
// confirmed V2 answer, or a second miss on the same uuid, is a stale bond.
|
|
1996
|
+
const isStaleV2Bond =
|
|
1997
|
+
expected === 'V2' &&
|
|
1998
|
+
(this.confirmedProtocolV2.has(uuid) || this.retryableV2Mismatch.has(uuid));
|
|
1999
|
+
if (expected === 'V2' && !isStaleV2Bond) {
|
|
2000
|
+
this.retryableV2Mismatch.add(uuid);
|
|
2001
|
+
} else if (isStaleV2Bond) {
|
|
2002
|
+
this.retryableV2Mismatch.delete(uuid);
|
|
2003
|
+
}
|
|
1987
2004
|
return ERRORS.TypedError(
|
|
1988
|
-
|
|
2005
|
+
isStaleV2Bond ? HardwareErrorCode.BleDeviceBondError : HardwareErrorCode.RuntimeError,
|
|
1989
2006
|
`Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`
|
|
1990
2007
|
);
|
|
1991
2008
|
}
|
|
@@ -2041,13 +2058,15 @@ export default class ReactNativeBleTransport {
|
|
|
2041
2058
|
});
|
|
2042
2059
|
return 'V1';
|
|
2043
2060
|
}
|
|
2044
|
-
throw this.createProtocolMismatchError(expectedProtocol);
|
|
2061
|
+
throw this.createProtocolMismatchError(expectedProtocol, uuid);
|
|
2045
2062
|
}
|
|
2046
2063
|
|
|
2047
2064
|
if (expectedProtocol === 'V2') {
|
|
2048
2065
|
if (await this.probeProtocolV2(uuid)) {
|
|
2049
2066
|
this.deviceProtocol.set(uuid, 'V2');
|
|
2050
2067
|
this.sessionProtocols.set(uuid, 'V2');
|
|
2068
|
+
this.confirmedProtocolV2.add(uuid);
|
|
2069
|
+
this.retryableV2Mismatch.delete(uuid);
|
|
2051
2070
|
Log?.debug('[ReactNativeBleTransport] protocol detected', {
|
|
2052
2071
|
deviceId: uuid,
|
|
2053
2072
|
protocol: 'V2',
|
|
@@ -2055,7 +2074,7 @@ export default class ReactNativeBleTransport {
|
|
|
2055
2074
|
});
|
|
2056
2075
|
return 'V2';
|
|
2057
2076
|
}
|
|
2058
|
-
throw this.createProtocolMismatchError(expectedProtocol);
|
|
2077
|
+
throw this.createProtocolMismatchError(expectedProtocol, uuid);
|
|
2059
2078
|
}
|
|
2060
2079
|
|
|
2061
2080
|
// Protocol must be actively probed after connection. Name, PID, and descriptors only
|
|
@@ -2090,6 +2109,10 @@ export default class ReactNativeBleTransport {
|
|
|
2090
2109
|
if (detected) {
|
|
2091
2110
|
this.deviceProtocol.set(uuid, protocol);
|
|
2092
2111
|
this.sessionProtocols.set(uuid, protocol);
|
|
2112
|
+
if (protocol === 'V2') {
|
|
2113
|
+
this.confirmedProtocolV2.add(uuid);
|
|
2114
|
+
this.retryableV2Mismatch.delete(uuid);
|
|
2115
|
+
}
|
|
2093
2116
|
this.protocolReprobeFailures.delete(uuid);
|
|
2094
2117
|
Log?.debug('[ReactNativeBleTransport] protocol detected', {
|
|
2095
2118
|
deviceId: uuid,
|