@onekeyfe/hd-core 1.1.26-patch.2 → 1.1.27-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/api/BaseMethod.d.ts +4 -0
  2. package/dist/api/BaseMethod.d.ts.map +1 -1
  3. package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
  4. package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
  5. package/dist/api/algo/AlgoSignTransaction.d.ts.map +1 -1
  6. package/dist/api/aptos/AptosSignInMessage.d.ts.map +1 -1
  7. package/dist/api/aptos/AptosSignMessage.d.ts.map +1 -1
  8. package/dist/api/aptos/AptosSignTransaction.d.ts.map +1 -1
  9. package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
  10. package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
  11. package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
  12. package/dist/api/btc/BTCSignPsbt.d.ts.map +1 -1
  13. package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
  14. package/dist/api/cardano/CardanoSignMessage.d.ts.map +1 -1
  15. package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -1
  16. package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -1
  17. package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -1
  18. package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
  19. package/dist/api/cosmos/CosmosSignTransaction.d.ts.map +1 -1
  20. package/dist/api/device/PreInitialize.d.ts +6 -0
  21. package/dist/api/device/PreInitialize.d.ts.map +1 -0
  22. package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
  23. package/dist/api/evm/EVMSignMessage.d.ts.map +1 -1
  24. package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
  25. package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
  26. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  27. package/dist/api/filecoin/FilecoinSignTransaction.d.ts.map +1 -1
  28. package/dist/api/index.d.ts +1 -0
  29. package/dist/api/index.d.ts.map +1 -1
  30. package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
  31. package/dist/api/near/NearSignTransaction.d.ts.map +1 -1
  32. package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -1
  33. package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
  34. package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
  35. package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
  36. package/dist/api/nostr/NostrSignEvent.d.ts.map +1 -1
  37. package/dist/api/nostr/NostrSignSchnorr.d.ts.map +1 -1
  38. package/dist/api/polkadot/PolkadotSignTransaction.d.ts.map +1 -1
  39. package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
  40. package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
  41. package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
  42. package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
  43. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
  44. package/dist/api/starcoin/StarcoinSignMessage.d.ts.map +1 -1
  45. package/dist/api/starcoin/StarcoinSignTransaction.d.ts.map +1 -1
  46. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
  47. package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
  48. package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
  49. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  50. package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
  51. package/dist/api/ton/TonSignProof.d.ts.map +1 -1
  52. package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
  53. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
  54. package/dist/api/xrp/XrpSignTransaction.d.ts.map +1 -1
  55. package/dist/core/PollingStateManager.d.ts +8 -0
  56. package/dist/core/PollingStateManager.d.ts.map +1 -0
  57. package/dist/core/RequestQueue.d.ts +1 -1
  58. package/dist/core/RequestQueue.d.ts.map +1 -1
  59. package/dist/core/index.d.ts.map +1 -1
  60. package/dist/device/Device.d.ts +17 -0
  61. package/dist/device/Device.d.ts.map +1 -1
  62. package/dist/index.d.ts +21 -0
  63. package/dist/index.js +347 -113
  64. package/dist/types/api/index.d.ts +2 -0
  65. package/dist/types/api/index.d.ts.map +1 -1
  66. package/dist/types/api/preInitialize.d.ts +3 -0
  67. package/dist/types/api/preInitialize.d.ts.map +1 -0
  68. package/dist/types/params.d.ts +1 -0
  69. package/dist/types/params.d.ts.map +1 -1
  70. package/package.json +4 -4
  71. package/src/api/BaseMethod.ts +24 -0
  72. package/src/api/alephium/AlephiumSignMessage.ts +1 -0
  73. package/src/api/alephium/AlephiumSignTransaction.ts +1 -0
  74. package/src/api/algo/AlgoSignTransaction.ts +1 -0
  75. package/src/api/aptos/AptosSignInMessage.ts +1 -0
  76. package/src/api/aptos/AptosSignMessage.ts +1 -0
  77. package/src/api/aptos/AptosSignTransaction.ts +1 -0
  78. package/src/api/benfen/BenfenSignMessage.ts +1 -0
  79. package/src/api/benfen/BenfenSignTransaction.ts +1 -0
  80. package/src/api/btc/BTCSignMessage.ts +1 -0
  81. package/src/api/btc/BTCSignPsbt.ts +1 -0
  82. package/src/api/btc/BTCSignTransaction.ts +1 -0
  83. package/src/api/cardano/CardanoSignMessage.ts +1 -0
  84. package/src/api/cardano/CardanoSignTransaction.ts +1 -0
  85. package/src/api/conflux/ConfluxSignMessage.ts +1 -0
  86. package/src/api/conflux/ConfluxSignMessageCIP23.ts +1 -0
  87. package/src/api/conflux/ConfluxSignTransaction.ts +1 -0
  88. package/src/api/cosmos/CosmosSignTransaction.ts +1 -0
  89. package/src/api/device/PreInitialize.ts +43 -0
  90. package/src/api/dynex/DnxSignTransaction.ts +1 -0
  91. package/src/api/evm/EVMSignMessage.ts +2 -0
  92. package/src/api/evm/EVMSignMessageEIP712.ts +1 -0
  93. package/src/api/evm/EVMSignTransaction.ts +2 -0
  94. package/src/api/evm/EVMSignTypedData.ts +2 -0
  95. package/src/api/filecoin/FilecoinSignTransaction.ts +1 -0
  96. package/src/api/index.ts +1 -0
  97. package/src/api/kaspa/KaspaSignTransaction.ts +1 -0
  98. package/src/api/near/NearSignTransaction.ts +1 -0
  99. package/src/api/nem/NEMSignTransaction.ts +1 -0
  100. package/src/api/neo/NeoSignTransaction.ts +1 -0
  101. package/src/api/nervos/NervosSignTransaction.ts +1 -0
  102. package/src/api/nexa/NexaSignTransaction.ts +2 -0
  103. package/src/api/nostr/NostrSignEvent.ts +1 -0
  104. package/src/api/nostr/NostrSignSchnorr.ts +1 -0
  105. package/src/api/polkadot/PolkadotSignTransaction.ts +1 -0
  106. package/src/api/scdo/ScdoSignMessage.ts +1 -0
  107. package/src/api/scdo/ScdoSignTransaction.ts +1 -0
  108. package/src/api/solana/SolSignMessage.ts +1 -0
  109. package/src/api/solana/SolSignOffchainMessage.ts +1 -0
  110. package/src/api/solana/SolSignTransaction.ts +1 -0
  111. package/src/api/starcoin/StarcoinSignMessage.ts +1 -0
  112. package/src/api/starcoin/StarcoinSignTransaction.ts +1 -0
  113. package/src/api/stellar/StellarSignTransaction.ts +1 -0
  114. package/src/api/sui/SuiSignMessage.ts +1 -0
  115. package/src/api/sui/SuiSignTransaction.ts +1 -0
  116. package/src/api/ton/TonSignData.ts +1 -0
  117. package/src/api/ton/TonSignMessage.ts +1 -0
  118. package/src/api/ton/TonSignProof.ts +1 -0
  119. package/src/api/tron/TronSignMessage.ts +1 -0
  120. package/src/api/tron/TronSignTransaction.ts +1 -0
  121. package/src/api/xrp/XrpSignTransaction.ts +1 -0
  122. package/src/core/PollingStateManager.ts +47 -0
  123. package/src/core/RequestQueue.ts +10 -3
  124. package/src/core/index.ts +145 -27
  125. package/src/device/Device.ts +73 -9
  126. package/src/inject.ts +1 -1
  127. package/src/types/api/index.ts +2 -0
  128. package/src/types/api/preInitialize.ts +3 -0
  129. package/src/types/params.ts +5 -0
package/dist/index.js CHANGED
@@ -131,6 +131,7 @@ const createCoreApi = (call) => ({
131
131
  checkFirmwareTypeAvailable: params => call(Object.assign(Object.assign({}, params), { method: 'checkFirmwareTypeAvailable' })),
132
132
  cipherKeyValue: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'cipherKeyValue' })),
133
133
  testInitializeDeviceDuration: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'testInitializeDeviceDuration' })),
134
+ preInitialize: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'preInitialize' })),
134
135
  deviceBackup: connectId => call({ connectId, method: 'deviceBackup' }),
135
136
  deviceChangePin: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceChangePin' })),
136
137
  deviceFlags: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFlags' })),
