@onekeyfe/hd-transport-electron 1.2.0-alpha.180 → 1.2.0-alpha.182
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.
|
@@ -32,7 +32,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
32
32
|
|
|
33
33
|
function initNobleBleSupport(webContents) {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-
|
|
35
|
+
const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-848639db.js'); });
|
|
36
36
|
setupNobleBleHandlers(webContents);
|
|
37
37
|
});
|
|
38
38
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-696b29dd.js');
|
|
4
4
|
var hdShared = require('@onekeyfe/hd-shared');
|
|
5
|
+
var hdTransport = require('@onekeyfe/hd-transport');
|
|
5
6
|
var pRetry = require('p-retry');
|
|
6
7
|
|
|
7
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -453,6 +454,15 @@ function setupMtuListener(peripheral, deviceId, webContents) {
|
|
|
453
454
|
deviceMtuListeners.set(deviceId, { peripheral, listener });
|
|
454
455
|
peripheral.on('mtu', listener);
|
|
455
456
|
}
|
|
457
|
+
function frameHeadPreview(packet) {
|
|
458
|
+
if (hdShared.isHeaderChunk(packet)) {
|
|
459
|
+
return packet.subarray(0, 8).toString('hex');
|
|
460
|
+
}
|
|
461
|
+
if (packet.length >= 1 && packet[0] === hdTransport.protocolV2.PROTO_HEAD_SOF) {
|
|
462
|
+
return packet.subarray(0, 7).toString('hex');
|
|
463
|
+
}
|
|
464
|
+
return undefined;
|
|
465
|
+
}
|
|
456
466
|
function writeCharacteristicWithoutResponse(deviceId, writeCharacteristic, buffer) {
|
|
457
467
|
return index.__awaiter(this, void 0, void 0, function* () {
|
|
458
468
|
return new Promise((resolve, reject) => {
|
|
@@ -560,7 +570,7 @@ function transmitHexDataToDevice(deviceId, hexData, options) {
|
|
|
560
570
|
logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Write frame', {
|
|
561
571
|
deviceId,
|
|
562
572
|
bytes: toBuffer.length,
|
|
563
|
-
head: toBuffer
|
|
573
|
+
head: frameHeadPreview(toBuffer),
|
|
564
574
|
packetCapacity,
|
|
565
575
|
mtu: (_a = peripheral.mtu) !== null && _a !== void 0 ? _a : null,
|
|
566
576
|
pacingDelayMs,
|
|
@@ -1015,11 +1025,12 @@ function setupConnectionAndDiscoverServices(peripheral, deviceId, webContents) {
|
|
|
1015
1025
|
}
|
|
1016
1026
|
catch (discoveryError) {
|
|
1017
1027
|
if (peripheral.state === 'connected') {
|
|
1018
|
-
logger === null || logger === void 0 ? void 0 : logger.error('[NobleBLE] Service discovery failed on a live link, dropping it
|
|
1028
|
+
logger === null || logger === void 0 ? void 0 : logger.error('[NobleBLE] Service discovery failed on a live link, dropping it before the fresh scan', discoveryError);
|
|
1019
1029
|
yield disconnectDevice(deviceId).catch(() => undefined);
|
|
1020
|
-
throw discoveryError;
|
|
1021
1030
|
}
|
|
1022
|
-
|
|
1031
|
+
else {
|
|
1032
|
+
logger === null || logger === void 0 ? void 0 : logger.error('[NobleBLE] Service discovery failed, attempting fresh scan...', discoveryError);
|
|
1033
|
+
}
|
|
1023
1034
|
return freshScanAndDiscover(deviceId, webContents);
|
|
1024
1035
|
}
|
|
1025
1036
|
});
|
|
@@ -1206,9 +1217,9 @@ function connectDevice(deviceId, webContents) {
|
|
|
1206
1217
|
}
|
|
1207
1218
|
catch (setupError) {
|
|
1208
1219
|
logger === null || logger === void 0 ? void 0 : logger.error('[NobleBLE] Connection setup failed:', setupError);
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1220
|
+
disconnectDevice(deviceId)
|
|
1221
|
+
.catch(() => undefined)
|
|
1222
|
+
.then(() => reject(setupError));
|
|
1212
1223
|
}
|
|
1213
1224
|
}));
|
|
1214
1225
|
});
|
|
@@ -1320,7 +1331,7 @@ function subscribeNotifications(deviceId, callback) {
|
|
|
1320
1331
|
logger === null || logger === void 0 ? void 0 : logger.debug('[NobleBLE] Notify frame', {
|
|
1321
1332
|
deviceId,
|
|
1322
1333
|
bytes: data.length,
|
|
1323
|
-
head: data
|
|
1334
|
+
head: frameHeadPreview(data),
|
|
1324
1335
|
});
|
|
1325
1336
|
if (!pairedDevices.has(deviceId)) {
|
|
1326
1337
|
pairedDevices.add(deviceId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"AAkCA,OAAO,KAAK,EAA+B,WAAW,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAoFhE,wBAAgB,+BAA+B,CAAC,OAAO,CAAC,EAAE,oBAAoB,UAI7E;AA4xDD,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAkMpE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-electron",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.182",
|
|
4
4
|
"author": "OneKey",
|
|
5
5
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"electron-log": ">=4.0.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-core": "1.2.0-alpha.
|
|
29
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
30
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-core": "1.2.0-alpha.182",
|
|
29
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.182",
|
|
30
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.182",
|
|
31
31
|
"@stoprocent/noble": "2.3.16",
|
|
32
32
|
"p-retry": "^4.6.2"
|
|
33
33
|
},
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"electron": "^25.0.0",
|
|
37
37
|
"typescript": "^5.3.3"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "86d5a6b9be303da50566b6a4865a015829c15341"
|
|
40
40
|
}
|
package/src/noble-ble-handler.ts
CHANGED
|
@@ -15,11 +15,13 @@ import {
|
|
|
15
15
|
ONEKEY_WRITE_CHARACTERISTIC_UUID,
|
|
16
16
|
createKnownBleUuidAliases,
|
|
17
17
|
hasOnekeyCommunicationService,
|
|
18
|
+
isHeaderChunk,
|
|
18
19
|
isOnekeyBluetoothDevice,
|
|
19
20
|
isPro2FamilyBleName,
|
|
20
21
|
matchesKnownBleUuid,
|
|
21
22
|
wait,
|
|
22
23
|
} from '@onekeyfe/hd-shared';
|
|
24
|
+
import { protocolV2 } from '@onekeyfe/hd-transport';
|
|
23
25
|
import pRetry from 'p-retry';
|
|
24
26
|
|
|
25
27
|
import { resolveBlePacketCapacity } from './ble-packet-capacity';
|
|
@@ -588,6 +590,28 @@ function setupMtuListener(
|
|
|
588
590
|
|
|
589
591
|
// ===== Write helpers (inline) =====
|
|
590
592
|
|
|
593
|
+
/**
|
|
594
|
+
* Hex preview of a BLE packet, for diagnostics only.
|
|
595
|
+
*
|
|
596
|
+
* Only a frame header is safe to print: a multi-packet message calls the write
|
|
597
|
+
* hook and the notify listener once per packet, and every continuation packet
|
|
598
|
+
* starts in raw protobuf payload (field logs have shown a device serial and a
|
|
599
|
+
* firmware string land in the log this way).
|
|
600
|
+
*
|
|
601
|
+
* V1 header: report id 0x3f + magic 0x23 0x23 + message type (2) + length (4).
|
|
602
|
+
* V2 header: SOF 0x5A + frame length (2) + CRC8 + router + attr + seq, i.e.
|
|
603
|
+
* bytes 0-6; byte 7 is already payload.
|
|
604
|
+
*/
|
|
605
|
+
function frameHeadPreview(packet: Buffer): string | undefined {
|
|
606
|
+
if (isHeaderChunk(packet)) {
|
|
607
|
+
return packet.subarray(0, 8).toString('hex');
|
|
608
|
+
}
|
|
609
|
+
if (packet.length >= 1 && packet[0] === protocolV2.PROTO_HEAD_SOF) {
|
|
610
|
+
return packet.subarray(0, 7).toString('hex');
|
|
611
|
+
}
|
|
612
|
+
return undefined;
|
|
613
|
+
}
|
|
614
|
+
|
|
591
615
|
async function writeCharacteristicWithoutResponse(
|
|
592
616
|
deviceId: string,
|
|
593
617
|
writeCharacteristic: Characteristic,
|
|
@@ -733,12 +757,12 @@ async function transmitHexDataToDevice(
|
|
|
733
757
|
);
|
|
734
758
|
const pacingDelayMs = resolveNobleBleWritePacingDelay(options);
|
|
735
759
|
|
|
736
|
-
// Diagnostics:
|
|
737
|
-
//
|
|
760
|
+
// Diagnostics: a frame header identifies which protocol frame went out.
|
|
761
|
+
// Continuation packets carry payload, so they report scalars only.
|
|
738
762
|
logger?.info('[NobleBLE] Write frame', {
|
|
739
763
|
deviceId,
|
|
740
764
|
bytes: toBuffer.length,
|
|
741
|
-
head: toBuffer
|
|
765
|
+
head: frameHeadPreview(toBuffer),
|
|
742
766
|
packetCapacity,
|
|
743
767
|
mtu: peripheral.mtu ?? null,
|
|
744
768
|
pacingDelayMs,
|
|
@@ -1431,21 +1455,24 @@ async function setupConnectionAndDiscoverServices(
|
|
|
1431
1455
|
try {
|
|
1432
1456
|
return await discoverServicesAndCharacteristicsWithRetry(peripheral, deviceId);
|
|
1433
1457
|
} catch (discoveryError) {
|
|
1434
|
-
// A connected peripheral does not advertise, so the fresh scan below
|
|
1435
|
-
// only run out its timeout. Drop the link
|
|
1436
|
-
//
|
|
1437
|
-
//
|
|
1438
|
-
//
|
|
1439
|
-
//
|
|
1458
|
+
// A connected peripheral does not advertise, so the fresh scan below would
|
|
1459
|
+
// only run out its timeout. Drop the link first, then rescan: the cold
|
|
1460
|
+
// reconnect is what recovers a device whose stack stopped serving its
|
|
1461
|
+
// application layer. Recover here rather than throwing to the caller —
|
|
1462
|
+
// one acquire pays ~2s for the rescan, while a thrown error costs the
|
|
1463
|
+
// renderer a full retry round trip.
|
|
1440
1464
|
if (peripheral.state === 'connected') {
|
|
1441
1465
|
logger?.error(
|
|
1442
|
-
'[NobleBLE] Service discovery failed on a live link, dropping it
|
|
1466
|
+
'[NobleBLE] Service discovery failed on a live link, dropping it before the fresh scan',
|
|
1443
1467
|
discoveryError
|
|
1444
1468
|
);
|
|
1445
1469
|
await disconnectDevice(deviceId).catch(() => undefined);
|
|
1446
|
-
|
|
1470
|
+
} else {
|
|
1471
|
+
logger?.error(
|
|
1472
|
+
'[NobleBLE] Service discovery failed, attempting fresh scan...',
|
|
1473
|
+
discoveryError
|
|
1474
|
+
);
|
|
1447
1475
|
}
|
|
1448
|
-
logger?.error('[NobleBLE] Service discovery failed, attempting fresh scan...', discoveryError);
|
|
1449
1476
|
return freshScanAndDiscover(deviceId, webContents);
|
|
1450
1477
|
}
|
|
1451
1478
|
}
|
|
@@ -1716,9 +1743,14 @@ async function connectDevice(deviceId: string, webContents: WebContents): Promis
|
|
|
1716
1743
|
resolve();
|
|
1717
1744
|
} catch (setupError) {
|
|
1718
1745
|
logger?.error('[NobleBLE] Connection setup failed:', setupError);
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1746
|
+
// Never reject from inside a raw disconnect callback: noble only fires
|
|
1747
|
+
// it on a real 'disconnect' event, so a peripheral that is already
|
|
1748
|
+
// down leaves this promise — and the renderer acquire awaiting it —
|
|
1749
|
+
// pending forever. disconnectDevice always settles (it no-ops on an
|
|
1750
|
+
// unknown peripheral and caps the confirm wait).
|
|
1751
|
+
disconnectDevice(deviceId)
|
|
1752
|
+
.catch(() => undefined)
|
|
1753
|
+
.then(() => reject(setupError));
|
|
1722
1754
|
}
|
|
1723
1755
|
});
|
|
1724
1756
|
});
|
|
@@ -1883,7 +1915,7 @@ async function subscribeNotifications(
|
|
|
1883
1915
|
logger?.debug('[NobleBLE] Notify frame', {
|
|
1884
1916
|
deviceId,
|
|
1885
1917
|
bytes: data.length,
|
|
1886
|
-
head: data
|
|
1918
|
+
head: frameHeadPreview(data),
|
|
1887
1919
|
});
|
|
1888
1920
|
// Windows BLE pairing detection: receiving any data means device is paired
|
|
1889
1921
|
if (!pairedDevices.has(deviceId)) {
|