@onekeyfe/hd-transport-web-device 1.2.11-alpha.15 → 1.2.11-alpha.17

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.
@@ -1534,7 +1534,8 @@ describe('ElectronBleTransport protocol detection', () => {
1534
1534
  'Initialize',
1535
1535
  {},
1536
1536
  { timeoutMs: 3000 },
1537
- { oneShot: true }
1537
+ { oneShot: true },
1538
+ true
1538
1539
  );
1539
1540
  });
1540
1541
 
@@ -1644,4 +1645,116 @@ describe('ElectronBleTransport protocol detection', () => {
1644
1645
  });
1645
1646
  expect(callProtocolV1).not.toHaveBeenCalled();
1646
1647
  });
1648
+
1649
+ test('does not send Initialize wake when GetFeatures fails from an ordinary GATT write error', async () => {
1650
+ const device = { id: 'gatt-write-err-classic-id', name: 'K8141' };
1651
+ const nobleBle = createNobleBle(device);
1652
+ const bleTransport = configureTransport(nobleBle);
1653
+ const probes = bleTransport as any;
1654
+ const wakeSpy = jest.spyOn(probes, 'wakeSilentProtocolV1Device');
1655
+ jest.spyOn(probes, 'probeProtocolV2').mockResolvedValue(false);
1656
+ nobleBle.write.mockRejectedValueOnce(new Error('GATT write error'));
1657
+
1658
+ await expect(bleTransport.acquire({ uuid: device.id })).rejects.toMatchObject({
1659
+ errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
1660
+ });
1661
+ expect(wakeSpy).not.toHaveBeenCalled();
1662
+ });
1663
+
1664
+ test('prevents a canceled acquire whose getDevice settles late from disconnecting a replacement acquire', async () => {
1665
+ const device = { id: 'superseded-acquire-id', name: 'K8141' };
1666
+ const nobleBle = createNobleBle(device);
1667
+ let resolveFirstGetDevice: ((d: typeof device) => void) | undefined;
1668
+ nobleBle.getDevice
1669
+ .mockImplementationOnce(
1670
+ () =>
1671
+ new Promise(resolve => {
1672
+ resolveFirstGetDevice = resolve;
1673
+ })
1674
+ )
1675
+ .mockResolvedValue(device);
1676
+ const bleTransport = configureTransport(nobleBle);
1677
+ const abortA = new AbortController();
1678
+
1679
+ const acquireA = bleTransport.acquire({
1680
+ uuid: device.id,
1681
+ expectedProtocol: 'V1',
1682
+ abortSignal: abortA.signal,
1683
+ });
1684
+ abortA.abort();
1685
+
1686
+ // Acquire B succeeds while acquire A is still waiting on getDevice.
1687
+ await expect(
1688
+ bleTransport.acquire({ uuid: device.id, expectedProtocol: 'V1' })
1689
+ ).resolves.toMatchObject({ uuid: device.id, protocolType: 'V1' });
1690
+ nobleBle.disconnect.mockClear();
1691
+ nobleBle.unsubscribe.mockClear();
1692
+
1693
+ // Acquire A resumes when its delayed lookup settles; it must not tear down B's link.
1694
+ resolveFirstGetDevice?.(device);
1695
+ await expect(acquireA).rejects.toMatchObject({
1696
+ errorCode: HardwareErrorCode.DeviceInterruptedFromUser,
1697
+ });
1698
+ expect(nobleBle.unsubscribe).not.toHaveBeenCalled();
1699
+ expect(nobleBle.disconnect).not.toHaveBeenCalled();
1700
+ expect(bleTransport.getProtocolType(device.id)).toBe('V1');
1701
+ });
1702
+
1703
+ test('restores wake eligibility when Windows rejects the Initialize wake write with writeRejected', async () => {
1704
+ const device = { id: 'win-wake-reject-id', name: 'K8141' };
1705
+ const nobleBle = createNobleBle(device);
1706
+ const bleTransport = configureTransport(nobleBle);
1707
+ const probes = bleTransport as any;
1708
+ jest.spyOn(probes, 'probeProtocolV1').mockResolvedValue(false);
1709
+ jest.spyOn(probes, 'probeProtocolV2').mockResolvedValue(false);
1710
+
1711
+ nobleBle.write.mockRejectedValueOnce(
1712
+ ERRORS.TypedError(
1713
+ HardwareErrorCode.BleConnectedError,
1714
+ 'Write failed with abortable error for device win-wake-reject-id: status: 3',
1715
+ { writeRejected: true }
1716
+ )
1717
+ );
1718
+ await expect(bleTransport.acquire({ uuid: device.id })).rejects.toMatchObject({
1719
+ errorCode: HardwareErrorCode.BleConnectedError,
1720
+ });
1721
+
1722
+ // After pairing succeeds on the next acquire, Initialize wake must still run.
1723
+ const callProtocolV1 = jest.spyOn(probes, 'callProtocolV1').mockResolvedValueOnce({
1724
+ type: 'Features',
1725
+ message: {},
1726
+ });
1727
+ await expect(bleTransport.acquire({ uuid: device.id })).resolves.toMatchObject({
1728
+ uuid: device.id,
1729
+ protocolType: 'V1',
1730
+ });
1731
+ expect(callProtocolV1).toHaveBeenCalledTimes(1);
1732
+ expect(callProtocolV1.mock.calls[0]?.[1]).toBe('Initialize');
1733
+ });
1734
+
1735
+ test('disconnects an ordinary 3000ms Initialize call on timeout instead of treating it as a probe', async () => {
1736
+ const device = { id: 'ordinary-init-3s-id', name: 'OneKey Classic' };
1737
+ const nobleBle = createNobleBle(device);
1738
+ nobleBle.onNotification.mockImplementation(() => jest.fn());
1739
+ nobleBle.write.mockImplementation(() => Promise.resolve());
1740
+ const bleTransport = configureTransport(nobleBle);
1741
+
1742
+ await bleTransport.acquire({ uuid: device.id, expectedProtocol: 'V1' });
1743
+ jest.useFakeTimers({ doNotFake: ['performance'] });
1744
+ try {
1745
+ const pending = bleTransport.call(device.id, 'Initialize', {}, { timeoutMs: 3000 });
1746
+ const expectation = expect(pending).rejects.toMatchObject({
1747
+ errorCode: HardwareErrorCode.BleTimeoutError,
1748
+ });
1749
+ await Promise.resolve();
1750
+ await Promise.resolve();
1751
+ jest.advanceTimersByTime(3000);
1752
+ await expectation;
1753
+ } finally {
1754
+ jest.useRealTimers();
1755
+ }
1756
+
1757
+ expect(nobleBle.disconnect).toHaveBeenCalledWith(device.id);
1758
+ expect(bleTransport.getProtocolType(device.id)).toBeUndefined();
1759
+ });
1647
1760
  });
