@onekeyfe/hd-core 1.1.27-alpha.42 → 1.1.27-alpha.43

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 (146) hide show
  1. package/__tests__/DeviceCommands.test.ts +99 -0
  2. package/__tests__/evmLedgerLegacySafety.test.ts +261 -0
  3. package/__tests__/preInitialize.test.ts +22 -0
  4. package/__tests__/protocol-v2.test.ts +10 -15
  5. package/dist/api/BaseMethod.d.ts +7 -1
  6. package/dist/api/BaseMethod.d.ts.map +1 -1
  7. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  8. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  9. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  10. package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
  11. package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
  12. package/dist/api/algo/AlgoSignTransaction.d.ts.map +1 -1
  13. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  14. package/dist/api/aptos/AptosSignInMessage.d.ts.map +1 -1
  15. package/dist/api/aptos/AptosSignMessage.d.ts.map +1 -1
  16. package/dist/api/aptos/AptosSignTransaction.d.ts.map +1 -1
  17. package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
  18. package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
  19. package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
  20. package/dist/api/btc/BTCSignPsbt.d.ts.map +1 -1
  21. package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
  22. package/dist/api/cardano/CardanoSignMessage.d.ts.map +1 -1
  23. package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -1
  24. package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -1
  25. package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -1
  26. package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
  27. package/dist/api/cosmos/CosmosSignTransaction.d.ts.map +1 -1
  28. package/dist/api/device/PreInitialize.d.ts +6 -0
  29. package/dist/api/device/PreInitialize.d.ts.map +1 -0
  30. package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
  31. package/dist/api/evm/EVMSignMessage.d.ts.map +1 -1
  32. package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
  33. package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
  34. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  35. package/dist/api/filecoin/FilecoinSignTransaction.d.ts.map +1 -1
  36. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +2 -10
  37. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  38. package/dist/api/index.d.ts +1 -0
  39. package/dist/api/index.d.ts.map +1 -1
  40. package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
  41. package/dist/api/near/NearSignTransaction.d.ts.map +1 -1
  42. package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -1
  43. package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
  44. package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
  45. package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
  46. package/dist/api/nostr/NostrSignEvent.d.ts.map +1 -1
  47. package/dist/api/nostr/NostrSignSchnorr.d.ts.map +1 -1
  48. package/dist/api/polkadot/PolkadotSignTransaction.d.ts.map +1 -1
  49. package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
  50. package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
  51. package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
  52. package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
  53. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
  54. package/dist/api/starcoin/StarcoinSignMessage.d.ts.map +1 -1
  55. package/dist/api/starcoin/StarcoinSignTransaction.d.ts.map +1 -1
  56. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
  57. package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
  58. package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
  59. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  60. package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
  61. package/dist/api/ton/TonSignProof.d.ts.map +1 -1
  62. package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
  63. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
  64. package/dist/api/xrp/XrpSignTransaction.d.ts.map +1 -1
  65. package/dist/core/PollingStateManager.d.ts +8 -0
  66. package/dist/core/PollingStateManager.d.ts.map +1 -0
  67. package/dist/core/RequestQueue.d.ts +1 -1
  68. package/dist/core/RequestQueue.d.ts.map +1 -1
  69. package/dist/core/index.d.ts.map +1 -1
  70. package/dist/device/Device.d.ts +15 -0
  71. package/dist/device/Device.d.ts.map +1 -1
  72. package/dist/index.d.ts +19 -0
  73. package/dist/index.js +431 -177
  74. package/dist/types/api/index.d.ts +2 -0
  75. package/dist/types/api/index.d.ts.map +1 -1
  76. package/dist/types/api/preInitialize.d.ts +3 -0
  77. package/dist/types/api/preInitialize.d.ts.map +1 -0
  78. package/dist/types/params.d.ts +1 -0
  79. package/dist/types/params.d.ts.map +1 -1
  80. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  81. package/package.json +4 -4
  82. package/src/api/BaseMethod.ts +82 -2
  83. package/src/api/FirmwareUpdateV3.ts +0 -4
  84. package/src/api/FirmwareUpdateV4.ts +1 -19
  85. package/src/api/GetPassphraseState.ts +4 -3
  86. package/src/api/alephium/AlephiumSignMessage.ts +1 -0
  87. package/src/api/alephium/AlephiumSignTransaction.ts +1 -0
  88. package/src/api/algo/AlgoSignTransaction.ts +1 -0
  89. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +8 -0
  90. package/src/api/aptos/AptosSignInMessage.ts +1 -0
  91. package/src/api/aptos/AptosSignMessage.ts +1 -0
  92. package/src/api/aptos/AptosSignTransaction.ts +1 -0
  93. package/src/api/benfen/BenfenSignMessage.ts +1 -0
  94. package/src/api/benfen/BenfenSignTransaction.ts +1 -0
  95. package/src/api/btc/BTCSignMessage.ts +1 -0
  96. package/src/api/btc/BTCSignPsbt.ts +1 -0
  97. package/src/api/btc/BTCSignTransaction.ts +1 -0
  98. package/src/api/cardano/CardanoSignMessage.ts +1 -0
  99. package/src/api/cardano/CardanoSignTransaction.ts +1 -0
  100. package/src/api/conflux/ConfluxSignMessage.ts +1 -0
  101. package/src/api/conflux/ConfluxSignMessageCIP23.ts +1 -0
  102. package/src/api/conflux/ConfluxSignTransaction.ts +1 -0
  103. package/src/api/cosmos/CosmosSignTransaction.ts +1 -0
  104. package/src/api/device/PreInitialize.ts +41 -0
  105. package/src/api/dynex/DnxSignTransaction.ts +1 -0
  106. package/src/api/evm/EVMSignMessage.ts +2 -0
  107. package/src/api/evm/EVMSignMessageEIP712.ts +1 -0
  108. package/src/api/evm/EVMSignTransaction.ts +2 -0
  109. package/src/api/evm/EVMSignTypedData.ts +2 -0
  110. package/src/api/filecoin/FilecoinSignTransaction.ts +1 -0
  111. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +4 -27
  112. package/src/api/index.ts +1 -0
  113. package/src/api/kaspa/KaspaSignTransaction.ts +1 -0
  114. package/src/api/near/NearSignTransaction.ts +1 -0
  115. package/src/api/nem/NEMSignTransaction.ts +1 -0
  116. package/src/api/neo/NeoSignTransaction.ts +1 -0
  117. package/src/api/nervos/NervosSignTransaction.ts +1 -0
  118. package/src/api/nexa/NexaSignTransaction.ts +2 -0
  119. package/src/api/nostr/NostrSignEvent.ts +1 -0
  120. package/src/api/nostr/NostrSignSchnorr.ts +1 -0
  121. package/src/api/polkadot/PolkadotSignTransaction.ts +1 -0
  122. package/src/api/scdo/ScdoSignMessage.ts +1 -0
  123. package/src/api/scdo/ScdoSignTransaction.ts +1 -0
  124. package/src/api/solana/SolSignMessage.ts +1 -0
  125. package/src/api/solana/SolSignOffchainMessage.ts +1 -0
  126. package/src/api/solana/SolSignTransaction.ts +1 -0
  127. package/src/api/starcoin/StarcoinSignMessage.ts +1 -0
  128. package/src/api/starcoin/StarcoinSignTransaction.ts +1 -0
  129. package/src/api/stellar/StellarSignTransaction.ts +1 -0
  130. package/src/api/sui/SuiSignMessage.ts +1 -0
  131. package/src/api/sui/SuiSignTransaction.ts +1 -0
  132. package/src/api/ton/TonSignData.ts +1 -0
  133. package/src/api/ton/TonSignMessage.ts +1 -0
  134. package/src/api/ton/TonSignProof.ts +1 -0
  135. package/src/api/tron/TronSignMessage.ts +1 -0
  136. package/src/api/tron/TronSignTransaction.ts +1 -0
  137. package/src/api/xrp/XrpSignTransaction.ts +1 -0
  138. package/src/core/PollingStateManager.ts +47 -0
  139. package/src/core/RequestQueue.ts +10 -3
  140. package/src/core/index.ts +153 -34
  141. package/src/device/Device.ts +71 -18
  142. package/src/inject.ts +1 -1
  143. package/src/types/api/index.ts +2 -0
  144. package/src/types/api/preInitialize.ts +3 -0
  145. package/src/types/params.ts +5 -0
  146. package/src/utils/deviceFeaturesUtils.ts +8 -17
package/dist/index.js CHANGED
@@ -132,6 +132,7 @@ const createCoreApi = (call) => ({
132
132
  checkFirmwareTypeAvailable: params => call(Object.assign(Object.assign({}, params), { method: 'checkFirmwareTypeAvailable' })),
133
133
  cipherKeyValue: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'cipherKeyValue' })),
134
134
  testInitializeDeviceDuration: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'testInitializeDeviceDuration' })),
135
+ preInitialize: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'preInitialize' })),
135
136
  deviceBackup: connectId => call({ connectId, method: 'deviceBackup' }),
136
137
  deviceChangePin: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceChangePin' })),
137
138
  deviceFlags: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFlags' })),
