@onekeyfe/hd-web-sdk 0.1.37 → 0.1.40

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.
@@ -4145,6 +4145,10 @@ const inject = ({
4145
4145
  connectId,
4146
4146
  method: 'deviceWipe'
4147
4147
  }),
4148
+ getPassphraseState: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4149
+ connectId,
4150
+ method: 'getPassphraseState'
4151
+ })),
4148
4152
  evmGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4149
4153
  connectId,
4150
4154
  deviceId,
@@ -4819,6 +4823,262 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
4819
4823
  }
4820
4824
  }
4821
4825
 
4826
+ const HD_HARDENED = 0x80000000;
4827
+
4828
+ const toHardened = n => (n | HD_HARDENED) >>> 0;
4829
+
4830
+ const fromHardened = n => (n & ~HD_HARDENED) >>> 0;
4831
+
4832
+ const PATH_NOT_VALID = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Not a valid path');
4833
+ const PATH_NEGATIVE_VALUES = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Path cannot contain negative values');
4834
+
4835
+ const getHDPath = path => {
4836
+ const parts = path.toLowerCase().split('/');
4837
+ if (parts[0] !== 'm') throw PATH_NOT_VALID;
4838
+ return parts.filter(p => p !== 'm' && p !== '').map(p => {
4839
+ let hardened = false;
4840
+
4841
+ if (p.substr(p.length - 1) === "'") {
4842
+ hardened = true;
4843
+ p = p.substr(0, p.length - 1);
4844
+ }
4845
+
4846
+ let n = parseInt(p);
4847
+
4848
+ if (Number.isNaN(n)) {
4849
+ throw PATH_NOT_VALID;
4850
+ } else if (n < 0) {
4851
+ throw PATH_NEGATIVE_VALUES;
4852
+ }
4853
+
4854
+ if (hardened) {
4855
+ n = toHardened(n);
4856
+ }
4857
+
4858
+ return n;
4859
+ });
4860
+ };
4861
+
4862
+ const isMultisigPath = path => Array.isArray(path) && path[0] === toHardened(48);
4863
+
4864
+ const isSegwitPath = path => Array.isArray(path) && path[0] === toHardened(49);
4865
+
4866
+ const getScriptType = path => {
4867
+ if (!Array.isArray(path) || path.length < 1) return 'SPENDADDRESS';
4868
+ const p1 = fromHardened(path[0]);
4869
+
4870
+ switch (p1) {
4871
+ case 48:
4872
+ return 'SPENDMULTISIG';
4873
+
4874
+ case 49:
4875
+ return 'SPENDP2SHWITNESS';
4876
+
4877
+ case 84:
4878
+ return 'SPENDWITNESS';
4879
+
4880
+ default:
4881
+ return 'SPENDADDRESS';
4882
+ }
4883
+ };
4884
+
4885
+ const getOutputScriptType = path => {
4886
+ if (!Array.isArray(path) || path.length < 1) return 'PAYTOADDRESS';
4887
+
4888
+ if (path[0] === 49) {
4889
+ return 'PAYTOP2SHWITNESS';
4890
+ }
4891
+
4892
+ const p = fromHardened(path[0]);
4893
+
4894
+ switch (p) {
4895
+ case 48:
4896
+ return 'PAYTOMULTISIG';
4897
+
4898
+ case 49:
4899
+ return 'PAYTOP2SHWITNESS';
4900
+
4901
+ case 84:
4902
+ return 'PAYTOWITNESS';
4903
+
4904
+ default:
4905
+ return 'PAYTOADDRESS';
4906
+ }
4907
+ };
4908
+
4909
+ const serializedPath = path => {
4910
+ const pathStr = path.map(p => {
4911
+ if (p & HD_HARDENED) {
4912
+ return `${p & ~HD_HARDENED}'`;
4913
+ }
4914
+
4915
+ return p;
4916
+ }).join('/');
4917
+ return `m/${pathStr}`;
4918
+ };
4919
+
4920
+ const validatePath = (path, length = 0, base = false) => {
4921
+ let valid;
4922
+
4923
+ if (typeof path === 'string') {
4924
+ valid = getHDPath(path);
4925
+ } else if (Array.isArray(path)) {
4926
+ valid = path.map(p => {
4927
+ const n = parseInt(p);
4928
+
4929
+ if (Number.isNaN(n)) {
4930
+ throw PATH_NOT_VALID;
4931
+ } else if (n < 0) {
4932
+ throw PATH_NEGATIVE_VALUES;
4933
+ }
4934
+
4935
+ return n;
4936
+ });
4937
+ } else {
4938
+ valid = undefined;
4939
+ }
4940
+
4941
+ if (!valid) throw PATH_NOT_VALID;
4942
+ if (length > 0 && valid.length < length) throw PATH_NOT_VALID;
4943
+ return base ? valid.splice(0, 3) : valid;
4944
+ };
4945
+
4946
+ const getDeviceModel = features => {
4947
+ if (!features || typeof features !== 'object') {
4948
+ return 'model_mini';
4949
+ }
4950
+
4951
+ if (features.model === '1') {
4952
+ return 'model_mini';
4953
+ }
4954
+
4955
+ return 'model_touch';
4956
+ };
4957
+
4958
+ const getDeviceType = features => {
4959
+ if (!features || typeof features !== 'object' || !features.serial_no) {
4960
+ return 'classic';
4961
+ }
4962
+
4963
+ const serialNo = features.serial_no;
4964
+ const miniFlag = serialNo.slice(0, 2);
4965
+ if (miniFlag.toLowerCase() === 'mi') return 'mini';
4966
+ if (miniFlag.toLowerCase() === 'tc') return 'touch';
4967
+ return 'classic';
4968
+ };
4969
+
4970
+ const getDeviceTypeOnBootloader = features => getDeviceType(features);
4971
+
4972
+ const getDeviceTypeByBleName = name => {
4973
+ if (!name) return 'classic';
4974
+ if (name.startsWith('MI')) return 'mini';
4975
+ if (name.startsWith('T')) return 'touch';
4976
+ return 'classic';
4977
+ };
4978
+
4979
+ const getDeviceTypeByDeviceId = deviceId => {
4980
+ if (!deviceId) {
4981
+ return 'classic';
4982
+ }
4983
+
4984
+ const miniFlag = deviceId.slice(0, 2);
4985
+ if (miniFlag.toLowerCase() === 'mi') return 'mini';
4986
+ return 'classic';
4987
+ };
4988
+
4989
+ const getDeviceUUID = features => {
4990
+ const deviceType = getDeviceType(features);
4991
+
4992
+ if (deviceType === 'classic') {
4993
+ return features.onekey_serial;
4994
+ }
4995
+
4996
+ return features.serial_no;
4997
+ };
4998
+
4999
+ const getDeviceLabel = features => {
5000
+ const deviceType = getDeviceType(features);
5001
+
5002
+ if (typeof features.label === 'string') {
5003
+ return features.label;
5004
+ }
5005
+
5006
+ return `My OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
5007
+ };
5008
+
5009
+ const getDeviceFirmwareVersion = features => {
5010
+ if (!features) return [0, 0, 0];
5011
+
5012
+ if (features.onekey_version) {
5013
+ return features.onekey_version.split('.');
5014
+ }
5015
+
5016
+ return [features.major_version, features.minor_version, features.patch_version];
5017
+ };
5018
+
5019
+ const getDeviceBLEFirmwareVersion = features => {
5020
+ if (!features.ble_ver) {
5021
+ return null;
5022
+ }
5023
+
5024
+ if (!semver__default["default"].valid(features.ble_ver)) {
5025
+ return null;
5026
+ }
5027
+
5028
+ return features.ble_ver.split('.');
5029
+ };
5030
+
5031
+ const supportInputPinOnSoftware = features => {
5032
+ if (!features) return {
5033
+ support: false
5034
+ };
5035
+ const deviceType = getDeviceType(features);
5036
+
5037
+ if (deviceType === 'touch') {
5038
+ return {
5039
+ support: false
5040
+ };
5041
+ }
5042
+
5043
+ const currentVersion = getDeviceFirmwareVersion(features).join('.');
5044
+ return {
5045
+ support: semver__default["default"].gte(currentVersion, '2.3.0'),
5046
+ require: '2.3.0'
5047
+ };
5048
+ };
5049
+
5050
+ const supportNewPassphrase = features => {
5051
+ if (!features) return {
5052
+ support: false
5053
+ };
5054
+ const deviceType = getDeviceType(features);
5055
+
5056
+ if (deviceType === 'touch' || deviceType === 'pro') {
5057
+ return {
5058
+ support: true
5059
+ };
5060
+ }
5061
+
5062
+ const currentVersion = getDeviceFirmwareVersion(features).join('.');
5063
+ return {
5064
+ support: semver__default["default"].gte(currentVersion, '2.4.0'),
5065
+ require: '2.4.0'
5066
+ };
5067
+ };
5068
+
5069
+ const getPassphraseState = (features, commands) => __awaiter(void 0, void 0, void 0, function* () {
5070
+ if (!features) return false;
5071
+ const {
5072
+ message
5073
+ } = yield commands.typedCall('GetAddress', 'Address', {
5074
+ address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
5075
+ coin_name: 'Testnet',
5076
+ script_type: 'SPENDADDRESS',
5077
+ show_display: false
5078
+ });
5079
+ return message.address;
5080
+ });
5081
+
4822
5082
  var nested = {
4823
5083
  BinanceGetAddress: {
4824
5084
  fields: {
@@ -13599,223 +13859,6 @@ function patchFeatures(response) {
13599
13859
  return response;
13600
13860
  }
13601
13861
 
13602
- const getDeviceModel = features => {
13603
- if (!features || typeof features !== 'object') {
13604
- return 'model_mini';
13605
- }
13606
-
13607
- if (features.model === '1') {
13608
- return 'model_mini';
13609
- }
13610
-
13611
- return 'model_touch';
13612
- };
13613
-
13614
- const getDeviceType = features => {
13615
- if (!features || typeof features !== 'object' || !features.serial_no) {
13616
- return 'classic';
13617
- }
13618
-
13619
- const serialNo = features.serial_no;
13620
- const miniFlag = serialNo.slice(0, 2);
13621
- if (miniFlag.toLowerCase() === 'mi') return 'mini';
13622
- if (miniFlag.toLowerCase() === 'tc') return 'touch';
13623
- return 'classic';
13624
- };
13625
-
13626
- const getDeviceTypeOnBootloader = features => getDeviceType(features);
13627
-
13628
- const getDeviceTypeByBleName = name => {
13629
- if (!name) return 'classic';
13630
- if (name.startsWith('MI')) return 'mini';
13631
- if (name.startsWith('T')) return 'touch';
13632
- return 'classic';
13633
- };
13634
-
13635
- const getDeviceTypeByDeviceId = deviceId => {
13636
- if (!deviceId) {
13637
- return 'classic';
13638
- }
13639
-
13640
- const miniFlag = deviceId.slice(0, 2);
13641
- if (miniFlag.toLowerCase() === 'mi') return 'mini';
13642
- return 'classic';
13643
- };
13644
-
13645
- const getDeviceUUID = features => {
13646
- const deviceType = getDeviceType(features);
13647
-
13648
- if (deviceType === 'classic') {
13649
- return features.onekey_serial;
13650
- }
13651
-
13652
- return features.serial_no;
13653
- };
13654
-
13655
- const getDeviceLabel = features => {
13656
- const deviceType = getDeviceType(features);
13657
-
13658
- if (typeof features.label === 'string') {
13659
- return features.label;
13660
- }
13661
-
13662
- return `My OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
13663
- };
13664
-
13665
- const getDeviceFirmwareVersion = features => {
13666
- if (!features) return [0, 0, 0];
13667
-
13668
- if (features.onekey_version) {
13669
- return features.onekey_version.split('.');
13670
- }
13671
-
13672
- return [features.major_version, features.minor_version, features.patch_version];
13673
- };
13674
-
13675
- const getDeviceBLEFirmwareVersion = features => {
13676
- if (!features.ble_ver) {
13677
- return null;
13678
- }
13679
-
13680
- if (!semver__default["default"].valid(features.ble_ver)) {
13681
- return null;
13682
- }
13683
-
13684
- return features.ble_ver.split('.');
13685
- };
13686
-
13687
- const supportInputPinOnSoftware = features => {
13688
- if (!features) return false;
13689
- const deviceType = getDeviceType(features);
13690
-
13691
- if (deviceType === 'touch') {
13692
- return false;
13693
- }
13694
-
13695
- const currentVersion = getDeviceFirmwareVersion(features).join('.');
13696
- return semver__default["default"].gte(currentVersion, '2.3.0');
13697
- };
13698
-
13699
- const HD_HARDENED = 0x80000000;
13700
-
13701
- const toHardened = n => (n | HD_HARDENED) >>> 0;
13702
-
13703
- const fromHardened = n => (n & ~HD_HARDENED) >>> 0;
13704
-
13705
- const PATH_NOT_VALID = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Not a valid path');
13706
- const PATH_NEGATIVE_VALUES = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Path cannot contain negative values');
13707
-
13708
- const getHDPath = path => {
13709
- const parts = path.toLowerCase().split('/');
13710
- if (parts[0] !== 'm') throw PATH_NOT_VALID;
13711
- return parts.filter(p => p !== 'm' && p !== '').map(p => {
13712
- let hardened = false;
13713
-
13714
- if (p.substr(p.length - 1) === "'") {
13715
- hardened = true;
13716
- p = p.substr(0, p.length - 1);
13717
- }
13718
-
13719
- let n = parseInt(p);
13720
-
13721
- if (Number.isNaN(n)) {
13722
- throw PATH_NOT_VALID;
13723
- } else if (n < 0) {
13724
- throw PATH_NEGATIVE_VALUES;
13725
- }
13726
-
13727
- if (hardened) {
13728
- n = toHardened(n);
13729
- }
13730
-
13731
- return n;
13732
- });
13733
- };
13734
-
13735
- const isMultisigPath = path => Array.isArray(path) && path[0] === toHardened(48);
13736
-
13737
- const isSegwitPath = path => Array.isArray(path) && path[0] === toHardened(49);
13738
-
13739
- const getScriptType = path => {
13740
- if (!Array.isArray(path) || path.length < 1) return 'SPENDADDRESS';
13741
- const p1 = fromHardened(path[0]);
13742
-
13743
- switch (p1) {
13744
- case 48:
13745
- return 'SPENDMULTISIG';
13746
-
13747
- case 49:
13748
- return 'SPENDP2SHWITNESS';
13749
-
13750
- case 84:
13751
- return 'SPENDWITNESS';
13752
-
13753
- default:
13754
- return 'SPENDADDRESS';
13755
- }
13756
- };
13757
-
13758
- const getOutputScriptType = path => {
13759
- if (!Array.isArray(path) || path.length < 1) return 'PAYTOADDRESS';
13760
-
13761
- if (path[0] === 49) {
13762
- return 'PAYTOP2SHWITNESS';
13763
- }
13764
-
13765
- const p = fromHardened(path[0]);
13766
-
13767
- switch (p) {
13768
- case 48:
13769
- return 'PAYTOMULTISIG';
13770
-
13771
- case 49:
13772
- return 'PAYTOP2SHWITNESS';
13773
-
13774
- case 84:
13775
- return 'PAYTOWITNESS';
13776
-
13777
- default:
13778
- return 'PAYTOADDRESS';
13779
- }
13780
- };
13781
-
13782
- const serializedPath = path => {
13783
- const pathStr = path.map(p => {
13784
- if (p & HD_HARDENED) {
13785
- return `${p & ~HD_HARDENED}'`;
13786
- }
13787
-
13788
- return p;
13789
- }).join('/');
13790
- return `m/${pathStr}`;
13791
- };
13792
-
13793
- const validatePath = (path, length = 0, base = false) => {
13794
- let valid;
13795
-
13796
- if (typeof path === 'string') {
13797
- valid = getHDPath(path);
13798
- } else if (Array.isArray(path)) {
13799
- valid = path.map(p => {
13800
- const n = parseInt(p);
13801
-
13802
- if (Number.isNaN(n)) {
13803
- throw PATH_NOT_VALID;
13804
- } else if (n < 0) {
13805
- throw PATH_NEGATIVE_VALUES;
13806
- }
13807
-
13808
- return n;
13809
- });
13810
- } else {
13811
- valid = undefined;
13812
- }
13813
-
13814
- if (!valid) throw PATH_NOT_VALID;
13815
- if (length > 0 && valid.length < length) throw PATH_NOT_VALID;
13816
- return base ? valid.splice(0, 3) : valid;
13817
- };
13818
-
13819
13862
  const LOG_EVENT = 'LOG_EVENT';
