@onekeyfe/hd-core 1.2.0-alpha.147 → 1.2.0-alpha.149
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 +177 -2
- package/__tests__/device-utils.test.ts +8 -0
- package/__tests__/deviceUploadNft.test.ts +3 -0
- package/__tests__/protocol-v2-resources.test.ts +35 -89
- package/__tests__/protocol-v2-unlock-policy.test.ts +72 -0
- package/__tests__/protocol-v2.test.ts +51 -188
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceReboot.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceReboot.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/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +6 -0
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/index.d.ts +17 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +212 -314
- package/dist/protocols/protocol-v2/resources.d.ts +11 -7
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/types/settings.d.ts +0 -13
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +61 -238
- package/src/api/PromptWebDeviceAccess.ts +2 -2
- package/src/api/device/DeviceRebootToBoardloader.ts +3 -1
- package/src/api/device/DeviceRebootToBootloader.ts +3 -1
- package/src/api/protocol-v2/DeviceReboot.ts +5 -0
- package/src/api/protocol-v2/DeviceUploadNft.ts +5 -1
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +5 -1
- package/src/core/index.ts +31 -106
- package/src/device/Device.ts +71 -8
- package/src/index.ts +0 -4
- package/src/protocols/protocol-v2/resources.ts +92 -102
- package/src/types/settings.ts +0 -15
- package/src/utils/deviceInfoUtils.ts +7 -2
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { FirmwareUpdateV4Target } from '../../types/api/firmwareUpdate';
|
|
1
|
+
import type { IProtocolV2Resources, IVersionArray } from '../../types';
|
|
3
2
|
export declare const PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH = "vol0:/loaders/bootloader/boot_resource.okpkg";
|
|
4
3
|
export declare const PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH: string;
|
|
5
4
|
export declare const PROTOCOL_V2_ROM_PARAMS_PACKAGE_PATH = "vol0:/loaders/rom/params.okpkg";
|
|
5
|
+
export declare const PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE = 24464;
|
|
6
6
|
export declare function parseProtocolV2Resources(value: unknown): IProtocolV2Resources | undefined;
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export type ProtocolV2ResourcePackageHeader = {
|
|
8
|
+
version: IVersionArray;
|
|
9
|
+
payloadLength: number;
|
|
10
|
+
devicePath: string;
|
|
11
|
+
payloadHash: string;
|
|
12
|
+
headerHash: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function parseProtocolV2ResourcePackageHeader(bytes: Uint8Array, packageSize: number): ProtocolV2ResourcePackageHeader;
|
|
15
|
+
export declare function parseProtocolV2ResourcePackage(binary: ArrayBuffer | Uint8Array): ProtocolV2ResourcePackageHeader;
|
|
12
16
|
//# sourceMappingURL=resources.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/resources.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/resources.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEvE,eAAO,MAAM,sCAAsC,iDACH,CAAC;AACjD,eAAO,MAAM,8CAA8C,QAAsD,CAAC;AAClH,eAAO,MAAM,mCAAmC,mCAAmC,CAAC;AACpF,eAAO,MAAM,wCAAwC,QAAS,CAAC;AAW/D,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS,CA8BzF;AAoDD,MAAM,MAAM,+BAA+B,GAAG;IAC5C,OAAO,EAAE,aAAa,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,oCAAoC,CAClD,KAAK,EAAE,UAAU,EACjB,WAAW,EAAE,MAAM,GAClB,+BAA+B,CAyCjC;AAED,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,WAAW,GAAG,UAAU,GAC/B,+BAA+B,CAGjC"}
|
package/dist/types/settings.d.ts
CHANGED
|
@@ -43,19 +43,6 @@ export type IProtocolV2ResourceSource = {
|
|
|
43
43
|
export type IProtocolV2Resources = {
|
|
44
44
|
source: IProtocolV2ResourceSource;
|
|
45
45
|
};
|
|
46
|
-
export type IProtocolV2ResourceManifestFile = {
|
|
47
|
-
archive_path: string;
|
|
48
|
-
original_name?: string;
|
|
49
|
-
device_path: string;
|
|
50
|
-
size: number;
|
|
51
|
-
sha256: string;
|
|
52
|
-
signed?: boolean;
|
|
53
|
-
sig_algo?: string;
|
|
54
|
-
payload_version?: string | null;
|
|
55
|
-
};
|
|
56
|
-
export type IProtocolV2ResourceManifest = {
|
|
57
|
-
files: IProtocolV2ResourceManifestFile[];
|
|
58
|
-
};
|
|
59
46
|
export type IFirmwareReleaseInfo = {
|
|
60
47
|
required: boolean;
|
|
61
48
|
url: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/types/settings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,KAAK,GACL,cAAc,GACd,UAAU,GACV,cAAc,GACd,QAAQ,GACR,gBAAgB,GAChB,iBAAiB,GACjB,UAAU,GACV,UAAU,GACV,UAAU,CAAC;AACf,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,GAAG,EAAE,YAAY,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oBAAoB,CAAC,EAAE,aAAa,GAAG,eAAe,CAAC;IACvD,eAAe,CAAC,EAAE,oBAAoB,CAAC;IACvC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,oBAAoB,GAAG,IAAI,CA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MAAM,CAAC;QACrB,SAAS,EAAE;aACR,CAAC,IAAI,OAAO,GAAG,MAAM;SACvB,CAAC;KACH,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;CAC7B,GAAG,aAAa,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deviceInfoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceInfoUtils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAKlE,eAAO,MAAM,aAAa,cAAe,mBAAmB,KAAG,WAClC,CAAC;AAM9B,eAAO,MAAM,sBAAsB,UAAW,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"deviceInfoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceInfoUtils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAKlE,eAAO,MAAM,aAAa,cAAe,mBAAmB,KAAG,WAClC,CAAC;AAM9B,eAAO,MAAM,sBAAsB,UAAW,MAAM,KAAG,WAmBtD,CAAC;AAMF,eAAO,MAAM,gBAAgB,cAAe,mBAAmB,KAAG,MAAM,GAAG,IAC3C,CAAC;AAKjC,eAAO,MAAM,iBAAiB,cAAe,mBAAmB,KAAG,MAClC,CAAC;AAKlC,eAAO,MAAM,aAAa,cANmB,mBAAmB,KAAG,MAMrB,CAAC;AAK/C,eAAO,MAAM,cAAc,cAAe,mBAAmB,kBAkB5D,CAAC;AAMF,eAAO,MAAM,qBAAqB,aACtB,mBAAmB,GAAG,SAAS,iCACV,WAAW,GAAG,YAAY,KAAK,aAAa,GAAG,SAAS,KACtF,aAAa,GAAG,SAyBlB,CAAC;AAEF,eAAO,MAAM,eAAe,cAAe,mBAAmB,gDACzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.149",
|
|
4
4
|
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.149",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.149",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"buffer": "^6.0.3",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/w3c-web-usb": "^1.0.10",
|
|
47
47
|
"@types/web-bluetooth": "^0.0.21"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "0c2b72c1edbafb2b738e3eb0b9ecdad8d8b92df7"
|
|
50
50
|
}
|
|
@@ -32,8 +32,11 @@ import {
|
|
|
32
32
|
} from '../protocols/protocol-v2';
|
|
33
33
|
import { requestProtocolV2DeviceInfo } from '../protocols/protocol-v2/features';
|
|
34
34
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH,
|
|
36
|
+
PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE,
|
|
37
|
+
parseProtocolV2ResourcePackage,
|
|
38
|
+
parseProtocolV2ResourcePackageHeader,
|
|
39
|
+
type ProtocolV2ResourcePackageHeader,
|
|
37
40
|
} from '../protocols/protocol-v2/resources';
|
|
38
41
|
import {
|
|
39
42
|
getProtocolV2UnknownErrorText,
|
|
@@ -70,7 +73,6 @@ import type {
|
|
|
70
73
|
Features,
|
|
71
74
|
IFirmwareReleaseInfo,
|
|
72
75
|
IProtocolV2FirmwareComponent,
|
|
73
|
-
IProtocolV2ResourceManifestFile,
|
|
74
76
|
IVersionArray,
|
|
75
77
|
KnownDevice,
|
|
76
78
|
} from '../types';
|
|
@@ -109,21 +111,9 @@ const PROTOCOL_V2_TRANSFER_PROGRESS_HEARTBEAT_MS = 1000;
|
|
|
109
111
|
const PROTOCOL_V2_INSTALL_STATUS_CONFLICT_CODE = 'FirmwareInstallStatusConflict';
|
|
110
112
|
const PROTOCOL_V2_INSTALL_FAILED_CODE = 'FirmwareInstallFailed';
|
|
111
113
|
const PROTOCOL_V2_INSTALL_TIMEOUT_CODE = 'FirmwareInstallTimeout';
|
|
112
|
-
const PROTOCOL_V2_OKPP_HEADER_SIZE = 0x52a0;
|
|
113
|
-
const PROTOCOL_V2_OKPP_PAYLOAD_HASH_OFFSET = 0x200;
|
|
114
|
-
const PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET = 0x240;
|
|
115
|
-
const PROTOCOL_V2_OKPP_HASH_SIZE = 64;
|
|
116
|
-
const PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES = 1024 * 1024;
|
|
117
114
|
const PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT = 512;
|
|
118
115
|
const PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES = 256 * 1024 * 1024;
|
|
119
116
|
|
|
120
|
-
const getProtocolV2LocalResourceArchivePath = (entryName: string) => {
|
|
121
|
-
const match = entryName.match(
|
|
122
|
-
/(?:^|\/)((?:bundles\/|loaders\/(?:bootloader|rom)\/).+\.okpkg)$/iu
|
|
123
|
-
);
|
|
124
|
-
return match?.[1];
|
|
125
|
-
};
|
|
126
|
-
|
|
127
117
|
const PROTOCOL_V2_NEO_UNSUPPORTED_TARGETS = new Set<FirmwareUpdateV4Target>(['se03', 'se04']);
|
|
128
118
|
|
|
129
119
|
const getProtocolV2ZipEntrySizes = (entry: JSZip.JSZipObject) => {
|
|
@@ -241,6 +231,11 @@ type ProtocolV2ResourceBundleSource = {
|
|
|
241
231
|
type ProtocolV2LocalResourceArchive = {
|
|
242
232
|
binary: ArrayBuffer;
|
|
243
233
|
materializedEntries: FirmwareMemoryArtifactEntry[];
|
|
234
|
+
resources: Array<{
|
|
235
|
+
entryName: string;
|
|
236
|
+
binary: ArrayBuffer;
|
|
237
|
+
header: ProtocolV2ResourcePackageHeader;
|
|
238
|
+
}>;
|
|
244
239
|
};
|
|
245
240
|
|
|
246
241
|
type JSZipSizedEntry = JSZip.JSZipObject & {
|
|
@@ -255,13 +250,6 @@ type ProtocolV2TransferBatch = {
|
|
|
255
250
|
resourceSources: ProtocolV2ResourceBundleSource[];
|
|
256
251
|
};
|
|
257
252
|
|
|
258
|
-
type ProtocolV2OkppHeader = {
|
|
259
|
-
type: string;
|
|
260
|
-
version: IVersionArray;
|
|
261
|
-
payloadHash: string;
|
|
262
|
-
headerHash: string;
|
|
263
|
-
};
|
|
264
|
-
|
|
265
253
|
const PROTOCOL_V2_REMOTE_COMPONENT_TARGETS: Readonly<
|
|
266
254
|
Record<string, ProtocolV2RemoteComponentTarget>
|
|
267
255
|
> = {
|
|
@@ -313,18 +301,9 @@ const PROTOCOL_V2_FIRMWARE_STAGING_PATHS = new Set(
|
|
|
313
301
|
)
|
|
314
302
|
);
|
|
315
303
|
|
|
316
|
-
const PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH = 'vol0:/loaders/bootloader/boot_resource.okpkg';
|
|
317
|
-
const PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH = `${PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH}.staging`;
|
|
318
|
-
|
|
319
304
|
const isProtocolV2BootResourcePackagePath = (devicePath: string) =>
|
|
320
305
|
typeof devicePath === 'string' &&
|
|
321
|
-
devicePath.
|
|
322
|
-
PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH;
|
|
323
|
-
|
|
324
|
-
const resolveProtocolV2ResourceWritePath = (devicePath: string) =>
|
|
325
|
-
isProtocolV2BootResourcePackagePath(devicePath)
|
|
326
|
-
? PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH
|
|
327
|
-
: devicePath;
|
|
306
|
+
devicePath.toLowerCase() === PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH;
|
|
328
307
|
|
|
329
308
|
const PROTOCOL_V2_UPDATE_TARGET_BY_TARGET_ID = new Map<
|
|
330
309
|
number,
|
|
@@ -491,42 +470,6 @@ const toProtocolV2FiniteNumber = (value: unknown) => {
|
|
|
491
470
|
return undefined;
|
|
492
471
|
};
|
|
493
472
|
|
|
494
|
-
const readProtocolV2Ascii = (bytes: Uint8Array, offset: number, length: number) =>
|
|
495
|
-
Array.from(bytes.slice(offset, offset + length))
|
|
496
|
-
.map(byte => String.fromCharCode(byte))
|
|
497
|
-
.join('');
|
|
498
|
-
|
|
499
|
-
const parseProtocolV2OkppHeader = (bytes: Uint8Array): ProtocolV2OkppHeader | null => {
|
|
500
|
-
if (bytes.byteLength < PROTOCOL_V2_OKPP_HEADER_SIZE) return null;
|
|
501
|
-
if (readProtocolV2Ascii(bytes, 0, 4) !== 'OKPP') return null;
|
|
502
|
-
|
|
503
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
504
|
-
const headerLen = view.getUint32(0x0c, true);
|
|
505
|
-
if (headerLen !== PROTOCOL_V2_OKPP_HEADER_SIZE) return null;
|
|
506
|
-
|
|
507
|
-
const packedVersion = view.getUint32(0x10, true);
|
|
508
|
-
return {
|
|
509
|
-
type: readProtocolV2Ascii(bytes, 0x08, 4),
|
|
510
|
-
version: [
|
|
511
|
-
Math.floor(packedVersion / 0x10000) % 0x100,
|
|
512
|
-
Math.floor(packedVersion / 0x100) % 0x100,
|
|
513
|
-
packedVersion % 0x100,
|
|
514
|
-
],
|
|
515
|
-
payloadHash: bytesToHex(
|
|
516
|
-
bytes.slice(
|
|
517
|
-
PROTOCOL_V2_OKPP_PAYLOAD_HASH_OFFSET,
|
|
518
|
-
PROTOCOL_V2_OKPP_PAYLOAD_HASH_OFFSET + PROTOCOL_V2_OKPP_HASH_SIZE
|
|
519
|
-
)
|
|
520
|
-
),
|
|
521
|
-
headerHash: bytesToHex(
|
|
522
|
-
bytes.slice(
|
|
523
|
-
PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET,
|
|
524
|
-
PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET + PROTOCOL_V2_OKPP_HASH_SIZE
|
|
525
|
-
)
|
|
526
|
-
),
|
|
527
|
-
};
|
|
528
|
-
};
|
|
529
|
-
|
|
530
473
|
export const isProtocolV2FirmwareFingerprintValid = (
|
|
531
474
|
binary: ArrayBuffer | Uint8Array,
|
|
532
475
|
fingerprint: string | undefined
|
|
@@ -1262,130 +1205,69 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1262
1205
|
);
|
|
1263
1206
|
}
|
|
1264
1207
|
const zipEntries = Object.values(zip.files);
|
|
1208
|
+
const resourceEntries = zipEntries.filter(
|
|
1209
|
+
entry => !entry.dir && entry.name.toLowerCase().endsWith('.okpkg')
|
|
1210
|
+
);
|
|
1265
1211
|
if (
|
|
1266
|
-
|
|
1212
|
+
resourceEntries.length === 0 ||
|
|
1213
|
+
resourceEntries.length > PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT
|
|
1267
1214
|
) {
|
|
1268
1215
|
throw ERRORS.TypedError(
|
|
1269
1216
|
HardwareErrorCode.RuntimeError,
|
|
1270
|
-
'Protocol V2
|
|
1271
|
-
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1272
|
-
);
|
|
1273
|
-
}
|
|
1274
|
-
const entries = zipEntries.filter(entry => !entry.dir);
|
|
1275
|
-
if (entries.length === 0) {
|
|
1276
|
-
throw ERRORS.TypedError(
|
|
1277
|
-
HardwareErrorCode.RuntimeError,
|
|
1278
|
-
'Protocol V2 local resource ZIP entry set is invalid',
|
|
1217
|
+
'Protocol V2 resource ZIP has no valid resource package set',
|
|
1279
1218
|
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1280
1219
|
);
|
|
1281
1220
|
}
|
|
1282
|
-
|
|
1283
|
-
let
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1221
|
+
|
|
1222
|
+
let totalSize = 0;
|
|
1223
|
+
const materializedEntries: FirmwareMemoryArtifactEntry[] = [];
|
|
1224
|
+
const resources: ProtocolV2LocalResourceArchive['resources'] = [];
|
|
1225
|
+
const devicePaths = new Set<string>();
|
|
1226
|
+
for (const entry of resourceEntries) {
|
|
1227
|
+
const { compressedSize, uncompressedSize } = getProtocolV2ZipEntrySizes(entry);
|
|
1228
|
+
totalSize += uncompressedSize;
|
|
1287
1229
|
if (
|
|
1288
|
-
|
|
1289
|
-
|
|
1230
|
+
compressedSize > binary.byteLength ||
|
|
1231
|
+
uncompressedSize > PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES ||
|
|
1232
|
+
totalSize > PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES
|
|
1290
1233
|
) {
|
|
1291
1234
|
throw ERRORS.TypedError(
|
|
1292
1235
|
HardwareErrorCode.RuntimeError,
|
|
1293
|
-
|
|
1236
|
+
`Protocol V2 resource package size is invalid: ${entry.name}`,
|
|
1294
1237
|
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1295
1238
|
);
|
|
1296
1239
|
}
|
|
1297
|
-
|
|
1298
|
-
if (
|
|
1299
|
-
manifestBinary.byteLength <= 0 ||
|
|
1300
|
-
manifestBinary.byteLength > PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES
|
|
1301
|
-
) {
|
|
1240
|
+
const fileBinary = await entry.async('arraybuffer');
|
|
1241
|
+
if (fileBinary.byteLength !== uncompressedSize) {
|
|
1302
1242
|
throw ERRORS.TypedError(
|
|
1303
1243
|
HardwareErrorCode.RuntimeError,
|
|
1304
|
-
|
|
1305
|
-
{ firmwareUpdateCode: '
|
|
1244
|
+
`Protocol V2 resource package is incomplete: ${entry.name}`,
|
|
1245
|
+
{ firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch' }
|
|
1306
1246
|
);
|
|
1307
1247
|
}
|
|
1308
|
-
let
|
|
1248
|
+
let header: ProtocolV2ResourcePackageHeader;
|
|
1309
1249
|
try {
|
|
1310
|
-
|
|
1250
|
+
header = parseProtocolV2ResourcePackage(fileBinary);
|
|
1311
1251
|
} catch (error) {
|
|
1312
1252
|
throw ERRORS.TypedError(
|
|
1313
1253
|
HardwareErrorCode.RuntimeError,
|
|
1314
|
-
`Protocol V2
|
|
1254
|
+
`Protocol V2 resource package is invalid: ${entry.name}: ${String(error)}`,
|
|
1315
1255
|
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1316
1256
|
);
|
|
1317
1257
|
}
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
targetsToUpdate: this.params.targetsToUpdate ?? [],
|
|
1321
|
-
});
|
|
1322
|
-
manifestDirectory = manifestEntry.name.slice(0, -'manifest.json'.length);
|
|
1323
|
-
} else {
|
|
1324
|
-
selectedFiles = entries.flatMap(entry => {
|
|
1325
|
-
const archivePath = getProtocolV2LocalResourceArchivePath(entry.name);
|
|
1326
|
-
if (!archivePath) return [];
|
|
1327
|
-
return [
|
|
1328
|
-
{
|
|
1329
|
-
archive_path: archivePath,
|
|
1330
|
-
original_name: archivePath.split('/').pop() ?? archivePath,
|
|
1331
|
-
device_path: `vol0:/${archivePath}`,
|
|
1332
|
-
size: getProtocolV2ZipEntrySizes(entry).uncompressedSize,
|
|
1333
|
-
sha256: '',
|
|
1334
|
-
},
|
|
1335
|
-
];
|
|
1336
|
-
});
|
|
1337
|
-
}
|
|
1338
|
-
if (selectedFiles.length === 0 || selectedFiles.length > PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT) {
|
|
1339
|
-
throw ERRORS.TypedError(
|
|
1340
|
-
HardwareErrorCode.RuntimeError,
|
|
1341
|
-
'Protocol V2 local resource ZIP has no resource packages',
|
|
1342
|
-
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1343
|
-
);
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1346
|
-
let totalSize = 0;
|
|
1347
|
-
const materializedEntries: FirmwareMemoryArtifactEntry[] = [];
|
|
1348
|
-
const normalizedFiles: IProtocolV2ResourceManifestFile[] = [];
|
|
1349
|
-
for (const file of selectedFiles) {
|
|
1350
|
-
const entry = manifestEntry
|
|
1351
|
-
? zip.file(`${manifestDirectory}${file.archive_path}`)
|
|
1352
|
-
: entries.find(
|
|
1353
|
-
candidate => getProtocolV2LocalResourceArchivePath(candidate.name) === file.archive_path
|
|
1354
|
-
);
|
|
1355
|
-
if (!entry) {
|
|
1258
|
+
const canonicalDevicePath = header.devicePath.toLowerCase();
|
|
1259
|
+
if (devicePaths.has(canonicalDevicePath)) {
|
|
1356
1260
|
throw ERRORS.TypedError(
|
|
1357
1261
|
HardwareErrorCode.RuntimeError,
|
|
1358
|
-
`Protocol V2
|
|
1262
|
+
`Protocol V2 resource ZIP contains duplicate device path: ${header.devicePath}`,
|
|
1359
1263
|
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1360
1264
|
);
|
|
1361
1265
|
}
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
throw ERRORS.TypedError(
|
|
1366
|
-
HardwareErrorCode.RuntimeError,
|
|
1367
|
-
`Protocol V2 local resource file declared size is invalid: ${file.archive_path}`,
|
|
1368
|
-
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1369
|
-
);
|
|
1370
|
-
}
|
|
1371
|
-
const fileBinary = await entry.async('arraybuffer');
|
|
1372
|
-
const digest = bytesToHex(sha256(new Uint8Array(fileBinary)));
|
|
1373
|
-
if (
|
|
1374
|
-
fileBinary.byteLength !== file.size ||
|
|
1375
|
-
(file.sha256 && digest !== file.sha256.toLowerCase())
|
|
1376
|
-
) {
|
|
1377
|
-
throw ERRORS.TypedError(
|
|
1378
|
-
HardwareErrorCode.RuntimeError,
|
|
1379
|
-
`Protocol V2 local resource file does not match manifest: ${file.archive_path}`,
|
|
1380
|
-
{ firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch' }
|
|
1381
|
-
);
|
|
1382
|
-
}
|
|
1383
|
-
normalizedFiles.push({ ...file, sha256: digest });
|
|
1384
|
-
materializedEntries.push({ entryName: file.archive_path, binary: fileBinary });
|
|
1266
|
+
devicePaths.add(canonicalDevicePath);
|
|
1267
|
+
materializedEntries.push({ entryName: entry.name, binary: fileBinary });
|
|
1268
|
+
resources.push({ entryName: entry.name, binary: fileBinary, header });
|
|
1385
1269
|
}
|
|
1386
|
-
|
|
1387
|
-
materializedEntries.unshift({ entryName: 'manifest.json', binary: manifestBinary });
|
|
1388
|
-
return { binary, materializedEntries };
|
|
1270
|
+
return { binary, materializedEntries, resources };
|
|
1389
1271
|
}
|
|
1390
1272
|
|
|
1391
1273
|
private async prepareProtocolV2ResourceSources(): Promise<ProtocolV2ResourceBundleSource[]> {
|
|
@@ -1450,82 +1332,19 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1450
1332
|
);
|
|
1451
1333
|
}
|
|
1452
1334
|
|
|
1453
|
-
// The verified
|
|
1454
|
-
//
|
|
1335
|
+
// The verified ZIP bytes are authoritative. Non-okpkg entries are release
|
|
1336
|
+
// metadata only; each RESOURCE package carries its own device path.
|
|
1455
1337
|
const verifiedArchive = await this.prepareProtocolV2LocalResourceArchive(archiveBinary);
|
|
1456
|
-
const verifiedEntriesByName = new Map(
|
|
1457
|
-
verifiedArchive.materializedEntries.map(entry => [entry.entryName, entry.binary] as const)
|
|
1458
|
-
);
|
|
1459
|
-
const manifestBinary = verifiedEntriesByName.get('manifest.json');
|
|
1460
|
-
if (!manifestBinary) {
|
|
1461
|
-
throw ERRORS.TypedError(
|
|
1462
|
-
HardwareErrorCode.RuntimeError,
|
|
1463
|
-
'Protocol V2 prepared resource archive has no valid manifest.json',
|
|
1464
|
-
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1465
|
-
);
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
let manifestValue: unknown;
|
|
1469
|
-
try {
|
|
1470
|
-
manifestValue = JSON.parse(new TextDecoder().decode(manifestBinary));
|
|
1471
|
-
} catch (error) {
|
|
1472
|
-
throw ERRORS.TypedError(
|
|
1473
|
-
HardwareErrorCode.RuntimeError,
|
|
1474
|
-
`Protocol V2 prepared resource manifest is invalid: ${String(error)}`,
|
|
1475
|
-
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1476
|
-
);
|
|
1477
|
-
}
|
|
1478
|
-
const manifest = parseProtocolV2ResourceManifest(manifestValue);
|
|
1479
|
-
const selectedFiles = selectProtocolV2ResourceManifestFiles({
|
|
1480
|
-
manifest,
|
|
1481
|
-
targetsToUpdate: this.params.targetsToUpdate ?? [],
|
|
1482
|
-
});
|
|
1483
|
-
if (selectedFiles.length > PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT) {
|
|
1484
|
-
throw ERRORS.TypedError(
|
|
1485
|
-
HardwareErrorCode.RuntimeError,
|
|
1486
|
-
'Protocol V2 prepared resource archive contains too many files',
|
|
1487
|
-
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1488
|
-
);
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
let totalSize = 0;
|
|
1492
1338
|
const sources: ProtocolV2ResourceBundleSource[] = [];
|
|
1493
|
-
for (const
|
|
1494
|
-
const
|
|
1495
|
-
if (!binary || binary.byteLength !== file.size) {
|
|
1496
|
-
throw ERRORS.TypedError(
|
|
1497
|
-
HardwareErrorCode.RuntimeError,
|
|
1498
|
-
`Protocol V2 prepared resource file does not match manifest: ${file.archive_path}`,
|
|
1499
|
-
{ firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch' }
|
|
1500
|
-
);
|
|
1501
|
-
}
|
|
1502
|
-
totalSize += binary.byteLength;
|
|
1503
|
-
if (totalSize > PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES) {
|
|
1504
|
-
throw ERRORS.TypedError(
|
|
1505
|
-
HardwareErrorCode.RuntimeError,
|
|
1506
|
-
'Protocol V2 prepared resource archive exceeds the total size limit',
|
|
1507
|
-
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1508
|
-
);
|
|
1509
|
-
}
|
|
1510
|
-
// 使用从获批 ZIP 中提取的规范字节,避免宿主在校验后替换 entry reader 内容。
|
|
1511
|
-
const source = await this.openProtocolV2MemorySource(binary);
|
|
1512
|
-
const header =
|
|
1513
|
-
source.size >= PROTOCOL_V2_OKPP_HEADER_SIZE
|
|
1514
|
-
? parseProtocolV2OkppHeader(
|
|
1515
|
-
new Uint8Array(await source.readAt(0, PROTOCOL_V2_OKPP_HEADER_SIZE))
|
|
1516
|
-
)
|
|
1517
|
-
: null;
|
|
1339
|
+
for (const resource of verifiedArchive.resources) {
|
|
1340
|
+
const source = await this.openProtocolV2MemorySource(resource.binary);
|
|
1518
1341
|
sources.push({
|
|
1519
|
-
name:
|
|
1342
|
+
name: resource.entryName.split('/').pop() ?? resource.entryName,
|
|
1520
1343
|
source,
|
|
1521
|
-
devicePath:
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
payloadHash: header.payloadHash,
|
|
1526
|
-
headerHash: header.headerHash,
|
|
1527
|
-
}
|
|
1528
|
-
: {}),
|
|
1344
|
+
devicePath: resource.header.devicePath,
|
|
1345
|
+
version: resource.header.version,
|
|
1346
|
+
payloadHash: resource.header.payloadHash,
|
|
1347
|
+
headerHash: resource.header.headerHash,
|
|
1529
1348
|
});
|
|
1530
1349
|
}
|
|
1531
1350
|
return sources;
|
|
@@ -2023,7 +1842,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2023
1842
|
!pathInfoRes.message?.exist ||
|
|
2024
1843
|
pathInfoRes.message?.directory ||
|
|
2025
1844
|
fileSize === undefined ||
|
|
2026
|
-
fileSize <
|
|
1845
|
+
fileSize < PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE ||
|
|
2027
1846
|
(expectedSize !== undefined && fileSize !== expectedSize)
|
|
2028
1847
|
) {
|
|
2029
1848
|
return null;
|
|
@@ -2032,8 +1851,8 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2032
1851
|
const chunkSize = this.getProtocolV2FirmwareChunkSize('read');
|
|
2033
1852
|
const chunks: Uint8Array[] = [];
|
|
2034
1853
|
let offset = 0;
|
|
2035
|
-
while (offset <
|
|
2036
|
-
const readLen = Math.min(chunkSize,
|
|
1854
|
+
while (offset < PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE) {
|
|
1855
|
+
const readLen = Math.min(chunkSize, PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE - offset);
|
|
2037
1856
|
const res = await typedCall('FilesystemFileRead', 'FilesystemFile', {
|
|
2038
1857
|
file: {
|
|
2039
1858
|
path: filePath,
|
|
@@ -2055,7 +1874,11 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2055
1874
|
headerBytes.set(chunk, cursor);
|
|
2056
1875
|
cursor += chunk.byteLength;
|
|
2057
1876
|
});
|
|
2058
|
-
|
|
1877
|
+
try {
|
|
1878
|
+
return parseProtocolV2ResourcePackageHeader(headerBytes, fileSize);
|
|
1879
|
+
} catch {
|
|
1880
|
+
return null;
|
|
1881
|
+
}
|
|
2059
1882
|
}
|
|
2060
1883
|
|
|
2061
1884
|
/** Compare the downloaded and installed okpkg headers before transferring a resource. */
|
|
@@ -2348,7 +2171,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2348
2171
|
for (const resource of resourcesToSync) {
|
|
2349
2172
|
// The bootloader keeps its live resource package mounted. FatFs rejects
|
|
2350
2173
|
// replacing an open file, so early boot promotes this staging file before mounting it.
|
|
2351
|
-
const writePath =
|
|
2174
|
+
const writePath = resource.devicePath;
|
|
2352
2175
|
processedSize = await this.protocolV2SourceUpdateProcess({
|
|
2353
2176
|
source: resource.source,
|
|
2354
2177
|
filePath: writePath,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
1
|
+
import { ERRORS, HardwareErrorCode, resolveOneKeyUsbDevicePath } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import { BaseMethod } from './BaseMethod';
|
|
4
4
|
import TransportManager from '../data-manager/TransportManager';
|
|
@@ -52,7 +52,7 @@ export default class PromptWebDeviceAccess extends BaseMethod {
|
|
|
52
52
|
|
|
53
53
|
if (isWebUsbEnv) {
|
|
54
54
|
const usbDevice = device as USBDevice;
|
|
55
|
-
const path = usbDevice
|
|
55
|
+
const path = resolveOneKeyUsbDevicePath(usbDevice);
|
|
56
56
|
if (!path) {
|
|
57
57
|
throw ERRORS.TypedError(HardwareErrorCode.WebDevicePromptAccessError);
|
|
58
58
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DeviceRebootType } from '@onekeyfe/hd-transport';
|
|
1
|
+
import { DeviceRebootType, DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
2
|
|
|
3
3
|
import { BaseMethod } from '../BaseMethod';
|
|
4
4
|
|
|
@@ -13,6 +13,8 @@ export default class DeviceRebootToBoardloader extends BaseMethod<RebootToBoardl
|
|
|
13
13
|
init() {
|
|
14
14
|
this.useDevicePassphraseState = false;
|
|
15
15
|
this.skipForceUpdateCheck = true;
|
|
16
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
17
|
+
this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
getVersionRange() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DeviceRebootType } from '@onekeyfe/hd-transport';
|
|
1
|
+
import { DeviceRebootType, DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
2
|
|
|
3
3
|
import { BaseMethod } from '../BaseMethod';
|
|
4
4
|
|
|
@@ -13,6 +13,8 @@ export default class DeviceRebootToBootloader extends BaseMethod<RebootToBootloa
|
|
|
13
13
|
init() {
|
|
14
14
|
this.useDevicePassphraseState = false;
|
|
15
15
|
this.skipForceUpdateCheck = true;
|
|
16
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
17
|
+
this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
getVersionRange() {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
|
+
|
|
1
3
|
import { BaseMethod } from '../BaseMethod';
|
|
2
4
|
import { normalizeRebootType } from './helpers';
|
|
3
5
|
|
|
@@ -11,6 +13,9 @@ export default class DeviceReboot extends BaseMethod<DeviceRebootParams> {
|
|
|
11
13
|
init() {
|
|
12
14
|
this.skipForceUpdateCheck = true;
|
|
13
15
|
this.useDevicePassphraseState = false;
|
|
16
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
17
|
+
// Device-management action: main PIN or Attach PIN may authorize reboot.
|
|
18
|
+
this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
|
|
14
19
|
this.params = {
|
|
15
20
|
rebootType: this.payload.rebootType,
|
|
16
21
|
reboot_type: this.payload.reboot_type,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ERRORS, HardwareErrorCode, createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
|
|
2
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
3
|
|
|
3
4
|
import { UI_REQUEST, createUiMessage } from '../../events/ui-request';
|
|
4
5
|
import { supportsProtocolV2Message } from '../../protocols/protocol-v2/features';
|
|
@@ -129,7 +130,10 @@ export default class DeviceUploadNft extends BaseMethod<DeviceUploadNftParams> {
|
|
|
129
130
|
paceMs,
|
|
130
131
|
timeoutMs,
|
|
131
132
|
};
|
|
132
|
-
this.unlockPolicy = '
|
|
133
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
134
|
+
// File writes and NftUpdate require an unlocked device. Either PIN may
|
|
135
|
+
// authorize this device-management action.
|
|
136
|
+
this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
|
|
133
137
|
this.skipForceUpdateCheck = true;
|
|
134
138
|
this.useDevicePassphraseState = false;
|
|
135
139
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { blake2s } from '@noble/hashes/blake2s';
|
|
2
2
|
import { bytesToHex } from '@noble/hashes/utils';
|
|
3
3
|
import { createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
|
|
4
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
4
5
|
|
|
5
6
|
import { BaseMethod } from '../BaseMethod';
|
|
6
7
|
import { decodeJpegBase64ToRgba } from '../helpers/base64Data';
|
|
@@ -78,7 +79,10 @@ export default class DeviceUploadWallpaper extends BaseMethod<DeviceUploadWallpa
|
|
|
78
79
|
});
|
|
79
80
|
this.path = `${WALLPAPER_DIRECTORY}/${normalizeFileName(fileName, this.encoded.data)}`;
|
|
80
81
|
this.params = { jpegBase64, fileName, chunkSize };
|
|
81
|
-
this.unlockPolicy = '
|
|
82
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
83
|
+
// File writes and wallpaper apply require an unlocked device. Either PIN
|
|
84
|
+
// may authorize this device-management action.
|
|
85
|
+
this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
|
|
82
86
|
this.skipForceUpdateCheck = true;
|
|
83
87
|
this.useDevicePassphraseState = false;
|
|
84
88
|
}
|