@onekeyfe/hd-core 1.2.0-alpha.3 → 1.2.0-alpha.5

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 (117) hide show
  1. package/__tests__/preInitialize.test.ts +33 -0
  2. package/__tests__/protocol-v2.test.ts +1443 -480
  3. package/dist/api/FileRead.d.ts.map +1 -1
  4. package/dist/api/FileWrite.d.ts.map +1 -1
  5. package/dist/api/FirmwareUpdateV4.d.ts +22 -2
  6. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  7. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +1 -0
  8. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  9. package/dist/api/firmware/getBinary.d.ts +4 -0
  10. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  11. package/dist/api/firmware/progressThrottle.d.ts +3 -0
  12. package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
  13. package/dist/api/index.d.ts +5 -10
  14. package/dist/api/index.d.ts.map +1 -1
  15. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts +6 -0
  16. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -0
  17. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +7 -0
  18. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -0
  19. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +1 -1
  20. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
  21. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +3 -2
  22. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
  23. package/dist/api/protocol-v2/{DeviceGetDeviceInfo.d.ts → DeviceInfoGet.d.ts} +10 -10
  24. package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -0
  25. package/dist/api/protocol-v2/{FilesystemFixPermission.d.ts → FilesystemPermissionFix.d.ts} +2 -2
  26. package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -0
  27. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts +6 -0
  28. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -0
  29. package/dist/api/protocol-v2/helpers.d.ts +27 -18
  30. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  31. package/dist/api/ton/TonSignData.d.ts +1 -5
  32. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  33. package/dist/core/index.d.ts.map +1 -1
  34. package/dist/data-manager/DataManager.d.ts +1 -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 +4 -1
  38. package/dist/device/Device.d.ts.map +1 -1
  39. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
  40. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
  41. package/dist/index.d.ts +82 -54
  42. package/dist/index.js +1615 -1537
  43. package/dist/inject.d.ts.map +1 -1
  44. package/dist/protocols/protocol-v2/features.d.ts +12 -14
  45. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  46. package/dist/protocols/protocol-v2/firmware.d.ts +11 -9
  47. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
  48. package/dist/types/api/firmwareUpdate.d.ts +1 -6
  49. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  50. package/dist/types/api/getDeviceInfo.d.ts +2 -0
  51. package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
  52. package/dist/types/api/index.d.ts +6 -11
  53. package/dist/types/api/index.d.ts.map +1 -1
  54. package/dist/types/api/protocolV2.d.ts +12 -17
  55. package/dist/types/api/protocolV2.d.ts.map +1 -1
  56. package/dist/types/device.d.ts +1 -0
  57. package/dist/types/device.d.ts.map +1 -1
  58. package/dist/types/params.d.ts +1 -0
  59. package/dist/types/params.d.ts.map +1 -1
  60. package/dist/types/settings.d.ts +29 -2
  61. package/dist/types/settings.d.ts.map +1 -1
  62. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  63. package/dist/utils/patch.d.ts +1 -1
  64. package/dist/utils/patch.d.ts.map +1 -1
  65. package/package.json +4 -4
  66. package/src/api/FileRead.ts +14 -1
  67. package/src/api/FileWrite.ts +14 -1
  68. package/src/api/FirmwareUpdateV4.ts +975 -201
  69. package/src/api/GetOnekeyFeatures.ts +1 -1
  70. package/src/api/device/DeviceRebootToBoardloader.ts +4 -4
  71. package/src/api/device/DeviceRebootToBootloader.ts +4 -4
  72. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +18 -4
  73. package/src/api/firmware/progressThrottle.ts +44 -0
  74. package/src/api/index.ts +5 -10
  75. package/src/api/protocol-v2/{FactoryGetDeviceInfo.ts → DeviceFactoryInfoGet.ts} +3 -3
  76. package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +32 -0
  77. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +3 -5
  78. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +39 -5
  79. package/src/api/protocol-v2/{DeviceGetDeviceInfo.ts → DeviceInfoGet.ts} +52 -22
  80. package/src/api/protocol-v2/DeviceReboot.ts +1 -1
  81. package/src/api/protocol-v2/{FilesystemFixPermission.ts → FilesystemPermissionFix.ts} +2 -2
  82. package/src/api/protocol-v2/{GetProtoVersion.ts → ProtocolInfoRequest.ts} +2 -2
  83. package/src/api/protocol-v2/helpers.ts +64 -43
  84. package/src/api/ton/TonSignData.ts +1 -5
  85. package/src/core/index.ts +19 -5
  86. package/src/data/messages/messages-protocol-v2.json +485 -1069
  87. package/src/data-manager/DataManager.ts +7 -0
  88. package/src/data-manager/connectSettings.ts +0 -6
  89. package/src/device/Device.ts +25 -14
  90. package/src/deviceProfile/buildDeviceFeatures.ts +60 -63
  91. package/src/deviceProfile/buildDeviceProfile.ts +77 -58
  92. package/src/inject.ts +10 -16
  93. package/src/protocols/protocol-v2/features.ts +26 -63
  94. package/src/protocols/protocol-v2/firmware.ts +12 -36
  95. package/src/types/api/firmwareUpdate.ts +10 -20
  96. package/src/types/api/getDeviceInfo.ts +2 -0
  97. package/src/types/api/index.ts +10 -20
  98. package/src/types/api/protocolV2.ts +25 -43
  99. package/src/types/device.ts +1 -0
  100. package/src/types/params.ts +4 -0
  101. package/src/types/settings.ts +44 -35
  102. package/src/utils/deviceFeaturesUtils.ts +45 -10
  103. package/dist/api/protocol-v2/DevReboot.d.ts +0 -7
  104. package/dist/api/protocol-v2/DevReboot.d.ts.map +0 -1
  105. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +0 -1
  106. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +0 -6
  107. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +0 -1
  108. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +0 -7
  109. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +0 -1
  110. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +0 -6
  111. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +0 -1
  112. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +0 -1
  113. package/dist/api/protocol-v2/GetProtoVersion.d.ts +0 -6
  114. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +0 -1
  115. package/src/api/protocol-v2/DevReboot.ts +0 -24
  116. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +0 -16
  117. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +0 -29
package/dist/index.js CHANGED
@@ -138,20 +138,15 @@ const createCoreApi = (call) => ({
138
138
  deviceFlags: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFlags' })),
139
139
  deviceRebootToBoardloader: connectId => call({ connectId, method: 'deviceRebootToBoardloader' }),
140
140
  deviceRebootToBootloader: connectId => call({ connectId, method: 'deviceRebootToBootloader' }),
141
- getProtoVersion: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'getProtoVersion' })),
141
+ protocolInfoRequest: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'protocolInfoRequest' })),
142
142
  ping: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'ping' })),
143
143
  deviceReboot: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceReboot' })),
144
- deviceGetDeviceInfo: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceGetDeviceInfo' })),
145
- deviceGetOnboardingStatus: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceGetOnboardingStatus' })),
144
+ deviceInfoGet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceInfoGet' })),
146
145
  deviceFirmwareUpdate: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFirmwareUpdate' })),
147
146
  deviceGetFirmwareUpdateStatus: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceGetFirmwareUpdateStatus' })),
148
- devReboot: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'devReboot' })),
149
- devGetDeviceInfo: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'devGetDeviceInfo' })),
150
- devFirmwareUpdate: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'devFirmwareUpdate' })),
151
- devGetFirmwareUpdateStatus: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'devGetFirmwareUpdateStatus' })),
152
- factoryDeviceInfoSettings: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'factoryDeviceInfoSettings' })),
153
- factoryGetDeviceInfo: connectId => call({ connectId, method: 'factoryGetDeviceInfo' }),
154
- filesystemFixPermission: connectId => call({ connectId, method: 'filesystemFixPermission' }),
147
+ deviceFactoryInfoSet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFactoryInfoSet' })),
148
+ deviceFactoryInfoGet: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFactoryInfoGet' })),
149
+ filesystemPermissionFix: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'filesystemPermissionFix' })),
155
150
  fileRead: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'fileRead' })),
156
151
  fileWrite: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'fileWrite' })),
157
152
  fileDelete: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'fileDelete' })),
