@onekeyfe/hd-core 1.2.0-alpha.34 → 1.2.0-alpha.35

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 (65) hide show
  1. package/__tests__/DeviceCommands.test.ts +84 -0
  2. package/__tests__/device-settings.test.ts +3 -0
  3. package/__tests__/device-wallet-session-store.test.ts +80 -7
  4. package/__tests__/evmSignTransaction.test.ts +69 -0
  5. package/__tests__/get-device-state.test.ts +78 -30
  6. package/__tests__/open-wallet-session.test.ts +186 -51
  7. package/__tests__/protocol-v2.test.ts +490 -112
  8. package/dist/api/FirmwareUpdateV4.d.ts +1 -0
  9. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  10. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  11. package/dist/api/OpenWalletSession.d.ts.map +1 -1
  12. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  13. package/dist/api/evm/protocol.d.ts +3 -0
  14. package/dist/api/evm/protocol.d.ts.map +1 -0
  15. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +1 -1
  16. package/dist/device/Device.d.ts +3 -2
  17. package/dist/device/Device.d.ts.map +1 -1
  18. package/dist/device/DeviceCommands.d.ts.map +1 -1
  19. package/dist/device/DeviceWalletSessionStore.d.ts +0 -1
  20. package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -1
  21. package/dist/index.d.ts +8 -6
  22. package/dist/index.js +606 -641
  23. package/dist/protocols/protocol-v2/features.d.ts +17 -6
  24. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  25. package/dist/protocols/protocol-v2/index.d.ts +2 -2
  26. package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
  27. package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts +1 -0
  28. package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -1
  29. package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -1
  30. package/dist/protocols/protocol-v2/walletSession.d.ts +1 -0
  31. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  32. package/dist/types/api/openWalletSession.d.ts +1 -1
  33. package/dist/types/api/openWalletSession.d.ts.map +1 -1
  34. package/dist/types/api/protocolV2.d.ts +2 -2
  35. package/dist/types/api/protocolV2.d.ts.map +1 -1
  36. package/dist/types/device.d.ts +2 -1
  37. package/dist/types/device.d.ts.map +1 -1
  38. package/dist/utils/patch.d.ts +1 -1
  39. package/dist/utils/patch.d.ts.map +1 -1
  40. package/package.json +4 -4
  41. package/src/api/FirmwareUpdateV4.ts +26 -8
  42. package/src/api/GetPassphraseState.ts +11 -0
  43. package/src/api/OpenWalletSession.ts +15 -7
  44. package/src/api/evm/EVMGetAddress.ts +2 -2
  45. package/src/api/evm/EVMGetPublicKey.ts +2 -2
  46. package/src/api/evm/EVMSignMessage.ts +2 -2
  47. package/src/api/evm/EVMSignTransaction.ts +2 -2
  48. package/src/api/evm/EVMSignTypedData.ts +35 -45
  49. package/src/api/evm/EVMVerifyMessage.ts +2 -2
  50. package/src/api/evm/protocol.ts +6 -0
  51. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +2 -2
  52. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +1 -1
  53. package/src/data/messages/messages-protocol-v2.json +393 -485
  54. package/src/device/Device.ts +63 -37
  55. package/src/device/DeviceCommands.ts +12 -2
  56. package/src/device/DeviceWalletSessionStore.ts +0 -14
  57. package/src/deviceProfile/buildDeviceFeatures.ts +1 -1
  58. package/src/protocols/protocol-v2/features.ts +58 -16
  59. package/src/protocols/protocol-v2/index.ts +5 -0
  60. package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +8 -3
  61. package/src/protocols/protocol-v2/unlockRetry.ts +18 -7
  62. package/src/protocols/protocol-v2/walletSession.ts +35 -35
  63. package/src/types/api/openWalletSession.ts +1 -1
  64. package/src/types/api/protocolV2.ts +2 -2
  65. package/src/types/device.ts +2 -0
