@onekeyfe/hwk-ledger-adapter 1.2.3-alpha.3 → 1.2.3-alpha.4
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.js +46 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -5
package/dist/index.mjs
CHANGED
|
@@ -466,6 +466,15 @@ function mapLedgerError(err, opts) {
|
|
|
466
466
|
};
|
|
467
467
|
}
|
|
468
468
|
|
|
469
|
+
// src/utils/queueKey.ts
|
|
470
|
+
var LEDGER_DEFAULT_QUEUE_KEY = "__ledger_default__";
|
|
471
|
+
function ledgerQueueKey({
|
|
472
|
+
operationId,
|
|
473
|
+
connectId
|
|
474
|
+
}) {
|
|
475
|
+
return (operationId ?? connectId) || LEDGER_DEFAULT_QUEUE_KEY;
|
|
476
|
+
}
|
|
477
|
+
|
|
469
478
|
// src/adapter/methods/allNetworkGetAddress.ts
|
|
470
479
|
import {
|
|
471
480
|
HardwareErrorCode as HardwareErrorCode2,
|
|
@@ -531,7 +540,8 @@ function createAllNetworkGetAddress({
|
|
|
531
540
|
callChain,
|
|
532
541
|
getChainFingerprint,
|
|
533
542
|
retainOperation,
|
|
534
|
-
errorToFailure
|
|
543
|
+
errorToFailure,
|
|
544
|
+
createCancelScope
|
|
535
545
|
}) {
|
|
536
546
|
return async function allNetworkGetAddress(connectId, _deviceId, params) {
|
|
537
547
|
debugLog("[LedgerAdapter][REQ]", {
|
|
@@ -548,6 +558,9 @@ function createAllNetworkGetAddress({
|
|
|
548
558
|
} catch (error) {
|
|
549
559
|
return errorToFailure(error);
|
|
550
560
|
}
|
|
561
|
+
const cancelScope = createCancelScope(
|
|
562
|
+
ledgerQueueKey({ operationId: target.payload.operationId, connectId: effectiveTargetId })
|
|
563
|
+
);
|
|
551
564
|
const installContext = {};
|
|
552
565
|
const commonParams = {
|
|
553
566
|
autoInstallApp: params.autoInstallApp,
|
|
@@ -565,6 +578,7 @@ function createAllNetworkGetAddress({
|
|
|
565
578
|
normalizeItem: normalizeLedgerAllNetworkItem,
|
|
566
579
|
buildUnsupportedNetworkResponse: (item) => isUnsupportedLedgerAllNetworkNetwork(item) ? buildUnsupportedNetworkResponse(item) : void 0,
|
|
567
580
|
callItem: async ({ method, chain, item }) => {
|
|
581
|
+
if (cancelScope.signal.aborted) return buildCancelledFailure(cancelScope.signal);
|
|
568
582
|
const itemDeviceId = getItemDeviceId(item) ?? chainFingerprints.get(chain) ?? "";
|
|
569
583
|
return callAllNetworkMethod(
|
|
570
584
|
callChain,
|
|
@@ -583,7 +597,8 @@ function createAllNetworkGetAddress({
|
|
|
583
597
|
chain,
|
|
584
598
|
payload,
|
|
585
599
|
chainFingerprints,
|
|
586
|
-
installContext
|
|
600
|
+
installContext,
|
|
601
|
+
cancelScope.signal
|
|
587
602
|
),
|
|
588
603
|
shouldAbortBundle: isTopLevelAllNetworkFailure,
|
|
589
604
|
buildTopLevelFailure: (response) => {
|
|
@@ -602,10 +617,17 @@ function createAllNetworkGetAddress({
|
|
|
602
617
|
});
|
|
603
618
|
return result;
|
|
604
619
|
} finally {
|
|
620
|
+
cancelScope.release();
|
|
605
621
|
releaseOperationRetention?.();
|
|
606
622
|
}
|
|
607
623
|
};
|
|
608
624
|
}
|
|
625
|
+
function buildCancelledFailure(signal) {
|
|
626
|
+
const reason = signal.reason;
|
|
627
|
+
const code = typeof reason?.code === "number" ? reason.code : HardwareErrorCode2.UserAborted;
|
|
628
|
+
const message = typeof reason?.message === "string" ? reason.message : "";
|
|
629
|
+
return failure(code, message || "All-network get-address cancelled");
|
|
630
|
+
}
|
|
609
631
|
function isTopLevelAllNetworkFailure(response) {
|
|
610
632
|
if (response.success) {
|
|
611
633
|
return false;
|
|
@@ -641,8 +663,13 @@ function normalizeLedgerAllNetworkItem(method, item) {
|
|
|
641
663
|
const coin = LEDGER_BTC_NETWORK_COIN_MAP[item.network];
|
|
642
664
|
return coin ? { ...item, coin } : item;
|
|
643
665
|
}
|
|
644
|
-
async function attachLedgerIdentity(getChainFingerprint, connectId, item, chain, payload, chainFingerprints, context) {
|
|
645
|
-
const
|
|
666
|
+
async function attachLedgerIdentity(getChainFingerprint, connectId, item, chain, payload, chainFingerprints, context, cancelSignal) {
|
|
667
|
+
const knownFingerprint = getItemDeviceId(item) || chainFingerprints.get(chain) || "";
|
|
668
|
+
if (!knownFingerprint && cancelSignal.aborted) {
|
|
669
|
+
const cancelled = buildCancelledFailure(cancelSignal);
|
|
670
|
+
return { ...item, success: false, payload: cancelled.payload };
|
|
671
|
+
}
|
|
672
|
+
const fingerprint = knownFingerprint || await bootstrapChainFingerprint(
|
|
646
673
|
getChainFingerprint,
|
|
647
674
|
context.connection?.connectId ?? connectId,
|
|
648
675
|
chain,
|
|
@@ -831,7 +858,8 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
831
858
|
}
|
|
832
859
|
},
|
|
833
860
|
retainOperation: (operationId) => this._operations.retain(operationId),
|
|
834
|
-
errorToFailure: (error) => this.errorToFailure(error)
|
|
861
|
+
errorToFailure: (error) => this.errorToFailure(error),
|
|
862
|
+
createCancelScope: (queueKey) => this._jobQueue.createCancelScope(queueKey)
|
|
835
863
|
});
|
|
836
864
|
// ---------------------------------------------------------------------------
|
|
837
865
|
// Private helpers
|
|
@@ -1850,14 +1878,23 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1850
1878
|
this._uiRegistry.cancel();
|
|
1851
1879
|
this._finishBleBinding("cancelled");
|
|
1852
1880
|
const interactionForPhysicalId = !operationId && connectId ? this._operations.findActiveByConnectionKey(connectId) : void 0;
|
|
1853
|
-
const queueKey = operationId ?? (activeJobId === connectId ? connectId : interactionForPhysicalId?.operationId) ?? connectId;
|
|
1854
1881
|
const pendingOperationId = operationId ?? interactionForPhysicalId?.operationId;
|
|
1855
1882
|
if (!connectId) this._pendingOperationBindings.clear();
|
|
1856
1883
|
else if (pendingOperationId) {
|
|
1857
1884
|
this._pendingOperationBindings.delete(pendingOperationId);
|
|
1858
1885
|
}
|
|
1859
|
-
|
|
1860
|
-
|
|
1886
|
+
const queueKeys = /* @__PURE__ */ new Set();
|
|
1887
|
+
if (connectId) queueKeys.add(ledgerQueueKey({ connectId }));
|
|
1888
|
+
if (pendingOperationId) queueKeys.add(ledgerQueueKey({ operationId: pendingOperationId }));
|
|
1889
|
+
if (queueKeys.size) {
|
|
1890
|
+
let cancelledAnyJob = false;
|
|
1891
|
+
for (const key of queueKeys) {
|
|
1892
|
+
cancelledAnyJob = this._jobQueue.cancelActiveAndPending(key, userAbortReason) || cancelledAnyJob;
|
|
1893
|
+
}
|
|
1894
|
+
debugLog("[LedgerAdapter] cancel routed to queue keys", {
|
|
1895
|
+
queueKeys: [...queueKeys],
|
|
1896
|
+
cancelledAnyJob
|
|
1897
|
+
});
|
|
1861
1898
|
} else {
|
|
1862
1899
|
this._jobQueue.cancelActiveAndPending(void 0, userAbortReason);
|
|
1863
1900
|
}
|
|
@@ -2525,7 +2562,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
2525
2562
|
connectId: effectiveConnectId || "(empty)",
|
|
2526
2563
|
params
|
|
2527
2564
|
});
|
|
2528
|
-
const queueKey = (operationId
|
|
2565
|
+
const queueKey = ledgerQueueKey({ operationId, connectId: effectiveConnectId });
|
|
2529
2566
|
try {
|
|
2530
2567
|
const result = await this._jobQueue.enqueue(
|
|
2531
2568
|
queueKey,
|