@onekeyfe/hwk-trezor-adapter 1.2.8-alpha.13 → 1.2.8-alpha.131
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 +102 -80
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -28
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
resolveHardwareOperationTarget,
|
|
29
29
|
runAllNetworkGetAddress,
|
|
30
30
|
success,
|
|
31
|
+
summarizeForLog,
|
|
31
32
|
toPhysicalDeviceSearchTarget
|
|
32
33
|
} from "@onekeyfe/hwk-adapter-core";
|
|
33
34
|
import { randomBytes } from "@noble/hashes/utils";
|
|
@@ -912,7 +913,8 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
912
913
|
this._emitter.emit(data.type, { ...data, payload });
|
|
913
914
|
};
|
|
914
915
|
this._onUiEvent = (data) => {
|
|
915
|
-
this.
|
|
916
|
+
const operationId = this._activeOperationId();
|
|
917
|
+
this._emitter.emit("ui-event", operationId ? { ...data, operationId } : data);
|
|
916
918
|
};
|
|
917
919
|
this._onThpCredentialsChanged = (data) => {
|
|
918
920
|
this._emitter.emit(DEVICE.TREZOR_THP_CREDENTIALS_CHANGED, {
|
|
@@ -984,11 +986,21 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
984
986
|
static _normalizeLogKey(key) {
|
|
985
987
|
return key.replace(/[_-]/g, "").toLowerCase();
|
|
986
988
|
}
|
|
987
|
-
//
|
|
988
|
-
//
|
|
989
|
-
static _sanitizeForLog(value, methodName) {
|
|
990
|
-
|
|
991
|
-
|
|
989
|
+
// [REQ]/[RES] bodies: paths, chain ids and flags stay readable; transaction
|
|
990
|
+
// contents, keys and addresses become length + short hash; secrets are redacted.
|
|
991
|
+
static _sanitizeForLog(value, methodName, role = "params") {
|
|
992
|
+
return summarizeForLog(value, { method: methodName, role });
|
|
993
|
+
}
|
|
994
|
+
// A failure payload is an error record, so its message/error text stays readable.
|
|
995
|
+
static _responseForLog(response, methodName) {
|
|
996
|
+
if (response.success) {
|
|
997
|
+
return _TrezorAdapter._sanitizeForLog(response.payload, methodName, "result");
|
|
998
|
+
}
|
|
999
|
+
const out = summarizeForLog(
|
|
1000
|
+
{ error: response.payload },
|
|
1001
|
+
{ method: methodName, role: "result" }
|
|
1002
|
+
);
|
|
1003
|
+
return out && typeof out === "object" ? out.error : out;
|
|
992
1004
|
}
|
|
993
1005
|
static _redactForLog(value, seen) {
|
|
994
1006
|
if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {
|
|
@@ -1009,14 +1021,17 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1009
1021
|
static _errorForLog(error) {
|
|
1010
1022
|
if (!error || typeof error !== "object") return error;
|
|
1011
1023
|
const typed = error;
|
|
1012
|
-
return _TrezorAdapter.
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1024
|
+
return _TrezorAdapter._redactForLog(
|
|
1025
|
+
{
|
|
1026
|
+
name: typed.name,
|
|
1027
|
+
message: typed.message,
|
|
1028
|
+
code: typed.code,
|
|
1029
|
+
errorCode: typed.errorCode,
|
|
1030
|
+
statusCode: typed.statusCode,
|
|
1031
|
+
response: typed.response
|
|
1032
|
+
},
|
|
1033
|
+
/* @__PURE__ */ new WeakSet()
|
|
1034
|
+
);
|
|
1020
1035
|
}
|
|
1021
1036
|
_setPassphraseRequestContext(connectId, context) {
|
|
1022
1037
|
const previous = this._passphraseRequestContextByConnectId.get(connectId);
|
|
@@ -1413,6 +1428,10 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1413
1428
|
}
|
|
1414
1429
|
async _releaseOperationConnection(operation) {
|
|
1415
1430
|
const { connectId } = operation;
|
|
1431
|
+
const activeKey = this._jobQueue.getActiveJob()?.deviceId;
|
|
1432
|
+
if (activeKey !== void 0 && !isHardwareOperationId(activeKey) && (activeKey === connectId || activeKey === "" || activeKey === operation.device.deviceId)) {
|
|
1433
|
+
return;
|
|
1434
|
+
}
|
|
1416
1435
|
const connecting = this._connectingPromises.has(connectId);
|
|
1417
1436
|
this._connectingPromises.delete(connectId);
|
|
1418
1437
|
const sessionId = this._sessions.get(connectId);
|
|
@@ -1642,15 +1661,19 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1642
1661
|
"getFeatures",
|
|
1643
1662
|
connectId,
|
|
1644
1663
|
hasConnectionContext || !connectId ? expectedDeviceId : void 0,
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1664
|
+
{
|
|
1665
|
+
// Routing limits always apply: the connection found here is reused by the whole
|
|
1666
|
+
// bundle, so dropping them would let a bundle open a transport the host excluded.
|
|
1667
|
+
operationId: commonParams?.operationId,
|
|
1668
|
+
knownConnections: commonParams?.knownConnections,
|
|
1669
|
+
extra: commonParams?.extra,
|
|
1670
|
+
allowDeviceSelection: commonParams?.allowDeviceSelection,
|
|
1671
|
+
supportedTransports: commonParams?.supportedTransports,
|
|
1672
|
+
...hasConnectionContext ? {
|
|
1673
|
+
passphraseState: commonParams.passphraseState,
|
|
1674
|
+
useEmptyPassphrase: commonParams.useEmptyPassphrase
|
|
1675
|
+
} : {}
|
|
1676
|
+
},
|
|
1654
1677
|
false,
|
|
1655
1678
|
bundleContext
|
|
1656
1679
|
) : await this.getFeatures(
|
|
@@ -1710,7 +1733,7 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1710
1733
|
for (const key of queueKeys) {
|
|
1711
1734
|
this._jobQueue.cancelActiveAndPending(key, userAbortReason);
|
|
1712
1735
|
}
|
|
1713
|
-
if (resolvedConnectId) {
|
|
1736
|
+
if (resolvedConnectId && (activeJobId === void 0 || ownsConnectorInteraction)) {
|
|
1714
1737
|
void this._connector.cancel(this._sessions.get(resolvedConnectId) ?? resolvedConnectId);
|
|
1715
1738
|
}
|
|
1716
1739
|
return;
|
|
@@ -1723,8 +1746,7 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1723
1746
|
}
|
|
1724
1747
|
}
|
|
1725
1748
|
/**
|
|
1726
|
-
*
|
|
1727
|
-
* operation of its connectId, so a mid-call UI request can name it.
|
|
1749
|
+
* Only the operation explicitly supplied to the running job owns its UI requests.
|
|
1728
1750
|
*/
|
|
1729
1751
|
_activeOperationId() {
|
|
1730
1752
|
return this._operations.findOperationIdByJobKey(this._jobQueue.getActiveJob()?.deviceId);
|
|
@@ -2145,7 +2167,7 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2145
2167
|
debugLog("[TrezorAdapter][RES]", {
|
|
2146
2168
|
method: methodName,
|
|
2147
2169
|
success: response.success,
|
|
2148
|
-
payload: _TrezorAdapter.
|
|
2170
|
+
payload: _TrezorAdapter._responseForLog(response, methodName)
|
|
2149
2171
|
});
|
|
2150
2172
|
return response;
|
|
2151
2173
|
} catch (error) {
|
|
@@ -2153,7 +2175,7 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2153
2175
|
debugLog("[TrezorAdapter][RES]", {
|
|
2154
2176
|
method: methodName,
|
|
2155
2177
|
success: false,
|
|
2156
|
-
payload: _TrezorAdapter.
|
|
2178
|
+
payload: _TrezorAdapter._responseForLog(response, methodName)
|
|
2157
2179
|
});
|
|
2158
2180
|
return response;
|
|
2159
2181
|
} finally {
|