@onekeyfe/hd-core 1.2.0-alpha.23 → 1.2.0-alpha.24

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.
Files changed (131) hide show
  1. package/__tests__/DeviceCommands.test.ts +35 -0
  2. package/__tests__/connectSettings.test.ts +5 -47
  3. package/__tests__/device-lifecycle-events.test.ts +59 -0
  4. package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +30 -39
  5. package/__tests__/open-wallet-session.test.ts +192 -129
  6. package/__tests__/protocol-v2-ping.test.ts +28 -0
  7. package/__tests__/protocol-v2.test.ts +338 -376
  8. package/__tests__/public-pro2-api-boundary.test.ts +22 -0
  9. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  10. package/dist/api/FirmwareUpdateV2.d.ts +0 -11
  11. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  12. package/dist/api/FirmwareUpdateV3.d.ts +3 -7
  13. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  14. package/dist/api/FirmwareUpdateV4.d.ts +5 -21
  15. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  16. package/dist/api/OpenWalletSession.d.ts +1 -8
  17. package/dist/api/OpenWalletSession.d.ts.map +1 -1
  18. package/dist/api/device/DeviceUpdateBootloader.d.ts +1 -5
  19. package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
  20. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +0 -7
  21. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  22. package/dist/api/firmware/getBinary.d.ts +0 -7
  23. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  24. package/dist/api/firmware/updateBootloader.d.ts +0 -2
  25. package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
  26. package/dist/api/firmware/uploadFirmware.d.ts +1 -9
  27. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  28. package/dist/api/index.d.ts +1 -0
  29. package/dist/api/index.d.ts.map +1 -1
  30. package/dist/api/protocol-v2/Ping.d.ts +2 -0
  31. package/dist/api/protocol-v2/Ping.d.ts.map +1 -1
  32. package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
  33. package/dist/core/index.d.ts.map +1 -1
  34. package/dist/data-manager/DataManager.d.ts +0 -1
  35. package/dist/data-manager/DataManager.d.ts.map +1 -1
  36. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  37. package/dist/device/Device.d.ts.map +1 -1
  38. package/dist/device/DeviceCommands.d.ts.map +1 -1
  39. package/dist/index.d.ts +89 -273
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +783 -2443
  42. package/dist/inject.d.ts.map +1 -1
  43. package/dist/lowLevelInject.d.ts.map +1 -1
  44. package/dist/protocols/protocol-v2/unlockRetry.d.ts +2 -3
  45. package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -1
  46. package/dist/protocols/protocol-v2/walletSession.d.ts +12 -0
  47. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  48. package/dist/topLevelInject.d.ts.map +1 -1
  49. package/dist/types/api/checkAllFirmwareRelease.d.ts +0 -3
  50. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  51. package/dist/types/api/deviceUpdateBootloader.d.ts +0 -6
  52. package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
  53. package/dist/types/api/export.d.ts +1 -4
  54. package/dist/types/api/export.d.ts.map +1 -1
  55. package/dist/types/api/firmwareUpdate.d.ts +0 -69
  56. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  57. package/dist/types/api/index.d.ts +4 -10
  58. package/dist/types/api/index.d.ts.map +1 -1
  59. package/dist/types/api/openWalletSession.d.ts +0 -12
  60. package/dist/types/api/openWalletSession.d.ts.map +1 -1
  61. package/dist/types/api/protocolV2.d.ts +4 -0
  62. package/dist/types/api/protocolV2.d.ts.map +1 -1
  63. package/dist/types/settings.d.ts +0 -13
  64. package/dist/types/settings.d.ts.map +1 -1
  65. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  66. package/dist/utils/patch.d.ts +1 -1
  67. package/dist/utils/patch.d.ts.map +1 -1
  68. package/package.json +4 -4
  69. package/src/api/CheckAllFirmwareRelease.ts +3 -23
  70. package/src/api/FirmwareUpdateV2.ts +120 -292
  71. package/src/api/FirmwareUpdateV3.ts +55 -256
  72. package/src/api/FirmwareUpdateV4.ts +297 -757
  73. package/src/api/OpenWalletSession.ts +23 -86
  74. package/src/api/device/DeviceUpdateBootloader.ts +6 -122
  75. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +0 -50
  76. package/src/api/firmware/updateBootloader.ts +4 -19
  77. package/src/api/firmware/uploadFirmware.ts +22 -140
  78. package/src/api/index.ts +1 -0
  79. package/src/api/protocol-v2/Ping.ts +32 -1
  80. package/src/core/index.ts +39 -7
  81. package/src/data/messages/messages-protocol-v2.json +33 -1
  82. package/src/data-manager/DataManager.ts +33 -33
  83. package/src/data-manager/connectSettings.ts +0 -11
  84. package/src/device/Device.ts +7 -9
  85. package/src/device/DeviceCommands.ts +19 -0
  86. package/src/index.ts +0 -5
  87. package/src/inject.ts +4 -22
  88. package/src/lowLevelInject.ts +1 -5
  89. package/src/protocols/protocol-v2/unlockRetry.ts +20 -3
  90. package/src/protocols/protocol-v2/walletSession.ts +26 -8
  91. package/src/topLevelInject.ts +1 -5
  92. package/src/types/api/checkAllFirmwareRelease.ts +0 -3
  93. package/src/types/api/deviceUpdateBootloader.ts +0 -6
  94. package/src/types/api/export.ts +0 -18
  95. package/src/types/api/firmwareUpdate.ts +0 -76
  96. package/src/types/api/index.ts +3 -14
  97. package/src/types/api/openWalletSession.ts +0 -19
  98. package/src/types/api/protocolV2.ts +10 -0
  99. package/src/types/settings.ts +0 -13
  100. package/src/utils/deviceInfoUtils.ts +15 -3
  101. package/__tests__/firmware-update/check-all-firmware-release.test.ts +0 -86
  102. package/__tests__/firmware-update/firmware-artifact-source.test.ts +0 -119
  103. package/__tests__/firmware-update/firmware-host-binding.test.ts +0 -70
  104. package/__tests__/firmware-update/firmware-update-capabilities.test.ts +0 -13
  105. package/__tests__/firmware-update/firmware-update-plan.test.ts +0 -326
  106. package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +0 -213
  107. package/__tests__/firmware-update/firmware-upload-source.test.ts +0 -70
  108. package/dist/api/firmware/FirmwareArtifactSource.d.ts +0 -25
  109. package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +0 -1
  110. package/dist/api/firmware/FirmwareHostBinding.d.ts +0 -6
  111. package/dist/api/firmware/FirmwareHostBinding.d.ts.map +0 -1
  112. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +0 -3
  113. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +0 -1
  114. package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -23
  115. package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +0 -1
  116. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +0 -30
  117. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +0 -1
  118. package/dist/types/api/firmwareUpdateCapabilities.d.ts +0 -9
  119. package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +0 -1
  120. package/dist/types/api/firmwareUpdatePlan.d.ts +0 -27
  121. package/dist/types/api/firmwareUpdatePlan.d.ts.map +0 -1
  122. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +0 -42
  123. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +0 -1
  124. package/src/api/firmware/FirmwareArtifactSource.ts +0 -278
  125. package/src/api/firmware/FirmwareHostBinding.ts +0 -100
  126. package/src/api/firmware/FirmwareUpdateCapabilities.ts +0 -9
  127. package/src/api/firmware/FirmwareUpdatePlan.ts +0 -621
  128. package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +0 -392
  129. package/src/types/api/firmwareUpdateCapabilities.ts +0 -9
  130. package/src/types/api/firmwareUpdatePlan.ts +0 -36
  131. package/src/types/api/firmwareUpdatePreparedPlan.ts +0 -53
