@onekeyfe/hd-core 0.1.41 → 0.1.44

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 (103) hide show
  1. package/dist/api/BaseMethod.d.ts.map +1 -1
  2. package/dist/api/aptos/AptosGetAddress.d.ts +9 -0
  3. package/dist/api/aptos/AptosGetAddress.d.ts.map +1 -0
  4. package/dist/api/aptos/AptosSignTransaction.d.ts +12 -0
  5. package/dist/api/aptos/AptosSignTransaction.d.ts.map +1 -0
  6. package/dist/api/conflux/ConfluxGetAddress.d.ts +14 -0
  7. package/dist/api/conflux/ConfluxGetAddress.d.ts.map +1 -0
  8. package/dist/api/conflux/ConfluxSignMessage.d.ts +12 -0
  9. package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -0
  10. package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts +12 -0
  11. package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -0
  12. package/dist/api/conflux/ConfluxSignTransaction.d.ts +17 -0
  13. package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -0
  14. package/dist/api/helpers/stringUtils.d.ts +1 -0
  15. package/dist/api/helpers/stringUtils.d.ts.map +1 -1
  16. package/dist/api/index.d.ts +21 -10
  17. package/dist/api/index.d.ts.map +1 -1
  18. package/dist/api/near/NearGetAddress.d.ts +14 -0
  19. package/dist/api/near/NearGetAddress.d.ts.map +1 -0
  20. package/dist/api/near/NearSignTransaction.d.ts +12 -0
  21. package/dist/api/near/NearSignTransaction.d.ts.map +1 -0
  22. package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
  23. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
  24. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
  25. package/dist/api/tron/TronGetAddress.d.ts +14 -0
  26. package/dist/api/tron/TronGetAddress.d.ts.map +1 -0
  27. package/dist/api/tron/TronSignMessage.d.ts +12 -0
  28. package/dist/api/tron/TronSignMessage.d.ts.map +1 -0
  29. package/dist/api/tron/TronSignTransaction.d.ts +14 -0
  30. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -0
  31. package/dist/core/index.d.ts.map +1 -1
  32. package/dist/device/DeviceCommands.d.ts +1 -1
  33. package/dist/device/DeviceCommands.d.ts.map +1 -1
  34. package/dist/index.d.ts +347 -199
  35. package/dist/index.js +1579 -594
  36. package/dist/inject.d.ts.map +1 -1
  37. package/dist/types/api/aptosGetAddress.d.ts +14 -0
  38. package/dist/types/api/aptosGetAddress.d.ts.map +1 -0
  39. package/dist/types/api/aptosSignTransaction.d.ts +11 -0
  40. package/dist/types/api/aptosSignTransaction.d.ts.map +1 -0
  41. package/dist/types/api/confluxGetAddress.d.ts +15 -0
  42. package/dist/types/api/confluxGetAddress.d.ts.map +1 -0
  43. package/dist/types/api/confluxSignMessage.d.ts +8 -0
  44. package/dist/types/api/confluxSignMessage.d.ts.map +1 -0
  45. package/dist/types/api/confluxSignMessageCIP23.d.ts +9 -0
  46. package/dist/types/api/confluxSignMessageCIP23.d.ts.map +1 -0
  47. package/dist/types/api/confluxSignTransaction.d.ts +25 -0
  48. package/dist/types/api/confluxSignTransaction.d.ts.map +1 -0
  49. package/dist/types/api/deviceVerify.d.ts +2 -3
  50. package/dist/types/api/deviceVerify.d.ts.map +1 -1
  51. package/dist/types/api/export.d.ts +11 -0
  52. package/dist/types/api/export.d.ts.map +1 -1
  53. package/dist/types/api/index.d.ts +49 -27
  54. package/dist/types/api/index.d.ts.map +1 -1
  55. package/dist/types/api/nearGetAddress.d.ts +14 -0
  56. package/dist/types/api/nearGetAddress.d.ts.map +1 -0
  57. package/dist/types/api/nearSignTransaction.d.ts +8 -0
  58. package/dist/types/api/nearSignTransaction.d.ts.map +1 -0
  59. package/dist/types/api/tronGetAddress.d.ts +14 -0
  60. package/dist/types/api/tronGetAddress.d.ts.map +1 -0
  61. package/dist/types/api/tronSignMessage.d.ts +8 -0
  62. package/dist/types/api/tronSignMessage.d.ts.map +1 -0
  63. package/dist/types/api/tronSignTransaction.d.ts +32 -0
  64. package/dist/types/api/tronSignTransaction.d.ts.map +1 -0
  65. package/dist/utils/patch.d.ts +1 -1
  66. package/dist/utils/patch.d.ts.map +1 -1
  67. package/package.json +4 -4
  68. package/src/api/BaseMethod.ts +5 -2
  69. package/src/api/aptos/AptosGetAddress.ts +60 -0
  70. package/src/api/aptos/AptosSignTransaction.ts +45 -0
  71. package/src/api/conflux/ConfluxGetAddress.ts +67 -0
  72. package/src/api/conflux/ConfluxSignMessage.ts +48 -0
  73. package/src/api/conflux/ConfluxSignMessageCIP23.ts +48 -0
  74. package/src/api/conflux/ConfluxSignTransaction.ts +134 -0
  75. package/src/api/helpers/stringUtils.ts +3 -0
  76. package/src/api/index.ts +26 -10
  77. package/src/api/near/NearGetAddress.ts +68 -0
  78. package/src/api/near/NearSignTransaction.ts +45 -0
  79. package/src/api/solana/SolGetAddress.ts +0 -2
  80. package/src/api/solana/SolSignTransaction.ts +0 -2
  81. package/src/api/stellar/StellarSignTransaction.ts +14 -7
  82. package/src/api/tron/TronGetAddress.ts +68 -0
  83. package/src/api/tron/TronSignMessage.ts +48 -0
  84. package/src/api/tron/TronSignTransaction.ts +87 -0
  85. package/src/core/index.ts +15 -2
  86. package/src/data/messages/messages.json +8887 -8433
  87. package/src/device/DeviceCommands.ts +6 -7
  88. package/src/inject.ts +26 -0
  89. package/src/types/api/aptosGetAddress.ts +23 -0
  90. package/src/types/api/aptosSignTransaction.ts +17 -0
  91. package/src/types/api/confluxGetAddress.ts +24 -0
  92. package/src/types/api/confluxSignMessage.ts +13 -0
  93. package/src/types/api/confluxSignMessageCIP23.ts +14 -0
  94. package/src/types/api/confluxSignTransaction.ts +32 -0
  95. package/src/types/api/deviceVerify.ts +2 -2
  96. package/src/types/api/export.ts +25 -0
  97. package/src/types/api/index.ts +101 -35
  98. package/src/types/api/nearGetAddress.ts +23 -0
  99. package/src/types/api/nearSignTransaction.ts +13 -0
  100. package/src/types/api/tronGetAddress.ts +23 -0
  101. package/src/types/api/tronSignMessage.ts +13 -0
  102. package/src/types/api/tronSignTransaction.ts +41 -0
  103. package/src/utils/deviceFeaturesUtils.ts +2 -2
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import semver from 'semver';
2
2
  import { ERRORS, HardwareErrorCode, HardwareError, serializeError, createDeferred } from '@onekeyfe/hd-shared';
3
+ import { FailureType, EthereumDataType, StellarMemoType } from '@onekeyfe/hd-transport';
4
+ export { Messages as PROTO } from '@onekeyfe/hd-transport';
3
5
  import axios from 'axios';
4
6
  import BigNumber from 'bignumber.js';
5
7
  import sha256 from 'js-sha256';
6
- import { EthereumDataType } from '@onekeyfe/hd-transport';
7
- export { Messages as PROTO } from '@onekeyfe/hd-transport';
8
8
 
9
9
  const inject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, }) => {
10
10
  const api = {
@@ -67,6 +67,17 @@ const inject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, }) => {
67
67
  stellarSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'stellarSignTransaction' })),
68
68
  firmwareUpdate: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'firmwareUpdate' })),
69
69
  requestWebUsbDevice: () => call({ method: 'requestWebUsbDevice' }),
70
+ tronGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'tronGetAddress' })),
71
+ tronSignMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'tronSignMessage' })),
72
+ tronSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'tronSignTransaction' })),
73
+ confluxGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'confluxGetAddress' })),
74
+ confluxSignMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'confluxSignMessage' })),
75
+ confluxSignMessageCIP23: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'confluxSignMessageCIP23' })),
76
+ confluxSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'confluxSignTransaction' })),
77
+ nearGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'nearGetAddress' })),
78
+ nearSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'nearSignTransaction' })),
79
+ aptosGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'aptosGetAddress' })),
80
+ aptosSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'aptosSignTransaction' })),
70
81
  };
71
82
  return api;
72
83
  };
@@ -748,11 +759,12 @@ const getDeviceTypeByDeviceId = (deviceId) => {
748
759
  return 'classic';
749
760
  };
750
761
  const getDeviceUUID = (features) => {
762
+ var _a, _b;
751
763
  const deviceType = getDeviceType(features);
752
764
  if (deviceType === 'classic') {
753
- return features.onekey_serial;
765
+ return (_a = features.onekey_serial) !== null && _a !== void 0 ? _a : '';
754
766
  }
755
- return features.serial_no;
767
+ return (_b = features.serial_no) !== null && _b !== void 0 ? _b : '';
756
768
  };
757
769
  const getDeviceLabel = (features) => {
758
770
  const deviceType = getDeviceType(features);
@@ -811,6 +823,61 @@ const getPassphraseState = (features, commands) => __awaiter(void 0, void 0, voi
811
823
  });
812
824
 
