@onekeyfe/hd-web-sdk 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.
@@ -4023,12 +4023,12 @@ __webpack_unused_export__ = ({
4023
4023
  value: true
4024
4024
  });
4025
4025
 
4026
+ var semver = __webpack_require__(7699);
4027
+
4026
4028
  var hdTransport = __webpack_require__(7495);
4027
4029
 
4028
4030
  var axios = __webpack_require__(9644);
4029
4031
 
4030
- var semver = __webpack_require__(7699);
4031
-
4032
4032
  var BigNumber = __webpack_require__(6391);
4033
4033
 
4034
4034
  function _interopDefaultLegacy(e) {
@@ -4037,10 +4037,10 @@ function _interopDefaultLegacy(e) {
4037
4037
  };
4038
4038
  }
4039
4039
 
4040
- var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
4041
-
4042
4040
  var semver__default = /*#__PURE__*/_interopDefaultLegacy(semver);
4043
4041
 
4042
+ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
4043
+
4044
4044
  var BigNumber__default = /*#__PURE__*/_interopDefaultLegacy(BigNumber);
4045
4045
 
4046
4046
  const inject = ({
@@ -4084,6 +4084,10 @@ const inject = ({
4084
4084
  checkTransportRelease: () => call({
4085
4085
  method: 'checkTransportRelease'
4086
4086
  }),
4087
+ cipherKeyValue: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4088
+ connectId,
4089
+ method: 'cipherKeyValue'
4090
+ })),
4087
4091
  deviceBackup: connectId => call({
4088
4092
  connectId,
4089
4093
  method: 'deviceBackup'
@@ -4187,6 +4191,34 @@ const inject = ({
4187
4191
  starcoinVerifyMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4188
4192
  connectId,
4189
4193
  method: 'starcoinVerifyMessage'
4194
+ })),
4195
+ nemGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4196
+ connectId,
4197
+ method: 'nemGetAddress'
4198
+ })),
4199
+ nemSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4200
+ connectId,
4201
+ method: 'nemSignTransaction'
4202
+ })),
4203
+ solGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4204
+ connectId,
4205
+ method: 'solGetAddress'
4206
+ })),
4207
+ solSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4208
+ connectId,
4209
+ method: 'solSignTransaction'
4210
+ })),
4211
+ stellarGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4212
+ connectId,
4213
+ method: 'stellarGetAddress'
4214
+ })),
4215
+ stellarSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4216
+ connectId,
4217
+ method: 'stellarSignTransaction'
4218
+ })),
4219
+ firmwareUpdate: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4220
+ connectId,
4221
+ method: 'firmwareUpdate'
4190
4222
  }))
4191
4223
  };
4192
4224
  return api;
@@ -4207,6 +4239,17 @@ PERFORMANCE OF THIS SOFTWARE.
4207
4239
  ***************************************************************************** */
4208
4240
 
4209
4241
 
