@onekeyfe/hwk-ledger-adapter 1.1.26-alpha.105 → 1.1.26-alpha.106

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.d.mts CHANGED
@@ -91,16 +91,20 @@ declare class LedgerAdapter implements IHardwareWallet {
91
91
  */
92
92
  private _verifyDeviceFingerprintWithSession;
93
93
  /**
94
- * Derive an address at the fixed testnet path for fingerprint generation.
95
- * Uses connectorCall (goes through ensureConnected). For public API use.
96
- */
97
- private _deriveAddressForFingerprint;
98
- /**
99
- * Derive an address using an existing sessionId directly.
100
- * Does NOT go through connectorCall safe to call inside connectorCall
101
- * without causing queue deadlock.
94
+ * Compute the chain fingerprint via a caller-supplied call strategy.
95
+ *
96
+ * Chains with a native device-side identity primitive (BTC → BIP32 master
97
+ * fingerprint) short-circuit at the top and return it verbatim, so the value
98
+ * stays reusable for higher-level use (BIP380 descriptors, PSBT signing).
99
+ *
100
+ * All other chains derive a fixed-path address and run it through
101
+ * `deriveDeviceFingerprint` to produce an opaque seed identifier.
102
+ *
103
+ * The two callers (`getChainFingerprint` / `_verifyDeviceFingerprintWithSession`)
104
+ * differ only in the underlying call mechanism, which is injected as `callMethod`
105
+ * to avoid queue deadlocks when running inside `connectorCall`.
102
106
  */
103
- private _deriveAddressWithSession;
107
+ private _computeChainFingerprint;
104
108
  /**
105
109
  * Ensure at least one device is connected and return a valid connectId.
106
110
  *
package/dist/index.d.ts CHANGED
@@ -91,16 +91,20 @@ declare class LedgerAdapter implements IHardwareWallet {
91
91
  */
92
92
  private _verifyDeviceFingerprintWithSession;
93
93
  /**
94
- * Derive an address at the fixed testnet path for fingerprint generation.
95
- * Uses connectorCall (goes through ensureConnected). For public API use.
96
- */
97
- private _deriveAddressForFingerprint;
98
- /**
99
- * Derive an address using an existing sessionId directly.
100
- * Does NOT go through connectorCall safe to call inside connectorCall
101
- * without causing queue deadlock.
94
+ * Compute the chain fingerprint via a caller-supplied call strategy.
95
+ *
96
+ * Chains with a native device-side identity primitive (BTC → BIP32 master
97
+ * fingerprint) short-circuit at the top and return it verbatim, so the value
98
+ * stays reusable for higher-level use (BIP380 descriptors, PSBT signing).
99
+ *
100
+ * All other chains derive a fixed-path address and run it through
101
+ * `deriveDeviceFingerprint` to produce an opaque seed identifier.
102
+ *
103
+ * The two callers (`getChainFingerprint` / `_verifyDeviceFingerprintWithSession`)
104
+ * differ only in the underlying call mechanism, which is injected as `callMethod`
105
+ * to avoid queue deadlocks when running inside `connectorCall`.
102
106
  */
103
- private _deriveAddressWithSession;
107
+ private _computeChainFingerprint;
104
108
  /**
105
109
  * Ensure at least one device is connected and return a valid connectId.
106
110
  *
package/dist/index.js CHANGED
@@ -529,19 +529,16 @@ var _LedgerAdapter = class _LedgerAdapter {
529
529
  this._sessions.size
530
530
  );
531
531
  await this._ensureDevicePermission(connectId, deviceId);
532
- debugLog(
533
- "[LedgerAdapter] getChainFingerprint permission ok, calling _deriveAddressForFingerprint"
534
- );
532
+ debugLog("[LedgerAdapter] getChainFingerprint permission ok, computing fingerprint");
535
533
  try {
536
- const address = await this._deriveAddressForFingerprint(connectId, chain);
537
- debugLog("[LedgerAdapter] getChainFingerprint address:", address?.substring(0, 20));
538
- return (0, import_hwk_adapter_core2.success)((0, import_hwk_adapter_core2.deriveDeviceFingerprint)(address));
539
- } catch (err) {
540
- debugError(
541
- "[LedgerAdapter] getChainFingerprint error in _deriveAddressForFingerprint:",
534
+ const fingerprint = await this._computeChainFingerprint(
542
535
  chain,
543
- err
536
+ (method, params) => this.connectorCall(connectId, method, params)
544
537
  );
538
+ debugLog("[LedgerAdapter] getChainFingerprint result:", fingerprint?.substring(0, 20));
539
+ return (0, import_hwk_adapter_core2.success)(fingerprint);
540
+ } catch (err) {
541
+ debugError("[LedgerAdapter] getChainFingerprint error:", chain, err);
545
542
  return this.errorToFailure(err);
546
543
  }
547
544
  }
@@ -552,8 +549,10 @@ var _LedgerAdapter = class _LedgerAdapter {
552
549
  async _verifyDeviceFingerprintWithSession(sessionId, deviceId, chain) {
553
550
  if (!deviceId) return { success: true };
554
551
  try {
555
- const address = await this._deriveAddressWithSession(sessionId, chain);
556
- const fingerprint = (0, import_hwk_adapter_core2.deriveDeviceFingerprint)(address);
552
+ const fingerprint = await this._computeChainFingerprint(
553
+ chain,
554
+ (method, params) => this.connector.call(sessionId, method, params)
555
+ );
557
556
  if (fingerprint === deviceId) {
558
557
  return { success: true };
559
558
  }
@@ -567,77 +566,36 @@ var _LedgerAdapter = class _LedgerAdapter {
567
566
  }
568
567
  }
569
568
  /**
570
- * Derive an address at the fixed testnet path for fingerprint generation.
571
- * Uses connectorCall (goes through ensureConnected). For public API use.
569
+ * Compute the chain fingerprint via a caller-supplied call strategy.
570
+ *
571
+ * Chains with a native device-side identity primitive (BTC → BIP32 master
572
+ * fingerprint) short-circuit at the top and return it verbatim, so the value
573
+ * stays reusable for higher-level use (BIP380 descriptors, PSBT signing).
574
+ *
575
+ * All other chains derive a fixed-path address and run it through
576
+ * `deriveDeviceFingerprint` to produce an opaque seed identifier.
577
+ *
578
+ * The two callers (`getChainFingerprint` / `_verifyDeviceFingerprintWithSession`)
579
+ * differ only in the underlying call mechanism, which is injected as `callMethod`
580
+ * to avoid queue deadlocks when running inside `connectorCall`.
572
581
  */
573
- async _deriveAddressForFingerprint(connectId, chain) {
574
- const path = import_hwk_adapter_core2.CHAIN_FINGERPRINT_PATHS[chain];
575
- if (chain === "evm") {
576
- const result = await this.connectorCall(connectId, "evmGetAddress", {
577
- path,
578
- showOnDevice: false
579
- });
580
- return result.address;
581
- }
582
+ async _computeChainFingerprint(chain, callMethod) {
582
583
  if (chain === "btc") {
583
- const result = await this.connectorCall(connectId, "btcGetPublicKey", {
584
- path,
585
- showOnDevice: false
586
- });
587
- return result.xpub;
584
+ const result = await callMethod("btcGetMasterFingerprint", {});
585
+ return result.masterFingerprint;
588
586
  }
589
- if (chain === "sol") {
590
- const result = await this.connectorCall(connectId, "solGetAddress", {
591
- path,
592
- showOnDevice: false
593
- });
594
- return result.address;
595
- }
596
- if (chain === "tron") {
597
- const result = await this.connectorCall(connectId, "tronGetAddress", {
598
- path,
599
- showOnDevice: false
600
- });
601
- return result.address;
602
- }
603
- throw new Error(`Unsupported chain for fingerprint: ${chain}`);
604
- }
605
- /**
606
- * Derive an address using an existing sessionId directly.
607
- * Does NOT go through connectorCall — safe to call inside connectorCall
608
- * without causing queue deadlock.
609
- */
610
- async _deriveAddressWithSession(sessionId, chain) {
611
587
  const path = import_hwk_adapter_core2.CHAIN_FINGERPRINT_PATHS[chain];
588
+ let address;
612
589
  if (chain === "evm") {
613
- const result = await this.connector.call(sessionId, "evmGetAddress", {
614
- path,
615
- showOnDevice: false
616
- });
617
- return result.address;
618
- }
619
- if (chain === "btc") {
620
- const result = await this.connector.call(sessionId, "btcGetPublicKey", {
621
- path,
622
- showOnDevice: false
623
- });
624
- return result.xpub;
625
- }
626
- if (chain === "sol") {
627
- const result = await this.connector.call(sessionId, "solGetAddress", {
628
- path,
629
- showOnDevice: false
630
- });
631
- return result.address;
632
- }
633
- if (chain === "tron") {
634
- const result = await this.connector.call(sessionId, "tronGetAddress", {
635
- path,
636
- showOnDevice: false
637
- });
638
- return result.address;
590
+ address = (await callMethod("evmGetAddress", { path, showOnDevice: false })).address;
591
+ } else if (chain === "sol") {
592
+ address = (await callMethod("solGetAddress", { path, showOnDevice: false })).address;
593
+ } else if (chain === "tron") {
594
+ address = (await callMethod("tronGetAddress", { path, showOnDevice: false })).address;
595
+ } else {
596
+ throw new Error(`Unsupported chain for fingerprint: ${chain}`);
639
597
  }
640
- throw new Error(`Unsupported chain for fingerprint: ${chain}`);
598
+ return (0, import_hwk_adapter_core2.deriveDeviceFingerprint)(address);
641
599
  }
642
600
  // Ledger WebUSB won't expose a locked device, so we can't auto-detect unlock.
643
601
  // The user must press Confirm after unlocking, which triggers a search retry.