@onekeyfe/hd-core 0.0.8 → 0.1.0

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 (119) hide show
  1. package/dist/api/BaseMethod.d.ts +4 -0
  2. package/dist/api/BaseMethod.d.ts.map +1 -1
  3. package/dist/api/CipherKeyValue.d.ts +9 -0
  4. package/dist/api/CipherKeyValue.d.ts.map +1 -0
  5. package/dist/api/FirmwareUpdate.d.ts +14 -0
  6. package/dist/api/FirmwareUpdate.d.ts.map +1 -0
  7. package/dist/api/device/DeviceRebootToBootloader.d.ts +8 -0
  8. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  9. package/dist/api/evm/EVMSignMessageEIP712.d.ts +5 -0
  10. package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
  11. package/dist/api/evm/EVMSignTransaction.d.ts +5 -0
  12. package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
  13. package/dist/api/evm/EVMSignTypedData.d.ts +7 -1
  14. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  15. package/dist/api/firmware/getBinary.d.ts +33 -0
  16. package/dist/api/firmware/getBinary.d.ts.map +1 -0
  17. package/dist/api/firmware/uploadFirmware.d.ts +8 -0
  18. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -0
  19. package/dist/api/helpers/hexUtils.d.ts.map +1 -1
  20. package/dist/api/index.d.ts +8 -0
  21. package/dist/api/index.d.ts.map +1 -1
  22. package/dist/api/nem/NEMGetAddress.d.ts +9 -0
  23. package/dist/api/nem/NEMGetAddress.d.ts.map +1 -0
  24. package/dist/api/nem/NEMSignTransaction.d.ts +20 -0
  25. package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -0
  26. package/dist/api/solana/SolGetAddress.d.ts +9 -0
  27. package/dist/api/solana/SolGetAddress.d.ts.map +1 -0
  28. package/dist/api/solana/SolSignTransaction.d.ts +17 -0
  29. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -0
  30. package/dist/api/stellar/StellarGetAddress.d.ts +9 -0
  31. package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -0
  32. package/dist/api/stellar/StellarSignTransaction.d.ts +335 -0
  33. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -0
  34. package/dist/constants/errors.d.ts +1 -0
  35. package/dist/constants/errors.d.ts.map +1 -1
  36. package/dist/core/index.d.ts.map +1 -1
  37. package/dist/data/version.d.ts +1 -1
  38. package/dist/data/version.d.ts.map +1 -1
  39. package/dist/device/Device.d.ts +1 -0
  40. package/dist/device/Device.d.ts.map +1 -1
  41. package/dist/device/DeviceCommands.d.ts +1 -0
  42. package/dist/device/DeviceCommands.d.ts.map +1 -1
  43. package/dist/events/ui-request.d.ts +9 -1
  44. package/dist/events/ui-request.d.ts.map +1 -1
  45. package/dist/index.d.ts +364 -5
  46. package/dist/index.js +845 -21
  47. package/dist/inject.d.ts.map +1 -1
  48. package/dist/types/api/cipherKeyValue.d.ts +19 -0
  49. package/dist/types/api/cipherKeyValue.d.ts.map +1 -0
  50. package/dist/types/api/export.d.ts +7 -0
  51. package/dist/types/api/export.d.ts.map +1 -1
  52. package/dist/types/api/firmwareUpdate.d.ts +13 -0
  53. package/dist/types/api/firmwareUpdate.d.ts.map +1 -0
  54. package/dist/types/api/index.d.ts +16 -0
  55. package/dist/types/api/index.d.ts.map +1 -1
  56. package/dist/types/api/nemGetAddress.d.ts +15 -0
  57. package/dist/types/api/nemGetAddress.d.ts.map +1 -0
  58. package/dist/types/api/nemSignTransaction.d.ts +93 -0
  59. package/dist/types/api/nemSignTransaction.d.ts.map +1 -0
  60. package/dist/types/api/solGetAddress.d.ts +14 -0
  61. package/dist/types/api/solGetAddress.d.ts.map +1 -0
  62. package/dist/types/api/solSignTransaction.d.ts +14 -0
  63. package/dist/types/api/solSignTransaction.d.ts.map +1 -0
  64. package/dist/types/api/stellarGetAddress.d.ts +14 -0
  65. package/dist/types/api/stellarGetAddress.d.ts.map +1 -0
  66. package/dist/types/api/stellarSignTransaction.d.ts +130 -0
  67. package/dist/types/api/stellarSignTransaction.d.ts.map +1 -0
  68. package/dist/types/device.d.ts +45 -0
  69. package/dist/types/device.d.ts.map +1 -1
  70. package/dist/types/firmware.d.ts +2 -1
  71. package/dist/types/firmware.d.ts.map +1 -1
  72. package/dist/types/params.d.ts +3 -0
  73. package/dist/types/params.d.ts.map +1 -1
  74. package/dist/utils/assets.d.ts +1 -1
  75. package/dist/utils/assets.d.ts.map +1 -1
  76. package/dist/utils/deviceFeaturesUtils.d.ts +49 -2
  77. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  78. package/dist/utils/networkUtils.d.ts.map +1 -1
  79. package/package.json +3 -3
  80. package/src/api/BaseMethod.ts +9 -0
  81. package/src/api/CipherKeyValue.ts +66 -0
  82. package/src/api/FirmwareUpdate.ts +78 -0
  83. package/src/api/device/DeviceRebootToBootloader.ts +11 -0
  84. package/src/api/evm/EVMSignMessageEIP712.ts +8 -0
  85. package/src/api/evm/EVMSignTransaction.ts +15 -0
  86. package/src/api/evm/EVMSignTypedData.ts +55 -15
  87. package/src/api/firmware/getBinary.ts +46 -0
  88. package/src/api/firmware/uploadFirmware.ts +72 -0
  89. package/src/api/helpers/hexUtils.ts +0 -1
  90. package/src/api/index.ts +12 -0
  91. package/src/api/nem/NEMGetAddress.ts +61 -0
  92. package/src/api/nem/NEMSignTransaction.ts +246 -0
  93. package/src/api/solana/SolGetAddress.ts +59 -0
  94. package/src/api/solana/SolSignTransaction.ts +69 -0
  95. package/src/api/stellar/StellarGetAddress.ts +59 -0
  96. package/src/api/stellar/StellarSignTransaction.ts +213 -0
  97. package/src/constants/errors.ts +1 -0
  98. package/src/core/index.ts +40 -5
  99. package/src/data/version.ts +1 -1
  100. package/src/device/Device.ts +4 -0
  101. package/src/device/DeviceCommands.ts +2 -0
  102. package/src/events/ui-request.ts +15 -1
  103. package/src/inject.ts +17 -0
  104. package/src/types/api/cipherKeyValue.ts +26 -0
  105. package/src/types/api/export.ts +27 -0
  106. package/src/types/api/firmwareUpdate.ts +21 -0
  107. package/src/types/api/index.ts +21 -0
  108. package/src/types/api/nemGetAddress.ts +22 -0
  109. package/src/types/api/nemSignTransaction.ts +117 -0
  110. package/src/types/api/solGetAddress.ts +21 -0
  111. package/src/types/api/solSignTransaction.ts +21 -0
  112. package/src/types/api/stellarGetAddress.ts +21 -0
  113. package/src/types/api/stellarSignTransaction.ts +153 -0
  114. package/src/types/device.ts +52 -0
  115. package/src/types/firmware.ts +2 -1
  116. package/src/types/params.ts +2 -0
  117. package/src/utils/assets.ts +1 -1
  118. package/src/utils/deviceFeaturesUtils.ts +16 -2
  119. package/src/utils/networkUtils.ts +3 -1