@@ -9,7 +9,6 @@ import {
9
9
  getDeviceBLEFirmwareVersion,
10
10
  getDeviceBootloaderVersion,
11
11
  getDeviceFirmwareVersion,
12
- getDeviceUUID,
13
12
  getLogger,
14
13
  } from '../utils';
15
14
  import { getBinary, getSysResourceBinary } from './firmware/getBinary';
@@ -18,21 +17,10 @@ import { FirmwareUpdateBaseMethod } from './firmware/FirmwareUpdateBaseMethod';
18
17
  import { DevicePool } from '../device/DevicePool';
19
18
  import { DEVICE } from '../events';
20
19
  import { buildProtocolV1FeaturesPayload } from '../deviceProfile';
21
- import { openFirmwareByteSource } from './firmware/FirmwareArtifactSource';
22
- import { resolveFirmwareUpdateHostBinding } from './firmware/FirmwareHostBinding';
23
- import {
24
- assertFirmwareUpdatePreparedPlanDeviceIdentity,
25
- assertFirmwareUpdatePreparedPlanBinding,
26
- getFirmwareUpdateResourceName,
27
- } from './firmware/FirmwareUpdatePreparedPlan';
28
-
29
- import type {
30
- FirmwareArtifactReference,
31
- FirmwareUpdateV3Params,
32
- } from '../types/api/firmwareUpdate';
20
+
21
+ import type { FirmwareUpdateV3Params } from '../types/api/firmwareUpdate';
33
22
  import type { Deferred, EFirmwareType } from '@onekeyfe/hd-shared';
