@onekeyfe/hd-transport-electron 1.2.0-alpha.182 → 1.2.0-alpha.183
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-56d2eab3.js'); });
|
|
36
36
|
setupNobleBleHandlers(webContents);
|
|
37
37
|
});
|
|
38
38
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-a518d449.js');
|
|
4
4
|
var hdShared = require('@onekeyfe/hd-shared');
|
|
5
|
-
var hdTransport = require('@onekeyfe/hd-transport');
|
|
6
5
|
var pRetry = require('p-retry');
|
|
7
6
|
|
|
8
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -454,15 +453,6 @@ function setupMtuListener(peripheral, deviceId, webContents) {
|
|
|
454
453
|
deviceMtuListeners.set(deviceId, { peripheral, listener });
|
|
455
454
|
peripheral.on('mtu', listener);
|
|
456
455
|
}
|
|
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
|
-
}
|
|
466
456
|
function writeCharacteristicWithoutResponse(deviceId, writeCharacteristic, buffer) {
|
|
467
457
|
return index.__awaiter(this, void 0, void 0, function* () {
|
|
468
458
|
return new Promise((resolve, reject) => {
|
|
@@ -555,7 +545,6 @@ function attemptWindowsWriteUntilPaired(deviceId, doGetWriteCharacteristic, payl
|
|
|
555
545
|
});
|
|
556
546
|
}
|
|
557
547
|
function transmitHexDataToDevice(deviceId, hexData, options) {
|
|
558
|
-
var _a;
|
|
559
548
|
return index.__awaiter(this, void 0, void 0, function* () {
|
|
560
549
|
const characteristics = deviceCharacteristics.get(deviceId);
|
|
561
550
|
const peripheral = connectedDevices.get(deviceId);
|
|
@@ -567,14 +556,6 @@ function transmitHexDataToDevice(deviceId, hexData, options) {
|
|
|
567
556
|
const doGetWriteCharacteristic = () => { var _a; return (_a = deviceCharacteristics.get(deviceId)) === null || _a === void 0 ? void 0 : _a.write; };
|
|
568
557
|
const packetCapacity = resolveBlePacketCapacity(peripheral.mtu, BLE_PACKET_SIZE_MAXIMUM, BLE_PACKET_SIZE_FALLBACK);
|
|
569
558
|
const pacingDelayMs = resolveNobleBleWritePacingDelay(options);
|
|
570
|
-
logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Write frame', {
|
|
571
|
-
deviceId,
|
|
572
|
-
bytes: toBuffer.length,
|
|
573
|
-
head: frameHeadPreview(toBuffer),
|
|
574
|
-
packetCapacity,
|
|
575
|
-
mtu: (_a = peripheral.mtu) !== null && _a !== void 0 ? _a : null,
|
|
576
|
-
pacingDelayMs,
|
|
577
|
-
});
|
|
578
559
|
if (!IS_WINDOWS || pairedDevices.has(deviceId)) {
|
|
579
560
|
const writeCharacteristic = doGetWriteCharacteristic();
|
|
580
561
|
if (!writeCharacteristic) {
|
|
@@ -1328,11 +1309,6 @@ function subscribeNotifications(deviceId, callback) {
|
|
|
1328
1309
|
timeoutBehavior: 'reject',
|
|
1329
1310
|
});
|
|
1330
1311
|
notifyCharacteristic.on('data', (data) => {
|
|
1331
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('[NobleBLE] Notify frame', {
|
|
1332
|
-
deviceId,
|
|
1333
|
-
bytes: data.length,
|
|
1334
|
-
head: frameHeadPreview(data),
|
|
1335
|
-
});
|
|
1336
1312
|
if (!pairedDevices.has(deviceId)) {
|
|
1337
1313
|
pairedDevices.add(deviceId);
|
|
1338
1314
|
logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Device paired successfully', { 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":"AAgCA,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;AAsvDD,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.183",
|
|
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.183",
|
|
29
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.183",
|
|
30
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.183",
|
|
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": "fd9b6e749495b0144e734dbe32c57cf483547349"
|
|
40
40
|
}
|
package/src/noble-ble-handler.ts
CHANGED
|
@@ -15,13 +15,11 @@ import {
|
|
|
15
15
|
ONEKEY_WRITE_CHARACTERISTIC_UUID,
|
|
16
16
|
createKnownBleUuidAliases,
|
|
17
17
|
hasOnekeyCommunicationService,
|
|
18
|
-
isHeaderChunk,
|
|
19
18
|
isOnekeyBluetoothDevice,
|
|
20
19
|
isPro2FamilyBleName,
|
|
21
20
|
matchesKnownBleUuid,
|
|
22
21
|
wait,
|
|
23
22
|
} from '@onekeyfe/hd-shared';
|
|
24
|
-
import { protocolV2 } from '@onekeyfe/hd-transport';
|
|
25
23
|
import pRetry from 'p-retry';
|
|
26
24
|
|
|
27
25
|
import { resolveBlePacketCapacity } from './ble-packet-capacity';
|
|
@@ -590,28 +588,6 @@ function setupMtuListener(
|
|
|
590
588
|
|
|
591
589
|
// ===== Write helpers (inline) =====
|
|
592
590
|
|
|
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
|
-
|
|
615
591
|
async function writeCharacteristicWithoutResponse(
|
|
616
592
|
deviceId: string,
|
|
617
593
|
writeCharacteristic: Characteristic,
|
|
@@ -757,17 +733,6 @@ async function transmitHexDataToDevice(
|
|
|
757
733
|
);
|
|
758
734
|
const pacingDelayMs = resolveNobleBleWritePacingDelay(options);
|
|
759
735
|
|
|
760
|
-
// Diagnostics: a frame header identifies which protocol frame went out.
|
|
761
|
-
// Continuation packets carry payload, so they report scalars only.
|
|
762
|
-
logger?.info('[NobleBLE] Write frame', {
|
|
763
|
-
deviceId,
|
|
764
|
-
bytes: toBuffer.length,
|
|
765
|
-
head: frameHeadPreview(toBuffer),
|
|
766
|
-
packetCapacity,
|
|
767
|
-
mtu: peripheral.mtu ?? null,
|
|
768
|
-
pacingDelayMs,
|
|
769
|
-
});
|
|
770
|
-
|
|
771
736
|
if (!IS_WINDOWS || pairedDevices.has(deviceId)) {
|
|
772
737
|
// macOS / Linux or already paired on Windows: direct write
|
|
773
738
|
const writeCharacteristic = doGetWriteCharacteristic();
|
|
@@ -1912,11 +1877,6 @@ async function subscribeNotifications(
|
|
|
1912
1877
|
});
|
|
1913
1878
|
|
|
1914
1879
|
notifyCharacteristic.on('data', (data: Buffer) => {
|
|
1915
|
-
logger?.debug('[NobleBLE] Notify frame', {
|
|
1916
|
-
deviceId,
|
|
1917
|
-
bytes: data.length,
|
|
1918
|
-
head: frameHeadPreview(data),
|
|
1919
|
-
});
|
|
1920
1880
|
// Windows BLE pairing detection: receiving any data means device is paired
|
|
1921
1881
|
if (!pairedDevices.has(deviceId)) {
|
|
1922
1882
|
pairedDevices.add(deviceId);
|