@onekeyfe/hwk-keystone-adapter 1.2.8-alpha.119 → 1.2.8-alpha.121

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
@@ -200,7 +200,7 @@ function relativeHdPath(relativeDerivePath) {
200
200
  }
201
201
  return `m/${segments.join("/")}`;
202
202
  }
203
- var FIRMWARE_VERSION = /^\d{1,4}(\.\d{1,4}){1,3}(-[0-9A-Za-z.]{1,20})?$/;
203
+ var FIRMWARE_VERSION = /^\d{1,4}(\.\d{1,4}){1,3}(-[0-9A-Za-z.-]{1,20})?$/;
204
204
  var DEVICE_TEXT = /^[^\p{Cc}\p{Cf}]{1,64}$/u;
205
205
  function deviceText(value, pattern) {
206
206
  return typeof value === "string" && pattern.test(value) ? value : void 0;
@@ -308,7 +308,9 @@ var KeystoneUrEngine = class {
308
308
  }
309
309
  const byPath = /* @__PURE__ */ new Map();
310
310
  for (const account of parsed.accounts) {
311
- if (!/^m(?:\/\d+')+(?:\/\d+)*$/.test(account.path) || account.path.slice(2).split("/").some((segment) => Number(segment.replace("'", "")) >= BIP32_HARDENED_OFFSET)) {
311
+ if (!/^m(?:\/\d+')+(?:\/\d+)*$/.test(account.path) || account.path.slice(2).split("/").some(
312
+ (segment) => Number(segment.endsWith("'") ? segment.slice(0, -1) : segment) >= BIP32_HARDENED_OFFSET
313
+ )) {
312
314
  throw new Error("Account export has an unsupported derivation path");
313
315
  }
314
316
  let identity = account.publicKey;
@@ -567,31 +569,6 @@ import {
567
569
  success
568
570
  } from "@onekeyfe/hwk-adapter-core";
569
571
 
570
- // src/adapter/firmwareCapabilities.ts
571
- var MULTI_COIN = {
572
- variant: "multi-coin",
573
- supportedChains: ["btc", "evm", "sol", "tron"]
574
- };
575
- var BITCOIN_ONLY = {
576
- variant: "bitcoin-only",
577
- supportedChains: ["btc"]
578
- };
579
- var CYPHERPUNK = {
580
- variant: "cypherpunk",
581
- // Firmware support alone is insufficient: this adapter has no Zcash/Monero methods yet.
582
- supportedChains: ["btc"]
583
- };
584
- function getKeystoneFirmwareProfile(firmwareVersion) {
585
- if (!firmwareVersion || firmwareVersion === "0.0.0") return void 0;
586
- const version = /^\d{1,4}(?:\.\d{1,4}){1,3}(?:-([a-z0-9.-]{1,40}))?$/i.exec(firmwareVersion);
587
- if (!version) return void 0;
588
- const suffix = version[1]?.toUpperCase();
589
- if (!suffix) return MULTI_COIN;
590
- if (suffix === "C" || suffix === "CYPHERPUNK" || suffix === "CYPHERPUNK-B") return CYPHERPUNK;
591
- if (suffix === "B" || suffix === "BTC" || suffix === "BTC-ONLY") return BITCOIN_ONLY;
592
- return void 0;
593
- }
594
-
595
572
  // src/adapter/pathUtils.ts
596
573
  function normalizePath(path) {
597
574
  const trimmed = path.trim();
@@ -667,7 +644,6 @@ function toDeviceInfo(record) {
667
644
  }
668
645
  function toDeviceInfoForConnection(record, connectionType) {
669
646
  const firmwareVersion = connectionType === "usb" ? record.usbFirmwareVersion : record.deviceVersion;
670
- const firmware = connectionType === "usb" ? getKeystoneFirmwareProfile(firmwareVersion) : void 0;
671
647
  let availableChannels = ["qr"];
672
648
  if (record.usbSessionId) {
673
649
  availableChannels = record.qrSynced ? ["qr", "usb"] : ["usb"];
@@ -681,8 +657,7 @@ function toDeviceInfoForConnection(record, connectionType) {
681
657
  connectId: record.connectId,
682
658
  connectionType,
683
659
  capabilities: {
684
- ...CAPABILITIES,
685
- ...firmware ? { supportedChains: [...firmware.supportedChains] } : {}
660
+ ...CAPABILITIES
686
661
  },
687
662
  raw: {
688
663
  availableChannels,
@@ -703,6 +678,31 @@ function placeholderDeviceInfo() {
703
678
  };
704
679
  }
705
680
 
681
+ // src/adapter/firmwareCapabilities.ts
682
+ var MULTI_COIN = {
683
+ variant: "multi-coin",
684
+ supportedChains: ["btc", "evm", "sol", "tron"]
685
+ };
686
+ var BITCOIN_ONLY = {
687
+ variant: "bitcoin-only",
688
+ supportedChains: ["btc"]
689
+ };
690
+ var CYPHERPUNK = {
691
+ variant: "cypherpunk",
692
+ // Firmware support alone is insufficient: this adapter has no Zcash/Monero methods yet.
693
+ supportedChains: ["btc"]
694
+ };
695
+ function getKeystoneFirmwareProfile(firmwareVersion) {
696
+ if (!firmwareVersion || firmwareVersion === "0.0.0") return void 0;
697
+ const version = /^\d{1,4}(?:\.\d{1,4}){1,3}(?:-([a-z0-9.-]{1,40}))?$/i.exec(firmwareVersion);
698
+ if (!version) return void 0;
699
+ const suffix = version[1]?.toUpperCase();
700
+ if (!suffix) return MULTI_COIN;
701
+ if (suffix === "C" || suffix === "CYPHERPUNK" || suffix === "CYPHERPUNK-B") return CYPHERPUNK;
702
+ if (suffix === "B" || suffix === "BTC" || suffix === "BTC-ONLY") return BITCOIN_ONLY;
703
+ return void 0;
704
+ }
705
+
706
706
  // src/utils/queueKey.ts
707
707
  import { isHardwareOperationId, parseWalletMasterFingerprint as parseWalletMasterFingerprint2 } from "@onekeyfe/hwk-adapter-core";
708
708
  var KEYSTONE_COLD_START_JOB_LABEL = "keystone-cold-start";
@@ -1505,7 +1505,6 @@ var KeystoneAdapter = class _KeystoneAdapter {
1505
1505
  true,
1506
1506
  connectId,
1507
1507
  signal,
1508
- "btc",
1509
1508
  "btcSignPsbt"
1510
1509
  );
1511
1510
  _KeystoneAdapter._throwIfAborted(signal);
@@ -1853,7 +1852,6 @@ var KeystoneAdapter = class _KeystoneAdapter {
1853
1852
  true,
1854
1853
  connectId,
1855
1854
  signal,
1856
- args.chain,
1857
1855
  args.operationName
1858
1856
  );
1859
1857
  _KeystoneAdapter._throwIfAborted(signal);
@@ -2222,7 +2220,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
2222
2220
  * Decides QR vs USB for one UR round trip. A pinned 'usb' with no live session reattaches once
2223
2221
  * and fails closed if that fails; otherwise a failed USB reattach leaves the call on QR.
2224
2222
  */
2225
- async _resolveUr(record, requestUr, animated, operationId, signal, chain, operationName, qrFallback) {
2223
+ async _resolveUr(record, requestUr, animated, operationId, signal, operationName, qrFallback) {
2226
2224
  const releaseOperationRetention = isHardwareOperationId2(operationId) ? this._operations.retain(operationId) : void 0;
2227
2225
  try {
2228
2226
  return await this._resolveUrWithRoute(
@@ -2231,7 +2229,6 @@ var KeystoneAdapter = class _KeystoneAdapter {
2231
2229
  animated,
2232
2230
  operationId,
2233
2231
  signal,
2234
- chain,
2235
2232
  operationName,
2236
2233
  qrFallback
2237
2234
  );
@@ -2239,7 +2236,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
2239
2236
  releaseOperationRetention?.();
2240
2237
  }
2241
2238
  }
2242
- async _resolveUrWithRoute(callerRecord, requestUr, animated, operationId, signal, chain, operationName, qrFallback) {
2239
+ async _resolveUrWithRoute(callerRecord, requestUr, animated, operationId, signal, operationName, qrFallback) {
2243
2240
  let record = callerRecord;
2244
2241
  let interactionRoute;
2245
2242
  if (isHardwareOperationId2(operationId)) {
@@ -2272,7 +2269,6 @@ var KeystoneAdapter = class _KeystoneAdapter {
2272
2269
  message: "USB channel is not connected for this Keystone wallet"
2273
2270
  });
2274
2271
  }
2275
- this._assertChainSupported(record.usbFirmwareVersion, chain);
2276
2272
  const result = await this._callUsbResolveUr(
2277
2273
  this._usbConnector,
2278
2274
  record.usbSessionId,
@@ -2396,7 +2392,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
2396
2392
  message: `Keystone did not return the requested derivation path (${syncPath})`
2397
2393
  });
2398
2394
  }
2399
- this._assertChainSupported(bundle.firmwareVersion, hwkChain);
2395
+ this._assertQrChainSupported(bundle.firmwareVersion, hwkChain);
2400
2396
  return { record: target.record, account: scanned };
2401
2397
  }
2402
2398
  if (bundle?.channel === "usb" && target.record?.usbSessionId !== bundle.usbSessionId) {
@@ -2419,7 +2415,6 @@ var KeystoneAdapter = class _KeystoneAdapter {
2419
2415
  false,
2420
2416
  connectId,
2421
2417
  signal,
2422
- hwkChain,
2423
2418
  void 0,
2424
2419
  bundle?.channel === "usb" ? bundle.qrFallback : void 0
2425
2420
  );
@@ -2438,7 +2433,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
2438
2433
  }
2439
2434
  record = existingRecord;
2440
2435
  } else {
2441
- this._assertChainSupported(parsed.deviceVersion, hwkChain);
2436
+ this._assertQrChainSupported(parsed.deviceVersion, hwkChain);
2442
2437
  record = this._upsertDeviceRecord(parsed);
2443
2438
  }
2444
2439
  return { record, account: { ...account, hwkChain } };
@@ -2461,15 +2456,15 @@ var KeystoneAdapter = class _KeystoneAdapter {
2461
2456
  schemas: [keySchema(chain, accountPath)],
2462
2457
  origin: this._origin
2463
2458
  });
2464
- const responseUr = await this._resolveUr(void 0, requestUr, false, connectId, signal, chain);
2459
+ const responseUr = await this._resolveUr(void 0, requestUr, false, connectId, signal);
2465
2460
  _KeystoneAdapter._throwIfAborted(signal);
2466
2461
  const parsed = responseUr.accountExport ? this.urEngine.parseAccountExport(responseUr) : this.urEngine.parseAccountResponse(responseUr);
2467
2462
  requireExportedPath(parsed, normalizePath(accountPath), responseUr.accountExport);
2468
- this._assertChainSupported(parsed.deviceVersion, chain);
2463
+ this._assertQrChainSupported(parsed.deviceVersion, chain);
2469
2464
  const record = this._upsertDeviceRecord(parsed);
2470
2465
  return { record };
2471
2466
  }
2472
- _assertChainSupported(firmwareVersion, chain) {
2467
+ _assertQrChainSupported(firmwareVersion, chain) {
2473
2468
  const firmware = getKeystoneFirmwareProfile(firmwareVersion);
2474
2469
  if (firmware && !firmware.supportedChains.includes(chain)) {
2475
2470
  throw createHwkError2({
@@ -2521,15 +2516,17 @@ var KeystoneAdapter = class _KeystoneAdapter {
2521
2516
  async _confirmQrFallback(signal, choice) {
2522
2517
  if (choice?.confirmed !== void 0) return choice.confirmed;
2523
2518
  const requestType = UI_REQUEST.REQUEST_QR_FALLBACK_CONFIRM;
2519
+ const requestId = this._uiRegistry.createRequestId();
2524
2520
  const operationId = this._activeOperationId();
2525
2521
  const release = operationId ? this._operations.retain(operationId) : void 0;
2526
2522
  try {
2527
2523
  const waitPromise = this._uiRegistry.wait(requestType, {
2524
+ requestId,
2528
2525
  operationId
2529
2526
  });
2530
2527
  this.emitter.emit(requestType, {
2531
2528
  type: requestType,
2532
- payload: { vendor: "keystone", operationId }
2529
+ payload: { vendor: "keystone", requestId, operationId }
2533
2530
  });
2534
2531
  let confirmed = false;
2535
2532
  try {