@onekeyfe/hd-core 1.2.2-alpha.0 → 1.2.2-alpha.100
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 +4 -20
- package/__tests__/DeviceCommands.test.ts +0 -13
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +2 -0
- package/__tests__/check-firmware-release-protocol-v2.test.ts +2 -0
- package/__tests__/device-lifecycle-events.test.ts +0 -19
- package/__tests__/deviceUploadNft.test.ts +0 -41
- package/__tests__/evmSignTypedData.test.ts +0 -42
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +12 -524
- package/__tests__/open-wallet-session.test.ts +1 -127
- package/__tests__/protocol-v2-resources.test.ts +4 -7
- package/__tests__/protocol-v2-unlock-policy.test.ts +1 -35
- package/__tests__/protocol-v2.test.ts +27 -673
- package/dist/api/FirmwareUpdateV4.d.ts +0 -3
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.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/FirmwareUpdateBaseMethod.d.ts +2 -2
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +2 -2
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +1 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +0 -3
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +5 -10
- package/dist/index.js +398 -1116
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +0 -2
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +0 -3
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/settings.d.ts +2 -2
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +0 -3
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +75 -416
- package/src/api/OpenWalletSession.ts +9 -39
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +1 -2
- package/src/api/evm/EVMSignTypedData.ts +0 -1
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +3 -9
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +1 -7
- package/src/api/protocol-v2/DeviceUploadNft.ts +8 -28
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +8 -19
- package/src/api/protocol-v2/helpers.ts +0 -8
- package/src/core/index.ts +10 -121
- package/src/data/messages/messages-protocol-v2.json +1 -111
- package/src/device/Device.ts +1 -3
- package/src/device/DeviceConnector.ts +3 -7
- package/src/events/ui-request.ts +0 -3
- package/src/protocols/protocol-v2/resources.ts +1 -9
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +1 -8
- package/src/protocols/protocol-v2/walletSession.ts +22 -65
- package/src/types/settings.ts +2 -4
- package/src/utils/deviceFeaturesUtils.ts +0 -4
- package/__tests__/pro2HostAssetPackage.test.ts +0 -58
- package/dist/utils/pro2HostAssetPackage.d.ts +0 -8
- package/dist/utils/pro2HostAssetPackage.d.ts.map +0 -1
- package/src/utils/pro2HostAssetPackage.ts +0 -315
package/dist/index.js
CHANGED
|
@@ -27476,9 +27476,6 @@ var nested = {
|
|
|
27476
27476
|
MessageType_DeviceCertificateSignature: 60423,
|
|
27477
27477
|
MessageType_DeviceCertificateSign: 60424,
|
|
27478
27478
|
MessageType_DeviceMiscUsbMscControl: 60440,
|
|
27479
|
-
MessageType_DeviceFindMyTokenState: 60450,
|
|
27480
|
-
MessageType_DeviceFindMyTokenUpdate: 60451,
|
|
27481
|
-
MessageType_DeviceFindMyTokenStateGet: 60452,
|
|
27482
27479
|
MessageType_DeviceInfoGet: 60600,
|
|
27483
27480
|
MessageType_DeviceInfo: 60601,
|
|
27484
27481
|
MessageType_DeviceStatusGet: 60602,
|
|
@@ -32455,10 +32452,6 @@ var nested = {
|
|
|
32455
32452
|
request_id: {
|
|
32456
32453
|
type: "bytes",
|
|
32457
32454
|
id: 5
|
|
32458
|
-
},
|
|
32459
|
-
source_fingerprint: {
|
|
32460
|
-
type: "uint32",
|
|
32461
|
-
id: 6
|
|
32462
32455
|
}
|
|
32463
32456
|
}
|
|
32464
32457
|
},
|
|
@@ -32594,14 +32587,6 @@ var nested = {
|
|
|
32594
32587
|
tx_type: {
|
|
32595
32588
|
type: "uint32",
|
|
32596
32589
|
id: 10
|
|
32597
|
-
},
|
|
32598
|
-
expected_address: {
|
|
32599
|
-
type: "bytes",
|
|
32600
|
-
id: 12
|
|
32601
|
-
},
|
|
32602
|
-
source_fingerprint: {
|
|
32603
|
-
type: "uint32",
|
|
32604
|
-
id: 13
|
|
32605
32590
|
}
|
|
32606
32591
|
}
|
|
32607
32592
|
},
|
|
@@ -32682,14 +32667,6 @@ var nested = {
|
|
|
32682
32667
|
rule: "repeated",
|
|
32683
32668
|
type: "EthereumAccessListOneKey",
|
|
32684
32669
|
id: 11
|
|
32685
|
-
},
|
|
32686
|
-
expected_address: {
|
|
32687
|
-
type: "bytes",
|
|
32688
|
-
id: 12
|
|
32689
|
-
},
|
|
32690
|
-
source_fingerprint: {
|
|
32691
|
-
type: "uint32",
|
|
32692
|
-
id: 13
|
|
32693
32670
|
}
|
|
32694
32671
|
}
|
|
32695
32672
|
},
|
|
@@ -32866,10 +32843,6 @@ var nested = {
|
|
|
32866
32843
|
chain_id: {
|
|
32867
32844
|
type: "uint64",
|
|
32868
32845
|
id: 3
|
|
32869
|
-
},
|
|
32870
|
-
source_fingerprint: {
|
|
32871
|
-
type: "uint32",
|
|
32872
|
-
id: 4
|
|
32873
32846
|
}
|
|
32874
32847
|
}
|
|
32875
32848
|
},
|
|
@@ -36572,10 +36545,6 @@ var nested = {
|
|
|
36572
36545
|
rule: "required",
|
|
36573
36546
|
type: "bytes",
|
|
36574
36547
|
id: 2
|
|
36575
|
-
},
|
|
36576
|
-
source_fingerprint: {
|
|
36577
|
-
type: "uint32",
|
|
36578
|
-
id: 3
|
|
36579
36548
|
}
|
|
36580
36549
|
}
|
|
36581
36550
|
},
|
|
@@ -36620,10 +36589,6 @@ var nested = {
|
|
|
36620
36589
|
application_domain: {
|
|
36621
36590
|
type: "bytes",
|
|
36622
36591
|
id: 5
|
|
36623
|
-
},
|
|
36624
|
-
source_fingerprint: {
|
|
36625
|
-
type: "uint32",
|
|
36626
|
-
id: 6
|
|
36627
36592
|
}
|
|
36628
36593
|
}
|
|
36629
36594
|
},
|
|
@@ -36641,10 +36606,6 @@ var nested = {
|
|
|
36641
36606
|
rule: "required",
|
|
36642
36607
|
type: "bytes",
|
|
36643
36608
|
id: 2
|
|
36644
|
-
},
|
|
36645
|
-
source_fingerprint: {
|
|
36646
|
-
type: "uint32",
|
|
36647
|
-
id: 3
|
|
36648
36609
|
}
|
|
36649
36610
|
}
|
|
36650
36611
|
},
|
|
@@ -38880,28 +38841,6 @@ var nested = {
|
|
|
38880
38841
|
}
|
|
38881
38842
|
}
|
|
38882
38843
|
},
|
|
38883
|
-
DeviceFindMyTokenUpdate: {
|
|
38884
|
-
fields: {
|
|
38885
|
-
token: {
|
|
38886
|
-
rule: "required",
|
|
38887
|
-
type: "bytes",
|
|
38888
|
-
id: 1
|
|
38889
|
-
}
|
|
38890
|
-
}
|
|
38891
|
-
},
|
|
38892
|
-
DeviceFindMyTokenStateGet: {
|
|
38893
|
-
fields: {
|
|
38894
|
-
}
|
|
38895
|
-
},
|
|
38896
|
-
DeviceFindMyTokenState: {
|
|
38897
|
-
fields: {
|
|
38898
|
-
burned: {
|
|
38899
|
-
rule: "required",
|
|
38900
|
-
type: "bool",
|
|
38901
|
-
id: 1
|
|
38902
|
-
}
|
|
38903
|
-
}
|
|
38904
|
-
},
|
|
38905
38844
|
DeviceFactoryAck: {
|
|
38906
38845
|
values: {
|
|
38907
38846
|
FACTORY_ACK_SUCCESS: 0,
|
|
@@ -39032,13 +38971,6 @@ var nested = {
|
|
|
39032
38971
|
FW_MGMT_UPDATER_TASK_STATUS_FAILED_ENTRY_OUT_OF_BOUNDS: 10
|
|
39033
38972
|
}
|
|
39034
38973
|
},
|
|
39035
|
-
DeviceFirmwareUpdatePhase: {
|
|
39036
|
-
values: {
|
|
39037
|
-
FW_MGMT_UPDATER_PHASE_PREPARE: 0,
|
|
39038
|
-
FW_MGMT_UPDATER_PHASE_INSTALL: 1,
|
|
39039
|
-
FW_MGMT_UPDATER_PHASE_VERIFY: 2
|
|
39040
|
-
}
|
|
39041
|
-
},
|
|
39042
38974
|
DeviceFirmwareTarget: {
|
|
39043
38975
|
fields: {
|
|
39044
38976
|
target_id: {
|
|
@@ -39064,24 +38996,6 @@ var nested = {
|
|
|
39064
38996
|
},
|
|
39065
38997
|
DeviceFirmwareUpdateRequest: {
|
|
39066
38998
|
fields: {
|
|
39067
|
-
reboot_after_update: {
|
|
39068
|
-
type: "bool",
|
|
39069
|
-
id: 1
|
|
39070
|
-
}
|
|
39071
|
-
}
|
|
39072
|
-
},
|
|
39073
|
-
DeviceFirmwareUpdatePhaseInfo: {
|
|
39074
|
-
fields: {
|
|
39075
|
-
phase: {
|
|
39076
|
-
rule: "required",
|
|
39077
|
-
type: "DeviceFirmwareUpdatePhase",
|
|
39078
|
-
id: 1
|
|
39079
|
-
},
|
|
39080
|
-
progress_percent: {
|
|
39081
|
-
rule: "required",
|
|
39082
|
-
type: "uint32",
|
|
39083
|
-
id: 2
|
|
39084
|
-
}
|
|
39085
38999
|
}
|
|
39086
39000
|
},
|
|
39087
39001
|
DeviceFirmwareUpdateRecord: {
|
|
@@ -39095,14 +39009,6 @@ var nested = {
|
|
|
39095
39009
|
type: "DeviceFirmwareUpdateTaskStatus",
|
|
39096
39010
|
id: 10
|
|
39097
39011
|
},
|
|
39098
|
-
progress_percent: {
|
|
39099
|
-
type: "uint32",
|
|
39100
|
-
id: 11
|
|
39101
|
-
},
|
|
39102
|
-
phase_info: {
|
|
39103
|
-
type: "DeviceFirmwareUpdatePhaseInfo",
|
|
39104
|
-
id: 12
|
|
39105
|
-
},
|
|
39106
39012
|
payload_version: {
|
|
39107
39013
|
type: "uint32",
|
|
39108
39014
|
id: 20
|
|
@@ -39119,14 +39025,6 @@ var nested = {
|
|
|
39119
39025
|
type: "bool",
|
|
39120
39026
|
id: 10
|
|
39121
39027
|
},
|
|
39122
|
-
progress_percent: {
|
|
39123
|
-
type: "bool",
|
|
39124
|
-
id: 11
|
|
39125
|
-
},
|
|
39126
|
-
phase_info: {
|
|
39127
|
-
type: "bool",
|
|
39128
|
-
id: 12
|
|
39129
|
-
},
|
|
39130
39028
|
payload_version: {
|
|
39131
39029
|
type: "bool",
|
|
39132
39030
|
id: 20
|
|
@@ -39898,10 +39796,6 @@ var nested = {
|
|
|
39898
39796
|
text_id: {
|
|
39899
39797
|
type: "uint32",
|
|
39900
39798
|
id: 3
|
|
39901
|
-
},
|
|
39902
|
-
text_arg: {
|
|
39903
|
-
type: "string",
|
|
39904
|
-
id: 4
|
|
39905
39799
|
}
|
|
39906
39800
|
}
|
|
39907
39801
|
},
|
|
@@ -39969,10 +39863,6 @@ var nested = {
|
|
|
39969
39863
|
title_id: {
|
|
39970
39864
|
type: "uint32",
|
|
39971
39865
|
id: 8
|
|
39972
|
-
},
|
|
39973
|
-
title_arg: {
|
|
39974
|
-
type: "string",
|
|
39975
|
-
id: 9
|
|
39976
39866
|
}
|
|
39977
39867
|
}
|
|
39978
39868
|
},
|
|
@@ -40826,12 +40716,7 @@ function isProtocolV2ResourceArchiveEntryName(entryName) {
|
|
|
40826
40716
|
const fileName = (_a = parts[parts.length - 1]) !== null && _a !== void 0 ? _a : '';
|
|
40827
40717
|
return (fileName.length > 0 &&
|
|
40828
40718
|
!fileName.startsWith('.') &&
|
|
40829
|
-
!parts.some(part =>
|
|
40830
|
-
part === '.' ||
|
|
40831
|
-
part === '..' ||
|
|
40832
|
-
part === '.DS_Store' ||
|
|
40833
|
-
part.startsWith('._') ||
|
|
40834
|
-
part.toUpperCase() === '__MACOSX'));
|
|
40719
|
+
!parts.some(part => part === '__MACOSX' || part === '.' || part === '..' || part === ''));
|
|
40835
40720
|
}
|
|
40836
40721
|
function isSafeResourceDevicePath(path) {
|
|
40837
40722
|
return !(path.includes('\\') ||
|
|
@@ -41689,12 +41574,11 @@ const buildDeviceSessionGetRequest = ({ sessionId, expectedPassphraseState, deri
|
|
|
41689
41574
|
hdTransport.DeviceSessionSeedDomain.SeedDomain_Standard,
|
|
41690
41575
|
...(deriveCardano ? [hdTransport.DeviceSessionSeedDomain.SeedDomain_Cardano] : []),
|
|
41691
41576
|
] }));
|
|
41692
|
-
const askDevicePassphrase = (device, requestPayload
|
|
41577
|
+
const askDevicePassphrase = (device, requestPayload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41693
41578
|
yield device.commands.typedCall('DeviceSessionAskPassphrase', 'Success', requestPayload);
|
|
41694
41579
|
yield refreshProtocolV2DeviceStatus(device);
|
|
41695
|
-
onStatusRefreshed === null || onStatusRefreshed === void 0 ? void 0 : onStatusRefreshed();
|
|
41696
41580
|
});
|
|
41697
|
-
const selectDeviceSession = (device, expectedPassphraseState, deriveCardano
|
|
41581
|
+
const selectDeviceSession = (device, expectedPassphraseState, deriveCardano) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41698
41582
|
var _a, _b, _c, _d;
|
|
41699
41583
|
const existsAttachPinUser = ((_a = device.features) === null || _a === void 0 ? void 0 : _a.attachToPinEnabled) === true;
|
|
41700
41584
|
const metadata = Object.assign({ source: 'wallet-session-coordinator', reason: expectedPassphraseState ? 'session-recovery' : 'open-wallet' }, (expectedPassphraseState ? { expectedPassphraseState } : {}));
|
|
@@ -41727,19 +41611,18 @@ const selectDeviceSession = (device, expectedPassphraseState, deriveCardano, onS
|
|
|
41727
41611
|
emitUiEvent: false,
|
|
41728
41612
|
interaction: attachPinInteraction,
|
|
41729
41613
|
});
|
|
41730
|
-
onStatusRefreshed === null || onStatusRefreshed === void 0 ? void 0 : onStatusRefreshed();
|
|
41731
41614
|
return getDeviceSession(device, buildDeviceSessionGetRequest({ deriveCardano }));
|
|
41732
41615
|
}
|
|
41733
41616
|
if (hasHostPassphrase) {
|
|
41734
41617
|
yield askDevicePassphrase(device, {
|
|
41735
41618
|
passphrase: hostPassphrase,
|
|
41736
41619
|
on_device: false,
|
|
41737
|
-
}
|
|
41620
|
+
});
|
|
41738
41621
|
return getDeviceSession(device, buildDeviceSessionGetRequest({ deriveCardano }));
|
|
41739
41622
|
}
|
|
41740
41623
|
const passphraseOnDeviceInteraction = (_d = device.createProtocolV2UiPhaseMetadata) === null || _d === void 0 ? void 0 : _d.call(device, 'passphrase-on-device', 'start');
|
|
41741
41624
|
device.emit(DEVICE.PASSPHRASE_ON_DEVICE, device, Object.assign(Object.assign({}, metadata), (passphraseOnDeviceInteraction ? { interaction: passphraseOnDeviceInteraction } : {})));
|
|
41742
|
-
yield askDevicePassphrase(device, { on_device: true }
|
|
41625
|
+
yield askDevicePassphrase(device, { on_device: true });
|
|
41743
41626
|
return getDeviceSession(device, buildDeviceSessionGetRequest({ deriveCardano }));
|
|
41744
41627
|
});
|
|
41745
41628
|
function getProtocolV2WalletSession(device, options) {
|
|
@@ -41773,15 +41656,9 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41773
41656
|
: undefined;
|
|
41774
41657
|
let response;
|
|
41775
41658
|
let resumed = false;
|
|
41776
|
-
let
|
|
41777
|
-
|
|
41778
|
-
|
|
41779
|
-
};
|
|
41780
|
-
let mainPinAuthenticated = (options === null || options === void 0 ? void 0 : options.mainPinSelected) === true ||
|
|
41781
|
-
((options === null || options === void 0 ? void 0 : options.onlyMainPin) === true &&
|
|
41782
|
-
((_d = device.features) === null || _d === void 0 ? void 0 : _d.unlocked) === true &&
|
|
41783
|
-
((_e = device.features) === null || _e === void 0 ? void 0 : _e.unlockedAttachPin) === false);
|
|
41784
|
-
let standardWalletSelected = (options === null || options === void 0 ? void 0 : options.mainPinSelected) === true;
|
|
41659
|
+
let mainPinSelected = (options === null || options === void 0 ? void 0 : options.onlyMainPin) === true &&
|
|
41660
|
+
((_d = device.features) === null || _d === void 0 ? void 0 : _d.unlocked) === true &&
|
|
41661
|
+
((_e = device.features) === null || _e === void 0 ? void 0 : _e.unlockedAttachPin) === false;
|
|
41785
41662
|
const clearCurrentWalletSession = () => {
|
|
41786
41663
|
var _a;
|
|
41787
41664
|
if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
@@ -41794,7 +41671,6 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41794
41671
|
const rejectMismatchedAttachPinWallet = () => __awaiter(this, void 0, void 0, function* () {
|
|
41795
41672
|
var _k;
|
|
41796
41673
|
const features = yield refreshProtocolV2DeviceStatus(device);
|
|
41797
|
-
markWalletStatusRefreshed();
|
|
41798
41674
|
if (features.unlockedAttachPin !== true) {
|
|
41799
41675
|
return;
|
|
41800
41676
|
}
|
|
@@ -41816,35 +41692,28 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41816
41692
|
yield rejectMismatchedAttachPinWallet();
|
|
41817
41693
|
}
|
|
41818
41694
|
const selectMainPin = (force = false) => __awaiter(this, void 0, void 0, function* () {
|
|
41819
|
-
if (force || !
|
|
41695
|
+
if (force || !mainPinSelected) {
|
|
41820
41696
|
yield device.unlockDevice(hdTransport.DeviceSessionPinType.Main, {
|
|
41821
41697
|
source: 'wallet-session-coordinator',
|
|
41822
41698
|
reason: expectedPassphraseState ? 'session-recovery' : 'open-wallet',
|
|
41823
41699
|
deviceOnly: true,
|
|
41824
41700
|
});
|
|
41825
|
-
|
|
41826
|
-
mainPinAuthenticated = true;
|
|
41827
|
-
standardWalletSelected = true;
|
|
41701
|
+
mainPinSelected = true;
|
|
41828
41702
|
}
|
|
41829
41703
|
});
|
|
41830
41704
|
const selectStandardWallet = () => __awaiter(this, void 0, void 0, function* () {
|
|
41831
41705
|
var _m;
|
|
41706
|
+
yield selectMainPin();
|
|
41832
41707
|
if (((_m = device.features) === null || _m === void 0 ? void 0 : _m.passphraseProtection) === true) {
|
|
41833
|
-
yield selectMainPin();
|
|
41834
41708
|
yield askDevicePassphrase(device, {
|
|
41835
41709
|
passphrase: '',
|
|
41836
41710
|
on_device: false,
|
|
41837
|
-
}
|
|
41838
|
-
standardWalletSelected = true;
|
|
41839
|
-
}
|
|
41840
|
-
else if (!standardWalletSelected) {
|
|
41841
|
-
yield selectMainPin(true);
|
|
41711
|
+
});
|
|
41842
41712
|
}
|
|
41843
41713
|
});
|
|
41844
41714
|
if (readCurrentAttachPinSession) {
|
|
41845
41715
|
const status = yield requestProtocolV2DeviceStatus$1(device);
|
|
41846
41716
|
device.updateProtocolV2Status(status);
|
|
41847
|
-
markWalletStatusRefreshed();
|
|
41848
41717
|
if (status.unlocked !== true ||
|
|
41849
41718
|
status.passphrase_enabled !== true ||
|
|
41850
41719
|
status.unlocked_by_attach_to_pin !== true) {
|
|
@@ -41915,7 +41784,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41915
41784
|
device.clearInternalState();
|
|
41916
41785
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WalletSessionInvalid);
|
|
41917
41786
|
}
|
|
41918
|
-
response = yield selectDeviceSession(device, expectedPassphraseState, options === null || options === void 0 ? void 0 : options.deriveCardano
|
|
41787
|
+
response = yield selectDeviceSession(device, expectedPassphraseState, options === null || options === void 0 ? void 0 : options.deriveCardano);
|
|
41919
41788
|
}
|
|
41920
41789
|
let { message } = response;
|
|
41921
41790
|
try {
|
|
@@ -41944,7 +41813,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41944
41813
|
}
|
|
41945
41814
|
else {
|
|
41946
41815
|
device.clearInternalState();
|
|
41947
|
-
response = yield selectDeviceSession(device, expectedPassphraseState, options === null || options === void 0 ? void 0 : options.deriveCardano
|
|
41816
|
+
response = yield selectDeviceSession(device, expectedPassphraseState, options === null || options === void 0 ? void 0 : options.deriveCardano);
|
|
41948
41817
|
}
|
|
41949
41818
|
message = response.message;
|
|
41950
41819
|
try {
|
|
@@ -41982,7 +41851,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41982
41851
|
if (readCurrentAttachPinSession) {
|
|
41983
41852
|
unlockedAttachPin = true;
|
|
41984
41853
|
}
|
|
41985
|
-
else if (
|
|
41854
|
+
else if (mainPinSelected) {
|
|
41986
41855
|
unlockedAttachPin = false;
|
|
41987
41856
|
}
|
|
41988
41857
|
return {
|
|
@@ -41990,7 +41859,6 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41990
41859
|
newSession: message.session_id,
|
|
41991
41860
|
unlockedAttachPin,
|
|
41992
41861
|
resumed,
|
|
41993
|
-
walletStatusRefreshed,
|
|
41994
41862
|
};
|
|
41995
41863
|
});
|
|
41996
41864
|
}
|
|
@@ -42058,7 +41926,6 @@ const getPassphraseStateWithRefreshDeviceInfo = (device, options) => __awaiter(v
|
|
|
42058
41926
|
onlyMainPin: options === null || options === void 0 ? void 0 : options.onlyMainPin,
|
|
42059
41927
|
deriveCardano: options === null || options === void 0 ? void 0 : options.deriveCardano,
|
|
42060
41928
|
rejectAttachPinForMainWallet: options === null || options === void 0 ? void 0 : options.rejectAttachPinForMainWallet,
|
|
42061
|
-
mainPinSelected: options === null || options === void 0 ? void 0 : options.mainPinSelected,
|
|
42062
41929
|
});
|
|
42063
41930
|
}
|
|
42064
41931
|
const { features } = device;
|
|
@@ -42104,7 +41971,6 @@ const getPassphraseState = (device, options) => __awaiter(void 0, void 0, void 0
|
|
|
42104
41971
|
onlyMainPin: options === null || options === void 0 ? void 0 : options.onlyMainPin,
|
|
42105
41972
|
deriveCardano: options === null || options === void 0 ? void 0 : options.deriveCardano,
|
|
42106
41973
|
rejectAttachPinForMainWallet: options === null || options === void 0 ? void 0 : options.rejectAttachPinForMainWallet,
|
|
42107
|
-
mainPinSelected: options === null || options === void 0 ? void 0 : options.mainPinSelected,
|
|
42108
41974
|
});
|
|
42109
41975
|
}
|
|
42110
41976
|
const supportAttachPinCapability = existCapability(features, hdTransport.Enum_Capability.Capability_AttachToPin);
|
|
@@ -42623,7 +42489,7 @@ function invalidParameter$2(message) {
|
|
|
42623
42489
|
function asBytes(rgba) {
|
|
42624
42490
|
return rgba instanceof Uint8Array ? rgba : new Uint8Array(rgba);
|
|
42625
42491
|
}
|
|
42626
|
-
function align
|
|
42492
|
+
function align(value, boundary) {
|
|
42627
42493
|
return Math.ceil(value / boundary) * boundary;
|
|
42628
42494
|
}
|
|
42629
42495
|
function encodePro2Image(options) {
|
|
@@ -42651,7 +42517,7 @@ function encodePro2Image(options) {
|
|
|
42651
42517
|
}
|
|
42652
42518
|
}
|
|
42653
42519
|
const colorFormat = hasTransparency ? 'RGB565A8' : 'RGB565';
|
|
42654
|
-
const stride = align
|
|
42520
|
+
const stride = align(width * 2, 4);
|
|
42655
42521
|
const alphaStride = stride / 2;
|
|
42656
42522
|
const rgbSize = stride * height;
|
|
42657
42523
|
const alphaSize = hasTransparency ? alphaStride * height : 0;
|
|
@@ -46589,7 +46455,7 @@ class Device extends events.exports {
|
|
|
46589
46455
|
return Promise.resolve(features);
|
|
46590
46456
|
});
|
|
46591
46457
|
}
|
|
46592
|
-
checkPassphraseStateSafety(passphraseState, useEmptyPassphrase, skipPassphraseCheck, deriveCardano
|
|
46458
|
+
checkPassphraseStateSafety(passphraseState, useEmptyPassphrase, skipPassphraseCheck, deriveCardano) {
|
|
46593
46459
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46594
46460
|
if (this.isUnacquired())
|
|
46595
46461
|
return false;
|
|
@@ -46599,7 +46465,6 @@ class Device extends events.exports {
|
|
|
46599
46465
|
onlyMainPin: useEmptyPassphrase,
|
|
46600
46466
|
deriveCardano,
|
|
46601
46467
|
rejectAttachPinForMainWallet: useEmptyPassphrase === true,
|
|
46602
|
-
mainPinSelected,
|
|
46603
46468
|
});
|
|
46604
46469
|
const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
|
|
46605
46470
|
const useErrorAttachPin = unlockedAttachPin &&
|
|
@@ -47424,10 +47289,6 @@ const wasResumed = (session) => !!session &&
|
|
|
47424
47289
|
typeof session === 'object' &&
|
|
47425
47290
|
'resumed' in session &&
|
|
47426
47291
|
session.resumed === true;
|
|
47427
|
-
const wasWalletStatusRefreshed = (session) => !!session &&
|
|
47428
|
-
typeof session === 'object' &&
|
|
47429
|
-
'walletStatusRefreshed' in session &&
|
|
47430
|
-
session.walletStatusRefreshed === true;
|
|
47431
47292
|
const requireHiddenWalletResponse = (session) => {
|
|
47432
47293
|
if (!session.passphraseState) {
|
|
47433
47294
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, 'Hidden wallet response is missing passphraseState');
|
|
@@ -47470,20 +47331,12 @@ class OpenWalletSession extends BaseMethod {
|
|
|
47470
47331
|
this.unlockPolicy = 'unlock-before-run';
|
|
47471
47332
|
this.skipForceUpdateCheck = true;
|
|
47472
47333
|
this.params = normalizeParams(this.payload);
|
|
47473
|
-
this.protocolV2PreUnlockPinType =
|
|
47474
|
-
this.params.mode === OpenWalletSessionMode.SelectHidden
|
|
47475
|
-
? hdTransport.DeviceSessionPinType.Any
|
|
47476
|
-
: hdTransport.DeviceSessionPinType.Main;
|
|
47477
47334
|
this.payload.useEmptyPassphrase = this.params.mode === OpenWalletSessionMode.Standard;
|
|
47478
47335
|
}
|
|
47479
47336
|
run() {
|
|
47480
|
-
var _a, _b;
|
|
47481
47337
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47482
47338
|
const isProtocolV2 = this.device.isProtocolV2();
|
|
47483
|
-
|
|
47484
|
-
let state = reusePreflightStatus
|
|
47485
|
-
? yield this.device.getDeviceState()
|
|
47486
|
-
: yield this.device.getDeviceState({ refreshSections: ['status'] });
|
|
47339
|
+
let state = yield this.device.getDeviceState({ refreshSections: ['status'] });
|
|
47487
47340
|
let currentDeviceId = state.identity.deviceId;
|
|
47488
47341
|
const hasAuthoritativeProtocolV2WalletStatus = (candidate) => candidate.status.unlocked === true &&
|
|
47489
47342
|
typeof candidate.status.passphraseProtection === 'boolean' &&
|
|
@@ -47505,18 +47358,9 @@ class OpenWalletSession extends BaseMethod {
|
|
|
47505
47358
|
currentDeviceId = state.identity.deviceId;
|
|
47506
47359
|
return state;
|
|
47507
47360
|
});
|
|
47508
|
-
const resolveProtocolV2DeviceStateAfterSession = (session) => __awaiter(this, void 0, void 0, function* () {
|
|
47509
|
-
if (!wasWalletStatusRefreshed(session)) {
|
|
47510
|
-
return refreshProtocolV2DeviceState();
|
|
47511
|
-
}
|
|
47512
|
-
state = yield this.device.getDeviceState();
|
|
47513
|
-
currentDeviceId = state.identity.deviceId;
|
|
47514
|
-
return state;
|
|
47515
|
-
});
|
|
47516
47361
|
const ensureProtocolV2WalletStatus = () => __awaiter(this, void 0, void 0, function* () {
|
|
47517
|
-
var _d;
|
|
47518
47362
|
if (isProtocolV2 && !hasAuthoritativeProtocolV2WalletStatus(state)) {
|
|
47519
|
-
yield this.device.unlockDevice(
|
|
47363
|
+
yield this.device.unlockDevice(hdTransport.DeviceSessionPinType.Main, {
|
|
47520
47364
|
source: 'unlock-coordinator',
|
|
47521
47365
|
reason: 'device-locked',
|
|
47522
47366
|
deviceOnly: true,
|
|
@@ -47535,14 +47379,13 @@ class OpenWalletSession extends BaseMethod {
|
|
|
47535
47379
|
deriveCardano: this.payload.deriveCardano,
|
|
47536
47380
|
selectMainWalletBeforeRestore: !hasAuthoritativeProtocolV2WalletStatus(state) ||
|
|
47537
47381
|
state.status.unlockedAttachPin === true,
|
|
47538
|
-
mainPinSelected: (_b = this.protocolV2UnlockContext) === null || _b === void 0 ? void 0 : _b.preflightMainPinSelected,
|
|
47539
47382
|
})
|
|
47540
47383
|
: yield getPassphraseStateWithRefreshDeviceInfo(this.device, {
|
|
47541
47384
|
onlyMainPin: true,
|
|
47542
47385
|
initSession: this.payload.initSession,
|
|
47543
47386
|
});
|
|
47544
47387
|
const refreshedState = isProtocolV2
|
|
47545
|
-
? requireAuthoritativeProtocolV2WalletStatus(yield
|
|
47388
|
+
? requireAuthoritativeProtocolV2WalletStatus(yield refreshProtocolV2DeviceState())
|
|
47546
47389
|
: state;
|
|
47547
47390
|
const deviceId = requireDeviceId();
|
|
47548
47391
|
if (session.unlockedAttachPin ||
|
|
@@ -47550,7 +47393,7 @@ class OpenWalletSession extends BaseMethod {
|
|
|
47550
47393
|
try {
|
|
47551
47394
|
yield this.device.lockDevice();
|
|
47552
47395
|
}
|
|
47553
|
-
catch (
|
|
47396
|
+
catch (_a) {
|
|
47554
47397
|
}
|
|
47555
47398
|
this.device.clearInternalState();
|
|
47556
47399
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckUnlockTypeError);
|
|
@@ -47614,7 +47457,7 @@ class OpenWalletSession extends BaseMethod {
|
|
|
47614
47457
|
: { forceWalletSelection: true })), { deriveCardano: this.payload.deriveCardano }))
|
|
47615
47458
|
: yield getPassphraseStateWithRefreshDeviceInfo(this.device, { initSession: true });
|
|
47616
47459
|
const refreshedState = isProtocolV2
|
|
47617
|
-
? requireAuthoritativeProtocolV2WalletStatus(yield
|
|
47460
|
+
? requireAuthoritativeProtocolV2WalletStatus(yield refreshProtocolV2DeviceState())
|
|
47618
47461
|
: state;
|
|
47619
47462
|
const deviceId = requireDeviceId();
|
|
47620
47463
|
if (isProtocolV2 && refreshedState.status.passphraseProtection !== true) {
|
|
@@ -51816,12 +51659,6 @@ const getProtocolV2UnknownErrorText = (error) => {
|
|
|
51816
51659
|
return parts.filter(Boolean).join(' ');
|
|
51817
51660
|
};
|
|
51818
51661
|
const isProtocolV2DeviceDisconnectedError = (error) => {
|
|
51819
|
-
var _a;
|
|
51820
|
-
const errorCode = error && typeof error === 'object'
|
|
51821
|
-
? (_a = error.errorCode) !== null && _a !== void 0 ? _a : error.code
|
|
51822
|
-
: undefined;
|
|
51823
|
-
if (errorCode === hdShared.HardwareErrorCode.BleDeviceDisconnected)
|
|
51824
|
-
return true;
|
|
51825
51662
|
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
51826
51663
|
const compactMessage = message.replace(/\s+/g, '');
|
|
51827
51664
|
return (message.includes('notfounderror') ||
|
|
@@ -51866,289 +51703,14 @@ const INSTALLABLE_FIRMWARE_TARGET_IDS = new Set([
|
|
|
51866
51703
|
]);
|
|
51867
51704
|
new Map(Object.entries(ProtocolV2FirmwareTargetType).flatMap(([key, value]) => INSTALLABLE_FIRMWARE_TARGET_IDS.has(value) ? [[key, value]] : []));
|
|
51868
51705
|
|
|
51869
|
-
const Log$7 = getLogger(exports.LoggerNames.
|
|
51870
|
-
const MIN_FILE_CHUNK_SIZE = 64;
|
|
51871
|
-
const FILE_TRANSFER_RATE_WINDOW_MS = 1000;
|
|
51872
|
-
const FILE_TRANSFER_LOG_INTERVAL_MS = 10000;
|
|
51706
|
+
const Log$7 = getLogger(exports.LoggerNames.Method);
|
|
51873
51707
|
const SESSION_ERROR$1 = 'session not found';
|
|
51874
|
-
function formatFileTransferRate(bytesPerSecond) {
|
|
51875
|
-
return (Math.max(bytesPerSecond, 0) / 1024).toFixed(2);
|
|
51876
|
-
}
|
|
51877
|
-
function getAverageFileTransferRate(transferredBytes, elapsedMs) {
|
|
51878
|
-
if (elapsedMs <= 0)
|
|
51879
|
-
return 0;
|
|
51880
|
-
return Math.round((Math.max(transferredBytes, 0) / elapsedMs) * 1000);
|
|
51881
|
-
}
|
|
51882
|
-
function getFileTransferTransport() {
|
|
51883
|
-
const env = DataManager.getSettings('env');
|
|
51884
|
-
return env && DataManager.isBleConnect(env) ? 'BLE' : String(env !== null && env !== void 0 ? env : 'unknown');
|
|
51885
|
-
}
|
|
51886
|
-
function logFileTransferMetrics({ transport, status, path, transferredBytes, totalBytes, elapsedMs, rateBytesPerSecond, hostWriteElapsedMs, responseWaitElapsedMs, measuredAttempts, }) {
|
|
51887
|
-
const segmentedMetrics = measuredAttempts > 0
|
|
51888
|
-
? ` hostWriteTotal=${(hostWriteElapsedMs / 1000).toFixed(2)}s responseWaitTotal=${(responseWaitElapsedMs / 1000).toFixed(2)}s measuredAttempts=${measuredAttempts}`
|
|
51889
|
-
: '';
|
|
51890
|
-
Log$7.log(`[FileWrite] metrics transport=${transport} status=${status} path=${path} bytes=${transferredBytes}/${totalBytes} elapsed=${(elapsedMs / 1000).toFixed(2)}s speed=${formatFileTransferRate(rateBytesPerSecond)} KiB/s${segmentedMetrics}`);
|
|
51891
|
-
}
|
|
51892
|
-
function isProtocolV2ResponseTimeout(error) {
|
|
51893
|
-
var _a, _b;
|
|
51894
|
-
if (!error || typeof error !== 'object')
|
|
51895
|
-
return false;
|
|
51896
|
-
const candidate = error;
|
|
51897
|
-
const code = (_a = candidate.errorCode) !== null && _a !== void 0 ? _a : candidate.code;
|
|
51898
|
-
return (code === hdShared.HardwareErrorCode.BleTimeoutError ||
|
|
51899
|
-
code === 'response-timeout' ||
|
|
51900
|
-
/(?:BLE|Lowlevel|Protocol V2) response timeout/i.test((_b = candidate.message) !== null && _b !== void 0 ? _b : ''));
|
|
51901
|
-
}
|
|
51902
|
-
function getProtocolV2FileChunkLimit() {
|
|
51903
|
-
const env = DataManager.getSettings('env');
|
|
51904
|
-
return env && DataManager.isBleConnect(env)
|
|
51905
|
-
? hdTransport.PROTOCOL_V2_BLE_FILE_CHUNK_SIZE
|
|
51906
|
-
: hdTransport.PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
51907
|
-
}
|
|
51908
|
-
function dataToUint8Array(data) {
|
|
51909
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51910
|
-
if (typeof data === 'string')
|
|
51911
|
-
return new TextEncoder().encode(data);
|
|
51912
|
-
if (data instanceof ArrayBuffer)
|
|
51913
|
-
return new Uint8Array(data);
|
|
51914
|
-
if (ArrayBuffer.isView(data)) {
|
|
51915
|
-
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
51916
|
-
}
|
|
51917
|
-
if (typeof Blob !== 'undefined' && data instanceof Blob) {
|
|
51918
|
-
return new Uint8Array(yield data.arrayBuffer());
|
|
51919
|
-
}
|
|
51920
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Unsupported FilesystemFileWrite data');
|
|
51921
|
-
});
|
|
51922
|
-
}
|
|
51923
|
-
function normalizeChunkSize(value, maxChunkSize) {
|
|
51924
|
-
const numeric = Number(value);
|
|
51925
|
-
if (!Number.isFinite(numeric) || numeric <= 0)
|
|
51926
|
-
return maxChunkSize;
|
|
51927
|
-
return Math.min(Math.max(Math.floor(numeric), MIN_FILE_CHUNK_SIZE), maxChunkSize);
|
|
51928
|
-
}
|
|
51929
|
-
function getDeviceTransferProgress(before, after, total) {
|
|
51930
|
-
if (!Number.isFinite(total) || total <= 0)
|
|
51931
|
-
return 100;
|
|
51932
|
-
if (before <= 0 && after < total)
|
|
51933
|
-
return 0;
|
|
51934
|
-
if (after >= total)
|
|
51935
|
-
return 100;
|
|
51936
|
-
return Math.min(Math.max(Math.ceil((after / total) * 100), 1), 99);
|
|
51937
|
-
}
|
|
51938
|
-
function getConfirmedProgress(processed, total, written, length) {
|
|
51939
|
-
if (Number.isFinite(processed) && Number.isFinite(total) && total > 0) {
|
|
51940
|
-
if (processed >= total)
|
|
51941
|
-
return 100;
|
|
51942
|
-
return Math.min(Math.max(Math.floor((processed / total) * 100), 0), 99);
|
|
51943
|
-
}
|
|
51944
|
-
if (length > 0)
|
|
51945
|
-
return written >= length ? 100 : Math.floor((written / length) * 100);
|
|
51946
|
-
return 100;
|
|
51947
|
-
}
|
|
51948
|
-
function writeProtocolV2File(options) {
|
|
51949
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
51950
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51951
|
-
(_a = options.throwIfAborted) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
51952
|
-
const data = yield dataToUint8Array(options.data);
|
|
51953
|
-
const dataLength = data.byteLength;
|
|
51954
|
-
const startOffset = Number.isFinite(options.offset) && Number(options.offset) > 0 ? Number(options.offset) : 0;
|
|
51955
|
-
const totalSize = Number.isFinite(options.totalSize) && Number(options.totalSize) > 0
|
|
51956
|
-
? Number(options.totalSize)
|
|
51957
|
-
: startOffset + dataLength;
|
|
51958
|
-
if (totalSize < startOffset + dataLength) {
|
|
51959
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite totalSize ${totalSize} is smaller than offset + data length ${startOffset + dataLength}`);
|
|
51960
|
-
}
|
|
51961
|
-
const defaultChunkSizeLimit = getProtocolV2FileChunkLimit();
|
|
51962
|
-
const configuredChunkSizeLimit = Number(options.chunkSizeLimit);
|
|
51963
|
-
const chunkSizeLimit = Number.isFinite(configuredChunkSizeLimit) && configuredChunkSizeLimit > 0
|
|
51964
|
-
? Math.floor(configuredChunkSizeLimit)
|
|
51965
|
-
: defaultChunkSizeLimit;
|
|
51966
|
-
const chunkSize = normalizeChunkSize((_b = options.chunkSize) !== null && _b !== void 0 ? _b : options.chunkLen, chunkSizeLimit);
|
|
51967
|
-
let written = 0;
|
|
51968
|
-
let chunks = 0;
|
|
51969
|
-
let lastMessage;
|
|
51970
|
-
const startTime = Date.now();
|
|
51971
|
-
let rateWindowStartedAt = startTime;
|
|
51972
|
-
let rateWindowStartedBytes = 0;
|
|
51973
|
-
let rateBytesPerSecond;
|
|
51974
|
-
let lastConfirmedAt = startTime;
|
|
51975
|
-
let logWindowStartedAt = startTime;
|
|
51976
|
-
let logWindowStartedBytes = 0;
|
|
51977
|
-
let hostWriteElapsedMs = 0;
|
|
51978
|
-
let responseWaitElapsedMs = 0;
|
|
51979
|
-
let measuredAttempts = 0;
|
|
51980
|
-
const transport = getFileTransferTransport();
|
|
51981
|
-
Log$7.log(`[FileWrite] started transport=${transport} path=${options.path} bytes=${dataLength} offset=${startOffset} chunk=${chunkSize}`);
|
|
51982
|
-
try {
|
|
51983
|
-
while (written < dataLength) {
|
|
51984
|
-
(_c = options.throwIfAborted) === null || _c === void 0 ? void 0 : _c.call(options);
|
|
51985
|
-
const chunk = data.slice(written, Math.min(written + chunkSize, dataLength));
|
|
51986
|
-
const offset = startOffset + written;
|
|
51987
|
-
const progress = (_f = (_d = options.uiPercentage) !== null && _d !== void 0 ? _d : (_e = options.getUiPercentage) === null || _e === void 0 ? void 0 : _e.call(options, {
|
|
51988
|
-
offset,
|
|
51989
|
-
chunkLength: chunk.byteLength,
|
|
51990
|
-
totalSize,
|
|
51991
|
-
})) !== null && _f !== void 0 ? _f : getDeviceTransferProgress(offset, offset + chunk.byteLength, totalSize);
|
|
51992
|
-
const request = {
|
|
51993
|
-
file: { path: options.path, offset, total_size: totalSize, data: chunk },
|
|
51994
|
-
overwrite: chunks === 0 ? (_g = options.overwrite) !== null && _g !== void 0 ? _g : false : false,
|
|
51995
|
-
append: (_h = options.append) !== null && _h !== void 0 ? _h : false,
|
|
51996
|
-
ui_percentage: progress,
|
|
51997
|
-
};
|
|
51998
|
-
const maxChunkRetries = Math.max(Math.floor((_j = options.maxChunkRetries) !== null && _j !== void 0 ? _j : 0), 0);
|
|
51999
|
-
let retryCount = 0;
|
|
52000
|
-
let response;
|
|
52001
|
-
let isWritePending = true;
|
|
52002
|
-
while (isWritePending) {
|
|
52003
|
-
let currentHostWriteElapsedMs;
|
|
52004
|
-
let responseWaitStartedAt;
|
|
52005
|
-
try {
|
|
52006
|
-
const callOptions = options.writeWithResponse === undefined
|
|
52007
|
-
? {
|
|
52008
|
-
timeoutMs: options.timeoutMs,
|
|
52009
|
-
onWriteCompleted: ({ elapsedMs }) => {
|
|
52010
|
-
currentHostWriteElapsedMs = elapsedMs;
|
|
52011
|
-
responseWaitStartedAt = Date.now();
|
|
52012
|
-
},
|
|
52013
|
-
}
|
|
52014
|
-
: Object.assign(Object.assign({}, (options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs })), { writeWithResponse: options.writeWithResponse, onWriteCompleted: ({ elapsedMs }) => {
|
|
52015
|
-
currentHostWriteElapsedMs = elapsedMs;
|
|
52016
|
-
responseWaitStartedAt = Date.now();
|
|
52017
|
-
} });
|
|
52018
|
-
response = yield options.commands.typedCall('FilesystemFileWrite', 'FilesystemFile', request, callOptions);
|
|
52019
|
-
isWritePending = false;
|
|
52020
|
-
}
|
|
52021
|
-
catch (error) {
|
|
52022
|
-
if (retryCount >= maxChunkRetries || !isProtocolV2ResponseTimeout(error))
|
|
52023
|
-
throw error;
|
|
52024
|
-
retryCount += 1;
|
|
52025
|
-
(_k = options.throwIfAborted) === null || _k === void 0 ? void 0 : _k.call(options);
|
|
52026
|
-
}
|
|
52027
|
-
finally {
|
|
52028
|
-
if (currentHostWriteElapsedMs !== undefined && responseWaitStartedAt !== undefined) {
|
|
52029
|
-
hostWriteElapsedMs += currentHostWriteElapsedMs;
|
|
52030
|
-
responseWaitElapsedMs += Math.max(Date.now() - responseWaitStartedAt, 0);
|
|
52031
|
-
measuredAttempts += 1;
|
|
52032
|
-
}
|
|
52033
|
-
}
|
|
52034
|
-
}
|
|
52035
|
-
if (!response) {
|
|
52036
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'FilesystemFileWrite completed without a response');
|
|
52037
|
-
}
|
|
52038
|
-
const responseType = response.type;
|
|
52039
|
-
if (responseType && responseType !== 'FilesystemFile') {
|
|
52040
|
-
const responseError = (_l = response.message) === null || _l === void 0 ? void 0 : _l.error;
|
|
52041
|
-
if (typeof responseError === 'string' && responseError.includes(SESSION_ERROR$1)) {
|
|
52042
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, SESSION_ERROR$1);
|
|
52043
|
-
}
|
|
52044
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite received unexpected response ${responseType}`);
|
|
52045
|
-
}
|
|
52046
|
-
(_m = options.throwIfAborted) === null || _m === void 0 ? void 0 : _m.call(options);
|
|
52047
|
-
lastMessage = response.message;
|
|
52048
|
-
const rawProcessedByte = (_o = response.message) === null || _o === void 0 ? void 0 : _o.processed_byte;
|
|
52049
|
-
const processedByte = Number(rawProcessedByte);
|
|
52050
|
-
if (rawProcessedByte !== undefined &&
|
|
52051
|
-
(!Number.isFinite(processedByte) ||
|
|
52052
|
-
processedByte <= offset ||
|
|
52053
|
-
processedByte > offset + chunk.byteLength)) {
|
|
52054
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite invalid processed_byte ${processedByte}`);
|
|
52055
|
-
}
|
|
52056
|
-
written =
|
|
52057
|
-
rawProcessedByte === undefined ? written + chunk.byteLength : processedByte - startOffset;
|
|
52058
|
-
chunks += 1;
|
|
52059
|
-
const now = Date.now();
|
|
52060
|
-
lastConfirmedAt = now;
|
|
52061
|
-
const elapsedMs = now - startTime;
|
|
52062
|
-
const transferredBytes = Math.min(written, dataLength);
|
|
52063
|
-
const rateWindowElapsedMs = now - rateWindowStartedAt;
|
|
52064
|
-
if (rateWindowElapsedMs >= FILE_TRANSFER_RATE_WINDOW_MS) {
|
|
52065
|
-
const rateWindowBytes = Math.max(transferredBytes - rateWindowStartedBytes, 0);
|
|
52066
|
-
rateBytesPerSecond = Math.round((rateWindowBytes / rateWindowElapsedMs) * 1000);
|
|
52067
|
-
rateWindowStartedAt = now;
|
|
52068
|
-
rateWindowStartedBytes = transferredBytes;
|
|
52069
|
-
}
|
|
52070
|
-
else if (rateBytesPerSecond === undefined && elapsedMs > 0) {
|
|
52071
|
-
rateBytesPerSecond = Math.round((transferredBytes / elapsedMs) * 1000);
|
|
52072
|
-
}
|
|
52073
|
-
(_p = options.onProgress) === null || _p === void 0 ? void 0 : _p.call(options, {
|
|
52074
|
-
progress: getConfirmedProgress(startOffset + written, totalSize, written, dataLength),
|
|
52075
|
-
transferredBytes,
|
|
52076
|
-
totalBytes: dataLength,
|
|
52077
|
-
rateBytesPerSecond,
|
|
52078
|
-
elapsedMs,
|
|
52079
|
-
});
|
|
52080
|
-
const logWindowElapsedMs = now - logWindowStartedAt;
|
|
52081
|
-
if (logWindowElapsedMs >= FILE_TRANSFER_LOG_INTERVAL_MS && transferredBytes < dataLength) {
|
|
52082
|
-
const logWindowBytes = Math.max(transferredBytes - logWindowStartedBytes, 0);
|
|
52083
|
-
logFileTransferMetrics({
|
|
52084
|
-
transport,
|
|
52085
|
-
status: 'progress',
|
|
52086
|
-
path: options.path,
|
|
52087
|
-
transferredBytes,
|
|
52088
|
-
totalBytes: dataLength,
|
|
52089
|
-
elapsedMs,
|
|
52090
|
-
rateBytesPerSecond: getAverageFileTransferRate(logWindowBytes, logWindowElapsedMs),
|
|
52091
|
-
hostWriteElapsedMs,
|
|
52092
|
-
responseWaitElapsedMs,
|
|
52093
|
-
measuredAttempts,
|
|
52094
|
-
});
|
|
52095
|
-
logWindowStartedAt = now;
|
|
52096
|
-
logWindowStartedBytes = transferredBytes;
|
|
52097
|
-
}
|
|
52098
|
-
if (options.paceMs && options.paceMs > 0) {
|
|
52099
|
-
yield new Promise(resolve => {
|
|
52100
|
-
setTimeout(resolve, options.paceMs);
|
|
52101
|
-
});
|
|
52102
|
-
}
|
|
52103
|
-
}
|
|
52104
|
-
}
|
|
52105
|
-
catch (error) {
|
|
52106
|
-
const now = Date.now();
|
|
52107
|
-
const elapsedMs = Math.max(now - startTime, 0);
|
|
52108
|
-
const logWindowElapsedMs = Math.max(now - logWindowStartedAt, 0);
|
|
52109
|
-
const logWindowBytes = Math.max(written - logWindowStartedBytes, 0);
|
|
52110
|
-
logFileTransferMetrics({
|
|
52111
|
-
transport,
|
|
52112
|
-
status: 'failed',
|
|
52113
|
-
path: options.path,
|
|
52114
|
-
transferredBytes: written,
|
|
52115
|
-
totalBytes: dataLength,
|
|
52116
|
-
elapsedMs,
|
|
52117
|
-
rateBytesPerSecond: getAverageFileTransferRate(logWindowBytes, logWindowElapsedMs),
|
|
52118
|
-
hostWriteElapsedMs,
|
|
52119
|
-
responseWaitElapsedMs,
|
|
52120
|
-
measuredAttempts,
|
|
52121
|
-
});
|
|
52122
|
-
throw error;
|
|
52123
|
-
}
|
|
52124
|
-
const elapsedMs = Math.max(lastConfirmedAt - startTime, 0);
|
|
52125
|
-
const logWindowElapsedMs = Math.max(lastConfirmedAt - logWindowStartedAt, 0);
|
|
52126
|
-
const logWindowBytes = Math.max(written - logWindowStartedBytes, 0);
|
|
52127
|
-
logFileTransferMetrics({
|
|
52128
|
-
transport,
|
|
52129
|
-
status: 'completed',
|
|
52130
|
-
path: options.path,
|
|
52131
|
-
transferredBytes: written,
|
|
52132
|
-
totalBytes: dataLength,
|
|
52133
|
-
elapsedMs,
|
|
52134
|
-
rateBytesPerSecond: getAverageFileTransferRate(logWindowBytes, logWindowElapsedMs),
|
|
52135
|
-
hostWriteElapsedMs,
|
|
52136
|
-
responseWaitElapsedMs,
|
|
52137
|
-
measuredAttempts,
|
|
52138
|
-
});
|
|
52139
|
-
return Object.assign(Object.assign({}, lastMessage), { path: options.path, offset: startOffset, total_size: totalSize, processed_byte: startOffset + written, chunks });
|
|
52140
|
-
});
|
|
52141
|
-
}
|
|
52142
|
-
|
|
52143
|
-
const Log$6 = getLogger(exports.LoggerNames.Method);
|
|
52144
|
-
const SESSION_ERROR = 'session not found';
|
|
52145
51708
|
const PROTOCOL_V2_BOOTLOADER_RECONNECT_TIMEOUT = 90 * 1000;
|
|
52146
51709
|
const PROTOCOL_V2_FINAL_RECONNECT_TIMEOUT = 3 * 60 * 1000;
|
|
52147
51710
|
const PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT = 5 * 1000;
|
|
52148
51711
|
const PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT = 15 * 1000;
|
|
52149
51712
|
const PROTOCOL_V2_INSTALL_TIMEOUT = 5 * 60 * 1000;
|
|
52150
51713
|
const PROTOCOL_V2_INSTALL_STATUS_INITIAL_DELAY = 1000;
|
|
52151
|
-
const PROTOCOL_V2_INSTALL_FINISHED_AFTER_DISCONNECT_POLLS = 4;
|
|
52152
51714
|
const PROTOCOL_V2_TARGET_STATUS_PENDING = 0;
|
|
52153
51715
|
const PROTOCOL_V2_TARGET_STATUS_IN_PROGRESS = 1;
|
|
52154
51716
|
const PROTOCOL_V2_TARGET_STATUS_FINISHED = 2;
|
|
@@ -52304,12 +51866,11 @@ const isProtocolV2FirmwareStatusEndpointUnavailable = (error) => {
|
|
|
52304
51866
|
};
|
|
52305
51867
|
const isProtocolV2TerminalInstallStatusError = (error) => {
|
|
52306
51868
|
var _a;
|
|
52307
|
-
return hdShared.
|
|
52308
|
-
(error
|
|
52309
|
-
|
|
52310
|
-
|
|
52311
|
-
|
|
52312
|
-
((_a = error.params) === null || _a === void 0 ? void 0 : _a.firmwareUpdateCode) === PROTOCOL_V2_INSTALL_STATUS_CONFLICT_CODE));
|
|
51869
|
+
return error instanceof hdShared.HardwareError &&
|
|
51870
|
+
(error.errorCode === hdShared.HardwareErrorCode.ActionCancelled ||
|
|
51871
|
+
error.errorCode === hdShared.HardwareErrorCode.FirmwareError ||
|
|
51872
|
+
error.errorCode === hdShared.HardwareErrorCode.FirmwareVerificationFailed ||
|
|
51873
|
+
((_a = error.params) === null || _a === void 0 ? void 0 : _a.firmwareUpdateCode) === PROTOCOL_V2_INSTALL_STATUS_CONFLICT_CODE);
|
|
52313
51874
|
};
|
|
52314
51875
|
const isProtocolV2TargetStatusFinished = (status) => normalizeProtocolV2TargetStatus(status) === PROTOCOL_V2_TARGET_STATUS_FINISHED;
|
|
52315
51876
|
const isProtocolV2TargetStatusInProgress = (status) => normalizeProtocolV2TargetStatus(status) === PROTOCOL_V2_TARGET_STATUS_PENDING ||
|
|
@@ -52333,14 +51894,6 @@ const normalizeProtocolV2TargetStatus = (status) => {
|
|
|
52333
51894
|
}
|
|
52334
51895
|
return undefined;
|
|
52335
51896
|
};
|
|
52336
|
-
const PROTOCOL_V2_INSTALL_PHASE_BY_DECODED_VALUE = new Map([
|
|
52337
|
-
[0, 'prepare'],
|
|
52338
|
-
[1, 'install'],
|
|
52339
|
-
[2, 'verify'],
|
|
52340
|
-
['FW_MGMT_UPDATER_PHASE_PREPARE', 'prepare'],
|
|
52341
|
-
['FW_MGMT_UPDATER_PHASE_INSTALL', 'install'],
|
|
52342
|
-
['FW_MGMT_UPDATER_PHASE_VERIFY', 'verify'],
|
|
52343
|
-
]);
|
|
52344
51897
|
const normalizeProtocolV2Hex = (value) => value === null || value === void 0 ? void 0 : value.replace(/^0x/i, '').toLowerCase();
|
|
52345
51898
|
const versionArrayToNumber = (version) => {
|
|
52346
51899
|
if (!version)
|
|
@@ -52396,10 +51949,6 @@ const toProtocolV2FiniteNumber = (value) => {
|
|
|
52396
51949
|
}
|
|
52397
51950
|
return undefined;
|
|
52398
51951
|
};
|
|
52399
|
-
const normalizeProtocolV2ProgressPercent = (value) => {
|
|
52400
|
-
const progress = toProtocolV2FiniteNumber(value);
|
|
52401
|
-
return progress === undefined ? undefined : Math.min(100, Math.max(0, progress));
|
|
52402
|
-
};
|
|
52403
51952
|
const isProtocolV2FirmwareFingerprintValid = (binary, fingerprint) => {
|
|
52404
51953
|
const expectedFingerprint = normalizeProtocolV2Hex(fingerprint);
|
|
52405
51954
|
if (!expectedFingerprint)
|
|
@@ -52428,8 +51977,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52428
51977
|
this.protocolV2CompletedTargetVersions = new Map();
|
|
52429
51978
|
this.protocolV2CompletedTargetIds = new Set();
|
|
52430
51979
|
this.protocolV2InstallBaselineVersions = new Map();
|
|
52431
|
-
this.protocolV2InstallNeedsReconnect = false;
|
|
52432
|
-
this.protocolV2InstallTerminalSuccessObserved = false;
|
|
52433
51980
|
this.protocolV2LastTransferProgressAt = 0;
|
|
52434
51981
|
}
|
|
52435
51982
|
getSupportedProtocols() {
|
|
@@ -52600,7 +52147,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52600
52147
|
}
|
|
52601
52148
|
run() {
|
|
52602
52149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52603
|
-
Log$
|
|
52150
|
+
Log$7.debug('FirmwareUpdateV4 strategy: Protocol V2');
|
|
52604
52151
|
return this.runProtocolV2();
|
|
52605
52152
|
});
|
|
52606
52153
|
}
|
|
@@ -53032,7 +52579,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53032
52579
|
if (!observedVersion) {
|
|
53033
52580
|
const hasCompleteTargetEvidence = targetId !== undefined && this.protocolV2CompletedTargetIds.has(targetId);
|
|
53034
52581
|
if (hasCompleteTargetEvidence) {
|
|
53035
|
-
Log$
|
|
52582
|
+
Log$7.warn(`Protocol V2 target ${target} has no observable final version; install completion is authoritative`);
|
|
53036
52583
|
}
|
|
53037
52584
|
else {
|
|
53038
52585
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareVerificationFailed, `Protocol V2 target ${target} has no observable final version after status fallback`);
|
|
@@ -53395,10 +52942,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53395
52942
|
return true;
|
|
53396
52943
|
}
|
|
53397
52944
|
catch (error) {
|
|
53398
|
-
|
|
53399
|
-
throw error;
|
|
53400
|
-
}
|
|
53401
|
-
Log$6.log(`[FirmwareUpdateV4] RESC bundle ${bundle.name} header check failed: `, error);
|
|
52945
|
+
Log$7.log(`[FirmwareUpdateV4] RESC bundle ${bundle.name} header check failed: `, error);
|
|
53402
52946
|
return false;
|
|
53403
52947
|
}
|
|
53404
52948
|
});
|
|
@@ -53438,7 +52982,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53438
52982
|
if (error instanceof hdShared.HardwareError) {
|
|
53439
52983
|
throw error;
|
|
53440
52984
|
}
|
|
53441
|
-
Log$
|
|
52985
|
+
Log$7.log('Protocol V2 auto go to bootloader mode failed: ', error);
|
|
53442
52986
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure);
|
|
53443
52987
|
}
|
|
53444
52988
|
});
|
|
@@ -53446,12 +52990,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53446
52990
|
enterProtocolV2BootloaderMode() {
|
|
53447
52991
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53448
52992
|
if (this.isProtocolV2RomloaderMode()) {
|
|
53449
|
-
Log$
|
|
52993
|
+
Log$7.debug('Protocol V2 device is in romloader mode; start firmware update directly');
|
|
53450
52994
|
this.protocolV2ExecutionInLoader = true;
|
|
53451
52995
|
return false;
|
|
53452
52996
|
}
|
|
53453
52997
|
if (this.isProtocolV2BootloaderMode()) {
|
|
53454
|
-
Log$
|
|
52998
|
+
Log$7.debug('Protocol V2 device is already in bootloader mode, skip reboot');
|
|
53455
52999
|
this.protocolV2ExecutionInLoader = true;
|
|
53456
53000
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.GoToBootloaderSuccess);
|
|
53457
53001
|
return false;
|
|
@@ -53482,12 +53026,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53482
53026
|
lastError = new Error('Protocol V2 device is reachable but is not in bootloader mode');
|
|
53483
53027
|
}
|
|
53484
53028
|
catch (error) {
|
|
53485
|
-
if (
|
|
53029
|
+
if (this.isProtocolV2ReconnectIdentityError(error)) {
|
|
53486
53030
|
throw error;
|
|
53487
53031
|
}
|
|
53488
53032
|
shouldReconnect = true;
|
|
53489
53033
|
lastError = error;
|
|
53490
|
-
Log$
|
|
53034
|
+
Log$7.log('Protocol V2 bootloader mode not ready, polling reconnect: ', error);
|
|
53491
53035
|
}
|
|
53492
53036
|
yield hdShared.wait(retryInterval);
|
|
53493
53037
|
}
|
|
@@ -53583,7 +53127,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53583
53127
|
const resourcesToSync = [];
|
|
53584
53128
|
for (const resource of resourceSources) {
|
|
53585
53129
|
if (yield this.isProtocolV2ResourceBundleUpToDate(resource)) {
|
|
53586
|
-
Log$
|
|
53130
|
+
Log$7.log(`[FirmwareUpdateV4] skip RESC bundle ${resource.name}; already up to date`);
|
|
53587
53131
|
}
|
|
53588
53132
|
else {
|
|
53589
53133
|
resourcesToSync.push(resource);
|
|
@@ -53685,9 +53229,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53685
53229
|
return processedSize + source.size;
|
|
53686
53230
|
}
|
|
53687
53231
|
catch (error) {
|
|
53688
|
-
if (hdShared.isBleStaleBondHardwareError(error)) {
|
|
53689
|
-
throw error;
|
|
53690
|
-
}
|
|
53691
53232
|
lastError = error;
|
|
53692
53233
|
if (attempt < PROTOCOL_V2_FILE_TRANSFER_RETRY_COUNT) {
|
|
53693
53234
|
yield this.recoverProtocolV2FileTransfer();
|
|
@@ -53711,25 +53252,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53711
53252
|
}
|
|
53712
53253
|
});
|
|
53713
53254
|
}
|
|
53714
|
-
|
|
53715
|
-
|
|
53716
|
-
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53717
|
-
if (targetId !== undefined &&
|
|
53718
|
-
expectedTargetIds.has(targetId) &&
|
|
53719
|
-
isProtocolV2TargetStatusInProgress(target.status)) {
|
|
53720
|
-
liveTargetIds.add(targetId);
|
|
53721
|
-
}
|
|
53722
|
-
});
|
|
53723
|
-
}
|
|
53724
|
-
assertProtocolV2TargetStatus(statusTargets, expectedTargetIds, expectedPaths, liveTargetIds) {
|
|
53725
|
-
const resolvedExpectedPaths = expectedPaths !== null && expectedPaths !== void 0 ? expectedPaths : new Map();
|
|
53726
|
-
Log$6.log(`[FirmwareUpdateV4] DeviceFirmwareUpdateStatus records=${JSON.stringify(statusTargets)}`);
|
|
53255
|
+
assertProtocolV2TargetStatus(statusTargets, expectedTargetIds, expectedPaths = new Map()) {
|
|
53256
|
+
Log$7.log(`[FirmwareUpdateV4] DeviceFirmwareUpdateStatus records=${JSON.stringify(statusTargets)}`);
|
|
53727
53257
|
const failedTarget = statusTargets.find(target => {
|
|
53728
53258
|
var _a;
|
|
53729
|
-
|
|
53730
|
-
|
|
53731
|
-
isProtocolV2TargetStatusFailed(target.status) &&
|
|
53732
|
-
(!liveTargetIds || liveTargetIds.has(targetId)));
|
|
53259
|
+
return expectedTargetIds.has((_a = normalizeProtocolV2TargetId(target.target_id)) !== null && _a !== void 0 ? _a : -1) &&
|
|
53260
|
+
isProtocolV2TargetStatusFailed(target.status);
|
|
53733
53261
|
});
|
|
53734
53262
|
if (failedTarget) {
|
|
53735
53263
|
const failedTargetDetails = JSON.stringify({
|
|
@@ -53738,51 +53266,26 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53738
53266
|
payloadVersion: failedTarget.payload_version,
|
|
53739
53267
|
path: failedTarget.path,
|
|
53740
53268
|
});
|
|
53741
|
-
Log$
|
|
53269
|
+
Log$7.error(`[FirmwareUpdateV4] firmware install failed target=${failedTargetDetails}`);
|
|
53742
53270
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, 'Protocol V2 firmware install failed', {
|
|
53743
53271
|
firmwareUpdateCode: PROTOCOL_V2_INSTALL_FAILED_CODE,
|
|
53744
53272
|
});
|
|
53745
53273
|
}
|
|
53746
|
-
if (liveTargetIds) {
|
|
53747
|
-
const staleFailedTargets = statusTargets.filter(target => {
|
|
53748
|
-
var _a;
|
|
53749
|
-
const targetId = (_a = normalizeProtocolV2TargetId(target.target_id)) !== null && _a !== void 0 ? _a : -1;
|
|
53750
|
-
return (expectedTargetIds.has(targetId) &&
|
|
53751
|
-
isProtocolV2TargetStatusFailed(target.status) &&
|
|
53752
|
-
!liveTargetIds.has(targetId));
|
|
53753
|
-
});
|
|
53754
|
-
if (staleFailedTargets.length > 0) {
|
|
53755
|
-
Log$6.log(`[FirmwareUpdateV4] ignoring stale failed firmware status until those targets start: ${JSON.stringify(staleFailedTargets.map(target => ({
|
|
53756
|
-
targetId: target.target_id,
|
|
53757
|
-
status: target.status,
|
|
53758
|
-
path: target.path,
|
|
53759
|
-
})))}`);
|
|
53760
|
-
}
|
|
53761
|
-
}
|
|
53762
53274
|
const matchingTargets = statusTargets.filter(target => { var _a; return expectedTargetIds.has((_a = normalizeProtocolV2TargetId(target.target_id)) !== null && _a !== void 0 ? _a : -1); });
|
|
53763
53275
|
const seenTargetIds = new Set();
|
|
53764
53276
|
for (const target of matchingTargets) {
|
|
53765
53277
|
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53766
|
-
const pathConflictsWithCurrentInstall = targetId !== undefined &&
|
|
53767
|
-
Boolean(target.path) &&
|
|
53768
|
-
Boolean(resolvedExpectedPaths.get(targetId)) &&
|
|
53769
|
-
target.path !== resolvedExpectedPaths.get(targetId) &&
|
|
53770
|
-
(!liveTargetIds || liveTargetIds.has(targetId));
|
|
53771
53278
|
if (targetId === undefined ||
|
|
53772
53279
|
seenTargetIds.has(targetId) ||
|
|
53773
|
-
|
|
53774
|
-
Log$
|
|
53280
|
+
(target.path && expectedPaths.get(targetId) && target.path !== expectedPaths.get(targetId))) {
|
|
53281
|
+
Log$7.error(`[FirmwareUpdateV4] install status conflicts with target=${target.target_id}`);
|
|
53775
53282
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, 'Protocol V2 firmware install status conflict', {
|
|
53776
53283
|
firmwareUpdateCode: PROTOCOL_V2_INSTALL_STATUS_CONFLICT_CODE,
|
|
53777
53284
|
});
|
|
53778
53285
|
}
|
|
53779
53286
|
seenTargetIds.add(targetId);
|
|
53780
53287
|
}
|
|
53781
|
-
const completedTargets = matchingTargets.filter(target =>
|
|
53782
|
-
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53783
|
-
return (isProtocolV2TargetStatusFinished(target.status) &&
|
|
53784
|
-
(!liveTargetIds || (targetId !== undefined && liveTargetIds.has(targetId))));
|
|
53785
|
-
});
|
|
53288
|
+
const completedTargets = matchingTargets.filter(target => isProtocolV2TargetStatusFinished(target.status));
|
|
53786
53289
|
const completedTargetIds = new Set();
|
|
53787
53290
|
completedTargets.forEach(target => {
|
|
53788
53291
|
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
@@ -53812,41 +53315,10 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53812
53315
|
return true;
|
|
53813
53316
|
}
|
|
53814
53317
|
if (expectedTargetIds.size > 0 && matchingTargets.length > 0) {
|
|
53815
|
-
|
|
53816
|
-
let installProgressMetadata;
|
|
53817
|
-
let hasInProgressTarget = false;
|
|
53818
|
-
matchingTargets.forEach(target => {
|
|
53819
|
-
var _a, _b;
|
|
53820
|
-
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53821
|
-
if (targetId === undefined ||
|
|
53822
|
-
completedTargetIds.has(targetId) ||
|
|
53823
|
-
!isProtocolV2TargetStatusInProgress(target.status) ||
|
|
53824
|
-
(liveTargetIds && !liveTargetIds.has(targetId))) {
|
|
53825
|
-
return;
|
|
53826
|
-
}
|
|
53827
|
-
hasInProgressTarget = true;
|
|
53828
|
-
detailedProgress += (_a = normalizeProtocolV2ProgressPercent(target.progress_percent)) !== null && _a !== void 0 ? _a : 0;
|
|
53829
|
-
const installPhase = target.phase_info
|
|
53830
|
-
? PROTOCOL_V2_INSTALL_PHASE_BY_DECODED_VALUE.get(target.phase_info.phase)
|
|
53831
|
-
: undefined;
|
|
53832
|
-
const installPhaseProgress = normalizeProtocolV2ProgressPercent((_b = target.phase_info) === null || _b === void 0 ? void 0 : _b.progress_percent);
|
|
53833
|
-
if (installPhase && installPhaseProgress !== undefined && !installProgressMetadata) {
|
|
53834
|
-
installProgressMetadata = {
|
|
53835
|
-
installTargetId: targetId,
|
|
53836
|
-
installPhase,
|
|
53837
|
-
installPhaseProgress,
|
|
53838
|
-
};
|
|
53839
|
-
}
|
|
53840
|
-
});
|
|
53318
|
+
const hasInProgressTarget = matchingTargets.some(target => isProtocolV2TargetStatusInProgress(target.status));
|
|
53841
53319
|
const completedProgress = Math.floor((completedTargetIds.size / expectedTargetIds.size) * 100);
|
|
53842
|
-
const
|
|
53843
|
-
|
|
53844
|
-
if (installProgressMetadata) {
|
|
53845
|
-
this.postProgressMessage(progress, 'installingFirmware', installProgressMetadata);
|
|
53846
|
-
}
|
|
53847
|
-
else {
|
|
53848
|
-
this.postProgressMessage(progress, 'installingFirmware');
|
|
53849
|
-
}
|
|
53320
|
+
const progress = Math.min(99, Math.max(completedProgress, hasInProgressTarget ? 1 : 0));
|
|
53321
|
+
this.postProgressMessage(progress, 'installingFirmware');
|
|
53850
53322
|
}
|
|
53851
53323
|
return false;
|
|
53852
53324
|
}
|
|
@@ -53899,54 +53371,43 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53899
53371
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53900
53372
|
const expectedTargetIds = new Set(targets.map(target => target.target_id));
|
|
53901
53373
|
const expectedPaths = new Map(targets.map(target => [target.target_id, target.path]));
|
|
53902
|
-
const isBleCoprocessorInstall = this.isBleReconnect() &&
|
|
53903
|
-
expectedTargetIds.has(ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_COPROCESSOR);
|
|
53904
53374
|
const startTime = Date.now();
|
|
53905
53375
|
let lastError;
|
|
53906
|
-
let shouldReconnect =
|
|
53907
|
-
this.protocolV2InstallNeedsReconnect = false;
|
|
53376
|
+
let shouldReconnect = false;
|
|
53908
53377
|
let deviceInfo;
|
|
53909
|
-
let
|
|
53910
|
-
let installStatusDisconnectObserved = false;
|
|
53911
|
-
let installReconnectObserved = false;
|
|
53912
|
-
let finishedStatusSnapshotKey;
|
|
53913
|
-
let finishedStatusSnapshotPolls = 0;
|
|
53914
|
-
let fastFinishedInstallProgressReported = false;
|
|
53915
|
-
let installEvidenceObserved = this.protocolV2InstallTerminalSuccessObserved;
|
|
53378
|
+
let installEvidenceObserved = false;
|
|
53916
53379
|
let currentInstallStatusObserved = false;
|
|
53917
|
-
const liveTargetIds = new Set();
|
|
53918
53380
|
while (Date.now() - startTime < PROTOCOL_V2_INSTALL_TIMEOUT) {
|
|
53919
53381
|
this.throwIfAborted();
|
|
53920
53382
|
try {
|
|
53921
53383
|
if (shouldReconnect) {
|
|
53922
|
-
|
|
53923
|
-
yield this.
|
|
53924
|
-
bleInstallLinkReady = isBleInstallReconnect;
|
|
53925
|
-
deviceInfo = isBleInstallReconnect
|
|
53926
|
-
? undefined
|
|
53927
|
-
: yield this.verifyProtocolV2ReconnectIdentity();
|
|
53928
|
-
if (isBleInstallReconnect && installStatusDisconnectObserved) {
|
|
53929
|
-
installReconnectObserved = true;
|
|
53930
|
-
}
|
|
53384
|
+
yield this.reconnectProtocolV2Device();
|
|
53385
|
+
deviceInfo = yield this.verifyProtocolV2ReconnectIdentity();
|
|
53931
53386
|
shouldReconnect = false;
|
|
53932
53387
|
}
|
|
53933
|
-
|
|
53388
|
+
const currentDeviceInfo = deviceInfo;
|
|
53934
53389
|
try {
|
|
53935
|
-
const statusResponse = yield this.device.getCommands().typedCall('DeviceFirmwareUpdateStatusGet', 'DeviceFirmwareUpdateStatus', {
|
|
53390
|
+
const statusResponse = yield this.device.getCommands().typedCall('DeviceFirmwareUpdateStatusGet', ['DeviceFirmwareUpdateStatus', 'Success'], {
|
|
53936
53391
|
fields: {
|
|
53937
53392
|
status: true,
|
|
53938
|
-
progress_percent: true,
|
|
53939
|
-
phase_info: true,
|
|
53940
53393
|
payload_version: true,
|
|
53941
53394
|
path: true,
|
|
53942
53395
|
},
|
|
53943
53396
|
}, { timeoutMs: PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT });
|
|
53944
|
-
if (
|
|
53397
|
+
if (statusResponse.type === 'Success') {
|
|
53945
53398
|
installEvidenceObserved = true;
|
|
53399
|
+
lastError = new Error('Protocol V2 firmware install acknowledged; waiting for target status');
|
|
53946
53400
|
}
|
|
53947
|
-
const statusTargets =
|
|
53948
|
-
|
|
53949
|
-
|
|
53401
|
+
const statusTargets = statusResponse.type === 'DeviceFirmwareUpdateStatus'
|
|
53402
|
+
? ((_a = statusResponse.message.records) !== null && _a !== void 0 ? _a : [])
|
|
53403
|
+
: [];
|
|
53404
|
+
const hasInProgressTarget = statusTargets.some(target => {
|
|
53405
|
+
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53406
|
+
return (targetId !== undefined &&
|
|
53407
|
+
expectedTargetIds.has(targetId) &&
|
|
53408
|
+
isProtocolV2TargetStatusInProgress(target.status));
|
|
53409
|
+
});
|
|
53410
|
+
if (hasInProgressTarget) {
|
|
53950
53411
|
currentInstallStatusObserved = true;
|
|
53951
53412
|
}
|
|
53952
53413
|
const hasMatchingTargetStatus = statusTargets.some(target => {
|
|
@@ -53961,102 +53422,31 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53961
53422
|
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53962
53423
|
return targetId !== undefined && expectedTargetIds.has(targetId);
|
|
53963
53424
|
});
|
|
53964
|
-
const
|
|
53965
|
-
const matchingFinishedStatus = matchingStatusTargets
|
|
53966
|
-
.map(target => {
|
|
53967
|
-
var _a;
|
|
53968
|
-
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53969
|
-
const expectedPath = targetId === undefined ? undefined : expectedPaths.get(targetId);
|
|
53970
|
-
const expectedVersion = targetId === undefined
|
|
53971
|
-
? undefined
|
|
53972
|
-
: this.getExpectedProtocolV2TargetVersion(targetId);
|
|
53973
|
-
const payloadVersion = toProtocolV2FiniteNumber(target.payload_version);
|
|
53974
|
-
if (targetId === undefined ||
|
|
53975
|
-
matchingFinishedTargetIds.has(targetId) ||
|
|
53976
|
-
!isProtocolV2TargetStatusFinished(target.status) ||
|
|
53977
|
-
(Boolean(target.path) && Boolean(expectedPath) && target.path !== expectedPath) ||
|
|
53978
|
-
(expectedVersion !== undefined &&
|
|
53979
|
-
payloadVersion !== undefined &&
|
|
53980
|
-
payloadVersion !== expectedVersion)) {
|
|
53981
|
-
return undefined;
|
|
53982
|
-
}
|
|
53983
|
-
matchingFinishedTargetIds.add(targetId);
|
|
53984
|
-
return [targetId, (_a = target.path) !== null && _a !== void 0 ? _a : null, payloadVersion !== null && payloadVersion !== void 0 ? payloadVersion : null];
|
|
53985
|
-
})
|
|
53986
|
-
.filter((target) => !!target)
|
|
53987
|
-
.sort(([leftTargetId], [rightTargetId]) => leftTargetId - rightTargetId);
|
|
53988
|
-
const hasCompleteMatchingFinishedStatus = matchingFinishedStatus.length === expectedTargetIds.size &&
|
|
53989
|
-
matchingFinishedTargetIds.size === expectedTargetIds.size &&
|
|
53990
|
-
expectedTargetIds.size > 0;
|
|
53991
|
-
if (requireCurrentInstallStatus &&
|
|
53992
|
-
installReconnectObserved &&
|
|
53993
|
-
hasCompleteMatchingFinishedStatus) {
|
|
53994
|
-
const nextSnapshotKey = JSON.stringify(matchingFinishedStatus);
|
|
53995
|
-
if (nextSnapshotKey === finishedStatusSnapshotKey) {
|
|
53996
|
-
finishedStatusSnapshotPolls += 1;
|
|
53997
|
-
}
|
|
53998
|
-
else {
|
|
53999
|
-
finishedStatusSnapshotKey = nextSnapshotKey;
|
|
54000
|
-
finishedStatusSnapshotPolls = 1;
|
|
54001
|
-
}
|
|
54002
|
-
}
|
|
54003
|
-
else {
|
|
54004
|
-
finishedStatusSnapshotKey = undefined;
|
|
54005
|
-
finishedStatusSnapshotPolls = 0;
|
|
54006
|
-
}
|
|
54007
|
-
if (requireCurrentInstallStatus &&
|
|
54008
|
-
installReconnectObserved &&
|
|
54009
|
-
hasCompleteMatchingFinishedStatus &&
|
|
54010
|
-
!currentInstallStatusObserved &&
|
|
54011
|
-
!this.protocolV2InstallTerminalSuccessObserved &&
|
|
54012
|
-
!fastFinishedInstallProgressReported) {
|
|
54013
|
-
this.postProgressMessage(1, 'installingFirmware');
|
|
54014
|
-
fastFinishedInstallProgressReported = true;
|
|
54015
|
-
}
|
|
54016
|
-
const finishedAfterDisconnectObserved = finishedStatusSnapshotPolls >= PROTOCOL_V2_INSTALL_FINISHED_AFTER_DISCONNECT_POLLS;
|
|
54017
|
-
const hasCurrentInstallEvidence = currentInstallStatusObserved ||
|
|
54018
|
-
this.protocolV2InstallTerminalSuccessObserved ||
|
|
54019
|
-
finishedAfterDisconnectObserved;
|
|
54020
|
-
if (hasCurrentInstallEvidence) {
|
|
54021
|
-
installEvidenceObserved = true;
|
|
54022
|
-
}
|
|
54023
|
-
const shouldVerifyTargetCompletion = !requireCurrentInstallStatus || hasCurrentInstallEvidence;
|
|
53425
|
+
const shouldVerifyTargetCompletion = !requireCurrentInstallStatus || currentInstallStatusObserved;
|
|
54024
53426
|
if (shouldVerifyTargetCompletion &&
|
|
54025
|
-
this.assertProtocolV2TargetStatus(statusTargets, expectedTargetIds, expectedPaths
|
|
54026
|
-
!this.protocolV2InstallTerminalSuccessObserved &&
|
|
54027
|
-
!finishedAfterDisconnectObserved
|
|
54028
|
-
? liveTargetIds
|
|
54029
|
-
: undefined)) {
|
|
53427
|
+
this.assertProtocolV2TargetStatus(statusTargets, expectedTargetIds, expectedPaths)) {
|
|
54030
53428
|
return;
|
|
54031
53429
|
}
|
|
54032
|
-
if (!hasCurrentInstallEvidence) {
|
|
54033
|
-
this.device.setCancelableAction(() => this.device.getCommands().cancelDevice());
|
|
54034
|
-
}
|
|
54035
53430
|
if (requireCurrentInstallStatus &&
|
|
54036
|
-
!
|
|
53431
|
+
!currentInstallStatusObserved &&
|
|
54037
53432
|
matchingStatusTargets.length > 0) {
|
|
54038
53433
|
lastError = new Error('Protocol V2 firmware status is stale; waiting for the current install to start');
|
|
54039
53434
|
}
|
|
54040
|
-
if (statusTargets.length === 0 &&
|
|
54041
|
-
!currentDeviceInfo &&
|
|
54042
|
-
bleInstallLinkReady &&
|
|
54043
|
-
installEvidenceObserved) {
|
|
54044
|
-
currentDeviceInfo = yield this.verifyProtocolV2ReconnectIdentity();
|
|
54045
|
-
deviceInfo = currentDeviceInfo;
|
|
54046
|
-
}
|
|
54047
53435
|
if (statusTargets.length === 0 && currentDeviceInfo) {
|
|
54048
53436
|
const isNormalMode = yield this.probeProtocolV2NormalMode(currentDeviceInfo);
|
|
54049
53437
|
if (isNormalMode &&
|
|
54050
53438
|
(installEvidenceObserved ||
|
|
54051
53439
|
this.hasProtocolV2InstallVersionChanged(expectedTargetIds))) {
|
|
54052
|
-
Log$
|
|
53440
|
+
Log$7.log('[FirmwareUpdateV4] empty firmware status after confirmed App reboot; update complete');
|
|
54053
53441
|
this.recordProtocolV2AuthoritativeInstallCompletion(expectedTargetIds);
|
|
54054
53442
|
this.postProgressMessage(100, 'installingFirmware');
|
|
54055
53443
|
return;
|
|
54056
53444
|
}
|
|
54057
53445
|
}
|
|
54058
53446
|
if (statusTargets.length === 0) {
|
|
54059
|
-
|
|
53447
|
+
if (statusResponse.type !== 'Success') {
|
|
53448
|
+
lastError = new Error('Protocol V2 firmware update is waiting for user confirmation or target status');
|
|
53449
|
+
}
|
|
54060
53450
|
}
|
|
54061
53451
|
else {
|
|
54062
53452
|
const missingTargetIds = this.getProtocolV2MissingTargetIds(statusTargets, expectedTargetIds);
|
|
@@ -54075,20 +53465,13 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54075
53465
|
}
|
|
54076
53466
|
if (isProtocolV2FirmwareStatusEndpointUnavailable(error)) {
|
|
54077
53467
|
if (!currentDeviceInfo) {
|
|
54078
|
-
if (!bleInstallLinkReady) {
|
|
54079
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 device identity is unavailable during install polling');
|
|
54080
|
-
}
|
|
54081
|
-
deviceInfo = yield this.verifyProtocolV2ReconnectIdentity();
|
|
54082
|
-
}
|
|
54083
|
-
const reconnectDeviceInfo = currentDeviceInfo !== null && currentDeviceInfo !== void 0 ? currentDeviceInfo : deviceInfo;
|
|
54084
|
-
if (!reconnectDeviceInfo) {
|
|
54085
53468
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 device identity is unavailable during install polling');
|
|
54086
53469
|
}
|
|
54087
|
-
const isNormalMode = yield this.probeProtocolV2NormalMode(
|
|
53470
|
+
const isNormalMode = yield this.probeProtocolV2NormalMode(currentDeviceInfo);
|
|
54088
53471
|
if (isNormalMode &&
|
|
54089
53472
|
(installEvidenceObserved ||
|
|
54090
53473
|
this.hasProtocolV2InstallVersionChanged(expectedTargetIds))) {
|
|
54091
|
-
Log$
|
|
53474
|
+
Log$7.log('[FirmwareUpdateV4] firmware status endpoint unavailable after confirmed App reboot');
|
|
54092
53475
|
this.recordProtocolV2AuthoritativeInstallCompletion(expectedTargetIds);
|
|
54093
53476
|
this.postProgressMessage(100, 'installingFirmware');
|
|
54094
53477
|
return;
|
|
@@ -54101,18 +53484,10 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54101
53484
|
}
|
|
54102
53485
|
}
|
|
54103
53486
|
else {
|
|
54104
|
-
if (isBleCoprocessorInstall &&
|
|
54105
|
-
isProtocolV2DeviceDisconnectedError(error) &&
|
|
54106
|
-
!isProtocolV2ResponseTimeout(error)) {
|
|
54107
|
-
installStatusDisconnectObserved = true;
|
|
54108
|
-
finishedStatusSnapshotKey = undefined;
|
|
54109
|
-
finishedStatusSnapshotPolls = 0;
|
|
54110
|
-
}
|
|
54111
53487
|
shouldReconnect = true;
|
|
54112
53488
|
deviceInfo = undefined;
|
|
54113
|
-
bleInstallLinkReady = false;
|
|
54114
53489
|
lastError = error;
|
|
54115
|
-
Log$
|
|
53490
|
+
Log$7.log('[FirmwareUpdateV4] DeviceFirmwareUpdateStatusGet unavailable during install: ', error);
|
|
54116
53491
|
}
|
|
54117
53492
|
}
|
|
54118
53493
|
}
|
|
@@ -54130,12 +53505,11 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54130
53505
|
}
|
|
54131
53506
|
shouldReconnect = true;
|
|
54132
53507
|
deviceInfo = undefined;
|
|
54133
|
-
|
|
54134
|
-
Log$6.log('Protocol V2 firmware install device readiness probe failed: ', error);
|
|
53508
|
+
Log$7.log('Protocol V2 firmware install device readiness probe failed: ', error);
|
|
54135
53509
|
}
|
|
54136
53510
|
yield hdShared.wait(1000);
|
|
54137
53511
|
}
|
|
54138
|
-
Log$
|
|
53512
|
+
Log$7.error(`[FirmwareUpdateV4] install timed out after ${PROTOCOL_V2_INSTALL_TIMEOUT / 1000}s: ${this.normalizeErrorMessage(lastError)}`);
|
|
54139
53513
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, 'Protocol V2 firmware install timed out', {
|
|
54140
53514
|
firmwareUpdateCode: PROTOCOL_V2_INSTALL_TIMEOUT_CODE,
|
|
54141
53515
|
});
|
|
@@ -54147,15 +53521,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54147
53521
|
const deviceInfo = yield this.verifyProtocolV2ReconnectIdentity();
|
|
54148
53522
|
try {
|
|
54149
53523
|
if (yield this.probeProtocolV2NormalMode(deviceInfo)) {
|
|
54150
|
-
Log$
|
|
53524
|
+
Log$7.log('[FirmwareUpdateV4] device already returned to App mode; skip Normal reboot');
|
|
54151
53525
|
return;
|
|
54152
53526
|
}
|
|
54153
53527
|
}
|
|
54154
53528
|
catch (error) {
|
|
54155
|
-
|
|
54156
|
-
throw error;
|
|
54157
|
-
}
|
|
54158
|
-
Log$6.log('[FirmwareUpdateV4] unable to confirm App mode before Normal reboot: ', error);
|
|
53529
|
+
Log$7.log('[FirmwareUpdateV4] unable to confirm App mode before Normal reboot: ', error);
|
|
54159
53530
|
}
|
|
54160
53531
|
yield this.protocolV2Reboot(hdTransport.DeviceRebootType.Normal);
|
|
54161
53532
|
this.protocolV2ExecutionInLoader = false;
|
|
@@ -54183,7 +53554,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54183
53554
|
const firmwareVersion = getDeviceFirmwareVersion(features).join('.');
|
|
54184
53555
|
this.protocolV2LatestFinalFeatures = features;
|
|
54185
53556
|
if (firmwareVersion === '0.0.0') {
|
|
54186
|
-
Log$
|
|
53557
|
+
Log$7.warn('Protocol V2 firmware update finished but app firmware version is still 0.0.0. This is allowed for Pro2 debug BLE-only update flows.');
|
|
54187
53558
|
}
|
|
54188
53559
|
return {
|
|
54189
53560
|
bootloaderVersion,
|
|
@@ -54229,49 +53600,29 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54229
53600
|
lastError = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, 'Protocol V2 device is still in bootloader mode');
|
|
54230
53601
|
}
|
|
54231
53602
|
catch (error) {
|
|
54232
|
-
if (
|
|
53603
|
+
if (this.isProtocolV2ReconnectIdentityError(error)) {
|
|
54233
53604
|
throw error;
|
|
54234
53605
|
}
|
|
54235
53606
|
shouldReconnect = true;
|
|
54236
53607
|
lastError = error;
|
|
54237
|
-
Log$
|
|
53608
|
+
Log$7.log('Protocol V2 normal mode not ready, polling Ping: ', error);
|
|
54238
53609
|
}
|
|
54239
53610
|
yield hdShared.wait(1000);
|
|
54240
53611
|
}
|
|
54241
53612
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, `Protocol V2 final features not ready within ${timeout / 1000}s: ${this.normalizeErrorMessage(lastError)}`);
|
|
54242
53613
|
});
|
|
54243
53614
|
}
|
|
54244
|
-
reconnectProtocolV2Device(
|
|
54245
|
-
var _a, _b, _c, _d, _e, _f
|
|
53615
|
+
reconnectProtocolV2Device() {
|
|
53616
|
+
var _a, _b, _c, _d, _e, _f;
|
|
54246
53617
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54247
53618
|
if (this.isBleReconnect()) {
|
|
54248
|
-
yield this.acquireProtocolV2BleDevice(
|
|
53619
|
+
yield this.acquireProtocolV2BleDevice();
|
|
54249
53620
|
return;
|
|
54250
53621
|
}
|
|
54251
53622
|
const deviceDiff = yield ((_a = this.device.deviceConnector) === null || _a === void 0 ? void 0 : _a.enumerate());
|
|
54252
53623
|
const devicesDescriptor = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
|
|
54253
|
-
|
|
54254
|
-
|
|
54255
|
-
if (isWebUsb && (options === null || options === void 0 ? void 0 : options.skipProtocolProbe)) {
|
|
54256
|
-
const expectedSerialNumber = (_c = this.protocolV2ExpectedSerialNumber) === null || _c === void 0 ? void 0 : _c.trim();
|
|
54257
|
-
const expectedPath = (_d = this.protocolV2ExpectedPath) === null || _d === void 0 ? void 0 : _d.trim();
|
|
54258
|
-
const reconnectDescriptor = devicesDescriptor.find(descriptor => {
|
|
54259
|
-
var _a;
|
|
54260
|
-
const descriptorPath = (_a = descriptor.path) === null || _a === void 0 ? void 0 : _a.trim();
|
|
54261
|
-
return ((!!expectedSerialNumber && descriptorPath === expectedSerialNumber) ||
|
|
54262
|
-
(!!expectedPath && descriptorPath === expectedPath));
|
|
54263
|
-
});
|
|
54264
|
-
if (!(reconnectDescriptor === null || reconnectDescriptor === void 0 ? void 0 : reconnectDescriptor.path)) {
|
|
54265
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
|
|
54266
|
-
}
|
|
54267
|
-
this.device.updateDescriptor(Object.assign(Object.assign({}, reconnectDescriptor), { protocolType: PROTOCOL_V2_CONNECT_PROTOCOL }), true);
|
|
54268
|
-
const mainId = yield ((_e = this.device.deviceConnector) === null || _e === void 0 ? void 0 : _e.acquire(reconnectDescriptor.path, null, undefined, PROTOCOL_V2_CONNECT_PROTOCOL, undefined, undefined, true));
|
|
54269
|
-
this.device.mainId = typeof mainId === 'string' ? mainId : reconnectDescriptor.path;
|
|
54270
|
-
this.device.commands.disposed = false;
|
|
54271
|
-
this.device.getCommands().mainId = this.device.mainId;
|
|
54272
|
-
return;
|
|
54273
|
-
}
|
|
54274
|
-
if (isWebUsb && devicesDescriptor.length === 1) {
|
|
53624
|
+
if (DataManager.isBrowserWebUsb(DataManager.getSettings('env')) &&
|
|
53625
|
+
devicesDescriptor.length === 1) {
|
|
54275
53626
|
const descriptor = devicesDescriptor[0];
|
|
54276
53627
|
if (!this.protocolV2ExpectedSerialNumber && descriptor.path !== this.protocolV2ExpectedPath) {
|
|
54277
53628
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
|
|
@@ -54279,14 +53630,14 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54279
53630
|
this.device.updateDescriptor(Object.assign(Object.assign({}, descriptor), { protocolType: PROTOCOL_V2_CONNECT_PROTOCOL }), true);
|
|
54280
53631
|
yield this.ensureProtocolV2DeviceAcquired();
|
|
54281
53632
|
this.device.commands.disposed = false;
|
|
54282
|
-
this.device.getCommands().mainId = (
|
|
53633
|
+
this.device.getCommands().mainId = (_c = this.device.mainId) !== null && _c !== void 0 ? _c : '';
|
|
54283
53634
|
return;
|
|
54284
53635
|
}
|
|
54285
53636
|
const { deviceList } = yield DevicePool.getDevices(devicesDescriptor, undefined, {
|
|
54286
53637
|
connectProtocol: PROTOCOL_V2_CONNECT_PROTOCOL,
|
|
54287
53638
|
});
|
|
54288
|
-
const expectedSerialNumber = (
|
|
54289
|
-
const expectedPath = (
|
|
53639
|
+
const expectedSerialNumber = (_d = this.protocolV2ExpectedSerialNumber) === null || _d === void 0 ? void 0 : _d.trim();
|
|
53640
|
+
const expectedPath = (_e = this.protocolV2ExpectedPath) === null || _e === void 0 ? void 0 : _e.trim();
|
|
54290
53641
|
const reconnectDevice = deviceList.find(candidate => {
|
|
54291
53642
|
var _a;
|
|
54292
53643
|
const candidateSerialNumber = (_a = candidate.getCurrentSerialNo) === null || _a === void 0 ? void 0 : _a.call(candidate).trim();
|
|
@@ -54298,11 +53649,11 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54298
53649
|
if (!reconnectDevice) {
|
|
54299
53650
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
|
|
54300
53651
|
}
|
|
54301
|
-
Log$
|
|
53652
|
+
Log$7.debug('Protocol V2 firmware reconnect using matched device:', reconnectDevice.getConnectId());
|
|
54302
53653
|
this.device.updateFromCache(reconnectDevice);
|
|
54303
53654
|
yield this.ensureProtocolV2DeviceAcquired();
|
|
54304
53655
|
this.device.commands.disposed = false;
|
|
54305
|
-
this.device.getCommands().mainId = (
|
|
53656
|
+
this.device.getCommands().mainId = (_f = this.device.mainId) !== null && _f !== void 0 ? _f : '';
|
|
54306
53657
|
});
|
|
54307
53658
|
}
|
|
54308
53659
|
ensureProtocolV2DeviceAcquired() {
|
|
@@ -54339,8 +53690,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54339
53690
|
});
|
|
54340
53691
|
if (writeRes.type !== 'FilesystemFile') {
|
|
54341
53692
|
if (writeRes.type === 'CallMethodError') {
|
|
54342
|
-
if (((_a = writeRes.message.error) !== null && _a !== void 0 ? _a : '').indexOf(SESSION_ERROR) > -1) {
|
|
54343
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, SESSION_ERROR);
|
|
53693
|
+
if (((_a = writeRes.message.error) !== null && _a !== void 0 ? _a : '').indexOf(SESSION_ERROR$1) > -1) {
|
|
53694
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, SESSION_ERROR$1);
|
|
54344
53695
|
}
|
|
54345
53696
|
}
|
|
54346
53697
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.EmmcFileWriteFirmwareError, 'transfer data error');
|
|
@@ -54360,51 +53711,21 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54360
53711
|
yield hdShared.wait(2000);
|
|
54361
53712
|
});
|
|
54362
53713
|
}
|
|
54363
|
-
acquireProtocolV2BleDevice(
|
|
53714
|
+
acquireProtocolV2BleDevice() {
|
|
53715
|
+
var _a;
|
|
54364
53716
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54365
|
-
|
|
54366
|
-
const expectedId = this.device.originalDescriptor.id;
|
|
54367
|
-
if (!skipProtocolProbe) {
|
|
54368
|
-
yield (connector === null || connector === void 0 ? void 0 : connector.acquire(expectedId, null, true, PROTOCOL_V2_CONNECT_PROTOCOL));
|
|
54369
|
-
return;
|
|
54370
|
-
}
|
|
54371
|
-
yield (connector === null || connector === void 0 ? void 0 : connector.acquire(expectedId, null, true, PROTOCOL_V2_CONNECT_PROTOCOL, undefined, undefined, skipProtocolProbe));
|
|
54372
|
-
this.device.commands.disposed = false;
|
|
54373
|
-
this.device.getCommands().mainId = expectedId;
|
|
53717
|
+
yield ((_a = this.device.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.device.originalDescriptor.id, null, true, PROTOCOL_V2_CONNECT_PROTOCOL));
|
|
54374
53718
|
});
|
|
54375
53719
|
}
|
|
54376
53720
|
protocolV2StartFirmwareUpdate({ targets, }) {
|
|
54377
53721
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54378
53722
|
this.protocolV2LastRuntimeProbeFeatures = undefined;
|
|
54379
|
-
this.protocolV2InstallNeedsReconnect = false;
|
|
54380
|
-
this.protocolV2InstallTerminalSuccessObserved = false;
|
|
54381
53723
|
const commands = this.device.getCommands();
|
|
54382
53724
|
yield commands.typedCall('DeviceFirmwareUpdateStage', 'Success', { targets });
|
|
54383
|
-
this.device.setCancelableAction(() =>
|
|
53725
|
+
this.device.setCancelableAction(() => commands.cancelDevice());
|
|
54384
53726
|
const interaction = this.device.createProtocolV2UiPhaseMetadata('button', 'start');
|
|
54385
53727
|
this.postMessage(createUiMessage(UI_REQUEST.REQUEST_BUTTON, Object.assign({ device: this.device.toMessageObject(), source: 'method-lifecycle', reason: 'firmware-update', completion: 'operation-completed', deviceOnly: true, operation: this.name }, (interaction ? { interaction } : {}))));
|
|
54386
|
-
|
|
54387
|
-
yield commands.call('DeviceFirmwareUpdateRequest', {}, {
|
|
54388
|
-
returnAfterWrite: true,
|
|
54389
|
-
expectedTypes: ['Success'],
|
|
54390
|
-
onResponseAfterWrite: response => {
|
|
54391
|
-
if (response.type !== 'Success')
|
|
54392
|
-
return;
|
|
54393
|
-
this.protocolV2InstallTerminalSuccessObserved = true;
|
|
54394
|
-
this.device.clearCancelableAction();
|
|
54395
|
-
Log$6.log('[FirmwareUpdateV4] firmware install completed by device response');
|
|
54396
|
-
},
|
|
54397
|
-
});
|
|
54398
|
-
Log$6.log('[FirmwareUpdateV4] firmware install request written; continue with status polling');
|
|
54399
|
-
}
|
|
54400
|
-
catch (error) {
|
|
54401
|
-
this.throwIfAborted();
|
|
54402
|
-
if (!isProtocolV2DeviceDisconnectedError(error)) {
|
|
54403
|
-
throw error;
|
|
54404
|
-
}
|
|
54405
|
-
Log$6.log('[FirmwareUpdateV4] transport released while writing install request; continue status polling');
|
|
54406
|
-
this.protocolV2InstallNeedsReconnect = true;
|
|
54407
|
-
}
|
|
53728
|
+
yield commands.call('DeviceFirmwareUpdateRequest', {}, { returnAfterWrite: true });
|
|
54408
53729
|
});
|
|
54409
53730
|
}
|
|
54410
53731
|
protocolV2Reboot(rebootType) {
|
|
@@ -54413,14 +53734,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54413
53734
|
try {
|
|
54414
53735
|
const res = yield typedCall('DeviceReboot', 'Success', {
|
|
54415
53736
|
reboot_type: rebootType,
|
|
54416
|
-
}
|
|
53737
|
+
});
|
|
54417
53738
|
this.device.markProtocolV2Reboot(rebootType);
|
|
54418
53739
|
return res.message;
|
|
54419
53740
|
}
|
|
54420
53741
|
catch (error) {
|
|
54421
|
-
if (isProtocolV2DeviceDisconnectedError(error) ||
|
|
54422
|
-
isProtocolV2ReconnectProbeError(error) ||
|
|
54423
|
-
isProtocolV2ResponseTimeout(error)) {
|
|
53742
|
+
if (isProtocolV2DeviceDisconnectedError(error) || isProtocolV2ReconnectProbeError(error)) {
|
|
54424
53743
|
this.device.markProtocolV2Reboot(rebootType);
|
|
54425
53744
|
return { message: 'Device rebooted successfully' };
|
|
54426
53745
|
}
|
|
@@ -54436,7 +53755,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54436
53755
|
}
|
|
54437
53756
|
}
|
|
54438
53757
|
|
|
54439
|
-
const Log$
|
|
53758
|
+
const Log$6 = getLogger(exports.LoggerNames.Method);
|
|
54440
53759
|
class PromptWebDeviceAccess extends BaseMethod {
|
|
54441
53760
|
init() {
|
|
54442
53761
|
this.useDevice = false;
|
|
@@ -54491,7 +53810,7 @@ class PromptWebDeviceAccess extends BaseMethod {
|
|
|
54491
53810
|
return { device: null };
|
|
54492
53811
|
}
|
|
54493
53812
|
catch (error) {
|
|
54494
|
-
Log$
|
|
53813
|
+
Log$6.debug(error);
|
|
54495
53814
|
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Please select the device to connect'));
|
|
54496
53815
|
}
|
|
54497
53816
|
});
|
|
@@ -54596,234 +53915,281 @@ function decodeJpegBase64ToRgba({ jpegBase64, parameterName, expectedWidth, expe
|
|
|
54596
53915
|
return decoded;
|
|
54597
53916
|
}
|
|
54598
53917
|
|
|
54599
|
-
const
|
|
54600
|
-
const
|
|
54601
|
-
const
|
|
54602
|
-
const
|
|
54603
|
-
const
|
|
54604
|
-
|
|
54605
|
-
|
|
54606
|
-
const CONTAINER_RESOURCE_TYPE_MAGIC = 0x43534552;
|
|
54607
|
-
const CONTAINER_ED25519_SIGNATURE_ALGORITHM = 0x71717171;
|
|
54608
|
-
const ARCHIVE_MAGIC = 0x52414b4f;
|
|
54609
|
-
const ARCHIVE_VERSION = 1;
|
|
54610
|
-
const ARCHIVE_HEADER_SIZE = 42;
|
|
54611
|
-
const ARCHIVE_ENTRY_SIZE = 296;
|
|
54612
|
-
const ARCHIVE_ENTRY_NAME_MAX_LENGTH = 255;
|
|
54613
|
-
const ARCHIVE_COMPRESS_LZ4_BLOCKED = 1;
|
|
54614
|
-
const ARCHIVE_ALIGNMENT = 4;
|
|
54615
|
-
const LZ4_BLOCK_SIZE_LOG2 = 12;
|
|
54616
|
-
const LZ4_MIN_MATCH = 4;
|
|
54617
|
-
const LZ4_LAST_LITERALS = 5;
|
|
54618
|
-
const LZ4_MATCH_FIND_LIMIT = 12;
|
|
54619
|
-
const LZ4_MAX_OFFSET = 0xffff;
|
|
54620
|
-
const LZ4_LENGTH_MASK = 15;
|
|
54621
|
-
const LZ4_HASH_LOG = 16;
|
|
54622
|
-
const LZ4_HASH_MULTIPLIER = 2654435761;
|
|
54623
|
-
const LZ4_SKIP_TRIGGER = 6;
|
|
54624
|
-
const HOST_ASSET_PACKAGE_MAX_SIZE = 4 * 1024 * 1024;
|
|
54625
|
-
function supportsPro2HostAssetPackage(firmwareVersion) {
|
|
54626
|
-
return Boolean(firmwareVersion &&
|
|
54627
|
-
semver__default["default"].valid(firmwareVersion) &&
|
|
54628
|
-
semver__default["default"].gte(firmwareVersion, PRO2_HOST_ASSET_PACKAGE_MIN_VERSION));
|
|
54629
|
-
}
|
|
54630
|
-
function align(value) {
|
|
54631
|
-
return (value + ARCHIVE_ALIGNMENT - 1) & ~(ARCHIVE_ALIGNMENT - 1);
|
|
53918
|
+
const Log$5 = getLogger(exports.LoggerNames.Core);
|
|
53919
|
+
const MIN_FILE_CHUNK_SIZE = 64;
|
|
53920
|
+
const FILE_TRANSFER_RATE_WINDOW_MS = 1000;
|
|
53921
|
+
const FILE_TRANSFER_LOG_INTERVAL_MS = 10000;
|
|
53922
|
+
const SESSION_ERROR = 'session not found';
|
|
53923
|
+
function formatFileTransferRate(bytesPerSecond) {
|
|
53924
|
+
return (Math.max(bytesPerSecond, 0) / 1024).toFixed(2);
|
|
54632
53925
|
}
|
|
54633
|
-
function
|
|
54634
|
-
|
|
54635
|
-
|
|
54636
|
-
|
|
54637
|
-
output.set(part, offset);
|
|
54638
|
-
offset += part.byteLength;
|
|
54639
|
-
}
|
|
54640
|
-
return output;
|
|
53926
|
+
function getAverageFileTransferRate(transferredBytes, elapsedMs) {
|
|
53927
|
+
if (elapsedMs <= 0)
|
|
53928
|
+
return 0;
|
|
53929
|
+
return Math.round((Math.max(transferredBytes, 0) / elapsedMs) * 1000);
|
|
54641
53930
|
}
|
|
54642
|
-
function
|
|
54643
|
-
|
|
54644
|
-
|
|
54645
|
-
while (remaining >= 255) {
|
|
54646
|
-
output[nextOffset] = 255;
|
|
54647
|
-
nextOffset += 1;
|
|
54648
|
-
remaining -= 255;
|
|
54649
|
-
}
|
|
54650
|
-
output[nextOffset] = remaining;
|
|
54651
|
-
return nextOffset + 1;
|
|
53931
|
+
function getFileTransferTransport() {
|
|
53932
|
+
const env = DataManager.getSettings('env');
|
|
53933
|
+
return env && DataManager.isBleConnect(env) ? 'BLE' : String(env !== null && env !== void 0 ? env : 'unknown');
|
|
54652
53934
|
}
|
|
54653
|
-
function
|
|
54654
|
-
|
|
54655
|
-
|
|
53935
|
+
function logFileTransferMetrics({ transport, status, path, transferredBytes, totalBytes, elapsedMs, rateBytesPerSecond, hostWriteElapsedMs, responseWaitElapsedMs, measuredAttempts, }) {
|
|
53936
|
+
const segmentedMetrics = measuredAttempts > 0
|
|
53937
|
+
? ` hostWriteTotal=${(hostWriteElapsedMs / 1000).toFixed(2)}s responseWaitTotal=${(responseWaitElapsedMs / 1000).toFixed(2)}s measuredAttempts=${measuredAttempts}`
|
|
53938
|
+
: '';
|
|
53939
|
+
Log$5.log(`[FileWrite] metrics transport=${transport} status=${status} path=${path} bytes=${transferredBytes}/${totalBytes} elapsed=${(elapsedMs / 1000).toFixed(2)}s speed=${formatFileTransferRate(rateBytesPerSecond)} KiB/s${segmentedMetrics}`);
|
|
54656
53940
|
}
|
|
54657
|
-
function
|
|
54658
|
-
|
|
54659
|
-
|
|
54660
|
-
|
|
54661
|
-
|
|
54662
|
-
|
|
54663
|
-
|
|
54664
|
-
|
|
54665
|
-
|
|
54666
|
-
token = literalLength << 4;
|
|
54667
|
-
}
|
|
54668
|
-
nextOffset = copyBytes(output, nextOffset, input, anchor, literalLength);
|
|
54669
|
-
output[nextOffset] = matchOffset & 0xff;
|
|
54670
|
-
output[nextOffset + 1] = (matchOffset >>> 8) & 0xff;
|
|
54671
|
-
nextOffset += 2;
|
|
54672
|
-
if (matchLengthCode >= LZ4_LENGTH_MASK) {
|
|
54673
|
-
token |= LZ4_LENGTH_MASK;
|
|
54674
|
-
nextOffset = writeExtendedLength(output, nextOffset, matchLengthCode - LZ4_LENGTH_MASK);
|
|
54675
|
-
}
|
|
54676
|
-
else {
|
|
54677
|
-
token |= matchLengthCode;
|
|
54678
|
-
}
|
|
54679
|
-
output[tokenOffset] = token;
|
|
54680
|
-
return nextOffset;
|
|
53941
|
+
function isProtocolV2ResponseTimeout(error) {
|
|
53942
|
+
var _a, _b;
|
|
53943
|
+
if (!error || typeof error !== 'object')
|
|
53944
|
+
return false;
|
|
53945
|
+
const candidate = error;
|
|
53946
|
+
const code = (_a = candidate.errorCode) !== null && _a !== void 0 ? _a : candidate.code;
|
|
53947
|
+
return (code === hdShared.HardwareErrorCode.BleTimeoutError ||
|
|
53948
|
+
code === 'response-timeout' ||
|
|
53949
|
+
/(?:BLE|Lowlevel|Protocol V2) response timeout/i.test((_b = candidate.message) !== null && _b !== void 0 ? _b : ''));
|
|
54681
53950
|
}
|
|
54682
|
-
function
|
|
54683
|
-
const
|
|
54684
|
-
|
|
54685
|
-
|
|
54686
|
-
|
|
54687
|
-
nextOffset = writeExtendedLength(output, nextOffset, literalLength - LZ4_LENGTH_MASK);
|
|
54688
|
-
}
|
|
54689
|
-
else {
|
|
54690
|
-
output[tokenOffset] = literalLength << 4;
|
|
54691
|
-
}
|
|
54692
|
-
return copyBytes(output, nextOffset, input, anchor, literalLength);
|
|
53951
|
+
function getProtocolV2FileChunkLimit() {
|
|
53952
|
+
const env = DataManager.getSettings('env');
|
|
53953
|
+
return env && DataManager.isBleConnect(env)
|
|
53954
|
+
? hdTransport.PROTOCOL_V2_BLE_FILE_CHUNK_SIZE
|
|
53955
|
+
: hdTransport.PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
54693
53956
|
}
|
|
54694
|
-
function
|
|
54695
|
-
|
|
54696
|
-
|
|
54697
|
-
|
|
54698
|
-
|
|
54699
|
-
|
|
54700
|
-
|
|
54701
|
-
|
|
54702
|
-
let searchMatchCount = 1 << LZ4_SKIP_TRIGGER;
|
|
54703
|
-
hashTable.fill(0);
|
|
54704
|
-
while (inputOffset < matchFindLimit) {
|
|
54705
|
-
const sequence = inputView.getUint32(inputOffset, true);
|
|
54706
|
-
const hash = Math.imul(sequence, LZ4_HASH_MULTIPLIER) >>> (32 - LZ4_HASH_LOG);
|
|
54707
|
-
const candidate = hashTable[hash] - 1;
|
|
54708
|
-
hashTable[hash] = inputOffset + 1;
|
|
54709
|
-
const hasMatch = !(candidate < 0 ||
|
|
54710
|
-
inputOffset - candidate > LZ4_MAX_OFFSET ||
|
|
54711
|
-
inputView.getUint32(candidate, true) !== sequence);
|
|
54712
|
-
if (!hasMatch) {
|
|
54713
|
-
inputOffset += searchMatchCount >> LZ4_SKIP_TRIGGER;
|
|
54714
|
-
searchMatchCount += 1;
|
|
53957
|
+
function dataToUint8Array(data) {
|
|
53958
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53959
|
+
if (typeof data === 'string')
|
|
53960
|
+
return new TextEncoder().encode(data);
|
|
53961
|
+
if (data instanceof ArrayBuffer)
|
|
53962
|
+
return new Uint8Array(data);
|
|
53963
|
+
if (ArrayBuffer.isView(data)) {
|
|
53964
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
54715
53965
|
}
|
|
54716
|
-
|
|
54717
|
-
|
|
54718
|
-
let matchEnd = inputOffset + LZ4_MIN_MATCH;
|
|
54719
|
-
let reference = candidate + LZ4_MIN_MATCH;
|
|
54720
|
-
while (matchEnd < matchExtendLimit && input[matchEnd] === input[reference]) {
|
|
54721
|
-
matchEnd += 1;
|
|
54722
|
-
reference += 1;
|
|
54723
|
-
}
|
|
54724
|
-
outputOffset = emitSequence(output, outputOffset, input, anchor, inputOffset - anchor, inputOffset - candidate, matchEnd - inputOffset - LZ4_MIN_MATCH);
|
|
54725
|
-
inputOffset = matchEnd;
|
|
54726
|
-
anchor = inputOffset;
|
|
53966
|
+
if (typeof Blob !== 'undefined' && data instanceof Blob) {
|
|
53967
|
+
return new Uint8Array(yield data.arrayBuffer());
|
|
54727
53968
|
}
|
|
54728
|
-
|
|
54729
|
-
|
|
54730
|
-
return output.slice(0, outputOffset);
|
|
53969
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Unsupported FilesystemFileWrite data');
|
|
53970
|
+
});
|
|
54731
53971
|
}
|
|
54732
|
-
function
|
|
54733
|
-
const
|
|
54734
|
-
|
|
54735
|
-
|
|
54736
|
-
|
|
54737
|
-
const header = new Uint8Array(8 + blockCount * 4);
|
|
54738
|
-
const headerView = new DataView(header.buffer);
|
|
54739
|
-
headerView.setUint16(0, blockCount, true);
|
|
54740
|
-
headerView.setUint16(2, LZ4_BLOCK_SIZE_LOG2, true);
|
|
54741
|
-
for (let index = 0; index < blockCount; index += 1) {
|
|
54742
|
-
const block = compressRawLz4Block(data.subarray(index * blockSize, Math.min((index + 1) * blockSize, data.byteLength)), hashTable);
|
|
54743
|
-
headerView.setUint32(8 + index * 4, block.byteLength, true);
|
|
54744
|
-
blocks.push(block);
|
|
54745
|
-
}
|
|
54746
|
-
return concatBytes([header, ...blocks]);
|
|
53972
|
+
function normalizeChunkSize(value, maxChunkSize) {
|
|
53973
|
+
const numeric = Number(value);
|
|
53974
|
+
if (!Number.isFinite(numeric) || numeric <= 0)
|
|
53975
|
+
return maxChunkSize;
|
|
53976
|
+
return Math.min(Math.max(Math.floor(numeric), MIN_FILE_CHUNK_SIZE), maxChunkSize);
|
|
54747
53977
|
}
|
|
54748
|
-
|
|
54749
|
-
|
|
54750
|
-
|
|
54751
|
-
|
|
54752
|
-
|
|
54753
|
-
|
|
54754
|
-
|
|
54755
|
-
|
|
54756
|
-
|
|
54757
|
-
|
|
54758
|
-
|
|
54759
|
-
|
|
54760
|
-
|
|
54761
|
-
|
|
54762
|
-
value = CRC32_TABLE[(value ^ byte) & 0xff] ^ (value >>> 8);
|
|
53978
|
+
function getDeviceTransferProgress(before, after, total) {
|
|
53979
|
+
if (!Number.isFinite(total) || total <= 0)
|
|
53980
|
+
return 100;
|
|
53981
|
+
if (before <= 0 && after < total)
|
|
53982
|
+
return 0;
|
|
53983
|
+
if (after >= total)
|
|
53984
|
+
return 100;
|
|
53985
|
+
return Math.min(Math.max(Math.ceil((after / total) * 100), 1), 99);
|
|
53986
|
+
}
|
|
53987
|
+
function getConfirmedProgress(processed, total, written, length) {
|
|
53988
|
+
if (Number.isFinite(processed) && Number.isFinite(total) && total > 0) {
|
|
53989
|
+
if (processed >= total)
|
|
53990
|
+
return 100;
|
|
53991
|
+
return Math.min(Math.max(Math.floor((processed / total) * 100), 0), 99);
|
|
54763
53992
|
}
|
|
54764
|
-
|
|
53993
|
+
if (length > 0)
|
|
53994
|
+
return written >= length ? 100 : Math.floor((written / length) * 100);
|
|
53995
|
+
return 100;
|
|
54765
53996
|
}
|
|
54766
|
-
function
|
|
54767
|
-
|
|
54768
|
-
|
|
54769
|
-
|
|
54770
|
-
const
|
|
54771
|
-
|
|
54772
|
-
|
|
53997
|
+
function writeProtocolV2File(options) {
|
|
53998
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
53999
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54000
|
+
(_a = options.throwIfAborted) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
54001
|
+
const data = yield dataToUint8Array(options.data);
|
|
54002
|
+
const dataLength = data.byteLength;
|
|
54003
|
+
const startOffset = Number.isFinite(options.offset) && Number(options.offset) > 0 ? Number(options.offset) : 0;
|
|
54004
|
+
const totalSize = Number.isFinite(options.totalSize) && Number(options.totalSize) > 0
|
|
54005
|
+
? Number(options.totalSize)
|
|
54006
|
+
: startOffset + dataLength;
|
|
54007
|
+
if (totalSize < startOffset + dataLength) {
|
|
54008
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite totalSize ${totalSize} is smaller than offset + data length ${startOffset + dataLength}`);
|
|
54773
54009
|
}
|
|
54774
|
-
|
|
54775
|
-
|
|
54010
|
+
const defaultChunkSizeLimit = getProtocolV2FileChunkLimit();
|
|
54011
|
+
const configuredChunkSizeLimit = Number(options.chunkSizeLimit);
|
|
54012
|
+
const chunkSizeLimit = Number.isFinite(configuredChunkSizeLimit) && configuredChunkSizeLimit > 0
|
|
54013
|
+
? Math.floor(configuredChunkSizeLimit)
|
|
54014
|
+
: defaultChunkSizeLimit;
|
|
54015
|
+
const chunkSize = normalizeChunkSize((_b = options.chunkSize) !== null && _b !== void 0 ? _b : options.chunkLen, chunkSizeLimit);
|
|
54016
|
+
let written = 0;
|
|
54017
|
+
let chunks = 0;
|
|
54018
|
+
let lastMessage;
|
|
54019
|
+
const startTime = Date.now();
|
|
54020
|
+
let rateWindowStartedAt = startTime;
|
|
54021
|
+
let rateWindowStartedBytes = 0;
|
|
54022
|
+
let rateBytesPerSecond;
|
|
54023
|
+
let lastConfirmedAt = startTime;
|
|
54024
|
+
let logWindowStartedAt = startTime;
|
|
54025
|
+
let logWindowStartedBytes = 0;
|
|
54026
|
+
let hostWriteElapsedMs = 0;
|
|
54027
|
+
let responseWaitElapsedMs = 0;
|
|
54028
|
+
let measuredAttempts = 0;
|
|
54029
|
+
const transport = getFileTransferTransport();
|
|
54030
|
+
Log$5.log(`[FileWrite] started transport=${transport} path=${options.path} bytes=${dataLength} offset=${startOffset} chunk=${chunkSize}`);
|
|
54031
|
+
try {
|
|
54032
|
+
while (written < dataLength) {
|
|
54033
|
+
(_c = options.throwIfAborted) === null || _c === void 0 ? void 0 : _c.call(options);
|
|
54034
|
+
const chunk = data.slice(written, Math.min(written + chunkSize, dataLength));
|
|
54035
|
+
const offset = startOffset + written;
|
|
54036
|
+
const progress = (_f = (_d = options.uiPercentage) !== null && _d !== void 0 ? _d : (_e = options.getUiPercentage) === null || _e === void 0 ? void 0 : _e.call(options, {
|
|
54037
|
+
offset,
|
|
54038
|
+
chunkLength: chunk.byteLength,
|
|
54039
|
+
totalSize,
|
|
54040
|
+
})) !== null && _f !== void 0 ? _f : getDeviceTransferProgress(offset, offset + chunk.byteLength, totalSize);
|
|
54041
|
+
const request = {
|
|
54042
|
+
file: { path: options.path, offset, total_size: totalSize, data: chunk },
|
|
54043
|
+
overwrite: chunks === 0 ? (_g = options.overwrite) !== null && _g !== void 0 ? _g : false : false,
|
|
54044
|
+
append: (_h = options.append) !== null && _h !== void 0 ? _h : false,
|
|
54045
|
+
ui_percentage: progress,
|
|
54046
|
+
};
|
|
54047
|
+
const maxChunkRetries = Math.max(Math.floor((_j = options.maxChunkRetries) !== null && _j !== void 0 ? _j : 0), 0);
|
|
54048
|
+
let retryCount = 0;
|
|
54049
|
+
let response;
|
|
54050
|
+
let isWritePending = true;
|
|
54051
|
+
while (isWritePending) {
|
|
54052
|
+
let currentHostWriteElapsedMs;
|
|
54053
|
+
let responseWaitStartedAt;
|
|
54054
|
+
try {
|
|
54055
|
+
const callOptions = options.writeWithResponse === undefined
|
|
54056
|
+
? {
|
|
54057
|
+
timeoutMs: options.timeoutMs,
|
|
54058
|
+
onWriteCompleted: ({ elapsedMs }) => {
|
|
54059
|
+
currentHostWriteElapsedMs = elapsedMs;
|
|
54060
|
+
responseWaitStartedAt = Date.now();
|
|
54061
|
+
},
|
|
54062
|
+
}
|
|
54063
|
+
: Object.assign(Object.assign({}, (options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs })), { writeWithResponse: options.writeWithResponse, onWriteCompleted: ({ elapsedMs }) => {
|
|
54064
|
+
currentHostWriteElapsedMs = elapsedMs;
|
|
54065
|
+
responseWaitStartedAt = Date.now();
|
|
54066
|
+
} });
|
|
54067
|
+
response = yield options.commands.typedCall('FilesystemFileWrite', 'FilesystemFile', request, callOptions);
|
|
54068
|
+
isWritePending = false;
|
|
54069
|
+
}
|
|
54070
|
+
catch (error) {
|
|
54071
|
+
if (retryCount >= maxChunkRetries || !isProtocolV2ResponseTimeout(error))
|
|
54072
|
+
throw error;
|
|
54073
|
+
retryCount += 1;
|
|
54074
|
+
(_k = options.throwIfAborted) === null || _k === void 0 ? void 0 : _k.call(options);
|
|
54075
|
+
}
|
|
54076
|
+
finally {
|
|
54077
|
+
if (currentHostWriteElapsedMs !== undefined && responseWaitStartedAt !== undefined) {
|
|
54078
|
+
hostWriteElapsedMs += currentHostWriteElapsedMs;
|
|
54079
|
+
responseWaitElapsedMs += Math.max(Date.now() - responseWaitStartedAt, 0);
|
|
54080
|
+
measuredAttempts += 1;
|
|
54081
|
+
}
|
|
54082
|
+
}
|
|
54083
|
+
}
|
|
54084
|
+
if (!response) {
|
|
54085
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'FilesystemFileWrite completed without a response');
|
|
54086
|
+
}
|
|
54087
|
+
const responseType = response.type;
|
|
54088
|
+
if (responseType && responseType !== 'FilesystemFile') {
|
|
54089
|
+
const responseError = (_l = response.message) === null || _l === void 0 ? void 0 : _l.error;
|
|
54090
|
+
if (typeof responseError === 'string' && responseError.includes(SESSION_ERROR)) {
|
|
54091
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, SESSION_ERROR);
|
|
54092
|
+
}
|
|
54093
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite received unexpected response ${responseType}`);
|
|
54094
|
+
}
|
|
54095
|
+
(_m = options.throwIfAborted) === null || _m === void 0 ? void 0 : _m.call(options);
|
|
54096
|
+
lastMessage = response.message;
|
|
54097
|
+
const rawProcessedByte = (_o = response.message) === null || _o === void 0 ? void 0 : _o.processed_byte;
|
|
54098
|
+
const processedByte = Number(rawProcessedByte);
|
|
54099
|
+
if (rawProcessedByte !== undefined &&
|
|
54100
|
+
(!Number.isFinite(processedByte) ||
|
|
54101
|
+
processedByte <= offset ||
|
|
54102
|
+
processedByte > offset + chunk.byteLength)) {
|
|
54103
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite invalid processed_byte ${processedByte}`);
|
|
54104
|
+
}
|
|
54105
|
+
written =
|
|
54106
|
+
rawProcessedByte === undefined ? written + chunk.byteLength : processedByte - startOffset;
|
|
54107
|
+
chunks += 1;
|
|
54108
|
+
const now = Date.now();
|
|
54109
|
+
lastConfirmedAt = now;
|
|
54110
|
+
const elapsedMs = now - startTime;
|
|
54111
|
+
const transferredBytes = Math.min(written, dataLength);
|
|
54112
|
+
const rateWindowElapsedMs = now - rateWindowStartedAt;
|
|
54113
|
+
if (rateWindowElapsedMs >= FILE_TRANSFER_RATE_WINDOW_MS) {
|
|
54114
|
+
const rateWindowBytes = Math.max(transferredBytes - rateWindowStartedBytes, 0);
|
|
54115
|
+
rateBytesPerSecond = Math.round((rateWindowBytes / rateWindowElapsedMs) * 1000);
|
|
54116
|
+
rateWindowStartedAt = now;
|
|
54117
|
+
rateWindowStartedBytes = transferredBytes;
|
|
54118
|
+
}
|
|
54119
|
+
else if (rateBytesPerSecond === undefined && elapsedMs > 0) {
|
|
54120
|
+
rateBytesPerSecond = Math.round((transferredBytes / elapsedMs) * 1000);
|
|
54121
|
+
}
|
|
54122
|
+
(_p = options.onProgress) === null || _p === void 0 ? void 0 : _p.call(options, {
|
|
54123
|
+
progress: getConfirmedProgress(startOffset + written, totalSize, written, dataLength),
|
|
54124
|
+
transferredBytes,
|
|
54125
|
+
totalBytes: dataLength,
|
|
54126
|
+
rateBytesPerSecond,
|
|
54127
|
+
elapsedMs,
|
|
54128
|
+
});
|
|
54129
|
+
const logWindowElapsedMs = now - logWindowStartedAt;
|
|
54130
|
+
if (logWindowElapsedMs >= FILE_TRANSFER_LOG_INTERVAL_MS && transferredBytes < dataLength) {
|
|
54131
|
+
const logWindowBytes = Math.max(transferredBytes - logWindowStartedBytes, 0);
|
|
54132
|
+
logFileTransferMetrics({
|
|
54133
|
+
transport,
|
|
54134
|
+
status: 'progress',
|
|
54135
|
+
path: options.path,
|
|
54136
|
+
transferredBytes,
|
|
54137
|
+
totalBytes: dataLength,
|
|
54138
|
+
elapsedMs,
|
|
54139
|
+
rateBytesPerSecond: getAverageFileTransferRate(logWindowBytes, logWindowElapsedMs),
|
|
54140
|
+
hostWriteElapsedMs,
|
|
54141
|
+
responseWaitElapsedMs,
|
|
54142
|
+
measuredAttempts,
|
|
54143
|
+
});
|
|
54144
|
+
logWindowStartedAt = now;
|
|
54145
|
+
logWindowStartedBytes = transferredBytes;
|
|
54146
|
+
}
|
|
54147
|
+
if (options.paceMs && options.paceMs > 0) {
|
|
54148
|
+
yield new Promise(resolve => {
|
|
54149
|
+
setTimeout(resolve, options.paceMs);
|
|
54150
|
+
});
|
|
54151
|
+
}
|
|
54152
|
+
}
|
|
54776
54153
|
}
|
|
54777
|
-
|
|
54778
|
-
|
|
54779
|
-
|
|
54780
|
-
|
|
54781
|
-
|
|
54782
|
-
|
|
54783
|
-
|
|
54784
|
-
|
|
54785
|
-
|
|
54786
|
-
|
|
54787
|
-
|
|
54788
|
-
|
|
54789
|
-
|
|
54790
|
-
|
|
54791
|
-
|
|
54792
|
-
|
|
54793
|
-
|
|
54794
|
-
|
|
54795
|
-
|
|
54796
|
-
|
|
54797
|
-
|
|
54154
|
+
catch (error) {
|
|
54155
|
+
const now = Date.now();
|
|
54156
|
+
const elapsedMs = Math.max(now - startTime, 0);
|
|
54157
|
+
const logWindowElapsedMs = Math.max(now - logWindowStartedAt, 0);
|
|
54158
|
+
const logWindowBytes = Math.max(written - logWindowStartedBytes, 0);
|
|
54159
|
+
logFileTransferMetrics({
|
|
54160
|
+
transport,
|
|
54161
|
+
status: 'failed',
|
|
54162
|
+
path: options.path,
|
|
54163
|
+
transferredBytes: written,
|
|
54164
|
+
totalBytes: dataLength,
|
|
54165
|
+
elapsedMs,
|
|
54166
|
+
rateBytesPerSecond: getAverageFileTransferRate(logWindowBytes, logWindowElapsedMs),
|
|
54167
|
+
hostWriteElapsedMs,
|
|
54168
|
+
responseWaitElapsedMs,
|
|
54169
|
+
measuredAttempts,
|
|
54170
|
+
});
|
|
54171
|
+
throw error;
|
|
54172
|
+
}
|
|
54173
|
+
const elapsedMs = Math.max(lastConfirmedAt - startTime, 0);
|
|
54174
|
+
const logWindowElapsedMs = Math.max(lastConfirmedAt - logWindowStartedAt, 0);
|
|
54175
|
+
const logWindowBytes = Math.max(written - logWindowStartedBytes, 0);
|
|
54176
|
+
logFileTransferMetrics({
|
|
54177
|
+
transport,
|
|
54178
|
+
status: 'completed',
|
|
54179
|
+
path: options.path,
|
|
54180
|
+
transferredBytes: written,
|
|
54181
|
+
totalBytes: dataLength,
|
|
54182
|
+
elapsedMs,
|
|
54183
|
+
rateBytesPerSecond: getAverageFileTransferRate(logWindowBytes, logWindowElapsedMs),
|
|
54184
|
+
hostWriteElapsedMs,
|
|
54185
|
+
responseWaitElapsedMs,
|
|
54186
|
+
measuredAttempts,
|
|
54187
|
+
});
|
|
54188
|
+
return Object.assign(Object.assign({}, lastMessage), { path: options.path, offset: startOffset, total_size: totalSize, processed_byte: startOffset + written, chunks });
|
|
54798
54189
|
});
|
|
54799
|
-
return archive;
|
|
54800
|
-
}
|
|
54801
|
-
function buildPro2HostAssetPackage(entries) {
|
|
54802
|
-
if (entries.length === 0 || new Set(entries.map(entry => entry.name)).size !== entries.length) {
|
|
54803
|
-
throw new Error('Pro2 host asset package entries must have unique, non-empty names.');
|
|
54804
|
-
}
|
|
54805
|
-
const payload = buildArchive(entries);
|
|
54806
|
-
const header = new Uint8Array(CONTAINER_HEADER_SIZE);
|
|
54807
|
-
const view = new DataView(header.buffer);
|
|
54808
|
-
view.setUint32(0, CONTAINER_HEADER_MAGIC, true);
|
|
54809
|
-
view.setUint32(4, CONTAINER_HEADER_VERSION, true);
|
|
54810
|
-
view.setUint32(8, CONTAINER_RESOURCE_TYPE_MAGIC, true);
|
|
54811
|
-
view.setUint32(0x0c, CONTAINER_HEADER_SIZE, true);
|
|
54812
|
-
view.setUint32(0x10, 1, true);
|
|
54813
|
-
view.setUint32(0x14, payload.byteLength, true);
|
|
54814
|
-
header.set(sha3.sha3_512(payload), CONTAINER_HASH_SECTION_OFFSET);
|
|
54815
|
-
header.set(sha3.sha3_512(header.subarray(0, CONTAINER_HEADER_HASH_INPUT_LENGTH)), 0x240);
|
|
54816
|
-
view.setUint32(CONTAINER_SIGNATURE_ALGORITHM_OFFSET, CONTAINER_ED25519_SIGNATURE_ALGORITHM, true);
|
|
54817
|
-
const packageData = concatBytes([header, payload]);
|
|
54818
|
-
if (packageData.byteLength > HOST_ASSET_PACKAGE_MAX_SIZE) {
|
|
54819
|
-
throw new Error('Pro2 host asset package exceeds the firmware 4 MiB limit.');
|
|
54820
|
-
}
|
|
54821
|
-
return packageData;
|
|
54822
54190
|
}
|
|
54823
54191
|
|
|
54824
54192
|
const WALLPAPER_DIRECTORY = 'vol1:/wallpapers';
|
|
54825
|
-
const WALLPAPER_PACKAGE_PATH = `${WALLPAPER_DIRECTORY}/wallpaper.okpkg`;
|
|
54826
|
-
const WALLPAPER_PACKAGE_ENTRY = 'wallpaper.bin';
|
|
54827
54193
|
const SAFE_FILE_NAME = /^[A-Za-z0-9_-]+(?:\.bin)?$/;
|
|
54828
54194
|
const DEVICE_SETTINGS_SET_MESSAGE_TYPE = 60412;
|
|
54829
54195
|
const FILESYSTEM_FILE_WRITE_MESSAGE_TYPE$2 = 60805;
|
|
@@ -54899,15 +54265,18 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
54899
54265
|
this.directoryReady = true;
|
|
54900
54266
|
});
|
|
54901
54267
|
}
|
|
54902
|
-
upload(
|
|
54268
|
+
upload() {
|
|
54903
54269
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54904
54270
|
if (this.uploaded)
|
|
54905
54271
|
return;
|
|
54272
|
+
const { encoded } = this;
|
|
54273
|
+
if (!encoded)
|
|
54274
|
+
throw invalidParameter$1('Wallpaper data has not been initialized.');
|
|
54906
54275
|
yield writeProtocolV2File({
|
|
54907
54276
|
commands: this.device.commands,
|
|
54908
|
-
path,
|
|
54909
|
-
data,
|
|
54910
|
-
totalSize: data.byteLength,
|
|
54277
|
+
path: this.path,
|
|
54278
|
+
data: encoded.data,
|
|
54279
|
+
totalSize: encoded.data.byteLength,
|
|
54911
54280
|
chunkSize: this.params.chunkSize,
|
|
54912
54281
|
maxChunkRetries: 3,
|
|
54913
54282
|
overwrite: true,
|
|
@@ -54930,13 +54299,7 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
54930
54299
|
throw invalidParameter$1('Wallpaper data has not been initialized.');
|
|
54931
54300
|
yield this.assertCapabilities();
|
|
54932
54301
|
yield this.ensureDirectory();
|
|
54933
|
-
|
|
54934
|
-
const data = useHostAssetPackage
|
|
54935
|
-
? buildPro2HostAssetPackage([{ name: WALLPAPER_PACKAGE_ENTRY, data: encoded.data }])
|
|
54936
|
-
: encoded.data;
|
|
54937
|
-
if (useHostAssetPackage)
|
|
54938
|
-
this.path = WALLPAPER_PACKAGE_PATH;
|
|
54939
|
-
yield this.upload(this.path, data);
|
|
54302
|
+
yield this.upload();
|
|
54940
54303
|
const response = yield this.device.commands.typedCall('DeviceSettingsSet', 'Success', {
|
|
54941
54304
|
settings: { wallpaper_path: this.path },
|
|
54942
54305
|
});
|
|
@@ -54950,7 +54313,7 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
54950
54313
|
}
|
|
54951
54314
|
return {
|
|
54952
54315
|
path: this.path,
|
|
54953
|
-
size: data.byteLength,
|
|
54316
|
+
size: encoded.data.byteLength,
|
|
54954
54317
|
colorFormat: encoded.colorFormat,
|
|
54955
54318
|
message: (_a = response.message) === null || _a === void 0 ? void 0 : _a.message,
|
|
54956
54319
|
};
|
|
@@ -55029,14 +54392,14 @@ class DeviceUploadNft extends BaseMethod {
|
|
|
55029
54392
|
this.skipForceUpdateCheck = true;
|
|
55030
54393
|
this.useDevicePassphraseState = false;
|
|
55031
54394
|
}
|
|
55032
|
-
assertCapabilities(
|
|
54395
|
+
assertCapabilities() {
|
|
55033
54396
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55034
54397
|
const protocolInfo = yield this.device.ensureProtocolV2RuntimeContext();
|
|
55035
54398
|
const hasFileWrite = supportsProtocolV2Message(protocolInfo, FILESYSTEM_FILE_WRITE_MESSAGE_TYPE$1);
|
|
55036
54399
|
const hasPathInfo = supportsProtocolV2Message(protocolInfo, FILESYSTEM_PATH_INFO_QUERY_MESSAGE_TYPE);
|
|
55037
54400
|
const hasDirList = supportsProtocolV2Message(protocolInfo, FILESYSTEM_DIR_LIST_MESSAGE_TYPE);
|
|
55038
54401
|
const hasNftUpdate = supportsProtocolV2Message(protocolInfo, NFT_UPDATE_MESSAGE_TYPE);
|
|
55039
|
-
if (!hasFileWrite || !
|
|
54402
|
+
if (!hasFileWrite || !hasPathInfo || !hasDirList || !hasNftUpdate) {
|
|
55040
54403
|
throw hdShared.createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
|
|
55041
54404
|
}
|
|
55042
54405
|
});
|
|
@@ -55067,28 +54430,15 @@ class DeviceUploadNft extends BaseMethod {
|
|
|
55067
54430
|
const { bundle } = this;
|
|
55068
54431
|
if (!bundle)
|
|
55069
54432
|
throw invalidParameter$1('NFT data has not been initialized.');
|
|
55070
|
-
|
|
55071
|
-
yield this.assertCapabilities(useHostAssetPackage);
|
|
54433
|
+
yield this.assertCapabilities();
|
|
55072
54434
|
this.throwIfAborted();
|
|
55073
|
-
|
|
55074
|
-
yield this.assertStorageCapacity(bundle.basename);
|
|
54435
|
+
yield this.assertStorageCapacity(bundle.basename);
|
|
55075
54436
|
this.throwIfAborted();
|
|
55076
|
-
const
|
|
54437
|
+
const files = [
|
|
55077
54438
|
{ path: `${PRO2_NFT_DIRECTORY}/${bundle.basename}.bin`, data: bundle.image },
|
|
55078
54439
|
{ path: `${PRO2_NFT_DIRECTORY}/${bundle.basename}_m.bin`, data: bundle.thumbnail },
|
|
55079
54440
|
{ path: `${PRO2_NFT_DIRECTORY}/${bundle.basename}.json`, data: bundle.metadata },
|
|
55080
54441
|
];
|
|
55081
|
-
const files = useHostAssetPackage
|
|
55082
|
-
? [
|
|
55083
|
-
{
|
|
55084
|
-
path: `${PRO2_NFT_DIRECTORY}/${bundle.basename}.okpkg`,
|
|
55085
|
-
data: buildPro2HostAssetPackage(extractedFiles.map(file => ({
|
|
55086
|
-
name: file.path.slice(`${PRO2_NFT_DIRECTORY}/`.length),
|
|
55087
|
-
data: file.data,
|
|
55088
|
-
}))),
|
|
55089
|
-
},
|
|
55090
|
-
]
|
|
55091
|
-
: extractedFiles;
|
|
55092
54442
|
const totalSize = files.reduce((sum, file) => sum + file.data.byteLength, 0);
|
|
55093
54443
|
let transferredBeforeFile = 0;
|
|
55094
54444
|
for (const file of files) {
|
|
@@ -55117,9 +54467,9 @@ class DeviceUploadNft extends BaseMethod {
|
|
|
55117
54467
|
const response = yield this.updateNft(bundle.basename);
|
|
55118
54468
|
return {
|
|
55119
54469
|
basename: bundle.basename,
|
|
55120
|
-
imagePath:
|
|
55121
|
-
thumbnailPath:
|
|
55122
|
-
metadataPath:
|
|
54470
|
+
imagePath: files[0].path,
|
|
54471
|
+
thumbnailPath: files[1].path,
|
|
54472
|
+
metadataPath: files[2].path,
|
|
55123
54473
|
totalSize,
|
|
55124
54474
|
nftUpdated: true,
|
|
55125
54475
|
message: (_a = response.message) === null || _a === void 0 ? void 0 : _a.message,
|
|
@@ -55398,8 +54748,6 @@ class ProtocolV2UiInteractionCoordinator {
|
|
|
55398
54748
|
const Log$3 = getLogger(exports.LoggerNames.Core);
|
|
55399
54749
|
const createProtocolV2UnlockContext = () => ({
|
|
55400
54750
|
preflightCompleted: false,
|
|
55401
|
-
preflightStatusRefreshed: false,
|
|
55402
|
-
preflightMainPinSelected: false,
|
|
55403
54751
|
});
|
|
55404
54752
|
const resolvePreUnlockPinType = (method) => {
|
|
55405
54753
|
var _a, _b;
|
|
@@ -55432,11 +54780,10 @@ function runMethodWithUnlockPolicy(method, device, options = {}) {
|
|
|
55432
54780
|
}
|
|
55433
54781
|
yield (afterStatusBeforeUnlock === null || afterStatusBeforeUnlock === void 0 ? void 0 : afterStatusBeforeUnlock());
|
|
55434
54782
|
if (!status.unlocked) {
|
|
55435
|
-
const preUnlockPinType = resolvePreUnlockPinType(method);
|
|
55436
54783
|
const unlockInteraction = shouldCoordinateUi
|
|
55437
54784
|
? uiCoordinator.enterUnlockInteraction(method.name)
|
|
55438
54785
|
: undefined;
|
|
55439
|
-
const unlockedStatus = yield device.unlockDevice(
|
|
54786
|
+
const unlockedStatus = yield device.unlockDevice(resolvePreUnlockPinType(method), shouldCoordinateUi
|
|
55440
54787
|
? { emitUiEvent: false, interaction: unlockInteraction }
|
|
55441
54788
|
: {
|
|
55442
54789
|
source: 'unlock-coordinator',
|
|
@@ -55447,10 +54794,8 @@ function runMethodWithUnlockPolicy(method, device, options = {}) {
|
|
|
55447
54794
|
if ((unlockedStatus === null || unlockedStatus === void 0 ? void 0 : unlockedStatus.unlocked) !== true) {
|
|
55448
54795
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 device remained locked after the unlock flow.');
|
|
55449
54796
|
}
|
|
55450
|
-
context.preflightMainPinSelected = preUnlockPinType === hdTransport.DeviceSessionPinType.Main;
|
|
55451
54797
|
Log$3.debug('Protocol V2 pre-unlock completed', { method: method.name });
|
|
55452
54798
|
}
|
|
55453
|
-
context.preflightStatusRefreshed = true;
|
|
55454
54799
|
context.preflightCompleted = true;
|
|
55455
54800
|
}
|
|
55456
54801
|
yield (prepare === null || prepare === void 0 ? void 0 : prepare());
|
|
@@ -55739,7 +55084,6 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
55739
55084
|
const response = yield runMethodWithUnlockPolicy(method, this.device, {
|
|
55740
55085
|
context: this.protocolV2UnlockContext,
|
|
55741
55086
|
prepare: () => __awaiter(this, void 0, void 0, function* () {
|
|
55742
|
-
var _d;
|
|
55743
55087
|
if (this.temporarySafetyCheckPrompted) {
|
|
55744
55088
|
method.temporarySafetyCheckPrompted = true;
|
|
55745
55089
|
}
|
|
@@ -55753,7 +55097,7 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
55753
55097
|
const deriveCardano = method.name.startsWith('cardano');
|
|
55754
55098
|
const shouldResumeWalletSession = useEmptyPassphrase || !!this.payload.passphraseState;
|
|
55755
55099
|
if (this.device.isProtocolV2() && shouldResumeWalletSession) {
|
|
55756
|
-
const passphraseStateSafety = yield this.device.checkPassphraseStateSafety(this.payload.passphraseState, useEmptyPassphrase, this.payload.skipPassphraseCheck, deriveCardano
|
|
55100
|
+
const passphraseStateSafety = yield this.device.checkPassphraseStateSafety(this.payload.passphraseState, useEmptyPassphrase, this.payload.skipPassphraseCheck, deriveCardano);
|
|
55757
55101
|
if (!passphraseStateSafety) {
|
|
55758
55102
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
55759
55103
|
}
|
|
@@ -58414,7 +57758,6 @@ class EVMSignTypedData extends BaseMethod {
|
|
|
58414
57758
|
const currentDeviceType = this.device.getCurrentDeviceType();
|
|
58415
57759
|
const supportBiggerDataVersion = '4.4.0';
|
|
58416
57760
|
const supportBiggerData = DeviceModelToTypes.model_classic1s.includes(currentDeviceType) ||
|
|
58417
|
-
DeviceModelToTypes.model_pro2.includes(currentDeviceType) ||
|
|
58418
57761
|
(DeviceModelToTypes.model_touch.includes(currentDeviceType) &&
|
|
58419
57762
|
semver__default["default"].gte(currentVersion, supportBiggerDataVersion));
|
|
58420
57763
|
if (supportBiggerData) {
|
|
@@ -65195,7 +64538,7 @@ class DeviceConnector {
|
|
|
65195
64538
|
stop() {
|
|
65196
64539
|
this.listening = false;
|
|
65197
64540
|
}
|
|
65198
|
-
acquire(path, session, forceCleanRunPromise, expectedProtocol, protocolHint, forceProtocolDetection
|
|
64541
|
+
acquire(path, session, forceCleanRunPromise, expectedProtocol, protocolHint, forceProtocolDetection) {
|
|
65199
64542
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65200
64543
|
Log$2.debug('acquire', path, session, expectedProtocol, protocolHint);
|
|
65201
64544
|
const env = DataManager.getSettings('env');
|
|
@@ -65203,15 +64546,13 @@ class DeviceConnector {
|
|
|
65203
64546
|
const transport = this.getActiveTransport();
|
|
65204
64547
|
let res;
|
|
65205
64548
|
if (DataManager.isBleConnect(env)) {
|
|
65206
|
-
|
|
64549
|
+
res = yield transport.acquire({
|
|
65207
64550
|
uuid: path,
|
|
65208
64551
|
forceCleanRunPromise,
|
|
65209
64552
|
expectedProtocol,
|
|
65210
64553
|
protocolHint,
|
|
65211
64554
|
forceProtocolDetection,
|
|
65212
|
-
|
|
65213
|
-
};
|
|
65214
|
-
res = yield transport.acquire(acquireInput);
|
|
64555
|
+
});
|
|
65215
64556
|
}
|
|
65216
64557
|
else {
|
|
65217
64558
|
res = yield transport.acquire({
|
|
@@ -65220,7 +64561,6 @@ class DeviceConnector {
|
|
|
65220
64561
|
expectedProtocol,
|
|
65221
64562
|
protocolHint,
|
|
65222
64563
|
forceProtocolDetection,
|
|
65223
|
-
skipProtocolProbe,
|
|
65224
64564
|
});
|
|
65225
64565
|
}
|
|
65226
64566
|
if (expectedProtocol) {
|
|
@@ -65728,8 +65068,6 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
65728
65068
|
if ((_g = method.payload) === null || _g === void 0 ? void 0 : _g.onlyConnectBleDevice) {
|
|
65729
65069
|
preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
|
|
65730
65070
|
Log.debug('Call API - only connect ble device: ', device === null || device === void 0 ? void 0 : device.mainId);
|
|
65731
|
-
completeMethodRequestContext(method);
|
|
65732
|
-
requestQueue.releaseTask(method.responseID);
|
|
65733
65071
|
return createResponseMessage(method.responseID, true, null);
|
|
65734
65072
|
}
|
|
65735
65073
|
Log.debug('Call API - setDevice: ', device.mainId);
|
|
@@ -65851,7 +65189,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
65851
65189
|
}
|
|
65852
65190
|
},
|
|
65853
65191
|
prepare: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65854
|
-
var _o, _p, _q, _r, _s
|
|
65192
|
+
var _o, _p, _q, _r, _s;
|
|
65855
65193
|
if (method.deviceId && method.checkDeviceId && !deviceIdCheckedDuringUnlockPreflight) {
|
|
65856
65194
|
const isSameDeviceID = yield checkLiveDeviceId(device, method.deviceId);
|
|
65857
65195
|
if (!isSameDeviceID) {
|
|
@@ -65871,7 +65209,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
65871
65209
|
require: support.require,
|
|
65872
65210
|
});
|
|
65873
65211
|
}
|
|
65874
|
-
const passphraseStateSafety = yield device.checkPassphraseStateSafety((_o = method.payload) === null || _o === void 0 ? void 0 : _o.passphraseState, (_p = method.payload) === null || _p === void 0 ? void 0 : _p.useEmptyPassphrase, (_q = method.payload) === null || _q === void 0 ? void 0 : _q.skipPassphraseCheck, hasDeriveCardano(method)
|
|
65212
|
+
const passphraseStateSafety = yield device.checkPassphraseStateSafety((_o = method.payload) === null || _o === void 0 ? void 0 : _o.passphraseState, (_p = method.payload) === null || _p === void 0 ? void 0 : _p.useEmptyPassphrase, (_q = method.payload) === null || _q === void 0 ? void 0 : _q.skipPassphraseCheck, hasDeriveCardano(method));
|
|
65875
65213
|
checkPassphraseEnableState(method, device.features);
|
|
65876
65214
|
if (!passphraseStateSafety) {
|
|
65877
65215
|
DevicePool.clearDeviceCache(method.payload.connectId);
|
|
@@ -65889,7 +65227,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
65889
65227
|
? e
|
|
65890
65228
|
: hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'open safety check failed.');
|
|
65891
65229
|
}
|
|
65892
|
-
(
|
|
65230
|
+
(_s = (_r = method.device) === null || _r === void 0 ? void 0 : _r.commands) === null || _s === void 0 ? void 0 : _s.checkDisposed();
|
|
65893
65231
|
}),
|
|
65894
65232
|
});
|
|
65895
65233
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
@@ -66105,36 +65443,7 @@ function isMissingDetectedProtocolV2Error(method, error) {
|
|
|
66105
65443
|
typeof typedError.message === 'string' &&
|
|
66106
65444
|
typedError.message.includes('Device protocol has not been detected'));
|
|
66107
65445
|
}
|
|
66108
|
-
function
|
|
66109
|
-
return (method.payload.connectProtocol === 'V2' &&
|
|
66110
|
-
(error === null || error === void 0 ? void 0 : error.errorCode) ===
|
|
66111
|
-
hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation);
|
|
66112
|
-
}
|
|
66113
|
-
const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
|
|
66114
|
-
function raceBleAcquire(acquirePromise, abortSignal) {
|
|
66115
|
-
return new Promise((resolve, reject) => {
|
|
66116
|
-
let settled = false;
|
|
66117
|
-
const settle = (fn) => {
|
|
66118
|
-
if (settled)
|
|
66119
|
-
return;
|
|
66120
|
-
settled = true;
|
|
66121
|
-
clearTimeout(deadline);
|
|
66122
|
-
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', onAbort);
|
|
66123
|
-
fn();
|
|
66124
|
-
};
|
|
66125
|
-
const onAbort = () => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled)));
|
|
66126
|
-
const deadline = setTimeout(() => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, `BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline`))), BLE_ACQUIRE_DEADLINE_MS);
|
|
66127
|
-
acquirePromise.then(value => settle(() => resolve(value)), error => settle(() => reject(error)));
|
|
66128
|
-
if (abortSignal) {
|
|
66129
|
-
if (abortSignal.aborted) {
|
|
66130
|
-
onAbort();
|
|
66131
|
-
return;
|
|
66132
|
-
}
|
|
66133
|
-
abortSignal.addEventListener('abort', onAbort);
|
|
66134
|
-
}
|
|
66135
|
-
});
|
|
66136
|
-
}
|
|
66137
|
-
function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
65446
|
+
function connectDeviceForBle(method, device, retryCount = 0) {
|
|
66138
65447
|
var _a;
|
|
66139
65448
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66140
65449
|
try {
|
|
@@ -66149,31 +65458,9 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
|
66149
65458
|
!device.commands ||
|
|
66150
65459
|
device.commands.disposed;
|
|
66151
65460
|
if (shouldAcquire) {
|
|
66152
|
-
|
|
66153
|
-
|
|
66154
|
-
|
|
66155
|
-
}
|
|
66156
|
-
if (!useAcquireGuards) {
|
|
66157
|
-
yield device.acquire(method.payload.connectProtocol, {
|
|
66158
|
-
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
66159
|
-
});
|
|
66160
|
-
}
|
|
66161
|
-
else {
|
|
66162
|
-
try {
|
|
66163
|
-
yield raceBleAcquire(device.acquire(method.payload.connectProtocol, {
|
|
66164
|
-
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
66165
|
-
}), abortSignal);
|
|
66166
|
-
}
|
|
66167
|
-
catch (err) {
|
|
66168
|
-
if (err.errorCode === hdShared.HardwareErrorCode.BleTimeoutError &&
|
|
66169
|
-
device.mainId &&
|
|
66170
|
-
device.deviceConnector) {
|
|
66171
|
-
yield device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
|
|
66172
|
-
device.markTransportDisconnected();
|
|
66173
|
-
}
|
|
66174
|
-
throw err;
|
|
66175
|
-
}
|
|
66176
|
-
}
|
|
65461
|
+
yield device.acquire(method.payload.connectProtocol, {
|
|
65462
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
65463
|
+
});
|
|
66177
65464
|
}
|
|
66178
65465
|
if ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.onlyConnectBleDevice) {
|
|
66179
65466
|
if (shouldAcquire) {
|
|
@@ -66204,7 +65491,7 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
|
66204
65491
|
const nextRetry = retryCount + 1;
|
|
66205
65492
|
Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
|
|
66206
65493
|
yield wait(3000);
|
|
66207
|
-
yield connectDeviceForBle(method, device,
|
|
65494
|
+
yield connectDeviceForBle(method, device, nextRetry);
|
|
66208
65495
|
}
|
|
66209
65496
|
else {
|
|
66210
65497
|
throw err;
|
|
@@ -66221,7 +65508,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66221
65508
|
Log.debug(`EnsureConnected function start, MAX_RETRY_COUNT=${MAX_RETRY_COUNT}, POLL_INTERVAL_TIME=${POLL_INTERVAL_TIME} `);
|
|
66222
65509
|
const poll = (time = POLL_INTERVAL_TIME) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66223
65510
|
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66224
|
-
var
|
|
65511
|
+
var _t;
|
|
66225
65512
|
const abort = () => {
|
|
66226
65513
|
if (abortSignal && abortSignal.aborted) {
|
|
66227
65514
|
if (timer) {
|
|
@@ -66289,7 +65576,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66289
65576
|
if (tryCount === 1) {
|
|
66290
65577
|
device.beginConnectionAttempt();
|
|
66291
65578
|
}
|
|
66292
|
-
yield connectDeviceForBle(method, device
|
|
65579
|
+
yield connectDeviceForBle(method, device);
|
|
66293
65580
|
}
|
|
66294
65581
|
resolve(device);
|
|
66295
65582
|
return;
|
|
@@ -66331,8 +65618,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66331
65618
|
hdShared.HardwareErrorCode.BridgeNeedsPermission,
|
|
66332
65619
|
hdShared.HardwareErrorCode.DeviceInterruptedFromUser,
|
|
66333
65620
|
hdShared.HardwareErrorCode.CallQueueActionCancelled,
|
|
66334
|
-
].includes(error.errorCode)
|
|
66335
|
-
isProtocolV2PeerRemovedPairingError(method, error)) {
|
|
65621
|
+
].includes(error.errorCode)) {
|
|
66336
65622
|
reject(error);
|
|
66337
65623
|
return;
|
|
66338
65624
|
}
|
|
@@ -66342,7 +65628,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66342
65628
|
clearTimeout(timer);
|
|
66343
65629
|
}
|
|
66344
65630
|
Log.debug('EnsureConnected get to max try count, will return: ', tryCount);
|
|
66345
|
-
if (DataManager.isBrowserWebUsb(env) && !((
|
|
65631
|
+
if (DataManager.isBrowserWebUsb(env) && !((_t = method.payload) === null || _t === void 0 ? void 0 : _t.skipWebDevicePrompt)) {
|
|
66346
65632
|
postMessage(createUiMessage(UI_REQUEST.WEB_DEVICE_PROMPT_ACCESS_PERMISSION));
|
|
66347
65633
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission));
|
|
66348
65634
|
}
|
|
@@ -66367,7 +65653,6 @@ const cancel = (context, connectId) => {
|
|
|
66367
65653
|
requestQueue.cancelCallbackTasks(connectId);
|
|
66368
65654
|
const requestIds = requestQueue.getRequestTasksId();
|
|
66369
65655
|
Log.debug(`Cancel Api connect requestQueues: length:${requestIds.length} requestIds:${requestIds.join(',')}`);
|
|
66370
|
-
requestQueue.abortRequestsByConnectId(connectId);
|
|
66371
65656
|
const canceledDevices = [];
|
|
66372
65657
|
const interruptDevice = (device, deviceConnectId) => {
|
|
66373
65658
|
if (!device || canceledDevices.includes(device)) {
|
|
@@ -66386,6 +65671,7 @@ const cancel = (context, connectId) => {
|
|
|
66386
65671
|
}
|
|
66387
65672
|
}
|
|
66388
65673
|
interruptDevice(deviceCacheMap.get(connectId), connectId);
|
|
65674
|
+
requestQueue.abortRequestsByConnectId(connectId);
|
|
66389
65675
|
pollingManager.stop(connectId);
|
|
66390
65676
|
}
|
|
66391
65677
|
catch (e) {
|
|
@@ -66396,7 +65682,6 @@ const cancel = (context, connectId) => {
|
|
|
66396
65682
|
const env = DataManager.getSettings('env');
|
|
66397
65683
|
if (DataManager.isBleConnect(env)) {
|
|
66398
65684
|
Log.debug('Cancel Api all _deviceList: ');
|
|
66399
|
-
requestQueue.abortAllRequests();
|
|
66400
65685
|
const canceledDevices = [];
|
|
66401
65686
|
const interruptDevice = (device) => {
|
|
66402
65687
|
if (!device || canceledDevices.includes(device)) {
|
|
@@ -66418,6 +65703,7 @@ const cancel = (context, connectId) => {
|
|
|
66418
65703
|
}
|
|
66419
65704
|
}
|
|
66420
65705
|
deviceCacheMap.forEach(interruptDevice);
|
|
65706
|
+
requestQueue.abortAllRequests();
|
|
66421
65707
|
pollingManager.stopAll();
|
|
66422
65708
|
}
|
|
66423
65709
|
else {
|
|
@@ -66455,12 +65741,8 @@ const checkPassphraseEnableState = (method, features) => {
|
|
|
66455
65741
|
}
|
|
66456
65742
|
};
|
|
66457
65743
|
const shouldCheckPassphraseState = (method, device) => {
|
|
66458
|
-
var _a;
|
|
66459
65744
|
if (!method.useDevicePassphraseState)
|
|
66460
65745
|
return false;
|
|
66461
|
-
if (device.isProtocolV2() && ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.useEmptyPassphrase) === true) {
|
|
66462
|
-
return true;
|
|
66463
|
-
}
|
|
66464
65746
|
return device.hasUsePassphrase();
|
|
66465
65747
|
};
|
|
66466
65748
|
const cleanup = () => {
|