34
23
  import type { TypedResponseMessage } from '../device/DeviceCommands';
35
- import type { FirmwareByteSource } from './firmware/FirmwareArtifactSource';
36
24
 
37
25
  const Log = getLogger(LoggerNames.Method);
38
26
 
@@ -54,8 +42,6 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
54
42
 
55
43
  private isSwitchFirmware = false;
56
44
 
57
- private artifactSources: FirmwareByteSource[] = [];
58
-
59
45
  init() {
60
46
  this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.NOT_INITIALIZE];
61
47
  this.requireDeviceMode = [];
@@ -76,54 +62,8 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
76
62
  { name: 'firmwareType', type: 'string' },
77
63
  { name: 'platform', type: 'string' },
78
64
  ]);
79
- const hostBinding =
80
- payload.artifacts || payload.preparedPlan
81
- ? resolveFirmwareUpdateHostBinding(payload.hostBindingGeneration)
82
- : undefined;
83
- if (hostBinding) {
84
- assertFirmwareUpdatePreparedPlanBinding({
85
- preparedPlan: payload.preparedPlan,
86
- executor: 'v3',
87
- platform: payload.platform,
88
- scopeTargets: ['bootloader', 'firmware', 'resource', 'ble'],
89
- bindings: [
90
- ...(payload.artifacts?.bootloader
91
- ? [
92
- {
93
- target: 'bootloader' as const,
94
- artifact: payload.artifacts.bootloader,
95
- },
96
- ]
97
- : []),
98
- ...(payload.artifacts?.firmware
99
- ? [
100
- {
101
- target: 'firmware' as const,
102
- artifact: payload.artifacts.firmware,
103
- },
104
- ]
105
- : []),
106
- ...(payload.artifacts?.ble
107
- ? [
108
- {
109
- target: 'ble' as const,
110
- artifact: payload.artifacts.ble,
111
- },
112
- ]
113
- : []),
114
- ...(payload.artifacts?.resourceEntries ?? []).map(
115
- (entry: { entryName: string; artifact: FirmwareArtifactReference }) => ({
116
- target: 'resource' as const,
117
- entryName: entry.entryName,
118
- artifact: entry.artifact,
119
- })
120
- ),
121
- ],
122
- });
123
- }
124
65
 
125
66
  this.params = {
126
- preparedPlan: payload.preparedPlan,
127
67
  bleBinary: payload.bleBinary,
128
68
  firmwareBinary: payload.firmwareBinary,
129
69
  forcedUpdateRes: payload.forcedUpdateRes,
@@ -134,8 +74,6 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
134
74
  resourceBinary: payload.resourceBinary,
135
75
  firmwareType: payload.firmwareType,
136
76
  platform: payload.platform,
137
- artifactReader: hostBinding?.artifactReader ?? payload.artifactReader,
138
- artifacts: payload.artifacts,
139
77
  };
140
78
  }
141
79
 
@@ -165,53 +103,39 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
165
103
  if (!features) {
166
104
  throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Device features not available');
167
105
  }
168
- if (this.params.preparedPlan) {
169
- assertFirmwareUpdatePreparedPlanDeviceIdentity({
170
- preparedPlan: this.params.preparedPlan,
171
- deviceIdentity: getDeviceUUID(features) || undefined,
172
- });
173
- }
174
106
 
175
107
  const deviceFirmwareType = device.getCurrentFirmwareType();
176
108
  const firmwareType = this.params.firmwareType ?? deviceFirmwareType;
177
109
  this.isSwitchFirmware = firmwareType !== deviceFirmwareType;
178
110
 
179
111
  let resourceBinary: ArrayBuffer | null = null;