@@ -25392,7 +25387,6 @@ var nested = {
25392
25387
  MessageType_GetFeatures: 55,
25393
25388
  MessageType_SdProtect: 79,
25394
25389
  MessageType_ChangeWipeCode: 82,
25395
- MessageType_EndSession: 83,
25396
25390
  MessageType_DoPreauthorized: 84,
25397
25391
  MessageType_PreauthorizedRequest: 85,
25398
25392
  MessageType_CancelAuthorization: 86,
@@ -25400,6 +25394,8 @@ var nested = {
25400
25394
  MessageType_FirmwareHash: 89,
25401
25395
  MessageType_UnlockPath: 93,
25402
25396
  MessageType_UnlockedPathRequest: 94,
25397
+ MessageType_UnLockDevice: 10030,
25398
+ MessageType_UnLockDeviceResponse: 10031,
25403
25399
  MessageType_SetU2FCounter: 63,
25404
25400
  MessageType_GetNextU2FCounter: 80,
25405
25401
  MessageType_NextU2FCounter: 81,
@@ -25711,8 +25707,6 @@ var nested = {
25711
25707
  MessageType_TonSignProof: 11905,
25712
25708
  MessageType_TonSignedProof: 11906,
25713
25709
  MessageType_TonTxAck: 11907,
25714
- MessageType_TonSignData: 11908,
25715
- MessageType_TonSignedData: 11909,
25716
25710
  MessageType_ScdoGetAddress: 12001,
25717
25711
  MessageType_ScdoAddress: 12002,
25718
25712
  MessageType_ScdoSignTx: 12003,
@@ -25742,46 +25736,36 @@ var nested = {
25742
25736
  MessageType_NeoAddress: 12302,
25743
25737
  MessageType_NeoSignTx: 12303,
25744
25738
  MessageType_NeoSignedTx: 12304,
25745
- MessageType_ReadSEPublicKey: 10004,
25746
- MessageType_SEPublicKey: 10005,
25747
- MessageType_WriteSEPublicCert: 10006,
25748
- MessageType_ReadSEPublicCert: 10007,
25749
- MessageType_SEPublicCert: 10008,
25750
- MessageType_SESignMessage: 10012,
25751
- MessageType_SEMessageSignature: 10013,
25752
- MessageType_ResourceUpload: 10018,
25753
- MessageType_ZoomRequest: 10019,
25754
- MessageType_BlurRequest: 10032,
25755
- MessageType_SetWallpaper: 10033,
25756
- MessageType_GetWallpaper: 10034,
25757
- MessageType_Wallpaper: 10035,
25758
- MessageType_ResourceRequest: 10020,
25759
- MessageType_ResourceAck: 10021,
25760
- MessageType_ResourceUpdate: 10022,
25761
- MessageType_ListResDir: 10023,
25762
- MessageType_FileInfoList: 10024,
25763
- MessageType_OnekeyGetFeatures: 10025,
25764
- MessageType_OnekeyFeatures: 10026,
25765
- MessageType_WriteSEPrivateKey: 10027,
25766
- MessageType_GetPassphraseState: 10028,
25767
- MessageType_PassphraseState: 10029,
25768
- MessageType_UnLockDevice: 10030,
25769
- MessageType_UnLockDeviceResponse: 10031,
25770
- MessageType_FactoryDeviceInfoSettings: 60000,
25771
- MessageType_FactoryGetDeviceInfo: 60001,
25772
- MessageType_FactoryDeviceInfo: 60002,
25773
- MessageType_GetProtoVersion: 60200,
25774
- MessageType_ProtoVersion: 60201,
25775
- MessageType_StartSession: 60205,
25739
+ MessageType_UiviewShowAddressRequest: 30200,
25740
+ MessageType_UiviewShowPublicKeyRequest: 30201,
25741
+ MessageType_UiviewConfirmTxRequest: 30202,
25742
+ MessageType_UiviewConfirmSignMessageRequest: 30203,
25743
+ MessageType_UiviewResponse: 30204,
25744
+ MessageType_DeviceFactoryInfoSet: 60000,
25745
+ MessageType_DeviceFactoryInfoGet: 60001,
25746
+ MessageType_DeviceFactoryInfo: 60002,
25747
+ MessageType_DeviceFactoryPermanentLock: 60003,
25748
+ MessageType_DeviceFactoryTest: 60004,
25749
+ MessageType_ProtocolInfoRequest: 60200,
25750
+ MessageType_ProtocolInfo: 60201,
25776
25751
  MessageType_Ping: 60206,
25777
25752
  MessageType_Success: 60207,
25778
25753
  MessageType_Failure: 60208,
25779
- MessageType_DevReboot: 60400,
25780
- MessageType_DevGetDeviceInfo: 60600,
25754
+ MessageType_DeviceReboot: 60400,
25755
+ MessageType_DeviceSettings: 60410,
25756
+ MessageType_DeviceSettingsGet: 60411,
25757
+ MessageType_DeviceSettingsSet: 60412,
25758
+ MessageType_DeviceCertificate: 60420,
25759
+ MessageType_DeviceCertificateWrite: 60421,
25760
+ MessageType_DeviceCertificateRead: 60422,
25761
+ MessageType_DeviceCertificateSignature: 60423,
25762
+ MessageType_DeviceCertificateSign: 60424,
25763
+ MessageType_SetWallpaper: 60430,
25764
+ MessageType_GetWallpaper: 60431,
25765
+ MessageType_Wallpaper: 60432,
25766
+ MessageType_DeviceInfoGet: 60600,
25781
25767
  MessageType_DeviceInfo: 60601,
25782
- MessageType_GetOnboardingStatus: 60602,
25783
- MessageType_OnboardingStatus: 60603,
25784
- MessageType_FilesystemFixPermission: 60800,
25768
+ MessageType_FilesystemPermissionFix: 60800,
25785
25769
  MessageType_FilesystemPathInfo: 60801,
25786
25770
  MessageType_FilesystemPathInfoQuery: 60802,
25787
25771
  MessageType_FilesystemFile: 60803,
@@ -25793,11 +25777,28 @@ var nested = {
25793
25777
  MessageType_FilesystemDirMake: 60809,
25794
25778
  MessageType_FilesystemDirRemove: 60810,
25795
25779
  MessageType_FilesystemFormat: 60811,
25796
- MessageType_DevFirmwareUpdate: 61000,
25797
- MessageType_DevFirmwareInstallProgress: 61001,
25798
- MessageType_DevGetFirmwareUpdateStatus: 61002,
25799
- MessageType_DevFirmwareUpdateStatus: 61003
25800
- }
25780
+ MessageType_DeviceFirmwareUpdateRequest: 61000,
25781
+ MessageType_DeviceFirmwareUpdateStatusGet: 61001,
25782
+ MessageType_DeviceFirmwareUpdateStatus: 61002
25783
+ },
25784
+ reserved: [
25785
+ [
25786
+ 90,
25787
+ 92
25788
+ ],
25789
+ [
25790
+ 114,
25791
+ 122
25792
+ ],
25793
+ [
25794
+ 300,
25795
+ 304
25796
+ ],
25797
+ [
25798
+ 309,
25799
+ 312
25800
+ ]
25801
+ ]
25801
25802
  },
25802
25803
  AlephiumGetAddress: {
25803
25804
  fields: {
@@ -29391,208 +29392,6 @@ var nested = {
29391
29392
  }
29392
29393
  }
29393
29394
  },
29394
- DebugLinkInput: {
29395
- fields: {
29396
- x: {
29397
- type: "uint32",
29398
- id: 1
29399
- },
29400
- y: {
29401
- type: "uint32",
29402
- id: 2
29403
- },
29404
- duration_ms: {
29405
- type: "uint32",
29406
- id: 3
29407
- },
29408
- x_end: {
29409
- type: "uint32",
29410
- id: 4
29411
- },
29412
- y_end: {
29413
- type: "uint32",
29414
- id: 5
29415
- }
29416
- }
29417
- },
29418
- DebugLinkLayout: {
29419
- fields: {
29420
- lines: {
29421
- rule: "repeated",
29422
- type: "string",
29423
- id: 1
29424
- }
29425
- }
29426
- },
29427
- DebugLinkReseedRandom: {
29428
- fields: {
29429
- value: {
29430
- type: "uint32",
29431
- id: 1
29432
- }
29433
- }
29434
- },
29435
- DebugLinkRecordScreen: {
29436
- fields: {
29437
- target_directory: {
29438
- type: "string",
29439
- id: 1
29440
- }
29441
- }
29442
- },
29443
- DebugLinkGetState: {
29444
- fields: {
29445
- wait_word_list: {
29446
- type: "bool",
29447
- id: 1
29448
- },
29449
- wait_word_pos: {
29450
- type: "bool",
29451
- id: 2
29452
- },
29453
- wait_layout: {
29454
- type: "bool",
29455
- id: 3
29456
- }
29457
- }
29458
- },
29459
- DebugLinkState: {
29460
- fields: {
29461
- layout: {
29462
- type: "bytes",
29463
- id: 1
29464
- },
29465
- pin: {
29466
- type: "string",
29467
- id: 2
29468
- },
29469
- matrix: {
29470
- type: "string",
29471
- id: 3
29472
- },
29473
- mnemonic_secret: {
29474
- type: "bytes",
29475
- id: 4
29476
- },
29477
- node: {
29478
- type: "HDNodeType",
29479
- id: 5
29480
- },
29481
- passphrase_protection: {
29482
- type: "bool",
29483
- id: 6
29484
- },
29485
- reset_word: {
29486
- type: "string",
29487
- id: 7
29488
- },
29489
- reset_entropy: {
29490
- type: "bytes",
29491
- id: 8
29492
- },
29493
- recovery_fake_word: {
29494
- type: "string",
29495
- id: 9
29496
- },
29497
- recovery_word_pos: {
29498
- type: "uint32",
29499
- id: 10
29500
- },
29501
- reset_word_pos: {
29502
- type: "uint32",
29503
- id: 11
29504
- },
29505
- mnemonic_type: {
29506
- type: "BackupType",
29507
- id: 12
29508
- },
29509
- layout_lines: {
29510
- rule: "repeated",
29511
- type: "string",
29512
- id: 13
29513
- }
29514
- }
29515
- },
29516
- DebugLinkStop: {
29517
- fields: {
29518
- }
29519
- },
29520
- DebugLinkLog: {
29521
- fields: {
29522
- level: {
29523
- type: "uint32",
29524
- id: 1
29525
- },
29526
- bucket: {
29527
- type: "string",
29528
- id: 2
29529
- },
29530
- text: {
29531
- type: "string",
29532
- id: 3
29533
- }
29534
- }
29535
- },
29536
- DebugLinkMemoryRead: {
29537
- fields: {
29538
- address: {
29539
- type: "uint32",
29540
- id: 1
29541
- },
29542
- length: {
29543
- type: "uint32",
29544
- id: 2
29545
- }
29546
- }
29547
- },
29548
- DebugLinkMemory: {
29549
- fields: {
29550
- memory: {
29551
- type: "bytes",
29552
- id: 1
29553
- }
29554
- }
29555
- },
29556
- DebugLinkMemoryWrite: {
29557
- fields: {
29558
- address: {
29559
- type: "uint32",
29560
- id: 1
29561
- },
29562
- memory: {
29563
- type: "bytes",
29564
- id: 2
29565
- },
29566
- flash: {
29567
- type: "bool",
29568
- id: 3
29569
- }
29570
- }
29571
- },
29572
- DebugLinkFlashErase: {
29573
- fields: {
29574
- sector: {
29575
- type: "uint32",
29576
- id: 1
29577
- }
29578
- }
29579
- },
29580
- DebugLinkEraseSdCard: {
29581
- fields: {
29582
- format: {
29583
- type: "bool",
29584
- id: 1
29585
- }
29586
- }
29587
- },
29588
- DebugLinkWatchLayout: {
29589
- fields: {
29590
- watch: {
29591
- type: "bool",
29592
- id: 1
29593
- }
29594
- }
29595
- },
29596
29395
  EosGetPublicKey: {
29597
29396
  fields: {
29598
29397
  address_n: {
@@ -31627,7 +31426,7 @@ var nested = {
31627
31426
  PromptTemporarily: 2
31628
31427
  }
31629
31428
  },
31630
- Initialize: {
31429
+ StartSession: {
31631
31430
  fields: {
31632
31431
  session_id: {
31633
31432
  type: "bytes",
@@ -31643,22 +31442,10 @@ var nested = {
31643
31442
  derive_cardano: {
31644
31443
  type: "bool",
31645
31444
  id: 3
31646
- },
31647
- passphrase_state: {
31648
- type: "string",
31649
- id: 8000
31650
- },
31651
- is_contains_attach: {
31652
- type: "bool",
31653
- id: 8001
31654
31445
  }
31655
31446
  }
31656
31447
  },
31657
- GetFeatures: {
31658
- fields: {
31659
- }
31660
- },
31661
- OnekeyGetFeatures: {
31448
+ EndSession: {
31662
31449
  fields: {
31663
31450
  }
31664
31451
  },
@@ -31683,399 +31470,17 @@ var nested = {
31683
31470
  APP: 1
31684
31471
  }
31685
31472
  },
31686
- Features: {
31687
- fields: {
31688
- vendor: {
31689
- type: "string",
31690
- id: 1
31691
- },
31692
- major_version: {
31693
- rule: "required",
31694
- type: "uint32",
31695
- id: 2
31696
- },
31697
- minor_version: {
31698
- rule: "required",
31699
- type: "uint32",
31700
- id: 3
31701
- },
31702
- patch_version: {
31703
- rule: "required",
31704
- type: "uint32",
31705
- id: 4
31706
- },
31707
- bootloader_mode: {
31708
- type: "bool",
31709
- id: 5
31710
- },
31711
- device_id: {
31712
- type: "string",
31713
- id: 6
31714
- },
31715
- pin_protection: {
31716
- type: "bool",
31717
- id: 7
31718
- },
31719
- passphrase_protection: {
31720
- type: "bool",
31721
- id: 8
31722
- },
31723
- language: {
31724
- type: "string",
31725
- id: 9
31726
- },
31727
- label: {
31728
- type: "string",
31729
- id: 10
31730
- },
31731
- initialized: {
31732
- type: "bool",
31733
- id: 12
31734
- },
31735
- revision: {
31736
- type: "bytes",
31737
- id: 13
31738
- },
31739
- bootloader_hash: {
31740
- type: "bytes",
31741
- id: 14
31742
- },
31743
- imported: {
31744
- type: "bool",
31745
- id: 15
31746
- },
31747
- unlocked: {
31748
- type: "bool",
31749
- id: 16
31750
- },
31751
- _passphrase_cached: {
31752
- type: "bool",
31753
- id: 17,
31754
- options: {
31755
- deprecated: true
31756
- }
31757
- },
31758
- firmware_present: {
31759
- type: "bool",
31760
- id: 18
31761
- },
31762
- needs_backup: {
31763
- type: "bool",
31764
- id: 19
31765
- },
31766
- flags: {
31767
- type: "uint32",
31768
- id: 20
31769
- },
31770
- model: {
31771
- type: "string",
31772
- id: 21
31773
- },
31774
- fw_major: {
31775
- type: "uint32",
31776
- id: 22
31777
- },
31778
- fw_minor: {
31779
- type: "uint32",
31780
- id: 23
31781
- },
31782
- fw_patch: {
31783
- type: "uint32",
31784
- id: 24
31785
- },
31786
- fw_vendor: {
31787
- type: "string",
31788
- id: 25
31789
- },
31790
- unfinished_backup: {
31791
- type: "bool",
31792
- id: 27
31793
- },
31794
- no_backup: {
31795
- type: "bool",
31796
- id: 28
31797
- },
31798
- recovery_mode: {
31799
- type: "bool",
31800
- id: 29
31801
- },
31802
- capabilities: {
31803
- rule: "repeated",
31804
- type: "Capability",
31805
- id: 30,
31806
- options: {
31807
- packed: false
31808
- }
31809
- },
31810
- backup_type: {
31811
- type: "BackupType",
31812
- id: 31
31813
- },
31814
- sd_card_present: {
31815
- type: "bool",
31816
- id: 32
31817
- },
31818
- sd_protection: {
31819
- type: "bool",
31820
- id: 33
31821
- },
31822
- wipe_code_protection: {
31823
- type: "bool",
31824
- id: 34
31825
- },
31826
- session_id: {
31827
- type: "bytes",
31828
- id: 35
31829
- },
31830
- passphrase_always_on_device: {
31831
- type: "bool",
31832
- id: 36
31833
- },
31834
- safety_checks: {
31835
- type: "SafetyCheckLevel",
31836
- id: 37
31837
- },
31838
- auto_lock_delay_ms: {
31839
- type: "uint32",
31840
- id: 38
31841
- },
31842
- display_rotation: {
31843
- type: "uint32",
31844
- id: 39
31845
- },
31846
- experimental_features: {
31847
- type: "bool",
31848
- id: 40
31849
- },
31850
- offset: {
31851
- type: "uint32",
31852
- id: 500
31853
- },
31854
- ble_name: {
31855
- type: "string",
31856
- id: 501
31857
- },
31858
- ble_ver: {
31859
- type: "string",
31860
- id: 502
31861
- },
31862
- ble_enable: {
31863
- type: "bool",
31864
- id: 503
31865
- },
31866
- se_enable: {
31867
- type: "bool",
31868
- id: 504
31869
- },
31870
- se_ver: {
31871
- type: "string",
31872
- id: 506
31873
- },
31874
- backup_only: {
31875
- type: "bool",
31876
- id: 507
31877
- },
31878
- onekey_version: {
31879
- type: "string",
31880
- id: 508
31881
- },
31882
- onekey_serial: {
31883
- type: "string",
31884
- id: 509
31885
- },
31886
- bootloader_version: {
31887
- type: "string",
31888
- id: 510
31889
- },
31890
- serial_no: {
31891
- type: "string",
31892
- id: 511
31893
- },
31894
- spi_flash: {
31895
- type: "string",
31896
- id: 512
31897
- },
31898
- initstates: {
31899
- type: "uint32",
31900
- id: 513
31901
- },
31902
- NFT_voucher: {
31903
- type: "bytes",
31904
- id: 514
31905
- },
31906
- cpu_info: {
31907
- type: "string",
31908
- id: 515
31909
- },
31910
- pre_firmware: {
31911
- type: "string",
31912
- id: 516
31913
- },
31914
- coin_switch: {
31915
- type: "uint32",
31916
- id: 517
31917
- },
31918
- build_id: {
31919
- type: "bytes",
31920
- id: 518
31921
- },
31922
- boardloader_version: {
31923
- type: "string",
31924
- id: 519
31925
- },
31926
- busy: {
31927
- type: "bool",
31928
- id: 41
31929
- },
31930
- onekey_device_type: {
31931
- type: "OneKeyDeviceType",
31932
- id: 600
31933
- },
31934
- onekey_se_type: {
31935
- type: "OneKeySeType",
31936
- id: 601
31937
- },
31938
- onekey_board_version: {
31939
- type: "string",
31940
- id: 602
31941
- },
31942
- onekey_board_hash: {
31943
- type: "bytes",
31944
- id: 603
31945
- },
31946
- onekey_boot_version: {
31947
- type: "string",
31948
- id: 604
31949
- },
31950
- onekey_boot_hash: {
31951
- type: "bytes",
31952
- id: 605
31953
- },
31954
- onekey_se01_version: {
31955
- type: "string",
31956
- id: 606
31957
- },
31958
- onekey_se01_hash: {
31959
- type: "bytes",
31960
- id: 607
31961
- },
31962
- onekey_se01_build_id: {
31963
- type: "string",
31964
- id: 608
31965
- },
31966
- onekey_firmware_version: {
31967
- type: "string",
31968
- id: 609
31969
- },
31970
- onekey_firmware_hash: {
31971
- type: "bytes",
31972
- id: 610
31973
- },
31974
- onekey_firmware_build_id: {
31975
- type: "string",
31976
- id: 611
31977
- },
31978
- onekey_serial_no: {
31979
- type: "string",
31980
- id: 612
31981
- },
31982
- onekey_boot_build_id: {
31983
- type: "string",
31984
- id: 613
31985
- },
31986
- onekey_ble_name: {
31987
- type: "string",
31988
- id: 614
31989
- },
31990
- onekey_ble_version: {
31991
- type: "string",
31992
- id: 615
31993
- },
31994
- onekey_ble_build_id: {
31995
- type: "string",
31996
- id: 616
31997
- },
31998
- onekey_ble_hash: {
31999
- type: "bytes",
32000
- id: 617
32001
- },
32002
- onekey_se02_version: {
32003
- type: "string",
32004
- id: 618
32005
- },
32006
- onekey_se03_version: {
32007
- type: "string",
32008
- id: 619
32009
- },
32010
- onekey_se04_version: {
32011
- type: "string",
32012
- id: 620
32013
- },
32014
- onekey_se01_state: {
32015
- type: "OneKeySEState",
32016
- id: 621
32017
- },
32018
- onekey_se02_state: {
32019
- type: "OneKeySEState",
32020
- id: 622
32021
- },
32022
- onekey_se03_state: {
32023
- type: "OneKeySEState",
32024
- id: 623
32025
- },
32026
- onekey_se04_state: {
32027
- type: "OneKeySEState",
32028
- id: 624
32029
- },
32030
- attach_to_pin_user: {
32031
- type: "bool",
32032
- id: 625
32033
- },
32034
- unlocked_attach_pin: {
32035
- type: "bool",
32036
- id: 626
32037
- }
32038
- },
32039
- nested: {
32040
- Capability: {
32041
- options: {
32042
- "(has_bitcoin_only_values)": true
32043
- },
32044
- values: {
32045
- Capability_Bitcoin: 1,
32046
- Capability_Bitcoin_like: 2,
32047
- Capability_Binance: 3,
32048
- Capability_Cardano: 4,
32049
- Capability_Crypto: 5,
32050
- Capability_EOS: 6,
32051
- Capability_Ethereum: 7,
32052
- Capability_Lisk: 8,
32053
- Capability_Monero: 9,
32054
- Capability_NEM: 10,
32055
- Capability_Ripple: 11,
32056
- Capability_Stellar: 12,
32057
- Capability_Tezos: 13,
32058
- Capability_U2F: 14,
32059
- Capability_Shamir: 15,
32060
- Capability_ShamirGroups: 16,
32061
- Capability_PassphraseEntry: 17,
32062
- Capability_AttachToPin: 18,
32063
- Capability_EthereumTypedData: 1000
32064
- }
32065
- }
32066
- }
32067
- },
32068
31473
  OnekeyFeatures: {
32069
31474
  fields: {
32070
31475
  onekey_device_type: {
32071
31476
  type: "OneKeyDeviceType",
32072
31477
  id: 1
32073
31478
  },
32074
- onekey_board_version: {
31479
+ onekey_romloader_version: {
32075
31480
  type: "string",
32076
31481
  id: 2
32077
31482
  },
32078
- onekey_boot_version: {
31483
+ onekey_bootloader_version: {
32079
31484
  type: "string",
32080
31485
  id: 3
32081
31486
  },
@@ -32083,11 +31488,11 @@ var nested = {
32083
31488
  type: "string",
32084
31489
  id: 4
32085
31490
  },
32086
- onekey_board_hash: {
31491
+ onekey_romloader_hash: {
32087
31492
  type: "bytes",
32088
31493
  id: 5
32089
31494
  },
32090
- onekey_boot_hash: {
31495
+ onekey_bootloader_hash: {
32091
31496
  type: "bytes",
32092
31497
  id: 6
32093
31498
  },
@@ -32095,11 +31500,11 @@ var nested = {
32095
31500
  type: "bytes",
32096
31501
  id: 7
32097
31502
  },
32098
- onekey_board_build_id: {
31503
+ onekey_romloader_build_id: {
32099
31504
  type: "string",
32100
31505
  id: 8
32101
31506
  },
32102
- onekey_boot_build_id: {
31507
+ onekey_bootloader_build_id: {
32103
31508
  type: "string",
32104
31509
  id: 9
32105
31510
  },
@@ -32111,19 +31516,19 @@ var nested = {
32111
31516
  type: "string",
32112
31517
  id: 11
32113
31518
  },
32114
- onekey_ble_name: {
31519
+ onekey_coprocessor_bt_name: {
32115
31520
  type: "string",
32116
31521
  id: 12
32117
31522
  },
32118
- onekey_ble_version: {
31523
+ onekey_coprocessor_version: {
32119
31524
  type: "string",
32120
31525
  id: 13
32121
31526
  },
32122
- onekey_ble_build_id: {
31527
+ onekey_coprocessor_build_id: {
32123
31528
  type: "string",
32124
31529
  id: 14
32125
31530
  },
32126
- onekey_ble_hash: {
31531
+ onekey_coprocessor_hash: {
32127
31532
  type: "bytes",
32128
31533
  id: 15
32129
31534
  },
@@ -32195,51 +31600,51 @@ var nested = {
32195
31600
  type: "string",
32196
31601
  id: 32
32197
31602
  },
32198
- onekey_se01_boot_version: {
31603
+ onekey_se01_bootloader_version: {
32199
31604
  type: "string",
32200
31605
  id: 33
32201
31606
  },
32202
- onekey_se02_boot_version: {
31607
+ onekey_se02_bootloader_version: {
32203
31608
  type: "string",
32204
31609
  id: 34
32205
31610
  },
32206
- onekey_se03_boot_version: {
31611
+ onekey_se03_bootloader_version: {
32207
31612
  type: "string",
32208
31613
  id: 35
32209
31614
  },
32210
- onekey_se04_boot_version: {
31615
+ onekey_se04_bootloader_version: {
32211
31616
  type: "string",
32212
31617
  id: 36
32213
31618
  },
32214
- onekey_se01_boot_hash: {
31619
+ onekey_se01_bootloader_hash: {
32215
31620
  type: "bytes",
32216
31621
  id: 37
32217
31622
  },
32218
- onekey_se02_boot_hash: {
31623
+ onekey_se02_bootloader_hash: {
32219
31624
  type: "bytes",
32220
31625
  id: 38
32221
31626
  },
32222
- onekey_se03_boot_hash: {
31627
+ onekey_se03_bootloader_hash: {
32223
31628
  type: "bytes",
32224
31629
  id: 39
32225
31630
  },
32226
- onekey_se04_boot_hash: {
31631
+ onekey_se04_bootloader_hash: {
32227
31632
  type: "bytes",
32228
31633
  id: 40
32229
31634
  },
32230
- onekey_se01_boot_build_id: {
31635
+ onekey_se01_bootloader_build_id: {
32231
31636
  type: "string",
32232
31637
  id: 41
32233
31638
  },
32234
- onekey_se02_boot_build_id: {
31639
+ onekey_se02_bootloader_build_id: {
32235
31640
  type: "string",
32236
31641
  id: 42
32237
31642
  },
32238
- onekey_se03_boot_build_id: {
31643
+ onekey_se03_bootloader_build_id: {
32239
31644
  type: "string",
32240
31645
  id: 43
32241
31646
  },
32242
- onekey_se04_boot_build_id: {
31647
+ onekey_se04_bootloader_build_id: {
32243
31648
  type: "string",
32244
31649
  id: 44
32245
31650
  }
@@ -32257,10 +31662,6 @@ var nested = {
32257
31662
  }
32258
31663
  }
32259
31664
  },
32260
- EndSession: {
32261
- fields: {
32262
- }
32263
- },
32264
31665
  ApplySettings: {
32265
31666
  fields: {
32266
31667
  language: {
@@ -37173,182 +36574,373 @@ var nested = {
37173
36574
  }
37174
36575
  }
37175
36576
  },
37176
- TonSignData: {
36577
+ ProtocolInfoRequest: {
37177
36578
  fields: {
37178
- address_n: {
36579
+ }
36580
+ },
36581
+ ProtocolInfo: {
36582
+ fields: {
36583
+ version: {
36584
+ rule: "required",
36585
+ type: "uint32",
36586
+ id: 1
36587
+ },
36588
+ supported_messages: {
37179
36589
  rule: "repeated",
37180
36590
  type: "uint32",
37181
- id: 1,
36591
+ id: 2,
37182
36592
  options: {
37183
36593
  packed: false
37184
36594
  }
37185
36595
  },
37186
- type: {
37187
- rule: "required",
37188
- type: "TonSignDataType",
37189
- id: 2
37190
- },
37191
- payload: {
37192
- rule: "required",
37193
- type: "bytes",
37194
- id: 3
37195
- },
37196
- schema: {
36596
+ protobuf_definition: {
37197
36597
  type: "string",
37198
- id: 4
37199
- },
37200
- appdomain: {
37201
- rule: "required",
37202
- type: "string",
37203
- id: 5
37204
- },
37205
- timestamp: {
37206
- rule: "required",
37207
- type: "uint64",
37208
- id: 6
37209
- },
37210
- from_address: {
36598
+ id: 3
36599
+ }
36600
+ }
36601
+ },
36602
+ Ping: {
36603
+ fields: {
36604
+ message: {
37211
36605
  type: "string",
37212
- id: 7
37213
- },
37214
- wallet_version: {
37215
- type: "TonWalletVersion",
37216
- id: 8,
37217
- options: {
37218
- "default": "V4R2"
37219
- }
37220
- },
37221
- wallet_id: {
37222
- type: "uint32",
37223
- id: 9,
36606
+ id: 1,
37224
36607
  options: {
37225
- "default": 698983191
36608
+ "default": ""
37226
36609
  }
37227
- },
37228
- workchain: {
37229
- type: "TonWorkChain",
37230
- id: 10,
36610
+ }
36611
+ }
36612
+ },
36613
+ Success: {
36614
+ fields: {
36615
+ message: {
36616
+ type: "string",
36617
+ id: 1,
37231
36618
  options: {
37232
- "default": "BASECHAIN"
36619
+ "default": ""
37233
36620
  }
36621
+ }
36622
+ }
36623
+ },
36624
+ Failure: {
36625
+ fields: {
36626
+ code: {
36627
+ rule: "required",
36628
+ type: "FailureType",
36629
+ id: 1
37234
36630
  },
37235
- is_bounceable: {
37236
- type: "bool",
37237
- id: 11,
37238
- options: {
37239
- "default": false
37240
- }
36631
+ subcode: {
36632
+ type: "uint32",
36633
+ id: 2
37241
36634
  },
37242
- is_testnet_only: {
37243
- type: "bool",
37244
- id: 12,
37245
- options: {
37246
- "default": false
37247
- }
36635
+ message: {
36636
+ type: "string",
36637
+ id: 3
37248
36638
  }
37249
36639
  },
37250
36640
  nested: {
37251
- TonSignDataType: {
36641
+ FailureType: {
37252
36642
  values: {
37253
- TEXT: 0,
37254
- BINARY: 1,
37255
- CELL: 2
36643
+ Failure_InvalidMessage: 1,
36644
+ Failure_UndefinedError: 2,
36645
+ Failure_UsageError: 3,
36646
+ Failure_DataError: 4,
36647
+ Failure_ProcessError: 5
37256
36648
  }
37257
36649
  }
37258
36650
  }
37259
36651
  },
37260
- TonSignedData: {
36652
+ DeviceRebootType: {
36653
+ values: {
36654
+ Normal: 0,
36655
+ Romloader: 1,
36656
+ Bootloader: 2
36657
+ }
36658
+ },
36659
+ DeviceReboot: {
37261
36660
  fields: {
37262
- signature: {
36661
+ reboot_type: {
36662
+ rule: "required",
36663
+ type: "DeviceRebootType",
36664
+ id: 1
36665
+ }
36666
+ }
36667
+ },
36668
+ DeviceSettings: {
36669
+ fields: {
36670
+ label: {
36671
+ type: "string",
36672
+ id: 1
36673
+ },
36674
+ bt_enable: {
36675
+ type: "bool",
36676
+ id: 2
36677
+ },
36678
+ language: {
36679
+ type: "string",
36680
+ id: 3
36681
+ }
36682
+ }
36683
+ },
36684
+ DeviceSettingsGet: {
36685
+ fields: {
36686
+ }
36687
+ },
36688
+ DeviceSettingsSet: {
36689
+ fields: {
36690
+ settings: {
36691
+ rule: "required",
36692
+ type: "DeviceSettings",
36693
+ id: 1
36694
+ }
36695
+ }
36696
+ },
36697
+ DeviceCertificate: {
36698
+ fields: {
36699
+ cert_and_pubkey: {
36700
+ rule: "required",
37263
36701
  type: "bytes",
37264
36702
  id: 1
37265
36703
  },
37266
- digest: {
36704
+ private_key: {
37267
36705
  type: "bytes",
37268
36706
  id: 2
37269
36707
  }
37270
36708
  }
37271
36709
  },
37272
- GetProtoVersion: {
36710
+ DeviceCertificateWrite: {
36711
+ fields: {
36712
+ cert: {
36713
+ rule: "required",
36714
+ type: "DeviceCertificate",
36715
+ id: 1
36716
+ }
36717
+ }
36718
+ },
36719
+ DeviceCertificateRead: {
37273
36720
  fields: {
37274
36721
  }
37275
36722
  },
37276
- ProtoVersion: {
36723
+ DeviceCertificateSignature: {
37277
36724
  fields: {
37278
- proto_version: {
36725
+ data: {
37279
36726
  rule: "required",
37280
- type: "uint32",
36727
+ type: "bytes",
37281
36728
  id: 1
37282
36729
  }
37283
36730
  }
37284
36731
  },
37285
- Ping: {
36732
+ DeviceCertificateSign: {
37286
36733
  fields: {
37287
- message: {
36734
+ data: {
36735
+ rule: "required",
36736
+ type: "bytes",
36737
+ id: 1
36738
+ }
36739
+ }
36740
+ },
36741
+ DeviceFirmwareTargetType: {
36742
+ values: {
36743
+ FW_MGMT_TARGET_INVALID: 0,
36744
+ FW_MGMT_TARGET_CRATE: 1,
36745
+ FW_MGMT_TARGET_ROMLOADER: 2,
36746
+ FW_MGMT_TARGET_BOOTLOADER: 3,
36747
+ FW_MGMT_TARGET_APPLICATION_P1: 4,
36748
+ FW_MGMT_TARGET_APPLICATION_P2: 5,
36749
+ FW_MGMT_TARGET_COPROCESSOR: 6,
36750
+ FW_MGMT_TARGET_SE01: 7,
36751
+ FW_MGMT_TARGET_SE02: 8,
36752
+ FW_MGMT_TARGET_SE03: 9,
36753
+ FW_MGMT_TARGET_SE04: 10
36754
+ }
36755
+ },
36756
+ DeviceFirmwareUpdateTaskStatus: {
36757
+ values: {
36758
+ FW_MGMT_UPDATER_TASK_STATUS_PENDING: 0,
36759
+ FW_MGMT_UPDATER_TASK_STATUS_IN_PROGRESS: 1,
36760
+ FW_MGMT_UPDATER_TASK_STATUS_FINISHED: 2,
36761
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_FILE_NOT_FOUND: 3,
36762
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_FILE_READ: 4,
36763
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_FILE_WRITE: 5,
36764
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_VERIFY: 6,
36765
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_INSTALL: 7,
36766
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_ABORT: 8,
36767
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_BUSY: 9,
36768
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_ENTRY_OUT_OF_BOUNDS: 10
36769
+ }
36770
+ },
36771
+ DeviceFirmwareTarget: {
36772
+ fields: {
36773
+ target_id: {
36774
+ rule: "required",
36775
+ type: "DeviceFirmwareTargetType",
36776
+ id: 1
36777
+ },
36778
+ path: {
36779
+ rule: "required",
37288
36780
  type: "string",
37289
- id: 1,
37290
- options: {
37291
- "default": ""
37292
- }
36781
+ id: 2
37293
36782
  }
37294
36783
  }
37295
36784
  },
37296
- Success: {
36785
+ DeviceFirmwareUpdateRequest: {
37297
36786
  fields: {
37298
- message: {
36787
+ targets: {
36788
+ rule: "repeated",
36789
+ type: "DeviceFirmwareTarget",
36790
+ id: 1
36791
+ }
36792
+ }
36793
+ },
36794
+ DeviceFirmwareUpdateRecord: {
36795
+ fields: {
36796
+ target_id: {
36797
+ rule: "required",
36798
+ type: "DeviceFirmwareTargetType",
36799
+ id: 1
36800
+ },
36801
+ status: {
36802
+ type: "DeviceFirmwareUpdateTaskStatus",
36803
+ id: 10
36804
+ },
36805
+ payload_version: {
36806
+ type: "uint32",
36807
+ id: 20
36808
+ },
36809
+ path: {
37299
36810
  type: "string",
37300
- id: 1,
37301
- options: {
37302
- "default": ""
37303
- }
36811
+ id: 30
37304
36812
  }
37305
36813
  }
37306
36814
  },
37307
- Failure: {
36815
+ DeviceFirmwareUpdateRecordFields: {
37308
36816
  fields: {
37309
- code: {
37310
- type: "FailureType",
36817
+ status: {
36818
+ type: "bool",
36819
+ id: 10
36820
+ },
36821
+ payload_version: {
36822
+ type: "bool",
36823
+ id: 20
36824
+ },
36825
+ path: {
36826
+ type: "bool",
36827
+ id: 30
36828
+ }
36829
+ }
36830
+ },
36831
+ DeviceFirmwareUpdateStatusGet: {
36832
+ fields: {
36833
+ fields: {
36834
+ type: "DeviceFirmwareUpdateRecordFields",
36835
+ id: 1
36836
+ }
36837
+ }
36838
+ },
36839
+ DeviceFirmwareUpdateStatus: {
36840
+ fields: {
36841
+ records: {
36842
+ rule: "repeated",
36843
+ type: "DeviceFirmwareUpdateRecord",
36844
+ id: 1
36845
+ }
36846
+ }
36847
+ },
36848
+ DeviceFactoryAck: {
36849
+ values: {
36850
+ FACTORY_ACK_SUCCESS: 0,
36851
+ FACTORY_ACK_FAIL: 1
36852
+ }
36853
+ },
36854
+ DeviceFactoryInfoManufactureTime: {
36855
+ fields: {
36856
+ year: {
36857
+ rule: "required",
36858
+ type: "uint32",
37311
36859
  id: 1
37312
36860
  },
37313
- message: {
36861
+ month: {
36862
+ rule: "required",
36863
+ type: "uint32",
36864
+ id: 2
36865
+ },
36866
+ day: {
36867
+ rule: "required",
36868
+ type: "uint32",
36869
+ id: 3
36870
+ },
36871
+ hour: {
36872
+ rule: "required",
36873
+ type: "uint32",
36874
+ id: 4
36875
+ },
36876
+ minute: {
36877
+ rule: "required",
36878
+ type: "uint32",
36879
+ id: 5
36880
+ },
36881
+ second: {
36882
+ rule: "required",
36883
+ type: "uint32",
36884
+ id: 6
36885
+ }
36886
+ }
36887
+ },
36888
+ DeviceFactoryInfo: {
36889
+ fields: {
36890
+ version: {
36891
+ type: "uint32",
36892
+ id: 1
36893
+ },
36894
+ serial_number: {
37314
36895
  type: "string",
37315
36896
  id: 2
36897
+ },
36898
+ burn_in_completed: {
36899
+ type: "bool",
36900
+ id: 3
36901
+ },
36902
+ factory_test_completed: {
36903
+ type: "bool",
36904
+ id: 4
36905
+ },
36906
+ manufacture_time: {
36907
+ type: "DeviceFactoryInfoManufactureTime",
36908
+ id: 5
37316
36909
  }
37317
- },
37318
- nested: {
37319
- FailureType: {
37320
- values: {
37321
- Failure_UnexpectedMessage: 1,
37322
- Failure_ButtonExpected: 2,
37323
- Failure_DataError: 3,
37324
- Failure_ActionCancelled: 4,
37325
- Failure_PinExpected: 5,
37326
- Failure_PinCancelled: 6,
37327
- Failure_PinInvalid: 7,
37328
- Failure_InvalidSignature: 8,
37329
- Failure_ProcessError: 9,
37330
- Failure_NotEnoughFunds: 10,
37331
- Failure_NotInitialized: 11,
37332
- Failure_PinMismatch: 12,
37333
- Failure_WipeCodeMismatch: 13,
37334
- Failure_InvalidSession: 14,
37335
- Failure_FirmwareError: 99
37336
- }
36910
+ }
36911
+ },
36912
+ DeviceFactoryInfoSet: {
36913
+ fields: {
36914
+ info: {
36915
+ rule: "required",
36916
+ type: "DeviceFactoryInfo",
36917
+ id: 1
37337
36918
  }
37338
36919
  }
37339
36920
  },
37340
- DevRebootType: {
37341
- values: {
37342
- Normal: 0,
37343
- Boardloader: 1,
37344
- Bootloader: 2
36921
+ DeviceFactoryInfoGet: {
36922
+ fields: {
37345
36923
  }
37346
36924
  },
37347
- DevReboot: {
36925
+ DeviceFactoryPermanentLock: {
37348
36926
  fields: {
37349
- reboot_type: {
36927
+ check_a: {
37350
36928
  rule: "required",
37351
- type: "DevRebootType",
36929
+ type: "bytes",
36930
+ id: 1
36931
+ },
36932
+ check_b: {
36933
+ rule: "required",
36934
+ type: "bytes",
36935
+ id: 2
36936
+ }
36937
+ }
36938
+ },
36939
+ DeviceFactoryTest: {
36940
+ fields: {
36941
+ burn_in_test: {
36942
+ rule: "required",
36943
+ type: "bool",
37352
36944
  id: 1
37353
36945
  }
37354
36946
  }
@@ -37360,23 +36952,25 @@ var nested = {
37360
36952
  MINI: 2,
37361
36953
  TOUCH: 3,
37362
36954
  PRO: 5,
37363
- CLASSIC1S_PURE: 6
36955
+ CLASSIC1S_PURE: 6,
36956
+ PRO2: 7,
36957
+ NEO: 8
37364
36958
  }
37365
36959
  },
37366
- DevSeType: {
36960
+ DeviceSeType: {
37367
36961
  values: {
37368
36962
  THD89: 0,
37369
36963
  SE608A: 1
37370
36964
  }
37371
36965
  },
37372
- DevSEState: {
36966
+ DeviceSEState: {
37373
36967
  values: {
37374
36968
  BOOT: 0,
37375
36969
  APP_FACTORY: 51,
37376
36970
  APP: 85
37377
36971
  }
37378
36972
  },
37379
- DevFirmwareImageInfo: {
36973
+ DeviceFirmwareImageInfo: {
37380
36974
  fields: {
37381
36975
  version: {
37382
36976
  type: "string",
@@ -37392,19 +36986,15 @@ var nested = {
37392
36986
  }
37393
36987
  }
37394
36988
  },
37395
- DevHardwareInfo: {
36989
+ DeviceHardwareInfo: {
37396
36990
  fields: {
37397
- device_type: {
36991
+ Device_type: {
37398
36992
  type: "DeviceType",
37399
36993
  id: 10
37400
36994
  },
37401
36995
  serial_no: {
37402
36996
  type: "string",
37403
- id: 11
37404
- },
37405
- device_id: {
37406
- type: "string",
37407
- id: 12
36997
+ id: 20
37408
36998
  },
37409
36999
  hardware_version: {
37410
37000
  type: "string",
@@ -37412,67 +37002,71 @@ var nested = {
37412
37002
  },
37413
37003
  hardware_version_raw_adc: {
37414
37004
  type: "uint32",
37415
- id: 101
37005
+ id: 110
37416
37006
  }
37417
37007
  }
37418
37008
  },
37419
- DevMainMcuInfo: {
37009
+ DeviceMainMcuInfo: {
37420
37010
  fields: {
37421
- board: {
37422
- type: "DevFirmwareImageInfo",
37011
+ romloader: {
37012
+ type: "DeviceFirmwareImageInfo",
37423
37013
  id: 10
37424
37014
  },
37425
- boot: {
37426
- type: "DevFirmwareImageInfo",
37015
+ bootloader: {
37016
+ type: "DeviceFirmwareImageInfo",
37427
37017
  id: 20
37428
37018
  },
37429
- app: {
37430
- type: "DevFirmwareImageInfo",
37019
+ application: {
37020
+ type: "DeviceFirmwareImageInfo",
37431
37021
  id: 30
37022
+ },
37023
+ application_data: {
37024
+ type: "DeviceFirmwareImageInfo",
37025
+ id: 40
37432
37026
  }
37433
37027
  }
37434
37028
  },
37435
- DevBluetoothInfo: {
37029
+ DeviceCoprocessorInfo: {
37436
37030
  fields: {
37437
- boot: {
37438
- type: "DevFirmwareImageInfo",
37031
+ bootloader: {
37032
+ type: "DeviceFirmwareImageInfo",
37439
37033
  id: 20
37440
37034
  },
37441
- app: {
37442
- type: "DevFirmwareImageInfo",
37035
+ application: {
37036
+ type: "DeviceFirmwareImageInfo",
37443
37037
  id: 30
37444
37038
  },
37445
- adv_name: {
37039
+ bt_adv_name: {
37446
37040
  type: "string",
37447
37041
  id: 100
37448
37042
  },
37449
- mac: {
37043
+ bt_mac: {
37450
37044
  type: "bytes",
37451
37045
  id: 110
37452
37046
  }
37453
37047
  }
37454
37048
  },
37455
- DevSEInfo: {
37049
+ DeviceSEInfo: {
37456
37050
  fields: {
37457
- boot: {
37458
- type: "DevFirmwareImageInfo",
37051
+ bootloader: {
37052
+ type: "DeviceFirmwareImageInfo",
37459
37053
  id: 20
37460
37054
  },
37461
- app: {
37462
- type: "DevFirmwareImageInfo",
37055
+ application: {
37056
+ type: "DeviceFirmwareImageInfo",
37463
37057
  id: 30
37464
37058
  },
37465
37059
  type: {
37466
- type: "DevSeType",
37060
+ type: "DeviceSeType",
37467
37061
  id: 100
37468
37062
  },
37469
37063
  state: {
37470
- type: "DevSEState",
37064
+ type: "DeviceSEState",
37471
37065
  id: 110
37472
37066
  }
37473
37067
  }
37474
37068
  },
37475
- DevInfoTargets: {
37069
+ DeviceInfoTargets: {
37476
37070
  fields: {
37477
37071
  hw: {
37478
37072
  type: "bool",
@@ -37482,7 +37076,7 @@ var nested = {
37482
37076
  type: "bool",
37483
37077
  id: 200
37484
37078
  },
37485
- bt: {
37079
+ coprocessor: {
37486
37080
  type: "bool",
37487
37081
  id: 300
37488
37082
  },
@@ -37508,7 +37102,7 @@ var nested = {
37508
37102
  }
37509
37103
  }
37510
37104
  },
37511
- DevInfoTypes: {
37105
+ DeviceInfoTypes: {
37512
37106
  fields: {
37513
37107
  version: {
37514
37108
  type: "bool",
@@ -37528,42 +37122,14 @@ var nested = {
37528
37122
  }
37529
37123
  }
37530
37124
  },
37531
- DevStatus: {
37532
- fields: {
37533
- language: {
37534
- type: "string",
37535
- id: 100
37536
- },
37537
- bt_enable: {
37538
- type: "bool",
37539
- id: 101
37540
- },
37541
- init_states: {
37542
- type: "bool",
37543
- id: 102
37544
- },
37545
- backup_required: {
37546
- type: "bool",
37547
- id: 200
37548
- },
37549
- passphrase_protection: {
37550
- type: "bool",
37551
- id: 201
37552
- },
37553
- label: {
37554
- type: "string",
37555
- id: 300
37556
- }
37557
- }
37558
- },
37559
- DevGetDeviceInfo: {
37125
+ DeviceInfoGet: {
37560
37126
  fields: {
37561
37127
  targets: {
37562
- type: "DevInfoTargets",
37128
+ type: "DeviceInfoTargets",
37563
37129
  id: 1
37564
37130
  },
37565
37131
  types: {
37566
- type: "DevInfoTypes",
37132
+ type: "DeviceInfoTypes",
37567
37133
  id: 2
37568
37134
  }
37569
37135
  }
@@ -37576,168 +37142,92 @@ var nested = {
37576
37142
  id: 1
37577
37143
  },
37578
37144
  hw: {
37579
- type: "DevHardwareInfo",
37145
+ type: "DeviceHardwareInfo",
37580
37146
  id: 100
37581
37147
  },
37582
37148
  fw: {
37583
- type: "DevMainMcuInfo",
37149
+ type: "DeviceMainMcuInfo",
37584
37150
  id: 200
37585
37151
  },
37586
- bt: {
37587
- type: "DevBluetoothInfo",
37152
+ coprocessor: {
37153
+ type: "DeviceCoprocessorInfo",
37588
37154
  id: 300
37589
37155
  },
37590
37156
  se1: {
37591
- type: "DevSEInfo",
37157
+ type: "DeviceSEInfo",
37592
37158
  id: 400
37593
37159
  },
37594
37160
  se2: {
37595
- type: "DevSEInfo",
37161
+ type: "DeviceSEInfo",
37596
37162
  id: 410
37597
37163
  },
37598
37164
  se3: {
37599
- type: "DevSEInfo",
37165
+ type: "DeviceSEInfo",
37600
37166
  id: 420
37601
37167
  },
37602
37168
  se4: {
37603
- type: "DevSEInfo",
37169
+ type: "DeviceSEInfo",
37604
37170
  id: 430
37605
37171
  },
37606
37172
  status: {
37607
- type: "DevStatus",
37173
+ type: "DeviceStatus",
37608
37174
  id: 10000
37609
37175
  }
37610
37176
  }
37611
37177
  },
37612
- DevFirmwareTargetType: {
37613
- values: {
37614
- TARGET_MAIN_APP: 0,
37615
- TARGET_MAIN_BOOT: 1,
37616
- TARGET_BT: 2,
37617
- TARGET_SE1: 3,
37618
- TARGET_SE2: 4,
37619
- TARGET_SE3: 5,
37620
- TARGET_SE4: 6,
37621
- TARGET_RESOURCE: 10
37622
- }
37623
- },
37624
- DevFirmwareTarget: {
37625
- fields: {
37626
- target_id: {
37627
- rule: "required",
37628
- type: "DevFirmwareTargetType",
37629
- id: 1
37630
- },
37631
- path: {
37632
- rule: "required",
37633
- type: "string",
37634
- id: 2
37635
- }
37636
- }
37637
- },
37638
- DevFirmwareUpdate: {
37639
- fields: {
37640
- targets: {
37641
- rule: "repeated",
37642
- type: "DevFirmwareTarget",
37643
- id: 1
37644
- }
37645
- }
37646
- },
37647
- DevFirmwareInstallProgress: {
37648
- fields: {
37649
- target_id: {
37650
- rule: "required",
37651
- type: "DevFirmwareTargetType",
37652
- id: 1
37653
- },
37654
- progress: {
37655
- rule: "required",
37656
- type: "uint32",
37657
- id: 2
37658
- },
37659
- stage: {
37660
- type: "string",
37661
- id: 3
37662
- }
37663
- }
37664
- },
37665
- DevFirmwareUpdateStatusEntry: {
37666
- fields: {
37667
- target_id: {
37668
- rule: "required",
37669
- type: "DevFirmwareTargetType",
37670
- id: 1
37671
- },
37672
- status: {
37673
- rule: "required",
37674
- type: "uint32",
37675
- id: 2
37676
- }
37677
- }
37678
- },
37679
- DevGetFirmwareUpdateStatus: {
37178
+ DeviceSessionGet: {
37680
37179
  fields: {
37681
- }
37682
- },
37683
- DevFirmwareUpdateStatus: {
37684
- fields: {
37685
- targets: {
37686
- rule: "repeated",
37687
- type: "DevFirmwareUpdateStatusEntry",
37180
+ session_id: {
37181
+ type: "bytes",
37688
37182
  id: 1
37689
37183
  }
37690
37184
  }
37691
37185
  },
37692
- FactoryDeviceInfoSettings: {
37186
+ DeviceSession: {
37693
37187
  fields: {
37694
- serial_no: {
37695
- type: "string",
37188
+ session_id: {
37189
+ type: "bytes",
37696
37190
  id: 1
37697
37191
  },
37698
- cpu_info: {
37192
+ btc_test_address: {
37699
37193
  type: "string",
37700
37194
  id: 2
37701
- },
37702
- pre_firmware: {
37703
- type: "string",
37704
- id: 3
37705
37195
  }
37706
37196
  }
37707
37197
  },
37708
- FactoryGetDeviceInfo: {
37709
- fields: {
37710
- }
37711
- },
37712
- FactoryDeviceInfo: {
37198
+ DeviceStatus: {
37713
37199
  fields: {
37714
- serial_no: {
37200
+ device_id: {
37715
37201
  type: "string",
37716
37202
  id: 1
37717
37203
  },
37718
- spi_flash_info: {
37719
- type: "string",
37204
+ unlocked: {
37205
+ type: "bool",
37720
37206
  id: 2
37721
37207
  },
37722
- se_info: {
37723
- type: "string",
37208
+ init_states: {
37209
+ type: "bool",
37724
37210
  id: 3
37725
37211
  },
37726
- nft_voucher: {
37727
- type: "bytes",
37212
+ backup_required: {
37213
+ type: "bool",
37728
37214
  id: 4
37729
37215
  },
37730
- cpu_info: {
37731
- type: "string",
37732
- id: 5
37216
+ passphrase_enabled: {
37217
+ type: "bool",
37218
+ id: 10
37733
37219
  },
37734
- pre_firmware: {
37735
- type: "string",
37736
- id: 6
37220
+ attach_to_pin_enabled: {
37221
+ type: "bool",
37222
+ id: 11
37223
+ },
37224
+ unlocked_by_attach_to_pin: {
37225
+ type: "bool",
37226
+ id: 12
37737
37227
  }
37738
37228
  }
37739
37229
  },
37740
- FilesystemFixPermission: {
37230
+ FilesystemPermissionFix: {
37741
37231
  fields: {
37742
37232
  }
37743
37233
  },
@@ -37954,76 +37444,6 @@ var nested = {
37954
37444
  fields: {
37955
37445
  }
37956
37446
  },
37957
- OnboardingStep: {
37958
- values: {
37959
- ONBOARDING_STEP_UNKNOWN: 0,
37960
- ONBOARDING_STEP_DEVICE_VERIFICATION: 1,
37961
- ONBOARDING_STEP_PERSONALIZATION: 2,
37962
- ONBOARDING_STEP_SETUP: 3,
37963
- ONBOARDING_STEP_FIRMWARE: 4
37964
- }
37965
- },
37966
- GetOnboardingStatus: {
37967
- fields: {
37968
- }
37969
- },
37970
- OnboardingStatus: {
37971
- fields: {
37972
- step: {
37973
- rule: "required",
37974
- type: "OnboardingStep",
37975
- id: 1
37976
- },
37977
- setup: {
37978
- type: "Setup",
37979
- id: 2
37980
- },
37981
- detail_code: {
37982
- type: "uint32",
37983
- id: 3
37984
- },
37985
- detail_str: {
37986
- type: "string",
37987
- id: 4
37988
- }
37989
- },
37990
- nested: {
37991
- Setup: {
37992
- fields: {
37993
- new_device: {
37994
- type: "NewDevice",
37995
- id: 1
37996
- },
37997
- restore: {
37998
- type: "Restore",
37999
- id: 2
38000
- }
38001
- },
38002
- nested: {
38003
- NewDevice: {
38004
- fields: {
38005
- seedcard_backup: {
38006
- type: "bool",
38007
- id: 1
38008
- }
38009
- }
38010
- },
38011
- Restore: {
38012
- fields: {
38013
- mnemonic: {
38014
- type: "bool",
38015
- id: 1
38016
- },
38017
- seedcard: {
38018
- type: "bool",
38019
- id: 2
38020
- }
38021
- }
38022
- }
38023
- }
38024
- }
38025
- }
38026
- },
38027
37447
  google: {
38028
37448
  nested: {
38029
37449
  protobuf: {
@@ -38792,12 +38212,14 @@ var _a$1;
38792
38212
  const Log$g = getLogger(exports.LoggerNames.Core);
38793
38213
  const FIRMWARE_FIELDS = [
38794
38214
  'firmware',
38215
+ 'firmware-v1',
38795
38216
  'firmware-v2',
38796
38217
  'firmware-v8',
38797
38218
  'firmware-btc-v8',
38798
38219
  ];
38799
38220
  const FIRMWARE_FIELD_TYPE_MAP = {
38800
38221
  firmware: hdShared.EFirmwareType.Universal,
38222
+ 'firmware-v1': hdShared.EFirmwareType.Universal,
38801
38223
  'firmware-v2': hdShared.EFirmwareType.Universal,
38802
38224
  'firmware-v8': hdShared.EFirmwareType.Universal,
38803
38225
  'firmware-btc-v8': hdShared.EFirmwareType.BitcoinOnly,
@@ -38889,6 +38311,7 @@ class DataManager {
38889
38311
  [hdShared.EDeviceType.Mini]: this.enrichFirmwareReleaseInfo(data.mini),
38890
38312
  [hdShared.EDeviceType.Touch]: this.enrichFirmwareReleaseInfo(data.touch),
38891
38313
  [hdShared.EDeviceType.Pro]: this.enrichFirmwareReleaseInfo(data.pro),
38314
+ [hdShared.EDeviceType.Pro2]: this.enrichFirmwareReleaseInfo(data.pro2),
38892
38315
  };
38893
38316
  this.assets = {
38894
38317
  bridge: data.bridge,
@@ -38949,6 +38372,10 @@ DataManager.deviceMap = {
38949
38372
  firmware: [],
38950
38373
  ble: [],
38951
38374
  },
38375
+ [hdShared.EDeviceType.Pro2]: {
38376
+ firmware: [],
38377
+ ble: [],
38378
+ },
38952
38379
  [hdShared.EDeviceType.ClassicPure]: {
38953
38380
  firmware: [],
38954
38381
  ble: [],
@@ -39207,7 +38634,7 @@ const supportInputPinOnSoftware = (features) => {
39207
38634
  return { support: semver__default["default"].gte(currentVersion, '2.3.0'), require: '2.3.0' };
39208
38635
  };
39209
38636
  const getPassphraseStateWithRefreshDeviceInfo = (device, options) => __awaiter(void 0, void 0, void 0, function* () {
39210
- var _a, _b;
38637
+ var _a, _b, _c;
39211
38638
  const { features } = device;
39212
38639
  const locked = (features === null || features === void 0 ? void 0 : features.unlocked) === false;
39213
38640
  const deviceType = device.getCurrentDeviceType();
@@ -39225,19 +38652,38 @@ const getPassphraseStateWithRefreshDeviceInfo = (device, options) => __awaiter(v
39225
38652
  }
39226
38653
  const deviceId = device.getCurrentDeviceId();
39227
38654
  device.updateInternalState((_a = device.getCurrentPassphraseProtection()) !== null && _a !== void 0 ? _a : false, passphraseState, deviceId, newSession, (options === null || options === void 0 ? void 0 : options.initSession) ? null : (_b = device.features) === null || _b === void 0 ? void 0 : _b.sessionId);
39228
- return { passphraseState, newSession, unlockedAttachPin };
38655
+ return {
38656
+ passphraseState,
38657
+ newSession,
38658
+ unlockedAttachPin: unlockedAttachPin !== null && unlockedAttachPin !== void 0 ? unlockedAttachPin : (_c = device.features) === null || _c === void 0 ? void 0 : _c.unlockedAttachPin,
38659
+ };
39229
38660
  });
39230
38661
  const supportProSeriesAttachPinPassphrase = (deviceType, firmwareVersion) => deviceType === hdShared.EDeviceType.Pro && semver__default["default"].gte(firmwareVersion, '4.15.0');
39231
38662
  const getPassphraseState = (device, options) => __awaiter(void 0, void 0, void 0, function* () {
39232
- var _c;
38663
+ var _d, _e;
39233
38664
  const { features, commands } = device;
39234
38665
  if (!features)
39235
38666
  return { passphraseState: undefined, newSession: undefined, unlockedAttachPin: undefined };
39236
- const firmwareVersion = (_c = device.getCurrentFirmwareVersionString()) !== null && _c !== void 0 ? _c : '0.0.0';
38667
+ const firmwareVersion = (_d = device.getCurrentFirmwareVersionString()) !== null && _d !== void 0 ? _d : '0.0.0';
39237
38668
  const deviceType = device.getCurrentDeviceType();
38669
+ if (device.isProtocolV2()) {
38670
+ const payload = {};
38671
+ const cachedSessionId = typeof device.getInternalState === 'function' ? device.getInternalState() : undefined;
38672
+ if (cachedSessionId) {
38673
+ payload.session_id = cachedSessionId;
38674
+ }
38675
+ const { message, type } = yield commands.typedCall('DeviceSessionGet', 'DeviceSession', payload);
38676
+ if (type === 'CallMethodError') {
38677
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
38678
+ }
38679
+ return {
38680
+ passphraseState: message.btc_test_address,
38681
+ newSession: message.session_id,
38682
+ unlockedAttachPin: (_e = features.unlockedAttachPin) !== null && _e !== void 0 ? _e : undefined,
38683
+ };
38684
+ }
39238
38685
  const supportAttachPinCapability = existCapability(features, hdTransport.Enum_Capability.Capability_AttachToPin);
39239
- const supportGetPassphraseState = device.isProtocolV2() ||
39240
- supportAttachPinCapability ||
38686
+ const supportGetPassphraseState = supportAttachPinCapability ||
39241
38687
  supportProSeriesAttachPinPassphrase(deviceType, firmwareVersion);
39242
38688
  if (supportGetPassphraseState) {
39243
38689
  const payload = (options === null || options === void 0 ? void 0 : options.onlyMainPin)
@@ -39311,6 +38757,9 @@ const getFirmwareUpdateField = ({ features, updateType, targetVersion, firmwareT
39311
38757
  if (deviceType === hdShared.EDeviceType.Pro) {
39312
38758
  return latestFirmwareField;
39313
38759
  }
38760
+ if (deviceType === hdShared.EDeviceType.Pro2) {
38761
+ return 'firmware-v1';
38762
+ }
39314
38763
  return 'firmware';
39315
38764
  };
39316
38765
  const getFirmwareUpdateFieldArray = (features, updateType) => {
@@ -39340,6 +38789,9 @@ const getFirmwareUpdateFieldArray = (features, updateType) => {
39340
38789
  if (deviceType === 'pro') {
39341
38790
  return ['firmware-v8'];
39342
38791
  }
38792
+ if (deviceType === 'pro2') {
38793
+ return ['firmware-v1'];
38794
+ }
39343
38795
  return ['firmware'];
39344
38796
  };
39345
38797
  function fixVersion(version) {
@@ -39391,7 +38843,6 @@ const initialSettings = {
39391
38843
  env: 'web',
39392
38844
  lazyLoad: false,
39393
38845
  timestamp: new Date().getTime(),
39394
- protocolV2DeviceInfoMockEnabled: false,
39395
38846
  };
39396
38847
  const getEnv = () => {
39397
38848
  if (typeof chrome !== 'undefined' &&
@@ -39465,9 +38916,6 @@ const parseConnectSettings = (input = {}) => {
39465
38916
  if (input.fetchConfig) {
39466
38917
  settings.fetchConfig = input.fetchConfig;
39467
38918
  }
39468
- if (typeof input.protocolV2DeviceInfoMockEnabled === 'boolean') {
39469
- settings.protocolV2DeviceInfoMockEnabled = input.protocolV2DeviceInfoMockEnabled;
39470
- }
39471
38919
  return settings;
39472
38920
  };
39473
38921
 
@@ -41053,11 +40501,12 @@ class DeviceCommands {
41053
40501
  }
41054
40502
  }
41055
40503
 
40504
+ const isProtocolV2BootloaderDeviceInfo = (deviceInfo) => !!deviceInfo && deviceInfo.status == null;
41056
40505
  const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
41057
40506
  targets: {
41058
40507
  hw: true,
41059
40508
  fw: true,
41060
- bt: true,
40509
+ coprocessor: true,
41061
40510
  status: true,
41062
40511
  },
41063
40512
  types: {
@@ -41068,7 +40517,7 @@ const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
41068
40517
  const PROTOCOL_V2_STATUS_DEVICE_INFO_REQUEST = {
41069
40518
  targets: {
41070
40519
  hw: true,
41071
- bt: true,
40520
+ coprocessor: true,
41072
40521
  status: true,
41073
40522
  },
41074
40523
  types: {
@@ -41080,7 +40529,7 @@ const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST = {
41080
40529
  targets: {
41081
40530
  hw: true,
41082
40531
  fw: true,
41083
- bt: true,
40532
+ coprocessor: true,
41084
40533
  se1: true,
41085
40534
  se2: true,
41086
40535
  se3: true,
@@ -41096,7 +40545,7 @@ const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
41096
40545
  targets: {
41097
40546
  hw: true,
41098
40547
  fw: true,
41099
- bt: true,
40548
+ coprocessor: true,
41100
40549
  se1: true,
41101
40550
  se2: true,
41102
40551
  se3: true,
@@ -41112,33 +40561,9 @@ const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
41112
40561
  };
41113
40562
  const PROTOCOL_V2_DEVICE_INFO_REQUEST = PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST;
41114
40563
  const PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS = 10 * 1000;
41115
- let protocolV2DeviceInfoMockEnabled = false;
41116
- const setProtocolV2DeviceInfoMock = (enabled) => {
41117
- protocolV2DeviceInfoMockEnabled = enabled;
41118
- };
41119
- const isProtocolV2DeviceInfoMockEnabled = () => protocolV2DeviceInfoMockEnabled;
41120
- const buildMockProtocolV2DeviceInfo = () => ({
41121
- protocol_version: 2,
41122
- hw: {
41123
- serial_no: '',
41124
- },
41125
- fw: {
41126
- app: { version: '0.1.0' },
41127
- },
41128
- bt: {},
41129
- status: {
41130
- init_states: true,
41131
- language: 'en_US',
41132
- passphrase_protection: false,
41133
- bt_enable: true,
41134
- },
41135
- });
41136
40564
  function requestProtocolV2DeviceInfo({ commands, timeoutMs = PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS, request = PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST, }) {
41137
40565
  return __awaiter(this, void 0, void 0, function* () {
41138
- if (isProtocolV2DeviceInfoMockEnabled()) {
41139
- return buildMockProtocolV2DeviceInfo();
41140
- }
41141
- const { message } = yield commands.typedCall('DevGetDeviceInfo', 'DeviceInfo', request, {
40566
+ const { message } = yield commands.typedCall('DeviceInfoGet', 'DeviceInfo', request, {
41142
40567
  timeoutMs,
41143
40568
  });
41144
40569
  return message;
@@ -41153,7 +40578,7 @@ const versionArrayToString = (version) => {
41153
40578
  const value = version.join('.');
41154
40579
  return isMeaningfulVersion(value) ? value : null;
41155
40580
  };
41156
- const bytesToHex$2 = (value) => {
40581
+ const bytesToHex$3 = (value) => {
41157
40582
  if (!value)
41158
40583
  return undefined;
41159
40584
  if (typeof value === 'string')
@@ -41170,7 +40595,7 @@ const bytesToHex$2 = (value) => {
41170
40595
  };
41171
40596
  const getImageVersion$1 = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.version) !== null && _a !== void 0 ? _a : null; };
41172
40597
  const getImageBuildId$1 = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.build_id) !== null && _a !== void 0 ? _a : undefined; };
41173
- const getImageHash$1 = (image) => bytesToHex$2(image === null || image === void 0 ? void 0 : image.hash);
40598
+ const getImageHash$1 = (image) => bytesToHex$3(image === null || image === void 0 ? void 0 : image.hash);
41174
40599
  const shouldIncludeVerify = (scope) => scope === 'verify' || scope === 'full';
41175
40600
  const getDeviceMode = (features) => {
41176
40601
  if (!features)
@@ -41185,6 +40610,8 @@ const getDeviceMode = (features) => {
41185
40610
  };
41186
40611
  const getProtocolV2Mode = (deviceInfo) => {
41187
40612
  var _a;
40613
+ if (isProtocolV2BootloaderDeviceInfo(deviceInfo))
40614
+ return 'bootloader';
41188
40615
  const initialized = (_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _a === void 0 ? void 0 : _a.init_states;
41189
40616
  if (initialized === false)
41190
40617
  return 'notInitialized';
@@ -41207,49 +40634,56 @@ const normalizeV1Versions = (features, protocolV1OneKeyFeatures) => ({
41207
40634
  se04Boot: firstMeaningfulVersion$1(protocolV1OneKeyFeatures === null || protocolV1OneKeyFeatures === void 0 ? void 0 : protocolV1OneKeyFeatures.onekey_se04_boot_version, features === null || features === void 0 ? void 0 : features.se04BootVersion),
41208
40635
  });
41209
40636
  const normalizeV2Versions = (deviceInfo) => {
41210
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
41211
- return ({
41212
- firmware: firstMeaningfulVersion$1(getImageVersion$1((_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _a === void 0 ? void 0 : _a.app)),
41213
- bootloader: firstMeaningfulVersion$1(getImageVersion$1((_b = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _b === void 0 ? void 0 : _b.boot)),
41214
- board: firstMeaningfulVersion$1(getImageVersion$1((_c = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _c === void 0 ? void 0 : _c.board)),
41215
- ble: firstMeaningfulVersion$1(getImageVersion$1((_d = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.bt) === null || _d === void 0 ? void 0 : _d.app)),
41216
- se01: firstMeaningfulVersion$1(getImageVersion$1((_e = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _e === void 0 ? void 0 : _e.app)),
41217
- se02: firstMeaningfulVersion$1(getImageVersion$1((_f = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _f === void 0 ? void 0 : _f.app)),
41218
- se03: firstMeaningfulVersion$1(getImageVersion$1((_g = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _g === void 0 ? void 0 : _g.app)),
41219
- se04: firstMeaningfulVersion$1(getImageVersion$1((_h = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _h === void 0 ? void 0 : _h.app)),
41220
- se01Boot: firstMeaningfulVersion$1(getImageVersion$1((_j = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _j === void 0 ? void 0 : _j.boot)),
41221
- se02Boot: firstMeaningfulVersion$1(getImageVersion$1((_k = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _k === void 0 ? void 0 : _k.boot)),
41222
- se03Boot: firstMeaningfulVersion$1(getImageVersion$1((_l = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _l === void 0 ? void 0 : _l.boot)),
41223
- se04Boot: firstMeaningfulVersion$1(getImageVersion$1((_m = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _m === void 0 ? void 0 : _m.boot)),
41224
- });
40637
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
40638
+ const info = deviceInfo;
40639
+ return {
40640
+ firmware: firstMeaningfulVersion$1(getImageVersion$1((_a = info === null || info === void 0 ? void 0 : info.fw) === null || _a === void 0 ? void 0 : _a.application)),
40641
+ bootloader: firstMeaningfulVersion$1(getImageVersion$1((_b = info === null || info === void 0 ? void 0 : info.fw) === null || _b === void 0 ? void 0 : _b.bootloader)),
40642
+ board: firstMeaningfulVersion$1(getImageVersion$1((_d = (_c = info === null || info === void 0 ? void 0 : info.fw) === null || _c === void 0 ? void 0 : _c.application_data) !== null && _d !== void 0 ? _d : (_e = info === null || info === void 0 ? void 0 : info.fw) === null || _e === void 0 ? void 0 : _e.romloader)),
40643
+ ble: firstMeaningfulVersion$1(getImageVersion$1((_f = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _f === void 0 ? void 0 : _f.application)),
40644
+ se01: firstMeaningfulVersion$1(getImageVersion$1((_g = info === null || info === void 0 ? void 0 : info.se1) === null || _g === void 0 ? void 0 : _g.application)),
40645
+ se02: firstMeaningfulVersion$1(getImageVersion$1((_h = info === null || info === void 0 ? void 0 : info.se2) === null || _h === void 0 ? void 0 : _h.application)),
40646
+ se03: firstMeaningfulVersion$1(getImageVersion$1((_j = info === null || info === void 0 ? void 0 : info.se3) === null || _j === void 0 ? void 0 : _j.application)),
40647
+ se04: firstMeaningfulVersion$1(getImageVersion$1((_k = info === null || info === void 0 ? void 0 : info.se4) === null || _k === void 0 ? void 0 : _k.application)),
40648
+ se01Boot: firstMeaningfulVersion$1(getImageVersion$1((_l = info === null || info === void 0 ? void 0 : info.se1) === null || _l === void 0 ? void 0 : _l.bootloader)),
40649
+ se02Boot: firstMeaningfulVersion$1(getImageVersion$1((_m = info === null || info === void 0 ? void 0 : info.se2) === null || _m === void 0 ? void 0 : _m.bootloader)),
40650
+ se03Boot: firstMeaningfulVersion$1(getImageVersion$1((_o = info === null || info === void 0 ? void 0 : info.se3) === null || _o === void 0 ? void 0 : _o.bootloader)),
40651
+ se04Boot: firstMeaningfulVersion$1(getImageVersion$1((_p = info === null || info === void 0 ? void 0 : info.se4) === null || _p === void 0 ? void 0 : _p.bootloader)),
40652
+ };
41225
40653
  };
41226
40654
  const normalizeV1Status = (features) => {
41227
- var _a, _b, _c, _d, _e, _f, _g, _h;
40655
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
41228
40656
  return ({
41229
40657
  mode: getDeviceMode(features),
41230
40658
  initialized: (_a = features === null || features === void 0 ? void 0 : features.initialized) !== null && _a !== void 0 ? _a : null,
41231
40659
  bootloaderMode: (_b = features === null || features === void 0 ? void 0 : features.bootloaderMode) !== null && _b !== void 0 ? _b : null,
41232
40660
  unlocked: (_c = features === null || features === void 0 ? void 0 : features.unlocked) !== null && _c !== void 0 ? _c : null,
41233
40661
  passphraseProtection: (_d = features === null || features === void 0 ? void 0 : features.passphraseProtection) !== null && _d !== void 0 ? _d : null,
41234
- backupRequired: (_e = features === null || features === void 0 ? void 0 : features.backupRequired) !== null && _e !== void 0 ? _e : null,
41235
- noBackup: (_f = features === null || features === void 0 ? void 0 : features.noBackup) !== null && _f !== void 0 ? _f : null,
41236
- language: (_g = features === null || features === void 0 ? void 0 : features.language) !== null && _g !== void 0 ? _g : null,
41237
- bleEnabled: (_h = features === null || features === void 0 ? void 0 : features.bleEnabled) !== null && _h !== void 0 ? _h : null,
40662
+ attachToPinEnabled: (_e = features === null || features === void 0 ? void 0 : features.attachToPinEnabled) !== null && _e !== void 0 ? _e : null,
40663
+ unlockedAttachPin: (_f = features === null || features === void 0 ? void 0 : features.unlockedAttachPin) !== null && _f !== void 0 ? _f : null,
40664
+ backupRequired: (_g = features === null || features === void 0 ? void 0 : features.backupRequired) !== null && _g !== void 0 ? _g : null,
40665
+ noBackup: (_h = features === null || features === void 0 ? void 0 : features.noBackup) !== null && _h !== void 0 ? _h : null,
40666
+ language: (_j = features === null || features === void 0 ? void 0 : features.language) !== null && _j !== void 0 ? _j : null,
40667
+ bleEnabled: (_k = features === null || features === void 0 ? void 0 : features.bleEnabled) !== null && _k !== void 0 ? _k : null,
41238
40668
  });
41239
40669
  };
41240
40670
  const normalizeV2Status = (deviceInfo) => {
41241
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
41242
- return ({
40671
+ var _a, _b, _c, _d, _e, _f;
40672
+ const status = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status;
40673
+ const bootloaderMode = isProtocolV2BootloaderDeviceInfo(deviceInfo);
40674
+ return {
41243
40675
  mode: getProtocolV2Mode(deviceInfo),
41244
- initialized: (_b = (_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _a === void 0 ? void 0 : _a.init_states) !== null && _b !== void 0 ? _b : null,
41245
- bootloaderMode: false,
41246
- unlocked: null,
41247
- passphraseProtection: (_d = (_c = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _c === void 0 ? void 0 : _c.passphrase_protection) !== null && _d !== void 0 ? _d : null,
41248
- backupRequired: (_f = (_e = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _e === void 0 ? void 0 : _e.backup_required) !== null && _f !== void 0 ? _f : null,
40676
+ initialized: (_a = status === null || status === void 0 ? void 0 : status.init_states) !== null && _a !== void 0 ? _a : null,
40677
+ bootloaderMode,
40678
+ unlocked: (_b = status === null || status === void 0 ? void 0 : status.unlocked) !== null && _b !== void 0 ? _b : null,
40679
+ passphraseProtection: (_c = status === null || status === void 0 ? void 0 : status.passphrase_enabled) !== null && _c !== void 0 ? _c : null,
40680
+ attachToPinEnabled: (_d = status === null || status === void 0 ? void 0 : status.attach_to_pin_enabled) !== null && _d !== void 0 ? _d : null,
40681
+ unlockedAttachPin: (_e = status === null || status === void 0 ? void 0 : status.unlocked_by_attach_to_pin) !== null && _e !== void 0 ? _e : null,
40682
+ backupRequired: (_f = status === null || status === void 0 ? void 0 : status.backup_required) !== null && _f !== void 0 ? _f : null,
41249
40683
  noBackup: null,
41250
- language: (_h = (_g = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _g === void 0 ? void 0 : _g.language) !== null && _h !== void 0 ? _h : null,
41251
- bleEnabled: (_k = (_j = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _j === void 0 ? void 0 : _j.bt_enable) !== null && _k !== void 0 ? _k : null,
41252
- });
40684
+ language: null,
40685
+ bleEnabled: null,
40686
+ };
41253
40687
  };
41254
40688
  const normalizeV1Verify = (features, protocolV1OneKeyFeatures) => {
41255
40689
  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;
@@ -41281,33 +40715,34 @@ const normalizeV1Verify = (features, protocolV1OneKeyFeatures) => {
41281
40715
  });
41282
40716
  };
41283
40717
  const normalizeV2Verify = (deviceInfo) => {
41284
- 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;
41285
- return ({
41286
- firmwareBuildId: getImageBuildId$1((_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _a === void 0 ? void 0 : _a.app),
41287
- firmwareHash: getImageHash$1((_b = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _b === void 0 ? void 0 : _b.app),
41288
- bootloaderBuildId: getImageBuildId$1((_c = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _c === void 0 ? void 0 : _c.boot),
41289
- bootloaderHash: getImageHash$1((_d = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _d === void 0 ? void 0 : _d.boot),
41290
- boardBuildId: getImageBuildId$1((_e = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _e === void 0 ? void 0 : _e.board),
41291
- boardHash: getImageHash$1((_f = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _f === void 0 ? void 0 : _f.board),
41292
- bleBuildId: getImageBuildId$1((_g = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.bt) === null || _g === void 0 ? void 0 : _g.app),
41293
- bleHash: getImageHash$1((_h = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.bt) === null || _h === void 0 ? void 0 : _h.app),
41294
- se01BuildId: getImageBuildId$1((_j = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _j === void 0 ? void 0 : _j.app),
41295
- se01Hash: getImageHash$1((_k = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _k === void 0 ? void 0 : _k.app),
41296
- se02BuildId: getImageBuildId$1((_l = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _l === void 0 ? void 0 : _l.app),
41297
- se02Hash: getImageHash$1((_m = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _m === void 0 ? void 0 : _m.app),
41298
- se03BuildId: getImageBuildId$1((_o = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _o === void 0 ? void 0 : _o.app),
41299
- se03Hash: getImageHash$1((_p = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _p === void 0 ? void 0 : _p.app),
41300
- se04BuildId: getImageBuildId$1((_q = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _q === void 0 ? void 0 : _q.app),
41301
- se04Hash: getImageHash$1((_r = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _r === void 0 ? void 0 : _r.app),
41302
- se01BootBuildId: getImageBuildId$1((_s = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _s === void 0 ? void 0 : _s.boot),
41303
- se01BootHash: getImageHash$1((_t = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _t === void 0 ? void 0 : _t.boot),
41304
- se02BootBuildId: getImageBuildId$1((_u = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _u === void 0 ? void 0 : _u.boot),
41305
- se02BootHash: getImageHash$1((_v = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _v === void 0 ? void 0 : _v.boot),
41306
- se03BootBuildId: getImageBuildId$1((_w = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _w === void 0 ? void 0 : _w.boot),
41307
- se03BootHash: getImageHash$1((_x = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _x === void 0 ? void 0 : _x.boot),
41308
- se04BootBuildId: getImageBuildId$1((_y = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _y === void 0 ? void 0 : _y.boot),
41309
- se04BootHash: getImageHash$1((_z = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _z === void 0 ? void 0 : _z.boot),
41310
- });
40718
+ 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;
40719
+ const info = deviceInfo;
40720
+ return {
40721
+ firmwareBuildId: getImageBuildId$1((_a = info === null || info === void 0 ? void 0 : info.fw) === null || _a === void 0 ? void 0 : _a.application),
40722
+ firmwareHash: getImageHash$1((_b = info === null || info === void 0 ? void 0 : info.fw) === null || _b === void 0 ? void 0 : _b.application),
40723
+ bootloaderBuildId: getImageBuildId$1((_c = info === null || info === void 0 ? void 0 : info.fw) === null || _c === void 0 ? void 0 : _c.bootloader),
40724
+ bootloaderHash: getImageHash$1((_d = info === null || info === void 0 ? void 0 : info.fw) === null || _d === void 0 ? void 0 : _d.bootloader),
40725
+ boardBuildId: getImageBuildId$1((_f = (_e = info === null || info === void 0 ? void 0 : info.fw) === null || _e === void 0 ? void 0 : _e.application_data) !== null && _f !== void 0 ? _f : (_g = info === null || info === void 0 ? void 0 : info.fw) === null || _g === void 0 ? void 0 : _g.romloader),
40726
+ boardHash: getImageHash$1((_j = (_h = info === null || info === void 0 ? void 0 : info.fw) === null || _h === void 0 ? void 0 : _h.application_data) !== null && _j !== void 0 ? _j : (_k = info === null || info === void 0 ? void 0 : info.fw) === null || _k === void 0 ? void 0 : _k.romloader),
40727
+ bleBuildId: getImageBuildId$1((_l = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _l === void 0 ? void 0 : _l.application),
40728
+ bleHash: getImageHash$1((_m = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _m === void 0 ? void 0 : _m.application),
40729
+ se01BuildId: getImageBuildId$1((_o = info === null || info === void 0 ? void 0 : info.se1) === null || _o === void 0 ? void 0 : _o.application),
40730
+ se01Hash: getImageHash$1((_p = info === null || info === void 0 ? void 0 : info.se1) === null || _p === void 0 ? void 0 : _p.application),
40731
+ se02BuildId: getImageBuildId$1((_q = info === null || info === void 0 ? void 0 : info.se2) === null || _q === void 0 ? void 0 : _q.application),
40732
+ se02Hash: getImageHash$1((_r = info === null || info === void 0 ? void 0 : info.se2) === null || _r === void 0 ? void 0 : _r.application),
40733
+ se03BuildId: getImageBuildId$1((_s = info === null || info === void 0 ? void 0 : info.se3) === null || _s === void 0 ? void 0 : _s.application),
40734
+ se03Hash: getImageHash$1((_t = info === null || info === void 0 ? void 0 : info.se3) === null || _t === void 0 ? void 0 : _t.application),
40735
+ se04BuildId: getImageBuildId$1((_u = info === null || info === void 0 ? void 0 : info.se4) === null || _u === void 0 ? void 0 : _u.application),
40736
+ se04Hash: getImageHash$1((_v = info === null || info === void 0 ? void 0 : info.se4) === null || _v === void 0 ? void 0 : _v.application),
40737
+ se01BootBuildId: getImageBuildId$1((_w = info === null || info === void 0 ? void 0 : info.se1) === null || _w === void 0 ? void 0 : _w.bootloader),
40738
+ se01BootHash: getImageHash$1((_x = info === null || info === void 0 ? void 0 : info.se1) === null || _x === void 0 ? void 0 : _x.bootloader),
40739
+ se02BootBuildId: getImageBuildId$1((_y = info === null || info === void 0 ? void 0 : info.se2) === null || _y === void 0 ? void 0 : _y.bootloader),
40740
+ se02BootHash: getImageHash$1((_z = info === null || info === void 0 ? void 0 : info.se2) === null || _z === void 0 ? void 0 : _z.bootloader),
40741
+ se03BootBuildId: getImageBuildId$1((_0 = info === null || info === void 0 ? void 0 : info.se3) === null || _0 === void 0 ? void 0 : _0.bootloader),
40742
+ se03BootHash: getImageHash$1((_1 = info === null || info === void 0 ? void 0 : info.se3) === null || _1 === void 0 ? void 0 : _1.bootloader),
40743
+ se04BootBuildId: getImageBuildId$1((_2 = info === null || info === void 0 ? void 0 : info.se4) === null || _2 === void 0 ? void 0 : _2.bootloader),
40744
+ se04BootHash: getImageHash$1((_3 = info === null || info === void 0 ? void 0 : info.se4) === null || _3 === void 0 ? void 0 : _3.bootloader),
40745
+ };
41311
40746
  };
41312
40747
  const normalizeRaw = ({ features, protocolV1OneKeyFeatures, protocolV2DeviceInfo, }) => (Object.assign(Object.assign(Object.assign({}, (features ? { features } : {})), (protocolV1OneKeyFeatures ? { protocolV1OneKeyFeatures } : {})), (protocolV2DeviceInfo ? { protocolV2DeviceInfo } : {})));
41313
40748
  function buildProfileFromProtocolV1({ protocol = 'V1', features, protocolV1OneKeyFeatures, sources = ['features'], scope = 'basic', includeRaw = false, }) {
@@ -41324,11 +40759,12 @@ function buildProfileFromProtocolV1({ protocol = 'V1', features, protocolV1OneKe
41324
40759
  : {}));
41325
40760
  }
41326
40761
  function buildProfileFromProtocolV2({ deviceInfo, sources = ['deviceInfo'], scope = 'basic', includeRaw = false, }) {
41327
- var _a, _b, _c, _d, _e, _f;
41328
- const deviceId = ((_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.hw) === null || _a === void 0 ? void 0 : _a.device_id) || '';
40762
+ var _a, _b, _c, _d;
40763
+ const info = deviceInfo;
40764
+ const deviceId = ((_a = info === null || info === void 0 ? void 0 : info.status) === null || _a === void 0 ? void 0 : _a.device_id) || '';
41329
40765
  const serialNo = ((_b = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.hw) === null || _b === void 0 ? void 0 : _b.serial_no) || '';
41330
- const label = (_d = (_c = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : null;
41331
- const bleName = (_f = (_e = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.bt) === null || _e === void 0 ? void 0 : _e.adv_name) !== null && _f !== void 0 ? _f : null;
40766
+ const label = null;
40767
+ const bleName = (_d = (_c = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _c === void 0 ? void 0 : _c.bt_adv_name) !== null && _d !== void 0 ? _d : null;
41332
40768
  const verify = normalizeV2Verify(deviceInfo);
41333
40769
  return Object.assign(Object.assign({ protocol: 'V2', sources, deviceType: hdShared.EDeviceType.Pro2, firmwareType: hdShared.EFirmwareType.Universal, deviceId,
41334
40770
  serialNo,
@@ -41343,7 +40779,7 @@ function buildProfileFromProtocolV2({ deviceInfo, sources = ['deviceInfo'], scop
41343
40779
  }
41344
40780
 
41345
40781
  const getImageVersion = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.version) !== null && _a !== void 0 ? _a : null; };
41346
- const bytesToHex$1 = (value) => {
40782
+ const bytesToHex$2 = (value) => {
41347
40783
  if (!value)
41348
40784
  return undefined;
41349
40785
  if (typeof value === 'string')
@@ -41359,7 +40795,7 @@ const bytesToHex$1 = (value) => {
41359
40795
  return undefined;
41360
40796
  };
41361
40797
  const getImageBuildId = (image) => { var _a; return (_a = image === null || image === void 0 ? void 0 : image.build_id) !== null && _a !== void 0 ? _a : undefined; };
41362
- const getImageHash = (image) => bytesToHex$1(image === null || image === void 0 ? void 0 : image.hash);
40798
+ const getImageHash = (image) => bytesToHex$2(image === null || image === void 0 ? void 0 : image.hash);
41363
40799
  const firstValue = (...values) => values.find(value => value !== undefined && value !== null);
41364
40800
  const firstMeaningfulVersion = (...versions) => { var _a; return (_a = versions.find(version => Boolean(version && version !== '0.0.0'))) !== null && _a !== void 0 ? _a : null; };
41365
40801
  const versionFromParts = (major, minor, patch) => [major, minor, patch].map(part => Number(part) || 0).join('.');
@@ -41518,30 +40954,42 @@ const buildProtocolV1FeaturesPayload = (protocolV1Features, previous) => {
41518
40954
  };
41519
40955
  };
41520
40956
  const buildProtocolV2FeaturesPayload = (deviceInfo, previous) => {
41521
- 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, _70, _71, _72, _73, _74, _75, _76, _77, _78, _79;
40957
+ 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, _70;
41522
40958
  const info = deviceInfo;
41523
- const fwApplication = firstValue((_a = info === null || info === void 0 ? void 0 : info.fw) === null || _a === void 0 ? void 0 : _a.application, (_b = info === null || info === void 0 ? void 0 : info.fw) === null || _b === void 0 ? void 0 : _b.app);
41524
- const fwBootloader = firstValue((_c = info === null || info === void 0 ? void 0 : info.fw) === null || _c === void 0 ? void 0 : _c.bootloader, (_d = info === null || info === void 0 ? void 0 : info.fw) === null || _d === void 0 ? void 0 : _d.boot);
41525
- const fwBoard = firstValue((_e = info === null || info === void 0 ? void 0 : info.fw) === null || _e === void 0 ? void 0 : _e.application_data, (_f = info === null || info === void 0 ? void 0 : info.fw) === null || _f === void 0 ? void 0 : _f.board);
41526
- const bleApplication = firstValue((_g = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _g === void 0 ? void 0 : _g.application, (_h = info === null || info === void 0 ? void 0 : info.bt) === null || _h === void 0 ? void 0 : _h.app);
40959
+ const fwApplication = (_a = info === null || info === void 0 ? void 0 : info.fw) === null || _a === void 0 ? void 0 : _a.application;
40960
+ const fwBootloader = (_b = info === null || info === void 0 ? void 0 : info.fw) === null || _b === void 0 ? void 0 : _b.bootloader;
40961
+ const fwBoard = firstValue((_c = info === null || info === void 0 ? void 0 : info.fw) === null || _c === void 0 ? void 0 : _c.application_data, (_d = info === null || info === void 0 ? void 0 : info.fw) === null || _d === void 0 ? void 0 : _d.romloader);
40962
+ const bleApplication = (_e = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _e === void 0 ? void 0 : _e.application;
40963
+ const status = info === null || info === void 0 ? void 0 : info.status;
41527
40964
  const firmwareVersion = firstMeaningfulVersion(getImageVersion(fwApplication), previous === null || previous === void 0 ? void 0 : previous.firmwareVersion);
41528
40965
  const bootloaderVersion = firstMeaningfulVersion(getImageVersion(fwBootloader), previous === null || previous === void 0 ? void 0 : previous.bootloaderVersion);
41529
40966
  const boardVersion = firstMeaningfulVersion(getImageVersion(fwBoard), previous === null || previous === void 0 ? void 0 : previous.boardVersion);
41530
40967
  const bleVersion = firstMeaningfulVersion(getImageVersion(bleApplication), previous === null || previous === void 0 ? void 0 : previous.bleVersion);
41531
- const deviceId = (_k = firstValue((_j = info === null || info === void 0 ? void 0 : info.hw) === null || _j === void 0 ? void 0 : _j.device_id, previous === null || previous === void 0 ? void 0 : previous.deviceId)) !== null && _k !== void 0 ? _k : null;
41532
- const serialNo = (_m = firstValue((_l = info === null || info === void 0 ? void 0 : info.hw) === null || _l === void 0 ? void 0 : _l.serial_no, previous === null || previous === void 0 ? void 0 : previous.serialNo)) !== null && _m !== void 0 ? _m : '';
41533
- const label = (_p = firstValue((_o = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _o === void 0 ? void 0 : _o.label, previous === null || previous === void 0 ? void 0 : previous.label)) !== null && _p !== void 0 ? _p : null;
41534
- const bleName = firstValue((_q = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _q === void 0 ? void 0 : _q.bt_adv_name, (_r = info === null || info === void 0 ? void 0 : info.bt) === null || _r === void 0 ? void 0 : _r.adv_name, previous === null || previous === void 0 ? void 0 : previous.bleName);
41535
- const initialized = (_t = firstValue((_s = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _s === void 0 ? void 0 : _s.init_states, previous === null || previous === void 0 ? void 0 : previous.initialized)) !== null && _t !== void 0 ? _t : null;
41536
- const passphraseProtection = (_v = firstValue((_u = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _u === void 0 ? void 0 : _u.passphrase_protection, previous === null || previous === void 0 ? void 0 : previous.passphraseProtection)) !== null && _v !== void 0 ? _v : null;
41537
- const language = (_x = firstValue((_w = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _w === void 0 ? void 0 : _w.language, previous === null || previous === void 0 ? void 0 : previous.language)) !== null && _x !== void 0 ? _x : null;
41538
- const backupRequired = (_z = firstValue((_y = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _y === void 0 ? void 0 : _y.backup_required, previous === null || previous === void 0 ? void 0 : previous.backupRequired)) !== null && _z !== void 0 ? _z : null;
41539
- const bleEnabled = firstValue((_0 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.status) === null || _0 === void 0 ? void 0 : _0.bt_enable, previous === null || previous === void 0 ? void 0 : previous.bleEnabled);
40968
+ const deviceId = (_f = status === null || status === void 0 ? void 0 : status.device_id) !== null && _f !== void 0 ? _f : null;
40969
+ const serialNo = (_h = firstValue((_g = info === null || info === void 0 ? void 0 : info.hw) === null || _g === void 0 ? void 0 : _g.serial_no, previous === null || previous === void 0 ? void 0 : previous.serialNo)) !== null && _h !== void 0 ? _h : '';
40970
+ const label = (_j = previous === null || previous === void 0 ? void 0 : previous.label) !== null && _j !== void 0 ? _j : null;
40971
+ const bleName = firstValue((_k = info === null || info === void 0 ? void 0 : info.coprocessor) === null || _k === void 0 ? void 0 : _k.bt_adv_name, previous === null || previous === void 0 ? void 0 : previous.bleName);
40972
+ const initialized = (_l = firstValue(status === null || status === void 0 ? void 0 : status.init_states, previous === null || previous === void 0 ? void 0 : previous.initialized)) !== null && _l !== void 0 ? _l : null;
40973
+ const passphraseProtection = (_m = status === null || status === void 0 ? void 0 : status.passphrase_enabled) !== null && _m !== void 0 ? _m : null;
40974
+ const language = (_o = previous === null || previous === void 0 ? void 0 : previous.language) !== null && _o !== void 0 ? _o : null;
40975
+ const backupRequired = (_p = firstValue(status === null || status === void 0 ? void 0 : status.backup_required, previous === null || previous === void 0 ? void 0 : previous.backupRequired)) !== null && _p !== void 0 ? _p : null;
40976
+ const bleEnabled = previous === null || previous === void 0 ? void 0 : previous.bleEnabled;
40977
+ const unlocked = (_q = firstValue(status === null || status === void 0 ? void 0 : status.unlocked, previous === null || previous === void 0 ? void 0 : previous.unlocked)) !== null && _q !== void 0 ? _q : null;
40978
+ const attachToPinEnabled = (_r = status === null || status === void 0 ? void 0 : status.attach_to_pin_enabled) !== null && _r !== void 0 ? _r : null;
40979
+ const unlockedAttachPin = (_s = status === null || status === void 0 ? void 0 : status.unlocked_by_attach_to_pin) !== null && _s !== void 0 ? _s : undefined;
40980
+ const bootloaderMode = isProtocolV2BootloaderDeviceInfo(info);
40981
+ const mode = bootloaderMode
40982
+ ? 'bootloader'
40983
+ : initialized === false
40984
+ ? 'notInitialized'
40985
+ : initialized === true
40986
+ ? 'normal'
40987
+ : 'unknown';
41540
40988
  return {
41541
40989
  protocol: 'V2',
41542
- protocolVersion: (_2 = (_1 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.protocol_version) !== null && _1 !== void 0 ? _1 : previous === null || previous === void 0 ? void 0 : previous.protocolVersion) !== null && _2 !== void 0 ? _2 : null,
40990
+ protocolVersion: (_u = (_t = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.protocol_version) !== null && _t !== void 0 ? _t : previous === null || previous === void 0 ? void 0 : previous.protocolVersion) !== null && _u !== void 0 ? _u : null,
41543
40991
  deviceType: hdShared.EDeviceType.Pro2,
41544
- firmwareType: (_3 = previous === null || previous === void 0 ? void 0 : previous.firmwareType) !== null && _3 !== void 0 ? _3 : hdShared.EFirmwareType.Universal,
40992
+ firmwareType: (_v = previous === null || previous === void 0 ? void 0 : previous.firmwareType) !== null && _v !== void 0 ? _v : hdShared.EFirmwareType.Universal,
41545
40993
  model: 'pro2',
41546
40994
  vendor: 'onekey.so',
41547
40995
  deviceId,
@@ -41549,11 +40997,11 @@ const buildProtocolV2FeaturesPayload = (deviceInfo, previous) => {
41549
40997
  label,
41550
40998
  bleName: bleName !== null && bleName !== void 0 ? bleName : null,
41551
40999
  capabilities: [],
41552
- mode: initialized === false ? 'notInitialized' : initialized === true ? 'normal' : 'unknown',
41000
+ mode,
41553
41001
  initialized,
41554
- bootloaderMode: false,
41555
- unlocked: (_4 = previous === null || previous === void 0 ? void 0 : previous.unlocked) !== null && _4 !== void 0 ? _4 : null,
41556
- firmwarePresent: (_5 = previous === null || previous === void 0 ? void 0 : previous.firmwarePresent) !== null && _5 !== void 0 ? _5 : null,
41002
+ bootloaderMode,
41003
+ unlocked,
41004
+ firmwarePresent: (_w = previous === null || previous === void 0 ? void 0 : previous.firmwarePresent) !== null && _w !== void 0 ? _w : null,
41557
41005
  passphraseProtection,
41558
41006
  pinProtection: null,
41559
41007
  backupRequired,
@@ -41566,6 +41014,7 @@ const buildProtocolV2FeaturesPayload = (deviceInfo, previous) => {
41566
41014
  sdProtection: null,
41567
41015
  wipeCodeProtection: null,
41568
41016
  passphraseAlwaysOnDevice: null,
41017
+ attachToPinEnabled,
41569
41018
  safetyChecks: null,
41570
41019
  autoLockDelayMs: null,
41571
41020
  displayRotation: null,
@@ -41574,44 +41023,44 @@ const buildProtocolV2FeaturesPayload = (deviceInfo, previous) => {
41574
41023
  bootloaderVersion,
41575
41024
  boardVersion,
41576
41025
  bleVersion,
41577
- se01Version: firstMeaningfulVersion(getImageVersion((_6 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _6 === void 0 ? void 0 : _6.app), previous === null || previous === void 0 ? void 0 : previous.se01Version),
41578
- se02Version: firstMeaningfulVersion(getImageVersion((_7 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _7 === void 0 ? void 0 : _7.app), previous === null || previous === void 0 ? void 0 : previous.se02Version),
41579
- se03Version: firstMeaningfulVersion(getImageVersion((_8 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _8 === void 0 ? void 0 : _8.app), previous === null || previous === void 0 ? void 0 : previous.se03Version),
41580
- se04Version: firstMeaningfulVersion(getImageVersion((_9 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _9 === void 0 ? void 0 : _9.app), previous === null || previous === void 0 ? void 0 : previous.se04Version),
41581
- se01BootVersion: firstMeaningfulVersion(getImageVersion((_10 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _10 === void 0 ? void 0 : _10.boot), previous === null || previous === void 0 ? void 0 : previous.se01BootVersion),
41582
- se02BootVersion: firstMeaningfulVersion(getImageVersion((_11 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _11 === void 0 ? void 0 : _11.boot), previous === null || previous === void 0 ? void 0 : previous.se02BootVersion),
41583
- se03BootVersion: firstMeaningfulVersion(getImageVersion((_12 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _12 === void 0 ? void 0 : _12.boot), previous === null || previous === void 0 ? void 0 : previous.se03BootVersion),
41584
- se04BootVersion: firstMeaningfulVersion(getImageVersion((_13 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _13 === void 0 ? void 0 : _13.boot), previous === null || previous === void 0 ? void 0 : previous.se04BootVersion),
41585
- seVersion: (_14 = previous === null || previous === void 0 ? void 0 : previous.seVersion) !== null && _14 !== void 0 ? _14 : null,
41026
+ se01Version: firstMeaningfulVersion(getImageVersion((_x = info === null || info === void 0 ? void 0 : info.se1) === null || _x === void 0 ? void 0 : _x.application), previous === null || previous === void 0 ? void 0 : previous.se01Version),
41027
+ se02Version: firstMeaningfulVersion(getImageVersion((_y = info === null || info === void 0 ? void 0 : info.se2) === null || _y === void 0 ? void 0 : _y.application), previous === null || previous === void 0 ? void 0 : previous.se02Version),
41028
+ se03Version: firstMeaningfulVersion(getImageVersion((_z = info === null || info === void 0 ? void 0 : info.se3) === null || _z === void 0 ? void 0 : _z.application), previous === null || previous === void 0 ? void 0 : previous.se03Version),
41029
+ se04Version: firstMeaningfulVersion(getImageVersion((_0 = info === null || info === void 0 ? void 0 : info.se4) === null || _0 === void 0 ? void 0 : _0.application), previous === null || previous === void 0 ? void 0 : previous.se04Version),
41030
+ se01BootVersion: firstMeaningfulVersion(getImageVersion((_1 = info === null || info === void 0 ? void 0 : info.se1) === null || _1 === void 0 ? void 0 : _1.bootloader), previous === null || previous === void 0 ? void 0 : previous.se01BootVersion),
41031
+ se02BootVersion: firstMeaningfulVersion(getImageVersion((_2 = info === null || info === void 0 ? void 0 : info.se2) === null || _2 === void 0 ? void 0 : _2.bootloader), previous === null || previous === void 0 ? void 0 : previous.se02BootVersion),
41032
+ se03BootVersion: firstMeaningfulVersion(getImageVersion((_3 = info === null || info === void 0 ? void 0 : info.se3) === null || _3 === void 0 ? void 0 : _3.bootloader), previous === null || previous === void 0 ? void 0 : previous.se03BootVersion),
41033
+ se04BootVersion: firstMeaningfulVersion(getImageVersion((_4 = info === null || info === void 0 ? void 0 : info.se4) === null || _4 === void 0 ? void 0 : _4.bootloader), previous === null || previous === void 0 ? void 0 : previous.se04BootVersion),
41034
+ seVersion: (_5 = previous === null || previous === void 0 ? void 0 : previous.seVersion) !== null && _5 !== void 0 ? _5 : null,
41586
41035
  verify: {
41587
- firmwareBuildId: (_15 = getImageBuildId(fwApplication)) !== null && _15 !== void 0 ? _15 : (_16 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _16 === void 0 ? void 0 : _16.firmwareBuildId,
41588
- firmwareHash: (_17 = getImageHash(fwApplication)) !== null && _17 !== void 0 ? _17 : (_18 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _18 === void 0 ? void 0 : _18.firmwareHash,
41589
- bootloaderBuildId: (_19 = getImageBuildId(fwBootloader)) !== null && _19 !== void 0 ? _19 : (_20 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _20 === void 0 ? void 0 : _20.bootloaderBuildId,
41590
- bootloaderHash: (_21 = getImageHash(fwBootloader)) !== null && _21 !== void 0 ? _21 : (_22 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _22 === void 0 ? void 0 : _22.bootloaderHash,
41591
- boardBuildId: (_23 = getImageBuildId(fwBoard)) !== null && _23 !== void 0 ? _23 : (_24 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _24 === void 0 ? void 0 : _24.boardBuildId,
41592
- boardHash: (_25 = getImageHash(fwBoard)) !== null && _25 !== void 0 ? _25 : (_26 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _26 === void 0 ? void 0 : _26.boardHash,
41593
- bleBuildId: (_27 = getImageBuildId(bleApplication)) !== null && _27 !== void 0 ? _27 : (_28 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _28 === void 0 ? void 0 : _28.bleBuildId,
41594
- bleHash: (_29 = getImageHash(bleApplication)) !== null && _29 !== void 0 ? _29 : (_30 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _30 === void 0 ? void 0 : _30.bleHash,
41595
- se01BuildId: (_32 = getImageBuildId((_31 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _31 === void 0 ? void 0 : _31.app)) !== null && _32 !== void 0 ? _32 : (_33 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _33 === void 0 ? void 0 : _33.se01BuildId,
41596
- se01Hash: (_35 = getImageHash((_34 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _34 === void 0 ? void 0 : _34.app)) !== null && _35 !== void 0 ? _35 : (_36 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _36 === void 0 ? void 0 : _36.se01Hash,
41597
- se02BuildId: (_38 = getImageBuildId((_37 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _37 === void 0 ? void 0 : _37.app)) !== null && _38 !== void 0 ? _38 : (_39 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _39 === void 0 ? void 0 : _39.se02BuildId,
41598
- se02Hash: (_41 = getImageHash((_40 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _40 === void 0 ? void 0 : _40.app)) !== null && _41 !== void 0 ? _41 : (_42 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _42 === void 0 ? void 0 : _42.se02Hash,
41599
- se03BuildId: (_44 = getImageBuildId((_43 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _43 === void 0 ? void 0 : _43.app)) !== null && _44 !== void 0 ? _44 : (_45 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _45 === void 0 ? void 0 : _45.se03BuildId,
41600
- se03Hash: (_47 = getImageHash((_46 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _46 === void 0 ? void 0 : _46.app)) !== null && _47 !== void 0 ? _47 : (_48 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _48 === void 0 ? void 0 : _48.se03Hash,
41601
- se04BuildId: (_50 = getImageBuildId((_49 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _49 === void 0 ? void 0 : _49.app)) !== null && _50 !== void 0 ? _50 : (_51 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _51 === void 0 ? void 0 : _51.se04BuildId,
41602
- se04Hash: (_53 = getImageHash((_52 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _52 === void 0 ? void 0 : _52.app)) !== null && _53 !== void 0 ? _53 : (_54 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _54 === void 0 ? void 0 : _54.se04Hash,
41603
- se01BootBuildId: (_56 = getImageBuildId((_55 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _55 === void 0 ? void 0 : _55.boot)) !== null && _56 !== void 0 ? _56 : (_57 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _57 === void 0 ? void 0 : _57.se01BootBuildId,
41604
- se01BootHash: (_59 = getImageHash((_58 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se1) === null || _58 === void 0 ? void 0 : _58.boot)) !== null && _59 !== void 0 ? _59 : (_60 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _60 === void 0 ? void 0 : _60.se01BootHash,
41605
- se02BootBuildId: (_62 = getImageBuildId((_61 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _61 === void 0 ? void 0 : _61.boot)) !== null && _62 !== void 0 ? _62 : (_63 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _63 === void 0 ? void 0 : _63.se02BootBuildId,
41606
- se02BootHash: (_65 = getImageHash((_64 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se2) === null || _64 === void 0 ? void 0 : _64.boot)) !== null && _65 !== void 0 ? _65 : (_66 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _66 === void 0 ? void 0 : _66.se02BootHash,
41607
- se03BootBuildId: (_68 = getImageBuildId((_67 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _67 === void 0 ? void 0 : _67.boot)) !== null && _68 !== void 0 ? _68 : (_69 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _69 === void 0 ? void 0 : _69.se03BootBuildId,
41608
- se03BootHash: (_71 = getImageHash((_70 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se3) === null || _70 === void 0 ? void 0 : _70.boot)) !== null && _71 !== void 0 ? _71 : (_72 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _72 === void 0 ? void 0 : _72.se03BootHash,
41609
- se04BootBuildId: (_74 = getImageBuildId((_73 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _73 === void 0 ? void 0 : _73.boot)) !== null && _74 !== void 0 ? _74 : (_75 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _75 === void 0 ? void 0 : _75.se04BootBuildId,
41610
- se04BootHash: (_77 = getImageHash((_76 = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.se4) === null || _76 === void 0 ? void 0 : _76.boot)) !== null && _77 !== void 0 ? _77 : (_78 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _78 === void 0 ? void 0 : _78.se04BootHash,
41036
+ firmwareBuildId: (_6 = getImageBuildId(fwApplication)) !== null && _6 !== void 0 ? _6 : (_7 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _7 === void 0 ? void 0 : _7.firmwareBuildId,
41037
+ firmwareHash: (_8 = getImageHash(fwApplication)) !== null && _8 !== void 0 ? _8 : (_9 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _9 === void 0 ? void 0 : _9.firmwareHash,
41038
+ bootloaderBuildId: (_10 = getImageBuildId(fwBootloader)) !== null && _10 !== void 0 ? _10 : (_11 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _11 === void 0 ? void 0 : _11.bootloaderBuildId,
41039
+ bootloaderHash: (_12 = getImageHash(fwBootloader)) !== null && _12 !== void 0 ? _12 : (_13 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _13 === void 0 ? void 0 : _13.bootloaderHash,
41040
+ boardBuildId: (_14 = getImageBuildId(fwBoard)) !== null && _14 !== void 0 ? _14 : (_15 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _15 === void 0 ? void 0 : _15.boardBuildId,
41041
+ boardHash: (_16 = getImageHash(fwBoard)) !== null && _16 !== void 0 ? _16 : (_17 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _17 === void 0 ? void 0 : _17.boardHash,
41042
+ bleBuildId: (_18 = getImageBuildId(bleApplication)) !== null && _18 !== void 0 ? _18 : (_19 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _19 === void 0 ? void 0 : _19.bleBuildId,
41043
+ bleHash: (_20 = getImageHash(bleApplication)) !== null && _20 !== void 0 ? _20 : (_21 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _21 === void 0 ? void 0 : _21.bleHash,
41044
+ se01BuildId: (_23 = getImageBuildId((_22 = info === null || info === void 0 ? void 0 : info.se1) === null || _22 === void 0 ? void 0 : _22.application)) !== null && _23 !== void 0 ? _23 : (_24 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _24 === void 0 ? void 0 : _24.se01BuildId,
41045
+ se01Hash: (_26 = getImageHash((_25 = info === null || info === void 0 ? void 0 : info.se1) === null || _25 === void 0 ? void 0 : _25.application)) !== null && _26 !== void 0 ? _26 : (_27 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _27 === void 0 ? void 0 : _27.se01Hash,
41046
+ se02BuildId: (_29 = getImageBuildId((_28 = info === null || info === void 0 ? void 0 : info.se2) === null || _28 === void 0 ? void 0 : _28.application)) !== null && _29 !== void 0 ? _29 : (_30 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _30 === void 0 ? void 0 : _30.se02BuildId,
41047
+ se02Hash: (_32 = getImageHash((_31 = info === null || info === void 0 ? void 0 : info.se2) === null || _31 === void 0 ? void 0 : _31.application)) !== null && _32 !== void 0 ? _32 : (_33 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _33 === void 0 ? void 0 : _33.se02Hash,
41048
+ se03BuildId: (_35 = getImageBuildId((_34 = info === null || info === void 0 ? void 0 : info.se3) === null || _34 === void 0 ? void 0 : _34.application)) !== null && _35 !== void 0 ? _35 : (_36 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _36 === void 0 ? void 0 : _36.se03BuildId,
41049
+ se03Hash: (_38 = getImageHash((_37 = info === null || info === void 0 ? void 0 : info.se3) === null || _37 === void 0 ? void 0 : _37.application)) !== null && _38 !== void 0 ? _38 : (_39 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _39 === void 0 ? void 0 : _39.se03Hash,
41050
+ se04BuildId: (_41 = getImageBuildId((_40 = info === null || info === void 0 ? void 0 : info.se4) === null || _40 === void 0 ? void 0 : _40.application)) !== null && _41 !== void 0 ? _41 : (_42 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _42 === void 0 ? void 0 : _42.se04BuildId,
41051
+ se04Hash: (_44 = getImageHash((_43 = info === null || info === void 0 ? void 0 : info.se4) === null || _43 === void 0 ? void 0 : _43.application)) !== null && _44 !== void 0 ? _44 : (_45 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _45 === void 0 ? void 0 : _45.se04Hash,
41052
+ se01BootBuildId: (_47 = getImageBuildId((_46 = info === null || info === void 0 ? void 0 : info.se1) === null || _46 === void 0 ? void 0 : _46.bootloader)) !== null && _47 !== void 0 ? _47 : (_48 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _48 === void 0 ? void 0 : _48.se01BootBuildId,
41053
+ se01BootHash: (_50 = getImageHash((_49 = info === null || info === void 0 ? void 0 : info.se1) === null || _49 === void 0 ? void 0 : _49.bootloader)) !== null && _50 !== void 0 ? _50 : (_51 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _51 === void 0 ? void 0 : _51.se01BootHash,
41054
+ se02BootBuildId: (_53 = getImageBuildId((_52 = info === null || info === void 0 ? void 0 : info.se2) === null || _52 === void 0 ? void 0 : _52.bootloader)) !== null && _53 !== void 0 ? _53 : (_54 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _54 === void 0 ? void 0 : _54.se02BootBuildId,
41055
+ se02BootHash: (_56 = getImageHash((_55 = info === null || info === void 0 ? void 0 : info.se2) === null || _55 === void 0 ? void 0 : _55.bootloader)) !== null && _56 !== void 0 ? _56 : (_57 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _57 === void 0 ? void 0 : _57.se02BootHash,
41056
+ se03BootBuildId: (_59 = getImageBuildId((_58 = info === null || info === void 0 ? void 0 : info.se3) === null || _58 === void 0 ? void 0 : _58.bootloader)) !== null && _59 !== void 0 ? _59 : (_60 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _60 === void 0 ? void 0 : _60.se03BootBuildId,
41057
+ se03BootHash: (_62 = getImageHash((_61 = info === null || info === void 0 ? void 0 : info.se3) === null || _61 === void 0 ? void 0 : _61.bootloader)) !== null && _62 !== void 0 ? _62 : (_63 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _63 === void 0 ? void 0 : _63.se03BootHash,
41058
+ se04BootBuildId: (_65 = getImageBuildId((_64 = info === null || info === void 0 ? void 0 : info.se4) === null || _64 === void 0 ? void 0 : _64.bootloader)) !== null && _65 !== void 0 ? _65 : (_66 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _66 === void 0 ? void 0 : _66.se04BootBuildId,
41059
+ se04BootHash: (_68 = getImageHash((_67 = info === null || info === void 0 ? void 0 : info.se4) === null || _67 === void 0 ? void 0 : _67.bootloader)) !== null && _68 !== void 0 ? _68 : (_69 = previous === null || previous === void 0 ? void 0 : previous.verify) === null || _69 === void 0 ? void 0 : _69.se04BootHash,
41611
41060
  },
41612
- sessionId: (_79 = previous === null || previous === void 0 ? void 0 : previous.sessionId) !== null && _79 !== void 0 ? _79 : null,
41061
+ sessionId: (_70 = previous === null || previous === void 0 ? void 0 : previous.sessionId) !== null && _70 !== void 0 ? _70 : null,
41613
41062
  passphraseState: previous === null || previous === void 0 ? void 0 : previous.passphraseState,
41614
- unlockedAttachPin: previous === null || previous === void 0 ? void 0 : previous.unlockedAttachPin,
41063
+ unlockedAttachPin,
41615
41064
  raw: {
41616
41065
  protocolV2DeviceInfo: deviceInfo,
41617
41066
  },
@@ -41716,7 +41165,7 @@ class Device extends events.exports {
41716
41165
  resolve(false);
41717
41166
  }));
41718
41167
  }
41719
- acquire(connectProtocol) {
41168
+ acquire(connectProtocol, options) {
41720
41169
  var _a, _b, _c, _d, _e, _f, _g;
41721
41170
  return __awaiter(this, void 0, void 0, function* () {
41722
41171
  const env = DataManager.getSettings('env');
@@ -41746,6 +41195,9 @@ class Device extends events.exports {
41746
41195
  this.commands = new DeviceCommands(this, (_g = this.mainId) !== null && _g !== void 0 ? _g : '');
41747
41196
  }
41748
41197
  catch (error) {
41198
+ if (options === null || options === void 0 ? void 0 : options.throwOnRunPromiseError) {
41199
+ throw error;
41200
+ }
41749
41201
  if (this.runPromise) {
41750
41202
  this.runPromise.reject(error);
41751
41203
  }
@@ -42029,10 +41481,13 @@ class Device extends events.exports {
42029
41481
  if (this.isProtocolV2()) {
42030
41482
  this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
42031
41483
  if (this.features && !this.featuresNeedsReload && !(options === null || options === void 0 ? void 0 : options.initSession)) {
42032
- yield this._refreshProtocolV2Status();
41484
+ if (this.features.bootloaderMode) {
41485
+ return;
41486
+ }
41487
+ yield this._refreshProtocolV2Status(options);
42033
41488
  return;
42034
41489
  }
42035
- yield this._initializeProtocolV2();
41490
+ yield this._initializeProtocolV2(options);
42036
41491
  return;
42037
41492
  }
42038
41493
  this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
@@ -42070,12 +41525,13 @@ class Device extends events.exports {
42070
41525
  }
42071
41526
  });
42072
41527
  }
42073
- _initializeProtocolV2() {
41528
+ _initializeProtocolV2(options) {
42074
41529
  return __awaiter(this, void 0, void 0, function* () {
42075
41530
  Log$c.debug('Initialize device via Protocol V2 features adapter');
42076
41531
  try {
42077
41532
  const deviceInfo = yield requestProtocolV2DeviceInfo({
42078
41533
  commands: this.commands,
41534
+ timeoutMs: options === null || options === void 0 ? void 0 : options.protocolV2DeviceInfoTimeoutMs,
42079
41535
  });
42080
41536
  const features = this.updateProtocolV2Features(deviceInfo);
42081
41537
  Log$c.debug('Protocol V2 features:', features);
@@ -42087,12 +41543,13 @@ class Device extends events.exports {
42087
41543
  }
42088
41544
  });
42089
41545
  }
42090
- _refreshProtocolV2Status() {
41546
+ _refreshProtocolV2Status(options) {
42091
41547
  return __awaiter(this, void 0, void 0, function* () {
42092
41548
  try {
42093
41549
  const deviceInfo = yield requestProtocolV2DeviceInfo({
42094
41550
  commands: this.commands,
42095
41551
  request: PROTOCOL_V2_STATUS_DEVICE_INFO_REQUEST,
41552
+ timeoutMs: options === null || options === void 0 ? void 0 : options.protocolV2DeviceInfoTimeoutMs,
42096
41553
  });
42097
41554
  const features = this.updateProtocolV2Features(deviceInfo);
42098
41555
  Log$c.debug('Protocol V2 features (status refresh):', features);
@@ -42842,36 +42299,18 @@ class GetFeatures extends BaseMethod {
42842
42299
  }
42843
42300
 
42844
42301
  const ProtocolV2FirmwareTargetType = {
42845
- TARGET_MAIN_APP: 0,
42846
- TARGET_MAIN_BOOT: 1,
42847
- TARGET_BT: 2,
42848
- TARGET_SE1: 3,
42849
- TARGET_SE2: 4,
42850
- TARGET_SE3: 5,
42851
- TARGET_SE4: 6,
42852
- TARGET_RESOURCE: 10,
42302
+ FW_MGMT_TARGET_INVALID: 0,
42303
+ FW_MGMT_TARGET_CRATE: 1,
42304
+ FW_MGMT_TARGET_ROMLOADER: 2,
42305
+ FW_MGMT_TARGET_BOOTLOADER: 3,
42306
+ FW_MGMT_TARGET_APPLICATION_P1: 4,
42307
+ FW_MGMT_TARGET_APPLICATION_P2: 5,
42308
+ FW_MGMT_TARGET_COPROCESSOR: 6,
42309
+ FW_MGMT_TARGET_SE01: 7,
42310
+ FW_MGMT_TARGET_SE02: 8,
42311
+ FW_MGMT_TARGET_SE03: 9,
42312
+ FW_MGMT_TARGET_SE04: 10,
42853
42313
  };
42854
- function protocolV2FileNameToTargetId(fileName) {
42855
- const normalized = fileName.toLowerCase();
42856
- if (normalized.includes('bootloader') || normalized.includes('update_rom')) {
42857
- return ProtocolV2FirmwareTargetType.TARGET_MAIN_BOOT;
42858
- }
42859
- if (normalized.includes('coprocessor') ||
42860
- normalized.includes('ble') ||
42861
- normalized.includes('bluetooth') ||
42862
- normalized.includes('bt')) {
42863
- return ProtocolV2FirmwareTargetType.TARGET_BT;
42864
- }
42865
- if (normalized.includes('se4'))
42866
- return ProtocolV2FirmwareTargetType.TARGET_SE4;
42867
- if (normalized.includes('se3'))
42868
- return ProtocolV2FirmwareTargetType.TARGET_SE3;
42869
- if (normalized.includes('se2'))
42870
- return ProtocolV2FirmwareTargetType.TARGET_SE2;
42871
- if (normalized.includes('se'))
42872
- return ProtocolV2FirmwareTargetType.TARGET_SE1;
42873
- return ProtocolV2FirmwareTargetType.TARGET_MAIN_APP;
42874
- }
42875
42314
 
42876
42315
  const DEVICE_INFO_SCOPES = ['basic', 'versions', 'verify', 'full'];
42877
42316
  function isDeviceInfoScope(scope) {
@@ -43428,7 +42867,7 @@ const formatAnyHex = value => {
43428
42867
  return value;
43429
42868
  };
43430
42869
  const hexes = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
43431
- function bytesToHex(uint8a) {
42870
+ function bytesToHex$1(uint8a) {
43432
42871
  if (!(uint8a instanceof Uint8Array))
43433
42872
  throw new Error('Uint8Array expected');
43434
42873
  let hex = '';
@@ -43626,8 +43065,8 @@ class DeviceRebootToBootloader extends BaseMethod {
43626
43065
  run() {
43627
43066
  return __awaiter(this, void 0, void 0, function* () {
43628
43067
  if (this.device.isProtocolV2()) {
43629
- const res = yield this.device.commands.typedCall('DevReboot', 'Success', {
43630
- reboot_type: hdTransport.DevRebootType.Bootloader,
43068
+ const res = yield this.device.commands.typedCall('DeviceReboot', 'Success', {
43069
+ reboot_type: hdTransport.DeviceRebootType.Bootloader,
43631
43070
  });
43632
43071
  return Promise.resolve(res.message);
43633
43072
  }
@@ -43655,8 +43094,8 @@ class DeviceRebootToBoardloader extends BaseMethod {
43655
43094
  run() {
43656
43095
  return __awaiter(this, void 0, void 0, function* () {
43657
43096
  if (this.device.isProtocolV2()) {
43658
- const res = yield this.device.commands.typedCall('DevReboot', 'Success', {
43659
- reboot_type: hdTransport.DevRebootType.Boardloader,
43097
+ const res = yield this.device.commands.typedCall('DeviceReboot', 'Success', {
43098
+ reboot_type: hdTransport.DeviceRebootType.Romloader,
43660
43099
  });
43661
43100
  return Promise.resolve(res.message);
43662
43101
  }
@@ -44164,7 +43603,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload, r
44164
43603
  const header = new Uint8Array(payload.slice(0, HEADER_SIZE));
44165
43604
  try {
44166
43605
  const headerRes = yield typedCall('UpgradeFileHeader', 'Success', {
44167
- data: bytesToHex(header),
43606
+ data: bytesToHex$1(header),
44168
43607
  });
44169
43608
  const isUnknownMessage = (_b = (_a = headerRes.message) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.includes('Failure_UnknownMessage');
44170
43609
  if (headerRes.type !== 'Success' && !isUnknownMessage) {
@@ -44413,8 +43852,8 @@ const processResourceRequest = (typedCall, res, data) => __awaiter(void 0, void
44413
43852
  const payload = new Uint8Array(data.slice(offset, Math.min(offset + data_length, data.byteLength)));
44414
43853
  const digest = blake2s.blake2s(payload);
44415
43854
  const resourceAckParams = {
44416
- data_chunk: bytesToHex(payload),
44417
- hash: bytesToHex(digest),
43855
+ data_chunk: bytesToHex$1(payload),
43856
+ hash: bytesToHex$1(digest),
44418
43857
  };
44419
43858
  const response = yield typedCall('ResourceAck', ['ResourceRequest', 'Success'], Object.assign({}, resourceAckParams));
44420
43859
  return processResourceRequest(typedCall, response, data);
@@ -44425,8 +43864,8 @@ const updateResource = (typedCall, fileName, data, onConfirmAfter) => __awaiter(
44425
43864
  const res = yield typedCall('ResourceUpdate', ['ResourceRequest', 'Success'], {
44426
43865
  file_name: fileName,
44427
43866
  data_length: data.byteLength,
44428
- initial_data_chunk: bytesToHex(chunk),
44429
- hash: bytesToHex(digest),
43867
+ initial_data_chunk: bytesToHex$1(chunk),
43868
+ hash: bytesToHex$1(digest),
44430
43869
  });
44431
43870
  onConfirmAfter === null || onConfirmAfter === void 0 ? void 0 : onConfirmAfter();
44432
43871
  return processResourceRequest(typedCall, res, data);
@@ -44517,6 +43956,35 @@ class DeviceFullyUploadResource extends BaseMethod {
44517
43956
  }
44518
43957
  }
44519
43958
 
43959
+ const DEFAULT_FIRMWARE_PROGRESS_INTERVAL_MS = 250;
43960
+ const createFirmwareProgressThrottle = (intervalMs = DEFAULT_FIRMWARE_PROGRESS_INTERVAL_MS) => {
43961
+ const stateByType = new Map();
43962
+ return (progress, progressType) => {
43963
+ if (progressType !== 'transferData') {
43964
+ return true;
43965
+ }
43966
+ const normalizedProgress = Math.max(0, Math.min(100, Math.floor(progress)));
43967
+ if (normalizedProgress === 0 || normalizedProgress === 100) {
43968
+ stateByType.set(progressType, {
43969
+ lastEmittedAt: Date.now(),
43970
+ lastProgress: normalizedProgress,
43971
+ });
43972
+ return true;
43973
+ }
43974
+ const now = Date.now();
43975
+ const state = stateByType.get(progressType);
43976
+ if (state &&
43977
+ (state.lastProgress === normalizedProgress || now - state.lastEmittedAt < intervalMs)) {
43978
+ return false;
43979
+ }
43980
+ stateByType.set(progressType, {
43981
+ lastEmittedAt: now,
43982
+ lastProgress: normalizedProgress,
43983
+ });
43984
+ return true;
43985
+ };
43986
+ };
43987
+
44520
43988
  const Log$8 = getLogger(exports.LoggerNames.Method);
44521
43989
  const SESSION_ERROR$1 = 'session not found';
44522
43990
  const FIRMWARE_UPDATE_CONFIRM = 'Firmware install confirmed';
@@ -44530,6 +43998,7 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
44530
43998
  constructor() {
44531
43999
  super(...arguments);
44532
44000
  this.checkPromise = null;
44001
+ this.shouldPostFirmwareProgress = createFirmwareProgressThrottle();
44533
44002
  this.postTipMessage = (message) => {
44534
44003
  this.postMessage(createUiMessage(UI_REQUEST.FIRMWARE_TIP, {
44535
44004
  device: this.device.toMessageObject(),
@@ -44544,6 +44013,9 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
44544
44013
  }));
44545
44014
  };
44546
44015
  this.postProgressMessage = (progress, progressType) => {
44016
+ if (!this.shouldPostFirmwareProgress(progress, progressType)) {
44017
+ return;
44018
+ }
44547
44019
  this.postMessage(createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
44548
44020
  device: this.device.toMessageObject(),
44549
44021
  progress,
@@ -44599,6 +44071,8 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
44599
44071
  Log$8.log('FirmwareUpdateBaseMethod [checkDeviceToBootloader] isBleReconnect: ', isBleReconnect);
44600
44072
  let isFirstCheck = true;
44601
44073
  let checkCount = 0;
44074
+ let hasPromptedWebDevice = false;
44075
+ let isPromptingWebDevice = false;
44602
44076
  let timeoutTimer;
44603
44077
  const isTouchOrProDevice = ((_a = this === null || this === void 0 ? void 0 : this.device) === null || _a === void 0 ? void 0 : _a.getCurrentDeviceType()) === hdShared.EDeviceType.Touch ||
44604
44078
  ((_b = this === null || this === void 0 ? void 0 : this.device) === null || _b === void 0 ? void 0 : _b.getCurrentDeviceType()) === hdShared.EDeviceType.Pro;
@@ -44613,20 +44087,27 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
44613
44087
  }
44614
44088
  if (checkCount > 4 &&
44615
44089
  DataManager.isBrowserWebUsb(DataManager.getSettings('env')) &&
44616
- !this.payload.skipWebDevicePrompt) {
44617
- clearInterval(intervalTimer);
44618
- clearTimeout(timeoutTimer);
44090
+ !this.payload.skipWebDevicePrompt &&
44091
+ !hasPromptedWebDevice &&
44092
+ !isPromptingWebDevice) {
44093
+ isPromptingWebDevice = true;
44619
44094
  try {
44620
44095
  this.postTipMessage(exports.FirmwareUpdateTipMessage.SelectDeviceInBootloaderForWebDevice);
44621
44096
  const confirmed = yield this._promptDeviceInBootloaderForWebDevice();
44097
+ hasPromptedWebDevice = true;
44622
44098
  if (confirmed) {
44623
44099
  yield this._checkDeviceInBootloaderMode(connectId, intervalTimer, timeoutTimer);
44624
44100
  }
44625
44101
  }
44626
44102
  catch (e) {
44103
+ clearInterval(intervalTimer);
44104
+ clearTimeout(timeoutTimer);
44627
44105
  Log$8.log('FirmwareUpdateBaseMethod [checkDeviceToBootloader] _promptDeviceInBootloaderForWebDevice failed: ', e);
44628
44106
  (_c = this.checkPromise) === null || _c === void 0 ? void 0 : _c.reject(e);
44629
44107
  }
44108
+ finally {
44109
+ isPromptingWebDevice = false;
44110
+ }
44630
44111
  return;
44631
44112
  }
44632
44113
  if (isBleReconnect) {
@@ -45889,20 +45370,20 @@ function validateRequiredData(value, name) {
45889
45370
  }
45890
45371
  }
45891
45372
 
45892
- const DEV_REBOOT_TYPES = {
45893
- Normal: hdTransport.DevRebootType.Normal,
45894
- normal: hdTransport.DevRebootType.Normal,
45895
- Romloader: hdTransport.DevRebootType.Boardloader,
45896
- romloader: hdTransport.DevRebootType.Boardloader,
45897
- Boardloader: hdTransport.DevRebootType.Boardloader,
45898
- boardloader: hdTransport.DevRebootType.Boardloader,
45899
- Bootloader: hdTransport.DevRebootType.Bootloader,
45900
- bootloader: hdTransport.DevRebootType.Bootloader,
45373
+ const DEVICE_REBOOT_TYPES = {
45374
+ Normal: hdTransport.DeviceRebootType.Normal,
45375
+ normal: hdTransport.DeviceRebootType.Normal,
45376
+ Romloader: hdTransport.DeviceRebootType.Romloader,
45377
+ romloader: hdTransport.DeviceRebootType.Romloader,
45378
+ Boardloader: hdTransport.DeviceRebootType.Romloader,
45379
+ boardloader: hdTransport.DeviceRebootType.Romloader,
45380
+ Bootloader: hdTransport.DeviceRebootType.Bootloader,
45381
+ bootloader: hdTransport.DeviceRebootType.Bootloader,
45901
45382
  };
45902
45383
  const PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS = {
45903
- intermediateTypes: ['DevFirmwareInstallProgress'],
45384
+ intermediateTypes: ['DeviceFirmwareUpdateStatus'],
45904
45385
  };
45905
- const PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES = ['Success', 'DevFirmwareUpdateStatus'];
45386
+ const PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES = ['Success', 'DeviceFirmwareUpdateStatus'];
45906
45387
  const getProtocolV2UnknownErrorText = (error) => {
45907
45388
  if (!error) {
45908
45389
  return '';
@@ -45959,17 +45440,21 @@ function normalizeRebootType(value) {
45959
45440
  const numeric = Number(value);
45960
45441
  if (Number.isFinite(numeric))
45961
45442
  return numeric;
45962
- if (value in DEV_REBOOT_TYPES)
45963
- return DEV_REBOOT_TYPES[value];
45443
+ if (value in DEVICE_REBOOT_TYPES)
45444
+ return DEVICE_REBOOT_TYPES[value];
45964
45445
  }
45965
- return hdTransport.DevRebootType.Normal;
45446
+ return hdTransport.DeviceRebootType.Normal;
45966
45447
  }
45967
- const VALID_FIRMWARE_TARGET_IDS = new Set([0, 1, 2, 3, 4, 5, 6, 10]);
45448
+ const VALID_FIRMWARE_TARGET_IDS = new Set(Object.values(ProtocolV2FirmwareTargetType).filter(value => typeof value === 'number'));
45449
+ const FIRMWARE_TARGET_ID_BY_NAME = new Map(Object.entries(ProtocolV2FirmwareTargetType).flatMap(([key, value]) => VALID_FIRMWARE_TARGET_IDS.has(value)
45450
+ ? [[key, value]]
45451
+ : []));
45968
45452
  function normalizeTargetId(value, name) {
45969
45453
  if (value === undefined || value === null) {
45970
45454
  throw invalidParameter(`Missing required parameter: ${name}`);
45971
45455
  }
45972
- const numeric = typeof value === 'number' ? value : Number(value);
45456
+ const named = typeof value === 'string' ? FIRMWARE_TARGET_ID_BY_NAME.get(value) : undefined;
45457
+ const numeric = named !== null && named !== void 0 ? named : (typeof value === 'number' ? value : Number(value));
45973
45458
  if (Number.isSafeInteger(numeric) && VALID_FIRMWARE_TARGET_IDS.has(numeric)) {
45974
45459
  return numeric;
45975
45460
  }
@@ -46007,13 +45492,101 @@ const Log$4 = getLogger(exports.LoggerNames.Method);
46007
45492
  const SESSION_ERROR = 'session not found';
46008
45493
  const PROTOCOL_V2_BOOTLOADER_RECONNECT_TIMEOUT = 60 * 1000;
46009
45494
  const PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT = 5 * 1000;
45495
+ const PROTOCOL_V2_START_UPDATE_TIMEOUT = 60 * 1000;
46010
45496
  const PROTOCOL_V2_INSTALL_TIMEOUT = 5 * 60 * 1000;
46011
- const PROTOCOL_V2_TARGET_STATUS_FINISHED = 0;
45497
+ const PROTOCOL_V2_TARGET_STATUS_PENDING = 0;
46012
45498
  const PROTOCOL_V2_TARGET_STATUS_IN_PROGRESS = 1;
46013
- const PROTOCOL_V2_TARGET_STATUS_FAILED = 2;
45499
+ const PROTOCOL_V2_TARGET_STATUS_FINISHED = 2;
45500
+ const PROTOCOL_V2_TARGET_STATUS_FAILED_MIN = 3;
46014
45501
  const PROTOCOL_V2_CONNECT_PROTOCOL = 'V2';
46015
45502
  const PROTOCOL_V2_FIRMWARE_STAGING_VOLUME = 'vol1:';
46016
45503
  const PROTOCOL_V2_MIN_FILE_CHUNK_SIZE = 64;
45504
+ const PROTOCOL_V2_CONNECT_RETRY_COUNT = 10;
45505
+ const PROTOCOL_V2_CONNECT_POLL_INTERVAL = 500;
45506
+ const PROTOCOL_V2_CONNECT_SINGLE_TIMEOUT = 75 * 1000;
45507
+ const PROTOCOL_V2_DEVICE_INFO_READY_TIMEOUT = 60 * 1000;
45508
+ const PROTOCOL_V2_OKPP_HEADER_SIZE = 0x52a0;
45509
+ const PROTOCOL_V2_OKPP_PAYLOAD_HASH_OFFSET = 0x200;
45510
+ const PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET = 0x240;
45511
+ const PROTOCOL_V2_OKPP_HASH_SIZE = 64;
45512
+ const getProtocolV2DeviceTransferProgress = (bytesBeforeChunk, bytesAfterChunk, totalBytes) => {
45513
+ if (!Number.isFinite(totalBytes) || totalBytes <= 0) {
45514
+ return 100;
45515
+ }
45516
+ if (bytesBeforeChunk <= 0 && bytesAfterChunk < totalBytes) {
45517
+ return 0;
45518
+ }
45519
+ if (bytesAfterChunk >= totalBytes) {
45520
+ return 100;
45521
+ }
45522
+ return Math.min(Math.max(Math.ceil((bytesAfterChunk / totalBytes) * 100), 1), 99);
45523
+ };
45524
+ const formatProtocolV2TransferSpeed = (bytes, elapsedMs) => {
45525
+ const safeElapsedMs = Math.max(elapsedMs, 1);
45526
+ return (bytes / 1024 / (safeElapsedMs / 1000)).toFixed(2);
45527
+ };
45528
+ const PROTOCOL_V2_REMOTE_COMPONENT_TARGETS = {
45529
+ BOOTLOADER: {
45530
+ fileName: 'bootloader.bin',
45531
+ targetId: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_BOOTLOADER,
45532
+ kind: 'bootloader',
45533
+ },
45534
+ APPLICATION_P1: {
45535
+ fileName: 'application_p1.bin',
45536
+ targetId: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P1,
45537
+ kind: 'firmware',
45538
+ },
45539
+ APPLICATION_P2: {
45540
+ fileName: 'application_p2.bin',
45541
+ targetId: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P2,
45542
+ kind: 'firmware',
45543
+ },
45544
+ COPROCESSOR: {
45545
+ fileName: 'coprocessor.bin',
45546
+ targetId: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_COPROCESSOR,
45547
+ kind: 'firmware',
45548
+ },
45549
+ SE01: {
45550
+ fileName: 'se01.bin',
45551
+ targetId: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE01,
45552
+ kind: 'firmware',
45553
+ },
45554
+ SE02: {
45555
+ fileName: 'se02.bin',
45556
+ targetId: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE02,
45557
+ kind: 'firmware',
45558
+ },
45559
+ SE03: {
45560
+ fileName: 'se03.bin',
45561
+ targetId: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE03,
45562
+ kind: 'firmware',
45563
+ },
45564
+ SE04: {
45565
+ fileName: 'se04.bin',
45566
+ targetId: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE04,
45567
+ kind: 'firmware',
45568
+ },
45569
+ CRATE: {
45570
+ fileName: 'resource.bin',
45571
+ targetId: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_CRATE,
45572
+ kind: 'resource',
45573
+ },
45574
+ };
45575
+ const PROTOCOL_V2_ROMLOADER_UNSUPPORTED_MESSAGE = 'FW_MGMT_TARGET_ROMLOADER is not accepted by the current Pro2 bootloader update request. Flash romloader with the loader-specific flow instead of firmwareUpdateV4.';
45576
+ const PROTOCOL_V2_TARGET_ID_BY_DECODED_NAME = new Map(Object.entries(ProtocolV2FirmwareTargetType).map(([key, value]) => [key, value]));
45577
+ const PROTOCOL_V2_TARGET_STATUS_BY_DECODED_NAME = new Map([
45578
+ ['FW_MGMT_UPDATER_TASK_STATUS_PENDING', PROTOCOL_V2_TARGET_STATUS_PENDING],
45579
+ ['FW_MGMT_UPDATER_TASK_STATUS_IN_PROGRESS', PROTOCOL_V2_TARGET_STATUS_IN_PROGRESS],
45580
+ ['FW_MGMT_UPDATER_TASK_STATUS_FINISHED', PROTOCOL_V2_TARGET_STATUS_FINISHED],
45581
+ ['FW_MGMT_UPDATER_TASK_STATUS_FAILED_FILE_NOT_FOUND', 3],
45582
+ ['FW_MGMT_UPDATER_TASK_STATUS_FAILED_FILE_READ', 4],
45583
+ ['FW_MGMT_UPDATER_TASK_STATUS_FAILED_FILE_WRITE', 5],
45584
+ ['FW_MGMT_UPDATER_TASK_STATUS_FAILED_VERIFY', 6],
45585
+ ['FW_MGMT_UPDATER_TASK_STATUS_FAILED_INSTALL', 7],
45586
+ ['FW_MGMT_UPDATER_TASK_STATUS_FAILED_ABORT', 8],
45587
+ ['FW_MGMT_UPDATER_TASK_STATUS_FAILED_BUSY', 9],
45588
+ ['FW_MGMT_UPDATER_TASK_STATUS_FAILED_ENTRY_OUT_OF_BOUNDS', 10],
45589
+ ]);
46017
45590
  const isProtocolV2ReconnectProbeError = (error) => {
46018
45591
  const message = getProtocolV2UnknownErrorText(error).toLowerCase();
46019
45592
  return ((message.includes('device protocol mismatch') && message.includes('expected v2')) ||
@@ -46023,10 +45596,127 @@ const isProtocolV2PollingTransientError = (error) => {
46023
45596
  const message = getProtocolV2UnknownErrorText(error).toLowerCase();
46024
45597
  return (isProtocolV2DeviceDisconnectedError(error) ||
46025
45598
  isProtocolV2ReconnectProbeError(error) ||
46026
- (message.includes('response timeout') && message.includes('devicegetfirmwareupdatestatus')) ||
45599
+ message.includes('libusb_transfer_timed_out') ||
45600
+ (message.includes('response timeout') && message.includes('devicefirmwareupdatestatusget')) ||
46027
45601
  message.includes('device not found') ||
46028
45602
  message.includes('transportnotfound'));
46029
45603
  };
45604
+ const isProtocolV2StartUpdateTransientError = (error) => {
45605
+ const message = getProtocolV2UnknownErrorText(error).toLowerCase();
45606
+ return (isProtocolV2DeviceDisconnectedError(error) ||
45607
+ isProtocolV2ReconnectProbeError(error) ||
45608
+ message.includes('libusb_transfer_timed_out') ||
45609
+ (message.includes('response timeout') && message.includes('devicefirmwareupdaterequest')));
45610
+ };
45611
+ const isProtocolV2TargetStatusFinished = (status) => normalizeProtocolV2TargetStatus(status) === PROTOCOL_V2_TARGET_STATUS_FINISHED;
45612
+ const isProtocolV2TargetStatusInProgress = (status) => normalizeProtocolV2TargetStatus(status) === PROTOCOL_V2_TARGET_STATUS_PENDING ||
45613
+ normalizeProtocolV2TargetStatus(status) === PROTOCOL_V2_TARGET_STATUS_IN_PROGRESS;
45614
+ const isProtocolV2TargetStatusFailed = (status) => {
45615
+ const normalizedStatus = normalizeProtocolV2TargetStatus(status);
45616
+ return (typeof normalizedStatus === 'number' && normalizedStatus >= PROTOCOL_V2_TARGET_STATUS_FAILED_MIN);
45617
+ };
45618
+ const normalizeProtocolV2TargetId = (targetId) => {
45619
+ if (typeof targetId === 'number') {
45620
+ return targetId;
45621
+ }
45622
+ return PROTOCOL_V2_TARGET_ID_BY_DECODED_NAME.get(targetId);
45623
+ };
45624
+ const normalizeProtocolV2TargetStatus = (status) => {
45625
+ if (typeof status === 'number') {
45626
+ return status;
45627
+ }
45628
+ if (typeof status === 'string') {
45629
+ return PROTOCOL_V2_TARGET_STATUS_BY_DECODED_NAME.get(status);
45630
+ }
45631
+ return undefined;
45632
+ };
45633
+ const normalizeProtocolV2Hex = (value) => value === null || value === void 0 ? void 0 : value.replace(/^0x/i, '').toLowerCase();
45634
+ const versionArrayToNumber = (version) => {
45635
+ if (!version)
45636
+ return undefined;
45637
+ return version[0] * 0x10000 + version[1] * 0x100 + version[2];
45638
+ };
45639
+ const versionStringToArray = (version) => {
45640
+ if (!version)
45641
+ return undefined;
45642
+ const parts = version.split('.').map(part => Number(part));
45643
+ if (parts.length !== 3 || parts.some(part => !Number.isFinite(part)))
45644
+ return undefined;
45645
+ return parts;
45646
+ };
45647
+ const compareProtocolV2Versions = (current, target) => {
45648
+ const currentNumber = versionArrayToNumber(current);
45649
+ const targetNumber = versionArrayToNumber(target);
45650
+ if (currentNumber === undefined || targetNumber === undefined)
45651
+ return undefined;
45652
+ return currentNumber - targetNumber;
45653
+ };
45654
+ const bytesToHex = (bytes) => Array.from(bytes)
45655
+ .map(byte => byte.toString(16).padStart(2, '0'))
45656
+ .join('');
45657
+ const hexToProtocolV2Bytes = (hex) => {
45658
+ const normalized = hex.replace(/^0x/i, '');
45659
+ if (!normalized || normalized.length % 2 !== 0 || /[^0-9a-f]/i.test(normalized)) {
45660
+ return new Uint8Array(0);
45661
+ }
45662
+ const bytes = new Uint8Array(normalized.length / 2);
45663
+ for (let i = 0; i < bytes.length; i++) {
45664
+ bytes[i] = Number.parseInt(normalized.slice(i * 2, i * 2 + 2), 16);
45665
+ }
45666
+ return bytes;
45667
+ };
45668
+ const toProtocolV2Bytes = (value) => {
45669
+ if (value instanceof Uint8Array)
45670
+ return value;
45671
+ if (value instanceof ArrayBuffer)
45672
+ return new Uint8Array(value);
45673
+ if (ArrayBuffer.isView(value)) {
45674
+ return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
45675
+ }
45676
+ if (typeof value === 'string')
45677
+ return hexToProtocolV2Bytes(value);
45678
+ return new Uint8Array(0);
45679
+ };
45680
+ const toProtocolV2FiniteNumber = (value) => {
45681
+ if (typeof value === 'number' && Number.isFinite(value))
45682
+ return value;
45683
+ if (typeof value === 'string') {
45684
+ const numeric = Number(value);
45685
+ return Number.isFinite(numeric) ? numeric : undefined;
45686
+ }
45687
+ if (value && typeof value === 'object') {
45688
+ const longLike = value;
45689
+ if (typeof longLike.toNumber === 'function') {
45690
+ const numeric = longLike.toNumber();
45691
+ return Number.isFinite(numeric) ? numeric : undefined;
45692
+ }
45693
+ }
45694
+ return undefined;
45695
+ };
45696
+ const readProtocolV2Ascii = (bytes, offset, length) => Array.from(bytes.slice(offset, offset + length))
45697
+ .map(byte => String.fromCharCode(byte))
45698
+ .join('');
45699
+ const parseProtocolV2OkppHeader = (bytes) => {
45700
+ if (bytes.byteLength < PROTOCOL_V2_OKPP_HEADER_SIZE)
45701
+ return null;
45702
+ if (readProtocolV2Ascii(bytes, 0, 4) !== 'OKPP')
45703
+ return null;
45704
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
45705
+ const headerLen = view.getUint32(0x0c, true);
45706
+ if (headerLen !== PROTOCOL_V2_OKPP_HEADER_SIZE)
45707
+ return null;
45708
+ const packedVersion = view.getUint32(0x10, true);
45709
+ return {
45710
+ type: readProtocolV2Ascii(bytes, 0x08, 4),
45711
+ version: [
45712
+ Math.floor(packedVersion / 0x10000) % 0x100,
45713
+ Math.floor(packedVersion / 0x100) % 0x100,
45714
+ packedVersion % 0x100,
45715
+ ],
45716
+ payloadHash: bytesToHex(bytes.slice(PROTOCOL_V2_OKPP_PAYLOAD_HASH_OFFSET, PROTOCOL_V2_OKPP_PAYLOAD_HASH_OFFSET + PROTOCOL_V2_OKPP_HASH_SIZE)),
45717
+ headerHash: bytesToHex(bytes.slice(PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET, PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET + PROTOCOL_V2_OKPP_HASH_SIZE)),
45718
+ };
45719
+ };
46030
45720
  class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46031
45721
  init() {
46032
45722
  this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.NOT_INITIALIZE];
@@ -46034,15 +45724,22 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46034
45724
  this.useDevicePassphraseState = false;
46035
45725
  this.skipForceUpdateCheck = true;
46036
45726
  const { payload } = this;
45727
+ if (typeof payload.retryCount !== 'number') {
45728
+ payload.retryCount = PROTOCOL_V2_CONNECT_RETRY_COUNT;
45729
+ }
45730
+ if (typeof payload.pollIntervalTime !== 'number') {
45731
+ payload.pollIntervalTime = PROTOCOL_V2_CONNECT_POLL_INTERVAL;
45732
+ }
45733
+ if (typeof payload.timeout !== 'number') {
45734
+ payload.timeout = PROTOCOL_V2_CONNECT_SINGLE_TIMEOUT;
45735
+ }
45736
+ if (typeof payload.protocolV2DeviceInfoTimeoutMs !== 'number') {
45737
+ payload.protocolV2DeviceInfoTimeoutMs = PROTOCOL_V2_DEVICE_INFO_READY_TIMEOUT;
45738
+ }
46037
45739
  validateParams(payload, [
46038
- { name: 'bleVersion', type: 'array' },
46039
- { name: 'bleBinary', type: 'buffer' },
46040
45740
  { name: 'chunkSize', type: 'number' },
46041
- { name: 'firmwareVersion', type: 'array' },
46042
- { name: 'firmwareBinary', type: 'buffer' },
46043
- { name: 'resourceBinary', type: 'buffer' },
45741
+ { name: 'resourceBinaries', type: 'array', allowEmpty: true },
46044
45742
  { name: 'forcedUpdateRes', type: 'boolean' },
46045
- { name: 'bootloaderVersion', type: 'array' },
46046
45743
  { name: 'bootloaderBinary', type: 'buffer' },
46047
45744
  { name: 'romloaderBinary', type: 'buffer' },
46048
45745
  { name: 'applicationP1Binary', type: 'buffer' },
@@ -46056,12 +45753,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46056
45753
  { name: 'platform', type: 'string' },
46057
45754
  ]);
46058
45755
  this.params = {
46059
- bleBinary: payload.bleBinary,
46060
45756
  chunkSize: payload.chunkSize,
46061
- firmwareBinary: payload.firmwareBinary,
46062
45757
  forcedUpdateRes: payload.forcedUpdateRes,
46063
- bleVersion: payload.bleVersion,
46064
- bootloaderVersion: payload.bootloaderVersion,
46065
45758
  bootloaderBinary: payload.bootloaderBinary,
46066
45759
  romloaderBinary: payload.romloaderBinary,
46067
45760
  applicationP1Binary: payload.applicationP1Binary,
@@ -46071,8 +45764,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46071
45764
  se02Binary: payload.se02Binary,
46072
45765
  se03Binary: payload.se03Binary,
46073
45766
  se04Binary: payload.se04Binary,
46074
- firmwareVersion: payload.firmwareVersion,
46075
- resourceBinary: payload.resourceBinary,
45767
+ resourceBinaries: payload.resourceBinaries,
46076
45768
  firmwareType: payload.firmwareType,
46077
45769
  platform: payload.platform,
46078
45770
  };
@@ -46104,28 +45796,34 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46104
45796
  const deviceFeatures = yield this.getProtocolV2DeviceFeatures();
46105
45797
  const deviceFirmwareType = getFirmwareType(deviceFeatures);
46106
45798
  const firmwareType = (_a = this.params.firmwareType) !== null && _a !== void 0 ? _a : deviceFirmwareType;
46107
- let resourceBinary = null;
45799
+ let resourceBinaryMap = [];
46108
45800
  let fwBinaryMap = [];
46109
45801
  let bootloaderBinary = null;
45802
+ let installItems;
46110
45803
  try {
46111
45804
  this.postTipMessage(exports.FirmwareUpdateTipMessage.StartDownloadFirmware);
46112
- resourceBinary = yield this.prepareResourceBinary(firmwareType, deviceFeatures);
46113
- fwBinaryMap = yield this.prepareFirmwareAndBleBinary(firmwareType, deviceFeatures);
46114
- bootloaderBinary = yield this.prepareBootloaderBinary(firmwareType, deviceFeatures);
46115
- fwBinaryMap.push(...this.collectExplicitTargetBinaries());
45805
+ resourceBinaryMap = yield this.prepareResourceBinaries(firmwareType, deviceFeatures);
45806
+ fwBinaryMap = this.collectExplicitTargetBinaries();
45807
+ bootloaderBinary = this.prepareBootloaderBinary();
45808
+ if (!this.hasExplicitProtocolV2Payload(fwBinaryMap)) {
45809
+ const remoteBinaries = yield this.prepareRemoteProtocolV2Binaries(firmwareType, deviceFeatures);
45810
+ resourceBinaryMap = remoteBinaries.resourceBinaryMap;
45811
+ bootloaderBinary = remoteBinaries.bootloaderBinary;
45812
+ fwBinaryMap = remoteBinaries.fwBinaryMap;
45813
+ installItems = remoteBinaries.installItems;
45814
+ }
46116
45815
  this.postTipMessage(exports.FirmwareUpdateTipMessage.FinishDownloadFirmware);
46117
45816
  }
46118
45817
  catch (err) {
46119
45818
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, (_b = err.message) !== null && _b !== void 0 ? _b : err);
46120
45819
  }
46121
- if (!resourceBinary && !bootloaderBinary && fwBinaryMap.length === 0) {
45820
+ if (resourceBinaryMap.length === 0 && !bootloaderBinary && fwBinaryMap.length === 0) {
46122
45821
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, 'No firmware to update');
46123
45822
  }
46124
- yield this.executeProtocolV2Update({
46125
- resourceBinary,
45823
+ yield this.enterProtocolV2BootloaderMode();
45824
+ yield this.executeProtocolV2Update(Object.assign({ resourceBinaryMap,
46126
45825
  fwBinaryMap,
46127
- bootloaderBinary,
46128
- });
45826
+ bootloaderBinary }, (installItems ? { installItems } : undefined)));
46129
45827
  yield this.exitProtocolV2BootloaderToNormal();
46130
45828
  const versions = yield this.waitForProtocolV2FinalFeatures();
46131
45829
  this.postTipMessage(exports.FirmwareUpdateTipMessage.FirmwareUpdateCompleted);
@@ -46135,21 +45833,31 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46135
45833
  }
46136
45834
  getProtocolV2DeviceFeatures() {
46137
45835
  return __awaiter(this, void 0, void 0, function* () {
45836
+ if (this.device.features) {
45837
+ return this.device.features;
45838
+ }
46138
45839
  if (typeof this.device.getFeatures === 'function') {
46139
45840
  const features = yield this.device.getFeatures();
46140
45841
  if (features)
46141
45842
  return features;
46142
45843
  }
46143
- if (this.device.features) {
46144
- return this.device.features;
46145
- }
46146
45844
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Device features not available');
46147
45845
  });
46148
45846
  }
46149
- prepareResourceBinary(firmwareType, features) {
45847
+ prepareResourceBinaries(firmwareType, features) {
45848
+ var _a;
46150
45849
  return __awaiter(this, void 0, void 0, function* () {
46151
- if (this.params.resourceBinary) {
46152
- return this.params.resourceBinary;
45850
+ if ((_a = this.params.resourceBinaries) === null || _a === void 0 ? void 0 : _a.length) {
45851
+ this.params.resourceBinaries.forEach((binary, index) => {
45852
+ if (!(binary instanceof ArrayBuffer)) {
45853
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Parameter [resourceBinaries.${index}] is of type invalid and should be [buffer].`);
45854
+ }
45855
+ });
45856
+ return this.params.resourceBinaries.map((binary, index) => ({
45857
+ fileName: `resource-${index + 1}.bin`,
45858
+ binary,
45859
+ targetId: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_CRATE,
45860
+ }));
46153
45861
  }
46154
45862
  const resourceUrl = DataManager.getSysResourcesLatestRelease({
46155
45863
  features,
@@ -46158,25 +45866,297 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46158
45866
  });
46159
45867
  if (resourceUrl) {
46160
45868
  const resource = (yield getSysResourceBinary(resourceUrl)).binary;
46161
- return resource;
45869
+ return [
45870
+ {
45871
+ fileName: 'resource.bin',
45872
+ binary: resource,
45873
+ targetId: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_CRATE,
45874
+ },
45875
+ ];
46162
45876
  }
46163
45877
  Log$4.warn('No resource url found');
46164
- return null;
45878
+ return [];
46165
45879
  });
46166
45880
  }
46167
- prepareBootloaderBinary(firmwareType, features) {
45881
+ prepareBootloaderBinary() {
45882
+ var _a;
45883
+ return (_a = this.params.bootloaderBinary) !== null && _a !== void 0 ? _a : null;
45884
+ }
45885
+ hasExplicitProtocolV2Payload(fwBinaryMap) {
45886
+ var _a;
45887
+ return (!!((_a = this.params.resourceBinaries) === null || _a === void 0 ? void 0 : _a.length) ||
45888
+ !!this.params.bootloaderBinary ||
45889
+ fwBinaryMap.length > 0);
45890
+ }
45891
+ buildProtocolV2InstallItems({ resourceBinaryMap, bootloaderBinary, fwBinaryMap, }) {
45892
+ const installItems = resourceBinaryMap.map(resource => (Object.assign(Object.assign({}, resource), { kind: 'resource' })));
45893
+ if (bootloaderBinary) {
45894
+ installItems.push({
45895
+ fileName: 'bootloader.bin',
45896
+ binary: bootloaderBinary,
45897
+ targetId: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_BOOTLOADER,
45898
+ kind: 'bootloader',
45899
+ });
45900
+ }
45901
+ installItems.push(...fwBinaryMap.map(item => (Object.assign(Object.assign({}, item), { kind: 'firmware' }))));
45902
+ return installItems;
45903
+ }
45904
+ getRemoteComponentEntries(release) {
45905
+ var _a;
45906
+ const { components } = release;
45907
+ if (!components)
45908
+ return [];
45909
+ const orderedKeys = [
45910
+ ...((_a = release.installOrder) !== null && _a !== void 0 ? _a : []),
45911
+ ...Object.keys(components).filter(key => { var _a; return !((_a = release.installOrder) === null || _a === void 0 ? void 0 : _a.includes(key)); }),
45912
+ ];
45913
+ return orderedKeys
45914
+ .map(key => {
45915
+ const component = components[key];
45916
+ return component ? [key, component] : undefined;
45917
+ })
45918
+ .filter((entry) => !!entry);
45919
+ }
45920
+ getRemoteComponentTarget(key, component) {
45921
+ var _a;
45922
+ const targetName = (_a = component.target) === null || _a === void 0 ? void 0 : _a.toUpperCase();
45923
+ if (targetName === 'ROMLOADER') {
45924
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, PROTOCOL_V2_ROMLOADER_UNSUPPORTED_MESSAGE);
45925
+ }
45926
+ const target = PROTOCOL_V2_REMOTE_COMPONENT_TARGETS[targetName];
45927
+ if (!target) {
45928
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Unsupported Protocol V2 firmware component target: ${key}/${component.target}`);
45929
+ }
45930
+ return target;
45931
+ }
45932
+ getProtocolV2ComponentTargetVersion(release, component, target) {
45933
+ if (component.version)
45934
+ return component.version;
45935
+ if (target.targetId === ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_BOOTLOADER) {
45936
+ return release.bootloaderVersion;
45937
+ }
45938
+ if (target.targetId === ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P1 ||
45939
+ target.targetId === ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P2) {
45940
+ return release.version;
45941
+ }
45942
+ return undefined;
45943
+ }
45944
+ getProtocolV2ComponentCurrentVersion(features, target) {
45945
+ switch (target.targetId) {
45946
+ case ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_BOOTLOADER:
45947
+ return getDeviceBootloaderVersion(features);
45948
+ case ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P1:
45949
+ case ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P2:
45950
+ return getDeviceFirmwareVersion(features);
45951
+ case ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_COPROCESSOR:
45952
+ return getDeviceBLEFirmwareVersion(features);
45953
+ case ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE01:
45954
+ return versionStringToArray(features.se01Version);
45955
+ case ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE02:
45956
+ return versionStringToArray(features.se02Version);
45957
+ case ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE03:
45958
+ return versionStringToArray(features.se03Version);
45959
+ case ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE04:
45960
+ return versionStringToArray(features.se04Version);
45961
+ default:
45962
+ return undefined;
45963
+ }
45964
+ }
45965
+ isProtocolV2ComponentVersionSatisfied(release, component, target, features) {
45966
+ const targetVersion = this.getProtocolV2ComponentTargetVersion(release, component, target);
45967
+ if (!targetVersion)
45968
+ return false;
45969
+ const currentVersion = this.getProtocolV2ComponentCurrentVersion(features, target);
45970
+ const compareResult = compareProtocolV2Versions(currentVersion, targetVersion);
45971
+ return compareResult !== undefined && compareResult >= 0;
45972
+ }
45973
+ getProtocolV2ResourceFilePath(path) {
45974
+ if (path.startsWith('vol'))
45975
+ return path;
45976
+ if (path.startsWith('/'))
45977
+ return `vol0:${path}`;
45978
+ return `vol0:/${path}`;
45979
+ }
45980
+ readProtocolV2DeviceFileHeader(path) {
45981
+ var _a, _b, _c, _d;
46168
45982
  return __awaiter(this, void 0, void 0, function* () {
46169
- if (this.params.bootloaderBinary) {
46170
- return this.params.bootloaderBinary;
45983
+ const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
45984
+ const filePath = this.getProtocolV2ResourceFilePath(path);
45985
+ const pathInfoRes = yield typedCall('FilesystemPathInfoQuery', 'FilesystemPathInfo', {
45986
+ path: filePath,
45987
+ });
45988
+ const fileSize = toProtocolV2FiniteNumber((_a = pathInfoRes.message) === null || _a === void 0 ? void 0 : _a.size);
45989
+ if (!((_b = pathInfoRes.message) === null || _b === void 0 ? void 0 : _b.exist) ||
45990
+ ((_c = pathInfoRes.message) === null || _c === void 0 ? void 0 : _c.directory) ||
45991
+ fileSize === undefined ||
45992
+ fileSize < PROTOCOL_V2_OKPP_HEADER_SIZE) {
45993
+ return null;
46171
45994
  }
46172
- if (this.params.bootloaderVersion) {
46173
- const bootResourceUrl = DataManager.getBootloaderResource(features, firmwareType);
46174
- if (bootResourceUrl) {
46175
- const bootBinary = (yield getSysResourceBinary(bootResourceUrl)).binary;
46176
- return bootBinary;
45995
+ const chunkSize = this.getProtocolV2FirmwareChunkSize();
45996
+ const chunks = [];
45997
+ let offset = 0;
45998
+ while (offset < PROTOCOL_V2_OKPP_HEADER_SIZE) {
45999
+ const readLen = Math.min(chunkSize, PROTOCOL_V2_OKPP_HEADER_SIZE - offset);
46000
+ const res = yield typedCall('FilesystemFileRead', 'FilesystemFile', {
46001
+ file: {
46002
+ path: filePath,
46003
+ offset,
46004
+ total_size: 0,
46005
+ },
46006
+ chunk_len: readLen,
46007
+ ui_percentage: undefined,
46008
+ });
46009
+ const data = toProtocolV2Bytes((_d = res.message) === null || _d === void 0 ? void 0 : _d.data);
46010
+ if (data.byteLength === 0)
46011
+ return null;
46012
+ chunks.push(data);
46013
+ offset += data.byteLength;
46014
+ }
46015
+ const headerBytes = new Uint8Array(offset);
46016
+ let cursor = 0;
46017
+ chunks.forEach(chunk => {
46018
+ headerBytes.set(chunk, cursor);
46019
+ cursor += chunk.byteLength;
46020
+ });
46021
+ return parseProtocolV2OkppHeader(headerBytes);
46022
+ });
46023
+ }
46024
+ isProtocolV2ResourcePackageMatched(pkg, manifestVersion) {
46025
+ var _a, _b;
46026
+ return __awaiter(this, void 0, void 0, function* () {
46027
+ try {
46028
+ const header = yield this.readProtocolV2DeviceFileHeader(pkg.path);
46029
+ if (!header)
46030
+ return false;
46031
+ const expectedType = (_a = pkg.type) !== null && _a !== void 0 ? _a : 'RESC';
46032
+ const expectedVersion = (_b = pkg.version) !== null && _b !== void 0 ? _b : manifestVersion;
46033
+ if (header.type !== expectedType)
46034
+ return false;
46035
+ if (expectedVersion && compareProtocolV2Versions(header.version, expectedVersion) !== 0) {
46036
+ return false;
46037
+ }
46038
+ const expectedPayloadHash = normalizeProtocolV2Hex(pkg.payloadHash);
46039
+ if (expectedPayloadHash && header.payloadHash !== expectedPayloadHash)
46040
+ return false;
46041
+ const expectedHeaderHash = normalizeProtocolV2Hex(pkg.headerHash);
46042
+ if (expectedHeaderHash && header.headerHash !== expectedHeaderHash)
46043
+ return false;
46044
+ return true;
46045
+ }
46046
+ catch (error) {
46047
+ Log$4.log(`Protocol V2 resource package check failed for ${pkg.path}: `, error);
46048
+ return false;
46049
+ }
46050
+ });
46051
+ }
46052
+ isProtocolV2ResourceManifestSatisfied(manifest) {
46053
+ var _a;
46054
+ return __awaiter(this, void 0, void 0, function* () {
46055
+ if (!((_a = manifest === null || manifest === void 0 ? void 0 : manifest.packages) === null || _a === void 0 ? void 0 : _a.length))
46056
+ return false;
46057
+ for (const pkg of manifest.packages) {
46058
+ if (!(yield this.isProtocolV2ResourcePackageMatched(pkg, manifest.version))) {
46059
+ return false;
46177
46060
  }
46178
46061
  }
46179
- return null;
46062
+ return true;
46063
+ });
46064
+ }
46065
+ getProtocolV2ResourceManifest(release, component) {
46066
+ var _a;
46067
+ return (_a = component.resourceManifest) !== null && _a !== void 0 ? _a : release.resourceManifest;
46068
+ }
46069
+ getProtocolV2ResourceComponentFileName(key) {
46070
+ const safeKey = key.replace(/[^a-z0-9_-]/gi, '_') || 'resource';
46071
+ return `resource-${safeKey}.bin`;
46072
+ }
46073
+ shouldInstallRemoteProtocolV2Component(release, key, component, target, features) {
46074
+ return __awaiter(this, void 0, void 0, function* () {
46075
+ if (target.kind === 'resource') {
46076
+ if (this.params.forcedUpdateRes ||
46077
+ features.bootloaderMode ||
46078
+ features.mode === 'bootloader') {
46079
+ return true;
46080
+ }
46081
+ const resourceMatched = yield this.isProtocolV2ResourceManifestSatisfied(this.getProtocolV2ResourceManifest(release, component));
46082
+ if (resourceMatched) {
46083
+ Log$4.log(`[FirmwareUpdateV4] skip Protocol V2 resource component ${key}; manifest matched`);
46084
+ }
46085
+ return !resourceMatched;
46086
+ }
46087
+ const versionSatisfied = this.isProtocolV2ComponentVersionSatisfied(release, component, target, features);
46088
+ if (versionSatisfied) {
46089
+ Log$4.log(`[FirmwareUpdateV4] skip Protocol V2 component ${key}; version is up to date`);
46090
+ }
46091
+ return !versionSatisfied;
46092
+ });
46093
+ }
46094
+ downloadRemoteProtocolV2Component(key, component) {
46095
+ return __awaiter(this, void 0, void 0, function* () {
46096
+ const target = this.getRemoteComponentTarget(key, component);
46097
+ if (!component.url) {
46098
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Missing Protocol V2 firmware component url: ${key}/${component.target}`);
46099
+ }
46100
+ const { binary } = yield getSysResourceBinary(component.url);
46101
+ return Object.assign(Object.assign({}, target), { binary });
46102
+ });
46103
+ }
46104
+ prepareRemoteProtocolV2Binaries(firmwareType, features) {
46105
+ return __awaiter(this, void 0, void 0, function* () {
46106
+ const release = DataManager.getFirmwareLatestRelease(features, firmwareType);
46107
+ const resourceBinaryMap = [];
46108
+ let bootloaderBinary = null;
46109
+ const fwBinaryMap = [];
46110
+ const installItems = [];
46111
+ if (!release) {
46112
+ return {
46113
+ resourceBinaryMap,
46114
+ bootloaderBinary,
46115
+ fwBinaryMap,
46116
+ installItems,
46117
+ };
46118
+ }
46119
+ const entries = this.getRemoteComponentEntries(release);
46120
+ for (const [key, component] of entries) {
46121
+ const target = this.getRemoteComponentTarget(key, component);
46122
+ const shouldInstall = yield this.shouldInstallRemoteProtocolV2Component(release, key, component, target, features);
46123
+ if (shouldInstall) {
46124
+ const remoteBinary = yield this.downloadRemoteProtocolV2Component(key, component);
46125
+ if (remoteBinary.kind === 'resource') {
46126
+ const binaryEntry = {
46127
+ fileName: this.getProtocolV2ResourceComponentFileName(key),
46128
+ binary: remoteBinary.binary,
46129
+ targetId: remoteBinary.targetId,
46130
+ };
46131
+ resourceBinaryMap.push(binaryEntry);
46132
+ installItems.push(Object.assign(Object.assign({}, binaryEntry), { kind: remoteBinary.kind }));
46133
+ }
46134
+ else if (remoteBinary.kind === 'bootloader') {
46135
+ bootloaderBinary = remoteBinary.binary;
46136
+ installItems.push({
46137
+ fileName: remoteBinary.fileName,
46138
+ binary: remoteBinary.binary,
46139
+ targetId: remoteBinary.targetId,
46140
+ kind: remoteBinary.kind,
46141
+ });
46142
+ }
46143
+ else {
46144
+ const binaryEntry = {
46145
+ fileName: remoteBinary.fileName,
46146
+ binary: remoteBinary.binary,
46147
+ targetId: remoteBinary.targetId,
46148
+ };
46149
+ fwBinaryMap.push(binaryEntry);
46150
+ installItems.push(Object.assign(Object.assign({}, binaryEntry), { kind: remoteBinary.kind }));
46151
+ }
46152
+ }
46153
+ }
46154
+ return {
46155
+ resourceBinaryMap,
46156
+ bootloaderBinary,
46157
+ fwBinaryMap,
46158
+ installItems,
46159
+ };
46180
46160
  });
46181
46161
  }
46182
46162
  isProtocolV2BootloaderMode() {
@@ -46187,20 +46167,17 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46187
46167
  return !!((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.bootloaderMode);
46188
46168
  }
46189
46169
  enterProtocolV2BootloaderMode() {
46190
- var _a, _b, _c;
46191
46170
  return __awaiter(this, void 0, void 0, function* () {
46192
46171
  if (this.isProtocolV2BootloaderMode()) {
46172
+ Log$4.debug('Protocol V2 device is already in bootloader mode, skip reboot to bootloader');
46193
46173
  return false;
46194
46174
  }
46195
46175
  try {
46196
46176
  this.postTipMessage(exports.FirmwareUpdateTipMessage.AutoRebootToBootloader);
46197
- yield this.protocolV2Reboot(hdTransport.DevRebootType.Bootloader);
46177
+ yield this.protocolV2Reboot(hdTransport.DeviceRebootType.Bootloader);
46198
46178
  this.postTipMessage(exports.FirmwareUpdateTipMessage.GoToBootloaderSuccess);
46199
- this.checkDeviceToBootloader(this.payload.connectId);
46200
- yield ((_a = this.checkPromise) === null || _a === void 0 ? void 0 : _a.promise);
46201
- this.checkPromise = null;
46202
- yield hdShared.wait(1500);
46203
- yield ((_c = (_b = this.device).acquire) === null || _c === void 0 ? void 0 : _c.call(_b));
46179
+ yield hdShared.wait(1000);
46180
+ yield this.waitForProtocolV2BootloaderMode();
46204
46181
  return true;
46205
46182
  }
46206
46183
  catch (error) {
@@ -46212,129 +46189,134 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46212
46189
  }
46213
46190
  });
46214
46191
  }
46192
+ waitForProtocolV2BootloaderMode(timeout = PROTOCOL_V2_BOOTLOADER_RECONNECT_TIMEOUT, retryInterval = 1000) {
46193
+ return __awaiter(this, void 0, void 0, function* () {
46194
+ const startTime = Date.now();
46195
+ let lastError;
46196
+ while (Date.now() - startTime < timeout) {
46197
+ try {
46198
+ yield this.reconnectProtocolV2Device();
46199
+ const deviceInfo = yield requestProtocolV2DeviceInfo({
46200
+ commands: this.device.getCommands(),
46201
+ timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT,
46202
+ });
46203
+ const features = this.device.updateProtocolV2Features(deviceInfo);
46204
+ if (features === null || features === void 0 ? void 0 : features.bootloaderMode) {
46205
+ return features;
46206
+ }
46207
+ lastError = new Error('Protocol V2 device is reachable but is not in bootloader mode');
46208
+ }
46209
+ catch (error) {
46210
+ lastError = error;
46211
+ Log$4.log('Protocol V2 bootloader mode not ready, polling reconnect: ', error);
46212
+ }
46213
+ yield hdShared.wait(retryInterval);
46214
+ }
46215
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure, `Protocol V2 bootloader not ready within ${timeout / 1000}s: ${this.normalizeErrorMessage(lastError)}`);
46216
+ });
46217
+ }
46215
46218
  collectExplicitTargetBinaries() {
46216
46219
  const entries = [];
46217
46220
  const push = (binary, fileName, targetId) => {
46218
46221
  if (binary)
46219
46222
  entries.push({ fileName, binary, targetId });
46220
46223
  };
46221
- push(this.params.romloaderBinary, 'romloader.bin', ProtocolV2FirmwareTargetType.TARGET_MAIN_BOOT);
46222
- push(this.params.applicationP1Binary, 'application_p1.bin', ProtocolV2FirmwareTargetType.TARGET_MAIN_APP);
46223
- push(this.params.applicationP2Binary, 'application_p2.bin', ProtocolV2FirmwareTargetType.TARGET_MAIN_APP);
46224
- push(this.params.coprocessorBinary, 'coprocessor.bin', ProtocolV2FirmwareTargetType.TARGET_BT);
46225
- push(this.params.se01Binary, 'se01.bin', ProtocolV2FirmwareTargetType.TARGET_SE1);
46226
- push(this.params.se02Binary, 'se02.bin', ProtocolV2FirmwareTargetType.TARGET_SE2);
46227
- push(this.params.se03Binary, 'se03.bin', ProtocolV2FirmwareTargetType.TARGET_SE3);
46228
- push(this.params.se04Binary, 'se04.bin', ProtocolV2FirmwareTargetType.TARGET_SE4);
46224
+ if (this.params.romloaderBinary) {
46225
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, PROTOCOL_V2_ROMLOADER_UNSUPPORTED_MESSAGE);
46226
+ }
46227
+ push(this.params.applicationP1Binary, 'application_p1.bin', ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P1);
46228
+ push(this.params.applicationP2Binary, 'application_p2.bin', ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P2);
46229
+ push(this.params.coprocessorBinary, 'coprocessor.bin', ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_COPROCESSOR);
46230
+ push(this.params.se01Binary, 'se01.bin', ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE01);
46231
+ push(this.params.se02Binary, 'se02.bin', ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE02);
46232
+ push(this.params.se03Binary, 'se03.bin', ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE03);
46233
+ push(this.params.se04Binary, 'se04.bin', ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE04);
46229
46234
  return entries;
46230
46235
  }
46231
- prepareFirmwareAndBleBinary(firmwareType, features) {
46232
- return __awaiter(this, void 0, void 0, function* () {
46233
- const fwBinaryMap = [];
46234
- if (this.params.firmwareBinary) {
46235
- fwBinaryMap.push({
46236
- fileName: 'firmware.bin',
46237
- binary: this.params.firmwareBinary,
46238
- });
46239
- }
46240
- else if (this.params.firmwareVersion) {
46241
- const firmwareBinary = (yield getBinary({
46242
- features,
46243
- version: this.params.firmwareVersion,
46244
- updateType: 'firmware',
46245
- isUpdateBootloader: false,
46246
- firmwareType,
46247
- })).binary;
46248
- fwBinaryMap.push({
46249
- fileName: 'firmware.bin',
46250
- binary: firmwareBinary,
46251
- });
46252
- }
46253
- if (this.params.bleBinary) {
46254
- fwBinaryMap.push({
46255
- fileName: 'ble-firmware.bin',
46256
- binary: this.params.bleBinary,
46257
- });
46258
- }
46259
- else if (this.params.bleVersion) {
46260
- const bleBinary = yield getBinary({
46261
- features,
46262
- version: this.params.bleVersion,
46263
- updateType: 'ble',
46264
- firmwareType,
46265
- });
46266
- fwBinaryMap.push({
46267
- fileName: 'ble-firmware.bin',
46268
- binary: bleBinary.binary,
46269
- });
46270
- }
46271
- return fwBinaryMap;
46272
- });
46273
- }
46274
- executeProtocolV2Update({ resourceBinary, fwBinaryMap, bootloaderBinary, }) {
46275
- var _a;
46236
+ executeProtocolV2Update({ resourceBinaryMap, fwBinaryMap, bootloaderBinary, installItems, }) {
46276
46237
  return __awaiter(this, void 0, void 0, function* () {
46238
+ const orderedInstallItems = installItems !== null && installItems !== void 0 ? installItems : this.buildProtocolV2InstallItems({
46239
+ resourceBinaryMap: resourceBinaryMap !== null && resourceBinaryMap !== void 0 ? resourceBinaryMap : [],
46240
+ bootloaderBinary: bootloaderBinary !== null && bootloaderBinary !== void 0 ? bootloaderBinary : null,
46241
+ fwBinaryMap: fwBinaryMap !== null && fwBinaryMap !== void 0 ? fwBinaryMap : [],
46242
+ });
46277
46243
  let totalSize = 0;
46278
46244
  let processedSize = 0;
46279
- if (resourceBinary)
46280
- totalSize += resourceBinary.byteLength;
46281
- for (const fwbinary of fwBinaryMap)
46282
- totalSize += fwbinary.binary.byteLength;
46283
- if (bootloaderBinary)
46284
- totalSize += bootloaderBinary.byteLength;
46245
+ let transferredSize = 0;
46246
+ for (const item of orderedInstallItems)
46247
+ totalSize += item.binary.byteLength;
46285
46248
  this.postTipMessage(exports.FirmwareUpdateTipMessage.StartTransferData);
46286
- const targets = [];
46287
- if (resourceBinary) {
46288
- const resourceFilePath = `${PROTOCOL_V2_FIRMWARE_STAGING_VOLUME}resource.bin`;
46289
- processedSize = yield this.protocolV2CommonUpdateProcess({
46290
- payload: resourceBinary,
46291
- filePath: resourceFilePath,
46292
- processedSize,
46293
- totalSize,
46294
- });
46295
- targets.push({
46296
- target_id: ProtocolV2FirmwareTargetType.TARGET_RESOURCE,
46297
- path: resourceFilePath,
46298
- });
46299
- }
46300
- if (bootloaderBinary) {
46301
- const bootloaderPath = `${PROTOCOL_V2_FIRMWARE_STAGING_VOLUME}bootloader.bin`;
46302
- processedSize = yield this.protocolV2CommonUpdateProcess({
46303
- payload: bootloaderBinary,
46304
- filePath: bootloaderPath,
46305
- processedSize,
46306
- totalSize,
46307
- });
46308
- targets.push({
46309
- target_id: ProtocolV2FirmwareTargetType.TARGET_MAIN_BOOT,
46310
- path: bootloaderPath,
46311
- });
46312
- }
46313
- for (const fwbinary of fwBinaryMap) {
46314
- const firmwarePath = `${PROTOCOL_V2_FIRMWARE_STAGING_VOLUME}${fwbinary.fileName}`;
46315
- processedSize = yield this.protocolV2CommonUpdateProcess({
46316
- payload: fwbinary.binary,
46317
- filePath: firmwarePath,
46318
- processedSize,
46319
- totalSize,
46320
- });
46321
- targets.push({
46322
- target_id: (_a = fwbinary.targetId) !== null && _a !== void 0 ? _a : protocolV2FileNameToTargetId(fwbinary.fileName),
46323
- path: firmwarePath,
46324
- });
46249
+ const transferStartTime = Date.now();
46250
+ const transferTransport = this.getProtocolV2FirmwareTransferTransport();
46251
+ const chunkSize = this.getProtocolV2FirmwareChunkSize();
46252
+ const onTransferredBytes = (bytes) => {
46253
+ transferredSize = bytes;
46254
+ };
46255
+ Log$4.log(`[FirmwareUpdateV4] transfer started transport=${transferTransport} total=${totalSize} bytes chunk=${chunkSize} bytes`);
46256
+ const stagedInstallTargets = [];
46257
+ try {
46258
+ for (const item of orderedInstallItems) {
46259
+ const filePath = this.getProtocolV2InstallItemStagingPath(item);
46260
+ Log$4.log(`[FirmwareUpdateV4] staging ${item.kind} via FilesystemFileWrite target=${item.targetId} path=${filePath} source=${item.fileName} bytes=${item.binary.byteLength}`);
46261
+ processedSize = yield this.protocolV2CommonUpdateProcess({
46262
+ payload: item.binary,
46263
+ filePath,
46264
+ processedSize,
46265
+ totalSize,
46266
+ onTransferredBytes,
46267
+ });
46268
+ transferredSize = processedSize;
46269
+ stagedInstallTargets.push(Object.assign(Object.assign({}, item), { path: filePath }));
46270
+ }
46271
+ if (totalSize > 0) {
46272
+ this.postProgressMessage(100, 'transferData');
46273
+ }
46274
+ const elapsedMs = Date.now() - transferStartTime;
46275
+ Log$4.log(`[FirmwareUpdateV4] transfer finished transport=${transferTransport} bytes=${totalSize} elapsed=${(elapsedMs / 1000).toFixed(2)}s speed=${formatProtocolV2TransferSpeed(totalSize, elapsedMs)} KB/s`);
46325
46276
  }
46326
- if (totalSize > 0) {
46327
- this.postProgressMessage(100, 'transferData');
46277
+ catch (error) {
46278
+ const elapsedMs = Date.now() - transferStartTime;
46279
+ Log$4.warn(`[FirmwareUpdateV4] transfer failed transport=${transferTransport} bytes=${transferredSize}/${totalSize} elapsed=${(elapsedMs / 1000).toFixed(2)}s speed=${formatProtocolV2TransferSpeed(transferredSize, elapsedMs)} KB/s`);
46280
+ throw error;
46328
46281
  }
46329
46282
  this.postTipMessage(exports.FirmwareUpdateTipMessage.ConfirmOnDevice);
46330
- const startResponse = yield this.protocolV2StartFirmwareUpdate({ targets });
46331
- yield this.waitForProtocolV2FirmwareUpdateComplete(targets, startResponse);
46283
+ const firmwareTargets = [];
46284
+ const flushFirmwareTargets = () => __awaiter(this, void 0, void 0, function* () {
46285
+ if (firmwareTargets.length === 0)
46286
+ return;
46287
+ const targets = firmwareTargets.splice(0, firmwareTargets.length);
46288
+ Log$4.log(`[FirmwareUpdateV4] DeviceFirmwareUpdateRequest targets=${JSON.stringify(targets)}`);
46289
+ const startResponse = yield this.protocolV2StartFirmwareUpdate({ targets });
46290
+ yield this.waitForProtocolV2FirmwareUpdateComplete(targets, startResponse);
46291
+ });
46292
+ for (const item of stagedInstallTargets) {
46293
+ const target = {
46294
+ target_id: item.targetId,
46295
+ path: item.path,
46296
+ };
46297
+ if (item.kind === 'resource') {
46298
+ yield flushFirmwareTargets();
46299
+ const resourceTargets = [target];
46300
+ Log$4.log(`[FirmwareUpdateV4] DeviceFirmwareUpdateRequest resources=${JSON.stringify(resourceTargets)}`);
46301
+ const startResponse = yield this.protocolV2StartFirmwareUpdate({
46302
+ targets: resourceTargets,
46303
+ });
46304
+ yield this.waitForProtocolV2FirmwareUpdateComplete(resourceTargets, startResponse);
46305
+ }
46306
+ else {
46307
+ firmwareTargets.push(target);
46308
+ }
46309
+ }
46310
+ yield flushFirmwareTargets();
46332
46311
  });
46333
46312
  }
46313
+ getProtocolV2InstallItemStagingPath(item) {
46314
+ return `${PROTOCOL_V2_FIRMWARE_STAGING_VOLUME}${item.fileName}`;
46315
+ }
46334
46316
  queryProtocolV2FirmwareUpdateStatus() {
46335
46317
  return __awaiter(this, void 0, void 0, function* () {
46336
46318
  const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
46337
- return typedCall('DevGetFirmwareUpdateStatus', 'DevFirmwareUpdateStatus', {}, {
46319
+ return typedCall('DeviceFirmwareUpdateStatusGet', 'DeviceFirmwareUpdateStatus', {}, {
46338
46320
  timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT,
46339
46321
  });
46340
46322
  });
@@ -46347,19 +46329,46 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46347
46329
  });
46348
46330
  });
46349
46331
  }
46332
+ isProtocolV2NormalModeFeatures(features) {
46333
+ return !!features && !features.bootloaderMode && features.mode !== 'bootloader';
46334
+ }
46335
+ probeProtocolV2NormalMode() {
46336
+ return __awaiter(this, void 0, void 0, function* () {
46337
+ const deviceInfo = yield requestProtocolV2DeviceInfo({
46338
+ commands: this.device.getCommands(),
46339
+ timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT,
46340
+ request: PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST,
46341
+ });
46342
+ const features = this.device.updateProtocolV2Features(deviceInfo);
46343
+ if (this.isProtocolV2NormalModeFeatures(features)) {
46344
+ Log$4.log('Protocol V2 firmware install finished; device is back in normal mode');
46345
+ return true;
46346
+ }
46347
+ return false;
46348
+ });
46349
+ }
46350
46350
  assertProtocolV2TargetStatus(statusTargets, expectedTargetIds) {
46351
- const failedTarget = statusTargets.find(target => expectedTargetIds.has(target.target_id) &&
46352
- target.status === PROTOCOL_V2_TARGET_STATUS_FAILED);
46351
+ const failedTarget = statusTargets.find(target => {
46352
+ var _a;
46353
+ return expectedTargetIds.has((_a = normalizeProtocolV2TargetId(target.target_id)) !== null && _a !== void 0 ? _a : -1) &&
46354
+ isProtocolV2TargetStatusFailed(target.status);
46355
+ });
46353
46356
  if (failedTarget) {
46354
46357
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, `Protocol V2 firmware target ${failedTarget.target_id} failed`);
46355
46358
  }
46356
- const completedTargets = statusTargets.filter(target => expectedTargetIds.has(target.target_id) &&
46357
- target.status === PROTOCOL_V2_TARGET_STATUS_FINISHED);
46359
+ const completedTargets = statusTargets.filter(target => {
46360
+ var _a;
46361
+ return expectedTargetIds.has((_a = normalizeProtocolV2TargetId(target.target_id)) !== null && _a !== void 0 ? _a : -1) &&
46362
+ isProtocolV2TargetStatusFinished(target.status);
46363
+ });
46358
46364
  if (completedTargets.length === expectedTargetIds.size && expectedTargetIds.size > 0) {
46359
46365
  return true;
46360
46366
  }
46361
- const inProgressTarget = statusTargets.find(target => expectedTargetIds.has(target.target_id) &&
46362
- target.status === PROTOCOL_V2_TARGET_STATUS_IN_PROGRESS);
46367
+ const inProgressTarget = statusTargets.find(target => {
46368
+ var _a;
46369
+ return expectedTargetIds.has((_a = normalizeProtocolV2TargetId(target.target_id)) !== null && _a !== void 0 ? _a : -1) &&
46370
+ isProtocolV2TargetStatusInProgress(target.status);
46371
+ });
46363
46372
  if (inProgressTarget) {
46364
46373
  this.postProgressMessage(99, 'installingFirmware');
46365
46374
  }
@@ -46369,11 +46378,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46369
46378
  var _a, _b;
46370
46379
  return __awaiter(this, void 0, void 0, function* () {
46371
46380
  const expectedTargetIds = new Set(targets.map(target => target.target_id));
46372
- if ((startResponse === null || startResponse === void 0 ? void 0 : startResponse.type) === 'Success') {
46373
- return;
46374
- }
46375
- if ((startResponse === null || startResponse === void 0 ? void 0 : startResponse.type) === 'DevFirmwareUpdateStatus') {
46376
- const statusTargets = ((_a = startResponse.message.targets) !== null && _a !== void 0 ? _a : []);
46381
+ if ((startResponse === null || startResponse === void 0 ? void 0 : startResponse.type) === 'DeviceFirmwareUpdateStatus') {
46382
+ const statusTargets = ((_a = startResponse.message.records) !== null && _a !== void 0 ? _a : []);
46377
46383
  if (this.assertProtocolV2TargetStatus(statusTargets, expectedTargetIds)) {
46378
46384
  return;
46379
46385
  }
@@ -46383,7 +46389,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46383
46389
  while (Date.now() - startTime < PROTOCOL_V2_INSTALL_TIMEOUT) {
46384
46390
  try {
46385
46391
  const statusRes = yield this.queryProtocolV2FirmwareUpdateStatus();
46386
- const statusTargets = ((_b = statusRes.message.targets) !== null && _b !== void 0 ? _b : []);
46392
+ const statusTargets = ((_b = statusRes.message.records) !== null && _b !== void 0 ? _b : []);
46387
46393
  if (this.assertProtocolV2TargetStatus(statusTargets, expectedTargetIds)) {
46388
46394
  return;
46389
46395
  }
@@ -46397,15 +46403,17 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46397
46403
  if (isProtocolV2PollingTransientError(error)) {
46398
46404
  try {
46399
46405
  yield this.reconnectProtocolV2Device();
46406
+ if (yield this.probeProtocolV2NormalMode()) {
46407
+ return;
46408
+ }
46400
46409
  }
46401
46410
  catch (reconnectError) {
46402
46411
  lastError = reconnectError;
46403
- Log$4.log('Protocol V2 firmware install reconnect/status polling failed: ', reconnectError);
46412
+ Log$4.log('Protocol V2 firmware install reconnect/normal-mode probe failed: ', reconnectError);
46404
46413
  }
46405
46414
  try {
46406
46415
  yield this.pingProtocolV2Device();
46407
46416
  Log$4.log('Protocol V2 firmware status unavailable, Ping is ready');
46408
- return;
46409
46417
  }
46410
46418
  catch (pingError) {
46411
46419
  lastError = pingError;
@@ -46421,7 +46429,17 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46421
46429
  exitProtocolV2BootloaderToNormal() {
46422
46430
  return __awaiter(this, void 0, void 0, function* () {
46423
46431
  this.postTipMessage(exports.FirmwareUpdateTipMessage.SwitchFirmwareReconnectDevice);
46424
- yield this.protocolV2Reboot(hdTransport.DevRebootType.Normal);
46432
+ try {
46433
+ yield this.reconnectProtocolV2Device();
46434
+ if (yield this.probeProtocolV2NormalMode()) {
46435
+ Log$4.log('Protocol V2 device is already in normal mode, skip normal reboot');
46436
+ return;
46437
+ }
46438
+ }
46439
+ catch (error) {
46440
+ Log$4.log('Protocol V2 normal-mode probe before reboot failed: ', error);
46441
+ }
46442
+ yield this.protocolV2Reboot(hdTransport.DeviceRebootType.Normal);
46425
46443
  });
46426
46444
  }
46427
46445
  waitForProtocolV2FinalFeatures() {
@@ -46452,7 +46470,11 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46452
46470
  timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT,
46453
46471
  request: PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST,
46454
46472
  });
46455
- return this.device.updateProtocolV2Features(deviceInfo);
46473
+ const features = this.device.updateProtocolV2Features(deviceInfo);
46474
+ if (features.bootloaderMode || features.mode === 'bootloader') {
46475
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, 'Protocol V2 device is still in bootloader mode');
46476
+ }
46477
+ return features;
46456
46478
  }
46457
46479
  catch (error) {
46458
46480
  lastError = error;
@@ -46464,7 +46486,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46464
46486
  });
46465
46487
  }
46466
46488
  reconnectProtocolV2Device() {
46467
- var _a, _b, _c;
46489
+ var _a, _b, _c, _d;
46468
46490
  return __awaiter(this, void 0, void 0, function* () {
46469
46491
  if (this.isBleReconnect()) {
46470
46492
  yield this.acquireProtocolV2BleDevice();
@@ -46472,17 +46494,30 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46472
46494
  }
46473
46495
  const deviceDiff = yield ((_a = this.device.deviceConnector) === null || _a === void 0 ? void 0 : _a.enumerate());
46474
46496
  const devicesDescriptor = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
46475
- const { deviceList } = yield DevicePool.getDevices(devicesDescriptor, this.connectId);
46497
+ if (DataManager.isBrowserWebUsb(DataManager.getSettings('env')) &&
46498
+ devicesDescriptor.length === 1) {
46499
+ this.device.updateDescriptor(Object.assign(Object.assign({}, devicesDescriptor[0]), { protocolType: PROTOCOL_V2_CONNECT_PROTOCOL }), true);
46500
+ yield this.device.acquire(PROTOCOL_V2_CONNECT_PROTOCOL, { throwOnRunPromiseError: true });
46501
+ this.device.commands.disposed = false;
46502
+ this.device.getCommands().mainId = (_c = this.device.mainId) !== null && _c !== void 0 ? _c : '';
46503
+ yield this.device.initialize();
46504
+ return;
46505
+ }
46506
+ const { deviceList } = yield DevicePool.getDevices(devicesDescriptor, undefined, {
46507
+ connectProtocol: PROTOCOL_V2_CONNECT_PROTOCOL,
46508
+ });
46476
46509
  if (deviceList.length !== 1) {
46477
46510
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
46478
46511
  }
46512
+ Log$4.debug('Protocol V2 firmware reconnect using single enumerated device:', deviceList[0].getConnectId());
46479
46513
  this.device.updateFromCache(deviceList[0]);
46480
- yield this.device.acquire();
46514
+ yield this.device.acquire(PROTOCOL_V2_CONNECT_PROTOCOL, { throwOnRunPromiseError: true });
46481
46515
  this.device.commands.disposed = false;
46482
- this.device.getCommands().mainId = (_c = this.device.mainId) !== null && _c !== void 0 ? _c : '';
46516
+ this.device.getCommands().mainId = (_d = this.device.mainId) !== null && _d !== void 0 ? _d : '';
46517
+ yield this.device.initialize();
46483
46518
  });
46484
46519
  }
46485
- protocolV2CommonUpdateProcess({ payload, filePath, processedSize, totalSize, }) {
46520
+ protocolV2CommonUpdateProcess({ payload, filePath, processedSize, totalSize, onTransferredBytes, }) {
46486
46521
  return __awaiter(this, void 0, void 0, function* () {
46487
46522
  const chunkSize = this.getProtocolV2FirmwareChunkSize();
46488
46523
  let offset = 0;
@@ -46497,7 +46532,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46497
46532
  const chunkLength = chunkEnd - offset;
46498
46533
  const chunk = payload.slice(offset, chunkEnd);
46499
46534
  const overwrite = offset === 0;
46500
- const progress = getUploadProgress(chunkEnd);
46535
+ const progress = getProtocolV2DeviceTransferProgress((processedSize !== null && processedSize !== void 0 ? processedSize : 0) + offset, (processedSize !== null && processedSize !== void 0 ? processedSize : 0) + chunkEnd, totalSize !== null && totalSize !== void 0 ? totalSize : payload.byteLength);
46501
46536
  const writeRes = yield this.fileWriteWithRetry(filePath, payload.byteLength, offset, chunk, overwrite, progress);
46502
46537
  const processedByte = Number(writeRes.message.processed_byte);
46503
46538
  const nextOffset = Number.isFinite(processedByte) && processedByte > offset
@@ -46507,11 +46542,23 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46507
46542
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.EmmcFileWriteFirmwareError, `invalid processed_byte ${writeRes.message.processed_byte} for offset ${offset}`);
46508
46543
  }
46509
46544
  offset = nextOffset;
46545
+ onTransferredBytes === null || onTransferredBytes === void 0 ? void 0 : onTransferredBytes((processedSize !== null && processedSize !== void 0 ? processedSize : 0) + offset);
46510
46546
  this.postProgressMessage(getUploadProgress(offset), 'transferData');
46511
46547
  }
46512
46548
  return totalSize !== undefined ? (processedSize !== null && processedSize !== void 0 ? processedSize : 0) + payload.byteLength : 0;
46513
46549
  });
46514
46550
  }
46551
+ getProtocolV2FirmwareTransferTransport() {
46552
+ const env = DataManager.getSettings('env');
46553
+ if (env && DataManager.isBleConnect(env)) {
46554
+ return 'BLE';
46555
+ }
46556
+ if (env &&
46557
+ (DataManager.isBrowserWebUsb(env) || DataManager.isDesktopWebUsb(env) || env === 'web')) {
46558
+ return 'WebUSB';
46559
+ }
46560
+ return env !== null && env !== void 0 ? env : 'unknown';
46561
+ }
46515
46562
  fileWriteWithRetry(filePath, totalFileSize, offset, chunk, overwrite, progress) {
46516
46563
  return __awaiter(this, void 0, void 0, function* () {
46517
46564
  const writeFunc = () => __awaiter(this, void 0, void 0, function* () {
@@ -46573,22 +46620,21 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46573
46620
  const commands = this.device.getCommands();
46574
46621
  let response;
46575
46622
  try {
46576
- response = yield commands.typedCall('DevFirmwareUpdate', PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES, {
46623
+ response = yield commands.typedCall('DeviceFirmwareUpdateRequest', PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES, {
46577
46624
  targets,
46578
46625
  }, {
46579
- intermediateTypes: ['DevFirmwareInstallProgress'],
46626
+ intermediateTypes: ['DeviceFirmwareUpdateStatus'],
46627
+ timeoutMs: PROTOCOL_V2_START_UPDATE_TIMEOUT,
46580
46628
  onIntermediateResponse: (response) => {
46581
- var _a;
46582
- const progress = Number((_a = response.message) === null || _a === void 0 ? void 0 : _a.progress);
46583
- if (Number.isFinite(progress)) {
46584
- this.postProgressMessage(Math.min(progress, 99), 'installingFirmware');
46629
+ if (response.type === 'DeviceFirmwareUpdateStatus') {
46630
+ this.postProgressMessage(99, 'installingFirmware');
46585
46631
  }
46586
46632
  },
46587
46633
  });
46588
46634
  }
46589
46635
  catch (error) {
46590
- if (isProtocolV2DeviceDisconnectedError(error)) {
46591
- Log$4.log('Rebooting device');
46636
+ if (isProtocolV2StartUpdateTransientError(error)) {
46637
+ Log$4.log('Protocol V2 firmware update request did not return; continue status polling', error);
46592
46638
  }
46593
46639
  else {
46594
46640
  throw error;
@@ -46602,7 +46648,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46602
46648
  return __awaiter(this, void 0, void 0, function* () {
46603
46649
  const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
46604
46650
  try {
46605
- const res = yield typedCall('DevReboot', 'Success', {
46651
+ const res = yield typedCall('DeviceReboot', 'Success', {
46606
46652
  reboot_type: rebootType,
46607
46653
  });
46608
46654
  return res.message;
@@ -46687,7 +46733,7 @@ class PromptWebDeviceAccess extends BaseMethod {
46687
46733
  }
46688
46734
  }
46689
46735
 
46690
- class GetProtoVersion extends BaseMethod {
46736
+ class ProtocolInfoRequest extends BaseMethod {
46691
46737
  init() {
46692
46738
  this.requireProtocolV2 = true;
46693
46739
  this.skipForceUpdateCheck = true;
@@ -46696,7 +46742,7 @@ class GetProtoVersion extends BaseMethod {
46696
46742
  }
46697
46743
  run() {
46698
46744
  return __awaiter(this, void 0, void 0, function* () {
46699
- const res = yield this.device.commands.typedCall('GetProtoVersion', 'ProtoVersion', {});
46745
+ const res = yield this.device.commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {});
46700
46746
  return Promise.resolve(res.message);
46701
46747
  });
46702
46748
  }
@@ -46733,7 +46779,7 @@ class DeviceReboot extends BaseMethod {
46733
46779
  run() {
46734
46780
  var _a;
46735
46781
  return __awaiter(this, void 0, void 0, function* () {
46736
- const res = yield this.device.commands.typedCall('DevReboot', 'Success', {
46782
+ const res = yield this.device.commands.typedCall('DeviceReboot', 'Success', {
46737
46783
  reboot_type: normalizeRebootType((_a = this.params.reboot_type) !== null && _a !== void 0 ? _a : this.params.rebootType),
46738
46784
  });
46739
46785
  return Promise.resolve(res.message);
@@ -46744,7 +46790,7 @@ class DeviceReboot extends BaseMethod {
46744
46790
  const TARGET_KEYS = [
46745
46791
  'hw',
46746
46792
  'fw',
46747
- 'bt',
46793
+ 'coprocessor',
46748
46794
  'se1',
46749
46795
  'se2',
46750
46796
  'se3',
@@ -46755,7 +46801,7 @@ const TYPE_KEYS = ['version', 'build_id', 'hash', 'specific'];
46755
46801
  const DEFAULT_TARGETS = {
46756
46802
  hw: true,
46757
46803
  fw: true,
46758
- bt: true,
46804
+ coprocessor: true,
46759
46805
  status: true,
46760
46806
  };
46761
46807
  const DEFAULT_TYPES = {
@@ -46776,7 +46822,27 @@ function pickBooleanKeys(value, keys) {
46776
46822
  }
46777
46823
  return hasKey ? result : undefined;
46778
46824
  }
46779
- class DeviceGetDeviceInfo extends BaseMethod {
46825
+ function assertKnownKeys(value, keys, name) {
46826
+ if (value == null)
46827
+ return;
46828
+ if (typeof value !== 'object' || Array.isArray(value)) {
46829
+ throw invalidParameter(`Parameter [${name}] must be an object.`);
46830
+ }
46831
+ const allowed = new Set(keys);
46832
+ const unknownKeys = Object.keys(value).filter(key => !allowed.has(key));
46833
+ if (unknownKeys.length > 0) {
46834
+ throw invalidParameter(`Parameter [${name}] contains unsupported key(s): ${unknownKeys.join(', ')}.`);
46835
+ }
46836
+ }
46837
+ function normalizeTargets(value) {
46838
+ assertKnownKeys(value, TARGET_KEYS.map(key => String(key)), 'targets');
46839
+ return pickBooleanKeys(value, TARGET_KEYS);
46840
+ }
46841
+ function normalizeTypes(value) {
46842
+ assertKnownKeys(value, TYPE_KEYS.map(key => String(key)), 'types');
46843
+ return pickBooleanKeys(value, TYPE_KEYS);
46844
+ }
46845
+ class DeviceInfoGet extends BaseMethod {
46780
46846
  init() {
46781
46847
  var _a, _b;
46782
46848
  this.requireProtocolV2 = true;
@@ -46788,8 +46854,8 @@ class DeviceGetDeviceInfo extends BaseMethod {
46788
46854
  this.useDevicePassphraseState = false;
46789
46855
  this.skipForceUpdateCheck = true;
46790
46856
  this.params = {
46791
- targets: (_a = pickBooleanKeys(this.payload.targets, TARGET_KEYS)) !== null && _a !== void 0 ? _a : DEFAULT_TARGETS,
46792
- types: (_b = pickBooleanKeys(this.payload.types, TYPE_KEYS)) !== null && _b !== void 0 ? _b : DEFAULT_TYPES,
46857
+ targets: (_a = normalizeTargets(this.payload.targets)) !== null && _a !== void 0 ? _a : DEFAULT_TARGETS,
46858
+ types: (_b = normalizeTypes(this.payload.types)) !== null && _b !== void 0 ? _b : DEFAULT_TYPES,
46793
46859
  };
46794
46860
  }
46795
46861
  run() {
@@ -46797,7 +46863,7 @@ class DeviceGetDeviceInfo extends BaseMethod {
46797
46863
  if (!this.device.isProtocolV2()) {
46798
46864
  throw hdShared.createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
46799
46865
  }
46800
- const res = yield this.device.commands.typedCall('DevGetDeviceInfo', 'DeviceInfo', {
46866
+ const res = yield this.device.commands.typedCall('DeviceInfoGet', 'DeviceInfo', {
46801
46867
  targets: this.params.targets,
46802
46868
  types: this.params.types,
46803
46869
  }, { timeoutMs: PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS });
@@ -46806,21 +46872,6 @@ class DeviceGetDeviceInfo extends BaseMethod {
46806
46872
  }
46807
46873
  }
46808
46874
 
46809
- class DeviceGetOnboardingStatus extends BaseMethod {
46810
- init() {
46811
- this.requireProtocolV2 = true;
46812
- this.skipForceUpdateCheck = true;
46813
- this.useDevicePassphraseState = false;
46814
- this.params = undefined;
46815
- }
46816
- run() {
46817
- return __awaiter(this, void 0, void 0, function* () {
46818
- const res = yield this.device.commands.typedCall('GetOnboardingStatus', 'OnboardingStatus', {});
46819
- return Promise.resolve(res.message);
46820
- });
46821
- }
46822
- }
46823
-
46824
46875
  class DeviceFirmwareUpdate extends BaseMethod {
46825
46876
  init() {
46826
46877
  this.requireProtocolV2 = true;
@@ -46837,18 +46888,14 @@ class DeviceFirmwareUpdate extends BaseMethod {
46837
46888
  return __awaiter(this, void 0, void 0, function* () {
46838
46889
  const targets = normalizeFirmwareTargets(this.params);
46839
46890
  try {
46840
- const res = yield this.device.commands.typedCall('DevFirmwareUpdate', PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES, {
46891
+ const res = yield this.device.commands.typedCall('DeviceFirmwareUpdateRequest', PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES, {
46841
46892
  targets,
46842
46893
  }, Object.assign(Object.assign({}, PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS), { onIntermediateResponse: (response) => {
46843
- var _a;
46844
- if (response.type !== 'DevFirmwareInstallProgress')
46845
- return;
46846
- const progress = Number((_a = response.message) === null || _a === void 0 ? void 0 : _a.progress);
46847
- if (!Number.isFinite(progress))
46894
+ if (response.type !== 'DeviceFirmwareUpdateStatus')
46848
46895
  return;
46849
46896
  this.postMessage(createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
46850
46897
  device: this.device.toMessageObject(),
46851
- progress: Math.min(Math.max(progress, 0), 100),
46898
+ progress: 99,
46852
46899
  progressType: 'installingFirmware',
46853
46900
  }));
46854
46901
  } }));
@@ -46866,70 +46913,75 @@ class DeviceFirmwareUpdate extends BaseMethod {
46866
46913
  }
46867
46914
  }
46868
46915
 
46869
- class DeviceGetFirmwareUpdateStatus extends BaseMethod {
46870
- init() {
46871
- this.requireProtocolV2 = true;
46872
- this.skipForceUpdateCheck = true;
46873
- this.useDevicePassphraseState = false;
46874
- this.params = undefined;
46916
+ const DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS = ['status', 'payload_version', 'path'];
46917
+ function normalizeStatusFields(fields) {
46918
+ if (fields === undefined || fields === null)
46919
+ return undefined;
46920
+ if (typeof fields !== 'object' || Array.isArray(fields)) {
46921
+ throw invalidParameter('Parameter [fields] must be an object.');
46875
46922
  }
46876
- run() {
46877
- return __awaiter(this, void 0, void 0, function* () {
46878
- const res = yield this.device.commands.typedCall('DevGetFirmwareUpdateStatus', 'DevFirmwareUpdateStatus', {});
46879
- return Promise.resolve(res.message);
46880
- });
46923
+ const unknownField = Object.keys(fields).find(field => !DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS.includes(field));
46924
+ if (unknownField) {
46925
+ throw invalidParameter(`Unsupported firmware update status field: ${unknownField}`);
46881
46926
  }
46927
+ const normalized = {};
46928
+ for (const field of DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS) {
46929
+ const value = fields[field];
46930
+ if (value === undefined)
46931
+ continue;
46932
+ if (typeof value !== 'boolean') {
46933
+ throw invalidParameter(`Parameter [fields.${field}] must be a boolean.`);
46934
+ }
46935
+ normalized[field] = value;
46936
+ }
46937
+ return normalized;
46882
46938
  }
46883
-
46884
- class DevReboot extends BaseMethod {
46939
+ class DeviceGetFirmwareUpdateStatus extends BaseMethod {
46885
46940
  init() {
46886
46941
  this.requireProtocolV2 = true;
46887
46942
  this.skipForceUpdateCheck = true;
46888
46943
  this.useDevicePassphraseState = false;
46889
- this.params = {
46890
- rebootType: this.payload.rebootType,
46891
- reboot_type: this.payload.reboot_type,
46892
- };
46944
+ const fields = normalizeStatusFields(this.payload.fields);
46945
+ this.params = fields ? { fields } : {};
46893
46946
  }
46894
46947
  run() {
46895
- var _a;
46896
46948
  return __awaiter(this, void 0, void 0, function* () {
46897
- const res = yield this.device.commands.typedCall('DevReboot', 'Success', {
46898
- reboot_type: normalizeRebootType((_a = this.params.reboot_type) !== null && _a !== void 0 ? _a : this.params.rebootType),
46899
- });
46949
+ const res = yield this.device.commands.typedCall('DeviceFirmwareUpdateStatusGet', 'DeviceFirmwareUpdateStatus', this.params);
46900
46950
  return Promise.resolve(res.message);
46901
46951
  });
46902
46952
  }
46903
46953
  }
46904
46954
 
46905
- class FactoryDeviceInfoSettings extends BaseMethod {
46955
+ class DeviceFactoryInfoSet extends BaseMethod {
46906
46956
  init() {
46907
46957
  this.requireProtocolV2 = true;
46908
46958
  this.skipForceUpdateCheck = true;
46909
46959
  this.useDevicePassphraseState = false;
46910
46960
  this.params = {
46911
- serial_no: this.payload.serial_no,
46912
- serialNo: this.payload.serialNo,
46913
- cpu_info: this.payload.cpu_info,
46914
- cpuInfo: this.payload.cpuInfo,
46915
- pre_firmware: this.payload.pre_firmware,
46916
- preFirmware: this.payload.preFirmware,
46961
+ version: this.payload.version,
46962
+ serial_number: this.payload.serial_number,
46963
+ burn_in_completed: this.payload.burn_in_completed,
46964
+ factory_test_completed: this.payload.factory_test_completed,
46965
+ manufacture_time: this.payload.manufacture_time,
46917
46966
  };
46918
46967
  }
46919
46968
  run() {
46920
- var _a, _b, _c;
46921
46969
  return __awaiter(this, void 0, void 0, function* () {
46922
- const res = yield this.device.commands.typedCall('FactoryDeviceInfoSettings', 'Success', {
46923
- serial_no: (_a = this.params.serial_no) !== null && _a !== void 0 ? _a : this.params.serialNo,
46924
- cpu_info: (_b = this.params.cpu_info) !== null && _b !== void 0 ? _b : this.params.cpuInfo,
46925
- pre_firmware: (_c = this.params.pre_firmware) !== null && _c !== void 0 ? _c : this.params.preFirmware,
46970
+ const res = yield this.device.commands.typedCall('DeviceFactoryInfoSet', 'Success', {
46971
+ info: {
46972
+ version: this.params.version,
46973
+ serial_number: this.params.serial_number,
46974
+ burn_in_completed: this.params.burn_in_completed,
46975
+ factory_test_completed: this.params.factory_test_completed,
46976
+ manufacture_time: this.params.manufacture_time,
46977
+ },
46926
46978
  });
46927
46979
  return Promise.resolve(res.message);
46928
46980
  });
46929
46981
  }
46930
46982
  }
46931
46983
 
46932
- class FactoryGetDeviceInfo extends BaseMethod {
46984
+ class DeviceFactoryInfoGet extends BaseMethod {
46933
46985
  init() {
46934
46986
  this.requireProtocolV2 = true;
46935
46987
  this.skipForceUpdateCheck = true;
@@ -46938,13 +46990,13 @@ class FactoryGetDeviceInfo extends BaseMethod {
46938
46990
  }
46939
46991
  run() {
46940
46992
  return __awaiter(this, void 0, void 0, function* () {
46941
- const res = yield this.device.commands.typedCall('FactoryGetDeviceInfo', 'FactoryDeviceInfo', {});
46993
+ const res = yield this.device.commands.typedCall('DeviceFactoryInfoGet', 'DeviceFactoryInfo', {});
46942
46994
  return Promise.resolve(res.message);
46943
46995
  });
46944
46996
  }
46945
46997
  }
46946
46998
 
46947
- class FilesystemFixPermission extends BaseMethod {
46999
+ class FilesystemPermissionFix extends BaseMethod {
46948
47000
  init() {
46949
47001
  this.requireProtocolV2 = true;
46950
47002
  this.skipForceUpdateCheck = true;
@@ -46953,7 +47005,7 @@ class FilesystemFixPermission extends BaseMethod {
46953
47005
  }
46954
47006
  run() {
46955
47007
  return __awaiter(this, void 0, void 0, function* () {
46956
- const res = yield this.device.commands.typedCall('FilesystemFixPermission', 'Success', {});
47008
+ const res = yield this.device.commands.typedCall('FilesystemPermissionFix', 'Success', {});
46957
47009
  return Promise.resolve(res.message);
46958
47010
  });
46959
47011
  }
@@ -47056,6 +47108,18 @@ function toUint8Array(value) {
47056
47108
  }
47057
47109
  return new Uint8Array(0);
47058
47110
  }
47111
+ function getDeviceTransferProgress$1(bytesBeforeChunk, bytesAfterChunk, totalBytes) {
47112
+ if (!Number.isFinite(totalBytes) || totalBytes <= 0) {
47113
+ return 100;
47114
+ }
47115
+ if (bytesBeforeChunk <= 0 && bytesAfterChunk < totalBytes) {
47116
+ return 0;
47117
+ }
47118
+ if (bytesAfterChunk >= totalBytes) {
47119
+ return 100;
47120
+ }
47121
+ return Math.min(Math.max(Math.ceil((bytesAfterChunk / totalBytes) * 100), 1), 99);
47122
+ }
47059
47123
  class FileRead extends BaseMethod {
47060
47124
  init() {
47061
47125
  this.requireProtocolV2 = true;
@@ -47096,7 +47160,7 @@ class FileRead extends BaseMethod {
47096
47160
  while (read < totalLength) {
47097
47161
  const readLen = Math.min(chunkSize, totalLength - read);
47098
47162
  const offset = startOffset + read;
47099
- const progress = (_e = this.params.uiPercentage) !== null && _e !== void 0 ? _e : Math.min(Math.ceil(((read + readLen) / Math.max(totalLength, 1)) * 100), 99);
47163
+ const progress = (_e = this.params.uiPercentage) !== null && _e !== void 0 ? _e : getDeviceTransferProgress$1(read, read + readLen, totalLength);
47100
47164
  const res = yield this.device.commands.typedCall('FilesystemFileRead', 'FilesystemFile', {
47101
47165
  file: {
47102
47166
  path: this.params.path,
@@ -47169,6 +47233,18 @@ function getConfirmedProgress(processedByte, totalSize, written, dataLength) {
47169
47233
  }
47170
47234
  return 100;
47171
47235
  }
47236
+ function getDeviceTransferProgress(bytesBeforeChunk, bytesAfterChunk, totalBytes) {
47237
+ if (!Number.isFinite(totalBytes) || totalBytes <= 0) {
47238
+ return 100;
47239
+ }
47240
+ if (bytesBeforeChunk <= 0 && bytesAfterChunk < totalBytes) {
47241
+ return 0;
47242
+ }
47243
+ if (bytesAfterChunk >= totalBytes) {
47244
+ return 100;
47245
+ }
47246
+ return Math.min(Math.max(Math.ceil((bytesAfterChunk / totalBytes) * 100), 1), 99);
47247
+ }
47172
47248
  class FileWrite extends BaseMethod {
47173
47249
  init() {
47174
47250
  var _a, _b;
@@ -47218,7 +47294,7 @@ class FileWrite extends BaseMethod {
47218
47294
  const chunk = data.slice(written, chunkEnd);
47219
47295
  const offset = startOffset + written;
47220
47296
  const isFirstChunk = chunkIndex === 0;
47221
- const progress = (_e = this.params.uiPercentage) !== null && _e !== void 0 ? _e : Math.min(Math.ceil(((written + chunk.byteLength) / dataLength) * 100), 99);
47297
+ const progress = (_e = this.params.uiPercentage) !== null && _e !== void 0 ? _e : getDeviceTransferProgress(offset, offset + chunk.byteLength, totalSize);
47222
47298
  const res = yield this.device.commands.typedCall('FilesystemFileWrite', 'FilesystemFile', {
47223
47299
  file: {
47224
47300
  path: this.params.path,
@@ -54920,7 +54996,7 @@ class NostrSignEvent extends BaseMethod {
54920
54996
  const addressN = validatePath(payload.path, 5);
54921
54997
  this.params = {
54922
54998
  address_n: addressN,
54923
- event: bytesToHex(Buffer.from(JSON.stringify(payload.event, null, 0), 'utf-8')),
54999
+ event: bytesToHex$1(Buffer.from(JSON.stringify(payload.event, null, 0), 'utf-8')),
54924
55000
  };
54925
55001
  }
54926
55002
  getVersionRange() {
@@ -55102,8 +55178,8 @@ class LnurlAuth1 extends BaseMethod {
55102
55178
  { name: 'k1', type: 'string', required: true },
55103
55179
  ]);
55104
55180
  this.params = {
55105
- domain: bytesToHex(Buffer.from(payload.domain, 'utf-8')),
55106
- data: bytesToHex(Buffer.from(payload.k1, 'hex')),
55181
+ domain: bytesToHex$1(Buffer.from(payload.domain, 'utf-8')),
55182
+ data: bytesToHex$1(Buffer.from(payload.k1, 'hex')),
55107
55183
  };
55108
55184
  }
55109
55185
  getVersionRange() {
@@ -55762,11 +55838,7 @@ class TonSignData extends BaseMethod {
55762
55838
  };
55763
55839
  }
55764
55840
  getVersionRange() {
55765
- return {
55766
- pro2: {
55767
- min: '0.0.0',
55768
- },
55769
- };
55841
+ return {};
55770
55842
  }
55771
55843
  run() {
55772
55844
  return __awaiter(this, void 0, void 0, function* () {
@@ -56574,20 +56646,15 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
56574
56646
  firmwareUpdateV3: FirmwareUpdateV3,
56575
56647
  firmwareUpdateV4: FirmwareUpdateV4,
56576
56648
  promptWebDeviceAccess: PromptWebDeviceAccess,
56577
- getProtoVersion: GetProtoVersion,
56649
+ protocolInfoRequest: ProtocolInfoRequest,
56578
56650
  ping: Ping,
56579
56651
  deviceReboot: DeviceReboot,
56580
- deviceGetDeviceInfo: DeviceGetDeviceInfo,
56581
- deviceGetOnboardingStatus: DeviceGetOnboardingStatus,
56652
+ deviceInfoGet: DeviceInfoGet,
56582
56653
  deviceFirmwareUpdate: DeviceFirmwareUpdate,
56583
56654
  deviceGetFirmwareUpdateStatus: DeviceGetFirmwareUpdateStatus,
56584
- devReboot: DevReboot,
56585
- devGetDeviceInfo: DeviceGetDeviceInfo,
56586
- devFirmwareUpdate: DeviceFirmwareUpdate,
56587
- devGetFirmwareUpdateStatus: DeviceGetFirmwareUpdateStatus,
56588
- factoryDeviceInfoSettings: FactoryDeviceInfoSettings,
56589
- factoryGetDeviceInfo: FactoryGetDeviceInfo,
56590
- filesystemFixPermission: FilesystemFixPermission,
56655
+ deviceFactoryInfoSet: DeviceFactoryInfoSet,
56656
+ deviceFactoryInfoGet: DeviceFactoryInfoGet,
56657
+ filesystemPermissionFix: FilesystemPermissionFix,
56591
56658
  filesystemFormat: FilesystemFormat,
56592
56659
  filesystemDiskControl: FilesystemDiskControl,
56593
56660
  fileRead: FileRead,
@@ -56992,6 +57059,7 @@ const parseInitOptions = (method) => ({
56992
57059
  deviceId: method === null || method === void 0 ? void 0 : method.payload.deviceId,
56993
57060
  deriveCardano: method && hasDeriveCardano(method),
56994
57061
  connectProtocol: method === null || method === void 0 ? void 0 : method.payload.connectProtocol,
57062
+ protocolV2DeviceInfoTimeoutMs: method === null || method === void 0 ? void 0 : method.payload.protocolV2DeviceInfoTimeoutMs,
56995
57063
  });
56996
57064
  let _core;
56997
57065
  let _deviceList;
@@ -57081,8 +57149,13 @@ const callAPI = (context, message) => __awaiter(void 0, void 0, void 0, function
57081
57149
  return onCallDevice(context, message, method);
57082
57150
  });
57083
57151
  const handlePreWarmSignal = (context, message, method) => __awaiter(void 0, void 0, void 0, function* () {
57084
- if (!method.connectId) {
57152
+ const createAckResponse = () => {
57153
+ completeMethodRequestContext(method);
57154
+ method.dispose();
57085
57155
  return createResponseMessage(method.responseID, true, true);
57156
+ };
57157
+ if (!method.connectId) {
57158
+ return createAckResponse();
57086
57159
  }
57087
57160
  const key = method.getPreWarmKey();
57088
57161
  const inflight = preWarmInflight.get(key);
@@ -57092,11 +57165,11 @@ const handlePreWarmSignal = (context, message, method) => __awaiter(void 0, void
57092
57165
  }
57093
57166
  catch (_b) {
57094
57167
  }
57095
- return createResponseMessage(method.responseID, true, true);
57168
+ return createAckResponse();
57096
57169
  }
57097
57170
  const doneAt = preWarmDoneAt.get(key);
57098
57171
  if (typeof doneAt === 'number' && Date.now() - doneAt <= method.preWarmTtl) {
57099
- return createResponseMessage(method.responseID, true, true);
57172
+ return createAckResponse();
57100
57173
  }
57101
57174
  const run = onCallDevice(context, message, method);
57102
57175
  preWarmInflight.set(key, run);
@@ -57405,6 +57478,13 @@ function initDevice(method) {
57405
57478
  }
57406
57479
  if (method.connectId) {
57407
57480
  device = _deviceList.getDevice(method.connectId);
57481
+ if (!device && method.name === 'firmwareUpdateV4' && allDevices.length === 1) {
57482
+ const [singleDevice] = allDevices;
57483
+ if (singleDevice.isBootloader()) {
57484
+ Log.debug('firmwareUpdateV4 uses the only bootloader device when connectId changed after reboot');
57485
+ device = singleDevice;
57486
+ }
57487
+ }
57408
57488
  }
57409
57489
  else if (allDevices.length === 1) {
57410
57490
  [device] = allDevices;
@@ -57933,14 +58013,12 @@ const initTransport = (Transport, plugin) => {
57933
58013
  TransportManager.setTransport(Transport, plugin);
57934
58014
  };
57935
58015
  const init = (settings, Transport, plugin) => __awaiter(void 0, void 0, void 0, function* () {
57936
- var _r;
57937
58016
  try {
57938
58017
  try {
57939
58018
  yield DataManager.load(settings);
57940
- setProtocolV2DeviceInfoMock((_r = settings.protocolV2DeviceInfoMockEnabled) !== null && _r !== void 0 ? _r : false);
57941
58019
  initTransport(Transport, plugin);
57942
58020
  }
57943
- catch (_s) {
58021
+ catch (_r) {
57944
58022
  Log.error('DataManager.load error');
57945
58023
  }
57946
58024
  enableLog(DataManager.getSettings('debug'));