@@ -35,6 +35,10 @@ export default class ElectronBleTransport {
35
35
  private deviceProtocol;
36
36
  private deviceProtocolHints;
37
37
  private silentDetections;
38
+ private probeResponseTimeoutErrors;
39
+ private lastV1ProbeFailedWithoutTimeout;
40
+ private acquireGenerations;
41
+ private nextAcquireGeneration;
38
42
  private deviceMtus;
39
43
  private devicePacketCapacities;
40
44
  private v1Buffers;
@@ -1 +1 @@
1
- {"version":3,"file":"electron-ble-transport.d.ts","s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AAC,oBAAoB;IAqB5B,OAAO,CAAC,kBAAkB;IA+B1B,OAAO,CAAC,iCAAiC;IAazC,OAAO,CAAC,4BAA4B;IAkBpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,sBAAsB;YAShB,mBAAmB;IAiBjC,OAAO,CAAC,4BAA4B;IAqB9B,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,oBAAoB;IAuB1B,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;YAatD,cAAc;YA+Fd,cAAc;IA+B5B,OAAO,CAAC,uBAAuB;IAyC/B,OAAO,CAAC,6BAA6B;IA4CrC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
package/dist/index.d.ts CHANGED
@@ -272,6 +272,10 @@ declare class ElectronBleTransport {
272
272
  private deviceProtocol;
273
273
  private deviceProtocolHints;
274
274
  private silentDetections;
275
+ private probeResponseTimeoutErrors;
276
+ private lastV1ProbeFailedWithoutTimeout;
277
+ private acquireGenerations;
278
+ private nextAcquireGeneration;
275
279
  private deviceMtus;
276
280
  private devicePacketCapacities;
277
281
  private v1Buffers;
package/dist/index.js CHANGED
@@ -1543,8 +1543,11 @@ const shouldRethrowElectronProtocolProbeError = (error) => {
1543
1543
  code === hdShared.HardwareErrorCode.BleLocationError);
1544
1544
  };
1545
1545
  const isUnstartedElectronWakeError = (error) => {
1546
- const code = error === null || error === void 0 ? void 0 : error.errorCode;
1547
- return (code === hdShared.HardwareErrorCode.BleCharacteristicNotFound ||
1546
+ var _a;
1547
+ const candidate = error;
1548
+ const code = candidate === null || candidate === void 0 ? void 0 : candidate.errorCode;
1549
+ return (((_a = candidate === null || candidate === void 0 ? void 0 : candidate.params) === null || _a === void 0 ? void 0 : _a.writeRejected) === true ||
1550
+ code === hdShared.HardwareErrorCode.BleCharacteristicNotFound ||
1548
1551
  code === hdShared.HardwareErrorCode.BlePoweredOff ||
1549
1552
  code === hdShared.HardwareErrorCode.BleUnsupported ||
1550
1553
  code === hdShared.HardwareErrorCode.BleLocationError);
@@ -1563,6 +1566,10 @@ class ElectronBleTransport {
1563
1566
  this.deviceProtocol = new Map();
1564
1567
  this.deviceProtocolHints = new Map();
1565
1568
  this.silentDetections = new Map();
1569
+ this.probeResponseTimeoutErrors = new WeakSet();
1570
+ this.lastV1ProbeFailedWithoutTimeout = new Set();
1571
+ this.acquireGenerations = new Map();
1572
+ this.nextAcquireGeneration = 1;
1566
1573
  this.deviceMtus = new Map();
1567
1574
  this.devicePacketCapacities = new Map();
1568
1575
  this.v1Buffers = new Map();
@@ -1645,6 +1652,7 @@ class ElectronBleTransport {
1645
1652
  this.devicePacketCapacities.delete(deviceId);
1646
1653
  this.v1Buffers.delete(deviceId);
1647
1654
  this.v2Assemblers.delete(deviceId);
1655
+ this.lastV1ProbeFailedWithoutTimeout.delete(deviceId);
1648
1656
  this.resetProtocolV2Frames(deviceId);
1649
1657
  this.notificationTokens.delete(deviceId);
1650
1658
  if (this.runPromise && this.runPromiseDeviceId === deviceId) {
@@ -1704,6 +1712,8 @@ class ElectronBleTransport {
1704
1712
  ]);
1705
1713
  yield Promise.all(Array.from(trackedDeviceIds, deviceId => this.releaseNative(deviceId)));
1706
1714
  this.acquiringDevices.clear();
1715
+ this.acquireGenerations.clear();
1716
+ this.lastV1ProbeFailedWithoutTimeout.clear();
1707
1717
  this.protocolV2CallCounts.clear();
1708
1718
  this.silentDetections.clear();
1709
1719
  yield this.protocolV2Links
@@ -1778,6 +1788,17 @@ class ElectronBleTransport {
1778
1788
  if (!uuid) {
1779
1789
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleRequiredUUID);
1780
1790
  }
1791
+ const acquireGeneration = this.nextAcquireGeneration;
1792
+ this.nextAcquireGeneration += 1;
1793
+ this.acquireGenerations.set(uuid, acquireGeneration);
1794
+ const isCurrentAcquire = () => this.acquireGenerations.get(uuid) === acquireGeneration;
1795
+ const assertAcquireActive = () => {
1796
+ var _a;
1797
+ this.assertRunning();
1798
+ if (((_a = input.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) || !isCurrentAcquire()) {
1799
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser);
1800
+ }
1801
+ };
1781
1802
  const retainedToken = this.retainedDevices.has(uuid) &&
1782
1803
  !forceProtocolDetection &&
1783
1804
  (!expectedProtocol || expectedProtocol === 'V2') &&
@@ -1788,13 +1809,13 @@ class ElectronBleTransport {
1788
1809
  if (this.connectedDevices.has(uuid) && retainedToken === undefined) {
1789
1810
  yield this.release(uuid);
1790
1811
  }
1812
+ assertAcquireActive();
1791
1813
  if (forceCleanRunPromise && this.runPromise) {
1792
1814
  const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleForceCleanRunPromise);
1793
1815
  this.runPromise.reject(error);
1794
1816
  this.runPromise = null;
1795
1817
  this.runPromiseDeviceId = null;
1796
1818
  }
1797
- this.assertRunning();
1798
1819
  this.acquiringDevices.add(uuid);
1799
1820
  let connectAttempted = false;
1800
1821
  try {
@@ -1802,7 +1823,7 @@ class ElectronBleTransport {
1802
1823
  throw new Error('Noble BLE API not available');
1803
1824
  }
1804
1825
  const device = yield invokeNobleBle(window.desktopApi.nobleBle.getDevice(uuid));
1805
- this.assertRunning();
1826
+ assertAcquireActive();
1806
1827
  if (!device) {
1807
1828
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, `Device ${uuid} not found`);
1808
1829
  }
@@ -1821,12 +1842,13 @@ class ElectronBleTransport {
1821
1842
  try {
1822
1843
  connectAttempted = true;
1823
1844
  yield invokeNobleBle(window.desktopApi.nobleBle.connect(uuid));
1845
+ assertAcquireActive();
1824
1846
  this.connectedDevices.add(uuid);
1825
1847
  }
1826
1848
  catch (error) {
1827
1849
  this.handleBluetoothError(error);
1828
1850
  }
1829
- this.assertRunning();
1851
+ assertAcquireActive();
1830
1852
  const mtuCleanup = this.createMtuSubscription(uuid);
1831
1853
  if (mtuCleanup) {
1832
1854
  this.mtuCleanups.set(uuid, mtuCleanup);
@@ -1839,8 +1861,9 @@ class ElectronBleTransport {
1839
1861
  catch (error) {
1840
1862
  this.handleBluetoothError(error);
1841
1863
  }
1864
+ assertAcquireActive();
1842
1865
  yield this.refreshBlePacketCapacity(uuid);
1843
- this.assertRunning();
1866
+ assertAcquireActive();
1844
1867
  const cleanup = this.createNotificationSubscription(uuid);
1845
1868
  this.notificationCleanups.set(uuid, cleanup);
1846
1869
  const protocolType = yield this.detectProtocol(uuid, expectedProtocol, protocolHint, {
@@ -1848,7 +1871,7 @@ class ElectronBleTransport {
1848
1871
  onlyConnectBleDevice: input.onlyConnectBleDevice,
1849
1872
  abortSignal: input.abortSignal,
1850
1873
  });
1851
- this.assertRunning();
1874
+ assertAcquireActive();
1852
1875
  if (protocolType === 'V2') {
1853
1876
  (_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug('[Electron BLE] Protocol V2 write configured', {
1854
1877
  writeMode: 'withoutResponse',
@@ -1860,26 +1883,30 @@ class ElectronBleTransport {
1860
1883
  }
1861
1884
  catch (error) {
1862
1885
  (_e = this.Log) === null || _e === void 0 ? void 0 : _e.error('[Electron BLE] acquire failed:', error);
1863
- try {
1864
- const nobleBle = (_f = window.desktopApi) === null || _f === void 0 ? void 0 : _f.nobleBle;
1865
- if (nobleBle && !this.stopped && (connectAttempted || this.connectedDevices.has(uuid))) {
1866
- if (this.connectedDevices.has(uuid)) {
1867
- yield invokeNobleBle(nobleBle.unsubscribe(uuid)).catch(cleanupError => {
1868
- var _a;
1869
- (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[Electron BLE] acquire unsubscribe failed:', cleanupError);
1870
- });
1886
+ if (isCurrentAcquire()) {
1887
+ try {
1888
+ const nobleBle = (_f = window.desktopApi) === null || _f === void 0 ? void 0 : _f.nobleBle;
1889
+ if (nobleBle && !this.stopped && (connectAttempted || this.connectedDevices.has(uuid))) {
1890
+ if (this.connectedDevices.has(uuid)) {
1891
+ yield invokeNobleBle(nobleBle.unsubscribe(uuid)).catch(cleanupError => {
1892
+ var _a;
1893
+ (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[Electron BLE] acquire unsubscribe failed:', cleanupError);
1894
+ });
1895
+ }
1896
+ yield invokeNobleBle(nobleBle.disconnect(uuid));
1871
1897
  }
1872
- yield invokeNobleBle(nobleBle.disconnect(uuid));
1873
1898
  }
1899
+ catch (cleanupError) {
1900
+ (_g = this.Log) === null || _g === void 0 ? void 0 : _g.debug('[Electron BLE] acquire cleanup failed:', cleanupError);
1901
+ }
1902
+ this.cleanupDeviceState(uuid);
1874
1903
  }
1875
- catch (cleanupError) {
1876
- (_g = this.Log) === null || _g === void 0 ? void 0 : _g.debug('[Electron BLE] acquire cleanup failed:', cleanupError);
1877
- }
1878
- this.cleanupDeviceState(uuid);
1879
- this.handleBluetoothError(error);
1904
+ throw this.normalizeBluetoothError(error);
1880
1905
  }
1881
1906
  finally {
1882
- this.acquiringDevices.delete(uuid);
1907
+ if (isCurrentAcquire()) {
1908
+ this.acquiringDevices.delete(uuid);
1909
+ }
1883
1910
  }
1884
1911
  });
1885
1912
  }
@@ -2001,8 +2028,9 @@ class ElectronBleTransport {
2001
2028
  yield this.resetProbeStateAfterProtocolProbe(uuid, probeOrder[i - 1]);
2002
2029
  this.assertRunning();
2003
2030
  }
2031
+ this.lastV1ProbeFailedWithoutTimeout.delete(uuid);
2004
2032
  let detected = protocol === 'V1' ? yield this.probeProtocolV1(uuid) : yield this.probeProtocolV2(uuid);
2005
- if (!detected && protocol === 'V1') {
2033
+ if (!detected && protocol === 'V1' && !this.lastV1ProbeFailedWithoutTimeout.has(uuid)) {
2006
2034
  detected = yield this.wakeSilentProtocolV1Device(uuid, probeOrder, options);
2007
2035
  }
2008
2036
  this.assertRunning();
@@ -2047,7 +2075,7 @@ class ElectronBleTransport {
2047
2075
  let answeredV1 = false;
2048
2076
  try {
2049
2077
  this.deviceProtocol.set(uuid, 'V1');
2050
- const response = yield this.callProtocolV1(uuid, 'Initialize', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT_MS }, { oneShot: true });
2078
+ const response = yield this.callProtocolV1(uuid, 'Initialize', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT_MS }, { oneShot: true }, true);
2051
2079
  answeredV1 = typeof (response === null || response === void 0 ? void 0 : response.type) === 'string';
2052
2080
  }
2053
2081
  catch (error) {
@@ -2118,7 +2146,8 @@ class ElectronBleTransport {
2118
2146
  }
2119
2147
  try {
2120
2148
  this.deviceProtocol.set(uuid, 'V1');
2121
- yield this.callProtocolV1(uuid, 'GetFeatures', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT_MS }, { oneShot: true });
2149
+ this.lastV1ProbeFailedWithoutTimeout.delete(uuid);
2150
+ yield this.callProtocolV1(uuid, 'GetFeatures', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT_MS }, { oneShot: true }, true);
2122
2151
  return true;
2123
2152
  }
2124
2153
  catch (error) {
@@ -2127,6 +2156,9 @@ class ElectronBleTransport {
2127
2156
  if (shouldRethrowElectronProtocolProbeError(error)) {
2128
2157
  throw error;
2129
2158
  }
2159
+ if (!(error instanceof Error && this.probeResponseTimeoutErrors.has(error))) {
2160
+ this.lastV1ProbeFailedWithoutTimeout.add(uuid);
2161
+ }
2130
2162
  return false;
2131
2163
  }
2132
2164
  });
@@ -2371,7 +2403,7 @@ class ElectronBleTransport {
2371
2403
  yield this.callProtocolV1(uuid, name, data);
2372
2404
  });
2373
2405
  }
2374
- callProtocolV1(uuid, name, data, options, writeOptions) {
2406
+ callProtocolV1(uuid, name, data, options, writeOptions, isProtocolProbe = false) {
2375
2407
  var _a, _b;
2376
2408
  return __awaiter(this, void 0, void 0, function* () {
2377
2409
  if (!this._messages) {
@@ -2388,6 +2420,7 @@ class ElectronBleTransport {
2388
2420
  const messages = this._messages;
2389
2421
  const buffers = ProtocolV1.encodeTransportPackets(messages, name, data);
2390
2422
  let timeout;
2423
+ let responseTimedOut = false;
2391
2424
  try {
2392
2425
  if (!((_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle)) {
2393
2426
  throw new Error('Noble BLE write API not available');
@@ -2410,6 +2443,7 @@ class ElectronBleTransport {
2410
2443
  new Promise((_, reject) => {
2411
2444
  if (options === null || options === void 0 ? void 0 : options.timeoutMs) {
2412
2445
  timeout = setTimeout(() => {
2446
+ responseTimedOut = true;
2413
2447
  const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, `BLE response timeout after ${options.timeoutMs}ms for ${name}`);
2414
2448
  runPromise.reject(error);
2415
2449
  reject(error);
@@ -2425,19 +2459,21 @@ class ElectronBleTransport {
2425
2459
  }
2426
2460
  catch (e) {
2427
2461
  (_b = this.Log) === null || _b === void 0 ? void 0 : _b.error('[Electron BLE] Protocol V1 call error:', e);
2428
- const isProbeTimeout = (name === 'GetFeatures' || name === 'Initialize') &&
2429
- (options === null || options === void 0 ? void 0 : options.timeoutMs) === PROTOCOL_PROBE_TIMEOUT_MS;
2430
2462
  if ((e === null || e === void 0 ? void 0 : e.errorCode) === hdShared.HardwareErrorCode.BleTimeoutError) {
2431
2463
  this.v1Buffers.set(uuid, { buffer: [], bufferLength: 0 });
2432
2464
  const notifyCleanup = this.notificationCleanups.get(uuid);
2433
2465
  notifyCleanup === null || notifyCleanup === void 0 ? void 0 : notifyCleanup();
2434
2466
  this.notificationCleanups.delete(uuid);
2435
2467
  this.notificationTokens.delete(uuid);
2436
- if (!isProbeTimeout) {
2468
+ if (!isProtocolProbe) {
2437
2469
  yield this.releaseNative(uuid, { forceNative: true });
2438
2470
  }
2439
2471
  }
2440
- throw this.normalizeBluetoothError(e);
2472
+ const normalized = this.normalizeBluetoothError(e);
2473
+ if (isProtocolProbe && responseTimedOut && normalized instanceof Error) {
2474
+ this.probeResponseTimeoutErrors.add(normalized);
2475
+ }
2476
+ throw normalized;
2441
2477
  }
2442
2478
  finally {
2443
2479
  if (timeout)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-web-device",
3
- "version": "1.2.11-alpha.15",
3
+ "version": "1.2.11-alpha.17",
4
4
  "author": "OneKey",
5
5
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
6
6
  "license": "MIT",
@@ -21,14 +21,14 @@
21
21
  "lint:fix": "eslint . --fix"
22
22
  },
23
23
  "dependencies": {
24
- "@onekeyfe/hd-shared": "1.2.11-alpha.15",
25
- "@onekeyfe/hd-transport": "1.2.11-alpha.15",
24
+ "@onekeyfe/hd-shared": "1.2.11-alpha.17",
25
+ "@onekeyfe/hd-transport": "1.2.11-alpha.17",
26
26
  "bytebuffer": "^5.0.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@onekeyfe/hd-transport-electron": "1.2.11-alpha.15",
29
+ "@onekeyfe/hd-transport-electron": "1.2.11-alpha.17",
30
30
  "@types/w3c-web-usb": "^1.0.6",
31
31
  "@types/web-bluetooth": "^0.0.17"
32
32
  },
33
- "gitHead": "9cf72875d3f29f904f1e337f80a2f2e20bf88aed"
33
+ "gitHead": "0983ef025972bb84f363d23dc32d62eeae72a623"
34
34
  }
@@ -122,9 +122,12 @@ const shouldRethrowElectronProtocolProbeError = (error: unknown): boolean => {
122
122
  };
123
123
 
124
124
  const isUnstartedElectronWakeError = (error: unknown): boolean => {
125
- const code = (error as { errorCode?: unknown })?.errorCode;
126
- // Errors returned before a GATT write is submitted to the peripheral.
125
+ const candidate = error as { errorCode?: unknown; params?: { writeRejected?: unknown } };
126
+ const code = candidate?.errorCode;
127
+ // Errors returned before a GATT write is submitted or explicitly rejected by the host
128
+ // (e.g. Windows pairing rejection with status: 3) leave the peripheral untouched.
127
129
  return (
130
+ candidate?.params?.writeRejected === true ||
128
131
  code === HardwareErrorCode.BleCharacteristicNotFound ||
129
132
  code === HardwareErrorCode.BlePoweredOff ||
130
133
  code === HardwareErrorCode.BleUnsupported ||
@@ -182,6 +185,14 @@ export default class ElectronBleTransport {
182
185
 
183
186
  private silentDetections = new Map<string, 'silent' | 'woken'>();
184
187
 
188
+ private probeResponseTimeoutErrors = new WeakSet<Error>();
189
+
190
+ private lastV1ProbeFailedWithoutTimeout: Set<string> = new Set();
191
+
192
+ private acquireGenerations: Map<string, number> = new Map();
193
+
194
+ private nextAcquireGeneration = 1;
195
+
185
196
  private deviceMtus: Map<string, number> = new Map();
186
197
 
187
198
  private devicePacketCapacities: Map<string, number> = new Map();
@@ -294,6 +305,7 @@ export default class ElectronBleTransport {
294
305
  // and doesn't depend on connection state. Preserving it avoids redundant V1 probe on reconnect.
295
306
  this.v1Buffers.delete(deviceId);
296
307
  this.v2Assemblers.delete(deviceId);
308
+ this.lastV1ProbeFailedWithoutTimeout.delete(deviceId);
297
309
  this.resetProtocolV2Frames(deviceId);
298
310
  this.notificationTokens.delete(deviceId);
299
311
  if (this.runPromise && this.runPromiseDeviceId === deviceId) {
@@ -364,6 +376,8 @@ export default class ElectronBleTransport {
364
376
 
365
377
  await Promise.all(Array.from(trackedDeviceIds, deviceId => this.releaseNative(deviceId)));
366
378
  this.acquiringDevices.clear();
379
+ this.acquireGenerations.clear();
380
+ this.lastV1ProbeFailedWithoutTimeout.clear();
367
381
  this.protocolV2CallCounts.clear();
368
382
  this.silentDetections.clear();
369
383
  await this.protocolV2Links
@@ -458,6 +472,17 @@ export default class ElectronBleTransport {
458
472
  throw ERRORS.TypedError(HardwareErrorCode.BleRequiredUUID);
459
473
  }
460
474
 
475
+ const acquireGeneration = this.nextAcquireGeneration;
476
+ this.nextAcquireGeneration += 1;
477
+ this.acquireGenerations.set(uuid, acquireGeneration);
478
+ const isCurrentAcquire = () => this.acquireGenerations.get(uuid) === acquireGeneration;
479
+ const assertAcquireActive = () => {
480
+ this.assertRunning();
481
+ if (input.abortSignal?.aborted || !isCurrentAcquire()) {
482
+ throw ERRORS.TypedError(HardwareErrorCode.DeviceInterruptedFromUser);
483
+ }
484
+ };
485
+
461
486
  const retainedToken =
462
487
  this.retainedDevices.has(uuid) &&
463
488
  !forceProtocolDetection &&
@@ -470,6 +495,8 @@ export default class ElectronBleTransport {
470
495
  await this.release(uuid);
471
496
  }
472
497
 
498
+ assertAcquireActive();
499
+
473
500
  if (forceCleanRunPromise && this.runPromise) {
474
501
  const error = ERRORS.TypedError(HardwareErrorCode.BleForceCleanRunPromise);
475
502
  this.runPromise.reject(error);
@@ -477,7 +504,6 @@ export default class ElectronBleTransport {
477
504
  this.runPromiseDeviceId = null;
478
505
  }
479
506
 
480
- this.assertRunning();
481
507
  this.acquiringDevices.add(uuid);
482
508
  let connectAttempted = false;
483
509
  try {
@@ -486,7 +512,7 @@ export default class ElectronBleTransport {
486
512
  }
487
513
 
488
514
  const device = await invokeNobleBle(window.desktopApi.nobleBle.getDevice(uuid));
489
- this.assertRunning();
515
+ assertAcquireActive();
490
516
  if (!device) {
491
517
  throw ERRORS.TypedError(HardwareErrorCode.DeviceNotFound, `Device ${uuid} not found`);
492
518
  }
@@ -512,11 +538,12 @@ export default class ElectronBleTransport {
512
538
  try {
513
539
  connectAttempted = true;
514
540
  await invokeNobleBle(window.desktopApi.nobleBle.connect(uuid));
541
+ assertAcquireActive();
515
542
  this.connectedDevices.add(uuid);
516
543
  } catch (error) {
517
544
  this.handleBluetoothError(error);
518
545
  }
519
- this.assertRunning();
546
+ assertAcquireActive();
520
547
 
521
548
  const mtuCleanup = this.createMtuSubscription(uuid);
522
549
  if (mtuCleanup) {
@@ -531,8 +558,9 @@ export default class ElectronBleTransport {
531
558
  } catch (error) {
532
559
  this.handleBluetoothError(error);
533
560
  }
561
+ assertAcquireActive();
534
562
  await this.refreshBlePacketCapacity(uuid);
535
- this.assertRunning();
563
+ assertAcquireActive();
536
564
 
537
565
  const cleanup = this.createNotificationSubscription(uuid);
538
566
  this.notificationCleanups.set(uuid, cleanup);
@@ -542,7 +570,7 @@ export default class ElectronBleTransport {
542
570
  onlyConnectBleDevice: input.onlyConnectBleDevice,
543
571
  abortSignal: input.abortSignal,
544
572
  });
545
- this.assertRunning();
573
+ assertAcquireActive();
546
574
  if (protocolType === 'V2') {
547
575
  this.Log?.debug('[Electron BLE] Protocol V2 write configured', {
548
576
  writeMode: 'withoutResponse',
@@ -557,23 +585,27 @@ export default class ElectronBleTransport {
557
585
  };
558
586
  } catch (error) {
559
587
  this.Log?.error('[Electron BLE] acquire failed:', error);
560
- try {
561
- const nobleBle = window.desktopApi?.nobleBle;
562
- if (nobleBle && !this.stopped && (connectAttempted || this.connectedDevices.has(uuid))) {
563
- if (this.connectedDevices.has(uuid)) {
564
- await invokeNobleBle(nobleBle.unsubscribe(uuid)).catch(cleanupError => {
565
- this.Log?.debug('[Electron BLE] acquire unsubscribe failed:', cleanupError);
566
- });
588
+ if (isCurrentAcquire()) {
589
+ try {
590
+ const nobleBle = window.desktopApi?.nobleBle;
591
+ if (nobleBle && !this.stopped && (connectAttempted || this.connectedDevices.has(uuid))) {
592
+ if (this.connectedDevices.has(uuid)) {
593
+ await invokeNobleBle(nobleBle.unsubscribe(uuid)).catch(cleanupError => {
594
+ this.Log?.debug('[Electron BLE] acquire unsubscribe failed:', cleanupError);
595
+ });
596
+ }
597
+ await invokeNobleBle(nobleBle.disconnect(uuid));
567
598
  }
568
- await invokeNobleBle(nobleBle.disconnect(uuid));
599
+ } catch (cleanupError) {
600
+ this.Log?.debug('[Electron BLE] acquire cleanup failed:', cleanupError);
569
601
  }
570
- } catch (cleanupError) {
571
- this.Log?.debug('[Electron BLE] acquire cleanup failed:', cleanupError);
602
+ this.cleanupDeviceState(uuid);
572
603
  }
573
- this.cleanupDeviceState(uuid);
574
- this.handleBluetoothError(error);
604
+ throw this.normalizeBluetoothError(error);
575
605
  } finally {
576
- this.acquiringDevices.delete(uuid);
606
+ if (isCurrentAcquire()) {
607
+ this.acquiringDevices.delete(uuid);
608
+ }
577
609
  }
578
610
  }
579
611
 
@@ -731,9 +763,10 @@ export default class ElectronBleTransport {
731
763
  await this.resetProbeStateAfterProtocolProbe(uuid, probeOrder[i - 1]);
732
764
  this.assertRunning();
733
765
  }
766
+ this.lastV1ProbeFailedWithoutTimeout.delete(uuid);
734
767
  let detected =
735
768
  protocol === 'V1' ? await this.probeProtocolV1(uuid) : await this.probeProtocolV2(uuid);
736
- if (!detected && protocol === 'V1') {
769
+ if (!detected && protocol === 'V1' && !this.lastV1ProbeFailedWithoutTimeout.has(uuid)) {
737
770
  detected = await this.wakeSilentProtocolV1Device(uuid, probeOrder, options);
738
771
  }
739
772
  this.assertRunning();
@@ -797,7 +830,8 @@ export default class ElectronBleTransport {
797
830
  'Initialize',
798
831
  {},
799
832
  { timeoutMs: PROTOCOL_PROBE_TIMEOUT_MS },
800
- { oneShot: true }
833
+ { oneShot: true },
834
+ true
801
835
  );
802
836
  answeredV1 = typeof response?.type === 'string';
803
837
  } catch (error) {
@@ -878,12 +912,14 @@ export default class ElectronBleTransport {
878
912
  // session before Core has a chance to restore a hidden wallet. Use a one-shot
879
913
  // native write so a fresh Windows link does not stall 28s in the 15-attempt
880
914
  // pairing retry loop when a sleeping Classic silently ignores GetFeatures.
915
+ this.lastV1ProbeFailedWithoutTimeout.delete(uuid);
881
916
  await this.callProtocolV1(
882
917
  uuid,
883
918
  'GetFeatures',
884
919
  {},
885
920
  { timeoutMs: PROTOCOL_PROBE_TIMEOUT_MS },
886
- { oneShot: true }
921
+ { oneShot: true },
922
+ true
887
923
  );
888
924
  return true;
889
925
  } catch (error) {
@@ -892,6 +928,9 @@ export default class ElectronBleTransport {
892
928
  if (shouldRethrowElectronProtocolProbeError(error)) {
893
929
  throw error;
894
930
  }
931
+ if (!(error instanceof Error && this.probeResponseTimeoutErrors.has(error))) {
932
+ this.lastV1ProbeFailedWithoutTimeout.add(uuid);
933
+ }
895
934
  return false;
896
935
  }
897
936
  }
@@ -1164,7 +1203,8 @@ export default class ElectronBleTransport {
1164
1203
  name: string,
1165
1204
  data: Record<string, unknown>,
1166
1205
  options?: TransportCallOptions,
1167
- writeOptions?: NobleBleWriteOptions
1206
+ writeOptions?: NobleBleWriteOptions,
1207
+ isProtocolProbe = false
1168
1208
  ) {
1169
1209
  if (!this._messages) {
1170
1210
  throw ERRORS.TypedError(HardwareErrorCode.TransportNotConfigured);
@@ -1182,6 +1222,7 @@ export default class ElectronBleTransport {
1182
1222
  const messages = this._messages;
1183
1223
  const buffers = ProtocolV1.encodeTransportPackets(messages, name, data);
1184
1224
  let timeout: ReturnType<typeof setTimeout> | undefined;
1225
+ let responseTimedOut = false;
1185
1226
 
1186
1227
  try {
1187
1228
  if (!window.desktopApi?.nobleBle) {
@@ -1209,6 +1250,7 @@ export default class ElectronBleTransport {
1209
1250
  new Promise<never>((_, reject) => {
1210
1251
  if (options?.timeoutMs) {
1211
1252
  timeout = setTimeout(() => {
1253
+ responseTimedOut = true;
1212
1254
  const error = ERRORS.TypedError(
1213
1255
  HardwareErrorCode.BleTimeoutError,
1214
1256
  `BLE response timeout after ${options.timeoutMs}ms for ${name}`
@@ -1227,20 +1269,21 @@ export default class ElectronBleTransport {
1227
1269
  return check.call(jsonData);
1228
1270
  } catch (e) {
1229
1271
  this.Log?.error('[Electron BLE] Protocol V1 call error:', e);
1230
- const isProbeTimeout =
1231
- (name === 'GetFeatures' || name === 'Initialize') &&
1232
- options?.timeoutMs === PROTOCOL_PROBE_TIMEOUT_MS;
1233
1272
  if ((e as { errorCode?: unknown })?.errorCode === HardwareErrorCode.BleTimeoutError) {
1234
1273
  this.v1Buffers.set(uuid, { buffer: [], bufferLength: 0 });
1235
1274
  const notifyCleanup = this.notificationCleanups.get(uuid);
1236
1275
  notifyCleanup?.();
1237
1276
  this.notificationCleanups.delete(uuid);
1238
1277
  this.notificationTokens.delete(uuid);
1239
- if (!isProbeTimeout) {
1278
+ if (!isProtocolProbe) {
1240
1279
  await this.releaseNative(uuid, { forceNative: true });
1241
1280
  }
1242
1281
  }
1243
- throw this.normalizeBluetoothError(e);
1282
+ const normalized = this.normalizeBluetoothError(e);
1283
+ if (isProtocolProbe && responseTimedOut && normalized instanceof Error) {
1284
+ this.probeResponseTimeoutErrors.add(normalized);
1285
+ }
1286
+ throw normalized;
1244
1287
  } finally {
1245
1288
  if (timeout) clearTimeout(timeout);
1246
1289
  if (this.runPromise === runPromise) {