@@ -816,7 +817,7 @@ const createLogMessage = (type, payload) => ({
816
817
 
817
818
  const MAX_ENTRIES = 500;
818
819
  let postMessage$1;
819
- class Log$h {
820
+ class Log$i {
820
821
  constructor(prefix, enabled) {
821
822
  this.prefix = prefix;
822
823
  this.enabled = enabled;
@@ -868,7 +869,7 @@ class Log$h {
868
869
  }
869
870
  const _logs = {};
870
871
  const initLog = (prefix, enabled) => {
871
- const instance = new Log$h(prefix, !!enabled);
872
+ const instance = new Log$i(prefix, !!enabled);
872
873
  _logs[prefix] = instance;
873
874
  return instance;
874
875
  };
@@ -1066,7 +1067,7 @@ function patchFeatures(response) {
1066
1067
  return response;
1067
1068
  }
1068
1069
 
1069
- const Log$g = getLogger(exports.LoggerNames.Core);
1070
+ const Log$h = getLogger(exports.LoggerNames.Core);
1070
1071
  let globalInstanceCounter = 0;
1071
1072
  let sdkInstanceCounter = 0;
1072
1073
  function generateSdkInstanceId() {
@@ -1126,7 +1127,7 @@ function completeRequestContext(responseID, error) {
1126
1127
  context.status = error ? 'error' : 'success';
1127
1128
  if (error) {
1128
1129
  context.error = error.message;
1129
- Log$g.error(`[RequestContext] [completeRequestContext] Error: ${formatRequestContext(context)}`);
1130
+ Log$h.error(`[RequestContext] [completeRequestContext] Error: ${formatRequestContext(context)}`);
1130
1131
  }
1131
1132
  globalActiveRequests.delete(responseID);
1132
1133
  if (context.sdkInstanceId) {
@@ -38790,7 +38791,7 @@ const findLatestRelease = (releases) => {
38790
38791
  };
38791
38792
 
38792
38793
  var _a$1;
38793
- const Log$f = getLogger(exports.LoggerNames.Core);
38794
+ const Log$g = getLogger(exports.LoggerNames.Core);
38794
38795
  const FIRMWARE_FIELDS = [
38795
38796
  'firmware',
38796
38797
  'firmware-v2',
@@ -38852,37 +38853,37 @@ class DataManager {
38852
38853
  let data = null;
38853
38854
  let fetchMethod = 'none';
38854
38855
  if (settings.configFetcher) {
38855
- Log$f.debug('[DataConfig] Trying configFetcher (client-side fetcher)...');
38856
+ Log$g.debug('[DataConfig] Trying configFetcher (client-side fetcher)...');
38856
38857
  try {
38857
38858
  data = yield settings.configFetcher(urlWithCache);
38858
38859
  if (data) {
38859
38860
  fetchMethod = 'configFetcher';
38860
- Log$f.log('[DataConfig] ConfigFetcher success');
38861
+ Log$g.log('[DataConfig] ConfigFetcher success');
38861
38862
  }
38862
38863
  else {
38863
- Log$f.debug('[DataConfig] ConfigFetcher returned null, will fallback to axios');
38864
+ Log$g.debug('[DataConfig] ConfigFetcher returned null, will fallback to axios');
38864
38865
  }
38865
38866
  }
38866
38867
  catch (e) {
38867
- Log$f.warn('[DataConfig] ConfigFetcher error, will fallback to axios:', e);
38868
+ Log$g.warn('[DataConfig] ConfigFetcher error, will fallback to axios:', e);
38868
38869
  }
38869
38870
  }
38870
38871
  if (!data) {
38871
- Log$f.debug('[DataConfig] Trying axios (SDK default fetcher)...');
38872
+ Log$g.debug('[DataConfig] Trying axios (SDK default fetcher)...');
38872
38873
  try {
38873
38874
  const response = yield axios__default["default"].get(urlWithCache, {
38874
38875
  timeout: 7000,
38875
38876
  });
38876
38877
  data = response.data;
38877
38878
  fetchMethod = 'axios';
38878
- Log$f.log('[DataConfig] Axios fetch success');
38879
+ Log$g.log('[DataConfig] Axios fetch success');
38879
38880
  }
38880
38881
  catch (e) {
38881
- Log$f.warn('[DataConfig] Axios fetch error:', e);
38882
+ Log$g.warn('[DataConfig] Axios fetch error:', e);
38882
38883
  }
38883
38884
  }
38884
38885
  if (data) {
38885
- Log$f.log(`[DataConfig] Config loaded successfully via [${fetchMethod}]`);
38886
+ Log$g.log(`[DataConfig] Config loaded successfully via [${fetchMethod}]`);
38886
38887
  this.deviceMap = {
38887
38888
  [hdShared.EDeviceType.Classic]: this.enrichFirmwareReleaseInfo(data.classic),
38888
38889
  [hdShared.EDeviceType.Classic1s]: this.enrichFirmwareReleaseInfo(data.classic1s),
@@ -38896,7 +38897,7 @@ class DataManager {
38896
38897
  };
38897
38898
  }
38898
38899
  else {
38899
- Log$f.warn('[DataConfig] All fetch methods failed, using built-in default config');
38900
+ Log$g.warn('[DataConfig] All fetch methods failed, using built-in default config');
38900
38901
  }
38901
38902
  });
38902
38903
  }
@@ -39224,27 +39225,20 @@ const getPassphraseStateWithRefreshDeviceInfo = (device, options) => __awaiter(v
39224
39225
  const { features, commands } = device;
39225
39226
  const locked = (features === null || features === void 0 ? void 0 : features.unlocked) === false;
39226
39227
  const deviceType = getDeviceType(features);
39227
- const isPro2 = deviceType === hdShared.EDeviceType.Pro2;
39228
39228
  const { passphraseState, newSession, unlockedAttachPin } = yield getPassphraseState(features, commands, Object.assign({}, options));
39229
39229
  const isModeT = deviceType === hdShared.EDeviceType.Touch || deviceType === hdShared.EDeviceType.Pro;
39230
- const needRefreshWithPassphrase = !isPro2 && passphraseState && (features === null || features === void 0 ? void 0 : features.passphrase_protection) !== true;
39230
+ const needRefreshWithPassphrase = passphraseState && (features === null || features === void 0 ? void 0 : features.passphrase_protection) !== true;
39231
39231
  const needRefreshWithLocked = isModeT && locked;
39232
39232
  if (needRefreshWithLocked || needRefreshWithPassphrase) {
39233
39233
  yield device.getFeatures();
39234
39234
  }
39235
- if (isPro2 && device.features) {
39236
- if (passphraseState) {
39237
- device.features.passphrase_protection = true;
39238
- }
39239
- if (newSession) {
39240
- device.features.session_id = newSession;
39241
- }
39242
- }
39243
39235
  if (features === null || features === void 0 ? void 0 : features.device_id) {
39244
- device.updateInternalState(((_b = (_a = device.features) === null || _a === void 0 ? void 0 : _a.passphrase_protection) !== null && _b !== void 0 ? _b : false) || isPro2, passphraseState, (_d = (_c = device.features) === null || _c === void 0 ? void 0 : _c.device_id) !== null && _d !== void 0 ? _d : '', newSession, (_e = device.features) === null || _e === void 0 ? void 0 : _e.session_id);
39236
+ device.updateInternalState((_b = (_a = device.features) === null || _a === void 0 ? void 0 : _a.passphrase_protection) !== null && _b !== void 0 ? _b : false, passphraseState, (_d = (_c = device.features) === null || _c === void 0 ? void 0 : _c.device_id) !== null && _d !== void 0 ? _d : '', newSession, (_e = device.features) === null || _e === void 0 ? void 0 : _e.session_id);
39245
39237
  }
39246
39238
  return { passphraseState, newSession, unlockedAttachPin };
39247
39239
  });
39240
+ const supportProSeriesAttachPinPassphrase = (deviceType, firmwareVersion) => (deviceType === hdShared.EDeviceType.Pro || deviceType === hdShared.EDeviceType.Pro2) &&
39241
+ semver__default["default"].gte(firmwareVersion, '4.15.0');
39248
39242
  const getPassphraseState = (features, commands, options) => __awaiter(void 0, void 0, void 0, function* () {
39249
39243
  if (!features)
39250
39244
  return { passphraseState: undefined, newSession: undefined, unlockedAttachPin: undefined };
@@ -39252,8 +39246,7 @@ const getPassphraseState = (features, commands, options) => __awaiter(void 0, vo
39252
39246
  const deviceType = getDeviceType(features);
39253
39247
  const supportAttachPinCapability = existCapability(features, hdTransport.Enum_Capability.Capability_AttachToPin);
39254
39248
  const supportGetPassphraseState = supportAttachPinCapability ||
39255
- deviceType === hdShared.EDeviceType.Pro2 ||
39256
- (deviceType === hdShared.EDeviceType.Pro && semver__default["default"].gte(firmwareVersion.join('.'), '4.15.0'));
39249
+ supportProSeriesAttachPinPassphrase(deviceType, firmwareVersion.join('.'));
39257
39250
  if (supportGetPassphraseState) {
39258
39251
  const payload = (options === null || options === void 0 ? void 0 : options.onlyMainPin)
39259
39252
  ? { _only_main_pin: true }
@@ -40199,7 +40192,7 @@ function getLogBlockLabel(message) {
40199
40192
  return undefined;
40200
40193
  }
40201
40194
 
40202
- const Log$e = getLogger(exports.LoggerNames.DevicePool);
40195
+ const Log$f = getLogger(exports.LoggerNames.DevicePool);
40203
40196
  const getDiff = (current, descriptors) => {
40204
40197
  const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
40205
40198
  const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
@@ -40257,7 +40250,7 @@ class DevicePool extends events.exports {
40257
40250
  yield this._checkDevicePool(initOptions);
40258
40251
  return { devices, deviceList };
40259
40252
  }
40260
- Log$e.debug('found device in cache, but path is different: ', connectId);
40253
+ Log$f.debug('found device in cache, but path is different: ', connectId);
40261
40254
  }
40262
40255
  }
40263
40256
  try {
@@ -40318,7 +40311,7 @@ class DevicePool extends events.exports {
40318
40311
  for (let i = this.connectedPool.length - 1; i >= 0; i--) {
40319
40312
  const descriptor = this.connectedPool[i];
40320
40313
  const device = yield this._createDevice(descriptor, initOptions);
40321
- Log$e.debug('emit DEVICE.CONNECT: ', device === null || device === void 0 ? void 0 : device.features);
40314
+ Log$f.debug('emit DEVICE.CONNECT: ', device === null || device === void 0 ? void 0 : device.features);
40322
40315
  this.emitter.emit(DEVICE.CONNECT, device);
40323
40316
  this.connectedPool.splice(i, 1);
40324
40317
  }
@@ -40338,9 +40331,9 @@ class DevicePool extends events.exports {
40338
40331
  const diff = getDiff(this.current || [], upcoming);
40339
40332
  this.upcoming = upcoming;
40340
40333
  this.current = this.upcoming;
40341
- Log$e.debug('device pool -> current: ', this.current);
40342
- Log$e.debug('device pool -> upcomming: ', this.upcoming);
40343
- Log$e.debug('DeviceCache.reportDeviceChange diff: ', diff);
40334
+ Log$f.debug('device pool -> current: ', this.current);
40335
+ Log$f.debug('device pool -> upcomming: ', this.upcoming);
40336
+ Log$f.debug('DeviceCache.reportDeviceChange diff: ', diff);
40344
40337
  if (!diff.didUpdate) {
40345
40338
  return;
40346
40339
  }
@@ -40350,7 +40343,7 @@ class DevicePool extends events.exports {
40350
40343
  this._addConnectedDeviceToPool(d);
40351
40344
  return;
40352
40345
  }
40353
- Log$e.debug('emit DEVICE.CONNECT: ', device.features);
40346
+ Log$f.debug('emit DEVICE.CONNECT: ', device.features);
40354
40347
  this.emitter.emit(DEVICE.CONNECT, device);
40355
40348
  });
40356
40349
  diff.disconnected.forEach(d => {
@@ -40360,7 +40353,7 @@ class DevicePool extends events.exports {
40360
40353
  this._addDisconnectedDeviceToPool(d);
40361
40354
  return;
40362
40355
  }
40363
- Log$e.debug('emit DEVICE.DISCONNECT: ', device.features);
40356
+ Log$f.debug('emit DEVICE.DISCONNECT: ', device.features);
40364
40357
  this.emitter.emit(DEVICE.DISCONNECT, device);
40365
40358
  });
40366
40359
  }
@@ -40396,7 +40389,7 @@ class DevicePool extends events.exports {
40396
40389
  this.disconnectPool = [];
40397
40390
  this.devicesCache = {};
40398
40391
  this.emitter.removeAllListeners();
40399
- Log$e.debug('DevicePool state has been reset');
40392
+ Log$f.debug('DevicePool state has been reset');
40400
40393
  }
40401
40394
  }
40402
40395
  DevicePool.current = null;
@@ -40406,7 +40399,7 @@ DevicePool.disconnectPool = [];
40406
40399
  DevicePool.devicesCache = {};
40407
40400
  DevicePool.emitter = new events.exports();
40408
40401
 
40409
- const Log$d = getLogger(exports.LoggerNames.Transport);
40402
+ const Log$e = getLogger(exports.LoggerNames.Transport);
40410
40403
  const BleLogger = getLogger(exports.LoggerNames.HdBleTransport);
40411
40404
  const HttpLogger = getLogger(exports.LoggerNames.HdTransportHttp);
40412
40405
  const LowLevelLogger = getLogger(exports.LoggerNames.HdTransportLowLevel);
@@ -40416,7 +40409,7 @@ const WebUsbLogger = getLogger(exports.LoggerNames.HdTransportWebUsb);
40416
40409
  const REACT_NATIVE_BLE_SCAN_TIMEOUT_MS = 8000;
40417
40410
  class TransportManager {
40418
40411
  static load() {
40419
- Log$d.debug('transport manager load');
40412
+ Log$e.debug('transport manager load');
40420
40413
  this.defaultMessages = DataManager.getProtobufMessages();
40421
40414
  this.currentMessages = this.defaultMessages;
40422
40415
  this.protocolV1MessageSchema = 'v1CurrentSchema';
@@ -40425,14 +40418,14 @@ class TransportManager {
40425
40418
  return __awaiter(this, void 0, void 0, function* () {
40426
40419
  try {
40427
40420
  const env = DataManager.getSettings('env');
40428
- Log$d.debug('Initializing transports', env);
40421
+ Log$e.debug('Initializing transports', env);
40429
40422
  if (env === 'react-native') {
40430
40423
  if (!this.reactNativeInit) {
40431
40424
  yield this.transport.init(BleLogger, DevicePool.emitter);
40432
40425
  this.reactNativeInit = true;
40433
40426
  }
40434
40427
  else {
40435
- Log$d.debug('React Native Do Not Initializing transports');
40428
+ Log$e.debug('React Native Do Not Initializing transports');
40436
40429
  }
40437
40430
  }
40438
40431
  else if (env === 'node-usb') {
@@ -40453,15 +40446,15 @@ class TransportManager {
40453
40446
  else {
40454
40447
  yield this.transport.init(HttpLogger);
40455
40448
  }
40456
- Log$d.debug('Configuring transports');
40449
+ Log$e.debug('Configuring transports');
40457
40450
  yield this.transport.configure(JSON.stringify(this.defaultMessages));
40458
40451
  this.currentMessages = this.defaultMessages;
40459
40452
  this.protocolV1MessageSchema = 'v1CurrentSchema';
40460
40453
  yield this.configureProtocolV2Messages();
40461
- Log$d.debug('Configuring transports done');
40454
+ Log$e.debug('Configuring transports done');
40462
40455
  }
40463
40456
  catch (error) {
40464
- Log$d.debug('Initializing transports error: ', error);
40457
+ Log$e.debug('Initializing transports error: ', error);
40465
40458
  if (error.code === 'ECONNABORTED') {
40466
40459
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
40467
40460
  }
@@ -40477,7 +40470,7 @@ class TransportManager {
40477
40470
  if (this.currentMessages === messages || !messages) {
40478
40471
  return;
40479
40472
  }
40480
- Log$d.debug(`Reconfiguring transports Protocol V1 schema:${protocolV1MessageSchema}`);
40473
+ Log$e.debug(`Reconfiguring transports Protocol V1 schema:${protocolV1MessageSchema}`);
40481
40474
  try {
40482
40475
  yield this.transport.configure(JSON.stringify(messages));
40483
40476
  this.currentMessages = messages;
@@ -40500,9 +40493,9 @@ class TransportManager {
40500
40493
  }
40501
40494
  if (plugin) {
40502
40495
  this.plugin = plugin;
40503
- Log$d.debug('set transport plugin: ', this.plugin);
40496
+ Log$e.debug('set transport plugin: ', this.plugin);
40504
40497
  }
40505
- Log$d.debug('set transport: ', this.transport.name, this.transport.version, this.transport.configured);
40498
+ Log$e.debug('set transport: ', this.transport.name, this.transport.version, this.transport.configured);
40506
40499
  }
40507
40500
  static getTransport() {
40508
40501
  return this.transport;
@@ -40513,7 +40506,7 @@ class TransportManager {
40513
40506
  const { configureProtocolV2 } = this.transport;
40514
40507
  if (protocolV2Messages && typeof configureProtocolV2 === 'function') {
40515
40508
  yield configureProtocolV2.call(this.transport, JSON.stringify(protocolV2Messages));
40516
- Log$d.debug('Protocol V2 messages configured');
40509
+ Log$e.debug('Protocol V2 messages configured');
40517
40510
  }
40518
40511
  });
40519
40512
  }
@@ -40685,7 +40678,7 @@ const cancelDeviceWithInitialize = (device) => {
40685
40678
  },
40686
40679
  }));
40687
40680
  };
40688
- const Log$c = getLogger(exports.LoggerNames.DeviceCommands);
40681
+ const Log$d = getLogger(exports.LoggerNames.DeviceCommands);
40689
40682
  const LogCore = getLogger(exports.LoggerNames.Core);
40690
40683
  class DeviceCommands {
40691
40684
  constructor(device, mainId) {
@@ -40694,7 +40687,7 @@ class DeviceCommands {
40694
40687
  this.transport = TransportManager.getTransport();
40695
40688
  this.disposed = false;
40696
40689
  this.instanceId = generateInstanceId('DeviceCommands', device.sdkInstanceId);
40697
- Log$c.debug(`[DeviceCommands] Created: ${this.instanceId}, device: ${this.device.instanceId}`);
40690
+ Log$d.debug(`[DeviceCommands] Created: ${this.instanceId}, device: ${this.device.instanceId}`);
40698
40691
  }
40699
40692
  dispose(_cancelRequest) {
40700
40693
  var _a, _b;
@@ -40764,7 +40757,7 @@ class DeviceCommands {
40764
40757
  return __awaiter(this, void 0, void 0, function* () {
40765
40758
  const shouldReduceDebug = shouldReduceDebugForCall(type);
40766
40759
  if (!shouldReduceDebug) {
40767
- Log$c.debug('[DeviceCommands] [call] Sending', type);
40760
+ Log$d.debug('[DeviceCommands] [call] Sending', type);
40768
40761
  }
40769
40762
  try {
40770
40763
  const promise = this.transport.call(this.mainId, type, msg !== null && msg !== void 0 ? msg : {}, options);
@@ -40799,7 +40792,7 @@ class DeviceCommands {
40799
40792
  }
40800
40793
  }
40801
40794
  if (responseData) {
40802
- Log$c.debug('error response', responseData);
40795
+ Log$d.debug('error response', responseData);
40803
40796
  }
40804
40797
  if (responseError === 'device disconnected during action') {
40805
40798
  return { type: 'BridgeDeviceDisconnected', message: { error: responseError } };
@@ -40839,7 +40832,7 @@ class DeviceCommands {
40839
40832
  'ResourceAck',
40840
40833
  ];
40841
40834
  if (!skipTypes.includes(type) && msg) {
40842
- Log$c.debug('[DeviceCommands] [typedCall] Sending payload', type, sanitizeDebugPayload(msg));
40835
+ Log$d.debug('[DeviceCommands] [typedCall] Sending payload', type, sanitizeDebugPayload(msg));
40843
40836
  }
40844
40837
  }
40845
40838
  catch (e) {
@@ -40850,10 +40843,10 @@ class DeviceCommands {
40850
40843
  assertType(response, resType);
40851
40844
  }
40852
40845
  catch (error) {
40853
- Log$c.debug('DeviceCommands typedcall error: ', error);
40846
+ Log$d.debug('DeviceCommands typedcall error: ', error);
40854
40847
  if (error instanceof hdShared.HardwareError) {
40855
40848
  if (error.errorCode === hdShared.HardwareErrorCode.ResponseUnexpectTypeError) {
40856
- Log$c.debug('[DeviceCommands] [typedCall] Unexpected response type', {
40849
+ Log$d.debug('[DeviceCommands] [typedCall] Unexpected response type', {
40857
40850
  request: type,
40858
40851
  expected: resType,
40859
40852
  received: response.type,
@@ -40889,10 +40882,10 @@ class DeviceCommands {
40889
40882
  if (shouldReduceDebugForCall(callType)) {
40890
40883
  }
40891
40884
  else if (DataManager.getSettings('env') === 'react-native') {
40892
- Log$c.debug('_filterCommonTypes: ', JSON.stringify(sanitizeDebugPayload(res)));
40885
+ Log$d.debug('_filterCommonTypes: ', JSON.stringify(sanitizeDebugPayload(res)));
40893
40886
  }
40894
40887
  else {
40895
- Log$c.debug('_filterCommonTypes: ', sanitizeDebugPayload(res));
40888
+ Log$d.debug('_filterCommonTypes: ', sanitizeDebugPayload(res));
40896
40889
  }
40897
40890
  }
40898
40891
  catch (error) {
@@ -41021,7 +41014,7 @@ class DeviceCommands {
41021
41014
  reject(error);
41022
41015
  });
41023
41016
  const listenerCount = this.device.listenerCount(DEVICE.PIN);
41024
- Log$c.debug(`[${this.instanceId}] _promptPin called`, {
41017
+ Log$d.debug(`[${this.instanceId}] _promptPin called`, {
41025
41018
  responseID: this.currentResponseID,
41026
41019
  deviceInstanceId: this.device.instanceId,
41027
41020
  listenerCount,
@@ -41260,7 +41253,7 @@ const parseRunOptions = (options) => {
41260
41253
  options = {};
41261
41254
  return options;
41262
41255
  };
41263
- const Log$b = getLogger(exports.LoggerNames.Device);
41256
+ const Log$c = getLogger(exports.LoggerNames.Device);
41264
41257
  const deviceSessionCache = {};
41265
41258
  function preloadSessionCache(deviceId, passphraseState, sessionId) {
41266
41259
  const key = `${deviceId}@${passphraseState}`;
@@ -41284,7 +41277,7 @@ class Device extends events.exports {
41284
41277
  this.sdkInstanceId = sdkInstanceId;
41285
41278
  this.instanceId = generateInstanceId('Device', this.sdkInstanceId);
41286
41279
  this.createdAt = Date.now();
41287
- Log$b.debug(`[Device] Created: ${this.instanceId}${this.sdkInstanceId ? ` for SDK: ${this.sdkInstanceId}` : ''}`);
41280
+ Log$c.debug(`[Device] Created: ${this.instanceId}${this.sdkInstanceId ? ` for SDK: ${this.sdkInstanceId}` : ''}`);
41288
41281
  }
41289
41282
  static fromDescriptor(originalDescriptor, sdkInstanceId) {
41290
41283
  const descriptor = Object.assign({}, originalDescriptor);
@@ -41359,12 +41352,12 @@ class Device extends events.exports {
41359
41352
  if (DataManager.isBleConnect(env)) {
41360
41353
  acquireResult = yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.originalDescriptor.id, undefined, true, expectedProtocol));
41361
41354
  this.mainId = (_b = acquireResult === null || acquireResult === void 0 ? void 0 : acquireResult.uuid) !== null && _b !== void 0 ? _b : '';
41362
- Log$b.debug('Expected uuid:', this.mainId);
41355
+ Log$c.debug('Expected uuid:', this.mainId);
41363
41356
  }
41364
41357
  else {
41365
41358
  acquireResult = yield ((_c = this.deviceConnector) === null || _c === void 0 ? void 0 : _c.acquire(this.originalDescriptor.path, this.originalDescriptor.session, undefined, expectedProtocol));
41366
41359
  this.mainId = acquireResult;
41367
- Log$b.debug('Expected session id:', this.mainId);
41360
+ Log$c.debug('Expected session id:', this.mainId);
41368
41361
  }
41369
41362
  this.deviceAcquired = true;
41370
41363
  this.updateDescriptor({ [mainIdKey]: this.mainId });
@@ -41396,11 +41389,11 @@ class Device extends events.exports {
41396
41389
  (this.mainId && DataManager.isBleConnect(env))) {
41397
41390
  if (this.pendingCallbackPromise) {
41398
41391
  try {
41399
- Log$b.debug('Waiting for callback tasks to complete before releasing device (in release method)');
41392
+ Log$c.debug('Waiting for callback tasks to complete before releasing device (in release method)');
41400
41393
  yield this.pendingCallbackPromise.promise;
41401
41394
  }
41402
41395
  catch (error) {
41403
- Log$b.error('Error waiting for callback tasks in release method:', error);
41396
+ Log$c.error('Error waiting for callback tasks in release method:', error);
41404
41397
  }
41405
41398
  }
41406
41399
  if (this.commands) {
@@ -41419,7 +41412,7 @@ class Device extends events.exports {
41419
41412
  this.updateDescriptor({ session: null });
41420
41413
  }
41421
41414
  catch (err) {
41422
- Log$b.error('[Device] release error: ', err);
41415
+ Log$c.error('[Device] release error: ', err);
41423
41416
  }
41424
41417
  finally {
41425
41418
  this.needReloadDevice = true;
@@ -41428,6 +41421,46 @@ class Device extends events.exports {
41428
41421
  this.deviceAcquired = false;
41429
41422
  });
41430
41423
  }
41424
+ preInitialize(initOptions) {
41425
+ return __awaiter(this, void 0, void 0, function* () {
41426
+ if (!this.features) {
41427
+ yield this.acquire();
41428
+ yield this.initialize(initOptions);
41429
+ }
41430
+ this.markPreInitialized({
41431
+ passphraseState: initOptions === null || initOptions === void 0 ? void 0 : initOptions.passphraseState,
41432
+ });
41433
+ });
41434
+ }
41435
+ markPreInitialized(meta) {
41436
+ this.preInitializedAt = Date.now();
41437
+ this.preInitializeMeta = meta
41438
+ ? {
41439
+ passphraseState: meta.passphraseState === '' ? undefined : meta.passphraseState,
41440
+ }
41441
+ : undefined;
41442
+ }
41443
+ clearPreInitialized() {
41444
+ this.preInitializedAt = undefined;
41445
+ this.preInitializeMeta = undefined;
41446
+ }
41447
+ isPreInitializeMetaMatch(payload) {
41448
+ if (!this.preInitializeMeta)
41449
+ return true;
41450
+ const passphraseState = (payload === null || payload === void 0 ? void 0 : payload.passphraseState) === '' ? undefined : payload === null || payload === void 0 ? void 0 : payload.passphraseState;
41451
+ return this.preInitializeMeta.passphraseState === passphraseState;
41452
+ }
41453
+ isPreInitializedValid(ttlMs) {
41454
+ if (!this.preInitializedAt)
41455
+ return false;
41456
+ return Date.now() - this.preInitializedAt <= ttlMs;
41457
+ }
41458
+ setLastInitializeDuration(durationMs) {
41459
+ this.lastInitializeDurationMs = durationMs;
41460
+ }
41461
+ getLastInitializeDuration() {
41462
+ return this.lastInitializeDurationMs;
41463
+ }
41431
41464
  getCommands() {
41432
41465
  return this.commands;
41433
41466
  }
@@ -41439,8 +41472,8 @@ class Device extends events.exports {
41439
41472
  }
41440
41473
  getInternalState(_deviceId) {
41441
41474
  var _a, _b;
41442
- Log$b.debug('getInternalState session cache: ', deviceSessionCache);
41443
- 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}`);
41475
+ Log$c.debug('getInternalState session cache: ', deviceSessionCache);
41476
+ Log$c.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}`);
41444
41477
  const deviceId = _deviceId || ((_b = this.features) === null || _b === void 0 ? void 0 : _b.device_id);
41445
41478
  if (!deviceId)
41446
41479
  return undefined;
@@ -41450,7 +41483,7 @@ class Device extends events.exports {
41450
41483
  return deviceSessionCache[usePassKey];
41451
41484
  }
41452
41485
  updateInternalState(enablePassphrase, passphraseState, deviceId, sessionId = null, featuresSessionId = null) {
41453
- Log$b.debug('updateInternalState session param: ', `device_id: ${deviceId}`, `enablePassphrase: ${enablePassphrase}`, `passphraseState: ${passphraseState}`, `sessionId: ${sessionId}`, `featuresSessionId: ${featuresSessionId}`);
41486
+ Log$c.debug('updateInternalState session param: ', `device_id: ${deviceId}`, `enablePassphrase: ${enablePassphrase}`, `passphraseState: ${passphraseState}`, `sessionId: ${sessionId}`, `featuresSessionId: ${featuresSessionId}`);
41454
41487
  if (enablePassphrase) {
41455
41488
  if (sessionId) {
41456
41489
  deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = sessionId;
@@ -41463,11 +41496,11 @@ class Device extends events.exports {
41463
41496
  if (deviceSessionCache[oldKey]) {
41464
41497
  delete deviceSessionCache[oldKey];
41465
41498
  }
41466
- Log$b.debug('updateInternalState session cache: ', deviceSessionCache);
41499
+ Log$c.debug('updateInternalState session cache: ', deviceSessionCache);
41467
41500
  }
41468
41501
  setInternalState(state, initSession) {
41469
41502
  var _a, _b;
41470
- 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}`);
41503
+ Log$c.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}`);
41471
41504
  if (!this.features)
41472
41505
  return;
41473
41506
  if (!this.passphraseState && !initSession)
@@ -41479,11 +41512,11 @@ class Device extends events.exports {
41479
41512
  if (state) {
41480
41513
  deviceSessionCache[key] = state;
41481
41514
  }
41482
- Log$b.debug('setInternalState done session cache: ', deviceSessionCache);
41515
+ Log$c.debug('setInternalState done session cache: ', deviceSessionCache);
41483
41516
  }
41484
41517
  clearInternalState(_deviceId) {
41485
41518
  var _a;
41486
- Log$b.debug('clearInternalState param: ', _deviceId);
41519
+ Log$c.debug('clearInternalState param: ', _deviceId);
41487
41520
  const deviceId = _deviceId || ((_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id);
41488
41521
  if (!deviceId)
41489
41522
  return;
@@ -41499,7 +41532,7 @@ class Device extends events.exports {
41499
41532
  if (this.originalDescriptor.protocolType === 'V2') {
41500
41533
  this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
41501
41534
  if (this.features && !this.featuresNeedsReload && !(options === null || options === void 0 ? void 0 : options.initSession)) {
41502
- Log$b.debug('Skip Protocol V2 feature adapter; cached features are available');
41535
+ Log$c.debug('Skip Protocol V2 feature adapter; cached features are available');
41503
41536
  return;
41504
41537
  }
41505
41538
  yield this._initializeProtocolV2();
@@ -41519,12 +41552,7 @@ class Device extends events.exports {
41519
41552
  }
41520
41553
  payload.passphrase_state = options === null || options === void 0 ? void 0 : options.passphraseState;
41521
41554
  payload.is_contains_attach = true;
41522
- Log$b.debug('Initialize device begin:', {
41523
- deviceId: options === null || options === void 0 ? void 0 : options.deviceId,
41524
- passphraseState: options === null || options === void 0 ? void 0 : options.passphraseState,
41525
- initSession: options === null || options === void 0 ? void 0 : options.initSession,
41526
- InitializePayload: payload,
41527
- });
41555
+ const initStartAt = Date.now();
41528
41556
  try {
41529
41557
  const { message } = yield Promise.race([
41530
41558
  this.commands.typedCall('Initialize', 'Features', payload),
@@ -41534,19 +41562,20 @@ class Device extends events.exports {
41534
41562
  }, 25 * 1000);
41535
41563
  }),
41536
41564
  ]);
41537
- Log$b.debug('Initialize device end: ', message);
41565
+ const initCostMs = Date.now() - initStartAt;
41566
+ this.setLastInitializeDuration(initCostMs);
41538
41567
  this._updateFeatures(message, options === null || options === void 0 ? void 0 : options.initSession);
41539
41568
  yield TransportManager.reconfigure(this.features);
41540
41569
  }
41541
41570
  catch (error) {
41542
- Log$b.error('Initialization failed:', error);
41571
+ Log$c.error('Initialization failed:', error);
41543
41572
  throw error;
41544
41573
  }
41545
41574
  });
41546
41575
  }
41547
41576
  _initializeProtocolV2() {
41548
41577
  return __awaiter(this, void 0, void 0, function* () {
41549
- Log$b.debug('Initialize device via Protocol V2 feature adapter');
41578
+ Log$c.debug('Initialize device via Protocol V2 feature adapter');
41550
41579
  try {
41551
41580
  const features = yield Promise.race([
41552
41581
  getProtocolV2Features({
@@ -41560,11 +41589,11 @@ class Device extends events.exports {
41560
41589
  }, 10 * 1000);
41561
41590
  }),
41562
41591
  ]);
41563
- Log$b.debug('Protocol V2 normalized features:', features);
41592
+ Log$c.debug('Protocol V2 normalized features:', features);
41564
41593
  this._updateFeatures(features);
41565
41594
  }
41566
41595
  catch (error) {
41567
- Log$b.error('Protocol V2 initialization failed:', error);
41596
+ Log$c.error('Protocol V2 initialization failed:', error);
41568
41597
  throw error;
41569
41598
  }
41570
41599
  });
@@ -41615,7 +41644,7 @@ class Device extends events.exports {
41615
41644
  return __awaiter(this, void 0, void 0, function* () {
41616
41645
  if (this.runPromise) {
41617
41646
  yield this.interruptionFromOutside();
41618
- Log$b.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
41647
+ Log$c.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
41619
41648
  }
41620
41649
  options = parseRunOptions(options);
41621
41650
  this.runPromise = hdShared.createDeferred(this._runInner.bind(this, fn, options));
@@ -41637,7 +41666,9 @@ class Device extends events.exports {
41637
41666
  }
41638
41667
  try {
41639
41668
  if (fn) {
41640
- yield this.initialize(options);
41669
+ if (!(options === null || options === void 0 ? void 0 : options.skipInitialize)) {
41670
+ yield this.initialize(options);
41671
+ }
41641
41672
  }
41642
41673
  }
41643
41674
  catch (error) {
@@ -41671,7 +41702,7 @@ class Device extends events.exports {
41671
41702
  yield ((_a = this.deviceConnector) === null || _a === void 0 ? void 0 : _a.disconnect(this.mainId));
41672
41703
  }
41673
41704
  yield this.release();
41674
- Log$b.debug(`error code ${e.errorCode} release device, mainId: ${this.mainId}`);
41705
+ Log$c.debug(`error code ${e.errorCode} release device, mainId: ${this.mainId}`);
41675
41706
  }
41676
41707
  this.runPromise = null;
41677
41708
  return;
@@ -41681,7 +41712,7 @@ class Device extends events.exports {
41681
41712
  options.keepSession === false) {
41682
41713
  this.keepSession = false;
41683
41714
  yield this.release();
41684
- Log$b.debug('release device, mainId: ', this.mainId);
41715
+ Log$c.debug('release device, mainId: ', this.mainId);
41685
41716
  }
41686
41717
  if (this.runPromise) {
41687
41718
  this.runPromise.resolve();
@@ -41714,7 +41745,7 @@ class Device extends events.exports {
41714
41745
  setCancelableAction(callback) {
41715
41746
  this.cancelableAction = (e) => callback(e)
41716
41747
  .catch(e2 => {
41717
- Log$b.debug('cancelableAction error', e2);
41748
+ Log$c.debug('cancelableAction error', e2);
41718
41749
  })
41719
41750
  .finally(() => {
41720
41751
  this.clearCancelableAction();
@@ -41798,7 +41829,8 @@ class Device extends events.exports {
41798
41829
  hasUsePassphrase() {
41799
41830
  var _a;
41800
41831
  const isModeT = getDeviceType(this.features) === hdShared.EDeviceType.Touch ||
41801
- getDeviceType(this.features) === hdShared.EDeviceType.Pro;
41832
+ getDeviceType(this.features) === hdShared.EDeviceType.Pro ||
41833
+ getDeviceType(this.features) === hdShared.EDeviceType.Pro2;
41802
41834
  const preCheckTouch = isModeT && ((_a = this.features) === null || _a === void 0 ? void 0 : _a.unlocked) === false;
41803
41835
  return this.features && (!!this.features.passphrase_protection || preCheckTouch);
41804
41836
  }
@@ -41810,9 +41842,6 @@ class Device extends events.exports {
41810
41842
  }
41811
41843
  lockDevice() {
41812
41844
  return __awaiter(this, void 0, void 0, function* () {
41813
- if (getDeviceType(this.features) === hdShared.EDeviceType.Pro2) {
41814
- return { message: 'LockDevice skipped for Pro2' };
41815
- }
41816
41845
  const res = yield this.commands.typedCall('LockDevice', 'Success', {});
41817
41846
  return res.message;
41818
41847
  });
@@ -41822,6 +41851,9 @@ class Device extends events.exports {
41822
41851
  pro: {
41823
41852
  min: '4.15.0',
41824
41853
  },
41854
+ pro2: {
41855
+ min: '4.15.0',
41856
+ },
41825
41857
  };
41826
41858
  }
41827
41859
  unlockDevice() {
@@ -41830,9 +41862,7 @@ class Device extends events.exports {
41830
41862
  const firmwareVersion = (_a = getDeviceFirmwareVersion(this.features)) === null || _a === void 0 ? void 0 : _a.join('.');
41831
41863
  const versionRange = getMethodVersionRange(this.features, type => this.supportUnlockVersionRange()[type]);
41832
41864
  const supportAttachPinCapability = existCapability(this.features, hdTransport.Enum_Capability.Capability_AttachToPin);
41833
- const isPro2 = getDeviceType(this.features) === hdShared.EDeviceType.Pro2;
41834
41865
  const supportUnlock = supportAttachPinCapability ||
41835
- isPro2 ||
41836
41866
  (versionRange && semver__default["default"].gte(firmwareVersion, versionRange.min));
41837
41867
  if (supportUnlock) {
41838
41868
  const res = yield this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
@@ -41873,7 +41903,7 @@ class Device extends events.exports {
41873
41903
  const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
41874
41904
  const useErrorAttachPin = unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
41875
41905
  const passphraseStateMismatch = !!passphraseState && passphraseState !== newPassphraseState;
41876
- Log$b.debug('Check passphrase state safety: ', {
41906
+ Log$c.debug('Check passphrase state safety: ', {
41877
41907
  passphraseState,
41878
41908
  newPassphraseState,
41879
41909
  unlockedAttachPin,
@@ -41928,6 +41958,27 @@ class DeviceList extends events.exports {
41928
41958
  }
41929
41959
  }
41930
41960
 
41961
+ class PollingStateManager {
41962
+ constructor() {
41963
+ this.activePolls = new Map();
41964
+ }
41965
+ start(connectId) {
41966
+ var _a;
41967
+ const currentId = ((_a = this.activePolls.get(connectId)) !== null && _a !== void 0 ? _a : 0) + 1;
41968
+ this.activePolls.set(connectId, currentId);
41969
+ return currentId;
41970
+ }
41971
+ isActive(connectId, pollingId) {
41972
+ return this.activePolls.get(connectId) === pollingId;
41973
+ }
41974
+ stop(connectId) {
41975
+ this.activePolls.delete(connectId);
41976
+ }
41977
+ stopAll() {
41978
+ this.activePolls.clear();
41979
+ }
41980
+ }
41981
+
41931
41982
  const getFirmwareReleaseInfo = (features, firmwareType) => {
41932
41983
  const firmwareStatus = DataManager.getFirmwareStatus(features, firmwareType);
41933
41984
  const changelog = DataManager.getFirmwareChangelog(features, firmwareType);
@@ -41980,14 +42031,49 @@ const getBootloaderReleaseInfo = ({ features, willUpdateFirmwareVersion, firmwar
41980
42031
  };
41981
42032
  };
41982
42033
 
41983
- const Log$a = getLogger(exports.LoggerNames.Method);
42034
+ const Log$b = getLogger(exports.LoggerNames.Method);
42035
+ const isEvmLedgerLegacyPathWithHighIndex = (path) => {
42036
+ let addressN;
42037
+ if (typeof path === 'string') {
42038
+ try {
42039
+ addressN = getHDPath(path);
42040
+ }
42041
+ catch (_a) {
42042
+ return false;
42043
+ }
42044
+ }
42045
+ else if (Array.isArray(path)) {
42046
+ addressN = path.map((item) => Number(item));
42047
+ }
42048
+ return (Array.isArray(addressN) &&
42049
+ addressN.length === 4 &&
42050
+ addressN[0] === toHardened(44) &&
42051
+ addressN[1] === toHardened(60) &&
42052
+ addressN[2] === toHardened(0) &&
42053
+ addressN[3] > 1 &&
42054
+ addressN[3] < toHardened(0));
42055
+ };
42056
+ const EVM_LEDGER_LEGACY_METHODS = ['evmGetAddress', 'evmGetPublicKey'];
41984
42057
  class BaseMethod {
42058
+ getPreWarmKey() {
42059
+ var _a, _b, _c, _d;
42060
+ const payload = ((_a = this.payload) !== null && _a !== void 0 ? _a : {});
42061
+ return [
42062
+ (_c = (_b = this.connectId) !== null && _b !== void 0 ? _b : payload.connectId) !== null && _c !== void 0 ? _c : '',
42063
+ (_d = payload.passphraseState) !== null && _d !== void 0 ? _d : '',
42064
+ this.name,
42065
+ ].join('|');
42066
+ }
41985
42067
  constructor(message) {
41986
42068
  this.shouldEnsureConnected = true;
41987
42069
  this.checkDeviceId = false;
41988
42070
  this.useDevicePassphraseState = true;
41989
42071
  this.skipForceUpdateCheck = false;
42072
+ this.allowUsePreInitialize = false;
42073
+ this.isPreWarmSignal = false;
42074
+ this.preWarmTtl = 60 * 1000;
41990
42075
  this.strictCheckDeviceSupport = false;
42076
+ this.temporarySafetyCheckPrompted = false;
41991
42077
  this.postPreviousAddressMessage = (data) => {
41992
42078
  this.postMessage(createUiMessage(UI_REQUEST.PREVIOUS_ADDRESS_RESULT, {
41993
42079
  device: this.device.toMessageObject(),
@@ -42010,7 +42096,7 @@ class BaseMethod {
42010
42096
  setContext(context) {
42011
42097
  this.sdkInstanceId = context.sdkInstanceId;
42012
42098
  this.instanceId = generateInstanceId('Method', this.sdkInstanceId);
42013
- Log$a.debug(`[BaseMethod] Created: ${this.instanceId}, method: ${this.name}, SDK: ${this.sdkInstanceId}`);
42099
+ Log$b.debug(`[BaseMethod] Created: ${this.instanceId}, method: ${this.name}, SDK: ${this.sdkInstanceId}`);
42014
42100
  }
42015
42101
  setDevice(device) {
42016
42102
  var _a, _b;
@@ -42030,7 +42116,7 @@ class BaseMethod {
42030
42116
  if (device.commands) {
42031
42117
  device.commands.currentResponseID = this.responseID;
42032
42118
  }
42033
- Log$a.debug(`[${this.instanceId}] setDevice: ${device.instanceId}, commands: ${(_b = device.commands) === null || _b === void 0 ? void 0 : _b.instanceId}`);
42119
+ Log$b.debug(`[${this.instanceId}] setDevice: ${device.instanceId}, commands: ${(_b = device.commands) === null || _b === void 0 ? void 0 : _b.instanceId}`);
42034
42120
  }
42035
42121
  checkFirmwareRelease() {
42036
42122
  if (!this.device || !this.device.features)
@@ -42077,20 +42163,43 @@ class BaseMethod {
42077
42163
  });
42078
42164
  }
42079
42165
  }
42166
+ shouldPromptSafetyCheckForEvmLedgerLegacyPath() {
42167
+ var _a, _b;
42168
+ if (!EVM_LEDGER_LEGACY_METHODS.includes(this.name)) {
42169
+ return false;
42170
+ }
42171
+ const deviceType = getDeviceType(this.device.features);
42172
+ if (!DeviceModelToTypes.model_touch.includes(deviceType)) {
42173
+ return false;
42174
+ }
42175
+ const paths = Array.isArray((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle)
42176
+ ? this.payload.bundle.map((item) => item === null || item === void 0 ? void 0 : item.path)
42177
+ : [(_b = this.payload) === null || _b === void 0 ? void 0 : _b.path];
42178
+ return paths.some(isEvmLedgerLegacyPathWithHighIndex);
42179
+ }
42080
42180
  checkSafetyLevelOnTestNet() {
42081
42181
  var _a, _b, _c;
42082
42182
  return __awaiter(this, void 0, void 0, function* () {
42183
+ if (this.temporarySafetyCheckPrompted) {
42184
+ return false;
42185
+ }
42083
42186
  let checkFlag = false;
42084
42187
  if (this.name === 'evmSignTransaction' &&
42085
42188
  [3, 4, 5, 420, 11155111].includes(Number((_b = (_a = this.payload) === null || _a === void 0 ? void 0 : _a.transaction) === null || _b === void 0 ? void 0 : _b.chainId))) {
42086
42189
  checkFlag = true;
42087
42190
  }
42191
+ if (this.shouldPromptSafetyCheckForEvmLedgerLegacyPath()) {
42192
+ checkFlag = true;
42193
+ }
42088
42194
  if (checkFlag && ((_c = this.device.features) === null || _c === void 0 ? void 0 : _c.safety_checks) === 'Strict') {
42089
- Log$a.debug('will change safety_checks level');
42195
+ Log$b.debug('will change safety_checks level');
42090
42196
  yield this.device.commands.typedCall('ApplySettings', 'Success', {
42091
42197
  safety_checks: 'PromptTemporarily',
42092
42198
  });
42199
+ this.temporarySafetyCheckPrompted = true;
42200
+ return true;
42093
42201
  }
42202
+ return false;
42094
42203
  });
42095
42204
  }
42096
42205
  dispose() { }
@@ -42117,6 +42226,36 @@ class TestInitializeDeviceDuration extends BaseMethod {
42117
42226
  }
42118
42227
  }
42119
42228
 
42229
+ const Log$a = getLogger(exports.LoggerNames.Core);
42230
+ const parseInitOptions$1 = (payload) => ({
42231
+ initSession: payload === null || payload === void 0 ? void 0 : payload.initSession,
42232
+ passphraseState: payload === null || payload === void 0 ? void 0 : payload.passphraseState,
42233
+ deriveCardano: payload === null || payload === void 0 ? void 0 : payload.deriveCardano,
42234
+ });
42235
+ class PreInitialize extends BaseMethod {
42236
+ init() {
42237
+ this.skipForceUpdateCheck = true;
42238
+ this.useDevicePassphraseState = false;
42239
+ this.isPreWarmSignal = true;
42240
+ }
42241
+ run() {
42242
+ return __awaiter(this, void 0, void 0, function* () {
42243
+ try {
42244
+ yield this.device.preInitialize(parseInitOptions$1(this.payload));
42245
+ if (this.device.hasDeviceAcquire()) {
42246
+ yield this.device.release();
42247
+ }
42248
+ return true;
42249
+ }
42250
+ catch (_a) {
42251
+ this.device.clearPreInitialized();
42252
+ Log$a.debug('[PRE-INIT][FAILED]');
42253
+ return false;
42254
+ }
42255
+ });
42256
+ }
42257
+ }
42258
+
42120
42259
  class SearchDevices extends BaseMethod {
42121
42260
  init() {
42122
42261
  this.useDevice = false;
@@ -42489,10 +42628,11 @@ class GetPassphraseState extends BaseMethod {
42489
42628
  allowCreateAttachPin: this.payload.allowCreateAttachPin,
42490
42629
  });
42491
42630
  const { features } = this.device;
42492
- const isPro2 = getDeviceType(features) === hdShared.EDeviceType.Pro2;
42493
42631
  const passphraseProtection = (_a = features === null || features === void 0 ? void 0 : features.passphrase_protection) !== null && _a !== void 0 ? _a : null;
42632
+ const deviceType = getDeviceType(features);
42633
+ const isProSeries = deviceType === hdShared.EDeviceType.Pro || deviceType === hdShared.EDeviceType.Pro2;
42494
42634
  return Promise.resolve({
42495
- passphrase_state: isPro2 || passphraseProtection === true ? passphraseState : undefined,
42635
+ passphrase_state: isProSeries || passphraseProtection === true ? passphraseState : undefined,
42496
42636
  session_id: (_b = newSession !== null && newSession !== void 0 ? newSession : features === null || features === void 0 ? void 0 : features.session_id) !== null && _b !== void 0 ? _b : undefined,
42497
42637
  unlocked_attach_pin: unlockedAttachPin !== null && unlockedAttachPin !== void 0 ? unlockedAttachPin : features === null || features === void 0 ? void 0 : features.unlocked_attach_pin,
42498
42638
  passphrase_protection: passphraseProtection,
@@ -43942,9 +44082,12 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
43942
44082
  type,
43943
44083
  }));
43944
44084
  };
43945
- this.postProgressMessage = (progress, progressType, metadata = {}) => {
43946
- this.postMessage(createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, Object.assign({ device: this.device.toMessageObject(), progress,
43947
- progressType }, metadata)));
44085
+ this.postProgressMessage = (progress, progressType) => {
44086
+ this.postMessage(createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
44087
+ device: this.device.toMessageObject(),
44088
+ progress,
44089
+ progressType,
44090
+ }));
43948
44091
  };
43949
44092
  }
43950
44093
  init() { }
@@ -44140,7 +44283,7 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
44140
44283
  });
44141
44284
  });
44142
44285
  }
44143
- emmcCommonUpdateProcess({ payload, filePath, processedSize, totalSize, transferStartTime = Date.now(), }) {
44286
+ emmcCommonUpdateProcess({ payload, filePath, processedSize, totalSize, }) {
44144
44287
  return __awaiter(this, void 0, void 0, function* () {
44145
44288
  if (!filePath.startsWith('0:')) {
44146
44289
  throw new Error('filePath must start with 0:');
@@ -44150,6 +44293,7 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
44150
44293
  const chunkSize = 1024 * perPackageSize;
44151
44294
  const totalChunks = Math.ceil(payload.byteLength / chunkSize);
44152
44295
  let offset = 0;
44296
+ let currentFileProcessed = 0;
44153
44297
  for (let i = 0; i < totalChunks; i++) {
44154
44298
  const chunkStart = i * chunkSize;
44155
44299
  const chunkEnd = Math.min(chunkStart + chunkSize, payload.byteLength);
@@ -44158,7 +44302,7 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
44158
44302
  const overwrite = i === 0;
44159
44303
  let progress;
44160
44304
  if (totalSize !== undefined && processedSize !== undefined) {
44161
- const currentFileProcessed = processedSize + chunkEnd;
44305
+ currentFileProcessed = processedSize + chunkEnd;
44162
44306
  progress = Math.min(Math.ceil((currentFileProcessed / totalSize) * 100), 99);
44163
44307
  }
44164
44308
  else {
@@ -44166,15 +44310,7 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
44166
44310
  }
44167
44311
  const writeRes = yield this.emmcFileWriteWithRetry(filePath, chunkLength, offset, chunk, overwrite, progress);
44168
44312
  offset += writeRes.message.processed_byte;
44169
- const elapsedMs = Date.now() - transferStartTime;
44170
- const transferredBytes = totalSize !== undefined && processedSize !== undefined ? processedSize + offset : offset;
44171
- const totalBytes = totalSize !== null && totalSize !== void 0 ? totalSize : payload.byteLength;
44172
- this.postProgressMessage(progress, 'transferData', {
44173
- transferredBytes,
44174
- totalBytes,
44175
- rateBytesPerSecond: elapsedMs > 0 ? Math.round((transferredBytes / elapsedMs) * 1000) : undefined,
44176
- elapsedMs,
44177
- });
44313
+ this.postProgressMessage(progress, 'transferData');
44178
44314
  }
44179
44315
  return totalSize !== undefined ? (processedSize !== null && processedSize !== void 0 ? processedSize : 0) + payload.byteLength : 0;
44180
44316
  });
@@ -45006,7 +45142,6 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
45006
45142
  totalSize += bootloaderBinary.byteLength;
45007
45143
  }
45008
45144
  this.postTipMessage(exports.FirmwareUpdateTipMessage.StartTransferData);
45009
- const transferStartTime = Date.now();
45010
45145
  if (resourceBinary) {
45011
45146
  const file = yield JSZip__default["default"].loadAsync(resourceBinary);
45012
45147
  const files = Object.entries(file.files);
@@ -45019,7 +45154,6 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
45019
45154
  filePath: `0:res/${name}`,
45020
45155
  processedSize,
45021
45156
  totalSize,
45022
- transferStartTime,
45023
45157
  });
45024
45158
  }
45025
45159
  }
@@ -45030,7 +45164,6 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
45030
45164
  filePath: `0:boot/bootloader.bin`,
45031
45165
  processedSize,
45032
45166
  totalSize,
45033
- transferStartTime,
45034
45167
  });
45035
45168
  }
45036
45169
  yield this.createUpdatesFolderIfNotExists(`0:updates/`);
@@ -45041,7 +45174,6 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
45041
45174
  filePath: `0:updates/${fwbinary.fileName}`,
45042
45175
  processedSize,
45043
45176
  totalSize,
45044
- transferStartTime,
45045
45177
  });
45046
45178
  }
45047
45179
  }
@@ -45647,7 +45779,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
45647
45779
  if (bootloaderBinary)
45648
45780
  totalSize += bootloaderBinary.byteLength;
45649
45781
  this.postTipMessage(exports.FirmwareUpdateTipMessage.StartTransferData);
45650
- const transferStartTime = Date.now();
45651
45782
  const targets = [];
45652
45783
  if (resourceBinary) {
45653
45784
  const resourcePath = `${PROTOCOL_V2_FIRMWARE_STAGING_VOLUME}res/`;
@@ -45663,7 +45794,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
45663
45794
  filePath: `${resourcePath}${name}`,
45664
45795
  processedSize,
45665
45796
  totalSize,
45666
- transferStartTime,
45667
45797
  });
45668
45798
  }
45669
45799
  }
@@ -45679,7 +45809,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
45679
45809
  filePath: bootloaderPath,
45680
45810
  processedSize,
45681
45811
  totalSize,
45682
- transferStartTime,
45683
45812
  });
45684
45813
  targets.push({
45685
45814
  target_id: ProtocolV2FirmwareTargetType.TARGET_BOOTLOADER,
@@ -45693,7 +45822,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
45693
45822
  filePath: firmwarePath,
45694
45823
  processedSize,
45695
45824
  totalSize,
45696
- transferStartTime,
45697
45825
  });
45698
45826
  targets.push({
45699
45827
  target_id: protocolV2FileNameToTargetId(fwbinary.fileName),
@@ -45863,7 +45991,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
45863
45991
  yield typedCall('FilesystemDirMake', 'Success', { path });
45864
45992
  });
45865
45993
  }
45866
- protocolV2CommonUpdateProcess({ payload, filePath, processedSize, totalSize, transferStartTime = Date.now(), }) {
45994
+ protocolV2CommonUpdateProcess({ payload, filePath, processedSize, totalSize, }) {
45867
45995
  var _a;
45868
45996
  return __awaiter(this, void 0, void 0, function* () {
45869
45997
  const chunkSize = this.getProtocolV2FirmwareChunkSize();
@@ -45886,17 +46014,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
45886
46014
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.EmmcFileWriteFirmwareError, `invalid processed_byte ${nextOffset} for offset ${offset}`);
45887
46015
  }
45888
46016
  offset = nextOffset;
45889
- const elapsedMs = Date.now() - transferStartTime;
45890
- const transferredBytes = totalSize !== undefined && processedSize !== undefined
45891
- ? Math.min(processedSize + offset, totalSize)
45892
- : offset;
45893
- const totalBytes = totalSize !== null && totalSize !== void 0 ? totalSize : payload.byteLength;
45894
- this.postProgressMessage(getUploadProgress(offset), 'transferData', {
45895
- transferredBytes,
45896
- totalBytes,
45897
- rateBytesPerSecond: elapsedMs > 0 ? Math.round((transferredBytes / elapsedMs) * 1000) : undefined,
45898
- elapsedMs,
45899
- });
46017
+ this.postProgressMessage(getUploadProgress(offset), 'transferData');
45900
46018
  }
45901
46019
  return totalSize !== undefined ? (processedSize !== null && processedSize !== void 0 ? processedSize : 0) + payload.byteLength : 0;
45902
46020
  });
@@ -46956,6 +47074,15 @@ class AllNetworkGetAddressBase extends BaseMethod {
46956
47074
  this.device.on(DEVICE.PIN, onSignalAbort);
46957
47075
  this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
46958
47076
  preCheckDeviceSupport(this.device, method);
47077
+ if (this.temporarySafetyCheckPrompted) {
47078
+ method.temporarySafetyCheckPrompted = true;
47079
+ }
47080
+ else {
47081
+ const appliedTemporarySafetyCheck = yield method.checkSafetyLevelOnTestNet();
47082
+ if (appliedTemporarySafetyCheck) {
47083
+ this.temporarySafetyCheckPrompted = true;
47084
+ }
47085
+ }
46959
47086
  const response = yield method.run();
46960
47087
  if (!Array.isArray(response) || response.length === 0) {
46961
47088
  throw new Error('No response');
@@ -47846,6 +47973,7 @@ class BTCSignMessage extends BaseMethod {
47846
47973
  init() {
47847
47974
  this.checkDeviceId = true;
47848
47975
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
47976
+ this.allowUsePreInitialize = true;
47849
47977
  validateParams(this.payload, [
47850
47978
  { name: 'path', required: true },
47851
47979
  { name: 'messageHex', type: 'hexString', required: true },
@@ -47902,6 +48030,7 @@ class BTCSignPsbt extends BaseMethod {
47902
48030
  init() {
47903
48031
  this.checkDeviceId = true;
47904
48032
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
48033
+ this.allowUsePreInitialize = true;
47905
48034
  validateParams(this.payload, [
47906
48035
  { name: 'psbt', type: 'hexString', required: true },
47907
48036
  { name: 'coin', type: 'string' },
@@ -48220,6 +48349,7 @@ class BTCSignTransaction extends BaseMethod {
48220
48349
  init() {
48221
48350
  this.checkDeviceId = true;
48222
48351
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
48352
+ this.allowUsePreInitialize = true;
48223
48353
  validateParams(this.payload, [
48224
48354
  { name: 'coin', type: 'string', required: true },
48225
48355
  { name: 'inputs', type: 'array', required: true },
@@ -48400,6 +48530,7 @@ class ConfluxGetAddress extends BaseMethod {
48400
48530
  class ConfluxSignMessage extends BaseMethod {
48401
48531
  init() {
48402
48532
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
48533
+ this.allowUsePreInitialize = true;
48403
48534
  validateParams(this.payload, [
48404
48535
  { name: 'path', required: true },
48405
48536
  { name: 'messageHex', type: 'hexString', required: true },
@@ -48429,6 +48560,7 @@ class ConfluxSignMessage extends BaseMethod {
48429
48560
  class ConfluxSignMessageCIP23 extends BaseMethod {
48430
48561
  init() {
48431
48562
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
48563
+ this.allowUsePreInitialize = true;
48432
48564
  validateParams(this.payload, [
48433
48565
  { name: 'path', required: true },
48434
48566
  { name: 'domainHash', type: 'hexString', required: true },
@@ -48514,6 +48646,7 @@ class ConfluxSignTransaction extends BaseMethod {
48514
48646
  }
48515
48647
  init() {
48516
48648
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
48649
+ this.allowUsePreInitialize = true;
48517
48650
  validateParams(this.payload, [
48518
48651
  { name: 'path', required: true },
48519
48652
  { name: 'transaction', type: 'object', required: true },
@@ -48757,10 +48890,12 @@ class EVMSignMessage$2 extends BaseMethod {
48757
48890
  init() {
48758
48891
  this.checkDeviceId = true;
48759
48892
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
48893
+ this.allowUsePreInitialize = true;
48760
48894
  validateParams(this.payload, [
48761
48895
  { name: 'path', required: true },
48762
48896
  { name: 'messageHex', type: 'hexString', required: true },
48763
48897
  { name: 'chainId', type: 'number' },
48898
+ { name: 'usePreInitialize', type: 'boolean' },
48764
48899
  ]);
48765
48900
  const { path, messageHex, chainId } = this.payload;
48766
48901
  const addressN = validatePath(path, 3);
@@ -48790,6 +48925,7 @@ class EVMSignMessageEIP712 extends BaseMethod {
48790
48925
  init() {
48791
48926
  this.checkDeviceId = true;
48792
48927
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
48928
+ this.allowUsePreInitialize = true;
48793
48929
  validateParams(this.payload, [
48794
48930
  { name: 'path', required: true },
48795
48931
  { name: 'domainHash', type: 'hexString', required: true },
@@ -49030,9 +49166,11 @@ class EVMSignTransaction extends BaseMethod {
49030
49166
  init() {
49031
49167
  this.checkDeviceId = true;
49032
49168
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
49169
+ this.allowUsePreInitialize = true;
49033
49170
  validateParams(this.payload, [
49034
49171
  { name: 'path', required: true },
49035
49172
  { name: 'transaction', type: 'object', required: true },
49173
+ { name: 'usePreInitialize', type: 'boolean' },
49036
49174
  ]);
49037
49175
  const { path, transaction } = this.payload;
49038
49176
  this.addressN = validatePath(path, 3);
@@ -49299,6 +49437,7 @@ class EVMSignTypedData extends BaseMethod {
49299
49437
  init() {
49300
49438
  this.checkDeviceId = true;
49301
49439
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
49440
+ this.allowUsePreInitialize = true;
49302
49441
  validateParams(this.payload, [
49303
49442
  { name: 'path', required: true },
49304
49443
  { name: 'metamaskV4Compat', type: 'boolean' },
@@ -49306,6 +49445,7 @@ class EVMSignTypedData extends BaseMethod {
49306
49445
  { name: 'domainHash', type: 'hexString' },
49307
49446
  { name: 'messageHash', type: 'hexString' },
49308
49447
  { name: 'chainId', type: 'number' },
49448
+ { name: 'usePreInitialize', type: 'boolean' },
49309
49449
  ]);
49310
49450
  const { path, data, metamaskV4Compat, domainHash, messageHash, chainId } = this.payload;
49311
49451
  const addressN = validatePath(path, 3);
@@ -49852,6 +49992,7 @@ class StarcoinSignMessage extends BaseMethod {
49852
49992
  init() {
49853
49993
  this.checkDeviceId = true;
49854
49994
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
49995
+ this.allowUsePreInitialize = true;
49855
49996
  validateParams(this.payload, [
49856
49997
  { name: 'path', required: true },
49857
49998
  { name: 'messageHex', type: 'hexString', required: true },
@@ -49875,6 +50016,7 @@ class StarcoinSignTransaction extends BaseMethod {
49875
50016
  init() {
49876
50017
  this.checkDeviceId = true;
49877
50018
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
50019
+ this.allowUsePreInitialize = true;
49878
50020
  validateParams(this.payload, [
49879
50021
  { name: 'path', required: true },
49880
50022
  { name: 'rawTx', type: 'hexString', required: true },
@@ -50143,6 +50285,7 @@ class NEMSignTransaction extends BaseMethod {
50143
50285
  init() {
50144
50286
  this.checkDeviceId = true;
50145
50287
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
50288
+ this.allowUsePreInitialize = true;
50146
50289
  validateParams(this.payload, [
50147
50290
  { name: 'path', required: true },
50148
50291
  { name: 'transaction', type: 'object', required: true },
@@ -50220,6 +50363,7 @@ class SolSignTransaction extends BaseMethod {
50220
50363
  var _a;
50221
50364
  this.checkDeviceId = true;
50222
50365
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
50366
+ this.allowUsePreInitialize = true;
50223
50367
  this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
50224
50368
  const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
50225
50369
  validateParams(payload, [{ name: 'bundle', type: 'array' }]);
@@ -50305,6 +50449,7 @@ class SolSignOffchainMessage extends BaseMethod {
50305
50449
  init() {
50306
50450
  this.checkDeviceId = true;
50307
50451
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
50452
+ this.allowUsePreInitialize = true;
50308
50453
  validateParams(this.payload, [
50309
50454
  { name: 'path', required: true },
50310
50455
  { name: 'messageHex', type: 'hexString', required: true },
@@ -50351,6 +50496,7 @@ class SolSignMessage extends BaseMethod {
50351
50496
  init() {
50352
50497
  this.checkDeviceId = true;
50353
50498
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
50499
+ this.allowUsePreInitialize = true;
50354
50500
  validateParams(this.payload, [
50355
50501
  { name: 'path', required: true },
50356
50502
  { name: 'messageHex', type: 'hexString', required: true },
@@ -50672,6 +50818,7 @@ class StellarSignTransaction extends BaseMethod {
50672
50818
  init() {
50673
50819
  this.checkDeviceId = true;
50674
50820
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
50821
+ this.allowUsePreInitialize = true;
50675
50822
  validateParams(this.payload, [
50676
50823
  { name: 'path', required: true },
50677
50824
  { name: 'networkPassphrase', type: 'string', required: true },
@@ -50782,6 +50929,7 @@ class TronSignMessage extends BaseMethod {
50782
50929
  var _a;
50783
50930
  this.checkDeviceId = true;
50784
50931
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
50932
+ this.allowUsePreInitialize = true;
50785
50933
  validateParams(this.payload, [
50786
50934
  { name: 'path', required: true },
50787
50935
  { name: 'messageHex', type: 'hexString', required: true },
@@ -50940,6 +51088,7 @@ class TronSignTransaction extends BaseMethod {
50940
51088
  init() {
50941
51089
  this.checkDeviceId = true;
50942
51090
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
51091
+ this.allowUsePreInitialize = true;
50943
51092
  validateParams(this.payload, [
50944
51093
  { name: 'path', required: true },
50945
51094
  { name: 'transaction', type: 'object', required: true },
@@ -51073,6 +51222,7 @@ class NearSignTransaction extends BaseMethod {
51073
51222
  init() {
51074
51223
  this.checkDeviceId = true;
51075
51224
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
51225
+ this.allowUsePreInitialize = true;
51076
51226
  validateParams(this.payload, [
51077
51227
  { name: 'path', required: true },
51078
51228
  { name: 'rawTx', type: 'hexString', required: true },
@@ -51249,6 +51399,7 @@ class AptosSignTransaction extends BaseMethod {
51249
51399
  init() {
51250
51400
  this.checkDeviceId = true;
51251
51401
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
51402
+ this.allowUsePreInitialize = true;
51252
51403
  validateParams(this.payload, [
51253
51404
  { name: 'path', required: true },
51254
51405
  { name: 'rawTx', type: 'hexString', required: true },
@@ -51299,6 +51450,7 @@ class AptosSignMessage extends BaseMethod {
51299
51450
  init() {
51300
51451
  this.checkDeviceId = true;
51301
51452
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
51453
+ this.allowUsePreInitialize = true;
51302
51454
  validateParams(this.payload, [
51303
51455
  { name: 'path', required: true },
51304
51456
  { name: 'payload', type: 'object', required: true },
@@ -51360,6 +51512,7 @@ class AptosSignInMessage extends BaseMethod {
51360
51512
  init() {
51361
51513
  this.checkDeviceId = true;
51362
51514
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
51515
+ this.allowUsePreInitialize = true;
51363
51516
  validateParams(this.payload, [
51364
51517
  { name: 'path', required: true },
51365
51518
  { name: 'payload', type: 'string', required: true },
@@ -51455,6 +51608,7 @@ class AlgoSignTransaction extends BaseMethod {
51455
51608
  init() {
51456
51609
  this.checkDeviceId = true;
51457
51610
  this.allowDeviceMode = [...this.allowDeviceMode];
51611
+ this.allowUsePreInitialize = true;
51458
51612
  validateParams(this.payload, [
51459
51613
  { name: 'path', required: true },
51460
51614
  { name: 'rawTx', type: 'hexString', required: true },
@@ -51617,6 +51771,7 @@ class CosmosSignTransaction extends BaseMethod {
51617
51771
  init() {
51618
51772
  this.checkDeviceId = true;
51619
51773
  this.allowDeviceMode = [...this.allowDeviceMode];
51774
+ this.allowUsePreInitialize = true;
51620
51775
  validateParams(this.payload, [
51621
51776
  { name: 'path', required: true },
51622
51777
  { name: 'rawTx', type: 'hexString', required: true },
@@ -51738,6 +51893,7 @@ class XrpGetAddress extends BaseMethod {
51738
51893
  init() {
51739
51894
  this.checkDeviceId = true;
51740
51895
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
51896
+ this.allowUsePreInitialize = true;
51741
51897
  const { payload } = this;
51742
51898
  validateParams(payload, [
51743
51899
  { name: 'path', required: true },
@@ -51964,6 +52120,7 @@ class SuiSignMessage extends BaseMethod {
51964
52120
  init() {
51965
52121
  this.checkDeviceId = true;
51966
52122
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
52123
+ this.allowUsePreInitialize = true;
51967
52124
  validateParams(this.payload, [
51968
52125
  { name: 'path', required: true },
51969
52126
  { name: 'messageHex', type: 'hexString', required: true },
@@ -52020,6 +52177,7 @@ class SuiSignTransaction extends BaseMethod {
52020
52177
  init() {
52021
52178
  this.checkDeviceId = true;
52022
52179
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
52180
+ this.allowUsePreInitialize = true;
52023
52181
  validateParams(this.payload, [
52024
52182
  { name: 'path', required: true },
52025
52183
  { name: 'rawTx', type: 'hexString', required: true },
@@ -52826,6 +52984,7 @@ class CardanoSignTransaction extends BaseMethod {
52826
52984
  var _a;
52827
52985
  this.checkDeviceId = true;
52828
52986
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
52987
+ this.allowUsePreInitialize = true;
52829
52988
  this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
52830
52989
  const { payload } = this;
52831
52990
  if (payload.auxiliaryData && payload.auxiliaryData.governanceRegistrationParameters) {
@@ -53061,6 +53220,7 @@ class CardanoSignMessage extends BaseMethod {
53061
53220
  init() {
53062
53221
  this.checkDeviceId = true;
53063
53222
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
53223
+ this.allowUsePreInitialize = true;
53064
53224
  const { payload } = this;
53065
53225
  validateParams(payload, [
53066
53226
  { name: 'path', type: 'string', required: true },
@@ -53174,6 +53334,7 @@ class FilecoinSignTransaction extends BaseMethod {
53174
53334
  init() {
53175
53335
  this.checkDeviceId = true;
53176
53336
  this.allowDeviceMode = [...this.allowDeviceMode];
53337
+ this.allowUsePreInitialize = true;
53177
53338
  validateParams(this.payload, [
53178
53339
  { name: 'path', required: true },
53179
53340
  { name: 'rawTx', type: 'hexString', required: true },
@@ -53344,6 +53505,7 @@ class PolkadotSignTransaction extends BaseMethod {
53344
53505
  init() {
53345
53506
  this.checkDeviceId = true;
53346
53507
  this.allowDeviceMode = [...this.allowDeviceMode];
53508
+ this.allowUsePreInitialize = true;
53347
53509
  validateParams(this.payload, [
53348
53510
  { name: 'path', required: true },
53349
53511
  { name: 'network', required: true },
@@ -53766,6 +53928,7 @@ class KaspaSignTransaction extends BaseMethod {
53766
53928
  var _a, _b, _c, _d, _e;
53767
53929
  this.checkDeviceId = true;
53768
53930
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
53931
+ this.allowUsePreInitialize = true;
53769
53932
  const payload = this.payload;
53770
53933
  validateParams(payload, [
53771
53934
  { name: 'version', type: 'number' },
@@ -53942,6 +54105,7 @@ class NexaSignTransaction extends BaseMethod {
53942
54105
  this.hasBundle = false;
53943
54106
  }
53944
54107
  init() {
54108
+ this.allowUsePreInitialize = true;
53945
54109
  const payload = this.payload;
53946
54110
  payload.inputs.forEach(input => {
53947
54111
  validateParams(input, [
@@ -54097,6 +54261,7 @@ class NostrSignEvent extends BaseMethod {
54097
54261
  init() {
54098
54262
  this.checkDeviceId = true;
54099
54263
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
54264
+ this.allowUsePreInitialize = true;
54100
54265
  const { payload } = this;
54101
54266
  if (!validateEvent(payload.event)) {
54102
54267
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Can't serialize event with wrong or missing properties`);
@@ -54239,6 +54404,7 @@ class NostrSignSchnorr extends BaseMethod {
54239
54404
  init() {
54240
54405
  this.checkDeviceId = true;
54241
54406
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
54407
+ this.allowUsePreInitialize = true;
54242
54408
  const { payload } = this;
54243
54409
  validateParams(payload, [
54244
54410
  { name: 'path', required: true },
@@ -54406,6 +54572,7 @@ class NervosSignTransaction extends BaseMethod {
54406
54572
  init() {
54407
54573
  this.checkDeviceId = true;
54408
54574
  this.allowDeviceMode = [...this.allowDeviceMode];
54575
+ this.allowUsePreInitialize = true;
54409
54576
  validateParams(this.payload, [
54410
54577
  { name: 'path', required: true },
54411
54578
  { name: 'rawTx', type: 'hexString', required: true },
@@ -54521,6 +54688,7 @@ class DnxSignTransaction extends BaseMethod {
54521
54688
  init() {
54522
54689
  this.checkDeviceId = true;
54523
54690
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
54691
+ this.allowUsePreInitialize = true;
54524
54692
  const { payload } = this;
54525
54693
  const addressN = validatePath(payload.path, 3);
54526
54694
  validateParams(payload, [
@@ -54709,6 +54877,7 @@ class TonSignMessage extends BaseMethod {
54709
54877
  this.strictCheckDeviceSupport = true;
54710
54878
  this.checkDeviceId = true;
54711
54879
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
54880
+ this.allowUsePreInitialize = true;
54712
54881
  validateParams(this.payload, [
54713
54882
  { name: 'path', required: true },
54714
54883
  { name: 'destination', type: 'string' },
@@ -54856,6 +55025,7 @@ class TonSignProof extends BaseMethod {
54856
55025
  this.strictCheckDeviceSupport = true;
54857
55026
  this.checkDeviceId = true;
54858
55027
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
55028
+ this.allowUsePreInitialize = true;
54859
55029
  validateParams(this.payload, [
54860
55030
  { name: 'path', required: true },
54861
55031
  { name: 'appdomain', type: 'string' },
@@ -54907,6 +55077,7 @@ class TonSignData extends BaseMethod {
54907
55077
  this.strictCheckDeviceSupport = false;
54908
55078
  this.checkDeviceId = true;
54909
55079
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
55080
+ this.allowUsePreInitialize = true;
54910
55081
  validateParams(this.payload, [
54911
55082
  { name: 'path', required: true },
54912
55083
  { name: 'type', type: 'number', required: true },
@@ -55034,6 +55205,7 @@ class ScdoSignTransaction extends BaseMethod {
55034
55205
  init() {
55035
55206
  this.checkDeviceId = true;
55036
55207
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
55208
+ this.allowUsePreInitialize = true;
55037
55209
  validateParams(this.payload, [
55038
55210
  { name: 'path', required: true },
55039
55211
  { name: 'nonce', required: true },
@@ -55091,6 +55263,7 @@ class ScdoSignMessage extends BaseMethod {
55091
55263
  init() {
55092
55264
  this.checkDeviceId = true;
55093
55265
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
55266
+ this.allowUsePreInitialize = true;
55094
55267
  validateParams(this.payload, [
55095
55268
  { name: 'path', required: true },
55096
55269
  { name: 'messageHex', type: 'hexString', required: true },
@@ -55221,6 +55394,7 @@ class AlephiumSignTransaction extends BaseMethod {
55221
55394
  init() {
55222
55395
  this.checkDeviceId = true;
55223
55396
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
55397
+ this.allowUsePreInitialize = true;
55224
55398
  validateParams(this.payload, [
55225
55399
  { name: 'path', required: true },
55226
55400
  { name: 'rawTx', required: true, type: 'hexString' },
@@ -55266,6 +55440,7 @@ class AlephiumSignMessage extends BaseMethod {
55266
55440
  init() {
55267
55441
  this.checkDeviceId = true;
55268
55442
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
55443
+ this.allowUsePreInitialize = true;
55269
55444
  validateParams(this.payload, [
55270
55445
  { name: 'path', required: true },
55271
55446
  { name: 'messageHex', type: 'hexString', required: true },
@@ -55483,6 +55658,7 @@ class BenfenSignMessage extends BaseMethod {
55483
55658
  init() {
55484
55659
  this.checkDeviceId = true;
55485
55660
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
55661
+ this.allowUsePreInitialize = true;
55486
55662
  validateParams(this.payload, [
55487
55663
  { name: 'path', required: true },
55488
55664
  { name: 'messageHex', type: 'hexString', required: true },
@@ -55540,6 +55716,7 @@ class BenfenSignTransaction extends BaseMethod {
55540
55716
  init() {
55541
55717
  this.checkDeviceId = true;
55542
55718
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
55719
+ this.allowUsePreInitialize = true;
55543
55720
  validateParams(this.payload, [
55544
55721
  { name: 'path', required: true },
55545
55722
  { name: 'rawTx', type: 'hexString', required: true },
@@ -55655,6 +55832,7 @@ class NeoSignTransaction extends BaseMethod {
55655
55832
  init() {
55656
55833
  this.checkDeviceId = true;
55657
55834
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
55835
+ this.allowUsePreInitialize = true;
55658
55836
  this.strictCheckDeviceSupport = true;
55659
55837
  validateParams(this.payload, [
55660
55838
  { name: 'path', required: true },
@@ -55703,6 +55881,7 @@ class NeoSignTransaction extends BaseMethod {
55703
55881
  var ApiMethods = /*#__PURE__*/Object.freeze({
55704
55882
  __proto__: null,
55705
55883
  testInitializeDeviceDuration: TestInitializeDeviceDuration,
55884
+ preInitialize: PreInitialize,
55706
55885
  searchDevices: SearchDevices,
55707
55886
  getFeatures: GetFeatures,
55708
55887
  getDeviceInfo: GetDeviceInfo,
@@ -56091,13 +56270,15 @@ class RequestQueue {
56091
56270
  this.pendingCallbackTasks.set(connectId, callbackPromise);
56092
56271
  callbackPromise.promise.finally(() => {
56093
56272
  Log$1.debug(`Callback task completed for connectId: ${connectId}`);
56094
- this.pendingCallbackTasks.delete(connectId);
56273
+ if (this.pendingCallbackTasks.get(connectId) === callbackPromise) {
56274
+ this.pendingCallbackTasks.delete(connectId);
56275
+ }
56095
56276
  });
56096
56277
  }
56097
- waitForPendingCallbackTasks(connectId) {
56278
+ waitForPendingCallbackTasks(connectId, exceptTask) {
56098
56279
  return __awaiter(this, void 0, void 0, function* () {
56099
56280
  const pendingTask = this.pendingCallbackTasks.get(connectId);
56100
- if (pendingTask) {
56281
+ if (pendingTask && pendingTask !== exceptTask) {
56101
56282
  Log$1.debug(`Waiting for pending callback task to complete for connectId: ${connectId}`);
56102
56283
  yield pendingTask.promise;
56103
56284
  }
@@ -56134,6 +56315,9 @@ const getSynchronize = (mutex) => {
56134
56315
  };
56135
56316
 
56136
56317
  const Log = getLogger(exports.LoggerNames.Core);
56318
+ const PRE_INITIALIZE_TTL_MS = 60 * 1000;
56319
+ const preWarmInflight = new Map();
56320
+ const preWarmDoneAt = new Map();
56137
56321
  function hasDeriveCardano(method) {
56138
56322
  var _a;
56139
56323
  if (method.name.startsWith('allNetworkGetAddress') &&
@@ -56156,8 +56340,7 @@ let _deviceList;
56156
56340
  let _connector;
56157
56341
  let _uiPromises = [];
56158
56342
  const deviceCacheMap = new Map();
56159
- let pollingId = 1;
56160
- const pollingState = {};
56343
+ const pollingManager = new PollingStateManager();
56161
56344
  let preConnectCache = {
56162
56345
  passphraseState: undefined,
56163
56346
  };
@@ -56234,8 +56417,44 @@ const callAPI = (context, message) => __awaiter(void 0, void 0, void 0, function
56234
56417
  if (error) {
56235
56418
  return createResponseMessage(method.responseID, false, { error });
56236
56419
  }
56420
+ if (method.isPreWarmSignal) {
56421
+ return handlePreWarmSignal(context, message, method);
56422
+ }
56237
56423
  return onCallDevice(context, message, method);
56238
56424
  });
56425
+ const handlePreWarmSignal = (context, message, method) => __awaiter(void 0, void 0, void 0, function* () {
56426
+ if (!method.connectId) {
56427
+ return createResponseMessage(method.responseID, true, true);
56428
+ }
56429
+ const key = method.getPreWarmKey();
56430
+ const inflight = preWarmInflight.get(key);
56431
+ if (inflight) {
56432
+ try {
56433
+ yield inflight;
56434
+ }
56435
+ catch (_b) {
56436
+ }
56437
+ return createResponseMessage(method.responseID, true, true);
56438
+ }
56439
+ const doneAt = preWarmDoneAt.get(key);
56440
+ if (typeof doneAt === 'number' && Date.now() - doneAt <= method.preWarmTtl) {
56441
+ return createResponseMessage(method.responseID, true, true);
56442
+ }
56443
+ const run = onCallDevice(context, message, method);
56444
+ preWarmInflight.set(key, run);
56445
+ try {
56446
+ const result = yield run;
56447
+ if ((result === null || result === void 0 ? void 0 : result.success) === true && (result === null || result === void 0 ? void 0 : result.payload) === true) {
56448
+ preWarmDoneAt.set(key, Date.now());
56449
+ }
56450
+ return result;
56451
+ }
56452
+ finally {
56453
+ if (preWarmInflight.get(key) === run) {
56454
+ preWarmInflight.delete(key);
56455
+ }
56456
+ }
56457
+ });
56239
56458
  const waitWithTimeout = (promise, timeout) => __awaiter(void 0, void 0, void 0, function* () {
56240
56459
  const timeoutPromise = new Promise((_, reject) => {
56241
56460
  setTimeout(() => reject(new Error('Request timeout')), timeout);
@@ -56256,11 +56475,13 @@ const waitForPendingPromise = (getPrePendingCallPromise, removePrePendingCallPro
56256
56475
  }
56257
56476
  });
56258
56477
  const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, void 0, function* () {
56259
- var _b, _c, _d, _e;
56478
+ var _c, _d, _e, _f, _g;
56260
56479
  let messageResponse;
56261
56480
  const { requestQueue, getPrePendingCallPromise, setPrePendingCallPromise } = context;
56262
56481
  updateMethodRequestContext(method, { status: 'running' });
56263
- const connectStateChange = preConnectCache.passphraseState !== method.payload.passphraseState;
56482
+ const normalizePassphraseState = (s) => s || '';
56483
+ const connectStateChange = normalizePassphraseState(preConnectCache.passphraseState) !==
56484
+ normalizePassphraseState(method.payload.passphraseState);
56264
56485
  preConnectCache = {
56265
56486
  passphraseState: method.payload.passphraseState,
56266
56487
  };
@@ -56273,15 +56494,19 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
56273
56494
  }
56274
56495
  yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
56275
56496
  const task = requestQueue.createTask(method);
56497
+ let preWarmCallbackTask;
56498
+ if (method.isPreWarmSignal && method.connectId) {
56499
+ preWarmCallbackTask = hdShared.createDeferred();
56500
+ context.registerCallbackTask(method.connectId, preWarmCallbackTask);
56501
+ }
56276
56502
  let device;
56277
56503
  try {
56278
- if (pollingState[pollingId]) {
56279
- pollingState[pollingId] = false;
56280
- }
56281
- pollingId += 1;
56282
- device = yield ensureConnected(context, method, pollingId, (_b = task.abortController) === null || _b === void 0 ? void 0 : _b.signal);
56504
+ const connectId = (_c = method.connectId) !== null && _c !== void 0 ? _c : '';
56505
+ const pollingId = pollingManager.start(connectId);
56506
+ device = yield ensureConnected(context, method, connectId, pollingId, (_d = task.abortController) === null || _d === void 0 ? void 0 : _d.signal);
56283
56507
  }
56284
56508
  catch (e) {
56509
+ preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
56285
56510
  console.log('ensureConnected error: ', e);
56286
56511
  completeMethodRequestContext(method, e);
56287
56512
  if (e.name === 'AbortError' || e.message === 'Request aborted') {
@@ -56293,16 +56518,17 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
56293
56518
  requestQueue.releaseTask(method.responseID);
56294
56519
  return createResponseMessage(method.responseID, false, { error: e });
56295
56520
  }
56296
- if ((_c = method.payload) === null || _c === void 0 ? void 0 : _c.onlyConnectBleDevice) {
56521
+ if ((_e = method.payload) === null || _e === void 0 ? void 0 : _e.onlyConnectBleDevice) {
56522
+ preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
56297
56523
  Log.debug('Call API - only connect ble device: ', device === null || device === void 0 ? void 0 : device.mainId);
56298
56524
  return createResponseMessage(method.responseID, true, null);
56299
56525
  }
56300
56526
  Log.debug('Call API - setDevice: ', device.mainId);
56301
- (_d = method.setDevice) === null || _d === void 0 ? void 0 : _d.call(method, device);
56527
+ (_f = method.setDevice) === null || _f === void 0 ? void 0 : _f.call(method, device);
56302
56528
  method.context = context;
56303
56529
  updateMethodRequestContext(method, {
56304
56530
  deviceInstanceId: device.instanceId,
56305
- commandsInstanceId: (_e = device.commands) === null || _e === void 0 ? void 0 : _e.instanceId,
56531
+ commandsInstanceId: (_g = device.commands) === null || _g === void 0 ? void 0 : _g.instanceId,
56306
56532
  });
56307
56533
  const activeRequests = getActiveRequestsByDeviceInstance(device.instanceId);
56308
56534
  if (activeRequests.length > 0) {
@@ -56317,11 +56543,11 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
56317
56543
  device.on(DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE, onSelectDeviceForSwitchFirmwareWebDeviceHandler);
56318
56544
  try {
56319
56545
  if (method.connectId) {
56320
- yield context.waitForCallbackTasks(method.connectId);
56546
+ yield context.waitForCallbackTasks(method.connectId, preWarmCallbackTask);
56321
56547
  }
56322
56548
  yield waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
56323
56549
  const inner = () => __awaiter(void 0, void 0, void 0, function* () {
56324
- var _f, _g, _h, _j, _k;
56550
+ var _h, _j, _k, _l, _m;
56325
56551
  const versionRange = getMethodVersionRange(device.features, type => method.getVersionRange()[type]);
56326
56552
  if (device.features) {
56327
56553
  yield DataManager.checkAndReloadData();
@@ -56411,7 +56637,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
56411
56637
  require: support.require,
56412
56638
  }));
56413
56639
  }
56414
- 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);
56640
+ 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);
56415
56641
  checkPassphraseEnableState(method, device.features);
56416
56642
  if (!passphraseStateSafety) {
56417
56643
  DevicePool.clearDeviceCache(method.payload.connectId);
@@ -56428,10 +56654,9 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
56428
56654
  : hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'open safety check failed.');
56429
56655
  throw error;
56430
56656
  }
56431
- (_k = (_j = method.device) === null || _j === void 0 ? void 0 : _j.commands) === null || _k === void 0 ? void 0 : _k.checkDisposed();
56657
+ (_m = (_l = method.device) === null || _l === void 0 ? void 0 : _l.commands) === null || _m === void 0 ? void 0 : _m.checkDisposed();
56432
56658
  try {
56433
56659
  const response = yield method.run();
56434
- Log.debug('Call API - Inner Method Run: ');
56435
56660
  messageResponse = createResponseMessage(method.responseID, true, response);
56436
56661
  requestQueue.resolveRequest(method.responseID, messageResponse);
56437
56662
  completeMethodRequestContext(method);
@@ -56448,7 +56673,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
56448
56673
  }
56449
56674
  });
56450
56675
  Log.debug('Call API - Device Run: ', device.mainId);
56451
- const runOptions = Object.assign({ keepSession: method.payload.keepSession }, parseInitOptions(method));
56676
+ const runOptions = Object.assign({ keepSession: method.payload.keepSession, skipInitialize: canSkipInitialize(method, device) }, parseInitOptions(method));
56452
56677
  const deviceRun = () => device.run(inner, runOptions);
56453
56678
  task.callPromise = hdShared.createDeferred(deviceRun);
56454
56679
  try {
@@ -56467,6 +56692,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
56467
56692
  completeMethodRequestContext(method, error);
56468
56693
  }
56469
56694
  finally {
56695
+ preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
56470
56696
  const response = messageResponse;
56471
56697
  if (response) {
56472
56698
  if (method) {
@@ -56562,7 +56788,30 @@ function initDeviceForBle(method) {
56562
56788
  device.deviceConnector = _connector;
56563
56789
  return device;
56564
56790
  }
56565
- let bleTimeoutRetry = 0;
56791
+ function canSkipInitialize(method, device) {
56792
+ var _a;
56793
+ const reasons = [];
56794
+ if (!method.allowUsePreInitialize)
56795
+ reasons.push('method.disallow');
56796
+ if (!((_a = method.payload) === null || _a === void 0 ? void 0 : _a.usePreInitialize))
56797
+ reasons.push('payload.usePreInitialize=false');
56798
+ if (!method.connectId)
56799
+ reasons.push('connectId.missing');
56800
+ if (!device.isPreInitializeMetaMatch(method.payload))
56801
+ reasons.push('meta.mismatch');
56802
+ if (!device.features)
56803
+ reasons.push('features.missing');
56804
+ if (!device.isPreInitializedValid(PRE_INITIALIZE_TTL_MS))
56805
+ reasons.push('ttl.expired');
56806
+ if (reasons.length) {
56807
+ Log.debug(`[PRE-INIT][MISS] method=${method.name} ${reasons.join(',')}`);
56808
+ return false;
56809
+ }
56810
+ const savedMs = device.getLastInitializeDuration();
56811
+ const saved = typeof savedMs === 'number' ? `saved ${savedMs}ms` : 'within TTL + meta match';
56812
+ Log.debug(`[PRE-INIT][HIT] method=${method.name} skip Initialize (${saved})`);
56813
+ return true;
56814
+ }
56566
56815
  function isRetryableBleProtocolV2ProbeError(method, error) {
56567
56816
  const message = error instanceof Error ? error.message : String(error !== null && error !== void 0 ? error : '');
56568
56817
  return (method.payload.connectProtocol === 'V2' &&
@@ -56570,7 +56819,7 @@ function isRetryableBleProtocolV2ProbeError(method, error) {
56570
56819
  message.includes('expected V2') &&
56571
56820
  message.includes('did not respond to expected protocol'));
56572
56821
  }
56573
- function connectDeviceForBle(method, device) {
56822
+ function connectDeviceForBle(method, device, retryCount = 0) {
56574
56823
  var _a;
56575
56824
  return __awaiter(this, void 0, void 0, function* () {
56576
56825
  try {
@@ -56578,17 +56827,23 @@ function connectDeviceForBle(method, device) {
56578
56827
  if ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.onlyConnectBleDevice) {
56579
56828
  return;
56580
56829
  }
56581
- yield device.initialize(parseInitOptions(method));
56830
+ if (!canSkipInitialize(method, device)) {
56831
+ const initOptions = parseInitOptions(method);
56832
+ yield device.initialize(initOptions);
56833
+ device.markPreInitialized({
56834
+ passphraseState: initOptions.passphraseState,
56835
+ });
56836
+ }
56582
56837
  }
56583
56838
  catch (err) {
56584
56839
  if ((err.errorCode === hdShared.HardwareErrorCode.BleTimeoutError ||
56585
56840
  err.errorCode === hdShared.HardwareErrorCode.BleConnectedError ||
56586
56841
  isRetryableBleProtocolV2ProbeError(method, err)) &&
56587
- bleTimeoutRetry <= 5) {
56588
- bleTimeoutRetry += 1;
56589
- Log.debug(`Bletooth connect timeout and will retry, retry count: ${bleTimeoutRetry}`);
56842
+ retryCount < 6) {
56843
+ const nextRetry = retryCount + 1;
56844
+ Log.debug(`Bluetooth connect timeout and will retry, retry count: ${nextRetry}`);
56590
56845
  yield wait(3000);
56591
- yield connectDeviceForBle(method, device);
56846
+ yield connectDeviceForBle(method, device, nextRetry);
56592
56847
  }
56593
56848
  else {
56594
56849
  throw err;
@@ -56596,7 +56851,7 @@ function connectDeviceForBle(method, device) {
56596
56851
  }
56597
56852
  });
56598
56853
  }
56599
- const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(void 0, void 0, void 0, function* () {
56854
+ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) => __awaiter(void 0, void 0, void 0, function* () {
56600
56855
  let tryCount = 0;
56601
56856
  const MAX_RETRY_COUNT = method.payload && typeof method.payload.retryCount === 'number' ? method.payload.retryCount : 5;
56602
56857
  const POLL_INTERVAL_TIME = (method.payload && method.payload.pollIntervalTime) || 1000;
@@ -56605,7 +56860,7 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
56605
56860
  Log.debug(`EnsureConnected function start, MAX_RETRY_COUNT=${MAX_RETRY_COUNT}, POLL_INTERVAL_TIME=${POLL_INTERVAL_TIME} `);
56606
56861
  const poll = (time = POLL_INTERVAL_TIME) => __awaiter(void 0, void 0, void 0, function* () {
56607
56862
  return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
56608
- var _l;
56863
+ var _o;
56609
56864
  const abort = () => {
56610
56865
  if (abortSignal && abortSignal.aborted) {
56611
56866
  if (timer) {
@@ -56619,7 +56874,7 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
56619
56874
  if (abort()) {
56620
56875
  return;
56621
56876
  }
56622
- if (!pollingState[pollingId]) {
56877
+ if (!pollingManager.isActive(connectId, pollingId)) {
56623
56878
  Log.debug('EnsureConnected function stop, polling id: ', pollingId);
56624
56879
  reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PollingStop));
56625
56880
  return;
@@ -56667,7 +56922,6 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
56667
56922
  clearTimeout(timer);
56668
56923
  }
56669
56924
  if (DataManager.isBleConnect(env)) {
56670
- bleTimeoutRetry = 0;
56671
56925
  if (abort()) {
56672
56926
  return;
56673
56927
  }
@@ -56710,7 +56964,7 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
56710
56964
  clearTimeout(timer);
56711
56965
  }
56712
56966
  Log.debug('EnsureConnected get to max try count, will return: ', tryCount);
56713
- if (DataManager.isBrowserWebUsb(env) && !((_l = method.payload) === null || _l === void 0 ? void 0 : _l.skipWebDevicePrompt)) {
56967
+ if (DataManager.isBrowserWebUsb(env) && !((_o = method.payload) === null || _o === void 0 ? void 0 : _o.skipWebDevicePrompt)) {
56714
56968
  postMessage(createUiMessage(UI_REQUEST.WEB_DEVICE_PROMPT_ACCESS_PERMISSION));
56715
56969
  reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission));
56716
56970
  }
@@ -56725,7 +56979,6 @@ const ensureConnected = (_context, method, pollingId, abortSignal) => __awaiter(
56725
56979
  return setTimeout(() => resolve(poll(time * 1.5)), time);
56726
56980
  }));
56727
56981
  });
56728
- pollingState[pollingId] = true;
56729
56982
  return poll();
56730
56983
  });
56731
56984
  const cancel = (context, connectId) => {
@@ -56805,12 +57058,9 @@ const checkPassphraseEnableState = (method, features) => {
56805
57058
  }
56806
57059
  };
56807
57060
  const shouldCheckPassphraseState = (method, device) => {
56808
- var _a, _b;
56809
57061
  if (!method.useDevicePassphraseState)
56810
57062
  return false;
56811
- const isPro2 = getDeviceType(device.features) === hdShared.EDeviceType.Pro2;
56812
- const pro2ExplicitWalletSelection = isPro2 && (!!((_a = method.payload) === null || _a === void 0 ? void 0 : _a.passphraseState) || !!((_b = method.payload) === null || _b === void 0 ? void 0 : _b.useEmptyPassphrase));
56813
- return device.hasUsePassphrase() || pro2ExplicitWalletSelection;
57063
+ return device.hasUsePassphrase();
56814
57064
  };
56815
57065
  const cleanup = () => {
56816
57066
  _uiPromises = [];
@@ -56829,6 +57079,7 @@ const onDeviceConnectHandler = (device) => {
56829
57079
  postMessage(createDeviceMessage(DEVICE.CONNECT, { device: deviceObject }));
56830
57080
  };
56831
57081
  const onDeviceDisconnectHandler = (device) => {
57082
+ device.clearPreInitialized();
56832
57083
  const env = DataManager.getSettings('env');
56833
57084
  const deviceObject = DataManager.isBleConnect(env) ? device : device.toMessageObject();
56834
57085
  postMessage(createDeviceMessage(DEVICE.DISCONNECT, { device: deviceObject }));
@@ -56942,7 +57193,7 @@ class Core extends events.exports {
56942
57193
  registerCallbackTask: (connectId, callbackPromise) => {
56943
57194
  this.requestQueue.registerPendingCallbackTask(connectId, callbackPromise);
56944
57195
  },
56945
- waitForCallbackTasks: (connectId) => this.requestQueue.waitForPendingCallbackTasks(connectId),
57196
+ waitForCallbackTasks: (connectId, exceptTask) => this.requestQueue.waitForPendingCallbackTasks(connectId, exceptTask),
56946
57197
  cancelCallbackTasks: (connectId) => this.requestQueue.cancelCallbackTasks(connectId),
56947
57198
  };
56948
57199
  }
@@ -56972,10 +57223,10 @@ class Core extends events.exports {
56972
57223
  break;
56973
57224
  }
56974
57225
  case IFRAME.CALL: {
56975
- Log.log('call API: ', message);
57226
+ Log.log(`[${Date.now()}][CALL_API]`, message);
56976
57227
  const response = yield callAPI(this.getCoreContext(), message);
56977
57228
  const { success, payload } = response;
56978
- Log.log('call API Response: ', response);
57229
+ Log.log(`[${Date.now()}][CALL_API_RESPONSE]`, response);
56979
57230
  if (success) {
56980
57231
  return response;
56981
57232
  }
@@ -56998,6 +57249,9 @@ class Core extends events.exports {
56998
57249
  dispose() {
56999
57250
  _deviceList = undefined;
57000
57251
  _connector = undefined;
57252
+ deviceCacheMap.clear();
57253
+ preWarmInflight.clear();
57254
+ preWarmDoneAt.clear();
57001
57255
  Log.debug(`[Core] Disposing SDK instance: ${this.sdkInstanceId}`);
57002
57256
  cleanupSdkInstance(this.sdkInstanceId);
57003
57257
  }
@@ -57020,7 +57274,7 @@ const init = (settings, Transport, plugin) => __awaiter(void 0, void 0, void 0,
57020
57274
  yield DataManager.load(settings);
57021
57275
  initTransport(Transport, plugin);
57022
57276
  }
57023
- catch (_m) {
57277
+ catch (_p) {
57024
57278
  Log.error('DataManager.load error');
57025
57279
  }
57026
57280
  enableLog(DataManager.getSettings('debug'));