@@ -788,7 +789,7 @@ const createLogMessage = (type, payload) => ({
788
789
 
789
790
  const MAX_ENTRIES = 500;
790
791
  let postMessage$1;
791
- class Log$g {
792
+ class Log$h {
792
793
  constructor(prefix, enabled) {
793
794
  this.prefix = prefix;
794
795
  this.enabled = enabled;
@@ -840,7 +841,7 @@ class Log$g {
840
841
  }
841
842
  const _logs = {};
842
843
  const initLog = (prefix, enabled) => {
843
- const instance = new Log$g(prefix, !!enabled);
844
+ const instance = new Log$h(prefix, !!enabled);
844
845
  _logs[prefix] = instance;
845
846
  return instance;
846
847
  };
@@ -1038,7 +1039,7 @@ function patchFeatures(response) {
1038
1039
  return response;
1039
1040
  }
1040
1041
 
1041
- const Log$f = getLogger(exports.LoggerNames.Core);
1042
+ const Log$g = getLogger(exports.LoggerNames.Core);
1042
1043
  let globalInstanceCounter = 0;
1043
1044
  let sdkInstanceCounter = 0;
1044
1045
  function generateSdkInstanceId() {
@@ -1098,7 +1099,7 @@ function completeRequestContext(responseID, error) {
1098
1099
  context.status = error ? 'error' : 'success';
1099
1100
  if (error) {
1100
1101
  context.error = error.message;
1101
- Log$f.error(`[RequestContext] [completeRequestContext] Error: ${formatRequestContext(context)}`);
1102
+ Log$g.error(`[RequestContext] [completeRequestContext] Error: ${formatRequestContext(context)}`);
1102
1103
  }
1103
1104
  globalActiveRequests.delete(responseID);
1104
1105
  if (context.sdkInstanceId) {
@@ -25308,7 +25309,7 @@ const findLatestRelease = (releases) => {
25308
25309
  };
25309
25310
 
25310
25311
  var _a$1;
25311
- const Log$e = getLogger(exports.LoggerNames.Core);
25312
+ const Log$f = getLogger(exports.LoggerNames.Core);
25312
25313
  const FIRMWARE_FIELDS = [
25313
25314
  'firmware',
25314
25315
  'firmware-v2',
@@ -25370,37 +25371,37 @@ class DataManager {
25370
25371
  let data = null;
25371
25372
  let fetchMethod = 'none';
25372
25373
  if (settings.configFetcher) {
25373
- Log$e.debug('[DataConfig] Trying configFetcher (client-side fetcher)...');
25374
+ Log$f.debug('[DataConfig] Trying configFetcher (client-side fetcher)...');
25374
25375
  try {
25375
25376
  data = yield settings.configFetcher(urlWithCache);
25376
25377
  if (data) {
25377
25378
  fetchMethod = 'configFetcher';
25378
- Log$e.log('[DataConfig] ConfigFetcher success');
25379
+ Log$f.log('[DataConfig] ConfigFetcher success');
25379
25380
  }
25380
25381
  else {
25381
- Log$e.debug('[DataConfig] ConfigFetcher returned null, will fallback to axios');
25382
+ Log$f.debug('[DataConfig] ConfigFetcher returned null, will fallback to axios');
25382
25383
  }
25383
25384
  }
25384
25385
  catch (e) {
25385
- Log$e.warn('[DataConfig] ConfigFetcher error, will fallback to axios:', e);
25386
+ Log$f.warn('[DataConfig] ConfigFetcher error, will fallback to axios:', e);
25386
25387
  }
25387
25388
  }
25388
25389
  if (!data) {
25389
- Log$e.debug('[DataConfig] Trying axios (SDK default fetcher)...');
25390
+ Log$f.debug('[DataConfig] Trying axios (SDK default fetcher)...');
25390
25391
  try {
25391
25392
  const response = yield axios__default["default"].get(urlWithCache, {
25392
25393
  timeout: 7000,
25393
25394
  });
25394
25395
  data = response.data;
25395
25396
  fetchMethod = 'axios';
25396
- Log$e.log('[DataConfig] Axios fetch success');
25397
+ Log$f.log('[DataConfig] Axios fetch success');
25397
25398
  }
25398
25399
  catch (e) {
25399
- Log$e.warn('[DataConfig] Axios fetch error:', e);
25400
+ Log$f.warn('[DataConfig] Axios fetch error:', e);
25400
25401
  }
25401
25402
  }
25402
25403
  if (data) {
25403
- Log$e.log(`[DataConfig] Config loaded successfully via [${fetchMethod}]`);
25404
+ Log$f.log(`[DataConfig] Config loaded successfully via [${fetchMethod}]`);
25404
25405
  this.deviceMap = {
25405
25406
  [hdShared.EDeviceType.Classic]: this.enrichFirmwareReleaseInfo(data.classic),
25406
25407
  [hdShared.EDeviceType.Classic1s]: this.enrichFirmwareReleaseInfo(data.classic1s),
@@ -25414,7 +25415,7 @@ class DataManager {
25414
25415
  };
25415
25416
  }
25416
25417
  else {
25417
- Log$e.warn('[DataConfig] All fetch methods failed, using built-in default config');
25418
+ Log$f.warn('[DataConfig] All fetch methods failed, using built-in default config');
25418
25419
  }
25419
25420
  });
25420
25421
  }
@@ -26682,7 +26683,7 @@ const LogBlockEvent = new Set([
26682
26683
  UI_RESPONSE.RECEIVE_PASSPHRASE,
26683
26684
  ]);
26684
26685
 
26685
- const Log$d = getLogger(exports.LoggerNames.DevicePool);
26686
+ const Log$e = getLogger(exports.LoggerNames.DevicePool);
26686
26687
  const getDiff = (current, descriptors) => {
26687
26688
  const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
26688
26689
  const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
@@ -26740,7 +26741,7 @@ class DevicePool extends events.exports {
26740
26741
  yield this._checkDevicePool(initOptions);
26741
26742
  return { devices, deviceList };
26742
26743
  }
26743
- Log$d.debug('found device in cache, but path is different: ', connectId);
26744
+ Log$e.debug('found device in cache, but path is different: ', connectId);
26744
26745
  }
26745
26746
  }
26746
26747
  try {
@@ -26801,7 +26802,7 @@ class DevicePool extends events.exports {
26801
26802
  for (let i = this.connectedPool.length - 1; i >= 0; i--) {
26802
26803
  const descriptor = this.connectedPool[i];
26803
26804
  const device = yield this._createDevice(descriptor, initOptions);
26804
- Log$d.debug('emit DEVICE.CONNECT: ', device === null || device === void 0 ? void 0 : device.features);
26805
+ Log$e.debug('emit DEVICE.CONNECT: ', device === null || device === void 0 ? void 0 : device.features);
26805
26806
  this.emitter.emit(DEVICE.CONNECT, device);
26806
26807
  this.connectedPool.splice(i, 1);
26807
26808
  }
@@ -26821,9 +26822,9 @@ class DevicePool extends events.exports {
26821
26822
  const diff = getDiff(this.current || [], upcoming);
26822
26823
  this.upcoming = upcoming;
26823
26824
  this.current = this.upcoming;
26824
- Log$d.debug('device pool -> current: ', this.current);
26825
- Log$d.debug('device pool -> upcomming: ', this.upcoming);
26826
- Log$d.debug('DeviceCache.reportDeviceChange diff: ', diff);
26825
+ Log$e.debug('device pool -> current: ', this.current);
26826
+ Log$e.debug('device pool -> upcomming: ', this.upcoming);
26827
+ Log$e.debug('DeviceCache.reportDeviceChange diff: ', diff);
26827
26828
  if (!diff.didUpdate) {
26828
26829
  return;
26829
26830
  }
@@ -26833,7 +26834,7 @@ class DevicePool extends events.exports {
26833
26834
  this._addConnectedDeviceToPool(d);
26834
26835
  return;
26835
26836
  }
26836
- Log$d.debug('emit DEVICE.CONNECT: ', device.features);
26837
+ Log$e.debug('emit DEVICE.CONNECT: ', device.features);
26837
26838
  this.emitter.emit(DEVICE.CONNECT, device);
26838
26839
  });
26839
26840
  diff.disconnected.forEach(d => {
@@ -26843,7 +26844,7 @@ class DevicePool extends events.exports {
26843
26844
  this._addDisconnectedDeviceToPool(d);
26844
26845
  return;
26845
26846
  }
26846
- Log$d.debug('emit DEVICE.DISCONNECT: ', device.features);
26847
+ Log$e.debug('emit DEVICE.DISCONNECT: ', device.features);
26847
26848
  this.emitter.emit(DEVICE.DISCONNECT, device);
26848
26849
  });
26849
26850
  }
@@ -26879,7 +26880,7 @@ class DevicePool extends events.exports {
26879
26880
  this.disconnectPool = [];
26880
26881
  this.devicesCache = {};
26881
26882
  this.emitter.removeAllListeners();
26882
- Log$d.debug('DevicePool state has been reset');
26883
+ Log$e.debug('DevicePool state has been reset');
26883
26884
  }
26884
26885
  }
26885
26886
  DevicePool.current = null;
@@ -26889,7 +26890,7 @@ DevicePool.disconnectPool = [];
26889
26890
  DevicePool.devicesCache = {};
26890
26891
  DevicePool.emitter = new events.exports();
26891
26892
 
26892
- const Log$c = getLogger(exports.LoggerNames.Transport);
26893
+ const Log$d = getLogger(exports.LoggerNames.Transport);
26893
26894
  const BleLogger = getLogger(exports.LoggerNames.HdBleTransport);
26894
26895
  const HttpLogger = getLogger(exports.LoggerNames.HdTransportHttp);
26895
26896
  const LowLevelLogger = getLogger(exports.LoggerNames.HdTransportLowLevel);
@@ -26898,7 +26899,7 @@ const WebBleLogger = getLogger(exports.LoggerNames.HdWebBleTransport);
26898
26899
  const WebUsbLogger = getLogger(exports.LoggerNames.HdTransportWebUsb);
26899
26900
  class TransportManager {
26900
26901
  static load() {
26901
- Log$c.debug('transport manager load');
26902
+ Log$d.debug('transport manager load');
26902
26903
  this.defaultMessages = DataManager.getProtobufMessages();
26903
26904
  this.currentMessages = this.defaultMessages;
26904
26905
  this.messageVersion = 'latest';
@@ -26907,14 +26908,14 @@ class TransportManager {
26907
26908
  return __awaiter(this, void 0, void 0, function* () {
26908
26909
  try {
26909
26910
  const env = DataManager.getSettings('env');
26910
- Log$c.debug('Initializing transports', env);
26911
+ Log$d.debug('Initializing transports', env);
26911
26912
  if (env === 'react-native') {
26912
26913
  if (!this.reactNativeInit) {
26913
26914
  yield this.transport.init(BleLogger, DevicePool.emitter);
26914
26915
  this.reactNativeInit = true;
26915
26916
  }
26916
26917
  else {
26917
- Log$c.debug('React Native Do Not Initializing transports');
26918
+ Log$d.debug('React Native Do Not Initializing transports');
26918
26919
  }
26919
26920
  }
26920
26921
  else if (env === 'node-usb') {
@@ -26935,12 +26936,12 @@ class TransportManager {
26935
26936
  else {
26936
26937
  yield this.transport.init(HttpLogger);
26937
26938
  }
26938
- Log$c.debug('Configuring transports');
26939
+ Log$d.debug('Configuring transports');
26939
26940
  yield this.transport.configure(JSON.stringify(this.defaultMessages));
26940
- Log$c.debug('Configuring transports done');
26941
+ Log$d.debug('Configuring transports done');
26941
26942
  }
26942
26943
  catch (error) {
26943
- Log$c.debug('Initializing transports error: ', error);
26944
+ Log$d.debug('Initializing transports error: ', error);
26944
26945
  if (error.code === 'ECONNABORTED') {
26945
26946
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
26946
26947
  }
@@ -26949,12 +26950,12 @@ class TransportManager {
26949
26950
  }
26950
26951
  static reconfigure(features) {
26951
26952
  return __awaiter(this, void 0, void 0, function* () {
26952
- Log$c.debug(`Begin reconfiguring transports`);
26953
+ Log$d.debug(`Begin reconfiguring transports`);
26953
26954
  const { messageVersion, messages } = getSupportMessageVersion(features);
26954
26955
  if (this.currentMessages === messages || !messages) {
26955
26956
  return;
26956
26957
  }
26957
- Log$c.debug(`Reconfiguring transports version:${messageVersion}`);
26958
+ Log$d.debug(`Reconfiguring transports version:${messageVersion}`);
26958
26959
  try {
26959
26960
  yield this.transport.configure(JSON.stringify(messages));
26960
26961
  this.currentMessages = messages;
@@ -26975,9 +26976,9 @@ class TransportManager {
26975
26976
  }
26976
26977
  if (plugin) {
26977
26978
  this.plugin = plugin;
26978
- Log$c.debug('set transport plugin: ', this.plugin);
26979
+ Log$d.debug('set transport plugin: ', this.plugin);
26979
26980
  }
26980
- Log$c.debug('set transport: ', this.transport.name, this.transport.version, this.transport.configured);
26981
+ Log$d.debug('set transport: ', this.transport.name, this.transport.version, this.transport.configured);
26981
26982
  }
26982
26983
  static getTransport() {
26983
26984
  return this.transport;
@@ -27065,7 +27066,7 @@ const cancelDeviceWithInitialize = (device) => {
27065
27066
  },
27066
27067
  }));
27067
27068
  };
27068
- const Log$b = getLogger(exports.LoggerNames.DeviceCommands);
27069
+ const Log$c = getLogger(exports.LoggerNames.DeviceCommands);
27069
27070
  const LogCore = getLogger(exports.LoggerNames.Core);
27070
27071
  class DeviceCommands {
27071
27072
  constructor(device, mainId) {
@@ -27074,7 +27075,7 @@ class DeviceCommands {
27074
27075
  this.transport = TransportManager.getTransport();
27075
27076
  this.disposed = false;
27076
27077
  this.instanceId = generateInstanceId('DeviceCommands', device.sdkInstanceId);
27077
- Log$b.debug(`[DeviceCommands] Created: ${this.instanceId}, device: ${this.device.instanceId}`);
27078
+ Log$c.debug(`[DeviceCommands] Created: ${this.instanceId}, device: ${this.device.instanceId}`);
27078
27079
  }
27079
27080
  dispose(_cancelRequest) {
27080
27081
  var _a, _b;
@@ -27142,7 +27143,7 @@ class DeviceCommands {
27142
27143
  call(type, msg = {}) {
27143
27144
  var _a;
27144
27145
  return __awaiter(this, void 0, void 0, function* () {
27145
- Log$b.debug('[DeviceCommands] [call] Sending', type);
27146
+ Log$c.debug('[DeviceCommands] [call] Sending', type);
27146
27147
  try {
27147
27148
  const promise = this.transport.call(this.mainId, type, msg);
27148
27149
  this.callPromise = promise;
@@ -27176,7 +27177,7 @@ class DeviceCommands {
27176
27177
  }
27177
27178
  }
27178
27179
  if (responseData) {
27179
- Log$b.debug('error response', responseData);
27180
+ Log$c.debug('error response', responseData);
27180
27181
  }
27181
27182
  if (responseError === 'device disconnected during action') {
27182
27183
  return { type: 'BridgeDeviceDisconnected', message: { error: responseError } };
@@ -27207,7 +27208,7 @@ class DeviceCommands {
27207
27208
  'BixinPinInputOnDevice',
27208
27209
  ];
27209
27210
  if (!skipTypes.includes(type) && msg) {
27210
- Log$b.debug('[DeviceCommands] [typedCall] Sending payload', type, msg);
27211
+ Log$c.debug('[DeviceCommands] [typedCall] Sending payload', type, msg);
27211
27212
  }
27212
27213
  }
27213
27214
  catch (e) {
@@ -27217,7 +27218,7 @@ class DeviceCommands {
27217
27218
  assertType(response, resType);
27218
27219
  }
27219
27220
  catch (error) {
27220
- Log$b.debug('DeviceCommands typedcall error: ', error);
27221
+ Log$c.debug('DeviceCommands typedcall error: ', error);
27221
27222
  if (error instanceof hdShared.HardwareError) {
27222
27223
  if (error.errorCode === hdShared.HardwareErrorCode.ResponseUnexpectTypeError) {
27223
27224
  if (error.message.indexOf('BridgeNetworkError') > -1) {
@@ -27248,10 +27249,10 @@ class DeviceCommands {
27248
27249
  _filterCommonTypes(res, callType) {
27249
27250
  try {
27250
27251
  if (DataManager.getSettings('env') === 'react-native') {
27251
- Log$b.debug('_filterCommonTypes: ', JSON.stringify(res));
27252
+ Log$c.debug('_filterCommonTypes: ', JSON.stringify(res));
27252
27253
  }
27253
27254
  else {
27254
- Log$b.debug('_filterCommonTypes: ', res);
27255
+ Log$c.debug('_filterCommonTypes: ', res);
27255
27256
  }
27256
27257
  }
27257
27258
  catch (error) {
@@ -27380,7 +27381,7 @@ class DeviceCommands {
27380
27381
  reject(error);
27381
27382
  });
27382
27383
  const listenerCount = this.device.listenerCount(DEVICE.PIN);
27383
- Log$b.debug(`[${this.instanceId}] _promptPin called`, {
27384
+ Log$c.debug(`[${this.instanceId}] _promptPin called`, {
27384
27385
  responseID: this.currentResponseID,
27385
27386
  deviceInstanceId: this.device.instanceId,
27386
27387
  listenerCount,
@@ -27452,7 +27453,7 @@ const parseRunOptions = (options) => {
27452
27453
  options = {};
27453
27454
  return options;
27454
27455
  };
27455
- const Log$a = getLogger(exports.LoggerNames.Device);
27456
+ const Log$b = getLogger(exports.LoggerNames.Device);
27456
27457
  const deviceSessionCache = {};
27457
27458
  function preloadSessionCache(deviceId, passphraseState, sessionId) {
27458
27459
  const key = `${deviceId}@${passphraseState}`;
@@ -27476,7 +27477,7 @@ class Device extends events.exports {
27476
27477
  this.sdkInstanceId = sdkInstanceId;
27477
27478
  this.instanceId = generateInstanceId('Device', this.sdkInstanceId);
27478
27479
  this.createdAt = Date.now();
27479
- Log$a.debug(`[Device] Created: ${this.instanceId}${this.sdkInstanceId ? ` for SDK: ${this.sdkInstanceId}` : ''}`);
27480
+ Log$b.debug(`[Device] Created: ${this.instanceId}${this.sdkInstanceId ? ` for SDK: ${this.sdkInstanceId}` : ''}`);
27480
27481
  }
27481
27482
  static fromDescriptor(originalDescriptor, sdkInstanceId) {
27482
27483
  const descriptor = Object.assign({}, originalDescriptor);
@@ -27549,11 +27550,11 @@ class Device extends events.exports {
27549
27550
  if (DataManager.isBleConnect(env)) {
27550
27551
  const res = yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.originalDescriptor.id));
27551
27552
  this.mainId = (_b = res.uuid) !== null && _b !== void 0 ? _b : '';
27552
- Log$a.debug('Expected uuid:', this.mainId);
27553
+ Log$b.debug('Expected uuid:', this.mainId);
27553
27554
  }
27554
27555
  else {
27555
27556
  this.mainId = yield ((_c = this.deviceConnector) === null || _c === void 0 ? void 0 : _c.acquire(this.originalDescriptor.path, this.originalDescriptor.session));
27556
- Log$a.debug('Expected session id:', this.mainId);
27557
+ Log$b.debug('Expected session id:', this.mainId);
27557
27558
  }
27558
27559
  this.deviceAcquired = true;
27559
27560
  this.updateDescriptor({ [mainIdKey]: this.mainId });
@@ -27581,11 +27582,11 @@ class Device extends events.exports {
27581
27582
  (this.mainId && DataManager.isBleConnect(env))) {
27582
27583
  if (this.pendingCallbackPromise) {
27583
27584
  try {
27584
- Log$a.debug('Waiting for callback tasks to complete before releasing device (in release method)');
27585
+ Log$b.debug('Waiting for callback tasks to complete before releasing device (in release method)');
27585
27586
  yield this.pendingCallbackPromise.promise;
27586
27587
  }
27587
27588
  catch (error) {
27588
- Log$a.error('Error waiting for callback tasks in release method:', error);
27589
+ Log$b.error('Error waiting for callback tasks in release method:', error);
27589
27590
  }
27590
27591
  }
27591
27592
  if (this.commands) {
@@ -27604,7 +27605,7 @@ class Device extends events.exports {
27604
27605
  this.updateDescriptor({ session: null });
27605
27606
  }
27606
27607
  catch (err) {
27607
- Log$a.error('[Device] release error: ', err);
27608
+ Log$b.error('[Device] release error: ', err);
27608
27609
  }
27609
27610
  finally {
27610
27611
  this.needReloadDevice = true;
@@ -27613,6 +27614,50 @@ class Device extends events.exports {
27613
27614
  this.deviceAcquired = false;
27614
27615
  });
27615
27616
  }
27617
+ preInitialize(initOptions) {
27618
+ return __awaiter(this, void 0, void 0, function* () {
27619
+ if (!this.features) {
27620
+ yield this.acquire();
27621
+ yield this.initialize(initOptions);
27622
+ }
27623
+ this.markPreInitialized({
27624
+ passphraseState: initOptions === null || initOptions === void 0 ? void 0 : initOptions.passphraseState,
27625
+ deviceId: initOptions === null || initOptions === void 0 ? void 0 : initOptions.deviceId,
27626
+ });
27627
+ });
27628
+ }
27629
+ markPreInitialized(meta) {
27630
+ this.preInitializedAt = Date.now();
27631
+ this.preInitializeMeta = meta
27632
+ ? {
27633
+ passphraseState: meta.passphraseState === '' ? undefined : meta.passphraseState,
27634
+ deviceId: meta.deviceId === '' ? undefined : meta.deviceId,
27635
+ }
27636
+ : undefined;
27637
+ }
27638
+ clearPreInitialized() {
27639
+ this.preInitializedAt = undefined;
27640
+ this.preInitializeMeta = undefined;
27641
+ }
27642
+ isPreInitializeMetaMatch(payload) {
27643
+ if (!this.preInitializeMeta)
27644
+ return true;
27645
+ const passphraseState = (payload === null || payload === void 0 ? void 0 : payload.passphraseState) === '' ? undefined : payload === null || payload === void 0 ? void 0 : payload.passphraseState;
27646
+ const deviceId = (payload === null || payload === void 0 ? void 0 : payload.deviceId) === '' ? undefined : payload === null || payload === void 0 ? void 0 : payload.deviceId;
27647
+ return (this.preInitializeMeta.passphraseState === passphraseState &&
27648
+ this.preInitializeMeta.deviceId === deviceId);
27649
+ }
27650
+ isPreInitializedValid(ttlMs) {
27651
+ if (!this.preInitializedAt)
27652
+ return false;
27653
+ return Date.now() - this.preInitializedAt <= ttlMs;
27654
+ }
27655
+ setLastInitializeDuration(durationMs) {
27656
+ this.lastInitializeDurationMs = durationMs;
27657
+ }
27658
+ getLastInitializeDuration() {
27659
+ return this.lastInitializeDurationMs;
27660
+ }
27616
27661
  getCommands() {
27617
27662
  return this.commands;
27618
27663
  }
@@ -27624,8 +27669,8 @@ class Device extends events.exports {
27624
27669
  }
27625
27670
  getInternalState(_deviceId) {
27626
27671
  var _a, _b;
27627
- Log$a.debug('getInternalState session cache: ', deviceSessionCache);
27628
- Log$a.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}`);
27672
+ Log$b.debug('getInternalState session cache: ', deviceSessionCache);
27673
+ Log$b.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}`);
27629
27674
  const deviceId = _deviceId || ((_b = this.features) === null || _b === void 0 ? void 0 : _b.device_id);
27630
27675
  if (!deviceId)
27631
27676
  return undefined;
@@ -27635,7 +27680,7 @@ class Device extends events.exports {
27635
27680
  return deviceSessionCache[usePassKey];
27636
27681
  }
27637
27682
  updateInternalState(enablePassphrase, passphraseState, deviceId, sessionId = null, featuresSessionId = null) {
27638
- Log$a.debug('updateInternalState session param: ', `device_id: ${deviceId}`, `enablePassphrase: ${enablePassphrase}`, `passphraseState: ${passphraseState}`, `sessionId: ${sessionId}`, `featuresSessionId: ${featuresSessionId}`);
27683
+ Log$b.debug('updateInternalState session param: ', `device_id: ${deviceId}`, `enablePassphrase: ${enablePassphrase}`, `passphraseState: ${passphraseState}`, `sessionId: ${sessionId}`, `featuresSessionId: ${featuresSessionId}`);
27639
27684
  if (enablePassphrase) {
27640
27685
  if (sessionId) {
27641
27686
  deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = sessionId;
@@ -27648,11 +27693,11 @@ class Device extends events.exports {
27648
27693
  if (deviceSessionCache[oldKey]) {
27649
27694
  delete deviceSessionCache[oldKey];
27650
27695
  }
27651
- Log$a.debug('updateInternalState session cache: ', deviceSessionCache);
27696
+ Log$b.debug('updateInternalState session cache: ', deviceSessionCache);
27652
27697
  }
27653
27698
  setInternalState(state, initSession) {
27654
27699
  var _a, _b;
27655
- Log$a.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}`);
27700
+ Log$b.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}`);
27656
27701
  if (!this.features)
27657
27702
  return;
27658
27703
  if (!this.passphraseState && !initSession)
@@ -27664,11 +27709,11 @@ class Device extends events.exports {
27664
27709
  if (state) {
27665
27710
  deviceSessionCache[key] = state;
27666
27711
  }
27667
- Log$a.debug('setInternalState done session cache: ', deviceSessionCache);
27712
+ Log$b.debug('setInternalState done session cache: ', deviceSessionCache);
27668
27713
  }
27669
27714
  clearInternalState(_deviceId) {
27670
27715
  var _a;
27671
- Log$a.debug('clearInternalState param: ', _deviceId);
27716
+ Log$b.debug('clearInternalState param: ', _deviceId);
27672
27717
  const deviceId = _deviceId || ((_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id);
27673
27718
  if (!deviceId)
27674
27719
  return;
@@ -27695,12 +27740,7 @@ class Device extends events.exports {
27695
27740
  }
27696
27741
  payload.passphrase_state = options === null || options === void 0 ? void 0 : options.passphraseState;
27697
27742
  payload.is_contains_attach = true;
27698
- Log$a.debug('Initialize device begin:', {
27699
- deviceId: options === null || options === void 0 ? void 0 : options.deviceId,
27700
- passphraseState: options === null || options === void 0 ? void 0 : options.passphraseState,
27701
- initSession: options === null || options === void 0 ? void 0 : options.initSession,
27702
- InitializePayload: payload,
27703
- });
27743
+ const initStartAt = Date.now();
27704
27744
  try {
27705
27745
  const { message } = yield Promise.race([
27706
27746
  this.commands.typedCall('Initialize', 'Features', payload),
@@ -27710,12 +27750,13 @@ class Device extends events.exports {
27710
27750
  }, 25 * 1000);
27711
27751
  }),
27712
27752
  ]);
27713
- Log$a.debug('Initialize device end: ', message);
27753
+ const initCostMs = Date.now() - initStartAt;
27754
+ this.setLastInitializeDuration(initCostMs);
27714
27755
  this._updateFeatures(message, options === null || options === void 0 ? void 0 : options.initSession);
27715
27756
  yield TransportManager.reconfigure(this.features);
27716
27757
  }
27717
27758
  catch (error) {
27718
- Log$a.error('Initialization failed:', error);
27759
+ Log$b.error('Initialization failed:', error);
27719
27760
  throw error;
27720
27761
  }
27721
27762
  });
@@ -27766,7 +27807,7 @@ class Device extends events.exports {
27766
27807
  return __awaiter(this, void 0, void 0, function* () {
27767
27808
  if (this.runPromise) {
27768
27809
  yield this.interruptionFromOutside();
27769
- Log$a.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
27810
+ Log$b.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
27770
27811
  }
27771
27812
  options = parseRunOptions(options);
27772
27813
  this.runPromise = hdShared.createDeferred(this._runInner.bind(this, fn, options));
@@ -27788,7 +27829,9 @@ class Device extends events.exports {
27788
27829
  }
27789
27830
  try {
27790
27831
  if (fn) {
27791
- yield this.initialize(options);
27832
+ if (!(options === null || options === void 0 ? void 0 : options.skipInitialize)) {
27833
+ yield this.initialize(options);
27834
+ }
27792
27835
  }
27793
27836
  }
27794
27837
  catch (error) {
@@ -27822,7 +27865,7 @@ class Device extends events.exports {
27822
27865
  yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.disconnect(this.mainId));
27823
27866
  }
27824
27867
  yield this.release();
27825
- Log$a.debug(`error code ${e.errorCode} release device, mainId: ${this.mainId}`);
27868
+ Log$b.debug(`error code ${e.errorCode} release device, mainId: ${this.mainId}`);
27826
27869
  }
27827
27870
  this.runPromise = null;
27828
27871
  return;
@@ -27832,7 +27875,7 @@ class Device extends events.exports {
27832
27875
  options.keepSession === false) {
27833
27876
  this.keepSession = false;
27834
27877
  yield this.release();
27835
- Log$a.debug('release device, mainId: ', this.mainId);
27878
+ Log$b.debug('release device, mainId: ', this.mainId);
27836
27879
  }
27837
27880
  if (this.runPromise) {
27838
27881
  this.runPromise.resolve();
@@ -27865,7 +27908,7 @@ class Device extends events.exports {
27865
27908
  setCancelableAction(callback) {
27866
27909
  this.cancelableAction = (e) => callback(e)
27867
27910
  .catch(e2 => {
27868
- Log$a.debug('cancelableAction error', e2);
27911
+ Log$b.debug('cancelableAction error', e2);
27869
27912
  })
27870
27913
  .finally(() => {
27871
27914
  this.clearCancelableAction();
@@ -28020,7 +28063,7 @@ class Device extends events.exports {
28020
28063
  }
28021
28064
  const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
28022
28065
  const useErrorAttachPin = unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
28023
- Log$a.debug('Check passphrase state safety: ', {
28066
+ Log$b.debug('Check passphrase state safety: ', {
28024
28067
  passphraseState,
28025
28068
  newPassphraseState,
28026
28069
  unlockedAttachPin,
@@ -28068,6 +28111,27 @@ class DeviceList extends events.exports {
28068
28111
  }
28069
28112
  }
28070
28113
 
28114
+ class PollingStateManager {
28115
+ constructor() {
28116
+ this.activePolls = new Map();
28117
+ }
28118
+ start(connectId) {
28119
+ var _a;
28120
+ const currentId = ((_a = this.activePolls.get(connectId)) !== null && _a !== void 0 ? _a : 0) + 1;
28121
+ this.activePolls.set(connectId, currentId);
28122
+ return currentId;
28123
+ }
28124
+ isActive(connectId, pollingId) {
28125
+ return this.activePolls.get(connectId) === pollingId;
28126
+ }
28127
+ stop(connectId) {
28128
+ this.activePolls.delete(connectId);
28129
+ }
28130
+ stopAll() {
28131
+ this.activePolls.clear();
28132
+ }
28133
+ }
28134
+
28071
28135
  const getFirmwareReleaseInfo = (features, firmwareType) => {
28072
28136
  const firmwareStatus = DataManager.getFirmwareStatus(features, firmwareType);
28073
28137
  const changelog = DataManager.getFirmwareChangelog(features, firmwareType);
@@ -28120,7 +28184,7 @@ const getBootloaderReleaseInfo = ({ features, willUpdateFirmwareVersion, firmwar
28120
28184
  };
28121
28185
  };
28122
28186
 
28123
- const Log$9 = getLogger(exports.LoggerNames.Method);
28187
+ const Log$a = getLogger(exports.LoggerNames.Method);
28124
28188
  const isEvmLedgerLegacyPathWithHighIndex = (path) => {
28125
28189
  let addressN;
28126
28190
  if (typeof path === 'string') {
@@ -28144,11 +28208,24 @@ const isEvmLedgerLegacyPathWithHighIndex = (path) => {
28144
28208
  };
28145
28209
  const EVM_LEDGER_LEGACY_METHODS = ['evmGetAddress', 'evmGetPublicKey'];
28146
28210
  class BaseMethod {
28211
+ getPreWarmKey() {
28212
+ var _a, _b, _c, _d, _e;
28213
+ const payload = ((_a = this.payload) !== null && _a !== void 0 ? _a : {});
28214
+ return [
28215
+ (_c = (_b = this.connectId) !== null && _b !== void 0 ? _b : payload.connectId) !== null && _c !== void 0 ? _c : '',
28216
+ (_d = payload.passphraseState) !== null && _d !== void 0 ? _d : '',
28217
+ (_e = payload.deviceId) !== null && _e !== void 0 ? _e : '',
28218
+ this.name,
28219
+ ].join('|');
28220
+ }
28147
28221
  constructor(message) {
28148
28222
  this.shouldEnsureConnected = true;
28149
28223
  this.checkDeviceId = false;
28150
28224
  this.useDevicePassphraseState = true;
28151
28225
  this.skipForceUpdateCheck = false;
28226
+ this.allowUsePreInitialize = false;
28227
+ this.isPreWarmSignal = false;
28228
+ this.preWarmTtl = 60 * 1000;
28152
28229
  this.strictCheckDeviceSupport = false;
28153
28230
  this.temporarySafetyCheckPrompted = false;
28154
28231
  this.postPreviousAddressMessage = (data) => {
@@ -28173,7 +28250,7 @@ class BaseMethod {
28173
28250
  setContext(context) {
28174
28251
  this.sdkInstanceId = context.sdkInstanceId;
28175
28252
  this.instanceId = generateInstanceId('Method', this.sdkInstanceId);
28176
- Log$9.debug(`[BaseMethod] Created: ${this.instanceId}, method: ${this.name}, SDK: ${this.sdkInstanceId}`);
28253
+ Log$a.debug(`[BaseMethod] Created: ${this.instanceId}, method: ${this.name}, SDK: ${this.sdkInstanceId}`);
28177
28254
  }
28178
28255
  setDevice(device) {
28179
28256
  var _a, _b;
@@ -28193,7 +28270,7 @@ class BaseMethod {
28193
28270
  if (device.commands) {
28194
28271
  device.commands.currentResponseID = this.responseID;
28195
28272
  }
28196
- Log$9.debug(`[${this.instanceId}] setDevice: ${device.instanceId}, commands: ${(_b = device.commands) === null || _b === void 0 ? void 0 : _b.instanceId}`);
28273
+ Log$a.debug(`[${this.instanceId}] setDevice: ${device.instanceId}, commands: ${(_b = device.commands) === null || _b === void 0 ? void 0 : _b.instanceId}`);
28197
28274
  }
28198
28275
  checkFirmwareRelease() {
28199
28276
  if (!this.device || !this.device.features)
@@ -28266,7 +28343,7 @@ class BaseMethod {
28266
28343
  checkFlag = true;
28267
28344
  }
28268
28345
  if (checkFlag && ((_c = this.device.features) === null || _c === void 0 ? void 0 : _c.safety_checks) === 'Strict') {
28269
- Log$9.debug('will change safety_checks level');
28346
+ Log$a.debug('will change safety_checks level');
28270
28347
  yield this.device.commands.typedCall('ApplySettings', 'Success', {
28271
28348
  safety_checks: 'PromptTemporarily',
28272
28349
  });
@@ -28300,6 +28377,37 @@ class TestInitializeDeviceDuration extends BaseMethod {
28300
28377
  }
28301
28378
  }
28302
28379
 
28380
+ const Log$9 = getLogger(exports.LoggerNames.Core);
28381
+ const parseInitOptions$1 = (payload) => ({
28382
+ initSession: payload === null || payload === void 0 ? void 0 : payload.initSession,
28383
+ passphraseState: payload === null || payload === void 0 ? void 0 : payload.passphraseState,
28384
+ deviceId: payload === null || payload === void 0 ? void 0 : payload.deviceId,
28385
+ deriveCardano: payload === null || payload === void 0 ? void 0 : payload.deriveCardano,
28386
+ });
28387
+ class PreInitialize extends BaseMethod {
28388
+ init() {
28389
+ this.skipForceUpdateCheck = true;
28390
+ this.useDevicePassphraseState = false;
28391
+ this.isPreWarmSignal = true;
28392
+ }
28393
+ run() {
28394
+ return __awaiter(this, void 0, void 0, function* () {
28395
+ try {
28396
+ yield this.device.preInitialize(parseInitOptions$1(this.payload));
28397
+ if (this.device.hasDeviceAcquire()) {
28398
+ yield this.device.release();
28399
+ }
28400
+ return true;
28401
+ }
28402
+ catch (_a) {
28403
+ this.device.clearPreInitialized();
28404
+ Log$9.debug('[PRE-INIT][FAILED]');
28405
+ return false;
28406
+ }
28407
+ });
28408
+ }
28409
+ }
28410
+
28303
28411
  class SearchDevices extends BaseMethod {
28304
28412
  init() {
28305
28413
  this.useDevice = false;
@@ -32378,6 +32486,7 @@ class BTCSignMessage extends BaseMethod {
32378
32486
  init() {
32379
32487
  this.checkDeviceId = true;
32380
32488
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
32489
+ this.allowUsePreInitialize = true;
32381
32490
  validateParams(this.payload, [
32382
32491
  { name: 'path', required: true },
32383
32492
  { name: 'messageHex', type: 'hexString', required: true },
@@ -32434,6 +32543,7 @@ class BTCSignPsbt extends BaseMethod {
32434
32543
  init() {
32435
32544
  this.checkDeviceId = true;
32436
32545
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
32546
+ this.allowUsePreInitialize = true;
32437
32547
  validateParams(this.payload, [
32438
32548
  { name: 'psbt', type: 'hexString', required: true },
32439
32549
  { name: 'coin', type: 'string' },
@@ -32752,6 +32862,7 @@ class BTCSignTransaction extends BaseMethod {
32752
32862
  init() {
32753
32863
  this.checkDeviceId = true;
32754
32864
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
32865
+ this.allowUsePreInitialize = true;
32755
32866
  validateParams(this.payload, [
32756
32867
  { name: 'coin', type: 'string', required: true },
32757
32868
  { name: 'inputs', type: 'array', required: true },
@@ -32932,6 +33043,7 @@ class ConfluxGetAddress extends BaseMethod {
32932
33043
  class ConfluxSignMessage extends BaseMethod {
32933
33044
  init() {
32934
33045
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
33046
+ this.allowUsePreInitialize = true;
32935
33047
  validateParams(this.payload, [
32936
33048
  { name: 'path', required: true },
32937
33049
  { name: 'messageHex', type: 'hexString', required: true },
@@ -32961,6 +33073,7 @@ class ConfluxSignMessage extends BaseMethod {
32961
33073
  class ConfluxSignMessageCIP23 extends BaseMethod {
32962
33074
  init() {
32963
33075
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
33076
+ this.allowUsePreInitialize = true;
32964
33077
  validateParams(this.payload, [
32965
33078
  { name: 'path', required: true },
32966
33079
  { name: 'domainHash', type: 'hexString', required: true },
@@ -33046,6 +33159,7 @@ class ConfluxSignTransaction extends BaseMethod {
33046
33159
  }
33047
33160
  init() {
33048
33161
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
33162
+ this.allowUsePreInitialize = true;
33049
33163
  validateParams(this.payload, [
33050
33164
  { name: 'path', required: true },
33051
33165
  { name: 'transaction', type: 'object', required: true },
@@ -33289,10 +33403,12 @@ class EVMSignMessage$2 extends BaseMethod {
33289
33403
  init() {
33290
33404
  this.checkDeviceId = true;
33291
33405
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
33406
+ this.allowUsePreInitialize = true;
33292
33407
  validateParams(this.payload, [
33293
33408
  { name: 'path', required: true },
33294
33409
  { name: 'messageHex', type: 'hexString', required: true },
33295
33410
  { name: 'chainId', type: 'number' },
33411
+ { name: 'usePreInitialize', type: 'boolean' },
33296
33412
  ]);
33297
33413
  const { path, messageHex, chainId } = this.payload;
33298
33414
  const addressN = validatePath(path, 3);
@@ -33322,6 +33438,7 @@ class EVMSignMessageEIP712 extends BaseMethod {
33322
33438
  init() {
33323
33439
  this.checkDeviceId = true;
33324
33440
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
33441
+ this.allowUsePreInitialize = true;
33325
33442
  validateParams(this.payload, [
33326
33443
  { name: 'path', required: true },
33327
33444
  { name: 'domainHash', type: 'hexString', required: true },
@@ -33555,9 +33672,11 @@ class EVMSignTransaction extends BaseMethod {
33555
33672
  init() {
33556
33673
  this.checkDeviceId = true;
33557
33674
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
33675
+ this.allowUsePreInitialize = true;
33558
33676
  validateParams(this.payload, [
33559
33677
  { name: 'path', required: true },
33560
33678
  { name: 'transaction', type: 'object', required: true },
33679
+ { name: 'usePreInitialize', type: 'boolean' },
33561
33680
  ]);
33562
33681
  const { path, transaction } = this.payload;
33563
33682
  this.addressN = validatePath(path, 3);
@@ -33824,6 +33943,7 @@ class EVMSignTypedData extends BaseMethod {
33824
33943
  init() {
33825
33944
  this.checkDeviceId = true;
33826
33945
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
33946
+ this.allowUsePreInitialize = true;
33827
33947
  validateParams(this.payload, [
33828
33948
  { name: 'path', required: true },
33829
33949
  { name: 'metamaskV4Compat', type: 'boolean' },
@@ -33831,6 +33951,7 @@ class EVMSignTypedData extends BaseMethod {
33831
33951
  { name: 'domainHash', type: 'hexString' },
33832
33952
  { name: 'messageHash', type: 'hexString' },
33833
33953
  { name: 'chainId', type: 'number' },
33954
+ { name: 'usePreInitialize', type: 'boolean' },
33834
33955
  ]);
33835
33956
  const { path, data, metamaskV4Compat, domainHash, messageHash, chainId } = this.payload;
33836
33957
  const addressN = validatePath(path, 3);
@@ -34377,6 +34498,7 @@ class StarcoinSignMessage extends BaseMethod {
34377
34498
  init() {
34378
34499
  this.checkDeviceId = true;
34379
34500
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
34501
+ this.allowUsePreInitialize = true;
34380
34502
  validateParams(this.payload, [
34381
34503
  { name: 'path', required: true },
34382
34504
  { name: 'messageHex', type: 'hexString', required: true },
@@ -34400,6 +34522,7 @@ class StarcoinSignTransaction extends BaseMethod {
34400
34522
  init() {
34401
34523
  this.checkDeviceId = true;
34402
34524
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
34525
+ this.allowUsePreInitialize = true;
34403
34526
  validateParams(this.payload, [
34404
34527
  { name: 'path', required: true },
34405
34528
  { name: 'rawTx', type: 'hexString', required: true },
@@ -34668,6 +34791,7 @@ class NEMSignTransaction extends BaseMethod {
34668
34791
  init() {
34669
34792
  this.checkDeviceId = true;
34670
34793
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
34794
+ this.allowUsePreInitialize = true;
34671
34795
  validateParams(this.payload, [
34672
34796
  { name: 'path', required: true },
34673
34797
  { name: 'transaction', type: 'object', required: true },
@@ -34742,6 +34866,7 @@ class SolSignTransaction extends BaseMethod {
34742
34866
  var _a;
34743
34867
  this.checkDeviceId = true;
34744
34868
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
34869
+ this.allowUsePreInitialize = true;
34745
34870
  this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
34746
34871
  const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
34747
34872
  validateParams(payload, [{ name: 'bundle', type: 'array' }]);
@@ -34819,6 +34944,7 @@ class SolSignOffchainMessage extends BaseMethod {
34819
34944
  init() {
34820
34945
  this.checkDeviceId = true;
34821
34946
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
34947
+ this.allowUsePreInitialize = true;
34822
34948
  validateParams(this.payload, [
34823
34949
  { name: 'path', required: true },
34824
34950
  { name: 'messageHex', type: 'hexString', required: true },
@@ -34861,6 +34987,7 @@ class SolSignMessage extends BaseMethod {
34861
34987
  init() {
34862
34988
  this.checkDeviceId = true;
34863
34989
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
34990
+ this.allowUsePreInitialize = true;
34864
34991
  validateParams(this.payload, [
34865
34992
  { name: 'path', required: true },
34866
34993
  { name: 'messageHex', type: 'hexString', required: true },
@@ -35162,6 +35289,7 @@ class StellarSignTransaction extends BaseMethod {
35162
35289
  init() {
35163
35290
  this.checkDeviceId = true;
35164
35291
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
35292
+ this.allowUsePreInitialize = true;
35165
35293
  validateParams(this.payload, [
35166
35294
  { name: 'path', required: true },
35167
35295
  { name: 'networkPassphrase', type: 'string', required: true },
@@ -35271,6 +35399,7 @@ class TronSignMessage extends BaseMethod {
35271
35399
  init() {
35272
35400
  this.checkDeviceId = true;
35273
35401
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
35402
+ this.allowUsePreInitialize = true;
35274
35403
  validateParams(this.payload, [
35275
35404
  { name: 'path', required: true },
35276
35405
  { name: 'messageHex', type: 'hexString', required: true },
@@ -35425,6 +35554,7 @@ class TronSignTransaction extends BaseMethod {
35425
35554
  init() {
35426
35555
  this.checkDeviceId = true;
35427
35556
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
35557
+ this.allowUsePreInitialize = true;
35428
35558
  validateParams(this.payload, [
35429
35559
  { name: 'path', required: true },
35430
35560
  { name: 'transaction', type: 'object', required: true },
@@ -35554,6 +35684,7 @@ class NearSignTransaction extends BaseMethod {
35554
35684
  init() {
35555
35685
  this.checkDeviceId = true;
35556
35686
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
35687
+ this.allowUsePreInitialize = true;
35557
35688
  validateParams(this.payload, [
35558
35689
  { name: 'path', required: true },
35559
35690
  { name: 'rawTx', type: 'hexString', required: true },
@@ -35730,6 +35861,7 @@ class AptosSignTransaction extends BaseMethod {
35730
35861
  init() {
35731
35862
  this.checkDeviceId = true;
35732
35863
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
35864
+ this.allowUsePreInitialize = true;
35733
35865
  validateParams(this.payload, [
35734
35866
  { name: 'path', required: true },
35735
35867
  { name: 'rawTx', type: 'hexString', required: true },
@@ -35780,6 +35912,7 @@ class AptosSignMessage extends BaseMethod {
35780
35912
  init() {
35781
35913
  this.checkDeviceId = true;
35782
35914
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
35915
+ this.allowUsePreInitialize = true;
35783
35916
  validateParams(this.payload, [
35784
35917
  { name: 'path', required: true },
35785
35918
  { name: 'payload', type: 'object', required: true },
@@ -35841,6 +35974,7 @@ class AptosSignInMessage extends BaseMethod {
35841
35974
  init() {
35842
35975
  this.checkDeviceId = true;
35843
35976
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
35977
+ this.allowUsePreInitialize = true;
35844
35978
  validateParams(this.payload, [
35845
35979
  { name: 'path', required: true },
35846
35980
  { name: 'payload', type: 'string', required: true },
@@ -35936,6 +36070,7 @@ class AlgoSignTransaction extends BaseMethod {
35936
36070
  init() {
35937
36071
  this.checkDeviceId = true;
35938
36072
  this.allowDeviceMode = [...this.allowDeviceMode];
36073
+ this.allowUsePreInitialize = true;
35939
36074
  validateParams(this.payload, [
35940
36075
  { name: 'path', required: true },
35941
36076
  { name: 'rawTx', type: 'hexString', required: true },
@@ -36098,6 +36233,7 @@ class CosmosSignTransaction extends BaseMethod {
36098
36233
  init() {
36099
36234
  this.checkDeviceId = true;
36100
36235
  this.allowDeviceMode = [...this.allowDeviceMode];
36236
+ this.allowUsePreInitialize = true;
36101
36237
  validateParams(this.payload, [
36102
36238
  { name: 'path', required: true },
36103
36239
  { name: 'rawTx', type: 'hexString', required: true },
@@ -36219,6 +36355,7 @@ class XrpGetAddress extends BaseMethod {
36219
36355
  init() {
36220
36356
  this.checkDeviceId = true;
36221
36357
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
36358
+ this.allowUsePreInitialize = true;
36222
36359
  const { payload } = this;
36223
36360
  validateParams(payload, [
36224
36361
  { name: 'path', required: true },
@@ -36439,6 +36576,7 @@ class SuiSignMessage extends BaseMethod {
36439
36576
  init() {
36440
36577
  this.checkDeviceId = true;
36441
36578
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
36579
+ this.allowUsePreInitialize = true;
36442
36580
  validateParams(this.payload, [
36443
36581
  { name: 'path', required: true },
36444
36582
  { name: 'messageHex', type: 'hexString', required: true },
@@ -36492,6 +36630,7 @@ class SuiSignTransaction extends BaseMethod {
36492
36630
  init() {
36493
36631
  this.checkDeviceId = true;
36494
36632
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
36633
+ this.allowUsePreInitialize = true;
36495
36634
  validateParams(this.payload, [
36496
36635
  { name: 'path', required: true },
36497
36636
  { name: 'rawTx', type: 'hexString', required: true },
@@ -37290,6 +37429,7 @@ class CardanoSignTransaction extends BaseMethod {
37290
37429
  var _a;
37291
37430
  this.checkDeviceId = true;
37292
37431
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
37432
+ this.allowUsePreInitialize = true;
37293
37433
  this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
37294
37434
  const { payload } = this;
37295
37435
  if (payload.auxiliaryData && payload.auxiliaryData.governanceRegistrationParameters) {
@@ -37525,6 +37665,7 @@ class CardanoSignMessage extends BaseMethod {
37525
37665
  init() {
37526
37666
  this.checkDeviceId = true;
37527
37667
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
37668
+ this.allowUsePreInitialize = true;
37528
37669
  const { payload } = this;
37529
37670
  validateParams(payload, [
37530
37671
  { name: 'path', type: 'string', required: true },
@@ -37638,6 +37779,7 @@ class FilecoinSignTransaction extends BaseMethod {
37638
37779
  init() {
37639
37780
  this.checkDeviceId = true;
37640
37781
  this.allowDeviceMode = [...this.allowDeviceMode];
37782
+ this.allowUsePreInitialize = true;
37641
37783
  validateParams(this.payload, [
37642
37784
  { name: 'path', required: true },
37643
37785
  { name: 'rawTx', type: 'hexString', required: true },
@@ -37808,6 +37950,7 @@ class PolkadotSignTransaction extends BaseMethod {
37808
37950
  init() {
37809
37951
  this.checkDeviceId = true;
37810
37952
  this.allowDeviceMode = [...this.allowDeviceMode];
37953
+ this.allowUsePreInitialize = true;
37811
37954
  validateParams(this.payload, [
37812
37955
  { name: 'path', required: true },
37813
37956
  { name: 'network', required: true },
@@ -38230,6 +38373,7 @@ class KaspaSignTransaction extends BaseMethod {
38230
38373
  var _a, _b, _c, _d, _e;
38231
38374
  this.checkDeviceId = true;
38232
38375
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
38376
+ this.allowUsePreInitialize = true;
38233
38377
  const payload = this.payload;
38234
38378
  validateParams(payload, [
38235
38379
  { name: 'version', type: 'number' },
@@ -38402,6 +38546,7 @@ class NexaSignTransaction extends BaseMethod {
38402
38546
  this.hasBundle = false;
38403
38547
  }
38404
38548
  init() {
38549
+ this.allowUsePreInitialize = true;
38405
38550
  const payload = this.payload;
38406
38551
  payload.inputs.forEach(input => {
38407
38552
  validateParams(input, [
@@ -38553,6 +38698,7 @@ class NostrSignEvent extends BaseMethod {
38553
38698
  init() {
38554
38699
  this.checkDeviceId = true;
38555
38700
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
38701
+ this.allowUsePreInitialize = true;
38556
38702
  const { payload } = this;
38557
38703
  if (!validateEvent(payload.event)) {
38558
38704
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Can't serialize event with wrong or missing properties`);
@@ -38695,6 +38841,7 @@ class NostrSignSchnorr extends BaseMethod {
38695
38841
  init() {
38696
38842
  this.checkDeviceId = true;
38697
38843
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
38844
+ this.allowUsePreInitialize = true;
38698
38845
  const { payload } = this;
38699
38846
  validateParams(payload, [
38700
38847
  { name: 'path', required: true },
@@ -38858,6 +39005,7 @@ class NervosSignTransaction extends BaseMethod {
38858
39005
  init() {
38859
39006
  this.checkDeviceId = true;
38860
39007
  this.allowDeviceMode = [...this.allowDeviceMode];
39008
+ this.allowUsePreInitialize = true;
38861
39009
  validateParams(this.payload, [
38862
39010
  { name: 'path', required: true },
38863
39011
  { name: 'rawTx', type: 'hexString', required: true },
@@ -38965,6 +39113,7 @@ class DnxSignTransaction extends BaseMethod {
38965
39113
  init() {
38966
39114
  this.checkDeviceId = true;
38967
39115
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
39116
+ this.allowUsePreInitialize = true;
38968
39117
  const { payload } = this;
38969
39118
  const addressN = validatePath(payload.path, 3);
38970
39119
  validateParams(payload, [
@@ -39146,6 +39295,7 @@ class TonSignMessage extends BaseMethod {
39146
39295
  this.strictCheckDeviceSupport = true;
39147
39296
  this.checkDeviceId = true;
39148
39297
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
39298
+ this.allowUsePreInitialize = true;
39149
39299
  validateParams(this.payload, [
39150
39300
  { name: 'path', required: true },
39151
39301
  { name: 'destination', type: 'string' },
@@ -39290,6 +39440,7 @@ class TonSignProof extends BaseMethod {
39290
39440
  this.strictCheckDeviceSupport = true;
39291
39441
  this.checkDeviceId = true;
39292
39442
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
39443
+ this.allowUsePreInitialize = true;
39293
39444
  validateParams(this.payload, [
39294
39445
  { name: 'path', required: true },
39295
39446
  { name: 'appdomain', type: 'string' },
@@ -39338,6 +39489,7 @@ class TonSignData extends BaseMethod {
39338
39489
  this.strictCheckDeviceSupport = false;
39339
39490
  this.checkDeviceId = true;
39340
39491
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
39492
+ this.allowUsePreInitialize = true;
39341
39493
  validateParams(this.payload, [
39342
39494
  { name: 'path', required: true },
39343
39495
  { name: 'type', type: 'number', required: true },
@@ -39454,6 +39606,7 @@ class ScdoSignTransaction extends BaseMethod {
39454
39606
  init() {
39455
39607
  this.checkDeviceId = true;
39456
39608
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
39609
+ this.allowUsePreInitialize = true;
39457
39610
  validateParams(this.payload, [
39458
39611
  { name: 'path', required: true },
39459
39612
  { name: 'nonce', required: true },
@@ -39507,6 +39660,7 @@ class ScdoSignMessage extends BaseMethod {
39507
39660
  init() {
39508
39661
  this.checkDeviceId = true;
39509
39662
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
39663
+ this.allowUsePreInitialize = true;
39510
39664
  validateParams(this.payload, [
39511
39665
  { name: 'path', required: true },
39512
39666
  { name: 'messageHex', type: 'hexString', required: true },
@@ -39629,6 +39783,7 @@ class AlephiumSignTransaction extends BaseMethod {
39629
39783
  init() {
39630
39784
  this.checkDeviceId = true;
39631
39785
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
39786
+ this.allowUsePreInitialize = true;
39632
39787
  validateParams(this.payload, [
39633
39788
  { name: 'path', required: true },
39634
39789
  { name: 'rawTx', required: true, type: 'hexString' },
@@ -39670,6 +39825,7 @@ class AlephiumSignMessage extends BaseMethod {
39670
39825
  init() {
39671
39826
  this.checkDeviceId = true;
39672
39827
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
39828
+ this.allowUsePreInitialize = true;
39673
39829
  validateParams(this.payload, [
39674
39830
  { name: 'path', required: true },
39675
39831
  { name: 'messageHex', type: 'hexString', required: true },
@@ -39875,6 +40031,7 @@ class BenfenSignMessage extends BaseMethod {
39875
40031
  init() {
39876
40032
  this.checkDeviceId = true;
39877
40033
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
40034
+ this.allowUsePreInitialize = true;
39878
40035
  validateParams(this.payload, [
39879
40036
  { name: 'path', required: true },
39880
40037
  { name: 'messageHex', type: 'hexString', required: true },
@@ -39928,6 +40085,7 @@ class BenfenSignTransaction extends BaseMethod {
39928
40085
  init() {
39929
40086
  this.checkDeviceId = true;
39930
40087
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
40088
+ this.allowUsePreInitialize = true;
39931
40089
  validateParams(this.payload, [
39932
40090
  { name: 'path', required: true },
39933
40091
  { name: 'rawTx', type: 'hexString', required: true },
@@ -40035,6 +40193,7 @@ class NeoSignTransaction extends BaseMethod {
40035
40193
  init() {
40036
40194
  this.checkDeviceId = true;
40037
40195
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
40196
+ this.allowUsePreInitialize = true;
40038
40197
  this.strictCheckDeviceSupport = true;
40039
40198
  validateParams(this.payload, [
40040
40199
  { name: 'path', required: true },
@@ -40079,6 +40238,7 @@ class NeoSignTransaction extends BaseMethod {
40079
40238
  var ApiMethods = /*#__PURE__*/Object.freeze({
40080
40239
  __proto__: null,
40081
40240
  testInitializeDeviceDuration: TestInitializeDeviceDuration,
40241
+ preInitialize: PreInitialize,
40082
40242
  searchDevices: SearchDevices,
40083
40243
  getFeatures: GetFeatures,
40084
40244
  getOnekeyFeatures: GetOnekeyFeatures,
@@ -40425,13 +40585,15 @@ class RequestQueue {
40425
40585
  this.pendingCallbackTasks.set(connectId, callbackPromise);
40426
40586
  callbackPromise.promise.finally(() => {
40427
40587
  Log$1.debug(`Callback task completed for connectId: ${connectId}`);
40428
- this.pendingCallbackTasks.delete(connectId);
40588
+ if (this.pendingCallbackTasks.get(connectId) === callbackPromise) {
40589
+ this.pendingCallbackTasks.delete(connectId);
40590
+ }
40429
40591
  });
40430
40592
  }
40431
- waitForPendingCallbackTasks(connectId) {
40593
+ waitForPendingCallbackTasks(connectId, exceptTask) {
40432
40594
  return __awaiter(this, void 0, void 0, function* () {
40433
40595
  const pendingTask = this.pendingCallbackTasks.get(connectId);
40434
- if (pendingTask) {
40596
+ if (pendingTask && pendingTask !== exceptTask) {
40435
40597
  Log$1.debug(`Waiting for pending callback task to complete for connectId: ${connectId}`);
40436
40598
  yield pendingTask.promise;
40437
40599
  }
@@ -40468,6 +40630,9 @@ const getSynchronize = (mutex) => {
40468
40630
  };
40469
40631
 
40470
40632
  const Log = getLogger(exports.LoggerNames.Core);
40633
+ const PRE_INITIALIZE_TTL_MS = 60 * 1000;
40634
+ const preWarmInflight = new Map();
40635
+ const preWarmDoneAt = new Map();
40471
40636
  function hasDeriveCardano(method) {
40472
40637
  var _a;
40473
40638
  if (method.name.startsWith('allNetworkGetAddress') &&
@@ -40489,8 +40654,7 @@ let _deviceList;
40489
40654
  let _connector;
40490
40655
  let _uiPromises = [];
40491
40656
  const deviceCacheMap = new Map();
40492
- let pollingId = 1;
40493
- const pollingState = {};
40657
+ const pollingManager = new PollingStateManager();
40494
40658
  let preConnectCache = {
40495
40659
  passphraseState: undefined,
40496
40660
  };
@@ -40567,8 +40731,41 @@ const callAPI = (context, message) => __awaiter(void 0, void 0, void 0, function
40567
40731
  if (error) {
40568
40732
  return createResponseMessage(method.responseID, false, { error });
40569
40733
  }
40734
+ if (method.isPreWarmSignal) {
40735
+ return handlePreWarmSignal(context, message, method);
40736
+ }
40570
40737
  return onCallDevice(context, message, method);
40571
40738
  });
40739
+ const handlePreWarmSignal = (context, message, method) => __awaiter(void 0, void 0, void 0, function* () {
40740
+ const key = method.getPreWarmKey();
40741
+ const inflight = preWarmInflight.get(key);
40742
+ if (inflight) {
40743
+ try {
40744
+ yield inflight;
40745
+ }
40746
+ catch (_b) {
40747
+ }
40748
+ return createResponseMessage(method.responseID, true, true);
40749
+ }
40750
+ const doneAt = preWarmDoneAt.get(key);
40751
+ if (typeof doneAt === 'number' && Date.now() - doneAt <= method.preWarmTtl) {
40752
+ return createResponseMessage(method.responseID, true, true);
40753
+ }
40754
+ const run = onCallDevice(context, message, method);
40755
+ preWarmInflight.set(key, run);
40756
+ try {
40757
+ const result = yield run;
40758
+ if ((result === null || result === void 0 ? void 0 : result.success) === true && (result === null || result === void 0 ? void 0 : result.payload) === true) {
40759
+ preWarmDoneAt.set(key, Date.now());
40760
+ }
40761
+ return result;
40762
+ }
40763
+ finally {
40764
+ if (preWarmInflight.get(key) === run) {
40765
+ preWarmInflight.delete(key);
40766
+ }
40767
+ }
40768
+ });
40572
40769
  const waitWithTimeout = (promise, timeout) => __awaiter(void 0, void 0, void 0, function* () {
40573
40770
  const timeoutPromise = new Promise((_, reject) => {
40574
40771
  setTimeout(() => reject(new Error('Request timeout')), timeout);
@@ -40589,11 +40786,13 @@ const waitForPendingPromise = (getPrePendingCallPromise, removePrePendingCallPro
40589
40786
  }
40590
40787
  });
40591
40788
  const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, void 0, function* () {
40592
- var _b, _c, _d, _e;
40789
+ var _c, _d, _e, _f, _g;
40593
40790
  let messageResponse;
40594
40791
  const { requestQueue, getPrePendingCallPromise, setPrePendingCallPromise } = context;
40595
40792
  updateMethodRequestContext(method, { status: 'running' });
40596
- const connectStateChange = preConnectCache.passphraseState !== method.payload.passphraseState;
40793
+ const normalizePassphraseState = (s) => s || '';
40794
+ const connectStateChange = normalizePassphraseState(preConnectCache.passphraseState) !==
40795
+ normalizePassphraseState(method.payload.passphraseState);
40597
40796
  preConnectCache = {
40598
40797
  passphraseState: method.payload.passphraseState,
40599
40798
  };
@@ -40606,15 +40805,19 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
40606
40805
  }
40607
40806
  yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
40608
40807
  const task = requestQueue.createTask(method);
40808
+ let preWarmCallbackTask;
40809
+ if (method.isPreWarmSignal && method.connectId) {
40810
+ preWarmCallbackTask = hdShared.createDeferred();
40811
+ context.registerCallbackTask(method.connectId, preWarmCallbackTask);
40812
+ }
40609
40813
  let device;
40610
40814
  try {
40611
- if (pollingState[pollingId]) {
40612
- pollingState[pollingId] = false;
40613
- }
40614
- pollingId += 1;
40615
- device = yield ensureConnected(context, method, pollingId, (_b = task.abortController) === null || _b === void 0 ? void 0 : _b.signal);
40815
+ const connectId = (_c = method.connectId) !== null && _c !== void 0 ? _c : '';
40816
+ const pollingId = pollingManager.start(connectId);
40817
+ device = yield ensureConnected(context, method, connectId, pollingId, (_d = task.abortController) === null || _d === void 0 ? void 0 : _d.signal);
40616
40818
  }
40617
40819
  catch (e) {
40820
+ preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
40618
40821
  console.log('ensureConnected error: ', e);
40619
40822
  completeMethodRequestContext(method, e);
40620
40823
  if (e.name === 'AbortError' || e.message === 'Request aborted') {
@@ -40626,16 +40829,17 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
40626
40829
  requestQueue.releaseTask(method.responseID);
40627
40830
  return createResponseMessage(method.responseID, false, { error: e });
40628
40831
  }
40629
- if ((_c = method.payload) === null || _c === void 0 ? void 0 : _c.onlyConnectBleDevice) {
40832
+ if ((_e = method.payload) === null || _e === void 0 ? void 0 : _e.onlyConnectBleDevice) {
40833
+ preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
40630
40834
  Log.debug('Call API - only connect ble device: ', device === null || device === void 0 ? void 0 : device.mainId);
40631
40835
  return createResponseMessage(method.responseID, true, null);
40632
40836
  }
40633
40837
  Log.debug('Call API - setDevice: ', device.mainId);
40634
- (_d = method.setDevice) === null || _d === void 0 ? void 0 : _d.call(method, device);
40838
+ (_f = method.setDevice) === null || _f === void 0 ? void 0 : _f.call(method, device);
40635
40839
  method.context = context;
40636
40840
  updateMethodRequestContext(method, {
40637
40841
  deviceInstanceId: device.instanceId,
40638
- commandsInstanceId: (_e = device.commands) === null || _e === void 0 ? void 0 : _e.instanceId,
40842
+ commandsInstanceId: (_g = device.commands) === null || _g === void 0 ? void 0 : _g.instanceId,
40639
40843
  });
40640
40844
  const activeRequests = getActiveRequestsByDeviceInstance(device.instanceId);
40641
40845
  if (activeRequests.length > 0) {
@@ -40650,11 +40854,11 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
40650
40854
  device.on(DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE, onSelectDeviceForSwitchFirmwareWebDeviceHandler);
40651
40855
  try {
40652
40856
  if (method.connectId) {
40653
- yield context.waitForCallbackTasks(method.connectId);
40857
+ yield context.waitForCallbackTasks(method.connectId, preWarmCallbackTask);
40654
40858
  }
40655
40859
  yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
40656
40860
  const inner = () => __awaiter(void 0, void 0, void 0, function* () {
40657
- var _f, _g, _h, _j, _k;
40861
+ var _h, _j, _k, _l, _m;
40658
40862
  const versionRange = getMethodVersionRange(device.features, type => method.getVersionRange()[type]);
40659
40863
  if (device.features) {
40660
40864
  yield DataManager.checkAndReloadData();
@@ -40741,7 +40945,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
40741
40945
  require: support.require,
40742
40946
  }));
40743
40947
  }
40744
- const passphraseStateSafety = yield device.checkPassphraseStateSafety((_f = method.payload) === null || _f === void 0 ? void 0 : _f.passphraseState, (_g = method.payload) === null || _g === void 0 ? void 0 : _g.useEmptyPassphrase, (_h = method.payload) === null || _h === void 0 ? void 0 : _h.skipPassphraseCheck);
40948
+ const passphraseStateSafety = yield device.checkPassphraseStateSafety((_h = method.payload) === null || _h === void 0 ? void 0 : _h.passphraseState, (_j = method.payload) === null || _j === void 0 ? void 0 : _j.useEmptyPassphrase, (_k = method.payload) === null || _k === void 0 ? void 0 : _k.skipPassphraseCheck);
40745
40949
  checkPassphraseEnableState(method, device.features);
40746
40950
  if (!passphraseStateSafety) {
40747
40951
  DevicePool.clearDeviceCache(method.payload.connectId);
@@ -40758,10 +40962,9 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
40758
40962
  : hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'open safety check failed.');
40759
40963
  throw error;
40760
40964
  }
40761
- (_k = (_j = method.device) === null || _j === void 0 ? void 0 : _j.commands) === null || _k === void 0 ? void 0 : _k.checkDisposed();
40965
+ (_m = (_l = method.device) === null || _l === void 0 ? void 0 : _l.commands) === null || _m === void 0 ? void 0 : _m.checkDisposed();
40762
40966
  try {
40763
40967
  const response = yield method.run();
40764
- Log.debug('Call API - Inner Method Run: ');
40765
40968
  messageResponse = createResponseMessage(method.responseID, true, response);
40766
40969
  requestQueue.resolveRequest(method.responseID, messageResponse);
40767
40970
  completeMethodRequestContext(method);
@@ -40778,7 +40981,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
40778
40981
  }
40779
40982
  });
40780
40983
  Log.debug('Call API - Device Run: ', device.mainId);
40781
- const runOptions = Object.assign({ keepSession: method.payload.keepSession }, parseInitOptions(method));
40984
+ const runOptions = Object.assign({ keepSession: method.payload.keepSession, skipInitialize: canSkipInitialize(method, device) }, parseInitOptions(method));
40782
40985
  const deviceRun = () => device.run(inner, runOptions);
40783
40986
  task.callPromise = hdShared.createDeferred(deviceRun);
40784
40987
  try {
@@ -40797,6 +41000,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
40797
41000
  completeMethodRequestContext(method, error);
40798
41001
  }
40799
41002
  finally {
41003
+ preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
40800
41004
  const response = messageResponse;
40801
41005
  if (response) {
40802
41006
  if (method) {
@@ -40891,8 +41095,29 @@ function initDeviceForBle(method) {
40891
41095
  device.deviceConnector = _connector;
40892
41096
  return device;
40893
41097
  }
40894
- let bleTimeoutRetry = 0;
40895
- function connectDeviceForBle(method, device) {
41098
+ function canSkipInitialize(method, device) {
41099
+ var _a;
41100
+ const reasons = [];
41101
+ if (!method.allowUsePreInitialize)
41102
+ reasons.push('method.disallow');
41103
+ if (!((_a = method.payload) === null || _a === void 0 ? void 0 : _a.usePreInitialize))
41104
+ reasons.push('payload.usePreInitialize=false');
41105
+ if (!device.isPreInitializeMetaMatch(method.payload))
41106
+ reasons.push('meta.mismatch');
41107
+ if (!device.features)
41108
+ reasons.push('features.missing');
41109
+ if (!device.isPreInitializedValid(PRE_INITIALIZE_TTL_MS))
41110
+ reasons.push('ttl.expired');
41111
+ if (reasons.length) {
41112
+ Log.debug(`[PRE-INIT][MISS] method=${method.name} ${reasons.join(',')}`);
41113
+ return false;
41114
+ }
41115
+ const savedMs = device.getLastInitializeDuration();
41116
+ const saved = typeof savedMs === 'number' ? `saved ${savedMs}ms` : 'within TTL + meta match';
41117
+ Log.debug(`[PRE-INIT][HIT] method=${method.name} skip Initialize (${saved})`);
41118
+ return true;
41119
+ }
41120
+ function connectDeviceForBle(method, device, retryCount = 0) {
40896
41121
  var _a;
40897
41122
  return __awaiter(this, void 0, void 0, function* () {
40898
41123
  try {
@@ -40900,14 +41125,21 @@ function connectDeviceForBle(method, device) {
40900
41125
  if ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.onlyConnectBleDevice) {
40901
41126
  return;
40902
41127
  }
40903
- yield device.initialize(parseInitOptions(method));
41128
+ if (!canSkipInitialize(method, device)) {
41129
+ const initOptions = parseInitOptions(method);
41130
+ yield device.initialize(initOptions);
41131
+ device.markPreInitialized({
41132
+ passphraseState: initOptions.passphraseState,
41133
+ deviceId: initOptions.deviceId,
41134
+ });
41135
+ }
40904
41136
  }
40905
41137
  catch (err) {
40906
- if (err.errorCode === hdShared.HardwareErrorCode.BleTimeoutError && bleTimeoutRetry <= 5) {
40907
- bleTimeoutRetry += 1;
40908
- Log.debug(`Bletooth connect timeout and will retry, retry count: ${bleTimeoutRetry}`);
41138
+ if (err.errorCode === hdShared.HardwareErrorCode.BleTimeoutError && retryCount < 6) {
41139
+ const nextRetry = retryCount + 1;
41140
+ Log.debug(`Bluetooth connect timeout and will retry, retry count: ${nextRetry}`);
40909
41141
  yield wait(3000);
40910
- yield connectDeviceForBle(method, device);
41142
+ yield connectDeviceForBle(method, device, nextRetry);
40911
41143
  }
40912
41144
  else {
40913
41145
  throw err;
@@ -40915,7 +41147,7 @@ function connectDeviceForBle(method, device) {
40915
41147
  }
40916
41148
  });
40917
41149
  }
40918
- const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(void 0, void 0, void 0, function* () {
41150
+ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) => __awaiter(void 0, void 0, void 0, function* () {
40919
41151
  let tryCount = 0;
40920
41152
  const MAX_RETRY_COUNT = method.payload && typeof method.payload.retryCount === 'number' ? method.payload.retryCount : 5;
40921
41153
  const POLL_INTERVAL_TIME = (method.payload && method.payload.pollIntervalTime) || 1000;
@@ -40924,7 +41156,7 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
40924
41156
  Log.debug(`EnsureConnected function start, MAX_RETRY_COUNT=${MAX_RETRY_COUNT}, POLL_INTERVAL_TIME=${POLL_INTERVAL_TIME} `);
40925
41157
  const poll = (time = POLL_INTERVAL_TIME) => __awaiter(void 0, void 0, void 0, function* () {
40926
41158
  return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
40927
- var _l;
41159
+ var _o;
40928
41160
  const abort = () => {
40929
41161
  if (abortSignal && abortSignal.aborted) {
40930
41162
  if (timer) {
@@ -40938,7 +41170,7 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
40938
41170
  if (abort()) {
40939
41171
  return;
40940
41172
  }
40941
- if (!pollingState[pollingId]) {
41173
+ if (!pollingManager.isActive(connectId, pollingId)) {
40942
41174
  Log.debug('EnsureConnected function stop, polling id: ', pollingId);
40943
41175
  reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PollingStop));
40944
41176
  return;
@@ -40986,7 +41218,6 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
40986
41218
  clearTimeout(timer);
40987
41219
  }
40988
41220
  if (DataManager.isBleConnect(env)) {
40989
- bleTimeoutRetry = 0;
40990
41221
  if (abort()) {
40991
41222
  return;
40992
41223
  }
@@ -41029,7 +41260,7 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
41029
41260
  clearTimeout(timer);
41030
41261
  }
41031
41262
  Log.debug('EnsureConnected get to max try count, will return: ', tryCount);
41032
- if (DataManager.isBrowserWebUsb(env) && !((_l = method.payload) === null || _l === void 0 ? void 0 : _l.skipWebDevicePrompt)) {
41263
+ if (DataManager.isBrowserWebUsb(env) && !((_o = method.payload) === null || _o === void 0 ? void 0 : _o.skipWebDevicePrompt)) {
41033
41264
  postMessage(createUiMessage(UI_REQUEST.WEB_DEVICE_PROMPT_ACCESS_PERMISSION));
41034
41265
  reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission));
41035
41266
  }
@@ -41044,7 +41275,6 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
41044
41275
  return setTimeout(() => resolve(poll(time * 1.5)), time);
41045
41276
  }));
41046
41277
  });
41047
- pollingState[pollingId] = true;
41048
41278
  return poll();
41049
41279
  });
41050
41280
  const cancel = (context, connectId) => {
@@ -41140,6 +41370,7 @@ const onDeviceConnectHandler = (device) => {
41140
41370
  postMessage(createDeviceMessage(DEVICE.CONNECT, { device: deviceObject }));
41141
41371
  };
41142
41372
  const onDeviceDisconnectHandler = (device) => {
41373
+ device.clearPreInitialized();
41143
41374
  const env = DataManager.getSettings('env');
41144
41375
  const deviceObject = DataManager.isBleConnect(env) ? device : device.toMessageObject();
41145
41376
  postMessage(createDeviceMessage(DEVICE.DISCONNECT, { device: deviceObject }));
@@ -41253,7 +41484,7 @@ class Core extends events.exports {
41253
41484
  registerCallbackTask: (connectId, callbackPromise) => {
41254
41485
  this.requestQueue.registerPendingCallbackTask(connectId, callbackPromise);
41255
41486
  },
41256
- waitForCallbackTasks: (connectId) => this.requestQueue.waitForPendingCallbackTasks(connectId),
41487
+ waitForCallbackTasks: (connectId, exceptTask) => this.requestQueue.waitForPendingCallbackTasks(connectId, exceptTask),
41257
41488
  cancelCallbackTasks: (connectId) => this.requestQueue.cancelCallbackTasks(connectId),
41258
41489
  };
41259
41490
  }
@@ -41283,10 +41514,10 @@ class Core extends events.exports {
41283
41514
  break;
41284
41515
  }
41285
41516
  case IFRAME.CALL: {
41286
- Log.log('call API: ', message);
41517
+ Log.log(`[${Date.now()}][CALL_API]`, message);
41287
41518
  const response = yield callAPI(this.getCoreContext(), message);
41288
41519
  const { success, payload } = response;
41289
- Log.log('call API Response: ', response);
41520
+ Log.log(`[${Date.now()}][CALL_API_RESPONSE]`, response);
41290
41521
  if (success) {
41291
41522
  return response;
41292
41523
  }
@@ -41309,6 +41540,9 @@ class Core extends events.exports {
41309
41540
  dispose() {
41310
41541
  _deviceList = undefined;
41311
41542
  _connector = undefined;
41543
+ deviceCacheMap.clear();
41544
+ preWarmInflight.clear();
41545
+ preWarmDoneAt.clear();
41312
41546
  Log.debug(`[Core] Disposing SDK instance: ${this.sdkInstanceId}`);
41313
41547
  cleanupSdkInstance(this.sdkInstanceId);
41314
41548
  }
@@ -41331,7 +41565,7 @@ const init = (settings, Transport, plugin) => __awaiter(void 0, void 0, void 0,
41331
41565
  yield DataManager.load(settings);
41332
41566
  initTransport(Transport, plugin);
41333
41567
  }
41334
- catch (_m) {
41568
+ catch (_p) {
41335
41569
  Log.error('DataManager.load error');
41336
41570
  }
41337
41571
  enableLog(DataManager.getSettings('debug'));