@onekeyfe/hd-core 1.2.2-alpha.5 → 1.2.2-alpha.7
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__/device-lifecycle-events.test.ts +14 -0
- package/__tests__/open-wallet-session.test.ts +318 -20
- package/__tests__/pro2HostAssetPackage.test.ts +108 -1
- package/__tests__/protocol-v2.test.ts +130 -20
- package/__tests__/protocolV2FileWrite.test.ts +40 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +1 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +217 -68
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/pro2HostAssetPackage.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +33 -6
- package/src/api/helpers/protocolV2FileWrite.ts +11 -5
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +8 -2
- package/src/core/index.ts +19 -8
- package/src/data/messages/messages-protocol-v2.json +39 -10
- package/src/protocols/protocol-v2/walletSession.ts +95 -15
- package/src/utils/pro2HostAssetPackage.ts +73 -27
package/dist/index.js
CHANGED
|
@@ -39947,36 +39947,57 @@ var nested = {
|
|
|
39947
39947
|
"placeholder"
|
|
39948
39948
|
]
|
|
39949
39949
|
},
|
|
39950
|
-
|
|
39950
|
+
ViewContentPreview: {
|
|
39951
39951
|
fields: {
|
|
39952
|
+
content_key: {
|
|
39953
|
+
rule: "required",
|
|
39954
|
+
type: "uint32",
|
|
39955
|
+
id: 1
|
|
39956
|
+
},
|
|
39952
39957
|
preview: {
|
|
39953
39958
|
rule: "required",
|
|
39954
39959
|
type: "bytes",
|
|
39955
|
-
id:
|
|
39960
|
+
id: 2
|
|
39956
39961
|
},
|
|
39957
39962
|
total_bytes: {
|
|
39958
|
-
rule: "required",
|
|
39959
39963
|
type: "uint32",
|
|
39960
|
-
id:
|
|
39964
|
+
id: 3
|
|
39961
39965
|
}
|
|
39962
39966
|
}
|
|
39963
39967
|
},
|
|
39964
|
-
|
|
39968
|
+
ViewContentEntry: {
|
|
39965
39969
|
fields: {
|
|
39966
|
-
|
|
39970
|
+
entry_key: {
|
|
39967
39971
|
rule: "required",
|
|
39968
|
-
type: "
|
|
39972
|
+
type: "uint32",
|
|
39969
39973
|
id: 1
|
|
39970
39974
|
},
|
|
39975
|
+
value: {
|
|
39976
|
+
rule: "required",
|
|
39977
|
+
type: "bytes",
|
|
39978
|
+
id: 2
|
|
39979
|
+
}
|
|
39980
|
+
}
|
|
39981
|
+
},
|
|
39982
|
+
ViewContentPage: {
|
|
39983
|
+
fields: {
|
|
39971
39984
|
page_index: {
|
|
39972
39985
|
rule: "required",
|
|
39973
39986
|
type: "uint32",
|
|
39974
|
-
id:
|
|
39987
|
+
id: 1
|
|
39975
39988
|
},
|
|
39976
39989
|
page_count: {
|
|
39977
39990
|
rule: "required",
|
|
39978
39991
|
type: "uint32",
|
|
39992
|
+
id: 2
|
|
39993
|
+
},
|
|
39994
|
+
chunk: {
|
|
39995
|
+
type: "bytes",
|
|
39979
39996
|
id: 3
|
|
39997
|
+
},
|
|
39998
|
+
entry: {
|
|
39999
|
+
type: "ViewContentEntry",
|
|
40000
|
+
id: 4
|
|
39980
40001
|
}
|
|
39981
40002
|
}
|
|
39982
40003
|
},
|
|
@@ -40035,8 +40056,8 @@ var nested = {
|
|
|
40035
40056
|
type: "string",
|
|
40036
40057
|
id: 9
|
|
40037
40058
|
},
|
|
40038
|
-
|
|
40039
|
-
type: "
|
|
40059
|
+
content: {
|
|
40060
|
+
type: "ViewContentPreview",
|
|
40040
40061
|
id: 10
|
|
40041
40062
|
},
|
|
40042
40063
|
custom_field: {
|
|
@@ -40060,6 +40081,10 @@ var nested = {
|
|
|
40060
40081
|
text_arg: {
|
|
40061
40082
|
type: "string",
|
|
40062
40083
|
id: 3
|
|
40084
|
+
},
|
|
40085
|
+
cancellable: {
|
|
40086
|
+
type: "bool",
|
|
40087
|
+
id: 4
|
|
40063
40088
|
}
|
|
40064
40089
|
}
|
|
40065
40090
|
},
|
|
@@ -40098,6 +40123,10 @@ var nested = {
|
|
|
40098
40123
|
chain_id: {
|
|
40099
40124
|
type: "uint32",
|
|
40100
40125
|
id: 8
|
|
40126
|
+
},
|
|
40127
|
+
content: {
|
|
40128
|
+
type: "ViewContentPreview",
|
|
40129
|
+
id: 9
|
|
40101
40130
|
}
|
|
40102
40131
|
}
|
|
40103
40132
|
},
|
|
@@ -41818,7 +41847,14 @@ const selectDeviceSession = (device, expectedPassphraseState, deriveCardano, onS
|
|
|
41818
41847
|
interaction: attachPinInteraction,
|
|
41819
41848
|
});
|
|
41820
41849
|
onStatusRefreshed === null || onStatusRefreshed === void 0 ? void 0 : onStatusRefreshed();
|
|
41821
|
-
|
|
41850
|
+
if (deriveCardano === true) {
|
|
41851
|
+
yield askDevicePassphrase(device, { passphrase: '', on_device: false }, true, onStatusRefreshed);
|
|
41852
|
+
if (device.features) {
|
|
41853
|
+
device.features.unlockedAttachPin = true;
|
|
41854
|
+
}
|
|
41855
|
+
}
|
|
41856
|
+
const attachPinSession = yield getDeviceSession(device, buildDeviceSessionGetRequest());
|
|
41857
|
+
return Object.assign(attachPinSession, { viaAttachPin: true });
|
|
41822
41858
|
}
|
|
41823
41859
|
if (hasHostPassphrase) {
|
|
41824
41860
|
yield askDevicePassphrase(device, {
|
|
@@ -41833,10 +41869,16 @@ const selectDeviceSession = (device, expectedPassphraseState, deriveCardano, onS
|
|
|
41833
41869
|
return getDeviceSession(device, buildDeviceSessionGetRequest());
|
|
41834
41870
|
});
|
|
41835
41871
|
function getProtocolV2WalletSession(device, options) {
|
|
41836
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
41872
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
41837
41873
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41838
41874
|
const forceWalletSelection = (options === null || options === void 0 ? void 0 : options.forceWalletSelection) === true || (options === null || options === void 0 ? void 0 : options.initSession) === true;
|
|
41839
41875
|
const readCurrentAttachPinSession = (options === null || options === void 0 ? void 0 : options.readCurrentAttachPinSession) === true;
|
|
41876
|
+
const sessionIsAttachPinWallet = (session) => {
|
|
41877
|
+
var _a;
|
|
41878
|
+
return readCurrentAttachPinSession ||
|
|
41879
|
+
(session === null || session === void 0 ? void 0 : session.viaAttachPin) === true ||
|
|
41880
|
+
((_a = device.features) === null || _a === void 0 ? void 0 : _a.unlockedAttachPin) === true;
|
|
41881
|
+
};
|
|
41840
41882
|
if (forceWalletSelection) {
|
|
41841
41883
|
if (options.onlyMainPin) {
|
|
41842
41884
|
(_a = device.clearStandardInternalState) === null || _a === void 0 ? void 0 : _a.call(device);
|
|
@@ -41881,8 +41923,20 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41881
41923
|
device.clearInternalState();
|
|
41882
41924
|
}
|
|
41883
41925
|
};
|
|
41926
|
+
const sessionGetRequest = ({ sessionId, expectedPassphraseState: passphraseState, } = {}) => buildDeviceSessionGetRequest({
|
|
41927
|
+
sessionId,
|
|
41928
|
+
expectedPassphraseState: passphraseState,
|
|
41929
|
+
});
|
|
41930
|
+
const askEmptyPassphraseAndGet = ({ deriveCardano, keepAttachPin, } = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
41931
|
+
yield askDevicePassphrase(device, { passphrase: '', on_device: false }, deriveCardano, markWalletStatusRefreshed);
|
|
41932
|
+
if (keepAttachPin && device.features) {
|
|
41933
|
+
device.features.unlockedAttachPin = true;
|
|
41934
|
+
}
|
|
41935
|
+
const session = yield getDeviceSession(device, buildDeviceSessionGetRequest());
|
|
41936
|
+
return keepAttachPin ? Object.assign(session, { viaAttachPin: true }) : session;
|
|
41937
|
+
});
|
|
41884
41938
|
const rejectMismatchedAttachPinWallet = () => __awaiter(this, void 0, void 0, function* () {
|
|
41885
|
-
var
|
|
41939
|
+
var _m;
|
|
41886
41940
|
const features = yield refreshProtocolV2DeviceStatus(device);
|
|
41887
41941
|
markWalletStatusRefreshed();
|
|
41888
41942
|
if (features.unlockedAttachPin !== true) {
|
|
@@ -41891,10 +41945,10 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41891
41945
|
try {
|
|
41892
41946
|
yield device.lockDevice();
|
|
41893
41947
|
}
|
|
41894
|
-
catch (
|
|
41948
|
+
catch (_o) {
|
|
41895
41949
|
}
|
|
41896
41950
|
if (options === null || options === void 0 ? void 0 : options.rejectAttachPinForMainWallet) {
|
|
41897
|
-
(
|
|
41951
|
+
(_m = device.clearStandardInternalState) === null || _m === void 0 ? void 0 : _m.call(device);
|
|
41898
41952
|
device.clearInternalState();
|
|
41899
41953
|
}
|
|
41900
41954
|
else {
|
|
@@ -41902,6 +41956,16 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41902
41956
|
}
|
|
41903
41957
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckUnlockTypeError);
|
|
41904
41958
|
});
|
|
41959
|
+
const lockAttachPinBeforePassphraseSelection = () => __awaiter(this, void 0, void 0, function* () {
|
|
41960
|
+
var _p;
|
|
41961
|
+
if (readCurrentAttachPinSession || (options === null || options === void 0 ? void 0 : options.onlyMainPin)) {
|
|
41962
|
+
return;
|
|
41963
|
+
}
|
|
41964
|
+
if (((_p = device.features) === null || _p === void 0 ? void 0 : _p.unlockedAttachPin) !== true) {
|
|
41965
|
+
return;
|
|
41966
|
+
}
|
|
41967
|
+
yield rejectMismatchedAttachPinWallet();
|
|
41968
|
+
});
|
|
41905
41969
|
if ((options === null || options === void 0 ? void 0 : options.onlyMainPin) && options.rejectAttachPinForMainWallet) {
|
|
41906
41970
|
yield rejectMismatchedAttachPinWallet();
|
|
41907
41971
|
}
|
|
@@ -41918,8 +41982,8 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41918
41982
|
}
|
|
41919
41983
|
});
|
|
41920
41984
|
const selectStandardWallet = () => __awaiter(this, void 0, void 0, function* () {
|
|
41921
|
-
var
|
|
41922
|
-
if (((
|
|
41985
|
+
var _q;
|
|
41986
|
+
if (((_q = device.features) === null || _q === void 0 ? void 0 : _q.passphraseProtection) === true) {
|
|
41923
41987
|
yield selectMainPin();
|
|
41924
41988
|
yield askDevicePassphrase(device, {
|
|
41925
41989
|
passphrase: '',
|
|
@@ -41941,7 +42005,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41941
42005
|
device.clearInternalState();
|
|
41942
42006
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckUnlockTypeError);
|
|
41943
42007
|
}
|
|
41944
|
-
response = yield getDeviceSession(device,
|
|
42008
|
+
response = yield getDeviceSession(device, sessionGetRequest());
|
|
41945
42009
|
}
|
|
41946
42010
|
else if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
41947
42011
|
expectedPassphraseState = cachedStandardSession === null || cachedStandardSession === void 0 ? void 0 : cachedStandardSession.passphraseState;
|
|
@@ -41950,7 +42014,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41950
42014
|
if (options === null || options === void 0 ? void 0 : options.selectMainWalletBeforeRestore) {
|
|
41951
42015
|
yield selectMainPin();
|
|
41952
42016
|
}
|
|
41953
|
-
response = yield getDeviceSession(device,
|
|
42017
|
+
response = yield getDeviceSession(device, sessionGetRequest({
|
|
41954
42018
|
sessionId: cachedStandardSession.sessionId,
|
|
41955
42019
|
expectedPassphraseState,
|
|
41956
42020
|
}));
|
|
@@ -41966,12 +42030,12 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41966
42030
|
}
|
|
41967
42031
|
if (!response) {
|
|
41968
42032
|
yield selectStandardWallet();
|
|
41969
|
-
response = yield getDeviceSession(device,
|
|
42033
|
+
response = yield getDeviceSession(device, sessionGetRequest());
|
|
41970
42034
|
}
|
|
41971
42035
|
}
|
|
41972
42036
|
else if (cachedSessionId && expectedPassphraseState) {
|
|
41973
42037
|
try {
|
|
41974
|
-
response = yield getDeviceSession(device,
|
|
42038
|
+
response = yield getDeviceSession(device, sessionGetRequest({
|
|
41975
42039
|
sessionId: cachedSessionId,
|
|
41976
42040
|
expectedPassphraseState,
|
|
41977
42041
|
}));
|
|
@@ -41987,7 +42051,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41987
42051
|
}
|
|
41988
42052
|
else if (expectedPassphraseState) {
|
|
41989
42053
|
try {
|
|
41990
|
-
response = yield getDeviceSession(device,
|
|
42054
|
+
response = yield getDeviceSession(device, sessionGetRequest({
|
|
41991
42055
|
expectedPassphraseState,
|
|
41992
42056
|
}));
|
|
41993
42057
|
}
|
|
@@ -42002,6 +42066,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42002
42066
|
device.clearInternalState();
|
|
42003
42067
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WalletSessionInvalid);
|
|
42004
42068
|
}
|
|
42069
|
+
yield lockAttachPinBeforePassphraseSelection();
|
|
42005
42070
|
response = yield selectDeviceSession(device, expectedPassphraseState, options === null || options === void 0 ? void 0 : options.deriveCardano, markWalletStatusRefreshed);
|
|
42006
42071
|
}
|
|
42007
42072
|
let { message } = response;
|
|
@@ -42027,10 +42092,11 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42027
42092
|
if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
42028
42093
|
(_h = device.clearStandardInternalState) === null || _h === void 0 ? void 0 : _h.call(device);
|
|
42029
42094
|
yield selectStandardWallet();
|
|
42030
|
-
response = yield getDeviceSession(device,
|
|
42095
|
+
response = yield getDeviceSession(device, sessionGetRequest());
|
|
42031
42096
|
}
|
|
42032
42097
|
else {
|
|
42033
42098
|
device.clearInternalState();
|
|
42099
|
+
yield lockAttachPinBeforePassphraseSelection();
|
|
42034
42100
|
response = yield selectDeviceSession(device, expectedPassphraseState, options === null || options === void 0 ? void 0 : options.deriveCardano, markWalletStatusRefreshed);
|
|
42035
42101
|
}
|
|
42036
42102
|
message = response.message;
|
|
@@ -42058,11 +42124,19 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42058
42124
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WalletSessionInvalid);
|
|
42059
42125
|
}
|
|
42060
42126
|
resumed = false;
|
|
42061
|
-
|
|
42062
|
-
|
|
42127
|
+
const previousAddress = message.btc_test_address;
|
|
42128
|
+
if (sessionIsAttachPinWallet(response)) {
|
|
42129
|
+
response = yield askEmptyPassphraseAndGet({ deriveCardano: true, keepAttachPin: true });
|
|
42130
|
+
}
|
|
42131
|
+
else if (((_k = device.features) === null || _k === void 0 ? void 0 : _k.passphraseProtection) === false) {
|
|
42063
42132
|
response = yield getDeviceSession(device, buildDeviceSessionGetRequest());
|
|
42064
42133
|
}
|
|
42134
|
+
else if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
42135
|
+
yield selectMainPin();
|
|
42136
|
+
response = yield askEmptyPassphraseAndGet({ deriveCardano: true });
|
|
42137
|
+
}
|
|
42065
42138
|
else {
|
|
42139
|
+
yield lockAttachPinBeforePassphraseSelection();
|
|
42066
42140
|
response = yield selectDeviceSession(device, expectedPassphraseState, true, markWalletStatusRefreshed);
|
|
42067
42141
|
}
|
|
42068
42142
|
message = response.message;
|
|
@@ -42071,13 +42145,22 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42071
42145
|
}
|
|
42072
42146
|
catch (error) {
|
|
42073
42147
|
if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
42074
|
-
(
|
|
42148
|
+
(_l = device.clearStandardInternalState) === null || _l === void 0 ? void 0 : _l.call(device);
|
|
42075
42149
|
}
|
|
42076
42150
|
else {
|
|
42077
42151
|
device.clearInternalState();
|
|
42078
42152
|
}
|
|
42079
42153
|
throw error;
|
|
42080
42154
|
}
|
|
42155
|
+
if (previousAddress && previousAddress !== message.btc_test_address) {
|
|
42156
|
+
yield rejectMismatchedAttachPinWallet();
|
|
42157
|
+
clearCurrentWalletSession();
|
|
42158
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
42159
|
+
}
|
|
42160
|
+
if (!deviceSessionHasCardano(message)) {
|
|
42161
|
+
clearCurrentWalletSession();
|
|
42162
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WalletSessionInvalid);
|
|
42163
|
+
}
|
|
42081
42164
|
}
|
|
42082
42165
|
const internalStateArgs = [
|
|
42083
42166
|
true,
|
|
@@ -42093,7 +42176,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42093
42176
|
device.updateInternalState(...internalStateArgs);
|
|
42094
42177
|
}
|
|
42095
42178
|
let unlockedAttachPin;
|
|
42096
|
-
if (readCurrentAttachPinSession) {
|
|
42179
|
+
if (readCurrentAttachPinSession || sessionIsAttachPinWallet(response)) {
|
|
42097
42180
|
unlockedAttachPin = true;
|
|
42098
42181
|
}
|
|
42099
42182
|
else if (mainPinAuthenticated) {
|
|
@@ -52011,11 +52094,15 @@ function isProtocolV2ResponseTimeout(error) {
|
|
|
52011
52094
|
code === 'response-timeout' ||
|
|
52012
52095
|
/(?:BLE|Lowlevel|Protocol V2) response timeout/i.test((_b = candidate.message) !== null && _b !== void 0 ? _b : ''));
|
|
52013
52096
|
}
|
|
52014
|
-
function getProtocolV2FileChunkLimit() {
|
|
52097
|
+
function getProtocolV2FileChunkLimit(bleChunkSizeLimit) {
|
|
52015
52098
|
const env = DataManager.getSettings('env');
|
|
52016
|
-
|
|
52017
|
-
|
|
52018
|
-
|
|
52099
|
+
if (env && DataManager.isBleConnect(env)) {
|
|
52100
|
+
const configuredLimit = Number(bleChunkSizeLimit);
|
|
52101
|
+
return Number.isFinite(configuredLimit) && configuredLimit > 0
|
|
52102
|
+
? Math.floor(configuredLimit)
|
|
52103
|
+
: hdTransport.PROTOCOL_V2_BLE_FILE_CHUNK_SIZE;
|
|
52104
|
+
}
|
|
52105
|
+
return hdTransport.PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
52019
52106
|
}
|
|
52020
52107
|
function dataToUint8Array(data) {
|
|
52021
52108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -52070,7 +52157,7 @@ function writeProtocolV2File(options) {
|
|
|
52070
52157
|
if (totalSize < startOffset + dataLength) {
|
|
52071
52158
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite totalSize ${totalSize} is smaller than offset + data length ${startOffset + dataLength}`);
|
|
52072
52159
|
}
|
|
52073
|
-
const defaultChunkSizeLimit = getProtocolV2FileChunkLimit();
|
|
52160
|
+
const defaultChunkSizeLimit = getProtocolV2FileChunkLimit(options.bleChunkSizeLimit);
|
|
52074
52161
|
const configuredChunkSizeLimit = Number(options.chunkSizeLimit);
|
|
52075
52162
|
const chunkSizeLimit = Number.isFinite(configuredChunkSizeLimit) && configuredChunkSizeLimit > 0
|
|
52076
52163
|
? Math.floor(configuredChunkSizeLimit)
|
|
@@ -52421,6 +52508,13 @@ const isProtocolV2InstallResponseTimeout = (error) => {
|
|
|
52421
52508
|
return (code === 'response-timeout' ||
|
|
52422
52509
|
/\bresponse timeout\b/i.test(getProtocolV2UnknownErrorText(error)));
|
|
52423
52510
|
};
|
|
52511
|
+
const getProtocolV2ErrorCode = (error) => {
|
|
52512
|
+
if (!error || typeof error !== 'object')
|
|
52513
|
+
return undefined;
|
|
52514
|
+
const { errorCode, code } = error;
|
|
52515
|
+
const causeCode = errorCode !== null && errorCode !== void 0 ? errorCode : code;
|
|
52516
|
+
return typeof causeCode === 'number' || typeof causeCode === 'string' ? causeCode : undefined;
|
|
52517
|
+
};
|
|
52424
52518
|
const isProtocolV2TerminalInstallStatusError = (error) => {
|
|
52425
52519
|
var _a;
|
|
52426
52520
|
return hdShared.isBleStaleBondHardwareError(error) ||
|
|
@@ -53713,6 +53807,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53713
53807
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.StartTransferData);
|
|
53714
53808
|
this.protocolV2LastTransferProgress = undefined;
|
|
53715
53809
|
this.protocolV2LastTransferProgressAt = 0;
|
|
53810
|
+
const transferStartedAt = Date.now();
|
|
53716
53811
|
let processedSize = 0;
|
|
53717
53812
|
for (const resource of resourcesToSync) {
|
|
53718
53813
|
const writePath = resource.devicePath;
|
|
@@ -53721,6 +53816,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53721
53816
|
filePath: writePath,
|
|
53722
53817
|
processedSize,
|
|
53723
53818
|
totalSize,
|
|
53819
|
+
transferStartedAt,
|
|
53724
53820
|
});
|
|
53725
53821
|
yield this.verifyProtocolV2StagedFile(writePath, resource.source.size);
|
|
53726
53822
|
if (isProtocolV2BootResourcePackagePath(resource.devicePath)) {
|
|
@@ -53735,6 +53831,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53735
53831
|
filePath,
|
|
53736
53832
|
processedSize,
|
|
53737
53833
|
totalSize,
|
|
53834
|
+
transferStartedAt,
|
|
53738
53835
|
});
|
|
53739
53836
|
yield this.verifyProtocolV2StagedFile(filePath, item.source.size);
|
|
53740
53837
|
stagedInstallTargets.push({
|
|
@@ -53743,7 +53840,13 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53743
53840
|
});
|
|
53744
53841
|
}
|
|
53745
53842
|
if (totalSize > 0) {
|
|
53746
|
-
|
|
53843
|
+
const elapsedMs = Math.max(Date.now() - transferStartedAt, 0);
|
|
53844
|
+
this.postProgressMessage(100, 'transferData', {
|
|
53845
|
+
transferredBytes: totalSize,
|
|
53846
|
+
totalBytes: totalSize,
|
|
53847
|
+
rateBytesPerSecond: elapsedMs > 0 ? Math.round((totalSize / elapsedMs) * 1000) : undefined,
|
|
53848
|
+
elapsedMs,
|
|
53849
|
+
});
|
|
53747
53850
|
}
|
|
53748
53851
|
if (stagedInstallTargets.length === 0) {
|
|
53749
53852
|
return;
|
|
@@ -53763,16 +53866,17 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53763
53866
|
}
|
|
53764
53867
|
});
|
|
53765
53868
|
}
|
|
53766
|
-
protocolV2SourceUpdateProcess({ source, filePath, processedSize, totalSize, }) {
|
|
53869
|
+
protocolV2SourceUpdateProcess({ source, filePath, processedSize, totalSize, transferStartedAt = Date.now(), }) {
|
|
53767
53870
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53768
53871
|
let lastError;
|
|
53769
53872
|
for (let attempt = 1; attempt <= PROTOCOL_V2_FILE_TRANSFER_RETRY_COUNT; attempt += 1) {
|
|
53873
|
+
this.throwIfAborted();
|
|
53770
53874
|
try {
|
|
53771
|
-
const transferStartedAt = Date.now();
|
|
53772
53875
|
yield writeFirmwareByteSource({
|
|
53773
53876
|
source,
|
|
53774
53877
|
chunkSize: this.getProtocolV2FirmwareChunkSize('write', filePath),
|
|
53775
53878
|
write: ({ data, sourceOffset, length, first }) => __awaiter(this, void 0, void 0, function* () {
|
|
53879
|
+
this.throwIfAborted();
|
|
53776
53880
|
const chunkEnd = sourceOffset + length;
|
|
53777
53881
|
const deviceProgress = getProtocolV2DeviceTransferProgress(processedSize + sourceOffset, processedSize + chunkEnd, totalSize);
|
|
53778
53882
|
const response = yield this.fileWriteChunk(filePath, source.size, sourceOffset, data, first, deviceProgress);
|
|
@@ -53795,7 +53899,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53795
53899
|
this.postProgressMessage(progress, 'transferData', {
|
|
53796
53900
|
transferredBytes,
|
|
53797
53901
|
totalBytes: totalSize,
|
|
53798
|
-
rateBytesPerSecond: elapsedMs > 0 ? Math.round((
|
|
53902
|
+
rateBytesPerSecond: elapsedMs > 0 ? Math.round((transferredBytes / elapsedMs) * 1000) : undefined,
|
|
53799
53903
|
elapsedMs,
|
|
53800
53904
|
});
|
|
53801
53905
|
}
|
|
@@ -53805,16 +53909,19 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53805
53909
|
return processedSize + source.size;
|
|
53806
53910
|
}
|
|
53807
53911
|
catch (error) {
|
|
53912
|
+
this.throwIfAborted();
|
|
53808
53913
|
if (hdShared.isBleStaleBondHardwareError(error)) {
|
|
53809
53914
|
throw error;
|
|
53810
53915
|
}
|
|
53811
53916
|
lastError = error;
|
|
53812
53917
|
if (attempt < PROTOCOL_V2_FILE_TRANSFER_RETRY_COUNT) {
|
|
53813
53918
|
yield this.recoverProtocolV2FileTransfer();
|
|
53919
|
+
this.throwIfAborted();
|
|
53814
53920
|
}
|
|
53815
53921
|
}
|
|
53816
53922
|
}
|
|
53817
|
-
|
|
53923
|
+
const causeCode = getProtocolV2ErrorCode(lastError);
|
|
53924
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.EmmcFileWriteFirmwareError, `transfer data error: ${getProtocolV2UnknownErrorText(lastError)}`, causeCode === undefined ? undefined : { causeCode });
|
|
53818
53925
|
});
|
|
53819
53926
|
}
|
|
53820
53927
|
getProtocolV2InstallItemStagingPath(item) {
|
|
@@ -54161,7 +54268,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54161
54268
|
return;
|
|
54162
54269
|
}
|
|
54163
54270
|
if (!hasCurrentInstallEvidence) {
|
|
54164
|
-
this.device.setCancelableAction(() =>
|
|
54271
|
+
this.device.setCancelableAction(() => Promise.resolve());
|
|
54165
54272
|
}
|
|
54166
54273
|
if (requireCurrentInstallStatus &&
|
|
54167
54274
|
!hasCurrentInstallEvidence &&
|
|
@@ -54507,7 +54614,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54507
54614
|
this.protocolV2InstallTerminalSuccessObserved = false;
|
|
54508
54615
|
const commands = this.device.getCommands();
|
|
54509
54616
|
yield commands.typedCall('DeviceFirmwareUpdateStage', 'Success', { targets });
|
|
54510
|
-
this.device.setCancelableAction(() =>
|
|
54617
|
+
this.device.setCancelableAction(() => Promise.resolve());
|
|
54511
54618
|
const interaction = this.device.createProtocolV2UiPhaseMetadata('button', 'start');
|
|
54512
54619
|
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 } : {}))));
|
|
54513
54620
|
try {
|
|
@@ -54741,7 +54848,9 @@ const ARCHIVE_ENTRY_SIZE = 296;
|
|
|
54741
54848
|
const ARCHIVE_ENTRY_NAME_MAX_LENGTH = 255;
|
|
54742
54849
|
const ARCHIVE_COMPRESS_LZ4_BLOCKED = 1;
|
|
54743
54850
|
const ARCHIVE_ALIGNMENT = 4;
|
|
54744
|
-
const
|
|
54851
|
+
const LZ4_PREFERRED_BLOCK_SIZE_LOG2 = 14;
|
|
54852
|
+
const LZ4_FALLBACK_BLOCK_SIZE_LOG2 = 13;
|
|
54853
|
+
const LZ4_COMPRESSED_BLOCK_SIZE_MAX = 1 << 14;
|
|
54745
54854
|
function supportsPro2HostAssetPackage(firmwareVersion) {
|
|
54746
54855
|
return Boolean(firmwareVersion &&
|
|
54747
54856
|
semver__default["default"].valid(firmwareVersion) &&
|
|
@@ -54763,7 +54872,7 @@ const LZ4_MAX_OFFSET = 0xffff;
|
|
|
54763
54872
|
const LZ4_LENGTH_MASK = 15;
|
|
54764
54873
|
const LZ4_HASH_LOG = 16;
|
|
54765
54874
|
const LZ4_HASH_MULTIPLIER = 2654435761;
|
|
54766
|
-
const
|
|
54875
|
+
const LZ4_MAX_SEARCH_DEPTH = 64;
|
|
54767
54876
|
function writeExtendedLength(output, offset, length) {
|
|
54768
54877
|
let remaining = length;
|
|
54769
54878
|
let nextOffset = offset;
|
|
@@ -54816,7 +54925,7 @@ function emitLastLiterals(output, outputOffset, input, anchor, literalLength) {
|
|
|
54816
54925
|
}
|
|
54817
54926
|
return copyBytes(output, nextOffset, input, anchor, literalLength);
|
|
54818
54927
|
}
|
|
54819
|
-
function compressRawLz4Block(input, hashTable) {
|
|
54928
|
+
function compressRawLz4Block(input, hashTable, matchChain) {
|
|
54820
54929
|
const output = new Uint8Array(input.byteLength + Math.floor(input.byteLength / 255) + 16);
|
|
54821
54930
|
const inputView = new DataView(input.buffer, input.byteOffset, input.byteLength);
|
|
54822
54931
|
const matchFindLimit = input.byteLength - LZ4_MATCH_FIND_LIMIT;
|
|
@@ -54824,52 +54933,82 @@ function compressRawLz4Block(input, hashTable) {
|
|
|
54824
54933
|
let anchor = 0;
|
|
54825
54934
|
let inputOffset = 0;
|
|
54826
54935
|
let outputOffset = 0;
|
|
54827
|
-
let searchMatchCount = 1 << LZ4_SKIP_TRIGGER;
|
|
54828
54936
|
hashTable.fill(0);
|
|
54829
54937
|
while (inputOffset < matchFindLimit) {
|
|
54830
54938
|
const sequence = inputView.getUint32(inputOffset, true);
|
|
54831
54939
|
const hash = Math.imul(sequence, LZ4_HASH_MULTIPLIER) >>> (32 - LZ4_HASH_LOG);
|
|
54832
|
-
|
|
54940
|
+
let candidate = hashTable[hash] - 1;
|
|
54941
|
+
matchChain[inputOffset] = candidate;
|
|
54833
54942
|
hashTable[hash] = inputOffset + 1;
|
|
54834
|
-
|
|
54835
|
-
|
|
54836
|
-
|
|
54837
|
-
|
|
54838
|
-
inputOffset
|
|
54839
|
-
|
|
54943
|
+
let bestCandidate = -1;
|
|
54944
|
+
let bestMatchEnd = inputOffset;
|
|
54945
|
+
let searchDepth = 0;
|
|
54946
|
+
while (candidate >= 0 &&
|
|
54947
|
+
inputOffset - candidate <= LZ4_MAX_OFFSET &&
|
|
54948
|
+
searchDepth < LZ4_MAX_SEARCH_DEPTH) {
|
|
54949
|
+
if (inputView.getUint32(candidate, true) === sequence) {
|
|
54950
|
+
let matchEnd = inputOffset + LZ4_MIN_MATCH;
|
|
54951
|
+
let reference = candidate + LZ4_MIN_MATCH;
|
|
54952
|
+
while (matchEnd < matchExtendLimit && input[matchEnd] === input[reference]) {
|
|
54953
|
+
matchEnd += 1;
|
|
54954
|
+
reference += 1;
|
|
54955
|
+
}
|
|
54956
|
+
if (matchEnd > bestMatchEnd) {
|
|
54957
|
+
bestCandidate = candidate;
|
|
54958
|
+
bestMatchEnd = matchEnd;
|
|
54959
|
+
}
|
|
54960
|
+
}
|
|
54961
|
+
candidate = matchChain[candidate];
|
|
54962
|
+
searchDepth += 1;
|
|
54963
|
+
}
|
|
54964
|
+
if (bestCandidate < 0) {
|
|
54965
|
+
inputOffset += 1;
|
|
54840
54966
|
}
|
|
54841
54967
|
else {
|
|
54842
|
-
|
|
54843
|
-
|
|
54844
|
-
|
|
54845
|
-
while (matchEnd < matchExtendLimit && input[matchEnd] === input[reference]) {
|
|
54846
|
-
matchEnd += 1;
|
|
54847
|
-
reference += 1;
|
|
54848
|
-
}
|
|
54849
|
-
outputOffset = emitSequence(output, outputOffset, input, anchor, inputOffset - anchor, inputOffset - candidate, matchEnd - inputOffset - LZ4_MIN_MATCH);
|
|
54850
|
-
inputOffset = matchEnd;
|
|
54968
|
+
const matchStart = inputOffset;
|
|
54969
|
+
outputOffset = emitSequence(output, outputOffset, input, anchor, inputOffset - anchor, inputOffset - bestCandidate, bestMatchEnd - inputOffset - LZ4_MIN_MATCH);
|
|
54970
|
+
inputOffset = bestMatchEnd;
|
|
54851
54971
|
anchor = inputOffset;
|
|
54972
|
+
for (let skippedOffset = matchStart + 1; skippedOffset < inputOffset && skippedOffset < matchFindLimit; skippedOffset += 1) {
|
|
54973
|
+
const skippedSequence = inputView.getUint32(skippedOffset, true);
|
|
54974
|
+
const skippedHash = Math.imul(skippedSequence, LZ4_HASH_MULTIPLIER) >>> (32 - LZ4_HASH_LOG);
|
|
54975
|
+
matchChain[skippedOffset] = hashTable[skippedHash] - 1;
|
|
54976
|
+
hashTable[skippedHash] = skippedOffset + 1;
|
|
54977
|
+
}
|
|
54852
54978
|
}
|
|
54853
54979
|
}
|
|
54854
54980
|
outputOffset = emitLastLiterals(output, outputOffset, input, anchor, input.byteLength - anchor);
|
|
54855
54981
|
return output.slice(0, outputOffset);
|
|
54856
54982
|
}
|
|
54857
|
-
function
|
|
54858
|
-
const blockSize = 1 <<
|
|
54983
|
+
function encodeLz4BlockedWithBlockSize(data, blockSizeLog2) {
|
|
54984
|
+
const blockSize = 1 << blockSizeLog2;
|
|
54859
54985
|
const blockCount = Math.ceil(data.byteLength / blockSize);
|
|
54860
54986
|
const hashTable = new Uint32Array(1 << LZ4_HASH_LOG);
|
|
54987
|
+
const matchChain = new Int32Array(blockSize);
|
|
54861
54988
|
const blocks = [];
|
|
54862
54989
|
const header = new Uint8Array(8 + blockCount * 4);
|
|
54863
54990
|
const headerView = new DataView(header.buffer);
|
|
54864
54991
|
headerView.setUint16(0, blockCount, true);
|
|
54865
|
-
headerView.setUint16(2,
|
|
54992
|
+
headerView.setUint16(2, blockSizeLog2, true);
|
|
54866
54993
|
for (let index = 0; index < blockCount; index += 1) {
|
|
54867
|
-
const block = compressRawLz4Block(data.subarray(index * blockSize, Math.min((index + 1) * blockSize, data.byteLength)), hashTable);
|
|
54994
|
+
const block = compressRawLz4Block(data.subarray(index * blockSize, Math.min((index + 1) * blockSize, data.byteLength)), hashTable, matchChain);
|
|
54995
|
+
if (block.byteLength > LZ4_COMPRESSED_BLOCK_SIZE_MAX)
|
|
54996
|
+
return undefined;
|
|
54868
54997
|
headerView.setUint32(8 + index * 4, block.byteLength, true);
|
|
54869
54998
|
blocks.push(block);
|
|
54870
54999
|
}
|
|
54871
55000
|
return concatBytes([header, ...blocks]);
|
|
54872
55001
|
}
|
|
55002
|
+
function encodeLz4Blocked(data) {
|
|
55003
|
+
const preferred = encodeLz4BlockedWithBlockSize(data, LZ4_PREFERRED_BLOCK_SIZE_LOG2);
|
|
55004
|
+
if (preferred)
|
|
55005
|
+
return preferred;
|
|
55006
|
+
const fallback = encodeLz4BlockedWithBlockSize(data, LZ4_FALLBACK_BLOCK_SIZE_LOG2);
|
|
55007
|
+
if (!fallback) {
|
|
55008
|
+
throw new Error('Pro2 host asset package LZ4 block exceeds the firmware buffer limit.');
|
|
55009
|
+
}
|
|
55010
|
+
return fallback;
|
|
55011
|
+
}
|
|
54873
55012
|
const CRC32_TABLE = (() => {
|
|
54874
55013
|
const table = new Uint32Array(256);
|
|
54875
55014
|
for (let index = 0; index < table.length; index += 1) {
|
|
@@ -54956,6 +55095,7 @@ const SAFE_FILE_NAME = /^[A-Za-z0-9_-]+(?:\.bin)?$/;
|
|
|
54956
55095
|
const DEVICE_SETTINGS_SET_MESSAGE_TYPE = 60412;
|
|
54957
55096
|
const FILESYSTEM_FILE_WRITE_MESSAGE_TYPE$2 = 60805;
|
|
54958
55097
|
const FILESYSTEM_DIR_MAKE_MESSAGE_TYPE = 60809;
|
|
55098
|
+
const WALLPAPER_PACKAGE_BLE_CHUNK_SIZE = 1960;
|
|
54959
55099
|
const Log$4 = getLogger(exports.LoggerNames.Method);
|
|
54960
55100
|
function normalizeFileName(fileName, data) {
|
|
54961
55101
|
if (fileName !== undefined && (!fileName || !SAFE_FILE_NAME.test(fileName))) {
|
|
@@ -55027,7 +55167,7 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
55027
55167
|
this.directoryReady = true;
|
|
55028
55168
|
});
|
|
55029
55169
|
}
|
|
55030
|
-
upload(path, data) {
|
|
55170
|
+
upload(path, data, bleChunkSizeLimit) {
|
|
55031
55171
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55032
55172
|
if (this.uploaded)
|
|
55033
55173
|
return;
|
|
@@ -55037,6 +55177,7 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
55037
55177
|
data,
|
|
55038
55178
|
totalSize: data.byteLength,
|
|
55039
55179
|
chunkSize: this.params.chunkSize,
|
|
55180
|
+
bleChunkSizeLimit,
|
|
55040
55181
|
maxChunkRetries: 3,
|
|
55041
55182
|
overwrite: true,
|
|
55042
55183
|
append: false,
|
|
@@ -55064,7 +55205,7 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
55064
55205
|
: encoded.data;
|
|
55065
55206
|
if (useHostAssetPackage)
|
|
55066
55207
|
this.path = WALLPAPER_PACKAGE_PATH;
|
|
55067
|
-
yield this.upload(this.path, data);
|
|
55208
|
+
yield this.upload(this.path, data, useHostAssetPackage ? WALLPAPER_PACKAGE_BLE_CHUNK_SIZE : undefined);
|
|
55068
55209
|
const response = yield this.device.commands.typedCall('DeviceSettingsSet', 'Success', {
|
|
55069
55210
|
settings: { wallpaper_path: this.path },
|
|
55070
55211
|
});
|
|
@@ -66283,18 +66424,19 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
|
66283
66424
|
!device.commands ||
|
|
66284
66425
|
device.commands.disposed;
|
|
66285
66426
|
if (shouldAcquire) {
|
|
66427
|
+
const connectProtocol = resolveBleConnectProtocol(method);
|
|
66286
66428
|
const useAcquireGuards = DataManager.getSettings('env') === 'desktop-web-ble';
|
|
66287
66429
|
if (useAcquireGuards && (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
|
|
66288
66430
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
|
|
66289
66431
|
}
|
|
66290
66432
|
if (!useAcquireGuards) {
|
|
66291
|
-
yield device.acquire(
|
|
66433
|
+
yield device.acquire(connectProtocol, {
|
|
66292
66434
|
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
66293
66435
|
});
|
|
66294
66436
|
}
|
|
66295
66437
|
else {
|
|
66296
66438
|
try {
|
|
66297
|
-
yield raceBleAcquire(device.acquire(
|
|
66439
|
+
yield raceBleAcquire(device.acquire(connectProtocol, {
|
|
66298
66440
|
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
66299
66441
|
}), abortSignal);
|
|
66300
66442
|
}
|
|
@@ -66346,6 +66488,13 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
|
66346
66488
|
}
|
|
66347
66489
|
});
|
|
66348
66490
|
}
|
|
66491
|
+
function resolveBleConnectProtocol(method) {
|
|
66492
|
+
if (method.payload.connectProtocol === 'V1' || method.payload.connectProtocol === 'V2') {
|
|
66493
|
+
return method.payload.connectProtocol;
|
|
66494
|
+
}
|
|
66495
|
+
const supportedProtocols = method.getSupportedProtocols();
|
|
66496
|
+
return supportedProtocols.length === 1 && supportedProtocols[0] === 'V2' ? 'V2' : undefined;
|
|
66497
|
+
}
|
|
66349
66498
|
const ensureConnected = (_context, method, connectId, pollingId, abortSignal) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66350
66499
|
let tryCount = 0;
|
|
66351
66500
|
const MAX_RETRY_COUNT = method.payload && typeof method.payload.retryCount === 'number' ? method.payload.retryCount : 5;
|
|
@@ -66501,7 +66650,7 @@ const cancel = (context, connectId) => {
|
|
|
66501
66650
|
requestQueue.cancelCallbackTasks(connectId);
|
|
66502
66651
|
const requestIds = requestQueue.getRequestTasksId();
|
|
66503
66652
|
Log.debug(`Cancel Api connect requestQueues: length:${requestIds.length} requestIds:${requestIds.join(',')}`);
|
|
66504
|
-
requestQueue.
|
|
66653
|
+
requestQueue.abortAllRequests();
|
|
66505
66654
|
const canceledDevices = [];
|
|
66506
66655
|
const interruptDevice = (device, deviceConnectId) => {
|
|
66507
66656
|
if (!device || canceledDevices.includes(device)) {
|