180
- let resourceEntries: Array<{ entryName: string; source: FirmwareByteSource }> = [];
181
- let fwSources: Array<{ fileName: string; source: FirmwareByteSource }> = [];
182
- let bootloaderSource: FirmwareByteSource | null = null;
112
+ let fwBinaryMap: { fileName: string; binary: ArrayBuffer }[] = [];
113
+ let bootloaderBinary: ArrayBuffer | null = null;
183
114
  try {
184
115
  this.postTipMessage(FirmwareUpdateTipMessage.StartDownloadFirmware);
185
- const resourceInput = await this.prepareResourceInput(firmwareType);
186
- resourceBinary = resourceInput.resourceBinary;
187
- resourceEntries = resourceInput.resourceEntries;
188
- fwSources = await this.prepareFirmwareAndBleSources(firmwareType);
189
- bootloaderSource = await this.prepareBootloaderSource(firmwareType);
116
+ resourceBinary = await this.prepareResourceBinary(firmwareType);
117
+ fwBinaryMap = await this.prepareFirmwareAndBleBinary(firmwareType);
118
+ bootloaderBinary = await this.prepareBootloaderBinary(firmwareType);
190
119
  this.postTipMessage(FirmwareUpdateTipMessage.FinishDownloadFirmware);
191
120
  } catch (err) {
192
- await this.closeArtifactSources();
193
121
  throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateDownloadFailed, err.message ?? err);
194
122
  }
195
123
 
196
- if (!bootloaderSource && fwSources.length === 0) {
197
- await this.closeArtifactSources();
124
+ if (!bootloaderBinary && fwBinaryMap.length === 0) {
198
125
  throw ERRORS.TypedError(
199
126
  HardwareErrorCode.FirmwareUpdateDownloadFailed,
200
127
  'No firmware to update'
201
128
  );
202
129
  }
203
130
 
204
- try {
205
- await this.enterBootloaderMode();
206
- return await this.executeUpdate({
207
- resourceBinary,
208
- resourceEntries,
209
- fwSources,
210
- bootloaderSource,
211
- });
212
- } finally {
213
- await this.closeArtifactSources();
214
- }
131
+ await this.enterBootloaderMode();
132
+
133
+ const updateResult = await this.executeUpdate({
134
+ resourceBinary,
135
+ fwBinaryMap,
136
+ bootloaderBinary,
137
+ });
138
+ return updateResult;
215
139
  }
216
140
 
217
141
  private validateDeviceAndVersion(deviceType: EDeviceType, bootloaderVersion: string) {
@@ -231,81 +155,12 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
231
155
  }
232
156
  }
233
157
 
