@onekeyfe/hwk-trezor-adapter 1.2.2-alpha.12 → 1.2.2-alpha.122

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.
package/dist/index.js CHANGED
@@ -996,6 +996,9 @@ var _TrezorAdapter = class _TrezorAdapter {
996
996
  if (failure2.code === "Failure_DataError" && failure2.message === "Forbidden key path") {
997
997
  return _hwkadaptercore.HardwareErrorCode.DevicePathForbidden;
998
998
  }
999
+ if (failure2.code === "Failure_DataError" && typeof failure2.message === "string" && failure2.message.includes("PASSPHRASE_ALWAYS_ON_DEVICE")) {
1000
+ return _hwkadaptercore.HardwareErrorCode.PassphraseAlwaysOnDevice;
1001
+ }
999
1002
  if (failure2.code === "Failure_FirmwareError") {
1000
1003
  return _hwkadaptercore.HardwareErrorCode.MethodNotSupported;
1001
1004
  }
@@ -1245,7 +1248,8 @@ var _TrezorAdapter = class _TrezorAdapter {
1245
1248
  shouldAbortBundle: (response, { index }) => {
1246
1249
  const isSessionLevelFailure = topLevelFailureIndexes.has(index);
1247
1250
  const isWholeChainForbidden = isSingleNetworkBundle && _optionalChain([response, 'access', _27 => _27.payload, 'optionalAccess', _28 => _28.code]) === _hwkadaptercore.HardwareErrorCode.DevicePathForbidden;
1248
- return isSessionLevelFailure || isWholeChainForbidden;
1251
+ const isPassphrasePolicyFailure = _optionalChain([response, 'access', _29 => _29.payload, 'optionalAccess', _30 => _30.code]) === _hwkadaptercore.HardwareErrorCode.PassphraseAlwaysOnDevice;
1252
+ return isSessionLevelFailure || isWholeChainForbidden || isPassphrasePolicyFailure;
1249
1253
  }
1250
1254
  });
1251
1255
  }
