@onekeyfe/hwk-ledger-adapter 1.1.26-alpha.4 → 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.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +71 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -590,4 +590,11 @@ declare function setDebugEnabled(value: boolean): void;
|
|
|
590
590
|
/** Returns the current debug-enabled state. */
|
|
591
591
|
declare function isDebugEnabled(): boolean;
|
|
592
592
|
|
|
593
|
-
|
|
593
|
+
/**
|
|
594
|
+
* Extract the stable 4-digit HEX identifier from a Ledger BLE device name.
|
|
595
|
+
* e.g., "Nano X 123A" -> "123A", "Ledger Nano X AB12" -> "AB12"
|
|
596
|
+
* Returns undefined if no valid HEX suffix found.
|
|
597
|
+
*/
|
|
598
|
+
declare function extractBleHexId(name?: string): string | undefined;
|
|
599
|
+
|
|
600
|
+
export { AppManager, type DeviceActionState, type DmkDiscoveredDevice, DmkTransport, LedgerAdapter, LedgerConnectorBase, type LedgerConnectorBaseOptions, LedgerDeviceManager, type LedgerFailure, SignerBtc, type SignerBtcAddress, SignerEth, type SignerEvmAddress, type SignerEvmSignature, SignerManager, SignerSol, type TransportFactory, deviceActionToPromise, extractBleHexId, isDebugEnabled, isDeviceLockedError, ledgerFailure, mapLedgerError, setDebugEnabled };
|
package/dist/index.d.ts
CHANGED
|
@@ -590,4 +590,11 @@ declare function setDebugEnabled(value: boolean): void;
|
|
|
590
590
|
/** Returns the current debug-enabled state. */
|
|
591
591
|
declare function isDebugEnabled(): boolean;
|
|
592
592
|
|
|
593
|
-
|
|
593
|
+
/**
|
|
594
|
+
* Extract the stable 4-digit HEX identifier from a Ledger BLE device name.
|
|
595
|
+
* e.g., "Nano X 123A" -> "123A", "Ledger Nano X AB12" -> "AB12"
|
|
596
|
+
* Returns undefined if no valid HEX suffix found.
|
|
597
|
+
*/
|
|
598
|
+
declare function extractBleHexId(name?: string): string | undefined;
|
|
599
|
+
|
|
600
|
+
export { AppManager, type DeviceActionState, type DmkDiscoveredDevice, DmkTransport, LedgerAdapter, LedgerConnectorBase, type LedgerConnectorBaseOptions, LedgerDeviceManager, type LedgerFailure, SignerBtc, type SignerBtcAddress, SignerEth, type SignerEvmAddress, type SignerEvmSignature, SignerManager, SignerSol, type TransportFactory, deviceActionToPromise, extractBleHexId, isDebugEnabled, isDeviceLockedError, ledgerFailure, mapLedgerError, setDebugEnabled };
|
package/dist/index.js
CHANGED
|
@@ -40,6 +40,7 @@ __export(index_exports, {
|
|
|
40
40
|
SignerManager: () => SignerManager,
|
|
41
41
|
SignerSol: () => SignerSol,
|
|
42
42
|
deviceActionToPromise: () => deviceActionToPromise,
|
|
43
|
+
extractBleHexId: () => extractBleHexId,
|
|
43
44
|
isDebugEnabled: () => isDebugEnabled,
|
|
44
45
|
isDeviceLockedError: () => isDeviceLockedError,
|
|
45
46
|
ledgerFailure: () => ledgerFailure,
|
|
@@ -75,6 +76,58 @@ function getEthAppErrorCode(err) {
|
|
|
75
76
|
}
|
|
76
77
|
return null;
|
|
77
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
|
+
}
|
|
78
131
|
function mapEthAppError(ethCode, lastStep) {
|
|
79
132
|
switch (ethCode) {
|
|
80
133
|
case "6a80":
|
|
@@ -190,8 +243,10 @@ function mapLedgerError(err) {
|
|
|
190
243
|
} else {
|
|
191
244
|
const ethCode = getEthAppErrorCode(err);
|
|
192
245
|
const lastStep = err && typeof err === "object" ? err._lastStep : void 0;
|
|
193
|
-
const
|
|
194
|
-
|
|
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;
|
|
195
250
|
}
|
|
196
251
|
const appName = err && typeof err === "object" ? err.appName : void 0;
|
|
197
252
|
return { code, message: (0, import_hwk_adapter_core.enrichErrorMessage)(code, originalMessage), appName };
|
|
@@ -869,7 +924,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
869
924
|
* If not granted, calls onDevicePermission so the consumer can request access.
|
|
870
925
|
*/
|
|
871
926
|
async _ensureDevicePermission(connectId, deviceId) {
|
|
872
|
-
const transportType = "hid";
|
|
927
|
+
const transportType = this.activeTransport ?? "hid";
|
|
873
928
|
let granted = false;
|
|
874
929
|
let context;
|
|
875
930
|
if (this._uiHandler?.checkDevicePermission) {
|
|
@@ -1597,7 +1652,7 @@ async function btcGetAddress(ctx, sessionId, params) {
|
|
|
1597
1652
|
const { DefaultWallet, DefaultDescriptorTemplate } = await ctx.importLedgerKit(
|
|
1598
1653
|
"@ledgerhq/device-signer-kit-bitcoin"
|
|
1599
1654
|
);
|
|
1600
|
-
const purpose = path.split("/")[0]?.
|
|
1655
|
+
const purpose = path.split("/")[0]?.replace(/'/g, "");
|
|
1601
1656
|
const template = _purposeToTemplate(purpose, DefaultDescriptorTemplate);
|
|
1602
1657
|
const wallet = new DefaultWallet(path, template);
|
|
1603
1658
|
debugLog("[LedgerConnector] btcGetAddress params:", {
|
|
@@ -1651,7 +1706,7 @@ async function btcSignTransaction(ctx, sessionId, params) {
|
|
|
1651
1706
|
"@ledgerhq/device-signer-kit-bitcoin"
|
|
1652
1707
|
);
|
|
1653
1708
|
const path = normalizePath(params.path || "84'/0'/0'");
|
|
1654
|
-
const purpose = path.split("/")[0]?.
|
|
1709
|
+
const purpose = path.split("/")[0]?.replace(/'/g, "");
|
|
1655
1710
|
const template = _purposeToTemplate(purpose, DefaultDescriptorTemplate);
|
|
1656
1711
|
const wallet = new DefaultWallet(path, template);
|
|
1657
1712
|
const signedTxHex = await btcSigner.signTransaction(wallet, params.psbt);
|
|
@@ -1675,7 +1730,7 @@ async function btcSignPsbt(ctx, sessionId, params) {
|
|
|
1675
1730
|
"@ledgerhq/device-signer-kit-bitcoin"
|
|
1676
1731
|
);
|
|
1677
1732
|
const path = normalizePath(params.path || "84'/0'/0'");
|
|
1678
|
-
const purpose = path.split("/")[0]?.
|
|
1733
|
+
const purpose = path.split("/")[0]?.replace(/'/g, "");
|
|
1679
1734
|
const template = _purposeToTemplate(purpose, DefaultDescriptorTemplate);
|
|
1680
1735
|
const wallet = new DefaultWallet(path, template);
|
|
1681
1736
|
const signatures = await btcSigner.signPsbt(wallet, params.psbt);
|
|
@@ -2026,35 +2081,8 @@ var AppManager = class {
|
|
|
2026
2081
|
};
|
|
2027
2082
|
|
|
2028
2083
|
// src/connector/chains/legacyAppRetry.ts
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
27013,
|
|
2032
|
-
// user denied
|
|
2033
|
-
21781,
|
|
2034
|
-
// device locked
|
|
2035
|
-
27274,
|
|
2036
|
-
// invalid BIP32 path
|
|
2037
|
-
27275,
|
|
2038
|
-
27276,
|
|
2039
|
-
27277,
|
|
2040
|
-
// app-specific data errors
|
|
2041
|
-
27264,
|
|
2042
|
-
// invalid data
|
|
2043
|
-
27392,
|
|
2044
|
-
// wrong parameter
|
|
2045
|
-
26368
|
|
2046
|
-
// wrong length
|
|
2047
|
-
])
|
|
2048
|
-
};
|
|
2049
|
-
function isLegacyWrongAppError(err, appName) {
|
|
2050
|
-
if (isWrongAppError(err)) return true;
|
|
2051
|
-
const msg = err instanceof Error ? err.message : "";
|
|
2052
|
-
const match = msg.match(/0x([0-9a-fA-F]{4})/);
|
|
2053
|
-
if (!match) return false;
|
|
2054
|
-
const sw = parseInt(match[1], 16);
|
|
2055
|
-
const knownCodes = KNOWN_APP_CODES[appName];
|
|
2056
|
-
if (knownCodes?.has(sw)) return false;
|
|
2057
|
-
return true;
|
|
2084
|
+
function isLegacyWrongAppError(err, _appName) {
|
|
2085
|
+
return isWrongAppError(err);
|
|
2058
2086
|
}
|
|
2059
2087
|
async function withLegacyAppRetry(ctx, sessionId, appName, action) {
|
|
2060
2088
|
try {
|
|
@@ -2593,6 +2621,13 @@ var LedgerConnectorBase = class {
|
|
|
2593
2621
|
return error;
|
|
2594
2622
|
}
|
|
2595
2623
|
};
|
|
2624
|
+
|
|
2625
|
+
// src/utils/bleIdentity.ts
|
|
2626
|
+
function extractBleHexId(name) {
|
|
2627
|
+
if (!name) return void 0;
|
|
2628
|
+
const match = name.match(/\b([0-9A-Fa-f]{4})$/);
|
|
2629
|
+
return match ? match[1].toUpperCase() : void 0;
|
|
2630
|
+
}
|
|
2596
2631
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2597
2632
|
0 && (module.exports = {
|
|
2598
2633
|
AppManager,
|
|
@@ -2605,6 +2640,7 @@ var LedgerConnectorBase = class {
|
|
|
2605
2640
|
SignerManager,
|
|
2606
2641
|
SignerSol,
|
|
2607
2642
|
deviceActionToPromise,
|
|
2643
|
+
extractBleHexId,
|
|
2608
2644
|
isDebugEnabled,
|
|
2609
2645
|
isDeviceLockedError,
|
|
2610
2646
|
ledgerFailure,
|