@onekeyfe/hd-core 0.0.6 → 0.0.9

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 (93) hide show
  1. package/dist/api/BaseMethod.d.ts +2 -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/SearchDevices.d.ts +1 -1
  6. package/dist/api/SearchDevices.d.ts.map +1 -1
  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/helpers/hexUtils.d.ts.map +1 -1
  16. package/dist/api/index.d.ts +7 -0
  17. package/dist/api/index.d.ts.map +1 -1
  18. package/dist/api/nem/NEMGetAddress.d.ts +9 -0
  19. package/dist/api/nem/NEMGetAddress.d.ts.map +1 -0
  20. package/dist/api/nem/NEMSignTransaction.d.ts +20 -0
  21. package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -0
  22. package/dist/api/solana/SolGetAddress.d.ts +9 -0
  23. package/dist/api/solana/SolGetAddress.d.ts.map +1 -0
  24. package/dist/api/solana/SolSignTransaction.d.ts +17 -0
  25. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -0
  26. package/dist/api/stellar/StellarGetAddress.d.ts +9 -0
  27. package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -0
  28. package/dist/api/stellar/StellarSignTransaction.d.ts +335 -0
  29. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -0
  30. package/dist/core/index.d.ts.map +1 -1
  31. package/dist/data/version.d.ts +1 -1
  32. package/dist/data/version.d.ts.map +1 -1
  33. package/dist/events/ui-request.d.ts +1 -1
  34. package/dist/events/ui-request.d.ts.map +1 -1
  35. package/dist/index.d.ts +301 -3
  36. package/dist/index.js +755 -21
  37. package/dist/inject.d.ts.map +1 -1
  38. package/dist/types/api/cipherKeyValue.d.ts +19 -0
  39. package/dist/types/api/cipherKeyValue.d.ts.map +1 -0
  40. package/dist/types/api/export.d.ts +7 -0
  41. package/dist/types/api/export.d.ts.map +1 -1
  42. package/dist/types/api/index.d.ts +14 -0
  43. package/dist/types/api/index.d.ts.map +1 -1
  44. package/dist/types/api/nemGetAddress.d.ts +15 -0
  45. package/dist/types/api/nemGetAddress.d.ts.map +1 -0
  46. package/dist/types/api/nemSignTransaction.d.ts +93 -0
  47. package/dist/types/api/nemSignTransaction.d.ts.map +1 -0
  48. package/dist/types/api/solGetAddress.d.ts +14 -0
  49. package/dist/types/api/solGetAddress.d.ts.map +1 -0
  50. package/dist/types/api/solSignTransaction.d.ts +14 -0
  51. package/dist/types/api/solSignTransaction.d.ts.map +1 -0
  52. package/dist/types/api/stellarGetAddress.d.ts +14 -0
  53. package/dist/types/api/stellarGetAddress.d.ts.map +1 -0
  54. package/dist/types/api/stellarSignTransaction.d.ts +130 -0
  55. package/dist/types/api/stellarSignTransaction.d.ts.map +1 -0
  56. package/dist/types/device.d.ts +7 -0
  57. package/dist/types/device.d.ts.map +1 -1
  58. package/dist/utils/deviceFeaturesUtils.d.ts +51 -2
  59. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  60. package/dist/utils/index.d.ts +1 -1
  61. package/dist/utils/index.d.ts.map +1 -1
  62. package/package.json +3 -3
  63. package/src/api/BaseMethod.ts +5 -0
  64. package/src/api/CipherKeyValue.ts +66 -0
  65. package/src/api/SearchDevices.ts +2 -2
  66. package/src/api/device/DeviceRebootToBootloader.ts +11 -0
  67. package/src/api/evm/EVMSignMessageEIP712.ts +8 -0
  68. package/src/api/evm/EVMSignTransaction.ts +15 -0
  69. package/src/api/evm/EVMSignTypedData.ts +55 -15
  70. package/src/api/helpers/hexUtils.ts +0 -1
  71. package/src/api/index.ts +10 -0
  72. package/src/api/nem/NEMGetAddress.ts +61 -0
  73. package/src/api/nem/NEMSignTransaction.ts +246 -0
  74. package/src/api/solana/SolGetAddress.ts +59 -0
  75. package/src/api/solana/SolSignTransaction.ts +69 -0
  76. package/src/api/stellar/StellarGetAddress.ts +59 -0
  77. package/src/api/stellar/StellarSignTransaction.ts +213 -0
  78. package/src/core/index.ts +50 -6
  79. package/src/data/version.ts +1 -1
  80. package/src/events/ui-request.ts +1 -1
  81. package/src/inject.ts +15 -0
  82. package/src/types/api/cipherKeyValue.ts +26 -0
  83. package/src/types/api/export.ts +27 -0
  84. package/src/types/api/index.ts +18 -0
  85. package/src/types/api/nemGetAddress.ts +22 -0
  86. package/src/types/api/nemSignTransaction.ts +117 -0
  87. package/src/types/api/solGetAddress.ts +21 -0
  88. package/src/types/api/solSignTransaction.ts +21 -0
  89. package/src/types/api/stellarGetAddress.ts +21 -0
  90. package/src/types/api/stellarSignTransaction.ts +153 -0
  91. package/src/types/device.ts +8 -0
  92. package/src/utils/deviceFeaturesUtils.ts +34 -2
  93. package/src/utils/index.ts +7 -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,12 @@ 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' })),
63
70
  };
64
71
  return api;
65
72
  };
@@ -79,6 +86,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
79
86
  PERFORMANCE OF THIS SOFTWARE.
80
87
  ***************************************************************************** */
81
88
 
89
+ function __rest(s, e) {
90
+ var t = {};
91
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
92
+ t[p] = s[p];
93
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
94
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
95
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
96
+ t[p[i]] = s[p[i]];
97
+ }
98
+ return t;
99
+ }
100
+
82
101
  function __awaiter(thisArg, _arguments, P, generator) {
83
102
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
84
103
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -808,12 +827,41 @@ function create(arg, data) {
808
827
  };
809
828
  }
