@onekeyfe/hwk-ledger-adapter 1.2.11-alpha.8 → 1.2.11-alpha.9
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 +0 -22
- package/dist/index.d.ts +0 -22
- package/dist/index.js +59 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -28
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -418,28 +418,6 @@ interface LedgerConnectorBaseOptions {
|
|
|
418
418
|
*/
|
|
419
419
|
dmk?: DeviceManagementKit;
|
|
420
420
|
}
|
|
421
|
-
/**
|
|
422
|
-
* Shared base class for Ledger IConnector implementations.
|
|
423
|
-
*
|
|
424
|
-
* Encapsulates all shared logic: device discovery, connection management,
|
|
425
|
-
* method dispatch (EVM / BTC / SOL / TRON), signer lifecycle, event emission,
|
|
426
|
-
* and error handling.
|
|
427
|
-
*
|
|
428
|
-
* Chain-specific method implementations live in `./chains/` and receive
|
|
429
|
-
* a ConnectorContext that exposes shared helpers.
|
|
430
|
-
*
|
|
431
|
-
* Subclasses only need to:
|
|
432
|
-
* 1. Supply a transport factory via the constructor.
|
|
433
|
-
* 2. Optionally override `_resolveConnectId()` for transport-specific
|
|
434
|
-
* device identity resolution.
|
|
435
|
-
*
|
|
436
|
-
* Invariant: one instance = one transport. `connectionType` is fixed at
|
|
437
|
-
* construction. To switch transport (e.g. desktop BLE ↔ WebHID), the host
|
|
438
|
-
* must build a new connector instance and replace the old one — don't add
|
|
439
|
-
* multiple transports to a single instance. Lifting this constraint would
|
|
440
|
-
* require routing `connectionType` from `descriptor.transport` per-device
|
|
441
|
-
* and updating every `this.connectionType` branch in this file.
|
|
442
|
-
*/
|
|
443
421
|
declare class LedgerConnectorBase implements IConnector {
|
|
444
422
|
private _deviceManager;
|
|
445
423
|
private _signerManager;
|
package/dist/index.d.ts
CHANGED
|
@@ -418,28 +418,6 @@ interface LedgerConnectorBaseOptions {
|
|
|
418
418
|
*/
|
|
419
419
|
dmk?: DeviceManagementKit;
|
|
420
420
|
}
|
|
421
|
-
/**
|
|
422
|
-
* Shared base class for Ledger IConnector implementations.
|
|
423
|
-
*
|
|
424
|
-
* Encapsulates all shared logic: device discovery, connection management,
|
|
425
|
-
* method dispatch (EVM / BTC / SOL / TRON), signer lifecycle, event emission,
|
|
426
|
-
* and error handling.
|
|
427
|
-
*
|
|
428
|
-
* Chain-specific method implementations live in `./chains/` and receive
|
|
429
|
-
* a ConnectorContext that exposes shared helpers.
|
|
430
|
-
*
|
|
431
|
-
* Subclasses only need to:
|
|
432
|
-
* 1. Supply a transport factory via the constructor.
|
|
433
|
-
* 2. Optionally override `_resolveConnectId()` for transport-specific
|
|
434
|
-
* device identity resolution.
|
|
435
|
-
*
|
|
436
|
-
* Invariant: one instance = one transport. `connectionType` is fixed at
|
|
437
|
-
* construction. To switch transport (e.g. desktop BLE ↔ WebHID), the host
|
|
438
|
-
* must build a new connector instance and replace the old one — don't add
|
|
439
|
-
* multiple transports to a single instance. Lifting this constraint would
|
|
440
|
-
* require routing `connectionType` from `descriptor.transport` per-device
|
|
441
|
-
* and updating every `this.connectionType` branch in this file.
|
|
442
|
-
*/
|
|
443
421
|
declare class LedgerConnectorBase implements IConnector {
|
|
444
422
|
private _deviceManager;
|
|
445
423
|
private _signerManager;
|
package/dist/index.js
CHANGED
|
@@ -248,7 +248,13 @@ function isDeviceNotAdvertisingError(err) {
|
|
|
248
248
|
if (!err || typeof err !== "object") return false;
|
|
249
249
|
return err._tag === ERROR_TAG.DeviceNotAdvertising;
|
|
250
250
|
}
|
|
251
|
-
function
|
|
251
|
+
function isBleGattBondingFailedError(err) {
|
|
252
|
+
if (!err || typeof err !== "object") return false;
|
|
253
|
+
if (err._tag === ERROR_TAG.BleGattBondingFailed) return true;
|
|
254
|
+
const orig = err.originalError;
|
|
255
|
+
return orig != null && isBleGattBondingFailedError(orig);
|
|
256
|
+
}
|
|
257
|
+
function findErrorInChain(err, matches) {
|
|
252
258
|
const pending = [err];
|
|
253
259
|
const seen = /* @__PURE__ */ new Set();
|
|
254
260
|
while (pending.length > 0) {
|
|
@@ -256,22 +262,38 @@ function isBleBondInvalidError(err) {
|
|
|
256
262
|
if (candidate && typeof candidate === "object" && !seen.has(candidate)) {
|
|
257
263
|
seen.add(candidate);
|
|
258
264
|
const e = candidate;
|
|
259
|
-
if (e
|
|
260
|
-
return true;
|
|
261
|
-
}
|
|
262
|
-
const reason = typeof e.reason === "string" ? e.reason : "";
|
|
263
|
-
const message = typeof e.message === "string" ? e.message : "";
|
|
264
|
-
if (/\bCBErrorDomain:14(?:\s|$)/.test(message) || reason.includes("Peer removed pairing information") || reason.includes("GATT_INSUF_AUTHENTICATION")) {
|
|
265
|
-
return true;
|
|
266
|
-
}
|
|
265
|
+
if (matches(e)) return e;
|
|
267
266
|
pending.push(e.originalError, e.err);
|
|
268
267
|
}
|
|
269
268
|
}
|
|
270
|
-
return
|
|
269
|
+
return void 0;
|
|
270
|
+
}
|
|
271
|
+
function someErrorInChain(err, matches) {
|
|
272
|
+
return findErrorInChain(err, matches) !== void 0;
|
|
273
|
+
}
|
|
274
|
+
function findCanonicalBleError(err) {
|
|
275
|
+
return findErrorInChain(err, (e) => (0, import_hwk_adapter_core.isHardwareErrorCode)(e.code));
|
|
276
|
+
}
|
|
277
|
+
function isBleBondInvalidError(err) {
|
|
278
|
+
return someErrorInChain(err, (e) => {
|
|
279
|
+
if (
|
|
280
|
+
// Already canonical: the desktop BLE host or a connector mapped the native signal.
|
|
281
|
+
e.code === import_hwk_adapter_core.HardwareErrorCode.BleBondInvalid || e._tag === ERROR_TAG.PeerRemovedPairing || e.iosErrorCode === 14 || e.attErrorCode === 5 || e.nativeErrorDomain === "CBErrorDomain" && e.nativeErrorCode === 14
|
|
282
|
+
) {
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
const reason = typeof e.reason === "string" ? e.reason : "";
|
|
286
|
+
return reason.includes("Peer removed pairing information") || reason.includes("GATT_INSUF_AUTHENTICATION");
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
function isBleNotAdvertisingTimeoutError(err) {
|
|
290
|
+
return someErrorInChain(
|
|
291
|
+
err,
|
|
292
|
+
(e) => e.code === import_hwk_adapter_core.HardwareErrorCode.DeviceNotFound && e.params?.notAdvertising === true
|
|
293
|
+
);
|
|
271
294
|
}
|
|
272
295
|
var PAIRING_FAILURE_TAGS = /* @__PURE__ */ new Set([
|
|
273
296
|
ERROR_TAG.BlePairingTimeout,
|
|
274
|
-
ERROR_TAG.BleGattBondingFailed,
|
|
275
297
|
ERROR_TAG.PairingRefused
|
|
276
298
|
]);
|
|
277
299
|
function isBlePairingFailureError(err) {
|
|
@@ -528,6 +550,8 @@ function mapLedgerError(err, opts) {
|
|
|
528
550
|
code = import_hwk_adapter_core.HardwareErrorCode.BleBondInvalid;
|
|
529
551
|
} else if (isBlePairingFailureError(err)) {
|
|
530
552
|
code = import_hwk_adapter_core.HardwareErrorCode.BlePairingTimeout;
|
|
553
|
+
} else if (isBleGattBondingFailedError(err)) {
|
|
554
|
+
code = import_hwk_adapter_core.HardwareErrorCode.BleConnectFailed;
|
|
531
555
|
} else if (isDeviceBusyError(err)) {
|
|
532
556
|
code = import_hwk_adapter_core.HardwareErrorCode.DeviceBusy;
|
|
533
557
|
} else if (isUserAbortedError(err)) {
|
|
@@ -952,6 +976,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
952
976
|
this._operations = new import_hwk_adapter_core4.OperationRegistry({
|
|
953
977
|
vendor: "ledger",
|
|
954
978
|
onEnded: (operation, reason) => {
|
|
979
|
+
debugLog("[LedgerAdapter] operation ended", { operationId: operation.operationId, reason });
|
|
955
980
|
this._discardPendingBinding(this._pendingOperationBindings.get(operation.operationId));
|
|
956
981
|
this._pendingOperationBindings.delete(operation.operationId);
|
|
957
982
|
this.emitter.emit(import_hwk_adapter_core4.SDK.OPERATION_ENDED, {
|
|
@@ -2683,7 +2708,8 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
2683
2708
|
if (!result.success) {
|
|
2684
2709
|
const payload = result.payload;
|
|
2685
2710
|
const rethrow = Object.assign(new Error(payload.error), {
|
|
2686
|
-
code: payload.code
|
|
2711
|
+
code: payload.code,
|
|
2712
|
+
...payload.params ? { params: payload.params } : {}
|
|
2687
2713
|
});
|
|
2688
2714
|
if (payload._tag !== void 0) {
|
|
2689
2715
|
rethrow._tag = payload._tag;
|
|
@@ -3267,9 +3293,10 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
3267
3293
|
}
|
|
3268
3294
|
const { granted, reason, message } = response;
|
|
3269
3295
|
if (!granted) {
|
|
3270
|
-
throw
|
|
3296
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
3271
3297
|
code: import_hwk_adapter_core4.HardwareErrorCode.DevicePermissionDenied,
|
|
3272
|
-
|
|
3298
|
+
message: message ?? "Device permission denied",
|
|
3299
|
+
...reason ? { params: { permissionDeniedReason: reason } } : {}
|
|
3273
3300
|
});
|
|
3274
3301
|
}
|
|
3275
3302
|
}
|
|
@@ -3282,13 +3309,12 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
3282
3309
|
const tag = err && typeof err === "object" ? err._tag : void 0;
|
|
3283
3310
|
if (err && typeof err === "object" && "code" in err && typeof err.code === "number") {
|
|
3284
3311
|
const e = err;
|
|
3285
|
-
const params = e.code === import_hwk_adapter_core4.HardwareErrorCode.DevicePermissionDenied && e.reason ? { permissionDeniedReason: e.reason } : e.params;
|
|
3286
3312
|
return ledgerFailure(
|
|
3287
3313
|
e.code,
|
|
3288
3314
|
e.message ?? "Unknown error",
|
|
3289
3315
|
e.appName,
|
|
3290
3316
|
tag,
|
|
3291
|
-
params,
|
|
3317
|
+
e.params,
|
|
3292
3318
|
void 0,
|
|
3293
3319
|
(0, import_hwk_adapter_core4.isHwkRecoveryHint)(e.recovery) ? e.recovery : void 0
|
|
3294
3320
|
);
|
|
@@ -4998,9 +5024,6 @@ function withOpenAppName(event, data, appName) {
|
|
|
4998
5024
|
}
|
|
4999
5025
|
return { ...uiEvent, payload: { ...uiEvent.payload, appName } };
|
|
5000
5026
|
}
|
|
5001
|
-
var HARDWARE_ERROR_CODE_VALUES = new Set(
|
|
5002
|
-
Object.values(import_hwk_adapter_core13.HardwareErrorCode).filter((value) => typeof value === "number")
|
|
5003
|
-
);
|
|
5004
5027
|
var BLE_CONNECT_SCAN_TIMEOUT_MS = 1500;
|
|
5005
5028
|
var LEDGER_RELAY_ALLOWED_ROOT_DOMAINS = ["onekeytest.com", "onekey.com"];
|
|
5006
5029
|
function isAllowedLedgerRelayHost(hostname) {
|
|
@@ -5060,6 +5083,11 @@ async function _getDeviceApps(ctx, sessionId) {
|
|
|
5060
5083
|
};
|
|
5061
5084
|
return apps;
|
|
5062
5085
|
}
|
|
5086
|
+
function describeCaller(error) {
|
|
5087
|
+
return (error.stack ?? "").split("\n").slice(2, 6).map(
|
|
5088
|
+
(frame) => frame.trim().replace(/^at /, "").replace(/ \(.*\)$/, "")
|
|
5089
|
+
).join(" <- ");
|
|
5090
|
+
}
|
|
5063
5091
|
var LedgerConnectorBase = class {
|
|
5064
5092
|
constructor(createTransport, options) {
|
|
5065
5093
|
this._deviceManager = null;
|
|
@@ -5295,17 +5323,21 @@ var LedgerConnectorBase = class {
|
|
|
5295
5323
|
_tag: ERROR_TAG.PeerRemovedPairing
|
|
5296
5324
|
});
|
|
5297
5325
|
}
|
|
5326
|
+
if (isBleNotAdvertisingTimeoutError(err)) throwNotAdvertising();
|
|
5327
|
+
const canonical = findCanonicalBleError(err);
|
|
5328
|
+
if (canonical) throw canonical;
|
|
5298
5329
|
const tag = err?._tag;
|
|
5299
5330
|
if (isKnownConnectionTag(tag) && !isConnectionOpeningTag(tag)) {
|
|
5300
5331
|
throw err;
|
|
5301
5332
|
}
|
|
5302
|
-
|
|
5303
|
-
|
|
5333
|
+
throw Object.assign(
|
|
5334
|
+
(0, import_hwk_adapter_core13.createHwkError)({
|
|
5335
|
+
code: import_hwk_adapter_core13.HardwareErrorCode.BleConnectFailed,
|
|
5336
|
+
message: "Ledger Bluetooth connection failed. Make sure the device is unlocked and nearby, then try again.",
|
|
5337
|
+
_tag: ERROR_TAG.BleGattBondingFailed
|
|
5338
|
+
}),
|
|
5339
|
+
{ originalError: err }
|
|
5304
5340
|
);
|
|
5305
|
-
wrapped._tag = ERROR_TAG.BleGattBondingFailed;
|
|
5306
|
-
wrapped.code = import_hwk_adapter_core13.HardwareErrorCode.BlePairingTimeout;
|
|
5307
|
-
wrapped.originalError = err;
|
|
5308
|
-
throw wrapped;
|
|
5309
5341
|
}
|
|
5310
5342
|
if (err && typeof err === "object" && err._tag) {
|
|
5311
5343
|
const taggedError = err instanceof Error ? err : Object.assign(
|
|
@@ -5319,6 +5351,7 @@ var LedgerConnectorBase = class {
|
|
|
5319
5351
|
}
|
|
5320
5352
|
async disconnect(sessionId) {
|
|
5321
5353
|
if (!this._deviceManager) return;
|
|
5354
|
+
debugLog("[DMK] disconnect requested", { caller: describeCaller(new Error()) });
|
|
5322
5355
|
const deviceId = this._deviceManager.getDeviceId(sessionId);
|
|
5323
5356
|
this._signerManager?.invalidate(sessionId);
|
|
5324
5357
|
this._unwatchSessionState(sessionId);
|
|
@@ -5821,8 +5854,7 @@ var LedgerConnectorBase = class {
|
|
|
5821
5854
|
}
|
|
5822
5855
|
_wrapError(err, opts) {
|
|
5823
5856
|
const src = err && typeof err === "object" ? err : {};
|
|
5824
|
-
const
|
|
5825
|
-
const mapped = hasSerializedCode ? {
|
|
5857
|
+
const mapped = (0, import_hwk_adapter_core13.isHardwareErrorCode)(src.code) ? {
|
|
5826
5858
|
code: src.code,
|
|
5827
5859
|
message: typeof src.message === "string" ? src.message : "Unknown Ledger error",
|
|
5828
5860
|
appName: typeof src.appName === "string" ? src.appName : opts?.defaultAppName
|