@onekeyfe/hwk-ledger-adapter 1.2.11-alpha.2 → 1.2.11-alpha.3
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 +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +27 -59
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -62
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -33,8 +33,7 @@ import {
|
|
|
33
33
|
HardwareErrorCode,
|
|
34
34
|
defaultOriginForCode,
|
|
35
35
|
defaultRecoveryForCode,
|
|
36
|
-
enrichErrorMessage
|
|
37
|
-
isHardwareErrorCode
|
|
36
|
+
enrichErrorMessage
|
|
38
37
|
} from "@onekeyfe/hwk-adapter-core";
|
|
39
38
|
function ledgerFailure(code, error, appName, tag, params, origin, recovery) {
|
|
40
39
|
const payload = { error, code };
|
|
@@ -226,13 +225,7 @@ function isDeviceNotAdvertisingError(err) {
|
|
|
226
225
|
if (!err || typeof err !== "object") return false;
|
|
227
226
|
return err._tag === ERROR_TAG.DeviceNotAdvertising;
|
|
228
227
|
}
|
|
229
|
-
function
|
|
230
|
-
if (!err || typeof err !== "object") return false;
|
|
231
|
-
if (err._tag === ERROR_TAG.BleGattBondingFailed) return true;
|
|
232
|
-
const orig = err.originalError;
|
|
233
|
-
return orig != null && isBleGattBondingFailedError(orig);
|
|
234
|
-
}
|
|
235
|
-
function findErrorInChain(err, matches) {
|
|
228
|
+
function isBleBondInvalidError(err) {
|
|
236
229
|
const pending = [err];
|
|
237
230
|
const seen = /* @__PURE__ */ new Set();
|
|
238
231
|
while (pending.length > 0) {
|
|
@@ -240,38 +233,22 @@ function findErrorInChain(err, matches) {
|
|
|
240
233
|
if (candidate && typeof candidate === "object" && !seen.has(candidate)) {
|
|
241
234
|
seen.add(candidate);
|
|
242
235
|
const e = candidate;
|
|
243
|
-
if (
|
|
236
|
+
if (e._tag === ERROR_TAG.PeerRemovedPairing || e.iosErrorCode === 14 || e.attErrorCode === 5 || e.nativeErrorDomain === "CBErrorDomain" && e.nativeErrorCode === 14) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
const reason = typeof e.reason === "string" ? e.reason : "";
|
|
240
|
+
const message = typeof e.message === "string" ? e.message : "";
|
|
241
|
+
if (/\bCBErrorDomain:14(?:\s|$)/.test(message) || reason.includes("Peer removed pairing information") || reason.includes("GATT_INSUF_AUTHENTICATION")) {
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
244
|
pending.push(e.originalError, e.err);
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
-
return
|
|
248
|
-
}
|
|
249
|
-
function someErrorInChain(err, matches) {
|
|
250
|
-
return findErrorInChain(err, matches) !== void 0;
|
|
251
|
-
}
|
|
252
|
-
function findCanonicalBleError(err) {
|
|
253
|
-
return findErrorInChain(err, (e) => isHardwareErrorCode(e.code));
|
|
254
|
-
}
|
|
255
|
-
function isBleBondInvalidError(err) {
|
|
256
|
-
return someErrorInChain(err, (e) => {
|
|
257
|
-
if (
|
|
258
|
-
// Already canonical: the desktop BLE host or a connector mapped the native signal.
|
|
259
|
-
e.code === HardwareErrorCode.BleBondInvalid || e._tag === ERROR_TAG.PeerRemovedPairing || e.iosErrorCode === 14 || e.attErrorCode === 5 || e.nativeErrorDomain === "CBErrorDomain" && e.nativeErrorCode === 14
|
|
260
|
-
) {
|
|
261
|
-
return true;
|
|
262
|
-
}
|
|
263
|
-
const reason = typeof e.reason === "string" ? e.reason : "";
|
|
264
|
-
return reason.includes("Peer removed pairing information") || reason.includes("GATT_INSUF_AUTHENTICATION");
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
function isBleNotAdvertisingTimeoutError(err) {
|
|
268
|
-
return someErrorInChain(
|
|
269
|
-
err,
|
|
270
|
-
(e) => e.code === HardwareErrorCode.DeviceNotFound && e.params?.notAdvertising === true
|
|
271
|
-
);
|
|
247
|
+
return false;
|
|
272
248
|
}
|
|
273
249
|
var PAIRING_FAILURE_TAGS = /* @__PURE__ */ new Set([
|
|
274
250
|
ERROR_TAG.BlePairingTimeout,
|
|
251
|
+
ERROR_TAG.BleGattBondingFailed,
|
|
275
252
|
ERROR_TAG.PairingRefused
|
|
276
253
|
]);
|
|
277
254
|
function isBlePairingFailureError(err) {
|
|
@@ -528,8 +505,6 @@ function mapLedgerError(err, opts) {
|
|
|
528
505
|
code = HardwareErrorCode.BleBondInvalid;
|
|
529
506
|
} else if (isBlePairingFailureError(err)) {
|
|
530
507
|
code = HardwareErrorCode.BlePairingTimeout;
|
|
531
|
-
} else if (isBleGattBondingFailedError(err)) {
|
|
532
|
-
code = HardwareErrorCode.BleConnectFailed;
|
|
533
508
|
} else if (isDeviceBusyError(err)) {
|
|
534
509
|
code = HardwareErrorCode.DeviceBusy;
|
|
535
510
|
} else if (isUserAbortedError(err)) {
|
|
@@ -964,7 +939,6 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
964
939
|
this._operations = new OperationRegistry({
|
|
965
940
|
vendor: "ledger",
|
|
966
941
|
onEnded: (operation, reason) => {
|
|
967
|
-
debugLog("[LedgerAdapter] operation ended", { operationId: operation.operationId, reason });
|
|
968
942
|
this._discardPendingBinding(this._pendingOperationBindings.get(operation.operationId));
|
|
969
943
|
this._pendingOperationBindings.delete(operation.operationId);
|
|
970
944
|
this.emitter.emit(SDK.OPERATION_ENDED, {
|
|
@@ -2696,8 +2670,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
2696
2670
|
if (!result.success) {
|
|
2697
2671
|
const payload = result.payload;
|
|
2698
2672
|
const rethrow = Object.assign(new Error(payload.error), {
|
|
2699
|
-
code: payload.code
|
|
2700
|
-
...payload.params ? { params: payload.params } : {}
|
|
2673
|
+
code: payload.code
|
|
2701
2674
|
});
|
|
2702
2675
|
if (payload._tag !== void 0) {
|
|
2703
2676
|
rethrow._tag = payload._tag;
|
|
@@ -3281,10 +3254,9 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
3281
3254
|
}
|
|
3282
3255
|
const { granted, reason, message } = response;
|
|
3283
3256
|
if (!granted) {
|
|
3284
|
-
throw
|
|
3257
|
+
throw Object.assign(new Error(message ?? "Device permission denied"), {
|
|
3285
3258
|
code: HardwareErrorCode3.DevicePermissionDenied,
|
|
3286
|
-
|
|
3287
|
-
...reason ? { params: { permissionDeniedReason: reason } } : {}
|
|
3259
|
+
reason
|
|
3288
3260
|
});
|
|
3289
3261
|
}
|
|
3290
3262
|
}
|
|
@@ -3297,12 +3269,13 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
3297
3269
|
const tag = err && typeof err === "object" ? err._tag : void 0;
|
|
3298
3270
|
if (err && typeof err === "object" && "code" in err && typeof err.code === "number") {
|
|
3299
3271
|
const e = err;
|
|
3272
|
+
const params = e.code === HardwareErrorCode3.DevicePermissionDenied && e.reason ? { permissionDeniedReason: e.reason } : e.params;
|
|
3300
3273
|
return ledgerFailure(
|
|
3301
3274
|
e.code,
|
|
3302
3275
|
e.message ?? "Unknown error",
|
|
3303
3276
|
e.appName,
|
|
3304
3277
|
tag,
|
|
3305
|
-
|
|
3278
|
+
params,
|
|
3306
3279
|
void 0,
|
|
3307
3280
|
isHwkRecoveryHint(e.recovery) ? e.recovery : void 0
|
|
3308
3281
|
);
|
|
@@ -3361,7 +3334,6 @@ import {
|
|
|
3361
3334
|
EConnectorInteraction as EConnectorInteraction3,
|
|
3362
3335
|
HardwareErrorCode as HardwareErrorCode7,
|
|
3363
3336
|
createHwkError as createHwkError2,
|
|
3364
|
-
isHardwareErrorCode as isHardwareErrorCode2,
|
|
3365
3337
|
isKnownNonTargetHardwareVendor,
|
|
3366
3338
|
serializeConnectorError
|
|
3367
3339
|
} from "@onekeyfe/hwk-adapter-core";
|
|
@@ -5019,6 +4991,9 @@ function withOpenAppName(event, data, appName) {
|
|
|
5019
4991
|
}
|
|
5020
4992
|
return { ...uiEvent, payload: { ...uiEvent.payload, appName } };
|
|
5021
4993
|
}
|
|
4994
|
+
var HARDWARE_ERROR_CODE_VALUES = new Set(
|
|
4995
|
+
Object.values(HardwareErrorCode7).filter((value) => typeof value === "number")
|
|
4996
|
+
);
|
|
5022
4997
|
var BLE_CONNECT_SCAN_TIMEOUT_MS = 1500;
|
|
5023
4998
|
var LEDGER_RELAY_ALLOWED_ROOT_DOMAINS = ["onekeytest.com", "onekey.com"];
|
|
5024
4999
|
function isAllowedLedgerRelayHost(hostname) {
|
|
@@ -5078,11 +5053,6 @@ async function _getDeviceApps(ctx, sessionId) {
|
|
|
5078
5053
|
};
|
|
5079
5054
|
return apps;
|
|
5080
5055
|
}
|
|
5081
|
-
function describeCaller(error) {
|
|
5082
|
-
return (error.stack ?? "").split("\n").slice(2, 6).map(
|
|
5083
|
-
(frame) => frame.trim().replace(/^at /, "").replace(/ \(.*\)$/, "")
|
|
5084
|
-
).join(" <- ");
|
|
5085
|
-
}
|
|
5086
5056
|
var LedgerConnectorBase = class {
|
|
5087
5057
|
constructor(createTransport, options) {
|
|
5088
5058
|
this._deviceManager = null;
|
|
@@ -5318,21 +5288,17 @@ var LedgerConnectorBase = class {
|
|
|
5318
5288
|
_tag: ERROR_TAG.PeerRemovedPairing
|
|
5319
5289
|
});
|
|
5320
5290
|
}
|
|
5321
|
-
if (isBleNotAdvertisingTimeoutError(err)) throwNotAdvertising();
|
|
5322
|
-
const canonical = findCanonicalBleError(err);
|
|
5323
|
-
if (canonical) throw canonical;
|
|
5324
5291
|
const tag = err?._tag;
|
|
5325
5292
|
if (isKnownConnectionTag(tag) && !isConnectionOpeningTag(tag)) {
|
|
5326
5293
|
throw err;
|
|
5327
5294
|
}
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
code: HardwareErrorCode7.BleConnectFailed,
|
|
5331
|
-
message: "Ledger Bluetooth connection failed. Make sure the device is unlocked and nearby, then try again.",
|
|
5332
|
-
_tag: ERROR_TAG.BleGattBondingFailed
|
|
5333
|
-
}),
|
|
5334
|
-
{ originalError: err }
|
|
5295
|
+
const wrapped = new Error(
|
|
5296
|
+
"Ledger Bluetooth pairing failed. Make sure the device is unlocked and nearby, then try again."
|
|
5335
5297
|
);
|
|
5298
|
+
wrapped._tag = ERROR_TAG.BleGattBondingFailed;
|
|
5299
|
+
wrapped.code = HardwareErrorCode7.BlePairingTimeout;
|
|
5300
|
+
wrapped.originalError = err;
|
|
5301
|
+
throw wrapped;
|
|
5336
5302
|
}
|
|
5337
5303
|
if (err && typeof err === "object" && err._tag) {
|
|
5338
5304
|
const taggedError = err instanceof Error ? err : Object.assign(
|
|
@@ -5346,7 +5312,6 @@ var LedgerConnectorBase = class {
|
|
|
5346
5312
|
}
|
|
5347
5313
|
async disconnect(sessionId) {
|
|
5348
5314
|
if (!this._deviceManager) return;
|
|
5349
|
-
debugLog("[DMK] disconnect requested", { caller: describeCaller(new Error()) });
|
|
5350
5315
|
const deviceId = this._deviceManager.getDeviceId(sessionId);
|
|
5351
5316
|
this._signerManager?.invalidate(sessionId);
|
|
5352
5317
|
this._unwatchSessionState(sessionId);
|
|
@@ -5849,7 +5814,8 @@ var LedgerConnectorBase = class {
|
|
|
5849
5814
|
}
|
|
5850
5815
|
_wrapError(err, opts) {
|
|
5851
5816
|
const src = err && typeof err === "object" ? err : {};
|
|
5852
|
-
const
|
|
5817
|
+
const hasSerializedCode = typeof src.code === "number" && HARDWARE_ERROR_CODE_VALUES.has(src.code);
|
|
5818
|
+
const mapped = hasSerializedCode ? {
|
|
5853
5819
|
code: src.code,
|
|
5854
5820
|
message: typeof src.message === "string" ? src.message : "Unknown Ledger error",
|
|
5855
5821
|
appName: typeof src.appName === "string" ? src.appName : opts?.defaultAppName
|