package/dist/index.js CHANGED
@@ -25880,8 +25880,6 @@ var nested = {
25880
25880
  MessageType_ResetDevice: 14,
25881
25881
  MessageType_SetBusy: 16,
25882
25882
  MessageType_Features: 17,
25883
- MessageType_PinMatrixRequest: 18,
25884
- MessageType_PinMatrixAck: 19,
25885
25883
  MessageType_Cancel: 20,
25886
25884
  MessageType_LockDevice: 24,
25887
25885
  MessageType_ApplySettings: 25,
@@ -25943,20 +25941,6 @@ var nested = {
25943
25941
  MessageType_CosiSignature: 74,
25944
25942
  MessageType_BatchGetPublickeys: 10016,
25945
25943
  MessageType_EcdsaPublicKeys: 10017,
25946
- MessageType_DebugLinkDecision: 100,
25947
- MessageType_DebugLinkGetState: 101,
25948
- MessageType_DebugLinkState: 102,
25949
- MessageType_DebugLinkStop: 103,
25950
- MessageType_DebugLinkLog: 104,
25951
- MessageType_DebugLinkMemoryRead: 110,
25952
- MessageType_DebugLinkMemory: 111,
25953
- MessageType_DebugLinkMemoryWrite: 112,
25954
- MessageType_DebugLinkFlashErase: 113,
25955
- MessageType_DebugLinkLayout: 9001,
25956
- MessageType_DebugLinkReseedRandom: 9002,
25957
- MessageType_DebugLinkRecordScreen: 9003,
25958
- MessageType_DebugLinkEraseSdCard: 9005,
25959
- MessageType_DebugLinkWatchLayout: 9006,
25960
25944
  MessageType_EthereumGetPublicKey: 450,
25961
25945
  MessageType_EthereumPublicKey: 451,
25962
25946
  MessageType_EthereumGetAddress: 56,
@@ -26220,13 +26204,6 @@ var nested = {
26220
26204
  MessageType_TonSignProof: 11905,
26221
26205
  MessageType_TonSignedProof: 11906,
26222
26206
  MessageType_TonTxAck: 11907,
26223
- MessageType_ScdoGetAddress: 12001,
26224
- MessageType_ScdoAddress: 12002,
26225
- MessageType_ScdoSignTx: 12003,
26226
- MessageType_ScdoSignedTx: 12004,
26227
- MessageType_ScdoTxAck: 12005,
26228
- MessageType_ScdoSignMessage: 12006,
26229
- MessageType_ScdoSignedMessage: 12007,
26230
26207
  MessageType_AlephiumGetAddress: 12101,
26231
26208
  MessageType_AlephiumAddress: 12102,
26232
26209
  MessageType_AlephiumSignTx: 12103,
@@ -26249,11 +26226,6 @@ var nested = {
26249
26226
  MessageType_NeoAddress: 12302,
26250
26227
  MessageType_NeoSignTx: 12303,
26251
26228
  MessageType_NeoSignedTx: 12304,
26252
- MessageType_UiviewShowAddressRequest: 30200,
26253
- MessageType_UiviewShowPublicKeyRequest: 30201,
26254
- MessageType_UiviewConfirmTxRequest: 30202,
26255
- MessageType_UiviewConfirmSignMessageRequest: 30203,
26256
- MessageType_UiviewResponse: 30204,
26257
26229
  MessageType_DeviceFactoryInfoSet: 60000,
26258
26230
  MessageType_DeviceFactoryInfoGet: 60001,
26259
26231
  MessageType_DeviceFactoryInfo: 60002,
@@ -26274,19 +26246,11 @@ var nested = {
26274
26246
  MessageType_DeviceCertificateRead: 60422,
26275
26247
  MessageType_DeviceCertificateSignature: 60423,
26276
26248
  MessageType_DeviceCertificateSign: 60424,
26277
- MessageType_SetWallpaper: 60430,
26278
- MessageType_GetWallpaper: 60431,
26279
- MessageType_Wallpaper: 60432,
26249
+ MessageType_DeviceMiscUsbMscControl: 60440,
26280
26250
  MessageType_DeviceInfoGet: 60600,
26281
26251
  MessageType_DeviceInfo: 60601,
26282
26252
  MessageType_DeviceStatusGet: 60602,
26283
26253
  MessageType_DeviceStatus: 60603,
26284
- MessageType_DevGetOnboardingStatus: 60604,
26285
- MessageType_DevOnboardingStatus: 60605,
26286
- MessageType_DeviceSessionGet: 60606,
26287
- MessageType_DeviceSession: 60607,
26288
- MessageType_DeviceSessionAskPin: 60608,
26289
- MessageType_DeviceSessionAskPassphrase: 60609,
26290
26254
  MessageType_FilesystemPermissionFix: 60800,
26291
26255
  MessageType_FilesystemPathInfo: 60801,
26292
26256
  MessageType_FilesystemPathInfoQuery: 60802,
@@ -26302,7 +26266,13 @@ var nested = {
26302
26266
  MessageType_DeviceFirmwareUpdateRequest: 61000,
26303
26267
  MessageType_DeviceFirmwareUpdateStatusGet: 61001,
26304
26268
  MessageType_DeviceFirmwareUpdateStatus: 61002,
26305
- MessageType_PortfolioUpdate: 61200
26269
+ MessageType_DeviceSessionGet: 61200,
26270
+ MessageType_DeviceSession: 61201,
26271
+ MessageType_DeviceSessionAskPin: 61202,
26272
+ MessageType_DeviceSessionAskPassphrase: 61203,
26273
+ MessageType_PortfolioUpdate: 61400,
26274
+ MessageType_OnboardingStatusGet: 61600,
26275
+ MessageType_OnboardingStatus: 61601
26306
26276
  },
26307
26277
  reserved: [
26308
26278
  [
@@ -31779,30 +31749,6 @@ var nested = {
31779
31749
  }
31780
31750
  }
31781
31751
  },
31782
- InternalMyAddressRequest: {
31783
- fields: {
31784
- coin_type: {
31785
- rule: "required",
31786
- type: "uint32",
31787
- id: 1
31788
- },
31789
- chain_id: {
31790
- rule: "required",
31791
- type: "uint32",
31792
- id: 2
31793
- },
31794
- account_index: {
31795
- rule: "required",
31796
- type: "uint32",
31797
- id: 3
31798
- },
31799
- derive_type: {
31800
- rule: "required",
31801
- type: "uint32",
31802
- id: 4
31803
- }
31804
- }
31805
- },
31806
31752
  KaspaGetAddress: {
31807
31753
  fields: {
31808
31754
  address_n: {
@@ -32007,29 +31953,6 @@ var nested = {
32007
31953
  }
32008
31954
  }
32009
31955
  },
32010
- StartSession: {
32011
- fields: {
32012
- session_id: {
32013
- type: "bytes",
32014
- id: 1
32015
- },
32016
- _skip_passphrase: {
32017
- type: "bool",
32018
- id: 2,
32019
- options: {
32020
- deprecated: true
32021
- }
32022
- },
32023
- derive_cardano: {
32024
- type: "bool",
32025
- id: 3
32026
- }
32027
- }
32028
- },
32029
- EndSession: {
32030
- fields: {
32031
- }
32032
- },
32033
31956
  GetFeatures: {
32034
31957
  fields: {
32035
31958
  }
@@ -33166,49 +33089,6 @@ var nested = {
33166
33089
  }
33167
33090
  }
33168
33091
  },
33169
- WallpaperTarget: {
33170
- values: {
33171
- Home: 0,
33172
- Lock: 1
33173
- }
33174
- },
33175
- SetWallpaper: {
33176
- fields: {
33177
- target: {
33178
- rule: "required",
33179
- type: "WallpaperTarget",
33180
- id: 1
33181
- },
33182
- path: {
33183
- rule: "required",
33184
- type: "string",
33185
- id: 2
33186
- }
33187
- }
33188
- },
33189
- GetWallpaper: {
33190
- fields: {
33191
- target: {
33192
- rule: "required",
33193
- type: "WallpaperTarget",
33194
- id: 1
33195
- }
33196
- }
33197
- },
33198
- Wallpaper: {
33199
- fields: {
33200
- target: {
33201
- rule: "required",
33202
- type: "WallpaperTarget",
33203
- id: 1
33204
- },
33205
- path: {
33206
- rule: "required",
33207
- type: "string",
33208
- id: 2
33209
- }
33210
- }
33211
- },
33212
33092
  ResourceUpdate: {
33213
33093
  fields: {
33214
33094
  file_name: {
@@ -37379,162 +37259,6 @@ var nested = {
37379
37259
  }
37380
37260
  }
37381
37261
  },
37382
- ViewAmount: {
37383
- fields: {
37384
- is_unlimited: {
37385
- rule: "required",
37386
- type: "bool",
37387
- id: 1
37388
- },
37389
- num: {
37390
- rule: "required",
37391
- type: "string",
37392
- id: 2
37393
- }
37394
- }
37395
- },
37396
- ViewDetail: {
37397
- fields: {
37398
- key: {
37399
- rule: "required",
37400
- type: "uint32",
37401
- id: 1
37402
- },
37403
- value: {
37404
- rule: "required",
37405
- type: "string",
37406
- id: 2
37407
- },
37408
- is_overview: {
37409
- rule: "required",
37410
- type: "bool",
37411
- id: 3
37412
- },
37413
- has_icon: {
37414
- rule: "required",
37415
- type: "bool",
37416
- id: 4
37417
- }
37418
- }
37419
- },
37420
- ViewTipType: {
37421
- values: {
37422
- Default: 0,
37423
- Highlight: 1,
37424
- Recommend: 2,
37425
- Warning: 3,
37426
- Danger: 4
37427
- }
37428
- },
37429
- ViewTip: {
37430
- fields: {
37431
- type: {
37432
- rule: "required",
37433
- type: "ViewTipType",
37434
- id: 1
37435
- },
37436
- text: {
37437
- rule: "required",
37438
- type: "string",
37439
- id: 2
37440
- }
37441
- }
37442
- },
37443
- ViewRawData: {
37444
- fields: {
37445
- initial_data: {
37446
- rule: "required",
37447
- type: "string",
37448
- id: 1
37449
- },
37450
- placeholder: {
37451
- rule: "required",
37452
- type: "uint32",
37453
- id: 2
37454
- }
37455
- }
37456
- },
37457
- ViewSignLayout: {
37458
- values: {
37459
- LayoutDefault: 0,
37460
- LayoutSafeTxCreate: 1,
37461
- LayoutFinalConfirm: 2,
37462
- Layout7702: 3,
37463
- LayoutFlat: 4,
37464
- LayoutEthApprove: 5
37465
- }
37466
- },
37467
- ViewSignPage: {
37468
- fields: {
37469
- title: {
37470
- rule: "required",
37471
- type: "string",
37472
- id: 1
37473
- },
37474
- amount: {
37475
- type: "ViewAmount",
37476
- id: 2
37477
- },
37478
- general: {
37479
- rule: "repeated",
37480
- type: "ViewDetail",
37481
- id: 3
37482
- },
37483
- tip: {
37484
- type: "ViewTip",
37485
- id: 4
37486
- },
37487
- raw_data: {
37488
- type: "ViewRawData",
37489
- id: 5
37490
- },
37491
- slide_to_confirm: {
37492
- type: "bool",
37493
- id: 6,
37494
- options: {
37495
- "default": true
37496
- }
37497
- },
37498
- layout: {
37499
- type: "ViewSignLayout",
37500
- id: 7,
37501
- options: {
37502
- "default": "LayoutDefault"
37503
- }
37504
- }
37505
- }
37506
- },
37507
- ViewVerifyPage: {
37508
- fields: {
37509
- title: {
37510
- rule: "required",
37511
- type: "string",
37512
- id: 1
37513
- },
37514
- address: {
37515
- rule: "required",
37516
- type: "string",
37517
- id: 2
37518
- },
37519
- path: {
37520
- rule: "required",
37521
- type: "string",
37522
- id: 3
37523
- },
37524
- network: {
37525
- type: "string",
37526
- id: 4
37527
- },
37528
- derive_type: {
37529
- type: "string",
37530
- id: 5
37531
- },
37532
- value_key: {
37533
- type: "uint32",
37534
- id: 6
37535
- }
37536
- }
37537
- },
37538
37262
  WebAuthnListResidentCredentials: {
37539
37263
  fields: {
37540
37264
  }
@@ -37636,17 +37360,18 @@ var nested = {
37636
37360
  type: "uint32",
37637
37361
  id: 1
37638
37362
  },
37363
+ build_fingerprint: {
37364
+ rule: "required",
37365
+ type: "string",
37366
+ id: 2
37367
+ },
37639
37368
  supported_messages: {
37640
37369
  rule: "repeated",
37641
37370
  type: "uint32",
37642
- id: 2,
37371
+ id: 3,
37643
37372
  options: {
37644
37373
  packed: false
37645
37374
  }
37646
- },
37647
- protobuf_definition: {
37648
- type: "string",
37649
- id: 3
37650
37375
  }
37651
37376
  }
37652
37377
  },
@@ -37876,109 +37601,11 @@ var nested = {
37876
37601
  }
37877
37602
  }
37878
37603
  },
37879
- DeviceFirmwareTargetType: {
37880
- values: {
37881
- FW_MGMT_TARGET_INVALID: 0,
37882
- FW_MGMT_TARGET_CRATE: 1,
37883
- FW_MGMT_TARGET_ROMLOADER: 2,
37884
- FW_MGMT_TARGET_BOOTLOADER: 3,
37885
- FW_MGMT_TARGET_APPLICATION_P1: 4,
37886
- FW_MGMT_TARGET_APPLICATION_P2: 5,
37887
- FW_MGMT_TARGET_COPROCESSOR: 6,
37888
- FW_MGMT_TARGET_SE01: 7,
37889
- FW_MGMT_TARGET_SE02: 8,
37890
- FW_MGMT_TARGET_SE03: 9,
37891
- FW_MGMT_TARGET_SE04: 10
37892
- }
37893
- },
37894
- DeviceFirmwareUpdateTaskStatus: {
37895
- values: {
37896
- FW_MGMT_UPDATER_TASK_STATUS_PENDING: 0,
37897
- FW_MGMT_UPDATER_TASK_STATUS_IN_PROGRESS: 1,
37898
- FW_MGMT_UPDATER_TASK_STATUS_FINISHED: 2,
37899
- FW_MGMT_UPDATER_TASK_STATUS_FAILED_FILE_NOT_FOUND: 3,
37900
- FW_MGMT_UPDATER_TASK_STATUS_FAILED_FILE_READ: 4,
37901
- FW_MGMT_UPDATER_TASK_STATUS_FAILED_FILE_WRITE: 5,
37902
- FW_MGMT_UPDATER_TASK_STATUS_FAILED_VERIFY: 6,
37903
- FW_MGMT_UPDATER_TASK_STATUS_FAILED_INSTALL: 7,
37904
- FW_MGMT_UPDATER_TASK_STATUS_FAILED_ABORT: 8,
37905
- FW_MGMT_UPDATER_TASK_STATUS_FAILED_BUSY: 9,
37906
- FW_MGMT_UPDATER_TASK_STATUS_FAILED_ENTRY_OUT_OF_BOUNDS: 10
37907
- }
37908
- },
37909
- DeviceFirmwareTarget: {
37604
+ DeviceMiscUsbMscControl: {
37910
37605
  fields: {
37911
- target_id: {
37606
+ enable: {
37912
37607
  rule: "required",
37913
- type: "DeviceFirmwareTargetType",
37914
- id: 1
37915
- },
37916
- path: {
37917
- rule: "required",
37918
- type: "string",
37919
- id: 2
37920
- }
37921
- }
37922
- },
37923
- DeviceFirmwareUpdateRequest: {
37924
- fields: {
37925
- targets: {
37926
- rule: "repeated",
37927
- type: "DeviceFirmwareTarget",
37928
- id: 1
37929
- }
37930
- }
37931
- },
37932
- DeviceFirmwareUpdateRecord: {
37933
- fields: {
37934
- target_id: {
37935
- rule: "required",
37936
- type: "DeviceFirmwareTargetType",
37937
- id: 1
37938
- },
37939
- status: {
37940
- type: "DeviceFirmwareUpdateTaskStatus",
37941
- id: 10
37942
- },
37943
- payload_version: {
37944
- type: "uint32",
37945
- id: 20
37946
- },
37947
- path: {
37948
- type: "string",
37949
- id: 30
37950
- }
37951
- }
37952
- },
37953
- DeviceFirmwareUpdateRecordFields: {
37954
- fields: {
37955
- status: {
37956
37608
  type: "bool",
37957
- id: 10
37958
- },
37959
- payload_version: {
37960
- type: "bool",
37961
- id: 20
37962
- },
37963
- path: {
37964
- type: "bool",
37965
- id: 30
37966
- }
37967
- }
37968
- },
37969
- DeviceFirmwareUpdateStatusGet: {
37970
- fields: {
37971
- fields: {
37972
- type: "DeviceFirmwareUpdateRecordFields",
37973
- id: 1
37974
- }
37975
- }
37976
- },
37977
- DeviceFirmwareUpdateStatus: {
37978
- fields: {
37979
- records: {
37980
- rule: "repeated",
37981
- type: "DeviceFirmwareUpdateRecord",
37982
37609
  id: 1
37983
37610
  }
37984
37611
  }
@@ -38083,6 +37710,113 @@ var nested = {
38083
37710
  }
38084
37711
  }
38085
37712
  },
37713
+ DeviceFirmwareTargetType: {
37714
+ values: {
37715
+ FW_MGMT_TARGET_INVALID: 0,
37716
+ FW_MGMT_TARGET_CRATE: 1,
37717
+ FW_MGMT_TARGET_ROMLOADER: 2,
37718
+ FW_MGMT_TARGET_BOOTLOADER: 3,
37719
+ FW_MGMT_TARGET_APPLICATION_P1: 4,
37720
+ FW_MGMT_TARGET_APPLICATION_P2: 5,
37721
+ FW_MGMT_TARGET_COPROCESSOR: 6,
37722
+ FW_MGMT_TARGET_SE01: 7,
37723
+ FW_MGMT_TARGET_SE02: 8,
37724
+ FW_MGMT_TARGET_SE03: 9,
37725
+ FW_MGMT_TARGET_SE04: 10
37726
+ }
37727
+ },
37728
+ DeviceFirmwareUpdateTaskStatus: {
37729
+ values: {
37730
+ FW_MGMT_UPDATER_TASK_STATUS_PENDING: 0,
37731
+ FW_MGMT_UPDATER_TASK_STATUS_IN_PROGRESS: 1,
37732
+ FW_MGMT_UPDATER_TASK_STATUS_FINISHED: 2,
37733
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_FILE_NOT_FOUND: 3,
37734
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_FILE_READ: 4,
37735
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_FILE_WRITE: 5,
37736
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_VERIFY: 6,
37737
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_INSTALL: 7,
37738
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_ABORT: 8,
37739
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_BUSY: 9,
37740
+ FW_MGMT_UPDATER_TASK_STATUS_FAILED_ENTRY_OUT_OF_BOUNDS: 10
37741
+ }
37742
+ },
37743
+ DeviceFirmwareTarget: {
37744
+ fields: {
37745
+ target_id: {
37746
+ rule: "required",
37747
+ type: "DeviceFirmwareTargetType",
37748
+ id: 1
37749
+ },
37750
+ path: {
37751
+ rule: "required",
37752
+ type: "string",
37753
+ id: 2
37754
+ }
37755
+ }
37756
+ },
37757
+ DeviceFirmwareUpdateRequest: {
37758
+ fields: {
37759
+ targets: {
37760
+ rule: "repeated",
37761
+ type: "DeviceFirmwareTarget",
37762
+ id: 1
37763
+ }
37764
+ }
37765
+ },
37766
+ DeviceFirmwareUpdateRecord: {
37767
+ fields: {
37768
+ target_id: {
37769
+ rule: "required",
37770
+ type: "DeviceFirmwareTargetType",
37771
+ id: 1
37772
+ },
37773
+ status: {
37774
+ type: "DeviceFirmwareUpdateTaskStatus",
37775
+ id: 10
37776
+ },
37777
+ payload_version: {
37778
+ type: "uint32",
37779
+ id: 20
37780
+ },
37781
+ path: {
37782
+ type: "string",
37783
+ id: 30
37784
+ }
37785
+ }
37786
+ },
37787
+ DeviceFirmwareUpdateRecordFields: {
37788
+ fields: {
37789
+ status: {
37790
+ type: "bool",
37791
+ id: 10
37792
+ },
37793
+ payload_version: {
37794
+ type: "bool",
37795
+ id: 20
37796
+ },
37797
+ path: {
37798
+ type: "bool",
37799
+ id: 30
37800
+ }
37801
+ }
37802
+ },
37803
+ DeviceFirmwareUpdateStatusGet: {
37804
+ fields: {
37805
+ fields: {
37806
+ type: "DeviceFirmwareUpdateRecordFields",
37807
+ id: 1
37808
+ }
37809
+ }
37810
+ },
37811
+ DeviceFirmwareUpdateStatus: {
37812
+ fields: {
37813
+ records: {
37814
+ rule: "repeated",
37815
+ type: "DeviceFirmwareUpdateRecord",
37816
+ id: 1
37817
+ }
37818
+ }
37819
+ },
38086
37820
  DeviceType: {
38087
37821
  values: {
38088
37822
  CLASSIC1: 0,
@@ -38233,10 +37967,6 @@ var nested = {
38233
37967
  se4: {
38234
37968
  type: "bool",
38235
37969
  id: 430
38236
- },
38237
- status: {
38238
- type: "bool",
38239
- id: 10000
38240
37970
  }
38241
37971
  }
38242
37972
  },
@@ -38306,10 +38036,6 @@ var nested = {
38306
38036
  se4: {
38307
38037
  type: "DeviceSEInfo",
38308
38038
  id: 430
38309
- },
38310
- status: {
38311
- type: "DeviceStatus",
38312
- id: 10000
38313
38039
  }
38314
38040
  }
38315
38041
  },
@@ -38365,6 +38091,7 @@ var nested = {
38365
38091
  id: 1
38366
38092
  },
38367
38093
  on_device: {
38094
+ rule: "required",
38368
38095
  type: "bool",
38369
38096
  id: 2
38370
38097
  }
@@ -38411,89 +38138,6 @@ var nested = {
38411
38138
  fields: {
38412
38139
  }
38413
38140
  },
38414
- DevOnboardingStep: {
38415
- values: {
38416
- DEV_ONBOARDING_STEP_UNKNOWN: 0,
38417
- DEV_ONBOARDING_STEP_CHECKING: 1,
38418
- DEV_ONBOARDING_STEP_PERSONALIZATION: 2,
38419
- DEV_ONBOARDING_STEP_PIN: 3,
38420
- DEV_ONBOARDING_STEP_SETUP: 4,
38421
- DEV_ONBOARDING_STEP_DONE: 5
38422
- }
38423
- },
38424
- DevOnboardingPhase: {
38425
- values: {
38426
- DEV_ONBOARDING_PHASE_UNKNOWN: 0,
38427
- DEV_ONBOARDING_PHASE_SAFETY_CHECK: 1,
38428
- DEV_ONBOARDING_PHASE_PIN_SETUP: 2,
38429
- DEV_ONBOARDING_PHASE_FINGERPRINT_SETUP: 3,
38430
- DEV_ONBOARDING_PHASE_SETUP_CHOICE: 4,
38431
- DEV_ONBOARDING_PHASE_WALLET_CREATE_START: 5,
38432
- DEV_ONBOARDING_PHASE_RECOVERY_PHRASE_VIEW: 6,
38433
- DEV_ONBOARDING_PHASE_RECOVERY_PHRASE_CONFIRM: 7,
38434
- DEV_ONBOARDING_PHASE_RESTORE_METHOD_CHOICE: 8,
38435
- DEV_ONBOARDING_PHASE_RECOVERY_PHRASE_RESTORE: 9,
38436
- DEV_ONBOARDING_PHASE_SEEDCARD_RESTORE: 10,
38437
- DEV_ONBOARDING_PHASE_WALLET_READY: 11,
38438
- DEV_ONBOARDING_PHASE_SEEDCARD_BACKUP_PROMPT: 12,
38439
- DEV_ONBOARDING_PHASE_SEEDCARD_BACKUP: 13
38440
- }
38441
- },
38442
- DevOnboardingSetupKind: {
38443
- values: {
38444
- DEV_ONBOARDING_SETUP_KIND_UNKNOWN: 0,
38445
- DEV_ONBOARDING_SETUP_KIND_CHOICE: 1,
38446
- DEV_ONBOARDING_SETUP_KIND_CREATE: 2,
38447
- DEV_ONBOARDING_SETUP_KIND_RESTORE: 3
38448
- }
38449
- },
38450
- DevOnboardingSetupMethod: {
38451
- values: {
38452
- DEV_ONBOARDING_SETUP_METHOD_UNKNOWN: 0,
38453
- DEV_ONBOARDING_SETUP_METHOD_RECOVERY_PHRASE: 1,
38454
- DEV_ONBOARDING_SETUP_METHOD_SEEDCARD: 2
38455
- }
38456
- },
38457
- DevOnboardingSetupStatus: {
38458
- fields: {
38459
- kind: {
38460
- type: "DevOnboardingSetupKind",
38461
- id: 1
38462
- },
38463
- method: {
38464
- type: "DevOnboardingSetupMethod",
38465
- id: 2
38466
- }
38467
- }
38468
- },
38469
- DevGetOnboardingStatus: {
38470
- fields: {
38471
- }
38472
- },
38473
- DevOnboardingStatus: {
38474
- fields: {
38475
- step: {
38476
- type: "DevOnboardingStep",
38477
- id: 1
38478
- },
38479
- phase: {
38480
- type: "DevOnboardingPhase",
38481
- id: 2
38482
- },
38483
- setup: {
38484
- type: "DevOnboardingSetupStatus",
38485
- id: 3
38486
- },
38487
- pin_set: {
38488
- type: "bool",
38489
- id: 4
38490
- },
38491
- wallet_initialized: {
38492
- type: "bool",
38493
- id: 5
38494
- }
38495
- }
38496
- },
38497
38141
  FilesystemPermissionFix: {
38498
38142
  fields: {
38499
38143
  }
@@ -38721,10 +38365,273 @@ var nested = {
38721
38365
  }
38722
38366
  }
38723
38367
  },
38368
+ InternalMyAddressRequest: {
38369
+ fields: {
38370
+ coin_type: {
38371
+ rule: "required",
38372
+ type: "uint32",
38373
+ id: 1
38374
+ },
38375
+ chain_id: {
38376
+ rule: "required",
38377
+ type: "uint32",
38378
+ id: 2
38379
+ },
38380
+ account_index: {
38381
+ rule: "required",
38382
+ type: "uint32",
38383
+ id: 3
38384
+ },
38385
+ derive_type: {
38386
+ rule: "required",
38387
+ type: "uint32",
38388
+ id: 4
38389
+ }
38390
+ }
38391
+ },
38392
+ OnboardingStep: {
38393
+ values: {
38394
+ ONBOARDING_STEP_UNKNOWN: 0,
38395
+ ONBOARDING_STEP_CHECKING: 1,
38396
+ ONBOARDING_STEP_PERSONALIZATION: 2,
38397
+ ONBOARDING_STEP_PIN: 3,
38398
+ ONBOARDING_STEP_SETUP: 4,
38399
+ ONBOARDING_STEP_DONE: 5
38400
+ }
38401
+ },
38402
+ OnboardingPhase: {
38403
+ values: {
38404
+ ONBOARDING_PHASE_UNKNOWN: 0,
38405
+ ONBOARDING_PHASE_SAFETY_CHECK: 1,
38406
+ ONBOARDING_PHASE_PIN_SETUP: 2,
38407
+ ONBOARDING_PHASE_FINGERPRINT_SETUP: 3,
38408
+ ONBOARDING_PHASE_SETUP_CHOICE: 4,
38409
+ ONBOARDING_PHASE_WALLET_CREATE_START: 5,
38410
+ ONBOARDING_PHASE_RECOVERY_PHRASE_VIEW: 6,
38411
+ ONBOARDING_PHASE_RECOVERY_PHRASE_CONFIRM: 7,
38412
+ ONBOARDING_PHASE_RESTORE_METHOD_CHOICE: 8,
38413
+ ONBOARDING_PHASE_RECOVERY_PHRASE_RESTORE: 9,
38414
+ ONBOARDING_PHASE_SEEDCARD_RESTORE: 10,
38415
+ ONBOARDING_PHASE_WALLET_READY: 11,
38416
+ ONBOARDING_PHASE_SEEDCARD_BACKUP_PROMPT: 12,
38417
+ ONBOARDING_PHASE_SEEDCARD_BACKUP: 13
38418
+ }
38419
+ },
38420
+ OnboardingSetupKind: {
38421
+ values: {
38422
+ ONBOARDING_SETUP_KIND_UNKNOWN: 0,
38423
+ ONBOARDING_SETUP_KIND_CHOICE: 1,
38424
+ ONBOARDING_SETUP_KIND_CREATE: 2,
38425
+ ONBOARDING_SETUP_KIND_RESTORE: 3
38426
+ }
38427
+ },
38428
+ OnboardingSetupMethod: {
38429
+ values: {
38430
+ ONBOARDING_SETUP_METHOD_UNKNOWN: 0,
38431
+ ONBOARDING_SETUP_METHOD_RECOVERY_PHRASE: 1,
38432
+ ONBOARDING_SETUP_METHOD_SEEDCARD: 2
38433
+ }
38434
+ },
38435
+ OnboardingSetupStatus: {
38436
+ fields: {
38437
+ kind: {
38438
+ type: "OnboardingSetupKind",
38439
+ id: 1
38440
+ },
38441
+ method: {
38442
+ type: "OnboardingSetupMethod",
38443
+ id: 2
38444
+ }
38445
+ }
38446
+ },
38447
+ OnboardingStatusGet: {
38448
+ fields: {
38449
+ }
38450
+ },
38451
+ OnboardingStatus: {
38452
+ fields: {
38453
+ step: {
38454
+ type: "OnboardingStep",
38455
+ id: 1
38456
+ },
38457
+ phase: {
38458
+ type: "OnboardingPhase",
38459
+ id: 2
38460
+ },
38461
+ setup: {
38462
+ type: "OnboardingSetupStatus",
38463
+ id: 3
38464
+ },
38465
+ pin_set: {
38466
+ type: "bool",
38467
+ id: 4
38468
+ },
38469
+ wallet_initialized: {
38470
+ type: "bool",
38471
+ id: 5
38472
+ }
38473
+ }
38474
+ },
38724
38475
  PortfolioUpdate: {
38725
38476
  fields: {
38726
38477
  }
38727
38478
  },
38479
+ ViewAmount: {
38480
+ fields: {
38481
+ is_unlimited: {
38482
+ rule: "required",
38483
+ type: "bool",
38484
+ id: 1
38485
+ },
38486
+ num: {
38487
+ rule: "required",
38488
+ type: "string",
38489
+ id: 2
38490
+ }
38491
+ }
38492
+ },
38493
+ ViewDetail: {
38494
+ fields: {
38495
+ key: {
38496
+ rule: "required",
38497
+ type: "uint32",
38498
+ id: 1
38499
+ },
38500
+ value: {
38501
+ rule: "required",
38502
+ type: "string",
38503
+ id: 2
38504
+ },
38505
+ is_overview: {
38506
+ rule: "required",
38507
+ type: "bool",
38508
+ id: 3
38509
+ },
38510
+ has_icon: {
38511
+ rule: "required",
38512
+ type: "bool",
38513
+ id: 4
38514
+ }
38515
+ }
38516
+ },
38517
+ ViewTipType: {
38518
+ values: {
38519
+ Default: 0,
38520
+ Highlight: 1,
38521
+ Recommend: 2,
38522
+ Warning: 3,
38523
+ Danger: 4
38524
+ }
38525
+ },
38526
+ ViewTip: {
38527
+ fields: {
38528
+ type: {
38529
+ rule: "required",
38530
+ type: "ViewTipType",
38531
+ id: 1
38532
+ },
38533
+ text: {
38534
+ rule: "required",
38535
+ type: "string",
38536
+ id: 2
38537
+ }
38538
+ }
38539
+ },
38540
+ ViewRawData: {
38541
+ fields: {
38542
+ initial_data: {
38543
+ rule: "required",
38544
+ type: "string",
38545
+ id: 1
38546
+ },
38547
+ placeholder: {
38548
+ rule: "required",
38549
+ type: "uint32",
38550
+ id: 2
38551
+ }
38552
+ }
38553
+ },
38554
+ ViewSignLayout: {
38555
+ values: {
38556
+ LayoutDefault: 0,
38557
+ LayoutSafeTxCreate: 1,
38558
+ LayoutFinalConfirm: 2,
38559
+ Layout7702: 3,
38560
+ LayoutFlat: 4,
38561
+ LayoutEthApprove: 5
38562
+ }
38563
+ },
38564
+ ViewSignPage: {
38565
+ fields: {
38566
+ title: {
38567
+ rule: "required",
38568
+ type: "string",
38569
+ id: 1
38570
+ },
38571
+ amount: {
38572
+ type: "ViewAmount",
38573
+ id: 2
38574
+ },
38575
+ general: {
38576
+ rule: "repeated",
38577
+ type: "ViewDetail",
38578
+ id: 3
38579
+ },
38580
+ tip: {
38581
+ type: "ViewTip",
38582
+ id: 4
38583
+ },
38584
+ raw_data: {
38585
+ type: "ViewRawData",
38586
+ id: 5
38587
+ },
38588
+ slide_to_confirm: {
38589
+ type: "bool",
38590
+ id: 6,
38591
+ options: {
38592
+ "default": true
38593
+ }
38594
+ },
38595
+ layout: {
38596
+ type: "ViewSignLayout",
38597
+ id: 7,
38598
+ options: {
38599
+ "default": "LayoutDefault"
38600
+ }
38601
+ }
38602
+ }
38603
+ },
38604
+ ViewVerifyPage: {
38605
+ fields: {
38606
+ title: {
38607
+ rule: "required",
38608
+ type: "string",
38609
+ id: 1
38610
+ },
38611
+ address: {
38612
+ rule: "required",
38613
+ type: "string",
38614
+ id: 2
38615
+ },
38616
+ path: {
38617
+ rule: "required",
38618
+ type: "string",
38619
+ id: 3
38620
+ },
38621
+ network: {
38622
+ type: "string",
38623
+ id: 4
38624
+ },
38625
+ derive_type: {
38626
+ type: "string",
38627
+ id: 5
38628
+ },
38629
+ value_key: {
38630
+ type: "uint32",
38631
+ id: 6
38632
+ }
38633
+ }
38634
+ },
38728
38635
  google: {
38729
38636
  nested: {
38730
38637
  protobuf: {
@@ -40144,14 +40051,11 @@ function assertCompleteDeviceSession(message) {
40144
40051
  }
40145
40052
  }
40146
40053
 
40147
- function isDeviceLockedError(error) {
40148
- return (typeof error === 'object' &&
40149
- error !== null &&
40150
- 'errorCode' in error &&
40151
- error.errorCode === hdShared.HardwareErrorCode.DeviceLocked);
40152
- }
40153
-
40154
40054
  const HOST_PASSPHRASE_MAX_BYTES = 50;
40055
+ const isWalletSessionInvalidError = (error) => typeof error === 'object' &&
40056
+ error !== null &&
40057
+ 'errorCode' in error &&
40058
+ error.errorCode === hdShared.HardwareErrorCode.WalletSessionInvalid;
40155
40059
  const utf8ByteLength = (value) => {
40156
40060
  var _a;
40157
40061
  let length = 0;
@@ -40187,30 +40091,9 @@ const negotiateEventlessWalletSession = (device) => __awaiter(void 0, void 0, vo
40187
40091
  eventless_wallet_session: true,
40188
40092
  });
40189
40093
  });
40190
- const getDeviceSession = (device, request) => __awaiter(void 0, void 0, void 0, function* () {
40191
- try {
40192
- return yield device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request);
40193
- }
40194
- catch (error) {
40195
- if (!isDeviceLockedError(error) || !request.session_id) {
40196
- throw error;
40197
- }
40198
- yield device.unlockDevice(hdTransport.DeviceSessionPinType.Main);
40199
- return device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request);
40200
- }
40201
- });
40202
- const askDevicePassphrase = (device, passphrase) => __awaiter(void 0, void 0, void 0, function* () {
40203
- const request = () => device.commands.typedCall('DeviceSessionAskPassphrase', 'Success', passphrase ? { passphrase, on_device: false } : { on_device: true });
40204
- try {
40205
- yield request();
40206
- }
40207
- catch (error) {
40208
- if (!isDeviceLockedError(error)) {
40209
- throw error;
40210
- }
40211
- yield device.unlockDevice(hdTransport.DeviceSessionPinType.Main);
40212
- yield request();
40213
- }
40094
+ const getDeviceSession = (device, request) => __awaiter(void 0, void 0, void 0, function* () { return device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request); });
40095
+ const askDevicePassphrase = (device, requestPayload) => __awaiter(void 0, void 0, void 0, function* () {
40096
+ yield device.commands.typedCall('DeviceSessionAskPassphrase', 'Success', requestPayload);
40214
40097
  yield refreshProtocolV2DeviceStatus(device);
40215
40098
  });
40216
40099
  const selectDeviceSession = (device, expectedPassphraseState) => __awaiter(void 0, void 0, void 0, function* () {
@@ -40244,17 +40127,21 @@ const selectDeviceSession = (device, expectedPassphraseState) => __awaiter(void
40244
40127
  return getDeviceSession(device, {});
40245
40128
  }
40246
40129
  if (hasHostPassphrase) {
40247
- yield askDevicePassphrase(device, hostPassphrase);
40130
+ yield askDevicePassphrase(device, {
40131
+ passphrase: hostPassphrase,
40132
+ on_device: false,
40133
+ });
40248
40134
  return getDeviceSession(device, {});
40249
40135
  }
40250
40136
  device.emit(DEVICE.PASSPHRASE_ON_DEVICE, device, metadata);
40251
- yield askDevicePassphrase(device);
40137
+ yield askDevicePassphrase(device, { on_device: true });
40252
40138
  return getDeviceSession(device, {});
40253
40139
  });
40254
40140
  function getProtocolV2WalletSession(device, options) {
40255
40141
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
40256
40142
  return __awaiter(this, void 0, void 0, function* () {
40257
- if (options === null || options === void 0 ? void 0 : options.initSession) {
40143
+ const forceWalletSelection = (options === null || options === void 0 ? void 0 : options.forceWalletSelection) === true || (options === null || options === void 0 ? void 0 : options.initSession) === true;
40144
+ if (forceWalletSelection) {
40258
40145
  if (options.onlyMainPin) {
40259
40146
  (_a = device.clearStandardInternalState) === null || _a === void 0 ? void 0 : _a.call(device);
40260
40147
  }
@@ -40292,7 +40179,10 @@ function getProtocolV2WalletSession(device, options) {
40292
40179
  }
40293
40180
  catch (error) {
40294
40181
  (_e = device.clearStandardInternalState) === null || _e === void 0 ? void 0 : _e.call(device);
40295
- throw error;
40182
+ if (!isWalletSessionInvalidError(error)) {
40183
+ throw error;
40184
+ }
40185
+ resumed = false;
40296
40186
  }
40297
40187
  }
40298
40188
  if (!response) {
@@ -40307,7 +40197,10 @@ function getProtocolV2WalletSession(device, options) {
40307
40197
  }
40308
40198
  catch (error) {
40309
40199
  device.clearInternalState();
40310
- throw error;
40200
+ if ((options === null || options === void 0 ? void 0 : options.resumeOnly) || !isWalletSessionInvalidError(error)) {
40201
+ throw error;
40202
+ }
40203
+ resumed = false;
40311
40204
  }
40312
40205
  }
40313
40206
  if (!response) {
@@ -40332,6 +40225,10 @@ function getProtocolV2WalletSession(device, options) {
40332
40225
  }
40333
40226
  if (expectedPassphraseState && expectedPassphraseState !== message.btc_test_address) {
40334
40227
  resumed = false;
40228
+ if (options === null || options === void 0 ? void 0 : options.resumeOnly) {
40229
+ device.clearInternalState();
40230
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WalletSessionInvalid);
40231
+ }
40335
40232
  if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
40336
40233
  (_g = device.clearStandardInternalState) === null || _g === void 0 ? void 0 : _g.call(device);
40337
40234
  yield device.unlockDevice(hdTransport.DeviceSessionPinType.Main);
@@ -40369,7 +40266,7 @@ function getProtocolV2WalletSession(device, options) {
40369
40266
  message.btc_test_address,
40370
40267
  device.getCurrentDeviceId(),
40371
40268
  message.session_id,
40372
- (options === null || options === void 0 ? void 0 : options.initSession) ? null : cachedSessionId !== null && cachedSessionId !== void 0 ? cachedSessionId : null,
40269
+ forceWalletSelection ? null : cachedSessionId !== null && cachedSessionId !== void 0 ? cachedSessionId : null,
40373
40270
  ];
40374
40271
  if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
40375
40272
  device.updateInternalState(...internalStateArgs, 'standard');
@@ -41944,18 +41841,18 @@ class DeviceCommands {
41944
41841
  });
41945
41842
  }
41946
41843
  call(type, msg, options) {
41947
- var _a;
41844
+ var _a, _b;
41948
41845
  return __awaiter(this, void 0, void 0, function* () {
41949
41846
  const shouldReduceDebug = shouldReduceDebugForCall(type);
41950
41847
  if (!shouldReduceDebug) {
41951
- Log$f.debug('[DeviceCommands] [call] Sending', type);
41848
+ Log$f.debug('[DeviceCommands] [call] Sending', type, hdTransport.getSafeTransportLogPayload(msg !== null && msg !== void 0 ? msg : {}, type));
41952
41849
  }
41953
41850
  try {
41954
41851
  const promise = this.transport.call(this.mainId, type, msg !== null && msg !== void 0 ? msg : {}, options);
41955
41852
  this.callPromise = promise;
41956
41853
  const res = yield promise;
41957
41854
  if (!shouldReduceDebug) {
41958
- LogCore.debug('[DeviceCommands] [call] Received', res.type);
41855
+ LogCore.debug('[DeviceCommands] [call] Received', res.type, hdTransport.getSafeTransportLogPayload(res.message, res.type));
41959
41856
  }
41960
41857
  return res;
41961
41858
  }
@@ -41963,6 +41860,7 @@ class DeviceCommands {
41963
41860
  LogCore.debug('[DeviceCommands] [call] Received error', {
41964
41861
  request: type,
41965
41862
  errorCode: error === null || error === void 0 ? void 0 : error.errorCode,
41863
+ response: hdTransport.getSafeTransportLogPayload((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data, type),
41966
41864
  });
41967
41865
  if (error.errorCode === hdShared.HardwareErrorCode.BleDeviceBondError) {
41968
41866
  return {
@@ -41972,7 +41870,7 @@ class DeviceCommands {
41972
41870
  },
41973
41871
  };
41974
41872
  }
41975
- const responseData = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data;
41873
+ const responseData = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data;
41976
41874
  let responseError = responseData === null || responseData === void 0 ? void 0 : responseData.error;
41977
41875
  if (!responseError && responseData && typeof responseData === 'string') {
41978
41876
  try {
@@ -42943,7 +42841,6 @@ class DeviceWalletSessionStore {
42943
42841
  return (_a = this.walletSessions.get(deviceKey)) === null || _a === void 0 ? void 0 : _a.get(passphraseState);
42944
42842
  }
42945
42843
  set(deviceKey, passphraseState, sessionId) {
42946
- var _a;
42947
42844
  if (!deviceKey || !passphraseState || !sessionId)
42948
42845
  return;
42949
42846
  let deviceSessions = this.walletSessions.get(deviceKey);
@@ -42951,16 +42848,6 @@ class DeviceWalletSessionStore {
42951
42848
  deviceSessions = new Map();
42952
42849
  this.walletSessions.set(deviceKey, deviceSessions);
42953
42850
  }
42954
- if (!deviceSessions.has(passphraseState) &&
42955
- deviceSessions.size >= DeviceWalletSessionStore.MAX_SESSIONS_PER_DEVICE) {
42956
- const oldestPassphraseState = deviceSessions.keys().next().value;
42957
- if (oldestPassphraseState) {
42958
- deviceSessions.delete(oldestPassphraseState);
42959
- if (((_a = this.standardWalletSessions.get(deviceKey)) === null || _a === void 0 ? void 0 : _a.passphraseState) === oldestPassphraseState) {
42960
- this.standardWalletSessions.delete(deviceKey);
42961
- }
42962
- }
42963
- }
42964
42851
  deviceSessions.set(passphraseState, sessionId);
42965
42852
  }
42966
42853
  getStandard(deviceKey) {
@@ -43062,14 +42949,31 @@ class DeviceWalletSessionStore {
43062
42949
  this.pendingSessions.clear();
43063
42950
  }
43064
42951
  }
43065
- DeviceWalletSessionStore.MAX_SESSIONS_PER_DEVICE = 3;
43066
42952
  const deviceWalletSessionStore = new DeviceWalletSessionStore();
43067
42953
 
43068
- const getProtocolV2RuntimeMode = ({ deviceInfo: _deviceInfo, deviceStatusAvailable, }) => {
43069
- if (deviceStatusAvailable)
42954
+ const parseProtocolV2BuildFingerprint = (buildFingerprint) => {
42955
+ if (!buildFingerprint)
42956
+ return null;
42957
+ const [binary, version, commit, environment, buildType, ...extra] = buildFingerprint.split('__');
42958
+ if (extra.length > 0 ||
42959
+ (binary !== 'application' && binary !== 'bootloader' && binary !== 'romloader') ||
42960
+ !version ||
42961
+ !commit ||
42962
+ (environment !== 'PROD' && environment !== 'DEV') ||
42963
+ (buildType !== 'DEBUG' && buildType !== 'RELEASE')) {
42964
+ return null;
42965
+ }
42966
+ return { binary, version, commit, environment, buildType };
42967
+ };
42968
+ const getProtocolV2RuntimeMode = (protocolInfo) => {
42969
+ var _a;
42970
+ const binary = (_a = parseProtocolV2BuildFingerprint(protocolInfo.build_fingerprint)) === null || _a === void 0 ? void 0 : _a.binary;
42971
+ if (binary === 'application')
43070
42972
  return 'normal';
43071
- return 'bootloader';
42973
+ return binary;
43072
42974
  };
42975
+ const PROTOCOL_V2_DEVICE_STATUS_GET_MESSAGE_TYPE = 60602;
42976
+ const supportsProtocolV2Message = (protocolInfo, messageType) => protocolInfo.supported_messages.includes(messageType);
43073
42977
  const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
43074
42978
  targets: {
43075
42979
  hw: true,
@@ -43118,6 +43022,14 @@ const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
43118
43022
  },
43119
43023
  };
43120
43024
  const PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS = 10 * 1000;
43025
+ function requestProtocolV2ProtocolInfo({ commands, timeoutMs, }) {
43026
+ return __awaiter(this, void 0, void 0, function* () {
43027
+ const response = timeoutMs === undefined
43028
+ ? yield commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {})
43029
+ : yield commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {}, { timeoutMs });
43030
+ return response.message;
43031
+ });
43032
+ }
43121
43033
  function requestProtocolV2DeviceInfo({ commands, timeoutMs = PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS, request = PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST, }) {
43122
43034
  return __awaiter(this, void 0, void 0, function* () {
43123
43035
  const { message } = yield commands.typedCall('DeviceInfoGet', 'DeviceInfo', request, {
@@ -43647,14 +43559,7 @@ class Device extends events.exports {
43647
43559
  if (options === null || options === void 0 ? void 0 : options.deriveCardano) {
43648
43560
  payload.derive_cardano = true;
43649
43561
  }
43650
- const requiresWalletInitialize = !expectedDeviceId ||
43651
- Boolean(internalState) ||
43652
- Boolean(options === null || options === void 0 ? void 0 : options.passphraseState) ||
43653
- (options === null || options === void 0 ? void 0 : options.deriveCardano) === true ||
43654
- (options === null || options === void 0 ? void 0 : options.initSession) === true;
43655
- if (requiresWalletInitialize) {
43656
- yield callInitialize(payload, options === null || options === void 0 ? void 0 : options.initSession);
43657
- }
43562
+ yield callInitialize(payload, options === null || options === void 0 ? void 0 : options.initSession);
43658
43563
  }
43659
43564
  catch (error) {
43660
43565
  Log$e.error('Initialization failed:', error);
@@ -43804,37 +43709,44 @@ class Device extends events.exports {
43804
43709
  return this.features;
43805
43710
  }
43806
43711
  probeProtocolV2RuntimeState(deviceInfo, timeoutMs) {
43712
+ var _a;
43807
43713
  return __awaiter(this, void 0, void 0, function* () {
43808
- let deviceStatus;
43809
- try {
43810
- deviceStatus = yield requestProtocolV2DeviceStatus({
43811
- commands: this.commands,
43812
- timeoutMs,
43813
- });
43714
+ const protocolInfo = yield requestProtocolV2ProtocolInfo({
43715
+ commands: this.commands,
43716
+ timeoutMs,
43717
+ });
43718
+ const runtimeMode = getProtocolV2RuntimeMode(protocolInfo);
43719
+ const protocolV2DeviceType = resolveProtocolV2DeviceIdentity((_a = deviceInfo.hw) === null || _a === void 0 ? void 0 : _a.Device_type).deviceType;
43720
+ if (runtimeMode === 'romloader' && protocolV2DeviceType !== hdShared.EDeviceType.Pro2) {
43721
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, 'Protocol V2 romloader mode is only supported for Pro2.');
43814
43722
  }
43815
- catch (error) {
43816
- const runtimeMode = getProtocolV2RuntimeMode({
43817
- deviceInfo,
43818
- deviceStatusAvailable: false,
43819
- });
43820
- Log$e.debug('Protocol V2 DeviceStatusGet unavailable; use temporary loader fallback', {
43821
- runtimeMode,
43822
- error: error instanceof Error ? error.message : String(error),
43823
- });
43824
- return this.updateProtocolV2Features(deviceInfo, null, runtimeMode);
43723
+ const deviceStatusSupported = supportsProtocolV2Message(protocolInfo, PROTOCOL_V2_DEVICE_STATUS_GET_MESSAGE_TYPE);
43724
+ if (runtimeMode === 'bootloader' || runtimeMode === 'romloader') {
43725
+ return this.updateProtocolV2Features(deviceInfo, null, runtimeMode, protocolInfo);
43726
+ }
43727
+ if (!deviceStatusSupported) {
43728
+ if (runtimeMode === 'normal') {
43729
+ return this.updateProtocolV2Features(deviceInfo, null, runtimeMode, protocolInfo);
43730
+ }
43731
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, `Unknown Protocol V2 build fingerprint without DeviceStatusGet capability: ${protocolInfo.build_fingerprint}`);
43825
43732
  }
43826
- return this.updateProtocolV2Features(deviceInfo, deviceStatus, 'normal');
43733
+ const deviceStatus = yield requestProtocolV2DeviceStatus({
43734
+ commands: this.commands,
43735
+ timeoutMs,
43736
+ });
43737
+ return this.updateProtocolV2Features(deviceInfo, deviceStatus, 'normal', protocolInfo);
43827
43738
  });
43828
43739
  }
43829
- updateProtocolV2Features(deviceInfo, deviceStatus, runtimeMode) {
43740
+ updateProtocolV2Features(deviceInfo, deviceStatus, runtimeMode, protocolInfo) {
43830
43741
  var _a;
43831
43742
  const previousDeviceId = this.getCurrentDeviceId();
43832
- const resolvedMode = runtimeMode !== null && runtimeMode !== void 0 ? runtimeMode : (deviceStatus
43833
- ? getProtocolV2RuntimeMode({ deviceInfo, deviceStatusAvailable: true })
43834
- : (_a = this.state) === null || _a === void 0 ? void 0 : _a.status.mode);
43743
+ const resolvedMode = runtimeMode !== null && runtimeMode !== void 0 ? runtimeMode : (deviceStatus ? 'normal' : (_a = this.state) === null || _a === void 0 ? void 0 : _a.status.mode);
43835
43744
  if (deviceInfo) {
43836
43745
  this.updateState(mapProtocolV2DeviceInfoToState(deviceInfo, resolvedMode), 'device-info');
43837
43746
  }
43747
+ if (protocolInfo) {
43748
+ this.updateState({ raw: { protocolV2ProtocolInfo: protocolInfo } }, 'device-info');
43749
+ }
43838
43750
  if (deviceStatus) {
43839
43751
  this.updateState(mapProtocolV2DeviceStatusToState(deviceStatus), 'device-status');
43840
43752
  }
@@ -43897,13 +43809,13 @@ class Device extends events.exports {
43897
43809
  attachToPinEnabled: null,
43898
43810
  unlockedAttachPin: null,
43899
43811
  },
43900
- raw: { protocolV2DeviceStatus: null },
43812
+ raw: { protocolV2ProtocolInfo: null, protocolV2DeviceStatus: null },
43901
43813
  }, 'transport-reconnect');
43902
43814
  return;
43903
43815
  }
43904
43816
  this.updateState({
43905
43817
  status: { mode: 'normal', unlocked: null },
43906
- raw: { protocolV2DeviceStatus: null },
43818
+ raw: { protocolV2ProtocolInfo: null, protocolV2DeviceStatus: null },
43907
43819
  }, 'transport-reconnect');
43908
43820
  }
43909
43821
  updateDescriptor(descriptor, forceUpdate = false) {
@@ -44110,7 +44022,14 @@ class Device extends events.exports {
44110
44022
  isBootloader() {
44111
44023
  if (!this.state)
44112
44024
  return undefined;
44113
- return this.state.status.mode === 'bootloader' || this.state.status.mode === 'romloader';
44025
+ return this.state.status.mode === 'bootloader';
44026
+ }
44027
+ isRomloader() {
44028
+ if (!this.state)
44029
+ return undefined;
44030
+ return (this.isProtocolV2() &&
44031
+ this.getCurrentDeviceType() === hdShared.EDeviceType.Pro2 &&
44032
+ this.state.status.mode === 'romloader');
44114
44033
  }
44115
44034
  isInitialized() {
44116
44035
  if (!this.state)
@@ -44915,12 +44834,21 @@ class GetPassphraseState extends BaseMethod {
44915
44834
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed);
44916
44835
  }
44917
44836
  const isProtocolV2 = this.device.isProtocolV2();
44837
+ if (isProtocolV2 && this.payload.useEmptyPassphrase !== true) {
44838
+ const features = yield refreshProtocolV2DeviceStatus(this.device);
44839
+ if (features.unlocked === false) {
44840
+ yield this.device.unlockDevice();
44841
+ }
44842
+ }
44918
44843
  const { passphraseState } = yield getPassphraseStateWithRefreshDeviceInfo(this.device, isProtocolV2
44919
44844
  ? {
44920
44845
  onlyMainPin: this.payload.useEmptyPassphrase === true,
44921
44846
  initSession: this.payload.initSession === true,
44922
44847
  }
44923
44848
  : undefined);
44849
+ if (!isProtocolV2 && this.device.getCurrentPassphraseProtection() !== true) {
44850
+ return undefined;
44851
+ }
44924
44852
  return passphraseState;
44925
44853
  });
44926
44854
  }
@@ -45167,7 +45095,6 @@ class OpenWalletSession extends BaseMethod {
45167
45095
  this.payload.useEmptyPassphrase = this.params.mode === OpenWalletSessionMode.Standard;
45168
45096
  }
45169
45097
  run() {
45170
- var _a, _b;
45171
45098
  return __awaiter(this, void 0, void 0, function* () {
45172
45099
  const isProtocolV2 = this.device.isProtocolV2();
45173
45100
  const state = yield this.device.getDeviceState({ refreshSections: ['status'] });
@@ -45183,6 +45110,11 @@ class OpenWalletSession extends BaseMethod {
45183
45110
  currentDeviceId = refreshedState.identity.deviceId;
45184
45111
  return requireDeviceId();
45185
45112
  });
45113
+ const unlockProtocolV2IfLocked = () => __awaiter(this, void 0, void 0, function* () {
45114
+ if (isProtocolV2 && state.status.unlocked === false) {
45115
+ yield this.device.unlockDevice();
45116
+ }
45117
+ });
45186
45118
  const protocol = isProtocolV2 ? 'V2' : 'V1';
45187
45119
  if (this.params.mode === OpenWalletSessionMode.Standard) {
45188
45120
  this.device.passphraseState = undefined;
@@ -45197,7 +45129,7 @@ class OpenWalletSession extends BaseMethod {
45197
45129
  try {
45198
45130
  yield this.device.lockDevice();
45199
45131
  }
45200
- catch (_c) {
45132
+ catch (_a) {
45201
45133
  }
45202
45134
  this.device.clearInternalState();
45203
45135
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckUnlockTypeError);
@@ -45206,15 +45138,13 @@ class OpenWalletSession extends BaseMethod {
45206
45138
  protocol,
45207
45139
  walletType: 'standard',
45208
45140
  deviceId,
45209
- passphraseState: (_a = session.passphraseState) !== null && _a !== void 0 ? _a : null,
45141
+ passphraseState: null,
45210
45142
  resumed: wasResumed(session),
45211
45143
  };
45212
45144
  }
45213
45145
  if (this.params.mode === OpenWalletSessionMode.ResumeHidden) {
45214
45146
  if (isProtocolV2) {
45215
- if (((_b = this.device.features) === null || _b === void 0 ? void 0 : _b.unlocked) === false) {
45216
- yield this.device.unlockDevice();
45217
- }
45147
+ yield unlockProtocolV2IfLocked();
45218
45148
  const refreshedDeviceId = yield refreshProtocolV2DeviceId();
45219
45149
  if (refreshedDeviceId !== this.params.deviceId) {
45220
45150
  deviceWalletSessionStore.delete(this.params.deviceId, this.params.passphraseState);
@@ -45226,7 +45156,7 @@ class OpenWalletSession extends BaseMethod {
45226
45156
  }
45227
45157
  this.device.passphraseState = this.params.passphraseState;
45228
45158
  const cachedSessionId = deviceWalletSessionStore.get(this.params.deviceId, this.params.passphraseState);
45229
- if (!cachedSessionId) {
45159
+ if (!cachedSessionId && !isProtocolV2) {
45230
45160
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WalletSessionInvalid);
45231
45161
  }
45232
45162
  if (!isProtocolV2) {
@@ -45247,13 +45177,18 @@ class OpenWalletSession extends BaseMethod {
45247
45177
  this.device.clearInternalState();
45248
45178
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
45249
45179
  }
45250
- return Object.assign(Object.assign({ protocol, walletType: 'hidden', deviceId }, requireHiddenWalletResponse(session)), { resumed: wasResumed(session) || session.newSession === cachedSessionId });
45180
+ return Object.assign(Object.assign({ protocol, walletType: 'hidden', deviceId }, requireHiddenWalletResponse(session)), { resumed: wasResumed(session) || (!isProtocolV2 && session.newSession === cachedSessionId) });
45251
45181
  }
45252
45182
  this.device.passphraseState = undefined;
45183
+ yield unlockProtocolV2IfLocked();
45253
45184
  const session = isProtocolV2
45254
- ? yield getProtocolV2WalletSession(this.device, { initSession: true })
45185
+ ? yield getProtocolV2WalletSession(this.device, { forceWalletSelection: true })
45255
45186
  : yield getPassphraseStateWithRefreshDeviceInfo(this.device, { initSession: true });
45256
45187
  const deviceId = isProtocolV2 ? yield refreshProtocolV2DeviceId() : requireDeviceId();
45188
+ if (isProtocolV2 && this.device.getCurrentPassphraseProtection() !== true) {
45189
+ this.device.clearInternalState();
45190
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotOpenedPassphrase);
45191
+ }
45257
45192
  const responseBase = {
45258
45193
  protocol,
45259
45194
  deviceId,
@@ -46061,12 +45996,16 @@ class DeviceReset extends BaseMethod {
46061
45996
  }
46062
45997
  }
46063
45998
 
46064
- const LOCK_FREE_DEVICE_SETTINGS = new Set([
45999
+ const PROTOCOL_V2_LOCK_FREE_DEVICE_SETTINGS = [
46065
46000
  'language',
46066
46001
  'brightness',
46002
+ 'animation_enable',
46003
+ 'tap_to_wake',
46067
46004
  'haptic_feedback',
46068
- ]);
46069
- const getProtocolV2SettingsUnlockPolicy = (settings) => Object.keys(settings).every(key => LOCK_FREE_DEVICE_SETTINGS.has(key))
46005
+ 'device_name_display_enabled',
46006
+ ];
46007
+ const lockFreeDeviceSettings = new Set(PROTOCOL_V2_LOCK_FREE_DEVICE_SETTINGS);
46008
+ const getProtocolV2SettingsUnlockPolicy = (settings) => Object.keys(settings).every(key => lockFreeDeviceSettings.has(key))
46070
46009
  ? 'none'
46071
46010
  : 'unlock-before-run';
46072
46011
  const getProtocolV2SettingsBehavior = (operation) => {
@@ -49302,17 +49241,31 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49302
49241
  });
49303
49242
  }
49304
49243
  isProtocolV2BootloaderMode() {
49305
- var _a;
49244
+ var _a, _b, _c;
49306
49245
  if (typeof this.device.isBootloader === 'function') {
49307
49246
  return this.device.isBootloader();
49308
49247
  }
49309
- return !!((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.bootloaderMode);
49248
+ return (((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.mode) === 'bootloader' ||
49249
+ (((_b = this.device.features) === null || _b === void 0 ? void 0 : _b.mode) == null && !!((_c = this.device.features) === null || _c === void 0 ? void 0 : _c.bootloaderMode)));
49310
49250
  }
49311
- enterProtocolV2BootloaderMode() {
49251
+ isProtocolV2RomloaderMode() {
49312
49252
  var _a;
49253
+ if (!this.device.isProtocolV2() || this.device.getCurrentDeviceType() !== hdShared.EDeviceType.Pro2) {
49254
+ return false;
49255
+ }
49256
+ if (typeof this.device.isRomloader === 'function') {
49257
+ return this.device.isRomloader();
49258
+ }
49259
+ return ((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.mode) === 'romloader';
49260
+ }
49261
+ enterProtocolV2BootloaderMode() {
49313
49262
  return __awaiter(this, void 0, void 0, function* () {
49314
- if (this.isProtocolV2BootloaderMode() || ((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.mode) === 'romloader') {
49315
- Log$5.debug('Protocol V2 device is already in loader mode, skip reboot to bootloader');
49263
+ if (this.isProtocolV2RomloaderMode()) {
49264
+ Log$5.debug('Protocol V2 device is in romloader mode; start firmware update directly');
49265
+ return false;
49266
+ }
49267
+ if (this.isProtocolV2BootloaderMode()) {
49268
+ Log$5.debug('Protocol V2 device is already in bootloader mode, skip reboot');
49316
49269
  return false;
49317
49270
  }
49318
49271
  try {
@@ -49344,8 +49297,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49344
49297
  timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT,
49345
49298
  });
49346
49299
  this.assertProtocolV2DeviceInfoIdentity(deviceInfo);
49347
- const features = this.device.updateProtocolV2Features(deviceInfo, null, 'bootloader');
49348
- if (features === null || features === void 0 ? void 0 : features.bootloaderMode) {
49300
+ const features = yield this.device.probeProtocolV2RuntimeState(deviceInfo, PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT);
49301
+ if ((features === null || features === void 0 ? void 0 : features.mode) === 'bootloader') {
49349
49302
  return features;
49350
49303
  }
49351
49304
  lastError = new Error('Protocol V2 device is reachable but is not in bootloader mode');
@@ -49892,7 +49845,7 @@ class DeviceGetOnboardingStatus extends BaseMethod {
49892
49845
  }
49893
49846
  run() {
49894
49847
  return __awaiter(this, void 0, void 0, function* () {
49895
- const { message } = yield this.device.commands.typedCall('DevGetOnboardingStatus', 'DevOnboardingStatus', {});
49848
+ const { message } = yield this.device.commands.typedCall('OnboardingStatusGet', 'OnboardingStatus', {});
49896
49849
  return message;
49897
49850
  });
49898
49851
  }
@@ -50065,7 +50018,7 @@ class DeviceUploadWallpaper extends BaseMethod {
50065
50018
  this.encoded = encodePro2Wallpaper({ width, height, rgba: rgbaBytes });
50066
50019
  this.path = `${WALLPAPER_DIRECTORY}/${normalizeFileName(fileName, this.encoded.data)}`;
50067
50020
  this.params = { width, height, rgba: rgbaBytes, fileName, chunkSize };
50068
- this.unlockPolicy = 'unlock-before-run';
50021
+ this.unlockPolicy = 'none';
50069
50022
  this.skipForceUpdateCheck = true;
50070
50023
  this.useDevicePassphraseState = false;
50071
50024
  }
@@ -52227,6 +52180,8 @@ function getAddress ({ typedCall, param, }) {
52227
52180
  });
52228
52181
  }
52229
52182
 
52183
+ const shouldUseLegacyV1EvmMessages = (device) => !device.isProtocolV2() && TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema';
52184
+
52230
52185
  class EvmGetAddress extends BaseMethod {
52231
52186
  constructor() {
52232
52187
  super(...arguments);
@@ -52261,7 +52216,7 @@ class EvmGetAddress extends BaseMethod {
52261
52216
  }
52262
52217
  getEvmAddress(param) {
52263
52218
  return __awaiter(this, void 0, void 0, function* () {
52264
- if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
52219
+ if (shouldUseLegacyV1EvmMessages(this.device)) {
52265
52220
  return getAddressLegacyV1({
52266
52221
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
52267
52222
  param,
@@ -52352,7 +52307,7 @@ class EVMGetPublicKey extends BaseMethod {
52352
52307
  });
52353
52308
  }
52354
52309
  getEvmPublicKey(param) {
52355
- if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
52310
+ if (shouldUseLegacyV1EvmMessages(this.device)) {
52356
52311
  return getPublicKeyLegacyV1({
52357
52312
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
52358
52313
  param,
@@ -52441,7 +52396,7 @@ class EVMSignMessage$2 extends BaseMethod {
52441
52396
  }
52442
52397
  run() {
52443
52398
  return __awaiter(this, void 0, void 0, function* () {
52444
- if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
52399
+ if (shouldUseLegacyV1EvmMessages(this.device)) {
52445
52400
  return signMessageLegacyV1({
52446
52401
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
52447
52402
  params: this.params,
@@ -52761,7 +52716,7 @@ class EVMSignTransaction extends BaseMethod {
52761
52716
  const { addressN, isEIP1559, isEIP7702, formattedTx } = this;
52762
52717
  if (formattedTx == null)
52763
52718
  throw hdShared.ERRORS.TypedError('Runtime', 'formattedTx is not set');
52764
- if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
52719
+ if (shouldUseLegacyV1EvmMessages(this.device)) {
52765
52720
  return signTransaction({
52766
52721
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
52767
52722
  addressN,
@@ -53122,28 +53077,24 @@ class EVMSignTypedData extends BaseMethod {
53122
53077
  const { addressN, data, metamaskV4Compat, chainId } = this.params;
53123
53078
  let supportTrezor = false;
53124
53079
  let response;
53125
- switch (TransportManager.getProtocolV1MessageSchema()) {
53126
- case 'v1LegacySchema':
53127
- supportTrezor = true;
53128
- response = yield signTypedData$1({
53129
- typedCall: this.device.commands.typedCall.bind(this.device.commands),
53130
- addressN,
53131
- data,
53132
- metamaskV4Compat,
53133
- chainId,
53134
- });
53135
- break;
53136
- case 'v1CurrentSchema':
53137
- default:
53138
- supportTrezor = false;
53139
- response = yield signTypedData({
53140
- typedCall: this.device.commands.typedCall.bind(this.device.commands),
53141
- addressN,
53142
- data,
53143
- metamaskV4Compat,
53144
- chainId,
53145
- });
53146
- break;
53080
+ if (shouldUseLegacyV1EvmMessages(this.device)) {
53081
+ supportTrezor = true;
53082
+ response = yield signTypedData$1({
53083
+ typedCall: this.device.commands.typedCall.bind(this.device.commands),
53084
+ addressN,
53085
+ data,
53086
+ metamaskV4Compat,
53087
+ chainId,
53088
+ });
53089
+ }
53090
+ else {
53091
+ response = yield signTypedData({
53092
+ typedCall: this.device.commands.typedCall.bind(this.device.commands),
53093
+ addressN,
53094
+ data,
53095
+ metamaskV4Compat,
53096
+ chainId,
53097
+ });
53147
53098
  }
53148
53099
  return this.handleSignTypedData({
53149
53100
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
@@ -53156,27 +53107,24 @@ class EVMSignTypedData extends BaseMethod {
53156
53107
  signTypedHash({ typedCall, addressN, chainId, domainHash, messageHash, }) {
53157
53108
  if (!domainHash)
53158
53109
  throw hdShared.ERRORS.TypedError('Runtime', 'domainHash is required');
53159
- switch (TransportManager.getProtocolV1MessageSchema()) {
53160
- case 'v1LegacySchema':
53161
- return signTypedHash$1({
53162
- typedCall,
53163
- addressN,
53164
- domainHash,
53165
- messageHash,
53166
- chainId,
53167
- device: this.device,
53168
- });
53169
- case 'v1CurrentSchema':
53170
- default:
53171
- return signTypedHash({
53172
- typedCall,
53173
- addressN,
53174
- domainHash,
53175
- messageHash,
53176
- chainId,
53177
- device: this.device,
53178
- });
53110
+ if (shouldUseLegacyV1EvmMessages(this.device)) {
53111
+ return signTypedHash$1({
53112
+ typedCall,
53113
+ addressN,
53114
+ domainHash,
53115
+ messageHash,
53116
+ chainId,
53117
+ device: this.device,
53118
+ });
53179
53119
  }
53120
+ return signTypedHash({
53121
+ typedCall,
53122
+ addressN,
53123
+ domainHash,
53124
+ messageHash,
53125
+ chainId,
53126
+ device: this.device,
53127
+ });
53180
53128
  }
53181
53129
  getVersionRange() {
53182
53130
  return {
@@ -53433,7 +53381,7 @@ class EVMSignMessage$1 extends BaseMethod {
53433
53381
  }
53434
53382
  run() {
53435
53383
  return __awaiter(this, void 0, void 0, function* () {
53436
- if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
53384
+ if (shouldUseLegacyV1EvmMessages(this.device)) {
53437
53385
  return verifyMessageLegacyV1({
53438
53386
  typedCall: this.device.commands.typedCall.bind(this.device.commands),
53439
53387
  params: this.params,
@@ -60171,6 +60119,13 @@ const getSynchronize = (mutex) => {
60171
60119
  return (action, lockId) => lock(lockId).then(unlock => Promise.resolve().then(action).finally(unlock));
60172
60120
  };
60173
60121
 
60122
+ function isDeviceLockedError(error) {
60123
+ return (typeof error === 'object' &&
60124
+ error !== null &&
60125
+ 'errorCode' in error &&
60126
+ error.errorCode === hdShared.HardwareErrorCode.DeviceLocked);
60127
+ }
60128
+
60174
60129
  const isProtocolV2UiEnabled = (method) => method.protocolV2UiMode !== 'none';
60175
60130
  const getDisplayState = (value) => {
60176
60131
  const visited = new Set();
@@ -60305,10 +60260,22 @@ const restoreExpectedWalletSessionAfterUnlock = (method, device) => __awaiter(vo
60305
60260
  Log$1.debug('Protocol V2 wallet session restored after unlock', { method: method.name });
60306
60261
  });
60307
60262
  function runMethodWithUnlockRetry(method, device, uiCoordinator) {
60308
- var _a;
60263
+ var _a, _b, _c, _d, _e;
60309
60264
  return __awaiter(this, void 0, void 0, function* () {
60310
60265
  const shouldEmitUi = isProtocolV2UiEnabled(method);
60311
- const shouldUnlockBeforeRun = device.isProtocolV2() && method.unlockPolicy !== 'none' && ((_a = device.features) === null || _a === void 0 ? void 0 : _a.unlocked) === false;
60266
+ const isProtocolV2 = device.isProtocolV2();
60267
+ const requiresFreshStatus = isProtocolV2 &&
60268
+ method.unlockPolicy === 'unlock-before-run' &&
60269
+ !((_a = device.isBootloader) === null || _a === void 0 ? void 0 : _a.call(device)) &&
60270
+ !((_b = device.isRomloader) === null || _b === void 0 ? void 0 : _b.call(device));
60271
+ if (requiresFreshStatus) {
60272
+ yield refreshProtocolV2DeviceStatus(device);
60273
+ }
60274
+ const shouldUnlockBeforeRun = isProtocolV2 &&
60275
+ method.unlockPolicy !== 'none' &&
60276
+ !((_c = device.isBootloader) === null || _c === void 0 ? void 0 : _c.call(device)) &&
60277
+ !((_d = device.isRomloader) === null || _d === void 0 ? void 0 : _d.call(device)) &&
60278
+ ((_e = device.features) === null || _e === void 0 ? void 0 : _e.unlocked) === false;
60312
60279
  if (shouldUnlockBeforeRun) {
60313
60280
  if (shouldEmitUi) {
60314
60281
  uiCoordinator === null || uiCoordinator === void 0 ? void 0 : uiCoordinator.enterUnlockInteraction(method.name);
@@ -60328,9 +60295,7 @@ function runMethodWithUnlockRetry(method, device, uiCoordinator) {
60328
60295
  return yield method.run();
60329
60296
  }
60330
60297
  catch (error) {
60331
- if (!device.isProtocolV2() ||
60332
- method.unlockPolicy !== 'retry-on-locked' ||
60333
- !isDeviceLockedError(error)) {
60298
+ if (!isProtocolV2 || method.unlockPolicy !== 'retry-on-locked' || !isDeviceLockedError(error)) {
60334
60299
  throw error;
60335
60300
  }
60336
60301
  Log$1.debug('Protocol V2 unlock retry triggered', { method: method.name });