package/dist/index.js CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var semver = require('semver');
5
6
  var hdTransport = require('@onekeyfe/hd-transport');
6
7
  var axios = require('axios');
7
- var semver = require('semver');
8
8
  var BigNumber = require('bignumber.js');
9
9
 
10
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
11
 
12
- var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
13
12
  var semver__default = /*#__PURE__*/_interopDefaultLegacy(semver);
13
+ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
14
14
  var BigNumber__default = /*#__PURE__*/_interopDefaultLegacy(BigNumber);
15
15
 
16
16
  const inject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, }) => {
@@ -34,6 +34,7 @@ const inject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, }) => {
34
34
  checkFirmwareRelease: connectId => call({ connectId, method: 'checkFirmwareRelease' }),
35
35
  checkBLEFirmwareRelease: connectId => call({ connectId, method: 'checkBLEFirmwareRelease' }),
36
36
  checkTransportRelease: () => call({ method: 'checkTransportRelease' }),
37
+ cipherKeyValue: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'cipherKeyValue' })),
37
38
  deviceBackup: connectId => call({ connectId, method: 'deviceBackup' }),
38
39
  deviceChangePin: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceChangePin' })),
39
40
  deviceFlags: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFlags' })),
@@ -60,6 +61,13 @@ const inject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, }) => {
60
61
  starcoinSignMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'starcoinSignMessage' })),
61
62
  starcoinSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'starcoinSignTransaction' })),
62
63
  starcoinVerifyMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'starcoinVerifyMessage' })),
64
+ nemGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'nemGetAddress' })),
65
+ nemSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'nemSignTransaction' })),
66
+ solGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'solGetAddress' })),
67
+ solSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'solSignTransaction' })),
68
+ stellarGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'stellarGetAddress' })),
69
+ stellarSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'stellarSignTransaction' })),
70
+ firmwareUpdate: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'firmwareUpdate' })),
63
71
  };
64
72
  return api;
65
73
  };
@@ -79,6 +87,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
79
87
  PERFORMANCE OF THIS SOFTWARE.
80
88
  ***************************************************************************** */
81
89
 
90
+ function __rest(s, e) {
91
+ var t = {};
92
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
93
+ t[p] = s[p];
94
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
95
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
96
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
97
+ t[p[i]] = s[p[i]];
98
+ }
99
+ return t;
100
+ }
101
+
82
102
  function __awaiter(thisArg, _arguments, P, generator) {
83
103
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
84
104
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -589,6 +609,7 @@ const ERROR_CODES = {
589
609
  Method_InvalidParameter: '',
590
610
  Call_API: '',
591
611
  Call_NotResponse: 'No response data',
612
+ Method_FirmwareUpdate_DownloadFailed: '',
592
613
  Transport_InvalidProtobuf: '',
593
614
  Device_FwException: '',
594
615
  Device_UnexpectedMode: '',
@@ -701,20 +722,21 @@ const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0,
701
722
  const response = yield axios__default["default"].request({
702
723
  url,
703
724
  withCredentials: false,
725
+ responseType: type === 'binary' ? 'arraybuffer' : 'json',
704
726
  });
705
727
  if (+response.status === 200) {
706
728
  if (type === 'json') {
707
729
  return response.data;
708
730
  }
709
731
  if (type === 'binary') {
710
- return response.data.arrayBuffer();
732
+ return response.data;
711
733
  }
712
734
  return response.data;
713
735
  }
714
736
  throw new Error(`httpRequest error: ${url} ${response.statusText}`);
715
737
  });
716
738
 
717
- const httpRequest = (url, _type) => httpRequest$1(url);
739
+ const httpRequest = (url, type) => httpRequest$1(url, type);
718
740
  const getTimeStamp = () => new Date().getTime();
719
741
 
720
742
  const VER_NUMS = 3;
@@ -808,6 +830,15 @@ function create(arg, data) {
808
830
  };
809
831
  }
810
832
 
833
+ const getDeviceModel = (features) => {
834
+ if (!features || typeof features !== 'object') {
835
+ return 'model_mini';
836
+ }
837
+ if (features.model === '1') {
838
+ return 'model_mini';
839
+ }
840
+ return 'model_touch';
841
+ };
811
842
  const getDeviceType = (features) => {
812
843
  if (!features || typeof features !== 'object' || !features.serial_no) {
813
844
  return 'classic';
@@ -853,6 +884,8 @@ const getDeviceLabel = (features) => {
853
884
  return `My OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
854
885
  };
855
886
  const getDeviceFirmwareVersion = (features) => {
887
+ if (!features)
888
+ return [0, 0, 0];
856
889
  if (features.onekey_version) {
857
890
  return features.onekey_version.split('.');
858
891
  }
@@ -9933,6 +9966,7 @@ const UI_REQUEST$1 = {
9933
9966
  CLOSE_UI_WINDOW: 'ui-close_window',
9934
9967
  BLUETOOTH_PERMISSION: 'ui-bluetooth_permission',
9935
9968
  LOCATION_PERMISSION: 'ui-location_permission',
9969
+ FIRMWARE_PROGRESS: 'ui-firmware-progress',
9936
9970
  };
9937
9971
  const createUiMessage = (type, payload) => ({
9938
9972
  event: UI_EVENT,
@@ -10125,7 +10159,7 @@ const UI_REQUEST = {
10125
10159
  };
10126
10160
 
10127
10161
  const VERSION = '1.0.0-alpha.1';
10128
- const DEFAULT_DOMAIN = `https://localhost:8088/`;
10162
+ const DEFAULT_DOMAIN = `https://hardware-sdk.onekey.so/`;
10129
10163
 
10130
10164
  const DEFAULT_PRIORITY = 2;
10131
10165
  const initialSettings = {
@@ -10349,6 +10383,9 @@ class Device extends events.exports {
10349
10383
  }
10350
10384
  });
10351
10385
  }
10386
+ getCommands() {
10387
+ return this.commands;
10388
+ }
10352
10389
  getInternalState() {
10353
10390
  return this.internalState[this.instance];
10354
10391
  }
@@ -10562,6 +10599,9 @@ class BaseMethod {
10562
10599
  this.allowDeviceMode = [UI_REQUEST.INITIALIZE];
10563
10600
  this.requireDeviceMode = [];
10564
10601
  }
10602
+ getVersionRange() {
10603
+ return {};
10604
+ }
10565
10605
  setDevice(device) {
10566
10606
  this.device = device;
10567
10607
  this.connectId = device.originalDescriptor.path;
@@ -10653,7 +10693,6 @@ const formatAnyHex = value => {
10653
10693
  if (typeof value === 'object') {
10654
10694
  return modifyValues(value, value => formatAnyHex(value));
10655
10695
  }
10656
- console.log('unexpected value', value);
10657
10696
  return value;
10658
10697
  };
10659
10698
 
@@ -10710,6 +10749,53 @@ const validateParams = (values, fields) => {
10710
10749
  });
10711
10750
  };
