@onekeyfe/hd-core 1.2.0-alpha.154 → 1.2.0-alpha.155

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.
@@ -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;AAqqBF,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,WAWpF;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,WAW/E;AAED,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,WAQlF;AAiVD,eAAO,MAAM,MAAM,YAAa,WAAW,cAAc,MAAM,SAoG9D,CAAC;AAmGF,eAAO,MAAM,qBAAqB,gFAejC,CAAC;AAiLF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IAC5C,OAAO,CAAC,cAAc,CAAoB;IAE1C,SAAgB,aAAa,EAAE,MAAM,CAAC;IAEtC,OAAO,CAAC,YAAY,CAAsB;IAE1C,OAAO,CAAC,c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E,QAAQ;IAyB5C,MAAM,CAAC,YAAY,CAAC,oBAAoB,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,6BAA6B;IA6BrF,MAAM,CAAC,YAAY;mBAIE,2BAA2B;IAShD,MAAM,CAAC,kBAAkB;IAIzB,MAAM,CAAC,kBAAkB;IAIzB,MAAM,CAAC,0BAA0B;CAGlC"}
package/dist/index.js CHANGED
@@ -43419,7 +43419,7 @@ class TransportManager {
43419
43419
  yield this.transport.init(WebBleLogger, DevicePool.emitter);
43420
43420
  }
43421
43421
  else if (env === 'webusb' || env === 'desktop-webusb') {
43422
- yield this.transport.init(WebUsbLogger);
43422
+ yield this.transport.init(WebUsbLogger, DevicePool.emitter);
43423
43423
  }
43424
43424
  else {
43425
43425
  yield this.transport.init(HttpLogger);
@@ -65216,7 +65216,6 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
65216
65216
  if ((_g = method.payload) === null || _g === void 0 ? void 0 : _g.onlyConnectBleDevice) {
65217
65217
  preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
65218
65218
  Log.debug('Call API - only connect ble device: ', device === null || device === void 0 ? void 0 : device.mainId);
65219
- requestQueue.releaseTask(method.responseID);
65220
65219
  return createResponseMessage(method.responseID, true, null);
65221
65220
  }
65222
65221
  Log.debug('Call API - setDevice: ', device.mainId);
@@ -65592,31 +65591,7 @@ function isMissingDetectedProtocolV2Error(method, error) {
65592
65591
  typeof typedError.message === 'string' &&
65593
65592
  typedError.message.includes('Device protocol has not been detected'));
65594
65593
  }
