@onekeyfe/hd-core 1.1.19-alpha.0 → 1.1.19-alpha.1
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/api/BaseMethod.d.ts +5 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +4 -4
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +5 -2
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +6 -4
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/index.d.ts +51 -6
- package/dist/index.js +348 -63
- package/dist/types/device.d.ts +3 -0
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/tracing.d.ts +34 -0
- package/dist/utils/tracing.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +38 -1
- package/src/api/FirmwareUpdateV3.ts +2 -0
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +46 -15
- package/src/api/evm/EVMSignTypedData.ts +8 -2
- package/src/api/firmware/uploadFirmware.ts +51 -15
- package/src/core/index.ts +108 -7
- package/src/data/messages/messages.json +11 -1
- package/src/device/Device.ts +24 -3
- package/src/device/DeviceCommands.ts +42 -8
- package/src/types/device.ts +5 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/tracing.ts +251 -0
package/dist/index.js
CHANGED
|
@@ -787,7 +787,7 @@ const createLogMessage = (type, payload) => ({
|
|
|
787
787
|
|
|
788
788
|
const MAX_ENTRIES = 500;
|
|
789
789
|
let postMessage$1;
|
|
790
|
-
class Log$
|
|
790
|
+
class Log$f {
|
|
791
791
|
constructor(prefix, enabled) {
|
|
792
792
|
this.prefix = prefix;
|
|
793
793
|
this.enabled = enabled;
|
|
@@ -839,7 +839,7 @@ class Log$e {
|
|
|
839
839
|
}
|
|
840
840
|
const _logs = {};
|
|
841
841
|
const initLog = (prefix, enabled) => {
|
|
842
|
-
const instance = new Log$
|
|
842
|
+
const instance = new Log$f(prefix, !!enabled);
|
|
843
843
|
_logs[prefix] = instance;
|
|
844
844
|
return instance;
|
|
845
845
|
};
|
|
@@ -1035,6 +1035,108 @@ function patchFeatures(response) {
|
|
|
1035
1035
|
return response;
|
|
1036
1036
|
}
|
|
1037
1037
|
|
|
1038
|
+
const Log$e = getLogger(exports.LoggerNames.Core);
|
|
1039
|
+
let globalInstanceCounter = 0;
|
|
1040
|
+
let sdkInstanceCounter = 0;
|
|
1041
|
+
function generateSdkInstanceId() {
|
|
1042
|
+
sdkInstanceCounter++;
|
|
1043
|
+
const timestamp = Date.now().toString().slice(-6);
|
|
1044
|
+
return `SDK-${sdkInstanceCounter}-${timestamp}`;
|
|
1045
|
+
}
|
|
1046
|
+
function generateInstanceId(type, sdkInstanceId) {
|
|
1047
|
+
globalInstanceCounter++;
|
|
1048
|
+
const timestamp = Date.now().toString().slice(-6);
|
|
1049
|
+
const baseId = `${type}-${globalInstanceCounter}-${timestamp}`;
|
|
1050
|
+
return sdkInstanceId ? `${sdkInstanceId}.${baseId}` : baseId;
|
|
1051
|
+
}
|
|
1052
|
+
const sdkInstances = new Map();
|
|
1053
|
+
const globalActiveRequests = new Map();
|
|
1054
|
+
function createSdkTracingContext() {
|
|
1055
|
+
const sdkInstanceId = generateSdkInstanceId();
|
|
1056
|
+
const context = {
|
|
1057
|
+
sdkInstanceId,
|
|
1058
|
+
createdAt: Date.now(),
|
|
1059
|
+
activeRequests: new Map(),
|
|
1060
|
+
};
|
|
1061
|
+
sdkInstances.set(sdkInstanceId, context);
|
|
1062
|
+
return context;
|
|
1063
|
+
}
|
|
1064
|
+
function createRequestContext(responseID, methodName, options) {
|
|
1065
|
+
const context = {
|
|
1066
|
+
responseID,
|
|
1067
|
+
sdkInstanceId: options === null || options === void 0 ? void 0 : options.sdkInstanceId,
|
|
1068
|
+
methodName,
|
|
1069
|
+
connectId: options === null || options === void 0 ? void 0 : options.connectId,
|
|
1070
|
+
deviceInstanceId: options === null || options === void 0 ? void 0 : options.deviceInstanceId,
|
|
1071
|
+
commandsInstanceId: options === null || options === void 0 ? void 0 : options.commandsInstanceId,
|
|
1072
|
+
parentResponseID: options === null || options === void 0 ? void 0 : options.parentResponseID,
|
|
1073
|
+
startTime: Date.now(),
|
|
1074
|
+
status: 'pending',
|
|
1075
|
+
};
|
|
1076
|
+
globalActiveRequests.set(context.responseID, context);
|
|
1077
|
+
if (options === null || options === void 0 ? void 0 : options.sdkInstanceId) {
|
|
1078
|
+
const sdkContext = sdkInstances.get(options.sdkInstanceId);
|
|
1079
|
+
if (sdkContext) {
|
|
1080
|
+
sdkContext.activeRequests.set(context.responseID, context);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
return context;
|
|
1084
|
+
}
|
|
1085
|
+
function updateRequestContext(responseID, updates) {
|
|
1086
|
+
const context = globalActiveRequests.get(responseID);
|
|
1087
|
+
if (context) {
|
|
1088
|
+
Object.assign(context, updates);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
function completeRequestContext(responseID, error) {
|
|
1092
|
+
const context = globalActiveRequests.get(responseID);
|
|
1093
|
+
if (context) {
|
|
1094
|
+
context.endTime = Date.now();
|
|
1095
|
+
context.status = error ? 'error' : 'success';
|
|
1096
|
+
if (error) {
|
|
1097
|
+
context.error = error.message;
|
|
1098
|
+
Log$e.error(`[RequestContext] [completeRequestContext] Error: ${formatRequestContext(context)}`);
|
|
1099
|
+
}
|
|
1100
|
+
globalActiveRequests.delete(responseID);
|
|
1101
|
+
if (context.sdkInstanceId) {
|
|
1102
|
+
const sdkContext = sdkInstances.get(context.sdkInstanceId);
|
|
1103
|
+
if (sdkContext) {
|
|
1104
|
+
sdkContext.activeRequests.delete(responseID);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
function getActiveRequestsByDeviceInstance(deviceInstanceId) {
|
|
1110
|
+
return Array.from(globalActiveRequests.values()).filter(ctx => ctx.deviceInstanceId === deviceInstanceId);
|
|
1111
|
+
}
|
|
1112
|
+
function formatRequestContext(context) {
|
|
1113
|
+
const duration = context.endTime
|
|
1114
|
+
? context.endTime - context.startTime
|
|
1115
|
+
: Date.now() - context.startTime;
|
|
1116
|
+
const parts = [
|
|
1117
|
+
`[req:${context.responseID}]`,
|
|
1118
|
+
context.sdkInstanceId ? `sdk=${context.sdkInstanceId}` : null,
|
|
1119
|
+
`method=${context.methodName}`,
|
|
1120
|
+
context.connectId ? `connectId=${context.connectId}` : null,
|
|
1121
|
+
context.deviceInstanceId ? `deviceInst=${context.deviceInstanceId}` : null,
|
|
1122
|
+
context.commandsInstanceId ? `commandsInst=${context.commandsInstanceId}` : null,
|
|
1123
|
+
context.parentResponseID ? `parent=${context.parentResponseID}` : null,
|
|
1124
|
+
`duration=${duration}ms`,
|
|
1125
|
+
`status=${context.status}`,
|
|
1126
|
+
`error=${context.error}`,
|
|
1127
|
+
].filter(Boolean);
|
|
1128
|
+
return parts.join(' ');
|
|
1129
|
+
}
|
|
1130
|
+
function cleanupSdkInstance(sdkInstanceId) {
|
|
1131
|
+
const sdkContext = sdkInstances.get(sdkInstanceId);
|
|
1132
|
+
if (sdkContext) {
|
|
1133
|
+
for (const responseID of sdkContext.activeRequests.keys()) {
|
|
1134
|
+
globalActiveRequests.delete(responseID);
|
|
1135
|
+
}
|
|
1136
|
+
sdkInstances.delete(sdkInstanceId);
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1038
1140
|
exports.EOneKeyDeviceMode = void 0;
|
|
1039
1141
|
(function (EOneKeyDeviceMode) {
|
|
1040
1142
|
EOneKeyDeviceMode["bootloader"] = "bootloader";
|
|
@@ -3351,6 +3453,15 @@ var nested$1 = {
|
|
|
3351
3453
|
}
|
|
3352
3454
|
}
|
|
3353
3455
|
},
|
|
3456
|
+
UpgradeFileHeader: {
|
|
3457
|
+
fields: {
|
|
3458
|
+
data: {
|
|
3459
|
+
rule: "required",
|
|
3460
|
+
type: "bytes",
|
|
3461
|
+
id: 1
|
|
3462
|
+
}
|
|
3463
|
+
}
|
|
3464
|
+
},
|
|
3354
3465
|
CardanoDerivationType: {
|
|
3355
3466
|
values: {
|
|
3356
3467
|
LEDGER: 0,
|
|
@@ -13795,7 +13906,8 @@ var nested$1 = {
|
|
|
13795
13906
|
MessageType_GetPassphraseState: 10028,
|
|
13796
13907
|
MessageType_PassphraseState: 10029,
|
|
13797
13908
|
MessageType_UnLockDevice: 10030,
|
|
13798
|
-
MessageType_UnLockDeviceResponse: 10031
|
|
13909
|
+
MessageType_UnLockDeviceResponse: 10031,
|
|
13910
|
+
MessageType_UpgradeFileHeader: 10050
|
|
13799
13911
|
}
|
|
13800
13912
|
},
|
|
13801
13913
|
google: {
|
|
@@ -26556,12 +26668,15 @@ const cancelDeviceWithInitialize = (device) => {
|
|
|
26556
26668
|
}));
|
|
26557
26669
|
};
|
|
26558
26670
|
const Log$b = getLogger(exports.LoggerNames.DeviceCommands);
|
|
26671
|
+
const LogCore = getLogger(exports.LoggerNames.Core);
|
|
26559
26672
|
class DeviceCommands {
|
|
26560
26673
|
constructor(device, mainId) {
|
|
26561
26674
|
this.device = device;
|
|
26562
26675
|
this.mainId = mainId;
|
|
26563
26676
|
this.transport = TransportManager.getTransport();
|
|
26564
26677
|
this.disposed = false;
|
|
26678
|
+
this.instanceId = generateInstanceId('DeviceCommands', device.sdkInstanceId);
|
|
26679
|
+
Log$b.debug(`[DeviceCommands] Created: ${this.instanceId}, device: ${this.device.instanceId}`);
|
|
26565
26680
|
}
|
|
26566
26681
|
dispose(_cancelRequest) {
|
|
26567
26682
|
var _a, _b;
|
|
@@ -26634,11 +26749,11 @@ class DeviceCommands {
|
|
|
26634
26749
|
const promise = this.transport.call(this.mainId, type, msg);
|
|
26635
26750
|
this.callPromise = promise;
|
|
26636
26751
|
const res = yield promise;
|
|
26637
|
-
|
|
26752
|
+
LogCore.debug('[DeviceCommands] [call] Received', res.type);
|
|
26638
26753
|
return res;
|
|
26639
26754
|
}
|
|
26640
26755
|
catch (error) {
|
|
26641
|
-
|
|
26756
|
+
LogCore.debug('[DeviceCommands] [call] Received error', error);
|
|
26642
26757
|
if (error.errorCode === hdShared.HardwareErrorCode.BleDeviceBondError) {
|
|
26643
26758
|
return {
|
|
26644
26759
|
type: 'BleDeviceBondError',
|
|
@@ -26837,7 +26952,7 @@ class DeviceCommands {
|
|
|
26837
26952
|
return new Promise((resolve, reject) => {
|
|
26838
26953
|
const cancelAndReject = (_error) => cancelDeviceInPrompt(this.device, false)
|
|
26839
26954
|
.then(onCancel => {
|
|
26840
|
-
const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.
|
|
26955
|
+
const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled, `${DEVICE.PIN} canceled`);
|
|
26841
26956
|
if (onCancel) {
|
|
26842
26957
|
const { payload } = onCancel || {};
|
|
26843
26958
|
reject(error || new Error(payload === null || payload === void 0 ? void 0 : payload.message));
|
|
@@ -26849,7 +26964,13 @@ class DeviceCommands {
|
|
|
26849
26964
|
.catch(error => {
|
|
26850
26965
|
reject(error);
|
|
26851
26966
|
});
|
|
26852
|
-
|
|
26967
|
+
const listenerCount = this.device.listenerCount(DEVICE.PIN);
|
|
26968
|
+
Log$b.debug(`[${this.instanceId}] _promptPin called`, {
|
|
26969
|
+
responseID: this.currentResponseID,
|
|
26970
|
+
deviceInstanceId: this.device.instanceId,
|
|
26971
|
+
listenerCount,
|
|
26972
|
+
});
|
|
26973
|
+
if (listenerCount > 0) {
|
|
26853
26974
|
this.device.setCancelableAction(cancelAndReject);
|
|
26854
26975
|
this.device.emit(DEVICE.PIN, this.device, type, (err, pin) => {
|
|
26855
26976
|
this.device.clearCancelableAction();
|
|
@@ -26862,8 +26983,16 @@ class DeviceCommands {
|
|
|
26862
26983
|
});
|
|
26863
26984
|
}
|
|
26864
26985
|
else {
|
|
26865
|
-
|
|
26866
|
-
|
|
26986
|
+
const activeRequests = getActiveRequestsByDeviceInstance(this.device.instanceId);
|
|
26987
|
+
const errorInfo = {
|
|
26988
|
+
commandsInstanceId: this.instanceId,
|
|
26989
|
+
deviceInstanceId: this.device.instanceId,
|
|
26990
|
+
currentResponseID: this.currentResponseID,
|
|
26991
|
+
listenerCount,
|
|
26992
|
+
activeRequests: activeRequests.map(formatRequestContext),
|
|
26993
|
+
};
|
|
26994
|
+
LogCore.error('[DeviceCommands] [call] PIN callback not configured, cancelling request', Object.assign({}, errorInfo));
|
|
26995
|
+
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `_promptPin: PIN callback not configured: ${JSON.stringify(errorInfo)}`));
|
|
26867
26996
|
}
|
|
26868
26997
|
});
|
|
26869
26998
|
}
|
|
@@ -26871,7 +27000,7 @@ class DeviceCommands {
|
|
|
26871
27000
|
return new Promise((resolve, reject) => {
|
|
26872
27001
|
const cancelAndReject = (_error) => cancelDeviceInPrompt(this.device, false)
|
|
26873
27002
|
.then(onCancel => {
|
|
26874
|
-
const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.
|
|
27003
|
+
const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled, `${DEVICE.PASSPHRASE} canceled`);
|
|
26875
27004
|
if (onCancel) {
|
|
26876
27005
|
const { payload } = onCancel || {};
|
|
26877
27006
|
reject(error || new Error(payload === null || payload === void 0 ? void 0 : payload.message));
|
|
@@ -26896,7 +27025,7 @@ class DeviceCommands {
|
|
|
26896
27025
|
});
|
|
26897
27026
|
}
|
|
26898
27027
|
else {
|
|
26899
|
-
|
|
27028
|
+
LogCore.error('[DeviceCommands] [call] Passphrase callback not configured, cancelling request');
|
|
26900
27029
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, '_promptPassphrase: Passphrase callback not configured'));
|
|
26901
27030
|
}
|
|
26902
27031
|
});
|
|
@@ -26911,7 +27040,7 @@ const parseRunOptions = (options) => {
|
|
|
26911
27040
|
const Log$a = getLogger(exports.LoggerNames.Device);
|
|
26912
27041
|
const deviceSessionCache = {};
|
|
26913
27042
|
class Device extends events.exports {
|
|
26914
|
-
constructor(descriptor) {
|
|
27043
|
+
constructor(descriptor, sdkInstanceId) {
|
|
26915
27044
|
super();
|
|
26916
27045
|
this.deviceConnector = null;
|
|
26917
27046
|
this.deviceAcquired = false;
|
|
@@ -26925,10 +27054,14 @@ class Device extends events.exports {
|
|
|
26925
27054
|
this.keepSession = false;
|
|
26926
27055
|
this.passphraseState = undefined;
|
|
26927
27056
|
this.originalDescriptor = descriptor;
|
|
27057
|
+
this.sdkInstanceId = sdkInstanceId;
|
|
27058
|
+
this.instanceId = generateInstanceId('Device', this.sdkInstanceId);
|
|
27059
|
+
this.createdAt = Date.now();
|
|
27060
|
+
Log$a.debug(`[Device] Created: ${this.instanceId}${this.sdkInstanceId ? ` for SDK: ${this.sdkInstanceId}` : ''}`);
|
|
26928
27061
|
}
|
|
26929
|
-
static fromDescriptor(originalDescriptor) {
|
|
27062
|
+
static fromDescriptor(originalDescriptor, sdkInstanceId) {
|
|
26930
27063
|
const descriptor = Object.assign({}, originalDescriptor);
|
|
26931
|
-
return new Device(descriptor);
|
|
27064
|
+
return new Device(descriptor, sdkInstanceId);
|
|
26932
27065
|
}
|
|
26933
27066
|
toMessageObject() {
|
|
26934
27067
|
if (this.isUnacquired() || !this.features)
|
|
@@ -26940,6 +27073,9 @@ class Device extends events.exports {
|
|
|
26940
27073
|
return {
|
|
26941
27074
|
connectId: DataManager.isBleConnect(env) ? this.mainId || null : getDeviceUUID(this.features),
|
|
26942
27075
|
uuid: getDeviceUUID(this.features),
|
|
27076
|
+
sdkInstanceId: this.sdkInstanceId,
|
|
27077
|
+
instanceId: this.instanceId,
|
|
27078
|
+
createdAt: this.createdAt,
|
|
26943
27079
|
deviceType,
|
|
26944
27080
|
deviceId: this.features.device_id || null,
|
|
26945
27081
|
path: this.originalDescriptor.path,
|
|
@@ -27593,8 +27729,30 @@ class BaseMethod {
|
|
|
27593
27729
|
getVersionRange() {
|
|
27594
27730
|
return {};
|
|
27595
27731
|
}
|
|
27732
|
+
setContext(context) {
|
|
27733
|
+
this.sdkInstanceId = context.sdkInstanceId;
|
|
27734
|
+
this.instanceId = generateInstanceId('Method', this.sdkInstanceId);
|
|
27735
|
+
Log$9.debug(`[BaseMethod] Created: ${this.instanceId}, method: ${this.name}, SDK: ${this.sdkInstanceId}`);
|
|
27736
|
+
}
|
|
27596
27737
|
setDevice(device) {
|
|
27738
|
+
var _a, _b;
|
|
27597
27739
|
this.device = device;
|
|
27740
|
+
if (!device.sdkInstanceId && this.sdkInstanceId) {
|
|
27741
|
+
device.sdkInstanceId = this.sdkInstanceId;
|
|
27742
|
+
device.instanceId = generateInstanceId('Device', this.sdkInstanceId);
|
|
27743
|
+
}
|
|
27744
|
+
if (this.requestContext) {
|
|
27745
|
+
this.requestContext.deviceInstanceId = device.instanceId;
|
|
27746
|
+
this.requestContext.commandsInstanceId = (_a = device.commands) === null || _a === void 0 ? void 0 : _a.instanceId;
|
|
27747
|
+
this.requestContext.sdkInstanceId = this.sdkInstanceId;
|
|
27748
|
+
}
|
|
27749
|
+
if (device.commands && this.sdkInstanceId) {
|
|
27750
|
+
device.commands.instanceId = generateInstanceId('DeviceCommands', this.sdkInstanceId);
|
|
27751
|
+
}
|
|
27752
|
+
if (device.commands) {
|
|
27753
|
+
device.commands.currentResponseID = this.responseID;
|
|
27754
|
+
}
|
|
27755
|
+
Log$9.debug(`[${this.instanceId}] setDevice: ${device.instanceId}, commands: ${(_b = device.commands) === null || _b === void 0 ? void 0 : _b.instanceId}`);
|
|
27598
27756
|
}
|
|
27599
27757
|
checkFirmwareRelease() {
|
|
27600
27758
|
if (!this.device || !this.device.features)
|
|
@@ -28748,11 +28906,34 @@ const waitBleInstall = (updateType) => __awaiter(void 0, void 0, void 0, functio
|
|
|
28748
28906
|
}
|
|
28749
28907
|
});
|
|
28750
28908
|
const uploadFirmware = (updateType, typedCall, postMessage, device, { payload, rebootOnSuccess, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28909
|
+
var _a, _b;
|
|
28751
28910
|
const deviceType = getDeviceType(device.features);
|
|
28752
28911
|
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
|
|
28753
28912
|
postConfirmationMessage(device);
|
|
28754
28913
|
postProgressTip(device, 'ConfirmOnDevice', postMessage);
|
|
28755
|
-
const
|
|
28914
|
+
const isFirmware = updateType === 'firmware';
|
|
28915
|
+
const deviceBootloaderVersion = getDeviceBootloaderVersion(device.features).join('.');
|
|
28916
|
+
const supportUpgradeFileHeader = semver__default["default"].gt(deviceBootloaderVersion, '2.1.0');
|
|
28917
|
+
Log$8.debug('supportUpgradeFileHeader:', supportUpgradeFileHeader, 'deviceBootloaderVersion:', deviceBootloaderVersion);
|
|
28918
|
+
if (isFirmware && supportUpgradeFileHeader) {
|
|
28919
|
+
const HEADER_SIZE = 1024;
|
|
28920
|
+
if (payload.byteLength < HEADER_SIZE) {
|
|
28921
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `firmware payload too small: ${payload.byteLength} bytes, expected at least ${HEADER_SIZE} bytes`);
|
|
28922
|
+
}
|
|
28923
|
+
Log$8.debug('Uploading firmware header:', { size: HEADER_SIZE, totalSize: payload.byteLength });
|
|
28924
|
+
postProgressTip(device, 'UploadingFirmwareHeader', postMessage);
|
|
28925
|
+
const header = new Uint8Array(payload.slice(0, HEADER_SIZE));
|
|
28926
|
+
const headerRes = (yield typedCall('UpgradeFileHeader', 'Success', {
|
|
28927
|
+
data: bytesToHex(header),
|
|
28928
|
+
}));
|
|
28929
|
+
const isUnexpectedMessage = (_b = (_a = headerRes.message) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.includes('Failure_UnexpectedMessage');
|
|
28930
|
+
if (headerRes.type !== 'Success' && !isUnexpectedMessage) {
|
|
28931
|
+
Log$8.error('Firmware header upload failed:', headerRes);
|
|
28932
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'failed to upload firmware header');
|
|
28933
|
+
}
|
|
28934
|
+
Log$8.debug('Firmware header uploaded successfully, isUnexpectedMessage:', isUnexpectedMessage);
|
|
28935
|
+
}
|
|
28936
|
+
const eraseCommand = isFirmware ? 'FirmwareErase' : 'FirmwareErase_ex';
|
|
28756
28937
|
const eraseRes = yield typedCall(eraseCommand, 'Success', {});
|
|
28757
28938
|
if (eraseRes.type !== 'Success') {
|
|
28758
28939
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'erase firmware error');
|
|
@@ -28805,7 +28986,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload, r
|
|
|
28805
28986
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown device model');
|
|
28806
28987
|
});
|
|
28807
28988
|
const newTouchUpdateProcess = (updateType, postMessage, device, { payload }, rebootOnSuccess = true) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28808
|
-
var
|
|
28989
|
+
var _c, _d, _e, _f, _g;
|
|
28809
28990
|
let typedCall = device.getCommands().typedCall.bind(device.getCommands());
|
|
28810
28991
|
postProgressTip(device, 'StartTransferData', postMessage);
|
|
28811
28992
|
const filePath = `0:${updateType === 'ble' ? 'ble-' : ''}firmware.bin`;
|
|
@@ -28849,7 +29030,7 @@ const newTouchUpdateProcess = (updateType, postMessage, device, { payload }, reb
|
|
|
28849
29030
|
}
|
|
28850
29031
|
}
|
|
28851
29032
|
if (response.type === 'Success' &&
|
|
28852
|
-
((
|
|
29033
|
+
((_c = response === null || response === void 0 ? void 0 : response.message) === null || _c === void 0 ? void 0 : _c.message) === FIRMWARE_UPDATE_CONFIRM$1) {
|
|
28853
29034
|
const timeout = 2 * 60 * 1000;
|
|
28854
29035
|
const startTime = Date.now();
|
|
28855
29036
|
const isBleReconnect = DataManager.isBleConnect(env);
|
|
@@ -28857,7 +29038,7 @@ const newTouchUpdateProcess = (updateType, postMessage, device, { payload }, reb
|
|
|
28857
29038
|
try {
|
|
28858
29039
|
if (isBleReconnect) {
|
|
28859
29040
|
try {
|
|
28860
|
-
yield ((
|
|
29041
|
+
yield ((_d = device.deviceConnector) === null || _d === void 0 ? void 0 : _d.acquire(device.originalDescriptor.id, null, true));
|
|
28861
29042
|
const typedCall = device.getCommands().typedCall.bind(device.getCommands());
|
|
28862
29043
|
yield Promise.race([
|
|
28863
29044
|
typedCall('Initialize', 'Features', {}),
|
|
@@ -28873,14 +29054,14 @@ const newTouchUpdateProcess = (updateType, postMessage, device, { payload }, reb
|
|
|
28873
29054
|
}
|
|
28874
29055
|
}
|
|
28875
29056
|
else {
|
|
28876
|
-
const deviceDiff = yield ((
|
|
28877
|
-
const devicesDescriptor = (
|
|
29057
|
+
const deviceDiff = yield ((_e = device.deviceConnector) === null || _e === void 0 ? void 0 : _e.enumerate());
|
|
29058
|
+
const devicesDescriptor = (_f = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _f !== void 0 ? _f : [];
|
|
28878
29059
|
const { deviceList } = yield DevicePool.getDevices(devicesDescriptor, device.originalDescriptor.id);
|
|
28879
29060
|
if (deviceList.length === 1) {
|
|
28880
29061
|
device.updateFromCache(deviceList[0]);
|
|
28881
29062
|
yield device.acquire();
|
|
28882
29063
|
device.commands.disposed = false;
|
|
28883
|
-
device.getCommands().mainId = (
|
|
29064
|
+
device.getCommands().mainId = (_g = device.mainId) !== null && _g !== void 0 ? _g : '';
|
|
28884
29065
|
}
|
|
28885
29066
|
}
|
|
28886
29067
|
const typedCall = device.getCommands().typedCall.bind(device.getCommands());
|
|
@@ -28898,9 +29079,9 @@ const newTouchUpdateProcess = (updateType, postMessage, device, { payload }, reb
|
|
|
28898
29079
|
return response;
|
|
28899
29080
|
});
|
|
28900
29081
|
const emmcFileWriteWithRetry = (device, filePath, chunkLength, offset, chunk, overwrite, progress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28901
|
-
var
|
|
29082
|
+
var _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
28902
29083
|
const writeFunc = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
28903
|
-
var
|
|
29084
|
+
var _s;
|
|
28904
29085
|
const typedCall = device.getCommands().typedCall.bind(device.getCommands());
|
|
28905
29086
|
const writeRes = yield typedCall('EmmcFileWrite', 'EmmcFile', {
|
|
28906
29087
|
file: {
|
|
@@ -28915,7 +29096,7 @@ const emmcFileWriteWithRetry = (device, filePath, chunkLength, offset, chunk, ov
|
|
|
28915
29096
|
});
|
|
28916
29097
|
if (writeRes.type !== 'EmmcFile') {
|
|
28917
29098
|
if (writeRes.type === 'CallMethodError') {
|
|
28918
|
-
if (((
|
|
29099
|
+
if (((_s = writeRes.message.error) !== null && _s !== void 0 ? _s : '').indexOf(SESSION_ERROR$1) > -1) {
|
|
28919
29100
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, SESSION_ERROR$1);
|
|
28920
29101
|
}
|
|
28921
29102
|
}
|
|
@@ -28938,18 +29119,18 @@ const emmcFileWriteWithRetry = (device, filePath, chunkLength, offset, chunk, ov
|
|
|
28938
29119
|
const env = DataManager.getSettings('env');
|
|
28939
29120
|
if (DataManager.isBleConnect(env)) {
|
|
28940
29121
|
yield wait(3000);
|
|
28941
|
-
yield ((
|
|
29122
|
+
yield ((_h = device.deviceConnector) === null || _h === void 0 ? void 0 : _h.acquire(device.originalDescriptor.id, null, true));
|
|
28942
29123
|
yield device.initialize();
|
|
28943
29124
|
}
|
|
28944
|
-
else if (((
|
|
28945
|
-
((
|
|
28946
|
-
const deviceDiff = yield ((
|
|
28947
|
-
const devicesDescriptor = (
|
|
29125
|
+
else if (((_j = error === null || error === void 0 ? void 0 : error.message) === null || _j === void 0 ? void 0 : _j.indexOf(SESSION_ERROR$1)) > -1 ||
|
|
29126
|
+
((_l = (_k = error === null || error === void 0 ? void 0 : error.response) === null || _k === void 0 ? void 0 : _k.data) === null || _l === void 0 ? void 0 : _l.indexOf(SESSION_ERROR$1)) > -1) {
|
|
29127
|
+
const deviceDiff = yield ((_m = device.deviceConnector) === null || _m === void 0 ? void 0 : _m.enumerate());
|
|
29128
|
+
const devicesDescriptor = (_o = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _o !== void 0 ? _o : [];
|
|
28948
29129
|
const { deviceList } = yield DevicePool.getDevices(devicesDescriptor, undefined);
|
|
28949
|
-
if (deviceList.length === 1 && ((
|
|
29130
|
+
if (deviceList.length === 1 && ((_q = (_p = deviceList[0]) === null || _p === void 0 ? void 0 : _p.features) === null || _q === void 0 ? void 0 : _q.bootloader_mode)) {
|
|
28950
29131
|
device.updateFromCache(deviceList[0]);
|
|
28951
29132
|
yield device.acquire();
|
|
28952
|
-
device.getCommands().mainId = (
|
|
29133
|
+
device.getCommands().mainId = (_r = device.mainId) !== null && _r !== void 0 ? _r : '';
|
|
28953
29134
|
}
|
|
28954
29135
|
}
|
|
28955
29136
|
yield wait(3000);
|
|
@@ -30178,6 +30359,7 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
30178
30359
|
if (error === null || error === void 0 ? void 0 : error.errorCode) {
|
|
30179
30360
|
const unexpectedError = [
|
|
30180
30361
|
hdShared.HardwareErrorCode.ActionCancelled,
|
|
30362
|
+
hdShared.HardwareErrorCode.CallQueueActionCancelled,
|
|
30181
30363
|
hdShared.HardwareErrorCode.FirmwareVerificationFailed,
|
|
30182
30364
|
hdShared.HardwareErrorCode.BleDeviceNotBonded,
|
|
30183
30365
|
hdShared.HardwareErrorCode.BleServiceNotFound,
|
|
@@ -30624,7 +30806,7 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
30624
30806
|
};
|
|
30625
30807
|
}
|
|
30626
30808
|
callMethod(methodName, params, rootFingerprint) {
|
|
30627
|
-
var _a;
|
|
30809
|
+
var _a, _b, _c;
|
|
30628
30810
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30629
30811
|
const method = findMethod({
|
|
30630
30812
|
event: IFRAME.CALL,
|
|
@@ -30633,25 +30815,38 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
30633
30815
|
});
|
|
30634
30816
|
method.connector = this.connector;
|
|
30635
30817
|
method.postMessage = this.postMessage;
|
|
30818
|
+
if (this.context) {
|
|
30819
|
+
(_a = method.setContext) === null || _a === void 0 ? void 0 : _a.call(method, this.context);
|
|
30820
|
+
}
|
|
30821
|
+
method.requestContext = createRequestContext(method.responseID, methodName, {
|
|
30822
|
+
sdkInstanceId: this.sdkInstanceId,
|
|
30823
|
+
connectId: this.payload.connectId,
|
|
30824
|
+
parentResponseID: this.responseID,
|
|
30825
|
+
});
|
|
30826
|
+
const onSignalAbort = () => {
|
|
30827
|
+
var _a;
|
|
30828
|
+
(_a = this.abortController) === null || _a === void 0 ? void 0 : _a.abort(hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.RepeatUnlocking]);
|
|
30829
|
+
};
|
|
30830
|
+
const buttonListener = (...[device, request]) => {
|
|
30831
|
+
if (request.code === 'ButtonRequest_PinEntry' || request.code === 'ButtonRequest_AttachPin') {
|
|
30832
|
+
onSignalAbort();
|
|
30833
|
+
}
|
|
30834
|
+
else {
|
|
30835
|
+
onDeviceButtonHandler(device, request);
|
|
30836
|
+
}
|
|
30837
|
+
};
|
|
30636
30838
|
let result;
|
|
30637
30839
|
try {
|
|
30638
30840
|
method.init();
|
|
30639
|
-
(
|
|
30841
|
+
(_b = method.setDevice) === null || _b === void 0 ? void 0 : _b.call(method, this.device);
|
|
30640
30842
|
method.context = this.context;
|
|
30641
|
-
|
|
30642
|
-
|
|
30643
|
-
|
|
30644
|
-
|
|
30645
|
-
|
|
30646
|
-
|
|
30647
|
-
|
|
30648
|
-
onSignalAbort();
|
|
30649
|
-
}
|
|
30650
|
-
else {
|
|
30651
|
-
onDeviceButtonHandler(device, request);
|
|
30652
|
-
}
|
|
30653
|
-
};
|
|
30654
|
-
this.device.on(DEVICE.BUTTON, _onDeviceButtonHandler);
|
|
30843
|
+
if (method.requestContext && this.device) {
|
|
30844
|
+
updateRequestContext(method.requestContext.responseID, {
|
|
30845
|
+
deviceInstanceId: this.device.instanceId,
|
|
30846
|
+
commandsInstanceId: (_c = this.device.commands) === null || _c === void 0 ? void 0 : _c.instanceId,
|
|
30847
|
+
});
|
|
30848
|
+
}
|
|
30849
|
+
this.device.on(DEVICE.BUTTON, buttonListener);
|
|
30655
30850
|
this.device.on(DEVICE.PIN, onSignalAbort);
|
|
30656
30851
|
this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
|
|
30657
30852
|
preCheckDeviceSupport(this.device, method);
|
|
@@ -30660,6 +30855,9 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
30660
30855
|
throw new Error('No response');
|
|
30661
30856
|
}
|
|
30662
30857
|
result = response.map((item, index) => (Object.assign(Object.assign({}, params.bundle[index]._originRequestParams), { success: true, payload: Object.assign(Object.assign({}, item), { rootFingerprint }) })));
|
|
30858
|
+
if (method.requestContext) {
|
|
30859
|
+
completeRequestContext(method.requestContext.responseID);
|
|
30860
|
+
}
|
|
30663
30861
|
}
|
|
30664
30862
|
catch (e) {
|
|
30665
30863
|
const error = handleSkippableHardwareError(e, this.device, method);
|
|
@@ -30675,6 +30873,14 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
30675
30873
|
else {
|
|
30676
30874
|
throw e;
|
|
30677
30875
|
}
|
|
30876
|
+
if (method.requestContext) {
|
|
30877
|
+
completeRequestContext(method.requestContext.responseID, e instanceof Error ? e : new Error(String(e)));
|
|
30878
|
+
}
|
|
30879
|
+
}
|
|
30880
|
+
finally {
|
|
30881
|
+
this.device.off(DEVICE.BUTTON, buttonListener);
|
|
30882
|
+
this.device.off(DEVICE.PIN, onSignalAbort);
|
|
30883
|
+
this.device.off(DEVICE.PASSPHRASE, onSignalAbort);
|
|
30678
30884
|
}
|
|
30679
30885
|
return result;
|
|
30680
30886
|
});
|
|
@@ -33159,8 +33365,12 @@ class EVMSignTypedData extends BaseMethod {
|
|
|
33159
33365
|
return false;
|
|
33160
33366
|
let biggerLimit = 1024;
|
|
33161
33367
|
const currentVersion = getDeviceFirmwareVersion(this.device.features).join('.');
|
|
33368
|
+
const currentDeviceType = getDeviceType(this.device.features);
|
|
33162
33369
|
const supportBiggerDataVersion = '4.4.0';
|
|
33163
|
-
|
|
33370
|
+
const supportBiggerData = DeviceModelToTypes.model_classic1s.includes(currentDeviceType) ||
|
|
33371
|
+
(DeviceModelToTypes.model_touch.includes(currentDeviceType) &&
|
|
33372
|
+
semver__default["default"].gte(currentVersion, supportBiggerDataVersion));
|
|
33373
|
+
if (supportBiggerData) {
|
|
33164
33374
|
biggerLimit = 1536;
|
|
33165
33375
|
}
|
|
33166
33376
|
const startIndex = data.startsWith('0x') ? 2 : 0;
|
|
@@ -39342,7 +39552,33 @@ const pollingState = {};
|
|
|
39342
39552
|
let preConnectCache = {
|
|
39343
39553
|
passphraseState: undefined,
|
|
39344
39554
|
};
|
|
39555
|
+
const toError = (error) => {
|
|
39556
|
+
if (error instanceof Error)
|
|
39557
|
+
return error;
|
|
39558
|
+
if (error == null)
|
|
39559
|
+
return undefined;
|
|
39560
|
+
if (typeof error === 'string')
|
|
39561
|
+
return new Error(error);
|
|
39562
|
+
try {
|
|
39563
|
+
return new Error(JSON.stringify(error));
|
|
39564
|
+
}
|
|
39565
|
+
catch (_a) {
|
|
39566
|
+
return new Error(String(error));
|
|
39567
|
+
}
|
|
39568
|
+
};
|
|
39569
|
+
const updateMethodRequestContext = (method, updates) => {
|
|
39570
|
+
if (method.requestContext) {
|
|
39571
|
+
updateRequestContext(method.requestContext.responseID, updates);
|
|
39572
|
+
}
|
|
39573
|
+
};
|
|
39574
|
+
const completeMethodRequestContext = (method, error) => {
|
|
39575
|
+
if (!method.requestContext) {
|
|
39576
|
+
return;
|
|
39577
|
+
}
|
|
39578
|
+
completeRequestContext(method.requestContext.responseID, toError(error));
|
|
39579
|
+
};
|
|
39345
39580
|
const callAPI = (context, message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39581
|
+
var _a;
|
|
39346
39582
|
if (!message.id || !message.payload || message.type !== IFRAME.CALL) {
|
|
39347
39583
|
return Promise.reject(hdShared.ERRORS.TypedError('on call: message.id or message.payload is missing'));
|
|
39348
39584
|
}
|
|
@@ -39351,6 +39587,12 @@ const callAPI = (context, message) => __awaiter(void 0, void 0, void 0, function
|
|
|
39351
39587
|
method = findMethod(message);
|
|
39352
39588
|
method.connector = _connector;
|
|
39353
39589
|
method.postMessage = postMessage;
|
|
39590
|
+
(_a = method.setContext) === null || _a === void 0 ? void 0 : _a.call(method, context);
|
|
39591
|
+
method.requestContext = createRequestContext(method.responseID, method.name, {
|
|
39592
|
+
sdkInstanceId: context.sdkInstanceId,
|
|
39593
|
+
connectId: method.connectId,
|
|
39594
|
+
});
|
|
39595
|
+
Log.debug(`[${context.sdkInstanceId}] callAPI: ${formatRequestContext(method.requestContext)}`);
|
|
39354
39596
|
method.init();
|
|
39355
39597
|
}
|
|
39356
39598
|
catch (error) {
|
|
@@ -39358,11 +39600,14 @@ const callAPI = (context, message) => __awaiter(void 0, void 0, void 0, function
|
|
|
39358
39600
|
}
|
|
39359
39601
|
DevicePool.emitter.on(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
39360
39602
|
if (!method.useDevice) {
|
|
39603
|
+
updateMethodRequestContext(method, { status: 'running' });
|
|
39361
39604
|
try {
|
|
39362
39605
|
const response = yield method.run();
|
|
39606
|
+
completeMethodRequestContext(method);
|
|
39363
39607
|
return createResponseMessage(method.responseID, true, response);
|
|
39364
39608
|
}
|
|
39365
39609
|
catch (error) {
|
|
39610
|
+
completeMethodRequestContext(method, error);
|
|
39366
39611
|
return createResponseMessage(method.responseID, false, { error });
|
|
39367
39612
|
}
|
|
39368
39613
|
}
|
|
@@ -39402,9 +39647,10 @@ const waitForPendingPromise = (getPrePendingCallPromise, removePrePendingCallPro
|
|
|
39402
39647
|
}
|
|
39403
39648
|
});
|
|
39404
39649
|
const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39405
|
-
var
|
|
39650
|
+
var _b, _c, _d;
|
|
39406
39651
|
let messageResponse;
|
|
39407
39652
|
const { requestQueue, getPrePendingCallPromise, setPrePendingCallPromise } = context;
|
|
39653
|
+
updateMethodRequestContext(method, { status: 'running' });
|
|
39408
39654
|
const connectStateChange = preConnectCache.passphraseState !== method.payload.passphraseState;
|
|
39409
39655
|
preConnectCache = {
|
|
39410
39656
|
passphraseState: method.payload.passphraseState,
|
|
@@ -39424,10 +39670,11 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
39424
39670
|
pollingState[pollingId] = false;
|
|
39425
39671
|
}
|
|
39426
39672
|
pollingId += 1;
|
|
39427
|
-
device = yield ensureConnected(context, method, pollingId, (
|
|
39673
|
+
device = yield ensureConnected(context, method, pollingId, (_b = task.abortController) === null || _b === void 0 ? void 0 : _b.signal);
|
|
39428
39674
|
}
|
|
39429
39675
|
catch (e) {
|
|
39430
39676
|
console.log('ensureConnected error: ', e);
|
|
39677
|
+
completeMethodRequestContext(method, e);
|
|
39431
39678
|
if (e.name === 'AbortError' || e.message === 'Request aborted') {
|
|
39432
39679
|
requestQueue.releaseTask(method.responseID);
|
|
39433
39680
|
return createResponseMessage(method.responseID, false, {
|
|
@@ -39438,8 +39685,16 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
39438
39685
|
return createResponseMessage(method.responseID, false, { error: e });
|
|
39439
39686
|
}
|
|
39440
39687
|
Log.debug('Call API - setDevice: ', device.mainId);
|
|
39441
|
-
(
|
|
39688
|
+
(_c = method.setDevice) === null || _c === void 0 ? void 0 : _c.call(method, device);
|
|
39442
39689
|
method.context = context;
|
|
39690
|
+
updateMethodRequestContext(method, {
|
|
39691
|
+
deviceInstanceId: device.instanceId,
|
|
39692
|
+
commandsInstanceId: (_d = device.commands) === null || _d === void 0 ? void 0 : _d.instanceId,
|
|
39693
|
+
});
|
|
39694
|
+
const activeRequests = getActiveRequestsByDeviceInstance(device.instanceId);
|
|
39695
|
+
if (activeRequests.length > 0) {
|
|
39696
|
+
Log.warn(`[${method.instanceId}] Device ${device.instanceId} has ${activeRequests.length} active requests:`, activeRequests.map(formatRequestContext));
|
|
39697
|
+
}
|
|
39443
39698
|
device.on(DEVICE.PIN, onDevicePinHandler);
|
|
39444
39699
|
device.on(DEVICE.BUTTON, onDeviceButtonHandler);
|
|
39445
39700
|
device.on(DEVICE.PASSPHRASE, message.payload.useEmptyPassphrase ? onEmptyPassphraseHandler : onDevicePassphraseHandler);
|
|
@@ -39452,7 +39707,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
39452
39707
|
}
|
|
39453
39708
|
yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
|
|
39454
39709
|
const inner = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39455
|
-
var
|
|
39710
|
+
var _e, _f, _g, _h, _j;
|
|
39456
39711
|
const versionRange = getMethodVersionRange(device.features, type => method.getVersionRange()[type]);
|
|
39457
39712
|
if (device.features) {
|
|
39458
39713
|
yield DataManager.checkAndReloadData();
|
|
@@ -39529,7 +39784,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
39529
39784
|
require: support.require,
|
|
39530
39785
|
}));
|
|
39531
39786
|
}
|
|
39532
|
-
const passphraseStateSafety = yield device.checkPassphraseStateSafety((
|
|
39787
|
+
const passphraseStateSafety = yield device.checkPassphraseStateSafety((_e = method.payload) === null || _e === void 0 ? void 0 : _e.passphraseState, (_f = method.payload) === null || _f === void 0 ? void 0 : _f.useEmptyPassphrase, (_g = method.payload) === null || _g === void 0 ? void 0 : _g.skipPassphraseCheck);
|
|
39533
39788
|
checkPassphraseEnableState(method, device.features);
|
|
39534
39789
|
if (!passphraseStateSafety) {
|
|
39535
39790
|
DevicePool.clearDeviceCache(method.payload.connectId);
|
|
@@ -39546,17 +39801,19 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
39546
39801
|
: hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'open safety check failed.');
|
|
39547
39802
|
throw error;
|
|
39548
39803
|
}
|
|
39549
|
-
(
|
|
39804
|
+
(_j = (_h = method.device) === null || _h === void 0 ? void 0 : _h.commands) === null || _j === void 0 ? void 0 : _j.checkDisposed();
|
|
39550
39805
|
try {
|
|
39551
39806
|
const response = yield method.run();
|
|
39552
39807
|
Log.debug('Call API - Inner Method Run: ');
|
|
39553
39808
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
39554
39809
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
39810
|
+
completeMethodRequestContext(method);
|
|
39555
39811
|
}
|
|
39556
39812
|
catch (error) {
|
|
39557
|
-
Log.debug(
|
|
39813
|
+
Log.debug(`Call API - Inner Method Run Error`, error);
|
|
39558
39814
|
messageResponse = createResponseMessage(method.responseID, false, { error });
|
|
39559
39815
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
39816
|
+
completeMethodRequestContext(method, error);
|
|
39560
39817
|
}
|
|
39561
39818
|
});
|
|
39562
39819
|
Log.debug('Call API - Device Run: ', device.mainId);
|
|
@@ -39568,6 +39825,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
39568
39825
|
}
|
|
39569
39826
|
catch (e) {
|
|
39570
39827
|
Log.debug('Device Run Error: ', e);
|
|
39828
|
+
completeMethodRequestContext(method, e);
|
|
39571
39829
|
return createResponseMessage(method.responseID, false, { error: e });
|
|
39572
39830
|
}
|
|
39573
39831
|
}
|
|
@@ -39575,6 +39833,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
39575
39833
|
messageResponse = createResponseMessage(method.responseID, false, { error });
|
|
39576
39834
|
requestQueue.rejectRequest(method.responseID, hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodError, error.message));
|
|
39577
39835
|
Log.debug('Call API - Run Error: ', error);
|
|
39836
|
+
completeMethodRequestContext(method, error);
|
|
39578
39837
|
}
|
|
39579
39838
|
finally {
|
|
39580
39839
|
const response = messageResponse;
|
|
@@ -39586,7 +39845,17 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
39586
39845
|
requestQueue.releaseTask(method.responseID);
|
|
39587
39846
|
closePopup();
|
|
39588
39847
|
cleanup();
|
|
39589
|
-
|
|
39848
|
+
if (device) {
|
|
39849
|
+
const stillActive = getActiveRequestsByDeviceInstance(device.instanceId);
|
|
39850
|
+
if (stillActive.length > 1) {
|
|
39851
|
+
Log.warn(`[${method.instanceId}] Removing listeners while ${stillActive.length} requests are active!`, {
|
|
39852
|
+
deviceInstanceId: device.instanceId,
|
|
39853
|
+
activeRequests: stillActive.map(formatRequestContext),
|
|
39854
|
+
pinListeners: device.listenerCount(DEVICE.PIN),
|
|
39855
|
+
});
|
|
39856
|
+
}
|
|
39857
|
+
removeDeviceListener(device);
|
|
39858
|
+
}
|
|
39590
39859
|
}
|
|
39591
39860
|
});
|
|
39592
39861
|
function initDeviceList(method) {
|
|
@@ -39656,7 +39925,7 @@ function initDeviceForBle(method) {
|
|
|
39656
39925
|
device = deviceCacheMap.get(method.connectId);
|
|
39657
39926
|
}
|
|
39658
39927
|
else {
|
|
39659
|
-
device = Device.fromDescriptor({ id: method.connectId });
|
|
39928
|
+
device = Device.fromDescriptor({ id: method.connectId }, method.sdkInstanceId);
|
|
39660
39929
|
deviceCacheMap.set(method.connectId, device);
|
|
39661
39930
|
}
|
|
39662
39931
|
device.deviceConnector = _connector;
|
|
@@ -39696,7 +39965,7 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
|
|
|
39696
39965
|
if (timer) {
|
|
39697
39966
|
clearTimeout(timer);
|
|
39698
39967
|
}
|
|
39699
|
-
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.
|
|
39968
|
+
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled));
|
|
39700
39969
|
return true;
|
|
39701
39970
|
}
|
|
39702
39971
|
return false;
|
|
@@ -39826,7 +40095,7 @@ const cancel = (context, connectId) => {
|
|
|
39826
40095
|
setPrePendingCallPromise(device === null || device === void 0 ? void 0 : device.interruptionFromUser());
|
|
39827
40096
|
canceledDevices.push(device);
|
|
39828
40097
|
}
|
|
39829
|
-
requestQueue.rejectRequest(requestId, hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.
|
|
40098
|
+
requestQueue.rejectRequest(requestId, hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled));
|
|
39830
40099
|
}
|
|
39831
40100
|
}
|
|
39832
40101
|
requestQueue.abortRequestsByConnectId(connectId);
|
|
@@ -39849,7 +40118,7 @@ const cancel = (context, connectId) => {
|
|
|
39849
40118
|
device === null || device === void 0 ? void 0 : device.interruptionFromUser();
|
|
39850
40119
|
canceledDevices.push(device);
|
|
39851
40120
|
}
|
|
39852
|
-
requestQueue.rejectRequest(requestId, hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.
|
|
40121
|
+
requestQueue.rejectRequest(requestId, hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled));
|
|
39853
40122
|
}
|
|
39854
40123
|
}
|
|
39855
40124
|
}
|
|
@@ -39861,7 +40130,7 @@ const cancel = (context, connectId) => {
|
|
|
39861
40130
|
}
|
|
39862
40131
|
});
|
|
39863
40132
|
requestQueue.getRequestTasksId().forEach(requestId => {
|
|
39864
|
-
requestQueue.rejectRequest(requestId, hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.
|
|
40133
|
+
requestQueue.rejectRequest(requestId, hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled));
|
|
39865
40134
|
});
|
|
39866
40135
|
}
|
|
39867
40136
|
}
|
|
@@ -39982,12 +40251,17 @@ const removeUiPromise = (promise) => {
|
|
|
39982
40251
|
};
|
|
39983
40252
|
class Core extends events.exports {
|
|
39984
40253
|
constructor() {
|
|
39985
|
-
super(
|
|
40254
|
+
super();
|
|
39986
40255
|
this.requestQueue = new RequestQueue();
|
|
39987
40256
|
this.methodSynchronize = getSynchronize();
|
|
40257
|
+
this.tracingContext = createSdkTracingContext();
|
|
40258
|
+
this.sdkInstanceId = this.tracingContext.sdkInstanceId;
|
|
40259
|
+
Log.debug(`[Core] Created SDK instance: ${this.sdkInstanceId}`);
|
|
39988
40260
|
}
|
|
39989
40261
|
getCoreContext() {
|
|
39990
40262
|
return {
|
|
40263
|
+
sdkInstanceId: this.sdkInstanceId,
|
|
40264
|
+
tracingContext: this.tracingContext,
|
|
39991
40265
|
requestQueue: this.requestQueue,
|
|
39992
40266
|
methodSynchronize: this.methodSynchronize,
|
|
39993
40267
|
getPrePendingCallPromise: () => this.prePendingCallPromise,
|
|
@@ -40052,6 +40326,8 @@ class Core extends events.exports {
|
|
|
40052
40326
|
dispose() {
|
|
40053
40327
|
_deviceList = undefined;
|
|
40054
40328
|
_connector = undefined;
|
|
40329
|
+
Log.debug(`[Core] Disposing SDK instance: ${this.sdkInstanceId}`);
|
|
40330
|
+
cleanupSdkInstance(this.sdkInstanceId);
|
|
40055
40331
|
}
|
|
40056
40332
|
}
|
|
40057
40333
|
const initCore = () => {
|
|
@@ -40072,7 +40348,7 @@ const init = (settings, Transport, plugin) => __awaiter(void 0, void 0, void 0,
|
|
|
40072
40348
|
yield DataManager.load(settings);
|
|
40073
40349
|
initTransport(Transport, plugin);
|
|
40074
40350
|
}
|
|
40075
|
-
catch (
|
|
40351
|
+
catch (_k) {
|
|
40076
40352
|
Log.error('DataManager.load error');
|
|
40077
40353
|
}
|
|
40078
40354
|
enableLog(DataManager.getSettings('debug'));
|
|
@@ -40146,18 +40422,26 @@ exports.UI_RESPONSE = UI_RESPONSE;
|
|
|
40146
40422
|
exports.checkNeedUpdateBootForClassicAndMini = checkNeedUpdateBootForClassicAndMini;
|
|
40147
40423
|
exports.checkNeedUpdateBootForTouch = checkNeedUpdateBootForTouch;
|
|
40148
40424
|
exports.cleanupCallback = cleanupCallback;
|
|
40425
|
+
exports.cleanupSdkInstance = cleanupSdkInstance;
|
|
40426
|
+
exports.completeRequestContext = completeRequestContext;
|
|
40149
40427
|
exports.corsValidator = corsValidator;
|
|
40150
40428
|
exports.createDeviceMessage = createDeviceMessage;
|
|
40151
40429
|
exports.createErrorMessage = createErrorMessage;
|
|
40152
40430
|
exports.createFirmwareMessage = createFirmwareMessage;
|
|
40153
40431
|
exports.createIFrameMessage = createIFrameMessage;
|
|
40154
40432
|
exports.createLogMessage = createLogMessage;
|
|
40433
|
+
exports.createRequestContext = createRequestContext;
|
|
40155
40434
|
exports.createResponseMessage = createResponseMessage;
|
|
40435
|
+
exports.createSdkTracingContext = createSdkTracingContext;
|
|
40156
40436
|
exports.createUiMessage = createUiMessage;
|
|
40157
40437
|
exports.createUiResponse = createUiResponse;
|
|
40158
40438
|
exports["default"] = HardwareSdk;
|
|
40159
40439
|
exports.enableLog = enableLog;
|
|
40160
40440
|
exports.executeCallback = executeCallback;
|
|
40441
|
+
exports.formatRequestContext = formatRequestContext;
|
|
40442
|
+
exports.generateInstanceId = generateInstanceId;
|
|
40443
|
+
exports.generateSdkInstanceId = generateSdkInstanceId;
|
|
40444
|
+
exports.getActiveRequestsByDeviceInstance = getActiveRequestsByDeviceInstance;
|
|
40161
40445
|
exports.getDeviceBLEFirmwareVersion = getDeviceBLEFirmwareVersion;
|
|
40162
40446
|
exports.getDeviceBleName = getDeviceBleName;
|
|
40163
40447
|
exports.getDeviceBoardloaderVersion = getDeviceBoardloaderVersion;
|
|
@@ -40195,6 +40479,7 @@ exports.safeThrowError = safeThrowError;
|
|
|
40195
40479
|
exports.setLoggerPostMessage = setLoggerPostMessage;
|
|
40196
40480
|
exports.supportInputPinOnSoftware = supportInputPinOnSoftware;
|
|
40197
40481
|
exports.switchTransport = switchTransport;
|
|
40482
|
+
exports.updateRequestContext = updateRequestContext;
|
|
40198
40483
|
exports.versionCompare = versionCompare;
|
|
40199
40484
|
exports.versionSplit = versionSplit;
|
|
40200
40485
|
exports.wait = wait;
|