@onekeyfe/hd-transport-react-native 1.2.0-alpha.99 → 1.2.0
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 +5 -0
- package/dist/bleStaleBond.d.ts.map +1 -0
- package/dist/index.d.ts +34 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +354 -132
- package/package.json +5 -5
- package/src/__tests__/bleStaleBond.test.ts +39 -0
- package/src/__tests__/connectTimeout.test.ts +19 -8
- package/src/__tests__/enumerate.test.ts +30 -12
- package/src/__tests__/protocolReprobe.test.ts +24 -0
- package/src/__tests__/protocolV2Link.test.ts +291 -10
- package/src/bleStaleBond.ts +61 -0
- package/src/index.ts +418 -136
|
@@ -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"}
|
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;
|
|
@@ -53,6 +61,7 @@ declare const getFirmwareUploadWriteRetryType: (error: unknown) => FirmwareUploa
|
|
|
53
61
|
* A healthy packet completes in milliseconds, so this only fires on a dead link.
|
|
54
62
|
*/
|
|
55
63
|
declare const BLE_WRITE_PACKET_TIMEOUT_MS = 10000;
|
|
64
|
+
declare const BLE_NATIVE_TEARDOWN_TIMEOUT_MS = 3000;
|
|
56
65
|
/** Consecutive wedged writes on one device before the BLE manager itself is recreated. */
|
|
57
66
|
declare const BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD = 2;
|
|
58
67
|
type ProtocolV2BleTuning = {
|
|
@@ -90,6 +99,7 @@ declare const BLE_GATT_SETUP_TIMEOUT_MS = 10000;
|
|
|
90
99
|
declare const PROTOCOL_REPROBE_FALLBACK_ATTEMPTS = 3;
|
|
91
100
|
/** BLE setup timeouts since the last successful setup before the manager is recreated. */
|
|
92
101
|
declare const BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD = 2;
|
|
102
|
+
declare const BLE_SETUP_WEDGED_MESSAGE = "BLE setup wedged repeatedly";
|
|
93
103
|
type IOneKeyDevice = OneKeyDeviceInfoBase & Device;
|
|
94
104
|
declare class ReactNativeBleTransport {
|
|
95
105
|
blePlxManager: BleManager | undefined;
|
|
@@ -120,8 +130,18 @@ declare class ReactNativeBleTransport {
|
|
|
120
130
|
private deviceProtocolHints;
|
|
121
131
|
/** Protocol this device actually answered on, kept across reconnects of one session. */
|
|
122
132
|
private sessionProtocols;
|
|
133
|
+
/** Endpoints that answered a V2 probe in this transport lifetime. Survives disconnect. */
|
|
134
|
+
private confirmedProtocolV2;
|
|
123
135
|
/** Consecutive detections that failed while trusting sessionProtocols. */
|
|
124
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;
|
|
125
145
|
private protocolV2Assemblers;
|
|
126
146
|
private protocolV2FrameQueues;
|
|
127
147
|
private protocolV2FramePromises;
|
|
@@ -132,6 +152,8 @@ declare class ReactNativeBleTransport {
|
|
|
132
152
|
private androidHighPriorityDevices;
|
|
133
153
|
private androidPriorityResetTimers;
|
|
134
154
|
private nextMonitorToken;
|
|
155
|
+
/** Serializes transport lifecycle changes for the same physical device. */
|
|
156
|
+
private lifecycleOperations;
|
|
135
157
|
constructor(options: TransportOptions);
|
|
136
158
|
init(logger: any, emitter: EventEmitter): void;
|
|
137
159
|
configure(signedData: any): void;
|
|
@@ -149,18 +171,24 @@ declare class ReactNativeBleTransport {
|
|
|
149
171
|
*/
|
|
150
172
|
enumerate(): Promise<IOneKeyDevice[]>;
|
|
151
173
|
private installTransportForAcquire;
|
|
152
|
-
acquire(input:
|
|
174
|
+
acquire(input: FirmwareInstallBleAcquireInput): Promise<{
|
|
153
175
|
uuid: string;
|
|
154
176
|
protocolType: ProtocolType;
|
|
155
177
|
}>;
|
|
178
|
+
private acquireUnlocked;
|
|
156
179
|
_monitorCharacteristic(characteristic: Characteristic, uuid: string, monitorToken: number, notifyTransactionId: string): Subscription;
|
|
157
180
|
release(uuid: string, onclose?: boolean): Promise<boolean>;
|
|
181
|
+
private releaseUnlocked;
|
|
158
182
|
private releaseNative;
|
|
159
183
|
post(session: string, name: string, data: Record<string, unknown>): Promise<void>;
|
|
160
184
|
call(uuid: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<transport.MessageFromOneKey>;
|
|
161
185
|
private callProtocolV1;
|
|
162
186
|
stop(): void;
|
|
163
187
|
disconnect(session: string): Promise<void>;
|
|
188
|
+
private disconnectUnlocked;
|
|
189
|
+
private runNativeTeardown;
|
|
190
|
+
private runBestEffortNativeOperation;
|
|
191
|
+
private runLifecycleOperation;
|
|
164
192
|
cancel(): void;
|
|
165
193
|
/** Run a native connect under the JS backstop budget. */
|
|
166
194
|
private connectWithTimeout;
|
|
@@ -170,8 +198,10 @@ declare class ReactNativeBleTransport {
|
|
|
170
198
|
* Give up on a BLE setup operation the native layer did not settle. The abandoned
|
|
171
199
|
* operation still owns native connection/GATT state that can poison the next attempt,
|
|
172
200
|
* so it is cleared here without awaiting the same queue that stopped responding.
|
|
201
|
+
* Returns true when the manager itself was reset so the caller can stop Core retries.
|
|
173
202
|
*/
|
|
174
203
|
private abandonStalledConnection;
|
|
204
|
+
private createWedgedBleSetupError;
|
|
175
205
|
private getCachedTransport;
|
|
176
206
|
/**
|
|
177
207
|
* Write one packet under a bounded budget. A write that never settles means the
|
|
@@ -202,6 +232,8 @@ declare class ReactNativeBleTransport {
|
|
|
202
232
|
private resolveProtocolV2Frame;
|
|
203
233
|
private resetProtocolV2Frames;
|
|
204
234
|
private rejectProtocolV2Frames;
|
|
235
|
+
private rememberStaleBondError;
|
|
236
|
+
private throwIfStaleBondError;
|
|
205
237
|
private readProtocolV2Frame;
|
|
206
238
|
private writeProtocolV2Packet;
|
|
207
239
|
private writeProtocolV2Frame;
|
|
@@ -215,4 +247,4 @@ declare class ReactNativeBleTransport {
|
|
|
215
247
|
getProtocolType(path: string): ProtocolType | undefined;
|
|
216
248
|
}
|
|
217
249
|
|
|
218
|
-
export { BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD, BLE_CONNECT_TIMEOUT_MS, BLE_GATT_SETUP_TIMEOUT_MS, BLE_WRITE_PACKET_TIMEOUT_MS, BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD, IOneKeyDevice, PROTOCOL_REPROBE_FALLBACK_ATTEMPTS, ProtocolV2BleTuning, configureProtocolV2BleTuning, ReactNativeBleTransport as default, getFirmwareUploadWriteRetryType, getProtocolV2BleTuning, resetProtocolV2BleTuning };
|
|
250
|
+
export { BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD, BLE_CONNECT_TIMEOUT_MS, BLE_GATT_SETUP_TIMEOUT_MS, BLE_NATIVE_TEARDOWN_TIMEOUT_MS, BLE_SETUP_WEDGED_MESSAGE, BLE_WRITE_PACKET_TIMEOUT_MS, BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD, IOneKeyDevice, PROTOCOL_REPROBE_FALLBACK_ATTEMPTS, ProtocolV2BleTuning, configureProtocolV2BleTuning, ReactNativeBleTransport as default, getFirmwareUploadWriteRetryType, getProtocolV2BleTuning, resetProtocolV2BleTuning };
|
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,
|
|
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;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,KAAK,YAAY,MA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