@onekeyfe/hardware-cli 1.2.0-alpha.3 → 1.2.0-alpha.4
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.
- package/dist/cli.js +292 -8
- package/dist/sdk.d.ts +2 -0
- package/dist/sdk.js +5 -3
- package/dist/transports/nobleBlePlugin.d.ts +2 -0
- package/dist/transports/nobleBlePlugin.js +328 -0
- package/package.json +7 -6
- package/src/cli.ts +411 -13
- package/src/sdk.ts +11 -3
- package/src/transports/nobleBlePlugin.ts +415 -0
package/dist/cli.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
4
5
|
const commander_1 = require("commander");
|
|
6
|
+
const hd_core_1 = require("@onekeyfe/hd-core");
|
|
7
|
+
const hd_shared_1 = require("@onekeyfe/hd-shared");
|
|
8
|
+
const chains_1 = require("./chains");
|
|
5
9
|
const sdk_1 = require("./sdk");
|
|
6
10
|
const session_1 = require("./session");
|
|
7
|
-
const chains_1 = require("./chains");
|
|
8
|
-
const hd_shared_1 = require("@onekeyfe/hd-shared");
|
|
9
|
-
const hd_core_1 = require("@onekeyfe/hd-core");
|
|
10
11
|
function extractPassphraseSession(payload) {
|
|
11
12
|
if (typeof payload === 'string') {
|
|
12
13
|
return { passphraseState: payload };
|
|
@@ -41,8 +42,10 @@ program
|
|
|
41
42
|
// ============================================================
|
|
42
43
|
program.option('--connect-id <id>', 'Device connection ID (USB: serial, iOS: uuid, Android: MAC)');
|
|
43
44
|
program.option('--device-id <id>', 'Persistent device ID from getFeatures (changes when seed changes)');
|
|
45
|
+
program.option('--transport <transport>', 'Transport to use: usb or ble', 'usb');
|
|
44
46
|
program.option('--passphrase-state <state>', 'Passphrase state for hidden wallet access');
|
|
45
47
|
program.option('--use-empty-passphrase', 'Use standard wallet (skip passphrase prompt)');
|
|
48
|
+
program.option('--debug', 'Enable SDK debug logs');
|
|
46
49
|
// ============================================================
|
|
47
50
|
// Device Commands
|
|
48
51
|
// ============================================================
|
|
@@ -51,8 +54,8 @@ program
|
|
|
51
54
|
.description('Search for connected OneKey hardware wallet devices')
|
|
52
55
|
.action(() => runCommand({}, async ({ sdk, globalOpts }) => {
|
|
53
56
|
const result = await sdk.searchDevices();
|
|
54
|
-
//
|
|
55
|
-
if (result?.success && Array.isArray(result.payload)) {
|
|
57
|
+
// USB 下自动读取 features 成本低;BLE 搜索阶段只做枚举,避免批量连接导致超时。
|
|
58
|
+
if (globalOpts.transport !== 'ble' && result?.success && Array.isArray(result.payload)) {
|
|
56
59
|
for (const device of result.payload) {
|
|
57
60
|
if (device.connectId) {
|
|
58
61
|
try {
|
|
@@ -411,14 +414,40 @@ program
|
|
|
411
414
|
}));
|
|
412
415
|
program
|
|
413
416
|
.command('firmware-update-ble')
|
|
414
|
-
.description('
|
|
417
|
+
.description('Run Protocol V2 firmware update over BLE')
|
|
415
418
|
.action(() => respondAndExit({
|
|
416
419
|
success: false,
|
|
417
420
|
payload: {
|
|
418
|
-
error: '
|
|
419
|
-
code: '
|
|
421
|
+
error: 'Use `onekey-hw --transport ble firmware-update-v4-debug` for BLE Protocol V2 firmware update debugging.',
|
|
422
|
+
code: 'USE_FIRMWARE_UPDATE_V4_DEBUG',
|
|
420
423
|
},
|
|
421
424
|
}));
|
|
425
|
+
program
|
|
426
|
+
.command('firmware-update-v4-debug')
|
|
427
|
+
.description('Debug Protocol V2 firmware update through sdk.firmwareUpdateV4')
|
|
428
|
+
.option('--chunk-size <bytes>', 'Transfer chunk size in bytes')
|
|
429
|
+
.option('--resource <path>', 'FW_MGMT_TARGET_CRATE resource package path')
|
|
430
|
+
.option('--romloader <path>', 'FW_MGMT_TARGET_ROMLOADER binary path')
|
|
431
|
+
.option('--bootloader <path>', 'FW_MGMT_TARGET_BOOTLOADER binary path')
|
|
432
|
+
.option('--application-p1 <path>', 'FW_MGMT_TARGET_APPLICATION_P1 binary path')
|
|
433
|
+
.option('--application-p2 <path>', 'FW_MGMT_TARGET_APPLICATION_P2 binary path')
|
|
434
|
+
.option('--coprocessor <path>', 'FW_MGMT_TARGET_COPROCESSOR binary path')
|
|
435
|
+
.option('--se01 <path>', 'FW_MGMT_TARGET_SE01 binary path')
|
|
436
|
+
.option('--se02 <path>', 'FW_MGMT_TARGET_SE02 binary path')
|
|
437
|
+
.option('--se03 <path>', 'FW_MGMT_TARGET_SE03 binary path')
|
|
438
|
+
.option('--se04 <path>', 'FW_MGMT_TARGET_SE04 binary path')
|
|
439
|
+
.option('--forced-update-res', 'Force resource update')
|
|
440
|
+
.option('--retries <count>', 'Retry count for transient Protocol V2 USB probe failures')
|
|
441
|
+
.action(opts => runCommand({}, async ({ sdk, globalOpts }) => {
|
|
442
|
+
const params = buildFirmwareUpdateV4DebugParams(opts);
|
|
443
|
+
const result = await runFirmwareUpdateV4DebugWithRetry({
|
|
444
|
+
sdk,
|
|
445
|
+
globalOpts,
|
|
446
|
+
params,
|
|
447
|
+
retries: opts.retries ? safeParseInt(opts.retries, '--retries') : undefined,
|
|
448
|
+
});
|
|
449
|
+
outputResult(globalOpts, result);
|
|
450
|
+
}));
|
|
422
451
|
program
|
|
423
452
|
.command('bootloader-check')
|
|
424
453
|
.description('Check bootloader version and status')
|
|
@@ -818,6 +847,9 @@ function outputResult(_globalOpts, result) {
|
|
|
818
847
|
async function runCommand(options, handler) {
|
|
819
848
|
const globalOpts = program.opts();
|
|
820
849
|
try {
|
|
850
|
+
if (globalOpts.transport !== 'usb' && globalOpts.transport !== 'ble') {
|
|
851
|
+
throw new Error(`Unsupported transport: ${globalOpts.transport}. Use "usb" or "ble".`);
|
|
852
|
+
}
|
|
821
853
|
const sdk = await (0, sdk_1.createSDK)(globalOpts);
|
|
822
854
|
if (options.needsSession) {
|
|
823
855
|
await prepareSession(sdk, globalOpts);
|
|
@@ -866,6 +898,258 @@ function safeJsonParse(input, label) {
|
|
|
866
898
|
throw err;
|
|
867
899
|
}
|
|
868
900
|
}
|
|
901
|
+
function readBinaryParam(path) {
|
|
902
|
+
const buffer = (0, node_fs_1.readFileSync)(path);
|
|
903
|
+
return new Uint8Array(buffer).buffer;
|
|
904
|
+
}
|
|
905
|
+
function getFirmwareUpdateV4DebugTotalBytes(params) {
|
|
906
|
+
return [
|
|
907
|
+
params.resourceBinary,
|
|
908
|
+
params.bootloaderBinary,
|
|
909
|
+
params.applicationP1Binary,
|
|
910
|
+
params.applicationP2Binary,
|
|
911
|
+
params.coprocessorBinary,
|
|
912
|
+
params.se01Binary,
|
|
913
|
+
params.se02Binary,
|
|
914
|
+
params.se03Binary,
|
|
915
|
+
params.se04Binary,
|
|
916
|
+
].reduce((total, binary) => total + (binary?.byteLength ?? 0), 0);
|
|
917
|
+
}
|
|
918
|
+
function getFirmwareUpdateV4DebugErrorText(result) {
|
|
919
|
+
if (!result || typeof result !== 'object')
|
|
920
|
+
return '';
|
|
921
|
+
const payload = result.payload;
|
|
922
|
+
if (!payload || typeof payload !== 'object')
|
|
923
|
+
return '';
|
|
924
|
+
const error = payload.error;
|
|
925
|
+
return typeof error === 'string' ? error : '';
|
|
926
|
+
}
|
|
927
|
+
function isProtocolV2UsbProbeTransientResult(result) {
|
|
928
|
+
const error = getFirmwareUpdateV4DebugErrorText(result);
|
|
929
|
+
return (error.includes('Device protocol mismatch') &&
|
|
930
|
+
error.includes('expected V2') &&
|
|
931
|
+
error.includes('did not respond to expected protocol'));
|
|
932
|
+
}
|
|
933
|
+
function isSuccessResult(result) {
|
|
934
|
+
return (!!result && typeof result === 'object' && result.success === true);
|
|
935
|
+
}
|
|
936
|
+
function getFirmwareDebugPayload(message) {
|
|
937
|
+
if (!message || typeof message !== 'object')
|
|
938
|
+
return undefined;
|
|
939
|
+
return message.payload;
|
|
940
|
+
}
|
|
941
|
+
function formatFirmwareDebugProgress(progress) {
|
|
942
|
+
if (!Number.isFinite(progress))
|
|
943
|
+
return '0%';
|
|
944
|
+
return `${Math.min(Math.max(Math.round(progress), 0), 100)}%`;
|
|
945
|
+
}
|
|
946
|
+
function formatFirmwareDebugBytes(bytes) {
|
|
947
|
+
if (!Number.isFinite(bytes) || bytes <= 0)
|
|
948
|
+
return '';
|
|
949
|
+
return `${(bytes / 1024).toFixed(1)} KiB`;
|
|
950
|
+
}
|
|
951
|
+
function maybePrintFirmwareDebugProgress({ progressType, progress, payload, lastPrintedProgress, }) {
|
|
952
|
+
const printableProgress = Math.floor(progress / 10) * 10;
|
|
953
|
+
if (printableProgress <= lastPrintedProgress && progress < 100) {
|
|
954
|
+
return lastPrintedProgress;
|
|
955
|
+
}
|
|
956
|
+
const transferredBytes = Number(payload.transferredBytes);
|
|
957
|
+
const totalBytes = Number(payload.totalBytes);
|
|
958
|
+
const rateBytesPerSecond = Number(payload.rateBytesPerSecond);
|
|
959
|
+
const sizeText = Number.isFinite(transferredBytes) && Number.isFinite(totalBytes) && totalBytes > 0
|
|
960
|
+
? ` ${formatFirmwareDebugBytes(transferredBytes)}/${formatFirmwareDebugBytes(totalBytes)}`
|
|
961
|
+
: '';
|
|
962
|
+
const speedText = Number.isFinite(rateBytesPerSecond) && rateBytesPerSecond > 0
|
|
963
|
+
? ` ${(rateBytesPerSecond / 1024).toFixed(2)} KiB/s`
|
|
964
|
+
: '';
|
|
965
|
+
process.stderr.write(`[onekey-hw] Firmware ${progressType}: ${formatFirmwareDebugProgress(progress)}${sizeText}${speedText}\n`);
|
|
966
|
+
return progress >= 100 ? 100 : printableProgress;
|
|
967
|
+
}
|
|
968
|
+
function buildFirmwareUpdateV4DebugMetrics({ attempt, maxAttempts, totalBytes, totalStartedAt, transferStartedAt, transferEndedAt, installStartedAt, installEndedAt, progressEvents, lastProgress, installProgressEvents, lastInstallProgress, retried, }) {
|
|
969
|
+
const totalElapsedMs = Date.now() - totalStartedAt;
|
|
970
|
+
const transferElapsedMs = transferStartedAt !== undefined && transferEndedAt !== undefined
|
|
971
|
+
? transferEndedAt - transferStartedAt
|
|
972
|
+
: undefined;
|
|
973
|
+
const installElapsedMs = installStartedAt !== undefined && installEndedAt !== undefined
|
|
974
|
+
? installEndedAt - installStartedAt
|
|
975
|
+
: undefined;
|
|
976
|
+
return {
|
|
977
|
+
attempt,
|
|
978
|
+
maxAttempts,
|
|
979
|
+
retried,
|
|
980
|
+
totalBytes,
|
|
981
|
+
progressEvents,
|
|
982
|
+
lastProgress,
|
|
983
|
+
installProgressEvents,
|
|
984
|
+
lastInstallProgress,
|
|
985
|
+
transferSeconds: transferElapsedMs !== undefined ? Number((transferElapsedMs / 1000).toFixed(2)) : null,
|
|
986
|
+
transferKiBPerSecond: transferElapsedMs !== undefined && transferElapsedMs > 0
|
|
987
|
+
? Number((totalBytes / 1024 / (transferElapsedMs / 1000)).toFixed(2))
|
|
988
|
+
: null,
|
|
989
|
+
installSeconds: installElapsedMs !== undefined ? Number((installElapsedMs / 1000).toFixed(2)) : null,
|
|
990
|
+
totalSeconds: Number((totalElapsedMs / 1000).toFixed(2)),
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
async function runFirmwareUpdateV4DebugWithRetry({ sdk, globalOpts, params, retries, }) {
|
|
994
|
+
const totalBytes = getFirmwareUpdateV4DebugTotalBytes(params);
|
|
995
|
+
const maxAttempts = Math.max((retries ?? 2) + 1, 1);
|
|
996
|
+
let currentSdk = sdk;
|
|
997
|
+
let lastResult;
|
|
998
|
+
let retried = false;
|
|
999
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
1000
|
+
let progressEvents = 0;
|
|
1001
|
+
let lastProgress = -1;
|
|
1002
|
+
let transferStartedAt;
|
|
1003
|
+
let transferEndedAt;
|
|
1004
|
+
let installProgressEvents = 0;
|
|
1005
|
+
let lastInstallProgress = -1;
|
|
1006
|
+
let installStartedAt;
|
|
1007
|
+
let installEndedAt;
|
|
1008
|
+
let lastPrintedTransferProgress = -10;
|
|
1009
|
+
let lastPrintedInstallProgress = -10;
|
|
1010
|
+
const totalStartedAt = Date.now();
|
|
1011
|
+
const connectId = retried && globalOpts.transport === 'usb' && globalOpts.connectId
|
|
1012
|
+
? undefined
|
|
1013
|
+
: globalOpts.connectId;
|
|
1014
|
+
const onUiEvent = (message) => {
|
|
1015
|
+
if (!message || typeof message !== 'object')
|
|
1016
|
+
return;
|
|
1017
|
+
const messageType = message.type;
|
|
1018
|
+
const payload = getFirmwareDebugPayload(message);
|
|
1019
|
+
if (messageType === hd_core_1.UI_REQUEST.FIRMWARE_TIP) {
|
|
1020
|
+
const tipMessage = payload?.data?.message;
|
|
1021
|
+
if (typeof tipMessage === 'string') {
|
|
1022
|
+
process.stderr.write(`[onekey-hw] Firmware: ${tipMessage}\n`);
|
|
1023
|
+
}
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
if (messageType === hd_core_1.UI_REQUEST.REQUEST_BUTTON) {
|
|
1027
|
+
const code = typeof payload?.code === 'string' ? ` (${payload.code})` : '';
|
|
1028
|
+
process.stderr.write(`[onekey-hw] Please confirm the firmware update on your device${code}.\n`);
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
if (messageType !== hd_core_1.UI_REQUEST.FIRMWARE_PROGRESS || !payload)
|
|
1032
|
+
return;
|
|
1033
|
+
const progress = Number(payload.progress);
|
|
1034
|
+
if (!Number.isFinite(progress))
|
|
1035
|
+
return;
|
|
1036
|
+
if (payload.progressType === 'transferData') {
|
|
1037
|
+
progressEvents += 1;
|
|
1038
|
+
lastProgress = Math.max(lastProgress, progress);
|
|
1039
|
+
transferStartedAt ?? (transferStartedAt = Date.now());
|
|
1040
|
+
lastPrintedTransferProgress = maybePrintFirmwareDebugProgress({
|
|
1041
|
+
progressType: 'transfer',
|
|
1042
|
+
progress,
|
|
1043
|
+
payload,
|
|
1044
|
+
lastPrintedProgress: lastPrintedTransferProgress,
|
|
1045
|
+
});
|
|
1046
|
+
if (progress >= 100) {
|
|
1047
|
+
transferEndedAt ?? (transferEndedAt = Date.now());
|
|
1048
|
+
}
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
if (payload.progressType === 'installingFirmware') {
|
|
1052
|
+
installProgressEvents += 1;
|
|
1053
|
+
lastInstallProgress = Math.max(lastInstallProgress, progress);
|
|
1054
|
+
installStartedAt ?? (installStartedAt = Date.now());
|
|
1055
|
+
lastPrintedInstallProgress = maybePrintFirmwareDebugProgress({
|
|
1056
|
+
progressType: 'install',
|
|
1057
|
+
progress,
|
|
1058
|
+
payload,
|
|
1059
|
+
lastPrintedProgress: lastPrintedInstallProgress,
|
|
1060
|
+
});
|
|
1061
|
+
if (progress >= 100) {
|
|
1062
|
+
installEndedAt ?? (installEndedAt = Date.now());
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
};
|
|
1066
|
+
currentSdk.on(hd_core_1.UI_EVENT, onUiEvent);
|
|
1067
|
+
try {
|
|
1068
|
+
lastResult = await currentSdk.firmwareUpdateV4(connectId, params);
|
|
1069
|
+
}
|
|
1070
|
+
finally {
|
|
1071
|
+
currentSdk.off?.(hd_core_1.UI_EVENT, onUiEvent);
|
|
1072
|
+
}
|
|
1073
|
+
if (installStartedAt !== undefined && installEndedAt === undefined) {
|
|
1074
|
+
installEndedAt = Date.now();
|
|
1075
|
+
}
|
|
1076
|
+
const debugMetrics = buildFirmwareUpdateV4DebugMetrics({
|
|
1077
|
+
attempt,
|
|
1078
|
+
maxAttempts,
|
|
1079
|
+
totalBytes,
|
|
1080
|
+
totalStartedAt,
|
|
1081
|
+
transferStartedAt,
|
|
1082
|
+
transferEndedAt,
|
|
1083
|
+
installStartedAt,
|
|
1084
|
+
installEndedAt,
|
|
1085
|
+
progressEvents,
|
|
1086
|
+
lastProgress,
|
|
1087
|
+
installProgressEvents,
|
|
1088
|
+
lastInstallProgress,
|
|
1089
|
+
retried,
|
|
1090
|
+
});
|
|
1091
|
+
if (lastResult && typeof lastResult === 'object') {
|
|
1092
|
+
const payload = (lastResult.payload ?? {});
|
|
1093
|
+
lastResult = {
|
|
1094
|
+
...lastResult,
|
|
1095
|
+
payload: {
|
|
1096
|
+
...payload,
|
|
1097
|
+
_debug: debugMetrics,
|
|
1098
|
+
},
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
if (isSuccessResult(lastResult)) {
|
|
1102
|
+
return lastResult;
|
|
1103
|
+
}
|
|
1104
|
+
if (attempt >= maxAttempts ||
|
|
1105
|
+
globalOpts.transport !== 'usb' ||
|
|
1106
|
+
!isProtocolV2UsbProbeTransientResult(lastResult)) {
|
|
1107
|
+
return lastResult;
|
|
1108
|
+
}
|
|
1109
|
+
retried = true;
|
|
1110
|
+
process.stderr.write(`[onekey-hw] Protocol V2 USB probe was transient; retrying firmwareUpdateV4 (${attempt}/${maxAttempts})...\n`);
|
|
1111
|
+
await (0, sdk_1.disposeSDK)();
|
|
1112
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
1113
|
+
currentSdk = await (0, sdk_1.createSDK)(globalOpts);
|
|
1114
|
+
}
|
|
1115
|
+
return lastResult;
|
|
1116
|
+
}
|
|
1117
|
+
function buildFirmwareUpdateV4DebugParams(opts) {
|
|
1118
|
+
const params = {
|
|
1119
|
+
platform: 'desktop',
|
|
1120
|
+
connectProtocol: 'V2',
|
|
1121
|
+
chunkSize: opts.chunkSize ? safeParseInt(opts.chunkSize, '--chunk-size') : undefined,
|
|
1122
|
+
forcedUpdateRes: opts.forcedUpdateRes,
|
|
1123
|
+
resourceBinary: opts.resource ? readBinaryParam(opts.resource) : undefined,
|
|
1124
|
+
romloaderBinary: opts.romloader ? readBinaryParam(opts.romloader) : undefined,
|
|
1125
|
+
bootloaderBinary: opts.bootloader ? readBinaryParam(opts.bootloader) : undefined,
|
|
1126
|
+
applicationP1Binary: opts.applicationP1 ? readBinaryParam(opts.applicationP1) : undefined,
|
|
1127
|
+
applicationP2Binary: opts.applicationP2 ? readBinaryParam(opts.applicationP2) : undefined,
|
|
1128
|
+
coprocessorBinary: opts.coprocessor ? readBinaryParam(opts.coprocessor) : undefined,
|
|
1129
|
+
se01Binary: opts.se01 ? readBinaryParam(opts.se01) : undefined,
|
|
1130
|
+
se02Binary: opts.se02 ? readBinaryParam(opts.se02) : undefined,
|
|
1131
|
+
se03Binary: opts.se03 ? readBinaryParam(opts.se03) : undefined,
|
|
1132
|
+
se04Binary: opts.se04 ? readBinaryParam(opts.se04) : undefined,
|
|
1133
|
+
};
|
|
1134
|
+
const hasPayload = [
|
|
1135
|
+
params.resourceBinary,
|
|
1136
|
+
params.romloaderBinary,
|
|
1137
|
+
params.bootloaderBinary,
|
|
1138
|
+
params.applicationP1Binary,
|
|
1139
|
+
params.applicationP2Binary,
|
|
1140
|
+
params.coprocessorBinary,
|
|
1141
|
+
params.se01Binary,
|
|
1142
|
+
params.se02Binary,
|
|
1143
|
+
params.se03Binary,
|
|
1144
|
+
params.se04Binary,
|
|
1145
|
+
].some(Boolean);
|
|
1146
|
+
if (!hasPayload) {
|
|
1147
|
+
const err = new Error('firmware-update-v4-debug requires at least one binary path');
|
|
1148
|
+
err.code = 'MISSING_FIRMWARE_BINARY';
|
|
1149
|
+
throw err;
|
|
1150
|
+
}
|
|
1151
|
+
return params;
|
|
1152
|
+
}
|
|
869
1153
|
/**
|
|
870
1154
|
* #9 FIX: Safe parseInt with NaN check
|
|
871
1155
|
*/
|
package/dist/sdk.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export interface SDKOptions {
|
|
|
13
13
|
connectId?: string;
|
|
14
14
|
passphraseState?: string;
|
|
15
15
|
useEmptyPassphrase?: boolean;
|
|
16
|
+
debug?: boolean;
|
|
17
|
+
transport?: 'usb' | 'ble';
|
|
16
18
|
}
|
|
17
19
|
export declare function createSDK(opts: SDKOptions): Promise<typeof HardwareSDK>;
|
|
18
20
|
/**
|
package/dist/sdk.js
CHANGED
|
@@ -41,6 +41,7 @@ const readline = __importStar(require("node:readline"));
|
|
|
41
41
|
const hd_common_connect_sdk_1 = __importDefault(require("@onekeyfe/hd-common-connect-sdk"));
|
|
42
42
|
const hd_core_1 = require("@onekeyfe/hd-core");
|
|
43
43
|
const pinentry_1 = require("./pinentry");
|
|
44
|
+
const nobleBlePlugin_1 = require("./transports/nobleBlePlugin");
|
|
44
45
|
/**
|
|
45
46
|
* Current per-invocation CLI options. Event handlers read from this object
|
|
46
47
|
* so that invoking createSDK() with different opts never results in stale
|
|
@@ -182,12 +183,13 @@ function registerEventHandlers(sdk) {
|
|
|
182
183
|
// SDK Factory
|
|
183
184
|
// ---------------------------------------------------------------------------
|
|
184
185
|
async function initSDK() {
|
|
186
|
+
const transport = currentOpts.transport ?? 'usb';
|
|
185
187
|
const settings = {
|
|
186
|
-
debug: false,
|
|
188
|
+
debug: currentOpts.debug ?? false,
|
|
187
189
|
fetchConfig: true,
|
|
188
|
-
env: 'node-usb',
|
|
190
|
+
env: transport === 'ble' ? 'lowlevel' : 'node-usb',
|
|
189
191
|
};
|
|
190
|
-
await hd_common_connect_sdk_1.default.init(settings);
|
|
192
|
+
await hd_common_connect_sdk_1.default.init(settings, undefined, transport === 'ble' ? (0, nobleBlePlugin_1.createNobleBlePlugin)() : undefined);
|
|
191
193
|
// Defensive: strip any stale listeners (e.g. left over from a previous
|
|
192
194
|
// dispose/init cycle in a long-running process) before wiring ours.
|
|
193
195
|
// Mirrors app-monorepo's cleanupHardwareSDKInstance() which removes
|