@onekeyfe/hwk-adapter-core 1.2.8-alpha.13 → 1.2.8-alpha.131

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.mjs CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  UI_REQUEST_TIMEOUT_TAG,
11
11
  UI_RESPONSE,
12
12
  UiRequestRegistry
13
- } from "./chunk-3D45OEC2.mjs";
13
+ } from "./chunk-Z574MVAT.mjs";
14
14
  import {
15
15
  HardwareErrorCode,
16
16
  ORPHAN_ELIGIBLE_ERROR_CODES,
@@ -19,7 +19,7 @@ import {
19
19
  defaultRecoveryForCode,
20
20
  isHwkRecoveryHint,
21
21
  operationMayHaveCompletedParams
22
- } from "./chunk-KTRQZ5AJ.mjs";
22
+ } from "./chunk-V2OHL2JS.mjs";
23
23
 
24
24
  // src/types/response.ts
25
25
  function success(payload) {
@@ -358,11 +358,9 @@ var OperationRegistry = class {
358
358
  (operation) => operation.connectionKeys.includes(connectionKey)
359
359
  );
360
360
  }
361
- /** Map a job queue key (an operation id or a connection key) to its live operation id. */
361
+ /** Only an explicitly supplied operation job key owns the call's UI requests. */
362
362
  findOperationIdByJobKey(jobKey) {
363
- if (!jobKey) return void 0;
364
- if (isHardwareOperationId(jobKey)) return jobKey;
365
- return this.findActiveByConnectionKey(jobKey)?.operationId;
363
+ return isHardwareOperationId(jobKey) ? jobKey : void 0;
366
364
  }
