@onekeyfe/hd-core 1.2.0-alpha.11 → 1.2.0-alpha.12
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__/protocol-v2.test.ts +114 -30
- package/__tests__/protocolV2FileWrite.test.ts +55 -0
- package/dist/api/FileWrite.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +32 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts +2 -2
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +263 -254
- package/dist/inject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +1 -0
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +1 -1
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/types/api/getDeviceInfo.d.ts +1 -1
- package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +2 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +2 -1
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +1 -1
- package/dist/types/device.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FileWrite.ts +18 -186
- package/src/api/helpers/protocolV2FileWrite.ts +164 -0
- package/src/api/index.ts +1 -0
- package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +18 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +13 -49
- package/src/deviceProfile/buildDeviceFeatures.ts +20 -12
- package/src/deviceProfile/buildDeviceProfile.ts +8 -6
- package/src/inject.ts +2 -0
- package/src/protocols/protocol-v2/features.ts +19 -1
- package/src/protocols/protocol-v2/index.ts +2 -0
- package/src/types/api/getDeviceInfo.ts +1 -1
- package/src/types/api/index.ts +2 -0
- package/src/types/api/protocolV2.ts +6 -0
- package/src/types/device.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -145,6 +145,7 @@ const createCoreApi = (call) => ({
|
|
|
145
145
|
deviceReboot: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceReboot' })),
|
|
146
146
|
deviceInfoGet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceInfoGet' })),
|
|
147
147
|
deviceStatusGet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceStatusGet' })),
|
|
148
|
+
deviceGetOnboardingStatus: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceGetOnboardingStatus' })),
|
|
148
149
|
deviceSessionGet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceSessionGet' })),
|
|
149
150
|
deviceFirmwareUpdate: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFirmwareUpdate' })),
|
|
150
151
|
deviceGetFirmwareUpdateStatus: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceGetFirmwareUpdateStatus' })),
|
|
@@ -41001,7 +41002,20 @@ class DeviceWalletSessionStore {
|
|
|
41001
41002
|
}
|
|
41002
41003
|
const deviceWalletSessionStore = new DeviceWalletSessionStore();
|
|
41003
41004
|
|
|
41004
|
-
const
|
|
41005
|
+
const isProtocolV2RomloaderDeviceInfo = (deviceInfo) => {
|
|
41006
|
+
var _a, _b, _c;
|
|
41007
|
+
return !!deviceInfo &&
|
|
41008
|
+
deviceInfo.status == null &&
|
|
41009
|
+
((_a = deviceInfo.fw) === null || _a === void 0 ? void 0 : _a.romloader) != null &&
|
|
41010
|
+
((_b = deviceInfo.fw) === null || _b === void 0 ? void 0 : _b.application) == null &&
|
|
41011
|
+
((_c = deviceInfo.fw) === null || _c === void 0 ? void 0 : _c.application_data) == null &&
|
|
41012
|
+
deviceInfo.coprocessor == null &&
|
|
41013
|
+
deviceInfo.se1 == null &&
|
|
41014
|
+
deviceInfo.se2 == null &&
|
|
41015
|
+
deviceInfo.se3 == null &&
|
|
41016
|
+
deviceInfo.se4 == null;
|
|
41017
|
+
};
|
|
41018
|
+
const isProtocolV2BootloaderDeviceInfo = (deviceInfo) => !!deviceInfo && deviceInfo.status == null && !isProtocolV2RomloaderDeviceInfo(deviceInfo);
|
|
41005
41019
|
const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
|
|
41006
41020
|
targets: {
|
|
41007
41021
|
hw: true,
|
|
@@ -41110,6 +41124,8 @@ const getDeviceMode = (features) => {
|
|
|
41110
41124
|
};
|
|
41111
41125
|
const getProtocolV2Mode = (deviceInfo) => {
|
|
41112
41126
|
var _a;
|
|
41127
|
+
if (isProtocolV2RomloaderDeviceInfo(deviceInfo))
|
|
41128
|
+
return 'romloader';
|
|
41113
41129
|
if (isProtocolV2BootloaderDeviceInfo(deviceInfo))
|
|
41114
41130
|
return 'bootloader';
|
|
41115
41131
|
const initialized = (_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _a === void 0 ? void 0 : _a.init_states;
|
|
@@ -41134,21 +41150,21 @@ const normalizeV1Versions = (features, protocolV1OneKeyFeatures) => ({
|
|
|
41134
41150
|
se04Boot: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_boot_version, features === null || features === void 0 ? void 0 : features.se04BootVersion),
|
|
41135
41151
|
});
|
|
41136
41152
|
const normalizeV2Versions = (deviceInfo) => {
|
|
41137
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m
|
|
41153
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
41138
41154
|
const info = deviceInfo;
|
|
41139
41155
|
return {
|
|
41140
41156
|
firmware: firstMeaningfulVersion$1(getImageVersion$1((_a = info === null || info === void 0 ? void 0 : info.fw) === null || _a === void 0 ? void 0 : _a.application)),
|
|
41141
41157
|
bootloader: firstMeaningfulVersion$1(getImageVersion$1((_b = info === null || info === void 0 ? void 0 : info.fw) === null || _b === void 0 ? void 0 : _b.bootloader)),
|
|
41142
|
-
board: firstMeaningfulVersion$1(getImageVersion$1((
|
|
41143
|
-
ble: firstMeaningfulVersion$1(getImageVersion$1((
|
|
41144
|
-
se01: firstMeaningfulVersion$1(getImageVersion$1((
|
|
41145
|
-
se02: firstMeaningfulVersion$1(getImageVersion$1((
|
|
41146
|
-
se03: firstMeaningfulVersion$1(getImageVersion$1((
|
|
41147
|
-
se04: firstMeaningfulVersion$1(getImageVersion$1((
|
|
41148
|
-
se01Boot: firstMeaningfulVersion$1(getImageVersion$1((
|
|
41149
|
-
se02Boot: firstMeaningfulVersion$1(getImageVersion$1((
|
|
41150
|
-
se03Boot: firstMeaningfulVersion$1(getImageVersion$1((
|
|
41151
|
-
se04Boot: firstMeaningfulVersion$1(getImageVersion$1((
|
|
41158
|
+
board: firstMeaningfulVersion$1(getImageVersion$1((_c = info === null || info === void 0 ? void 0 : info.fw) === null || _c === void 0 ? void 0 : _c.romloader)),
|
|
41159
|
+
ble: firstMeaningfulVersion$1(getImageVersion$1((_d = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _d === void 0 ? void 0 : _d.application)),
|
|
41160
|
+
se01: firstMeaningfulVersion$1(getImageVersion$1((_e = info === null || info === void 0 ? void 0 : info.se1) === null || _e === void 0 ? void 0 : _e.application)),
|
|
41161
|
+
se02: firstMeaningfulVersion$1(getImageVersion$1((_f = info === null || info === void 0 ? void 0 : info.se2) === null || _f === void 0 ? void 0 : _f.application)),
|
|
41162
|
+
se03: firstMeaningfulVersion$1(getImageVersion$1((_g = info === null || info === void 0 ? void 0 : info.se3) === null || _g === void 0 ? void 0 : _g.application)),
|
|
41163
|
+
se04: firstMeaningfulVersion$1(getImageVersion$1((_h = info === null || info === void 0 ? void 0 : info.se4) === null || _h === void 0 ? void 0 : _h.application)),
|
|
41164
|
+
se01Boot: firstMeaningfulVersion$1(getImageVersion$1((_j = info === null || info === void 0 ? void 0 : info.se1) === null || _j === void 0 ? void 0 : _j.bootloader)),
|
|
41165
|
+
se02Boot: firstMeaningfulVersion$1(getImageVersion$1((_k = info === null || info === void 0 ? void 0 : info.se2) === null || _k === void 0 ? void 0 : _k.bootloader)),
|
|
41166
|
+
se03Boot: firstMeaningfulVersion$1(getImageVersion$1((_l = info === null || info === void 0 ? void 0 : info.se3) === null || _l === void 0 ? void 0 : _l.bootloader)),
|
|
41167
|
+
se04Boot: firstMeaningfulVersion$1(getImageVersion$1((_m = info === null || info === void 0 ? void 0 : info.se4) === null || _m === void 0 ? void 0 : _m.bootloader)),
|
|
41152
41168
|
};
|
|
41153
41169
|
};
|
|
41154
41170
|
const normalizeV1Status = (features) => {
|
|
@@ -41215,33 +41231,33 @@ const normalizeV1Verify = (features, protocolV1OneKeyFeatures) => {
|
|
|
41215
41231
|
});
|
|
41216
41232
|
};
|
|
41217
41233
|
const normalizeV2Verify = (deviceInfo) => {
|
|
41218
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z
|
|
41234
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
41219
41235
|
const info = deviceInfo;
|
|
41220
41236
|
return {
|
|
41221
41237
|
firmwareBuildId: getImageBuildId$1((_a = info === null || info === void 0 ? void 0 : info.fw) === null || _a === void 0 ? void 0 : _a.application),
|
|
41222
41238
|
firmwareHash: getImageHash$1((_b = info === null || info === void 0 ? void 0 : info.fw) === null || _b === void 0 ? void 0 : _b.application),
|
|
41223
41239
|
bootloaderBuildId: getImageBuildId$1((_c = info === null || info === void 0 ? void 0 : info.fw) === null || _c === void 0 ? void 0 : _c.bootloader),
|
|
41224
41240
|
bootloaderHash: getImageHash$1((_d = info === null || info === void 0 ? void 0 : info.fw) === null || _d === void 0 ? void 0 : _d.bootloader),
|
|
41225
|
-
boardBuildId: getImageBuildId$1((
|
|
41226
|
-
boardHash: getImageHash$1((
|
|
41227
|
-
bleBuildId: getImageBuildId$1((
|
|
41228
|
-
bleHash: getImageHash$1((
|
|
41229
|
-
se01BuildId: getImageBuildId$1((
|
|
41230
|
-
se01Hash: getImageHash$1((
|
|
41231
|
-
se02BuildId: getImageBuildId$1((
|
|
41232
|
-
se02Hash: getImageHash$1((
|
|
41233
|
-
se03BuildId: getImageBuildId$1((
|
|
41234
|
-
se03Hash: getImageHash$1((
|
|
41235
|
-
se04BuildId: getImageBuildId$1((
|
|
41236
|
-
se04Hash: getImageHash$1((
|
|
41237
|
-
se01BootBuildId: getImageBuildId$1((
|
|
41238
|
-
se01BootHash: getImageHash$1((
|
|
41239
|
-
se02BootBuildId: getImageBuildId$1((
|
|
41240
|
-
se02BootHash: getImageHash$1((
|
|
41241
|
-
se03BootBuildId: getImageBuildId$1((
|
|
41242
|
-
se03BootHash: getImageHash$1((
|
|
41243
|
-
se04BootBuildId: getImageBuildId$1((
|
|
41244
|
-
se04BootHash: getImageHash$1((
|
|
41241
|
+
boardBuildId: getImageBuildId$1((_e = info === null || info === void 0 ? void 0 : info.fw) === null || _e === void 0 ? void 0 : _e.romloader),
|
|
41242
|
+
boardHash: getImageHash$1((_f = info === null || info === void 0 ? void 0 : info.fw) === null || _f === void 0 ? void 0 : _f.romloader),
|
|
41243
|
+
bleBuildId: getImageBuildId$1((_g = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _g === void 0 ? void 0 : _g.application),
|
|
41244
|
+
bleHash: getImageHash$1((_h = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _h === void 0 ? void 0 : _h.application),
|
|
41245
|
+
se01BuildId: getImageBuildId$1((_j = info === null || info === void 0 ? void 0 : info.se1) === null || _j === void 0 ? void 0 : _j.application),
|
|
41246
|
+
se01Hash: getImageHash$1((_k = info === null || info === void 0 ? void 0 : info.se1) === null || _k === void 0 ? void 0 : _k.application),
|
|
41247
|
+
se02BuildId: getImageBuildId$1((_l = info === null || info === void 0 ? void 0 : info.se2) === null || _l === void 0 ? void 0 : _l.application),
|
|
41248
|
+
se02Hash: getImageHash$1((_m = info === null || info === void 0 ? void 0 : info.se2) === null || _m === void 0 ? void 0 : _m.application),
|
|
41249
|
+
se03BuildId: getImageBuildId$1((_o = info === null || info === void 0 ? void 0 : info.se3) === null || _o === void 0 ? void 0 : _o.application),
|
|
41250
|
+
se03Hash: getImageHash$1((_p = info === null || info === void 0 ? void 0 : info.se3) === null || _p === void 0 ? void 0 : _p.application),
|
|
41251
|
+
se04BuildId: getImageBuildId$1((_q = info === null || info === void 0 ? void 0 : info.se4) === null || _q === void 0 ? void 0 : _q.application),
|
|
41252
|
+
se04Hash: getImageHash$1((_r = info === null || info === void 0 ? void 0 : info.se4) === null || _r === void 0 ? void 0 : _r.application),
|
|
41253
|
+
se01BootBuildId: getImageBuildId$1((_s = info === null || info === void 0 ? void 0 : info.se1) === null || _s === void 0 ? void 0 : _s.bootloader),
|
|
41254
|
+
se01BootHash: getImageHash$1((_t = info === null || info === void 0 ? void 0 : info.se1) === null || _t === void 0 ? void 0 : _t.bootloader),
|
|
41255
|
+
se02BootBuildId: getImageBuildId$1((_u = info === null || info === void 0 ? void 0 : info.se2) === null || _u === void 0 ? void 0 : _u.bootloader),
|
|
41256
|
+
se02BootHash: getImageHash$1((_v = info === null || info === void 0 ? void 0 : info.se2) === null || _v === void 0 ? void 0 : _v.bootloader),
|
|
41257
|
+
se03BootBuildId: getImageBuildId$1((_w = info === null || info === void 0 ? void 0 : info.se3) === null || _w === void 0 ? void 0 : _w.bootloader),
|
|
41258
|
+
se03BootHash: getImageHash$1((_x = info === null || info === void 0 ? void 0 : info.se3) === null || _x === void 0 ? void 0 : _x.bootloader),
|
|
41259
|
+
se04BootBuildId: getImageBuildId$1((_y = info === null || info === void 0 ? void 0 : info.se4) === null || _y === void 0 ? void 0 : _y.bootloader),
|
|
41260
|
+
se04BootHash: getImageHash$1((_z = info === null || info === void 0 ? void 0 : info.se4) === null || _z === void 0 ? void 0 : _z.bootloader),
|
|
41245
41261
|
};
|
|
41246
41262
|
};
|
|
41247
41263
|
const normalizeRaw = ({ features, protocolV1OneKeyFeatures, protocolV2DeviceInfo, }) => (Object.assign(Object.assign(Object.assign({}, (features ? { features } : {})), (protocolV1OneKeyFeatures ? { protocolV1OneKeyFeatures } : {})), (protocolV2DeviceInfo ? { protocolV2DeviceInfo } : {})));
|
|
@@ -41449,47 +41465,54 @@ const buildProtocolV1FeaturesPayload = (protocolV1Features, previous) => {
|
|
|
41449
41465
|
},
|
|
41450
41466
|
sessionId,
|
|
41451
41467
|
raw: {
|
|
41452
|
-
protocolV1Features
|
|
41468
|
+
protocolV1Features,
|
|
41453
41469
|
},
|
|
41454
41470
|
};
|
|
41455
41471
|
};
|
|
41456
41472
|
const buildProtocolV2FeaturesPayload = (deviceInfo, previous) => {
|
|
41457
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69
|
|
41473
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69;
|
|
41458
41474
|
const info = deviceInfo;
|
|
41459
41475
|
const fwApplication = (_a = info === null || info === void 0 ? void 0 : info.fw) === null || _a === void 0 ? void 0 : _a.application;
|
|
41460
41476
|
const fwBootloader = (_b = info === null || info === void 0 ? void 0 : info.fw) === null || _b === void 0 ? void 0 : _b.bootloader;
|
|
41461
|
-
const fwBoard =
|
|
41462
|
-
const bleApplication = (
|
|
41477
|
+
const fwBoard = (_c = info === null || info === void 0 ? void 0 : info.fw) === null || _c === void 0 ? void 0 : _c.romloader;
|
|
41478
|
+
const bleApplication = (_d = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _d === void 0 ? void 0 : _d.application;
|
|
41463
41479
|
const status = info === null || info === void 0 ? void 0 : info.status;
|
|
41464
41480
|
const firmwareVersion = firstMeaningfulVersion(getImageVersion(fwApplication), previous === null || previous === void 0 ? void 0 : previous.firmwareVersion);
|
|
41465
41481
|
const bootloaderVersion = firstMeaningfulVersion(getImageVersion(fwBootloader), previous === null || previous === void 0 ? void 0 : previous.bootloaderVersion);
|
|
41466
41482
|
const boardVersion = firstMeaningfulVersion(getImageVersion(fwBoard), previous === null || previous === void 0 ? void 0 : previous.boardVersion);
|
|
41467
41483
|
const bleVersion = firstMeaningfulVersion(getImageVersion(bleApplication), previous === null || previous === void 0 ? void 0 : previous.bleVersion);
|
|
41468
|
-
const deviceId = (
|
|
41469
|
-
const serialNo = (
|
|
41470
|
-
const label = (
|
|
41471
|
-
const bleName = firstValue((
|
|
41472
|
-
const initialized = (
|
|
41473
|
-
const passphraseProtection = (
|
|
41474
|
-
const language = (
|
|
41475
|
-
const backupRequired = (
|
|
41484
|
+
const deviceId = (_e = status === null || status === void 0 ? void 0 : status.device_id) !== null && _e !== void 0 ? _e : null;
|
|
41485
|
+
const serialNo = (_g = firstValue((_f = info === null || info === void 0 ? void 0 : info.hw) === null || _f === void 0 ? void 0 : _f.serial_no, previous === null || previous === void 0 ? void 0 : previous.serialNo)) !== null && _g !== void 0 ? _g : '';
|
|
41486
|
+
const label = (_h = previous === null || previous === void 0 ? void 0 : previous.label) !== null && _h !== void 0 ? _h : null;
|
|
41487
|
+
const bleName = firstValue((_j = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _j === void 0 ? void 0 : _j.bt_adv_name, previous === null || previous === void 0 ? void 0 : previous.bleName);
|
|
41488
|
+
const initialized = (_k = firstValue(status === null || status === void 0 ? void 0 : status.init_states, previous === null || previous === void 0 ? void 0 : previous.initialized)) !== null && _k !== void 0 ? _k : null;
|
|
41489
|
+
const passphraseProtection = (_l = status === null || status === void 0 ? void 0 : status.passphrase_enabled) !== null && _l !== void 0 ? _l : null;
|
|
41490
|
+
const language = (_m = previous === null || previous === void 0 ? void 0 : previous.language) !== null && _m !== void 0 ? _m : null;
|
|
41491
|
+
const backupRequired = (_o = firstValue(status === null || status === void 0 ? void 0 : status.backup_required, previous === null || previous === void 0 ? void 0 : previous.backupRequired)) !== null && _o !== void 0 ? _o : null;
|
|
41476
41492
|
const bleEnabled = previous === null || previous === void 0 ? void 0 : previous.bleEnabled;
|
|
41477
|
-
const unlocked = (
|
|
41478
|
-
const attachToPinEnabled = (
|
|
41479
|
-
const unlockedAttachPin = (
|
|
41493
|
+
const unlocked = (_p = firstValue(status === null || status === void 0 ? void 0 : status.unlocked, previous === null || previous === void 0 ? void 0 : previous.unlocked)) !== null && _p !== void 0 ? _p : null;
|
|
41494
|
+
const attachToPinEnabled = (_q = status === null || status === void 0 ? void 0 : status.attach_to_pin_enabled) !== null && _q !== void 0 ? _q : null;
|
|
41495
|
+
const unlockedAttachPin = (_r = status === null || status === void 0 ? void 0 : status.unlocked_by_attach_to_pin) !== null && _r !== void 0 ? _r : undefined;
|
|
41496
|
+
const romloaderMode = isProtocolV2RomloaderDeviceInfo(info);
|
|
41480
41497
|
const bootloaderMode = isProtocolV2BootloaderDeviceInfo(info);
|
|
41481
|
-
|
|
41482
|
-
|
|
41483
|
-
|
|
41484
|
-
|
|
41485
|
-
|
|
41486
|
-
|
|
41487
|
-
|
|
41498
|
+
let mode = 'unknown';
|
|
41499
|
+
if (romloaderMode) {
|
|
41500
|
+
mode = 'romloader';
|
|
41501
|
+
}
|
|
41502
|
+
else if (bootloaderMode) {
|
|
41503
|
+
mode = 'bootloader';
|
|
41504
|
+
}
|
|
41505
|
+
else if (initialized === false) {
|
|
41506
|
+
mode = 'notInitialized';
|
|
41507
|
+
}
|
|
41508
|
+
else if (initialized === true) {
|
|
41509
|
+
mode = 'normal';
|
|
41510
|
+
}
|
|
41488
41511
|
return {
|
|
41489
41512
|
protocol: 'V2',
|
|
41490
|
-
protocolVersion: (
|
|
41513
|
+
protocolVersion: (_t = (_s = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.protocol_version) !== null && _s !== void 0 ? _s : previous === null || previous === void 0 ? void 0 : previous.protocolVersion) !== null && _t !== void 0 ? _t : null,
|
|
41491
41514
|
deviceType: hdShared.EDeviceType.Pro2,
|
|
41492
|
-
firmwareType: (
|
|
41515
|
+
firmwareType: (_u = previous === null || previous === void 0 ? void 0 : previous.firmwareType) !== null && _u !== void 0 ? _u : hdShared.EFirmwareType.Universal,
|
|
41493
41516
|
model: 'pro2',
|
|
41494
41517
|
vendor: 'onekey.so',
|
|
41495
41518
|
deviceId,
|
|
@@ -41501,7 +41524,7 @@ const buildProtocolV2FeaturesPayload = (deviceInfo, previous) => {
|
|
|
41501
41524
|
initialized,
|
|
41502
41525
|
bootloaderMode,
|
|
41503
41526
|
unlocked,
|
|
41504
|
-
firmwarePresent: (
|
|
41527
|
+
firmwarePresent: (_v = previous === null || previous === void 0 ? void 0 : previous.firmwarePresent) !== null && _v !== void 0 ? _v : null,
|
|
41505
41528
|
passphraseProtection,
|
|
41506
41529
|
pinProtection: null,
|
|
41507
41530
|
backupRequired,
|
|
@@ -41523,42 +41546,42 @@ const buildProtocolV2FeaturesPayload = (deviceInfo, previous) => {
|
|
|
41523
41546
|
bootloaderVersion,
|
|
41524
41547
|
boardVersion,
|
|
41525
41548
|
bleVersion,
|
|
41526
|
-
se01Version: firstMeaningfulVersion(getImageVersion((
|
|
41527
|
-
se02Version: firstMeaningfulVersion(getImageVersion((
|
|
41528
|
-
se03Version: firstMeaningfulVersion(getImageVersion((
|
|
41529
|
-
se04Version: firstMeaningfulVersion(getImageVersion((
|
|
41530
|
-
se01BootVersion: firstMeaningfulVersion(getImageVersion((
|
|
41531
|
-
se02BootVersion: firstMeaningfulVersion(getImageVersion((
|
|
41532
|
-
se03BootVersion: firstMeaningfulVersion(getImageVersion((
|
|
41533
|
-
se04BootVersion: firstMeaningfulVersion(getImageVersion((
|
|
41534
|
-
seVersion: (
|
|
41549
|
+
se01Version: firstMeaningfulVersion(getImageVersion((_w = info === null || info === void 0 ? void 0 : info.se1) === null || _w === void 0 ? void 0 : _w.application), previous === null || previous === void 0 ? void 0 : previous.se01Version),
|
|
41550
|
+
se02Version: firstMeaningfulVersion(getImageVersion((_x = info === null || info === void 0 ? void 0 : info.se2) === null || _x === void 0 ? void 0 : _x.application), previous === null || previous === void 0 ? void 0 : previous.se02Version),
|
|
41551
|
+
se03Version: firstMeaningfulVersion(getImageVersion((_y = info === null || info === void 0 ? void 0 : info.se3) === null || _y === void 0 ? void 0 : _y.application), previous === null || previous === void 0 ? void 0 : previous.se03Version),
|
|
41552
|
+
se04Version: firstMeaningfulVersion(getImageVersion((_z = info === null || info === void 0 ? void 0 : info.se4) === null || _z === void 0 ? void 0 : _z.application), previous === null || previous === void 0 ? void 0 : previous.se04Version),
|
|
41553
|
+
se01BootVersion: firstMeaningfulVersion(getImageVersion((_0 = info === null || info === void 0 ? void 0 : info.se1) === null || _0 === void 0 ? void 0 : _0.bootloader), previous === null || previous === void 0 ? void 0 : previous.se01BootVersion),
|
|
41554
|
+
se02BootVersion: firstMeaningfulVersion(getImageVersion((_1 = info === null || info === void 0 ? void 0 : info.se2) === null || _1 === void 0 ? void 0 : _1.bootloader), previous === null || previous === void 0 ? void 0 : previous.se02BootVersion),
|
|
41555
|
+
se03BootVersion: firstMeaningfulVersion(getImageVersion((_2 = info === null || info === void 0 ? void 0 : info.se3) === null || _2 === void 0 ? void 0 : _2.bootloader), previous === null || previous === void 0 ? void 0 : previous.se03BootVersion),
|
|
41556
|
+
se04BootVersion: firstMeaningfulVersion(getImageVersion((_3 = info === null || info === void 0 ? void 0 : info.se4) === null || _3 === void 0 ? void 0 : _3.bootloader), previous === null || previous === void 0 ? void 0 : previous.se04BootVersion),
|
|
41557
|
+
seVersion: (_4 = previous === null || previous === void 0 ? void 0 : previous.seVersion) !== null && _4 !== void 0 ? _4 : null,
|
|
41535
41558
|
verify: {
|
|
41536
|
-
firmwareBuildId: (
|
|
41537
|
-
firmwareHash: (
|
|
41538
|
-
bootloaderBuildId: (
|
|
41539
|
-
bootloaderHash: (
|
|
41540
|
-
boardBuildId: (
|
|
41541
|
-
boardHash: (
|
|
41542
|
-
bleBuildId: (
|
|
41543
|
-
bleHash: (
|
|
41544
|
-
se01BuildId: (
|
|
41545
|
-
se01Hash: (
|
|
41546
|
-
se02BuildId: (
|
|
41547
|
-
se02Hash: (
|
|
41548
|
-
se03BuildId: (
|
|
41549
|
-
se03Hash: (
|
|
41550
|
-
se04BuildId: (
|
|
41551
|
-
se04Hash: (
|
|
41552
|
-
se01BootBuildId: (
|
|
41553
|
-
se01BootHash: (
|
|
41554
|
-
se02BootBuildId: (
|
|
41555
|
-
se02BootHash: (
|
|
41556
|
-
se03BootBuildId: (
|
|
41557
|
-
se03BootHash: (
|
|
41558
|
-
se04BootBuildId: (
|
|
41559
|
-
se04BootHash: (
|
|
41559
|
+
firmwareBuildId: (_5 = getImageBuildId(fwApplication)) !== null && _5 !== void 0 ? _5 : (_6 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _6 === void 0 ? void 0 : _6.firmwareBuildId,
|
|
41560
|
+
firmwareHash: (_7 = getImageHash(fwApplication)) !== null && _7 !== void 0 ? _7 : (_8 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _8 === void 0 ? void 0 : _8.firmwareHash,
|
|
41561
|
+
bootloaderBuildId: (_9 = getImageBuildId(fwBootloader)) !== null && _9 !== void 0 ? _9 : (_10 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _10 === void 0 ? void 0 : _10.bootloaderBuildId,
|
|
41562
|
+
bootloaderHash: (_11 = getImageHash(fwBootloader)) !== null && _11 !== void 0 ? _11 : (_12 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _12 === void 0 ? void 0 : _12.bootloaderHash,
|
|
41563
|
+
boardBuildId: (_13 = getImageBuildId(fwBoard)) !== null && _13 !== void 0 ? _13 : (_14 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _14 === void 0 ? void 0 : _14.boardBuildId,
|
|
41564
|
+
boardHash: (_15 = getImageHash(fwBoard)) !== null && _15 !== void 0 ? _15 : (_16 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _16 === void 0 ? void 0 : _16.boardHash,
|
|
41565
|
+
bleBuildId: (_17 = getImageBuildId(bleApplication)) !== null && _17 !== void 0 ? _17 : (_18 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _18 === void 0 ? void 0 : _18.bleBuildId,
|
|
41566
|
+
bleHash: (_19 = getImageHash(bleApplication)) !== null && _19 !== void 0 ? _19 : (_20 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _20 === void 0 ? void 0 : _20.bleHash,
|
|
41567
|
+
se01BuildId: (_22 = getImageBuildId((_21 = info === null || info === void 0 ? void 0 : info.se1) === null || _21 === void 0 ? void 0 : _21.application)) !== null && _22 !== void 0 ? _22 : (_23 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _23 === void 0 ? void 0 : _23.se01BuildId,
|
|
41568
|
+
se01Hash: (_25 = getImageHash((_24 = info === null || info === void 0 ? void 0 : info.se1) === null || _24 === void 0 ? void 0 : _24.application)) !== null && _25 !== void 0 ? _25 : (_26 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _26 === void 0 ? void 0 : _26.se01Hash,
|
|
41569
|
+
se02BuildId: (_28 = getImageBuildId((_27 = info === null || info === void 0 ? void 0 : info.se2) === null || _27 === void 0 ? void 0 : _27.application)) !== null && _28 !== void 0 ? _28 : (_29 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _29 === void 0 ? void 0 : _29.se02BuildId,
|
|
41570
|
+
se02Hash: (_31 = getImageHash((_30 = info === null || info === void 0 ? void 0 : info.se2) === null || _30 === void 0 ? void 0 : _30.application)) !== null && _31 !== void 0 ? _31 : (_32 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _32 === void 0 ? void 0 : _32.se02Hash,
|
|
41571
|
+
se03BuildId: (_34 = getImageBuildId((_33 = info === null || info === void 0 ? void 0 : info.se3) === null || _33 === void 0 ? void 0 : _33.application)) !== null && _34 !== void 0 ? _34 : (_35 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _35 === void 0 ? void 0 : _35.se03BuildId,
|
|
41572
|
+
se03Hash: (_37 = getImageHash((_36 = info === null || info === void 0 ? void 0 : info.se3) === null || _36 === void 0 ? void 0 : _36.application)) !== null && _37 !== void 0 ? _37 : (_38 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _38 === void 0 ? void 0 : _38.se03Hash,
|
|
41573
|
+
se04BuildId: (_40 = getImageBuildId((_39 = info === null || info === void 0 ? void 0 : info.se4) === null || _39 === void 0 ? void 0 : _39.application)) !== null && _40 !== void 0 ? _40 : (_41 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _41 === void 0 ? void 0 : _41.se04BuildId,
|
|
41574
|
+
se04Hash: (_43 = getImageHash((_42 = info === null || info === void 0 ? void 0 : info.se4) === null || _42 === void 0 ? void 0 : _42.application)) !== null && _43 !== void 0 ? _43 : (_44 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _44 === void 0 ? void 0 : _44.se04Hash,
|
|
41575
|
+
se01BootBuildId: (_46 = getImageBuildId((_45 = info === null || info === void 0 ? void 0 : info.se1) === null || _45 === void 0 ? void 0 : _45.bootloader)) !== null && _46 !== void 0 ? _46 : (_47 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _47 === void 0 ? void 0 : _47.se01BootBuildId,
|
|
41576
|
+
se01BootHash: (_49 = getImageHash((_48 = info === null || info === void 0 ? void 0 : info.se1) === null || _48 === void 0 ? void 0 : _48.bootloader)) !== null && _49 !== void 0 ? _49 : (_50 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _50 === void 0 ? void 0 : _50.se01BootHash,
|
|
41577
|
+
se02BootBuildId: (_52 = getImageBuildId((_51 = info === null || info === void 0 ? void 0 : info.se2) === null || _51 === void 0 ? void 0 : _51.bootloader)) !== null && _52 !== void 0 ? _52 : (_53 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _53 === void 0 ? void 0 : _53.se02BootBuildId,
|
|
41578
|
+
se02BootHash: (_55 = getImageHash((_54 = info === null || info === void 0 ? void 0 : info.se2) === null || _54 === void 0 ? void 0 : _54.bootloader)) !== null && _55 !== void 0 ? _55 : (_56 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _56 === void 0 ? void 0 : _56.se02BootHash,
|
|
41579
|
+
se03BootBuildId: (_58 = getImageBuildId((_57 = info === null || info === void 0 ? void 0 : info.se3) === null || _57 === void 0 ? void 0 : _57.bootloader)) !== null && _58 !== void 0 ? _58 : (_59 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _59 === void 0 ? void 0 : _59.se03BootBuildId,
|
|
41580
|
+
se03BootHash: (_61 = getImageHash((_60 = info === null || info === void 0 ? void 0 : info.se3) === null || _60 === void 0 ? void 0 : _60.bootloader)) !== null && _61 !== void 0 ? _61 : (_62 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _62 === void 0 ? void 0 : _62.se03BootHash,
|
|
41581
|
+
se04BootBuildId: (_64 = getImageBuildId((_63 = info === null || info === void 0 ? void 0 : info.se4) === null || _63 === void 0 ? void 0 : _63.bootloader)) !== null && _64 !== void 0 ? _64 : (_65 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _65 === void 0 ? void 0 : _65.se04BootBuildId,
|
|
41582
|
+
se04BootHash: (_67 = getImageHash((_66 = info === null || info === void 0 ? void 0 : info.se4) === null || _66 === void 0 ? void 0 : _66.bootloader)) !== null && _67 !== void 0 ? _67 : (_68 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _68 === void 0 ? void 0 : _68.se04BootHash,
|
|
41560
41583
|
},
|
|
41561
|
-
sessionId: (
|
|
41584
|
+
sessionId: (_69 = previous === null || previous === void 0 ? void 0 : previous.sessionId) !== null && _69 !== void 0 ? _69 : null,
|
|
41562
41585
|
passphraseState: previous === null || previous === void 0 ? void 0 : previous.passphraseState,
|
|
41563
41586
|
unlockedAttachPin,
|
|
41564
41587
|
raw: {
|
|
@@ -47394,6 +47417,20 @@ class DeviceStatusGet extends BaseMethod {
|
|
|
47394
47417
|
}
|
|
47395
47418
|
}
|
|
47396
47419
|
|
|
47420
|
+
class DeviceGetOnboardingStatus extends BaseMethod {
|
|
47421
|
+
init() {
|
|
47422
|
+
this.requireProtocolV2 = true;
|
|
47423
|
+
this.skipForceUpdateCheck = true;
|
|
47424
|
+
this.useDevicePassphraseState = false;
|
|
47425
|
+
}
|
|
47426
|
+
run() {
|
|
47427
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47428
|
+
const { message } = yield this.device.commands.typedCall('DevGetOnboardingStatus', 'DevOnboardingStatus', {});
|
|
47429
|
+
return message;
|
|
47430
|
+
});
|
|
47431
|
+
}
|
|
47432
|
+
}
|
|
47433
|
+
|
|
47397
47434
|
class DeviceSessionGet extends BaseMethod {
|
|
47398
47435
|
init() {
|
|
47399
47436
|
this.requireProtocolV2 = true;
|
|
@@ -47606,14 +47643,109 @@ class DeviceSettingsPageShow extends BaseMethod {
|
|
|
47606
47643
|
}
|
|
47607
47644
|
}
|
|
47608
47645
|
|
|
47609
|
-
const
|
|
47610
|
-
|
|
47611
|
-
function getDefaultChunkSize() {
|
|
47646
|
+
const MIN_FILE_CHUNK_SIZE = 64;
|
|
47647
|
+
function getProtocolV2FileChunkLimit() {
|
|
47612
47648
|
const env = DataManager.getSettings('env');
|
|
47613
47649
|
return env && DataManager.isBleConnect(env)
|
|
47614
47650
|
? hdTransport.PROTOCOL_V2_BLE_FILE_CHUNK_SIZE
|
|
47615
47651
|
: hdTransport.PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
47616
47652
|
}
|
|
47653
|
+
function dataToUint8Array(data) {
|
|
47654
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47655
|
+
if (typeof data === 'string')
|
|
47656
|
+
return new TextEncoder().encode(data);
|
|
47657
|
+
if (data instanceof ArrayBuffer)
|
|
47658
|
+
return new Uint8Array(data);
|
|
47659
|
+
if (ArrayBuffer.isView(data)) {
|
|
47660
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
47661
|
+
}
|
|
47662
|
+
if (typeof Blob !== 'undefined' && data instanceof Blob) {
|
|
47663
|
+
return new Uint8Array(yield data.arrayBuffer());
|
|
47664
|
+
}
|
|
47665
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Unsupported FilesystemFileWrite data');
|
|
47666
|
+
});
|
|
47667
|
+
}
|
|
47668
|
+
function normalizeChunkSize$1(value, maxChunkSize) {
|
|
47669
|
+
const numeric = Number(value);
|
|
47670
|
+
if (!Number.isFinite(numeric) || numeric <= 0)
|
|
47671
|
+
return maxChunkSize;
|
|
47672
|
+
return Math.min(Math.max(Math.floor(numeric), MIN_FILE_CHUNK_SIZE), maxChunkSize);
|
|
47673
|
+
}
|
|
47674
|
+
function getDeviceTransferProgress$1(before, after, total) {
|
|
47675
|
+
if (!Number.isFinite(total) || total <= 0)
|
|
47676
|
+
return 100;
|
|
47677
|
+
if (before <= 0 && after < total)
|
|
47678
|
+
return 0;
|
|
47679
|
+
if (after >= total)
|
|
47680
|
+
return 100;
|
|
47681
|
+
return Math.min(Math.max(Math.ceil((after / total) * 100), 1), 99);
|
|
47682
|
+
}
|
|
47683
|
+
function getConfirmedProgress(processed, total, written, length) {
|
|
47684
|
+
if (Number.isFinite(processed) && Number.isFinite(total) && total > 0) {
|
|
47685
|
+
if (processed >= total)
|
|
47686
|
+
return 100;
|
|
47687
|
+
return Math.min(Math.max(Math.floor((processed / total) * 100), 0), 99);
|
|
47688
|
+
}
|
|
47689
|
+
if (length > 0)
|
|
47690
|
+
return written >= length ? 100 : Math.floor((written / length) * 100);
|
|
47691
|
+
return 100;
|
|
47692
|
+
}
|
|
47693
|
+
function writeProtocolV2File(options) {
|
|
47694
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
47695
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47696
|
+
(_a = options.throwIfAborted) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
47697
|
+
const data = yield dataToUint8Array(options.data);
|
|
47698
|
+
const dataLength = data.byteLength;
|
|
47699
|
+
const startOffset = Number.isFinite(options.offset) && Number(options.offset) > 0 ? Number(options.offset) : 0;
|
|
47700
|
+
const totalSize = Number.isFinite(options.totalSize) && Number(options.totalSize) > 0
|
|
47701
|
+
? Number(options.totalSize)
|
|
47702
|
+
: startOffset + dataLength;
|
|
47703
|
+
if (totalSize < startOffset + dataLength) {
|
|
47704
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite totalSize ${totalSize} is smaller than offset + data length ${startOffset + dataLength}`);
|
|
47705
|
+
}
|
|
47706
|
+
const chunkSize = normalizeChunkSize$1((_b = options.chunkSize) !== null && _b !== void 0 ? _b : options.chunkLen, getProtocolV2FileChunkLimit());
|
|
47707
|
+
let written = 0;
|
|
47708
|
+
let chunks = 0;
|
|
47709
|
+
let lastMessage;
|
|
47710
|
+
const startTime = Date.now();
|
|
47711
|
+
while (written < dataLength) {
|
|
47712
|
+
(_c = options.throwIfAborted) === null || _c === void 0 ? void 0 : _c.call(options);
|
|
47713
|
+
const chunk = data.slice(written, Math.min(written + chunkSize, dataLength));
|
|
47714
|
+
const offset = startOffset + written;
|
|
47715
|
+
const progress = (_d = options.uiPercentage) !== null && _d !== void 0 ? _d : getDeviceTransferProgress$1(offset, offset + chunk.byteLength, totalSize);
|
|
47716
|
+
const response = yield options.commands.typedCall('FilesystemFileWrite', 'FilesystemFile', {
|
|
47717
|
+
file: { path: options.path, offset, total_size: totalSize, data: chunk },
|
|
47718
|
+
overwrite: chunks === 0 ? (_e = options.overwrite) !== null && _e !== void 0 ? _e : false : false,
|
|
47719
|
+
append: (_f = options.append) !== null && _f !== void 0 ? _f : false,
|
|
47720
|
+
ui_percentage: progress,
|
|
47721
|
+
}, { timeoutMs: options.timeoutMs });
|
|
47722
|
+
(_g = options.throwIfAborted) === null || _g === void 0 ? void 0 : _g.call(options);
|
|
47723
|
+
lastMessage = response.message;
|
|
47724
|
+
const processedByte = Number((_h = response.message) === null || _h === void 0 ? void 0 : _h.processed_byte);
|
|
47725
|
+
written =
|
|
47726
|
+
Number.isFinite(processedByte) && processedByte > offset
|
|
47727
|
+
? processedByte - startOffset
|
|
47728
|
+
: written + chunk.byteLength;
|
|
47729
|
+
if (written > dataLength) {
|
|
47730
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite invalid processed_byte ${processedByte}`);
|
|
47731
|
+
}
|
|
47732
|
+
chunks += 1;
|
|
47733
|
+
const elapsedMs = Date.now() - startTime;
|
|
47734
|
+
const transferredBytes = Math.min(written, dataLength);
|
|
47735
|
+
(_j = options.onProgress) === null || _j === void 0 ? void 0 : _j.call(options, {
|
|
47736
|
+
progress: getConfirmedProgress(startOffset + written, totalSize, written, dataLength),
|
|
47737
|
+
transferredBytes,
|
|
47738
|
+
totalBytes: dataLength,
|
|
47739
|
+
rateBytesPerSecond: elapsedMs > 0 ? Math.round((transferredBytes / elapsedMs) * 1000) : undefined,
|
|
47740
|
+
elapsedMs,
|
|
47741
|
+
});
|
|
47742
|
+
}
|
|
47743
|
+
return Object.assign(Object.assign({}, lastMessage), { path: options.path, offset: startOffset, total_size: totalSize, processed_byte: startOffset + written, chunks });
|
|
47744
|
+
});
|
|
47745
|
+
}
|
|
47746
|
+
|
|
47747
|
+
const WALLPAPER_DIRECTORY = 'vol0:/wallpapers/user';
|
|
47748
|
+
const SAFE_FILE_NAME = /^[A-Za-z0-9_-]+(?:\.bin)?$/;
|
|
47617
47749
|
function normalizeFileName(fileName, data) {
|
|
47618
47750
|
if (fileName !== undefined && (!fileName || !SAFE_FILE_NAME.test(fileName))) {
|
|
47619
47751
|
throw invalidParameter('Parameter [fileName] may only contain letters, numbers, underscores, hyphens and an optional .bin suffix.');
|
|
@@ -47668,38 +47800,22 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
47668
47800
|
});
|
|
47669
47801
|
}
|
|
47670
47802
|
upload() {
|
|
47671
|
-
var _a, _b;
|
|
47672
47803
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47673
47804
|
if (this.uploaded)
|
|
47674
47805
|
return;
|
|
47675
47806
|
const encoded = this.encoded;
|
|
47676
47807
|
if (!encoded)
|
|
47677
47808
|
throw invalidParameter('Wallpaper data has not been initialized.');
|
|
47678
|
-
|
|
47679
|
-
|
|
47680
|
-
|
|
47681
|
-
|
|
47682
|
-
|
|
47683
|
-
|
|
47684
|
-
|
|
47685
|
-
|
|
47686
|
-
|
|
47687
|
-
|
|
47688
|
-
total_size: encoded.data.byteLength,
|
|
47689
|
-
data: chunk,
|
|
47690
|
-
},
|
|
47691
|
-
overwrite: offset === 0,
|
|
47692
|
-
append: false,
|
|
47693
|
-
ui_percentage: Math.min(Math.ceil(((offset + chunk.byteLength) / encoded.data.byteLength) * 100), 100),
|
|
47694
|
-
}, { timeoutMs: undefined });
|
|
47695
|
-
const processedByte = Number((_b = response.message) === null || _b === void 0 ? void 0 : _b.processed_byte);
|
|
47696
|
-
offset = Number.isFinite(processedByte) && processedByte > offset
|
|
47697
|
-
? processedByte
|
|
47698
|
-
: offset + chunk.byteLength;
|
|
47699
|
-
if (offset > encoded.data.byteLength) {
|
|
47700
|
-
throw invalidParameter(`Invalid processed_byte returned by device: ${processedByte}.`);
|
|
47701
|
-
}
|
|
47702
|
-
}
|
|
47809
|
+
yield writeProtocolV2File({
|
|
47810
|
+
commands: this.device.commands,
|
|
47811
|
+
path: this.path,
|
|
47812
|
+
data: encoded.data,
|
|
47813
|
+
totalSize: encoded.data.byteLength,
|
|
47814
|
+
chunkSize: this.params.chunkSize,
|
|
47815
|
+
overwrite: true,
|
|
47816
|
+
append: false,
|
|
47817
|
+
throwIfAborted: () => this.throwIfAborted(),
|
|
47818
|
+
});
|
|
47703
47819
|
this.uploaded = true;
|
|
47704
47820
|
});
|
|
47705
47821
|
}
|
|
@@ -47711,9 +47827,8 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
47711
47827
|
throw invalidParameter('Wallpaper data has not been initialized.');
|
|
47712
47828
|
yield this.ensureDirectory();
|
|
47713
47829
|
yield this.upload();
|
|
47714
|
-
const response = yield this.device.commands.typedCall('
|
|
47715
|
-
|
|
47716
|
-
path: this.path,
|
|
47830
|
+
const response = yield this.device.commands.typedCall('DeviceSettingsSet', 'Success', {
|
|
47831
|
+
settings: { wallpaper_path: this.path },
|
|
47717
47832
|
});
|
|
47718
47833
|
return {
|
|
47719
47834
|
path: this.path,
|
|
@@ -47800,7 +47915,7 @@ function getProtocolV2FileReadChunkLimit() {
|
|
|
47800
47915
|
}
|
|
47801
47916
|
return hdTransport.PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
47802
47917
|
}
|
|
47803
|
-
function normalizeChunkSize
|
|
47918
|
+
function normalizeChunkSize(value, maxChunkSize) {
|
|
47804
47919
|
const numeric = Number(value);
|
|
47805
47920
|
if (!Number.isFinite(numeric) || numeric <= 0)
|
|
47806
47921
|
return maxChunkSize;
|
|
@@ -47840,7 +47955,7 @@ function toUint8Array(value) {
|
|
|
47840
47955
|
}
|
|
47841
47956
|
return new Uint8Array(0);
|
|
47842
47957
|
}
|
|
47843
|
-
function getDeviceTransferProgress
|
|
47958
|
+
function getDeviceTransferProgress(bytesBeforeChunk, bytesAfterChunk, totalBytes) {
|
|
47844
47959
|
if (!Number.isFinite(totalBytes) || totalBytes <= 0) {
|
|
47845
47960
|
return 100;
|
|
47846
47961
|
}
|
|
@@ -47871,7 +47986,7 @@ class FileRead extends BaseMethod {
|
|
|
47871
47986
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47872
47987
|
const startOffset = (_a = this.params.offset) !== null && _a !== void 0 ? _a : 0;
|
|
47873
47988
|
const requestedLength = Number(this.params.totalSize);
|
|
47874
|
-
const chunkSize = normalizeChunkSize
|
|
47989
|
+
const chunkSize = normalizeChunkSize(this.params.chunkLen, getProtocolV2FileReadChunkLimit());
|
|
47875
47990
|
let totalLength = Number.isFinite(requestedLength) && requestedLength > 0 ? requestedLength : 0;
|
|
47876
47991
|
if (totalLength === 0) {
|
|
47877
47992
|
const pathInfoRes = yield this.device.commands.typedCall('FilesystemPathInfoQuery', 'FilesystemPathInfo', {
|
|
@@ -47892,7 +48007,7 @@ class FileRead extends BaseMethod {
|
|
|
47892
48007
|
while (read < totalLength) {
|
|
47893
48008
|
const readLen = Math.min(chunkSize, totalLength - read);
|
|
47894
48009
|
const offset = startOffset + read;
|
|
47895
|
-
const progress = (_e = this.params.uiPercentage) !== null && _e !== void 0 ? _e : getDeviceTransferProgress
|
|
48010
|
+
const progress = (_e = this.params.uiPercentage) !== null && _e !== void 0 ? _e : getDeviceTransferProgress(read, read + readLen, totalLength);
|
|
47896
48011
|
const res = yield this.device.commands.typedCall('FilesystemFileRead', 'FilesystemFile', {
|
|
47897
48012
|
file: {
|
|
47898
48013
|
path: this.params.path,
|
|
@@ -47921,62 +48036,6 @@ class FileRead extends BaseMethod {
|
|
|
47921
48036
|
}
|
|
47922
48037
|
}
|
|
47923
48038
|
|
|
47924
|
-
const MIN_FILE_CHUNK_SIZE = 64;
|
|
47925
|
-
function getProtocolV2FileChunkLimit() {
|
|
47926
|
-
const env = DataManager.getSettings('env');
|
|
47927
|
-
if (env && DataManager.isBleConnect(env)) {
|
|
47928
|
-
return hdTransport.PROTOCOL_V2_BLE_FILE_CHUNK_SIZE;
|
|
47929
|
-
}
|
|
47930
|
-
return hdTransport.PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
47931
|
-
}
|
|
47932
|
-
function dataToUint8Array(data) {
|
|
47933
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47934
|
-
if (typeof data === 'string') {
|
|
47935
|
-
return new TextEncoder().encode(data);
|
|
47936
|
-
}
|
|
47937
|
-
if (data instanceof ArrayBuffer) {
|
|
47938
|
-
return new Uint8Array(data);
|
|
47939
|
-
}
|
|
47940
|
-
if (ArrayBuffer.isView(data)) {
|
|
47941
|
-
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
47942
|
-
}
|
|
47943
|
-
if (typeof Blob !== 'undefined' && data instanceof Blob) {
|
|
47944
|
-
return new Uint8Array(yield data.arrayBuffer());
|
|
47945
|
-
}
|
|
47946
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Unsupported FilesystemFileWrite data');
|
|
47947
|
-
});
|
|
47948
|
-
}
|
|
47949
|
-
function normalizeChunkSize(value, maxChunkSize) {
|
|
47950
|
-
const numeric = Number(value);
|
|
47951
|
-
if (!Number.isFinite(numeric) || numeric <= 0)
|
|
47952
|
-
return maxChunkSize;
|
|
47953
|
-
return Math.min(Math.max(Math.floor(numeric), MIN_FILE_CHUNK_SIZE), maxChunkSize);
|
|
47954
|
-
}
|
|
47955
|
-
function getConfirmedProgress(processedByte, totalSize, written, dataLength) {
|
|
47956
|
-
if (Number.isFinite(processedByte) && Number.isFinite(totalSize) && totalSize > 0) {
|
|
47957
|
-
if (processedByte >= totalSize)
|
|
47958
|
-
return 100;
|
|
47959
|
-
return Math.min(Math.max(Math.floor((processedByte / totalSize) * 100), 0), 99);
|
|
47960
|
-
}
|
|
47961
|
-
if (dataLength > 0) {
|
|
47962
|
-
if (written >= dataLength)
|
|
47963
|
-
return 100;
|
|
47964
|
-
return Math.min(Math.max(Math.floor((written / dataLength) * 100), 0), 99);
|
|
47965
|
-
}
|
|
47966
|
-
return 100;
|
|
47967
|
-
}
|
|
47968
|
-
function getDeviceTransferProgress(bytesBeforeChunk, bytesAfterChunk, totalBytes) {
|
|
47969
|
-
if (!Number.isFinite(totalBytes) || totalBytes <= 0) {
|
|
47970
|
-
return 100;
|
|
47971
|
-
}
|
|
47972
|
-
if (bytesBeforeChunk <= 0 && bytesAfterChunk < totalBytes) {
|
|
47973
|
-
return 0;
|
|
47974
|
-
}
|
|
47975
|
-
if (bytesAfterChunk >= totalBytes) {
|
|
47976
|
-
return 100;
|
|
47977
|
-
}
|
|
47978
|
-
return Math.min(Math.max(Math.ceil((bytesAfterChunk / totalBytes) * 100), 1), 99);
|
|
47979
|
-
}
|
|
47980
48039
|
class FileWrite extends BaseMethod {
|
|
47981
48040
|
init() {
|
|
47982
48041
|
var _a, _b;
|
|
@@ -48000,77 +48059,26 @@ class FileWrite extends BaseMethod {
|
|
|
48000
48059
|
};
|
|
48001
48060
|
}
|
|
48002
48061
|
run() {
|
|
48003
|
-
var _a, _b, _c, _d, _e, _f;
|
|
48004
48062
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48005
|
-
|
|
48006
|
-
|
|
48007
|
-
|
|
48008
|
-
|
|
48009
|
-
|
|
48010
|
-
|
|
48011
|
-
|
|
48012
|
-
|
|
48013
|
-
:
|
|
48014
|
-
|
|
48015
|
-
|
|
48016
|
-
|
|
48017
|
-
|
|
48018
|
-
|
|
48019
|
-
|
|
48020
|
-
|
|
48021
|
-
|
|
48022
|
-
|
|
48023
|
-
|
|
48024
|
-
const timeoutMs = this.params.timeoutMs === undefined ? undefined : Number(this.params.timeoutMs);
|
|
48025
|
-
while (written < dataLength) {
|
|
48026
|
-
this.throwIfAborted();
|
|
48027
|
-
const chunkEnd = Math.min(written + chunkSize, dataLength);
|
|
48028
|
-
const chunk = data.slice(written, chunkEnd);
|
|
48029
|
-
const offset = startOffset + written;
|
|
48030
|
-
const isFirstChunk = chunkIndex === 0;
|
|
48031
|
-
const progress = (_e = this.params.uiPercentage) !== null && _e !== void 0 ? _e : getDeviceTransferProgress(offset, offset + chunk.byteLength, totalSize);
|
|
48032
|
-
const res = yield this.device.commands.typedCall('FilesystemFileWrite', 'FilesystemFile', {
|
|
48033
|
-
file: {
|
|
48034
|
-
path: this.params.path,
|
|
48035
|
-
offset,
|
|
48036
|
-
total_size: totalSize,
|
|
48037
|
-
data: chunk,
|
|
48038
|
-
},
|
|
48039
|
-
overwrite: isFirstChunk ? overwrite : false,
|
|
48040
|
-
append,
|
|
48041
|
-
ui_percentage: progress,
|
|
48042
|
-
}, {
|
|
48043
|
-
timeoutMs,
|
|
48044
|
-
});
|
|
48045
|
-
this.throwIfAborted();
|
|
48046
|
-
lastMessage = res.message;
|
|
48047
|
-
const processedByte = Number((_f = res.message) === null || _f === void 0 ? void 0 : _f.processed_byte);
|
|
48048
|
-
if (Number.isFinite(processedByte) && processedByte > offset) {
|
|
48049
|
-
written = processedByte - startOffset;
|
|
48050
|
-
}
|
|
48051
|
-
else {
|
|
48052
|
-
written += chunk.byteLength;
|
|
48053
|
-
}
|
|
48054
|
-
if (written > dataLength) {
|
|
48055
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite invalid processed_byte ${processedByte}`);
|
|
48056
|
-
}
|
|
48057
|
-
const confirmedProcessedByte = Number.isFinite(processedByte) && processedByte > offset
|
|
48058
|
-
? processedByte
|
|
48059
|
-
: startOffset + written;
|
|
48060
|
-
if (typeof this.postMessage === 'function') {
|
|
48061
|
-
const elapsedMs = Date.now() - startTime;
|
|
48062
|
-
const transferredBytes = Math.min(written, dataLength);
|
|
48063
|
-
this.postMessage(createUiMessage(UI_REQUEST.DEVICE_PROGRESS, {
|
|
48064
|
-
progress: getConfirmedProgress(confirmedProcessedByte, totalSize, written, dataLength),
|
|
48065
|
-
transferredBytes,
|
|
48066
|
-
totalBytes: dataLength,
|
|
48067
|
-
rateBytesPerSecond: elapsedMs > 0 ? Math.round((transferredBytes / elapsedMs) * 1000) : undefined,
|
|
48068
|
-
elapsedMs,
|
|
48069
|
-
}));
|
|
48070
|
-
}
|
|
48071
|
-
chunkIndex += 1;
|
|
48072
|
-
}
|
|
48073
|
-
return Promise.resolve(Object.assign(Object.assign({}, lastMessage), { path: this.params.path, offset: startOffset, total_size: totalSize, processed_byte: startOffset + written, chunks: chunkIndex }));
|
|
48063
|
+
return writeProtocolV2File({
|
|
48064
|
+
commands: this.device.commands,
|
|
48065
|
+
path: this.params.path,
|
|
48066
|
+
data: this.params.data,
|
|
48067
|
+
offset: this.params.offset,
|
|
48068
|
+
totalSize: this.params.totalSize,
|
|
48069
|
+
chunkSize: this.params.chunkSize,
|
|
48070
|
+
chunkLen: this.params.chunkLen,
|
|
48071
|
+
overwrite: this.params.overwrite,
|
|
48072
|
+
append: this.params.append,
|
|
48073
|
+
uiPercentage: this.params.uiPercentage,
|
|
48074
|
+
timeoutMs: this.params.timeoutMs === undefined ? undefined : Number(this.params.timeoutMs),
|
|
48075
|
+
throwIfAborted: () => this.throwIfAborted(),
|
|
48076
|
+
onProgress: payload => {
|
|
48077
|
+
if (typeof this.postMessage === 'function') {
|
|
48078
|
+
this.postMessage(createUiMessage(UI_REQUEST.DEVICE_PROGRESS, payload));
|
|
48079
|
+
}
|
|
48080
|
+
},
|
|
48081
|
+
});
|
|
48074
48082
|
});
|
|
48075
48083
|
}
|
|
48076
48084
|
}
|
|
@@ -57408,6 +57416,7 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
|
57408
57416
|
deviceReboot: DeviceReboot,
|
|
57409
57417
|
deviceInfoGet: DeviceInfoGet,
|
|
57410
57418
|
deviceStatusGet: DeviceStatusGet,
|
|
57419
|
+
deviceGetOnboardingStatus: DeviceGetOnboardingStatus,
|
|
57411
57420
|
deviceSessionGet: DeviceSessionGet,
|
|
57412
57421
|
deviceFirmwareUpdate: DeviceFirmwareUpdate,
|
|
57413
57422
|
deviceGetFirmwareUpdateStatus: DeviceGetFirmwareUpdateStatus,
|