13820
13863
  const LOG = {
13821
13864
  OUTPUT: 'log-output'
@@ -14225,6 +14268,7 @@ const UI_REQUEST$1 = {
14225
14268
  REQUEST_PIN: 'ui-request_pin',
14226
14269
  INVALID_PIN: 'ui-invalid_pin',
14227
14270
  REQUEST_BUTTON: 'ui-button',
14271
+ REQUEST_PASSPHRASE_ON_DEVICE: 'ui-request_passphrase_on_device',
14228
14272
  CLOSE_UI_WINDOW: 'ui-close_window',
14229
14273
  BLUETOOTH_PERMISSION: 'ui-bluetooth_permission',
14230
14274
  LOCATION_PERMISSION: 'ui-location_permission',
@@ -14358,13 +14402,13 @@ class DevicePool extends events.exports {
14358
14402
  this.connector = connector;
14359
14403
  }
14360
14404
 
14361
- static getDevices(descriptorList, connectId) {
14405
+ static getDevices(descriptorList, connectId, initOptions) {
14362
14406
  var descriptorList_1, descriptorList_1_1;
14363
14407
 
14364
14408
  var e_1, _a;
14365
14409
 
14366
14410
  return __awaiter(this, void 0, void 0, function* () {
14367
- Log$6.debug('get device list');
14411
+ Log$6.debug('get device list: connectId: ', connectId);
14368
14412
  const devices = {};
14369
14413
  const deviceList = [];
14370
14414
 
@@ -14379,7 +14423,7 @@ class DevicePool extends events.exports {
14379
14423
  device.updateDescriptor(exist, true);
14380
14424
  devices[connectId] = device;
14381
14425
  deviceList.push(device);
14382
- yield this._checkDevicePool();
14426
+ yield this._checkDevicePool(initOptions);
14383
14427
  return {
14384
14428
  devices,
14385
14429
  deviceList
@@ -14393,7 +14437,7 @@ class DevicePool extends events.exports {
14393
14437
  try {
14394
14438
  for (descriptorList_1 = __asyncValues(descriptorList); descriptorList_1_1 = yield descriptorList_1.next(), !descriptorList_1_1.done;) {
14395
14439
  const descriptor = descriptorList_1_1.value;
14396
- const device = yield this._createDevice(descriptor);
14440
+ const device = yield this._createDevice(descriptor, initOptions);
14397
14441
 
14398
14442
  if (device.features) {
14399
14443
  const uuid = getDeviceUUID(device.features);
@@ -14424,7 +14468,7 @@ class DevicePool extends events.exports {
14424
14468
  Log$6.debug('get devices result : ', devices, deviceList);
14425
14469
  console.log('device poll -> connected: ', this.connectedPool);
14426
14470
  console.log('device poll -> disconnected: ', this.disconnectPool);
14427
- yield this._checkDevicePool();
14471
+ yield this._checkDevicePool(initOptions);
14428
14472
  return {
14429
14473
  devices,
14430
14474
  deviceList
@@ -14432,7 +14476,16 @@ class DevicePool extends events.exports {
14432
14476
  });
14433
14477
  }
14434
14478
 
14435
- static _createDevice(descriptor) {
14479
+ static clearDeviceCache(connectId) {
14480
+ Log$6.debug('clear device pool cache: connectId', connectId);
14481
+ Log$6.debug('clear device pool cache: ', this.devicesCache);
14482
+
14483
+ if (connectId) {
14484
+ delete this.devicesCache[connectId];
14485
+ }
14486
+ }
14487
+
14488
+ static _createDevice(descriptor, initOptions) {
14436
14489
  return __awaiter(this, void 0, void 0, function* () {
14437
14490
  let device = this.getDeviceByPath(descriptor.path);
14438
14491
 
@@ -14440,7 +14493,7 @@ class DevicePool extends events.exports {
14440
14493
  device = Device.fromDescriptor(descriptor);
14441
14494
  device.deviceConnector = this.connector;
14442
14495
  yield device.connect();
14443
- yield device.initialize();
14496
+ yield device.initialize(initOptions);
14444
14497
  yield device.release();
14445
14498
  }
14446
14499
 
@@ -14448,19 +14501,19 @@ class DevicePool extends events.exports {
14448
14501
  });
14449
14502
  }
14450
14503
 
14451
- static _checkDevicePool() {
14504
+ static _checkDevicePool(initOptions) {
14452
14505
  return __awaiter(this, void 0, void 0, function* () {
14453
- yield this._sendConnectMessage();
14506
+ yield this._sendConnectMessage(initOptions);
14454
14507
 
14455
14508
  this._sendDisconnectMessage();
14456
14509
  });
14457
14510
  }
14458
14511
 
14459
- static _sendConnectMessage() {
14512
+ static _sendConnectMessage(initOptions) {
14460
14513
  return __awaiter(this, void 0, void 0, function* () {
14461
14514
  for (let i = this.connectedPool.length - 1; i >= 0; i--) {
14462
14515
  const descriptor = this.connectedPool[i];
14463
- const device = yield this._createDevice(descriptor);
14516
+ const device = yield this._createDevice(descriptor, initOptions);
14464
14517
  Log$6.debug('emit DEVICE.CONNECT: ', device);
14465
14518
  this.emitter.emit(DEVICE.CONNECT, device);
14466
14519
  this.connectedPool.splice(i, 1);
@@ -14749,8 +14802,6 @@ class DeviceCommands {
14749
14802
  }
14750
14803
 
14751
14804
  _filterCommonTypes(res) {
14752
- var _a;
14753
-
14754
14805
  Log$4.debug('_filterCommonTypes: ', res);
14755
14806
 
14756
14807
  if (res.type === 'Failure') {
@@ -14778,6 +14829,10 @@ class DeviceCommands {
14778
14829
  error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PinCancelled);
14779
14830
  }
14780
14831
 
14832
+ if (code === 'Failure_DataError' && message === 'Please confirm the BlindSign enabled') {
14833
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlindSignDisabled);
14834
+ }
14835
+
14781
14836
  if (error) {
14782
14837
  return Promise.reject(error);
14783
14838
  }
@@ -14818,12 +14873,10 @@ class DeviceCommands {
14818
14873
  }, () => this._commonCall('Cancel', {}));
14819
14874
  }
14820
14875
 
14821
- if ((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.passphrase_protection) {
14822
- return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportPassphrase));
14823
- }
14824
-
14825
14876
  if (res.type === 'PassphraseRequest') {
14826
- return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportPassphrase));
14877
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportPassphrase, 'Device not support passphrase', {
14878
+ require: '2.4.0'
14879
+ }));
14827
14880
  }
14828
14881
 
14829
14882
  if (res.type === 'Deprecated_PassphraseStateRequest') ;
@@ -14865,7 +14918,7 @@ const UI_REQUEST = {
14865
14918
  FIRMWARE_NOT_INSTALLED: 'ui-device_firmware_not_installed',
14866
14919
  NOT_USE_ONEKEY_DEVICE: 'ui-device_please_use_onekey_device'
14867
14920
  };
14868
- const DEFAULT_DOMAIN = `https://jssdk.onekey.so/${"0.1.37"}/`;
14921
+ const DEFAULT_DOMAIN = `https://jssdk.onekey.so/${"0.1.40"}/`;
14869
14922
  const DEFAULT_PRIORITY = 2;
14870
14923
  const initialSettings = {
14871
14924
  configSrc: './data/config.json',
@@ -14967,6 +15020,7 @@ const parseRunOptions = options => {
14967
15020
  };
14968
15021
 
14969
15022
  const Log$3 = getLogger(exports.d0.Device);
15023
+ const deviceSessionCache = {};
14970
15024
 
14971
15025
  class Device extends events.exports {
14972
15026
  constructor(descriptor) {
@@ -14980,6 +15034,7 @@ class Device extends events.exports {
14980
15034
  this.internalState = [];
14981
15035
  this.needReloadDevice = false;
14982
15036
  this.keepSession = false;
15037
+ this.passphraseState = undefined;
14983
15038
  this.originalDescriptor = descriptor;
14984
15039
  }
14985
15040
 
@@ -15116,44 +15171,83 @@ class Device extends events.exports {
15116
15171
  return this.commands;
15117
15172
  }
15118
15173
 
15119
- getInternalState() {
15120
- return this.internalState[this.instance];
15174
+ getInternalState(_deviceId) {
15175
+ var _a, _b;
15176
+
15177
+ Log$3.debug('getInternalState session param: ', `device_id: ${_deviceId}`, `features.device_id: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id}`, `passphraseState: ${this.passphraseState}`);
15178
+ Log$3.debug('getInternalState session cache: ', deviceSessionCache);
15179
+ const deviceId = _deviceId || ((_b = this.features) === null || _b === void 0 ? void 0 : _b.device_id);
15180
+ if (!deviceId) return undefined;
15181
+ if (!this.passphraseState) return undefined;
15182
+ const usePassKey = `${deviceId}@${this.passphraseState}`;
15183
+
15184
+ if (!deviceSessionCache[usePassKey]) {
15185
+ const key = `${deviceId}`;
15186
+
15187
+ if (deviceSessionCache[key]) {
15188
+ deviceSessionCache[usePassKey] = deviceSessionCache[key];
15189
+ }
15190
+ }
15191
+
15192
+ return deviceSessionCache[usePassKey];
15193
+ }
15194
+
15195
+ setInternalState(state, initSession) {
15196
+ var _a;
15197
+
15198
+ Log$3.debug('setInternalState session param: ', `state: ${state}`, `initSession: ${initSession}`, `device_id: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id}`, `passphraseState: ${this.passphraseState}`);
15199
+ if (!this.features) return;
15200
+ if (!this.passphraseState && !initSession) return;
15201
+ let key = `${this.features.device_id}`;
15202
+
15203
+ if (this.passphraseState) {
15204
+ key += `@${this.passphraseState}`;
15205
+ }
15206
+
15207
+ if (state) {
15208
+ deviceSessionCache[key] = state;
15209
+ }
15210
+
15211
+ Log$3.debug('setInternalState done session cache: ', deviceSessionCache);
15212
+ }
15213
+
15214
+ clearInternalState(_deviceId) {
15215
+ var _a;
15216
+
15217
+ Log$3.debug('clearInternalState param: ', _deviceId);
15218
+ const deviceId = _deviceId || ((_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id);
15219
+ if (!deviceId) return;
15220
+ const key = `${deviceId}`;
15221
+ delete deviceSessionCache[key];
15222
+
15223
+ if (this.passphraseState) {
15224
+ const usePassKey = `${deviceId}@${this.passphraseState}`;
15225
+ delete deviceSessionCache[usePassKey];
15226
+ }
15121
15227
  }
15122
15228
 
15123
- initialize() {
15229
+ initialize(options) {
15124
15230
  return __awaiter(this, void 0, void 0, function* () {
15125
- let payload;
15231
+ Log$3.debug('initialize param:', options);
15232
+ this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
15126
15233
 
15127
- if (this.features) {
15128
- const internalState = this.getInternalState();
15129
- payload = {};
15234
+ if (options === null || options === void 0 ? void 0 : options.initSession) {
15235
+ this.clearInternalState(options === null || options === void 0 ? void 0 : options.deviceId);
15236
+ }
15130
15237
 
15131
- if (internalState) {
15132
- payload.session_id = internalState;
15133
- }
15238
+ const internalState = this.getInternalState(options === null || options === void 0 ? void 0 : options.deviceId);
15239
+ const payload = {};
15240
+
15241
+ if (internalState) {
15242
+ payload.session_id = internalState;
15134
15243
  }
15135
15244
 
15245
+ Log$3.debug('initialize payload:', payload);
15136
15246
  const {
15137
15247
  message
15138
15248
  } = yield this.commands.typedCall('Initialize', 'Features', payload);
15139
15249
 
15140
- this._updateFeatures(message);
15141
-
15142
- if (message.passphrase_protection) {
15143
- if (this.listenerCount(DEVICE.PIN) > 0) {
15144
- Log$3.debug('try to close passpharse');
15145
-
15146
- try {
15147
- yield this.commands.typedCall('ApplySettings', 'Success', {
15148
- use_passphrase: false
15149
- });
15150
- } catch (e) {
15151
- yield this.release();
15152
- this.runPromise = null;
15153
- throw e;
15154
- }
15155
- }
15156
- }
15250
+ this._updateFeatures(message, options === null || options === void 0 ? void 0 : options.initSession);
15157
15251
  });
15158
15252
  }
15159
15253
 
@@ -15167,11 +15261,15 @@ class Device extends events.exports {
15167
15261
  });
15168
15262
  }
15169
15263
 
15170
- _updateFeatures(feat) {
15264
+ _updateFeatures(feat, initSession) {
15171
15265
  if (this.features && this.features.session_id && !feat.session_id) {
15172
15266
  feat.session_id = this.features.session_id;
15173
15267
  }
15174
15268
 
15269
+ if (this.features && this.features.device_id && feat.session_id) {
15270
+ this.setInternalState(feat.session_id, initSession);
15271
+ }
15272
+
15175
15273
  feat.unlocked = feat.unlocked || true;
15176
15274
  this.features = feat;
15177
15275
  this.featuresNeedsReload = false;
@@ -15221,8 +15319,6 @@ class Device extends events.exports {
15221
15319
  }
15222
15320
 
15223
15321
  _runInner(fn, options) {
15224
- var _a;
15225
-
15226
15322
  return __awaiter(this, void 0, void 0, function* () {
15227
15323
  if (!this.isUsedHere() || this.commands.disposed) {
15228
15324
  const env = DataManager.getSettings('env');
@@ -15232,7 +15328,7 @@ class Device extends events.exports {
15232
15328
 
15233
15329
  try {
15234
15330
  if (fn) {
15235
- yield this.initialize();
15331
+ yield this.initialize(options);
15236
15332
  }
15237
15333
  } catch (error) {
15238
15334
  this.runPromise = null;
@@ -15243,21 +15339,6 @@ class Device extends events.exports {
15243
15339
 
15244
15340
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, `Initialize failed: ${error.message}, code: ${error.code}`));
15245
15341
  }
15246
- } else if (env === 'react-native') {
15247
- if ((_a = this.features) === null || _a === void 0 ? void 0 : _a.passphrase_protection) {
15248
- if (this.listenerCount(DEVICE.PIN) > 0) {
15249
- Log$3.debug('try to close passpharse for mobile');
15250
-
15251
- try {
15252
- yield this.commands.typedCall('ApplySettings', 'Success', {
15253
- use_passphrase: false
15254
- });
15255
- } catch (e) {
15256
- this.runPromise = null;
15257
- return Promise.reject(e);
15258
- }
15259
- }
15260
- }
15261
15342
  }
15262
15343
  }
15263
15344
 
@@ -15391,6 +15472,14 @@ class Device extends events.exports {
15391
15472
  return null;
15392
15473
  }
15393
15474
 
15475
+ hasUsePassphrase() {
15476
+ var _a;
15477
+
15478
+ const isModeT = getDeviceType(this.features) === 'touch' || getDeviceType(this.features) === 'pro';
15479
+ const preCheckTouch = isModeT && ((_a = this.features) === null || _a === void 0 ? void 0 : _a.unlocked) === true;
15480
+ return this.features && (!!this.features.passphrase_protection || preCheckTouch);
15481
+ }
15482
+
15394
15483
  checkDeviceId(deviceId) {
15395
15484
  if (this.features) {
15396
15485
  return this.features.device_id === deviceId;
@@ -15399,6 +15488,26 @@ class Device extends events.exports {
15399
15488
  return false;
15400
15489
  }
15401
15490
 
15491
+ checkPassphraseState() {
15492
+ var _a;
15493
+
15494
+ return __awaiter(this, void 0, void 0, function* () {
15495
+ if (!this.features) return false;
15496
+ const locked = ((_a = this.features) === null || _a === void 0 ? void 0 : _a.unlocked) === true;
15497
+ const isModeT = getDeviceType(this.features) === 'touch' || getDeviceType(this.features) === 'pro';
15498
+ const newState = yield getPassphraseState(this.features, this.commands);
15499
+
15500
+ if (isModeT && locked) {
15501
+ yield this.getFeatures();
15502
+ }
15503
+
15504
+ if (this.passphraseState && this.passphraseState !== newState) {
15505
+ this.clearInternalState();
15506
+ return newState;
15507
+ }
15508
+ });
15509
+ }
15510
+
15402
15511
  }
15403
15512
 
15404
15513
  class DeviceList extends events.exports {
@@ -15407,7 +15516,7 @@ class DeviceList extends events.exports {
15407
15516
  this.devices = {};
15408
15517
  }
15409
15518
 
15410
- getDeviceLists(connectId) {
15519
+ getDeviceLists(connectId, initOptions) {
15411
15520
  var _a, _b;
15412
15521
 
15413
15522
  return __awaiter(this, void 0, void 0, function* () {
@@ -15417,7 +15526,7 @@ class DeviceList extends events.exports {
15417
15526
  const {
15418
15527
  deviceList,
15419
15528
  devices
15420
- } = yield DevicePool.getDevices(descriptorList, connectId);
15529
+ } = yield DevicePool.getDevices(descriptorList, connectId, initOptions);
15421
15530
  this.devices = devices;
15422
15531
  return deviceList;
15423
15532
  });
@@ -15459,6 +15568,7 @@ class BaseMethod {
15459
15568
  constructor(message) {
15460
15569
  this.shouldEnsureConnected = true;
15461
15570
  this.checkDeviceId = false;
15571
+ this.useDevicePassphraseState = true;
15462
15572
  const {
15463
15573
  payload
15464
15574
  } = message;
@@ -15509,6 +15619,7 @@ class BaseMethod {
15509
15619
  class SearchDevices extends BaseMethod {
15510
15620
  init() {
15511
15621
  this.useDevice = false;
15622
+ this.useDevicePassphraseState = false;
15512
15623
  }
15513
15624
 
15514
15625
  run() {
@@ -15543,6 +15654,7 @@ class SearchDevices extends BaseMethod {
15543
15654
  class GetFeatures extends BaseMethod {
15544
15655
  init() {
15545
15656
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE, UI_REQUEST.BOOTLOADER];
15657
+ this.useDevicePassphraseState = false;
15546
15658
  }
15547
15659
 
15548
15660
  run() {
@@ -16810,7 +16922,9 @@ class BTCVerifyMessage extends BaseMethod {
16810
16922
  }
16811
16923
 
16812
16924
  class CheckFirmwareRelease extends BaseMethod {
16813
- init() {}
16925
+ init() {
16926
+ this.useDevicePassphraseState = false;
16927
+ }
16814
16928
 
16815
16929
  run() {
16816
16930
  if (this.device.features) {
@@ -16827,6 +16941,7 @@ class CheckBLEFirmwareRelease extends BaseMethod {
16827
16941
  init() {
16828
16942
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.BOOTLOADER];
16829
16943
  this.checkDeviceId = true;
16944
+ this.useDevicePassphraseState = false;
16830
16945
  }
16831
16946
 
16832
16947
  run() {
@@ -16843,6 +16958,7 @@ class CheckBLEFirmwareRelease extends BaseMethod {
16843
16958
  class CheckTransportRelease extends BaseMethod {
16844
16959
  init() {
16845
16960
  this.useDevice = false;
16961
+ this.useDevicePassphraseState = false;
16846
16962
  }
16847
16963
 
16848
16964
  run() {
@@ -16859,6 +16975,7 @@ class CheckTransportRelease extends BaseMethod {
16859
16975
  class CheckBridgeStatus$1 extends BaseMethod {
16860
16976
  init() {
16861
16977
  this.useDevice = false;
16978
+ this.useDevicePassphraseState = false;
16862
16979
  }
16863
16980
 
16864
16981
  run() {
@@ -16883,7 +17000,9 @@ class CheckBridgeStatus$1 extends BaseMethod {
16883
17000
  }
16884
17001
 
16885
17002
  class DeviceBackup extends BaseMethod {
16886
- init() {}
17003
+ init() {
17004
+ this.useDevicePassphraseState = false;
17005
+ }
16887
17006
 
16888
17007
  run() {
16889
17008
  return __awaiter(this, void 0, void 0, function* () {
@@ -16896,6 +17015,7 @@ class DeviceBackup extends BaseMethod {
16896
17015
 
16897
17016
  class DeviceChangePin extends BaseMethod {
16898
17017
  init() {
17018
+ this.useDevicePassphraseState = false;
16899
17019
  validateParams(this.payload, [{
16900
17020
  name: 'remove',
16901
17021
  type: 'boolean'
@@ -16916,6 +17036,7 @@ class DeviceChangePin extends BaseMethod {
16916
17036
 
16917
17037
  class DeviceFlags extends BaseMethod {
16918
17038
  init() {
17039
+ this.useDevicePassphraseState = false;
16919
17040
  validateParams(this.payload, [{
16920
17041
  name: 'flags',
16921
17042
  type: 'number'
@@ -16935,7 +17056,9 @@ class DeviceFlags extends BaseMethod {
16935
17056
  }
16936
17057
 
16937
17058
  class DeviceRebootToBootloader extends BaseMethod {
16938
- init() {}
17059
+ init() {
17060
+ this.useDevicePassphraseState = false;
17061
+ }
16939
17062
 
16940
17063
  getVersionRange() {
16941
17064
  return {
@@ -16959,6 +17082,7 @@ class DeviceRebootToBootloader extends BaseMethod {
16959
17082
 
16960
17083
  class DeviceRecovery extends BaseMethod {
16961
17084
  init() {
17085
+ this.useDevicePassphraseState = false;
16962
17086
  validateParams(this.payload, [{
16963
17087
  name: 'wordCount',
16964
17088
  type: 'number'
@@ -17011,6 +17135,7 @@ class DeviceRecovery extends BaseMethod {
17011
17135
 
17012
17136
  class DeviceReset extends BaseMethod {
17013
17137
  init() {
17138
+ this.useDevicePassphraseState = false;
17014
17139
  validateParams(this.payload, [{
17015
17140
  name: 'displayRandom',
17016
17141
  type: 'boolean'
@@ -17066,6 +17191,7 @@ class DeviceReset extends BaseMethod {
17066
17191
 
17067
17192
  class DeviceSettings extends BaseMethod {
17068
17193
  init() {
17194
+ this.useDevicePassphraseState = false;
17069
17195
  validateParams(this.payload, [{
17070
17196
  name: 'language',
17071
17197
  type: 'string'
@@ -17097,7 +17223,6 @@ class DeviceSettings extends BaseMethod {
17097
17223
  name: 'experimentalFeatures',
17098
17224
  type: 'boolean'
17099
17225
  }]);
17100
- console.log('DeviceSettings payload', this.payload);
17101
17226
  this.params = {
17102
17227
  language: this.payload.language,
17103
17228
  label: this.payload.label,
@@ -17112,6 +17237,18 @@ class DeviceSettings extends BaseMethod {
17112
17237
  };
17113
17238
  }
17114
17239
 
17240
+ getVersionRange() {
17241
+ if (this.payload.usePassphrase) {
17242
+ return {
17243
+ model_mini: {
17244
+ min: '2.4.0'
17245
+ }
17246
+ };
17247
+ }
17248
+
17249
+ return {};
17250
+ }
17251
+
17115
17252
  run() {
17116
17253
  return __awaiter(this, void 0, void 0, function* () {
17117
17254
  const res = yield this.device.commands.typedCall('ApplySettings', 'Success', Object.assign({}, this.params));
@@ -17122,7 +17259,9 @@ class DeviceSettings extends BaseMethod {
17122
17259
  }
17123
17260
 
17124
17261
  class DeviceUpdateReboot extends BaseMethod {
17125
- init() {}
17262
+ init() {
17263
+ this.useDevicePassphraseState = false;
17264
+ }
17126
17265
 
17127
17266
  run() {
17128
17267
  return __awaiter(this, void 0, void 0, function* () {
@@ -17134,7 +17273,9 @@ class DeviceUpdateReboot extends BaseMethod {
17134
17273
  }
17135
17274
 
17136
17275
  class DeviceSupportFeatures extends BaseMethod {
17137
- init() {}
17276
+ init() {
17277
+ this.useDevicePassphraseState = false;
17278
+ }
17138
17279
 
17139
17280
  run() {
17140
17281
  if (!this.device.features) return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Device not initialized'));
@@ -17149,6 +17290,7 @@ class DeviceSupportFeatures extends BaseMethod {
17149
17290
 
17150
17291
  class DeviceVerify extends BaseMethod {
17151
17292
  init() {
17293
+ this.useDevicePassphraseState = false;
17152
17294
  validateParams(this.payload, [{
17153
17295
  name: 'dataHex',
17154
17296
  type: 'hexString'
@@ -17187,7 +17329,9 @@ class DeviceVerify extends BaseMethod {
17187
17329
  }
17188
17330
 
17189
17331
  class DeviceWipe extends BaseMethod {
17190
- init() {}
17332
+ init() {
17333
+ this.useDevicePassphraseState = false;
17334
+ }
17191
17335
 
17192
17336
  run() {
17193
17337
  return __awaiter(this, void 0, void 0, function* () {
@@ -19075,6 +19219,7 @@ class FirmwareUpdate extends BaseMethod {
19075
19219
  init() {
19076
19220
  this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.INITIALIZE];
19077
19221
  this.requireDeviceMode = [UI_REQUEST.BOOTLOADER];
19222
+ this.useDevicePassphraseState = false;
19078
19223
  const {
19079
19224
  payload
19080
19225
  } = this;
@@ -19149,6 +19294,7 @@ const Log$2 = getLogger(exports.d0.Method);
19149
19294
  class RequestWebUsbDevice extends BaseMethod {
19150
19295
  init() {
19151
19296
  this.useDevice = false;
19297
+ this.useDevicePassphraseState = false;
19152
19298
  }
19153
19299
 
19154
19300
  run() {
@@ -19185,9 +19331,45 @@ class RequestWebUsbDevice extends BaseMethod {
19185
19331
 
19186
19332
  }
19187
19333
 
19334
+ class GetPassphraseState extends BaseMethod {
19335
+ init() {
19336
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
19337
+ this.useDevicePassphraseState = false;
19338
+ }
19339
+
19340
+ run() {
19341
+ var _a, _b;
19342
+
19343
+ return __awaiter(this, void 0, void 0, function* () {
19344
+ if (!this.device.features) return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed));
19345
+ let {
19346
+ features
19347
+ } = this.device;
19348
+ const locked = ((_b = (_a = this.device) === null || _a === void 0 ? void 0 : _a.features) === null || _b === void 0 ? void 0 : _b.unlocked) === true;
19349
+ const passphraseState = yield getPassphraseState(this.device.features, this.device.commands);
19350
+ const isModeT = getDeviceType(features) === 'touch' || getDeviceType(features) === 'pro';
19351
+
19352
+ if (isModeT && locked) {
19353
+ const {
19354
+ message
19355
+ } = yield this.device.commands.typedCall('GetFeatures', 'Features', {});
19356
+ features = message;
19357
+ }
19358
+
19359
+ if (features && features.passphrase_protection === true) {
19360
+ return Promise.resolve(passphraseState);
19361
+ }
19362
+
19363
+ return Promise.resolve(undefined);
19364
+ });
19365
+ }
19366
+
19367
+ }
19368
+
19188
19369
  class CheckBridgeStatus extends BaseMethod {
19189
19370
  init() {
19190
19371
  this.useDevice = false;
19372
+ this.useDevicePassphraseState = false;
19191
19373
  }
19192
19374
 
19193
19375
  run() {
@@ -19244,6 +19426,7 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
19244
19426
  stellarSignTransaction: StellarSignTransaction,
19245
19427
  firmwareUpdate: FirmwareUpdate,
19246
19428
  requestWebUsbDevice: RequestWebUsbDevice,
19429
+ getPassphraseState: GetPassphraseState,
19247
19430
  getLogs: CheckBridgeStatus
19248
19431
  });
19249
19432
 
@@ -19393,6 +19576,12 @@ class DeviceConnector {
19393
19576
 
19394
19577
  const Log = getLogger(exports.d0.Core);
19395
19578
 
19579
+ const parseInitOptions = method => ({
19580
+ initSession: method === null || method === void 0 ? void 0 : method.payload.initSession,
19581
+ passphraseState: method === null || method === void 0 ? void 0 : method.payload.passphraseState,
19582
+ deviceId: method === null || method === void 0 ? void 0 : method.payload.deviceId
19583
+ });
19584
+
19396
19585
  let _core;
19397
19586
 
19398
19587
  let _deviceList;
@@ -19407,6 +19596,9 @@ const callApiQueue = [];
19407
19596
  const deviceCacheMap = new Map();
19408
19597
  let pollingId = 1;
19409
19598
  const pollingState = {};
19599
+ let preConnectCache = {
19600
+ passphraseState: undefined
19601
+ };
19410
19602
 
19411
19603
  const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19412
19604
  var _a;
@@ -19446,6 +19638,16 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19446
19638
  Log.debug('should cancel the previous method execution: ', callApiQueue.map(m => m.name));
19447
19639
  }
19448
19640
 
19641
+ const connectStateChange = preConnectCache.passphraseState !== method.payload.passphraseState;
19642
+ preConnectCache = {
19643
+ passphraseState: method.payload.passphraseState
19644
+ };
19645
+
19646
+ if (connectStateChange || method.payload.initSession) {
19647
+ Log.debug('passphrase state change, clear device cache');
19648
+ DevicePool.clearDeviceCache(method.payload.connectId);
19649
+ }
19650
+
19449
19651
  if (pollingState[pollingId]) {
19450
19652
  pollingState[pollingId] = false;
19451
19653
  }
@@ -19465,6 +19667,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19465
19667
  (_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
19466
19668
  device.on(DEVICE.PIN, onDevicePinHandler);
19467
19669
  device.on(DEVICE.BUTTON, onDeviceButtonHandler);
19670
+ device.on(DEVICE.PASSPHRASE_ON_DEVICE, onDevicePassphraseHandler);
19468
19671
  device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
19469
19672
 
19470
19673
  try {
@@ -19518,6 +19721,26 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19518
19721
  yield TransportManager.reconfigure(device.getFirmwareVersion());
19519
19722
  }
19520
19723
 
19724
+ checkPassphraseSafety(method, device.features);
19725
+
19726
+ if (device.hasUsePassphrase() && method.useDevicePassphraseState) {
19727
+ const support = supportNewPassphrase(device.features);
19728
+
19729
+ if (!support.support) {
19730
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportPassphrase, `Device not support passphrase, please update to ${support.require}`, {
19731
+ require: support.require
19732
+ }));
19733
+ }
19734
+
19735
+ const passphraseState = yield device.checkPassphraseState();
19736
+ checkPassphraseSafety(method, device.features);
19737
+
19738
+ if (passphraseState) {
19739
+ DevicePool.clearDeviceCache(method.payload.connectId);
19740
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError));
19741
+ }
19742
+ }
19743
+
19521
19744
  try {
19522
19745
  const response = yield method.run();
19523
19746
  Log.debug('Call API - Inner Method Run: ');
@@ -19533,8 +19756,11 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19533
19756
  });
19534
19757
 
19535
19758
  Log.debug('Call API - Device Run: ', device.mainId);
19759
+ const runOptions = Object.assign({
19760
+ keepSession: method.payload.keepSession
19761
+ }, parseInitOptions(method));
19536
19762
 
19537
- const deviceRun = () => device.run(inner);
19763
+ const deviceRun = () => device.run(inner, runOptions);
19538
19764
 
19539
19765
  _callPromise = hdShared.createDeferred(deviceRun);
19540
19766
 
@@ -19589,7 +19815,7 @@ function initDeviceList(method) {
19589
19815
  _deviceList.connector = _connector;
19590
19816
  }
19591
19817
 
19592
- yield _deviceList.getDeviceLists(method.connectId);
19818
+ yield _deviceList.getDeviceLists(method.connectId, parseInitOptions(method));
19593
19819
  });
19594
19820
  }
19595
19821
 
@@ -19701,7 +19927,7 @@ const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0,
19701
19927
 
19702
19928
  if (env === 'react-native') {
19703
19929
  yield device.acquire();
19704
- yield device.initialize();
19930
+ yield device.initialize(parseInitOptions(method));
19705
19931
  }
19706
19932
 
19707
19933
  resolve(device);
@@ -19761,6 +19987,20 @@ const cancel = connectId => {
19761
19987
  closePopup();
19762
19988
  };
19763
19989
 
19990
+ const checkPassphraseSafety = (method, features) => {
19991
+ if (!method.useDevicePassphraseState) return;
19992
+
19993
+ if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true && !method.payload.passphraseState) {
19994
+ DevicePool.clearDeviceCache(method.payload.connectId);
19995
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceOpenedPassphrase);
19996
+ }
19997
+
19998
+ if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === false && method.payload.passphraseState) {
19999
+ DevicePool.clearDeviceCache(method.payload.connectId);
20000
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotOpenedPassphrase);
20001
+ }
20002
+ };
20003
+
19764
20004
  const cleanup = () => {
19765
20005
  _uiPromises = [];
19766
20006
  Log.debug('Cleanup...');
@@ -19769,6 +20009,7 @@ const cleanup = () => {
19769
20009
  const removeDeviceListener = device => {
19770
20010
  device.removeListener(DEVICE.PIN, onDevicePinHandler);
19771
20011
  device.removeListener(DEVICE.BUTTON, onDeviceButtonHandler);
20012
+ device.removeListener(DEVICE.PASSPHRASE_ON_DEVICE, onDevicePassphraseHandler);
19772
20013
  device.removeListener(DEVICE.FEATURES, onDeviceFeaturesHandler);
19773
20014
  DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
19774
20015
  };
@@ -19825,6 +20066,13 @@ const onDeviceFeaturesHandler = (...[_, features]) => {
19825
20066
  postMessage(createDeviceMessage(DEVICE.FEATURES, Object.assign({}, features)));
19826
20067
  };
19827
20068
 
20069
+ const onDevicePassphraseHandler = (...[device]) => {
20070
+ postMessage(createUiMessage(UI_REQUEST$1.REQUEST_PASSPHRASE_ON_DEVICE, {
20071
+ device: device.toMessageObject(),
20072
+ passphraseState: device.passphraseState
20073
+ }));
20074
+ };
20075
+
19828
20076
  const postMessage = message => {
19829
20077
  _core.emit(CORE_EVENT, message);
19830
20078
  };
@@ -21196,6 +21444,9 @@ const HardwareErrorCode = {
21196
21444
  DeviceInterruptedFromUser: 109,
21197
21445
  DeviceCheckDeviceIdError: 110,
21198
21446
  DeviceNotSupportPassphrase: 111,
21447
+ DeviceCheckPassphraseStateError: 112,
21448
+ DeviceNotOpenedPassphrase: 113,
21449
+ DeviceOpenedPassphrase: 114,
21199
21450
  NotInitialized: 200,
21200
21451
  IFrameNotInitialized: 300,
21201
21452
  IFrameAleradyInitialized: 301,
@@ -21235,7 +21486,8 @@ const HardwareErrorCode = {
21235
21486
  BridgeTimeoutError: 807,
21236
21487
  BridgeNotInstalled: 808,
21237
21488
  PollingTimeout: 809,
21238
- PollingStop: 810
21489
+ PollingStop: 810,
21490
+ BlindSignDisabled: 811
21239
21491
  };
21240
21492
  const HardwareErrorCodeMessage = {
21241
21493
  [HardwareErrorCode.UnknownError]: 'Unknown error occurred. Check message property.',
@@ -21250,6 +21502,9 @@ const HardwareErrorCodeMessage = {
21250
21502
  [HardwareErrorCode.DeviceUnexpectedBootloaderMode]: 'Device should be in bootloader mode',
21251
21503
  [HardwareErrorCode.DeviceCheckDeviceIdError]: 'Device Id in the features is not same.',
21252
21504
  [HardwareErrorCode.DeviceNotSupportPassphrase]: 'Device not support passphrase',
21505
+ [HardwareErrorCode.DeviceCheckPassphraseStateError]: 'Device passphrase state error',
21506
+ [HardwareErrorCode.DeviceNotOpenedPassphrase]: 'Device not opened passphrase',
21507
+ [HardwareErrorCode.DeviceOpenedPassphrase]: 'Device opened passphrase',
21253
21508
  [HardwareErrorCode.NotInitialized]: 'Not initialized',
21254
21509
  [HardwareErrorCode.IFrameNotInitialized]: 'IFrame not initialized',
21255
21510
  [HardwareErrorCode.IFrameAleradyInitialized]: 'IFrame alerady initialized',
@@ -21289,7 +21544,8 @@ const HardwareErrorCodeMessage = {
21289
21544
  [HardwareErrorCode.BridgeTimeoutError]: 'Bridge network timeout',
21290
21545
  [HardwareErrorCode.BridgeNotInstalled]: 'Bridge not installed',
21291
21546
  [HardwareErrorCode.PollingTimeout]: 'Polling timeout',
21292
- [HardwareErrorCode.PollingStop]: 'Polling stop'
21547
+ [HardwareErrorCode.PollingStop]: 'Polling stop',
21548
+ [HardwareErrorCode.BlindSignDisabled]: 'Please confirm the BlindSign enabled'
21293
21549
  };
21294
21550
 
21295
21551
  const TypedError = (hardwareError, message, params) => {
@@ -46540,7 +46796,7 @@ const src_init = async settings => {
46540
46796
 
46541
46797
  try {
46542
46798
  await init({ ..._settings,
46543
- version: "0.1.37"
46799
+ version: "0.1.40"
46544
46800
  });
46545
46801
  return true;
46546
46802
  } catch (e) {