@onekeyfe/hwk-ledger-adapter 1.2.8-alpha.122 → 1.2.8-alpha.124
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +28 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1030,6 +1030,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1030
1030
|
// need to subscribe in one place. The AppInstallProgress variant re-keys
|
|
1031
1031
|
// sessionId to connectId via `_sessions`, and drops if no mapping exists.
|
|
1032
1032
|
this.uiEventForwarder = (event) => {
|
|
1033
|
+
const operationId = this._activeOperationId();
|
|
1033
1034
|
if (event.type === EConnectorInteraction.AppInstallProgress) {
|
|
1034
1035
|
let connectId;
|
|
1035
1036
|
for (const [cid, sid] of this._sessions) {
|
|
@@ -1058,6 +1059,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1058
1059
|
this._installProgressLastEmittedValue = progress;
|
|
1059
1060
|
this.emitter.emit("ui-event", {
|
|
1060
1061
|
type: EConnectorInteraction.AppInstallProgress,
|
|
1062
|
+
...operationId ? { operationId } : {},
|
|
1061
1063
|
payload: {
|
|
1062
1064
|
connectId,
|
|
1063
1065
|
appName,
|
|
@@ -1066,7 +1068,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
1066
1068
|
});
|
|
1067
1069
|
return;
|
|
1068
1070
|
}
|
|
1069
|
-
this.emitter.emit("ui-event", event);
|
|
1071
|
+
this.emitter.emit("ui-event", operationId ? { ...event, operationId } : event);
|
|
1070
1072
|
};
|
|
1071
1073
|
this.connector = connector;
|
|
1072
1074
|
this._defaultAutoInstallApp = options?.autoInstallApp ?? false;
|
|
@@ -2056,12 +2058,6 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
2056
2058
|
} else {
|
|
2057
2059
|
this._jobQueue.cancelActiveAndPending(void 0, userAbortReason);
|
|
2058
2060
|
}
|
|
2059
|
-
if (resolvedConnectId) {
|
|
2060
|
-
const sessionId = this._sessions.get(resolvedConnectId) ?? resolvedConnectId;
|
|
2061
|
-
void this.connector.cancel(sessionId);
|
|
2062
|
-
} else {
|
|
2063
|
-
for (const sid of this._sessions.values()) void this.connector.cancel(sid);
|
|
2064
|
-
}
|
|
2065
2061
|
const connectingConnectId = this._connectingConnectId;
|
|
2066
2062
|
const targetKeys = new Set(
|
|
2067
2063
|
[
|
|
@@ -2071,6 +2067,14 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
2071
2067
|
].filter(Boolean)
|
|
2072
2068
|
);
|
|
2073
2069
|
const ownsPendingConnect = !connectId || activeJobId !== void 0 && queueKeys.has(activeJobId) || connectingConnectId !== void 0 && targetKeys.has(connectingConnectId);
|
|
2070
|
+
if (activeJobId === void 0 || ownsPendingConnect) {
|
|
2071
|
+
if (resolvedConnectId) {
|
|
2072
|
+
const sessionId = this._sessions.get(resolvedConnectId) ?? resolvedConnectId;
|
|
2073
|
+
void this.connector.cancel(sessionId);
|
|
2074
|
+
} else {
|
|
2075
|
+
for (const sid of this._sessions.values()) void this.connector.cancel(sid);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2074
2078
|
if (this._connectingPromise && ownsPendingConnect) {
|
|
2075
2079
|
this._doConnectAbortController?.abort(userAbortReason);
|
|
2076
2080
|
}
|
|
@@ -2253,7 +2257,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
2253
2257
|
} catch (err) {
|
|
2254
2258
|
this.emitter.emit(UI_REQUEST.CLOSE_UI_WINDOW, {
|
|
2255
2259
|
type: UI_REQUEST.CLOSE_UI_WINDOW,
|
|
2256
|
-
payload: {}
|
|
2260
|
+
payload: { operationId }
|
|
2257
2261
|
});
|
|
2258
2262
|
throw Object.assign(new Error("User cancelled Ledger connection"), {
|
|
2259
2263
|
_tag: ERROR_TAG.UserAborted,
|
|
@@ -2317,7 +2321,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
2317
2321
|
} catch (err) {
|
|
2318
2322
|
this.emitter.emit(UI_REQUEST.CLOSE_UI_WINDOW, {
|
|
2319
2323
|
type: UI_REQUEST.CLOSE_UI_WINDOW,
|
|
2320
|
-
payload: {}
|
|
2324
|
+
payload: { operationId }
|
|
2321
2325
|
});
|
|
2322
2326
|
return false;
|
|
2323
2327
|
}
|
|
@@ -2355,7 +2359,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
2355
2359
|
} catch (err) {
|
|
2356
2360
|
this.emitter.emit(UI_REQUEST.CLOSE_UI_WINDOW, {
|
|
2357
2361
|
type: UI_REQUEST.CLOSE_UI_WINDOW,
|
|
2358
|
-
payload: {}
|
|
2362
|
+
payload: { operationId }
|
|
2359
2363
|
});
|
|
2360
2364
|
return false;
|
|
2361
2365
|
}
|
|
@@ -3151,7 +3155,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
3151
3155
|
}
|
|
3152
3156
|
this.emitter.emit(UI_REQUEST.CLOSE_UI_WINDOW, {
|
|
3153
3157
|
type: UI_REQUEST.CLOSE_UI_WINDOW,
|
|
3154
|
-
payload: {}
|
|
3158
|
+
payload: { operationId }
|
|
3155
3159
|
});
|
|
3156
3160
|
return await this._runConnectorCall(
|
|
3157
3161
|
resolvedConnectId,
|
|
@@ -3218,7 +3222,7 @@ var _LedgerAdapter = class _LedgerAdapter {
|
|
|
3218
3222
|
if (err?._tag === UI_REQUEST_PREEMPTED_TAG) {
|
|
3219
3223
|
this.emitter.emit(UI_REQUEST.CLOSE_UI_WINDOW, {
|
|
3220
3224
|
type: UI_REQUEST.CLOSE_UI_WINDOW,
|
|
3221
|
-
payload: {}
|
|
3225
|
+
payload: { operationId }
|
|
3222
3226
|
});
|
|
3223
3227
|
throw Object.assign(new Error("Device permission request superseded"), {
|
|
3224
3228
|
_tag: ERROR_TAG.UserAborted,
|
|
@@ -4961,6 +4965,14 @@ var METHOD_PREFIX_TO_APP_NAME = {
|
|
|
4961
4965
|
tron: "Tron",
|
|
4962
4966
|
zcash: "Zcash"
|
|
4963
4967
|
};
|
|
4968
|
+
function withOpenAppName(event, data, appName) {
|
|
4969
|
+
if (event !== "ui-event") return data;
|
|
4970
|
+
const uiEvent = data;
|
|
4971
|
+
if (uiEvent.type !== EConnectorInteraction3.ConfirmOpenApp || uiEvent.payload.appName) {
|
|
4972
|
+
return data;
|
|
4973
|
+
}
|
|
4974
|
+
return { ...uiEvent, payload: { ...uiEvent.payload, appName } };
|
|
4975
|
+
}
|
|
4964
4976
|
var HARDWARE_ERROR_CODE_VALUES = new Set(
|
|
4965
4977
|
Object.values(HardwareErrorCode7).filter((value) => typeof value === "number")
|
|
4966
4978
|
);
|
|
@@ -5769,8 +5781,8 @@ var LedgerConnectorBase = class {
|
|
|
5769
5781
|
// ---------------------------------------------------------------------------
|
|
5770
5782
|
/**
|
|
5771
5783
|
* Return a per-call ctx with the chain's Ledger app name pre-bound to
|
|
5772
|
-
* wrapError, so chain handlers don't need to repeat
|
|
5773
|
-
*
|
|
5784
|
+
* UI prompts and wrapError, so chain handlers don't need to repeat the name.
|
|
5785
|
+
* Falls through unchanged for unknown methods.
|
|
5774
5786
|
*/
|
|
5775
5787
|
_ctxForMethod(method) {
|
|
5776
5788
|
const prefix = /^(evm|btc|sol|tron|zcash)/.exec(method)?.[1];
|
|
@@ -5778,7 +5790,8 @@ var LedgerConnectorBase = class {
|
|
|
5778
5790
|
if (!defaultAppName) return this._ctx;
|
|
5779
5791
|
return {
|
|
5780
5792
|
...this._ctx,
|
|
5781
|
-
wrapError: (err, opts) => this._wrapError(err, { defaultAppName, ...opts })
|
|
5793
|
+
wrapError: (err, opts) => this._wrapError(err, { defaultAppName, ...opts }),
|
|
5794
|
+
emit: (event, data) => this._ctx.emit(event, withOpenAppName(event, data, defaultAppName))
|
|
5782
5795
|
};
|
|
5783
5796
|
}
|
|
5784
5797
|
_wrapError(err, opts) {
|