@onekeyfe/hd-transport-electron 1.2.0-alpha.181 → 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,
|
|
@@ -1321,7 +1331,7 @@ function subscribeNotifications(deviceId, callback) {
|
|
|
1321
1331
|
logger === null || logger === void 0 ? void 0 : logger.debug('[NobleBLE] Notify frame', {
|
|
1322
1332
|
deviceId,
|
|
1323
1333
|
bytes: data.length,
|
|
1324
|
-
head: data
|
|
1334
|
+
head: frameHeadPreview(data),
|
|
1325
1335
|
});
|
|
1326
1336
|
if (!pairedDevices.has(deviceId)) {
|
|
1327
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,
|
|
@@ -1891,7 +1915,7 @@ async function subscribeNotifications(
|
|
|
1891
1915
|
logger?.debug('[NobleBLE] Notify frame', {
|
|
1892
1916
|
deviceId,
|
|
1893
1917
|
bytes: data.length,
|
|
1894
|
-
head: data
|
|
1918
|
+
head: frameHeadPreview(data),
|
|
1895
1919
|
});
|
|
1896
1920
|
// Windows BLE pairing detection: receiving any data means device is paired
|
|
1897
1921
|
if (!pairedDevices.has(deviceId)) {
|