4242
+ function __rest(s, e) {
4243
+ var t = {};
4244
+
4245
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
4246
+
4247
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
4248
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
4249
+ }
4250
+ return t;
4251
+ }
4252
+
4210
4253
  function __awaiter(thisArg, _arguments, P, generator) {
4211
4254
  function adopt(value) {
4212
4255
  return value instanceof P ? value : new P(function (resolve) {
@@ -4733,6 +4776,7 @@ const ERROR_CODES = {
4733
4776
  Method_InvalidParameter: '',
4734
4777
  Call_API: '',
4735
4778
  Call_NotResponse: 'No response data',
4779
+ Method_FirmwareUpdate_DownloadFailed: '',
4736
4780
  Transport_InvalidProtobuf: '',
4737
4781
  Device_FwException: '',
4738
4782
  Device_UnexpectedMode: '',
@@ -4865,7 +4909,8 @@ const enableLog = enabled => {
4865
4909
  const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0, function* () {
4866
4910
  const response = yield axios__default["default"].request({
4867
4911
  url,
4868
- withCredentials: false
4912
+ withCredentials: false,
4913
+ responseType: type === 'binary' ? 'arraybuffer' : 'json'
4869
4914
  });
4870
4915
 
4871
4916
  if (+response.status === 200) {
@@ -4874,7 +4919,7 @@ const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0,
4874
4919
  }
4875
4920
 
4876
4921
  if (type === 'binary') {
4877
- return response.data.arrayBuffer();
4922
+ return response.data;
4878
4923
  }
4879
4924
 
4880
4925
  return response.data;
@@ -4883,7 +4928,7 @@ const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0,
4883
4928
  throw new Error(`httpRequest error: ${url} ${response.statusText}`);
4884
4929
  });
4885
4930
 
4886
- const httpRequest = (url, _type) => httpRequest$1(url);
4931
+ const httpRequest = (url, type) => httpRequest$1(url, type);
4887
4932
 
4888
4933
  const getTimeStamp = () => new Date().getTime();
4889
4934
 
@@ -4998,6 +5043,18 @@ function create(arg, data) {
4998
5043
  };
4999
5044
  }
5000
5045
 
5046
+ const getDeviceModel = features => {
5047
+ if (!features || typeof features !== 'object') {
5048
+ return 'model_mini';
5049
+ }
5050
+
5051
+ if (features.model === '1') {
5052
+ return 'model_mini';
5053
+ }
5054
+
5055
+ return 'model_touch';
5056
+ };
5057
+
5001
5058
  const getDeviceType = features => {
5002
5059
  if (!features || typeof features !== 'object' || !features.serial_no) {
5003
5060
  return 'classic';
@@ -5048,6 +5105,8 @@ const getDeviceLabel = features => {
5048
5105
  };
5049
5106
 
5050
5107
  const getDeviceFirmwareVersion = features => {
5108
+ if (!features) return [0, 0, 0];
5109
+
5051
5110
  if (features.onekey_version) {
5052
5111
  return features.onekey_version.split('.');
5053
5112
  }
@@ -14089,7 +14148,8 @@ const UI_REQUEST$1 = {
14089
14148
  REQUEST_BUTTON: 'ui-button',
14090
14149
  CLOSE_UI_WINDOW: 'ui-close_window',
14091
14150
  BLUETOOTH_PERMISSION: 'ui-bluetooth_permission',
14092
- LOCATION_PERMISSION: 'ui-location_permission'
14151
+ LOCATION_PERMISSION: 'ui-location_permission',
14152
+ FIRMWARE_PROGRESS: 'ui-firmware-progress'
14093
14153
  };
14094
14154
 
14095
14155
  const createUiMessage = (type, payload) => ({
@@ -14313,7 +14373,7 @@ const UI_REQUEST = {
14313
14373
  NOT_USE_ONEKEY_DEVICE: 'ui-device_please_use_onekey_device'
14314
14374
  };
14315
14375
  const VERSION = '1.0.0-alpha.1';
14316
- const DEFAULT_DOMAIN = `https://localhost:8088/`;
14376
+ const DEFAULT_DOMAIN = `https://hardware-sdk.onekey.so/`;
14317
14377
  const DEFAULT_PRIORITY = 2;
14318
14378
  const initialSettings = {
14319
14379
  configSrc: './data/config.json',
@@ -14561,6 +14621,10 @@ class Device extends events.exports {
14561
14621
  });
14562
14622
  }
14563
14623
 
14624
+ getCommands() {
14625
+ return this.commands;
14626
+ }
14627
+
14564
14628
  getInternalState() {
14565
14629
  return this.internalState[this.instance];
14566
14630
  }
@@ -14829,6 +14893,10 @@ class BaseMethod {
14829
14893
  this.requireDeviceMode = [];
14830
14894
  }
14831
14895
 
14896
+ getVersionRange() {
14897
+ return {};
14898
+ }
14899
+
14832
14900
  setDevice(device) {
14833
14901
  this.device = device;
14834
14902
  this.connectId = device.originalDescriptor.path;
@@ -14953,7 +15021,6 @@ const formatAnyHex = value => {
14953
15021
  return modifyValues(value, value => formatAnyHex(value));
14954
15022
  }
14955
15023
 
14956
- console.log('unexpected value', value);
14957
15024
  return value;
14958
15025
  };
14959
15026
 
@@ -15022,6 +15089,79 @@ const validateParams = (values, fields) => {
15022
15089
  });
15023
15090
  };
15024
15091
 
15092
+ class CipherKeyValue extends BaseMethod {
15093
+ constructor() {
15094
+ super(...arguments);
15095
+ this.hasBundle = false;
15096
+ }
15097
+
15098
+ init() {
15099
+ var _a;
15100
+
15101
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
15102
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
15103
+ const payload = this.hasBundle ? this.payload : {
15104
+ bundle: [this.payload]
15105
+ };
15106
+ validateParams(payload, [{
15107
+ name: 'bundle',
15108
+ type: 'array'
15109
+ }]);
15110
+ this.params = [];
15111
+ payload.bundle.forEach(batch => {
15112
+ const addressN = validatePath(batch.path);
15113
+ validateParams(batch, [{
15114
+ name: 'path',
15115
+ required: true
15116
+ }, {
15117
+ name: 'key',
15118
+ type: 'string'
15119
+ }, {
15120
+ name: 'value',
15121
+ type: 'hexString'
15122
+ }, {
15123
+ name: 'encrypt',
15124
+ type: 'boolean'
15125
+ }, {
15126
+ name: 'askOnEncrypt',
15127
+ type: 'boolean'
15128
+ }, {
15129
+ name: 'askOnDecrypt',
15130
+ type: 'boolean'
15131
+ }, {
15132
+ name: 'iv',
15133
+ type: 'hexString'
15134
+ }]);
15135
+ this.params.push({
15136
+ address_n: addressN,
15137
+ key: batch.key,
15138
+ value: formatAnyHex(batch.value),
15139
+ encrypt: batch.encrypt,
15140
+ ask_on_encrypt: batch.askOnEncrypt,
15141
+ ask_on_decrypt: batch.askOnDecrypt,
15142
+ iv: formatAnyHex(batch.iv)
15143
+ });
15144
+ });
15145
+ }
15146
+
15147
+ run() {
15148
+ return __awaiter(this, void 0, void 0, function* () {
15149
+ const responses = [];
15150
+
15151
+ for (let i = 0; i < this.params.length; i++) {
15152
+ const param = this.params[i];
15153
+ const res = yield this.device.commands.typedCall('CipherKeyValue', 'CipheredKeyValue', Object.assign({}, param));
15154
+ responses.push(Object.assign({
15155
+ path: serializedPath(param.address_n)
15156
+ }, res.message));
15157
+ }
15158
+
15159
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
15160
+ });
15161
+ }
15162
+
15163
+ }
15164
+
15025
15165
  var bitcoin = [{
15026
15166
  name: "Bitcoin",
15027
15167
  label: "BTC",
@@ -16187,6 +16327,17 @@ class DeviceFlags extends BaseMethod {
16187
16327
  class DeviceRebootToBootloader extends BaseMethod {
16188
16328
  init() {}
16189
16329
 
16330
+ getVersionRange() {
16331
+ return {
16332
+ classic: {
16333
+ min: '2.1.11'
16334
+ },
16335
+ mini: {
16336
+ min: '2.1.11'
16337
+ }
16338
+ };
16339
+ }
16340
+
16190
16341
  run() {
16191
16342
  return __awaiter(this, void 0, void 0, function* () {
16192
16343
  const res = yield this.device.commands.typedCall('RebootToBootloader', 'Success');
@@ -16531,7 +16682,7 @@ class EVMSignMessage$2 extends BaseMethod {
16531
16682
 
16532
16683
  }
16533
16684
 
16534
- class EVMSignMessageEIP712$1 extends BaseMethod {
16685
+ class EVMSignMessageEIP712 extends BaseMethod {
16535
16686
  init() {
16536
16687
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16537
16688
  validateParams(this.payload, [{
@@ -16559,6 +16710,14 @@ class EVMSignMessageEIP712$1 extends BaseMethod {
16559
16710
  };
16560
16711
  }
16561
16712
 
16713
+ getVersionRange() {
16714
+ return {
16715
+ model_mini: {
16716
+ min: '2.1.9'
16717
+ }
16718
+ };
16719
+ }
16720
+
16562
16721
  run() {
16563
16722
  return __awaiter(this, void 0, void 0, function* () {
16564
16723
  const res = yield this.device.commands.typedCall('EthereumSignMessageEIP712', 'EthereumMessageSignature', Object.assign({}, this.params));
@@ -16756,6 +16915,22 @@ class EVMSignTransaction extends BaseMethod {
16756
16915
  this.formattedTx = formatAnyHex(tx);
16757
16916
  }
16758
16917
 
16918
+ getVersionRange() {
16919
+ if (this.isEIP1559) {
16920
+ return {
16921
+ model_mini: {
16922
+ min: '2.1.11'
16923
+ }
16924
+ };
16925
+ }
16926
+
16927
+ return {
16928
+ model_mini: {
16929
+ min: '1.0.0'
16930
+ }
16931
+ };
16932
+ }
16933
+
16759
16934
  run() {
16760
16935
  return __awaiter(this, void 0, void 0, function* () {
16761
16936
  const {
@@ -16770,7 +16945,7 @@ class EVMSignTransaction extends BaseMethod {
16770
16945
 
16771
16946
  }
16772
16947
 
16773
- class EVMSignMessageEIP712 extends BaseMethod {
16948
+ class EVMSignTypedData extends BaseMethod {
16774
16949
  init() {
16775
16950
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16776
16951
  validateParams(this.payload, [{
@@ -16778,12 +16953,10 @@ class EVMSignMessageEIP712 extends BaseMethod {
16778
16953
  required: true
16779
16954
  }, {
16780
16955
  name: 'metamaskV4Compat',
16781
- type: 'boolean',
16782
- required: true
16956
+ type: 'boolean'
16783
16957
  }, {
16784
16958
  name: 'data',
16785
- type: 'object',
16786
- required: true
16959
+ type: 'object'
16787
16960
  }, {
16788
16961
  name: 'domainHash',
16789
16962
  type: 'hexString'
@@ -16810,12 +16983,35 @@ class EVMSignMessageEIP712 extends BaseMethod {
16810
16983
 
16811
16984
  if (messageHash) {
16812
16985
  this.params.messageHash = formatAnyHex(messageHash);
16813
- } else if (!data.primaryType || data.primaryType !== 'EIP712Domain') {
16986
+ } else if (!!data && (!data.primaryType || data.primaryType !== 'EIP712Domain')) {
16814
16987
  throw TypedError('Method_InvalidParameter', 'message_hash should only be empty when data.primaryType=EIP712Domain');
16815
16988
  }
16816
16989
  }
16817
16990
  }
16818
16991
 
16992
+ getVersionRange() {
16993
+ return {
16994
+ model_mini: {
16995
+ min: '2.1.9'
16996
+ }
16997
+ };
16998
+ }
16999
+
17000
+ supportSignTyped() {
17001
+ const deviceType = getDeviceType(this.device.features);
17002
+
17003
+ if (deviceType === 'classic' || deviceType === 'mini') {
17004
+ const currentVersion = getDeviceFirmwareVersion(this.device.features).join('.');
17005
+ const supportSignTypedVersion = '2.2.0';
17006
+
17007
+ if (semver__default["default"].lt(currentVersion, supportSignTypedVersion)) {
17008
+ return false;
17009
+ }
17010
+ }
17011
+
17012
+ return true;
17013
+ }
17014
+
16819
17015
  run() {
16820
17016
  return __awaiter(this, void 0, void 0, function* () {
16821
17017
  if (!this.device.features) {
@@ -16825,25 +17021,38 @@ class EVMSignMessageEIP712 extends BaseMethod {
16825
17021
  const {
16826
17022
  addressN
16827
17023
  } = this.params;
17024
+ const deviceType = getDeviceType(this.device.features);
16828
17025
 
16829
- if (this.device.features.model === '1') {
17026
+ if (deviceType === 'classic' || deviceType === 'mini') {
16830
17027
  validateParams(this.params, [{
16831
17028
  name: 'domainHash',
16832
17029
  type: 'hexString',
16833
17030
  required: true
16834
17031
  }, {
16835
17032
  name: 'messageHash',
16836
- type: 'hexString'
17033
+ type: 'hexString',
17034
+ required: true
16837
17035
  }]);
16838
17036
  const {
16839
17037
  domainHash,
16840
17038
  messageHash
16841
17039
  } = this.params;
16842
- const response = yield this.device.commands.typedCall('EthereumSignTypedHash', 'EthereumTypedDataSignature', {
16843
- address_n: addressN,
16844
- domain_separator_hash: domainHash !== null && domainHash !== void 0 ? domainHash : '',
16845
- message_hash: messageHash
16846
- });
17040
+ let response;
17041
+
17042
+ if (this.supportSignTyped()) {
17043
+ response = yield this.device.commands.typedCall('EthereumSignTypedHash', 'EthereumTypedDataSignature', {
17044
+ address_n: addressN,
17045
+ domain_separator_hash: domainHash !== null && domainHash !== void 0 ? domainHash : '',
17046
+ message_hash: messageHash
17047
+ });
17048
+ } else {
17049
+ response = yield this.device.commands.typedCall('EthereumSignMessageEIP712', 'EthereumMessageSignature', {
17050
+ address_n: addressN,
17051
+ domain_hash: domainHash !== null && domainHash !== void 0 ? domainHash : '',
17052
+ message_hash: messageHash !== null && messageHash !== void 0 ? messageHash : ''
17053
+ });
17054
+ }
17055
+
16847
17056
  return Promise.resolve(response.message);
16848
17057
  }
16849
17058
 
@@ -17101,73 +17310,977 @@ class EVMSignMessage extends BaseMethod {
17101
17310
 
17102
17311
  }
17103
17312
 
17104
- var ApiMethods = /*#__PURE__*/Object.freeze({
17105
- __proto__: null,
17106
- searchDevices: SearchDevices,
17107
- getFeatures: GetFeatures,
17108
- btcGetAddress: BTCGetAddress,
17109
- btcGetPublicKey: BTCGetPublicKey,
17110
- btcSignMessage: BTCSignMessage,
17111
- btcSignTransaction: BTCSignTransaction,
17112
- btcVerifyMessage: BTCVerifyMessage,
17113
- checkFirmwareRelease: CheckFirmwareRelease,
17114
- checkBLEFirmwareRelease: CheckBLEFirmwareRelease,
17115
- checkTransportRelease: CheckTransportRelease,
17116
- deviceBackup: DeviceBackup,
17117
- deviceChangePin: DeviceChangePin,
17118
- deviceFlags: DeviceFlags,
17119
- deviceRebootToBootloader: DeviceRebootToBootloader,
17120
- deviceRecovery: DeviceRecovery,
17121
- deviceReset: DeviceReset,
17122
- deviceSettings: DeviceSettings,
17123
- deviceUpdateReboot: DeviceUpdateReboot,
17124
- deviceWipe: DeviceWipe,
17125
- evmGetAddress: EvmGetAddress,
17126
- evmGetPublicKey: EVMGetPublicKey,
17127
- evmSignMessage: EVMSignMessage$2,
17128
- evmSignMessageEIP712: EVMSignMessageEIP712$1,
17129
- evmSignTransaction: EVMSignTransaction,
17130
- evmSignTypedData: EVMSignMessageEIP712,
17131
- evmVerifyMessage: EVMSignMessage$1,
17132
- starcoinGetAddress: StarcoinGetAddress,
17133
- starcoinGetPublicKey: StarcoinGetPublicKey,
17134
- starcoinSignMessage: StarcoinSignMessage,
17135
- starcoinSignTransaction: StarcoinSignTransaction,
17136
- starcoinVerifyMessage: EVMSignMessage
17137
- });
17138
-
17139
- function findMethod(message) {
17140
- const {
17141
- method
17142
- } = message.payload;
17313
+ const MAINNET = 0x68;
17143
17314
 
17144
- if (typeof method !== 'string') {
17145
- throw TypedError('Method_InvalidParameter', 'Method is not set');
17315
+ class NEMGetAddress extends BaseMethod {
17316
+ constructor() {
17317
+ super(...arguments);
17318
+ this.hasBundle = false;
17146
17319
  }
17147
17320
 
17148
- const MethodConstructor = ApiMethods[method];
17321
+ init() {
17322
+ var _a;
17149
17323
 
17150
- if (MethodConstructor) {
17151
- return new MethodConstructor(message);
17324
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17325
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
17326
+ const payload = this.hasBundle ? this.payload : {
17327
+ bundle: [this.payload]
17328
+ };
17329
+ validateParams(payload, [{
17330
+ name: 'bundle',
17331
+ type: 'array'
17332
+ }]);
17333
+ this.params = [];
17334
+ payload.bundle.forEach(batch => {
17335
+ var _a;
17336
+
17337
+ const addressN = validatePath(batch.path, 3);
17338
+ validateParams(batch, [{
17339
+ name: 'path',
17340
+ required: true
17341
+ }, {
17342
+ name: 'network',
17343
+ type: 'number'
17344
+ }, {
17345
+ name: 'showOnOneKey',
17346
+ type: 'boolean'
17347
+ }]);
17348
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
17349
+ this.params.push({
17350
+ address_n: addressN,
17351
+ network: batch.network || MAINNET,
17352
+ show_display: showOnOneKey
17353
+ });
17354
+ });
17152
17355
  }
17153
17356
 
17154
- throw TypedError('Method_InvalidParameter', `Method ${method} is not set`);
17155
- }
17357
+ run() {
17358
+ return __awaiter(this, void 0, void 0, function* () {
17359
+ const responses = [];
17156
17360
 
17157
- const resolveAfter = (msec, value) => new Promise(resolve => {
17158
- setTimeout(resolve, msec, value);
17159
- });
17361
+ for (let i = 0; i < this.params.length; i++) {
17362
+ const param = this.params[i];
17363
+ const res = yield this.device.commands.typedCall('NEMGetAddress', 'NEMAddress', Object.assign({}, param));
17364
+ responses.push(Object.assign({
17365
+ path: serializedPath(param.address_n)
17366
+ }, res.message));
17367
+ }
17160
17368
 
17161
- const Log$1 = initLog('DeviceConnector');
17369
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
17370
+ });
17371
+ }
17162
17372
 
17163
- const getDiff = (current, descriptors) => {
17164
- const env = DataManager.getSettings('env');
17373
+ }
17165
17374
 
17166
- if (env === 'react-native') {
17167
- return {
17168
- descriptors
17169
- };
17170
- }
17375
+ const NEM_TRANSFER = 0x0101;
17376
+ const NEM_COSIGNING = 0x0102;
17377
+ const NEM_IMPORTANCE_TRANSFER = 0x0801;
17378
+ const NEM_AGGREGATE_MODIFICATION = 0x1001;
17379
+ const NEM_MULTISIG_SIGNATURE = 0x1002;
17380
+ const NEM_MULTISIG = 0x1004;
17381
+ const NEM_PROVISION_NAMESPACE = 0x2001;
17382
+ const NEM_MOSAIC_CREATION = 0x4001;
17383
+ const NEM_SUPPLY_CHANGE = 0x4002;
17384
+
17385
+ class NEMSignTransaction extends BaseMethod {
17386
+ constructor() {
17387
+ super(...arguments);
17388
+ this.NEM_MOSAIC_LEVY_TYPES = {
17389
+ 1: 'MosaicLevy_Absolute',
17390
+ 2: 'MosaicLevy_Percentile'
17391
+ };
17392
+ this.NEM_SUPPLY_CHANGE_TYPES = {
17393
+ 1: 'SupplyChange_Increase',
17394
+ 2: 'SupplyChange_Decrease'
17395
+ };
17396
+ this.NEM_AGGREGATE_MODIFICATION_TYPES = {
17397
+ 1: 'CosignatoryModification_Add',
17398
+ 2: 'CosignatoryModification_Delete'
17399
+ };
17400
+ this.NEM_IMPORTANCE_TRANSFER_MODES = {
17401
+ 1: 'ImportanceTransfer_Activate',
17402
+ 2: 'ImportanceTransfer_Deactivate'
17403
+ };
17404
+
17405
+ this.getCommon = (tx, address_n) => {
17406
+ var _a;
17407
+
17408
+ return {
17409
+ address_n,
17410
+ network: tx.version >> 24 & 0xff,
17411
+ timestamp: tx.timeStamp,
17412
+ fee: tx.fee,
17413
+ deadline: (_a = tx.deadline) !== null && _a !== void 0 ? _a : 0,
17414
+ signer: address_n ? undefined : tx.signer
17415
+ };
17416
+ };
17417
+
17418
+ this.transferMessage = tx => {
17419
+ const mosaics = tx.mosaics ? tx.mosaics.map(mosaic => ({
17420
+ namespace: mosaic.mosaicId.namespaceId,
17421
+ mosaic: mosaic.mosaicId.name,
17422
+ quantity: mosaic.quantity
17423
+ })) : undefined;
17424
+ return {
17425
+ recipient: tx.recipient,
17426
+ amount: tx.amount,
17427
+ payload: tx.message ? tx.message.payload : undefined,
17428
+ public_key: tx.message && tx.message.type === 0x02 ? tx.message.publicKey : undefined,
17429
+ mosaics
17430
+ };
17431
+ };
17432
+
17433
+ this.importanceTransferMessage = tx => ({
17434
+ mode: this.NEM_IMPORTANCE_TRANSFER_MODES[tx.importanceTransfer.mode],
17435
+ public_key: tx.importanceTransfer.publicKey
17436
+ });
17437
+
17438
+ this.aggregateModificationMessage = tx => {
17439
+ const modifications = tx.modifications ? tx.modifications.map(modification => ({
17440
+ type: this.NEM_AGGREGATE_MODIFICATION_TYPES[modification.modificationType],
17441
+ public_key: modification.cosignatoryAccount
17442
+ })) : undefined;
17443
+ return {
17444
+ modifications,
17445
+ relative_change: tx.minCosignatories.relativeChange
17446
+ };
17447
+ };
17448
+
17449
+ this.provisionNamespaceMessage = tx => {
17450
+ var _a, _b, _c;
17451
+
17452
+ return {
17453
+ namespace: (_a = tx.newPart) !== null && _a !== void 0 ? _a : '',
17454
+ parent: tx.parent || undefined,
17455
+ sink: (_b = tx.rentalFeeSink) !== null && _b !== void 0 ? _b : '',
17456
+ fee: (_c = tx.rentalFee) !== null && _c !== void 0 ? _c : 0
17457
+ };
17458
+ };
17459
+
17460
+ this.mosaicCreationMessage = tx => {
17461
+ var _a, _b;
17462
+
17463
+ const {
17464
+ levy
17465
+ } = tx.mosaicDefinition;
17466
+ const definition = {
17467
+ namespace: tx.mosaicDefinition.id.namespaceId,
17468
+ mosaic: tx.mosaicDefinition.id.name,
17469
+ levy: levy && levy.type ? this.NEM_MOSAIC_LEVY_TYPES[levy.type] : undefined,
17470
+ fee: levy && levy.fee,
17471
+ levy_address: levy && levy.recipient,
17472
+ levy_namespace: levy && levy.mosaicId && levy.mosaicId.namespaceId,
17473
+ levy_mosaic: levy && levy.mosaicId && levy.mosaicId.name,
17474
+ description: tx.mosaicDefinition.description
17475
+ };
17476
+ const {
17477
+ properties
17478
+ } = tx.mosaicDefinition;
17479
+
17480
+ if (Array.isArray(properties)) {
17481
+ properties.forEach(property => {
17482
+ const {
17483
+ name,
17484
+ value
17485
+ } = property;
17486
+
17487
+ switch (name) {
17488
+ case 'divisibility':
17489
+ definition.divisibility = parseInt(value);
17490
+ break;
17491
+
17492
+ case 'initialSupply':
17493
+ definition.supply = parseInt(value);
17494
+ break;
17495
+
17496
+ case 'supplyMutable':
17497
+ definition.mutable_supply = value === 'true';
17498
+ break;
17499
+
17500
+ case 'transferable':
17501
+ definition.transferable = value === 'true';
17502
+ break;
17503
+ }
17504
+ });
17505
+ }
17506
+
17507
+ return {
17508
+ definition,
17509
+ sink: (_a = tx.creationFeeSink) !== null && _a !== void 0 ? _a : '',
17510
+ fee: (_b = tx.creationFee) !== null && _b !== void 0 ? _b : 0
17511
+ };
17512
+ };
17513
+
17514
+ this.supplyChangeMessage = tx => {
17515
+ var _a;
17516
+
17517
+ return {
17518
+ namespace: tx.mosaicId.namespaceId,
17519
+ mosaic: tx.mosaicId.name,
17520
+ type: this.NEM_SUPPLY_CHANGE_TYPES[tx.supplyType],
17521
+ delta: (_a = tx.delta) !== null && _a !== void 0 ? _a : 0
17522
+ };
17523
+ };
17524
+
17525
+ this.parseTx = (tx, address_n) => {
17526
+ let transaction = tx;
17527
+ const message = {
17528
+ transaction: this.getCommon(tx, address_n),
17529
+ transfer: undefined,
17530
+ importance_transfer: undefined,
17531
+ aggregate_modification: undefined,
17532
+ provision_namespace: undefined,
17533
+ mosaic_creation: undefined,
17534
+ supply_change: undefined
17535
+ };
17536
+
17537
+ if (tx.type === NEM_COSIGNING || tx.type === NEM_MULTISIG || tx.type === NEM_MULTISIG_SIGNATURE) {
17538
+ message.cosigning = tx.type === NEM_COSIGNING || tx.type === NEM_MULTISIG_SIGNATURE;
17539
+ transaction = tx.otherTrans;
17540
+ message.multisig = this.getCommon(transaction);
17541
+ }
17542
+
17543
+ switch (transaction.type) {
17544
+ case NEM_TRANSFER:
17545
+ message.transfer = this.transferMessage(transaction);
17546
+ break;
17547
+
17548
+ case NEM_IMPORTANCE_TRANSFER:
17549
+ message.importance_transfer = this.importanceTransferMessage(transaction);
17550
+ break;
17551
+
17552
+ case NEM_AGGREGATE_MODIFICATION:
17553
+ message.aggregate_modification = this.aggregateModificationMessage(transaction);
17554
+ break;
17555
+
17556
+ case NEM_PROVISION_NAMESPACE:
17557
+ message.provision_namespace = this.provisionNamespaceMessage(transaction);
17558
+ break;
17559
+
17560
+ case NEM_MOSAIC_CREATION:
17561
+ message.mosaic_creation = this.mosaicCreationMessage(transaction);
17562
+ break;
17563
+
17564
+ case NEM_SUPPLY_CHANGE:
17565
+ message.supply_change = this.supplyChangeMessage(transaction);
17566
+ break;
17567
+
17568
+ default:
17569
+ throw TypedError('Method_InvalidParameter', 'Unknown transaction type');
17570
+ }
17571
+
17572
+ return message;
17573
+ };
17574
+ }
17575
+
17576
+ init() {
17577
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17578
+ validateParams(this.payload, [{
17579
+ name: 'path',
17580
+ required: true
17581
+ }, {
17582
+ name: 'transaction',
17583
+ type: 'object',
17584
+ required: true
17585
+ }]);
17586
+ const {
17587
+ path,
17588
+ transaction
17589
+ } = this.payload;
17590
+ const addressN = validatePath(path, 3);
17591
+ this.params = this.parseTx(transaction, addressN);
17592
+ }
17593
+
17594
+ run() {
17595
+ return __awaiter(this, void 0, void 0, function* () {
17596
+ const res = yield this.device.commands.typedCall('NEMSignTx', 'NEMSignedTx', Object.assign({}, this.params));
17597
+ return Promise.resolve(res);
17598
+ });
17599
+ }
17600
+
17601
+ }
17602
+
17603
+ class SolGetAddress extends BaseMethod {
17604
+ constructor() {
17605
+ super(...arguments);
17606
+ this.hasBundle = false;
17607
+ }
17608
+
17609
+ init() {
17610
+ var _a;
17611
+
17612
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17613
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
17614
+ const payload = this.hasBundle ? this.payload : {
17615
+ bundle: [this.payload]
17616
+ };
17617
+ validateParams(payload, [{
17618
+ name: 'bundle',
17619
+ type: 'array'
17620
+ }]);
17621
+ this.params = [];
17622
+ payload.bundle.forEach(batch => {
17623
+ var _a;
17624
+
17625
+ const addressN = validatePath(batch.path, 3);
17626
+ validateParams(batch, [{
17627
+ name: 'path',
17628
+ required: true
17629
+ }, {
17630
+ name: 'showOnOneKey',
17631
+ type: 'boolean'
17632
+ }]);
17633
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
17634
+ this.params.push({
17635
+ address_n: addressN,
17636
+ show_display: showOnOneKey
17637
+ });
17638
+ });
17639
+ }
17640
+
17641
+ run() {
17642
+ return __awaiter(this, void 0, void 0, function* () {
17643
+ const responses = [];
17644
+
17645
+ for (let i = 0; i < this.params.length; i++) {
17646
+ const param = this.params[i];
17647
+ const res = yield this.device.commands.typedCall('SolanaGetAddress', 'SolanaAddress', Object.assign({}, param));
17648
+ const {
17649
+ address
17650
+ } = res.message;
17651
+ responses.push({
17652
+ path: serializedPath(param.address_n),
17653
+ address
17654
+ });
17655
+ }
17656
+
17657
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
17658
+ });
17659
+ }
17660
+
17661
+ }
17662
+
17663
+ class SolSignTransaction extends BaseMethod {
17664
+ constructor() {
17665
+ super(...arguments);
17666
+ this.hasBundle = false;
17667
+ }
17668
+
17669
+ init() {
17670
+ var _a;
17671
+
17672
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17673
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
17674
+ const payload = this.hasBundle ? this.payload : {
17675
+ bundle: [this.payload]
17676
+ };
17677
+ validateParams(payload, [{
17678
+ name: 'bundle',
17679
+ type: 'array'
17680
+ }]);
17681
+ this.params = [];
17682
+ payload.bundle.forEach(batch => {
17683
+ const addressN = validatePath(batch.path, 3);
17684
+ validateParams(batch, [{
17685
+ name: 'path',
17686
+ required: true
17687
+ }, {
17688
+ name: 'rawTx',
17689
+ type: 'hexString',
17690
+ required: true
17691
+ }]);
17692
+ this.params.push({
17693
+ address_n: addressN,
17694
+ raw_tx: formatAnyHex(batch.rawTx)
17695
+ });
17696
+ });
17697
+ }
17698
+
17699
+ getVersionRange() {
17700
+ return {
17701
+ classic: {
17702
+ min: '2.1.9'
17703
+ },
17704
+ mini: {
17705
+ min: '2.1.9'
17706
+ }
17707
+ };
17708
+ }
17709
+
17710
+ run() {
17711
+ return __awaiter(this, void 0, void 0, function* () {
17712
+ const responses = [];
17713
+
17714
+ for (let i = 0; i < this.params.length; i++) {
17715
+ const param = this.params[i];
17716
+ const res = yield this.device.commands.typedCall('SolanaSignTx', 'SolanaSignedTx', Object.assign({}, param));
17717
+ const {
17718
+ signature
17719
+ } = res.message;
17720
+ responses.push({
17721
+ path: serializedPath(param.address_n),
17722
+ signature
17723
+ });
17724
+ }
17725
+
17726
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
17727
+ });
17728
+ }
17729
+
17730
+ }
17731
+
17732
+ class StellarGetAddress extends BaseMethod {
17733
+ constructor() {
17734
+ super(...arguments);
17735
+ this.hasBundle = false;
17736
+ }
17737
+
17738
+ init() {
17739
+ var _a;
17740
+
17741
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17742
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
17743
+ const payload = this.hasBundle ? this.payload : {
17744
+ bundle: [this.payload]
17745
+ };
17746
+ validateParams(payload, [{
17747
+ name: 'bundle',
17748
+ type: 'array'
17749
+ }]);
17750
+ this.params = [];
17751
+ payload.bundle.forEach(batch => {
17752
+ var _a;
17753
+
17754
+ const addressN = validatePath(batch.path, 3);
17755
+ validateParams(batch, [{
17756
+ name: 'path',
17757
+ required: true
17758
+ }, {
17759
+ name: 'showOnOneKey',
17760
+ type: 'boolean'
17761
+ }]);
17762
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
17763
+ this.params.push({
17764
+ address_n: addressN,
17765
+ show_display: showOnOneKey
17766
+ });
17767
+ });
17768
+ }
17769
+
17770
+ run() {
17771
+ return __awaiter(this, void 0, void 0, function* () {
17772
+ const responses = [];
17773
+
17774
+ for (let i = 0; i < this.params.length; i++) {
17775
+ const param = this.params[i];
17776
+ const res = yield this.device.commands.typedCall('StellarGetAddress', 'StellarAddress', Object.assign({}, param));
17777
+ const {
17778
+ address
17779
+ } = res.message;
17780
+ responses.push({
17781
+ path: serializedPath(param.address_n),
17782
+ address
17783
+ });
17784
+ }
17785
+
17786
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
17787
+ });
17788
+ }
17789
+
17790
+ }
17791
+
17792
+ class StellarSignTransaction extends BaseMethod {
17793
+ constructor() {
17794
+ super(...arguments);
17795
+ this.operations = [];
17796
+
17797
+ this.parseOperation = op => {
17798
+ switch (op.type) {
17799
+ case 'createAccount':
17800
+ validateParams(op, [{
17801
+ name: 'destination',
17802
+ type: 'string',
17803
+ required: true
17804
+ }, {
17805
+ name: 'startingBalance',
17806
+ type: 'bigNumber',
17807
+ required: true
17808
+ }]);
17809
+ return {
17810
+ type: 'StellarCreateAccountOp',
17811
+ source_account: op.source,
17812
+ new_account: op.destination,
17813
+ starting_balance: op.startingBalance
17814
+ };
17815
+
17816
+ case 'payment':
17817
+ validateParams(op, [{
17818
+ name: 'destination',
17819
+ type: 'string',
17820
+ required: true
17821
+ }, {
17822
+ name: 'amount',
17823
+ type: 'bigNumber',
17824
+ required: true
17825
+ }, {
17826
+ name: 'asset',
17827
+ required: true
17828
+ }]);
17829
+ return {
17830
+ type: 'StellarPaymentOp',
17831
+ source_account: op.source,
17832
+ destination_account: op.destination,
17833
+ asset: op.asset,
17834
+ amount: op.amount
17835
+ };
17836
+
17837
+ case 'pathPayment':
17838
+ validateParams(op, [{
17839
+ name: 'destAmount',
17840
+ type: 'bigNumber',
17841
+ required: true
17842
+ }]);
17843
+ return {
17844
+ type: 'StellarPathPaymentOp',
17845
+ source_account: op.source,
17846
+ send_asset: op.sendAsset,
17847
+ send_max: op.sendMax,
17848
+ destination_account: op.destination,
17849
+ destination_asset: op.destAsset,
17850
+ destination_amount: op.destAmount,
17851
+ paths: op.path
17852
+ };
17853
+
17854
+ case 'createPassiveOffer':
17855
+ validateParams(op, [{
17856
+ name: 'amount',
17857
+ type: 'bigNumber',
17858
+ required: true
17859
+ }]);
17860
+ return {
17861
+ type: 'StellarCreatePassiveOfferOp',
17862
+ source_account: op.source,
17863
+ buying_asset: op.buying,
17864
+ selling_asset: op.selling,
17865
+ amount: op.amount,
17866
+ price_n: op.price.n,
17867
+ price_d: op.price.d
17868
+ };
17869
+
17870
+ case 'manageOffer':
17871
+ validateParams(op, [{
17872
+ name: 'amount',
17873
+ type: 'bigNumber',
17874
+ required: true
17875
+ }]);
17876
+ return {
17877
+ type: 'StellarManageOfferOp',
17878
+ source_account: op.source,
17879
+ buying_asset: op.buying,
17880
+ selling_asset: op.selling,
17881
+ amount: op.amount,
17882
+ offer_id: op.offerId,
17883
+ price_n: op.price.n,
17884
+ price_d: op.price.d
17885
+ };
17886
+
17887
+ case 'setOptions':
17888
+ {
17889
+ const signer = op.signer ? {
17890
+ signer_type: op.signer.type,
17891
+ signer_key: op.signer.key,
17892
+ signer_weight: op.signer.weight
17893
+ } : undefined;
17894
+ return Object.assign({
17895
+ type: 'StellarSetOptionsOp',
17896
+ source_account: op.source,
17897
+ clear_flags: op.clearFlags,
17898
+ set_flags: op.setFlags,
17899
+ master_weight: op.masterWeight,
17900
+ low_threshold: op.lowThreshold,
17901
+ medium_threshold: op.medThreshold,
17902
+ high_threshold: op.highThreshold,
17903
+ home_domain: op.homeDomain,
17904
+ inflation_destination_account: op.inflationDest
17905
+ }, signer);
17906
+ }
17907
+
17908
+ case 'changeTrust':
17909
+ validateParams(op, [{
17910
+ name: 'limit',
17911
+ type: 'bigNumber'
17912
+ }]);
17913
+ return {
17914
+ type: 'StellarChangeTrustOp',
17915
+ source_account: op.source,
17916
+ asset: op.line,
17917
+ limit: op.limit
17918
+ };
17919
+
17920
+ case 'allowTrust':
17921
+ return {
17922
+ type: 'StellarAllowTrustOp',
17923
+ source_account: op.source,
17924
+ trusted_account: op.trustor,
17925
+ asset_type: op.assetType,
17926
+ asset_code: op.assetCode,
17927
+ is_authorized: op.authorize ? 1 : 0
17928
+ };
17929
+
17930
+ case 'accountMerge':
17931
+ return {
17932
+ type: 'StellarAccountMergeOp',
17933
+ source_account: op.source,
17934
+ destination_account: op.destination
17935
+ };
17936
+
17937
+ case 'manageData':
17938
+ return {
17939
+ type: 'StellarManageDataOp',
17940
+ source_account: op.source,
17941
+ key: op.name,
17942
+ value: op.value
17943
+ };
17944
+
17945
+ case 'bumpSequence':
17946
+ return {
17947
+ type: 'StellarBumpSequenceOp',
17948
+ source_account: op.source,
17949
+ bump_to: op.bumpTo
17950
+ };
17951
+
17952
+ default:
17953
+ return {};
17954
+ }
17955
+ };
17956
+
17957
+ this.processTxRequest = (operations, index) => __awaiter(this, void 0, void 0, function* () {
17958
+ const isLastOp = index + 1 >= operations.length;
17959
+
17960
+ const _a = operations[index],
17961
+ {
17962
+ type
17963
+ } = _a,
17964
+ op = __rest(_a, ["type"]);
17965
+
17966
+ if (isLastOp) {
17967
+ const response = yield this.device.commands.typedCall(type, 'StellarSignedTx', op);
17968
+ return response.message;
17969
+ }
17970
+
17971
+ yield this.device.commands.typedCall(type, 'StellarTxOpRequest', op);
17972
+ return this.processTxRequest(operations, index + 1);
17973
+ });
17974
+ }
17975
+
17976
+ init() {
17977
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17978
+ validateParams(this.payload, [{
17979
+ name: 'path',
17980
+ required: true
17981
+ }, {
17982
+ name: 'networkPassphrase',
17983
+ type: 'string',
17984
+ required: true
17985
+ }, {
17986
+ name: 'transaction',
17987
+ type: 'object',
17988
+ required: true
17989
+ }]);
17990
+ const addressN = validatePath(this.payload.path, 3);
17991
+ const {
17992
+ transaction,
17993
+ networkPassphrase
17994
+ } = this.payload;
17995
+ this.params = {
17996
+ address_n: addressN,
17997
+ network_passphrase: networkPassphrase,
17998
+ source_account: transaction.source,
17999
+ fee: transaction.fee,
18000
+ sequence_number: transaction.sequence,
18001
+ num_operations: transaction.operations.length
18002
+ };
18003
+
18004
+ if (transaction.timebounds) {
18005
+ this.params.timebounds_start = transaction.timebounds.minTime;
18006
+ this.params.timebounds_end = transaction.timebounds.maxTime;
18007
+ }
18008
+
18009
+ if (transaction.memo) {
18010
+ this.params.memo_type = transaction.memo.type;
18011
+ this.params.memo_text = transaction.memo.text;
18012
+ this.params.memo_id = transaction.memo.id;
18013
+ this.params.memo_hash = transaction.memo.hash;
18014
+ }
18015
+
18016
+ transaction.operations.forEach(op => {
18017
+ const transformed = this.parseOperation(op);
18018
+
18019
+ if (transformed) {
18020
+ this.operations.push(transformed);
18021
+ }
18022
+ });
18023
+ console.log('StellarSignTransactionParams', this.params);
18024
+ console.log('StellarSignTransactionOperations', this.operations);
18025
+ }
18026
+
18027
+ run() {
18028
+ return __awaiter(this, void 0, void 0, function* () {
18029
+ yield this.device.commands.typedCall('StellarSignTx', 'StellarTxOpRequest', Object.assign({}, this.params));
18030
+ return this.processTxRequest(this.operations, 0);
18031
+ });
18032
+ }
18033
+
18034
+ }
18035
+
18036
+ const getBinary = ({
18037
+ features,
18038
+ updateType,
18039
+ version
18040
+ }) => __awaiter(void 0, void 0, void 0, function* () {
18041
+ const releaseInfo = getInfo({
18042
+ features,
18043
+ updateType
18044
+ });
18045
+
18046
+ if (!releaseInfo) {
18047
+ throw TypedError('Runtime', 'no firmware found for this device');
18048
+ }
18049
+
18050
+ if (version && !semver__default["default"].eq(releaseInfo.version, version)) {
18051
+ throw TypedError('Runtime', 'firmware version mismatch');
18052
+ }
18053
+
18054
+ const url = updateType === 'ble' ? releaseInfo.webUpdate : releaseInfo.url;
18055
+ const fw = yield httpRequest(url, 'binary');
18056
+ return Object.assign(Object.assign({}, releaseInfo), {
18057
+ binary: fw
18058
+ });
18059
+ });
18060
+
18061
+ const getInfo = ({
18062
+ features,
18063
+ updateType
18064
+ }) => {
18065
+ var _a, _b, _c;
18066
+
18067
+ const deviceType = getDeviceType(features);
18068
+ const {
18069
+ deviceMap
18070
+ } = DataManager;
18071
+ 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;
18072
+ return releaseInfo;
18073
+ };
18074
+
18075
+ const postConfirmationMessage = device => {
18076
+ var _a;
18077
+
18078
+ if ((_a = device.features) === null || _a === void 0 ? void 0 : _a.firmware_present) {
18079
+ device.emit(DEVICE.BUTTON, device, {
18080
+ code: 'ButtonRequest_FirmwareUpdate'
18081
+ });
18082
+ }
18083
+ };
18084
+
18085
+ const postProgressMessage = (device, progress, postMessage) => {
18086
+ postMessage(createUiMessage(UI_REQUEST$1.FIRMWARE_PROGRESS, {
18087
+ device: device.toMessageObject(),
18088
+ progress
18089
+ }));
18090
+ };
18091
+
18092
+ const uploadFirmware = (updateType, typedCall, postMessage, device, {
18093
+ payload
18094
+ }) => __awaiter(void 0, void 0, void 0, function* () {
18095
+ var _a, _b;
18096
+
18097
+ if (((_a = device.features) === null || _a === void 0 ? void 0 : _a.major_version) === 1) {
18098
+ postConfirmationMessage(device);
18099
+ const eraseCommand = updateType === 'firmware' ? 'FirmwareErase' : 'FirmwareErase_ex';
18100
+ yield typedCall(eraseCommand, 'Success', {});
18101
+ postProgressMessage(device, 0, postMessage);
18102
+ const {
18103
+ message
18104
+ } = yield typedCall('FirmwareUpload', 'Success', {
18105
+ payload
18106
+ });
18107
+ return message;
18108
+ }
18109
+
18110
+ if (((_b = device.features) === null || _b === void 0 ? void 0 : _b.major_version) === 2) {
18111
+ postConfirmationMessage(device);
18112
+ const length = payload.byteLength;
18113
+ let response = yield typedCall('FirmwareErase', ['FirmwareRequest', 'Success'], {
18114
+ length
18115
+ });
18116
+
18117
+ while (response.type !== 'Success') {
18118
+ const start = response.message.offset;
18119
+ const end = response.message.offset + response.message.length;
18120
+ const chunk = payload.slice(start, end);
18121
+
18122
+ if (start > 0) {
18123
+ postProgressMessage(device, Math.round(start / length * 100), postMessage);
18124
+ }
18125
+
18126
+ response = yield typedCall('FirmwareUpload', ['FirmwareRequest', 'Success'], {
18127
+ payload: chunk
18128
+ });
18129
+ }
18130
+
18131
+ postProgressMessage(device, 100, postMessage);
18132
+ return response.message;
18133
+ }
18134
+
18135
+ throw TypedError('Runtime', 'uploadFirmware: unknown major_version');
18136
+ });
18137
+
18138
+ class FirmwareUpdate extends BaseMethod {
18139
+ init() {
18140
+ this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.INITIALIZE];
18141
+ this.requireDeviceMode = [UI_REQUEST.BOOTLOADER];
18142
+ const {
18143
+ payload
18144
+ } = this;
18145
+ validateParams(payload, [{
18146
+ name: 'version',
18147
+ type: 'array'
18148
+ }, {
18149
+ name: 'binary',
18150
+ type: 'buffer'
18151
+ }]);
18152
+
18153
+ if (!payload.updateType) {
18154
+ throw TypedError('Method_InvalidParameter', 'updateType is required');
18155
+ }
18156
+
18157
+ this.params = {
18158
+ updateType: payload.updateType
18159
+ };
18160
+
18161
+ if ('version' in payload) {
18162
+ this.params = Object.assign(Object.assign({}, this.params), {
18163
+ version: payload.version
18164
+ });
18165
+ }
18166
+
18167
+ if ('binary' in payload) {
18168
+ this.params = Object.assign(Object.assign({}, this.params), {
18169
+ binary: payload.binary
18170
+ });
18171
+ }
18172
+ }
18173
+
18174
+ run() {
18175
+ return __awaiter(this, void 0, void 0, function* () {
18176
+ const {
18177
+ device,
18178
+ params
18179
+ } = this;
18180
+ let binary;
18181
+
18182
+ try {
18183
+ if (params.binary) {
18184
+ binary = this.params.binary;
18185
+ } else {
18186
+ if (!device.features) {
18187
+ throw TypedError('Runtime', 'no features found for this device');
18188
+ }
18189
+
18190
+ const firmware = yield getBinary({
18191
+ features: device.features,
18192
+ version: params.version,
18193
+ updateType: params.updateType
18194
+ });
18195
+ binary = firmware.binary;
18196
+ }
18197
+ } catch (err) {
18198
+ throw TypedError('Method_FirmwareUpdate_DownloadFailed', err);
18199
+ }
18200
+
18201
+ return uploadFirmware(params.updateType, this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, {
18202
+ payload: binary
18203
+ });
18204
+ });
18205
+ }
18206
+
18207
+ }
18208
+
18209
+ var ApiMethods = /*#__PURE__*/Object.freeze({
18210
+ __proto__: null,
18211
+ searchDevices: SearchDevices,
18212
+ getFeatures: GetFeatures,
18213
+ cipherKeyValue: CipherKeyValue,
18214
+ btcGetAddress: BTCGetAddress,
18215
+ btcGetPublicKey: BTCGetPublicKey,
18216
+ btcSignMessage: BTCSignMessage,
18217
+ btcSignTransaction: BTCSignTransaction,
18218
+ btcVerifyMessage: BTCVerifyMessage,
18219
+ checkFirmwareRelease: CheckFirmwareRelease,
18220
+ checkBLEFirmwareRelease: CheckBLEFirmwareRelease,
18221
+ checkTransportRelease: CheckTransportRelease,
18222
+ deviceBackup: DeviceBackup,
18223
+ deviceChangePin: DeviceChangePin,
18224
+ deviceFlags: DeviceFlags,
18225
+ deviceRebootToBootloader: DeviceRebootToBootloader,
18226
+ deviceRecovery: DeviceRecovery,
18227
+ deviceReset: DeviceReset,
18228
+ deviceSettings: DeviceSettings,
18229
+ deviceUpdateReboot: DeviceUpdateReboot,
18230
+ deviceWipe: DeviceWipe,
18231
+ evmGetAddress: EvmGetAddress,
18232
+ evmGetPublicKey: EVMGetPublicKey,
18233
+ evmSignMessage: EVMSignMessage$2,
18234
+ evmSignMessageEIP712: EVMSignMessageEIP712,
18235
+ evmSignTransaction: EVMSignTransaction,
18236
+ evmSignTypedData: EVMSignTypedData,
18237
+ evmVerifyMessage: EVMSignMessage$1,
18238
+ starcoinGetAddress: StarcoinGetAddress,
18239
+ starcoinGetPublicKey: StarcoinGetPublicKey,
18240
+ starcoinSignMessage: StarcoinSignMessage,
18241
+ starcoinSignTransaction: StarcoinSignTransaction,
18242
+ starcoinVerifyMessage: EVMSignMessage,
18243
+ nemGetAddress: NEMGetAddress,
18244
+ nemSignTransaction: NEMSignTransaction,
18245
+ solGetAddress: SolGetAddress,
18246
+ solSignTransaction: SolSignTransaction,
18247
+ stellarGetAddress: StellarGetAddress,
18248
+ stellarSignTransaction: StellarSignTransaction,
18249
+ firmwareUpdate: FirmwareUpdate
18250
+ });
18251
+
18252
+ function findMethod(message) {
18253
+ const {
18254
+ method
18255
+ } = message.payload;
18256
+
18257
+ if (typeof method !== 'string') {
18258
+ throw TypedError('Method_InvalidParameter', 'Method is not set');
18259
+ }
18260
+
18261
+ const MethodConstructor = ApiMethods[method];
18262
+
18263
+ if (MethodConstructor) {
18264
+ return new MethodConstructor(message);
18265
+ }
18266
+
18267
+ throw TypedError('Method_InvalidParameter', `Method ${method} is not set`);
18268
+ }
18269
+
18270
+ const resolveAfter = (msec, value) => new Promise(resolve => {
18271
+ setTimeout(resolve, msec, value);
18272
+ });
18273
+
18274
+ const Log$1 = initLog('DeviceConnector');
18275
+
18276
+ const getDiff = (current, descriptors) => {
18277
+ const env = DataManager.getSettings('env');
18278
+
18279
+ if (env === 'react-native') {
18280
+ return {
18281
+ descriptors
18282
+ };
18283
+ }
17171
18284
 
17172
18285
  const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
17173
18286
  const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
@@ -17339,6 +18452,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
17339
18452
  try {
17340
18453
  method = findMethod(message);
17341
18454
  method.connector = _connector;
18455
+ method.postMessage = postMessage;
17342
18456
  method.init();
17343
18457
  } catch (error) {
17344
18458
  return Promise.reject(error);
@@ -17384,6 +18498,24 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
17384
18498
 
17385
18499
  try {
17386
18500
  const inner = () => __awaiter(void 0, void 0, void 0, function* () {
18501
+ const deviceType = getDeviceType(device.features);
18502
+ const deviceModel = getDeviceModel(device.features);
18503
+ const versionRangeType = method.getVersionRange()[deviceType];
18504
+ const versionRangeModel = method.getVersionRange()[deviceModel];
18505
+ const versionRange = versionRangeType !== null && versionRangeType !== void 0 ? versionRangeType : versionRangeModel;
18506
+
18507
+ if (versionRange && device.features) {
18508
+ const currentVersion = getDeviceFirmwareVersion(device.features).join('.');
18509
+
18510
+ if (semver__default["default"].valid(versionRange.min) && semver__default["default"].lt(currentVersion, versionRange.min)) {
18511
+ return Promise.reject(TypedError('Device_FwException', `Device firmware version is too low, please update to ${versionRange.min}`));
18512
+ }
18513
+
18514
+ if (versionRange.max && semver__default["default"].valid(versionRange.max) && semver__default["default"].gt(currentVersion, versionRange.max)) {
18515
+ return Promise.reject(TypedError('Device_FwException', `Device firmware version is too high, this method has been deprecated in ${versionRange.max}`));
18516
+ }
18517
+ }
18518
+
17387
18519
  const unexpectedMode = device.hasUnexpectedMode(method.allowDeviceMode, method.requireDeviceMode);
17388
18520
 
17389
18521
  if (unexpectedMode) {
@@ -17421,6 +18553,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
17421
18553
  } catch (error) {
17422
18554
  messageResponse = createResponseMessage(method.responseID, false, error);
17423
18555
  _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.reject(TypedError('Call_API', error));
18556
+ Log.debug('Call API - Run Error: ', error);
17424
18557
  } finally {
17425
18558
  const response = messageResponse;
17426
18559