367
365
  /**
368
366
  * End an operation on the caller's explicit release. Throws for an unknown id; returns undefined
@@ -565,6 +563,15 @@ function rehydrateConnectorError(error) {
565
563
  ...params ?? {}
566
564
  });
567
565
  }
566
+ function withChildConnectionType(event, data, connectionType) {
567
+ if (event !== "device-connect" && event !== "features") return data;
568
+ const { device } = data;
569
+ if (device.connectionType) return data;
570
+ return {
571
+ ...data,
572
+ device: { ...device, connectionType }
573
+ };
574
+ }
568
575
  function isDeviceUnavailableError(error) {
569
576
  const typed = error;
570
577
  if (typed.code === 10100 /* DeviceNotFound */ || typed.code === 10101 /* DeviceDisconnected */) {
@@ -763,7 +770,7 @@ function createCombinedConnector(connectors) {
763
770
  },
764
771
  on: (event, handler) => {
765
772
  const attached = connectors.map((child) => {
766
- const forward = (data) => handler(data);
773
+ const forward = (data) => handler(withChildConnectionType(event, data, child.connectionType));
767
774
  child.on(event, forward);
768
775
  return { child, handler: forward };
769
776
  });
@@ -1132,6 +1139,346 @@ function prepareSolanaOffchainMessageV1({
1132
1139
  };
1133
1140
  }
1134
1141
 
1142
+ // src/utils/logSummary.ts
1143
+ import { sha256 as sha2562 } from "@noble/hashes/sha256";
1144
+ import { bytesToHex as bytesToHex4, utf8ToBytes as utf8ToBytes2 } from "@noble/hashes/utils";
1145
+ var MAX_DEPTH = 6;
1146
+ var MAX_ARRAY_ITEMS = 20;
1147
+ var MAX_PLAIN_STRING = 64;
1148
+ var MAX_ERROR_STRING = 500;
1149
+ var normalizeKey = (key) => key.replace(/[_-]/g, "").toLowerCase();
1150
+ var keySet = (keys) => new Set(keys.map(normalizeKey));
1151
+ var KEEP_KEYS = keySet([
1152
+ "path",
1153
+ "paths",
1154
+ "derivationPath",
1155
+ "fullPath",
1156
+ "basePath",
1157
+ "method",
1158
+ "methodName",
1159
+ "chainId",
1160
+ "coin",
1161
+ "network",
1162
+ "networkName",
1163
+ "scriptType",
1164
+ "template",
1165
+ "appName",
1166
+ "_tag",
1167
+ "code",
1168
+ "errorCode",
1169
+ "statusCode"
1170
+ ]);
1171
+ var ERROR_TEXT_KEYS = keySet(["message", "error", "errorMessage", "originalMessage"]);
1172
+ var ERROR_CONTEXT_KEYS = keySet(["error", "err", "originalError", "cause"]);
1173
+ var SECRET_KEYS = keySet([
1174
+ "ufvk",
1175
+ "orchardFvk",
1176
+ "fvk",
1177
+ "viewingKey",
1178
+ "passphraseState",
1179
+ "passphrase",
1180
+ "password",
1181
+ "pin",
1182
+ "mnemonic",
1183
+ "mnemonics",
1184
+ "word",
1185
+ "words",
1186
+ "seed",
1187
+ "entropy",
1188
+ "privateKey",
1189
+ "xprv",
1190
+ "mac",
1191
+ // THP pairing and channel material.
1192
+ "credential",
1193
+ "credentials",
1194
+ "hostStaticKey",
1195
+ "trezorStaticPublicKey",
1196
+ // Wallet sessions and host connection records.
1197
+ "session",
1198
+ "sessionId",
1199
+ "knownConnections",
1200
+ "extra"
1201
+ ]);
1202
+ var KEY_MATERIAL_KEYS = keySet([
1203
+ "xpub",
1204
+ "ypub",
1205
+ "zpub",
1206
+ "tpub",
1207
+ "extendedPublicKey",
1208
+ "publicKey",
1209
+ "pubkey",
1210
+ "pub",
1211
+ "chainCode",
1212
+ "tapInternalKey"
1213
+ ]);
1214
+ var SIGNATURE_KEYS = keySet(["signature", "signatures", "sig", "r", "s", "v", "partialSig"]);
1215
+ var SIGNED_TX_KEYS = keySet(["signedTx", "signedTransaction", "signedTxHex"]);
1216
+ var SIGNED_PSBT_KEYS = keySet(["signedPsbt"]);
1217
+ var PAYLOAD_KEYS = keySet([
1218
+ "serializedTx",
1219
+ "rawTx",
1220
+ "rawTxHex",
1221
+ "txHex",
1222
+ "tx",
1223
+ "transaction",
1224
+ "psbt",
1225
+ "message",
1226
+ "messageHex",
1227
+ "data",
1228
+ "dataJson",
1229
+ "typedData",
1230
+ "hex",
1231
+ "bytes",
1232
+ "apdu",
1233
+ "domainSeparatorHash",
1234
+ "messageHash",
1235
+ "encodedNetwork",
1236
+ "encodedToken",
1237
+ "refBlockBytes",
1238
+ "refBlockHash",
1239
+ "opReturnData",
1240
+ "scriptSig",
1241
+ "witness",
1242
+ "extraData",
1243
+ // Structured transaction contents (Trezor-style and Tron params).
1244
+ "contract",
1245
+ "inputs",
1246
+ "outputs",
1247
+ "refTxs",
1248
+ "paymentRequest",
1249
+ "paymentRequests",
1250
+ "additionalInfo",
1251
+ "accessList",
1252
+ "memos"
1253
+ ]);
1254
+ var ADDRESS_KEYS = keySet([
1255
+ "to",
1256
+ "from",
1257
+ "recipient",
1258
+ "verifyingContract",
1259
+ "requiredSigners",
1260
+ "tokenMint",
1261
+ "tokenAccount",
1262
+ "tokenProgram"
1263
+ ]);
1264
+ var TX_IN_RESULT_KEYS = keySet(["serializedTx", "rawTx", "rawTxHex", "txHex", "tx"]);
1265
+ var AMOUNT_KEYS = keySet(["value", "amount", "amounts", "fee", "fees", "tokenAmount"]);
1266
+ var ERROR_FIELDS = ["_tag", "code", "errorCode", "statusCode", "originalError"];
1267
+ var XPUB_RE = /^[a-zA-Z]pub[1-9A-HJ-NP-Za-km-z]{90,}$/;
1268
+ var HEX_RE = /^(0x)?[0-9a-fA-F]*$/;
1269
+ var EVM_TX_TYPES = {
1270
+ 1: "eip2930",
1271
+ 2: "eip1559",
1272
+ 3: "eip4844",
1273
+ 4: "eip7702"
1274
+ };
1275
+ function sha256Short(input) {
1276
+ return bytesToHex4(sha2562(typeof input === "string" ? utf8ToBytes2(input) : input)).slice(0, 16);
1277
+ }
1278
+ function toBytes(value) {
1279
+ if (value instanceof Uint8Array) return value;
1280
+ if (value instanceof ArrayBuffer) return new Uint8Array(value);
1281
+ if (ArrayBuffer.isView(value)) {
1282
+ return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
1283
+ }
1284
+ if (value && typeof value === "object" && value.type === "Buffer" && Array.isArray(value.data)) {
1285
+ return Uint8Array.from(value.data);
1286
+ }
1287
+ return void 0;
1288
+ }
1289
+ function isPlainHex(value) {
1290
+ return value.length > 0 && HEX_RE.test(value) && value !== "0x";
1291
+ }
1292
+ function stripHexPrefix(value) {
1293
+ return value.startsWith("0x") || value.startsWith("0X") ? value.slice(2) : value;
1294
+ }
1295
+ function maskAddress(value) {
1296
+ if (value.length <= 12) return `<addr len=${value.length}>`;
1297
+ return `${value.slice(0, 6)}\u2026${value.slice(-4)}`;
1298
+ }
1299
+ function summarizeKeyMaterial(value) {
1300
+ const bytes = toBytes(value);
1301
+ if (bytes) return `\u2026 len=${bytes.length}`;
1302
+ const text = String(value);
1303
+ return XPUB_RE.test(text) ? `${text.slice(0, 4)}\u2026 len=${text.length}` : `\u2026 len=${text.length}`;
1304
+ }
1305
+ function lengthOf(value) {
1306
+ const bytes = toBytes(value);
1307
+ if (bytes) return bytes.length;
1308
+ if (typeof value === "string") return value.length;
1309
+ const json = safeJson(value);
1310
+ return json === void 0 ? 0 : json.length;
1311
+ }
1312
+ function safeJson(value) {
1313
+ try {
1314
+ return JSON.stringify(value, (_k, v) => typeof v === "bigint" ? `${v}n` : v);
1315
+ } catch {
1316
+ return void 0;
1317
+ }
1318
+ }
1319
+ function evmTxType(hex) {
1320
+ const body = stripHexPrefix(hex);
1321
+ if (body.length < 2) return void 0;
1322
+ const first = parseInt(body.slice(0, 2), 16);
1323
+ if (first >= 192) return "legacy";
1324
+ return EVM_TX_TYPES[first];
1325
+ }
1326
+ function describe(key, value, ctx) {
1327
+ if (!ctx.describePayload) return void 0;
1328
+ try {
1329
+ const hint = ctx.describePayload(key, value, { method: ctx.method, role: ctx.role });
1330
+ return typeof hint === "string" && hint.length > 0 ? hint : void 0;
1331
+ } catch {
1332
+ return void 0;
1333
+ }
1334
+ }
1335
+ function jsonSummary(json, parsed) {
1336
+ const primaryType = parsed && typeof parsed === "object" ? parsed.primaryType : void 0;
1337
+ const hint = typeof primaryType === "string" && primaryType.length <= MAX_PLAIN_STRING ? ` primaryType=${primaryType}` : "";
1338
+ return `<json len=${json.length} sha256=${sha256Short(json)}${hint}>`;
1339
+ }
1340
+ function summarizePayload(key, value, ctx) {
1341
+ if (value === null || value === void 0 || typeof value === "boolean") return value;
1342
+ if (typeof value === "number") return value;
1343
+ const bytes = toBytes(value);
1344
+ if (bytes) {
1345
+ const hint = describe(key, bytes, ctx);
1346
+ return `<hex len=${bytes.length} sha256=${sha256Short(bytes)}${hint ? ` ${hint}` : ""}>`;
1347
+ }
1348
+ if (typeof value === "string") {
1349
+ const trimmed = value.trim();
1350
+ if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
1351
+ try {
1352
+ return jsonSummary(value, JSON.parse(value));
1353
+ } catch {
1354
+ }
1355
+ }
1356
+ const hints = [];
1357
+ if (key === "serializedtx" && ctx.method.startsWith("evm") && isPlainHex(value)) {
1358
+ const type = evmTxType(value);
1359
+ if (type) hints.push(`type=${type}`);
1360
+ }
1361
+ const extra = describe(key, value, ctx);
1362
+ if (extra) hints.push(extra);
1363
+ const kind = isPlainHex(value) ? "hex" : "str";
1364
+ const suffix = hints.length ? ` ${hints.join(" ")}` : "";
1365
+ return `<${kind} len=${value.length} sha256=${sha256Short(value)}${suffix}>`;
1366
+ }
1367
+ const json = safeJson(value);
1368
+ if (json === void 0) return "<object unhashable>";
1369
+ return jsonSummary(json, value);
1370
+ }
1371
+ function summarizeString(value, key, ctx) {
1372
+ if (key && KEEP_KEYS.has(key)) return value;
1373
+ if (key && ctx.inError && ERROR_TEXT_KEYS.has(key)) {
1374
+ return value.length > MAX_ERROR_STRING ? `${value.slice(0, MAX_ERROR_STRING)}\u2026` : value;
1375
+ }
1376
+ if (XPUB_RE.test(value)) return summarizeKeyMaterial(value);
1377
+ if (value.length <= MAX_PLAIN_STRING) return value;
1378
+ const kind = isPlainHex(value) ? "hex" : "str";
1379
+ return `<${kind} len=${value.length} sha256=${sha256Short(value)}>`;
1380
+ }
1381
+ function summarizeError(err, depth, ctx) {
1382
+ const e = err;
1383
+ const out = {
1384
+ name: err.name,
1385
+ message: summarizeString(err.message, "message", ctx)
1386
+ };
1387
+ for (const field of ERROR_FIELDS) {
1388
+ if (e[field] !== void 0) {
1389
+ out[field] = summarizeValue(e[field], normalizeKey(field), depth + 1, ctx);
1390
+ }
1391
+ }
1392
+ return out;
1393
+ }
1394
+ function summarizeByKey(rawKey, value, depth, ctx) {
1395
+ const k = normalizeKey(rawKey);
1396
+ if (value === void 0 || value === null) return value;
1397
+ if (SECRET_KEYS.has(k)) return `<redacted len=${lengthOf(value)}>`;
1398
+ if (KEY_MATERIAL_KEYS.has(k)) {
1399
+ if (typeof value === "string" || toBytes(value)) return summarizeKeyMaterial(value);
1400
+ }
1401
+ if (SIGNATURE_KEYS.has(k)) {
1402
+ if (Array.isArray(value)) return `<signatures count=${value.length}>`;
1403
+ return `<signature len=${lengthOf(value)}>`;
1404
+ }
1405
+ if (SIGNED_PSBT_KEYS.has(k)) return `<psbt len=${lengthOf(value)}>`;
1406
+ if (SIGNED_TX_KEYS.has(k) || ctx.role === "result" && TX_IN_RESULT_KEYS.has(k)) {
1407
+ return `<signedTx len=${lengthOf(value)}>`;
1408
+ }
1409
+ if (AMOUNT_KEYS.has(k)) return "<amount>";
1410
+ if (ctx.inError && ERROR_TEXT_KEYS.has(k) && typeof value === "string") {
1411
+ return summarizeString(value, k, ctx);
1412
+ }
1413
+ if (PAYLOAD_KEYS.has(k)) return summarizePayload(k, value, ctx);
1414
+ if (ADDRESS_KEYS.has(k) || k.endsWith("address") || k.endsWith("addresses")) {
1415
+ if (typeof value === "string") return maskAddress(value);
1416
+ if (Array.isArray(value)) {
1417
+ return capArray(value, (item) => typeof item === "string" ? maskAddress(item) : "<addr>");
1418
+ }
1419
+ }
1420
+ const inError = ERROR_CONTEXT_KEYS.has(k);
1421
+ const childCtx = inError === ctx.inError ? ctx : { ...ctx, inError };
1422
+ return summarizeValue(value, k, depth, childCtx);
1423
+ }
1424
+ function capArray(items, map) {
1425
+ const out = items.slice(0, MAX_ARRAY_ITEMS).map(map);
1426
+ if (items.length > MAX_ARRAY_ITEMS) out.push(`\u2026+${items.length - MAX_ARRAY_ITEMS} more`);
1427
+ return out;
1428
+ }
1429
+ function summarizeValue(value, key, depth, ctx) {
1430
+ switch (typeof value) {
1431
+ case "undefined":
1432
+ case "boolean":
1433
+ return value;
1434
+ case "number":
1435
+ return Number.isFinite(value) ? value : String(value);
1436
+ case "bigint":
1437
+ return `${value}n`;
1438
+ case "string":
1439
+ return summarizeString(value, key, ctx);
1440
+ case "function":
1441
+ return "<function>";
1442
+ case "symbol":
1443
+ return "<symbol>";
1444
+ default:
1445
+ break;
1446
+ }
1447
+ if (value === null) return null;
1448
+ const bytes = toBytes(value);
1449
+ if (bytes) return `<hex len=${bytes.length} sha256=${sha256Short(bytes)}>`;
1450
+ const obj = value;
1451
+ if (ctx.ancestors.has(obj)) return "<circular>";
1452
+ if (depth >= MAX_DEPTH) return "<depth>";
1453
+ ctx.ancestors.add(obj);
1454
+ try {
1455
+ if (value instanceof Error) return summarizeError(value, depth, { ...ctx, inError: true });
1456
+ if (Array.isArray(value)) {
1457
+ return capArray(value, (item) => summarizeValue(item, key, depth + 1, ctx));
1458
+ }
1459
+ const out = {};
1460
+ for (const [childKey, child] of Object.entries(value)) {
1461
+ out[childKey] = summarizeByKey(childKey, child, depth + 1, ctx);
1462
+ }
1463
+ return out;
1464
+ } finally {
1465
+ ctx.ancestors.delete(obj);
1466
+ }
1467
+ }
1468
+ function summarizeForLog(value, options = {}) {
1469
+ try {
1470
+ return summarizeValue(value, void 0, 0, {
1471
+ method: options.method ?? "",
1472
+ role: options.role ?? "params",
1473
+ describePayload: options.describePayload,
1474
+ inError: false,
1475
+ ancestors: /* @__PURE__ */ new Set()
1476
+ });
1477
+ } catch {
1478
+ return "<unloggable>";
1479
+ }
1480
+ }
1481
+
1135
1482
  // src/utils/deviceIdentity.ts
1136
1483
  var ONEKEY_BLE_SERVICE_UUID = "00000001-0000-1000-8000-00805f9b34fb";
1137
1484
  var TREZOR_BLE_SERVICE_UUID = "8c000001-a59b-4d58-a9ad-073df69fa1b1";
@@ -1433,6 +1780,7 @@ export {
1433
1780
  serializeConnectorError,
1434
1781
  stripHex,
1435
1782
  success,
1783
+ summarizeForLog,
1436
1784
  toPhysicalDeviceSearchTarget
1437
1785
  };
1438
1786
  //# sourceMappingURL=index.mjs.map