65595
- const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
65596
- function raceBleAcquire(acquirePromise, abortSignal) {
65597
- return new Promise((resolve, reject) => {
65598
- let settled = false;
65599
- const settle = (fn) => {
65600
- if (settled)
65601
- return;
65602
- settled = true;
65603
- clearTimeout(deadline);
65604
- abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', onAbort);
65605
- fn();
65606
- };
65607
- const onAbort = () => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled)));
65608
- const deadline = setTimeout(() => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, `BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline`))), BLE_ACQUIRE_DEADLINE_MS);
65609
- acquirePromise.then(value => settle(() => resolve(value)), error => settle(() => reject(error)));
65610
- if (abortSignal) {
65611
- if (abortSignal.aborted) {
65612
- onAbort();
65613
- return;
65614
- }
65615
- abortSignal.addEventListener('abort', onAbort);
65616
- }
65617
- });
65618
- }
65619
- function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
65594
+ function connectDeviceForBle(method, device, retryCount = 0) {
65620
65595
  var _a;
65621
65596
  return __awaiter(this, void 0, void 0, function* () {
65622
65597
  try {
@@ -65631,31 +65606,9 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
65631
65606
  !device.commands ||
65632
65607
  device.commands.disposed;
65633
65608
  if (shouldAcquire) {
65634
- const useAcquireGuards = DataManager.getSettings('env') === 'desktop-web-ble';
65635
- if (useAcquireGuards && (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
65636
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
65637
- }
65638
- if (!useAcquireGuards) {
65639
- yield device.acquire(method.payload.connectProtocol, {
65640
- forceProtocolDetection: method.payload.forceProtocolDetection,
65641
- });
65642
- }
65643
- else {
65644
- try {
65645
- yield raceBleAcquire(device.acquire(method.payload.connectProtocol, {
65646
- forceProtocolDetection: method.payload.forceProtocolDetection,
65647
- }), abortSignal);
65648
- }
65649
- catch (err) {
65650
- if (err.errorCode === hdShared.HardwareErrorCode.BleTimeoutError &&
65651
- device.mainId &&
65652
- device.deviceConnector) {
65653
- yield device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
65654
- device.markTransportDisconnected();
65655
- }
65656
- throw err;
65657
- }
65658
- }
65609
+ yield device.acquire(method.payload.connectProtocol, {
65610
+ forceProtocolDetection: method.payload.forceProtocolDetection,
65611
+ });
65659
65612
  }
65660
65613
  if ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.onlyConnectBleDevice) {
65661
65614
  if (shouldAcquire) {
@@ -65686,7 +65639,7 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
65686
65639
  const nextRetry = retryCount + 1;
65687
65640
  Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
65688
65641
  yield wait(3000);
65689
- yield connectDeviceForBle(method, device, abortSignal, nextRetry);
65642
+ yield connectDeviceForBle(method, device, nextRetry);
65690
65643
  }
65691
65644
  else {
65692
65645
  throw err;
@@ -65771,7 +65724,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
65771
65724
  if (tryCount === 1) {
65772
65725
  device.beginConnectionAttempt();
65773
65726
  }
65774
- yield connectDeviceForBle(method, device, abortSignal);
65727
+ yield connectDeviceForBle(method, device);
65775
65728
  }
65776
65729
  resolve(device);
65777
65730
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.0-alpha.154",
3
+ "version": "1.2.0-alpha.155",
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.154",
29
- "@onekeyfe/hd-transport": "1.2.0-alpha.154",
28
+ "@onekeyfe/hd-shared": "1.2.0-alpha.155",
29
+ "@onekeyfe/hd-transport": "1.2.0-alpha.155",
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": "0b81bf264b2b33e00550b1008264c02e0a049b68"
49
+ "gitHead": "922cb4e29b2d89511c9b67c25840294335cb8005"
50
50
  }
package/src/core/index.ts CHANGED
@@ -415,10 +415,6 @@ 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 releaseTask 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
- requestQueue.releaseTask(method.responseID);
422
418
  return createResponseMessage(method.responseID, true, null);
423
419
  }
424
420
 
@@ -958,60 +954,7 @@ export function isMissingDetectedProtocolV2Error(method: BaseMethod, error: unkn
958
954
  * If the Bluetooth connection times out, retry up to 6 times
959
955
  * @param retryCount - Current retry count (default 0)
960
956
  */
961
- // device.acquire awaits a transport reply with no deadline of its own; a
962
- // transport that never settles (field case: Electron main lost an IPC reply,
963
- // "reply was never sent" after 5 minutes) hangs the call forever and cancel()
964
- // only takes effect at poll checkpoints. Race acquire against a deadline and
965
- // the caller's abort signal so the hang is bounded and cancel is immediate.
966
- const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
967
-
968
- function raceBleAcquire<T>(acquirePromise: Promise<T>, abortSignal?: AbortSignal): Promise<T> {
969
- return new Promise<T>((resolve, reject) => {
970
- let settled = false;
971
- const settle = (fn: () => void) => {
972
- if (settled) return;
973
- settled = true;
974
- clearTimeout(deadline);
975
- abortSignal?.removeEventListener('abort', onAbort);
976
- fn();
977
- };
978
- const onAbort = () =>
979
- settle(() => reject(ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled)));
980
- const deadline = setTimeout(
981
- () =>
982
- settle(() =>
983
- reject(
984
- ERRORS.TypedError(
985
- HardwareErrorCode.BleTimeoutError,
986
- `BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline`
987
- )
988
- )
989
- ),
990
- BLE_ACQUIRE_DEADLINE_MS
991
- );
992
- // Attach before any early return so a late settlement of acquirePromise
993
- // is always consumed — an abort or deadline must never leave the acquire
994
- // rejection unhandled.
995
- acquirePromise.then(
996
- value => settle(() => resolve(value)),
997
- error => settle(() => reject(error))
998
- );
999
- if (abortSignal) {
1000
- if (abortSignal.aborted) {
1001
- onAbort();
1002
- return;
1003
- }
1004
- abortSignal.addEventListener('abort', onAbort);
1005
- }
1006
- });
1007
- }
1008
-
1009
- async function connectDeviceForBle(
1010
- method: BaseMethod,
1011
- device: Device,
1012
- abortSignal?: AbortSignal,
1013
- retryCount = 0
1014
- ) {
957
+ async function connectDeviceForBle(method: BaseMethod, device: Device, retryCount = 0) {
1015
958
  try {
1016
959
  if (device.wasInterruptedByUser()) {
1017
960
  throw ERRORS.TypedError(HardwareErrorCode.DeviceInterruptedFromUser);
@@ -1025,43 +968,9 @@ async function connectDeviceForBle(
1025
968
  !device.commands ||
1026
969
  device.commands.disposed;
1027
970
  if (shouldAcquire) {
1028
- // The deadline/abort guards are scoped to the desktop electron
1029
- // transport: its IPC acquire is the only path with a proven
1030
- // never-settling failure mode, while react-native/lowlevel acquire may
1031
- // legitimately block on a user-driven system bonding prompt for longer
1032
- // than any sane deadline. Other envs keep the plain acquire unchanged.
1033
- const useAcquireGuards = DataManager.getSettings('env') === 'desktop-web-ble';
1034
- // A cancel landing during the retry backoff must not start a new acquire.
1035
- if (useAcquireGuards && abortSignal?.aborted) {
1036
- throw ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled);
1037
- }
1038
- if (!useAcquireGuards) {
1039
- await device.acquire(method.payload.connectProtocol, {
1040
- forceProtocolDetection: method.payload.forceProtocolDetection,
1041
- });
1042
- } else {
1043
- try {
1044
- await raceBleAcquire(
1045
- device.acquire(method.payload.connectProtocol, {
1046
- forceProtocolDetection: method.payload.forceProtocolDetection,
1047
- }),
1048
- abortSignal
1049
- );
1050
- } catch (err) {
1051
- // A deadline hit means the transport is wedged mid-acquire; drop the
1052
- // link before the retry so it cold-connects instead of stacking a
1053
- // second connect onto the half-open one.
1054
- if (
1055
- err.errorCode === HardwareErrorCode.BleTimeoutError &&
1056
- device.mainId &&
1057
- device.deviceConnector
1058
- ) {
1059
- await device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
1060
- device.markTransportDisconnected();
1061
- }
1062
- throw err;
1063
- }
1064
- }
971
+ await device.acquire(method.payload.connectProtocol, {
972
+ forceProtocolDetection: method.payload.forceProtocolDetection,
973
+ });
1065
974
  }
1066
975
  if (method.payload?.onlyConnectBleDevice) {
1067
976
  if (shouldAcquire) {
@@ -1101,7 +1010,7 @@ async function connectDeviceForBle(
1101
1010
  const nextRetry = retryCount + 1;
1102
1011
  Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
1103
1012
  await wait(3000);
1104
- await connectDeviceForBle(method, device, abortSignal, nextRetry);
1013
+ await connectDeviceForBle(method, device, nextRetry);
1105
1014
  } else {
1106
1015
  throw err;
1107
1016
  }
@@ -1211,7 +1120,7 @@ const ensureConnected = async (
1211
1120
  if (tryCount === 1) {
1212
1121
  device.beginConnectionAttempt();
1213
1122
  }
1214
- await connectDeviceForBle(method, device, abortSignal);
1123
+ await connectDeviceForBle(method, device);
1215
1124
  }
1216
1125
  resolve(device);
1217
1126
  return;
@@ -69,7 +69,9 @@ export default class TransportManager {
69
69
  } else if (env === 'desktop-web-ble') {
70
70
  await this.transport.init(WebBleLogger, DevicePool.emitter);
71
71
  } else if (env === 'webusb' || env === 'desktop-webusb') {
72
- await this.transport.init(WebUsbLogger);
72
+ // The emitter is what turns a navigator.usb 'disconnect' into a
73
+ // DEVICE.DISCONNECT; without it WebUSB never reports device removal.
74
+ await this.transport.init(WebUsbLogger, DevicePool.emitter);
73
75
  } else {
74
76
  await this.transport.init(HttpLogger);
75
77
  }