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