810
829
 
830
+ const getDeviceModel = (features) => {
831
+ if (!features || typeof features !== 'object') {
832
+ return 'model_mini';
833
+ }
834
+ if (features.model === '1') {
835
+ return 'model_mini';
836
+ }
837
+ return 'model_touch';
838
+ };
811
839
  const getDeviceType = (features) => {
812
840
  if (!features || typeof features !== 'object' || !features.serial_no) {
813
841
  return 'classic';
814
842
  }
815
843
  const serialNo = features.serial_no;
816
844
  const miniFlag = serialNo.slice(0, 2);
845
+ if (miniFlag.toLowerCase() === 'mi')
846
+ return 'mini';
847
+ if (miniFlag.toLowerCase() === 'tc')
848
+ return 'touch';
849
+ return 'classic';
850
+ };
851
+ const getDeviceTypeByBleName = (name) => {
852
+ if (!name)
853
+ return 'classic';
854
+ if (name.startsWith('MI'))
855
+ return 'mini';
856
+ if (name.startsWith('T'))
857
+ return 'touch';
858
+ return 'classic';
859
+ };
860
+ const getDeviceTypeByDeviceId = (deviceId) => {
861
+ if (!deviceId) {
862
+ return 'classic';
863
+ }
864
+ const miniFlag = deviceId.slice(0, 2);
817
865
  if (miniFlag.toLowerCase() === 'mi')
818
866
  return 'mini';
819
867
  return 'classic';
@@ -833,6 +881,8 @@ const getDeviceLabel = (features) => {
833
881
  return `My OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
834
882
  };
835
883
  const getDeviceFirmwareVersion = (features) => {
884
+ if (!features)
885
+ return [0, 0, 0];
836
886
  if (features.onekey_version) {
837
887
  return features.onekey_version.split('.');
838
888
  }
@@ -10105,7 +10155,7 @@ const UI_REQUEST = {
10105
10155
  };
10106
10156
 
10107
10157
  const VERSION = '1.0.0-alpha.1';
10108
- const DEFAULT_DOMAIN = `https://localhost:8088/`;
10158
+ const DEFAULT_DOMAIN = `https://hardware-sdk.onekey.so/`;
10109
10159
 
10110
10160
  const DEFAULT_PRIORITY = 2;
10111
10161
  const initialSettings = {
@@ -10542,6 +10592,9 @@ class BaseMethod {
10542
10592
  this.allowDeviceMode = [UI_REQUEST.INITIALIZE];
10543
10593
  this.requireDeviceMode = [];
10544
10594
  }
10595
+ getVersionRange() {
10596
+ return {};
10597
+ }
10545
10598
  setDevice(device) {
10546
10599
  this.device = device;
10547
10600
  this.connectId = device.originalDescriptor.path;
@@ -10562,7 +10615,10 @@ class SearchDevices extends BaseMethod {
10562
10615
  const devicesDescriptor = (_c = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _c !== void 0 ? _c : [];
10563
10616
  const env = DataManager.getSettings('env');
10564
10617
  if (env === 'react-native') {
10565
- return devicesDescriptor.map(device => (Object.assign(Object.assign({}, device), { connectId: device.id, deviceType: 'classic' })));
10618
+ return devicesDescriptor.map(device => {
10619
+ var _a;
10620
+ return (Object.assign(Object.assign({}, device), { connectId: device.id, deviceType: getDeviceTypeByBleName((_a = device.name) !== null && _a !== void 0 ? _a : '') }));
10621
+ });
10566
10622
  }
10567
10623
  const devices = [];
10568
10624
  try {
@@ -10630,7 +10686,6 @@ const formatAnyHex = value => {
10630
10686
  if (typeof value === 'object') {
10631
10687
  return modifyValues(value, value => formatAnyHex(value));
10632
10688
  }
10633
- console.log('unexpected value', value);
10634
10689
  return value;
10635
10690
  };
10636
10691
 
@@ -10687,6 +10742,53 @@ const validateParams = (values, fields) => {
10687
10742
  });
10688
10743
  };
10689
10744
 
10745
+ class CipherKeyValue extends BaseMethod {
10746
+ constructor() {
10747
+ super(...arguments);
10748
+ this.hasBundle = false;
10749
+ }
10750
+ init() {
10751
+ var _a;
10752
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
10753
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
10754
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
10755
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
10756
+ this.params = [];
10757
+ payload.bundle.forEach((batch) => {
10758
+ const addressN = validatePath(batch.path);
10759
+ validateParams(batch, [
10760
+ { name: 'path', required: true },
10761
+ { name: 'key', type: 'string' },
10762
+ { name: 'value', type: 'hexString' },
10763
+ { name: 'encrypt', type: 'boolean' },
10764
+ { name: 'askOnEncrypt', type: 'boolean' },
10765
+ { name: 'askOnDecrypt', type: 'boolean' },
10766
+ { name: 'iv', type: 'hexString' },
10767
+ ]);
10768
+ this.params.push({
10769
+ address_n: addressN,
10770
+ key: batch.key,
10771
+ value: formatAnyHex(batch.value),
10772
+ encrypt: batch.encrypt,
10773
+ ask_on_encrypt: batch.askOnEncrypt,
10774
+ ask_on_decrypt: batch.askOnDecrypt,
10775
+ iv: formatAnyHex(batch.iv),
10776
+ });
10777
+ });
10778
+ }
10779
+ run() {
10780
+ return __awaiter(this, void 0, void 0, function* () {
10781
+ const responses = [];
10782
+ for (let i = 0; i < this.params.length; i++) {
10783
+ const param = this.params[i];
10784
+ const res = yield this.device.commands.typedCall('CipherKeyValue', 'CipheredKeyValue', Object.assign({}, param));
10785
+ responses.push(Object.assign({ path: serializedPath(param.address_n) }, res.message));
10786
+ }
10787
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
10788
+ });
10789
+ }
10790
+ }
10791
+
10690
10792
  var bitcoin = [
10691
10793
  {
10692
10794
  name: "Bitcoin",
@@ -11528,6 +11630,16 @@ class DeviceFlags extends BaseMethod {
11528
11630
 
11529
11631
  class DeviceRebootToBootloader extends BaseMethod {
11530
11632
  init() { }
11633
+ getVersionRange() {
11634
+ return {
11635
+ classic: {
11636
+ min: '2.1.11',
11637
+ },
11638
+ mini: {
11639
+ min: '2.1.11',
11640
+ },
11641
+ };
11642
+ }
11531
11643
  run() {
11532
11644
  return __awaiter(this, void 0, void 0, function* () {
11533
11645
  const res = yield this.device.commands.typedCall('RebootToBootloader', 'Success');
@@ -11764,7 +11876,7 @@ class EVMSignMessage$2 extends BaseMethod {
11764
11876
  }
11765
11877
  }
11766
11878
 
11767
- class EVMSignMessageEIP712$1 extends BaseMethod {
11879
+ class EVMSignMessageEIP712 extends BaseMethod {
11768
11880
  init() {
11769
11881
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
11770
11882
  validateParams(this.payload, [
@@ -11780,6 +11892,13 @@ class EVMSignMessageEIP712$1 extends BaseMethod {
11780
11892
  message_hash: formatAnyHex(messageHash),
11781
11893
  };
11782
11894
  }
11895
+ getVersionRange() {
11896
+ return {
11897
+ model_mini: {
11898
+ min: '2.1.9',
11899
+ },
11900
+ };
11901
+ }
11783
11902
  run() {
11784
11903
  return __awaiter(this, void 0, void 0, function* () {
11785
11904
  const res = yield this.device.commands.typedCall('EthereumSignMessageEIP712', 'EthereumMessageSignature', Object.assign({}, this.params));
@@ -11900,6 +12019,20 @@ class EVMSignTransaction extends BaseMethod {
11900
12019
  validateParams(tx, schema);
11901
12020
  this.formattedTx = formatAnyHex(tx);
11902
12021
  }
12022
+ getVersionRange() {
12023
+ if (this.isEIP1559) {
12024
+ return {
12025
+ model_mini: {
12026
+ min: '2.1.11',
12027
+ },
12028
+ };
12029
+ }
12030
+ return {
12031
+ model_mini: {
12032
+ min: '1.0.0',
12033
+ },
12034
+ };
12035
+ }
11903
12036
  run() {
11904
12037
  return __awaiter(this, void 0, void 0, function* () {
11905
12038
  const { addressN, isEIP1559, formattedTx } = this;
@@ -11911,13 +12044,13 @@ class EVMSignTransaction extends BaseMethod {
11911
12044
  }
11912
12045
  }
11913
12046
 
11914
- class EVMSignMessageEIP712 extends BaseMethod {
12047
+ class EVMSignTypedData extends BaseMethod {
11915
12048
  init() {
11916
12049
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
11917
12050
  validateParams(this.payload, [
11918
12051
  { name: 'path', required: true },
11919
- { name: 'metamaskV4Compat', type: 'boolean', required: true },
11920
- { name: 'data', type: 'object', required: true },
12052
+ { name: 'metamaskV4Compat', type: 'boolean' },
12053
+ { name: 'data', type: 'object' },
11921
12054
  { name: 'domainHash', type: 'hexString' },
11922
12055
  { name: 'messageHash', type: 'hexString' },
11923
12056
  ]);
@@ -11933,28 +12066,57 @@ class EVMSignMessageEIP712 extends BaseMethod {
11933
12066
  if (messageHash) {
11934
12067
  this.params.messageHash = formatAnyHex(messageHash);
11935
12068
  }
11936
- else if (!data.primaryType || data.primaryType !== 'EIP712Domain') {
12069
+ else if (!!data && (!data.primaryType || data.primaryType !== 'EIP712Domain')) {
11937
12070
  throw TypedError('Method_InvalidParameter', 'message_hash should only be empty when data.primaryType=EIP712Domain');
11938
12071
  }
11939
12072
  }
11940
12073
  }
12074
+ getVersionRange() {
12075
+ return {
12076
+ model_mini: {
12077
+ min: '2.1.9',
12078
+ },
12079
+ };
12080
+ }
12081
+ supportSignTyped() {
12082
+ const deviceType = getDeviceType(this.device.features);
12083
+ if (deviceType === 'classic' || deviceType === 'mini') {
12084
+ const currentVersion = getDeviceFirmwareVersion(this.device.features).join('.');
12085
+ const supportSignTypedVersion = '2.2.0';
12086
+ if (semver__default["default"].lt(currentVersion, supportSignTypedVersion)) {
12087
+ return false;
12088
+ }
12089
+ }
12090
+ return true;
12091
+ }
11941
12092
  run() {
11942
12093
  return __awaiter(this, void 0, void 0, function* () {
11943
12094
  if (!this.device.features) {
11944
12095
  throw TypedError('Device_InitializeFailed', 'Device initialization failed. Please try again.');
11945
12096
  }
11946
12097
  const { addressN } = this.params;
11947
- if (this.device.features.model === '1') {
12098
+ const deviceType = getDeviceType(this.device.features);
12099
+ if (deviceType === 'classic' || deviceType === 'mini') {
11948
12100
  validateParams(this.params, [
11949
12101
  { name: 'domainHash', type: 'hexString', required: true },
11950
- { name: 'messageHash', type: 'hexString' },
12102
+ { name: 'messageHash', type: 'hexString', required: true },
11951
12103
  ]);
11952
12104
  const { domainHash, messageHash } = this.params;
11953
- const response = yield this.device.commands.typedCall('EthereumSignTypedHash', 'EthereumTypedDataSignature', {
11954
- address_n: addressN,
11955
- domain_separator_hash: domainHash !== null && domainHash !== void 0 ? domainHash : '',
11956
- message_hash: messageHash,
11957
- });
12105
+ let response;
12106
+ if (this.supportSignTyped()) {
12107
+ response = yield this.device.commands.typedCall('EthereumSignTypedHash', 'EthereumTypedDataSignature', {
12108
+ address_n: addressN,
12109
+ domain_separator_hash: domainHash !== null && domainHash !== void 0 ? domainHash : '',
12110
+ message_hash: messageHash,
12111
+ });
12112
+ }
12113
+ else {
12114
+ response = yield this.device.commands.typedCall('EthereumSignMessageEIP712', 'EthereumMessageSignature', {
12115
+ address_n: addressN,
12116
+ domain_hash: domainHash !== null && domainHash !== void 0 ? domainHash : '',
12117
+ message_hash: messageHash !== null && messageHash !== void 0 ? messageHash : '',
12118
+ });
12119
+ }
11958
12120
  return Promise.resolve(response.message);
11959
12121
  }
11960
12122
  return Promise.resolve(TypedError('Runtime', 'Not implemented'));
@@ -12130,10 +12292,549 @@ class EVMSignMessage extends BaseMethod {
12130
12292
  }
12131
12293
  }
12132
12294
 
12295
+ const MAINNET = 0x68;
12296
+ class NEMGetAddress extends BaseMethod {
12297
+ constructor() {
12298
+ super(...arguments);
12299
+ this.hasBundle = false;
12300
+ }
12301
+ init() {
12302
+ var _a;
12303
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12304
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
12305
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
12306
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
12307
+ this.params = [];
12308
+ payload.bundle.forEach((batch) => {
12309
+ var _a;
12310
+ const addressN = validatePath(batch.path, 3);
12311
+ validateParams(batch, [
12312
+ { name: 'path', required: true },
12313
+ { name: 'network', type: 'number' },
12314
+ { name: 'showOnOneKey', type: 'boolean' },
12315
+ ]);
12316
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
12317
+ this.params.push({
12318
+ address_n: addressN,
12319
+ network: batch.network || MAINNET,
12320
+ show_display: showOnOneKey,
12321
+ });
12322
+ });
12323
+ }
12324
+ run() {
12325
+ return __awaiter(this, void 0, void 0, function* () {
12326
+ const responses = [];
12327
+ for (let i = 0; i < this.params.length; i++) {
12328
+ const param = this.params[i];
12329
+ const res = yield this.device.commands.typedCall('NEMGetAddress', 'NEMAddress', Object.assign({}, param));
12330
+ responses.push(Object.assign({ path: serializedPath(param.address_n) }, res.message));
12331
+ }
12332
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
12333
+ });
12334
+ }
12335
+ }
12336
+
12337
+ const NEM_TRANSFER = 0x0101;
12338
+ const NEM_COSIGNING = 0x0102;
12339
+ const NEM_IMPORTANCE_TRANSFER = 0x0801;
12340
+ const NEM_AGGREGATE_MODIFICATION = 0x1001;
12341
+ const NEM_MULTISIG_SIGNATURE = 0x1002;
12342
+ const NEM_MULTISIG = 0x1004;
12343
+ const NEM_PROVISION_NAMESPACE = 0x2001;
12344
+ const NEM_MOSAIC_CREATION = 0x4001;
12345
+ const NEM_SUPPLY_CHANGE = 0x4002;
12346
+ class NEMSignTransaction extends BaseMethod {
12347
+ constructor() {
12348
+ super(...arguments);
12349
+ this.NEM_MOSAIC_LEVY_TYPES = {
12350
+ 1: 'MosaicLevy_Absolute',
12351
+ 2: 'MosaicLevy_Percentile',
12352
+ };
12353
+ this.NEM_SUPPLY_CHANGE_TYPES = {
12354
+ 1: 'SupplyChange_Increase',
12355
+ 2: 'SupplyChange_Decrease',
12356
+ };
12357
+ this.NEM_AGGREGATE_MODIFICATION_TYPES = {
12358
+ 1: 'CosignatoryModification_Add',
12359
+ 2: 'CosignatoryModification_Delete',
12360
+ };
12361
+ this.NEM_IMPORTANCE_TRANSFER_MODES = {
12362
+ 1: 'ImportanceTransfer_Activate',
12363
+ 2: 'ImportanceTransfer_Deactivate',
12364
+ };
12365
+ this.getCommon = (tx, address_n) => {
12366
+ var _a;
12367
+ return ({
12368
+ address_n,
12369
+ network: (tx.version >> 24) & 0xff,
12370
+ timestamp: tx.timeStamp,
12371
+ fee: tx.fee,
12372
+ deadline: (_a = tx.deadline) !== null && _a !== void 0 ? _a : 0,
12373
+ signer: address_n ? undefined : tx.signer,
12374
+ });
12375
+ };
12376
+ this.transferMessage = (tx) => {
12377
+ const mosaics = tx.mosaics
12378
+ ? tx.mosaics.map(mosaic => ({
12379
+ namespace: mosaic.mosaicId.namespaceId,
12380
+ mosaic: mosaic.mosaicId.name,
12381
+ quantity: mosaic.quantity,
12382
+ }))
12383
+ : undefined;
12384
+ return {
12385
+ recipient: tx.recipient,
12386
+ amount: tx.amount,
12387
+ payload: tx.message ? tx.message.payload : undefined,
12388
+ public_key: tx.message && tx.message.type === 0x02 ? tx.message.publicKey : undefined,
12389
+ mosaics,
12390
+ };
12391
+ };
12392
+ this.importanceTransferMessage = (tx) => ({
12393
+ mode: this.NEM_IMPORTANCE_TRANSFER_MODES[tx.importanceTransfer.mode],
12394
+ public_key: tx.importanceTransfer.publicKey,
12395
+ });
12396
+ this.aggregateModificationMessage = (tx) => {
12397
+ const modifications = tx.modifications
12398
+ ? tx.modifications.map(modification => ({
12399
+ type: this.NEM_AGGREGATE_MODIFICATION_TYPES[modification.modificationType],
12400
+ public_key: modification.cosignatoryAccount,
12401
+ }))
12402
+ : undefined;
12403
+ return {
12404
+ modifications,
12405
+ relative_change: tx.minCosignatories.relativeChange,
12406
+ };
12407
+ };
12408
+ this.provisionNamespaceMessage = (tx) => {
12409
+ var _a, _b, _c;
12410
+ return ({
12411
+ namespace: (_a = tx.newPart) !== null && _a !== void 0 ? _a : '',
12412
+ parent: tx.parent || undefined,
12413
+ sink: (_b = tx.rentalFeeSink) !== null && _b !== void 0 ? _b : '',
12414
+ fee: (_c = tx.rentalFee) !== null && _c !== void 0 ? _c : 0,
12415
+ });
12416
+ };
12417
+ this.mosaicCreationMessage = (tx) => {
12418
+ var _a, _b;
12419
+ const { levy } = tx.mosaicDefinition;
12420
+ const definition = {
12421
+ namespace: tx.mosaicDefinition.id.namespaceId,
12422
+ mosaic: tx.mosaicDefinition.id.name,
12423
+ levy: levy && levy.type ? this.NEM_MOSAIC_LEVY_TYPES[levy.type] : undefined,
12424
+ fee: levy && levy.fee,
12425
+ levy_address: levy && levy.recipient,
12426
+ levy_namespace: levy && levy.mosaicId && levy.mosaicId.namespaceId,
12427
+ levy_mosaic: levy && levy.mosaicId && levy.mosaicId.name,
12428
+ description: tx.mosaicDefinition.description,
12429
+ };
12430
+ const { properties } = tx.mosaicDefinition;
12431
+ if (Array.isArray(properties)) {
12432
+ properties.forEach(property => {
12433
+ const { name, value } = property;
12434
+ switch (name) {
12435
+ case 'divisibility':
12436
+ definition.divisibility = parseInt(value);
12437
+ break;
12438
+ case 'initialSupply':
12439
+ definition.supply = parseInt(value);
12440
+ break;
12441
+ case 'supplyMutable':
12442
+ definition.mutable_supply = value === 'true';
12443
+ break;
12444
+ case 'transferable':
12445
+ definition.transferable = value === 'true';
12446
+ break;
12447
+ }
12448
+ });
12449
+ }
12450
+ return {
12451
+ definition,
12452
+ sink: (_a = tx.creationFeeSink) !== null && _a !== void 0 ? _a : '',
12453
+ fee: (_b = tx.creationFee) !== null && _b !== void 0 ? _b : 0,
12454
+ };
12455
+ };
12456
+ this.supplyChangeMessage = (tx) => {
12457
+ var _a;
12458
+ return ({
12459
+ namespace: tx.mosaicId.namespaceId,
12460
+ mosaic: tx.mosaicId.name,
12461
+ type: this.NEM_SUPPLY_CHANGE_TYPES[tx.supplyType],
12462
+ delta: (_a = tx.delta) !== null && _a !== void 0 ? _a : 0,
12463
+ });
12464
+ };
12465
+ this.parseTx = (tx, address_n) => {
12466
+ let transaction = tx;
12467
+ const message = {
12468
+ transaction: this.getCommon(tx, address_n),
12469
+ transfer: undefined,
12470
+ importance_transfer: undefined,
12471
+ aggregate_modification: undefined,
12472
+ provision_namespace: undefined,
12473
+ mosaic_creation: undefined,
12474
+ supply_change: undefined,
12475
+ };
12476
+ if (tx.type === NEM_COSIGNING ||
12477
+ tx.type === NEM_MULTISIG ||
12478
+ tx.type === NEM_MULTISIG_SIGNATURE) {
12479
+ message.cosigning = tx.type === NEM_COSIGNING || tx.type === NEM_MULTISIG_SIGNATURE;
12480
+ transaction = tx.otherTrans;
12481
+ message.multisig = this.getCommon(transaction);
12482
+ }
12483
+ switch (transaction.type) {
12484
+ case NEM_TRANSFER:
12485
+ message.transfer = this.transferMessage(transaction);
12486
+ break;
12487
+ case NEM_IMPORTANCE_TRANSFER:
12488
+ message.importance_transfer = this.importanceTransferMessage(transaction);
12489
+ break;
12490
+ case NEM_AGGREGATE_MODIFICATION:
12491
+ message.aggregate_modification = this.aggregateModificationMessage(transaction);
12492
+ break;
12493
+ case NEM_PROVISION_NAMESPACE:
12494
+ message.provision_namespace = this.provisionNamespaceMessage(transaction);
12495
+ break;
12496
+ case NEM_MOSAIC_CREATION:
12497
+ message.mosaic_creation = this.mosaicCreationMessage(transaction);
12498
+ break;
12499
+ case NEM_SUPPLY_CHANGE:
12500
+ message.supply_change = this.supplyChangeMessage(transaction);
12501
+ break;
12502
+ default:
12503
+ throw TypedError('Method_InvalidParameter', 'Unknown transaction type');
12504
+ }
12505
+ return message;
12506
+ };
12507
+ }
12508
+ init() {
12509
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12510
+ validateParams(this.payload, [
12511
+ { name: 'path', required: true },
12512
+ { name: 'transaction', type: 'object', required: true },
12513
+ ]);
12514
+ const { path, transaction } = this.payload;
12515
+ const addressN = validatePath(path, 3);
12516
+ this.params = this.parseTx(transaction, addressN);
12517
+ }
12518
+ run() {
12519
+ return __awaiter(this, void 0, void 0, function* () {
12520
+ const res = yield this.device.commands.typedCall('NEMSignTx', 'NEMSignedTx', Object.assign({}, this.params));
12521
+ return Promise.resolve(res);
12522
+ });
12523
+ }
12524
+ }
12525
+
12526
+ class SolGetAddress extends BaseMethod {
12527
+ constructor() {
12528
+ super(...arguments);
12529
+ this.hasBundle = false;
12530
+ }
12531
+ init() {
12532
+ var _a;
12533
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12534
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
12535
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
12536
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
12537
+ this.params = [];
12538
+ payload.bundle.forEach((batch) => {
12539
+ var _a;
12540
+ const addressN = validatePath(batch.path, 3);
12541
+ validateParams(batch, [
12542
+ { name: 'path', required: true },
12543
+ { name: 'showOnOneKey', type: 'boolean' },
12544
+ ]);
12545
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
12546
+ this.params.push({
12547
+ address_n: addressN,
12548
+ show_display: showOnOneKey,
12549
+ });
12550
+ });
12551
+ }
12552
+ run() {
12553
+ return __awaiter(this, void 0, void 0, function* () {
12554
+ const responses = [];
12555
+ for (let i = 0; i < this.params.length; i++) {
12556
+ const param = this.params[i];
12557
+ const res = yield this.device.commands.typedCall('SolanaGetAddress', 'SolanaAddress', Object.assign({}, param));
12558
+ const { address } = res.message;
12559
+ responses.push({
12560
+ path: serializedPath(param.address_n),
12561
+ address,
12562
+ });
12563
+ }
12564
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
12565
+ });
12566
+ }
12567
+ }
12568
+
12569
+ class SolSignTransaction extends BaseMethod {
12570
+ constructor() {
12571
+ super(...arguments);
12572
+ this.hasBundle = false;
12573
+ }
12574
+ init() {
12575
+ var _a;
12576
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12577
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
12578
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
12579
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
12580
+ this.params = [];
12581
+ payload.bundle.forEach((batch) => {
12582
+ const addressN = validatePath(batch.path, 3);
12583
+ validateParams(batch, [
12584
+ { name: 'path', required: true },
12585
+ { name: 'rawTx', type: 'hexString', required: true },
12586
+ ]);
12587
+ this.params.push({
12588
+ address_n: addressN,
12589
+ raw_tx: formatAnyHex(batch.rawTx),
12590
+ });
12591
+ });
12592
+ }
12593
+ getVersionRange() {
12594
+ return {
12595
+ classic: {
12596
+ min: '2.1.9',
12597
+ },
12598
+ mini: {
12599
+ min: '2.1.9',
12600
+ },
12601
+ };
12602
+ }
12603
+ run() {
12604
+ return __awaiter(this, void 0, void 0, function* () {
12605
+ const responses = [];
12606
+ for (let i = 0; i < this.params.length; i++) {
12607
+ const param = this.params[i];
12608
+ const res = yield this.device.commands.typedCall('SolanaSignTx', 'SolanaSignedTx', Object.assign({}, param));
12609
+ const { signature } = res.message;
12610
+ responses.push({
12611
+ path: serializedPath(param.address_n),
12612
+ signature,
12613
+ });
12614
+ }
12615
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
12616
+ });
12617
+ }
12618
+ }
12619
+
12620
+ class StellarGetAddress extends BaseMethod {
12621
+ constructor() {
12622
+ super(...arguments);
12623
+ this.hasBundle = false;
12624
+ }
12625
+ init() {
12626
+ var _a;
12627
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12628
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
12629
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
12630
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
12631
+ this.params = [];
12632
+ payload.bundle.forEach((batch) => {
12633
+ var _a;
12634
+ const addressN = validatePath(batch.path, 3);
12635
+ validateParams(batch, [
12636
+ { name: 'path', required: true },
12637
+ { name: 'showOnOneKey', type: 'boolean' },
12638
+ ]);
12639
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
12640
+ this.params.push({
12641
+ address_n: addressN,
12642
+ show_display: showOnOneKey,
12643
+ });
12644
+ });
12645
+ }
12646
+ run() {
12647
+ return __awaiter(this, void 0, void 0, function* () {
12648
+ const responses = [];
12649
+ for (let i = 0; i < this.params.length; i++) {
12650
+ const param = this.params[i];
12651
+ const res = yield this.device.commands.typedCall('StellarGetAddress', 'StellarAddress', Object.assign({}, param));
12652
+ const { address } = res.message;
12653
+ responses.push({
12654
+ path: serializedPath(param.address_n),
12655
+ address,
12656
+ });
12657
+ }
12658
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
12659
+ });
12660
+ }
12661
+ }
12662
+
12663
+ class StellarSignTransaction extends BaseMethod {
12664
+ constructor() {
12665
+ super(...arguments);
12666
+ this.operations = [];
12667
+ this.parseOperation = (op) => {
12668
+ switch (op.type) {
12669
+ case 'createAccount':
12670
+ validateParams(op, [
12671
+ { name: 'destination', type: 'string', required: true },
12672
+ { name: 'startingBalance', type: 'bigNumber', required: true },
12673
+ ]);
12674
+ return {
12675
+ type: 'StellarCreateAccountOp',
12676
+ source_account: op.source,
12677
+ new_account: op.destination,
12678
+ starting_balance: op.startingBalance,
12679
+ };
12680
+ case 'payment':
12681
+ validateParams(op, [
12682
+ { name: 'destination', type: 'string', required: true },
12683
+ { name: 'amount', type: 'bigNumber', required: true },
12684
+ { name: 'asset', required: true },
12685
+ ]);
12686
+ return {
12687
+ type: 'StellarPaymentOp',
12688
+ source_account: op.source,
12689
+ destination_account: op.destination,
12690
+ asset: op.asset,
12691
+ amount: op.amount,
12692
+ };
12693
+ case 'pathPayment':
12694
+ validateParams(op, [{ name: 'destAmount', type: 'bigNumber', required: true }]);
12695
+ return {
12696
+ type: 'StellarPathPaymentOp',
12697
+ source_account: op.source,
12698
+ send_asset: op.sendAsset,
12699
+ send_max: op.sendMax,
12700
+ destination_account: op.destination,
12701
+ destination_asset: op.destAsset,
12702
+ destination_amount: op.destAmount,
12703
+ paths: op.path,
12704
+ };
12705
+ case 'createPassiveOffer':
12706
+ validateParams(op, [{ name: 'amount', type: 'bigNumber', required: true }]);
12707
+ return {
12708
+ type: 'StellarCreatePassiveOfferOp',
12709
+ source_account: op.source,
12710
+ buying_asset: op.buying,
12711
+ selling_asset: op.selling,
12712
+ amount: op.amount,
12713
+ price_n: op.price.n,
12714
+ price_d: op.price.d,
12715
+ };
12716
+ case 'manageOffer':
12717
+ validateParams(op, [{ name: 'amount', type: 'bigNumber', required: true }]);
12718
+ return {
12719
+ type: 'StellarManageOfferOp',
12720
+ source_account: op.source,
12721
+ buying_asset: op.buying,
12722
+ selling_asset: op.selling,
12723
+ amount: op.amount,
12724
+ offer_id: op.offerId,
12725
+ price_n: op.price.n,
12726
+ price_d: op.price.d,
12727
+ };
12728
+ case 'setOptions': {
12729
+ const signer = op.signer
12730
+ ? {
12731
+ signer_type: op.signer.type,
12732
+ signer_key: op.signer.key,
12733
+ signer_weight: op.signer.weight,
12734
+ }
12735
+ : undefined;
12736
+ 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);
12737
+ }
12738
+ case 'changeTrust':
12739
+ validateParams(op, [{ name: 'limit', type: 'bigNumber' }]);
12740
+ return {
12741
+ type: 'StellarChangeTrustOp',
12742
+ source_account: op.source,
12743
+ asset: op.line,
12744
+ limit: op.limit,
12745
+ };
12746
+ case 'allowTrust':
12747
+ return {
12748
+ type: 'StellarAllowTrustOp',
12749
+ source_account: op.source,
12750
+ trusted_account: op.trustor,
12751
+ asset_type: op.assetType,
12752
+ asset_code: op.assetCode,
12753
+ is_authorized: op.authorize ? 1 : 0,
12754
+ };
12755
+ case 'accountMerge':
12756
+ return {
12757
+ type: 'StellarAccountMergeOp',
12758
+ source_account: op.source,
12759
+ destination_account: op.destination,
12760
+ };
12761
+ case 'manageData':
12762
+ return {
12763
+ type: 'StellarManageDataOp',
12764
+ source_account: op.source,
12765
+ key: op.name,
12766
+ value: op.value,
12767
+ };
12768
+ case 'bumpSequence':
12769
+ return {
12770
+ type: 'StellarBumpSequenceOp',
12771
+ source_account: op.source,
12772
+ bump_to: op.bumpTo,
12773
+ };
12774
+ default:
12775
+ return {};
12776
+ }
12777
+ };
12778
+ this.processTxRequest = (operations, index) => __awaiter(this, void 0, void 0, function* () {
12779
+ const isLastOp = index + 1 >= operations.length;
12780
+ const _a = operations[index], { type } = _a, op = __rest(_a, ["type"]);
12781
+ if (isLastOp) {
12782
+ const response = yield this.device.commands.typedCall(type, 'StellarSignedTx', op);
12783
+ return response.message;
12784
+ }
12785
+ yield this.device.commands.typedCall(type, 'StellarTxOpRequest', op);
12786
+ return this.processTxRequest(operations, index + 1);
12787
+ });
12788
+ }
12789
+ init() {
12790
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12791
+ validateParams(this.payload, [
12792
+ { name: 'path', required: true },
12793
+ { name: 'networkPassphrase', type: 'string', required: true },
12794
+ { name: 'transaction', type: 'object', required: true },
12795
+ ]);
12796
+ const addressN = validatePath(this.payload.path, 3);
12797
+ const { transaction, networkPassphrase } = this.payload;
12798
+ this.params = {
12799
+ address_n: addressN,
12800
+ network_passphrase: networkPassphrase,
12801
+ source_account: transaction.source,
12802
+ fee: transaction.fee,
12803
+ sequence_number: transaction.sequence,
12804
+ num_operations: transaction.operations.length,
12805
+ };
12806
+ if (transaction.timebounds) {
12807
+ this.params.timebounds_start = transaction.timebounds.minTime;
12808
+ this.params.timebounds_end = transaction.timebounds.maxTime;
12809
+ }
12810
+ if (transaction.memo) {
12811
+ this.params.memo_type = transaction.memo.type;
12812
+ this.params.memo_text = transaction.memo.text;
12813
+ this.params.memo_id = transaction.memo.id;
12814
+ this.params.memo_hash = transaction.memo.hash;
12815
+ }
12816
+ transaction.operations.forEach(op => {
12817
+ const transformed = this.parseOperation(op);
12818
+ if (transformed) {
12819
+ this.operations.push(transformed);
12820
+ }
12821
+ });
12822
+ console.log('StellarSignTransactionParams', this.params);
12823
+ console.log('StellarSignTransactionOperations', this.operations);
12824
+ }
12825
+ run() {
12826
+ return __awaiter(this, void 0, void 0, function* () {
12827
+ yield this.device.commands.typedCall('StellarSignTx', 'StellarTxOpRequest', Object.assign({}, this.params));
12828
+ return this.processTxRequest(this.operations, 0);
12829
+ });
12830
+ }
12831
+ }
12832
+
12133
12833
  var ApiMethods = /*#__PURE__*/Object.freeze({
12134
12834
  __proto__: null,
12135
12835
  searchDevices: SearchDevices,
12136
12836
  getFeatures: GetFeatures,
12837
+ cipherKeyValue: CipherKeyValue,
12137
12838
  btcGetAddress: BTCGetAddress,
12138
12839
  btcGetPublicKey: BTCGetPublicKey,
12139
12840
  btcSignMessage: BTCSignMessage,
@@ -12154,15 +12855,21 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
12154
12855
  evmGetAddress: EvmGetAddress,
12155
12856
  evmGetPublicKey: EVMGetPublicKey,
12156
12857
  evmSignMessage: EVMSignMessage$2,
12157
- evmSignMessageEIP712: EVMSignMessageEIP712$1,
12858
+ evmSignMessageEIP712: EVMSignMessageEIP712,
12158
12859
  evmSignTransaction: EVMSignTransaction,
12159
- evmSignTypedData: EVMSignMessageEIP712,
12860
+ evmSignTypedData: EVMSignTypedData,
12160
12861
  evmVerifyMessage: EVMSignMessage$1,
12161
12862
  starcoinGetAddress: StarcoinGetAddress,
12162
12863
  starcoinGetPublicKey: StarcoinGetPublicKey,
12163
12864
  starcoinSignMessage: StarcoinSignMessage,
12164
12865
  starcoinSignTransaction: StarcoinSignTransaction,
12165
- starcoinVerifyMessage: EVMSignMessage
12866
+ starcoinVerifyMessage: EVMSignMessage,
12867
+ nemGetAddress: NEMGetAddress,
12868
+ nemSignTransaction: NEMSignTransaction,
12869
+ solGetAddress: SolGetAddress,
12870
+ solSignTransaction: SolSignTransaction,
12871
+ stellarGetAddress: StellarGetAddress,
12872
+ stellarSignTransaction: StellarSignTransaction
12166
12873
  });
12167
12874
 
12168
12875
  function findMethod(message) {
@@ -12380,6 +13087,22 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
12380
13087
  });
12381
13088
  try {
12382
13089
  const inner = () => __awaiter(void 0, void 0, void 0, function* () {
13090
+ const deviceType = getDeviceType(device.features);
13091
+ const deviceModel = getDeviceModel(device.features);
13092
+ const versionRangeType = method.getVersionRange()[deviceType];
13093
+ const versionRangeModel = method.getVersionRange()[deviceModel];
13094
+ const versionRange = versionRangeType !== null && versionRangeType !== void 0 ? versionRangeType : versionRangeModel;
13095
+ if (versionRange && device.features) {
13096
+ const currentVersion = getDeviceFirmwareVersion(device.features).join('.');
13097
+ if (semver__default["default"].valid(versionRange.min) && semver__default["default"].lt(currentVersion, versionRange.min)) {
13098
+ return Promise.reject(TypedError('Device_FwException', `Device firmware version is too low, please update to ${versionRange.min}`));
13099
+ }
13100
+ if (versionRange.max &&
13101
+ semver__default["default"].valid(versionRange.max) &&
13102
+ semver__default["default"].gt(currentVersion, versionRange.max)) {
13103
+ return Promise.reject(TypedError('Device_FwException', `Device firmware version is too high, this method has been deprecated in ${versionRange.max}`));
13104
+ }
13105
+ }
12383
13106
  const unexpectedMode = device.hasUnexpectedMode(method.allowDeviceMode, method.requireDeviceMode);
12384
13107
  if (unexpectedMode) {
12385
13108
  return Promise.reject(TypedError('Device_UnexpectedMode', unexpectedMode));
@@ -12413,6 +13136,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
12413
13136
  catch (error) {
12414
13137
  messageResponse = createResponseMessage(method.responseID, false, error);
12415
13138
  _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.reject(TypedError('Call_API', error));
13139
+ Log.debug('Call API - Run Error: ', error);
12416
13140
  }
12417
13141
  finally {
12418
13142
  const response = messageResponse;
@@ -12491,7 +13215,15 @@ const onDevicePinHandler = (...[device, type, callback]) => __awaiter(void 0, vo
12491
13215
  });
12492
13216
  const onDeviceButtonHandler = (...[device, request]) => {
12493
13217
  postMessage(createDeviceMessage(DEVICE.BUTTON, Object.assign(Object.assign({}, request), { device: device.toMessageObject() })));
12494
- postMessage(createUiMessage(UI_REQUEST$1.REQUEST_BUTTON, { device: device.toMessageObject() }));
13218
+ if (request.code === 'ButtonRequest_PinEntry') {
13219
+ postMessage(createUiMessage(UI_REQUEST$1.REQUEST_PIN, {
13220
+ device: device.toMessageObject(),
13221
+ type: 'ButtonRequest_PinEntry',
13222
+ }));
13223
+ }
13224
+ else {
13225
+ postMessage(createUiMessage(UI_REQUEST$1.REQUEST_BUTTON, { device: device.toMessageObject() }));
13226
+ }
12495
13227
  };
12496
13228
  const postMessage = (message) => {
12497
13229
  _core.emit(CORE_EVENT, message);
@@ -12600,6 +13332,8 @@ exports["default"] = HardwareSdk;
12600
13332
  exports.enableLog = enableLog;
12601
13333
  exports.getDeviceLabel = getDeviceLabel;
12602
13334
  exports.getDeviceType = getDeviceType;
13335
+ exports.getDeviceTypeByBleName = getDeviceTypeByBleName;
13336
+ exports.getDeviceTypeByDeviceId = getDeviceTypeByDeviceId;
12603
13337
  exports.getDeviceUUID = getDeviceUUID;
12604
13338
  exports.getEnv = getEnv;
12605
13339
  exports.getHDPath = getHDPath;