@@ -1285,7 +1289,7 @@ var _TrezorAdapter = class _TrezorAdapter {
1285
1289
  if (!internalModel) {
1286
1290
  return _hwkadaptercore.failure.call(void 0, _hwkadaptercore.HardwareErrorCode.UnknownError, "Device internal_model unavailable");
1287
1291
  }
1288
- const challengeHex = _nullishCoalesce(_optionalChain([params, 'access', _29 => _29.challenge, 'optionalAccess', _30 => _30.toLowerCase, 'call', _31 => _31()]), () => ( Buffer.from(_utils.randomBytes.call(void 0, 32)).toString("hex")));
1292
+ const challengeHex = _nullishCoalesce(_optionalChain([params, 'access', _31 => _31.challenge, 'optionalAccess', _32 => _32.toLowerCase, 'call', _33 => _33()]), () => ( Buffer.from(_utils.randomBytes.call(void 0, 32)).toString("hex")));
1289
1293
  const challenge = Buffer.from(challengeHex, "hex");
1290
1294
  const proofRes = await this._callDeviceManagerMethod(
1291
1295
  "authenticateDevice",
@@ -1639,7 +1643,7 @@ var _TrezorAdapter = class _TrezorAdapter {
1639
1643
  if (pending) return pending;
1640
1644
  const promise = (async () => {
1641
1645
  try {
1642
- if (_optionalChain([signal, 'optionalAccess', _32 => _32.aborted])) {
1646
+ if (_optionalChain([signal, 'optionalAccess', _34 => _34.aborted])) {
1643
1647
  throw Object.assign(new Error("Trezor connection aborted"), {
1644
1648
  code: _hwkadaptercore.HardwareErrorCode.UserAborted
1645
1649
  });
@@ -1685,8 +1689,8 @@ var _TrezorAdapter = class _TrezorAdapter {
1685
1689
  passphraseMode: "prompt"
1686
1690
  })
1687
1691
  );
1688
- if (_optionalChain([created, 'optionalAccess', _33 => _33.protocol]) === "thp" && !created.thpSessionId) return;
1689
- if (_optionalChain([created, 'optionalAccess', _34 => _34.protocol]) !== "thp" && _optionalChain([created, 'optionalAccess', _35 => _35.protocol]) !== "v1") return;
1692
+ if (_optionalChain([created, 'optionalAccess', _35 => _35.protocol]) === "thp" && !created.thpSessionId) return;
1693
+ if (_optionalChain([created, 'optionalAccess', _36 => _36.protocol]) !== "thp" && _optionalChain([created, 'optionalAccess', _37 => _37.protocol]) !== "v1") return;
1690
1694
  const state = await this._deriveState(sessionId, signal);
1691
1695
  if (state !== passphraseState) {
1692
1696
  throw Object.assign(
@@ -1700,13 +1704,13 @@ var _TrezorAdapter = class _TrezorAdapter {
1700
1704
  }
1701
1705
  _rememberVerifiedPassphraseSession(connectId, passphraseState, sessionId, created) {
1702
1706
  let session;
1703
- if (_optionalChain([created, 'optionalAccess', _36 => _36.protocol]) === "thp" && typeof created.thpSessionId === "string") {
1707
+ if (_optionalChain([created, 'optionalAccess', _38 => _38.protocol]) === "thp" && typeof created.thpSessionId === "string") {
1704
1708
  session = {
1705
1709
  sessionId,
1706
1710
  protocol: "thp",
1707
1711
  thpSessionId: created.thpSessionId
1708
1712
  };
1709
- } else if (_optionalChain([created, 'optionalAccess', _37 => _37.protocol]) === "v1") {
1713
+ } else if (_optionalChain([created, 'optionalAccess', _39 => _39.protocol]) === "v1") {
1710
1714
  session = {
1711
1715
  sessionId,
1712
1716
  protocol: "v1"
@@ -1726,7 +1730,7 @@ var _TrezorAdapter = class _TrezorAdapter {
1726
1730
  }
1727
1731
  }
1728
1732
  async _reuseVerifiedPassphraseSession(connectId, sessionId, passphraseState, signal) {
1729
- const cached = _optionalChain([this, 'access', _38 => _38._verifiedPassphraseSessionsByConnectId, 'access', _39 => _39.get, 'call', _40 => _40(connectId), 'optionalAccess', _41 => _41.get, 'call', _42 => _42(passphraseState)]);
1733
+ const cached = _optionalChain([this, 'access', _40 => _40._verifiedPassphraseSessionsByConnectId, 'access', _41 => _41.get, 'call', _42 => _42(connectId), 'optionalAccess', _43 => _43.get, 'call', _44 => _44(passphraseState)]);
1730
1734
  if (!cached || cached.sessionId !== sessionId) {
1731
1735
  this._forgetVerifiedPassphraseSession(connectId, passphraseState);
1732
1736
  return false;
@@ -1778,7 +1782,7 @@ var _TrezorAdapter = class _TrezorAdapter {
1778
1782
  showOnDevice: false
1779
1783
  })
1780
1784
  );
1781
- const state = _optionalChain([derived, 'optionalAccess', _43 => _43.publicKey]);
1785
+ const state = _optionalChain([derived, 'optionalAccess', _45 => _45.publicKey]);
1782
1786
  if (!state) {
1783
1787
  throw Object.assign(new Error("Failed to derive passphrase state (wallet public key)"), {
1784
1788
  code: _hwkadaptercore.HardwareErrorCode.UnknownError
@@ -1804,7 +1808,7 @@ var _TrezorAdapter = class _TrezorAdapter {
1804
1808
  signal,
1805
1809
  _TrezorAdapter._callConnector(this._connector, sessionId, "getFeatures", { refresh: true })
1806
1810
  );
1807
- if (_optionalChain([features, 'optionalAccess', _44 => _44.passphrase_protection]) !== true) {
1811
+ if (_optionalChain([features, 'optionalAccess', _46 => _46.passphrase_protection]) !== true) {
1808
1812
  return _hwkadaptercore.success.call(void 0, null);
1809
1813
  }
1810
1814
  this._rememberVerifiedPassphraseSession(connectId, state, sessionId, created);