234
- private async openArtifactSource(
235
- binary: ArrayBuffer | undefined,
236
- artifact: FirmwareArtifactReference | undefined
237
- ) {
238
- const source = await openFirmwareByteSource({
239
- binary,
240
- artifact,
241
- reader: this.params.artifactReader,
242
- });
243
- if (source) {
244
- this.artifactSources.push(source);
245
- }
246
- return source;
247
- }
248
-
249
- private async closeArtifactSources() {
250
- const sources = this.artifactSources.splice(0);
251
- await Promise.all(sources.map(source => source.close().catch(() => undefined)));
252
- }
253
-
254
- private assertSdkDownloadAllowed(artifactName: string) {
255
- if (
256
- this.params.artifactReader ||
257
- DataManager.getSettings('firmwareManifestMode') === 'external-only'
258
- ) {
259
- throw ERRORS.TypedError(
260
- HardwareErrorCode.RuntimeError,
261
- `${artifactName} must be prepared by the external firmware host`,
262
- {
263
- firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
264
- artifactName,
265
- }
266
- );
267
- }
268
- }
269
-
270
- private async prepareResourceInput(firmwareType: EFirmwareType) {
271
- const preparedEntries = this.params.artifacts?.resourceEntries;
272
- if (preparedEntries?.length && this.params.resourceBinary) {
273
- throw ERRORS.TypedError(
274
- HardwareErrorCode.RuntimeError,
275
- 'Firmware resource input must not contain both archive binary and prepared entries'
276
- );
277
- }
278
- if (preparedEntries?.length) {
279
- const resourceEntries: Array<{ entryName: string; source: FirmwareByteSource }> = [];
280
- for (const entry of preparedEntries) {
281
- const resourceName = getFirmwareUpdateResourceName(entry.entryName);
282
- const source = await this.openArtifactSource(undefined, entry.artifact);
283
- if (!source) {
284
- throw ERRORS.TypedError(
285
- HardwareErrorCode.RuntimeError,
286
- `Firmware resource entry ${entry.entryName} is not prepared`
287
- );
288
- }
289
- resourceEntries.push({ entryName: resourceName, source });
290
- }
291
- return {
292
- resourceBinary: null,
293
- resourceEntries,
294
- };
295
- }
158
+ private async prepareResourceBinary(firmwareType: EFirmwareType) {
296
159
  if (this.params.resourceBinary) {
297
- return {
298
- resourceBinary: this.params.resourceBinary,
299
- resourceEntries: [],
300
- };
160
+ return this.params.resourceBinary;
301
161
  }
302
162
  const { features } = this.device;
303
- if (!features) {
304
- return {
305
- resourceBinary: null,
306
- resourceEntries: [],
307
- };
308
- }
163
+ if (!features) return null;
309
164
  const resourceUrl = DataManager.getSysResourcesLatestRelease({
310
165
  features,
311
166
  forcedUpdateRes: this.params.forcedUpdateRes,
@@ -313,27 +168,16 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
313
168
  });
314
169
 
315
170
  if (resourceUrl) {
316
- this.assertSdkDownloadAllowed('resource');
317
- return {
318
- resourceBinary: (await getSysResourceBinary(resourceUrl)).binary,
319
- resourceEntries: [],
320
- };
171
+ const resource = (await getSysResourceBinary(resourceUrl)).binary;
172
+ return resource;
321
173
  }
322
174
  Log.warn('No resource url found');
323
- return {
324
- resourceBinary: null,
325
- resourceEntries: [],
326
- };
175
+ return null;
327
176
  }
328
177
 
329
- private async prepareBootloaderSource(
330
- firmwareType: EFirmwareType
331
- ): Promise<FirmwareByteSource | null> {
332
- if (this.params.bootloaderBinary || this.params.artifacts?.bootloader) {
333
- return this.openArtifactSource(
334
- this.params.bootloaderBinary,
335
- this.params.artifacts?.bootloader
336
- );
178
+ private async prepareBootloaderBinary(firmwareType: EFirmwareType): Promise<ArrayBuffer | null> {
179
+ if (this.params.bootloaderBinary) {
180
+ return this.params.bootloaderBinary;
337
181
  }
338
182
  const { features } = this.device;
339
183
  if (!features) return null;
@@ -341,35 +185,23 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
341
185
  if (this.params.bootloaderVersion) {
342
186
  const bootResourceUrl = DataManager.getBootloaderResource(features, firmwareType);
343
187
  if (bootResourceUrl) {
344
- this.assertSdkDownloadAllowed('bootloader');
345
188
  const bootBinary = (await getSysResourceBinary(bootResourceUrl)).binary;
346
- return this.openArtifactSource(bootBinary, undefined);
189
+ return bootBinary;
347
190
  }
348
191
  }
349
192
  return null;
350
193
  }
351
194
 
352
- private async prepareFirmwareAndBleSources(firmwareType: EFirmwareType) {
353
- const fwSources: Array<{ fileName: string; source: FirmwareByteSource }> = [];
354
- if (this.params.firmwareBinary || this.params.artifacts?.firmware) {
355
- const source = await this.openArtifactSource(
356
- this.params.firmwareBinary,
357
- this.params.artifacts?.firmware
358
- );
359
- if (!source) {
360
- throw ERRORS.TypedError(
361
- HardwareErrorCode.RuntimeError,
362
- 'Firmware artifact is not prepared'
363
- );
364
- }
365
- fwSources.push({
195
+ private async prepareFirmwareAndBleBinary(firmwareType: EFirmwareType) {
196
+ const fwBinaryMap: { fileName: string; binary: ArrayBuffer }[] = [];
197
+ if (this.params.firmwareBinary) {
198
+ fwBinaryMap.push({
366
199
  fileName: 'firmware.bin',
367
- source,
200
+ binary: this.params.firmwareBinary,
368
201
  });
369
202
  } else if (this.params.firmwareVersion) {
370
203
  const { features } = this.device;
371
204
  if (features) {
372
- this.assertSdkDownloadAllowed('firmware');
373
205
  const firmwareBinary = (
374
206
  await getBinary({
375
207
  features,
@@ -379,65 +211,44 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
379
211
  firmwareType,
380
212
  })
381
213
  ).binary;
382
- const source = await this.openArtifactSource(firmwareBinary, undefined);
383
- if (!source) {
384
- throw ERRORS.TypedError(
385
- HardwareErrorCode.RuntimeError,
386
- 'Firmware binary is not prepared'
387
- );
388
- }
389
- fwSources.push({
214
+ fwBinaryMap.push({
390
215
  fileName: 'firmware.bin',
391
- source,
216
+ binary: firmwareBinary,
392
217
  });
393
218
  }
394
219
  }
395
220
 
396
- if (this.params.bleBinary || this.params.artifacts?.ble) {
397
- const source = await this.openArtifactSource(
398
- this.params.bleBinary,
399
- this.params.artifacts?.ble
400
- );
401
- if (!source) {
402
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'BLE artifact is not prepared');
403
- }
404
- fwSources.push({
221
+ if (this.params.bleBinary) {
222
+ fwBinaryMap.push({
405
223
  fileName: 'ble-firmware.bin',
406
- source,
224
+ binary: this.params.bleBinary,
407
225
  });
408
226
  } else if (this.params.bleVersion) {
409
227
  const { features } = this.device;
410
228
  if (features) {
411
- this.assertSdkDownloadAllowed('ble');
412
229
  const bleBinary = await getBinary({
413
230
  features,
414
231
  version: this.params.bleVersion,
415
232
  updateType: 'ble',
416
233
  firmwareType,
417
234
  });
418
- const source = await this.openArtifactSource(bleBinary.binary, undefined);
419
- if (!source) {
420
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'BLE binary is not prepared');
421
- }
422
- fwSources.push({
235
+ fwBinaryMap.push({
423
236
  fileName: 'ble-firmware.bin',
424
- source,
237
+ binary: bleBinary.binary,
425
238
  });
426
239
  }
427
240
  }
428
- return fwSources;
241
+ return fwBinaryMap;
429
242
  }
430
243
 
431
244
  private async executeUpdate({
432
245
  resourceBinary,
433
- resourceEntries,
434
- fwSources,
435
- bootloaderSource,
246
+ fwBinaryMap,
247
+ bootloaderBinary,
436
248
  }: {
437
249
  resourceBinary: ArrayBuffer | null;
438
- resourceEntries: Array<{ entryName: string; source: FirmwareByteSource }>;
439
- fwSources: Array<{ fileName: string; source: FirmwareByteSource }>;
440
- bootloaderSource: FirmwareByteSource | null;
250
+ fwBinaryMap: { fileName: string; binary: ArrayBuffer }[];
251
+ bootloaderBinary: ArrayBuffer | null;
441
252
  }) {
442
253
  let totalSize = 0;
443
254
  let processedSize = 0;
@@ -445,14 +256,11 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
445
256
  if (resourceBinary) {
446
257
  totalSize += resourceBinary.byteLength;
447
258
  }
448
- for (const entry of resourceEntries) {
449
- totalSize += entry.source.size;
259
+ for (const fwbinary of fwBinaryMap) {
260
+ totalSize += fwbinary.binary.byteLength;
450
261
  }
451
- for (const firmware of fwSources) {
452
- totalSize += firmware.source.size;
453
- }
454
- if (bootloaderSource) {
455
- totalSize += bootloaderSource.size;
262
+ if (bootloaderBinary) {
263
+ totalSize += bootloaderBinary.byteLength;
456
264
  }
457
265
 
458
266
  this.postTipMessage(FirmwareUpdateTipMessage.StartTransferData);
@@ -475,18 +283,9 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
475
283
  }
476
284
  }
477
285
 
478
- for (const entry of resourceEntries) {
479
- processedSize = await this.emmcCommonUpdateProcessFromSource({
480
- source: entry.source,
481
- filePath: `0:res/${entry.entryName}`,
482
- processedSize,
483
- totalSize,
484
- });
485
- }
486
-
487
- if (bootloaderSource) {
488
- processedSize = await this.emmcCommonUpdateProcessFromSource({
489
- source: bootloaderSource,
286
+ if (bootloaderBinary) {
287
+ processedSize = await this.emmcCommonUpdateProcess({
288
+ payload: bootloaderBinary,
490
289
  filePath: `0:boot/bootloader.bin`,
491
290
  processedSize,
492
291
  totalSize,
@@ -495,11 +294,11 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
495
294
 
496
295
  await this.createUpdatesFolderIfNotExists(`0:updates/`);
497
296
 
498
- for (const firmware of fwSources) {
499
- if (firmware) {
500
- processedSize = await this.emmcCommonUpdateProcessFromSource({
501
- source: firmware.source,
502
- filePath: `0:updates/${firmware.fileName}`,
297
+ for (const fwbinary of fwBinaryMap) {
298
+ if (fwbinary) {
299
+ processedSize = await this.emmcCommonUpdateProcess({
300
+ payload: fwbinary.binary,
301
+ filePath: `0:updates/${fwbinary.fileName}`,
503
302
  processedSize,
504
303
  totalSize,
505
304
  });