@onekeyfe/hd-core 1.2.0-alpha.176 → 1.2.0-alpha.178
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/core/index.d.ts.map +1 -1
- package/dist/index.js +54 -6
- package/package.json +4 -4
- package/src/core/index.ts +100 -6
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAoClC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAsB1C,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAYxD,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,UAAU,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAmD,MAAM,WAAW,CAAC;AAI9F,OAAO,KAAK,EACV,6BAA6B,EAG9B,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAWpD,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAmE7D,eAAO,MAAM,OAAO,YAAmB,WAAW,WAAW,WAAW,iBAoFvE,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAoClC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAsB1C,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAYxD,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,UAAU,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAmD,MAAM,WAAW,CAAC;AAI9F,OAAO,KAAK,EACV,6BAA6B,EAG9B,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK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, voi
|
|
|
65184
65184
|
if ((_g = method.payload) === null || _g === void 0 ? void 0 : _g.onlyConnectBleDevice) {
|
|
65185
65185
|
preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
|
|
65186
65186
|
Log.debug('Call API - only connect ble device: ', device === null || device === void 0 ? void 0 : device.mainId);
|
|
65187
|
+
completeMethodRequestContext(method);
|
|
65188
|
+
requestQueue.releaseTask(method.responseID);
|
|
65187
65189
|
return createResponseMessage(method.responseID, true, null);
|
|
65188
65190
|
}
|
|
65189
65191
|
Log.debug('Call API - setDevice: ', device.mainId);
|
|
@@ -65559,7 +65561,31 @@ function isMissingDetectedProtocolV2Error(method, error) {
|
|
|
65559
65561
|
typeof typedError.message === 'string' &&
|
|
65560
65562
|
typedError.message.includes('Device protocol has not been detected'));
|
|
65561
65563
|
}
|
|
65562
|
-
|
|
65564
|
+
const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
|
|
65565
|
+
function raceBleAcquire(acquirePromise, abortSignal) {
|
|
65566
|
+
return new Promise((resolve, reject) => {
|
|
65567
|
+
let settled = false;
|
|
65568
|
+
const settle = (fn) => {
|
|
65569
|
+
if (settled)
|
|
65570
|
+
return;
|
|
65571
|
+
settled = true;
|
|
65572
|
+
clearTimeout(deadline);
|
|
65573
|
+
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', onAbort);
|
|
65574
|
+
fn();
|
|
65575
|
+
};
|
|
65576
|
+
const onAbort = () => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled)));
|
|
65577
|
+
const deadline = setTimeout(() => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, `BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline`))), BLE_ACQUIRE_DEADLINE_MS);
|
|
65578
|
+
acquirePromise.then(value => settle(() => resolve(value)), error => settle(() => reject(error)));
|
|
65579
|
+
if (abortSignal) {
|
|
65580
|
+
if (abortSignal.aborted) {
|
|
65581
|
+
onAbort();
|
|
65582
|
+
return;
|
|
65583
|
+
}
|
|
65584
|
+
abortSignal.addEventListener('abort', onAbort);
|
|
65585
|
+
}
|
|
65586
|
+
});
|
|
65587
|
+
}
|
|
65588
|
+
function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
65563
65589
|
var _a;
|
|
65564
65590
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65565
65591
|
try {
|
|
@@ -65574,9 +65600,31 @@ function connectDeviceForBle(method, device, retryCount = 0) {
|
|
|
65574
65600
|
!device.commands ||
|
|
65575
65601
|
device.commands.disposed;
|
|
65576
65602
|
if (shouldAcquire) {
|
|
65577
|
-
|
|
65578
|
-
|
|
65579
|
-
|
|
65603
|
+
const useAcquireGuards = DataManager.getSettings('env') === 'desktop-web-ble';
|
|
65604
|
+
if (useAcquireGuards && (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
|
|
65605
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
|
|
65606
|
+
}
|
|
65607
|
+
if (!useAcquireGuards) {
|
|
65608
|
+
yield device.acquire(method.payload.connectProtocol, {
|
|
65609
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
65610
|
+
});
|
|
65611
|
+
}
|
|
65612
|
+
else {
|
|
65613
|
+
try {
|
|
65614
|
+
yield raceBleAcquire(device.acquire(method.payload.connectProtocol, {
|
|
65615
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
65616
|
+
}), abortSignal);
|
|
65617
|
+
}
|
|
65618
|
+
catch (err) {
|
|
65619
|
+
if (err.errorCode === hdShared.HardwareErrorCode.BleTimeoutError &&
|
|
65620
|
+
device.mainId &&
|
|
65621
|
+
device.deviceConnector) {
|
|
65622
|
+
yield device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
|
|
65623
|
+
device.markTransportDisconnected();
|
|
65624
|
+
}
|
|
65625
|
+
throw err;
|
|
65626
|
+
}
|
|
65627
|
+
}
|
|
65580
65628
|
}
|
|
65581
65629
|
if ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.onlyConnectBleDevice) {
|
|
65582
65630
|
if (shouldAcquire) {
|
|
@@ -65607,7 +65655,7 @@ function connectDeviceForBle(method, device, retryCount = 0) {
|
|
|
65607
65655
|
const nextRetry = retryCount + 1;
|
|
65608
65656
|
Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
|
|
65609
65657
|
yield wait(3000);
|
|
65610
|
-
yield connectDeviceForBle(method, device, nextRetry);
|
|
65658
|
+
yield connectDeviceForBle(method, device, abortSignal, nextRetry);
|
|
65611
65659
|
}
|
|
65612
65660
|
else {
|
|
65613
65661
|
throw err;
|
|
@@ -65692,7 +65740,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
65692
65740
|
if (tryCount === 1) {
|
|
65693
65741
|
device.beginConnectionAttempt();
|
|
65694
65742
|
}
|
|
65695
|
-
yield connectDeviceForBle(method, device);
|
|
65743
|
+
yield connectDeviceForBle(method, device, abortSignal);
|
|
65696
65744
|
}
|
|
65697
65745
|
resolve(device);
|
|
65698
65746
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.178",
|
|
4
4
|
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.178",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.178",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"buffer": "^6.0.3",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/w3c-web-usb": "^1.0.10",
|
|
47
47
|
"@types/web-bluetooth": "^0.0.21"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "5df24cf8ab1b0e1909e5d9715b15ab042bba3ac7"
|
|
50
50
|
}
|
package/src/core/index.ts
CHANGED
|
@@ -415,6 +415,13 @@ const onCallDevice = async (
|
|
|
415
415
|
if (method.payload?.onlyConnectBleDevice) {
|
|
416
416
|
preWarmCallbackTask?.resolve();
|
|
417
417
|
Log.debug('Call API - only connect ble device: ', device?.mainId);
|
|
418
|
+
// This early return bypasses the normal-path bookkeeping at the end of the
|
|
419
|
+
// call. Without it the task leaks and haunts every later queue snapshot
|
|
420
|
+
// and cancel sweep (field log: a completed task lingered for 6 minutes),
|
|
421
|
+
// and the request stays in the active maps, so repeated preconnects pile
|
|
422
|
+
// up phantom work in diagnostics.
|
|
423
|
+
completeMethodRequestContext(method);
|
|
424
|
+
requestQueue.releaseTask(method.responseID);
|
|
418
425
|
return createResponseMessage(method.responseID, true, null);
|
|
419
426
|
}
|
|
420
427
|
|
|
@@ -954,7 +961,60 @@ export function isMissingDetectedProtocolV2Error(method: BaseMethod, error: unkn
|
|
|
954
961
|
* If the Bluetooth connection times out, retry up to 6 times
|
|
955
962
|
* @param retryCount - Current retry count (default 0)
|
|
956
963
|
*/
|
|
957
|
-
|
|
964
|
+
// device.acquire awaits a transport reply with no deadline of its own; a
|
|
965
|
+
// transport that never settles (field case: Electron main lost an IPC reply,
|
|
966
|
+
// "reply was never sent" after 5 minutes) hangs the call forever and cancel()
|
|
967
|
+
// only takes effect at poll checkpoints. Race acquire against a deadline and
|
|
968
|
+
// the caller's abort signal so the hang is bounded and cancel is immediate.
|
|
969
|
+
const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
|
|
970
|
+
|
|
971
|
+
function raceBleAcquire<T>(acquirePromise: Promise<T>, abortSignal?: AbortSignal): Promise<T> {
|
|
972
|
+
return new Promise<T>((resolve, reject) => {
|
|
973
|
+
let settled = false;
|
|
974
|
+
const settle = (fn: () => void) => {
|
|
975
|
+
if (settled) return;
|
|
976
|
+
settled = true;
|
|
977
|
+
clearTimeout(deadline);
|
|
978
|
+
abortSignal?.removeEventListener('abort', onAbort);
|
|
979
|
+
fn();
|
|
980
|
+
};
|
|
981
|
+
const onAbort = () =>
|
|
982
|
+
settle(() => reject(ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled)));
|
|
983
|
+
const deadline = setTimeout(
|
|
984
|
+
() =>
|
|
985
|
+
settle(() =>
|
|
986
|
+
reject(
|
|
987
|
+
ERRORS.TypedError(
|
|
988
|
+
HardwareErrorCode.BleTimeoutError,
|
|
989
|
+
`BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline`
|
|
990
|
+
)
|
|
991
|
+
)
|
|
992
|
+
),
|
|
993
|
+
BLE_ACQUIRE_DEADLINE_MS
|
|
994
|
+
);
|
|
995
|
+
// Attach before any early return so a late settlement of acquirePromise
|
|
996
|
+
// is always consumed — an abort or deadline must never leave the acquire
|
|
997
|
+
// rejection unhandled.
|
|
998
|
+
acquirePromise.then(
|
|
999
|
+
value => settle(() => resolve(value)),
|
|
1000
|
+
error => settle(() => reject(error))
|
|
1001
|
+
);
|
|
1002
|
+
if (abortSignal) {
|
|
1003
|
+
if (abortSignal.aborted) {
|
|
1004
|
+
onAbort();
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
abortSignal.addEventListener('abort', onAbort);
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
async function connectDeviceForBle(
|
|
1013
|
+
method: BaseMethod,
|
|
1014
|
+
device: Device,
|
|
1015
|
+
abortSignal?: AbortSignal,
|
|
1016
|
+
retryCount = 0
|
|
1017
|
+
) {
|
|
958
1018
|
try {
|
|
959
1019
|
if (device.wasInterruptedByUser()) {
|
|
960
1020
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceInterruptedFromUser);
|
|
@@ -968,9 +1028,43 @@ async function connectDeviceForBle(method: BaseMethod, device: Device, retryCoun
|
|
|
968
1028
|
!device.commands ||
|
|
969
1029
|
device.commands.disposed;
|
|
970
1030
|
if (shouldAcquire) {
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1031
|
+
// The deadline/abort guards are scoped to the desktop electron
|
|
1032
|
+
// transport: its IPC acquire is the only path with a proven
|
|
1033
|
+
// never-settling failure mode, while react-native/lowlevel acquire may
|
|
1034
|
+
// legitimately block on a user-driven system bonding prompt for longer
|
|
1035
|
+
// than any sane deadline. Other envs keep the plain acquire unchanged.
|
|
1036
|
+
const useAcquireGuards = DataManager.getSettings('env') === 'desktop-web-ble';
|
|
1037
|
+
// A cancel landing during the retry backoff must not start a new acquire.
|
|
1038
|
+
if (useAcquireGuards && abortSignal?.aborted) {
|
|
1039
|
+
throw ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled);
|
|
1040
|
+
}
|
|
1041
|
+
if (!useAcquireGuards) {
|
|
1042
|
+
await device.acquire(method.payload.connectProtocol, {
|
|
1043
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
1044
|
+
});
|
|
1045
|
+
} else {
|
|
1046
|
+
try {
|
|
1047
|
+
await raceBleAcquire(
|
|
1048
|
+
device.acquire(method.payload.connectProtocol, {
|
|
1049
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
1050
|
+
}),
|
|
1051
|
+
abortSignal
|
|
1052
|
+
);
|
|
1053
|
+
} catch (err) {
|
|
1054
|
+
// A deadline hit means the transport is wedged mid-acquire; drop the
|
|
1055
|
+
// link before the retry so it cold-connects instead of stacking a
|
|
1056
|
+
// second connect onto the half-open one.
|
|
1057
|
+
if (
|
|
1058
|
+
err.errorCode === HardwareErrorCode.BleTimeoutError &&
|
|
1059
|
+
device.mainId &&
|
|
1060
|
+
device.deviceConnector
|
|
1061
|
+
) {
|
|
1062
|
+
await device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
|
|
1063
|
+
device.markTransportDisconnected();
|
|
1064
|
+
}
|
|
1065
|
+
throw err;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
974
1068
|
}
|
|
975
1069
|
if (method.payload?.onlyConnectBleDevice) {
|
|
976
1070
|
if (shouldAcquire) {
|
|
@@ -1010,7 +1104,7 @@ async function connectDeviceForBle(method: BaseMethod, device: Device, retryCoun
|
|
|
1010
1104
|
const nextRetry = retryCount + 1;
|
|
1011
1105
|
Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
|
|
1012
1106
|
await wait(3000);
|
|
1013
|
-
await connectDeviceForBle(method, device, nextRetry);
|
|
1107
|
+
await connectDeviceForBle(method, device, abortSignal, nextRetry);
|
|
1014
1108
|
} else {
|
|
1015
1109
|
throw err;
|
|
1016
1110
|
}
|
|
@@ -1120,7 +1214,7 @@ const ensureConnected = async (
|
|
|
1120
1214
|
if (tryCount === 1) {
|
|
1121
1215
|
device.beginConnectionAttempt();
|
|
1122
1216
|
}
|
|
1123
|
-
await connectDeviceForBle(method, device);
|
|
1217
|
+
await connectDeviceForBle(method, device, abortSignal);
|
|
1124
1218
|
}
|
|
1125
1219
|
resolve(device);
|
|
1126
1220
|
return;
|