@onekeyfe/hd-core 1.2.0-alpha.56 → 1.2.0-alpha.58
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/__tests__/AllNetworkGetAddressBase.tracing.test.ts +84 -2
- package/__tests__/DeviceCommands.test.ts +17 -6
- package/__tests__/core-initialization.test.ts +23 -0
- package/__tests__/device-connector-protocol.test.ts +81 -0
- package/__tests__/device-settings.test.ts +39 -18
- package/__tests__/protocol-v2-resources.test.ts +24 -0
- package/__tests__/protocol-v2.test.ts +46 -1
- package/__tests__/protocolV2FileWrite.test.ts +113 -0
- package/dist/api/FirmwareUpdateV4.d.ts +0 -1
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +4 -2
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +7 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +1 -0
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +2 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +448 -336
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +39 -69
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +3 -1
- package/src/api/device/DeviceSettings.ts +5 -4
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +12 -1
- package/src/api/helpers/protocolV2FileWrite.ts +192 -73
- package/src/core/index.ts +9 -6
- package/src/data-manager/DataManager.ts +25 -4
- package/src/data-manager/TransportManager.ts +6 -0
- package/src/device/DeviceCommands.ts +20 -2
- package/src/device/DeviceConnector.ts +33 -13
package/dist/index.js
CHANGED
|
@@ -837,7 +837,7 @@ const createLogMessage = (type, payload) => ({
|
|
|
837
837
|
|
|
838
838
|
const MAX_ENTRIES = 500;
|
|
839
839
|
let postMessage$1;
|
|
840
|
-
class Log$
|
|
840
|
+
class Log$l {
|
|
841
841
|
constructor(prefix, enabled) {
|
|
842
842
|
this.prefix = prefix;
|
|
843
843
|
this.enabled = enabled;
|
|
@@ -889,7 +889,7 @@ class Log$k {
|
|
|
889
889
|
}
|
|
890
890
|
const _logs = {};
|
|
891
891
|
const initLog = (prefix, enabled) => {
|
|
892
|
-
const instance = new Log$
|
|
892
|
+
const instance = new Log$l(prefix, !!enabled);
|
|
893
893
|
_logs[prefix] = instance;
|
|
894
894
|
return instance;
|
|
895
895
|
};
|
|
@@ -1287,7 +1287,7 @@ function patchFeatures(response) {
|
|
|
1287
1287
|
return response;
|
|
1288
1288
|
}
|
|
1289
1289
|
|
|
1290
|
-
const Log$
|
|
1290
|
+
const Log$k = getLogger(exports.LoggerNames.Core);
|
|
1291
1291
|
let globalInstanceCounter = 0;
|
|
1292
1292
|
let sdkInstanceCounter = 0;
|
|
1293
1293
|
function generateSdkInstanceId() {
|
|
@@ -1347,7 +1347,7 @@ function completeRequestContext(responseID, error) {
|
|
|
1347
1347
|
context.status = error ? 'error' : 'success';
|
|
1348
1348
|
if (error) {
|
|
1349
1349
|
context.error = error.message;
|
|
1350
|
-
Log$
|
|
1350
|
+
Log$k.debug(`[RequestContext] [completeRequestContext] Error: ${formatRequestContext(context)}`);
|
|
1351
1351
|
}
|
|
1352
1352
|
globalActiveRequests.delete(responseID);
|
|
1353
1353
|
if (context.sdkInstanceId) {
|
|
@@ -39716,7 +39716,7 @@ function isProtocolV2ResourceFileValid(binary, resource) {
|
|
|
39716
39716
|
}
|
|
39717
39717
|
|
|
39718
39718
|
var _a$1;
|
|
39719
|
-
const Log$
|
|
39719
|
+
const Log$j = getLogger(exports.LoggerNames.Core);
|
|
39720
39720
|
const FIRMWARE_FIELDS = [
|
|
39721
39721
|
'firmware',
|
|
39722
39722
|
'firmware-v1',
|
|
@@ -39771,6 +39771,7 @@ class DataManager {
|
|
|
39771
39771
|
var _b;
|
|
39772
39772
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39773
39773
|
this.settings = settings;
|
|
39774
|
+
this.protocolV2ResourcesConfigError = undefined;
|
|
39774
39775
|
if (!settings.fetchConfig) {
|
|
39775
39776
|
return false;
|
|
39776
39777
|
}
|
|
@@ -39781,38 +39782,48 @@ class DataManager {
|
|
|
39781
39782
|
let data = null;
|
|
39782
39783
|
let fetchMethod = 'none';
|
|
39783
39784
|
if (settings.configFetcher) {
|
|
39784
|
-
Log$
|
|
39785
|
+
Log$j.debug('[DataConfig] Trying configFetcher (client-side fetcher)...');
|
|
39785
39786
|
try {
|
|
39786
39787
|
data = yield settings.configFetcher(urlWithCache);
|
|
39787
39788
|
if (data) {
|
|
39788
39789
|
fetchMethod = 'configFetcher';
|
|
39789
|
-
Log$
|
|
39790
|
+
Log$j.log('[DataConfig] ConfigFetcher success');
|
|
39790
39791
|
}
|
|
39791
39792
|
else {
|
|
39792
|
-
Log$
|
|
39793
|
+
Log$j.debug('[DataConfig] ConfigFetcher returned null, will fallback to axios');
|
|
39793
39794
|
}
|
|
39794
39795
|
}
|
|
39795
39796
|
catch (e) {
|
|
39796
|
-
Log$
|
|
39797
|
+
Log$j.warn('[DataConfig] ConfigFetcher error, will fallback to axios:', e);
|
|
39797
39798
|
}
|
|
39798
39799
|
}
|
|
39799
39800
|
if (!data) {
|
|
39800
|
-
Log$
|
|
39801
|
+
Log$j.debug('[DataConfig] Trying axios (SDK default fetcher)...');
|
|
39801
39802
|
try {
|
|
39802
39803
|
const response = yield axios__default["default"].get(urlWithCache, {
|
|
39803
39804
|
timeout: 7000,
|
|
39804
39805
|
});
|
|
39805
39806
|
data = response.data;
|
|
39806
39807
|
fetchMethod = 'axios';
|
|
39807
|
-
Log$
|
|
39808
|
+
Log$j.log('[DataConfig] Axios fetch success');
|
|
39808
39809
|
}
|
|
39809
39810
|
catch (e) {
|
|
39810
|
-
Log$
|
|
39811
|
+
Log$j.warn('[DataConfig] Axios fetch error:', e);
|
|
39811
39812
|
}
|
|
39812
39813
|
}
|
|
39813
39814
|
if (data) {
|
|
39814
|
-
|
|
39815
|
-
|
|
39815
|
+
let pro2Resources;
|
|
39816
|
+
try {
|
|
39817
|
+
pro2Resources = parseProtocolV2Resources((_b = data.pro2) === null || _b === void 0 ? void 0 : _b.resources);
|
|
39818
|
+
}
|
|
39819
|
+
catch (error) {
|
|
39820
|
+
this.protocolV2ResourcesConfigError =
|
|
39821
|
+
error instanceof Error ? error : new Error(String(error));
|
|
39822
|
+
Log$j.warn('[DataConfig] Ignoring invalid Pro2 resources config:', error);
|
|
39823
|
+
}
|
|
39824
|
+
const enrichedPro2Config = this.enrichFirmwareReleaseInfo(data.pro2);
|
|
39825
|
+
const pro2Config = __rest(enrichedPro2Config, ["resources"]);
|
|
39826
|
+
Log$j.log(`[DataConfig] Config loaded successfully via [${fetchMethod}]`);
|
|
39816
39827
|
this.deviceMap = {
|
|
39817
39828
|
[hdShared.EDeviceType.Classic]: this.enrichFirmwareReleaseInfo(data.classic),
|
|
39818
39829
|
[hdShared.EDeviceType.Classic1s]: this.enrichFirmwareReleaseInfo(data.classic1s),
|
|
@@ -39820,14 +39831,14 @@ class DataManager {
|
|
|
39820
39831
|
[hdShared.EDeviceType.Mini]: this.enrichFirmwareReleaseInfo(data.mini),
|
|
39821
39832
|
[hdShared.EDeviceType.Touch]: this.enrichFirmwareReleaseInfo(data.touch),
|
|
39822
39833
|
[hdShared.EDeviceType.Pro]: this.enrichFirmwareReleaseInfo(data.pro),
|
|
39823
|
-
[hdShared.EDeviceType.Pro2]: Object.assign(Object.assign({},
|
|
39834
|
+
[hdShared.EDeviceType.Pro2]: Object.assign(Object.assign({}, pro2Config), (pro2Resources ? { resources: pro2Resources } : undefined)),
|
|
39824
39835
|
};
|
|
39825
39836
|
this.assets = {
|
|
39826
39837
|
bridge: data.bridge,
|
|
39827
39838
|
};
|
|
39828
39839
|
return true;
|
|
39829
39840
|
}
|
|
39830
|
-
Log$
|
|
39841
|
+
Log$j.warn('[DataConfig] All fetch methods failed, using built-in default config');
|
|
39831
39842
|
return false;
|
|
39832
39843
|
});
|
|
39833
39844
|
}
|
|
@@ -39857,6 +39868,9 @@ class DataManager {
|
|
|
39857
39868
|
if (!loaded) {
|
|
39858
39869
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.NetworkError, 'Unable to refresh the latest remote config');
|
|
39859
39870
|
}
|
|
39871
|
+
if (this.protocolV2ResourcesConfigError) {
|
|
39872
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.NetworkError, `Invalid Pro2 resources config: ${this.protocolV2ResourcesConfigError.message}`);
|
|
39873
|
+
}
|
|
39860
39874
|
this.lastCheckTimestamp = getTimeStamp();
|
|
39861
39875
|
});
|
|
39862
39876
|
}
|
|
@@ -41933,7 +41947,7 @@ const getDefectiveDeviceInfo = (features) => {
|
|
|
41933
41947
|
};
|
|
41934
41948
|
};
|
|
41935
41949
|
|
|
41936
|
-
const Log$
|
|
41950
|
+
const Log$i = getLogger(exports.LoggerNames.DevicePool);
|
|
41937
41951
|
const getDiff = (current, descriptors) => {
|
|
41938
41952
|
const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
|
|
41939
41953
|
const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
|
|
@@ -41991,7 +42005,7 @@ class DevicePool extends events.exports {
|
|
|
41991
42005
|
yield this._checkDevicePool(initOptions, connectId);
|
|
41992
42006
|
return { devices, deviceList };
|
|
41993
42007
|
}
|
|
41994
|
-
Log$
|
|
42008
|
+
Log$i.debug('found device in cache, but path is different: ', connectId);
|
|
41995
42009
|
}
|
|
41996
42010
|
}
|
|
41997
42011
|
const matchedDescriptor = connectId
|
|
@@ -42083,7 +42097,7 @@ class DevicePool extends events.exports {
|
|
|
42083
42097
|
yield device.getDeviceState({ refreshSections: ['settings'] });
|
|
42084
42098
|
}
|
|
42085
42099
|
catch (error) {
|
|
42086
|
-
Log$
|
|
42100
|
+
Log$i.debug('Unable to refresh Protocol V2 device label during discovery', error);
|
|
42087
42101
|
}
|
|
42088
42102
|
});
|
|
42089
42103
|
}
|
|
@@ -42099,7 +42113,7 @@ class DevicePool extends events.exports {
|
|
|
42099
42113
|
const descriptor = this.connectedPool[i];
|
|
42100
42114
|
if (!connectId || descriptor.path === connectId) {
|
|
42101
42115
|
const device = yield this._createDevice(descriptor, initOptions);
|
|
42102
|
-
Log$
|
|
42116
|
+
Log$i.debug('emit DEVICE.CONNECT: ', device === null || device === void 0 ? void 0 : device.features);
|
|
42103
42117
|
this.emitter.emit(DEVICE.CONNECT, device);
|
|
42104
42118
|
this.connectedPool.splice(i, 1);
|
|
42105
42119
|
}
|
|
@@ -42121,9 +42135,9 @@ class DevicePool extends events.exports {
|
|
|
42121
42135
|
const diff = getDiff(this.current || [], upcoming);
|
|
42122
42136
|
this.upcoming = upcoming;
|
|
42123
42137
|
this.current = this.upcoming;
|
|
42124
|
-
Log$
|
|
42125
|
-
Log$
|
|
42126
|
-
Log$
|
|
42138
|
+
Log$i.debug('device pool -> current: ', this.current);
|
|
42139
|
+
Log$i.debug('device pool -> upcomming: ', this.upcoming);
|
|
42140
|
+
Log$i.debug('DeviceCache.reportDeviceChange diff: ', diff);
|
|
42127
42141
|
if (!diff.didUpdate) {
|
|
42128
42142
|
return;
|
|
42129
42143
|
}
|
|
@@ -42133,7 +42147,7 @@ class DevicePool extends events.exports {
|
|
|
42133
42147
|
this._addConnectedDeviceToPool(d);
|
|
42134
42148
|
return;
|
|
42135
42149
|
}
|
|
42136
|
-
Log$
|
|
42150
|
+
Log$i.debug('emit DEVICE.CONNECT: ', device.features);
|
|
42137
42151
|
this.emitter.emit(DEVICE.CONNECT, device);
|
|
42138
42152
|
});
|
|
42139
42153
|
diff.disconnected.forEach(d => {
|
|
@@ -42143,7 +42157,7 @@ class DevicePool extends events.exports {
|
|
|
42143
42157
|
this._addDisconnectedDeviceToPool(d);
|
|
42144
42158
|
return;
|
|
42145
42159
|
}
|
|
42146
|
-
Log$
|
|
42160
|
+
Log$i.debug('emit DEVICE.DISCONNECT: ', device.features);
|
|
42147
42161
|
device.markTransportDisconnected();
|
|
42148
42162
|
this.emitter.emit(DEVICE.DISCONNECT, device);
|
|
42149
42163
|
});
|
|
@@ -42179,7 +42193,7 @@ class DevicePool extends events.exports {
|
|
|
42179
42193
|
this.connectedPool = [];
|
|
42180
42194
|
this.disconnectPool = [];
|
|
42181
42195
|
this.devicesCache = {};
|
|
42182
|
-
Log$
|
|
42196
|
+
Log$i.debug('DevicePool state has been reset');
|
|
42183
42197
|
}
|
|
42184
42198
|
static dispose() {
|
|
42185
42199
|
this.resetState();
|
|
@@ -42193,7 +42207,7 @@ DevicePool.disconnectPool = [];
|
|
|
42193
42207
|
DevicePool.devicesCache = {};
|
|
42194
42208
|
DevicePool.emitter = new events.exports();
|
|
42195
42209
|
|
|
42196
|
-
const Log$
|
|
42210
|
+
const Log$h = getLogger(exports.LoggerNames.Transport);
|
|
42197
42211
|
const BleLogger = getLogger(exports.LoggerNames.HdBleTransport);
|
|
42198
42212
|
const HttpLogger = getLogger(exports.LoggerNames.HdTransportHttp);
|
|
42199
42213
|
const LowLevelLogger = getLogger(exports.LoggerNames.HdTransportLowLevel);
|
|
@@ -42203,7 +42217,7 @@ const WebUsbLogger = getLogger(exports.LoggerNames.HdTransportWebUsb);
|
|
|
42203
42217
|
const REACT_NATIVE_BLE_SCAN_TIMEOUT_MS = 3000;
|
|
42204
42218
|
class TransportManager {
|
|
42205
42219
|
static load() {
|
|
42206
|
-
Log$
|
|
42220
|
+
Log$h.debug('transport manager load');
|
|
42207
42221
|
this.defaultMessages = DataManager.getProtobufMessages();
|
|
42208
42222
|
this.currentMessages = this.defaultMessages;
|
|
42209
42223
|
this.protocolV1MessageSchema = 'v1CurrentSchema';
|
|
@@ -42212,14 +42226,14 @@ class TransportManager {
|
|
|
42212
42226
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42213
42227
|
try {
|
|
42214
42228
|
const env = DataManager.getSettings('env');
|
|
42215
|
-
Log$
|
|
42229
|
+
Log$h.debug('Initializing transports', env);
|
|
42216
42230
|
if (env === 'react-native') {
|
|
42217
42231
|
if (!this.reactNativeInit) {
|
|
42218
42232
|
yield this.transport.init(BleLogger, DevicePool.emitter);
|
|
42219
42233
|
this.reactNativeInit = true;
|
|
42220
42234
|
}
|
|
42221
42235
|
else {
|
|
42222
|
-
Log$
|
|
42236
|
+
Log$h.debug('React Native Do Not Initializing transports');
|
|
42223
42237
|
}
|
|
42224
42238
|
}
|
|
42225
42239
|
else if (env === 'node-usb') {
|
|
@@ -42240,15 +42254,15 @@ class TransportManager {
|
|
|
42240
42254
|
else {
|
|
42241
42255
|
yield this.transport.init(HttpLogger);
|
|
42242
42256
|
}
|
|
42243
|
-
Log$
|
|
42257
|
+
Log$h.debug('Configuring transports');
|
|
42244
42258
|
yield this.transport.configure(JSON.stringify(this.defaultMessages));
|
|
42245
42259
|
this.currentMessages = this.defaultMessages;
|
|
42246
42260
|
this.protocolV1MessageSchema = 'v1CurrentSchema';
|
|
42247
42261
|
yield this.configureProtocolV2Messages();
|
|
42248
|
-
Log$
|
|
42262
|
+
Log$h.debug('Configuring transports done');
|
|
42249
42263
|
}
|
|
42250
42264
|
catch (error) {
|
|
42251
|
-
Log$
|
|
42265
|
+
Log$h.debug('Initializing transports error: ', error);
|
|
42252
42266
|
if (error.code === 'ECONNABORTED') {
|
|
42253
42267
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
|
|
42254
42268
|
}
|
|
@@ -42264,7 +42278,7 @@ class TransportManager {
|
|
|
42264
42278
|
if (this.currentMessages === messages || !messages) {
|
|
42265
42279
|
return;
|
|
42266
42280
|
}
|
|
42267
|
-
Log$
|
|
42281
|
+
Log$h.debug(`Reconfiguring transports Protocol V1 schema:${protocolV1MessageSchema}`);
|
|
42268
42282
|
try {
|
|
42269
42283
|
yield this.transport.configure(JSON.stringify(messages));
|
|
42270
42284
|
this.currentMessages = messages;
|
|
@@ -42276,6 +42290,9 @@ class TransportManager {
|
|
|
42276
42290
|
});
|
|
42277
42291
|
}
|
|
42278
42292
|
static setTransport(TransportConstructor, plugin) {
|
|
42293
|
+
if (typeof TransportConstructor !== 'function') {
|
|
42294
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured, 'Transport constructor is not available');
|
|
42295
|
+
}
|
|
42279
42296
|
const env = DataManager.getSettings('env');
|
|
42280
42297
|
if (env === 'react-native') {
|
|
42281
42298
|
this.transport = new TransportConstructor({
|
|
@@ -42287,9 +42304,9 @@ class TransportManager {
|
|
|
42287
42304
|
}
|
|
42288
42305
|
if (plugin) {
|
|
42289
42306
|
this.plugin = plugin;
|
|
42290
|
-
Log$
|
|
42307
|
+
Log$h.debug('set transport plugin: ', this.plugin);
|
|
42291
42308
|
}
|
|
42292
|
-
Log$
|
|
42309
|
+
Log$h.debug('set transport: ', this.transport.name, this.transport.version, this.transport.configured);
|
|
42293
42310
|
}
|
|
42294
42311
|
static getTransport() {
|
|
42295
42312
|
return this.transport;
|
|
@@ -42300,7 +42317,7 @@ class TransportManager {
|
|
|
42300
42317
|
const { configureProtocolV2 } = this.transport;
|
|
42301
42318
|
if (protocolV2Messages && typeof configureProtocolV2 === 'function') {
|
|
42302
42319
|
yield configureProtocolV2.call(this.transport, JSON.stringify(protocolV2Messages));
|
|
42303
|
-
Log$
|
|
42320
|
+
Log$h.debug('Protocol V2 messages configured');
|
|
42304
42321
|
}
|
|
42305
42322
|
});
|
|
42306
42323
|
}
|
|
@@ -42333,6 +42350,7 @@ const DEVICE_SESSION_CALLS = new Set([
|
|
|
42333
42350
|
'DeviceSessionAskPin',
|
|
42334
42351
|
'DeviceSessionAskPassphrase',
|
|
42335
42352
|
]);
|
|
42353
|
+
const PROTOCOL_V2_ACTION_CANCELLED_SUBCODE = 1;
|
|
42336
42354
|
const isProtocolV2ActionCancelledMessage = (message) => /^(?:cancel(?:led|ed)(?: on device)?|confirm dismissed|user cancel(?:led|ed)(?:\s+.*)?)$/i.test(message);
|
|
42337
42355
|
function shouldReduceDebugForCall(type) {
|
|
42338
42356
|
return HIGH_VOLUME_DEBUG_CALLS.has(type);
|
|
@@ -42412,7 +42430,7 @@ const cancelDeviceWithInitialize = (device) => {
|
|
|
42412
42430
|
},
|
|
42413
42431
|
}));
|
|
42414
42432
|
};
|
|
42415
|
-
const Log$
|
|
42433
|
+
const Log$g = getLogger(exports.LoggerNames.DeviceCommands);
|
|
42416
42434
|
const LogCore = getLogger(exports.LoggerNames.Core);
|
|
42417
42435
|
class DeviceCommands {
|
|
42418
42436
|
constructor(device, mainId) {
|
|
@@ -42421,7 +42439,7 @@ class DeviceCommands {
|
|
|
42421
42439
|
this.transport = TransportManager.getTransport();
|
|
42422
42440
|
this.disposed = false;
|
|
42423
42441
|
this.instanceId = generateInstanceId('DeviceCommands', device.sdkInstanceId);
|
|
42424
|
-
Log$
|
|
42442
|
+
Log$g.debug(`[DeviceCommands] Created: ${this.instanceId}, device: ${this.device.instanceId}`);
|
|
42425
42443
|
}
|
|
42426
42444
|
dispose(_cancelRequest) {
|
|
42427
42445
|
var _a, _b;
|
|
@@ -42501,7 +42519,7 @@ class DeviceCommands {
|
|
|
42501
42519
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42502
42520
|
const shouldReduceDebug = shouldReduceDebugForCall(type);
|
|
42503
42521
|
if (!shouldReduceDebug) {
|
|
42504
|
-
Log$
|
|
42522
|
+
Log$g.debug('[DeviceCommands] [call] Sending', type, hdTransport.getSafeTransportLogPayload(msg !== null && msg !== void 0 ? msg : {}, type));
|
|
42505
42523
|
}
|
|
42506
42524
|
try {
|
|
42507
42525
|
const promise = this.transport.call(this.mainId, type, msg !== null && msg !== void 0 ? msg : {}, options);
|
|
@@ -42563,10 +42581,10 @@ class DeviceCommands {
|
|
|
42563
42581
|
assertType(response, resType);
|
|
42564
42582
|
}
|
|
42565
42583
|
catch (error) {
|
|
42566
|
-
Log$
|
|
42584
|
+
Log$g.debug('DeviceCommands typedcall error: ', error);
|
|
42567
42585
|
if (error instanceof hdShared.HardwareError) {
|
|
42568
42586
|
if (error.errorCode === hdShared.HardwareErrorCode.ResponseUnexpectTypeError) {
|
|
42569
|
-
Log$
|
|
42587
|
+
Log$g.debug('[DeviceCommands] [typedCall] Unexpected response type', {
|
|
42570
42588
|
request: type,
|
|
42571
42589
|
expected: resType,
|
|
42572
42590
|
received: response.type,
|
|
@@ -42600,7 +42618,7 @@ class DeviceCommands {
|
|
|
42600
42618
|
var _a;
|
|
42601
42619
|
try {
|
|
42602
42620
|
if (!shouldReduceDebugForCall(callType)) {
|
|
42603
|
-
Log$
|
|
42621
|
+
Log$g.debug('_filterCommonTypes: ', {
|
|
42604
42622
|
request: callType,
|
|
42605
42623
|
response: callType === 'DeviceFirmwareUpdateStatusGet'
|
|
42606
42624
|
? {
|
|
@@ -42652,6 +42670,11 @@ class DeviceCommands {
|
|
|
42652
42670
|
if (code === 'Failure_ProcessError') {
|
|
42653
42671
|
const normalizedMessage = (_a = message === null || message === void 0 ? void 0 : message.trim()) !== null && _a !== void 0 ? _a : '';
|
|
42654
42672
|
const isProtocolV2ActionCancelledFailure = this.device.isProtocolV2() && isProtocolV2ActionCancelledMessage(normalizedMessage);
|
|
42673
|
+
const isProtocolV2ActionCancelledSubcode = this.device.isProtocolV2() && subcode === PROTOCOL_V2_ACTION_CANCELLED_SUBCODE;
|
|
42674
|
+
const isProtocolV2DeviceBusyFailure = this.device.isProtocolV2() &&
|
|
42675
|
+
callType.startsWith('Device') &&
|
|
42676
|
+
!DEVICE_SESSION_CALLS.has(callType) &&
|
|
42677
|
+
subcode === hdTransport.DeviceErrorCode.DeviceError_Busy;
|
|
42655
42678
|
const isLegacyProtocolV2LockedFailure = this.device.isProtocolV2() && /^device (?:is )?locked$/i.test(normalizedMessage);
|
|
42656
42679
|
if (DEVICE_SESSION_CALLS.has(callType) &&
|
|
42657
42680
|
subcode === hdTransport.DeviceSessionErrorCode.DeviceSessionError_InvalidSession) {
|
|
@@ -42702,7 +42725,15 @@ class DeviceCommands {
|
|
|
42702
42725
|
firmwareMessage: message,
|
|
42703
42726
|
});
|
|
42704
42727
|
}
|
|
42728
|
+
else if (isProtocolV2DeviceBusyFailure) {
|
|
42729
|
+
error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceBusy, message, {
|
|
42730
|
+
failureCode: code,
|
|
42731
|
+
subcode,
|
|
42732
|
+
firmwareMessage: message,
|
|
42733
|
+
});
|
|
42734
|
+
}
|
|
42705
42735
|
else if (subcode === hdTransport.DeviceErrorCode.DeviceError_ActionCancelled ||
|
|
42736
|
+
isProtocolV2ActionCancelledSubcode ||
|
|
42706
42737
|
isProtocolV2ActionCancelledFailure) {
|
|
42707
42738
|
error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ActionCancelled, message, {
|
|
42708
42739
|
failureCode: code,
|
|
@@ -42805,7 +42836,7 @@ class DeviceCommands {
|
|
|
42805
42836
|
reject(error);
|
|
42806
42837
|
});
|
|
42807
42838
|
const listenerCount = this.device.listenerCount(DEVICE.PIN);
|
|
42808
|
-
Log$
|
|
42839
|
+
Log$g.debug(`[${this.instanceId}] _promptPin called`, {
|
|
42809
42840
|
responseID: this.currentResponseID,
|
|
42810
42841
|
deviceInstanceId: this.device.instanceId,
|
|
42811
42842
|
listenerCount,
|
|
@@ -43712,7 +43743,7 @@ const parseRunOptions = (options) => {
|
|
|
43712
43743
|
options = {};
|
|
43713
43744
|
return options;
|
|
43714
43745
|
};
|
|
43715
|
-
const Log$
|
|
43746
|
+
const Log$f = getLogger(exports.LoggerNames.Device);
|
|
43716
43747
|
const isProtocolV2DeviceStatusUnsupportedError = (error) => {
|
|
43717
43748
|
var _a, _b, _c;
|
|
43718
43749
|
if (error instanceof hdShared.HardwareError) {
|
|
@@ -43773,7 +43804,7 @@ class Device extends events.exports {
|
|
|
43773
43804
|
this.sdkInstanceId = sdkInstanceId;
|
|
43774
43805
|
this.instanceId = generateInstanceId('Device', this.sdkInstanceId);
|
|
43775
43806
|
this.createdAt = Date.now();
|
|
43776
|
-
Log$
|
|
43807
|
+
Log$f.debug(`[Device] Created: ${this.instanceId}${this.sdkInstanceId ? ` for SDK: ${this.sdkInstanceId}` : ''}`);
|
|
43777
43808
|
}
|
|
43778
43809
|
static fromDescriptor(originalDescriptor, sdkInstanceId) {
|
|
43779
43810
|
const descriptor = Object.assign({}, originalDescriptor);
|
|
@@ -43864,12 +43895,12 @@ class Device extends events.exports {
|
|
|
43864
43895
|
if (DataManager.isBleConnect(env)) {
|
|
43865
43896
|
acquireResult = yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.originalDescriptor.id, undefined, true, strictProtocol, undefined));
|
|
43866
43897
|
this.mainId = (_b = acquireResult === null || acquireResult === void 0 ? void 0 : acquireResult.uuid) !== null && _b !== void 0 ? _b : '';
|
|
43867
|
-
Log$
|
|
43898
|
+
Log$f.debug('Expected uuid:', this.mainId);
|
|
43868
43899
|
}
|
|
43869
43900
|
else {
|
|
43870
43901
|
acquireResult = yield ((_c = this.deviceConnector) === null || _c === void 0 ? void 0 : _c.acquire(this.originalDescriptor.path, this.originalDescriptor.session, undefined, strictProtocol, undefined));
|
|
43871
43902
|
this.mainId = acquireResult;
|
|
43872
|
-
Log$
|
|
43903
|
+
Log$f.debug('Expected session id:', this.mainId);
|
|
43873
43904
|
}
|
|
43874
43905
|
const detectedProtocol = (_d = acquireResult === null || acquireResult === void 0 ? void 0 : acquireResult.protocolType) !== null && _d !== void 0 ? _d : (_f = (_e = TransportManager.transport) === null || _e === void 0 ? void 0 : _e.getProtocolType) === null || _f === void 0 ? void 0 : _f.call(_e, DataManager.isBleConnect(env) ? this.originalDescriptor.id : this.originalDescriptor.path);
|
|
43875
43906
|
if ((options === null || options === void 0 ? void 0 : options.forceProtocolDetection) && !detectedProtocol) {
|
|
@@ -43895,7 +43926,7 @@ class Device extends events.exports {
|
|
|
43895
43926
|
yield ((_j = (_h = this.deviceConnector) === null || _h === void 0 ? void 0 : _h.release) === null || _j === void 0 ? void 0 : _j.call(_h, failedSession, false));
|
|
43896
43927
|
}
|
|
43897
43928
|
catch (releaseError) {
|
|
43898
|
-
Log$
|
|
43929
|
+
Log$f.debug('Failed to release an unsuccessful protocol probe', releaseError);
|
|
43899
43930
|
}
|
|
43900
43931
|
}
|
|
43901
43932
|
if (!DataManager.isBleConnect(env)) {
|
|
@@ -43924,11 +43955,11 @@ class Device extends events.exports {
|
|
|
43924
43955
|
(this.mainId && DataManager.isBleConnect(env))) {
|
|
43925
43956
|
if (this.pendingCallbackPromise) {
|
|
43926
43957
|
try {
|
|
43927
|
-
Log$
|
|
43958
|
+
Log$f.debug('Waiting for callback tasks to complete before releasing device (in release method)');
|
|
43928
43959
|
yield this.pendingCallbackPromise.promise;
|
|
43929
43960
|
}
|
|
43930
43961
|
catch (error) {
|
|
43931
|
-
Log$
|
|
43962
|
+
Log$f.error('Error waiting for callback tasks in release method:', error);
|
|
43932
43963
|
}
|
|
43933
43964
|
}
|
|
43934
43965
|
if (this.commands) {
|
|
@@ -43947,7 +43978,7 @@ class Device extends events.exports {
|
|
|
43947
43978
|
this.updateDescriptor({ session: null });
|
|
43948
43979
|
}
|
|
43949
43980
|
catch (err) {
|
|
43950
|
-
Log$
|
|
43981
|
+
Log$f.error('[Device] release error: ', err);
|
|
43951
43982
|
}
|
|
43952
43983
|
finally {
|
|
43953
43984
|
this.needReloadDevice = true;
|
|
@@ -44149,7 +44180,7 @@ class Device extends events.exports {
|
|
|
44149
44180
|
});
|
|
44150
44181
|
}
|
|
44151
44182
|
getInternalState(_deviceId) {
|
|
44152
|
-
Log$
|
|
44183
|
+
Log$f.debug('getInternalState session param: ', `device_id: ${_deviceId}`, `currentDeviceId: ${this.getCurrentDeviceId()}`, `hasPassphraseState: ${Boolean(this.passphraseState)}`);
|
|
44153
44184
|
const deviceId = this.getSessionCacheDeviceKey(_deviceId);
|
|
44154
44185
|
if (!deviceId)
|
|
44155
44186
|
return undefined;
|
|
@@ -44164,7 +44195,7 @@ class Device extends events.exports {
|
|
|
44164
44195
|
return deviceWalletSessionStore.getStandard(deviceId);
|
|
44165
44196
|
}
|
|
44166
44197
|
updateInternalState(enablePassphrase, passphraseState, deviceId, sessionId = null, featuresSessionId = null, walletType = 'hidden') {
|
|
44167
|
-
Log$
|
|
44198
|
+
Log$f.debug('updateInternalState session param: ', `device_id: ${deviceId}`, `enablePassphrase: ${enablePassphrase}`, `hasPassphraseState: ${Boolean(passphraseState)}`, `hasSessionId: ${Boolean(sessionId)}`, `hasFeaturesSessionId: ${Boolean(featuresSessionId)}`);
|
|
44168
44199
|
const cacheDeviceKey = this.getSessionCacheDeviceKey(deviceId);
|
|
44169
44200
|
if (!cacheDeviceKey)
|
|
44170
44201
|
return;
|
|
@@ -44180,7 +44211,7 @@ class Device extends events.exports {
|
|
|
44180
44211
|
deviceWalletSessionStore.deletePending(cacheDeviceKey);
|
|
44181
44212
|
}
|
|
44182
44213
|
setInternalState(state, initSession) {
|
|
44183
|
-
Log$
|
|
44214
|
+
Log$f.debug('setInternalState session param: ', `hasState: ${Boolean(state)}`, `initSession: ${initSession}`, `deviceId: ${this.getCurrentDeviceId()}`, `hasPassphraseState: ${Boolean(this.passphraseState)}`);
|
|
44184
44215
|
if (!this.passphraseState && !initSession)
|
|
44185
44216
|
return;
|
|
44186
44217
|
const deviceId = this.getSessionCacheDeviceKey();
|
|
@@ -44194,7 +44225,7 @@ class Device extends events.exports {
|
|
|
44194
44225
|
}
|
|
44195
44226
|
}
|
|
44196
44227
|
clearInternalState(_deviceId) {
|
|
44197
|
-
Log$
|
|
44228
|
+
Log$f.debug('clearInternalState param: ', _deviceId);
|
|
44198
44229
|
const deviceId = this.getSessionCacheDeviceKey(_deviceId);
|
|
44199
44230
|
if (!deviceId)
|
|
44200
44231
|
return;
|
|
@@ -44261,24 +44292,24 @@ class Device extends events.exports {
|
|
|
44261
44292
|
yield callInitialize(payload, options === null || options === void 0 ? void 0 : options.initSession);
|
|
44262
44293
|
}
|
|
44263
44294
|
catch (error) {
|
|
44264
|
-
Log$
|
|
44295
|
+
Log$f.error('Initialization failed:', error);
|
|
44265
44296
|
throw error;
|
|
44266
44297
|
}
|
|
44267
44298
|
});
|
|
44268
44299
|
}
|
|
44269
44300
|
_initializeProtocolV2(options) {
|
|
44270
44301
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44271
|
-
Log$
|
|
44302
|
+
Log$f.debug('Initialize device via Protocol V2 features adapter');
|
|
44272
44303
|
try {
|
|
44273
44304
|
const deviceInfo = yield requestProtocolV2DeviceInfo({
|
|
44274
44305
|
commands: this.commands,
|
|
44275
44306
|
timeoutMs: options === null || options === void 0 ? void 0 : options.protocolV2DeviceInfoTimeoutMs,
|
|
44276
44307
|
});
|
|
44277
44308
|
const features = yield this.probeProtocolV2RuntimeState(deviceInfo, options === null || options === void 0 ? void 0 : options.protocolV2DeviceInfoTimeoutMs);
|
|
44278
|
-
Log$
|
|
44309
|
+
Log$f.debug('Protocol V2 features:', features);
|
|
44279
44310
|
}
|
|
44280
44311
|
catch (error) {
|
|
44281
|
-
Log$
|
|
44312
|
+
Log$f.error('Protocol V2 initialization failed:', error);
|
|
44282
44313
|
throw error;
|
|
44283
44314
|
}
|
|
44284
44315
|
});
|
|
@@ -44384,7 +44415,7 @@ class Device extends events.exports {
|
|
|
44384
44415
|
source,
|
|
44385
44416
|
changedKeys: result.changedKeys,
|
|
44386
44417
|
};
|
|
44387
|
-
Log$
|
|
44418
|
+
Log$f.debug('Device state patch committed', {
|
|
44388
44419
|
source,
|
|
44389
44420
|
keys: result.changedKeys,
|
|
44390
44421
|
});
|
|
@@ -44602,7 +44633,7 @@ class Device extends events.exports {
|
|
|
44602
44633
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44603
44634
|
if (this.runPromise) {
|
|
44604
44635
|
yield this.interruptionFromOutside();
|
|
44605
|
-
Log$
|
|
44636
|
+
Log$f.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
|
|
44606
44637
|
}
|
|
44607
44638
|
options = parseRunOptions(options);
|
|
44608
44639
|
const runPromise = hdShared.createDeferred();
|
|
@@ -44679,7 +44710,7 @@ class Device extends events.exports {
|
|
|
44679
44710
|
yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.disconnect(this.mainId));
|
|
44680
44711
|
}
|
|
44681
44712
|
yield this.release();
|
|
44682
|
-
Log$
|
|
44713
|
+
Log$f.debug(`error code ${e.errorCode} release device, mainId: ${this.mainId}`);
|
|
44683
44714
|
}
|
|
44684
44715
|
clearRunPromise();
|
|
44685
44716
|
return;
|
|
@@ -44689,7 +44720,7 @@ class Device extends events.exports {
|
|
|
44689
44720
|
options.keepSession === false) {
|
|
44690
44721
|
this.keepSession = false;
|
|
44691
44722
|
yield this.release();
|
|
44692
|
-
Log$
|
|
44723
|
+
Log$f.debug('release device, mainId: ', this.mainId);
|
|
44693
44724
|
}
|
|
44694
44725
|
runPromise.resolve();
|
|
44695
44726
|
clearRunPromise();
|
|
@@ -44720,7 +44751,7 @@ class Device extends events.exports {
|
|
|
44720
44751
|
setCancelableAction(callback) {
|
|
44721
44752
|
this.cancelableAction = (e) => callback(e)
|
|
44722
44753
|
.catch(e2 => {
|
|
44723
|
-
Log$
|
|
44754
|
+
Log$f.debug('cancelableAction error', e2);
|
|
44724
44755
|
})
|
|
44725
44756
|
.finally(() => {
|
|
44726
44757
|
this.clearCancelableAction();
|
|
@@ -45001,7 +45032,7 @@ class Device extends events.exports {
|
|
|
45001
45032
|
expectedPassphraseState &&
|
|
45002
45033
|
expectedPassphraseState !== newPassphraseState;
|
|
45003
45034
|
const passphraseStateMismatch = !!expectedPassphraseState && expectedPassphraseState !== newPassphraseState;
|
|
45004
|
-
Log$
|
|
45035
|
+
Log$f.debug('Check passphrase state safety: ', {
|
|
45005
45036
|
hasExpectedPassphraseState: Boolean(expectedPassphraseState),
|
|
45006
45037
|
hasNewPassphraseState: Boolean(newPassphraseState),
|
|
45007
45038
|
passphraseStateMatches: Boolean(expectedPassphraseState) && expectedPassphraseState === newPassphraseState,
|
|
@@ -45139,7 +45170,7 @@ const getBootloaderReleaseInfo = ({ features, willUpdateFirmwareVersion, firmwar
|
|
|
45139
45170
|
};
|
|
45140
45171
|
};
|
|
45141
45172
|
|
|
45142
|
-
const Log$
|
|
45173
|
+
const Log$e = getLogger(exports.LoggerNames.Method);
|
|
45143
45174
|
const isEvmLedgerLegacyPathWithHighIndex = (path) => {
|
|
45144
45175
|
let addressN;
|
|
45145
45176
|
if (typeof path === 'string') {
|
|
@@ -45223,7 +45254,7 @@ class BaseMethod {
|
|
|
45223
45254
|
setContext(context) {
|
|
45224
45255
|
this.sdkInstanceId = context.sdkInstanceId;
|
|
45225
45256
|
this.instanceId = generateInstanceId('Method', this.sdkInstanceId);
|
|
45226
|
-
Log$
|
|
45257
|
+
Log$e.debug(`[BaseMethod] Created: ${this.instanceId}, method: ${this.name}, SDK: ${this.sdkInstanceId}`);
|
|
45227
45258
|
}
|
|
45228
45259
|
setDevice(device) {
|
|
45229
45260
|
var _a, _b;
|
|
@@ -45243,7 +45274,7 @@ class BaseMethod {
|
|
|
45243
45274
|
if (device.commands) {
|
|
45244
45275
|
device.commands.currentResponseID = this.responseID;
|
|
45245
45276
|
}
|
|
45246
|
-
Log$
|
|
45277
|
+
Log$e.debug(`[${this.instanceId}] setDevice: ${device.instanceId}, commands: ${(_b = device.commands) === null || _b === void 0 ? void 0 : _b.instanceId}`);
|
|
45247
45278
|
}
|
|
45248
45279
|
checkFirmwareRelease() {
|
|
45249
45280
|
if (!this.device || this.device.isProtocolV2())
|
|
@@ -45318,7 +45349,7 @@ class BaseMethod {
|
|
|
45318
45349
|
checkFlag = true;
|
|
45319
45350
|
}
|
|
45320
45351
|
if (checkFlag && this.device.getCurrentSafetyChecks() === hdTransport.Enum_SafetyCheckLevel.Strict) {
|
|
45321
|
-
Log$
|
|
45352
|
+
Log$e.debug('will change safety_checks level');
|
|
45322
45353
|
yield this.device.commands.typedCall('ApplySettings', 'Success', {
|
|
45323
45354
|
safety_checks: hdTransport.Enum_SafetyCheckLevel.PromptTemporarily,
|
|
45324
45355
|
});
|
|
@@ -45394,7 +45425,7 @@ class Ping extends BaseMethod {
|
|
|
45394
45425
|
}
|
|
45395
45426
|
}
|
|
45396
45427
|
|
|
45397
|
-
const Log$
|
|
45428
|
+
const Log$d = getLogger(exports.LoggerNames.Core);
|
|
45398
45429
|
const parseInitOptions$1 = (payload) => ({
|
|
45399
45430
|
initSession: payload === null || payload === void 0 ? void 0 : payload.initSession,
|
|
45400
45431
|
passphraseState: payload === null || payload === void 0 ? void 0 : payload.passphraseState,
|
|
@@ -45420,14 +45451,14 @@ class PreInitialize extends BaseMethod {
|
|
|
45420
45451
|
}
|
|
45421
45452
|
catch (_a) {
|
|
45422
45453
|
this.device.clearPreInitialized();
|
|
45423
|
-
Log$
|
|
45454
|
+
Log$d.debug('[PRE-INIT][FAILED]');
|
|
45424
45455
|
return false;
|
|
45425
45456
|
}
|
|
45426
45457
|
});
|
|
45427
45458
|
}
|
|
45428
45459
|
}
|
|
45429
45460
|
|
|
45430
|
-
const Log$
|
|
45461
|
+
const Log$c = getLogger(exports.LoggerNames.DevicePool);
|
|
45431
45462
|
class SearchDevices extends BaseMethod {
|
|
45432
45463
|
init() {
|
|
45433
45464
|
this.useDevice = false;
|
|
@@ -45468,7 +45499,7 @@ class SearchDevices extends BaseMethod {
|
|
|
45468
45499
|
const errorCode = error && typeof error === 'object' && 'errorCode' in error
|
|
45469
45500
|
? error.errorCode
|
|
45470
45501
|
: undefined;
|
|
45471
|
-
Log$
|
|
45502
|
+
Log$c.debug('Skip unavailable device during search', Object.assign({ path: descriptor.path }, (errorCode !== undefined ? { errorCode } : {})));
|
|
45472
45503
|
}
|
|
45473
45504
|
}
|
|
45474
45505
|
return deviceList.map(device => device.toMessageObject());
|
|
@@ -46886,6 +46917,7 @@ class DeviceSettings extends BaseMethod {
|
|
|
46886
46917
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46887
46918
|
try {
|
|
46888
46919
|
if (this.device.isProtocolV2()) {
|
|
46920
|
+
const refreshStatusAndSettings = () => this.device.getDeviceState({ refreshSections: ['status', 'settings'] });
|
|
46889
46921
|
assertSettingsSupported(this.payload, DEVICE_SETTINGS_V1_ONLY_FIELDS, 'Protocol V2');
|
|
46890
46922
|
const capabilities = getDeviceSettingsCapabilities(this.device.getCurrentDeviceType(), 'V2');
|
|
46891
46923
|
assertProtocolV2SettingValues(this.payload, capabilities);
|
|
@@ -46908,7 +46940,7 @@ class DeviceSettings extends BaseMethod {
|
|
|
46908
46940
|
const res = yield this.device.commands.typedCall('DeviceSettingsPageShow', 'Success', {
|
|
46909
46941
|
page: hdTransport.DeviceSettingsPage.DevicePassphrase,
|
|
46910
46942
|
});
|
|
46911
|
-
const updated = yield
|
|
46943
|
+
const updated = yield refreshStatusAndSettings();
|
|
46912
46944
|
const lockedAfterDisabling = requestedPassphrase === false &&
|
|
46913
46945
|
current.status.unlocked === true &&
|
|
46914
46946
|
updated.status.unlocked === false;
|
|
@@ -46926,7 +46958,7 @@ class DeviceSettings extends BaseMethod {
|
|
|
46926
46958
|
const res = yield this.device.commands.typedCall('DeviceSettingsPageShow', 'Success', {
|
|
46927
46959
|
page: hdTransport.DeviceSettingsPage.DeviceAirgap,
|
|
46928
46960
|
});
|
|
46929
|
-
const updated = yield
|
|
46961
|
+
const updated = yield refreshStatusAndSettings();
|
|
46930
46962
|
if (updated.settings.airgapMode !== requestedAirgap) {
|
|
46931
46963
|
throw hdShared.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 air-gap setting did not reach the requested value.');
|
|
46932
46964
|
}
|
|
@@ -46938,7 +46970,7 @@ class DeviceSettings extends BaseMethod {
|
|
|
46938
46970
|
const res = yield this.device.commands.typedCall('DeviceSettingsSet', 'Success', {
|
|
46939
46971
|
settings,
|
|
46940
46972
|
});
|
|
46941
|
-
|
|
46973
|
+
yield refreshStatusAndSettings();
|
|
46942
46974
|
return res.message;
|
|
46943
46975
|
}
|
|
46944
46976
|
assertSettingsSupported(this.payload, DEVICE_SETTINGS_V2_ONLY_FIELDS, 'Protocol V1');
|
|
@@ -47303,7 +47335,7 @@ const getInfo = ({ features, updateType, targetVersion, firmwareType }) => {
|
|
|
47303
47335
|
const NEW_BOOT_UPRATE_FIRMWARE_VERSION = '2.4.5';
|
|
47304
47336
|
const SESSION_ERROR$2 = 'session not found';
|
|
47305
47337
|
const FIRMWARE_UPDATE_CONFIRM$1 = 'Firmware install confirmed';
|
|
47306
|
-
const Log$
|
|
47338
|
+
const Log$b = getLogger(exports.LoggerNames.Method);
|
|
47307
47339
|
const isDeviceDisconnectedError$1 = (error) => {
|
|
47308
47340
|
const message = error instanceof Error ? error.message : String(error !== null && error !== void 0 ? error : '');
|
|
47309
47341
|
return (message.includes('device was disconnected') ||
|
|
@@ -47352,13 +47384,13 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload, r
|
|
|
47352
47384
|
const newFeatures = yield typedCall('GetFeatures', 'Features', {});
|
|
47353
47385
|
const deviceBootloaderVersion = getDeviceBootloaderVersion(buildProtocolV1FeaturesPayload(newFeatures.message, device.features)).join('.');
|
|
47354
47386
|
const supportUpgradeFileHeader = semver__default["default"].gte(deviceBootloaderVersion, '2.1.0');
|
|
47355
|
-
Log$
|
|
47387
|
+
Log$b.debug('supportUpgradeFileHeader:', supportUpgradeFileHeader);
|
|
47356
47388
|
if (supportUpgradeFileHeader) {
|
|
47357
47389
|
const HEADER_SIZE = 1024;
|
|
47358
47390
|
if (payload.byteLength < HEADER_SIZE) {
|
|
47359
47391
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `firmware payload too small: ${payload.byteLength} bytes, expected at least ${HEADER_SIZE} bytes`);
|
|
47360
47392
|
}
|
|
47361
|
-
Log$
|
|
47393
|
+
Log$b.debug('Uploading firmware header:', {
|
|
47362
47394
|
size: HEADER_SIZE,
|
|
47363
47395
|
totalSize: payload.byteLength,
|
|
47364
47396
|
});
|
|
@@ -47370,18 +47402,18 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload, r
|
|
|
47370
47402
|
});
|
|
47371
47403
|
const isUnknownMessage = (_b = (_a = headerRes.message) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.includes('Failure_UnknownMessage');
|
|
47372
47404
|
if (headerRes.type !== 'Success' && !isUnknownMessage) {
|
|
47373
|
-
Log$
|
|
47405
|
+
Log$b.error('Firmware header upload failed:', headerRes);
|
|
47374
47406
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'failed to upload firmware header');
|
|
47375
47407
|
}
|
|
47376
47408
|
}
|
|
47377
47409
|
catch (error) {
|
|
47378
|
-
Log$
|
|
47410
|
+
Log$b.error('Firmware header upload failed:', error);
|
|
47379
47411
|
const message = error instanceof Error ? error.message : String(error !== null && error !== void 0 ? error : '');
|
|
47380
47412
|
if (!message.includes('Failure_UnknownMessage')) {
|
|
47381
47413
|
throw error;
|
|
47382
47414
|
}
|
|
47383
47415
|
}
|
|
47384
|
-
Log$
|
|
47416
|
+
Log$b.debug('Firmware header uploaded successfully');
|
|
47385
47417
|
}
|
|
47386
47418
|
}
|
|
47387
47419
|
const eraseCommand = isFirmware ? 'FirmwareErase' : 'FirmwareErase_ex';
|
|
@@ -47399,7 +47431,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload, r
|
|
|
47399
47431
|
}
|
|
47400
47432
|
catch (error) {
|
|
47401
47433
|
if (isDeviceDisconnectedError$1(error)) {
|
|
47402
|
-
Log$
|
|
47434
|
+
Log$b.log('Rebooting device');
|
|
47403
47435
|
updateResponse = {
|
|
47404
47436
|
type: 'Success',
|
|
47405
47437
|
message: { message: FIRMWARE_UPDATE_CONFIRM$1 },
|
|
@@ -47485,7 +47517,7 @@ const newTouchUpdateProcess = (updateType, postMessage, device, { payload }, reb
|
|
|
47485
47517
|
}
|
|
47486
47518
|
catch (error) {
|
|
47487
47519
|
if (isDeviceDisconnectedError$1(error)) {
|
|
47488
|
-
Log$
|
|
47520
|
+
Log$b.log('Rebooting device');
|
|
47489
47521
|
response = {
|
|
47490
47522
|
type: 'Success',
|
|
47491
47523
|
message: { message: FIRMWARE_UPDATE_CONFIRM$1 },
|
|
@@ -47516,7 +47548,7 @@ const newTouchUpdateProcess = (updateType, postMessage, device, { payload }, reb
|
|
|
47516
47548
|
]);
|
|
47517
47549
|
}
|
|
47518
47550
|
catch (e) {
|
|
47519
|
-
Log$
|
|
47551
|
+
Log$b.log('catch Bluetooth error when device is restarting: ', e);
|
|
47520
47552
|
}
|
|
47521
47553
|
}
|
|
47522
47554
|
else {
|
|
@@ -47537,7 +47569,7 @@ const newTouchUpdateProcess = (updateType, postMessage, device, { payload }, reb
|
|
|
47537
47569
|
}
|
|
47538
47570
|
catch (error) {
|
|
47539
47571
|
console.error('Device reconnect failed: ', error);
|
|
47540
|
-
Log$
|
|
47572
|
+
Log$b.error('Device reconnect failed:', error);
|
|
47541
47573
|
yield wait(1000);
|
|
47542
47574
|
}
|
|
47543
47575
|
}
|
|
@@ -47577,7 +47609,7 @@ const emmcFileWriteWithRetry = (device, filePath, chunkLength, offset, chunk, ov
|
|
|
47577
47609
|
return result;
|
|
47578
47610
|
}
|
|
47579
47611
|
catch (error) {
|
|
47580
|
-
Log$
|
|
47612
|
+
Log$b.error(`emmcWrite error: `, error);
|
|
47581
47613
|
retryCount--;
|
|
47582
47614
|
if (retryCount === 0) {
|
|
47583
47615
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.EmmcFileWriteFirmwareError, 'transfer data error');
|
|
@@ -47722,7 +47754,7 @@ class DeviceFullyUploadResource extends BaseMethod {
|
|
|
47722
47754
|
}
|
|
47723
47755
|
}
|
|
47724
47756
|
|
|
47725
|
-
const Log$
|
|
47757
|
+
const Log$a = getLogger(exports.LoggerNames.Method);
|
|
47726
47758
|
const SESSION_ERROR$1 = 'session not found';
|
|
47727
47759
|
const FIRMWARE_UPDATE_CONFIRM = 'Firmware install confirmed';
|
|
47728
47760
|
const isDeviceDisconnectedError = (error) => {
|
|
@@ -47748,12 +47780,9 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
|
47748
47780
|
type,
|
|
47749
47781
|
}));
|
|
47750
47782
|
};
|
|
47751
|
-
this.postProgressMessage = (progress, progressType) => {
|
|
47752
|
-
this.postMessage(createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
|
|
47753
|
-
|
|
47754
|
-
progress,
|
|
47755
|
-
progressType,
|
|
47756
|
-
}));
|
|
47783
|
+
this.postProgressMessage = (progress, progressType, metrics) => {
|
|
47784
|
+
this.postMessage(createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, Object.assign({ device: this.device.toMessageObject(), progress,
|
|
47785
|
+
progressType }, metrics)));
|
|
47757
47786
|
};
|
|
47758
47787
|
}
|
|
47759
47788
|
init() { }
|
|
@@ -47801,7 +47830,7 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
|
47801
47830
|
this.checkPromise = hdShared.createDeferred();
|
|
47802
47831
|
const env = DataManager.getSettings('env');
|
|
47803
47832
|
const isBleReconnect = connectId && DataManager.isBleConnect(env);
|
|
47804
|
-
Log$
|
|
47833
|
+
Log$a.log('FirmwareUpdateBaseMethod [checkDeviceToBootloader] isBleReconnect: ', isBleReconnect);
|
|
47805
47834
|
let isFirstCheck = true;
|
|
47806
47835
|
let checkCount = 0;
|
|
47807
47836
|
let hasPromptedWebDevice = false;
|
|
@@ -47812,10 +47841,10 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
|
47812
47841
|
const intervalTimer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
47813
47842
|
var _c, _d, _e, _f;
|
|
47814
47843
|
checkCount += 1;
|
|
47815
|
-
Log$
|
|
47844
|
+
Log$a.log('FirmwareUpdateBaseMethod [checkDeviceToBootloader] isFirstCheck: ', isFirstCheck);
|
|
47816
47845
|
if (isTouchOrProDevice && isFirstCheck) {
|
|
47817
47846
|
isFirstCheck = false;
|
|
47818
|
-
Log$
|
|
47847
|
+
Log$a.log('FirmwareUpdateBaseMethod [checkDeviceToBootloader] wait 3000ms');
|
|
47819
47848
|
yield wait(3000);
|
|
47820
47849
|
}
|
|
47821
47850
|
if (checkCount > 4 &&
|
|
@@ -47835,7 +47864,7 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
|
47835
47864
|
catch (e) {
|
|
47836
47865
|
clearInterval(intervalTimer);
|
|
47837
47866
|
clearTimeout(timeoutTimer);
|
|
47838
|
-
Log$
|
|
47867
|
+
Log$a.log('FirmwareUpdateBaseMethod [checkDeviceToBootloader] _promptDeviceInBootloaderForWebDevice failed: ', e);
|
|
47839
47868
|
(_c = this.checkPromise) === null || _c === void 0 ? void 0 : _c.reject(e);
|
|
47840
47869
|
}
|
|
47841
47870
|
finally {
|
|
@@ -47853,7 +47882,7 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
|
47853
47882
|
}
|
|
47854
47883
|
}
|
|
47855
47884
|
catch (e) {
|
|
47856
|
-
Log$
|
|
47885
|
+
Log$a.log('catch Bluetooth error when device is restarting: ', e);
|
|
47857
47886
|
}
|
|
47858
47887
|
}
|
|
47859
47888
|
else {
|
|
@@ -47936,7 +47965,7 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
|
47936
47965
|
}
|
|
47937
47966
|
catch (error) {
|
|
47938
47967
|
if (isDeviceDisconnectedError(error)) {
|
|
47939
|
-
Log$
|
|
47968
|
+
Log$a.log('Rebooting device');
|
|
47940
47969
|
updateResponse = {
|
|
47941
47970
|
type: 'Success',
|
|
47942
47971
|
message: { message: FIRMWARE_UPDATE_CONFIRM },
|
|
@@ -48026,7 +48055,7 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
|
48026
48055
|
return result;
|
|
48027
48056
|
}
|
|
48028
48057
|
catch (error) {
|
|
48029
|
-
Log$
|
|
48058
|
+
Log$a.error(`emmcWrite error: `, error);
|
|
48030
48059
|
retryCount--;
|
|
48031
48060
|
if (retryCount === 0) {
|
|
48032
48061
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.EmmcFileWriteFirmwareError, 'transfer data error');
|
|
@@ -48230,7 +48259,7 @@ class GetNextU2FCounter extends BaseMethod {
|
|
|
48230
48259
|
}
|
|
48231
48260
|
}
|
|
48232
48261
|
|
|
48233
|
-
const Log$
|
|
48262
|
+
const Log$9 = getLogger(exports.LoggerNames.Method);
|
|
48234
48263
|
class FirmwareUpdate extends BaseMethod {
|
|
48235
48264
|
constructor() {
|
|
48236
48265
|
super(...arguments);
|
|
@@ -48268,7 +48297,7 @@ class FirmwareUpdate extends BaseMethod {
|
|
|
48268
48297
|
this.checkPromise = hdShared.createDeferred();
|
|
48269
48298
|
const env = DataManager.getSettings('env');
|
|
48270
48299
|
const isBleReconnect = connectId && DataManager.isBleConnect(env);
|
|
48271
|
-
Log$
|
|
48300
|
+
Log$9.log('FirmwareUpdate [checkDeviceToBootloader] isBleReconnect: ', isBleReconnect);
|
|
48272
48301
|
const intervalTimer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
48273
48302
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
48274
48303
|
if (isBleReconnect) {
|
|
@@ -48281,7 +48310,7 @@ class FirmwareUpdate extends BaseMethod {
|
|
|
48281
48310
|
}
|
|
48282
48311
|
}
|
|
48283
48312
|
catch (e) {
|
|
48284
|
-
Log$
|
|
48313
|
+
Log$9.log('catch Bluetooth error when device is restarting: ', e);
|
|
48285
48314
|
}
|
|
48286
48315
|
}
|
|
48287
48316
|
else {
|
|
@@ -48337,7 +48366,7 @@ class FirmwareUpdate extends BaseMethod {
|
|
|
48337
48366
|
if (e instanceof hdShared.HardwareError) {
|
|
48338
48367
|
return Promise.reject(e);
|
|
48339
48368
|
}
|
|
48340
|
-
Log$
|
|
48369
|
+
Log$9.log('auto go to bootloader mode failed: ', e);
|
|
48341
48370
|
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure));
|
|
48342
48371
|
}
|
|
48343
48372
|
}
|
|
@@ -48377,7 +48406,7 @@ class FirmwareUpdate extends BaseMethod {
|
|
|
48377
48406
|
}
|
|
48378
48407
|
}
|
|
48379
48408
|
|
|
48380
|
-
const Log$
|
|
48409
|
+
const Log$8 = getLogger(exports.LoggerNames.Method);
|
|
48381
48410
|
const FIRMWARE_DOWNLOAD_REQUEST_OPTIONS = {
|
|
48382
48411
|
connectTimeoutMs: 60000,
|
|
48383
48412
|
readTimeoutMs: 60000,
|
|
@@ -48493,7 +48522,7 @@ class FirmwareUpdateV2 extends BaseMethod {
|
|
|
48493
48522
|
this.checkPromise = hdShared.createDeferred();
|
|
48494
48523
|
const env = DataManager.getSettings('env');
|
|
48495
48524
|
const isBleReconnect = connectId && DataManager.isBleConnect(env);
|
|
48496
|
-
Log$
|
|
48525
|
+
Log$8.log('FirmwareUpdateV2 [checkDeviceToBootloader] isBleReconnect: ', isBleReconnect);
|
|
48497
48526
|
let isFirstCheck = true;
|
|
48498
48527
|
let checkCount = 0;
|
|
48499
48528
|
let timeoutTimer;
|
|
@@ -48502,10 +48531,10 @@ class FirmwareUpdateV2 extends BaseMethod {
|
|
|
48502
48531
|
const intervalTimer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
48503
48532
|
var _b, _c, _d, _e;
|
|
48504
48533
|
checkCount += 1;
|
|
48505
|
-
Log$
|
|
48534
|
+
Log$8.log('FirmwareUpdateV2 [checkDeviceToBootloader] isFirstCheck: ', isFirstCheck);
|
|
48506
48535
|
if (isTouchOrProDevice && isFirstCheck) {
|
|
48507
48536
|
isFirstCheck = false;
|
|
48508
|
-
Log$
|
|
48537
|
+
Log$8.log('FirmwareUpdateV2 [checkDeviceToBootloader] wait 3000ms');
|
|
48509
48538
|
yield wait(3000);
|
|
48510
48539
|
}
|
|
48511
48540
|
if (checkCount > 4 &&
|
|
@@ -48521,7 +48550,7 @@ class FirmwareUpdateV2 extends BaseMethod {
|
|
|
48521
48550
|
}
|
|
48522
48551
|
}
|
|
48523
48552
|
catch (e) {
|
|
48524
|
-
Log$
|
|
48553
|
+
Log$8.log('FirmwareUpdateV2 [checkDeviceToBootloader] promptDeviceInBootloaderForWebDevice failed: ', e);
|
|
48525
48554
|
(_b = this.checkPromise) === null || _b === void 0 ? void 0 : _b.reject(e);
|
|
48526
48555
|
}
|
|
48527
48556
|
return;
|
|
@@ -48536,7 +48565,7 @@ class FirmwareUpdateV2 extends BaseMethod {
|
|
|
48536
48565
|
}
|
|
48537
48566
|
}
|
|
48538
48567
|
catch (e) {
|
|
48539
|
-
Log$
|
|
48568
|
+
Log$8.log('catch Bluetooth error when device is restarting: ', e);
|
|
48540
48569
|
}
|
|
48541
48570
|
}
|
|
48542
48571
|
else {
|
|
@@ -48719,7 +48748,7 @@ class FirmwareUpdateV2 extends BaseMethod {
|
|
|
48719
48748
|
}
|
|
48720
48749
|
}
|
|
48721
48750
|
|
|
48722
|
-
const Log$
|
|
48751
|
+
const Log$7 = getLogger(exports.LoggerNames.Method);
|
|
48723
48752
|
const MIN_UPDATE_V3_BOOTLOADER_VERSION = '2.8.0';
|
|
48724
48753
|
class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
48725
48754
|
constructor() {
|
|
@@ -48760,7 +48789,7 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
48760
48789
|
}
|
|
48761
48790
|
run() {
|
|
48762
48791
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48763
|
-
Log$
|
|
48792
|
+
Log$7.debug('FirmwareUpdateV3 strategy: Protocol V1');
|
|
48764
48793
|
return this.runProtocolV1();
|
|
48765
48794
|
});
|
|
48766
48795
|
}
|
|
@@ -48831,7 +48860,7 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
48831
48860
|
const resource = (yield getSysResourceBinary(resourceUrl)).binary;
|
|
48832
48861
|
return resource;
|
|
48833
48862
|
}
|
|
48834
|
-
Log$
|
|
48863
|
+
Log$7.warn('No resource url found');
|
|
48835
48864
|
return null;
|
|
48836
48865
|
});
|
|
48837
48866
|
}
|
|
@@ -48956,7 +48985,7 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
48956
48985
|
yield this.startEmmcFirmwareUpdate({ path: '0:updates' });
|
|
48957
48986
|
}
|
|
48958
48987
|
catch (error) {
|
|
48959
|
-
Log$
|
|
48988
|
+
Log$7.error('triggerFirmwareUpdateEmmc error: ', error);
|
|
48960
48989
|
if (error === null || error === void 0 ? void 0 : error.errorCode) {
|
|
48961
48990
|
const unexpectedError = [
|
|
48962
48991
|
hdShared.HardwareErrorCode.ActionCancelled,
|
|
@@ -49017,7 +49046,7 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
49017
49046
|
yield hdShared.wait(1000);
|
|
49018
49047
|
}
|
|
49019
49048
|
catch (error) {
|
|
49020
|
-
Log$
|
|
49049
|
+
Log$7.log('getFeatures error', error);
|
|
49021
49050
|
let shouldReconnect = true;
|
|
49022
49051
|
const progress = this.extractUpdateModeProgress(error);
|
|
49023
49052
|
if (progress !== null) {
|
|
@@ -49115,7 +49144,7 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
49115
49144
|
return;
|
|
49116
49145
|
}
|
|
49117
49146
|
catch (e) {
|
|
49118
|
-
Log$
|
|
49147
|
+
Log$7.log('catch Bluetooth error when device is restarting: ', e);
|
|
49119
49148
|
}
|
|
49120
49149
|
}
|
|
49121
49150
|
else {
|
|
@@ -49130,7 +49159,7 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
49130
49159
|
yield this._promptDeviceForSwitchFirmwareWebDevice();
|
|
49131
49160
|
}
|
|
49132
49161
|
catch (e) {
|
|
49133
|
-
Log$
|
|
49162
|
+
Log$7.log('WebUSB re-authorization failed: ', e);
|
|
49134
49163
|
}
|
|
49135
49164
|
webUsbCheckCount = 0;
|
|
49136
49165
|
}
|
|
@@ -49153,7 +49182,7 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
49153
49182
|
}
|
|
49154
49183
|
catch (error) {
|
|
49155
49184
|
console.error('Device reconnect failed: ', error);
|
|
49156
|
-
Log$
|
|
49185
|
+
Log$7.error('Device reconnect failed:', error);
|
|
49157
49186
|
yield hdShared.wait(1000);
|
|
49158
49187
|
}
|
|
49159
49188
|
}
|
|
@@ -49162,6 +49191,238 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
|
|
|
49162
49191
|
}
|
|
49163
49192
|
}
|
|
49164
49193
|
|
|
49194
|
+
const Log$6 = getLogger(exports.LoggerNames.Method);
|
|
49195
|
+
const MIN_FILE_CHUNK_SIZE = 64;
|
|
49196
|
+
const FILE_TRANSFER_RATE_WINDOW_MS = 1000;
|
|
49197
|
+
const FILE_TRANSFER_LOG_INTERVAL_MS = 10000;
|
|
49198
|
+
const SESSION_ERROR = 'session not found';
|
|
49199
|
+
function formatFileTransferRate(bytesPerSecond) {
|
|
49200
|
+
return (Math.max(bytesPerSecond, 0) / 1024).toFixed(2);
|
|
49201
|
+
}
|
|
49202
|
+
function getAverageFileTransferRate(transferredBytes, elapsedMs) {
|
|
49203
|
+
if (elapsedMs <= 0)
|
|
49204
|
+
return 0;
|
|
49205
|
+
return Math.round((Math.max(transferredBytes, 0) / elapsedMs) * 1000);
|
|
49206
|
+
}
|
|
49207
|
+
function getFileTransferTransport() {
|
|
49208
|
+
const env = DataManager.getSettings('env');
|
|
49209
|
+
return env && DataManager.isBleConnect(env) ? 'BLE' : String(env !== null && env !== void 0 ? env : 'unknown');
|
|
49210
|
+
}
|
|
49211
|
+
function logFileTransferMetrics({ transport, status, transferredBytes, totalBytes, elapsedMs, rateBytesPerSecond, }) {
|
|
49212
|
+
Log$6.log(`[FileWrite] metrics transport=${transport} status=${status} bytes=${transferredBytes}/${totalBytes} elapsed=${(elapsedMs / 1000).toFixed(2)}s speed=${formatFileTransferRate(rateBytesPerSecond)} KiB/s`);
|
|
49213
|
+
}
|
|
49214
|
+
function isProtocolV2ResponseTimeout(error) {
|
|
49215
|
+
var _a, _b;
|
|
49216
|
+
if (!error || typeof error !== 'object')
|
|
49217
|
+
return false;
|
|
49218
|
+
const candidate = error;
|
|
49219
|
+
const code = (_a = candidate.errorCode) !== null && _a !== void 0 ? _a : candidate.code;
|
|
49220
|
+
return (code === hdShared.HardwareErrorCode.BleTimeoutError ||
|
|
49221
|
+
code === 'response-timeout' ||
|
|
49222
|
+
/(?:BLE|Lowlevel|Protocol V2) response timeout/i.test((_b = candidate.message) !== null && _b !== void 0 ? _b : ''));
|
|
49223
|
+
}
|
|
49224
|
+
function getProtocolV2FileChunkLimit() {
|
|
49225
|
+
const env = DataManager.getSettings('env');
|
|
49226
|
+
return env && DataManager.isBleConnect(env)
|
|
49227
|
+
? hdTransport.PROTOCOL_V2_BLE_FILE_CHUNK_SIZE
|
|
49228
|
+
: hdTransport.PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
49229
|
+
}
|
|
49230
|
+
function dataToUint8Array(data) {
|
|
49231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49232
|
+
if (typeof data === 'string')
|
|
49233
|
+
return new TextEncoder().encode(data);
|
|
49234
|
+
if (data instanceof ArrayBuffer)
|
|
49235
|
+
return new Uint8Array(data);
|
|
49236
|
+
if (ArrayBuffer.isView(data)) {
|
|
49237
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
49238
|
+
}
|
|
49239
|
+
if (typeof Blob !== 'undefined' && data instanceof Blob) {
|
|
49240
|
+
return new Uint8Array(yield data.arrayBuffer());
|
|
49241
|
+
}
|
|
49242
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Unsupported FilesystemFileWrite data');
|
|
49243
|
+
});
|
|
49244
|
+
}
|
|
49245
|
+
function normalizeChunkSize(value, maxChunkSize) {
|
|
49246
|
+
const numeric = Number(value);
|
|
49247
|
+
if (!Number.isFinite(numeric) || numeric <= 0)
|
|
49248
|
+
return maxChunkSize;
|
|
49249
|
+
return Math.min(Math.max(Math.floor(numeric), MIN_FILE_CHUNK_SIZE), maxChunkSize);
|
|
49250
|
+
}
|
|
49251
|
+
function getDeviceTransferProgress(before, after, total) {
|
|
49252
|
+
if (!Number.isFinite(total) || total <= 0)
|
|
49253
|
+
return 100;
|
|
49254
|
+
if (before <= 0 && after < total)
|
|
49255
|
+
return 0;
|
|
49256
|
+
if (after >= total)
|
|
49257
|
+
return 100;
|
|
49258
|
+
return Math.min(Math.max(Math.ceil((after / total) * 100), 1), 99);
|
|
49259
|
+
}
|
|
49260
|
+
function getConfirmedProgress(processed, total, written, length) {
|
|
49261
|
+
if (Number.isFinite(processed) && Number.isFinite(total) && total > 0) {
|
|
49262
|
+
if (processed >= total)
|
|
49263
|
+
return 100;
|
|
49264
|
+
return Math.min(Math.max(Math.floor((processed / total) * 100), 0), 99);
|
|
49265
|
+
}
|
|
49266
|
+
if (length > 0)
|
|
49267
|
+
return written >= length ? 100 : Math.floor((written / length) * 100);
|
|
49268
|
+
return 100;
|
|
49269
|
+
}
|
|
49270
|
+
function writeProtocolV2File(options) {
|
|
49271
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
49272
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49273
|
+
(_a = options.throwIfAborted) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
49274
|
+
const data = yield dataToUint8Array(options.data);
|
|
49275
|
+
const dataLength = data.byteLength;
|
|
49276
|
+
const startOffset = Number.isFinite(options.offset) && Number(options.offset) > 0 ? Number(options.offset) : 0;
|
|
49277
|
+
const totalSize = Number.isFinite(options.totalSize) && Number(options.totalSize) > 0
|
|
49278
|
+
? Number(options.totalSize)
|
|
49279
|
+
: startOffset + dataLength;
|
|
49280
|
+
if (totalSize < startOffset + dataLength) {
|
|
49281
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite totalSize ${totalSize} is smaller than offset + data length ${startOffset + dataLength}`);
|
|
49282
|
+
}
|
|
49283
|
+
const chunkSize = normalizeChunkSize((_b = options.chunkSize) !== null && _b !== void 0 ? _b : options.chunkLen, getProtocolV2FileChunkLimit());
|
|
49284
|
+
let written = 0;
|
|
49285
|
+
let chunks = 0;
|
|
49286
|
+
let lastMessage;
|
|
49287
|
+
const startTime = Date.now();
|
|
49288
|
+
let rateWindowStartedAt = startTime;
|
|
49289
|
+
let rateWindowStartedBytes = 0;
|
|
49290
|
+
let rateBytesPerSecond;
|
|
49291
|
+
let lastConfirmedAt = startTime;
|
|
49292
|
+
let logWindowStartedAt = startTime;
|
|
49293
|
+
let logWindowStartedBytes = 0;
|
|
49294
|
+
const transport = getFileTransferTransport();
|
|
49295
|
+
try {
|
|
49296
|
+
while (written < dataLength) {
|
|
49297
|
+
(_c = options.throwIfAborted) === null || _c === void 0 ? void 0 : _c.call(options);
|
|
49298
|
+
const chunk = data.slice(written, Math.min(written + chunkSize, dataLength));
|
|
49299
|
+
const offset = startOffset + written;
|
|
49300
|
+
const progress = (_f = (_d = options.uiPercentage) !== null && _d !== void 0 ? _d : (_e = options.getUiPercentage) === null || _e === void 0 ? void 0 : _e.call(options, {
|
|
49301
|
+
offset,
|
|
49302
|
+
chunkLength: chunk.byteLength,
|
|
49303
|
+
totalSize,
|
|
49304
|
+
})) !== null && _f !== void 0 ? _f : getDeviceTransferProgress(offset, offset + chunk.byteLength, totalSize);
|
|
49305
|
+
const request = {
|
|
49306
|
+
file: { path: options.path, offset, total_size: totalSize, data: chunk },
|
|
49307
|
+
overwrite: chunks === 0 ? (_g = options.overwrite) !== null && _g !== void 0 ? _g : false : false,
|
|
49308
|
+
append: (_h = options.append) !== null && _h !== void 0 ? _h : false,
|
|
49309
|
+
ui_percentage: progress,
|
|
49310
|
+
};
|
|
49311
|
+
const maxChunkRetries = Math.max(Math.floor((_j = options.maxChunkRetries) !== null && _j !== void 0 ? _j : 0), 0);
|
|
49312
|
+
let retryCount = 0;
|
|
49313
|
+
let response;
|
|
49314
|
+
let isWritePending = true;
|
|
49315
|
+
while (isWritePending) {
|
|
49316
|
+
try {
|
|
49317
|
+
const callOptions = options.writeWithResponse === undefined
|
|
49318
|
+
? { timeoutMs: options.timeoutMs }
|
|
49319
|
+
: Object.assign(Object.assign({}, (options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs })), { writeWithResponse: options.writeWithResponse });
|
|
49320
|
+
response = yield options.commands.typedCall('FilesystemFileWrite', 'FilesystemFile', request, callOptions);
|
|
49321
|
+
isWritePending = false;
|
|
49322
|
+
}
|
|
49323
|
+
catch (error) {
|
|
49324
|
+
if (retryCount >= maxChunkRetries || !isProtocolV2ResponseTimeout(error))
|
|
49325
|
+
throw error;
|
|
49326
|
+
retryCount += 1;
|
|
49327
|
+
(_k = options.throwIfAborted) === null || _k === void 0 ? void 0 : _k.call(options);
|
|
49328
|
+
}
|
|
49329
|
+
}
|
|
49330
|
+
if (!response) {
|
|
49331
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'FilesystemFileWrite completed without a response');
|
|
49332
|
+
}
|
|
49333
|
+
const responseType = response.type;
|
|
49334
|
+
if (responseType && responseType !== 'FilesystemFile') {
|
|
49335
|
+
const responseError = (_l = response.message) === null || _l === void 0 ? void 0 : _l.error;
|
|
49336
|
+
if (typeof responseError === 'string' && responseError.includes(SESSION_ERROR)) {
|
|
49337
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, SESSION_ERROR);
|
|
49338
|
+
}
|
|
49339
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite received unexpected response ${responseType}`);
|
|
49340
|
+
}
|
|
49341
|
+
(_m = options.throwIfAborted) === null || _m === void 0 ? void 0 : _m.call(options);
|
|
49342
|
+
lastMessage = response.message;
|
|
49343
|
+
const rawProcessedByte = (_o = response.message) === null || _o === void 0 ? void 0 : _o.processed_byte;
|
|
49344
|
+
const processedByte = Number(rawProcessedByte);
|
|
49345
|
+
if (rawProcessedByte !== undefined &&
|
|
49346
|
+
(!Number.isFinite(processedByte) ||
|
|
49347
|
+
processedByte <= offset ||
|
|
49348
|
+
processedByte > offset + chunk.byteLength)) {
|
|
49349
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite invalid processed_byte ${processedByte}`);
|
|
49350
|
+
}
|
|
49351
|
+
written =
|
|
49352
|
+
rawProcessedByte === undefined ? written + chunk.byteLength : processedByte - startOffset;
|
|
49353
|
+
chunks += 1;
|
|
49354
|
+
const now = Date.now();
|
|
49355
|
+
lastConfirmedAt = now;
|
|
49356
|
+
const elapsedMs = now - startTime;
|
|
49357
|
+
const transferredBytes = Math.min(written, dataLength);
|
|
49358
|
+
const rateWindowElapsedMs = now - rateWindowStartedAt;
|
|
49359
|
+
if (rateWindowElapsedMs >= FILE_TRANSFER_RATE_WINDOW_MS) {
|
|
49360
|
+
const rateWindowBytes = Math.max(transferredBytes - rateWindowStartedBytes, 0);
|
|
49361
|
+
rateBytesPerSecond = Math.round((rateWindowBytes / rateWindowElapsedMs) * 1000);
|
|
49362
|
+
rateWindowStartedAt = now;
|
|
49363
|
+
rateWindowStartedBytes = transferredBytes;
|
|
49364
|
+
}
|
|
49365
|
+
else if (rateBytesPerSecond === undefined && elapsedMs > 0) {
|
|
49366
|
+
rateBytesPerSecond = Math.round((transferredBytes / elapsedMs) * 1000);
|
|
49367
|
+
}
|
|
49368
|
+
(_p = options.onProgress) === null || _p === void 0 ? void 0 : _p.call(options, {
|
|
49369
|
+
progress: getConfirmedProgress(startOffset + written, totalSize, written, dataLength),
|
|
49370
|
+
transferredBytes,
|
|
49371
|
+
totalBytes: dataLength,
|
|
49372
|
+
rateBytesPerSecond,
|
|
49373
|
+
elapsedMs,
|
|
49374
|
+
});
|
|
49375
|
+
const logWindowElapsedMs = now - logWindowStartedAt;
|
|
49376
|
+
if (logWindowElapsedMs >= FILE_TRANSFER_LOG_INTERVAL_MS && transferredBytes < dataLength) {
|
|
49377
|
+
const logWindowBytes = Math.max(transferredBytes - logWindowStartedBytes, 0);
|
|
49378
|
+
logFileTransferMetrics({
|
|
49379
|
+
transport,
|
|
49380
|
+
status: 'progress',
|
|
49381
|
+
transferredBytes,
|
|
49382
|
+
totalBytes: dataLength,
|
|
49383
|
+
elapsedMs,
|
|
49384
|
+
rateBytesPerSecond: getAverageFileTransferRate(logWindowBytes, logWindowElapsedMs),
|
|
49385
|
+
});
|
|
49386
|
+
logWindowStartedAt = now;
|
|
49387
|
+
logWindowStartedBytes = transferredBytes;
|
|
49388
|
+
}
|
|
49389
|
+
if (options.paceMs && options.paceMs > 0) {
|
|
49390
|
+
yield new Promise(resolve => {
|
|
49391
|
+
setTimeout(resolve, options.paceMs);
|
|
49392
|
+
});
|
|
49393
|
+
}
|
|
49394
|
+
}
|
|
49395
|
+
}
|
|
49396
|
+
catch (error) {
|
|
49397
|
+
const now = Date.now();
|
|
49398
|
+
const elapsedMs = Math.max(now - startTime, 0);
|
|
49399
|
+
const logWindowElapsedMs = Math.max(now - logWindowStartedAt, 0);
|
|
49400
|
+
const logWindowBytes = Math.max(written - logWindowStartedBytes, 0);
|
|
49401
|
+
logFileTransferMetrics({
|
|
49402
|
+
transport,
|
|
49403
|
+
status: 'failed',
|
|
49404
|
+
transferredBytes: written,
|
|
49405
|
+
totalBytes: dataLength,
|
|
49406
|
+
elapsedMs,
|
|
49407
|
+
rateBytesPerSecond: getAverageFileTransferRate(logWindowBytes, logWindowElapsedMs),
|
|
49408
|
+
});
|
|
49409
|
+
throw error;
|
|
49410
|
+
}
|
|
49411
|
+
const elapsedMs = Math.max(lastConfirmedAt - startTime, 0);
|
|
49412
|
+
const logWindowElapsedMs = Math.max(lastConfirmedAt - logWindowStartedAt, 0);
|
|
49413
|
+
const logWindowBytes = Math.max(written - logWindowStartedBytes, 0);
|
|
49414
|
+
logFileTransferMetrics({
|
|
49415
|
+
transport,
|
|
49416
|
+
status: 'completed',
|
|
49417
|
+
transferredBytes: written,
|
|
49418
|
+
totalBytes: dataLength,
|
|
49419
|
+
elapsedMs,
|
|
49420
|
+
rateBytesPerSecond: getAverageFileTransferRate(logWindowBytes, logWindowElapsedMs),
|
|
49421
|
+
});
|
|
49422
|
+
return Object.assign(Object.assign({}, lastMessage), { path: options.path, offset: startOffset, total_size: totalSize, processed_byte: startOffset + written, chunks });
|
|
49423
|
+
});
|
|
49424
|
+
}
|
|
49425
|
+
|
|
49165
49426
|
const ProtocolV2FirmwareTargetType = {
|
|
49166
49427
|
FW_MGMT_TARGET_INVALID: 0,
|
|
49167
49428
|
FW_MGMT_TARGET_CRATE: 1,
|
|
@@ -49259,7 +49520,6 @@ const INSTALLABLE_FIRMWARE_TARGET_IDS = new Set([
|
|
|
49259
49520
|
new Map(Object.entries(ProtocolV2FirmwareTargetType).flatMap(([key, value]) => INSTALLABLE_FIRMWARE_TARGET_IDS.has(value) ? [[key, value]] : []));
|
|
49260
49521
|
|
|
49261
49522
|
const Log$5 = getLogger(exports.LoggerNames.Method);
|
|
49262
|
-
const SESSION_ERROR = 'session not found';
|
|
49263
49523
|
const PROTOCOL_V2_BOOTLOADER_RECONNECT_TIMEOUT = 90 * 1000;
|
|
49264
49524
|
const PROTOCOL_V2_FINAL_RECONNECT_TIMEOUT = 3 * 60 * 1000;
|
|
49265
49525
|
const PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT = 5 * 1000;
|
|
@@ -49970,14 +50230,15 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
49970
50230
|
}
|
|
49971
50231
|
if (this.isProtocolV2BootloaderMode()) {
|
|
49972
50232
|
Log$5.debug('Protocol V2 device is already in bootloader mode, skip reboot');
|
|
50233
|
+
this.postTipMessage(exports.FirmwareUpdateTipMessage.GoToBootloaderSuccess);
|
|
49973
50234
|
return false;
|
|
49974
50235
|
}
|
|
49975
50236
|
try {
|
|
49976
50237
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.AutoRebootToBootloader);
|
|
49977
50238
|
yield this.protocolV2Reboot(hdTransport.DeviceRebootType.Bootloader);
|
|
49978
|
-
this.postTipMessage(exports.FirmwareUpdateTipMessage.GoToBootloaderSuccess);
|
|
49979
50239
|
yield hdShared.wait(1000);
|
|
49980
50240
|
yield this.waitForProtocolV2BootloaderMode();
|
|
50241
|
+
this.postTipMessage(exports.FirmwareUpdateTipMessage.GoToBootloaderSuccess);
|
|
49981
50242
|
return true;
|
|
49982
50243
|
}
|
|
49983
50244
|
catch (error) {
|
|
@@ -50433,29 +50694,43 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
50433
50694
|
protocolV2WriteWholeFile({ payload, filePath, processedSize, totalSize, onTransferredBytes, }) {
|
|
50434
50695
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50435
50696
|
const chunkSize = this.getProtocolV2FirmwareChunkSize();
|
|
50436
|
-
let offset = 0;
|
|
50437
50697
|
const getUploadProgress = (fileOffset) => {
|
|
50438
50698
|
if (totalSize !== undefined && processedSize !== undefined) {
|
|
50439
50699
|
return Math.min(Math.ceil(((processedSize + fileOffset) / totalSize) * 100), 99);
|
|
50440
50700
|
}
|
|
50441
50701
|
return Math.min(Math.ceil((fileOffset / payload.byteLength) * 100), 99);
|
|
50442
50702
|
};
|
|
50443
|
-
|
|
50444
|
-
|
|
50445
|
-
|
|
50446
|
-
|
|
50447
|
-
|
|
50448
|
-
|
|
50449
|
-
|
|
50450
|
-
|
|
50451
|
-
|
|
50452
|
-
|
|
50453
|
-
|
|
50454
|
-
|
|
50703
|
+
try {
|
|
50704
|
+
yield writeProtocolV2File({
|
|
50705
|
+
commands: this.device.getCommands(),
|
|
50706
|
+
path: filePath,
|
|
50707
|
+
data: payload,
|
|
50708
|
+
totalSize: payload.byteLength,
|
|
50709
|
+
chunkSize,
|
|
50710
|
+
overwrite: true,
|
|
50711
|
+
append: false,
|
|
50712
|
+
writeWithResponse: true,
|
|
50713
|
+
maxChunkRetries: 0,
|
|
50714
|
+
getUiPercentage: ({ offset, chunkLength }) => getProtocolV2DeviceTransferProgress((processedSize !== null && processedSize !== void 0 ? processedSize : 0) + offset, (processedSize !== null && processedSize !== void 0 ? processedSize : 0) + offset + chunkLength, totalSize !== null && totalSize !== void 0 ? totalSize : payload.byteLength),
|
|
50715
|
+
onProgress: progress => {
|
|
50716
|
+
const transferredBytes = (processedSize !== null && processedSize !== void 0 ? processedSize : 0) + progress.transferredBytes;
|
|
50717
|
+
onTransferredBytes === null || onTransferredBytes === void 0 ? void 0 : onTransferredBytes(transferredBytes);
|
|
50718
|
+
this.postProgressMessage(getUploadProgress(progress.transferredBytes), 'transferData', {
|
|
50719
|
+
transferredBytes,
|
|
50720
|
+
totalBytes: totalSize !== null && totalSize !== void 0 ? totalSize : payload.byteLength,
|
|
50721
|
+
rateBytesPerSecond: progress.rateBytesPerSecond,
|
|
50722
|
+
elapsedMs: progress.elapsedMs,
|
|
50723
|
+
});
|
|
50724
|
+
},
|
|
50725
|
+
});
|
|
50726
|
+
}
|
|
50727
|
+
catch (error) {
|
|
50728
|
+
if (error instanceof hdShared.HardwareError &&
|
|
50729
|
+
error.errorCode === hdShared.HardwareErrorCode.RuntimeError &&
|
|
50730
|
+
error.message.includes('FilesystemFileWrite')) {
|
|
50731
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.EmmcFileWriteFirmwareError, error.message);
|
|
50455
50732
|
}
|
|
50456
|
-
|
|
50457
|
-
onTransferredBytes === null || onTransferredBytes === void 0 ? void 0 : onTransferredBytes((processedSize !== null && processedSize !== void 0 ? processedSize : 0) + offset);
|
|
50458
|
-
this.postProgressMessage(getUploadProgress(offset), 'transferData');
|
|
50733
|
+
throw error;
|
|
50459
50734
|
}
|
|
50460
50735
|
return totalSize !== undefined ? (processedSize !== null && processedSize !== void 0 ? processedSize : 0) + payload.byteLength : 0;
|
|
50461
50736
|
});
|
|
@@ -50471,32 +50746,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
50471
50746
|
}
|
|
50472
50747
|
return env !== null && env !== void 0 ? env : 'unknown';
|
|
50473
50748
|
}
|
|
50474
|
-
fileWriteChunk(filePath, totalFileSize, offset, chunk, overwrite, progress) {
|
|
50475
|
-
var _a;
|
|
50476
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50477
|
-
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
50478
|
-
const writeRes = yield typedCall('FilesystemFileWrite', 'FilesystemFile', {
|
|
50479
|
-
file: {
|
|
50480
|
-
path: filePath,
|
|
50481
|
-
offset,
|
|
50482
|
-
total_size: totalFileSize,
|
|
50483
|
-
data: chunk,
|
|
50484
|
-
},
|
|
50485
|
-
overwrite,
|
|
50486
|
-
append: false,
|
|
50487
|
-
ui_percentage: progress !== null && progress !== void 0 ? progress : undefined,
|
|
50488
|
-
}, { writeWithResponse: true });
|
|
50489
|
-
if (writeRes.type !== 'FilesystemFile') {
|
|
50490
|
-
if (writeRes.type === 'CallMethodError') {
|
|
50491
|
-
if (((_a = writeRes.message.error) !== null && _a !== void 0 ? _a : '').indexOf(SESSION_ERROR) > -1) {
|
|
50492
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, SESSION_ERROR);
|
|
50493
|
-
}
|
|
50494
|
-
}
|
|
50495
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.EmmcFileWriteFirmwareError, 'transfer data error');
|
|
50496
|
-
}
|
|
50497
|
-
return writeRes;
|
|
50498
|
-
});
|
|
50499
|
-
}
|
|
50500
50749
|
recoverProtocolV2FileTransfer() {
|
|
50501
50750
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50502
50751
|
const env = DataManager.getSettings('env');
|
|
@@ -50654,158 +50903,6 @@ class DeviceGetOnboardingStatus extends BaseMethod {
|
|
|
50654
50903
|
}
|
|
50655
50904
|
}
|
|
50656
50905
|
|
|
50657
|
-
const MIN_FILE_CHUNK_SIZE = 64;
|
|
50658
|
-
const FILE_TRANSFER_RATE_WINDOW_MS = 1000;
|
|
50659
|
-
function isProtocolV2ResponseTimeout(error) {
|
|
50660
|
-
var _a, _b;
|
|
50661
|
-
if (!error || typeof error !== 'object')
|
|
50662
|
-
return false;
|
|
50663
|
-
const candidate = error;
|
|
50664
|
-
const code = (_a = candidate.errorCode) !== null && _a !== void 0 ? _a : candidate.code;
|
|
50665
|
-
return (code === hdShared.HardwareErrorCode.BleTimeoutError ||
|
|
50666
|
-
code === 'response-timeout' ||
|
|
50667
|
-
/(?:BLE|Lowlevel|Protocol V2) response timeout/i.test((_b = candidate.message) !== null && _b !== void 0 ? _b : ''));
|
|
50668
|
-
}
|
|
50669
|
-
function getProtocolV2FileChunkLimit() {
|
|
50670
|
-
const env = DataManager.getSettings('env');
|
|
50671
|
-
return env && DataManager.isBleConnect(env)
|
|
50672
|
-
? hdTransport.PROTOCOL_V2_BLE_FILE_CHUNK_SIZE
|
|
50673
|
-
: hdTransport.PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
50674
|
-
}
|
|
50675
|
-
function dataToUint8Array(data) {
|
|
50676
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50677
|
-
if (typeof data === 'string')
|
|
50678
|
-
return new TextEncoder().encode(data);
|
|
50679
|
-
if (data instanceof ArrayBuffer)
|
|
50680
|
-
return new Uint8Array(data);
|
|
50681
|
-
if (ArrayBuffer.isView(data)) {
|
|
50682
|
-
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
50683
|
-
}
|
|
50684
|
-
if (typeof Blob !== 'undefined' && data instanceof Blob) {
|
|
50685
|
-
return new Uint8Array(yield data.arrayBuffer());
|
|
50686
|
-
}
|
|
50687
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Unsupported FilesystemFileWrite data');
|
|
50688
|
-
});
|
|
50689
|
-
}
|
|
50690
|
-
function normalizeChunkSize(value, maxChunkSize) {
|
|
50691
|
-
const numeric = Number(value);
|
|
50692
|
-
if (!Number.isFinite(numeric) || numeric <= 0)
|
|
50693
|
-
return maxChunkSize;
|
|
50694
|
-
return Math.min(Math.max(Math.floor(numeric), MIN_FILE_CHUNK_SIZE), maxChunkSize);
|
|
50695
|
-
}
|
|
50696
|
-
function getDeviceTransferProgress(before, after, total) {
|
|
50697
|
-
if (!Number.isFinite(total) || total <= 0)
|
|
50698
|
-
return 100;
|
|
50699
|
-
if (before <= 0 && after < total)
|
|
50700
|
-
return 0;
|
|
50701
|
-
if (after >= total)
|
|
50702
|
-
return 100;
|
|
50703
|
-
return Math.min(Math.max(Math.ceil((after / total) * 100), 1), 99);
|
|
50704
|
-
}
|
|
50705
|
-
function getConfirmedProgress(processed, total, written, length) {
|
|
50706
|
-
if (Number.isFinite(processed) && Number.isFinite(total) && total > 0) {
|
|
50707
|
-
if (processed >= total)
|
|
50708
|
-
return 100;
|
|
50709
|
-
return Math.min(Math.max(Math.floor((processed / total) * 100), 0), 99);
|
|
50710
|
-
}
|
|
50711
|
-
if (length > 0)
|
|
50712
|
-
return written >= length ? 100 : Math.floor((written / length) * 100);
|
|
50713
|
-
return 100;
|
|
50714
|
-
}
|
|
50715
|
-
function writeProtocolV2File(options) {
|
|
50716
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
50717
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50718
|
-
(_a = options.throwIfAborted) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
50719
|
-
const data = yield dataToUint8Array(options.data);
|
|
50720
|
-
const dataLength = data.byteLength;
|
|
50721
|
-
const startOffset = Number.isFinite(options.offset) && Number(options.offset) > 0 ? Number(options.offset) : 0;
|
|
50722
|
-
const totalSize = Number.isFinite(options.totalSize) && Number(options.totalSize) > 0
|
|
50723
|
-
? Number(options.totalSize)
|
|
50724
|
-
: startOffset + dataLength;
|
|
50725
|
-
if (totalSize < startOffset + dataLength) {
|
|
50726
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite totalSize ${totalSize} is smaller than offset + data length ${startOffset + dataLength}`);
|
|
50727
|
-
}
|
|
50728
|
-
const chunkSize = normalizeChunkSize((_b = options.chunkSize) !== null && _b !== void 0 ? _b : options.chunkLen, getProtocolV2FileChunkLimit());
|
|
50729
|
-
let written = 0;
|
|
50730
|
-
let chunks = 0;
|
|
50731
|
-
let lastMessage;
|
|
50732
|
-
const startTime = Date.now();
|
|
50733
|
-
let rateWindowStartedAt = startTime;
|
|
50734
|
-
let rateWindowStartedBytes = 0;
|
|
50735
|
-
let rateBytesPerSecond;
|
|
50736
|
-
while (written < dataLength) {
|
|
50737
|
-
(_c = options.throwIfAborted) === null || _c === void 0 ? void 0 : _c.call(options);
|
|
50738
|
-
const chunk = data.slice(written, Math.min(written + chunkSize, dataLength));
|
|
50739
|
-
const offset = startOffset + written;
|
|
50740
|
-
const progress = (_d = options.uiPercentage) !== null && _d !== void 0 ? _d : getDeviceTransferProgress(offset, offset + chunk.byteLength, totalSize);
|
|
50741
|
-
const request = {
|
|
50742
|
-
file: { path: options.path, offset, total_size: totalSize, data: chunk },
|
|
50743
|
-
overwrite: chunks === 0 ? (_e = options.overwrite) !== null && _e !== void 0 ? _e : false : false,
|
|
50744
|
-
append: (_f = options.append) !== null && _f !== void 0 ? _f : false,
|
|
50745
|
-
ui_percentage: progress,
|
|
50746
|
-
};
|
|
50747
|
-
const maxChunkRetries = Math.max(Math.floor((_g = options.maxChunkRetries) !== null && _g !== void 0 ? _g : 0), 0);
|
|
50748
|
-
let retryCount = 0;
|
|
50749
|
-
let response;
|
|
50750
|
-
let isWritePending = true;
|
|
50751
|
-
while (isWritePending) {
|
|
50752
|
-
try {
|
|
50753
|
-
response = yield options.commands.typedCall('FilesystemFileWrite', 'FilesystemFile', request, { timeoutMs: options.timeoutMs });
|
|
50754
|
-
isWritePending = false;
|
|
50755
|
-
}
|
|
50756
|
-
catch (error) {
|
|
50757
|
-
if (retryCount >= maxChunkRetries || !isProtocolV2ResponseTimeout(error))
|
|
50758
|
-
throw error;
|
|
50759
|
-
retryCount += 1;
|
|
50760
|
-
(_h = options.throwIfAborted) === null || _h === void 0 ? void 0 : _h.call(options);
|
|
50761
|
-
}
|
|
50762
|
-
}
|
|
50763
|
-
if (!response) {
|
|
50764
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'FilesystemFileWrite completed without a response');
|
|
50765
|
-
}
|
|
50766
|
-
(_j = options.throwIfAborted) === null || _j === void 0 ? void 0 : _j.call(options);
|
|
50767
|
-
lastMessage = response.message;
|
|
50768
|
-
const rawProcessedByte = (_k = response.message) === null || _k === void 0 ? void 0 : _k.processed_byte;
|
|
50769
|
-
const processedByte = Number(rawProcessedByte);
|
|
50770
|
-
if (rawProcessedByte !== undefined &&
|
|
50771
|
-
(!Number.isFinite(processedByte) ||
|
|
50772
|
-
processedByte <= offset ||
|
|
50773
|
-
processedByte > offset + chunk.byteLength)) {
|
|
50774
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite invalid processed_byte ${processedByte}`);
|
|
50775
|
-
}
|
|
50776
|
-
written =
|
|
50777
|
-
rawProcessedByte === undefined ? written + chunk.byteLength : processedByte - startOffset;
|
|
50778
|
-
chunks += 1;
|
|
50779
|
-
const now = Date.now();
|
|
50780
|
-
const elapsedMs = now - startTime;
|
|
50781
|
-
const transferredBytes = Math.min(written, dataLength);
|
|
50782
|
-
const rateWindowElapsedMs = now - rateWindowStartedAt;
|
|
50783
|
-
if (rateWindowElapsedMs >= FILE_TRANSFER_RATE_WINDOW_MS) {
|
|
50784
|
-
const rateWindowBytes = Math.max(transferredBytes - rateWindowStartedBytes, 0);
|
|
50785
|
-
rateBytesPerSecond = Math.round((rateWindowBytes / rateWindowElapsedMs) * 1000);
|
|
50786
|
-
rateWindowStartedAt = now;
|
|
50787
|
-
rateWindowStartedBytes = transferredBytes;
|
|
50788
|
-
}
|
|
50789
|
-
else if (rateBytesPerSecond === undefined && elapsedMs > 0) {
|
|
50790
|
-
rateBytesPerSecond = Math.round((transferredBytes / elapsedMs) * 1000);
|
|
50791
|
-
}
|
|
50792
|
-
(_l = options.onProgress) === null || _l === void 0 ? void 0 : _l.call(options, {
|
|
50793
|
-
progress: getConfirmedProgress(startOffset + written, totalSize, written, dataLength),
|
|
50794
|
-
transferredBytes,
|
|
50795
|
-
totalBytes: dataLength,
|
|
50796
|
-
rateBytesPerSecond,
|
|
50797
|
-
elapsedMs,
|
|
50798
|
-
});
|
|
50799
|
-
if (options.paceMs && options.paceMs > 0) {
|
|
50800
|
-
yield new Promise(resolve => {
|
|
50801
|
-
setTimeout(resolve, options.paceMs);
|
|
50802
|
-
});
|
|
50803
|
-
}
|
|
50804
|
-
}
|
|
50805
|
-
return Object.assign(Object.assign({}, lastMessage), { path: options.path, offset: startOffset, total_size: totalSize, processed_byte: startOffset + written, chunks });
|
|
50806
|
-
});
|
|
50807
|
-
}
|
|
50808
|
-
|
|
50809
50906
|
const WALLPAPER_DIRECTORY = 'vol1:/wallpapers';
|
|
50810
50907
|
const SAFE_FILE_NAME = /^[A-Za-z0-9_-]+(?:\.bin)?$/;
|
|
50811
50908
|
function normalizeFileName(fileName, data) {
|
|
@@ -51619,9 +51716,10 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
51619
51716
|
}
|
|
51620
51717
|
}
|
|
51621
51718
|
const useEmptyPassphrase = this.payload.useEmptyPassphrase === true;
|
|
51719
|
+
const deriveCardano = method.name.startsWith('cardano');
|
|
51622
51720
|
const shouldResumeWalletSession = useEmptyPassphrase || !!this.payload.passphraseState;
|
|
51623
51721
|
if (this.device.isProtocolV2() && shouldResumeWalletSession) {
|
|
51624
|
-
const passphraseStateSafety = yield this.device.checkPassphraseStateSafety(this.payload.passphraseState, useEmptyPassphrase, this.payload.skipPassphraseCheck);
|
|
51722
|
+
const passphraseStateSafety = yield this.device.checkPassphraseStateSafety(this.payload.passphraseState, useEmptyPassphrase, this.payload.skipPassphraseCheck, deriveCardano);
|
|
51625
51723
|
if (!passphraseStateSafety) {
|
|
51626
51724
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
51627
51725
|
}
|
|
@@ -60992,10 +61090,19 @@ class DeviceConnector {
|
|
|
60992
61090
|
this.transport = TransportManager.getTransport();
|
|
60993
61091
|
DevicePool.setConnector(this);
|
|
60994
61092
|
}
|
|
61093
|
+
getActiveTransport() {
|
|
61094
|
+
var _a;
|
|
61095
|
+
const transport = (_a = this.transport) !== null && _a !== void 0 ? _a : TransportManager.getTransport();
|
|
61096
|
+
if (!transport) {
|
|
61097
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured, 'Device connector was created before transport initialization');
|
|
61098
|
+
}
|
|
61099
|
+
this.transport = transport;
|
|
61100
|
+
return transport;
|
|
61101
|
+
}
|
|
60995
61102
|
enumerate() {
|
|
60996
61103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60997
61104
|
try {
|
|
60998
|
-
const descriptors = yield this.
|
|
61105
|
+
const descriptors = yield this.getActiveTransport().enumerate();
|
|
60999
61106
|
this.upcoming = descriptors;
|
|
61000
61107
|
this._reportDevicesChange();
|
|
61001
61108
|
return { descriptors };
|
|
@@ -61012,11 +61119,10 @@ class DeviceConnector {
|
|
|
61012
61119
|
this.listening = true;
|
|
61013
61120
|
let descriptors;
|
|
61014
61121
|
try {
|
|
61122
|
+
const transport = this.getActiveTransport();
|
|
61015
61123
|
Log$2.debug('Start listening', current);
|
|
61016
61124
|
this.listenTimestamp = new Date().getTime();
|
|
61017
|
-
descriptors = waitForEvent
|
|
61018
|
-
? yield this.transport.listen(current)
|
|
61019
|
-
: yield this.transport.enumerate();
|
|
61125
|
+
descriptors = waitForEvent ? yield transport.listen(current) : yield transport.enumerate();
|
|
61020
61126
|
if (!this.listening)
|
|
61021
61127
|
return;
|
|
61022
61128
|
this.upcoming = descriptors;
|
|
@@ -61047,9 +61153,10 @@ class DeviceConnector {
|
|
|
61047
61153
|
Log$2.debug('acquire', path, session, expectedProtocol, protocolHint);
|
|
61048
61154
|
const env = DataManager.getSettings('env');
|
|
61049
61155
|
try {
|
|
61156
|
+
const transport = this.getActiveTransport();
|
|
61050
61157
|
let res;
|
|
61051
61158
|
if (DataManager.isBleConnect(env)) {
|
|
61052
|
-
res = yield
|
|
61159
|
+
res = yield transport.acquire({
|
|
61053
61160
|
uuid: path,
|
|
61054
61161
|
forceCleanRunPromise,
|
|
61055
61162
|
expectedProtocol,
|
|
@@ -61057,7 +61164,7 @@ class DeviceConnector {
|
|
|
61057
61164
|
});
|
|
61058
61165
|
}
|
|
61059
61166
|
else {
|
|
61060
|
-
res = yield
|
|
61167
|
+
res = yield transport.acquire({
|
|
61061
61168
|
path,
|
|
61062
61169
|
previous: session !== null && session !== void 0 ? session : null,
|
|
61063
61170
|
expectedProtocol,
|
|
@@ -61065,7 +61172,10 @@ class DeviceConnector {
|
|
|
61065
61172
|
});
|
|
61066
61173
|
}
|
|
61067
61174
|
if (expectedProtocol) {
|
|
61068
|
-
const
|
|
61175
|
+
const acquiredProtocol = typeof res === 'object' && res !== null
|
|
61176
|
+
? res.protocolType
|
|
61177
|
+
: undefined;
|
|
61178
|
+
const detectedProtocol = acquiredProtocol !== null && acquiredProtocol !== void 0 ? acquiredProtocol : transport.getProtocolType(path);
|
|
61069
61179
|
if (detectedProtocol !== expectedProtocol) {
|
|
61070
61180
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expectedProtocol}, detected ${detectedProtocol}`);
|
|
61071
61181
|
}
|
|
@@ -61081,7 +61191,7 @@ class DeviceConnector {
|
|
|
61081
61191
|
release(session, onclose) {
|
|
61082
61192
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61083
61193
|
try {
|
|
61084
|
-
const res = yield this.
|
|
61194
|
+
const res = yield this.getActiveTransport().release(session, onclose);
|
|
61085
61195
|
return res;
|
|
61086
61196
|
}
|
|
61087
61197
|
catch (error) {
|
|
@@ -61092,8 +61202,9 @@ class DeviceConnector {
|
|
|
61092
61202
|
disconnect(session) {
|
|
61093
61203
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61094
61204
|
try {
|
|
61095
|
-
|
|
61096
|
-
|
|
61205
|
+
const transport = this.getActiveTransport();
|
|
61206
|
+
if (transport.disconnect && !!session) {
|
|
61207
|
+
yield transport.disconnect(session);
|
|
61097
61208
|
}
|
|
61098
61209
|
}
|
|
61099
61210
|
catch (error) {
|
|
@@ -61102,10 +61213,11 @@ class DeviceConnector {
|
|
|
61102
61213
|
});
|
|
61103
61214
|
}
|
|
61104
61215
|
promptDeviceAccess() {
|
|
61105
|
-
|
|
61216
|
+
const transport = this.getActiveTransport();
|
|
61217
|
+
if (!transport.promptDeviceAccess) {
|
|
61106
61218
|
return Promise.resolve(null);
|
|
61107
61219
|
}
|
|
61108
|
-
return
|
|
61220
|
+
return transport.promptDeviceAccess();
|
|
61109
61221
|
}
|
|
61110
61222
|
_reportDevicesChange() {
|
|
61111
61223
|
DevicePool.reportDeviceChange(this.upcoming);
|
|
@@ -61701,6 +61813,10 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
61701
61813
|
completeMethodRequestContext(method);
|
|
61702
61814
|
}
|
|
61703
61815
|
catch (error) {
|
|
61816
|
+
if (!requestQueue.getTask(method.responseID)) {
|
|
61817
|
+
Log.debug(`Call API - Ignore late inner method result`, error);
|
|
61818
|
+
return;
|
|
61819
|
+
}
|
|
61704
61820
|
Log.debug(`Call API - Inner Method Run Error`, error);
|
|
61705
61821
|
messageResponse = createResponseMessage(method.responseID, false, { error });
|
|
61706
61822
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
@@ -62423,13 +62539,8 @@ const initTransport = (Transport, plugin) => {
|
|
|
62423
62539
|
};
|
|
62424
62540
|
const init = (settings, Transport, plugin) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62425
62541
|
try {
|
|
62426
|
-
|
|
62427
|
-
|
|
62428
|
-
initTransport(Transport, plugin);
|
|
62429
|
-
}
|
|
62430
|
-
catch (_s) {
|
|
62431
|
-
Log.error('DataManager.load error');
|
|
62432
|
-
}
|
|
62542
|
+
yield DataManager.load(settings);
|
|
62543
|
+
initTransport(Transport, plugin);
|
|
62433
62544
|
enableLog(DataManager.getSettings('debug'));
|
|
62434
62545
|
if (DataManager.getSettings('env') !== 'react-native') {
|
|
62435
62546
|
setLoggerPostMessage(postMessage);
|
|
@@ -62440,6 +62551,7 @@ const init = (settings, Transport, plugin) => __awaiter(void 0, void 0, void 0,
|
|
|
62440
62551
|
}
|
|
62441
62552
|
catch (error) {
|
|
62442
62553
|
Log.error('core init', error);
|
|
62554
|
+
throw error;
|
|
62443
62555
|
}
|
|
62444
62556
|
});
|
|
62445
62557
|
const switchTransport = ({ env, Transport, plugin, }) => {
|