@onekeyfe/hd-core 1.2.2-alpha.1 → 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 -68
- package/__tests__/evmSignTypedData.test.ts +0 -42
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +12 -825
- 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 -710
- package/dist/api/FirmwareUpdateV4.d.ts +0 -4
- 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 -21
- package/dist/index.js +402 -1136
- 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 -434
- 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 -31
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +8 -27
- 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 -354
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;
|
|
@@ -52302,21 +51864,13 @@ const isProtocolV2FirmwareStatusEndpointUnavailable = (error) => {
|
|
|
52302
51864
|
message.includes('message handler not found') ||
|
|
52303
51865
|
message.includes('unsupported message'));
|
|
52304
51866
|
};
|
|
52305
|
-
const isProtocolV2InstallResponseTimeout = (error) => {
|
|
52306
|
-
if (!error || typeof error !== 'object')
|
|
52307
|
-
return false;
|
|
52308
|
-
const { code } = error;
|
|
52309
|
-
return (code === 'response-timeout' ||
|
|
52310
|
-
/\bresponse timeout\b/i.test(getProtocolV2UnknownErrorText(error)));
|
|
52311
|
-
};
|
|
52312
51867
|
const isProtocolV2TerminalInstallStatusError = (error) => {
|
|
52313
51868
|
var _a;
|
|
52314
|
-
return hdShared.
|
|
52315
|
-
(error
|
|
52316
|
-
|
|
52317
|
-
|
|
52318
|
-
|
|
52319
|
-
((_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);
|
|
52320
51874
|
};
|
|
52321
51875
|
const isProtocolV2TargetStatusFinished = (status) => normalizeProtocolV2TargetStatus(status) === PROTOCOL_V2_TARGET_STATUS_FINISHED;
|
|
52322
51876
|
const isProtocolV2TargetStatusInProgress = (status) => normalizeProtocolV2TargetStatus(status) === PROTOCOL_V2_TARGET_STATUS_PENDING ||
|
|
@@ -52340,14 +51894,6 @@ const normalizeProtocolV2TargetStatus = (status) => {
|
|
|
52340
51894
|
}
|
|
52341
51895
|
return undefined;
|
|
52342
51896
|
};
|
|
52343
|
-
const PROTOCOL_V2_INSTALL_PHASE_BY_DECODED_VALUE = new Map([
|
|
52344
|
-
[0, 'prepare'],
|
|
52345
|
-
[1, 'install'],
|
|
52346
|
-
[2, 'verify'],
|
|
52347
|
-
['FW_MGMT_UPDATER_PHASE_PREPARE', 'prepare'],
|
|
52348
|
-
['FW_MGMT_UPDATER_PHASE_INSTALL', 'install'],
|
|
52349
|
-
['FW_MGMT_UPDATER_PHASE_VERIFY', 'verify'],
|
|
52350
|
-
]);
|
|
52351
51897
|
const normalizeProtocolV2Hex = (value) => value === null || value === void 0 ? void 0 : value.replace(/^0x/i, '').toLowerCase();
|
|
52352
51898
|
const versionArrayToNumber = (version) => {
|
|
52353
51899
|
if (!version)
|
|
@@ -52403,10 +51949,6 @@ const toProtocolV2FiniteNumber = (value) => {
|
|
|
52403
51949
|
}
|
|
52404
51950
|
return undefined;
|
|
52405
51951
|
};
|
|
52406
|
-
const normalizeProtocolV2ProgressPercent = (value) => {
|
|
52407
|
-
const progress = toProtocolV2FiniteNumber(value);
|
|
52408
|
-
return progress === undefined ? undefined : Math.min(100, Math.max(0, progress));
|
|
52409
|
-
};
|
|
52410
51952
|
const isProtocolV2FirmwareFingerprintValid = (binary, fingerprint) => {
|
|
52411
51953
|
const expectedFingerprint = normalizeProtocolV2Hex(fingerprint);
|
|
52412
51954
|
if (!expectedFingerprint)
|
|
@@ -52435,9 +51977,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52435
51977
|
this.protocolV2CompletedTargetVersions = new Map();
|
|
52436
51978
|
this.protocolV2CompletedTargetIds = new Set();
|
|
52437
51979
|
this.protocolV2InstallBaselineVersions = new Map();
|
|
52438
|
-
this.protocolV2InstallNeedsReconnect = false;
|
|
52439
|
-
this.protocolV2InstallDisconnectObserved = false;
|
|
52440
|
-
this.protocolV2InstallTerminalSuccessObserved = false;
|
|
52441
51980
|
this.protocolV2LastTransferProgressAt = 0;
|
|
52442
51981
|
}
|
|
52443
51982
|
getSupportedProtocols() {
|
|
@@ -52608,7 +52147,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52608
52147
|
}
|
|
52609
52148
|
run() {
|
|
52610
52149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52611
|
-
Log$
|
|
52150
|
+
Log$7.debug('FirmwareUpdateV4 strategy: Protocol V2');
|
|
52612
52151
|
return this.runProtocolV2();
|
|
52613
52152
|
});
|
|
52614
52153
|
}
|
|
@@ -53040,7 +52579,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53040
52579
|
if (!observedVersion) {
|
|
53041
52580
|
const hasCompleteTargetEvidence = targetId !== undefined && this.protocolV2CompletedTargetIds.has(targetId);
|
|
53042
52581
|
if (hasCompleteTargetEvidence) {
|
|
53043
|
-
Log$
|
|
52582
|
+
Log$7.warn(`Protocol V2 target ${target} has no observable final version; install completion is authoritative`);
|
|
53044
52583
|
}
|
|
53045
52584
|
else {
|
|
53046
52585
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareVerificationFailed, `Protocol V2 target ${target} has no observable final version after status fallback`);
|
|
@@ -53403,10 +52942,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53403
52942
|
return true;
|
|
53404
52943
|
}
|
|
53405
52944
|
catch (error) {
|
|
53406
|
-
|
|
53407
|
-
throw error;
|
|
53408
|
-
}
|
|
53409
|
-
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);
|
|
53410
52946
|
return false;
|
|
53411
52947
|
}
|
|
53412
52948
|
});
|
|
@@ -53446,7 +52982,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53446
52982
|
if (error instanceof hdShared.HardwareError) {
|
|
53447
52983
|
throw error;
|
|
53448
52984
|
}
|
|
53449
|
-
Log$
|
|
52985
|
+
Log$7.log('Protocol V2 auto go to bootloader mode failed: ', error);
|
|
53450
52986
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure);
|
|
53451
52987
|
}
|
|
53452
52988
|
});
|
|
@@ -53454,12 +52990,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53454
52990
|
enterProtocolV2BootloaderMode() {
|
|
53455
52991
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53456
52992
|
if (this.isProtocolV2RomloaderMode()) {
|
|
53457
|
-
Log$
|
|
52993
|
+
Log$7.debug('Protocol V2 device is in romloader mode; start firmware update directly');
|
|
53458
52994
|
this.protocolV2ExecutionInLoader = true;
|
|
53459
52995
|
return false;
|
|
53460
52996
|
}
|
|
53461
52997
|
if (this.isProtocolV2BootloaderMode()) {
|
|
53462
|
-
Log$
|
|
52998
|
+
Log$7.debug('Protocol V2 device is already in bootloader mode, skip reboot');
|
|
53463
52999
|
this.protocolV2ExecutionInLoader = true;
|
|
53464
53000
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.GoToBootloaderSuccess);
|
|
53465
53001
|
return false;
|
|
@@ -53490,12 +53026,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53490
53026
|
lastError = new Error('Protocol V2 device is reachable but is not in bootloader mode');
|
|
53491
53027
|
}
|
|
53492
53028
|
catch (error) {
|
|
53493
|
-
if (
|
|
53029
|
+
if (this.isProtocolV2ReconnectIdentityError(error)) {
|
|
53494
53030
|
throw error;
|
|
53495
53031
|
}
|
|
53496
53032
|
shouldReconnect = true;
|
|
53497
53033
|
lastError = error;
|
|
53498
|
-
Log$
|
|
53034
|
+
Log$7.log('Protocol V2 bootloader mode not ready, polling reconnect: ', error);
|
|
53499
53035
|
}
|
|
53500
53036
|
yield hdShared.wait(retryInterval);
|
|
53501
53037
|
}
|
|
@@ -53591,7 +53127,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53591
53127
|
const resourcesToSync = [];
|
|
53592
53128
|
for (const resource of resourceSources) {
|
|
53593
53129
|
if (yield this.isProtocolV2ResourceBundleUpToDate(resource)) {
|
|
53594
|
-
Log$
|
|
53130
|
+
Log$7.log(`[FirmwareUpdateV4] skip RESC bundle ${resource.name}; already up to date`);
|
|
53595
53131
|
}
|
|
53596
53132
|
else {
|
|
53597
53133
|
resourcesToSync.push(resource);
|
|
@@ -53693,9 +53229,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53693
53229
|
return processedSize + source.size;
|
|
53694
53230
|
}
|
|
53695
53231
|
catch (error) {
|
|
53696
|
-
if (hdShared.isBleStaleBondHardwareError(error)) {
|
|
53697
|
-
throw error;
|
|
53698
|
-
}
|
|
53699
53232
|
lastError = error;
|
|
53700
53233
|
if (attempt < PROTOCOL_V2_FILE_TRANSFER_RETRY_COUNT) {
|
|
53701
53234
|
yield this.recoverProtocolV2FileTransfer();
|
|
@@ -53719,25 +53252,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53719
53252
|
}
|
|
53720
53253
|
});
|
|
53721
53254
|
}
|
|
53722
|
-
|
|
53723
|
-
|
|
53724
|
-
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53725
|
-
if (targetId !== undefined &&
|
|
53726
|
-
expectedTargetIds.has(targetId) &&
|
|
53727
|
-
isProtocolV2TargetStatusInProgress(target.status)) {
|
|
53728
|
-
liveTargetIds.add(targetId);
|
|
53729
|
-
}
|
|
53730
|
-
});
|
|
53731
|
-
}
|
|
53732
|
-
assertProtocolV2TargetStatus(statusTargets, expectedTargetIds, expectedPaths, liveTargetIds) {
|
|
53733
|
-
const resolvedExpectedPaths = expectedPaths !== null && expectedPaths !== void 0 ? expectedPaths : new Map();
|
|
53734
|
-
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)}`);
|
|
53735
53257
|
const failedTarget = statusTargets.find(target => {
|
|
53736
53258
|
var _a;
|
|
53737
|
-
|
|
53738
|
-
|
|
53739
|
-
isProtocolV2TargetStatusFailed(target.status) &&
|
|
53740
|
-
(!liveTargetIds || liveTargetIds.has(targetId)));
|
|
53259
|
+
return expectedTargetIds.has((_a = normalizeProtocolV2TargetId(target.target_id)) !== null && _a !== void 0 ? _a : -1) &&
|
|
53260
|
+
isProtocolV2TargetStatusFailed(target.status);
|
|
53741
53261
|
});
|
|
53742
53262
|
if (failedTarget) {
|
|
53743
53263
|
const failedTargetDetails = JSON.stringify({
|
|
@@ -53746,51 +53266,26 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53746
53266
|
payloadVersion: failedTarget.payload_version,
|
|
53747
53267
|
path: failedTarget.path,
|
|
53748
53268
|
});
|
|
53749
|
-
Log$
|
|
53269
|
+
Log$7.error(`[FirmwareUpdateV4] firmware install failed target=${failedTargetDetails}`);
|
|
53750
53270
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, 'Protocol V2 firmware install failed', {
|
|
53751
53271
|
firmwareUpdateCode: PROTOCOL_V2_INSTALL_FAILED_CODE,
|
|
53752
53272
|
});
|
|
53753
53273
|
}
|
|
53754
|
-
if (liveTargetIds) {
|
|
53755
|
-
const staleFailedTargets = statusTargets.filter(target => {
|
|
53756
|
-
var _a;
|
|
53757
|
-
const targetId = (_a = normalizeProtocolV2TargetId(target.target_id)) !== null && _a !== void 0 ? _a : -1;
|
|
53758
|
-
return (expectedTargetIds.has(targetId) &&
|
|
53759
|
-
isProtocolV2TargetStatusFailed(target.status) &&
|
|
53760
|
-
!liveTargetIds.has(targetId));
|
|
53761
|
-
});
|
|
53762
|
-
if (staleFailedTargets.length > 0) {
|
|
53763
|
-
Log$6.log(`[FirmwareUpdateV4] ignoring stale failed firmware status until those targets start: ${JSON.stringify(staleFailedTargets.map(target => ({
|
|
53764
|
-
targetId: target.target_id,
|
|
53765
|
-
status: target.status,
|
|
53766
|
-
path: target.path,
|
|
53767
|
-
})))}`);
|
|
53768
|
-
}
|
|
53769
|
-
}
|
|
53770
53274
|
const matchingTargets = statusTargets.filter(target => { var _a; return expectedTargetIds.has((_a = normalizeProtocolV2TargetId(target.target_id)) !== null && _a !== void 0 ? _a : -1); });
|
|
53771
53275
|
const seenTargetIds = new Set();
|
|
53772
53276
|
for (const target of matchingTargets) {
|
|
53773
53277
|
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53774
|
-
const pathConflictsWithCurrentInstall = targetId !== undefined &&
|
|
53775
|
-
Boolean(target.path) &&
|
|
53776
|
-
Boolean(resolvedExpectedPaths.get(targetId)) &&
|
|
53777
|
-
target.path !== resolvedExpectedPaths.get(targetId) &&
|
|
53778
|
-
(!liveTargetIds || liveTargetIds.has(targetId));
|
|
53779
53278
|
if (targetId === undefined ||
|
|
53780
53279
|
seenTargetIds.has(targetId) ||
|
|
53781
|
-
|
|
53782
|
-
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}`);
|
|
53783
53282
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, 'Protocol V2 firmware install status conflict', {
|
|
53784
53283
|
firmwareUpdateCode: PROTOCOL_V2_INSTALL_STATUS_CONFLICT_CODE,
|
|
53785
53284
|
});
|
|
53786
53285
|
}
|
|
53787
53286
|
seenTargetIds.add(targetId);
|
|
53788
53287
|
}
|
|
53789
|
-
const completedTargets = matchingTargets.filter(target =>
|
|
53790
|
-
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53791
|
-
return (isProtocolV2TargetStatusFinished(target.status) &&
|
|
53792
|
-
(!liveTargetIds || (targetId !== undefined && liveTargetIds.has(targetId))));
|
|
53793
|
-
});
|
|
53288
|
+
const completedTargets = matchingTargets.filter(target => isProtocolV2TargetStatusFinished(target.status));
|
|
53794
53289
|
const completedTargetIds = new Set();
|
|
53795
53290
|
completedTargets.forEach(target => {
|
|
53796
53291
|
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
@@ -53820,41 +53315,10 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53820
53315
|
return true;
|
|
53821
53316
|
}
|
|
53822
53317
|
if (expectedTargetIds.size > 0 && matchingTargets.length > 0) {
|
|
53823
|
-
|
|
53824
|
-
let installProgressMetadata;
|
|
53825
|
-
let hasInProgressTarget = false;
|
|
53826
|
-
matchingTargets.forEach(target => {
|
|
53827
|
-
var _a, _b;
|
|
53828
|
-
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53829
|
-
if (targetId === undefined ||
|
|
53830
|
-
completedTargetIds.has(targetId) ||
|
|
53831
|
-
!isProtocolV2TargetStatusInProgress(target.status) ||
|
|
53832
|
-
(liveTargetIds && !liveTargetIds.has(targetId))) {
|
|
53833
|
-
return;
|
|
53834
|
-
}
|
|
53835
|
-
hasInProgressTarget = true;
|
|
53836
|
-
detailedProgress += (_a = normalizeProtocolV2ProgressPercent(target.progress_percent)) !== null && _a !== void 0 ? _a : 0;
|
|
53837
|
-
const installPhase = target.phase_info
|
|
53838
|
-
? PROTOCOL_V2_INSTALL_PHASE_BY_DECODED_VALUE.get(target.phase_info.phase)
|
|
53839
|
-
: undefined;
|
|
53840
|
-
const installPhaseProgress = normalizeProtocolV2ProgressPercent((_b = target.phase_info) === null || _b === void 0 ? void 0 : _b.progress_percent);
|
|
53841
|
-
if (installPhase && installPhaseProgress !== undefined && !installProgressMetadata) {
|
|
53842
|
-
installProgressMetadata = {
|
|
53843
|
-
installTargetId: targetId,
|
|
53844
|
-
installPhase,
|
|
53845
|
-
installPhaseProgress,
|
|
53846
|
-
};
|
|
53847
|
-
}
|
|
53848
|
-
});
|
|
53318
|
+
const hasInProgressTarget = matchingTargets.some(target => isProtocolV2TargetStatusInProgress(target.status));
|
|
53849
53319
|
const completedProgress = Math.floor((completedTargetIds.size / expectedTargetIds.size) * 100);
|
|
53850
|
-
const
|
|
53851
|
-
|
|
53852
|
-
if (installProgressMetadata) {
|
|
53853
|
-
this.postProgressMessage(progress, 'installingFirmware', installProgressMetadata);
|
|
53854
|
-
}
|
|
53855
|
-
else {
|
|
53856
|
-
this.postProgressMessage(progress, 'installingFirmware');
|
|
53857
|
-
}
|
|
53320
|
+
const progress = Math.min(99, Math.max(completedProgress, hasInProgressTarget ? 1 : 0));
|
|
53321
|
+
this.postProgressMessage(progress, 'installingFirmware');
|
|
53858
53322
|
}
|
|
53859
53323
|
return false;
|
|
53860
53324
|
}
|
|
@@ -53907,65 +53371,43 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53907
53371
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53908
53372
|
const expectedTargetIds = new Set(targets.map(target => target.target_id));
|
|
53909
53373
|
const expectedPaths = new Map(targets.map(target => [target.target_id, target.path]));
|
|
53910
|
-
const isBleInstall = this.isBleReconnect();
|
|
53911
53374
|
const startTime = Date.now();
|
|
53912
53375
|
let lastError;
|
|
53913
|
-
let shouldReconnect =
|
|
53914
|
-
this.protocolV2InstallNeedsReconnect = false;
|
|
53376
|
+
let shouldReconnect = false;
|
|
53915
53377
|
let deviceInfo;
|
|
53916
|
-
let
|
|
53917
|
-
let installStatusDisconnectObserved = isBleInstall && this.protocolV2InstallDisconnectObserved;
|
|
53918
|
-
this.protocolV2InstallDisconnectObserved = false;
|
|
53919
|
-
let installReconnectObserved = false;
|
|
53920
|
-
let finishedStatusSnapshotKey;
|
|
53921
|
-
let finishedStatusSnapshotPolls = 0;
|
|
53922
|
-
let fastFinishedInstallProgressReported = false;
|
|
53923
|
-
let installEvidenceObserved = this.protocolV2InstallTerminalSuccessObserved;
|
|
53378
|
+
let installEvidenceObserved = false;
|
|
53924
53379
|
let currentInstallStatusObserved = false;
|
|
53925
|
-
const liveTargetIds = new Set();
|
|
53926
|
-
const recordBleInstallDisconnect = (error) => {
|
|
53927
|
-
if (!isBleInstall ||
|
|
53928
|
-
!isProtocolV2DeviceDisconnectedError(error) ||
|
|
53929
|
-
isProtocolV2InstallResponseTimeout(error)) {
|
|
53930
|
-
return;
|
|
53931
|
-
}
|
|
53932
|
-
installStatusDisconnectObserved = true;
|
|
53933
|
-
installReconnectObserved = false;
|
|
53934
|
-
finishedStatusSnapshotKey = undefined;
|
|
53935
|
-
finishedStatusSnapshotPolls = 0;
|
|
53936
|
-
};
|
|
53937
53380
|
while (Date.now() - startTime < PROTOCOL_V2_INSTALL_TIMEOUT) {
|
|
53938
53381
|
this.throwIfAborted();
|
|
53939
53382
|
try {
|
|
53940
53383
|
if (shouldReconnect) {
|
|
53941
|
-
|
|
53942
|
-
yield this.
|
|
53943
|
-
bleInstallLinkReady = isBleInstallReconnect;
|
|
53944
|
-
deviceInfo = isBleInstallReconnect
|
|
53945
|
-
? undefined
|
|
53946
|
-
: yield this.verifyProtocolV2ReconnectIdentity();
|
|
53947
|
-
if (isBleInstallReconnect && installStatusDisconnectObserved) {
|
|
53948
|
-
installReconnectObserved = true;
|
|
53949
|
-
}
|
|
53384
|
+
yield this.reconnectProtocolV2Device();
|
|
53385
|
+
deviceInfo = yield this.verifyProtocolV2ReconnectIdentity();
|
|
53950
53386
|
shouldReconnect = false;
|
|
53951
53387
|
}
|
|
53952
|
-
|
|
53388
|
+
const currentDeviceInfo = deviceInfo;
|
|
53953
53389
|
try {
|
|
53954
|
-
const statusResponse = yield this.device.getCommands().typedCall('DeviceFirmwareUpdateStatusGet', 'DeviceFirmwareUpdateStatus', {
|
|
53390
|
+
const statusResponse = yield this.device.getCommands().typedCall('DeviceFirmwareUpdateStatusGet', ['DeviceFirmwareUpdateStatus', 'Success'], {
|
|
53955
53391
|
fields: {
|
|
53956
53392
|
status: true,
|
|
53957
|
-
progress_percent: true,
|
|
53958
|
-
phase_info: true,
|
|
53959
53393
|
payload_version: true,
|
|
53960
53394
|
path: true,
|
|
53961
53395
|
},
|
|
53962
53396
|
}, { timeoutMs: PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT });
|
|
53963
|
-
if (
|
|
53397
|
+
if (statusResponse.type === 'Success') {
|
|
53964
53398
|
installEvidenceObserved = true;
|
|
53399
|
+
lastError = new Error('Protocol V2 firmware install acknowledged; waiting for target status');
|
|
53965
53400
|
}
|
|
53966
|
-
const statusTargets =
|
|
53967
|
-
|
|
53968
|
-
|
|
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) {
|
|
53969
53411
|
currentInstallStatusObserved = true;
|
|
53970
53412
|
}
|
|
53971
53413
|
const hasMatchingTargetStatus = statusTargets.some(target => {
|
|
@@ -53980,102 +53422,31 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53980
53422
|
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53981
53423
|
return targetId !== undefined && expectedTargetIds.has(targetId);
|
|
53982
53424
|
});
|
|
53983
|
-
const
|
|
53984
|
-
const matchingFinishedStatus = matchingStatusTargets
|
|
53985
|
-
.map(target => {
|
|
53986
|
-
var _a;
|
|
53987
|
-
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53988
|
-
const expectedPath = targetId === undefined ? undefined : expectedPaths.get(targetId);
|
|
53989
|
-
const expectedVersion = targetId === undefined
|
|
53990
|
-
? undefined
|
|
53991
|
-
: this.getExpectedProtocolV2TargetVersion(targetId);
|
|
53992
|
-
const payloadVersion = toProtocolV2FiniteNumber(target.payload_version);
|
|
53993
|
-
if (targetId === undefined ||
|
|
53994
|
-
matchingFinishedTargetIds.has(targetId) ||
|
|
53995
|
-
!isProtocolV2TargetStatusFinished(target.status) ||
|
|
53996
|
-
(Boolean(target.path) && Boolean(expectedPath) && target.path !== expectedPath) ||
|
|
53997
|
-
(expectedVersion !== undefined &&
|
|
53998
|
-
payloadVersion !== undefined &&
|
|
53999
|
-
payloadVersion !== expectedVersion)) {
|
|
54000
|
-
return undefined;
|
|
54001
|
-
}
|
|
54002
|
-
matchingFinishedTargetIds.add(targetId);
|
|
54003
|
-
return [targetId, (_a = target.path) !== null && _a !== void 0 ? _a : null, payloadVersion !== null && payloadVersion !== void 0 ? payloadVersion : null];
|
|
54004
|
-
})
|
|
54005
|
-
.filter((target) => !!target)
|
|
54006
|
-
.sort(([leftTargetId], [rightTargetId]) => leftTargetId - rightTargetId);
|
|
54007
|
-
const hasCompleteMatchingFinishedStatus = matchingFinishedStatus.length === expectedTargetIds.size &&
|
|
54008
|
-
matchingFinishedTargetIds.size === expectedTargetIds.size &&
|
|
54009
|
-
expectedTargetIds.size > 0;
|
|
54010
|
-
if (requireCurrentInstallStatus &&
|
|
54011
|
-
installReconnectObserved &&
|
|
54012
|
-
hasCompleteMatchingFinishedStatus) {
|
|
54013
|
-
const nextSnapshotKey = JSON.stringify(matchingFinishedStatus);
|
|
54014
|
-
if (nextSnapshotKey === finishedStatusSnapshotKey) {
|
|
54015
|
-
finishedStatusSnapshotPolls += 1;
|
|
54016
|
-
}
|
|
54017
|
-
else {
|
|
54018
|
-
finishedStatusSnapshotKey = nextSnapshotKey;
|
|
54019
|
-
finishedStatusSnapshotPolls = 1;
|
|
54020
|
-
}
|
|
54021
|
-
}
|
|
54022
|
-
else {
|
|
54023
|
-
finishedStatusSnapshotKey = undefined;
|
|
54024
|
-
finishedStatusSnapshotPolls = 0;
|
|
54025
|
-
}
|
|
54026
|
-
if (requireCurrentInstallStatus &&
|
|
54027
|
-
installReconnectObserved &&
|
|
54028
|
-
hasCompleteMatchingFinishedStatus &&
|
|
54029
|
-
!currentInstallStatusObserved &&
|
|
54030
|
-
!this.protocolV2InstallTerminalSuccessObserved &&
|
|
54031
|
-
!fastFinishedInstallProgressReported) {
|
|
54032
|
-
this.postProgressMessage(1, 'installingFirmware');
|
|
54033
|
-
fastFinishedInstallProgressReported = true;
|
|
54034
|
-
}
|
|
54035
|
-
const finishedAfterDisconnectObserved = finishedStatusSnapshotPolls >= PROTOCOL_V2_INSTALL_FINISHED_AFTER_DISCONNECT_POLLS;
|
|
54036
|
-
const hasCurrentInstallEvidence = currentInstallStatusObserved ||
|
|
54037
|
-
this.protocolV2InstallTerminalSuccessObserved ||
|
|
54038
|
-
finishedAfterDisconnectObserved;
|
|
54039
|
-
if (hasCurrentInstallEvidence) {
|
|
54040
|
-
installEvidenceObserved = true;
|
|
54041
|
-
}
|
|
54042
|
-
const shouldVerifyTargetCompletion = !requireCurrentInstallStatus || hasCurrentInstallEvidence;
|
|
53425
|
+
const shouldVerifyTargetCompletion = !requireCurrentInstallStatus || currentInstallStatusObserved;
|
|
54043
53426
|
if (shouldVerifyTargetCompletion &&
|
|
54044
|
-
this.assertProtocolV2TargetStatus(statusTargets, expectedTargetIds, expectedPaths
|
|
54045
|
-
!this.protocolV2InstallTerminalSuccessObserved &&
|
|
54046
|
-
!finishedAfterDisconnectObserved
|
|
54047
|
-
? liveTargetIds
|
|
54048
|
-
: undefined)) {
|
|
53427
|
+
this.assertProtocolV2TargetStatus(statusTargets, expectedTargetIds, expectedPaths)) {
|
|
54049
53428
|
return;
|
|
54050
53429
|
}
|
|
54051
|
-
if (!hasCurrentInstallEvidence) {
|
|
54052
|
-
this.device.setCancelableAction(() => this.device.getCommands().cancelDevice());
|
|
54053
|
-
}
|
|
54054
53430
|
if (requireCurrentInstallStatus &&
|
|
54055
|
-
!
|
|
53431
|
+
!currentInstallStatusObserved &&
|
|
54056
53432
|
matchingStatusTargets.length > 0) {
|
|
54057
53433
|
lastError = new Error('Protocol V2 firmware status is stale; waiting for the current install to start');
|
|
54058
53434
|
}
|
|
54059
|
-
if (statusTargets.length === 0 &&
|
|
54060
|
-
!currentDeviceInfo &&
|
|
54061
|
-
bleInstallLinkReady &&
|
|
54062
|
-
installEvidenceObserved) {
|
|
54063
|
-
currentDeviceInfo = yield this.verifyProtocolV2ReconnectIdentity();
|
|
54064
|
-
deviceInfo = currentDeviceInfo;
|
|
54065
|
-
}
|
|
54066
53435
|
if (statusTargets.length === 0 && currentDeviceInfo) {
|
|
54067
53436
|
const isNormalMode = yield this.probeProtocolV2NormalMode(currentDeviceInfo);
|
|
54068
53437
|
if (isNormalMode &&
|
|
54069
53438
|
(installEvidenceObserved ||
|
|
54070
53439
|
this.hasProtocolV2InstallVersionChanged(expectedTargetIds))) {
|
|
54071
|
-
Log$
|
|
53440
|
+
Log$7.log('[FirmwareUpdateV4] empty firmware status after confirmed App reboot; update complete');
|
|
54072
53441
|
this.recordProtocolV2AuthoritativeInstallCompletion(expectedTargetIds);
|
|
54073
53442
|
this.postProgressMessage(100, 'installingFirmware');
|
|
54074
53443
|
return;
|
|
54075
53444
|
}
|
|
54076
53445
|
}
|
|
54077
53446
|
if (statusTargets.length === 0) {
|
|
54078
|
-
|
|
53447
|
+
if (statusResponse.type !== 'Success') {
|
|
53448
|
+
lastError = new Error('Protocol V2 firmware update is waiting for user confirmation or target status');
|
|
53449
|
+
}
|
|
54079
53450
|
}
|
|
54080
53451
|
else {
|
|
54081
53452
|
const missingTargetIds = this.getProtocolV2MissingTargetIds(statusTargets, expectedTargetIds);
|
|
@@ -54094,20 +53465,13 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54094
53465
|
}
|
|
54095
53466
|
if (isProtocolV2FirmwareStatusEndpointUnavailable(error)) {
|
|
54096
53467
|
if (!currentDeviceInfo) {
|
|
54097
|
-
if (!bleInstallLinkReady) {
|
|
54098
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 device identity is unavailable during install polling');
|
|
54099
|
-
}
|
|
54100
|
-
deviceInfo = yield this.verifyProtocolV2ReconnectIdentity();
|
|
54101
|
-
}
|
|
54102
|
-
const reconnectDeviceInfo = currentDeviceInfo !== null && currentDeviceInfo !== void 0 ? currentDeviceInfo : deviceInfo;
|
|
54103
|
-
if (!reconnectDeviceInfo) {
|
|
54104
53468
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 device identity is unavailable during install polling');
|
|
54105
53469
|
}
|
|
54106
|
-
const isNormalMode = yield this.probeProtocolV2NormalMode(
|
|
53470
|
+
const isNormalMode = yield this.probeProtocolV2NormalMode(currentDeviceInfo);
|
|
54107
53471
|
if (isNormalMode &&
|
|
54108
53472
|
(installEvidenceObserved ||
|
|
54109
53473
|
this.hasProtocolV2InstallVersionChanged(expectedTargetIds))) {
|
|
54110
|
-
Log$
|
|
53474
|
+
Log$7.log('[FirmwareUpdateV4] firmware status endpoint unavailable after confirmed App reboot');
|
|
54111
53475
|
this.recordProtocolV2AuthoritativeInstallCompletion(expectedTargetIds);
|
|
54112
53476
|
this.postProgressMessage(100, 'installingFirmware');
|
|
54113
53477
|
return;
|
|
@@ -54120,12 +53484,10 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54120
53484
|
}
|
|
54121
53485
|
}
|
|
54122
53486
|
else {
|
|
54123
|
-
recordBleInstallDisconnect(error);
|
|
54124
53487
|
shouldReconnect = true;
|
|
54125
53488
|
deviceInfo = undefined;
|
|
54126
|
-
bleInstallLinkReady = false;
|
|
54127
53489
|
lastError = error;
|
|
54128
|
-
Log$
|
|
53490
|
+
Log$7.log('[FirmwareUpdateV4] DeviceFirmwareUpdateStatusGet unavailable during install: ', error);
|
|
54129
53491
|
}
|
|
54130
53492
|
}
|
|
54131
53493
|
}
|
|
@@ -54141,15 +53503,13 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54141
53503
|
((_b = error.params) === null || _b === void 0 ? void 0 : _b.firmwareUpdateCode) === 'FirmwareInstallStatusUnavailable') {
|
|
54142
53504
|
throw error;
|
|
54143
53505
|
}
|
|
54144
|
-
recordBleInstallDisconnect(error);
|
|
54145
53506
|
shouldReconnect = true;
|
|
54146
53507
|
deviceInfo = undefined;
|
|
54147
|
-
|
|
54148
|
-
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);
|
|
54149
53509
|
}
|
|
54150
53510
|
yield hdShared.wait(1000);
|
|
54151
53511
|
}
|
|
54152
|
-
Log$
|
|
53512
|
+
Log$7.error(`[FirmwareUpdateV4] install timed out after ${PROTOCOL_V2_INSTALL_TIMEOUT / 1000}s: ${this.normalizeErrorMessage(lastError)}`);
|
|
54153
53513
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, 'Protocol V2 firmware install timed out', {
|
|
54154
53514
|
firmwareUpdateCode: PROTOCOL_V2_INSTALL_TIMEOUT_CODE,
|
|
54155
53515
|
});
|
|
@@ -54161,15 +53521,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54161
53521
|
const deviceInfo = yield this.verifyProtocolV2ReconnectIdentity();
|
|
54162
53522
|
try {
|
|
54163
53523
|
if (yield this.probeProtocolV2NormalMode(deviceInfo)) {
|
|
54164
|
-
Log$
|
|
53524
|
+
Log$7.log('[FirmwareUpdateV4] device already returned to App mode; skip Normal reboot');
|
|
54165
53525
|
return;
|
|
54166
53526
|
}
|
|
54167
53527
|
}
|
|
54168
53528
|
catch (error) {
|
|
54169
|
-
|
|
54170
|
-
throw error;
|
|
54171
|
-
}
|
|
54172
|
-
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);
|
|
54173
53530
|
}
|
|
54174
53531
|
yield this.protocolV2Reboot(hdTransport.DeviceRebootType.Normal);
|
|
54175
53532
|
this.protocolV2ExecutionInLoader = false;
|
|
@@ -54197,7 +53554,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54197
53554
|
const firmwareVersion = getDeviceFirmwareVersion(features).join('.');
|
|
54198
53555
|
this.protocolV2LatestFinalFeatures = features;
|
|
54199
53556
|
if (firmwareVersion === '0.0.0') {
|
|
54200
|
-
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.');
|
|
54201
53558
|
}
|
|
54202
53559
|
return {
|
|
54203
53560
|
bootloaderVersion,
|
|
@@ -54243,49 +53600,29 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54243
53600
|
lastError = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, 'Protocol V2 device is still in bootloader mode');
|
|
54244
53601
|
}
|
|
54245
53602
|
catch (error) {
|
|
54246
|
-
if (
|
|
53603
|
+
if (this.isProtocolV2ReconnectIdentityError(error)) {
|
|
54247
53604
|
throw error;
|
|
54248
53605
|
}
|
|
54249
53606
|
shouldReconnect = true;
|
|
54250
53607
|
lastError = error;
|
|
54251
|
-
Log$
|
|
53608
|
+
Log$7.log('Protocol V2 normal mode not ready, polling Ping: ', error);
|
|
54252
53609
|
}
|
|
54253
53610
|
yield hdShared.wait(1000);
|
|
54254
53611
|
}
|
|
54255
53612
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, `Protocol V2 final features not ready within ${timeout / 1000}s: ${this.normalizeErrorMessage(lastError)}`);
|
|
54256
53613
|
});
|
|
54257
53614
|
}
|
|
54258
|
-
reconnectProtocolV2Device(
|
|
54259
|
-
var _a, _b, _c, _d, _e, _f
|
|
53615
|
+
reconnectProtocolV2Device() {
|
|
53616
|
+
var _a, _b, _c, _d, _e, _f;
|
|
54260
53617
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54261
53618
|
if (this.isBleReconnect()) {
|
|
54262
|
-
yield this.acquireProtocolV2BleDevice(
|
|
53619
|
+
yield this.acquireProtocolV2BleDevice();
|
|
54263
53620
|
return;
|
|
54264
53621
|
}
|
|
54265
53622
|
const deviceDiff = yield ((_a = this.device.deviceConnector) === null || _a === void 0 ? void 0 : _a.enumerate());
|
|
54266
53623
|
const devicesDescriptor = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
|
|
54267
|
-
|
|
54268
|
-
|
|
54269
|
-
if (isWebUsb && (options === null || options === void 0 ? void 0 : options.skipProtocolProbe)) {
|
|
54270
|
-
const expectedSerialNumber = (_c = this.protocolV2ExpectedSerialNumber) === null || _c === void 0 ? void 0 : _c.trim();
|
|
54271
|
-
const expectedPath = (_d = this.protocolV2ExpectedPath) === null || _d === void 0 ? void 0 : _d.trim();
|
|
54272
|
-
const reconnectDescriptor = devicesDescriptor.find(descriptor => {
|
|
54273
|
-
var _a;
|
|
54274
|
-
const descriptorPath = (_a = descriptor.path) === null || _a === void 0 ? void 0 : _a.trim();
|
|
54275
|
-
return ((!!expectedSerialNumber && descriptorPath === expectedSerialNumber) ||
|
|
54276
|
-
(!!expectedPath && descriptorPath === expectedPath));
|
|
54277
|
-
});
|
|
54278
|
-
if (!(reconnectDescriptor === null || reconnectDescriptor === void 0 ? void 0 : reconnectDescriptor.path)) {
|
|
54279
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
|
|
54280
|
-
}
|
|
54281
|
-
this.device.updateDescriptor(Object.assign(Object.assign({}, reconnectDescriptor), { protocolType: PROTOCOL_V2_CONNECT_PROTOCOL }), true);
|
|
54282
|
-
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));
|
|
54283
|
-
this.device.mainId = typeof mainId === 'string' ? mainId : reconnectDescriptor.path;
|
|
54284
|
-
this.device.commands.disposed = false;
|
|
54285
|
-
this.device.getCommands().mainId = this.device.mainId;
|
|
54286
|
-
return;
|
|
54287
|
-
}
|
|
54288
|
-
if (isWebUsb && devicesDescriptor.length === 1) {
|
|
53624
|
+
if (DataManager.isBrowserWebUsb(DataManager.getSettings('env')) &&
|
|
53625
|
+
devicesDescriptor.length === 1) {
|
|
54289
53626
|
const descriptor = devicesDescriptor[0];
|
|
54290
53627
|
if (!this.protocolV2ExpectedSerialNumber && descriptor.path !== this.protocolV2ExpectedPath) {
|
|
54291
53628
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
|
|
@@ -54293,14 +53630,14 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54293
53630
|
this.device.updateDescriptor(Object.assign(Object.assign({}, descriptor), { protocolType: PROTOCOL_V2_CONNECT_PROTOCOL }), true);
|
|
54294
53631
|
yield this.ensureProtocolV2DeviceAcquired();
|
|
54295
53632
|
this.device.commands.disposed = false;
|
|
54296
|
-
this.device.getCommands().mainId = (
|
|
53633
|
+
this.device.getCommands().mainId = (_c = this.device.mainId) !== null && _c !== void 0 ? _c : '';
|
|
54297
53634
|
return;
|
|
54298
53635
|
}
|
|
54299
53636
|
const { deviceList } = yield DevicePool.getDevices(devicesDescriptor, undefined, {
|
|
54300
53637
|
connectProtocol: PROTOCOL_V2_CONNECT_PROTOCOL,
|
|
54301
53638
|
});
|
|
54302
|
-
const expectedSerialNumber = (
|
|
54303
|
-
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();
|
|
54304
53641
|
const reconnectDevice = deviceList.find(candidate => {
|
|
54305
53642
|
var _a;
|
|
54306
53643
|
const candidateSerialNumber = (_a = candidate.getCurrentSerialNo) === null || _a === void 0 ? void 0 : _a.call(candidate).trim();
|
|
@@ -54312,11 +53649,11 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54312
53649
|
if (!reconnectDevice) {
|
|
54313
53650
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
|
|
54314
53651
|
}
|
|
54315
|
-
Log$
|
|
53652
|
+
Log$7.debug('Protocol V2 firmware reconnect using matched device:', reconnectDevice.getConnectId());
|
|
54316
53653
|
this.device.updateFromCache(reconnectDevice);
|
|
54317
53654
|
yield this.ensureProtocolV2DeviceAcquired();
|
|
54318
53655
|
this.device.commands.disposed = false;
|
|
54319
|
-
this.device.getCommands().mainId = (
|
|
53656
|
+
this.device.getCommands().mainId = (_f = this.device.mainId) !== null && _f !== void 0 ? _f : '';
|
|
54320
53657
|
});
|
|
54321
53658
|
}
|
|
54322
53659
|
ensureProtocolV2DeviceAcquired() {
|
|
@@ -54353,8 +53690,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54353
53690
|
});
|
|
54354
53691
|
if (writeRes.type !== 'FilesystemFile') {
|
|
54355
53692
|
if (writeRes.type === 'CallMethodError') {
|
|
54356
|
-
if (((_a = writeRes.message.error) !== null && _a !== void 0 ? _a : '').indexOf(SESSION_ERROR) > -1) {
|
|
54357
|
-
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);
|
|
54358
53695
|
}
|
|
54359
53696
|
}
|
|
54360
53697
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.EmmcFileWriteFirmwareError, 'transfer data error');
|
|
@@ -54374,53 +53711,21 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54374
53711
|
yield hdShared.wait(2000);
|
|
54375
53712
|
});
|
|
54376
53713
|
}
|
|
54377
|
-
acquireProtocolV2BleDevice(
|
|
53714
|
+
acquireProtocolV2BleDevice() {
|
|
53715
|
+
var _a;
|
|
54378
53716
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54379
|
-
|
|
54380
|
-
const expectedId = this.device.originalDescriptor.id;
|
|
54381
|
-
if (!skipProtocolProbe) {
|
|
54382
|
-
yield (connector === null || connector === void 0 ? void 0 : connector.acquire(expectedId, null, true, PROTOCOL_V2_CONNECT_PROTOCOL));
|
|
54383
|
-
return;
|
|
54384
|
-
}
|
|
54385
|
-
yield (connector === null || connector === void 0 ? void 0 : connector.acquire(expectedId, null, true, PROTOCOL_V2_CONNECT_PROTOCOL, undefined, undefined, skipProtocolProbe));
|
|
54386
|
-
this.device.commands.disposed = false;
|
|
54387
|
-
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));
|
|
54388
53718
|
});
|
|
54389
53719
|
}
|
|
54390
53720
|
protocolV2StartFirmwareUpdate({ targets, }) {
|
|
54391
53721
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54392
53722
|
this.protocolV2LastRuntimeProbeFeatures = undefined;
|
|
54393
|
-
this.protocolV2InstallNeedsReconnect = false;
|
|
54394
|
-
this.protocolV2InstallDisconnectObserved = false;
|
|
54395
|
-
this.protocolV2InstallTerminalSuccessObserved = false;
|
|
54396
53723
|
const commands = this.device.getCommands();
|
|
54397
53724
|
yield commands.typedCall('DeviceFirmwareUpdateStage', 'Success', { targets });
|
|
54398
|
-
this.device.setCancelableAction(() =>
|
|
53725
|
+
this.device.setCancelableAction(() => commands.cancelDevice());
|
|
54399
53726
|
const interaction = this.device.createProtocolV2UiPhaseMetadata('button', 'start');
|
|
54400
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 } : {}))));
|
|
54401
|
-
|
|
54402
|
-
yield commands.call('DeviceFirmwareUpdateRequest', {}, {
|
|
54403
|
-
returnAfterWrite: true,
|
|
54404
|
-
expectedTypes: ['Success'],
|
|
54405
|
-
onResponseAfterWrite: response => {
|
|
54406
|
-
if (response.type !== 'Success')
|
|
54407
|
-
return;
|
|
54408
|
-
this.protocolV2InstallTerminalSuccessObserved = true;
|
|
54409
|
-
this.device.clearCancelableAction();
|
|
54410
|
-
Log$6.log('[FirmwareUpdateV4] firmware install completed by device response');
|
|
54411
|
-
},
|
|
54412
|
-
});
|
|
54413
|
-
Log$6.log('[FirmwareUpdateV4] firmware install request written; continue with status polling');
|
|
54414
|
-
}
|
|
54415
|
-
catch (error) {
|
|
54416
|
-
this.throwIfAborted();
|
|
54417
|
-
if (!isProtocolV2DeviceDisconnectedError(error)) {
|
|
54418
|
-
throw error;
|
|
54419
|
-
}
|
|
54420
|
-
Log$6.log('[FirmwareUpdateV4] transport released while writing install request; continue status polling');
|
|
54421
|
-
this.protocolV2InstallNeedsReconnect = true;
|
|
54422
|
-
this.protocolV2InstallDisconnectObserved = !isProtocolV2InstallResponseTimeout(error);
|
|
54423
|
-
}
|
|
53728
|
+
yield commands.call('DeviceFirmwareUpdateRequest', {}, { returnAfterWrite: true });
|
|
54424
53729
|
});
|
|
54425
53730
|
}
|
|
54426
53731
|
protocolV2Reboot(rebootType) {
|
|
@@ -54429,14 +53734,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54429
53734
|
try {
|
|
54430
53735
|
const res = yield typedCall('DeviceReboot', 'Success', {
|
|
54431
53736
|
reboot_type: rebootType,
|
|
54432
|
-
}
|
|
53737
|
+
});
|
|
54433
53738
|
this.device.markProtocolV2Reboot(rebootType);
|
|
54434
53739
|
return res.message;
|
|
54435
53740
|
}
|
|
54436
53741
|
catch (error) {
|
|
54437
|
-
if (isProtocolV2DeviceDisconnectedError(error) ||
|
|
54438
|
-
isProtocolV2ReconnectProbeError(error) ||
|
|
54439
|
-
isProtocolV2ResponseTimeout(error)) {
|
|
53742
|
+
if (isProtocolV2DeviceDisconnectedError(error) || isProtocolV2ReconnectProbeError(error)) {
|
|
54440
53743
|
this.device.markProtocolV2Reboot(rebootType);
|
|
54441
53744
|
return { message: 'Device rebooted successfully' };
|
|
54442
53745
|
}
|
|
@@ -54452,7 +53755,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54452
53755
|
}
|
|
54453
53756
|
}
|
|
54454
53757
|
|
|
54455
|
-
const Log$
|
|
53758
|
+
const Log$6 = getLogger(exports.LoggerNames.Method);
|
|
54456
53759
|
class PromptWebDeviceAccess extends BaseMethod {
|
|
54457
53760
|
init() {
|
|
54458
53761
|
this.useDevice = false;
|
|
@@ -54507,7 +53810,7 @@ class PromptWebDeviceAccess extends BaseMethod {
|
|
|
54507
53810
|
return { device: null };
|
|
54508
53811
|
}
|
|
54509
53812
|
catch (error) {
|
|
54510
|
-
Log$
|
|
53813
|
+
Log$6.debug(error);
|
|
54511
53814
|
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Please select the device to connect'));
|
|
54512
53815
|
}
|
|
54513
53816
|
});
|
|
@@ -54612,234 +53915,281 @@ function decodeJpegBase64ToRgba({ jpegBase64, parameterName, expectedWidth, expe
|
|
|
54612
53915
|
return decoded;
|
|
54613
53916
|
}
|
|
54614
53917
|
|
|
54615
|
-
const
|
|
54616
|
-
const
|
|
54617
|
-
const
|
|
54618
|
-
const
|
|
54619
|
-
const
|
|
54620
|
-
|
|
54621
|
-
|
|
54622
|
-
const CONTAINER_RESOURCE_TYPE_MAGIC = 0x43534552;
|
|
54623
|
-
const CONTAINER_ED25519_SIGNATURE_ALGORITHM = 0x71717171;
|
|
54624
|
-
const HOST_ASSET_PACKAGE_MAX_SIZE = 4 * 1024 * 1024;
|
|
54625
|
-
const ARCHIVE_MAGIC = 0x52414b4f;
|
|
54626
|
-
const ARCHIVE_VERSION = 1;
|
|
54627
|
-
const ARCHIVE_HEADER_SIZE = 42;
|
|
54628
|
-
const ARCHIVE_ENTRY_SIZE = 296;
|
|
54629
|
-
const ARCHIVE_ENTRY_NAME_MAX_LENGTH = 255;
|
|
54630
|
-
const ARCHIVE_COMPRESS_LZ4_BLOCKED = 1;
|
|
54631
|
-
const ARCHIVE_ALIGNMENT = 4;
|
|
54632
|
-
const LZ4_BLOCK_SIZE_LOG2 = 12;
|
|
54633
|
-
function supportsPro2HostAssetPackage(firmwareVersion) {
|
|
54634
|
-
return Boolean(firmwareVersion &&
|
|
54635
|
-
semver__default["default"].valid(firmwareVersion) &&
|
|
54636
|
-
semver__default["default"].gte(firmwareVersion, PRO2_HOST_ASSET_PACKAGE_MIN_VERSION));
|
|
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);
|
|
54637
53925
|
}
|
|
54638
|
-
function
|
|
54639
|
-
|
|
54640
|
-
|
|
54641
|
-
|
|
54642
|
-
output.set(part, offset);
|
|
54643
|
-
offset += part.byteLength;
|
|
54644
|
-
}
|
|
54645
|
-
return output;
|
|
53926
|
+
function getAverageFileTransferRate(transferredBytes, elapsedMs) {
|
|
53927
|
+
if (elapsedMs <= 0)
|
|
53928
|
+
return 0;
|
|
53929
|
+
return Math.round((Math.max(transferredBytes, 0) / elapsedMs) * 1000);
|
|
54646
53930
|
}
|
|
54647
|
-
|
|
54648
|
-
const
|
|
54649
|
-
|
|
54650
|
-
const LZ4_MAX_OFFSET = 0xffff;
|
|
54651
|
-
const LZ4_LENGTH_MASK = 15;
|
|
54652
|
-
const LZ4_HASH_LOG = 16;
|
|
54653
|
-
const LZ4_HASH_MULTIPLIER = 2654435761;
|
|
54654
|
-
const LZ4_SKIP_TRIGGER = 6;
|
|
54655
|
-
function writeExtendedLength(output, offset, length) {
|
|
54656
|
-
let remaining = length;
|
|
54657
|
-
let nextOffset = offset;
|
|
54658
|
-
while (remaining >= 255) {
|
|
54659
|
-
output[nextOffset] = 255;
|
|
54660
|
-
nextOffset += 1;
|
|
54661
|
-
remaining -= 255;
|
|
54662
|
-
}
|
|
54663
|
-
output[nextOffset] = remaining;
|
|
54664
|
-
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');
|
|
54665
53934
|
}
|
|
54666
|
-
function
|
|
54667
|
-
|
|
54668
|
-
|
|
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}`);
|
|
54669
53940
|
}
|
|
54670
|
-
function
|
|
54671
|
-
|
|
54672
|
-
|
|
54673
|
-
|
|
54674
|
-
|
|
54675
|
-
|
|
54676
|
-
|
|
54677
|
-
|
|
54678
|
-
|
|
54679
|
-
token = literalLength << 4;
|
|
54680
|
-
}
|
|
54681
|
-
nextOffset = copyBytes(output, nextOffset, input, anchor, literalLength);
|
|
54682
|
-
output[nextOffset] = matchOffset & 0xff;
|
|
54683
|
-
output[nextOffset + 1] = (matchOffset >>> 8) & 0xff;
|
|
54684
|
-
nextOffset += 2;
|
|
54685
|
-
if (matchLengthCode >= LZ4_LENGTH_MASK) {
|
|
54686
|
-
token |= LZ4_LENGTH_MASK;
|
|
54687
|
-
nextOffset = writeExtendedLength(output, nextOffset, matchLengthCode - LZ4_LENGTH_MASK);
|
|
54688
|
-
}
|
|
54689
|
-
else {
|
|
54690
|
-
token |= matchLengthCode;
|
|
54691
|
-
}
|
|
54692
|
-
output[tokenOffset] = token;
|
|
54693
|
-
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 : ''));
|
|
54694
53950
|
}
|
|
54695
|
-
function
|
|
54696
|
-
const
|
|
54697
|
-
|
|
54698
|
-
|
|
54699
|
-
|
|
54700
|
-
nextOffset = writeExtendedLength(output, nextOffset, literalLength - LZ4_LENGTH_MASK);
|
|
54701
|
-
}
|
|
54702
|
-
else {
|
|
54703
|
-
output[tokenOffset] = literalLength << 4;
|
|
54704
|
-
}
|
|
54705
|
-
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;
|
|
54706
53956
|
}
|
|
54707
|
-
function
|
|
54708
|
-
|
|
54709
|
-
|
|
54710
|
-
|
|
54711
|
-
|
|
54712
|
-
|
|
54713
|
-
|
|
54714
|
-
|
|
54715
|
-
let searchMatchCount = 1 << LZ4_SKIP_TRIGGER;
|
|
54716
|
-
hashTable.fill(0);
|
|
54717
|
-
while (inputOffset < matchFindLimit) {
|
|
54718
|
-
const sequence = inputView.getUint32(inputOffset, true);
|
|
54719
|
-
const hash = Math.imul(sequence, LZ4_HASH_MULTIPLIER) >>> (32 - LZ4_HASH_LOG);
|
|
54720
|
-
const candidate = hashTable[hash] - 1;
|
|
54721
|
-
hashTable[hash] = inputOffset + 1;
|
|
54722
|
-
const hasMatch = !(candidate < 0 ||
|
|
54723
|
-
inputOffset - candidate > LZ4_MAX_OFFSET ||
|
|
54724
|
-
inputView.getUint32(candidate, true) !== sequence);
|
|
54725
|
-
if (!hasMatch) {
|
|
54726
|
-
inputOffset += searchMatchCount >> LZ4_SKIP_TRIGGER;
|
|
54727
|
-
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);
|
|
54728
53965
|
}
|
|
54729
|
-
|
|
54730
|
-
|
|
54731
|
-
let matchEnd = inputOffset + LZ4_MIN_MATCH;
|
|
54732
|
-
let reference = candidate + LZ4_MIN_MATCH;
|
|
54733
|
-
while (matchEnd < matchExtendLimit && input[matchEnd] === input[reference]) {
|
|
54734
|
-
matchEnd += 1;
|
|
54735
|
-
reference += 1;
|
|
54736
|
-
}
|
|
54737
|
-
outputOffset = emitSequence(output, outputOffset, input, anchor, inputOffset - anchor, inputOffset - candidate, matchEnd - inputOffset - LZ4_MIN_MATCH);
|
|
54738
|
-
inputOffset = matchEnd;
|
|
54739
|
-
anchor = inputOffset;
|
|
53966
|
+
if (typeof Blob !== 'undefined' && data instanceof Blob) {
|
|
53967
|
+
return new Uint8Array(yield data.arrayBuffer());
|
|
54740
53968
|
}
|
|
54741
|
-
|
|
54742
|
-
|
|
54743
|
-
|
|
53969
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Unsupported FilesystemFileWrite data');
|
|
53970
|
+
});
|
|
53971
|
+
}
|
|
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);
|
|
54744
53977
|
}
|
|
54745
|
-
function
|
|
54746
|
-
|
|
54747
|
-
|
|
54748
|
-
|
|
54749
|
-
|
|
54750
|
-
|
|
54751
|
-
|
|
54752
|
-
|
|
54753
|
-
headerView.setUint16(2, LZ4_BLOCK_SIZE_LOG2, true);
|
|
54754
|
-
for (let index = 0; index < blockCount; index += 1) {
|
|
54755
|
-
const block = compressRawLz4Block(data.subarray(index * blockSize, Math.min((index + 1) * blockSize, data.byteLength)), hashTable);
|
|
54756
|
-
headerView.setUint32(8 + index * 4, block.byteLength, true);
|
|
54757
|
-
blocks.push(block);
|
|
54758
|
-
}
|
|
54759
|
-
return concatBytes([header, ...blocks]);
|
|
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);
|
|
54760
53986
|
}
|
|
54761
|
-
|
|
54762
|
-
|
|
54763
|
-
|
|
54764
|
-
|
|
54765
|
-
|
|
54766
|
-
value = value & 1 ? 0xedb88320 ^ (value >>> 1) : value >>> 1;
|
|
54767
|
-
}
|
|
54768
|
-
table[index] = value >>> 0;
|
|
54769
|
-
}
|
|
54770
|
-
return table;
|
|
54771
|
-
})();
|
|
54772
|
-
function crc32(data) {
|
|
54773
|
-
let value = 0xffffffff;
|
|
54774
|
-
for (const byte of data) {
|
|
54775
|
-
value = CRC32_TABLE[(value ^ byte) & 0xff] ^ (value >>> 8);
|
|
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);
|
|
54776
53992
|
}
|
|
54777
|
-
|
|
54778
|
-
|
|
54779
|
-
|
|
54780
|
-
return (value + ARCHIVE_ALIGNMENT - 1) & ~(ARCHIVE_ALIGNMENT - 1);
|
|
53993
|
+
if (length > 0)
|
|
53994
|
+
return written >= length ? 100 : Math.floor((written / length) * 100);
|
|
53995
|
+
return 100;
|
|
54781
53996
|
}
|
|
54782
|
-
function
|
|
54783
|
-
|
|
54784
|
-
|
|
54785
|
-
|
|
54786
|
-
const
|
|
54787
|
-
|
|
54788
|
-
|
|
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}`);
|
|
54789
54009
|
}
|
|
54790
|
-
|
|
54791
|
-
|
|
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
|
+
}
|
|
54792
54153
|
}
|
|
54793
|
-
|
|
54794
|
-
|
|
54795
|
-
|
|
54796
|
-
|
|
54797
|
-
|
|
54798
|
-
|
|
54799
|
-
|
|
54800
|
-
|
|
54801
|
-
|
|
54802
|
-
|
|
54803
|
-
|
|
54804
|
-
|
|
54805
|
-
|
|
54806
|
-
|
|
54807
|
-
|
|
54808
|
-
|
|
54809
|
-
|
|
54810
|
-
|
|
54811
|
-
|
|
54812
|
-
|
|
54813
|
-
|
|
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 });
|
|
54814
54189
|
});
|
|
54815
|
-
return archive;
|
|
54816
|
-
}
|
|
54817
|
-
function buildPro2HostAssetPackage(entries) {
|
|
54818
|
-
if (entries.length === 0 || new Set(entries.map(entry => entry.name)).size !== entries.length) {
|
|
54819
|
-
throw new Error('Pro2 host asset package entries must have unique, non-empty names.');
|
|
54820
|
-
}
|
|
54821
|
-
const payload = buildArchive(entries);
|
|
54822
|
-
const header = new Uint8Array(CONTAINER_HEADER_SIZE);
|
|
54823
|
-
const view = new DataView(header.buffer);
|
|
54824
|
-
view.setUint32(0, CONTAINER_HEADER_MAGIC, true);
|
|
54825
|
-
view.setUint32(4, CONTAINER_HEADER_VERSION, true);
|
|
54826
|
-
view.setUint32(8, CONTAINER_RESOURCE_TYPE_MAGIC, true);
|
|
54827
|
-
view.setUint32(0x0c, CONTAINER_HEADER_SIZE, true);
|
|
54828
|
-
view.setUint32(0x10, 1, true);
|
|
54829
|
-
view.setUint32(0x14, payload.byteLength, true);
|
|
54830
|
-
header.set(sha3.sha3_512(payload), CONTAINER_HASH_SECTION_OFFSET);
|
|
54831
|
-
header.set(sha3.sha3_512(header.subarray(0, CONTAINER_HEADER_HASH_INPUT_LENGTH)), 0x240);
|
|
54832
|
-
view.setUint32(CONTAINER_SIGNATURE_ALGORITHM_OFFSET, CONTAINER_ED25519_SIGNATURE_ALGORITHM, true);
|
|
54833
|
-
const packageData = concatBytes([header, payload]);
|
|
54834
|
-
if (packageData.byteLength > HOST_ASSET_PACKAGE_MAX_SIZE) {
|
|
54835
|
-
throw new Error('Pro2 host asset package exceeds the firmware 4 MiB limit.');
|
|
54836
|
-
}
|
|
54837
|
-
return packageData;
|
|
54838
54190
|
}
|
|
54839
54191
|
|
|
54840
54192
|
const WALLPAPER_DIRECTORY = 'vol1:/wallpapers';
|
|
54841
|
-
const WALLPAPER_PACKAGE_PATH = `${WALLPAPER_DIRECTORY}/wallpaper.okpkg`;
|
|
54842
|
-
const WALLPAPER_PACKAGE_ENTRY = 'wallpaper.bin';
|
|
54843
54193
|
const SAFE_FILE_NAME = /^[A-Za-z0-9_-]+(?:\.bin)?$/;
|
|
54844
54194
|
const DEVICE_SETTINGS_SET_MESSAGE_TYPE = 60412;
|
|
54845
54195
|
const FILESYSTEM_FILE_WRITE_MESSAGE_TYPE$2 = 60805;
|
|
@@ -54915,15 +54265,18 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
54915
54265
|
this.directoryReady = true;
|
|
54916
54266
|
});
|
|
54917
54267
|
}
|
|
54918
|
-
upload(
|
|
54268
|
+
upload() {
|
|
54919
54269
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54920
54270
|
if (this.uploaded)
|
|
54921
54271
|
return;
|
|
54272
|
+
const { encoded } = this;
|
|
54273
|
+
if (!encoded)
|
|
54274
|
+
throw invalidParameter$1('Wallpaper data has not been initialized.');
|
|
54922
54275
|
yield writeProtocolV2File({
|
|
54923
54276
|
commands: this.device.commands,
|
|
54924
|
-
path,
|
|
54925
|
-
data,
|
|
54926
|
-
totalSize: data.byteLength,
|
|
54277
|
+
path: this.path,
|
|
54278
|
+
data: encoded.data,
|
|
54279
|
+
totalSize: encoded.data.byteLength,
|
|
54927
54280
|
chunkSize: this.params.chunkSize,
|
|
54928
54281
|
maxChunkRetries: 3,
|
|
54929
54282
|
overwrite: true,
|
|
@@ -54939,20 +54292,14 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
54939
54292
|
});
|
|
54940
54293
|
}
|
|
54941
54294
|
run() {
|
|
54942
|
-
var _a
|
|
54295
|
+
var _a;
|
|
54943
54296
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54944
54297
|
const { encoded } = this;
|
|
54945
54298
|
if (!encoded)
|
|
54946
54299
|
throw invalidParameter$1('Wallpaper data has not been initialized.');
|
|
54947
54300
|
yield this.assertCapabilities();
|
|
54948
54301
|
yield this.ensureDirectory();
|
|
54949
|
-
|
|
54950
|
-
const data = useHostAssetPackage
|
|
54951
|
-
? buildPro2HostAssetPackage([{ name: WALLPAPER_PACKAGE_ENTRY, data: encoded.data }])
|
|
54952
|
-
: encoded.data;
|
|
54953
|
-
if (useHostAssetPackage)
|
|
54954
|
-
this.path = WALLPAPER_PACKAGE_PATH;
|
|
54955
|
-
yield this.upload(this.path, data);
|
|
54302
|
+
yield this.upload();
|
|
54956
54303
|
const response = yield this.device.commands.typedCall('DeviceSettingsSet', 'Success', {
|
|
54957
54304
|
settings: { wallpaper_path: this.path },
|
|
54958
54305
|
});
|
|
@@ -54966,9 +54313,9 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
54966
54313
|
}
|
|
54967
54314
|
return {
|
|
54968
54315
|
path: this.path,
|
|
54969
|
-
size: data.byteLength,
|
|
54316
|
+
size: encoded.data.byteLength,
|
|
54970
54317
|
colorFormat: encoded.colorFormat,
|
|
54971
|
-
message: (
|
|
54318
|
+
message: (_a = response.message) === null || _a === void 0 ? void 0 : _a.message,
|
|
54972
54319
|
};
|
|
54973
54320
|
});
|
|
54974
54321
|
}
|
|
@@ -55045,14 +54392,14 @@ class DeviceUploadNft extends BaseMethod {
|
|
|
55045
54392
|
this.skipForceUpdateCheck = true;
|
|
55046
54393
|
this.useDevicePassphraseState = false;
|
|
55047
54394
|
}
|
|
55048
|
-
assertCapabilities(
|
|
54395
|
+
assertCapabilities() {
|
|
55049
54396
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55050
54397
|
const protocolInfo = yield this.device.ensureProtocolV2RuntimeContext();
|
|
55051
54398
|
const hasFileWrite = supportsProtocolV2Message(protocolInfo, FILESYSTEM_FILE_WRITE_MESSAGE_TYPE$1);
|
|
55052
54399
|
const hasPathInfo = supportsProtocolV2Message(protocolInfo, FILESYSTEM_PATH_INFO_QUERY_MESSAGE_TYPE);
|
|
55053
54400
|
const hasDirList = supportsProtocolV2Message(protocolInfo, FILESYSTEM_DIR_LIST_MESSAGE_TYPE);
|
|
55054
54401
|
const hasNftUpdate = supportsProtocolV2Message(protocolInfo, NFT_UPDATE_MESSAGE_TYPE);
|
|
55055
|
-
if (!hasFileWrite || !
|
|
54402
|
+
if (!hasFileWrite || !hasPathInfo || !hasDirList || !hasNftUpdate) {
|
|
55056
54403
|
throw hdShared.createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
|
|
55057
54404
|
}
|
|
55058
54405
|
});
|
|
@@ -55078,33 +54425,20 @@ class DeviceUploadNft extends BaseMethod {
|
|
|
55078
54425
|
});
|
|
55079
54426
|
}
|
|
55080
54427
|
run() {
|
|
55081
|
-
var _a
|
|
54428
|
+
var _a;
|
|
55082
54429
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55083
54430
|
const { bundle } = this;
|
|
55084
54431
|
if (!bundle)
|
|
55085
54432
|
throw invalidParameter$1('NFT data has not been initialized.');
|
|
55086
|
-
|
|
55087
|
-
yield this.assertCapabilities(useHostAssetPackage);
|
|
54433
|
+
yield this.assertCapabilities();
|
|
55088
54434
|
this.throwIfAborted();
|
|
55089
|
-
|
|
55090
|
-
yield this.assertStorageCapacity(bundle.basename);
|
|
54435
|
+
yield this.assertStorageCapacity(bundle.basename);
|
|
55091
54436
|
this.throwIfAborted();
|
|
55092
|
-
const
|
|
54437
|
+
const files = [
|
|
55093
54438
|
{ path: `${PRO2_NFT_DIRECTORY}/${bundle.basename}.bin`, data: bundle.image },
|
|
55094
54439
|
{ path: `${PRO2_NFT_DIRECTORY}/${bundle.basename}_m.bin`, data: bundle.thumbnail },
|
|
55095
54440
|
{ path: `${PRO2_NFT_DIRECTORY}/${bundle.basename}.json`, data: bundle.metadata },
|
|
55096
54441
|
];
|
|
55097
|
-
const files = useHostAssetPackage
|
|
55098
|
-
? [
|
|
55099
|
-
{
|
|
55100
|
-
path: `${PRO2_NFT_DIRECTORY}/${bundle.basename}.okpkg`,
|
|
55101
|
-
data: buildPro2HostAssetPackage(extractedFiles.map(file => ({
|
|
55102
|
-
name: file.path.slice(`${PRO2_NFT_DIRECTORY}/`.length),
|
|
55103
|
-
data: file.data,
|
|
55104
|
-
}))),
|
|
55105
|
-
},
|
|
55106
|
-
]
|
|
55107
|
-
: extractedFiles;
|
|
55108
54442
|
const totalSize = files.reduce((sum, file) => sum + file.data.byteLength, 0);
|
|
55109
54443
|
let transferredBeforeFile = 0;
|
|
55110
54444
|
for (const file of files) {
|
|
@@ -55133,12 +54467,12 @@ class DeviceUploadNft extends BaseMethod {
|
|
|
55133
54467
|
const response = yield this.updateNft(bundle.basename);
|
|
55134
54468
|
return {
|
|
55135
54469
|
basename: bundle.basename,
|
|
55136
|
-
imagePath:
|
|
55137
|
-
thumbnailPath:
|
|
55138
|
-
metadataPath:
|
|
54470
|
+
imagePath: files[0].path,
|
|
54471
|
+
thumbnailPath: files[1].path,
|
|
54472
|
+
metadataPath: files[2].path,
|
|
55139
54473
|
totalSize,
|
|
55140
54474
|
nftUpdated: true,
|
|
55141
|
-
message: (
|
|
54475
|
+
message: (_a = response.message) === null || _a === void 0 ? void 0 : _a.message,
|
|
55142
54476
|
};
|
|
55143
54477
|
});
|
|
55144
54478
|
}
|
|
@@ -55414,8 +54748,6 @@ class ProtocolV2UiInteractionCoordinator {
|
|
|
55414
54748
|
const Log$3 = getLogger(exports.LoggerNames.Core);
|
|
55415
54749
|
const createProtocolV2UnlockContext = () => ({
|
|
55416
54750
|
preflightCompleted: false,
|
|
55417
|
-
preflightStatusRefreshed: false,
|
|
55418
|
-
preflightMainPinSelected: false,
|
|
55419
54751
|
});
|
|
55420
54752
|
const resolvePreUnlockPinType = (method) => {
|
|
55421
54753
|
var _a, _b;
|
|
@@ -55448,11 +54780,10 @@ function runMethodWithUnlockPolicy(method, device, options = {}) {
|
|
|
55448
54780
|
}
|
|
55449
54781
|
yield (afterStatusBeforeUnlock === null || afterStatusBeforeUnlock === void 0 ? void 0 : afterStatusBeforeUnlock());
|
|
55450
54782
|
if (!status.unlocked) {
|
|
55451
|
-
const preUnlockPinType = resolvePreUnlockPinType(method);
|
|
55452
54783
|
const unlockInteraction = shouldCoordinateUi
|
|
55453
54784
|
? uiCoordinator.enterUnlockInteraction(method.name)
|
|
55454
54785
|
: undefined;
|
|
55455
|
-
const unlockedStatus = yield device.unlockDevice(
|
|
54786
|
+
const unlockedStatus = yield device.unlockDevice(resolvePreUnlockPinType(method), shouldCoordinateUi
|
|
55456
54787
|
? { emitUiEvent: false, interaction: unlockInteraction }
|
|
55457
54788
|
: {
|
|
55458
54789
|
source: 'unlock-coordinator',
|
|
@@ -55463,10 +54794,8 @@ function runMethodWithUnlockPolicy(method, device, options = {}) {
|
|
|
55463
54794
|
if ((unlockedStatus === null || unlockedStatus === void 0 ? void 0 : unlockedStatus.unlocked) !== true) {
|
|
55464
54795
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 device remained locked after the unlock flow.');
|
|
55465
54796
|
}
|
|
55466
|
-
context.preflightMainPinSelected = preUnlockPinType === hdTransport.DeviceSessionPinType.Main;
|
|
55467
54797
|
Log$3.debug('Protocol V2 pre-unlock completed', { method: method.name });
|
|
55468
54798
|
}
|
|
55469
|
-
context.preflightStatusRefreshed = true;
|
|
55470
54799
|
context.preflightCompleted = true;
|
|
55471
54800
|
}
|
|
55472
54801
|
yield (prepare === null || prepare === void 0 ? void 0 : prepare());
|
|
@@ -55755,7 +55084,6 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
55755
55084
|
const response = yield runMethodWithUnlockPolicy(method, this.device, {
|
|
55756
55085
|
context: this.protocolV2UnlockContext,
|
|
55757
55086
|
prepare: () => __awaiter(this, void 0, void 0, function* () {
|
|
55758
|
-
var _d;
|
|
55759
55087
|
if (this.temporarySafetyCheckPrompted) {
|
|
55760
55088
|
method.temporarySafetyCheckPrompted = true;
|
|
55761
55089
|
}
|
|
@@ -55769,7 +55097,7 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
55769
55097
|
const deriveCardano = method.name.startsWith('cardano');
|
|
55770
55098
|
const shouldResumeWalletSession = useEmptyPassphrase || !!this.payload.passphraseState;
|
|
55771
55099
|
if (this.device.isProtocolV2() && shouldResumeWalletSession) {
|
|
55772
|
-
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);
|
|
55773
55101
|
if (!passphraseStateSafety) {
|
|
55774
55102
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
55775
55103
|
}
|
|
@@ -58430,7 +57758,6 @@ class EVMSignTypedData extends BaseMethod {
|
|
|
58430
57758
|
const currentDeviceType = this.device.getCurrentDeviceType();
|
|
58431
57759
|
const supportBiggerDataVersion = '4.4.0';
|
|
58432
57760
|
const supportBiggerData = DeviceModelToTypes.model_classic1s.includes(currentDeviceType) ||
|
|
58433
|
-
DeviceModelToTypes.model_pro2.includes(currentDeviceType) ||
|
|
58434
57761
|
(DeviceModelToTypes.model_touch.includes(currentDeviceType) &&
|
|
58435
57762
|
semver__default["default"].gte(currentVersion, supportBiggerDataVersion));
|
|
58436
57763
|
if (supportBiggerData) {
|
|
@@ -65211,7 +64538,7 @@ class DeviceConnector {
|
|
|
65211
64538
|
stop() {
|
|
65212
64539
|
this.listening = false;
|
|
65213
64540
|
}
|
|
65214
|
-
acquire(path, session, forceCleanRunPromise, expectedProtocol, protocolHint, forceProtocolDetection
|
|
64541
|
+
acquire(path, session, forceCleanRunPromise, expectedProtocol, protocolHint, forceProtocolDetection) {
|
|
65215
64542
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65216
64543
|
Log$2.debug('acquire', path, session, expectedProtocol, protocolHint);
|
|
65217
64544
|
const env = DataManager.getSettings('env');
|
|
@@ -65219,15 +64546,13 @@ class DeviceConnector {
|
|
|
65219
64546
|
const transport = this.getActiveTransport();
|
|
65220
64547
|
let res;
|
|
65221
64548
|
if (DataManager.isBleConnect(env)) {
|
|
65222
|
-
|
|
64549
|
+
res = yield transport.acquire({
|
|
65223
64550
|
uuid: path,
|
|
65224
64551
|
forceCleanRunPromise,
|
|
65225
64552
|
expectedProtocol,
|
|
65226
64553
|
protocolHint,
|
|
65227
64554
|
forceProtocolDetection,
|
|
65228
|
-
|
|
65229
|
-
};
|
|
65230
|
-
res = yield transport.acquire(acquireInput);
|
|
64555
|
+
});
|
|
65231
64556
|
}
|
|
65232
64557
|
else {
|
|
65233
64558
|
res = yield transport.acquire({
|
|
@@ -65236,7 +64561,6 @@ class DeviceConnector {
|
|
|
65236
64561
|
expectedProtocol,
|
|
65237
64562
|
protocolHint,
|
|
65238
64563
|
forceProtocolDetection,
|
|
65239
|
-
skipProtocolProbe,
|
|
65240
64564
|
});
|
|
65241
64565
|
}
|
|
65242
64566
|
if (expectedProtocol) {
|
|
@@ -65744,8 +65068,6 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
65744
65068
|
if ((_g = method.payload) === null || _g === void 0 ? void 0 : _g.onlyConnectBleDevice) {
|
|
65745
65069
|
preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
|
|
65746
65070
|
Log.debug('Call API - only connect ble device: ', device === null || device === void 0 ? void 0 : device.mainId);
|
|
65747
|
-
completeMethodRequestContext(method);
|
|
65748
|
-
requestQueue.releaseTask(method.responseID);
|
|
65749
65071
|
return createResponseMessage(method.responseID, true, null);
|
|
65750
65072
|
}
|
|
65751
65073
|
Log.debug('Call API - setDevice: ', device.mainId);
|
|
@@ -65867,7 +65189,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
65867
65189
|
}
|
|
65868
65190
|
},
|
|
65869
65191
|
prepare: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65870
|
-
var _o, _p, _q, _r, _s
|
|
65192
|
+
var _o, _p, _q, _r, _s;
|
|
65871
65193
|
if (method.deviceId && method.checkDeviceId && !deviceIdCheckedDuringUnlockPreflight) {
|
|
65872
65194
|
const isSameDeviceID = yield checkLiveDeviceId(device, method.deviceId);
|
|
65873
65195
|
if (!isSameDeviceID) {
|
|
@@ -65887,7 +65209,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
65887
65209
|
require: support.require,
|
|
65888
65210
|
});
|
|
65889
65211
|
}
|
|
65890
|
-
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));
|
|
65891
65213
|
checkPassphraseEnableState(method, device.features);
|
|
65892
65214
|
if (!passphraseStateSafety) {
|
|
65893
65215
|
DevicePool.clearDeviceCache(method.payload.connectId);
|
|
@@ -65905,7 +65227,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
65905
65227
|
? e
|
|
65906
65228
|
: hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'open safety check failed.');
|
|
65907
65229
|
}
|
|
65908
|
-
(
|
|
65230
|
+
(_s = (_r = method.device) === null || _r === void 0 ? void 0 : _r.commands) === null || _s === void 0 ? void 0 : _s.checkDisposed();
|
|
65909
65231
|
}),
|
|
65910
65232
|
});
|
|
65911
65233
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
@@ -66121,36 +65443,7 @@ function isMissingDetectedProtocolV2Error(method, error) {
|
|
|
66121
65443
|
typeof typedError.message === 'string' &&
|
|
66122
65444
|
typedError.message.includes('Device protocol has not been detected'));
|
|
66123
65445
|
}
|
|
66124
|
-
function
|
|
66125
|
-
return (method.payload.connectProtocol === 'V2' &&
|
|
66126
|
-
(error === null || error === void 0 ? void 0 : error.errorCode) ===
|
|
66127
|
-
hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation);
|
|
66128
|
-
}
|
|
66129
|
-
const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
|
|
66130
|
-
function raceBleAcquire(acquirePromise, abortSignal) {
|
|
66131
|
-
return new Promise((resolve, reject) => {
|
|
66132
|
-
let settled = false;
|
|
66133
|
-
const settle = (fn) => {
|
|
66134
|
-
if (settled)
|
|
66135
|
-
return;
|
|
66136
|
-
settled = true;
|
|
66137
|
-
clearTimeout(deadline);
|
|
66138
|
-
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', onAbort);
|
|
66139
|
-
fn();
|
|
66140
|
-
};
|
|
66141
|
-
const onAbort = () => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled)));
|
|
66142
|
-
const deadline = setTimeout(() => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, `BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline`))), BLE_ACQUIRE_DEADLINE_MS);
|
|
66143
|
-
acquirePromise.then(value => settle(() => resolve(value)), error => settle(() => reject(error)));
|
|
66144
|
-
if (abortSignal) {
|
|
66145
|
-
if (abortSignal.aborted) {
|
|
66146
|
-
onAbort();
|
|
66147
|
-
return;
|
|
66148
|
-
}
|
|
66149
|
-
abortSignal.addEventListener('abort', onAbort);
|
|
66150
|
-
}
|
|
66151
|
-
});
|
|
66152
|
-
}
|
|
66153
|
-
function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
65446
|
+
function connectDeviceForBle(method, device, retryCount = 0) {
|
|
66154
65447
|
var _a;
|
|
66155
65448
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66156
65449
|
try {
|
|
@@ -66165,31 +65458,9 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
|
66165
65458
|
!device.commands ||
|
|
66166
65459
|
device.commands.disposed;
|
|
66167
65460
|
if (shouldAcquire) {
|
|
66168
|
-
|
|
66169
|
-
|
|
66170
|
-
|
|
66171
|
-
}
|
|
66172
|
-
if (!useAcquireGuards) {
|
|
66173
|
-
yield device.acquire(method.payload.connectProtocol, {
|
|
66174
|
-
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
66175
|
-
});
|
|
66176
|
-
}
|
|
66177
|
-
else {
|
|
66178
|
-
try {
|
|
66179
|
-
yield raceBleAcquire(device.acquire(method.payload.connectProtocol, {
|
|
66180
|
-
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
66181
|
-
}), abortSignal);
|
|
66182
|
-
}
|
|
66183
|
-
catch (err) {
|
|
66184
|
-
if (err.errorCode === hdShared.HardwareErrorCode.BleTimeoutError &&
|
|
66185
|
-
device.mainId &&
|
|
66186
|
-
device.deviceConnector) {
|
|
66187
|
-
yield device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
|
|
66188
|
-
device.markTransportDisconnected();
|
|
66189
|
-
}
|
|
66190
|
-
throw err;
|
|
66191
|
-
}
|
|
66192
|
-
}
|
|
65461
|
+
yield device.acquire(method.payload.connectProtocol, {
|
|
65462
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
65463
|
+
});
|
|
66193
65464
|
}
|
|
66194
65465
|
if ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.onlyConnectBleDevice) {
|
|
66195
65466
|
if (shouldAcquire) {
|
|
@@ -66220,7 +65491,7 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
|
66220
65491
|
const nextRetry = retryCount + 1;
|
|
66221
65492
|
Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
|
|
66222
65493
|
yield wait(3000);
|
|
66223
|
-
yield connectDeviceForBle(method, device,
|
|
65494
|
+
yield connectDeviceForBle(method, device, nextRetry);
|
|
66224
65495
|
}
|
|
66225
65496
|
else {
|
|
66226
65497
|
throw err;
|
|
@@ -66237,7 +65508,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66237
65508
|
Log.debug(`EnsureConnected function start, MAX_RETRY_COUNT=${MAX_RETRY_COUNT}, POLL_INTERVAL_TIME=${POLL_INTERVAL_TIME} `);
|
|
66238
65509
|
const poll = (time = POLL_INTERVAL_TIME) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66239
65510
|
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66240
|
-
var
|
|
65511
|
+
var _t;
|
|
66241
65512
|
const abort = () => {
|
|
66242
65513
|
if (abortSignal && abortSignal.aborted) {
|
|
66243
65514
|
if (timer) {
|
|
@@ -66305,7 +65576,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66305
65576
|
if (tryCount === 1) {
|
|
66306
65577
|
device.beginConnectionAttempt();
|
|
66307
65578
|
}
|
|
66308
|
-
yield connectDeviceForBle(method, device
|
|
65579
|
+
yield connectDeviceForBle(method, device);
|
|
66309
65580
|
}
|
|
66310
65581
|
resolve(device);
|
|
66311
65582
|
return;
|
|
@@ -66347,8 +65618,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66347
65618
|
hdShared.HardwareErrorCode.BridgeNeedsPermission,
|
|
66348
65619
|
hdShared.HardwareErrorCode.DeviceInterruptedFromUser,
|
|
66349
65620
|
hdShared.HardwareErrorCode.CallQueueActionCancelled,
|
|
66350
|
-
].includes(error.errorCode)
|
|
66351
|
-
isProtocolV2PeerRemovedPairingError(method, error)) {
|
|
65621
|
+
].includes(error.errorCode)) {
|
|
66352
65622
|
reject(error);
|
|
66353
65623
|
return;
|
|
66354
65624
|
}
|
|
@@ -66358,7 +65628,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
66358
65628
|
clearTimeout(timer);
|
|
66359
65629
|
}
|
|
66360
65630
|
Log.debug('EnsureConnected get to max try count, will return: ', tryCount);
|
|
66361
|
-
if (DataManager.isBrowserWebUsb(env) && !((
|
|
65631
|
+
if (DataManager.isBrowserWebUsb(env) && !((_t = method.payload) === null || _t === void 0 ? void 0 : _t.skipWebDevicePrompt)) {
|
|
66362
65632
|
postMessage(createUiMessage(UI_REQUEST.WEB_DEVICE_PROMPT_ACCESS_PERMISSION));
|
|
66363
65633
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission));
|
|
66364
65634
|
}
|
|
@@ -66383,7 +65653,6 @@ const cancel = (context, connectId) => {
|
|
|
66383
65653
|
requestQueue.cancelCallbackTasks(connectId);
|
|
66384
65654
|
const requestIds = requestQueue.getRequestTasksId();
|
|
66385
65655
|
Log.debug(`Cancel Api connect requestQueues: length:${requestIds.length} requestIds:${requestIds.join(',')}`);
|
|
66386
|
-
requestQueue.abortRequestsByConnectId(connectId);
|
|
66387
65656
|
const canceledDevices = [];
|
|
66388
65657
|
const interruptDevice = (device, deviceConnectId) => {
|
|
66389
65658
|
if (!device || canceledDevices.includes(device)) {
|
|
@@ -66402,6 +65671,7 @@ const cancel = (context, connectId) => {
|
|
|
66402
65671
|
}
|
|
66403
65672
|
}
|
|
66404
65673
|
interruptDevice(deviceCacheMap.get(connectId), connectId);
|
|
65674
|
+
requestQueue.abortRequestsByConnectId(connectId);
|
|
66405
65675
|
pollingManager.stop(connectId);
|
|
66406
65676
|
}
|
|
66407
65677
|
catch (e) {
|
|
@@ -66412,7 +65682,6 @@ const cancel = (context, connectId) => {
|
|
|
66412
65682
|
const env = DataManager.getSettings('env');
|
|
66413
65683
|
if (DataManager.isBleConnect(env)) {
|
|
66414
65684
|
Log.debug('Cancel Api all _deviceList: ');
|
|
66415
|
-
requestQueue.abortAllRequests();
|
|
66416
65685
|
const canceledDevices = [];
|
|
66417
65686
|
const interruptDevice = (device) => {
|
|
66418
65687
|
if (!device || canceledDevices.includes(device)) {
|
|
@@ -66434,6 +65703,7 @@ const cancel = (context, connectId) => {
|
|
|
66434
65703
|
}
|
|
66435
65704
|
}
|
|
66436
65705
|
deviceCacheMap.forEach(interruptDevice);
|
|
65706
|
+
requestQueue.abortAllRequests();
|
|
66437
65707
|
pollingManager.stopAll();
|
|
66438
65708
|
}
|
|
66439
65709
|
else {
|
|
@@ -66471,12 +65741,8 @@ const checkPassphraseEnableState = (method, features) => {
|
|
|
66471
65741
|
}
|
|
66472
65742
|
};
|
|
66473
65743
|
const shouldCheckPassphraseState = (method, device) => {
|
|
66474
|
-
var _a;
|
|
66475
65744
|
if (!method.useDevicePassphraseState)
|
|
66476
65745
|
return false;
|
|
66477
|
-
if (device.isProtocolV2() && ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.useEmptyPassphrase) === true) {
|
|
66478
|
-
return true;
|
|
66479
|
-
}
|
|
66480
65746
|
return device.hasUsePassphrase();
|
|
66481
65747
|
};
|
|
66482
65748
|
const cleanup = () => {
|