813
825
  var nested = {
826
+ AptosGetAddress: {
827
+ fields: {
828
+ address_n: {
829
+ rule: "repeated",
830
+ type: "uint32",
831
+ id: 1,
832
+ options: {
833
+ packed: false
834
+ }
835
+ },
836
+ show_display: {
837
+ type: "bool",
838
+ id: 2
839
+ }
840
+ }
841
+ },
842
+ AptosAddress: {
843
+ fields: {
844
+ address: {
845
+ type: "string",
846
+ id: 1
847
+ }
848
+ }
849
+ },
850
+ AptosSignTx: {
851
+ fields: {
852
+ address_n: {
853
+ rule: "repeated",
854
+ type: "uint32",
855
+ id: 1,
856
+ options: {
857
+ packed: false
858
+ }
859
+ },
860
+ raw_tx: {
861
+ rule: "required",
862
+ type: "bytes",
863
+ id: 2
864
+ }
865
+ }
866
+ },
867
+ AptosSignedTx: {
868
+ fields: {
869
+ public_key: {
870
+ rule: "required",
871
+ type: "bytes",
872
+ id: 1
873
+ },
874
+ signature: {
875
+ rule: "required",
876
+ type: "bytes",
877
+ id: 2
878
+ }
879
+ }
880
+ },
814
881
  BinanceGetAddress: {
815
882
  fields: {
816
883
  address_n: {
@@ -3435,6 +3502,162 @@ var nested = {
3435
3502
  fields: {
3436
3503
  }
3437
3504
  },
3505
+ ConfluxGetAddress: {
3506
+ fields: {
3507
+ address_n: {
3508
+ rule: "repeated",
3509
+ type: "uint32",
3510
+ id: 1,
3511
+ options: {
3512
+ packed: false
3513
+ }
3514
+ },
3515
+ show_display: {
3516
+ type: "bool",
3517
+ id: 2
3518
+ },
3519
+ chain_id: {
3520
+ type: "uint32",
3521
+ id: 3
3522
+ }
3523
+ }
3524
+ },
3525
+ ConfluxAddress: {
3526
+ fields: {
3527
+ address: {
3528
+ type: "string",
3529
+ id: 1
3530
+ }
3531
+ }
3532
+ },
3533
+ ConfluxSignTx: {
3534
+ fields: {
3535
+ address_n: {
3536
+ rule: "repeated",
3537
+ type: "uint32",
3538
+ id: 1,
3539
+ options: {
3540
+ packed: false
3541
+ }
3542
+ },
3543
+ nonce: {
3544
+ type: "bytes",
3545
+ id: 2
3546
+ },
3547
+ gas_price: {
3548
+ type: "bytes",
3549
+ id: 3
3550
+ },
3551
+ gas_limit: {
3552
+ type: "bytes",
3553
+ id: 4
3554
+ },
3555
+ to: {
3556
+ type: "string",
3557
+ id: 5
3558
+ },
3559
+ value: {
3560
+ type: "bytes",
3561
+ id: 6
3562
+ },
3563
+ epoch_height: {
3564
+ type: "bytes",
3565
+ id: 7
3566
+ },
3567
+ storage_limit: {
3568
+ type: "bytes",
3569
+ id: 8
3570
+ },
3571
+ data_initial_chunk: {
3572
+ type: "bytes",
3573
+ id: 9
3574
+ },
3575
+ data_length: {
3576
+ type: "uint32",
3577
+ id: 10
3578
+ },
3579
+ chain_id: {
3580
+ type: "uint32",
3581
+ id: 11
3582
+ }
3583
+ }
3584
+ },
3585
+ ConfluxTxRequest: {
3586
+ fields: {
3587
+ data_length: {
3588
+ type: "uint32",
3589
+ id: 1
3590
+ },
3591
+ signature_v: {
3592
+ type: "uint32",
3593
+ id: 2
3594
+ },
3595
+ signature_r: {
3596
+ type: "bytes",
3597
+ id: 3
3598
+ },
3599
+ signature_s: {
3600
+ type: "bytes",
3601
+ id: 4
3602
+ }
3603
+ }
3604
+ },
3605
+ ConfluxTxAck: {
3606
+ fields: {
3607
+ data_chunk: {
3608
+ type: "bytes",
3609
+ id: 1
3610
+ }
3611
+ }
3612
+ },
3613
+ ConfluxSignMessage: {
3614
+ fields: {
3615
+ address_n: {
3616
+ rule: "repeated",
3617
+ type: "uint32",
3618
+ id: 1,
3619
+ options: {
3620
+ packed: false
3621
+ }
3622
+ },
3623
+ message: {
3624
+ type: "bytes",
3625
+ id: 2
3626
+ }
3627
+ }
3628
+ },
3629
+ ConfluxMessageSignature: {
3630
+ fields: {
3631
+ signature: {
3632
+ type: "bytes",
3633
+ id: 2
3634
+ },
3635
+ address: {
3636
+ type: "string",
3637
+ id: 3
3638
+ }
3639
+ }
3640
+ },
3641
+ ConfluxSignMessageCIP23: {
3642
+ fields: {
3643
+ address_n: {
3644
+ rule: "repeated",
3645
+ type: "uint32",
3646
+ id: 1,
3647
+ options: {
3648
+ packed: false
3649
+ }
3650
+ },
3651
+ domain_hash: {
3652
+ type: "bytes",
3653
+ id: 2
3654
+ },
3655
+ message_hash: {
3656
+ type: "bytes",
3657
+ id: 3
3658
+ }
3659
+ }
3660
+ },
3438
3661
  CipherKeyValue: {
3439
3662
  fields: {
3440
3663
  address_n: {
@@ -5121,6 +5344,10 @@ var nested = {
5121
5344
  coin_switch: {
5122
5345
  type: "uint32",
5123
5346
  id: 517
5347
+ },
5348
+ build_id: {
5349
+ type: "string",
5350
+ id: 518
5124
5351
  }
5125
5352
  },
5126
5353
  nested: {
@@ -6835,6 +7062,55 @@ var nested = {
6835
7062
  }
6836
7063
  }
6837
7064
  },
7065
+ NearGetAddress: {
7066
+ fields: {
7067
+ address_n: {
7068
+ rule: "repeated",
7069
+ type: "uint32",
7070
+ id: 1,
7071
+ options: {
7072
+ packed: false
7073
+ }
7074
+ },
7075
+ show_display: {
7076
+ type: "bool",
7077
+ id: 2
7078
+ }
7079
+ }
7080
+ },
7081
+ NearAddress: {
7082
+ fields: {
7083
+ address: {
7084
+ type: "string",
7085
+ id: 1
7086
+ }
7087
+ }
7088
+ },
7089
+ NearSignTx: {
7090
+ fields: {
7091
+ address_n: {
7092
+ rule: "repeated",
7093
+ type: "uint32",
7094
+ id: 1,
7095
+ options: {
7096
+ packed: false
7097
+ }
7098
+ },
7099
+ raw_tx: {
7100
+ type: "bytes",
7101
+ id: 2
7102
+ }
7103
+ }
7104
+ },
7105
+ NearSignedTx: {
7106
+ fields: {
7107
+ signature: {
7108
+ rule: "required",
7109
+ type: "bytes",
7110
+ id: 1
7111
+ }
7112
+ }
7113
+ },
6838
7114
  NEMGetAddress: {
6839
7115
  fields: {
6840
7116
  address_n: {
@@ -7351,6 +7627,7 @@ var nested = {
7351
7627
  }
7352
7628
  },
7353
7629
  raw_tx: {
7630
+ rule: "required",
7354
7631
  type: "bytes",
7355
7632
  id: 2
7356
7633
  }
@@ -8388,15 +8665,180 @@ var nested = {
8388
8665
  }
8389
8666
  }
8390
8667
  },
8391
- WebAuthnListResidentCredentials: {
8392
- fields: {
8393
- }
8394
- },
8395
- WebAuthnAddResidentCredential: {
8668
+ TronGetAddress: {
8396
8669
  fields: {
8397
- credential_id: {
8398
- type: "bytes",
8399
- id: 1
8670
+ address_n: {
8671
+ rule: "repeated",
8672
+ type: "uint32",
8673
+ id: 1,
8674
+ options: {
8675
+ packed: false
8676
+ }
8677
+ },
8678
+ show_display: {
8679
+ type: "bool",
8680
+ id: 2
8681
+ }
8682
+ }
8683
+ },
8684
+ TronAddress: {
8685
+ fields: {
8686
+ address: {
8687
+ type: "string",
8688
+ id: 1
8689
+ }
8690
+ }
8691
+ },
8692
+ TronSignTx: {
8693
+ fields: {
8694
+ address_n: {
8695
+ rule: "repeated",
8696
+ type: "uint32",
8697
+ id: 1,
8698
+ options: {
8699
+ packed: false
8700
+ }
8701
+ },
8702
+ ref_block_bytes: {
8703
+ rule: "required",
8704
+ type: "bytes",
8705
+ id: 2
8706
+ },
8707
+ ref_block_hash: {
8708
+ rule: "required",
8709
+ type: "bytes",
8710
+ id: 3
8711
+ },
8712
+ expiration: {
8713
+ rule: "required",
8714
+ type: "uint64",
8715
+ id: 4
8716
+ },
8717
+ data: {
8718
+ type: "string",
8719
+ id: 5
8720
+ },
8721
+ contract: {
8722
+ rule: "required",
8723
+ type: "TronContract",
8724
+ id: 6
8725
+ },
8726
+ timestamp: {
8727
+ rule: "required",
8728
+ type: "uint64",
8729
+ id: 7
8730
+ },
8731
+ fee_limit: {
8732
+ type: "uint64",
8733
+ id: 8
8734
+ }
8735
+ },
8736
+ nested: {
8737
+ TronContract: {
8738
+ fields: {
8739
+ transfer_contract: {
8740
+ type: "TronTransferContract",
8741
+ id: 2
8742
+ },
8743
+ trigger_smart_contract: {
8744
+ type: "TronTriggerSmartContract",
8745
+ id: 31
8746
+ }
8747
+ },
8748
+ nested: {
8749
+ TronTransferContract: {
8750
+ fields: {
8751
+ to_address: {
8752
+ type: "string",
8753
+ id: 2
8754
+ },
8755
+ amount: {
8756
+ type: "uint64",
8757
+ id: 3
8758
+ }
8759
+ }
8760
+ },
8761
+ TronTriggerSmartContract: {
8762
+ fields: {
8763
+ contract_address: {
8764
+ type: "string",
8765
+ id: 2
8766
+ },
8767
+ call_value: {
8768
+ type: "uint64",
8769
+ id: 3
8770
+ },
8771
+ data: {
8772
+ type: "bytes",
8773
+ id: 4
8774
+ },
8775
+ call_token_value: {
8776
+ type: "uint64",
8777
+ id: 5
8778
+ },
8779
+ asset_id: {
8780
+ type: "uint64",
8781
+ id: 6
8782
+ }
8783
+ }
8784
+ }
8785
+ }
8786
+ }
8787
+ }
8788
+ },
8789
+ TronSignedTx: {
8790
+ fields: {
8791
+ signature: {
8792
+ rule: "required",
8793
+ type: "bytes",
8794
+ id: 1
8795
+ },
8796
+ serialized_tx: {
8797
+ type: "bytes",
8798
+ id: 2
8799
+ }
8800
+ }
8801
+ },
8802
+ TronSignMessage: {
8803
+ fields: {
8804
+ address_n: {
8805
+ rule: "repeated",
8806
+ type: "uint32",
8807
+ id: 1,
8808
+ options: {
8809
+ packed: false
8810
+ }
8811
+ },
8812
+ message: {
8813
+ rule: "required",
8814
+ type: "bytes",
8815
+ id: 2
8816
+ }
8817
+ }
8818
+ },
8819
+ TronMessageSignature: {
8820
+ fields: {
8821
+ address: {
8822
+ rule: "required",
8823
+ type: "bytes",
8824
+ id: 1
8825
+ },
8826
+ signature: {
8827
+ rule: "required",
8828
+ type: "bytes",
8829
+ id: 2
8830
+ }
8831
+ }
8832
+ },
8833
+ WebAuthnListResidentCredentials: {
8834
+ fields: {
8835
+ }
8836
+ },
8837
+ WebAuthnAddResidentCredential: {
8838
+ fields: {
8839
+ credential_id: {
8840
+ type: "bytes",
8841
+ id: 1
8400
8842
  }
8401
8843
  }
8402
8844
  },
@@ -8783,6 +9225,20 @@ var nested = {
8783
9225
  MessageType_StarcoinSignMessage: 10306,
8784
9226
  MessageType_StarcoinMessageSignature: 10307,
8785
9227
  MessageType_StarcoinVerifyMessage: 10308,
9228
+ MessageType_ConfluxGetAddress: 10401,
9229
+ MessageType_ConfluxAddress: 10402,
9230
+ MessageType_ConfluxSignTx: 10403,
9231
+ MessageType_ConfluxTxRequest: 10404,
9232
+ MessageType_ConfluxTxAck: 10405,
9233
+ MessageType_ConfluxSignMessage: 10406,
9234
+ MessageType_ConfluxSignMessageCIP23: 10407,
9235
+ MessageType_ConfluxMessageSignature: 10408,
9236
+ MessageType_ConfluxVerifyMessage: 10409,
9237
+ MessageType_ConfluxVerifyMessageCIP23: 10410,
9238
+ MessageType_AptosGetAddress: 10600,
9239
+ MessageType_AptosAddress: 10601,
9240
+ MessageType_AptosSignTx: 10602,
9241
+ MessageType_AptosSignedTx: 10603,
8786
9242
  MessageType_WebAuthnListResidentCredentials: 800,
8787
9243
  MessageType_WebAuthnCredentials: 801,
8788
9244
  MessageType_WebAuthnAddResidentCredential: 802,
@@ -8806,6 +9262,16 @@ var nested = {
8806
9262
  MessageType_EthereumSignMessageEIP712: 10200,
8807
9263
  MessageType_GetPublicKeyMultiple: 10210,
8808
9264
  MessageType_PublicKeyMultiple: 10211,
9265
+ MessageType_TronGetAddress: 10501,
9266
+ MessageType_TronAddress: 10502,
9267
+ MessageType_TronSignTx: 10503,
9268
+ MessageType_TronSignedTx: 10504,
9269
+ MessageType_TronSignMessage: 10505,
9270
+ MessageType_TronMessageSignature: 10506,
9271
+ MessageType_NearGetAddress: 10701,
9272
+ MessageType_NearAddress: 10702,
9273
+ MessageType_NearSignTx: 10703,
9274
+ MessageType_NearSignedTx: 10704,
8809
9275
  MessageType_DeviceInfoSettings: 10001,
8810
9276
  MessageType_GetDeviceInfo: 10002,
8811
9277
  MessageType_DeviceInfo: 10003,
@@ -10427,19 +10893,19 @@ class DeviceCommands {
10427
10893
  const { code } = res.message;
10428
10894
  const { message } = res.message;
10429
10895
  let error = null;
10430
- if (code === 'Failure_FirmwareError' && !message) {
10896
+ if (code === FailureType.Failure_FirmwareError && !message) {
10431
10897
  error = ERRORS.TypedError(HardwareErrorCode.FirmwareError);
10432
10898
  }
10433
- if (code === 'Failure_ActionCancelled') {
10899
+ if (code === FailureType.Failure_ActionCancelled) {
10434
10900
  error = ERRORS.TypedError(HardwareErrorCode.ActionCancelled);
10435
10901
  }
10436
- if (code === 'Failure_PinInvalid') {
10902
+ if (code === FailureType.Failure_PinInvalid) {
10437
10903
  error = ERRORS.TypedError(HardwareErrorCode.PinInvalid, message);
10438
10904
  }
10439
- if (code === 'Failure_PinCancelled') {
10905
+ if (code === FailureType.Failure_PinCancelled) {
10440
10906
  error = ERRORS.TypedError(HardwareErrorCode.PinCancelled);
10441
10907
  }
10442
- if (code === 'Failure_DataError' && message === 'Please confirm the BlindSign enabled') {
10908
+ if (code === FailureType.Failure_DataError && message === 'Please confirm the BlindSign enabled') {
10443
10909
  error = ERRORS.TypedError(HardwareErrorCode.BlindSignDisabled);
10444
10910
  }
10445
10911
  if (error) {
@@ -11113,7 +11579,8 @@ class BaseMethod {
11113
11579
  if (deviceType !== 'touch')
11114
11580
  return;
11115
11581
  let checkFlag = false;
11116
- if (this.name === 'evmSignTransaction' && Number((_b = (_a = this.payload) === null || _a === void 0 ? void 0 : _a.transaction) === null || _b === void 0 ? void 0 : _b.chainId) !== 1) {
11582
+ if (this.name === 'evmSignTransaction' &&
11583
+ [3, 4, 5, 42].includes(Number((_b = (_a = this.payload) === null || _a === void 0 ? void 0 : _a.transaction) === null || _b === void 0 ? void 0 : _b.chainId))) {
11117
11584
  checkFlag = true;
11118
11585
  }
11119
11586
  if (checkFlag && ((_c = this.device.features) === null || _c === void 0 ? void 0 : _c.safety_checks) === 'Strict') {
@@ -11161,68 +11628,191 @@ class GetFeatures extends BaseMethod {
11161
11628
  }
11162
11629
  }
11163
11630
 
11164
- const hasHexPrefix = (str) => str.slice(0, 2).toLowerCase() === '0x';
11165
- const stripHexPrefix = (str) => (hasHexPrefix(str) ? str.slice(2) : str);
11166
- const addHexPrefix = (str) => (hasHexPrefix(str) ? str : `0x${str}`);
11167
- const isHexString = (value, length) => {
11168
- if (typeof value !== 'string' || !value.match(/^(0x|0X)?[0-9A-Fa-f]*$/)) {
11169
- return false;
11631
+ class GetPassphraseState extends BaseMethod {
11632
+ init() {
11633
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
11634
+ this.useDevicePassphraseState = false;
11170
11635
  }
11171
- if (length && value.length !== 2 + 2 * length) {
11172
- return false;
11636
+ run() {
11637
+ var _a, _b;
11638
+ return __awaiter(this, void 0, void 0, function* () {
11639
+ if (!this.device.features)
11640
+ return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed));
11641
+ let { features } = this.device;
11642
+ const locked = ((_b = (_a = this.device) === null || _a === void 0 ? void 0 : _a.features) === null || _b === void 0 ? void 0 : _b.unlocked) === true;
11643
+ const passphraseState = yield getPassphraseState(this.device.features, this.device.commands);
11644
+ const isModeT = getDeviceType(features) === 'touch' || getDeviceType(features) === 'pro';
11645
+ if (isModeT && locked) {
11646
+ const { message } = yield this.device.commands.typedCall('GetFeatures', 'Features', {});
11647
+ features = message;
11648
+ }
11649
+ if (features && features.passphrase_protection === true) {
11650
+ return Promise.resolve(passphraseState);
11651
+ }
11652
+ return Promise.resolve(undefined);
11653
+ });
11173
11654
  }
11174
- return true;
11175
- };
11176
- const stripHexStartZeroes = (str) => {
11177
- while (/^00/.test(str)) {
11178
- str = str.slice(2);
11655
+ }
11656
+
11657
+ class CheckBridgeStatus$1 extends BaseMethod {
11658
+ init() {
11659
+ this.useDevice = false;
11660
+ this.useDevicePassphraseState = false;
11179
11661
  }
11180
- return str;
11181
- };
11182
- const modifyValues = (object, transformer) => Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transformer(value, key)]));
11183
- const formatAnyHex = value => {
11184
- if (typeof value === 'string') {
11185
- let stripped = stripHexPrefix(value);
11186
- if (stripped.length % 2 !== 0) {
11187
- stripped = `0${stripped}`;
11188
- }
11189
- return stripped;
11662
+ run() {
11663
+ return __awaiter(this, void 0, void 0, function* () {
11664
+ const logs = getLog();
11665
+ return Promise.resolve(logs);
11666
+ });
11190
11667
  }
11191
- if (Array.isArray(value)) {
11192
- return value.map(formatAnyHex);
11668
+ }
11669
+
11670
+ class CheckFirmwareRelease extends BaseMethod {
11671
+ init() {
11672
+ this.useDevicePassphraseState = false;
11193
11673
  }
11194
- if (typeof value === 'object') {
11195
- return modifyValues(value, value => formatAnyHex(value));
11674
+ run() {
11675
+ if (this.device.features) {
11676
+ const releaseInfo = getFirmwareReleaseInfo(this.device.features);
11677
+ return Promise.resolve(releaseInfo);
11678
+ }
11679
+ return Promise.resolve(null);
11196
11680
  }
11197
- return value;
11198
- };
11681
+ }
11199
11682
 
11200
- const invalidParameter = (message) => ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, message);
11201
- const validateParams = (values, fields) => {
11202
- fields.forEach(field => {
11203
- const existsProp = Object.prototype.hasOwnProperty.call(values, field.name);
11204
- if (!existsProp && field.required) {
11205
- throw invalidParameter(`Missing required parameter: ${field.name}`);
11683
+ class CheckBLEFirmwareRelease extends BaseMethod {
11684
+ init() {
11685
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.BOOTLOADER];
11686
+ this.checkDeviceId = true;
11687
+ this.useDevicePassphraseState = false;
11688
+ }
11689
+ run() {
11690
+ if (this.device.features) {
11691
+ const releaseInfo = getBleFirmwareReleaseInfo(this.device.features);
11692
+ return Promise.resolve(releaseInfo);
11206
11693
  }
11207
- const value = values[field.name];
11208
- if (value && field.type) {
11209
- switch (field.type) {
11210
- case 'array':
11211
- if (!Array.isArray(value)) {
11212
- throw invalidParameter(`Parameter [${field.name}] is of type invalid and should be [${field.type}].`);
11213
- }
11214
- else if (!field.allowEmpty && value.length < 1) {
11215
- throw invalidParameter(`Parameter "${field.name}" is empty.`);
11216
- }
11217
- break;
11218
- case 'bigNumber':
11219
- if (typeof value !== 'string') {
11220
- throw invalidParameter(`Parameter [${field.name}] is of type invalid and should be [string].`);
11221
- }
11222
- try {
11223
- const bn = new BigNumber(value);
11224
- if (bn.toFixed(0) !== value) {
11225
- throw new Error('');
11694
+ return Promise.resolve(null);
11695
+ }
11696
+ }
11697
+
11698
+ class CheckTransportRelease extends BaseMethod {
11699
+ init() {
11700
+ this.useDevice = false;
11701
+ this.useDevicePassphraseState = false;
11702
+ }
11703
+ run() {
11704
+ return __awaiter(this, void 0, void 0, function* () {
11705
+ const transport = TransportManager.getTransport();
11706
+ const localVersion = yield transport.init();
11707
+ const response = DataManager.getTransportStatus(localVersion);
11708
+ return Promise.resolve(response);
11709
+ });
11710
+ }
11711
+ }
11712
+
11713
+ class CheckBridgeStatus extends BaseMethod {
11714
+ init() {
11715
+ this.useDevice = false;
11716
+ this.useDevicePassphraseState = false;
11717
+ }
11718
+ run() {
11719
+ return __awaiter(this, void 0, void 0, function* () {
11720
+ return new Promise((resolve, reject) => {
11721
+ axios
11722
+ .request({
11723
+ url: 'http://localhost:21320',
11724
+ method: 'POST',
11725
+ withCredentials: false,
11726
+ timeout: 3000,
11727
+ })
11728
+ .then(() => resolve(true))
11729
+ .catch(e => {
11730
+ if (e.code === 'ECONNABORTED') {
11731
+ reject(ERRORS.TypedError(HardwareErrorCode.BridgeTimeoutError));
11732
+ }
11733
+ else {
11734
+ resolve(false);
11735
+ }
11736
+ });
11737
+ });
11738
+ });
11739
+ }
11740
+ }
11741
+
11742
+ class DeviceBackup extends BaseMethod {
11743
+ init() {
11744
+ this.useDevicePassphraseState = false;
11745
+ }
11746
+ run() {
11747
+ return __awaiter(this, void 0, void 0, function* () {
11748
+ const res = yield this.device.commands.typedCall('BackupDevice', 'Success');
11749
+ return Promise.resolve(res.message);
11750
+ });
11751
+ }
11752
+ }
11753
+
11754
+ const hasHexPrefix = (str) => str.slice(0, 2).toLowerCase() === '0x';
11755
+ const stripHexPrefix = (str) => (hasHexPrefix(str) ? str.slice(2) : str);
11756
+ const addHexPrefix = (str) => (hasHexPrefix(str) ? str : `0x${str}`);
11757
+ const isHexString = (value, length) => {
11758
+ if (typeof value !== 'string' || !value.match(/^(0x|0X)?[0-9A-Fa-f]*$/)) {
11759
+ return false;
11760
+ }
11761
+ if (length && value.length !== 2 + 2 * length) {
11762
+ return false;
11763
+ }
11764
+ return true;
11765
+ };
11766
+ const stripHexStartZeroes = (str) => {
11767
+ while (/^00/.test(str)) {
11768
+ str = str.slice(2);
11769
+ }
11770
+ return str;
11771
+ };
11772
+ const modifyValues = (object, transformer) => Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transformer(value, key)]));
11773
+ const formatAnyHex = value => {
11774
+ if (typeof value === 'string') {
11775
+ let stripped = stripHexPrefix(value);
11776
+ if (stripped.length % 2 !== 0) {
11777
+ stripped = `0${stripped}`;
11778
+ }
11779
+ return stripped;
11780
+ }
11781
+ if (Array.isArray(value)) {
11782
+ return value.map(formatAnyHex);
11783
+ }
11784
+ if (typeof value === 'object') {
11785
+ return modifyValues(value, value => formatAnyHex(value));
11786
+ }
11787
+ return value;
11788
+ };
11789
+
11790
+ const invalidParameter = (message) => ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, message);
11791
+ const validateParams = (values, fields) => {
11792
+ fields.forEach(field => {
11793
+ const existsProp = Object.prototype.hasOwnProperty.call(values, field.name);
11794
+ if (!existsProp && field.required) {
11795
+ throw invalidParameter(`Missing required parameter: ${field.name}`);
11796
+ }
11797
+ const value = values[field.name];
11798
+ if (value && field.type) {
11799
+ switch (field.type) {
11800
+ case 'array':
11801
+ if (!Array.isArray(value)) {
11802
+ throw invalidParameter(`Parameter [${field.name}] is of type invalid and should be [${field.type}].`);
11803
+ }
11804
+ else if (!field.allowEmpty && value.length < 1) {
11805
+ throw invalidParameter(`Parameter "${field.name}" is empty.`);
11806
+ }
11807
+ break;
11808
+ case 'bigNumber':
11809
+ if (typeof value !== 'string') {
11810
+ throw invalidParameter(`Parameter [${field.name}] is of type invalid and should be [string].`);
11811
+ }
11812
+ try {
11813
+ const bn = new BigNumber(value);
11814
+ if (bn.toFixed(0) !== value) {
11815
+ throw new Error('');
11226
11816
  }
11227
11817
  }
11228
11818
  catch (error) {
@@ -11247,8 +11837,404 @@ const validateParams = (values, fields) => {
11247
11837
  break;
11248
11838
  }
11249
11839
  }
11250
- });
11251
- };
11840
+ });
11841
+ };
11842
+
11843
+ class DeviceChangePin extends BaseMethod {
11844
+ init() {
11845
+ this.useDevicePassphraseState = false;
11846
+ validateParams(this.payload, [{ name: 'remove', type: 'boolean' }]);
11847
+ this.params = {
11848
+ remove: this.payload.remove,
11849
+ };
11850
+ }
11851
+ run() {
11852
+ return __awaiter(this, void 0, void 0, function* () {
11853
+ const res = yield this.device.commands.typedCall('ChangePin', 'Success', Object.assign({}, this.params));
11854
+ return Promise.resolve(res.message);
11855
+ });
11856
+ }
11857
+ }
11858
+
11859
+ class DeviceFlags extends BaseMethod {
11860
+ init() {
11861
+ this.useDevicePassphraseState = false;
11862
+ validateParams(this.payload, [{ name: 'flags', type: 'number' }]);
11863
+ this.params = {
11864
+ flags: this.payload.flags,
11865
+ };
11866
+ }
11867
+ run() {
11868
+ return __awaiter(this, void 0, void 0, function* () {
11869
+ const res = yield this.device.commands.typedCall('ApplyFlags', 'Success', Object.assign({}, this.params));
11870
+ return Promise.resolve(res.message);
11871
+ });
11872
+ }
11873
+ }
11874
+
11875
+ class DeviceRebootToBootloader extends BaseMethod {
11876
+ init() {
11877
+ this.useDevicePassphraseState = false;
11878
+ }
11879
+ getVersionRange() {
11880
+ return {
11881
+ classic: {
11882
+ min: '2.1.11',
11883
+ },
11884
+ mini: {
11885
+ min: '2.1.11',
11886
+ },
11887
+ };
11888
+ }
11889
+ run() {
11890
+ return __awaiter(this, void 0, void 0, function* () {
11891
+ const res = yield this.device.commands.typedCall('RebootToBootloader', 'Success');
11892
+ return Promise.resolve(res.message);
11893
+ });
11894
+ }
11895
+ }
11896
+
11897
+ class DeviceRecovery extends BaseMethod {
11898
+ init() {
11899
+ this.useDevicePassphraseState = false;
11900
+ validateParams(this.payload, [
11901
+ { name: 'wordCount', type: 'number' },
11902
+ { name: 'passphraseProtection', type: 'boolean' },
11903
+ { name: 'pinProtection', type: 'boolean' },
11904
+ { name: 'language', type: 'string' },
11905
+ { name: 'label', type: 'string' },
11906
+ { name: 'enforceWordlist', type: 'boolean' },
11907
+ { name: 'type', type: 'object' },
11908
+ { name: 'u2fCounter', type: 'number' },
11909
+ { name: 'dryRun', type: 'boolean' },
11910
+ ]);
11911
+ this.params = {
11912
+ word_count: this.payload.wordCount,
11913
+ passphrase_protection: this.payload.passphraseProtection,
11914
+ pin_protection: this.payload.pinProtection,
11915
+ language: this.payload.language,
11916
+ label: this.payload.label,
11917
+ enforce_wordlist: this.payload.enforceWordlist,
11918
+ type: this.payload.type,
11919
+ u2f_counter: this.payload.u2fCounter || Math.floor(Date.now() / 1000),
11920
+ dry_run: this.payload.dryRun,
11921
+ };
11922
+ }
11923
+ run() {
11924
+ return __awaiter(this, void 0, void 0, function* () {
11925
+ const res = yield this.device.commands.typedCall('RecoveryDevice', 'Success', Object.assign({}, this.params));
11926
+ return Promise.resolve(res.message);
11927
+ });
11928
+ }
11929
+ }
11930
+
11931
+ class DeviceReset extends BaseMethod {
11932
+ init() {
11933
+ this.useDevicePassphraseState = false;
11934
+ validateParams(this.payload, [
11935
+ { name: 'displayRandom', type: 'boolean' },
11936
+ { name: 'strength', type: 'number' },
11937
+ { name: 'passphraseProtection', type: 'boolean' },
11938
+ { name: 'pinProtection', type: 'boolean' },
11939
+ { name: 'language', type: 'string' },
11940
+ { name: 'label', type: 'string' },
11941
+ { name: 'u2fCounter', type: 'number' },
11942
+ { name: 'skipBackup', type: 'boolean' },
11943
+ { name: 'noBackup', type: 'boolean' },
11944
+ { name: 'backupType' },
11945
+ ]);
11946
+ this.params = {
11947
+ display_random: this.payload.displayRandom,
11948
+ strength: this.payload.strength || 256,
11949
+ passphrase_protection: this.payload.passphraseProtection,
11950
+ pin_protection: this.payload.pinProtection,
11951
+ language: this.payload.language,
11952
+ label: this.payload.label,
11953
+ u2f_counter: this.payload.u2fCounter || Math.floor(Date.now() / 1000),
11954
+ skip_backup: this.payload.skipBackup,
11955
+ no_backup: this.payload.noBackup,
11956
+ backup_type: this.payload.backupType,
11957
+ };
11958
+ }
11959
+ run() {
11960
+ return __awaiter(this, void 0, void 0, function* () {
11961
+ const res = yield this.device.commands.typedCall('ResetDevice', 'Success', Object.assign({}, this.params));
11962
+ return Promise.resolve(res.message);
11963
+ });
11964
+ }
11965
+ }
11966
+
11967
+ class DeviceSettings extends BaseMethod {
11968
+ init() {
11969
+ this.useDevicePassphraseState = false;
11970
+ validateParams(this.payload, [
11971
+ { name: 'language', type: 'string' },
11972
+ { name: 'label', type: 'string' },
11973
+ { name: 'usePassphrase', type: 'boolean' },
11974
+ { name: 'homescreen', type: 'string' },
11975
+ { name: 'passphraseSource', type: 'number' },
11976
+ { name: 'autoLockDelayMs', type: 'number' },
11977
+ { name: 'displayRotation', type: 'number' },
11978
+ { name: 'passphraseAlwaysOnDevice', type: 'boolean' },
11979
+ { name: 'safetyChecks', type: 'number' },
11980
+ { name: 'experimentalFeatures', type: 'boolean' },
11981
+ ]);
11982
+ this.params = {
11983
+ language: this.payload.language,
11984
+ label: this.payload.label,
11985
+ use_passphrase: this.payload.usePassphrase,
11986
+ homescreen: this.payload.homescreen,
11987
+ _passphrase_source: this.payload.passphraseSource,
11988
+ auto_lock_delay_ms: this.payload.autoLockDelayMs,
11989
+ display_rotation: this.payload.displayRotation,
11990
+ passphrase_always_on_device: this.payload.passphraseAlwaysOnDevice,
11991
+ safety_checks: this.payload.safetyChecks,
11992
+ experimental_features: this.payload.experimentalFeatures,
11993
+ };
11994
+ }
11995
+ getVersionRange() {
11996
+ if (this.payload.usePassphrase) {
11997
+ return {
11998
+ model_mini: {
11999
+ min: '2.4.0',
12000
+ },
12001
+ };
12002
+ }
12003
+ return {};
12004
+ }
12005
+ run() {
12006
+ return __awaiter(this, void 0, void 0, function* () {
12007
+ const res = yield this.device.commands.typedCall('ApplySettings', 'Success', Object.assign({}, this.params));
12008
+ return Promise.resolve(res.message);
12009
+ });
12010
+ }
12011
+ }
12012
+
12013
+ class DeviceUpdateReboot extends BaseMethod {
12014
+ init() {
12015
+ this.useDevicePassphraseState = false;
12016
+ }
12017
+ run() {
12018
+ return __awaiter(this, void 0, void 0, function* () {
12019
+ const res = yield this.device.commands.typedCall('BixinReboot', 'Success');
12020
+ return Promise.resolve(res.message);
12021
+ });
12022
+ }
12023
+ }
12024
+
12025
+ class DeviceSupportFeatures extends BaseMethod {
12026
+ init() {
12027
+ this.useDevicePassphraseState = false;
12028
+ }
12029
+ run() {
12030
+ if (!this.device.features)
12031
+ return Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Device not initialized'));
12032
+ const inputPinOnSoftware = supportInputPinOnSoftware(this.device.features);
12033
+ return Promise.resolve({
12034
+ inputPinOnSoftware,
12035
+ device: this.device.toMessageObject(),
12036
+ });
12037
+ }
12038
+ }
12039
+
12040
+ class DeviceVerify extends BaseMethod {
12041
+ init() {
12042
+ this.useDevicePassphraseState = false;
12043
+ validateParams(this.payload, [{ name: 'dataHex', type: 'hexString' }]);
12044
+ this.params = {
12045
+ data: formatAnyHex(this.payload.dataHex),
12046
+ };
12047
+ }
12048
+ run() {
12049
+ return __awaiter(this, void 0, void 0, function* () {
12050
+ const deviceType = getDeviceType(this.device.features);
12051
+ let response;
12052
+ if (deviceType === 'classic') {
12053
+ const res = yield this.device.commands.typedCall('BixinVerifyDeviceRequest', 'BixinVerifyDeviceAck', Object.assign(Object.assign({}, this.params), { data: sha256.sha256(this.params.data) }));
12054
+ response = res.message;
12055
+ }
12056
+ else {
12057
+ const signatureRes = yield this.device.commands.typedCall('SESignMessage', 'SEMessageSignature', {
12058
+ message: this.params.data,
12059
+ });
12060
+ const certRes = yield this.device.commands.typedCall('ReadSEPublicCert', 'SEPublicCert');
12061
+ response = {
12062
+ cert: certRes.message.public_cert,
12063
+ signature: signatureRes.message.signature,
12064
+ };
12065
+ }
12066
+ if (response)
12067
+ return Promise.resolve(response);
12068
+ return Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Device not support verify'));
12069
+ });
12070
+ }
12071
+ }
12072
+
12073
+ class DeviceWipe extends BaseMethod {
12074
+ init() {
12075
+ this.useDevicePassphraseState = false;
12076
+ }
12077
+ run() {
12078
+ return __awaiter(this, void 0, void 0, function* () {
12079
+ const res = yield this.device.commands.typedCall('WipeDevice', 'Success');
12080
+ return Promise.resolve(res.message);
12081
+ });
12082
+ }
12083
+ }
12084
+
12085
+ const getBinary = ({ features, updateType, version }) => __awaiter(void 0, void 0, void 0, function* () {
12086
+ const releaseInfo = getInfo({ features, updateType });
12087
+ if (!releaseInfo) {
12088
+ throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'no firmware found for this device');
12089
+ }
12090
+ if (version &&
12091
+ !semver.eq(releaseInfo.version, version)) {
12092
+ throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'firmware version mismatch');
12093
+ }
12094
+ const url = updateType === 'ble' ? releaseInfo.webUpdate : releaseInfo.url;
12095
+ let fw;
12096
+ try {
12097
+ fw = yield httpRequest(url, 'binary');
12098
+ }
12099
+ catch (_a) {
12100
+ throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Method_FirmwareUpdate_DownloadFailed');
12101
+ }
12102
+ return Object.assign(Object.assign({}, releaseInfo), { binary: fw });
12103
+ });
12104
+ const getInfo = ({ features, updateType }) => {
12105
+ var _a, _b, _c;
12106
+ const deviceType = getDeviceType(features);
12107
+ const { deviceMap } = DataManager;
12108
+ const releaseInfo = (_c = (_b = (_a = deviceMap === null || deviceMap === void 0 ? void 0 : deviceMap[deviceType]) === null || _a === void 0 ? void 0 : _a[updateType]) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : null;
12109
+ return releaseInfo;
12110
+ };
12111
+
12112
+ const postConfirmationMessage = (device) => {
12113
+ var _a;
12114
+ if ((_a = device.features) === null || _a === void 0 ? void 0 : _a.firmware_present) {
12115
+ device.emit(DEVICE.BUTTON, device, { code: 'ButtonRequest_FirmwareUpdate' });
12116
+ }
12117
+ };
12118
+ const postProgressMessage = (device, progress, postMessage) => {
12119
+ postMessage(createUiMessage(UI_REQUEST$1.FIRMWARE_PROGRESS, {
12120
+ device: device.toMessageObject(),
12121
+ progress,
12122
+ }));
12123
+ };
12124
+ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload }) => __awaiter(void 0, void 0, void 0, function* () {
12125
+ var _a, _b;
12126
+ if (((_a = device.features) === null || _a === void 0 ? void 0 : _a.major_version) === 1) {
12127
+ postConfirmationMessage(device);
12128
+ const eraseCommand = updateType === 'firmware' ? 'FirmwareErase' : 'FirmwareErase_ex';
12129
+ yield typedCall(eraseCommand, 'Success', {});
12130
+ postProgressMessage(device, 0, postMessage);
12131
+ const { message } = yield typedCall('FirmwareUpload', 'Success', {
12132
+ payload,
12133
+ });
12134
+ postProgressMessage(device, 100, postMessage);
12135
+ return message;
12136
+ }
12137
+ if (((_b = device.features) === null || _b === void 0 ? void 0 : _b.major_version) === 2) {
12138
+ postConfirmationMessage(device);
12139
+ const length = payload.byteLength;
12140
+ let response = yield typedCall('FirmwareErase', ['FirmwareRequest', 'Success'], { length });
12141
+ while (response.type !== 'Success') {
12142
+ const start = response.message.offset;
12143
+ const end = response.message.offset + response.message.length;
12144
+ const chunk = payload.slice(start, end);
12145
+ if (start > 0) {
12146
+ postProgressMessage(device, Math.round((start / length) * 100), postMessage);
12147
+ }
12148
+ response = yield typedCall('FirmwareUpload', ['FirmwareRequest', 'Success'], {
12149
+ payload: chunk,
12150
+ });
12151
+ }
12152
+ postProgressMessage(device, 100, postMessage);
12153
+ return response.message;
12154
+ }
12155
+ throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown major_version');
12156
+ });
12157
+
12158
+ class FirmwareUpdate extends BaseMethod {
12159
+ init() {
12160
+ this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.INITIALIZE];
12161
+ this.requireDeviceMode = [UI_REQUEST.BOOTLOADER];
12162
+ this.useDevicePassphraseState = false;
12163
+ const { payload } = this;
12164
+ validateParams(payload, [
12165
+ { name: 'version', type: 'array' },
12166
+ { name: 'binary', type: 'buffer' },
12167
+ ]);
12168
+ if (!payload.updateType) {
12169
+ throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'updateType is required');
12170
+ }
12171
+ this.params = { updateType: payload.updateType };
12172
+ if ('version' in payload) {
12173
+ this.params = Object.assign(Object.assign({}, this.params), { version: payload.version });
12174
+ }
12175
+ if ('binary' in payload) {
12176
+ this.params = Object.assign(Object.assign({}, this.params), { binary: payload.binary });
12177
+ }
12178
+ }
12179
+ run() {
12180
+ var _a;
12181
+ return __awaiter(this, void 0, void 0, function* () {
12182
+ const { device, params } = this;
12183
+ let binary;
12184
+ try {
12185
+ if (params.binary) {
12186
+ binary = this.params.binary;
12187
+ }
12188
+ else {
12189
+ if (!device.features) {
12190
+ throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'no features found for this device');
12191
+ }
12192
+ const firmware = yield getBinary({
12193
+ features: device.features,
12194
+ version: params.version,
12195
+ updateType: params.updateType,
12196
+ });
12197
+ binary = firmware.binary;
12198
+ }
12199
+ }
12200
+ catch (err) {
12201
+ throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateDownloadFailed, (_a = err.message) !== null && _a !== void 0 ? _a : err);
12202
+ }
12203
+ return uploadFirmware(params.updateType, this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, { payload: binary });
12204
+ });
12205
+ }
12206
+ }
12207
+
12208
+ const Log$2 = getLogger(LoggerNames.Method);
12209
+ class RequestWebUsbDevice extends BaseMethod {
12210
+ init() {
12211
+ this.useDevice = false;
12212
+ this.useDevicePassphraseState = false;
12213
+ }
12214
+ run() {
12215
+ var _a, _b;
12216
+ return __awaiter(this, void 0, void 0, function* () {
12217
+ yield TransportManager.configure();
12218
+ const env = DataManager.getSettings('env');
12219
+ if (env !== 'webusb') {
12220
+ return Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Not webusb environment'));
12221
+ }
12222
+ try {
12223
+ const deviceDiff = yield ((_a = this.connector) === null || _a === void 0 ? void 0 : _a.enumerate());
12224
+ const devicesDescriptor = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
12225
+ const { deviceList } = yield DevicePool.getDevices(devicesDescriptor);
12226
+ if (deviceList.length > 0) {
12227
+ return { device: deviceList[0].toMessageObject() };
12228
+ }
12229
+ return yield Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Please select the device to connect'));
12230
+ }
12231
+ catch (error) {
12232
+ Log$2.debug(error);
12233
+ return Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Please select the device to connect'));
12234
+ }
12235
+ });
12236
+ }
12237
+ }
11252
12238
 
11253
12239
  class CipherKeyValue extends BaseMethod {
11254
12240
  constructor() {
@@ -11973,419 +12959,298 @@ class BTCSignTransaction extends BaseMethod {
11973
12959
  { name: 'extra_data', type: 'string' },
11974
12960
  { name: 'timestamp', type: 'number' },
11975
12961
  { name: 'version_group_id', type: 'number' },
11976
- ]);
11977
- });
11978
- this.payload.inputs.forEach((input) => {
11979
- validatePath(input.address_n);
11980
- const useAmount = isSegwitPath(input.address_n);
11981
- validateParams(input, [
11982
- { name: 'prev_hash', type: 'hexString', required: true },
11983
- { name: 'prev_index', type: 'number', required: true },
11984
- { name: 'script_type', type: 'string' },
11985
- { name: 'amount', type: 'string', required: useAmount },
11986
- { name: 'sequence', type: 'number' },
11987
- { name: 'multisig', type: 'object' },
11988
- ]);
11989
- });
11990
- this.payload.outputs.forEach((output) => {
11991
- validateParams(output, [
11992
- { name: 'address_n', type: 'array' },
11993
- { name: 'address', type: 'string' },
11994
- { name: 'amount', type: 'string' },
11995
- { name: 'op_return_data', type: 'string' },
11996
- { name: 'multisig', type: 'object' },
11997
- ]);
11998
- if (Object.prototype.hasOwnProperty.call(output, 'address_n') &&
11999
- Object.prototype.hasOwnProperty.call(output, 'address')) {
12000
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'Cannot use address and address_n in one output');
12001
- }
12002
- if (output.address_n) {
12003
- const scriptType = getOutputScriptType(output.address_n);
12004
- if (output.script_type !== scriptType)
12005
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, `Output change script_type should be set to ${scriptType}`);
12006
- }
12007
- });
12008
- const { inputs, outputs, refTxs, account, coin } = this.payload;
12009
- const coinName = getCoinInfo(undefined, coin).name;
12010
- this.params = {
12011
- inputs,
12012
- outputs,
12013
- refTxs,
12014
- addresses: account ? account.addresses : undefined,
12015
- options: {
12016
- lock_time: this.payload.locktime,
12017
- timestamp: this.payload.timestamp,
12018
- version: this.payload.version,
12019
- expiry: this.payload.expiry,
12020
- overwintered: this.payload.overwintered,
12021
- version_group_id: this.payload.versionGroupId,
12022
- branch_id: this.payload.branchId,
12023
- },
12024
- coinName,
12025
- };
12026
- }
12027
- run() {
12028
- return __awaiter(this, void 0, void 0, function* () {
12029
- const { device, params } = this;
12030
- const useLegacySignProcess = device.unavailableCapabilities.replaceTransaction;
12031
- const { refTxs } = params;
12032
- const signTxMethod = !useLegacySignProcess ? signtx : signtxLegacy;
12033
- const response = yield signTxMethod(device.commands.typedCall.bind(device.commands), params.inputs, params.outputs, refTxs, params.options, params.coinName);
12034
- return response;
12035
- });
12036
- }
12037
- }
12038
-
12039
- class BTCVerifyMessage extends BaseMethod {
12040
- init() {
12041
- this.checkDeviceId = true;
12042
- this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12043
- validateParams(this.payload, [
12044
- { name: 'address', type: 'string', required: true },
12045
- { name: 'messageHex', type: 'hexString', required: true },
12046
- { name: 'signature', type: 'hexString', required: true },
12047
- { name: 'coin', type: 'string', required: true },
12048
- ]);
12049
- const { coin } = this.payload;
12050
- const { address, messageHex, signature } = formatAnyHex(this.payload);
12051
- const coinName = getCoinInfo(undefined, coin).name;
12052
- this.params = {
12053
- address,
12054
- message: messageHex,
12055
- signature,
12056
- coin_name: coinName,
12057
- };
12058
- }
12059
- run() {
12060
- return __awaiter(this, void 0, void 0, function* () {
12061
- const res = yield this.device.commands.typedCall('VerifyMessage', 'Success', Object.assign({}, this.params));
12062
- return Promise.resolve(res.message);
12063
- });
12064
- }
12065
- }
12066
-
12067
- class CheckFirmwareRelease extends BaseMethod {
12068
- init() {
12069
- this.useDevicePassphraseState = false;
12070
- }
12071
- run() {
12072
- if (this.device.features) {
12073
- const releaseInfo = getFirmwareReleaseInfo(this.device.features);
12074
- return Promise.resolve(releaseInfo);
12075
- }
12076
- return Promise.resolve(null);
12077
- }
12078
- }
12079
-
12080
- class CheckBLEFirmwareRelease extends BaseMethod {
12081
- init() {
12082
- this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.BOOTLOADER];
12083
- this.checkDeviceId = true;
12084
- this.useDevicePassphraseState = false;
12085
- }
12086
- run() {
12087
- if (this.device.features) {
12088
- const releaseInfo = getBleFirmwareReleaseInfo(this.device.features);
12089
- return Promise.resolve(releaseInfo);
12090
- }
12091
- return Promise.resolve(null);
12092
- }
12093
- }
12094
-
12095
- class CheckTransportRelease extends BaseMethod {
12096
- init() {
12097
- this.useDevice = false;
12098
- this.useDevicePassphraseState = false;
12099
- }
12100
- run() {
12101
- return __awaiter(this, void 0, void 0, function* () {
12102
- const transport = TransportManager.getTransport();
12103
- const localVersion = yield transport.init();
12104
- const response = DataManager.getTransportStatus(localVersion);
12105
- return Promise.resolve(response);
12106
- });
12107
- }
12108
- }
12109
-
12110
- class CheckBridgeStatus$1 extends BaseMethod {
12111
- init() {
12112
- this.useDevice = false;
12113
- this.useDevicePassphraseState = false;
12114
- }
12115
- run() {
12116
- return __awaiter(this, void 0, void 0, function* () {
12117
- return new Promise((resolve, reject) => {
12118
- axios
12119
- .request({
12120
- url: 'http://localhost:21320',
12121
- method: 'POST',
12122
- withCredentials: false,
12123
- timeout: 3000,
12124
- })
12125
- .then(() => resolve(true))
12126
- .catch(e => {
12127
- if (e.code === 'ECONNABORTED') {
12128
- reject(ERRORS.TypedError(HardwareErrorCode.BridgeTimeoutError));
12129
- }
12130
- else {
12131
- resolve(false);
12132
- }
12133
- });
12134
- });
12962
+ ]);
12135
12963
  });
12136
- }
12137
- }
12138
-
12139
- class DeviceBackup extends BaseMethod {
12140
- init() {
12141
- this.useDevicePassphraseState = false;
12142
- }
12143
- run() {
12144
- return __awaiter(this, void 0, void 0, function* () {
12145
- const res = yield this.device.commands.typedCall('BackupDevice', 'Success');
12146
- return Promise.resolve(res.message);
12964
+ this.payload.inputs.forEach((input) => {
12965
+ validatePath(input.address_n);
12966
+ const useAmount = isSegwitPath(input.address_n);
12967
+ validateParams(input, [
12968
+ { name: 'prev_hash', type: 'hexString', required: true },
12969
+ { name: 'prev_index', type: 'number', required: true },
12970
+ { name: 'script_type', type: 'string' },
12971
+ { name: 'amount', type: 'string', required: useAmount },
12972
+ { name: 'sequence', type: 'number' },
12973
+ { name: 'multisig', type: 'object' },
12974
+ ]);
12147
12975
  });
12148
- }
12149
- }
12150
-
12151
- class DeviceChangePin extends BaseMethod {
12152
- init() {
12153
- this.useDevicePassphraseState = false;
12154
- validateParams(this.payload, [{ name: 'remove', type: 'boolean' }]);
12155
- this.params = {
12156
- remove: this.payload.remove,
12157
- };
12158
- }
12159
- run() {
12160
- return __awaiter(this, void 0, void 0, function* () {
12161
- const res = yield this.device.commands.typedCall('ChangePin', 'Success', Object.assign({}, this.params));
12162
- return Promise.resolve(res.message);
12976
+ this.payload.outputs.forEach((output) => {
12977
+ validateParams(output, [
12978
+ { name: 'address_n', type: 'array' },
12979
+ { name: 'address', type: 'string' },
12980
+ { name: 'amount', type: 'string' },
12981
+ { name: 'op_return_data', type: 'string' },
12982
+ { name: 'multisig', type: 'object' },
12983
+ ]);
12984
+ if (Object.prototype.hasOwnProperty.call(output, 'address_n') &&
12985
+ Object.prototype.hasOwnProperty.call(output, 'address')) {
12986
+ throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'Cannot use address and address_n in one output');
12987
+ }
12988
+ if (output.address_n) {
12989
+ const scriptType = getOutputScriptType(output.address_n);
12990
+ if (output.script_type !== scriptType)
12991
+ throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, `Output change script_type should be set to ${scriptType}`);
12992
+ }
12163
12993
  });
12164
- }
12165
- }
12166
-
12167
- class DeviceFlags extends BaseMethod {
12168
- init() {
12169
- this.useDevicePassphraseState = false;
12170
- validateParams(this.payload, [{ name: 'flags', type: 'number' }]);
12994
+ const { inputs, outputs, refTxs, account, coin } = this.payload;
12995
+ const coinName = getCoinInfo(undefined, coin).name;
12171
12996
  this.params = {
12172
- flags: this.payload.flags,
12173
- };
12174
- }
12175
- run() {
12176
- return __awaiter(this, void 0, void 0, function* () {
12177
- const res = yield this.device.commands.typedCall('ApplyFlags', 'Success', Object.assign({}, this.params));
12178
- return Promise.resolve(res.message);
12179
- });
12180
- }
12181
- }
12182
-
12183
- class DeviceRebootToBootloader extends BaseMethod {
12184
- init() {
12185
- this.useDevicePassphraseState = false;
12186
- }
12187
- getVersionRange() {
12188
- return {
12189
- classic: {
12190
- min: '2.1.11',
12191
- },
12192
- mini: {
12193
- min: '2.1.11',
12997
+ inputs,
12998
+ outputs,
12999
+ refTxs,
13000
+ addresses: account ? account.addresses : undefined,
13001
+ options: {
13002
+ lock_time: this.payload.locktime,
13003
+ timestamp: this.payload.timestamp,
13004
+ version: this.payload.version,
13005
+ expiry: this.payload.expiry,
13006
+ overwintered: this.payload.overwintered,
13007
+ version_group_id: this.payload.versionGroupId,
13008
+ branch_id: this.payload.branchId,
12194
13009
  },
13010
+ coinName,
12195
13011
  };
12196
13012
  }
12197
13013
  run() {
12198
13014
  return __awaiter(this, void 0, void 0, function* () {
12199
- const res = yield this.device.commands.typedCall('RebootToBootloader', 'Success');
12200
- return Promise.resolve(res.message);
13015
+ const { device, params } = this;
13016
+ const useLegacySignProcess = device.unavailableCapabilities.replaceTransaction;
13017
+ const { refTxs } = params;
13018
+ const signTxMethod = !useLegacySignProcess ? signtx : signtxLegacy;
13019
+ const response = yield signTxMethod(device.commands.typedCall.bind(device.commands), params.inputs, params.outputs, refTxs, params.options, params.coinName);
13020
+ return response;
12201
13021
  });
12202
13022
  }
12203
13023
  }
12204
13024
 
12205
- class DeviceRecovery extends BaseMethod {
13025
+ class BTCVerifyMessage extends BaseMethod {
12206
13026
  init() {
12207
- this.useDevicePassphraseState = false;
13027
+ this.checkDeviceId = true;
13028
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12208
13029
  validateParams(this.payload, [
12209
- { name: 'wordCount', type: 'number' },
12210
- { name: 'passphraseProtection', type: 'boolean' },
12211
- { name: 'pinProtection', type: 'boolean' },
12212
- { name: 'language', type: 'string' },
12213
- { name: 'label', type: 'string' },
12214
- { name: 'enforceWordlist', type: 'boolean' },
12215
- { name: 'type', type: 'object' },
12216
- { name: 'u2fCounter', type: 'number' },
12217
- { name: 'dryRun', type: 'boolean' },
13030
+ { name: 'address', type: 'string', required: true },
13031
+ { name: 'messageHex', type: 'hexString', required: true },
13032
+ { name: 'signature', type: 'hexString', required: true },
13033
+ { name: 'coin', type: 'string', required: true },
12218
13034
  ]);
13035
+ const { coin } = this.payload;
13036
+ const { address, messageHex, signature } = formatAnyHex(this.payload);
13037
+ const coinName = getCoinInfo(undefined, coin).name;
12219
13038
  this.params = {
12220
- word_count: this.payload.wordCount,
12221
- passphrase_protection: this.payload.passphraseProtection,
12222
- pin_protection: this.payload.pinProtection,
12223
- language: this.payload.language,
12224
- label: this.payload.label,
12225
- enforce_wordlist: this.payload.enforceWordlist,
12226
- type: this.payload.type,
12227
- u2f_counter: this.payload.u2fCounter || Math.floor(Date.now() / 1000),
12228
- dry_run: this.payload.dryRun,
13039
+ address,
13040
+ message: messageHex,
13041
+ signature,
13042
+ coin_name: coinName,
12229
13043
  };
12230
13044
  }
12231
13045
  run() {
12232
13046
  return __awaiter(this, void 0, void 0, function* () {
12233
- const res = yield this.device.commands.typedCall('RecoveryDevice', 'Success', Object.assign({}, this.params));
13047
+ const res = yield this.device.commands.typedCall('VerifyMessage', 'Success', Object.assign({}, this.params));
12234
13048
  return Promise.resolve(res.message);
12235
13049
  });
12236
13050
  }
12237
13051
  }
12238
13052
 
12239
- class DeviceReset extends BaseMethod {
13053
+ class ConfluxGetAddress extends BaseMethod {
13054
+ constructor() {
13055
+ super(...arguments);
13056
+ this.hasBundle = false;
13057
+ }
12240
13058
  init() {
12241
- this.useDevicePassphraseState = false;
12242
- validateParams(this.payload, [
12243
- { name: 'displayRandom', type: 'boolean' },
12244
- { name: 'strength', type: 'number' },
12245
- { name: 'passphraseProtection', type: 'boolean' },
12246
- { name: 'pinProtection', type: 'boolean' },
12247
- { name: 'language', type: 'string' },
12248
- { name: 'label', type: 'string' },
12249
- { name: 'u2fCounter', type: 'number' },
12250
- { name: 'skipBackup', type: 'boolean' },
12251
- { name: 'noBackup', type: 'boolean' },
12252
- { name: 'backupType' },
12253
- ]);
12254
- this.params = {
12255
- display_random: this.payload.displayRandom,
12256
- strength: this.payload.strength || 256,
12257
- passphrase_protection: this.payload.passphraseProtection,
12258
- pin_protection: this.payload.pinProtection,
12259
- language: this.payload.language,
12260
- label: this.payload.label,
12261
- u2f_counter: this.payload.u2fCounter || Math.floor(Date.now() / 1000),
12262
- skip_backup: this.payload.skipBackup,
12263
- no_backup: this.payload.noBackup,
12264
- backup_type: this.payload.backupType,
13059
+ var _a;
13060
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
13061
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
13062
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
13063
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
13064
+ this.params = [];
13065
+ payload.bundle.forEach((batch) => {
13066
+ var _a;
13067
+ const addressN = validatePath(batch.path, 3);
13068
+ validateParams(batch, [
13069
+ { name: 'path', required: true },
13070
+ { name: 'chainId', type: 'number' },
13071
+ { name: 'showOnOneKey', type: 'boolean' },
13072
+ ]);
13073
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
13074
+ this.params.push({
13075
+ address_n: addressN,
13076
+ chain_id: batch.chainId,
13077
+ show_display: showOnOneKey,
13078
+ });
13079
+ });
13080
+ }
13081
+ getVersionRange() {
13082
+ return {
13083
+ model_mini: {
13084
+ min: '2.4.0',
13085
+ },
12265
13086
  };
12266
13087
  }
12267
13088
  run() {
12268
13089
  return __awaiter(this, void 0, void 0, function* () {
12269
- const res = yield this.device.commands.typedCall('ResetDevice', 'Success', Object.assign({}, this.params));
12270
- return Promise.resolve(res.message);
13090
+ const responses = [];
13091
+ for (let i = 0; i < this.params.length; i++) {
13092
+ const param = this.params[i];
13093
+ const res = yield this.device.commands.typedCall('ConfluxGetAddress', 'ConfluxAddress', Object.assign({}, param));
13094
+ responses.push(Object.assign({ path: serializedPath(param.address_n) }, res.message));
13095
+ }
13096
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
12271
13097
  });
12272
13098
  }
12273
13099
  }
12274
13100
 
12275
- class DeviceSettings extends BaseMethod {
13101
+ class ConfluxSignMessage extends BaseMethod {
12276
13102
  init() {
12277
- this.useDevicePassphraseState = false;
13103
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12278
13104
  validateParams(this.payload, [
12279
- { name: 'language', type: 'string' },
12280
- { name: 'label', type: 'string' },
12281
- { name: 'usePassphrase', type: 'boolean' },
12282
- { name: 'homescreen', type: 'string' },
12283
- { name: 'passphraseSource', type: 'number' },
12284
- { name: 'autoLockDelayMs', type: 'number' },
12285
- { name: 'displayRotation', type: 'number' },
12286
- { name: 'passphraseAlwaysOnDevice', type: 'boolean' },
12287
- { name: 'safetyChecks', type: 'number' },
12288
- { name: 'experimentalFeatures', type: 'boolean' },
13105
+ { name: 'path', required: true },
13106
+ { name: 'messageHex', type: 'hexString', required: true },
12289
13107
  ]);
13108
+ const { path, messageHex } = this.payload;
13109
+ const addressN = validatePath(path, 3);
12290
13110
  this.params = {
12291
- language: this.payload.language,
12292
- label: this.payload.label,
12293
- use_passphrase: this.payload.usePassphrase,
12294
- homescreen: this.payload.homescreen,
12295
- _passphrase_source: this.payload.passphraseSource,
12296
- auto_lock_delay_ms: this.payload.autoLockDelayMs,
12297
- display_rotation: this.payload.displayRotation,
12298
- passphrase_always_on_device: this.payload.passphraseAlwaysOnDevice,
12299
- safety_checks: this.payload.safetyChecks,
12300
- experimental_features: this.payload.experimentalFeatures,
13111
+ address_n: addressN,
13112
+ message: formatAnyHex(messageHex),
12301
13113
  };
12302
13114
  }
12303
13115
  getVersionRange() {
12304
- if (this.payload.usePassphrase) {
12305
- return {
12306
- model_mini: {
12307
- min: '2.4.0',
12308
- },
12309
- };
12310
- }
12311
- return {};
12312
- }
12313
- run() {
12314
- return __awaiter(this, void 0, void 0, function* () {
12315
- const res = yield this.device.commands.typedCall('ApplySettings', 'Success', Object.assign({}, this.params));
12316
- return Promise.resolve(res.message);
12317
- });
12318
- }
12319
- }
12320
-
12321
- class DeviceUpdateReboot extends BaseMethod {
12322
- init() {
12323
- this.useDevicePassphraseState = false;
13116
+ return {
13117
+ model_mini: {
13118
+ min: '2.4.0',
13119
+ },
13120
+ };
12324
13121
  }
12325
13122
  run() {
12326
13123
  return __awaiter(this, void 0, void 0, function* () {
12327
- const res = yield this.device.commands.typedCall('BixinReboot', 'Success');
13124
+ const res = yield this.device.commands.typedCall('ConfluxSignMessage', 'ConfluxMessageSignature', Object.assign({}, this.params));
12328
13125
  return Promise.resolve(res.message);
12329
13126
  });
12330
13127
  }
12331
13128
  }
12332
13129
 
12333
- class DeviceSupportFeatures extends BaseMethod {
13130
+ class ConfluxSignMessageCIP23 extends BaseMethod {
12334
13131
  init() {
12335
- this.useDevicePassphraseState = false;
13132
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
13133
+ validateParams(this.payload, [
13134
+ { name: 'path', required: true },
13135
+ { name: 'domainHash', type: 'hexString', required: true },
13136
+ { name: 'messageHash', type: 'hexString', required: true },
13137
+ ]);
13138
+ const { path, domainHash, messageHash } = this.payload;
13139
+ const addressN = validatePath(path, 3);
13140
+ this.params = {
13141
+ address_n: addressN,
13142
+ domain_hash: formatAnyHex(domainHash),
13143
+ message_hash: formatAnyHex(messageHash),
13144
+ };
13145
+ }
13146
+ getVersionRange() {
13147
+ return {
13148
+ model_mini: {
13149
+ min: '2.4.0',
13150
+ },
13151
+ };
12336
13152
  }
12337
13153
  run() {
12338
- if (!this.device.features)
12339
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Device not initialized'));
12340
- const inputPinOnSoftware = supportInputPinOnSoftware(this.device.features);
12341
- return Promise.resolve({
12342
- inputPinOnSoftware,
12343
- device: this.device.toMessageObject(),
13154
+ return __awaiter(this, void 0, void 0, function* () {
13155
+ const res = yield this.device.commands.typedCall('ConfluxSignMessageCIP23', 'ConfluxMessageSignature', Object.assign({}, this.params));
13156
+ return Promise.resolve(res.message);
12344
13157
  });
12345
13158
  }
12346
13159
  }
12347
13160
 
12348
- class DeviceVerify extends BaseMethod {
12349
- init() {
12350
- this.useDevicePassphraseState = false;
12351
- validateParams(this.payload, [{ name: 'dataHex', type: 'hexString' }]);
12352
- this.params = {
12353
- data: formatAnyHex(this.payload.dataHex),
12354
- };
13161
+ const cutString = (str, cutLen) => {
13162
+ if (!str) {
13163
+ return ['', ''];
12355
13164
  }
12356
- run() {
12357
- return __awaiter(this, void 0, void 0, function* () {
12358
- const deviceType = getDeviceType(this.device.features);
12359
- let response;
12360
- if (deviceType === 'classic') {
12361
- const res = yield this.device.commands.typedCall('BixinVerifyDeviceRequest', 'BixinVerifyDeviceAck', Object.assign(Object.assign({}, this.params), { data: sha256.sha256(this.params.data) }));
12362
- response = res.message;
12363
- }
12364
- else {
12365
- const signatureRes = yield this.device.commands.typedCall('SESignMessage', 'SEMessageSignature', {
12366
- message: this.params.data,
13165
+ const first = str.slice(0, cutLen);
13166
+ const second = str.slice(cutLen);
13167
+ return [first, second];
13168
+ };
13169
+
13170
+ class ConfluxSignTransaction extends BaseMethod {
13171
+ constructor() {
13172
+ super(...arguments);
13173
+ this.addressN = [];
13174
+ this.processTxRequest = (request, data) => __awaiter(this, void 0, void 0, function* () {
13175
+ if (!request.data_length) {
13176
+ const v = request.signature_v;
13177
+ const r = request.signature_r;
13178
+ const s = request.signature_s;
13179
+ if (v == null || r == null || s == null) {
13180
+ throw ERRORS.TypedError(HardwareErrorCode.CallMethodError, 'sign transaction failed');
13181
+ }
13182
+ return Promise.resolve({
13183
+ v: `0x${v.toString(16)}`,
13184
+ r: `0x${r}`,
13185
+ s: `0x${s}`,
12367
13186
  });
12368
- const certRes = yield this.device.commands.typedCall('ReadSEPublicCert', 'SEPublicCert');
12369
- response = {
12370
- cert: certRes.message.public_cert,
12371
- signature: signatureRes.message.signature,
12372
- };
12373
13187
  }
12374
- if (response)
12375
- return Promise.resolve(response);
12376
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Device not support verify'));
13188
+ const [first, rest] = cutString(data, request.data_length * 2);
13189
+ const response = yield this.device.commands.typedCall('ConfluxTxAck', 'ConfluxTxRequest', {
13190
+ data_chunk: first,
13191
+ });
13192
+ return this.processTxRequest(response.message, rest);
13193
+ });
13194
+ this.evmSignTx = (addressN, tx) => __awaiter(this, void 0, void 0, function* () {
13195
+ const { to, value, gasPrice, gasLimit, nonce, data, chainId, epochHeight, storageLimit } = tx;
13196
+ const length = data == null ? 0 : data.length / 2;
13197
+ const [first, rest] = cutString(data, 1024 * 2);
13198
+ let message = {
13199
+ address_n: addressN,
13200
+ nonce: stripHexStartZeroes(nonce),
13201
+ gas_price: stripHexStartZeroes(gasPrice),
13202
+ gas_limit: stripHexStartZeroes(gasLimit),
13203
+ to,
13204
+ value: stripHexStartZeroes(value),
13205
+ epoch_height: stripHexStartZeroes(epochHeight),
13206
+ storage_limit: stripHexStartZeroes(storageLimit),
13207
+ chain_id: chainId,
13208
+ };
13209
+ if (length !== 0) {
13210
+ message = Object.assign(Object.assign({}, message), { data_length: length, data_initial_chunk: first });
13211
+ }
13212
+ const response = yield this.device.commands.typedCall('ConfluxSignTx', 'ConfluxTxRequest', message);
13213
+ return this.processTxRequest(response.message, rest);
12377
13214
  });
12378
13215
  }
12379
- }
12380
-
12381
- class DeviceWipe extends BaseMethod {
12382
13216
  init() {
12383
- this.useDevicePassphraseState = false;
13217
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
13218
+ validateParams(this.payload, [
13219
+ { name: 'path', required: true },
13220
+ { name: 'transaction', type: 'object', required: true },
13221
+ ]);
13222
+ const { path, transaction } = this.payload;
13223
+ this.addressN = validatePath(path, 3);
13224
+ const tx = transaction;
13225
+ const schema = [
13226
+ { name: 'to', type: 'hexString', required: true },
13227
+ { name: 'value', type: 'hexString', required: true },
13228
+ { name: 'gasLimit', type: 'hexString', required: true },
13229
+ { name: 'gasPrice', type: 'hexString', required: true },
13230
+ { name: 'nonce', type: 'hexString', required: true },
13231
+ { name: 'epochHeight', type: 'hexString', required: true },
13232
+ { name: 'storageLimit', type: 'hexString', required: true },
13233
+ { name: 'chainId', type: 'number', required: true },
13234
+ { name: 'data', type: 'hexString' },
13235
+ ];
13236
+ validateParams(tx, schema);
13237
+ this.formattedTx = formatAnyHex(tx);
13238
+ }
13239
+ getVersionRange() {
13240
+ return {
13241
+ model_mini: {
13242
+ min: '2.4.0',
13243
+ },
13244
+ };
12384
13245
  }
12385
13246
  run() {
12386
13247
  return __awaiter(this, void 0, void 0, function* () {
12387
- const res = yield this.device.commands.typedCall('WipeDevice', 'Success');
12388
- return Promise.resolve(res.message);
13248
+ const { addressN, formattedTx } = this;
13249
+ if (formattedTx == null) {
13250
+ throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'ConfluxSignTransaction: format tx error');
13251
+ }
13252
+ const signedTx = yield this.evmSignTx(addressN, formattedTx);
13253
+ return Promise.resolve(signedTx);
12389
13254
  });
12390
13255
  }
12391
13256
  }
@@ -12529,15 +13394,6 @@ class EVMSignMessageEIP712 extends BaseMethod {
12529
13394
  }
12530
13395
  }
12531
13396
 
12532
- const cutString = (str, cutLen) => {
12533
- if (!str) {
12534
- return ['', ''];
12535
- }
12536
- const first = str.slice(0, cutLen);
12537
- const second = str.slice(cutLen);
12538
- return [first, second];
12539
- };
12540
-
12541
13397
  class EVMSignTransaction extends BaseMethod {
12542
13398
  constructor() {
12543
13399
  super(...arguments);
@@ -13622,8 +14478,11 @@ class StellarSignTransaction extends BaseMethod {
13622
14478
  { name: 'networkPassphrase', type: 'string', required: true },
13623
14479
  { name: 'transaction', type: 'object', required: true },
13624
14480
  ]);
13625
- const addressN = validatePath(this.payload.path, 3);
13626
14481
  const { transaction, networkPassphrase } = this.payload;
14482
+ if (!transaction.timebounds) {
14483
+ throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'timebounds is required');
14484
+ }
14485
+ const addressN = validatePath(this.payload.path, 3);
13627
14486
  this.params = {
13628
14487
  address_n: addressN,
13629
14488
  network_passphrase: networkPassphrase,
@@ -13631,11 +14490,10 @@ class StellarSignTransaction extends BaseMethod {
13631
14490
  fee: transaction.fee,
13632
14491
  sequence_number: transaction.sequence,
13633
14492
  num_operations: transaction.operations.length,
14493
+ memo_type: StellarMemoType.NONE,
14494
+ timebounds_start: transaction.timebounds.minTime,
14495
+ timebounds_end: transaction.timebounds.maxTime,
13634
14496
  };
13635
- if (transaction.timebounds) {
13636
- this.params.timebounds_start = transaction.timebounds.minTime;
13637
- this.params.timebounds_end = transaction.timebounds.maxTime;
13638
- }
13639
14497
  if (transaction.memo) {
13640
14498
  this.params.memo_type = transaction.memo.type;
13641
14499
  this.params.memo_text = transaction.memo.text;
@@ -13659,195 +14517,306 @@ class StellarSignTransaction extends BaseMethod {
13659
14517
  }
13660
14518
  }
13661
14519
 
13662
- const getBinary = ({ features, updateType, version }) => __awaiter(void 0, void 0, void 0, function* () {
13663
- const releaseInfo = getInfo({ features, updateType });
13664
- if (!releaseInfo) {
13665
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'no firmware found for this device');
14520
+ class TronGetAddress extends BaseMethod {
14521
+ constructor() {
14522
+ super(...arguments);
14523
+ this.hasBundle = false;
13666
14524
  }
13667
- if (version &&
13668
- !semver.eq(releaseInfo.version, version)) {
13669
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'firmware version mismatch');
14525
+ init() {
14526
+ var _a;
14527
+ this.checkDeviceId = true;
14528
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
14529
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
14530
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
14531
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
14532
+ this.params = [];
14533
+ payload.bundle.forEach((batch) => {
14534
+ var _a;
14535
+ const addressN = validatePath(batch.path, 3);
14536
+ validateParams(batch, [
14537
+ { name: 'path', required: true },
14538
+ { name: 'showOnOneKey', type: 'boolean' },
14539
+ ]);
14540
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
14541
+ this.params.push({
14542
+ address_n: addressN,
14543
+ show_display: showOnOneKey,
14544
+ });
14545
+ });
13670
14546
  }
13671
- const url = updateType === 'ble' ? releaseInfo.webUpdate : releaseInfo.url;
13672
- let fw;
13673
- try {
13674
- fw = yield httpRequest(url, 'binary');
14547
+ getVersionRange() {
14548
+ return {
14549
+ model_mini: {
14550
+ min: '2.4.0',
14551
+ },
14552
+ };
13675
14553
  }
13676
- catch (_a) {
13677
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Method_FirmwareUpdate_DownloadFailed');
14554
+ run() {
14555
+ return __awaiter(this, void 0, void 0, function* () {
14556
+ const responses = [];
14557
+ for (let i = 0; i < this.params.length; i++) {
14558
+ const param = this.params[i];
14559
+ const res = yield this.device.commands.typedCall('TronGetAddress', 'TronAddress', Object.assign({}, param));
14560
+ const { address } = res.message;
14561
+ responses.push({
14562
+ path: serializedPath(param.address_n),
14563
+ address,
14564
+ });
14565
+ }
14566
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
14567
+ });
13678
14568
  }
13679
- return Object.assign(Object.assign({}, releaseInfo), { binary: fw });
13680
- });
13681
- const getInfo = ({ features, updateType }) => {
13682
- var _a, _b, _c;
13683
- const deviceType = getDeviceType(features);
13684
- const { deviceMap } = DataManager;
13685
- const releaseInfo = (_c = (_b = (_a = deviceMap === null || deviceMap === void 0 ? void 0 : deviceMap[deviceType]) === null || _a === void 0 ? void 0 : _a[updateType]) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : null;
13686
- return releaseInfo;
13687
- };
14569
+ }
13688
14570
 
13689
- const postConfirmationMessage = (device) => {
13690
- var _a;
13691
- if ((_a = device.features) === null || _a === void 0 ? void 0 : _a.firmware_present) {
13692
- device.emit(DEVICE.BUTTON, device, { code: 'ButtonRequest_FirmwareUpdate' });
13693
- }
13694
- };
13695
- const postProgressMessage = (device, progress, postMessage) => {
13696
- postMessage(createUiMessage(UI_REQUEST$1.FIRMWARE_PROGRESS, {
13697
- device: device.toMessageObject(),
13698
- progress,
13699
- }));
13700
- };
13701
- const uploadFirmware = (updateType, typedCall, postMessage, device, { payload }) => __awaiter(void 0, void 0, void 0, function* () {
13702
- var _a, _b;
13703
- if (((_a = device.features) === null || _a === void 0 ? void 0 : _a.major_version) === 1) {
13704
- postConfirmationMessage(device);
13705
- const eraseCommand = updateType === 'firmware' ? 'FirmwareErase' : 'FirmwareErase_ex';
13706
- yield typedCall(eraseCommand, 'Success', {});
13707
- postProgressMessage(device, 0, postMessage);
13708
- const { message } = yield typedCall('FirmwareUpload', 'Success', {
13709
- payload,
13710
- });
13711
- postProgressMessage(device, 100, postMessage);
13712
- return message;
14571
+ class TronSignMessage extends BaseMethod {
14572
+ init() {
14573
+ this.checkDeviceId = true;
14574
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
14575
+ validateParams(this.payload, [
14576
+ { name: 'path', required: true },
14577
+ { name: 'messageHex', type: 'hexString', required: true },
14578
+ ]);
14579
+ const { path, messageHex } = this.payload;
14580
+ const addressN = validatePath(path, 3);
14581
+ this.params = {
14582
+ address_n: addressN,
14583
+ message: stripHexPrefix(messageHex),
14584
+ };
13713
14585
  }
13714
- if (((_b = device.features) === null || _b === void 0 ? void 0 : _b.major_version) === 2) {
13715
- postConfirmationMessage(device);
13716
- const length = payload.byteLength;
13717
- let response = yield typedCall('FirmwareErase', ['FirmwareRequest', 'Success'], { length });
13718
- while (response.type !== 'Success') {
13719
- const start = response.message.offset;
13720
- const end = response.message.offset + response.message.length;
13721
- const chunk = payload.slice(start, end);
13722
- if (start > 0) {
13723
- postProgressMessage(device, Math.round((start / length) * 100), postMessage);
14586
+ getVersionRange() {
14587
+ return {
14588
+ model_mini: {
14589
+ min: '2.4.0',
14590
+ },
14591
+ };
14592
+ }
14593
+ run() {
14594
+ return __awaiter(this, void 0, void 0, function* () {
14595
+ const response = yield this.device.commands.typedCall('TronSignMessage', 'TronMessageSignature', Object.assign({}, this.params));
14596
+ return Promise.resolve(response.message);
14597
+ });
14598
+ }
14599
+ }
14600
+
14601
+ class TronSignTransaction extends BaseMethod {
14602
+ parseTx(tx, address_n) {
14603
+ const unSignTx = {
14604
+ address_n,
14605
+ data: tx.data,
14606
+ timestamp: tx.timestamp,
14607
+ fee_limit: tx.feeLimit,
14608
+ ref_block_bytes: tx.refBlockBytes,
14609
+ ref_block_hash: tx.refBlockHash,
14610
+ expiration: tx.expiration,
14611
+ contract: {},
14612
+ };
14613
+ if (tx.contract) {
14614
+ if (tx.contract.transferContract) {
14615
+ unSignTx.contract = {
14616
+ transfer_contract: {
14617
+ to_address: tx.contract.transferContract.toAddress,
14618
+ amount: tx.contract.transferContract.amount,
14619
+ },
14620
+ };
14621
+ }
14622
+ if (tx.contract.triggerSmartContract) {
14623
+ unSignTx.contract = {
14624
+ trigger_smart_contract: {
14625
+ contract_address: tx.contract.triggerSmartContract.contractAddress,
14626
+ call_value: tx.contract.triggerSmartContract.callValue,
14627
+ data: tx.contract.triggerSmartContract.data,
14628
+ call_token_value: tx.contract.triggerSmartContract.callTokenValue,
14629
+ asset_id: tx.contract.triggerSmartContract.assetId,
14630
+ },
14631
+ };
13724
14632
  }
13725
- response = yield typedCall('FirmwareUpload', ['FirmwareRequest', 'Success'], {
13726
- payload: chunk,
13727
- });
13728
14633
  }
13729
- postProgressMessage(device, 100, postMessage);
13730
- return response.message;
14634
+ return unSignTx;
13731
14635
  }
13732
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown major_version');
13733
- });
13734
-
13735
- class FirmwareUpdate extends BaseMethod {
13736
14636
  init() {
13737
- this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.INITIALIZE];
13738
- this.requireDeviceMode = [UI_REQUEST.BOOTLOADER];
13739
- this.useDevicePassphraseState = false;
13740
- const { payload } = this;
13741
- validateParams(payload, [
13742
- { name: 'version', type: 'array' },
13743
- { name: 'binary', type: 'buffer' },
14637
+ this.checkDeviceId = true;
14638
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
14639
+ validateParams(this.payload, [
14640
+ { name: 'path', required: true },
14641
+ { name: 'transaction', type: 'object', required: true },
13744
14642
  ]);
13745
- if (!payload.updateType) {
13746
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'updateType is required');
13747
- }
13748
- this.params = { updateType: payload.updateType };
13749
- if ('version' in payload) {
13750
- this.params = Object.assign(Object.assign({}, this.params), { version: payload.version });
13751
- }
13752
- if ('binary' in payload) {
13753
- this.params = Object.assign(Object.assign({}, this.params), { binary: payload.binary });
13754
- }
14643
+ const { path, transaction } = this.payload;
14644
+ const addressN = validatePath(path, 3);
14645
+ validateParams(transaction, [
14646
+ { name: 'refBlockBytes', type: 'hexString', required: true },
14647
+ { name: 'refBlockHash', type: 'hexString', required: true },
14648
+ { name: 'expiration', type: 'number', required: true },
14649
+ { name: 'timestamp', type: 'number', required: true },
14650
+ { name: 'contract', type: 'object', required: true },
14651
+ ]);
14652
+ this.params = this.parseTx(formatAnyHex(transaction), addressN);
14653
+ }
14654
+ getVersionRange() {
14655
+ return {
14656
+ model_mini: {
14657
+ min: '2.4.0',
14658
+ },
14659
+ };
13755
14660
  }
13756
14661
  run() {
14662
+ return __awaiter(this, void 0, void 0, function* () {
14663
+ const response = yield this.device.commands.typedCall('TronSignTx', 'TronSignedTx', Object.assign({}, this.params));
14664
+ return Promise.resolve(response.message);
14665
+ });
14666
+ }
14667
+ }
14668
+
14669
+ class NearGetAddress extends BaseMethod {
14670
+ constructor() {
14671
+ super(...arguments);
14672
+ this.hasBundle = false;
14673
+ }
14674
+ init() {
13757
14675
  var _a;
14676
+ this.checkDeviceId = true;
14677
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
14678
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
14679
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
14680
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
14681
+ this.params = [];
14682
+ payload.bundle.forEach((batch) => {
14683
+ var _a;
14684
+ const addressN = validatePath(batch.path, 3);
14685
+ validateParams(batch, [
14686
+ { name: 'path', required: true },
14687
+ { name: 'showOnOneKey', type: 'boolean' },
14688
+ ]);
14689
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
14690
+ this.params.push({
14691
+ address_n: addressN,
14692
+ show_display: showOnOneKey,
14693
+ });
14694
+ });
14695
+ }
14696
+ getVersionRange() {
14697
+ return {
14698
+ model_mini: {
14699
+ min: '2.4.0',
14700
+ },
14701
+ };
14702
+ }
14703
+ run() {
13758
14704
  return __awaiter(this, void 0, void 0, function* () {
13759
- const { device, params } = this;
13760
- let binary;
13761
- try {
13762
- if (params.binary) {
13763
- binary = this.params.binary;
13764
- }
13765
- else {
13766
- if (!device.features) {
13767
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'no features found for this device');
13768
- }
13769
- const firmware = yield getBinary({
13770
- features: device.features,
13771
- version: params.version,
13772
- updateType: params.updateType,
13773
- });
13774
- binary = firmware.binary;
13775
- }
13776
- }
13777
- catch (err) {
13778
- throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateDownloadFailed, (_a = err.message) !== null && _a !== void 0 ? _a : err);
14705
+ const responses = [];
14706
+ for (let i = 0; i < this.params.length; i++) {
14707
+ const param = this.params[i];
14708
+ const res = yield this.device.commands.typedCall('NearGetAddress', 'NearAddress', Object.assign({}, param));
14709
+ const { address } = res.message;
14710
+ responses.push({
14711
+ path: serializedPath(param.address_n),
14712
+ address,
14713
+ });
13779
14714
  }
13780
- return uploadFirmware(params.updateType, this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, { payload: binary });
14715
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
13781
14716
  });
13782
14717
  }
13783
14718
  }
13784
14719
 
13785
- const Log$2 = getLogger(LoggerNames.Method);
13786
- class RequestWebUsbDevice extends BaseMethod {
14720
+ class NearSignTransaction extends BaseMethod {
13787
14721
  init() {
13788
- this.useDevice = false;
13789
- this.useDevicePassphraseState = false;
14722
+ this.checkDeviceId = true;
14723
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
14724
+ validateParams(this.payload, [
14725
+ { name: 'path', required: true },
14726
+ { name: 'rawTx', type: 'hexString', required: true },
14727
+ ]);
14728
+ const { path, rawTx } = this.payload;
14729
+ const addressN = validatePath(path, 3);
14730
+ this.params = {
14731
+ address_n: addressN,
14732
+ raw_tx: formatAnyHex(rawTx),
14733
+ };
14734
+ }
14735
+ getVersionRange() {
14736
+ return {
14737
+ model_mini: {
14738
+ min: '2.4.0',
14739
+ },
14740
+ };
13790
14741
  }
13791
14742
  run() {
13792
- var _a, _b;
13793
14743
  return __awaiter(this, void 0, void 0, function* () {
13794
- yield TransportManager.configure();
13795
- const env = DataManager.getSettings('env');
13796
- if (env !== 'webusb') {
13797
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Not webusb environment'));
13798
- }
13799
- try {
13800
- const deviceDiff = yield ((_a = this.connector) === null || _a === void 0 ? void 0 : _a.enumerate());
13801
- const devicesDescriptor = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
13802
- const { deviceList } = yield DevicePool.getDevices(devicesDescriptor);
13803
- if (deviceList.length > 0) {
13804
- return { device: deviceList[0].toMessageObject() };
13805
- }
13806
- return yield Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Please select the device to connect'));
13807
- }
13808
- catch (error) {
13809
- Log$2.debug(error);
13810
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Please select the device to connect'));
13811
- }
14744
+ const res = yield this.device.commands.typedCall('NearSignTx', 'NearSignedTx', Object.assign({}, this.params));
14745
+ return Promise.resolve(res.message);
13812
14746
  });
13813
14747
  }
13814
14748
  }
13815
14749
 
13816
- class GetPassphraseState extends BaseMethod {
14750
+ class AptosGetAddress extends BaseMethod {
14751
+ constructor() {
14752
+ super(...arguments);
14753
+ this.hasBundle = false;
14754
+ }
13817
14755
  init() {
14756
+ var _a;
14757
+ this.checkDeviceId = true;
13818
14758
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
13819
- this.useDevicePassphraseState = false;
14759
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
14760
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
14761
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
14762
+ this.params = [];
14763
+ payload.bundle.forEach((batch) => {
14764
+ var _a;
14765
+ const addressN = validatePath(batch.path, 3);
14766
+ validateParams(batch, [
14767
+ { name: 'path', required: true },
14768
+ { name: 'showOnOneKey', type: 'boolean' },
14769
+ ]);
14770
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
14771
+ this.params.push({
14772
+ address_n: addressN,
14773
+ show_display: showOnOneKey,
14774
+ });
14775
+ });
13820
14776
  }
13821
14777
  run() {
13822
- var _a, _b;
13823
14778
  return __awaiter(this, void 0, void 0, function* () {
13824
- if (!this.device.features)
13825
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed));
13826
- let { features } = this.device;
13827
- const locked = ((_b = (_a = this.device) === null || _a === void 0 ? void 0 : _a.features) === null || _b === void 0 ? void 0 : _b.unlocked) === true;
13828
- const passphraseState = yield getPassphraseState(this.device.features, this.device.commands);
13829
- const isModeT = getDeviceType(features) === 'touch' || getDeviceType(features) === 'pro';
13830
- if (isModeT && locked) {
13831
- const { message } = yield this.device.commands.typedCall('GetFeatures', 'Features', {});
13832
- features = message;
13833
- }
13834
- if (features && features.passphrase_protection === true) {
13835
- return Promise.resolve(passphraseState);
14779
+ const responses = [];
14780
+ for (let i = 0; i < this.params.length; i++) {
14781
+ const param = this.params[i];
14782
+ const res = yield this.device.commands.typedCall('AptosGetAddress', 'AptosAddress', Object.assign({}, param));
14783
+ const { address } = res.message;
14784
+ responses.push({
14785
+ path: serializedPath(param.address_n),
14786
+ address,
14787
+ });
13836
14788
  }
13837
- return Promise.resolve(undefined);
14789
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
13838
14790
  });
13839
14791
  }
13840
14792
  }
13841
14793
 
13842
- class CheckBridgeStatus extends BaseMethod {
14794
+ class AptosSignTransaction extends BaseMethod {
13843
14795
  init() {
13844
- this.useDevice = false;
13845
- this.useDevicePassphraseState = false;
14796
+ this.checkDeviceId = true;
14797
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
14798
+ validateParams(this.payload, [
14799
+ { name: 'path', required: true },
14800
+ { name: 'rawTx', type: 'hexString', required: true },
14801
+ ]);
14802
+ const { path, rawTx } = this.payload;
14803
+ const addressN = validatePath(path, 3);
14804
+ this.params = {
14805
+ address_n: addressN,
14806
+ raw_tx: formatAnyHex(rawTx),
14807
+ };
14808
+ }
14809
+ getVersionRange() {
14810
+ return {
14811
+ model_mini: {
14812
+ min: '2.4.0',
14813
+ },
14814
+ };
13846
14815
  }
13847
14816
  run() {
13848
14817
  return __awaiter(this, void 0, void 0, function* () {
13849
- const logs = getLog();
13850
- return Promise.resolve(logs);
14818
+ const res = yield this.device.commands.typedCall('AptosSignTx', 'AptosSignedTx', Object.assign({}, this.params));
14819
+ return Promise.resolve(res.message);
13851
14820
  });
13852
14821
  }
13853
14822
  }
@@ -13856,16 +14825,12 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
13856
14825
  __proto__: null,
13857
14826
  searchDevices: SearchDevices,
13858
14827
  getFeatures: GetFeatures,
13859
- cipherKeyValue: CipherKeyValue,
13860
- btcGetAddress: BTCGetAddress,
13861
- btcGetPublicKey: BTCGetPublicKey,
13862
- btcSignMessage: BTCSignMessage,
13863
- btcSignTransaction: BTCSignTransaction,
13864
- btcVerifyMessage: BTCVerifyMessage,
14828
+ getPassphraseState: GetPassphraseState,
14829
+ getLogs: CheckBridgeStatus$1,
13865
14830
  checkFirmwareRelease: CheckFirmwareRelease,
13866
14831
  checkBLEFirmwareRelease: CheckBLEFirmwareRelease,
13867
14832
  checkTransportRelease: CheckTransportRelease,
13868
- checkBridgeStatus: CheckBridgeStatus$1,
14833
+ checkBridgeStatus: CheckBridgeStatus,
13869
14834
  deviceBackup: DeviceBackup,
13870
14835
  deviceChangePin: DeviceChangePin,
13871
14836
  deviceFlags: DeviceFlags,
@@ -13877,6 +14842,18 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
13877
14842
  deviceSupportFeatures: DeviceSupportFeatures,
13878
14843
  deviceVerify: DeviceVerify,
13879
14844
  deviceWipe: DeviceWipe,
14845
+ firmwareUpdate: FirmwareUpdate,
14846
+ requestWebUsbDevice: RequestWebUsbDevice,
14847
+ cipherKeyValue: CipherKeyValue,
14848
+ btcGetAddress: BTCGetAddress,
14849
+ btcGetPublicKey: BTCGetPublicKey,
14850
+ btcSignMessage: BTCSignMessage,
14851
+ btcSignTransaction: BTCSignTransaction,
14852
+ btcVerifyMessage: BTCVerifyMessage,
14853
+ confluxGetAddress: ConfluxGetAddress,
14854
+ confluxSignMessage: ConfluxSignMessage,
14855
+ confluxSignMessageCIP23: ConfluxSignMessageCIP23,
14856
+ confluxSignTransaction: ConfluxSignTransaction,
13880
14857
  evmGetAddress: EvmGetAddress,
13881
14858
  evmGetPublicKey: EVMGetPublicKey,
13882
14859
  evmSignMessage: EVMSignMessage$2,
@@ -13895,10 +14872,13 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
13895
14872
  solSignTransaction: SolSignTransaction,
13896
14873
  stellarGetAddress: StellarGetAddress,
13897
14874
  stellarSignTransaction: StellarSignTransaction,
13898
- firmwareUpdate: FirmwareUpdate,
13899
- requestWebUsbDevice: RequestWebUsbDevice,
13900
- getPassphraseState: GetPassphraseState,
13901
- getLogs: CheckBridgeStatus
14875
+ tronGetAddress: TronGetAddress,
14876
+ tronSignMessage: TronSignMessage,
14877
+ tronSignTransaction: TronSignTransaction,
14878
+ nearGetAddress: NearGetAddress,
14879
+ nearSignTransaction: NearSignTransaction,
14880
+ aptosGetAddress: AptosGetAddress,
14881
+ aptosSignTransaction: AptosSignTransaction
13902
14882
  });
13903
14883
 
13904
14884
  function findMethod(message) {
@@ -14452,6 +15432,7 @@ const removeUiPromise = (promise) => {
14452
15432
  };
14453
15433
  class Core extends events.exports {
14454
15434
  handleMessage(message) {
15435
+ var _a, _b, _c, _d;
14455
15436
  return __awaiter(this, void 0, void 0, function* () {
14456
15437
  switch (message.type) {
14457
15438
  case UI_RESPONSE.RECEIVE_PIN: {
@@ -14469,7 +15450,11 @@ class Core extends events.exports {
14469
15450
  }
14470
15451
  case IFRAME.CALL: {
14471
15452
  const response = yield callAPI(message);
14472
- return response;
15453
+ const { success, payload } = response;
15454
+ if (success) {
15455
+ return response;
15456
+ }
15457
+ return Object.assign(Object.assign({}, response), { payload: Object.assign(Object.assign({}, payload), { connectId: (_b = (_a = message.payload) === null || _a === void 0 ? void 0 : _a.connectId) !== null && _b !== void 0 ? _b : '', deviceId: (_d = (_c = message.payload) === null || _c === void 0 ? void 0 : _c.deviceId) !== null && _d !== void 0 ? _d : '' }) });
14473
15458
  }
14474
15459
  case IFRAME.CANCEL: {
14475
15460
  cancel(message.payload.connectId);