@onekeyfe/hd-web-sdk 0.1.36 → 0.1.39

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.36"}/`;
14921
+ const DEFAULT_DOMAIN = `https://jssdk.onekey.so/${"0.1.39"}/`;
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,75 @@ 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, _c;
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
+ const key = `${deviceId}`;
15182
+ const usePassKey = `${deviceId}@${this.passphraseState}`;
15183
+ const session = (_c = deviceSessionCache[key]) !== null && _c !== void 0 ? _c : deviceSessionCache[usePassKey];
15184
+ return this.passphraseState ? session : undefined;
15185
+ }
15186
+
15187
+ setInternalState(state, initSession) {
15188
+ var _a;
15189
+
15190
+ 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}`);
15191
+ if (!this.features) return;
15192
+ if (!this.passphraseState && !initSession) return;
15193
+ let key = `${this.features.device_id}`;
15194
+
15195
+ if (this.passphraseState) {
15196
+ key += `@${this.passphraseState}`;
15197
+ }
15198
+
15199
+ if (state) {
15200
+ deviceSessionCache[key] = state;
15201
+ }
15202
+
15203
+ Log$3.debug('setInternalState done session cache: ', deviceSessionCache);
15121
15204
  }
15122
15205
 
15123
- initialize() {
15206
+ clearInternalState(_deviceId) {
15207
+ var _a;
15208
+
15209
+ Log$3.debug('clearInternalState param: ', _deviceId);
15210
+ const deviceId = _deviceId || ((_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id);
15211
+ if (!deviceId) return;
15212
+ const key = `${deviceId}`;
15213
+ delete deviceSessionCache[key];
15214
+
15215
+ if (this.passphraseState) {
15216
+ const usePassKey = `${deviceId}@${this.passphraseState}`;
15217
+ delete deviceSessionCache[usePassKey];
15218
+ }
15219
+ }
15220
+
15221
+ initialize(options) {
15124
15222
  return __awaiter(this, void 0, void 0, function* () {
15125
- let payload;
15223
+ Log$3.debug('initialize param:', options);
15224
+ this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
15225
+
15226
+ if (options === null || options === void 0 ? void 0 : options.initSession) {
15227
+ this.clearInternalState(options === null || options === void 0 ? void 0 : options.deviceId);
15228
+ }
15126
15229
 
15127
- if (this.features) {
15128
- const internalState = this.getInternalState();
15129
- payload = {};
15230
+ const internalState = this.getInternalState(options === null || options === void 0 ? void 0 : options.deviceId);
15231
+ const payload = {};
15130
15232
 
15131
- if (internalState) {
15132
- payload.session_id = internalState;
15133
- }
15233
+ if (internalState) {
15234
+ payload.session_id = internalState;
15134
15235
  }
15135
15236
 
15237
+ Log$3.debug('initialize payload:', payload);
15136
15238
  const {
15137
15239
  message
15138
15240
  } = yield this.commands.typedCall('Initialize', 'Features', payload);
15139
15241
 
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
- }
15242
+ this._updateFeatures(message, options === null || options === void 0 ? void 0 : options.initSession);
15157
15243
  });
15158
15244
  }
15159
15245
 
@@ -15167,11 +15253,15 @@ class Device extends events.exports {
15167
15253
  });
15168
15254
  }
15169
15255
 
15170
- _updateFeatures(feat) {
15256
+ _updateFeatures(feat, initSession) {
15171
15257
  if (this.features && this.features.session_id && !feat.session_id) {
15172
15258
  feat.session_id = this.features.session_id;
15173
15259
  }
15174
15260
 
15261
+ if (this.features && this.features.device_id && feat.session_id) {
15262
+ this.setInternalState(feat.session_id, initSession);
15263
+ }
15264
+
15175
15265
  feat.unlocked = feat.unlocked || true;
15176
15266
  this.features = feat;
15177
15267
  this.featuresNeedsReload = false;
@@ -15221,8 +15311,6 @@ class Device extends events.exports {
15221
15311
  }
15222
15312
 
15223
15313
  _runInner(fn, options) {
15224
- var _a;
15225
-
15226
15314
  return __awaiter(this, void 0, void 0, function* () {
15227
15315
  if (!this.isUsedHere() || this.commands.disposed) {
15228
15316
  const env = DataManager.getSettings('env');
@@ -15232,7 +15320,7 @@ class Device extends events.exports {
15232
15320
 
15233
15321
  try {
15234
15322
  if (fn) {
15235
- yield this.initialize();
15323
+ yield this.initialize(options);
15236
15324
  }
15237
15325
  } catch (error) {
15238
15326
  this.runPromise = null;
@@ -15243,21 +15331,6 @@ class Device extends events.exports {
15243
15331
 
15244
15332
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, `Initialize failed: ${error.message}, code: ${error.code}`));
15245
15333
  }
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
15334
  }
15262
15335
  }
15263
15336
 
@@ -15391,6 +15464,14 @@ class Device extends events.exports {
15391
15464
  return null;
15392
15465
  }
15393
15466
 
15467
+ hasUsePassphrase() {
15468
+ var _a;
15469
+
15470
+ const isModeT = getDeviceType(this.features) === 'touch' || getDeviceType(this.features) === 'pro';
15471
+ const preCheckTouch = isModeT && ((_a = this.features) === null || _a === void 0 ? void 0 : _a.unlocked) === true;
15472
+ return this.features && (!!this.features.passphrase_protection || preCheckTouch);
15473
+ }
15474
+
15394
15475
  checkDeviceId(deviceId) {
15395
15476
  if (this.features) {
15396
15477
  return this.features.device_id === deviceId;
@@ -15399,6 +15480,26 @@ class Device extends events.exports {
15399
15480
  return false;
15400
15481
  }
15401
15482
 
15483
+ checkPassphraseState() {
15484
+ var _a;
15485
+
15486
+ return __awaiter(this, void 0, void 0, function* () {
15487
+ if (!this.features) return false;
15488
+ const locked = ((_a = this.features) === null || _a === void 0 ? void 0 : _a.unlocked) === true;
15489
+ const isModeT = getDeviceType(this.features) === 'touch' || getDeviceType(this.features) === 'pro';
15490
+ const newState = yield getPassphraseState(this.features, this.commands);
15491
+
15492
+ if (isModeT && locked) {
15493
+ yield this.getFeatures();
15494
+ }
15495
+
15496
+ if (this.passphraseState && this.passphraseState !== newState) {
15497
+ this.clearInternalState();
15498
+ return newState;
15499
+ }
15500
+ });
15501
+ }
15502
+
15402
15503
  }
15403
15504
 
15404
15505
  class DeviceList extends events.exports {
@@ -15407,7 +15508,7 @@ class DeviceList extends events.exports {
15407
15508
  this.devices = {};
15408
15509
  }
15409
15510
 
15410
- getDeviceLists(connectId) {
15511
+ getDeviceLists(connectId, initOptions) {
15411
15512
  var _a, _b;
15412
15513
 
15413
15514
  return __awaiter(this, void 0, void 0, function* () {
@@ -15417,7 +15518,7 @@ class DeviceList extends events.exports {
15417
15518
  const {
15418
15519
  deviceList,
15419
15520
  devices
15420
- } = yield DevicePool.getDevices(descriptorList, connectId);
15521
+ } = yield DevicePool.getDevices(descriptorList, connectId, initOptions);
15421
15522
  this.devices = devices;
15422
15523
  return deviceList;
15423
15524
  });
@@ -15459,6 +15560,7 @@ class BaseMethod {
15459
15560
  constructor(message) {
15460
15561
  this.shouldEnsureConnected = true;
15461
15562
  this.checkDeviceId = false;
15563
+ this.useDevicePassphraseState = true;
15462
15564
  const {
15463
15565
  payload
15464
15566
  } = message;
@@ -15509,6 +15611,7 @@ class BaseMethod {
15509
15611
  class SearchDevices extends BaseMethod {
15510
15612
  init() {
15511
15613
  this.useDevice = false;
15614
+ this.useDevicePassphraseState = false;
15512
15615
  }
15513
15616
 
15514
15617
  run() {
@@ -15543,6 +15646,7 @@ class SearchDevices extends BaseMethod {
15543
15646
  class GetFeatures extends BaseMethod {
15544
15647
  init() {
15545
15648
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE, UI_REQUEST.BOOTLOADER];
15649
+ this.useDevicePassphraseState = false;
15546
15650
  }
15547
15651
 
15548
15652
  run() {
@@ -16810,7 +16914,9 @@ class BTCVerifyMessage extends BaseMethod {
16810
16914
  }
16811
16915
 
16812
16916
  class CheckFirmwareRelease extends BaseMethod {
16813
- init() {}
16917
+ init() {
16918
+ this.useDevicePassphraseState = false;
16919
+ }
16814
16920
 
16815
16921
  run() {
16816
16922
  if (this.device.features) {
@@ -16827,6 +16933,7 @@ class CheckBLEFirmwareRelease extends BaseMethod {
16827
16933
  init() {
16828
16934
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.BOOTLOADER];
16829
16935
  this.checkDeviceId = true;
16936
+ this.useDevicePassphraseState = false;
16830
16937
  }
16831
16938
 
16832
16939
  run() {
@@ -16843,6 +16950,7 @@ class CheckBLEFirmwareRelease extends BaseMethod {
16843
16950
  class CheckTransportRelease extends BaseMethod {
16844
16951
  init() {
16845
16952
  this.useDevice = false;
16953
+ this.useDevicePassphraseState = false;
16846
16954
  }
16847
16955
 
16848
16956
  run() {
@@ -16859,6 +16967,7 @@ class CheckTransportRelease extends BaseMethod {
16859
16967
  class CheckBridgeStatus$1 extends BaseMethod {
16860
16968
  init() {
16861
16969
  this.useDevice = false;
16970
+ this.useDevicePassphraseState = false;
16862
16971
  }
16863
16972
 
16864
16973
  run() {
@@ -16883,7 +16992,9 @@ class CheckBridgeStatus$1 extends BaseMethod {
16883
16992
  }
16884
16993
 
16885
16994
  class DeviceBackup extends BaseMethod {
16886
- init() {}
16995
+ init() {
16996
+ this.useDevicePassphraseState = false;
16997
+ }
16887
16998
 
16888
16999
  run() {
16889
17000
  return __awaiter(this, void 0, void 0, function* () {
@@ -16896,6 +17007,7 @@ class DeviceBackup extends BaseMethod {
16896
17007
 
16897
17008
  class DeviceChangePin extends BaseMethod {
16898
17009
  init() {
17010
+ this.useDevicePassphraseState = false;
16899
17011
  validateParams(this.payload, [{
16900
17012
  name: 'remove',
16901
17013
  type: 'boolean'
@@ -16916,6 +17028,7 @@ class DeviceChangePin extends BaseMethod {
16916
17028
 
16917
17029
  class DeviceFlags extends BaseMethod {
16918
17030
  init() {
17031
+ this.useDevicePassphraseState = false;
16919
17032
  validateParams(this.payload, [{
16920
17033
  name: 'flags',
16921
17034
  type: 'number'
@@ -16935,7 +17048,9 @@ class DeviceFlags extends BaseMethod {
16935
17048
  }
16936
17049
 
16937
17050
  class DeviceRebootToBootloader extends BaseMethod {
16938
- init() {}
17051
+ init() {
17052
+ this.useDevicePassphraseState = false;
17053
+ }
16939
17054
 
16940
17055
  getVersionRange() {
16941
17056
  return {
@@ -16959,6 +17074,7 @@ class DeviceRebootToBootloader extends BaseMethod {
16959
17074
 
16960
17075
  class DeviceRecovery extends BaseMethod {
16961
17076
  init() {
17077
+ this.useDevicePassphraseState = false;
16962
17078
  validateParams(this.payload, [{
16963
17079
  name: 'wordCount',
16964
17080
  type: 'number'
@@ -17011,6 +17127,7 @@ class DeviceRecovery extends BaseMethod {
17011
17127
 
17012
17128
  class DeviceReset extends BaseMethod {
17013
17129
  init() {
17130
+ this.useDevicePassphraseState = false;
17014
17131
  validateParams(this.payload, [{
17015
17132
  name: 'displayRandom',
17016
17133
  type: 'boolean'
@@ -17066,6 +17183,7 @@ class DeviceReset extends BaseMethod {
17066
17183
 
17067
17184
  class DeviceSettings extends BaseMethod {
17068
17185
  init() {
17186
+ this.useDevicePassphraseState = false;
17069
17187
  validateParams(this.payload, [{
17070
17188
  name: 'language',
17071
17189
  type: 'string'
@@ -17097,7 +17215,6 @@ class DeviceSettings extends BaseMethod {
17097
17215
  name: 'experimentalFeatures',
17098
17216
  type: 'boolean'
17099
17217
  }]);
17100
- console.log('DeviceSettings payload', this.payload);
17101
17218
  this.params = {
17102
17219
  language: this.payload.language,
17103
17220
  label: this.payload.label,
@@ -17112,6 +17229,18 @@ class DeviceSettings extends BaseMethod {
17112
17229
  };
17113
17230
  }
17114
17231
 
17232
+ getVersionRange() {
17233
+ if (this.payload.usePassphrase) {
17234
+ return {
17235
+ model_mini: {
17236
+ min: '2.4.0'
17237
+ }
17238
+ };
17239
+ }
17240
+
17241
+ return {};
17242
+ }
17243
+
17115
17244
  run() {
17116
17245
  return __awaiter(this, void 0, void 0, function* () {
17117
17246
  const res = yield this.device.commands.typedCall('ApplySettings', 'Success', Object.assign({}, this.params));
@@ -17122,7 +17251,9 @@ class DeviceSettings extends BaseMethod {
17122
17251
  }
17123
17252
 
17124
17253
  class DeviceUpdateReboot extends BaseMethod {
17125
- init() {}
17254
+ init() {
17255
+ this.useDevicePassphraseState = false;
17256
+ }
17126
17257
 
17127
17258
  run() {
17128
17259
  return __awaiter(this, void 0, void 0, function* () {
@@ -17134,7 +17265,9 @@ class DeviceUpdateReboot extends BaseMethod {
17134
17265
  }
17135
17266
 
17136
17267
  class DeviceSupportFeatures extends BaseMethod {
17137
- init() {}
17268
+ init() {
17269
+ this.useDevicePassphraseState = false;
17270
+ }
17138
17271
 
17139
17272
  run() {
17140
17273
  if (!this.device.features) return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Device not initialized'));
@@ -17149,6 +17282,7 @@ class DeviceSupportFeatures extends BaseMethod {
17149
17282
 
17150
17283
  class DeviceVerify extends BaseMethod {
17151
17284
  init() {
17285
+ this.useDevicePassphraseState = false;
17152
17286
  validateParams(this.payload, [{
17153
17287
  name: 'dataHex',
17154
17288
  type: 'hexString'
@@ -17187,7 +17321,9 @@ class DeviceVerify extends BaseMethod {
17187
17321
  }
17188
17322
 
17189
17323
  class DeviceWipe extends BaseMethod {
17190
- init() {}
17324
+ init() {
17325
+ this.useDevicePassphraseState = false;
17326
+ }
17191
17327
 
17192
17328
  run() {
17193
17329
  return __awaiter(this, void 0, void 0, function* () {
@@ -19075,6 +19211,7 @@ class FirmwareUpdate extends BaseMethod {
19075
19211
  init() {
19076
19212
  this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.INITIALIZE];
19077
19213
  this.requireDeviceMode = [UI_REQUEST.BOOTLOADER];
19214
+ this.useDevicePassphraseState = false;
19078
19215
  const {
19079
19216
  payload
19080
19217
  } = this;
@@ -19149,6 +19286,7 @@ const Log$2 = getLogger(exports.d0.Method);
19149
19286
  class RequestWebUsbDevice extends BaseMethod {
19150
19287
  init() {
19151
19288
  this.useDevice = false;
19289
+ this.useDevicePassphraseState = false;
19152
19290
  }
19153
19291
 
19154
19292
  run() {
@@ -19185,9 +19323,45 @@ class RequestWebUsbDevice extends BaseMethod {
19185
19323
 
19186
19324
  }
19187
19325
 
19326
+ class GetPassphraseState extends BaseMethod {
19327
+ init() {
19328
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
19329
+ this.useDevicePassphraseState = false;
19330
+ }
19331
+
19332
+ run() {
19333
+ var _a, _b;
19334
+
19335
+ return __awaiter(this, void 0, void 0, function* () {
19336
+ if (!this.device.features) return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed));
19337
+ let {
19338
+ features
19339
+ } = this.device;
19340
+ const locked = ((_b = (_a = this.device) === null || _a === void 0 ? void 0 : _a.features) === null || _b === void 0 ? void 0 : _b.unlocked) === true;
19341
+ const passphraseState = yield getPassphraseState(this.device.features, this.device.commands);
19342
+ const isModeT = getDeviceType(features) === 'touch' || getDeviceType(features) === 'pro';
19343
+
19344
+ if (isModeT && locked) {
19345
+ const {
19346
+ message
19347
+ } = yield this.device.commands.typedCall('GetFeatures', 'Features', {});
19348
+ features = message;
19349
+ }
19350
+
19351
+ if (features && features.passphrase_protection === true) {
19352
+ return Promise.resolve(passphraseState);
19353
+ }
19354
+
19355
+ return Promise.resolve(undefined);
19356
+ });
19357
+ }
19358
+
19359
+ }
19360
+
19188
19361
  class CheckBridgeStatus extends BaseMethod {
19189
19362
  init() {
19190
19363
  this.useDevice = false;
19364
+ this.useDevicePassphraseState = false;
19191
19365
  }
19192
19366
 
19193
19367
  run() {
@@ -19244,6 +19418,7 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
19244
19418
  stellarSignTransaction: StellarSignTransaction,
19245
19419
  firmwareUpdate: FirmwareUpdate,
19246
19420
  requestWebUsbDevice: RequestWebUsbDevice,
19421
+ getPassphraseState: GetPassphraseState,
19247
19422
  getLogs: CheckBridgeStatus
19248
19423
  });
19249
19424
 
@@ -19393,6 +19568,12 @@ class DeviceConnector {
19393
19568
 
19394
19569
  const Log = getLogger(exports.d0.Core);
19395
19570
 
19571
+ const parseInitOptions = method => ({
19572
+ initSession: method === null || method === void 0 ? void 0 : method.payload.initSession,
19573
+ passphraseState: method === null || method === void 0 ? void 0 : method.payload.passphraseState,
19574
+ deviceId: method === null || method === void 0 ? void 0 : method.payload.deviceId
19575
+ });
19576
+
19396
19577
  let _core;
19397
19578
 
19398
19579
  let _deviceList;
@@ -19407,6 +19588,9 @@ const callApiQueue = [];
19407
19588
  const deviceCacheMap = new Map();
19408
19589
  let pollingId = 1;
19409
19590
  const pollingState = {};
19591
+ let preConnectCache = {
19592
+ passphraseState: undefined
19593
+ };
19410
19594
 
19411
19595
  const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19412
19596
  var _a;
@@ -19446,6 +19630,16 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19446
19630
  Log.debug('should cancel the previous method execution: ', callApiQueue.map(m => m.name));
19447
19631
  }
19448
19632
 
19633
+ const connectStateChange = preConnectCache.passphraseState !== method.payload.passphraseState;
19634
+ preConnectCache = {
19635
+ passphraseState: method.payload.passphraseState
19636
+ };
19637
+
19638
+ if (connectStateChange || method.payload.initSession) {
19639
+ Log.debug('passphrase state change, clear device cache');
19640
+ DevicePool.clearDeviceCache(method.payload.connectId);
19641
+ }
19642
+
19449
19643
  if (pollingState[pollingId]) {
19450
19644
  pollingState[pollingId] = false;
19451
19645
  }
@@ -19465,6 +19659,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19465
19659
  (_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
19466
19660
  device.on(DEVICE.PIN, onDevicePinHandler);
19467
19661
  device.on(DEVICE.BUTTON, onDeviceButtonHandler);
19662
+ device.on(DEVICE.PASSPHRASE_ON_DEVICE, onDevicePassphraseHandler);
19468
19663
  device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
19469
19664
 
19470
19665
  try {
@@ -19518,6 +19713,26 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19518
19713
  yield TransportManager.reconfigure(device.getFirmwareVersion());
19519
19714
  }
19520
19715
 
19716
+ checkPassphraseSafety(method, device.features);
19717
+
19718
+ if (device.hasUsePassphrase() && method.useDevicePassphraseState) {
19719
+ const support = supportNewPassphrase(device.features);
19720
+
19721
+ if (!support.support) {
19722
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportPassphrase, `Device not support passphrase, please update to ${support.require}`, {
19723
+ require: support.require
19724
+ }));
19725
+ }
19726
+
19727
+ const passphraseState = yield device.checkPassphraseState();
19728
+ checkPassphraseSafety(method, device.features);
19729
+
19730
+ if (passphraseState) {
19731
+ DevicePool.clearDeviceCache(method.payload.connectId);
19732
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError));
19733
+ }
19734
+ }
19735
+
19521
19736
  try {
19522
19737
  const response = yield method.run();
19523
19738
  Log.debug('Call API - Inner Method Run: ');
@@ -19533,8 +19748,11 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19533
19748
  });
19534
19749
 
19535
19750
  Log.debug('Call API - Device Run: ', device.mainId);
19751
+ const runOptions = Object.assign({
19752
+ keepSession: method.payload.keepSession
19753
+ }, parseInitOptions(method));
19536
19754
 
19537
- const deviceRun = () => device.run(inner);
19755
+ const deviceRun = () => device.run(inner, runOptions);
19538
19756
 
19539
19757
  _callPromise = hdShared.createDeferred(deviceRun);
19540
19758
 
@@ -19589,7 +19807,7 @@ function initDeviceList(method) {
19589
19807
  _deviceList.connector = _connector;
19590
19808
  }
19591
19809
 
19592
- yield _deviceList.getDeviceLists(method.connectId);
19810
+ yield _deviceList.getDeviceLists(method.connectId, parseInitOptions(method));
19593
19811
  });
19594
19812
  }
19595
19813
 
@@ -19701,7 +19919,7 @@ const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0,
19701
19919
 
19702
19920
  if (env === 'react-native') {
19703
19921
  yield device.acquire();
19704
- yield device.initialize();
19922
+ yield device.initialize(parseInitOptions(method));
19705
19923
  }
19706
19924
 
19707
19925
  resolve(device);
@@ -19710,7 +19928,7 @@ const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0,
19710
19928
  } catch (error) {
19711
19929
  Log.debug('device error: ', error);
19712
19930
 
19713
- if ([hdShared.HardwareErrorCode.BlePermissionError, hdShared.HardwareErrorCode.BleLocationError, hdShared.HardwareErrorCode.BleDeviceNotBonded, hdShared.HardwareErrorCode.BleCharacteristicNotifyError, hdShared.HardwareErrorCode.BleWriteCharacteristicError].includes(error.errorCode)) {
19931
+ if ([hdShared.HardwareErrorCode.BlePermissionError, hdShared.HardwareErrorCode.BleLocationError, hdShared.HardwareErrorCode.BleDeviceNotBonded, hdShared.HardwareErrorCode.BleCharacteristicNotifyError, hdShared.HardwareErrorCode.BleWriteCharacteristicError, hdShared.HardwareErrorCode.BleAlreadyConnected].includes(error.errorCode)) {
19714
19932
  reject(error);
19715
19933
  return;
19716
19934
  }
@@ -19761,6 +19979,20 @@ const cancel = connectId => {
19761
19979
  closePopup();
19762
19980
  };
19763
19981
 
19982
+ const checkPassphraseSafety = (method, features) => {
19983
+ if (!method.useDevicePassphraseState) return;
19984
+
19985
+ if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true && !method.payload.passphraseState) {
19986
+ DevicePool.clearDeviceCache(method.payload.connectId);
19987
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceOpenedPassphrase);
19988
+ }
19989
+
19990
+ if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === false && method.payload.passphraseState) {
19991
+ DevicePool.clearDeviceCache(method.payload.connectId);
19992
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotOpenedPassphrase);
19993
+ }
19994
+ };
19995
+
19764
19996
  const cleanup = () => {
19765
19997
  _uiPromises = [];
19766
19998
  Log.debug('Cleanup...');
@@ -19769,6 +20001,7 @@ const cleanup = () => {
19769
20001
  const removeDeviceListener = device => {
19770
20002
  device.removeListener(DEVICE.PIN, onDevicePinHandler);
19771
20003
  device.removeListener(DEVICE.BUTTON, onDeviceButtonHandler);
20004
+ device.removeListener(DEVICE.PASSPHRASE_ON_DEVICE, onDevicePassphraseHandler);
19772
20005
  device.removeListener(DEVICE.FEATURES, onDeviceFeaturesHandler);
19773
20006
  DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
19774
20007
  };
@@ -19825,6 +20058,13 @@ const onDeviceFeaturesHandler = (...[_, features]) => {
19825
20058
  postMessage(createDeviceMessage(DEVICE.FEATURES, Object.assign({}, features)));
19826
20059
  };
19827
20060
 
20061
+ const onDevicePassphraseHandler = (...[device]) => {
20062
+ postMessage(createUiMessage(UI_REQUEST$1.REQUEST_PASSPHRASE_ON_DEVICE, {
20063
+ device: device.toMessageObject(),
20064
+ passphraseState: device.passphraseState
20065
+ }));
20066
+ };
20067
+
19828
20068
  const postMessage = message => {
19829
20069
  _core.emit(CORE_EVENT, message);
19830
20070
  };
@@ -21196,6 +21436,9 @@ const HardwareErrorCode = {
21196
21436
  DeviceInterruptedFromUser: 109,
21197
21437
  DeviceCheckDeviceIdError: 110,
21198
21438
  DeviceNotSupportPassphrase: 111,
21439
+ DeviceCheckPassphraseStateError: 112,
21440
+ DeviceNotOpenedPassphrase: 113,
21441
+ DeviceOpenedPassphrase: 114,
21199
21442
  NotInitialized: 200,
21200
21443
  IFrameNotInitialized: 300,
21201
21444
  IFrameAleradyInitialized: 301,
@@ -21224,6 +21467,7 @@ const HardwareErrorCode = {
21224
21467
  BleMonitorError: 708,
21225
21468
  BleCharacteristicNotifyError: 709,
21226
21469
  BleWriteCharacteristicError: 710,
21470
+ BleAlreadyConnected: 711,
21227
21471
  RuntimeError: 800,
21228
21472
  PinInvalid: 801,
21229
21473
  PinCancelled: 802,
@@ -21234,7 +21478,8 @@ const HardwareErrorCode = {
21234
21478
  BridgeTimeoutError: 807,
21235
21479
  BridgeNotInstalled: 808,
21236
21480
  PollingTimeout: 809,
21237
- PollingStop: 810
21481
+ PollingStop: 810,
21482
+ BlindSignDisabled: 811
21238
21483
  };
21239
21484
  const HardwareErrorCodeMessage = {
21240
21485
  [HardwareErrorCode.UnknownError]: 'Unknown error occurred. Check message property.',
@@ -21249,6 +21494,9 @@ const HardwareErrorCodeMessage = {
21249
21494
  [HardwareErrorCode.DeviceUnexpectedBootloaderMode]: 'Device should be in bootloader mode',
21250
21495
  [HardwareErrorCode.DeviceCheckDeviceIdError]: 'Device Id in the features is not same.',
21251
21496
  [HardwareErrorCode.DeviceNotSupportPassphrase]: 'Device not support passphrase',
21497
+ [HardwareErrorCode.DeviceCheckPassphraseStateError]: 'Device passphrase state error',
21498
+ [HardwareErrorCode.DeviceNotOpenedPassphrase]: 'Device not opened passphrase',
21499
+ [HardwareErrorCode.DeviceOpenedPassphrase]: 'Device opened passphrase',
21252
21500
  [HardwareErrorCode.NotInitialized]: 'Not initialized',
21253
21501
  [HardwareErrorCode.IFrameNotInitialized]: 'IFrame not initialized',
21254
21502
  [HardwareErrorCode.IFrameAleradyInitialized]: 'IFrame alerady initialized',
@@ -21277,6 +21525,7 @@ const HardwareErrorCodeMessage = {
21277
21525
  [HardwareErrorCode.BleMonitorError]: 'Monitor Error: characteristic not found',
21278
21526
  [HardwareErrorCode.BleCharacteristicNotifyError]: 'Characteristic Notify Error',
21279
21527
  [HardwareErrorCode.BleWriteCharacteristicError]: 'Write Characteristic Error',
21528
+ [HardwareErrorCode.BleAlreadyConnected]: 'Already connected to device',
21280
21529
  [HardwareErrorCode.RuntimeError]: 'Runtime error',
21281
21530
  [HardwareErrorCode.PinInvalid]: 'Pin invalid',
21282
21531
  [HardwareErrorCode.PinCancelled]: 'Pin cancelled',
@@ -21287,7 +21536,8 @@ const HardwareErrorCodeMessage = {
21287
21536
  [HardwareErrorCode.BridgeTimeoutError]: 'Bridge network timeout',
21288
21537
  [HardwareErrorCode.BridgeNotInstalled]: 'Bridge not installed',
21289
21538
  [HardwareErrorCode.PollingTimeout]: 'Polling timeout',
21290
- [HardwareErrorCode.PollingStop]: 'Polling stop'
21539
+ [HardwareErrorCode.PollingStop]: 'Polling stop',
21540
+ [HardwareErrorCode.BlindSignDisabled]: 'Please confirm the BlindSign enabled'
21291
21541
  };
21292
21542
 
21293
21543
  const TypedError = (hardwareError, message, params) => {
@@ -46538,7 +46788,7 @@ const src_init = async settings => {
46538
46788
 
46539
46789
  try {
46540
46790
  await init({ ..._settings,
46541
- version: "0.1.36"
46791
+ version: "0.1.39"
46542
46792
  });
46543
46793
  return true;
46544
46794
  } catch (e) {