@onekeyfe/hwk-ledger-adapter 1.1.26-alpha.5 → 1.1.26-alpha.6

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
@@ -76,6 +76,58 @@ function getEthAppErrorCode(err) {
76
76
  }
77
77
  return null;
78
78
  }
79
+ function extractApduHex(err) {
80
+ if (!err || typeof err !== "object") return null;
81
+ const e = err;
82
+ if (typeof e.errorCode === "string" && /^[0-9a-f]+$/i.test(e.errorCode)) {
83
+ return e.errorCode.toLowerCase();
84
+ }
85
+ if (typeof e.statusCode === "number" && Number.isFinite(e.statusCode)) {
86
+ return e.statusCode.toString(16).padStart(4, "0");
87
+ }
88
+ if (typeof e.statusCode === "string" && /^[0-9a-f]+$/i.test(e.statusCode)) {
89
+ return e.statusCode.toLowerCase();
90
+ }
91
+ if (e.originalError != null) {
92
+ const nested = extractApduHex(e.originalError);
93
+ if (nested) return nested;
94
+ }
95
+ if (e.error != null && typeof e._tag === "string") {
96
+ const nested = extractApduHex(e.error);
97
+ if (nested) return nested;
98
+ }
99
+ return null;
100
+ }
101
+ function mapSolanaAppError(hex) {
102
+ switch (hex) {
103
+ case "6808":
104
+ return import_hwk_adapter_core.HardwareErrorCode.SolanaBlindSigningRequired;
105
+ default:
106
+ return null;
107
+ }
108
+ }
109
+ function mapTronAppError(hex) {
110
+ switch (hex) {
111
+ case "6a8d":
112
+ return import_hwk_adapter_core.HardwareErrorCode.TronCustomContractRequired;
113
+ case "6a8b":
114
+ return import_hwk_adapter_core.HardwareErrorCode.TronDataSigningRequired;
115
+ case "6a8c":
116
+ return import_hwk_adapter_core.HardwareErrorCode.TronSignByHashRequired;
117
+ default:
118
+ return null;
119
+ }
120
+ }
121
+ function mapBtcAppError(hex) {
122
+ switch (hex) {
123
+ case "b008":
124
+ return import_hwk_adapter_core.HardwareErrorCode.BtcWalletPolicyHmacMismatch;
125
+ case "b007":
126
+ return import_hwk_adapter_core.HardwareErrorCode.BtcUnexpectedState;
127
+ default:
128
+ return null;
129
+ }
130
+ }
79
131
  function mapEthAppError(ethCode, lastStep) {
80
132
  switch (ethCode) {
81
133
  case "6a80":
@@ -191,8 +243,10 @@ function mapLedgerError(err) {
191
243
  } else {
192
244
  const ethCode = getEthAppErrorCode(err);
193
245
  const lastStep = err && typeof err === "object" ? err._lastStep : void 0;
194
- const mapped = ethCode ? mapEthAppError(ethCode, lastStep) : null;
195
- code = mapped ?? import_hwk_adapter_core.HardwareErrorCode.UnknownError;
246
+ const ethMapped = ethCode ? mapEthAppError(ethCode, lastStep) : null;
247
+ const apduHex = ethMapped ? null : extractApduHex(err);
248
+ const chainMapped = apduHex ? mapSolanaAppError(apduHex) ?? mapTronAppError(apduHex) ?? mapBtcAppError(apduHex) : null;
249
+ code = ethMapped ?? chainMapped ?? import_hwk_adapter_core.HardwareErrorCode.UnknownError;
196
250
  }
197
251
  const appName = err && typeof err === "object" ? err.appName : void 0;
198
252
  return { code, message: (0, import_hwk_adapter_core.enrichErrorMessage)(code, originalMessage), appName };
@@ -870,7 +924,7 @@ var _LedgerAdapter = class _LedgerAdapter {
870
924
  * If not granted, calls onDevicePermission so the consumer can request access.
871
925
  */
872
926
  async _ensureDevicePermission(connectId, deviceId) {
873
- const transportType = "hid";
927
+ const transportType = this.activeTransport ?? "hid";
874
928
  let granted = false;
875
929
  let context;
876
930
  if (this._uiHandler?.checkDevicePermission) {
@@ -2027,35 +2081,8 @@ var AppManager = class {
2027
2081
  };
2028
2082
 
2029
2083
  // src/connector/chains/legacyAppRetry.ts
2030
- var KNOWN_APP_CODES = {
2031
- Tron: /* @__PURE__ */ new Set([
2032
- 27013,
2033
- // user denied
2034
- 21781,
2035
- // device locked
2036
- 27274,
2037
- // invalid BIP32 path
2038
- 27275,
2039
- 27276,
2040
- 27277,
2041
- // app-specific data errors
2042
- 27264,
2043
- // invalid data
2044
- 27392,
2045
- // wrong parameter
2046
- 26368
2047
- // wrong length
2048
- ])
2049
- };
2050
- function isLegacyWrongAppError(err, appName) {
2051
- if (isWrongAppError(err)) return true;
2052
- const msg = err instanceof Error ? err.message : "";
2053
- const match = msg.match(/0x([0-9a-fA-F]{4})/);
2054
- if (!match) return false;
2055
- const sw = parseInt(match[1], 16);
2056
- const knownCodes = KNOWN_APP_CODES[appName];
2057
- if (knownCodes?.has(sw)) return false;
2058
- return true;
2084
+ function isLegacyWrongAppError(err, _appName) {
2085
+ return isWrongAppError(err);
2059
2086
  }
2060
2087
  async function withLegacyAppRetry(ctx, sessionId, appName, action) {
2061
2088
  try {