@onekeyfe/hwk-ledger-adapter 1.1.28 → 1.2.0-alpha.1
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 -6
- package/dist/index.d.ts +0 -6
- package/dist/index.js +220 -723
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +151 -655
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -4,16 +4,15 @@ import {
|
|
|
4
4
|
DEVICE,
|
|
5
5
|
DeviceJobQueue,
|
|
6
6
|
EConnectorInteraction,
|
|
7
|
-
HardwareErrorCode as
|
|
7
|
+
HardwareErrorCode as HardwareErrorCode2,
|
|
8
8
|
TypedEventEmitter,
|
|
9
9
|
UI_REQUEST,
|
|
10
10
|
UI_REQUEST_PREEMPTED_TAG,
|
|
11
11
|
UiRequestRegistry,
|
|
12
|
-
createHwkError,
|
|
13
12
|
deriveDeviceFingerprint,
|
|
14
|
-
failure
|
|
13
|
+
failure,
|
|
15
14
|
rehydrateConnectorError,
|
|
16
|
-
success
|
|
15
|
+
success
|
|
17
16
|
} from "@onekeyfe/hwk-adapter-core";
|
|
18
17
|
|
|
19
18
|
// src/errors.ts
|
|
@@ -36,37 +35,30 @@ var USER_REJECTED_CODES = /* @__PURE__ */ new Set(["6985", "27013"]);
|
|
|
36
35
|
var WRONG_APP_CODES = /* @__PURE__ */ new Set(["6e00", "28160", "6d00", "27904", "6a83", "27267"]);
|
|
37
36
|
var APP_NOT_INSTALLED_CODES = /* @__PURE__ */ new Set(["6807", "26631"]);
|
|
38
37
|
var STEP_BLIND_SIGN_TRANSACTION_FALLBACK = "signer.eth.steps.blindSignTransactionFallback";
|
|
39
|
-
var STEP_DETECT_BLIND_SIGNING = "signer.eth.steps.detectBlindSigning";
|
|
40
|
-
var BLIND_SIGNING_STEPS = /* @__PURE__ */ new Set([
|
|
41
|
-
STEP_BLIND_SIGN_TRANSACTION_FALLBACK,
|
|
42
|
-
STEP_DETECT_BLIND_SIGNING
|
|
43
|
-
]);
|
|
44
|
-
function normalizeApduHex(value) {
|
|
45
|
-
if (typeof value === "number" && Number.isInteger(value) && value >= 0 && value <= 65535) {
|
|
46
|
-
return value.toString(16).padStart(4, "0");
|
|
47
|
-
}
|
|
48
|
-
if (typeof value !== "string") return null;
|
|
49
|
-
const raw = value.toLowerCase().replace(/^0x/, "");
|
|
50
|
-
return /^[0-9a-f]{1,4}$/i.test(raw) ? raw.padStart(4, "0") : null;
|
|
51
|
-
}
|
|
52
38
|
function getEthAppErrorCode(err) {
|
|
53
39
|
if (!err || typeof err !== "object") return null;
|
|
54
40
|
const e = err;
|
|
55
|
-
if (e._tag === ERROR_TAG.EthAppCommand) {
|
|
56
|
-
|
|
57
|
-
if (code) return code;
|
|
41
|
+
if (e._tag === ERROR_TAG.EthAppCommand && typeof e.errorCode === "string") {
|
|
42
|
+
return e.errorCode.toLowerCase();
|
|
58
43
|
}
|
|
59
44
|
const orig = e.originalError;
|
|
60
|
-
if (orig?._tag === ERROR_TAG.EthAppCommand) {
|
|
61
|
-
return
|
|
45
|
+
if (orig?._tag === ERROR_TAG.EthAppCommand && typeof orig.errorCode === "string") {
|
|
46
|
+
return orig.errorCode.toLowerCase();
|
|
62
47
|
}
|
|
63
48
|
return null;
|
|
64
49
|
}
|
|
65
50
|
function extractApduHex(err) {
|
|
66
51
|
if (!err || typeof err !== "object") return null;
|
|
67
52
|
const e = err;
|
|
68
|
-
|
|
69
|
-
|
|
53
|
+
if (typeof e.errorCode === "string" && /^[0-9a-f]+$/i.test(e.errorCode)) {
|
|
54
|
+
return e.errorCode.toLowerCase();
|
|
55
|
+
}
|
|
56
|
+
if (typeof e.statusCode === "number" && Number.isFinite(e.statusCode)) {
|
|
57
|
+
return e.statusCode.toString(16).padStart(4, "0");
|
|
58
|
+
}
|
|
59
|
+
if (typeof e.statusCode === "string" && /^[0-9a-f]+$/i.test(e.statusCode)) {
|
|
60
|
+
return e.statusCode.toLowerCase();
|
|
61
|
+
}
|
|
70
62
|
if (e.originalError != null) {
|
|
71
63
|
const nested = extractApduHex(e.originalError);
|
|
72
64
|
if (nested) return nested;
|
|
@@ -125,15 +117,10 @@ function classifyEthAppError(err) {
|
|
|
125
117
|
const ethCode = getEthAppErrorCode(err);
|
|
126
118
|
if (!ethCode) return null;
|
|
127
119
|
if (ethCode === "6a80") {
|
|
128
|
-
return
|
|
120
|
+
return hasBlindSignFallbackStep(err) ? HardwareErrorCode.EvmBlindSigningRequired : null;
|
|
129
121
|
}
|
|
130
122
|
return mapEthAppErrorCode(ethCode);
|
|
131
123
|
}
|
|
132
|
-
function classifyBlindSigningDetectionError(err) {
|
|
133
|
-
if (!hasBlindSigningStep(err)) return null;
|
|
134
|
-
if (hasInvalidArgumentCode(err)) return HardwareErrorCode.EvmBlindSigningRequired;
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
124
|
var ERROR_TAG = {
|
|
138
125
|
// SDK-mint
|
|
139
126
|
DeviceNotAdvertising: "DeviceNotAdvertisingError",
|
|
@@ -149,10 +136,6 @@ var ERROR_TAG = {
|
|
|
149
136
|
// chain app wedged (APDU 0x6901)
|
|
150
137
|
DeviceTransportStuck: "DeviceTransportStuck",
|
|
151
138
|
// DMK transport queue wedged
|
|
152
|
-
// installApp resolved success but the app is still missing on device —
|
|
153
|
-
// DMK quirk. Surfaced as a distinct tag so callers can tell it apart from
|
|
154
|
-
// the original DMK-thrown AppNotInstalled.
|
|
155
|
-
AppInstallVerifyFailed: "AppInstallVerifyFailedError",
|
|
156
139
|
// DMK-reuse (DMK throws same string; we synthesize too)
|
|
157
140
|
DeviceLocked: "DeviceLockedError",
|
|
158
141
|
DeviceNotRecognized: "DeviceNotRecognizedError",
|
|
@@ -178,11 +161,7 @@ var ERROR_TAG = {
|
|
|
178
161
|
// ble-plx surfaces this when GATT notification setup fails — typical
|
|
179
162
|
// outcome when the user doesn't confirm pairing on the device, or the
|
|
180
163
|
// existing bond is invalid. Observed in production after ~30s.
|
|
181
|
-
PairingRefused: "PairingRefusedError"
|
|
182
|
-
// DMK remote-network failures (manager-api HTTP / secure-channel WS).
|
|
183
|
-
WebSocketConnection: "WebSocketConnectionError",
|
|
184
|
-
HttpFetch: "FetchError",
|
|
185
|
-
InvalidFirmwareMetadataResponse: "InvalidGetFirmwareMetadataResponseError"
|
|
164
|
+
PairingRefused: "PairingRefusedError"
|
|
186
165
|
};
|
|
187
166
|
function isDeviceLockedError(err) {
|
|
188
167
|
if (!err || typeof err !== "object") return false;
|
|
@@ -270,30 +249,15 @@ function hasStatusCode(err, codeSet) {
|
|
|
270
249
|
if (e.error != null && e._tag && hasStatusCode(e.error, codeSet)) return true;
|
|
271
250
|
return false;
|
|
272
251
|
}
|
|
273
|
-
function
|
|
252
|
+
function hasBlindSignFallbackStep(err) {
|
|
274
253
|
if (!err || typeof err !== "object") return false;
|
|
275
254
|
const e = err;
|
|
276
|
-
if (e._lastStep ===
|
|
277
|
-
if (Array.isArray(e._deviceActionSteps) && e._deviceActionSteps.includes(
|
|
255
|
+
if (e._lastStep === STEP_BLIND_SIGN_TRANSACTION_FALLBACK) return true;
|
|
256
|
+
if (Array.isArray(e._deviceActionSteps) && e._deviceActionSteps.includes(STEP_BLIND_SIGN_TRANSACTION_FALLBACK)) {
|
|
278
257
|
return true;
|
|
279
258
|
}
|
|
280
|
-
if (e.originalError != null &&
|
|
281
|
-
if (e.error != null && e._tag &&
|
|
282
|
-
return false;
|
|
283
|
-
}
|
|
284
|
-
function hasBlindSigningStep(err) {
|
|
285
|
-
for (const step of BLIND_SIGNING_STEPS) {
|
|
286
|
-
if (hasDeviceActionStep(err, step)) return true;
|
|
287
|
-
}
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
function hasInvalidArgumentCode(err) {
|
|
291
|
-
if (!err || typeof err !== "object") return false;
|
|
292
|
-
const e = err;
|
|
293
|
-
if (e.code === "INVALID_ARGUMENT") return true;
|
|
294
|
-
if (typeof e.message === "string" && e.message.includes("code=INVALID_ARGUMENT")) return true;
|
|
295
|
-
if (e.originalError != null && hasInvalidArgumentCode(e.originalError)) return true;
|
|
296
|
-
if (e.error != null && e._tag && hasInvalidArgumentCode(e.error)) return true;
|
|
259
|
+
if (e.originalError != null && hasBlindSignFallbackStep(e.originalError)) return true;
|
|
260
|
+
if (e.error != null && e._tag && hasBlindSignFallbackStep(e.error)) return true;
|
|
297
261
|
return false;
|
|
298
262
|
}
|
|
299
263
|
function isDeviceNotFoundError(err) {
|
|
@@ -322,11 +286,6 @@ function isUserRejectedError(err) {
|
|
|
322
286
|
if (hasStatusCode(err, USER_REJECTED_CODES)) return true;
|
|
323
287
|
return false;
|
|
324
288
|
}
|
|
325
|
-
function isUserAbortedError(err) {
|
|
326
|
-
if (!err || typeof err !== "object") return false;
|
|
327
|
-
const e = err;
|
|
328
|
-
return e._tag === ERROR_TAG.UserAborted;
|
|
329
|
-
}
|
|
330
289
|
function isWrongAppError(err) {
|
|
331
290
|
if (!err || typeof err !== "object") return false;
|
|
332
291
|
const e = err;
|
|
@@ -353,20 +312,6 @@ function isOutOfMemoryError(err) {
|
|
|
353
312
|
const e = err;
|
|
354
313
|
return e._tag === "OutOfMemoryDAError";
|
|
355
314
|
}
|
|
356
|
-
var NETWORK_ERROR_TAGS = /* @__PURE__ */ new Set([
|
|
357
|
-
ERROR_TAG.WebSocketConnection,
|
|
358
|
-
ERROR_TAG.HttpFetch,
|
|
359
|
-
ERROR_TAG.InvalidFirmwareMetadataResponse
|
|
360
|
-
]);
|
|
361
|
-
function isNetworkError(err) {
|
|
362
|
-
if (!err || typeof err !== "object") return false;
|
|
363
|
-
const e = err;
|
|
364
|
-
const tag = e._tag;
|
|
365
|
-
if (typeof tag === "string" && NETWORK_ERROR_TAGS.has(tag)) return true;
|
|
366
|
-
if (e.originalError != null && isNetworkError(e.originalError)) return true;
|
|
367
|
-
if (e.error != null && isNetworkError(e.error)) return true;
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
315
|
function isDeviceDisconnectedError(err) {
|
|
371
316
|
if (!err || typeof err !== "object") return false;
|
|
372
317
|
const e = err;
|
|
@@ -423,8 +368,6 @@ function mapLedgerError(err, opts) {
|
|
|
423
368
|
code = HardwareErrorCode.DeviceBusy;
|
|
424
369
|
} else if (isBlePairingFailureError(err)) {
|
|
425
370
|
code = HardwareErrorCode.BlePairingTimeout;
|
|
426
|
-
} else if (isUserAbortedError(err)) {
|
|
427
|
-
code = HardwareErrorCode.UserAborted;
|
|
428
371
|
} else if (isUserRejectedError(err)) {
|
|
429
372
|
code = HardwareErrorCode.UserRejected;
|
|
430
373
|
} else if (isWrongAppError(err)) {
|
|
@@ -433,14 +376,12 @@ function mapLedgerError(err, opts) {
|
|
|
433
376
|
code = HardwareErrorCode.AppNotInstalled;
|
|
434
377
|
} else if (isOutOfMemoryError(err)) {
|
|
435
378
|
code = HardwareErrorCode.DeviceOutOfMemory;
|
|
436
|
-
} else if (isNetworkError(err)) {
|
|
437
|
-
code = HardwareErrorCode.NetworkError;
|
|
438
379
|
} else if (isDeviceDisconnectedError(err)) {
|
|
439
380
|
code = HardwareErrorCode.DeviceDisconnected;
|
|
440
381
|
} else if (isTimeoutError(err)) {
|
|
441
382
|
code = HardwareErrorCode.OperationTimeout;
|
|
442
383
|
} else {
|
|
443
|
-
const ethMapped = classifyEthAppError(err)
|
|
384
|
+
const ethMapped = classifyEthAppError(err);
|
|
444
385
|
const apduHex = ethMapped ? null : extractApduHex(err);
|
|
445
386
|
const chainMapped = apduHex ? mapSolanaAppError(apduHex) ?? mapTronAppError(apduHex) ?? mapBtcAppError(apduHex) : null;
|
|
446
387
|
code = ethMapped ?? chainMapped ?? HardwareErrorCode.UnknownError;
|
|
@@ -450,8 +391,17 @@ function mapLedgerError(err, opts) {
|
|
|
450
391
|
return { code, message: enrichErrorMessage(code, originalMessage), appName };
|
|
451
392
|
}
|
|
452
393
|
|
|
453
|
-
// src/
|
|
454
|
-
|
|
394
|
+
// src/utils/ledgerDmkTransport.ts
|
|
395
|
+
function isLedgerDmkBleTransport(transport) {
|
|
396
|
+
const normalized = transport?.toUpperCase();
|
|
397
|
+
return normalized === "BLE" || normalized?.endsWith("_BLE") === true;
|
|
398
|
+
}
|
|
399
|
+
function isLedgerBleConnectionType(connectionType) {
|
|
400
|
+
return connectionType === "ble";
|
|
401
|
+
}
|
|
402
|
+
function isLedgerBleDescriptor(connectionType, descriptor) {
|
|
403
|
+
return isLedgerBleConnectionType(connectionType) || isLedgerDmkBleTransport(descriptor.transport);
|
|
404
|
+
}
|
|
455
405
|
|
|
456
406
|
// src/utils/sdkEventBus.ts
|
|
457
407
|
var listeners = /* @__PURE__ */ new Set();
|
|
@@ -498,252 +448,6 @@ function debugError(...args) {
|
|
|
498
448
|
emitLog("error", ...args);
|
|
499
449
|
}
|
|
500
450
|
|
|
501
|
-
// src/adapter/methods/allNetworkGetAddress.ts
|
|
502
|
-
var LEDGER_BTC_NETWORK_COIN_MAP = {
|
|
503
|
-
tbtc: "Testnet",
|
|
504
|
-
bch: "Bcash",
|
|
505
|
-
doge: "Dogecoin",
|
|
506
|
-
ltc: "Litecoin",
|
|
507
|
-
neurai: "Neurai"
|
|
508
|
-
};
|
|
509
|
-
function createAllNetworkGetAddress({
|
|
510
|
-
callChain,
|
|
511
|
-
getChainFingerprint
|
|
512
|
-
}) {
|
|
513
|
-
return async function allNetworkGetAddress(connectId, _deviceId, params) {
|
|
514
|
-
debugLog("[LedgerAdapter][REQ]", { method: "allNetworkGetAddress", connectId, params });
|
|
515
|
-
const installContext = {};
|
|
516
|
-
const commonParams = {
|
|
517
|
-
autoInstallApp: params.autoInstallApp
|
|
518
|
-
};
|
|
519
|
-
const responses = [];
|
|
520
|
-
const chainFingerprints = /* @__PURE__ */ new Map();
|
|
521
|
-
for (const item of params.bundle) {
|
|
522
|
-
const method = getAllNetworkMethod(item);
|
|
523
|
-
if (!method) {
|
|
524
|
-
responses.push(buildUnsupportedMethodResponse(item));
|
|
525
|
-
} else {
|
|
526
|
-
const chain = getFingerprintChain(method);
|
|
527
|
-
const itemDeviceId = getItemDeviceId(item) ?? chainFingerprints.get(chain) ?? "";
|
|
528
|
-
const normalizedItem = normalizeLedgerAllNetworkItem(method, item);
|
|
529
|
-
const response = await callAllNetworkItem(
|
|
530
|
-
callChain,
|
|
531
|
-
getChainFingerprint,
|
|
532
|
-
connectId,
|
|
533
|
-
itemDeviceId,
|
|
534
|
-
chain,
|
|
535
|
-
method,
|
|
536
|
-
normalizedItem,
|
|
537
|
-
commonParams,
|
|
538
|
-
installContext,
|
|
539
|
-
chainFingerprints
|
|
540
|
-
);
|
|
541
|
-
if (isTopLevelAllNetworkFailure(response)) {
|
|
542
|
-
const code = response.payload?.code ?? HardwareErrorCode2.DeviceMismatch;
|
|
543
|
-
const result2 = failure(
|
|
544
|
-
code,
|
|
545
|
-
response.payload?.error ?? "All-network get-address aborted",
|
|
546
|
-
response.payload?.params
|
|
547
|
-
);
|
|
548
|
-
debugLog("[LedgerAdapter][RES]", {
|
|
549
|
-
method: "allNetworkGetAddress",
|
|
550
|
-
success: false,
|
|
551
|
-
payload: result2
|
|
552
|
-
});
|
|
553
|
-
return result2;
|
|
554
|
-
}
|
|
555
|
-
responses.push(response);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
const result = success(responses);
|
|
559
|
-
debugLog("[LedgerAdapter][RES]", {
|
|
560
|
-
method: "allNetworkGetAddress",
|
|
561
|
-
success: true,
|
|
562
|
-
payload: result
|
|
563
|
-
});
|
|
564
|
-
return result;
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
function isTopLevelAllNetworkFailure(response) {
|
|
568
|
-
if (response.success) {
|
|
569
|
-
return false;
|
|
570
|
-
}
|
|
571
|
-
const code = response.payload?.code;
|
|
572
|
-
return code === HardwareErrorCode2.DeviceMismatch || code === HardwareErrorCode2.UserAborted || code === HardwareErrorCode2.UserRejected;
|
|
573
|
-
}
|
|
574
|
-
function getItemDeviceId(item) {
|
|
575
|
-
const { deviceId } = item;
|
|
576
|
-
return typeof deviceId === "string" && deviceId.length > 0 ? deviceId : void 0;
|
|
577
|
-
}
|
|
578
|
-
function getAllNetworkMethod(item) {
|
|
579
|
-
switch (item.methodName) {
|
|
580
|
-
case "evmGetAddress":
|
|
581
|
-
case "btcGetAddress":
|
|
582
|
-
case "btcGetPublicKey":
|
|
583
|
-
case "solGetAddress":
|
|
584
|
-
case "tronGetAddress":
|
|
585
|
-
return item.methodName;
|
|
586
|
-
default:
|
|
587
|
-
return void 0;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
function buildUnsupportedMethodResponse(item) {
|
|
591
|
-
return {
|
|
592
|
-
...item,
|
|
593
|
-
success: false,
|
|
594
|
-
payload: {
|
|
595
|
-
code: HardwareErrorCode2.InvalidParams,
|
|
596
|
-
error: `Unsupported allNetwork method: ${String(item.methodName)}`
|
|
597
|
-
}
|
|
598
|
-
};
|
|
599
|
-
}
|
|
600
|
-
function normalizeLedgerAllNetworkItem(method, item) {
|
|
601
|
-
if (method !== "btcGetAddress" && method !== "btcGetPublicKey") {
|
|
602
|
-
return item;
|
|
603
|
-
}
|
|
604
|
-
const itemWithCoin = item;
|
|
605
|
-
if (itemWithCoin.coin) {
|
|
606
|
-
return item;
|
|
607
|
-
}
|
|
608
|
-
const coin = LEDGER_BTC_NETWORK_COIN_MAP[item.network];
|
|
609
|
-
return coin ? { ...item, coin } : item;
|
|
610
|
-
}
|
|
611
|
-
async function callAllNetworkItem(callChain, getChainFingerprint, connectId, deviceId, chain, method, item, commonParams, installContext, chainFingerprints) {
|
|
612
|
-
const response = await callAllNetworkMethod(
|
|
613
|
-
callChain,
|
|
614
|
-
connectId,
|
|
615
|
-
deviceId,
|
|
616
|
-
method,
|
|
617
|
-
item,
|
|
618
|
-
commonParams,
|
|
619
|
-
installContext
|
|
620
|
-
);
|
|
621
|
-
if (!response.success) {
|
|
622
|
-
return { ...item, success: false, payload: response.payload };
|
|
623
|
-
}
|
|
624
|
-
const payload = response.payload;
|
|
625
|
-
const fingerprint = deviceId || chainFingerprints.get(chain) || await bootstrapChainFingerprint(getChainFingerprint, connectId, chain);
|
|
626
|
-
if (!fingerprint) {
|
|
627
|
-
return buildFingerprintBootstrapFailure(item, chain);
|
|
628
|
-
}
|
|
629
|
-
chainFingerprints.set(chain, fingerprint);
|
|
630
|
-
return {
|
|
631
|
-
...item,
|
|
632
|
-
success: true,
|
|
633
|
-
payload: {
|
|
634
|
-
...payload,
|
|
635
|
-
chainFingerprint: fingerprint,
|
|
636
|
-
chainFingerprintChain: chain
|
|
637
|
-
}
|
|
638
|
-
};
|
|
639
|
-
}
|
|
640
|
-
async function bootstrapChainFingerprint(getChainFingerprint, connectId, chain) {
|
|
641
|
-
const response = await getChainFingerprint(connectId, chain);
|
|
642
|
-
return response.success ? response.payload : "";
|
|
643
|
-
}
|
|
644
|
-
function buildFingerprintBootstrapFailure(item, chain) {
|
|
645
|
-
return {
|
|
646
|
-
...item,
|
|
647
|
-
success: false,
|
|
648
|
-
payload: {
|
|
649
|
-
code: HardwareErrorCode2.DeviceMismatch,
|
|
650
|
-
error: `Could not establish chain fingerprint for ${chain} after device call; refusing to return unverifiable result. Please retry.`
|
|
651
|
-
}
|
|
652
|
-
};
|
|
653
|
-
}
|
|
654
|
-
function getFingerprintChain(method) {
|
|
655
|
-
switch (method) {
|
|
656
|
-
case "evmGetAddress":
|
|
657
|
-
return "evm";
|
|
658
|
-
case "btcGetAddress":
|
|
659
|
-
case "btcGetPublicKey":
|
|
660
|
-
return "btc";
|
|
661
|
-
case "solGetAddress":
|
|
662
|
-
return "sol";
|
|
663
|
-
case "tronGetAddress":
|
|
664
|
-
return "tron";
|
|
665
|
-
default:
|
|
666
|
-
throw Object.assign(new Error(`Unsupported allNetwork method: ${method}`), {
|
|
667
|
-
code: HardwareErrorCode2.InvalidParams
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
async function callAllNetworkMethod(callChain, connectId, deviceId, method, item, commonParams, installContext) {
|
|
672
|
-
switch (method) {
|
|
673
|
-
case "evmGetAddress":
|
|
674
|
-
return callChain(
|
|
675
|
-
connectId,
|
|
676
|
-
deviceId,
|
|
677
|
-
"evm",
|
|
678
|
-
"evmGetAddress",
|
|
679
|
-
item,
|
|
680
|
-
commonParams,
|
|
681
|
-
false,
|
|
682
|
-
installContext
|
|
683
|
-
);
|
|
684
|
-
case "btcGetAddress":
|
|
685
|
-
return callChain(
|
|
686
|
-
connectId,
|
|
687
|
-
deviceId,
|
|
688
|
-
"btc",
|
|
689
|
-
"btcGetAddress",
|
|
690
|
-
item,
|
|
691
|
-
commonParams,
|
|
692
|
-
false,
|
|
693
|
-
installContext
|
|
694
|
-
);
|
|
695
|
-
case "btcGetPublicKey":
|
|
696
|
-
return callChain(
|
|
697
|
-
connectId,
|
|
698
|
-
deviceId,
|
|
699
|
-
"btc",
|
|
700
|
-
"btcGetPublicKey",
|
|
701
|
-
item,
|
|
702
|
-
commonParams,
|
|
703
|
-
false,
|
|
704
|
-
installContext
|
|
705
|
-
);
|
|
706
|
-
case "solGetAddress":
|
|
707
|
-
return callChain(
|
|
708
|
-
connectId,
|
|
709
|
-
deviceId,
|
|
710
|
-
"sol",
|
|
711
|
-
"solGetAddress",
|
|
712
|
-
item,
|
|
713
|
-
commonParams,
|
|
714
|
-
false,
|
|
715
|
-
installContext
|
|
716
|
-
);
|
|
717
|
-
case "tronGetAddress":
|
|
718
|
-
return callChain(
|
|
719
|
-
connectId,
|
|
720
|
-
deviceId,
|
|
721
|
-
"tron",
|
|
722
|
-
"tronGetAddress",
|
|
723
|
-
item,
|
|
724
|
-
commonParams,
|
|
725
|
-
false,
|
|
726
|
-
installContext
|
|
727
|
-
);
|
|
728
|
-
default:
|
|
729
|
-
throw Object.assign(new Error(`Unsupported allNetwork method: ${method}`), {
|
|
730
|
-
code: HardwareErrorCode2.InvalidParams
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
// src/utils/ledgerDmkTransport.ts
|
|
736
|
-
function isLedgerDmkBleTransport(transport) {
|
|
737
|
-
const normalized = transport?.toUpperCase();
|
|
738
|
-
return normalized === "BLE" || normalized?.endsWith("_BLE") === true;
|
|
739
|
-
}
|
|
740
|
-
function isLedgerBleConnectionType(connectionType) {
|
|
741
|
-
return connectionType === "ble";
|
|
742
|
-
}
|
|
743
|
-
function isLedgerBleDescriptor(connectionType, descriptor) {
|
|
744
|
-
return isLedgerBleConnectionType(connectionType) || isLedgerDmkBleTransport(descriptor.transport);
|
|
745
|
-
}
|
|
746
|
-
|
|
747
451
|
// src/adapter/LedgerAdapter.ts
|
|
748
452
|
function formatDeviceMismatchError(expected, actual) {
|
|
749
453
|
return `Wrong device: expected ${expected}, got ${actual}`;
|
|
@@ -771,11 +475,6 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
771
475
|
this._btcHighIndexConfirmedThisSession = false;
|
|
772
476
|
// Shared across concurrent callers — only `cancel()` aborts.
|
|
773
477
|
this._doConnectAbortController = null;
|
|
774
|
-
this._installProgressLastEmittedValue = -Infinity;
|
|
775
|
-
this.allNetworkGetAddress = createAllNetworkGetAddress({
|
|
776
|
-
callChain: this.callChain.bind(this),
|
|
777
|
-
getChainFingerprint: (connectId, chain) => this.getChainFingerprint(connectId, "", chain)
|
|
778
|
-
});
|
|
779
478
|
// ---------------------------------------------------------------------------
|
|
780
479
|
// Private helpers
|
|
781
480
|
// ---------------------------------------------------------------------------
|
|
@@ -829,23 +528,12 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
829
528
|
);
|
|
830
529
|
return;
|
|
831
530
|
}
|
|
832
|
-
const { appName, progress } = event.payload;
|
|
833
|
-
const key = `${connectId}:${appName}`;
|
|
834
|
-
if (this._installProgressLastKey !== key || this._installProgressLastEmittedValue >= 1) {
|
|
835
|
-
this._installProgressLastEmittedValue = -Infinity;
|
|
836
|
-
this._installProgressLastKey = key;
|
|
837
|
-
}
|
|
838
|
-
const delta = progress - this._installProgressLastEmittedValue;
|
|
839
|
-
if (delta < _LedgerAdapter.APP_INSTALL_PROGRESS_MIN_DELTA && progress < 1) {
|
|
840
|
-
return;
|
|
841
|
-
}
|
|
842
|
-
this._installProgressLastEmittedValue = progress;
|
|
843
531
|
this.emitter.emit("ui-event", {
|
|
844
532
|
type: EConnectorInteraction.AppInstallProgress,
|
|
845
533
|
payload: {
|
|
846
534
|
connectId,
|
|
847
|
-
appName,
|
|
848
|
-
progress
|
|
535
|
+
appName: event.payload.appName,
|
|
536
|
+
progress: event.payload.progress
|
|
849
537
|
}
|
|
850
538
|
});
|
|
851
539
|
return;
|
|
@@ -902,42 +590,30 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
902
590
|
// Device management
|
|
903
591
|
// ---------------------------------------------------------------------------
|
|
904
592
|
async searchDevices(options) {
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
593
|
+
if (options?.resetSession) {
|
|
594
|
+
this._doConnectAbortController?.abort();
|
|
595
|
+
this._sessions.clear();
|
|
596
|
+
this._connectingPromise = null;
|
|
597
|
+
this._doConnectAbortController = null;
|
|
598
|
+
this._btcHighIndexConfirmedThisSession = false;
|
|
599
|
+
}
|
|
600
|
+
await this._ensureDevicePermission();
|
|
601
|
+
const devices = await this.connector.searchDevices();
|
|
602
|
+
this._discoveredDevices.clear();
|
|
603
|
+
for (const d of devices) {
|
|
604
|
+
if (d.connectId) {
|
|
605
|
+
this._discoveredDevices.set(d.connectId, this.connectorDeviceToDeviceInfo(d));
|
|
913
606
|
}
|
|
607
|
+
}
|
|
608
|
+
if (this._discoveredDevices.size === 0) {
|
|
914
609
|
await this._ensureDevicePermission();
|
|
915
|
-
const devices = await this.connector.searchDevices();
|
|
916
|
-
this._discoveredDevices.clear();
|
|
917
|
-
for (const d of devices) {
|
|
918
|
-
if (d.connectId) {
|
|
919
|
-
this._discoveredDevices.set(d.connectId, this.connectorDeviceToDeviceInfo(d));
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
if (this._discoveredDevices.size === 0) {
|
|
923
|
-
await this._ensureDevicePermission();
|
|
924
|
-
}
|
|
925
|
-
const result = Array.from(this._discoveredDevices.values());
|
|
926
|
-
debugLog("[LedgerAdapter][RES]", {
|
|
927
|
-
method: "searchDevices",
|
|
928
|
-
success: true,
|
|
929
|
-
payload: result
|
|
930
|
-
});
|
|
931
|
-
return result;
|
|
932
|
-
} catch (err) {
|
|
933
|
-
const e = err;
|
|
934
|
-
debugLog("[LedgerAdapter][RES]", {
|
|
935
|
-
method: "searchDevices",
|
|
936
|
-
success: false,
|
|
937
|
-
error: { message: e?.message, _tag: e?._tag, code: e?.code ?? e?.errorCode }
|
|
938
|
-
});
|
|
939
|
-
throw err;
|
|
940
610
|
}
|
|
611
|
+
debugLog(
|
|
612
|
+
`[LedgerAdapter] searchDevices() return count=${this._discoveredDevices.size} ids=[${[
|
|
613
|
+
...this._discoveredDevices.keys()
|
|
614
|
+
].join(",")}]`
|
|
615
|
+
);
|
|
616
|
+
return Array.from(this._discoveredDevices.values());
|
|
941
617
|
}
|
|
942
618
|
// USB single-session invariant: evict all sessions, best-effort (see connectDevice).
|
|
943
619
|
async _evictAllSessions() {
|
|
@@ -953,15 +629,14 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
953
629
|
}
|
|
954
630
|
static _createDeviceBusyError(method) {
|
|
955
631
|
return Object.assign(new Error(`Ledger device is busy while calling ${method}`), {
|
|
956
|
-
code:
|
|
632
|
+
code: HardwareErrorCode2.DeviceBusy
|
|
957
633
|
});
|
|
958
634
|
}
|
|
959
635
|
async connectDevice(connectId) {
|
|
960
|
-
debugLog("[LedgerAdapter][REQ]", { method: "connectDevice", connectId, params: { connectId } });
|
|
961
636
|
try {
|
|
962
637
|
if (isLedgerBleConnectionType(this.connector.connectionType) && !connectId) {
|
|
963
638
|
throw Object.assign(new Error("Ledger BLE connectId is required."), {
|
|
964
|
-
code:
|
|
639
|
+
code: HardwareErrorCode2.DeviceNotFound
|
|
965
640
|
});
|
|
966
641
|
}
|
|
967
642
|
if (!isLedgerBleConnectionType(this.connector.connectionType)) {
|
|
@@ -973,79 +648,28 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
973
648
|
if (session.deviceInfo) {
|
|
974
649
|
this._discoveredDevices.set(connectId, session.deviceInfo);
|
|
975
650
|
}
|
|
976
|
-
|
|
977
|
-
debugLog("[LedgerAdapter][RES]", { method: "connectDevice", success: true, payload: result });
|
|
978
|
-
return result;
|
|
651
|
+
return success(connectId);
|
|
979
652
|
} catch (err) {
|
|
980
|
-
|
|
981
|
-
debugLog("[LedgerAdapter][RES]", {
|
|
982
|
-
method: "connectDevice",
|
|
983
|
-
success: false,
|
|
984
|
-
payload: failureResult
|
|
985
|
-
});
|
|
986
|
-
return failureResult;
|
|
653
|
+
return this.errorToFailure(err);
|
|
987
654
|
}
|
|
988
655
|
}
|
|
989
656
|
async disconnectDevice(connectId) {
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
});
|
|
995
|
-
try {
|
|
996
|
-
const sessionId = this._sessions.get(connectId);
|
|
997
|
-
if (sessionId) {
|
|
998
|
-
await this.connector.disconnect(sessionId);
|
|
999
|
-
this._sessions.delete(connectId);
|
|
1000
|
-
}
|
|
1001
|
-
debugLog("[LedgerAdapter][RES]", { method: "disconnectDevice", success: true });
|
|
1002
|
-
} catch (err) {
|
|
1003
|
-
const e = err;
|
|
1004
|
-
debugLog("[LedgerAdapter][RES]", {
|
|
1005
|
-
method: "disconnectDevice",
|
|
1006
|
-
success: false,
|
|
1007
|
-
error: { message: e?.message, _tag: e?._tag, code: e?.code ?? e?.errorCode }
|
|
1008
|
-
});
|
|
1009
|
-
throw err;
|
|
657
|
+
const sessionId = this._sessions.get(connectId);
|
|
658
|
+
if (sessionId) {
|
|
659
|
+
await this.connector.disconnect(sessionId);
|
|
660
|
+
this._sessions.delete(connectId);
|
|
1010
661
|
}
|
|
1011
662
|
}
|
|
1012
663
|
async getDeviceInfo(connectId, deviceId) {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
});
|
|
1018
|
-
try {
|
|
1019
|
-
await this._ensureDevicePermission(connectId, deviceId);
|
|
1020
|
-
const cached = this._discoveredDevices.get(connectId) ?? Array.from(this._discoveredDevices.values()).find((d) => d.deviceId === deviceId);
|
|
1021
|
-
if (cached) {
|
|
1022
|
-
const result = success2(cached);
|
|
1023
|
-
debugLog("[LedgerAdapter][RES]", {
|
|
1024
|
-
method: "getDeviceInfo",
|
|
1025
|
-
success: true,
|
|
1026
|
-
payload: result
|
|
1027
|
-
});
|
|
1028
|
-
return result;
|
|
1029
|
-
}
|
|
1030
|
-
const notFound = failure2(
|
|
1031
|
-
HardwareErrorCode3.DeviceNotFound,
|
|
1032
|
-
"Device not found in cache. Call searchDevices() or wait for a device-connected event first."
|
|
1033
|
-
);
|
|
1034
|
-
debugLog("[LedgerAdapter][RES]", {
|
|
1035
|
-
method: "getDeviceInfo",
|
|
1036
|
-
success: false,
|
|
1037
|
-
payload: notFound
|
|
1038
|
-
});
|
|
1039
|
-
return notFound;
|
|
1040
|
-
} catch (err) {
|
|
1041
|
-
const e = err;
|
|
1042
|
-
debugLog("[LedgerAdapter][RES]", {
|
|
1043
|
-
method: "getDeviceInfo",
|
|
1044
|
-
success: false,
|
|
1045
|
-
error: { message: e?.message, _tag: e?._tag, code: e?.code ?? e?.errorCode }
|
|
1046
|
-
});
|
|
1047
|
-
throw err;
|
|
664
|
+
await this._ensureDevicePermission(connectId, deviceId);
|
|
665
|
+
const cached = this._discoveredDevices.get(connectId) ?? Array.from(this._discoveredDevices.values()).find((d) => d.deviceId === deviceId);
|
|
666
|
+
if (cached) {
|
|
667
|
+
return success(cached);
|
|
1048
668
|
}
|
|
669
|
+
return failure(
|
|
670
|
+
HardwareErrorCode2.DeviceNotFound,
|
|
671
|
+
"Device not found in cache. Call searchDevices() or wait for a device-connected event first."
|
|
672
|
+
);
|
|
1049
673
|
}
|
|
1050
674
|
getSupportedChains() {
|
|
1051
675
|
return ["evm", "btc", "sol", "tron"];
|
|
@@ -1053,7 +677,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1053
677
|
// ---------------------------------------------------------------------------
|
|
1054
678
|
// Chain call helper
|
|
1055
679
|
// ---------------------------------------------------------------------------
|
|
1056
|
-
async callChain(connectId, deviceId, chain, method, params, commonParams, skipFingerprint = false
|
|
680
|
+
async callChain(connectId, deviceId, chain, method, params, commonParams, skipFingerprint = false) {
|
|
1057
681
|
try {
|
|
1058
682
|
const result = await this.connectorCall(
|
|
1059
683
|
connectId,
|
|
@@ -1065,10 +689,9 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1065
689
|
skipFingerprint
|
|
1066
690
|
},
|
|
1067
691
|
void 0,
|
|
1068
|
-
commonParams
|
|
1069
|
-
installContext
|
|
692
|
+
commonParams
|
|
1070
693
|
);
|
|
1071
|
-
return
|
|
694
|
+
return success(result);
|
|
1072
695
|
} catch (err) {
|
|
1073
696
|
return this.errorToFailure(err);
|
|
1074
697
|
}
|
|
@@ -1253,7 +876,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1253
876
|
async installApp(connectId, appName) {
|
|
1254
877
|
try {
|
|
1255
878
|
await this.connectorCall(connectId, "installApp", { appName });
|
|
1256
|
-
return
|
|
879
|
+
return success(void 0);
|
|
1257
880
|
} catch (err) {
|
|
1258
881
|
return this.errorToFailure(err);
|
|
1259
882
|
}
|
|
@@ -1261,16 +884,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1261
884
|
async listInstalledApps(connectId) {
|
|
1262
885
|
try {
|
|
1263
886
|
const result = await this.connectorCall(connectId, "listInstalledApps", {});
|
|
1264
|
-
return
|
|
1265
|
-
} catch (err) {
|
|
1266
|
-
return this.errorToFailure(err);
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
// Offline app-presence + unlock probe. No manager-api catalog (unlike listInstalledApps).
|
|
1270
|
-
async listInstalledNames(connectId) {
|
|
1271
|
-
try {
|
|
1272
|
-
const result = await this.connectorCall(connectId, "listInstalledNames", {});
|
|
1273
|
-
return success2(result);
|
|
887
|
+
return success(result);
|
|
1274
888
|
} catch (err) {
|
|
1275
889
|
return this.errorToFailure(err);
|
|
1276
890
|
}
|
|
@@ -1278,7 +892,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1278
892
|
async listAvailableApps(connectId) {
|
|
1279
893
|
try {
|
|
1280
894
|
const result = await this.connectorCall(connectId, "listAvailableApps", {});
|
|
1281
|
-
return
|
|
895
|
+
return success(result);
|
|
1282
896
|
} catch (err) {
|
|
1283
897
|
return this.errorToFailure(err);
|
|
1284
898
|
}
|
|
@@ -1286,7 +900,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1286
900
|
async getLedgerFirmwareVersion(connectId) {
|
|
1287
901
|
try {
|
|
1288
902
|
const result = await this.connectorCall(connectId, "getFirmwareVersion", {});
|
|
1289
|
-
return
|
|
903
|
+
return success(result);
|
|
1290
904
|
} catch (err) {
|
|
1291
905
|
return this.errorToFailure(err);
|
|
1292
906
|
}
|
|
@@ -1294,7 +908,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1294
908
|
async getLedgerDeviceInfo(connectId) {
|
|
1295
909
|
try {
|
|
1296
910
|
const result = await this.connectorCall(connectId, "getDeviceInfo", {});
|
|
1297
|
-
return
|
|
911
|
+
return success(result);
|
|
1298
912
|
} catch (err) {
|
|
1299
913
|
return this.errorToFailure(err);
|
|
1300
914
|
}
|
|
@@ -1307,7 +921,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1307
921
|
}
|
|
1308
922
|
cancel(connectId) {
|
|
1309
923
|
const userAbortReason = Object.assign(new Error("User aborted operation"), {
|
|
1310
|
-
code:
|
|
924
|
+
code: HardwareErrorCode2.UserAborted,
|
|
1311
925
|
_tag: ERROR_TAG.UserAborted
|
|
1312
926
|
});
|
|
1313
927
|
this._lastCancelReason = userAbortReason;
|
|
@@ -1341,7 +955,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1341
955
|
chain,
|
|
1342
956
|
(method, params) => this.connectorCall(connectId, method, params, void 0, deviceId)
|
|
1343
957
|
);
|
|
1344
|
-
return
|
|
958
|
+
return success(fingerprint);
|
|
1345
959
|
} catch (err) {
|
|
1346
960
|
debugError("[LedgerAdapter] getChainFingerprint error:", chain, err);
|
|
1347
961
|
return this.errorToFailure(err);
|
|
@@ -1364,7 +978,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1364
978
|
return { success: false, expected: deviceId, actual: fingerprint };
|
|
1365
979
|
} catch (err) {
|
|
1366
980
|
const mapped = mapLedgerError(err);
|
|
1367
|
-
if (mapped.code ===
|
|
981
|
+
if (mapped.code === HardwareErrorCode2.WrongApp || mapped.code === HardwareErrorCode2.DeviceLocked) {
|
|
1368
982
|
return { success: true };
|
|
1369
983
|
}
|
|
1370
984
|
throw err;
|
|
@@ -1444,14 +1058,14 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1444
1058
|
});
|
|
1445
1059
|
throw Object.assign(new Error("User cancelled Ledger connection"), {
|
|
1446
1060
|
_tag: ERROR_TAG.UserAborted,
|
|
1447
|
-
code:
|
|
1061
|
+
code: HardwareErrorCode2.UserAborted,
|
|
1448
1062
|
cause: err
|
|
1449
1063
|
});
|
|
1450
1064
|
}
|
|
1451
1065
|
if (!payload?.confirmed) {
|
|
1452
1066
|
throw Object.assign(new Error("User cancelled Ledger connection"), {
|
|
1453
1067
|
_tag: ERROR_TAG.UserAborted,
|
|
1454
|
-
code:
|
|
1068
|
+
code: HardwareErrorCode2.UserAborted
|
|
1455
1069
|
});
|
|
1456
1070
|
}
|
|
1457
1071
|
await new Promise((resolve) => {
|
|
@@ -1530,7 +1144,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1530
1144
|
if (signal.aborted) _LedgerAdapter._throwIfAborted(signal);
|
|
1531
1145
|
if (isLedgerBleConnectionType(this.connector.connectionType) && !connectId) {
|
|
1532
1146
|
throw Object.assign(new Error("Ledger BLE connectId is required."), {
|
|
1533
|
-
code:
|
|
1147
|
+
code: HardwareErrorCode2.DeviceNotFound
|
|
1534
1148
|
});
|
|
1535
1149
|
}
|
|
1536
1150
|
if (connectId && this._sessions.has(connectId)) return connectId;
|
|
@@ -1540,7 +1154,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1540
1154
|
new Error(
|
|
1541
1155
|
"Ledger USB session invariant violated: more than one session is active. Please reconnect the device."
|
|
1542
1156
|
),
|
|
1543
|
-
{ code:
|
|
1157
|
+
{ code: HardwareErrorCode2.DeviceOneDeviceOnly }
|
|
1544
1158
|
);
|
|
1545
1159
|
}
|
|
1546
1160
|
return this._sessions.keys().next().value;
|
|
@@ -1620,7 +1234,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1620
1234
|
new Error(
|
|
1621
1235
|
"Device not connected after multiple attempts. Please ensure your Ledger is awake, unlocked, and in range, then try again."
|
|
1622
1236
|
),
|
|
1623
|
-
{ code:
|
|
1237
|
+
{ code: HardwareErrorCode2.DeviceNotFound }
|
|
1624
1238
|
);
|
|
1625
1239
|
}
|
|
1626
1240
|
await this._waitForDeviceConnect(internalSignal);
|
|
@@ -1644,7 +1258,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1644
1258
|
return this._connectDeviceOrThrow(devices[0].connectId);
|
|
1645
1259
|
}
|
|
1646
1260
|
const err = Object.assign(new Error(`Target Ledger unavailable: ${targetConnectId}`), {
|
|
1647
|
-
code:
|
|
1261
|
+
code: HardwareErrorCode2.DeviceNotFound
|
|
1648
1262
|
});
|
|
1649
1263
|
if (isLedgerBleConnectionType(this.connector.connectionType)) {
|
|
1650
1264
|
err._tag = ERROR_TAG.DeviceNotAdvertising;
|
|
@@ -1653,7 +1267,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1653
1267
|
}
|
|
1654
1268
|
if (isLedgerBleConnectionType(this.connector.connectionType)) {
|
|
1655
1269
|
throw Object.assign(new Error("Ledger BLE connectId is required."), {
|
|
1656
|
-
code:
|
|
1270
|
+
code: HardwareErrorCode2.DeviceNotFound
|
|
1657
1271
|
});
|
|
1658
1272
|
}
|
|
1659
1273
|
if (devices.length > 1) {
|
|
@@ -1661,7 +1275,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1661
1275
|
}
|
|
1662
1276
|
if (devices.length !== 1) {
|
|
1663
1277
|
throw Object.assign(new Error("Ledger device not found."), {
|
|
1664
|
-
code:
|
|
1278
|
+
code: HardwareErrorCode2.DeviceNotFound
|
|
1665
1279
|
});
|
|
1666
1280
|
}
|
|
1667
1281
|
return this._connectDeviceOrThrow(devices[0].connectId);
|
|
@@ -1712,43 +1326,26 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1712
1326
|
const result = signal ? await this._abortable(signal, promise) : await promise;
|
|
1713
1327
|
return this._unwrapConnectorResult(result);
|
|
1714
1328
|
}
|
|
1715
|
-
async connectorCall(connectId, method, params, fingerprint, permissionDeviceId, commonParams
|
|
1716
|
-
debugLog("[LedgerAdapter]
|
|
1329
|
+
async connectorCall(connectId, method, params, fingerprint, permissionDeviceId, commonParams) {
|
|
1330
|
+
debugLog("[LedgerAdapter] connectorCall:", method, "connectId:", connectId || "(empty)");
|
|
1717
1331
|
const queueKey = connectId || "__ledger_default__";
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
connectId,
|
|
1723
|
-
method,
|
|
1724
|
-
params,
|
|
1725
|
-
signal,
|
|
1726
|
-
fingerprint,
|
|
1727
|
-
permissionDeviceId,
|
|
1728
|
-
commonParams,
|
|
1729
|
-
installContext
|
|
1730
|
-
),
|
|
1731
|
-
{
|
|
1732
|
-
label: method,
|
|
1733
|
-
rejectIfBusy: true,
|
|
1734
|
-
busyError: _LedgerAdapter._createDeviceBusyError(method)
|
|
1735
|
-
}
|
|
1736
|
-
);
|
|
1737
|
-
debugLog("[LedgerAdapter][RES]", { method, success: true, payload: result });
|
|
1738
|
-
return result;
|
|
1739
|
-
} catch (err) {
|
|
1740
|
-
const e = err;
|
|
1741
|
-
debugLog("[LedgerAdapter][RES]", {
|
|
1332
|
+
return this._jobQueue.enqueue(
|
|
1333
|
+
queueKey,
|
|
1334
|
+
async (signal) => this._runConnectorCall(
|
|
1335
|
+
connectId,
|
|
1742
1336
|
method,
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1337
|
+
params,
|
|
1338
|
+
signal,
|
|
1339
|
+
fingerprint,
|
|
1340
|
+
permissionDeviceId,
|
|
1341
|
+
commonParams
|
|
1342
|
+
),
|
|
1343
|
+
{
|
|
1344
|
+
label: method,
|
|
1345
|
+
rejectIfBusy: true,
|
|
1346
|
+
busyError: _LedgerAdapter._createDeviceBusyError(method)
|
|
1347
|
+
}
|
|
1348
|
+
);
|
|
1752
1349
|
}
|
|
1753
1350
|
/**
|
|
1754
1351
|
* Race a promise against an abort signal. On abort, rejects with
|
|
@@ -1783,7 +1380,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1783
1380
|
}
|
|
1784
1381
|
}
|
|
1785
1382
|
/** Actual work done under the job queue — connection, fingerprint, call, and recovery. */
|
|
1786
|
-
async _runConnectorCall(connectId, method, params, signal, fingerprint, permissionDeviceId, commonParams
|
|
1383
|
+
async _runConnectorCall(connectId, method, params, signal, fingerprint, permissionDeviceId, commonParams) {
|
|
1787
1384
|
_LedgerAdapter._throwIfAborted(signal);
|
|
1788
1385
|
await this._ensureDevicePermission(
|
|
1789
1386
|
connectId,
|
|
@@ -1797,7 +1394,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1797
1394
|
if (gatedParams === null) {
|
|
1798
1395
|
throw Object.assign(new Error("User cancelled BTC high-index confirmation"), {
|
|
1799
1396
|
_tag: ERROR_TAG.UserAborted,
|
|
1800
|
-
code:
|
|
1397
|
+
code: HardwareErrorCode2.UserAborted
|
|
1801
1398
|
});
|
|
1802
1399
|
}
|
|
1803
1400
|
effectiveParams = gatedParams;
|
|
@@ -1826,7 +1423,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1826
1423
|
);
|
|
1827
1424
|
if (!fp.success) {
|
|
1828
1425
|
throw Object.assign(new Error(formatDeviceMismatchError(fp.expected, fp.actual)), {
|
|
1829
|
-
code:
|
|
1426
|
+
code: HardwareErrorCode2.DeviceMismatch
|
|
1830
1427
|
});
|
|
1831
1428
|
}
|
|
1832
1429
|
}
|
|
@@ -1845,62 +1442,22 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1845
1442
|
isStuckApp: isStuckAppStateError(err)
|
|
1846
1443
|
});
|
|
1847
1444
|
const autoInstallApp = commonParams?.autoInstallApp ?? this._defaultAutoInstallApp;
|
|
1848
|
-
const isAppMissing = isAppNotInstalledError(err) || err?.code ===
|
|
1445
|
+
const isAppMissing = isAppNotInstalledError(err) || err?.code === HardwareErrorCode2.AppNotInstalled;
|
|
1849
1446
|
if (autoInstallApp && isAppMissing) {
|
|
1850
|
-
if (installContext?.deviceOutOfMemoryError) {
|
|
1851
|
-
throw installContext.deviceOutOfMemoryError;
|
|
1852
|
-
}
|
|
1853
1447
|
const appName = err?.appName ?? mapLedgerError(err).appName;
|
|
1854
1448
|
if (appName) {
|
|
1855
|
-
if (installContext?.installAttemptedAppNames?.has(appName)) {
|
|
1856
|
-
throw createHwkError({
|
|
1857
|
-
code: HardwareErrorCode3.AppNotInstalled,
|
|
1858
|
-
message: `${appName} install reported success but the app is still missing on device`,
|
|
1859
|
-
_tag: ERROR_TAG.AppInstallVerifyFailed,
|
|
1860
|
-
appName
|
|
1861
|
-
});
|
|
1862
|
-
}
|
|
1863
1449
|
const confirmed = await this._waitForInstallAppConfirm(appName);
|
|
1864
|
-
if (!confirmed)
|
|
1865
|
-
throw createHwkError({
|
|
1866
|
-
code: HardwareErrorCode3.UserAborted,
|
|
1867
|
-
message: `User declined to install ${appName}`,
|
|
1868
|
-
_tag: ERROR_TAG.UserAborted,
|
|
1869
|
-
appName
|
|
1870
|
-
});
|
|
1871
|
-
}
|
|
1450
|
+
if (!confirmed) throw err;
|
|
1872
1451
|
this.emitter.emit("ui-event", {
|
|
1873
1452
|
type: EConnectorInteraction.AppInstallProgress,
|
|
1874
1453
|
payload: { connectId: resolvedConnectId, appName, progress: 0 }
|
|
1875
1454
|
});
|
|
1876
|
-
|
|
1877
|
-
await this._callConnector(sessionId, "installApp", { appName }, signal);
|
|
1878
|
-
} catch (installErr) {
|
|
1879
|
-
if (mapLedgerError(installErr).code === HardwareErrorCode3.DeviceOutOfMemory) {
|
|
1880
|
-
if (installContext) {
|
|
1881
|
-
installContext.deviceOutOfMemoryError = installErr;
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
throw installErr;
|
|
1885
|
-
}
|
|
1886
|
-
if (installContext) {
|
|
1887
|
-
installContext.installAttemptedAppNames = installContext.installAttemptedAppNames ?? /* @__PURE__ */ new Set();
|
|
1888
|
-
installContext.installAttemptedAppNames.add(appName);
|
|
1889
|
-
}
|
|
1455
|
+
await this._callConnector(sessionId, "installApp", { appName }, signal);
|
|
1890
1456
|
this.emitter.emit(UI_REQUEST.CLOSE_UI_WINDOW, {
|
|
1891
1457
|
type: UI_REQUEST.CLOSE_UI_WINDOW,
|
|
1892
1458
|
payload: {}
|
|
1893
1459
|
});
|
|
1894
|
-
return await this.
|
|
1895
|
-
resolvedConnectId,
|
|
1896
|
-
method,
|
|
1897
|
-
effectiveParams,
|
|
1898
|
-
signal,
|
|
1899
|
-
fingerprint,
|
|
1900
|
-
permissionDeviceId,
|
|
1901
|
-
commonParams,
|
|
1902
|
-
installContext
|
|
1903
|
-
);
|
|
1460
|
+
return await this._callConnector(sessionId, method, effectiveParams, signal);
|
|
1904
1461
|
}
|
|
1905
1462
|
}
|
|
1906
1463
|
if (isStuckAppStateError(err)) {
|
|
@@ -1975,7 +1532,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1975
1532
|
);
|
|
1976
1533
|
if (!fp.success) {
|
|
1977
1534
|
throw Object.assign(new Error(formatDeviceMismatchError(fp.expected, fp.actual)), {
|
|
1978
|
-
code:
|
|
1535
|
+
code: HardwareErrorCode2.DeviceMismatch
|
|
1979
1536
|
});
|
|
1980
1537
|
}
|
|
1981
1538
|
}
|
|
@@ -2010,7 +1567,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
2010
1567
|
this.connector.reset();
|
|
2011
1568
|
const codeNum = err?.code;
|
|
2012
1569
|
throw Object.assign(err, {
|
|
2013
|
-
code: codeNum ??
|
|
1570
|
+
code: codeNum ?? HardwareErrorCode2.DeviceDisconnected
|
|
2014
1571
|
});
|
|
2015
1572
|
}
|
|
2016
1573
|
throw err;
|
|
@@ -2044,7 +1601,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
2044
1601
|
);
|
|
2045
1602
|
if (!fp.success) {
|
|
2046
1603
|
throw Object.assign(new Error(formatDeviceMismatchError(fp.expected, fp.actual)), {
|
|
2047
|
-
code:
|
|
1604
|
+
code: HardwareErrorCode2.DeviceMismatch
|
|
2048
1605
|
});
|
|
2049
1606
|
}
|
|
2050
1607
|
}
|
|
@@ -2101,7 +1658,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
2101
1658
|
);
|
|
2102
1659
|
if (!fp.success) {
|
|
2103
1660
|
throw Object.assign(new Error(formatDeviceMismatchError(fp.expected, fp.actual)), {
|
|
2104
|
-
code:
|
|
1661
|
+
code: HardwareErrorCode2.DeviceMismatch
|
|
2105
1662
|
});
|
|
2106
1663
|
}
|
|
2107
1664
|
}
|
|
@@ -2142,7 +1699,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
2142
1699
|
);
|
|
2143
1700
|
if (!fp.success) {
|
|
2144
1701
|
throw Object.assign(new Error(formatDeviceMismatchError(fp.expected, fp.actual)), {
|
|
2145
|
-
code:
|
|
1702
|
+
code: HardwareErrorCode2.DeviceMismatch
|
|
2146
1703
|
});
|
|
2147
1704
|
}
|
|
2148
1705
|
}
|
|
@@ -2192,7 +1749,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
2192
1749
|
});
|
|
2193
1750
|
throw Object.assign(new Error("Device permission request superseded"), {
|
|
2194
1751
|
_tag: ERROR_TAG.UserAborted,
|
|
2195
|
-
code:
|
|
1752
|
+
code: HardwareErrorCode2.UserAborted,
|
|
2196
1753
|
cause: err
|
|
2197
1754
|
});
|
|
2198
1755
|
}
|
|
@@ -2203,7 +1760,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
2203
1760
|
const { granted, reason, message } = response;
|
|
2204
1761
|
if (!granted) {
|
|
2205
1762
|
throw Object.assign(new Error(message ?? "Device permission denied"), {
|
|
2206
|
-
code:
|
|
1763
|
+
code: HardwareErrorCode2.DevicePermissionDenied,
|
|
2207
1764
|
reason
|
|
2208
1765
|
});
|
|
2209
1766
|
}
|
|
@@ -2217,7 +1774,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
2217
1774
|
const tag = err && typeof err === "object" ? err._tag : void 0;
|
|
2218
1775
|
if (err && typeof err === "object" && "code" in err && typeof err.code === "number") {
|
|
2219
1776
|
const e = err;
|
|
2220
|
-
const params = e.code ===
|
|
1777
|
+
const params = e.code === HardwareErrorCode2.DevicePermissionDenied && e.reason ? { permissionDeniedReason: e.reason } : e.params;
|
|
2221
1778
|
return ledgerFailure(e.code, e.message ?? "Unknown error", e.appName, tag, params);
|
|
2222
1779
|
}
|
|
2223
1780
|
const mapped = mapLedgerError(err);
|
|
@@ -2264,15 +1821,12 @@ _LedgerAdapter.STUCK_APP_RETRY_DELAY_MS = 500;
|
|
|
2264
1821
|
// Confirm but device never shows up / never unlocks), throw DeviceNotFound
|
|
2265
1822
|
// instead of looping forever.
|
|
2266
1823
|
_LedgerAdapter.MAX_DOCONNECT_CONFIRMS = 3;
|
|
2267
|
-
// Throttle AppInstallProgress by progress delta — DMK streams much faster
|
|
2268
|
-
// than UIs need. Final frame (progress >= 1) always passes.
|
|
2269
|
-
_LedgerAdapter.APP_INSTALL_PROGRESS_MIN_DELTA = 0.05;
|
|
2270
1824
|
var LedgerAdapter = _LedgerAdapter;
|
|
2271
1825
|
|
|
2272
1826
|
// src/connector/LedgerConnectorBase.ts
|
|
2273
1827
|
import {
|
|
2274
1828
|
EConnectorInteraction as EConnectorInteraction4,
|
|
2275
|
-
HardwareErrorCode as
|
|
1829
|
+
HardwareErrorCode as HardwareErrorCode7,
|
|
2276
1830
|
serializeConnectorError
|
|
2277
1831
|
} from "@onekeyfe/hwk-adapter-core";
|
|
2278
1832
|
|
|
@@ -2829,7 +2383,7 @@ var SignerManager = class _SignerManager {
|
|
|
2829
2383
|
};
|
|
2830
2384
|
|
|
2831
2385
|
// src/connector/chains/evm.ts
|
|
2832
|
-
import { HardwareErrorCode as
|
|
2386
|
+
import { HardwareErrorCode as HardwareErrorCode3, padHex64, stripHex } from "@onekeyfe/hwk-adapter-core";
|
|
2833
2387
|
|
|
2834
2388
|
// src/connector/chains/utils.ts
|
|
2835
2389
|
import { EConnectorInteraction as EConnectorInteraction2 } from "@onekeyfe/hwk-adapter-core";
|
|
@@ -2871,7 +2425,7 @@ async function evmSignTransaction(ctx, sessionId, params) {
|
|
|
2871
2425
|
new Error(
|
|
2872
2426
|
"Ledger requires a pre-serialized transaction (serializedTx). Provide an RLP-encoded hex string."
|
|
2873
2427
|
),
|
|
2874
|
-
{ code:
|
|
2428
|
+
{ code: HardwareErrorCode3.InvalidParams }
|
|
2875
2429
|
);
|
|
2876
2430
|
}
|
|
2877
2431
|
const signer = await _getEthSigner(ctx, sessionId);
|
|
@@ -2912,7 +2466,7 @@ async function evmSignTypedData(ctx, sessionId, params) {
|
|
|
2912
2466
|
new Error(
|
|
2913
2467
|
'Ledger does not support hash-only EIP-712 signing. Use mode "full" with the complete typed data structure.'
|
|
2914
2468
|
),
|
|
2915
|
-
{ code:
|
|
2469
|
+
{ code: HardwareErrorCode3.MethodNotSupported }
|
|
2916
2470
|
);
|
|
2917
2471
|
}
|
|
2918
2472
|
const signer = await _getEthSigner(ctx, sessionId);
|
|
@@ -2947,7 +2501,7 @@ async function _getEthSigner(ctx, sessionId) {
|
|
|
2947
2501
|
}
|
|
2948
2502
|
|
|
2949
2503
|
// src/connector/chains/btc.ts
|
|
2950
|
-
import { HardwareErrorCode as
|
|
2504
|
+
import { HardwareErrorCode as HardwareErrorCode4, stripHex as stripHex2 } from "@onekeyfe/hwk-adapter-core";
|
|
2951
2505
|
import { Psbt } from "bitcoinjs-lib";
|
|
2952
2506
|
|
|
2953
2507
|
// src/signer/SignerBtc.ts
|
|
@@ -3068,7 +2622,7 @@ function _purposeToTemplate(purpose, DDT) {
|
|
|
3068
2622
|
return DDT.TAPROOT;
|
|
3069
2623
|
default:
|
|
3070
2624
|
throw Object.assign(new Error(`Unsupported BTC purpose: m/${purpose ?? "<undefined>"}'`), {
|
|
3071
|
-
code:
|
|
2625
|
+
code: HardwareErrorCode4.InvalidParams
|
|
3072
2626
|
});
|
|
3073
2627
|
}
|
|
3074
2628
|
}
|
|
@@ -3124,7 +2678,7 @@ async function btcSignTransaction(ctx, sessionId, params) {
|
|
|
3124
2678
|
if (!params.psbt) {
|
|
3125
2679
|
throw Object.assign(
|
|
3126
2680
|
new Error("Ledger requires PSBT format for BTC transaction signing. Provide params.psbt."),
|
|
3127
|
-
{ code:
|
|
2681
|
+
{ code: HardwareErrorCode4.InvalidParams }
|
|
3128
2682
|
);
|
|
3129
2683
|
}
|
|
3130
2684
|
const btcSigner = await _createBtcSigner(ctx, sessionId);
|
|
@@ -3149,7 +2703,7 @@ async function btcSignTransaction(ctx, sessionId, params) {
|
|
|
3149
2703
|
async function btcSignPsbt(ctx, sessionId, params) {
|
|
3150
2704
|
if (!params.psbt) {
|
|
3151
2705
|
throw Object.assign(new Error("btcSignPsbt requires params.psbt"), {
|
|
3152
|
-
code:
|
|
2706
|
+
code: HardwareErrorCode4.InvalidParams
|
|
3153
2707
|
});
|
|
3154
2708
|
}
|
|
3155
2709
|
const btcSigner = await _createBtcSigner(ctx, sessionId);
|
|
@@ -3394,7 +2948,7 @@ async function _createSolSigner(ctx, sessionId) {
|
|
|
3394
2948
|
}
|
|
3395
2949
|
|
|
3396
2950
|
// src/connector/chains/tron.ts
|
|
3397
|
-
import { HardwareErrorCode as
|
|
2951
|
+
import { HardwareErrorCode as HardwareErrorCode6 } from "@onekeyfe/hwk-adapter-core";
|
|
3398
2952
|
import Trx from "@ledgerhq/hw-app-trx";
|
|
3399
2953
|
|
|
3400
2954
|
// src/connector/chains/legacyChainCall.ts
|
|
@@ -3407,7 +2961,7 @@ import {
|
|
|
3407
2961
|
OpenAppCommand,
|
|
3408
2962
|
isSuccessCommandResult
|
|
3409
2963
|
} from "@ledgerhq/device-management-kit";
|
|
3410
|
-
import { HardwareErrorCode as
|
|
2964
|
+
import { HardwareErrorCode as HardwareErrorCode5 } from "@onekeyfe/hwk-adapter-core";
|
|
3411
2965
|
var APP_NAME_MAP = {
|
|
3412
2966
|
ETH: "Ethereum",
|
|
3413
2967
|
BTC: "Bitcoin",
|
|
@@ -3511,30 +3065,15 @@ var AppManager = class {
|
|
|
3511
3065
|
command: new OpenAppCommand({ appName })
|
|
3512
3066
|
});
|
|
3513
3067
|
if (!isSuccessCommandResult(result)) {
|
|
3514
|
-
const
|
|
3515
|
-
const
|
|
3516
|
-
|
|
3517
|
-
debugLog(
|
|
3518
|
-
"[AppManager] openApp failed:",
|
|
3519
|
-
appName,
|
|
3520
|
-
"errorCode:",
|
|
3521
|
-
errorCode,
|
|
3522
|
-
"tag:",
|
|
3523
|
-
dmkErr._tag
|
|
3524
|
-
);
|
|
3525
|
-
let code;
|
|
3526
|
-
if (errorCode === "6807" || /unknown application/i.test(message)) {
|
|
3527
|
-
code = HardwareErrorCode6.AppNotInstalled;
|
|
3528
|
-
} else if (errorCode === "5501" || dmkErr._tag === "ActionRefusedError") {
|
|
3529
|
-
code = HardwareErrorCode6.UserRejected;
|
|
3530
|
-
}
|
|
3068
|
+
const { statusCode } = result;
|
|
3069
|
+
const hasStatusCode2 = statusCode != null && statusCode !== "";
|
|
3070
|
+
debugLog("[AppManager] openApp failed:", appName, "statusCode:", statusCode);
|
|
3531
3071
|
throw Object.assign(new Error(`Failed to open "${appName}"`), {
|
|
3532
3072
|
_tag: ERROR_TAG.OpenAppCommand,
|
|
3533
|
-
code,
|
|
3534
|
-
errorCode,
|
|
3535
|
-
statusCode
|
|
3536
|
-
appName
|
|
3537
|
-
originalError: dmkErr
|
|
3073
|
+
code: hasStatusCode2 ? void 0 : HardwareErrorCode5.AppNotInstalled,
|
|
3074
|
+
errorCode: String(statusCode ?? ""),
|
|
3075
|
+
statusCode,
|
|
3076
|
+
appName
|
|
3538
3077
|
});
|
|
3539
3078
|
}
|
|
3540
3079
|
}
|
|
@@ -3713,7 +3252,7 @@ async function tronSignTransaction(ctx, sessionId, params) {
|
|
|
3713
3252
|
if (!params.rawTxHex) {
|
|
3714
3253
|
throw Object.assign(
|
|
3715
3254
|
new Error("TRON signing requires a protobuf-encoded raw transaction hex (rawTxHex)."),
|
|
3716
|
-
{ code:
|
|
3255
|
+
{ code: HardwareErrorCode6.InvalidParams }
|
|
3717
3256
|
);
|
|
3718
3257
|
}
|
|
3719
3258
|
const path = normalizePath(params.path);
|
|
@@ -3874,22 +3413,6 @@ var DeviceApps = class {
|
|
|
3874
3413
|
);
|
|
3875
3414
|
return result.filter((a) => a !== null).map(applicationToMetadata);
|
|
3876
3415
|
}
|
|
3877
|
-
/** Installed app names via ListApps APDU. Offline (no manager-api), but still requires unlock + dashboard. */
|
|
3878
|
-
async listInstalledNames(options) {
|
|
3879
|
-
const action = this._dmk.executeDeviceAction({
|
|
3880
|
-
sessionId: this._sessionId,
|
|
3881
|
-
deviceAction: new this._ledgerKit.ListAppsDeviceAction({
|
|
3882
|
-
input: { unlockTimeout: options?.unlockTimeout }
|
|
3883
|
-
})
|
|
3884
|
-
});
|
|
3885
|
-
const result = await deviceActionToPromise(
|
|
3886
|
-
action,
|
|
3887
|
-
this.onInteraction,
|
|
3888
|
-
void 0,
|
|
3889
|
-
this.onRegisterCanceller
|
|
3890
|
-
);
|
|
3891
|
-
return result.map((entry) => entry?.appName).filter((name) => typeof name === "string" && name.length > 0);
|
|
3892
|
-
}
|
|
3893
3416
|
// Catalog lookup via custom device action — DMK has no typed wrapper for this.
|
|
3894
3417
|
async listAvailable() {
|
|
3895
3418
|
const customAction = new ListAvailableAppsDeviceAction({
|
|
@@ -3953,22 +3476,6 @@ var DeviceApps = class {
|
|
|
3953
3476
|
async install(appName, onProgress, options) {
|
|
3954
3477
|
if (!appName) throw new Error("DeviceApps.install: appName is required");
|
|
3955
3478
|
debugLog("[DeviceApps] install:", appName);
|
|
3956
|
-
const refreshAction = this._dmk.executeDeviceAction({
|
|
3957
|
-
sessionId: this._sessionId,
|
|
3958
|
-
deviceAction: new this._ledgerKit.GetDeviceMetadataDeviceAction({
|
|
3959
|
-
input: {
|
|
3960
|
-
useSecureChannel: true,
|
|
3961
|
-
forceUpdate: true,
|
|
3962
|
-
unlockTimeout: options?.unlockTimeout
|
|
3963
|
-
}
|
|
3964
|
-
})
|
|
3965
|
-
});
|
|
3966
|
-
await deviceActionToPromise(
|
|
3967
|
-
refreshAction,
|
|
3968
|
-
this.onInteraction,
|
|
3969
|
-
INSTALL_TIMEOUT_MS,
|
|
3970
|
-
this.onRegisterCanceller
|
|
3971
|
-
);
|
|
3972
3479
|
const action = this._dmk.executeDeviceAction({
|
|
3973
3480
|
sessionId: this._sessionId,
|
|
3974
3481
|
deviceAction: new this._ledgerKit.InstallOrUpdateAppsDeviceAction({
|
|
@@ -4046,7 +3553,7 @@ var METHOD_PREFIX_TO_APP_NAME = {
|
|
|
4046
3553
|
tron: "Tron"
|
|
4047
3554
|
};
|
|
4048
3555
|
var HARDWARE_ERROR_CODE_VALUES = new Set(
|
|
4049
|
-
Object.values(
|
|
3556
|
+
Object.values(HardwareErrorCode7).filter((value) => typeof value === "number")
|
|
4050
3557
|
);
|
|
4051
3558
|
var BLE_CONNECT_SCAN_TIMEOUT_MS = 1500;
|
|
4052
3559
|
async function defaultLedgerKitImporter(pkg) {
|
|
@@ -4217,7 +3724,7 @@ var LedgerConnectorBase = class {
|
|
|
4217
3724
|
`Ledger BLE connect did not return within ${HANG_CEILING_MS / 6e4}min \u2014 DMK hang fallback.`
|
|
4218
3725
|
);
|
|
4219
3726
|
err._tag = ERROR_TAG.BlePairingTimeout;
|
|
4220
|
-
err.code =
|
|
3727
|
+
err.code = HardwareErrorCode7.BlePairingTimeout;
|
|
4221
3728
|
reject(err);
|
|
4222
3729
|
}, HANG_CEILING_MS);
|
|
4223
3730
|
});
|
|
@@ -4250,7 +3757,7 @@ var LedgerConnectorBase = class {
|
|
|
4250
3757
|
"Ledger device is not currently advertising. Wake up and unlock the device, keep it nearby, then try again."
|
|
4251
3758
|
);
|
|
4252
3759
|
err._tag = ERROR_TAG.DeviceNotAdvertising;
|
|
4253
|
-
err.code =
|
|
3760
|
+
err.code = HardwareErrorCode7.DeviceNotFound;
|
|
4254
3761
|
throw err;
|
|
4255
3762
|
};
|
|
4256
3763
|
const doConnect = async (path) => {
|
|
@@ -4314,7 +3821,7 @@ var LedgerConnectorBase = class {
|
|
|
4314
3821
|
"Ledger Bluetooth pairing failed. Make sure the device is unlocked and nearby, then try again."
|
|
4315
3822
|
);
|
|
4316
3823
|
wrapped._tag = ERROR_TAG.BleGattBondingFailed;
|
|
4317
|
-
wrapped.code =
|
|
3824
|
+
wrapped.code = HardwareErrorCode7.BlePairingTimeout;
|
|
4318
3825
|
wrapped.originalError = err;
|
|
4319
3826
|
throw wrapped;
|
|
4320
3827
|
}
|
|
@@ -4392,7 +3899,7 @@ var LedgerConnectorBase = class {
|
|
|
4392
3899
|
this._unwatchSessionState(sessionId);
|
|
4393
3900
|
this._signerManager?.invalidate(sessionId);
|
|
4394
3901
|
this._cancellers.get(sessionId)?.({
|
|
4395
|
-
code:
|
|
3902
|
+
code: HardwareErrorCode7.DeviceDisconnected,
|
|
4396
3903
|
tag: "DeviceDisconnected",
|
|
4397
3904
|
message: "Device disconnected"
|
|
4398
3905
|
});
|
|
@@ -4418,7 +3925,7 @@ var LedgerConnectorBase = class {
|
|
|
4418
3925
|
success: false,
|
|
4419
3926
|
error: serializeConnectorError(
|
|
4420
3927
|
Object.assign(new Error("Ledger app is unresponsive"), {
|
|
4421
|
-
code:
|
|
3928
|
+
code: HardwareErrorCode7.DeviceAppStuck,
|
|
4422
3929
|
_tag: ERROR_TAG.DeviceAppStuck,
|
|
4423
3930
|
originalError: err
|
|
4424
3931
|
})
|
|
@@ -4430,7 +3937,7 @@ var LedgerConnectorBase = class {
|
|
|
4430
3937
|
success: false,
|
|
4431
3938
|
error: serializeConnectorError(
|
|
4432
3939
|
Object.assign(new Error("Device communication interrupted, please retry"), {
|
|
4433
|
-
code:
|
|
3940
|
+
code: HardwareErrorCode7.TransportError,
|
|
4434
3941
|
_tag: ERROR_TAG.DeviceTransportStuck,
|
|
4435
3942
|
originalError: err
|
|
4436
3943
|
})
|
|
@@ -4526,17 +4033,6 @@ var LedgerConnectorBase = class {
|
|
|
4526
4033
|
ctx.clearCanceller(sessionId);
|
|
4527
4034
|
}
|
|
4528
4035
|
}
|
|
4529
|
-
case "listInstalledNames": {
|
|
4530
|
-
const apps = await _getDeviceApps(ctx, sessionId);
|
|
4531
|
-
try {
|
|
4532
|
-
return await apps.listInstalledNames(params);
|
|
4533
|
-
} catch (err) {
|
|
4534
|
-
ctx.invalidateSession(sessionId);
|
|
4535
|
-
throw ctx.wrapError(err);
|
|
4536
|
-
} finally {
|
|
4537
|
-
ctx.clearCanceller(sessionId);
|
|
4538
|
-
}
|
|
4539
|
-
}
|
|
4540
4036
|
case "listAvailableApps": {
|
|
4541
4037
|
const apps = await _getDeviceApps(ctx, sessionId);
|
|
4542
4038
|
try {
|