10712
10751
 
10752
+ class CipherKeyValue extends BaseMethod {
10753
+ constructor() {
10754
+ super(...arguments);
10755
+ this.hasBundle = false;
10756
+ }
10757
+ init() {
10758
+ var _a;
10759
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
10760
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
10761
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
10762
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
10763
+ this.params = [];
10764
+ payload.bundle.forEach((batch) => {
10765
+ const addressN = validatePath(batch.path);
10766
+ validateParams(batch, [
10767
+ { name: 'path', required: true },
10768
+ { name: 'key', type: 'string' },
10769
+ { name: 'value', type: 'hexString' },
10770
+ { name: 'encrypt', type: 'boolean' },
10771
+ { name: 'askOnEncrypt', type: 'boolean' },
10772
+ { name: 'askOnDecrypt', type: 'boolean' },
10773
+ { name: 'iv', type: 'hexString' },
10774
+ ]);
10775
+ this.params.push({
10776
+ address_n: addressN,
10777
+ key: batch.key,
10778
+ value: formatAnyHex(batch.value),
10779
+ encrypt: batch.encrypt,
10780
+ ask_on_encrypt: batch.askOnEncrypt,
10781
+ ask_on_decrypt: batch.askOnDecrypt,
10782
+ iv: formatAnyHex(batch.iv),
10783
+ });
10784
+ });
10785
+ }
10786
+ run() {
10787
+ return __awaiter(this, void 0, void 0, function* () {
10788
+ const responses = [];
10789
+ for (let i = 0; i < this.params.length; i++) {
10790
+ const param = this.params[i];
10791
+ const res = yield this.device.commands.typedCall('CipherKeyValue', 'CipheredKeyValue', Object.assign({}, param));
10792
+ responses.push(Object.assign({ path: serializedPath(param.address_n) }, res.message));
10793
+ }
10794
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
10795
+ });
10796
+ }
10797
+ }
10798
+
10713
10799
  var bitcoin = [
10714
10800
  {
10715
10801
  name: "Bitcoin",
@@ -11551,6 +11637,16 @@ class DeviceFlags extends BaseMethod {
11551
11637
 
11552
11638
  class DeviceRebootToBootloader extends BaseMethod {
11553
11639
  init() { }
11640
+ getVersionRange() {
11641
+ return {
11642
+ classic: {
11643
+ min: '2.1.11',
11644
+ },
11645
+ mini: {
11646
+ min: '2.1.11',
11647
+ },
11648
+ };
11649
+ }
11554
11650
  run() {
11555
11651
  return __awaiter(this, void 0, void 0, function* () {
11556
11652
  const res = yield this.device.commands.typedCall('RebootToBootloader', 'Success');
@@ -11787,7 +11883,7 @@ class EVMSignMessage$2 extends BaseMethod {
11787
11883
  }
11788
11884
  }
11789
11885
 
11790
- class EVMSignMessageEIP712$1 extends BaseMethod {
11886
+ class EVMSignMessageEIP712 extends BaseMethod {
11791
11887
  init() {
11792
11888
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
11793
11889
  validateParams(this.payload, [
@@ -11803,6 +11899,13 @@ class EVMSignMessageEIP712$1 extends BaseMethod {
11803
11899
  message_hash: formatAnyHex(messageHash),
11804
11900
  };
11805
11901
  }
11902
+ getVersionRange() {
11903
+ return {
11904
+ model_mini: {
11905
+ min: '2.1.9',
11906
+ },
11907
+ };
11908
+ }
11806
11909
  run() {
11807
11910
  return __awaiter(this, void 0, void 0, function* () {
11808
11911
  const res = yield this.device.commands.typedCall('EthereumSignMessageEIP712', 'EthereumMessageSignature', Object.assign({}, this.params));
@@ -11923,6 +12026,20 @@ class EVMSignTransaction extends BaseMethod {
11923
12026
  validateParams(tx, schema);
11924
12027
  this.formattedTx = formatAnyHex(tx);
11925
12028
  }
12029
+ getVersionRange() {
12030
+ if (this.isEIP1559) {
12031
+ return {
12032
+ model_mini: {
12033
+ min: '2.1.11',
12034
+ },
12035
+ };
12036
+ }
12037
+ return {
12038
+ model_mini: {
12039
+ min: '1.0.0',
12040
+ },
12041
+ };
12042
+ }
11926
12043
  run() {
11927
12044
  return __awaiter(this, void 0, void 0, function* () {
11928
12045
  const { addressN, isEIP1559, formattedTx } = this;
@@ -11934,13 +12051,13 @@ class EVMSignTransaction extends BaseMethod {
11934
12051
  }
11935
12052
  }
11936
12053
 
11937
- class EVMSignMessageEIP712 extends BaseMethod {
12054
+ class EVMSignTypedData extends BaseMethod {
11938
12055
  init() {
11939
12056
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
11940
12057
  validateParams(this.payload, [
11941
12058
  { name: 'path', required: true },
11942
- { name: 'metamaskV4Compat', type: 'boolean', required: true },
11943
- { name: 'data', type: 'object', required: true },
12059
+ { name: 'metamaskV4Compat', type: 'boolean' },
12060
+ { name: 'data', type: 'object' },
11944
12061
  { name: 'domainHash', type: 'hexString' },
11945
12062
  { name: 'messageHash', type: 'hexString' },
11946
12063
  ]);
@@ -11956,28 +12073,57 @@ class EVMSignMessageEIP712 extends BaseMethod {
11956
12073
  if (messageHash) {
11957
12074
  this.params.messageHash = formatAnyHex(messageHash);
11958
12075
  }
11959
- else if (!data.primaryType || data.primaryType !== 'EIP712Domain') {
12076
+ else if (!!data && (!data.primaryType || data.primaryType !== 'EIP712Domain')) {
11960
12077
  throw TypedError('Method_InvalidParameter', 'message_hash should only be empty when data.primaryType=EIP712Domain');
11961
12078
  }
11962
12079
  }
11963
12080
  }
12081
+ getVersionRange() {
12082
+ return {
12083
+ model_mini: {
12084
+ min: '2.1.9',
12085
+ },
12086
+ };
12087
+ }
12088
+ supportSignTyped() {
12089
+ const deviceType = getDeviceType(this.device.features);
12090
+ if (deviceType === 'classic' || deviceType === 'mini') {
12091
+ const currentVersion = getDeviceFirmwareVersion(this.device.features).join('.');
12092
+ const supportSignTypedVersion = '2.2.0';
12093
+ if (semver__default["default"].lt(currentVersion, supportSignTypedVersion)) {
12094
+ return false;
12095
+ }
12096
+ }
12097
+ return true;
12098
+ }
11964
12099
  run() {
11965
12100
  return __awaiter(this, void 0, void 0, function* () {
11966
12101
  if (!this.device.features) {
11967
12102
  throw TypedError('Device_InitializeFailed', 'Device initialization failed. Please try again.');
11968
12103
  }
11969
12104
  const { addressN } = this.params;
11970
- if (this.device.features.model === '1') {
12105
+ const deviceType = getDeviceType(this.device.features);
12106
+ if (deviceType === 'classic' || deviceType === 'mini') {
11971
12107
  validateParams(this.params, [
11972
12108
  { name: 'domainHash', type: 'hexString', required: true },
11973
- { name: 'messageHash', type: 'hexString' },
12109
+ { name: 'messageHash', type: 'hexString', required: true },
11974
12110
  ]);
11975
12111
  const { domainHash, messageHash } = this.params;
11976
- const response = yield this.device.commands.typedCall('EthereumSignTypedHash', 'EthereumTypedDataSignature', {
11977
- address_n: addressN,
11978
- domain_separator_hash: domainHash !== null && domainHash !== void 0 ? domainHash : '',
11979
- message_hash: messageHash,
11980
- });
12112
+ let response;
12113
+ if (this.supportSignTyped()) {
12114
+ response = yield this.device.commands.typedCall('EthereumSignTypedHash', 'EthereumTypedDataSignature', {
12115
+ address_n: addressN,
12116
+ domain_separator_hash: domainHash !== null && domainHash !== void 0 ? domainHash : '',
12117
+ message_hash: messageHash,
12118
+ });
12119
+ }
12120
+ else {
12121
+ response = yield this.device.commands.typedCall('EthereumSignMessageEIP712', 'EthereumMessageSignature', {
12122
+ address_n: addressN,
12123
+ domain_hash: domainHash !== null && domainHash !== void 0 ? domainHash : '',
12124
+ message_hash: messageHash !== null && messageHash !== void 0 ? messageHash : '',
12125
+ });
12126
+ }
11981
12127
  return Promise.resolve(response.message);
11982
12128
  }
11983
12129
  return Promise.resolve(TypedError('Runtime', 'Not implemented'));
@@ -12153,10 +12299,663 @@ class EVMSignMessage extends BaseMethod {
12153
12299
  }
12154
12300
  }
12155
12301
 
12302
+ const MAINNET = 0x68;
12303
+ class NEMGetAddress extends BaseMethod {
12304
+ constructor() {
12305
+ super(...arguments);
12306
+ this.hasBundle = false;
12307
+ }
12308
+ init() {
12309
+ var _a;
12310
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12311
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
12312
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
12313
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
12314
+ this.params = [];
12315
+ payload.bundle.forEach((batch) => {
12316
+ var _a;
12317
+ const addressN = validatePath(batch.path, 3);
12318
+ validateParams(batch, [
12319
+ { name: 'path', required: true },
12320
+ { name: 'network', type: 'number' },
12321
+ { name: 'showOnOneKey', type: 'boolean' },
12322
+ ]);
12323
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
12324
+ this.params.push({
12325
+ address_n: addressN,
12326
+ network: batch.network || MAINNET,
12327
+ show_display: showOnOneKey,
12328
+ });
12329
+ });
12330
+ }
12331
+ run() {
12332
+ return __awaiter(this, void 0, void 0, function* () {
12333
+ const responses = [];
12334
+ for (let i = 0; i < this.params.length; i++) {
12335
+ const param = this.params[i];
12336
+ const res = yield this.device.commands.typedCall('NEMGetAddress', 'NEMAddress', Object.assign({}, param));
12337
+ responses.push(Object.assign({ path: serializedPath(param.address_n) }, res.message));
12338
+ }
12339
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
12340
+ });
12341
+ }
12342
+ }
12343
+
12344
+ const NEM_TRANSFER = 0x0101;
12345
+ const NEM_COSIGNING = 0x0102;
12346
+ const NEM_IMPORTANCE_TRANSFER = 0x0801;
12347
+ const NEM_AGGREGATE_MODIFICATION = 0x1001;
12348
+ const NEM_MULTISIG_SIGNATURE = 0x1002;
12349
+ const NEM_MULTISIG = 0x1004;
12350
+ const NEM_PROVISION_NAMESPACE = 0x2001;
12351
+ const NEM_MOSAIC_CREATION = 0x4001;
12352
+ const NEM_SUPPLY_CHANGE = 0x4002;
12353
+ class NEMSignTransaction extends BaseMethod {
12354
+ constructor() {
12355
+ super(...arguments);
12356
+ this.NEM_MOSAIC_LEVY_TYPES = {
12357
+ 1: 'MosaicLevy_Absolute',
12358
+ 2: 'MosaicLevy_Percentile',
12359
+ };
12360
+ this.NEM_SUPPLY_CHANGE_TYPES = {
12361
+ 1: 'SupplyChange_Increase',
12362
+ 2: 'SupplyChange_Decrease',
12363
+ };
12364
+ this.NEM_AGGREGATE_MODIFICATION_TYPES = {
12365
+ 1: 'CosignatoryModification_Add',
12366
+ 2: 'CosignatoryModification_Delete',
12367
+ };
12368
+ this.NEM_IMPORTANCE_TRANSFER_MODES = {
12369
+ 1: 'ImportanceTransfer_Activate',
12370
+ 2: 'ImportanceTransfer_Deactivate',
12371
+ };
12372
+ this.getCommon = (tx, address_n) => {
12373
+ var _a;
12374
+ return ({
12375
+ address_n,
12376
+ network: (tx.version >> 24) & 0xff,
12377
+ timestamp: tx.timeStamp,
12378
+ fee: tx.fee,
12379
+ deadline: (_a = tx.deadline) !== null && _a !== void 0 ? _a : 0,
12380
+ signer: address_n ? undefined : tx.signer,
12381
+ });
12382
+ };
12383
+ this.transferMessage = (tx) => {
12384
+ const mosaics = tx.mosaics
12385
+ ? tx.mosaics.map(mosaic => ({
12386
+ namespace: mosaic.mosaicId.namespaceId,
12387
+ mosaic: mosaic.mosaicId.name,
12388
+ quantity: mosaic.quantity,
12389
+ }))
12390
+ : undefined;
12391
+ return {
12392
+ recipient: tx.recipient,
12393
+ amount: tx.amount,
12394
+ payload: tx.message ? tx.message.payload : undefined,
12395
+ public_key: tx.message && tx.message.type === 0x02 ? tx.message.publicKey : undefined,
12396
+ mosaics,
12397
+ };
12398
+ };
12399
+ this.importanceTransferMessage = (tx) => ({
12400
+ mode: this.NEM_IMPORTANCE_TRANSFER_MODES[tx.importanceTransfer.mode],
12401
+ public_key: tx.importanceTransfer.publicKey,
12402
+ });
12403
+ this.aggregateModificationMessage = (tx) => {
12404
+ const modifications = tx.modifications
12405
+ ? tx.modifications.map(modification => ({
12406
+ type: this.NEM_AGGREGATE_MODIFICATION_TYPES[modification.modificationType],
12407
+ public_key: modification.cosignatoryAccount,
12408
+ }))
12409
+ : undefined;
12410
+ return {
12411
+ modifications,
12412
+ relative_change: tx.minCosignatories.relativeChange,
12413
+ };
12414
+ };
12415
+ this.provisionNamespaceMessage = (tx) => {
12416
+ var _a, _b, _c;
12417
+ return ({
12418
+ namespace: (_a = tx.newPart) !== null && _a !== void 0 ? _a : '',
12419
+ parent: tx.parent || undefined,
12420
+ sink: (_b = tx.rentalFeeSink) !== null && _b !== void 0 ? _b : '',
12421
+ fee: (_c = tx.rentalFee) !== null && _c !== void 0 ? _c : 0,
12422
+ });
12423
+ };
12424
+ this.mosaicCreationMessage = (tx) => {
12425
+ var _a, _b;
12426
+ const { levy } = tx.mosaicDefinition;
12427
+ const definition = {
12428
+ namespace: tx.mosaicDefinition.id.namespaceId,
12429
+ mosaic: tx.mosaicDefinition.id.name,
12430
+ levy: levy && levy.type ? this.NEM_MOSAIC_LEVY_TYPES[levy.type] : undefined,
12431
+ fee: levy && levy.fee,
12432
+ levy_address: levy && levy.recipient,
12433
+ levy_namespace: levy && levy.mosaicId && levy.mosaicId.namespaceId,
12434
+ levy_mosaic: levy && levy.mosaicId && levy.mosaicId.name,
12435
+ description: tx.mosaicDefinition.description,
12436
+ };
12437
+ const { properties } = tx.mosaicDefinition;
12438
+ if (Array.isArray(properties)) {
12439
+ properties.forEach(property => {
12440
+ const { name, value } = property;
12441
+ switch (name) {
12442
+ case 'divisibility':
12443
+ definition.divisibility = parseInt(value);
12444
+ break;
12445
+ case 'initialSupply':
12446
+ definition.supply = parseInt(value);
12447
+ break;
12448
+ case 'supplyMutable':
12449
+ definition.mutable_supply = value === 'true';
12450
+ break;
12451
+ case 'transferable':
12452
+ definition.transferable = value === 'true';
12453
+ break;
12454
+ }
12455
+ });
12456
+ }
12457
+ return {
12458
+ definition,
12459
+ sink: (_a = tx.creationFeeSink) !== null && _a !== void 0 ? _a : '',
12460
+ fee: (_b = tx.creationFee) !== null && _b !== void 0 ? _b : 0,
12461
+ };
12462
+ };
12463
+ this.supplyChangeMessage = (tx) => {
12464
+ var _a;
12465
+ return ({
12466
+ namespace: tx.mosaicId.namespaceId,
12467
+ mosaic: tx.mosaicId.name,
12468
+ type: this.NEM_SUPPLY_CHANGE_TYPES[tx.supplyType],
12469
+ delta: (_a = tx.delta) !== null && _a !== void 0 ? _a : 0,
12470
+ });
12471
+ };
12472
+ this.parseTx = (tx, address_n) => {
12473
+ let transaction = tx;
12474
+ const message = {
12475
+ transaction: this.getCommon(tx, address_n),
12476
+ transfer: undefined,
12477
+ importance_transfer: undefined,
12478
+ aggregate_modification: undefined,
12479
+ provision_namespace: undefined,
12480
+ mosaic_creation: undefined,
12481
+ supply_change: undefined,
12482
+ };
12483
+ if (tx.type === NEM_COSIGNING ||
12484
+ tx.type === NEM_MULTISIG ||
12485
+ tx.type === NEM_MULTISIG_SIGNATURE) {
12486
+ message.cosigning = tx.type === NEM_COSIGNING || tx.type === NEM_MULTISIG_SIGNATURE;
12487
+ transaction = tx.otherTrans;
12488
+ message.multisig = this.getCommon(transaction);
12489
+ }
12490
+ switch (transaction.type) {
12491
+ case NEM_TRANSFER:
12492
+ message.transfer = this.transferMessage(transaction);
12493
+ break;
12494
+ case NEM_IMPORTANCE_TRANSFER:
12495
+ message.importance_transfer = this.importanceTransferMessage(transaction);
12496
+ break;
12497
+ case NEM_AGGREGATE_MODIFICATION:
12498
+ message.aggregate_modification = this.aggregateModificationMessage(transaction);
12499
+ break;
12500
+ case NEM_PROVISION_NAMESPACE:
12501
+ message.provision_namespace = this.provisionNamespaceMessage(transaction);
12502
+ break;
12503
+ case NEM_MOSAIC_CREATION:
12504
+ message.mosaic_creation = this.mosaicCreationMessage(transaction);
12505
+ break;
12506
+ case NEM_SUPPLY_CHANGE:
12507
+ message.supply_change = this.supplyChangeMessage(transaction);
12508
+ break;
12509
+ default:
12510
+ throw TypedError('Method_InvalidParameter', 'Unknown transaction type');
12511
+ }
12512
+ return message;
12513
+ };
12514
+ }
12515
+ init() {
12516
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12517
+ validateParams(this.payload, [
12518
+ { name: 'path', required: true },
12519
+ { name: 'transaction', type: 'object', required: true },
12520
+ ]);
12521
+ const { path, transaction } = this.payload;
12522
+ const addressN = validatePath(path, 3);
12523
+ this.params = this.parseTx(transaction, addressN);
12524
+ }
12525
+ run() {
12526
+ return __awaiter(this, void 0, void 0, function* () {
12527
+ const res = yield this.device.commands.typedCall('NEMSignTx', 'NEMSignedTx', Object.assign({}, this.params));
12528
+ return Promise.resolve(res);
12529
+ });
12530
+ }
12531
+ }
12532
+
12533
+ class SolGetAddress extends BaseMethod {
12534
+ constructor() {
12535
+ super(...arguments);
12536
+ this.hasBundle = false;
12537
+ }
12538
+ init() {
12539
+ var _a;
12540
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12541
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
12542
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
12543
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
12544
+ this.params = [];
12545
+ payload.bundle.forEach((batch) => {
12546
+ var _a;
12547
+ const addressN = validatePath(batch.path, 3);
12548
+ validateParams(batch, [
12549
+ { name: 'path', required: true },
12550
+ { name: 'showOnOneKey', type: 'boolean' },
12551
+ ]);
12552
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
12553
+ this.params.push({
12554
+ address_n: addressN,
12555
+ show_display: showOnOneKey,
12556
+ });
12557
+ });
12558
+ }
12559
+ run() {
12560
+ return __awaiter(this, void 0, void 0, function* () {
12561
+ const responses = [];
12562
+ for (let i = 0; i < this.params.length; i++) {
12563
+ const param = this.params[i];
12564
+ const res = yield this.device.commands.typedCall('SolanaGetAddress', 'SolanaAddress', Object.assign({}, param));
12565
+ const { address } = res.message;
12566
+ responses.push({
12567
+ path: serializedPath(param.address_n),
12568
+ address,
12569
+ });
12570
+ }
12571
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
12572
+ });
12573
+ }
12574
+ }
12575
+
12576
+ class SolSignTransaction extends BaseMethod {
12577
+ constructor() {
12578
+ super(...arguments);
12579
+ this.hasBundle = false;
12580
+ }
12581
+ init() {
12582
+ var _a;
12583
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12584
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
12585
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
12586
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
12587
+ this.params = [];
12588
+ payload.bundle.forEach((batch) => {
12589
+ const addressN = validatePath(batch.path, 3);
12590
+ validateParams(batch, [
12591
+ { name: 'path', required: true },
12592
+ { name: 'rawTx', type: 'hexString', required: true },
12593
+ ]);
12594
+ this.params.push({
12595
+ address_n: addressN,
12596
+ raw_tx: formatAnyHex(batch.rawTx),
12597
+ });
12598
+ });
12599
+ }
12600
+ getVersionRange() {
12601
+ return {
12602
+ classic: {
12603
+ min: '2.1.9',
12604
+ },
12605
+ mini: {
12606
+ min: '2.1.9',
12607
+ },
12608
+ };
12609
+ }
12610
+ run() {
12611
+ return __awaiter(this, void 0, void 0, function* () {
12612
+ const responses = [];
12613
+ for (let i = 0; i < this.params.length; i++) {
12614
+ const param = this.params[i];
12615
+ const res = yield this.device.commands.typedCall('SolanaSignTx', 'SolanaSignedTx', Object.assign({}, param));
12616
+ const { signature } = res.message;
12617
+ responses.push({
12618
+ path: serializedPath(param.address_n),
12619
+ signature,
12620
+ });
12621
+ }
12622
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
12623
+ });
12624
+ }
12625
+ }
12626
+
12627
+ class StellarGetAddress extends BaseMethod {
12628
+ constructor() {
12629
+ super(...arguments);
12630
+ this.hasBundle = false;
12631
+ }
12632
+ init() {
12633
+ var _a;
12634
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12635
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
12636
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
12637
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
12638
+ this.params = [];
12639
+ payload.bundle.forEach((batch) => {
12640
+ var _a;
12641
+ const addressN = validatePath(batch.path, 3);
12642
+ validateParams(batch, [
12643
+ { name: 'path', required: true },
12644
+ { name: 'showOnOneKey', type: 'boolean' },
12645
+ ]);
12646
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
12647
+ this.params.push({
12648
+ address_n: addressN,
12649
+ show_display: showOnOneKey,
12650
+ });
12651
+ });
12652
+ }
12653
+ run() {
12654
+ return __awaiter(this, void 0, void 0, function* () {
12655
+ const responses = [];
12656
+ for (let i = 0; i < this.params.length; i++) {
12657
+ const param = this.params[i];
12658
+ const res = yield this.device.commands.typedCall('StellarGetAddress', 'StellarAddress', Object.assign({}, param));
12659
+ const { address } = res.message;
12660
+ responses.push({
12661
+ path: serializedPath(param.address_n),
12662
+ address,
12663
+ });
12664
+ }
12665
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
12666
+ });
12667
+ }
12668
+ }
12669
+
12670
+ class StellarSignTransaction extends BaseMethod {
12671
+ constructor() {
12672
+ super(...arguments);
12673
+ this.operations = [];
12674
+ this.parseOperation = (op) => {
12675
+ switch (op.type) {
12676
+ case 'createAccount':
12677
+ validateParams(op, [
12678
+ { name: 'destination', type: 'string', required: true },
12679
+ { name: 'startingBalance', type: 'bigNumber', required: true },
12680
+ ]);
12681
+ return {
12682
+ type: 'StellarCreateAccountOp',
12683
+ source_account: op.source,
12684
+ new_account: op.destination,
12685
+ starting_balance: op.startingBalance,
12686
+ };
12687
+ case 'payment':
12688
+ validateParams(op, [
12689
+ { name: 'destination', type: 'string', required: true },
12690
+ { name: 'amount', type: 'bigNumber', required: true },
12691
+ { name: 'asset', required: true },
12692
+ ]);
12693
+ return {
12694
+ type: 'StellarPaymentOp',
12695
+ source_account: op.source,
12696
+ destination_account: op.destination,
12697
+ asset: op.asset,
12698
+ amount: op.amount,
12699
+ };
12700
+ case 'pathPayment':
12701
+ validateParams(op, [{ name: 'destAmount', type: 'bigNumber', required: true }]);
12702
+ return {
12703
+ type: 'StellarPathPaymentOp',
12704
+ source_account: op.source,
12705
+ send_asset: op.sendAsset,
12706
+ send_max: op.sendMax,
12707
+ destination_account: op.destination,
12708
+ destination_asset: op.destAsset,
12709
+ destination_amount: op.destAmount,
12710
+ paths: op.path,
12711
+ };
12712
+ case 'createPassiveOffer':
12713
+ validateParams(op, [{ name: 'amount', type: 'bigNumber', required: true }]);
12714
+ return {
12715
+ type: 'StellarCreatePassiveOfferOp',
12716
+ source_account: op.source,
12717
+ buying_asset: op.buying,
12718
+ selling_asset: op.selling,
12719
+ amount: op.amount,
12720
+ price_n: op.price.n,
12721
+ price_d: op.price.d,
12722
+ };
12723
+ case 'manageOffer':
12724
+ validateParams(op, [{ name: 'amount', type: 'bigNumber', required: true }]);
12725
+ return {
12726
+ type: 'StellarManageOfferOp',
12727
+ source_account: op.source,
12728
+ buying_asset: op.buying,
12729
+ selling_asset: op.selling,
12730
+ amount: op.amount,
12731
+ offer_id: op.offerId,
12732
+ price_n: op.price.n,
12733
+ price_d: op.price.d,
12734
+ };
12735
+ case 'setOptions': {
12736
+ const signer = op.signer
12737
+ ? {
12738
+ signer_type: op.signer.type,
12739
+ signer_key: op.signer.key,
12740
+ signer_weight: op.signer.weight,
12741
+ }
12742
+ : undefined;
12743
+ return Object.assign({ type: 'StellarSetOptionsOp', source_account: op.source, clear_flags: op.clearFlags, set_flags: op.setFlags, master_weight: op.masterWeight, low_threshold: op.lowThreshold, medium_threshold: op.medThreshold, high_threshold: op.highThreshold, home_domain: op.homeDomain, inflation_destination_account: op.inflationDest }, signer);
12744
+ }
12745
+ case 'changeTrust':
12746
+ validateParams(op, [{ name: 'limit', type: 'bigNumber' }]);
12747
+ return {
12748
+ type: 'StellarChangeTrustOp',
12749
+ source_account: op.source,
12750
+ asset: op.line,
12751
+ limit: op.limit,
12752
+ };
12753
+ case 'allowTrust':
12754
+ return {
12755
+ type: 'StellarAllowTrustOp',
12756
+ source_account: op.source,
12757
+ trusted_account: op.trustor,
12758
+ asset_type: op.assetType,
12759
+ asset_code: op.assetCode,
12760
+ is_authorized: op.authorize ? 1 : 0,
12761
+ };
12762
+ case 'accountMerge':
12763
+ return {
12764
+ type: 'StellarAccountMergeOp',
12765
+ source_account: op.source,
12766
+ destination_account: op.destination,
12767
+ };
12768
+ case 'manageData':
12769
+ return {
12770
+ type: 'StellarManageDataOp',
12771
+ source_account: op.source,
12772
+ key: op.name,
12773
+ value: op.value,
12774
+ };
12775
+ case 'bumpSequence':
12776
+ return {
12777
+ type: 'StellarBumpSequenceOp',
12778
+ source_account: op.source,
12779
+ bump_to: op.bumpTo,
12780
+ };
12781
+ default:
12782
+ return {};
12783
+ }
12784
+ };
12785
+ this.processTxRequest = (operations, index) => __awaiter(this, void 0, void 0, function* () {
12786
+ const isLastOp = index + 1 >= operations.length;
12787
+ const _a = operations[index], { type } = _a, op = __rest(_a, ["type"]);
12788
+ if (isLastOp) {
12789
+ const response = yield this.device.commands.typedCall(type, 'StellarSignedTx', op);
12790
+ return response.message;
12791
+ }
12792
+ yield this.device.commands.typedCall(type, 'StellarTxOpRequest', op);
12793
+ return this.processTxRequest(operations, index + 1);
12794
+ });
12795
+ }
12796
+ init() {
12797
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12798
+ validateParams(this.payload, [
12799
+ { name: 'path', required: true },
12800
+ { name: 'networkPassphrase', type: 'string', required: true },
12801
+ { name: 'transaction', type: 'object', required: true },
12802
+ ]);
12803
+ const addressN = validatePath(this.payload.path, 3);
12804
+ const { transaction, networkPassphrase } = this.payload;
12805
+ this.params = {
12806
+ address_n: addressN,
12807
+ network_passphrase: networkPassphrase,
12808
+ source_account: transaction.source,
12809
+ fee: transaction.fee,
12810
+ sequence_number: transaction.sequence,
12811
+ num_operations: transaction.operations.length,
12812
+ };
12813
+ if (transaction.timebounds) {
12814
+ this.params.timebounds_start = transaction.timebounds.minTime;
12815
+ this.params.timebounds_end = transaction.timebounds.maxTime;
12816
+ }
12817
+ if (transaction.memo) {
12818
+ this.params.memo_type = transaction.memo.type;
12819
+ this.params.memo_text = transaction.memo.text;
12820
+ this.params.memo_id = transaction.memo.id;
12821
+ this.params.memo_hash = transaction.memo.hash;
12822
+ }
12823
+ transaction.operations.forEach(op => {
12824
+ const transformed = this.parseOperation(op);
12825
+ if (transformed) {
12826
+ this.operations.push(transformed);
12827
+ }
12828
+ });
12829
+ console.log('StellarSignTransactionParams', this.params);
12830
+ console.log('StellarSignTransactionOperations', this.operations);
12831
+ }
12832
+ run() {
12833
+ return __awaiter(this, void 0, void 0, function* () {
12834
+ yield this.device.commands.typedCall('StellarSignTx', 'StellarTxOpRequest', Object.assign({}, this.params));
12835
+ return this.processTxRequest(this.operations, 0);
12836
+ });
12837
+ }
12838
+ }
12839
+
12840
+ const getBinary = ({ features, updateType, version }) => __awaiter(void 0, void 0, void 0, function* () {
12841
+ const releaseInfo = getInfo({ features, updateType });
12842
+ if (!releaseInfo) {
12843
+ throw TypedError('Runtime', 'no firmware found for this device');
12844
+ }
12845
+ if (version &&
12846
+ !semver__default["default"].eq(releaseInfo.version, version)) {
12847
+ throw TypedError('Runtime', 'firmware version mismatch');
12848
+ }
12849
+ const url = updateType === 'ble' ? releaseInfo.webUpdate : releaseInfo.url;
12850
+ const fw = yield httpRequest(url, 'binary');
12851
+ return Object.assign(Object.assign({}, releaseInfo), { binary: fw });
12852
+ });
12853
+ const getInfo = ({ features, updateType }) => {
12854
+ var _a, _b, _c;
12855
+ const deviceType = getDeviceType(features);
12856
+ const { deviceMap } = DataManager;
12857
+ 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;
12858
+ return releaseInfo;
12859
+ };
12860
+
12861
+ const postConfirmationMessage = (device) => {
12862
+ var _a;
12863
+ if ((_a = device.features) === null || _a === void 0 ? void 0 : _a.firmware_present) {
12864
+ device.emit(DEVICE.BUTTON, device, { code: 'ButtonRequest_FirmwareUpdate' });
12865
+ }
12866
+ };
12867
+ const postProgressMessage = (device, progress, postMessage) => {
12868
+ postMessage(createUiMessage(UI_REQUEST$1.FIRMWARE_PROGRESS, {
12869
+ device: device.toMessageObject(),
12870
+ progress,
12871
+ }));
12872
+ };
12873
+ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload }) => __awaiter(void 0, void 0, void 0, function* () {
12874
+ var _a, _b;
12875
+ if (((_a = device.features) === null || _a === void 0 ? void 0 : _a.major_version) === 1) {
12876
+ postConfirmationMessage(device);
12877
+ const eraseCommand = updateType === 'firmware' ? 'FirmwareErase' : 'FirmwareErase_ex';
12878
+ yield typedCall(eraseCommand, 'Success', {});
12879
+ postProgressMessage(device, 0, postMessage);
12880
+ const { message } = yield typedCall('FirmwareUpload', 'Success', {
12881
+ payload,
12882
+ });
12883
+ return message;
12884
+ }
12885
+ if (((_b = device.features) === null || _b === void 0 ? void 0 : _b.major_version) === 2) {
12886
+ postConfirmationMessage(device);
12887
+ const length = payload.byteLength;
12888
+ let response = yield typedCall('FirmwareErase', ['FirmwareRequest', 'Success'], { length });
12889
+ while (response.type !== 'Success') {
12890
+ const start = response.message.offset;
12891
+ const end = response.message.offset + response.message.length;
12892
+ const chunk = payload.slice(start, end);
12893
+ if (start > 0) {
12894
+ postProgressMessage(device, Math.round((start / length) * 100), postMessage);
12895
+ }
12896
+ response = yield typedCall('FirmwareUpload', ['FirmwareRequest', 'Success'], {
12897
+ payload: chunk,
12898
+ });
12899
+ }
12900
+ postProgressMessage(device, 100, postMessage);
12901
+ return response.message;
12902
+ }
12903
+ throw TypedError('Runtime', 'uploadFirmware: unknown major_version');
12904
+ });
12905
+
12906
+ class FirmwareUpdate extends BaseMethod {
12907
+ init() {
12908
+ this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.INITIALIZE];
12909
+ this.requireDeviceMode = [UI_REQUEST.BOOTLOADER];
12910
+ const { payload } = this;
12911
+ validateParams(payload, [
12912
+ { name: 'version', type: 'array' },
12913
+ { name: 'binary', type: 'buffer' },
12914
+ ]);
12915
+ if (!payload.updateType) {
12916
+ throw TypedError('Method_InvalidParameter', 'updateType is required');
12917
+ }
12918
+ this.params = { updateType: payload.updateType };
12919
+ if ('version' in payload) {
12920
+ this.params = Object.assign(Object.assign({}, this.params), { version: payload.version });
12921
+ }
12922
+ if ('binary' in payload) {
12923
+ this.params = Object.assign(Object.assign({}, this.params), { binary: payload.binary });
12924
+ }
12925
+ }
12926
+ run() {
12927
+ return __awaiter(this, void 0, void 0, function* () {
12928
+ const { device, params } = this;
12929
+ let binary;
12930
+ try {
12931
+ if (params.binary) {
12932
+ binary = this.params.binary;
12933
+ }
12934
+ else {
12935
+ if (!device.features) {
12936
+ throw TypedError('Runtime', 'no features found for this device');
12937
+ }
12938
+ const firmware = yield getBinary({
12939
+ features: device.features,
12940
+ version: params.version,
12941
+ updateType: params.updateType,
12942
+ });
12943
+ binary = firmware.binary;
12944
+ }
12945
+ }
12946
+ catch (err) {
12947
+ throw TypedError('Method_FirmwareUpdate_DownloadFailed', err);
12948
+ }
12949
+ return uploadFirmware(params.updateType, this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, { payload: binary });
12950
+ });
12951
+ }
12952
+ }
12953
+
12156
12954
  var ApiMethods = /*#__PURE__*/Object.freeze({
12157
12955
  __proto__: null,
12158
12956
  searchDevices: SearchDevices,
12159
12957
  getFeatures: GetFeatures,
12958
+ cipherKeyValue: CipherKeyValue,
12160
12959
  btcGetAddress: BTCGetAddress,
12161
12960
  btcGetPublicKey: BTCGetPublicKey,
12162
12961
  btcSignMessage: BTCSignMessage,
@@ -12177,15 +12976,22 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
12177
12976
  evmGetAddress: EvmGetAddress,
12178
12977
  evmGetPublicKey: EVMGetPublicKey,
12179
12978
  evmSignMessage: EVMSignMessage$2,
12180
- evmSignMessageEIP712: EVMSignMessageEIP712$1,
12979
+ evmSignMessageEIP712: EVMSignMessageEIP712,
12181
12980
  evmSignTransaction: EVMSignTransaction,
12182
- evmSignTypedData: EVMSignMessageEIP712,
12981
+ evmSignTypedData: EVMSignTypedData,
12183
12982
  evmVerifyMessage: EVMSignMessage$1,
12184
12983
  starcoinGetAddress: StarcoinGetAddress,
12185
12984
  starcoinGetPublicKey: StarcoinGetPublicKey,
12186
12985
  starcoinSignMessage: StarcoinSignMessage,
12187
12986
  starcoinSignTransaction: StarcoinSignTransaction,
12188
- starcoinVerifyMessage: EVMSignMessage
12987
+ starcoinVerifyMessage: EVMSignMessage,
12988
+ nemGetAddress: NEMGetAddress,
12989
+ nemSignTransaction: NEMSignTransaction,
12990
+ solGetAddress: SolGetAddress,
12991
+ solSignTransaction: SolSignTransaction,
12992
+ stellarGetAddress: StellarGetAddress,
12993
+ stellarSignTransaction: StellarSignTransaction,
12994
+ firmwareUpdate: FirmwareUpdate
12189
12995
  });
12190
12996
 
12191
12997
  function findMethod(message) {
@@ -12359,6 +13165,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
12359
13165
  try {
12360
13166
  method = findMethod(message);
12361
13167
  method.connector = _connector;
13168
+ method.postMessage = postMessage;
12362
13169
  method.init();
12363
13170
  }
12364
13171
  catch (error) {
@@ -12403,6 +13210,22 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
12403
13210
  });
12404
13211
  try {
12405
13212
  const inner = () => __awaiter(void 0, void 0, void 0, function* () {
13213
+ const deviceType = getDeviceType(device.features);
13214
+ const deviceModel = getDeviceModel(device.features);
13215
+ const versionRangeType = method.getVersionRange()[deviceType];
13216
+ const versionRangeModel = method.getVersionRange()[deviceModel];
13217
+ const versionRange = versionRangeType !== null && versionRangeType !== void 0 ? versionRangeType : versionRangeModel;
13218
+ if (versionRange && device.features) {
13219
+ const currentVersion = getDeviceFirmwareVersion(device.features).join('.');
13220
+ if (semver__default["default"].valid(versionRange.min) && semver__default["default"].lt(currentVersion, versionRange.min)) {
13221
+ return Promise.reject(TypedError('Device_FwException', `Device firmware version is too low, please update to ${versionRange.min}`));
13222
+ }
13223
+ if (versionRange.max &&
13224
+ semver__default["default"].valid(versionRange.max) &&
13225
+ semver__default["default"].gt(currentVersion, versionRange.max)) {
13226
+ return Promise.reject(TypedError('Device_FwException', `Device firmware version is too high, this method has been deprecated in ${versionRange.max}`));
13227
+ }
13228
+ }
12406
13229
  const unexpectedMode = device.hasUnexpectedMode(method.allowDeviceMode, method.requireDeviceMode);
12407
13230
  if (unexpectedMode) {
12408
13231
  return Promise.reject(TypedError('Device_UnexpectedMode', unexpectedMode));
@@ -12436,6 +13259,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
12436
13259
  catch (error) {
12437
13260
  messageResponse = createResponseMessage(method.responseID, false, error);
12438
13261
  _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.reject(TypedError('Call_API', error));
13262
+ Log.debug('Call API - Run Error: ', error);
12439
13263
  }
12440
13264
  finally {
12441
13265
  const response = messageResponse;