@onekeyfe/hwk-ledger-adapter 1.1.26-alpha.104 → 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 +13 -9
- package/dist/index.d.ts +13 -9
- package/dist/index.js +43 -79
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -79
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -91,16 +91,20 @@ declare class LedgerAdapter implements IHardwareWallet {
|
|
|
91
91
|
*/
|
|
92
92
|
private _verifyDeviceFingerprintWithSession;
|
|
93
93
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
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
|
|
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
|
-
*
|
|
95
|
-
*
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
556
|
-
|
|
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
|
-
*
|
|
571
|
-
*
|
|
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
|
|
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
|
|
584
|
-
|
|
585
|
-
showOnDevice: false
|
|
586
|
-
});
|
|
587
|
-
return result.xpub;
|
|
588
|
-
}
|
|
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;
|
|
584
|
+
const result = await callMethod("btcGetMasterFingerprint", {});
|
|
585
|
+
return result.masterFingerprint;
|
|
602
586
|
}
|
|
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
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
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}`);
|
|
618
597
|
}
|
|
619
|
-
|
|
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;
|
|
639
|
-
}
|
|
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.
|
|
@@ -2337,8 +2295,14 @@ var LedgerConnectorBase = class {
|
|
|
2337
2295
|
return tronGetAddress(this._ctx, sessionId, params);
|
|
2338
2296
|
case "tronSignTransaction":
|
|
2339
2297
|
return tronSignTransaction(this._ctx, sessionId, params);
|
|
2340
|
-
case "tronSignMessage":
|
|
2341
|
-
|
|
2298
|
+
case "tronSignMessage": {
|
|
2299
|
+
const p = params;
|
|
2300
|
+
const internalParams = {
|
|
2301
|
+
path: p.path,
|
|
2302
|
+
messageHex: p.messageHex
|
|
2303
|
+
};
|
|
2304
|
+
return tronSignMessage(this._ctx, sessionId, internalParams);
|
|
2305
|
+
}
|
|
2342
2306
|
default:
|
|
2343
2307
|
throw new Error(`LedgerConnector: unknown method "${method}"`);
|
|
2344
2308
|
}
|