@onekeyfe/hwk-trezor-adapter 1.2.8-alpha.13 → 1.2.8-alpha.14
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 +25 -70
- package/dist/index.d.ts +25 -70
- package/dist/index.js +234 -1167
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +221 -1154
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -8,24 +8,6 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
11
|
|
|
30
12
|
|
|
31
13
|
|
|
@@ -780,34 +762,10 @@ function debugLog(...args) {
|
|
|
780
762
|
emitLog("debug", ...args);
|
|
781
763
|
}
|
|
782
764
|
|
|
783
|
-
// src/utils/queueKey.ts
|
|
784
|
-
function trezorQueueKey({
|
|
785
|
-
operationId,
|
|
786
|
-
connectId
|
|
787
|
-
}) {
|
|
788
|
-
return operationId || connectId || "";
|
|
789
|
-
}
|
|
790
|
-
|
|
791
765
|
// src/adapter/TrezorAdapter.ts
|
|
792
766
|
var KNOWN_HARDWARE_ERROR_CODES = new Set(
|
|
793
767
|
Object.values(_hwkadaptercore.HardwareErrorCode).filter((value) => typeof value === "number")
|
|
794
768
|
);
|
|
795
|
-
var ALL_NETWORK_COMMON_PARAM_KEYS = [
|
|
796
|
-
"autoInstallApp",
|
|
797
|
-
"passphraseState",
|
|
798
|
-
"useEmptyPassphrase",
|
|
799
|
-
"operationId",
|
|
800
|
-
"knownConnections",
|
|
801
|
-
"extra",
|
|
802
|
-
"allowDeviceSelection",
|
|
803
|
-
"supportedTransports"
|
|
804
|
-
];
|
|
805
|
-
var ALL_NETWORK_ROUTING_PARAM_KEYS = [
|
|
806
|
-
"operationId",
|
|
807
|
-
"knownConnections",
|
|
808
|
-
"allowDeviceSelection",
|
|
809
|
-
"supportedTransports"
|
|
810
|
-
];
|
|
811
769
|
var TREZOR_BTC_NETWORK_COIN_MAP = {
|
|
812
770
|
btc: "Bitcoin",
|
|
813
771
|
bitcoin: "Bitcoin",
|
|
@@ -824,24 +782,9 @@ var TREZOR_BTC_NETWORK_COIN_MAP = {
|
|
|
824
782
|
dash: "Dash"
|
|
825
783
|
};
|
|
826
784
|
var _TrezorAdapter = class _TrezorAdapter {
|
|
827
|
-
constructor(connector
|
|
785
|
+
constructor(connector) {
|
|
828
786
|
this.vendor = "trezor";
|
|
829
|
-
// The connector has no protocol-level cancel: the adapter stops waiting and
|
|
830
|
-
// drops the late response, the device carries on.
|
|
831
|
-
this.cancelCapability = "stops-waiting";
|
|
832
787
|
this._emitter = new (0, _hwkadaptercore.TypedEventEmitter)();
|
|
833
|
-
this._operations = new (0, _hwkadaptercore.OperationRegistry)({
|
|
834
|
-
vendor: "trezor",
|
|
835
|
-
onEnded: (operation, reason) => {
|
|
836
|
-
this._emitter.emit(_hwkadaptercore.SDK.OPERATION_ENDED, {
|
|
837
|
-
type: _hwkadaptercore.SDK.OPERATION_ENDED,
|
|
838
|
-
payload: { operationId: operation.operationId, reason }
|
|
839
|
-
});
|
|
840
|
-
if (reason === "timeout") {
|
|
841
|
-
void this._releaseOperationConnection(operation).catch(() => void 0);
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
});
|
|
845
788
|
this._devices = /* @__PURE__ */ new Map();
|
|
846
789
|
this._sessions = /* @__PURE__ */ new Map();
|
|
847
790
|
this._connectingPromises = /* @__PURE__ */ new Map();
|
|
@@ -850,21 +793,12 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
850
793
|
this._uiRegistry = new (0, _hwkadaptercore.UiRequestRegistry)();
|
|
851
794
|
this._passphraseRequestContextByConnectId = /* @__PURE__ */ new Map();
|
|
852
795
|
this._verifiedPassphraseSessionsByConnectId = /* @__PURE__ */ new Map();
|
|
853
|
-
/** Raw connector calls that outlive an aborted caller, keyed by session. */
|
|
854
|
-
this._unsettledConnectorOperations = /* @__PURE__ */ new Map();
|
|
855
|
-
this._connectorIdleWaiters = /* @__PURE__ */ new Set();
|
|
856
|
-
this._resetPromise = null;
|
|
857
|
-
this._connectorTeardownTail = Promise.resolve();
|
|
858
|
-
this._pendingConnectorTeardowns = 0;
|
|
859
|
-
this._stateGeneration = 0;
|
|
860
|
-
this._knownDeviceConnections = /* @__PURE__ */ new Map();
|
|
861
796
|
this._onDeviceConnect = (data) => {
|
|
862
797
|
const device = this._connectorDeviceToDeviceInfo(data.device);
|
|
863
798
|
this._devices.set(device.connectId, device);
|
|
864
799
|
this._emitter.emit(_hwkadaptercore.DEVICE.CONNECT, { type: _hwkadaptercore.DEVICE.CONNECT, payload: device });
|
|
865
800
|
};
|
|
866
801
|
this._onDeviceDisconnect = (data) => {
|
|
867
|
-
this._operations.endByConnectionKey(data.connectId, "disconnect");
|
|
868
802
|
this._sessions.delete(data.connectId);
|
|
869
803
|
this._verifiedPassphraseSessionsByConnectId.delete(data.connectId);
|
|
870
804
|
this._devices.delete(data.connectId);
|
|
@@ -884,32 +818,25 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
884
818
|
payload: { device }
|
|
885
819
|
});
|
|
886
820
|
};
|
|
887
|
-
// The one outlet for every connector-raised UI request (PIN, passphrase,
|
|
888
|
-
// button, THP pairing), so the operation is stamped here instead of at each
|
|
889
|
-
// connector call site.
|
|
890
821
|
this._onUiRequest = (data) => {
|
|
891
|
-
const operationId = this._activeOperationId();
|
|
892
|
-
const basePayload = data.payload && typeof data.payload === "object" ? data.payload : {};
|
|
893
|
-
const attribution = operationId === void 0 ? {} : { operationId };
|
|
894
822
|
if (data.type === _hwkadaptercore.UI_REQUEST.REQUEST_PASSPHRASE) {
|
|
895
|
-
const
|
|
823
|
+
const payload = data.payload && typeof data.payload === "object" ? data.payload : {};
|
|
824
|
+
const connectId = typeof payload.connectId === "string" ? payload.connectId : void 0;
|
|
896
825
|
const context = connectId ? this._passphraseRequestContextByConnectId.get(connectId) : void 0;
|
|
897
826
|
this._emitter.emit(
|
|
898
827
|
data.type,
|
|
899
828
|
{
|
|
900
829
|
...data,
|
|
901
830
|
payload: {
|
|
902
|
-
...
|
|
831
|
+
...payload,
|
|
903
832
|
..._optionalChain([context, 'optionalAccess', _13 => _13.passphraseState]) !== void 0 ? { passphraseState: context.passphraseState } : {},
|
|
904
|
-
..._optionalChain([context, 'optionalAccess', _14 => _14.useEmptyPassphrase]) !== void 0 ? { useEmptyPassphrase: context.useEmptyPassphrase } : {}
|
|
905
|
-
...attribution
|
|
833
|
+
..._optionalChain([context, 'optionalAccess', _14 => _14.useEmptyPassphrase]) !== void 0 ? { useEmptyPassphrase: context.useEmptyPassphrase } : {}
|
|
906
834
|
}
|
|
907
835
|
}
|
|
908
836
|
);
|
|
909
837
|
return;
|
|
910
838
|
}
|
|
911
|
-
|
|
912
|
-
this._emitter.emit(data.type, { ...data, payload });
|
|
839
|
+
this._emitter.emit(data.type, data);
|
|
913
840
|
};
|
|
914
841
|
this._onUiEvent = (data) => {
|
|
915
842
|
this._emitter.emit("ui-event", data);
|
|
@@ -921,11 +848,6 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
921
848
|
});
|
|
922
849
|
};
|
|
923
850
|
this._connector = connector;
|
|
924
|
-
for (const connection of _nullishCoalesce(_optionalChain([options, 'optionalAccess', _15 => _15.knownDeviceConnections]), () => ( []))) {
|
|
925
|
-
if (connection.deviceId) {
|
|
926
|
-
this._knownDeviceConnections.set(connection.deviceId, { ...connection });
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
851
|
this._jobQueue = new (0, _hwkadaptercore.DeviceJobQueue)();
|
|
930
852
|
this._registerConnectorEvents();
|
|
931
853
|
}
|
|
@@ -950,35 +872,29 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
950
872
|
const {
|
|
951
873
|
passphraseState,
|
|
952
874
|
autoInstallApp: _autoInstallApp,
|
|
953
|
-
operationId,
|
|
954
875
|
useEmptyPassphrase,
|
|
955
|
-
knownConnections,
|
|
956
|
-
extra,
|
|
957
|
-
allowDeviceSelection,
|
|
958
|
-
supportedTransports,
|
|
959
876
|
...rest
|
|
960
877
|
} = params;
|
|
961
878
|
return {
|
|
962
879
|
passphraseState: typeof passphraseState === "string" ? passphraseState : void 0,
|
|
963
880
|
useEmptyPassphrase: typeof useEmptyPassphrase === "boolean" ? useEmptyPassphrase : void 0,
|
|
964
|
-
operationId: typeof operationId === "string" ? operationId : void 0,
|
|
965
|
-
connectionContext: _hwkadaptercore.pickConnectionContext.call(void 0, {
|
|
966
|
-
knownConnections,
|
|
967
|
-
extra,
|
|
968
|
-
allowDeviceSelection,
|
|
969
|
-
supportedTransports
|
|
970
|
-
}),
|
|
971
881
|
rest
|
|
972
882
|
};
|
|
973
883
|
}
|
|
974
884
|
return { rest: _nullishCoalesce(params, () => ( {})) };
|
|
975
885
|
}
|
|
976
886
|
static _withAllNetworkRequestCommonParams(item, commonParams) {
|
|
977
|
-
const
|
|
887
|
+
const autoInstallApp = _optionalChain([commonParams, 'optionalAccess', _15 => _15.autoInstallApp]);
|
|
888
|
+
const passphraseState = _optionalChain([commonParams, 'optionalAccess', _16 => _16.passphraseState]);
|
|
889
|
+
const useEmptyPassphrase = _optionalChain([commonParams, 'optionalAccess', _17 => _17.useEmptyPassphrase]);
|
|
890
|
+
if (autoInstallApp === void 0 && passphraseState === void 0 && useEmptyPassphrase === void 0) {
|
|
891
|
+
return item;
|
|
892
|
+
}
|
|
978
893
|
return {
|
|
979
894
|
...item,
|
|
980
|
-
...
|
|
981
|
-
...
|
|
895
|
+
...autoInstallApp !== void 0 ? { autoInstallApp } : {},
|
|
896
|
+
...passphraseState !== void 0 ? { passphraseState } : {},
|
|
897
|
+
...useEmptyPassphrase !== void 0 ? { useEmptyPassphrase } : {}
|
|
982
898
|
};
|
|
983
899
|
}
|
|
984
900
|
static _normalizeLogKey(key) {
|
|
@@ -1034,8 +950,8 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1034
950
|
};
|
|
1035
951
|
}
|
|
1036
952
|
static _trezorFailureMessage(error) {
|
|
1037
|
-
const response = _optionalChain([error, 'optionalAccess',
|
|
1038
|
-
const message = _optionalChain([response, 'optionalAccess',
|
|
953
|
+
const response = _optionalChain([error, 'optionalAccess', _18 => _18.response]);
|
|
954
|
+
const message = _optionalChain([response, 'optionalAccess', _19 => _19.message]);
|
|
1039
955
|
if (!message || typeof message !== "object") return {};
|
|
1040
956
|
const failureMessage = message;
|
|
1041
957
|
return {
|
|
@@ -1044,7 +960,7 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1044
960
|
};
|
|
1045
961
|
}
|
|
1046
962
|
static _mapTrezorFailureCode(error) {
|
|
1047
|
-
const directCode = _optionalChain([error, 'optionalAccess',
|
|
963
|
+
const directCode = _optionalChain([error, 'optionalAccess', _20 => _20.code]);
|
|
1048
964
|
if (directCode === "Device_InitializeFailed") {
|
|
1049
965
|
return _hwkadaptercore.HardwareErrorCode.PinCancelled;
|
|
1050
966
|
}
|
|
@@ -1057,7 +973,7 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1057
973
|
if (directCode === "Failure_UnexpectedMessage") {
|
|
1058
974
|
return _hwkadaptercore.HardwareErrorCode.MethodNotSupported;
|
|
1059
975
|
}
|
|
1060
|
-
const message = _optionalChain([error, 'optionalAccess',
|
|
976
|
+
const message = _optionalChain([error, 'optionalAccess', _21 => _21.message]);
|
|
1061
977
|
if (typeof message === "string" && message.includes("Failed to execute 'transfer") && message.includes("on 'USBDevice'")) {
|
|
1062
978
|
return _hwkadaptercore.HardwareErrorCode.TransportError;
|
|
1063
979
|
}
|
|
@@ -1102,11 +1018,13 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1102
1018
|
* selected is gone (the device evicted it from its limited slot pool). The
|
|
1103
1019
|
* caller drops the stale cache entry and recreates from scratch.
|
|
1104
1020
|
*
|
|
1105
|
-
*
|
|
1106
|
-
*
|
|
1021
|
+
* NOTE: the exact eviction code still needs real-device confirmation — match
|
|
1022
|
+
* conservatively so a genuine error isn't mistaken for an evicted session
|
|
1023
|
+
* (which would silently re-prompt the passphrase).
|
|
1107
1024
|
*/
|
|
1108
1025
|
static _isStaleSessionError(code) {
|
|
1109
|
-
|
|
1026
|
+
if (typeof code !== "string") return false;
|
|
1027
|
+
return code === "ThpUnallocatedChannel" || /invalid.?session|unallocated.?session|session.?not.?found/i.test(code);
|
|
1110
1028
|
}
|
|
1111
1029
|
static _errorCode(error) {
|
|
1112
1030
|
return _nullishCoalesce(error.code, () => ( _TrezorAdapter._trezorFailureMessage(error).code));
|
|
@@ -1120,13 +1038,13 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1120
1038
|
return protocolError.name === "TrezorProtocolError" && protocolError.code === "Malformed protocol format" && protocolError.message === "Malformed protocol format";
|
|
1121
1039
|
}
|
|
1122
1040
|
/**
|
|
1123
|
-
* Race a promise against an abort signal.
|
|
1124
|
-
* be cancelled at the protocol level,
|
|
1125
|
-
*
|
|
1041
|
+
* Race a promise against an abort signal. Copied from LedgerAdapter:
|
|
1042
|
+
* IConnector.call() can't actually be cancelled at the protocol level, but
|
|
1043
|
+
* the caller gets the abort immediately and the underlying work completes
|
|
1044
|
+
* uselessly in the background.
|
|
1126
1045
|
*/
|
|
1127
1046
|
static _abortable(signal, promise) {
|
|
1128
1047
|
if (signal.aborted) {
|
|
1129
|
-
void promise.catch(() => void 0);
|
|
1130
1048
|
return Promise.reject(
|
|
1131
1049
|
_nullishCoalesce(signal.reason, () => ( new Error("Aborted")))
|
|
1132
1050
|
);
|
|
@@ -1148,37 +1066,17 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1148
1066
|
);
|
|
1149
1067
|
});
|
|
1150
1068
|
}
|
|
1151
|
-
async _connectSession(connectId, signal
|
|
1069
|
+
async _connectSession(connectId, signal) {
|
|
1152
1070
|
const connectOnce = async () => {
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
}
|
|
1156
|
-
this._assertConnectorIdle("connectDevice");
|
|
1157
|
-
const releaseOperation = this._retainConnectorOperation(`connect:${connectId}`);
|
|
1158
|
-
let connectPromise;
|
|
1159
|
-
try {
|
|
1160
|
-
connectPromise = transportType ? this._connector.connect(connectId, { transportType }) : this._connector.connect(connectId);
|
|
1161
|
-
} catch (error) {
|
|
1162
|
-
releaseOperation();
|
|
1163
|
-
throw error;
|
|
1164
|
-
}
|
|
1165
|
-
if (!signal) {
|
|
1166
|
-
try {
|
|
1167
|
-
return await connectPromise;
|
|
1168
|
-
} finally {
|
|
1169
|
-
releaseOperation();
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1071
|
+
const connectPromise = this._connector.connect(connectId);
|
|
1072
|
+
if (!signal) return connectPromise;
|
|
1172
1073
|
try {
|
|
1173
|
-
|
|
1174
|
-
releaseOperation();
|
|
1175
|
-
return session2;
|
|
1074
|
+
return await _TrezorAdapter._abortable(signal, connectPromise);
|
|
1176
1075
|
} catch (error) {
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
}
|
|
1076
|
+
void connectPromise.then(
|
|
1077
|
+
(orphan) => this._connector.disconnect(orphan.sessionId).catch(() => void 0),
|
|
1078
|
+
() => void 0
|
|
1079
|
+
);
|
|
1182
1080
|
throw error;
|
|
1183
1081
|
}
|
|
1184
1082
|
};
|
|
@@ -1186,7 +1084,7 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1186
1084
|
try {
|
|
1187
1085
|
session = await connectOnce();
|
|
1188
1086
|
} catch (error) {
|
|
1189
|
-
if (_optionalChain([signal, 'optionalAccess',
|
|
1087
|
+
if (_optionalChain([signal, 'optionalAccess', _22 => _22.aborted]) || !_TrezorAdapter._isRecoverableProtocolResidueError(error)) {
|
|
1190
1088
|
throw error;
|
|
1191
1089
|
}
|
|
1192
1090
|
debugLog("[TrezorAdapter] retrying connect after draining a stale THP frame", {
|
|
@@ -1194,13 +1092,8 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1194
1092
|
});
|
|
1195
1093
|
session = await connectOnce();
|
|
1196
1094
|
}
|
|
1197
|
-
if (
|
|
1198
|
-
|
|
1199
|
-
try {
|
|
1200
|
-
await this._connector.disconnect(session.sessionId).catch(() => void 0);
|
|
1201
|
-
} finally {
|
|
1202
|
-
releaseCleanup();
|
|
1203
|
-
}
|
|
1095
|
+
if (this._disconnectRequested.delete(connectId)) {
|
|
1096
|
+
await this._connector.disconnect(session.sessionId).catch(() => void 0);
|
|
1204
1097
|
throw Object.assign(new Error("Trezor connection aborted"), {
|
|
1205
1098
|
code: _hwkadaptercore.HardwareErrorCode.UserAborted
|
|
1206
1099
|
});
|
|
@@ -1216,9 +1109,14 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1216
1109
|
async init(_config) {
|
|
1217
1110
|
}
|
|
1218
1111
|
async dispose() {
|
|
1219
|
-
await this._resetStateAndDisconnectSessions();
|
|
1220
1112
|
this._unregisterConnectorEvents();
|
|
1113
|
+
this._uiRegistry.reset();
|
|
1114
|
+
this._jobQueue.clear();
|
|
1221
1115
|
this._connector.reset();
|
|
1116
|
+
this._devices.clear();
|
|
1117
|
+
this._sessions.clear();
|
|
1118
|
+
this._verifiedPassphraseSessionsByConnectId.clear();
|
|
1119
|
+
this._connectingPromises.clear();
|
|
1222
1120
|
this._emitter.removeAllListeners();
|
|
1223
1121
|
}
|
|
1224
1122
|
/**
|
|
@@ -1227,31 +1125,12 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1227
1125
|
* error flows. Aborts active jobs and releases UI waits.
|
|
1228
1126
|
*/
|
|
1229
1127
|
resetState() {
|
|
1230
|
-
void this._resetStateAndDisconnectSessions();
|
|
1231
|
-
}
|
|
1232
|
-
_resetStateAndDisconnectSessions() {
|
|
1233
|
-
if (this._resetPromise) return this._resetPromise;
|
|
1234
|
-
const sessionIds = new Set(this._sessions.values());
|
|
1235
|
-
this._stateGeneration += 1;
|
|
1236
|
-
this._operations.endAll("runtime-reset");
|
|
1237
1128
|
this._uiRegistry.reset();
|
|
1238
|
-
this._connector.uiResponse({ type: _hwkadaptercore.UI_RESPONSE.CANCEL });
|
|
1239
1129
|
this._jobQueue.clear();
|
|
1240
1130
|
this._devices.clear();
|
|
1241
1131
|
this._sessions.clear();
|
|
1242
1132
|
this._verifiedPassphraseSessionsByConnectId.clear();
|
|
1243
1133
|
this._connectingPromises.clear();
|
|
1244
|
-
const resetPromise = this._runConnectorTeardown(async () => {
|
|
1245
|
-
for (const sessionId of sessionIds) {
|
|
1246
|
-
await this._connector.disconnect(sessionId).catch(() => void 0);
|
|
1247
|
-
}
|
|
1248
|
-
});
|
|
1249
|
-
this._resetPromise = resetPromise;
|
|
1250
|
-
return resetPromise.finally(() => {
|
|
1251
|
-
if (this._resetPromise === resetPromise) {
|
|
1252
|
-
this._resetPromise = null;
|
|
1253
|
-
}
|
|
1254
|
-
});
|
|
1255
1134
|
}
|
|
1256
1135
|
getAvailableTransports() {
|
|
1257
1136
|
return this.activeTransport ? [this.activeTransport] : [];
|
|
@@ -1259,160 +1138,32 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1259
1138
|
async switchTransport(_type) {
|
|
1260
1139
|
}
|
|
1261
1140
|
async searchDevices(options) {
|
|
1262
|
-
await this._ensureDevicePermission(
|
|
1263
|
-
return this._searchDevices(options);
|
|
1264
|
-
}
|
|
1265
|
-
async _searchDevices(options, signal) {
|
|
1266
|
-
if (_optionalChain([options, 'optionalAccess', _27 => _27.transportType]) && !this._availableTransports().includes(options.transportType))
|
|
1267
|
-
return [];
|
|
1268
|
-
if (_optionalChain([options, 'optionalAccess', _28 => _28.resetSession])) {
|
|
1269
|
-
await this._resetStateAndDisconnectSessions();
|
|
1270
|
-
} else {
|
|
1271
|
-
await this._connectorTeardownTail;
|
|
1272
|
-
}
|
|
1273
|
-
if (_optionalChain([signal, 'optionalAccess', _29 => _29.aborted])) throw signal.reason;
|
|
1274
|
-
const stateGeneration = this._stateGeneration;
|
|
1141
|
+
await this._ensureDevicePermission();
|
|
1275
1142
|
const scanned = await this._connector.searchDevices(
|
|
1276
|
-
_optionalChain([options, 'optionalAccess',
|
|
1277
|
-
...options.waitForAllTransports ? { waitForAll: true } : {},
|
|
1278
|
-
...options.transportType ? { transportType: options.transportType } : {}
|
|
1279
|
-
} : void 0
|
|
1143
|
+
_optionalChain([options, 'optionalAccess', _23 => _23.waitForAllTransports]) ? { waitForAll: true } : void 0
|
|
1280
1144
|
);
|
|
1281
|
-
if (_optionalChain([signal, 'optionalAccess', _32 => _32.aborted])) throw signal.reason;
|
|
1282
|
-
if (stateGeneration !== this._stateGeneration) {
|
|
1283
|
-
throw _hwkadaptercore.createHwkError.call(void 0, {
|
|
1284
|
-
code: _hwkadaptercore.HardwareErrorCode.UserAborted,
|
|
1285
|
-
message: "Trezor discovery belongs to an ended operation"
|
|
1286
|
-
});
|
|
1287
|
-
}
|
|
1288
1145
|
const scannedIds = new Set(scanned.map((d) => d.connectId));
|
|
1289
1146
|
for (const connectId of [...this._devices.keys()]) {
|
|
1290
|
-
if (
|
|
1147
|
+
if (!scannedIds.has(connectId) && !this._sessions.has(connectId)) {
|
|
1291
1148
|
this._devices.delete(connectId);
|
|
1292
1149
|
}
|
|
1293
1150
|
}
|
|
1294
1151
|
for (const device of scanned) {
|
|
1295
1152
|
const info = this._connectorDeviceToDeviceInfo(device);
|
|
1296
|
-
|
|
1297
|
-
}
|
|
1298
|
-
return Array.from(this._devices.values()).filter(
|
|
1299
|
-
(device) => !_optionalChain([options, 'optionalAccess', _38 => _38.transportType]) || device.connectionType === options.transportType
|
|
1300
|
-
);
|
|
1301
|
-
}
|
|
1302
|
-
async searchDeviceTargets(options) {
|
|
1303
|
-
const devices = await this.searchDevices(options);
|
|
1304
|
-
return devices.map((device) => _hwkadaptercore.toPhysicalDeviceSearchTarget.call(void 0, "trezor", device));
|
|
1305
|
-
}
|
|
1306
|
-
async bindBleDevice(params) {
|
|
1307
|
-
if (_optionalChain([params, 'access', _39 => _39.identity, 'optionalAccess', _40 => _40.vendor]) !== "trezor" || !params.identity.value) {
|
|
1308
|
-
return _hwkadaptercore.failure.call(void 0, _hwkadaptercore.HardwareErrorCode.InvalidParams, "Trezor device identity is required");
|
|
1309
|
-
}
|
|
1310
|
-
const { value: deviceId } = params.identity;
|
|
1311
|
-
try {
|
|
1312
|
-
return await this._jobQueue.enqueue(
|
|
1313
|
-
deviceId,
|
|
1314
|
-
async (signal) => {
|
|
1315
|
-
const selected = await this._selectBleDeviceForBinding(
|
|
1316
|
-
deviceId,
|
|
1317
|
-
signal,
|
|
1318
|
-
{ extra: params.extra },
|
|
1319
|
-
"manual-rebind"
|
|
1320
|
-
);
|
|
1321
|
-
try {
|
|
1322
|
-
const persisted = await this._emitVerifiedBinding(
|
|
1323
|
-
deviceId,
|
|
1324
|
-
selected.connectId,
|
|
1325
|
-
selected.selectionRequestId,
|
|
1326
|
-
{ extra: params.extra },
|
|
1327
|
-
signal
|
|
1328
|
-
);
|
|
1329
|
-
if (!persisted) {
|
|
1330
|
-
throw _hwkadaptercore.createHwkError.call(void 0, {
|
|
1331
|
-
code: _hwkadaptercore.HardwareErrorCode.UnknownError,
|
|
1332
|
-
message: "Bluetooth binding could not be saved",
|
|
1333
|
-
origin: "host"
|
|
1334
|
-
});
|
|
1335
|
-
}
|
|
1336
|
-
this._rememberVerifiedConnection(deviceId, selected.connectId);
|
|
1337
|
-
return _hwkadaptercore.success.call(void 0, selected.connectId);
|
|
1338
|
-
} catch (error) {
|
|
1339
|
-
await this._releaseProvisionalConnection(selected.connectId, signal);
|
|
1340
|
-
throw error;
|
|
1341
|
-
}
|
|
1342
|
-
},
|
|
1343
|
-
{
|
|
1344
|
-
label: "bindBleDevice",
|
|
1345
|
-
rejectIfBusy: true,
|
|
1346
|
-
busyError: _TrezorAdapter._createDeviceBusyError("bindBleDevice")
|
|
1347
|
-
}
|
|
1348
|
-
);
|
|
1349
|
-
} catch (error) {
|
|
1350
|
-
return this._errorToFailure(error);
|
|
1153
|
+
this._devices.set(info.connectId, info);
|
|
1351
1154
|
}
|
|
1155
|
+
return Array.from(this._devices.values());
|
|
1352
1156
|
}
|
|
1353
|
-
async connectDevice(
|
|
1354
|
-
const scope = this._jobQueue.createCancelScope(searchTargetId);
|
|
1157
|
+
async connectDevice(connectId) {
|
|
1355
1158
|
try {
|
|
1356
|
-
await
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
searchTargetId,
|
|
1360
|
-
void 0,
|
|
1361
|
-
_optionalChain([this, 'access', _41 => _41._devices, 'access', _42 => _42.get, 'call', _43 => _43(searchTargetId), 'optionalAccess', _44 => _44.connectionType])
|
|
1362
|
-
)
|
|
1363
|
-
);
|
|
1364
|
-
await this._ensureSession(searchTargetId, scope.signal);
|
|
1365
|
-
if (scope.signal.aborted) throw scope.signal.reason;
|
|
1366
|
-
const device = this._devices.get(searchTargetId);
|
|
1367
|
-
if (!device) {
|
|
1368
|
-
return _hwkadaptercore.failure.call(void 0, _hwkadaptercore.HardwareErrorCode.DeviceNotFound, "Trezor device not found after connect");
|
|
1369
|
-
}
|
|
1370
|
-
this._operations.endByConnectionKey(searchTargetId, "explicit");
|
|
1371
|
-
const operation = this._operations.create({
|
|
1372
|
-
searchTargetId,
|
|
1373
|
-
connectId: searchTargetId,
|
|
1374
|
-
device,
|
|
1375
|
-
connectionType: device.connectionType,
|
|
1376
|
-
connectionKeys: [_nullishCoalesce(this._sessions.get(searchTargetId), () => ( ""))]
|
|
1377
|
-
});
|
|
1378
|
-
return _hwkadaptercore.success.call(void 0, operation.operationId);
|
|
1159
|
+
await this._ensureDevicePermission(connectId);
|
|
1160
|
+
await this._ensureSession(connectId);
|
|
1161
|
+
return _hwkadaptercore.success.call(void 0, connectId);
|
|
1379
1162
|
} catch (error) {
|
|
1380
|
-
if (scope.signal.aborted) {
|
|
1381
|
-
await this._waitForConnectorOperationsToDrain();
|
|
1382
|
-
return _hwkadaptercore.failure.call(void 0, _hwkadaptercore.HardwareErrorCode.UserAborted, "Trezor connection aborted");
|
|
1383
|
-
}
|
|
1384
1163
|
return this._errorToFailure(error);
|
|
1385
|
-
} finally {
|
|
1386
|
-
scope.release();
|
|
1387
1164
|
}
|
|
1388
1165
|
}
|
|
1389
|
-
async
|
|
1390
|
-
const operation = this._operations.findActive(operationId);
|
|
1391
|
-
if (operation) this._cancelOperationWork(operation);
|
|
1392
|
-
const endedOperation = this._operations.release(operationId);
|
|
1393
|
-
if (!endedOperation) return;
|
|
1394
|
-
await this._releaseOperationConnection(endedOperation);
|
|
1395
|
-
}
|
|
1396
|
-
/**
|
|
1397
|
-
* Ends a released operation's calls and prompts before teardown, which otherwise waits on a call
|
|
1398
|
-
* that waits on a prompt nobody will answer. Device I/O already on the wire still drains.
|
|
1399
|
-
*/
|
|
1400
|
-
_cancelOperationWork(operation) {
|
|
1401
|
-
const { operationId } = operation;
|
|
1402
|
-
const reason = _hwkadaptercore.createHwkError.call(void 0, {
|
|
1403
|
-
code: _hwkadaptercore.HardwareErrorCode.OperationEnded,
|
|
1404
|
-
message: "Trezor operation was released",
|
|
1405
|
-
params: { operationId, reason: "explicit" }
|
|
1406
|
-
});
|
|
1407
|
-
const queueKey = trezorQueueKey({ operationId });
|
|
1408
|
-
const ownsRunningCall = _optionalChain([this, 'access', _45 => _45._jobQueue, 'access', _46 => _46.getActiveJob, 'call', _47 => _47(), 'optionalAccess', _48 => _48.deviceId]) === queueKey;
|
|
1409
|
-
this._jobQueue.cancelActiveAndPending(queueKey, reason);
|
|
1410
|
-
if (!ownsRunningCall) return;
|
|
1411
|
-
this._uiRegistry.cancel(void 0, void 0, operationId);
|
|
1412
|
-
this._connector.uiResponse({ type: _hwkadaptercore.UI_RESPONSE.CANCEL });
|
|
1413
|
-
}
|
|
1414
|
-
async _releaseOperationConnection(operation) {
|
|
1415
|
-
const { connectId } = operation;
|
|
1166
|
+
async disconnectDevice(connectId) {
|
|
1416
1167
|
const connecting = this._connectingPromises.has(connectId);
|
|
1417
1168
|
this._connectingPromises.delete(connectId);
|
|
1418
1169
|
const sessionId = this._sessions.get(connectId);
|
|
@@ -1420,131 +1171,90 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1420
1171
|
if (connecting) this._disconnectRequested.add(connectId);
|
|
1421
1172
|
return;
|
|
1422
1173
|
}
|
|
1423
|
-
|
|
1174
|
+
this._sessions.delete(connectId);
|
|
1175
|
+
this._verifiedPassphraseSessionsByConnectId.delete(connectId);
|
|
1176
|
+
await this._connector.disconnect(sessionId);
|
|
1424
1177
|
}
|
|
1425
|
-
async getDeviceInfo(
|
|
1426
|
-
let connectId;
|
|
1427
|
-
try {
|
|
1428
|
-
connectId = _hwkadaptercore.isHardwareOperationId.call(void 0, connectIdOrOperationId) ? this._operations.resolve(connectIdOrOperationId).connectId : connectIdOrOperationId;
|
|
1429
|
-
} catch (error) {
|
|
1430
|
-
return this._errorToFailure(error);
|
|
1431
|
-
}
|
|
1178
|
+
async getDeviceInfo(connectId, deviceId) {
|
|
1432
1179
|
const device = _nullishCoalesce(this._devices.get(connectId), () => ( Array.from(this._devices.values()).find((item) => item.deviceId === deviceId)));
|
|
1433
1180
|
if (!device) return _hwkadaptercore.failure.call(void 0, _hwkadaptercore.HardwareErrorCode.DeviceNotFound, "Trezor device not found");
|
|
1434
1181
|
return _hwkadaptercore.success.call(void 0, device);
|
|
1435
1182
|
}
|
|
1183
|
+
getSupportedChains() {
|
|
1184
|
+
return ["btc", "evm", "sol", "tron"];
|
|
1185
|
+
}
|
|
1436
1186
|
async allNetworkGetAddress(connectId, deviceId, params) {
|
|
1437
|
-
const target = _hwkadaptercore.resolveHardwareOperationTarget.call(void 0, connectId, params.operationId, "trezor");
|
|
1438
|
-
if (!target.success) return target;
|
|
1439
|
-
let effectiveTargetId = _nullishCoalesce(target.payload.targetId, () => ( ""));
|
|
1440
|
-
let releaseOperationRetention;
|
|
1441
|
-
try {
|
|
1442
|
-
releaseOperationRetention = target.payload.operationId ? this._operations.retain(target.payload.operationId) : void 0;
|
|
1443
|
-
} catch (error) {
|
|
1444
|
-
return this._errorToFailure(error);
|
|
1445
|
-
}
|
|
1446
|
-
const cancelScope = this._jobQueue.createCancelScope(
|
|
1447
|
-
trezorQueueKey({ operationId: target.payload.operationId, connectId: effectiveTargetId })
|
|
1448
|
-
);
|
|
1449
1187
|
let liveDeviceId = "";
|
|
1450
|
-
const bundleContext = {};
|
|
1451
1188
|
const topLevelFailureIndexes = /* @__PURE__ */ new Set();
|
|
1452
1189
|
const isSingleNetworkBundle = params.bundle.every(
|
|
1453
|
-
(item) => item.network === _optionalChain([params, 'access',
|
|
1190
|
+
(item) => item.network === _optionalChain([params, 'access', _24 => _24.bundle, 'access', _25 => _25[0], 'optionalAccess', _26 => _26.network])
|
|
1454
1191
|
);
|
|
1455
|
-
const getLiveDeviceId = async (
|
|
1192
|
+
const getLiveDeviceId = async () => {
|
|
1456
1193
|
if (liveDeviceId) return _hwkadaptercore.success.call(void 0, liveDeviceId);
|
|
1457
|
-
const deviceIdResponse = await this._getTrezorDeviceId(
|
|
1458
|
-
effectiveTargetId,
|
|
1459
|
-
expectedDeviceId || deviceId,
|
|
1460
|
-
params,
|
|
1461
|
-
bundleContext
|
|
1462
|
-
);
|
|
1194
|
+
const deviceIdResponse = await this._getTrezorDeviceId(connectId);
|
|
1463
1195
|
if (deviceIdResponse.success) {
|
|
1464
1196
|
liveDeviceId = deviceIdResponse.payload;
|
|
1465
|
-
if (!target.payload.operationId) {
|
|
1466
|
-
effectiveTargetId = _nullishCoalesce(_optionalChain([bundleContext, 'access', _52 => _52.connection, 'optionalAccess', _53 => _53.connectId]), () => ( effectiveTargetId));
|
|
1467
|
-
}
|
|
1468
1197
|
}
|
|
1469
1198
|
return deviceIdResponse;
|
|
1470
1199
|
};
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1200
|
+
return _hwkadaptercore.runAllNetworkGetAddress.call(void 0, {
|
|
1201
|
+
connectId,
|
|
1202
|
+
deviceId,
|
|
1203
|
+
params,
|
|
1204
|
+
normalizeItem: _TrezorAdapter._normalizeAllNetworkItem,
|
|
1205
|
+
callItem: async ({ method, item, index }) => {
|
|
1206
|
+
const expectedDeviceId = _nullishCoalesce(_TrezorAdapter._getItemDeviceId(item), () => ( deviceId));
|
|
1207
|
+
if (expectedDeviceId) {
|
|
1208
|
+
const fingerprint = await getLiveDeviceId();
|
|
1209
|
+
if (!fingerprint.success) {
|
|
1479
1210
|
topLevelFailureIndexes.add(index);
|
|
1480
|
-
return
|
|
1211
|
+
return fingerprint;
|
|
1481
1212
|
}
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
if (expectedDeviceId !== fingerprint.payload) {
|
|
1490
|
-
topLevelFailureIndexes.add(index);
|
|
1491
|
-
return _hwkadaptercore.failure.call(void 0,
|
|
1492
|
-
_hwkadaptercore.HardwareErrorCode.DeviceMismatch,
|
|
1493
|
-
`Wrong device: expected ${expectedDeviceId}, got ${fingerprint.payload}`,
|
|
1494
|
-
{ expected: expectedDeviceId, actual: fingerprint.payload }
|
|
1495
|
-
);
|
|
1496
|
-
}
|
|
1213
|
+
if (expectedDeviceId !== fingerprint.payload) {
|
|
1214
|
+
topLevelFailureIndexes.add(index);
|
|
1215
|
+
return _hwkadaptercore.failure.call(void 0,
|
|
1216
|
+
_hwkadaptercore.HardwareErrorCode.DeviceMismatch,
|
|
1217
|
+
`Wrong device: expected ${expectedDeviceId}, got ${fingerprint.payload}`,
|
|
1218
|
+
{ expected: expectedDeviceId, actual: fingerprint.payload }
|
|
1219
|
+
);
|
|
1497
1220
|
}
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
}
|
|
1508
|
-
const fingerprint = await getLiveDeviceId(deviceId);
|
|
1509
|
-
if (!fingerprint.success) {
|
|
1510
|
-
return { ...item, success: false, payload: fingerprint.payload };
|
|
1511
|
-
}
|
|
1221
|
+
}
|
|
1222
|
+
const callItem = _TrezorAdapter._withAllNetworkRequestCommonParams(item, params);
|
|
1223
|
+
return this._callAllNetworkMethod(connectId, method, callItem);
|
|
1224
|
+
},
|
|
1225
|
+
attachIdentity: async ({ item, chain, payload }) => {
|
|
1226
|
+
if (!liveDeviceId) {
|
|
1227
|
+
const fingerprint = await getLiveDeviceId();
|
|
1228
|
+
if (!fingerprint.success) {
|
|
1229
|
+
return { ...item, success: false, payload: fingerprint.payload };
|
|
1512
1230
|
}
|
|
1513
|
-
return {
|
|
1514
|
-
...item,
|
|
1515
|
-
success: true,
|
|
1516
|
-
payload: {
|
|
1517
|
-
...payload,
|
|
1518
|
-
deviceIdentity: {
|
|
1519
|
-
vendor: "trezor",
|
|
1520
|
-
type: "deviceId",
|
|
1521
|
-
value: liveDeviceId
|
|
1522
|
-
},
|
|
1523
|
-
chainFingerprint: liveDeviceId,
|
|
1524
|
-
chainFingerprintChain: chain
|
|
1525
|
-
}
|
|
1526
|
-
};
|
|
1527
|
-
},
|
|
1528
|
-
// One named boolean per abort reason.
|
|
1529
|
-
shouldAbortBundle: (response, { index }) => {
|
|
1530
|
-
const isSessionLevelFailure = topLevelFailureIndexes.has(index);
|
|
1531
|
-
const isWholeChainForbidden = isSingleNetworkBundle && _optionalChain([response, 'access', _54 => _54.payload, 'optionalAccess', _55 => _55.code]) === _hwkadaptercore.HardwareErrorCode.DevicePathForbidden;
|
|
1532
|
-
const { code } = _nullishCoalesce(response.payload, () => ( {}));
|
|
1533
|
-
return isSessionLevelFailure || isWholeChainForbidden || _hwkadaptercore.isWalletSafetyFailure.call(void 0, code) || _hwkadaptercore.isUserRefusal.call(void 0, code) || _hwkadaptercore.isConnectionLost.call(void 0, code);
|
|
1534
1231
|
}
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1232
|
+
return {
|
|
1233
|
+
...item,
|
|
1234
|
+
success: true,
|
|
1235
|
+
payload: {
|
|
1236
|
+
...payload,
|
|
1237
|
+
deviceIdentity: {
|
|
1238
|
+
vendor: "trezor",
|
|
1239
|
+
type: "deviceId",
|
|
1240
|
+
value: liveDeviceId
|
|
1241
|
+
},
|
|
1242
|
+
chainFingerprint: liveDeviceId,
|
|
1243
|
+
chainFingerprintChain: chain
|
|
1244
|
+
}
|
|
1245
|
+
};
|
|
1246
|
+
},
|
|
1247
|
+
// One named boolean per abort reason.
|
|
1248
|
+
shouldAbortBundle: (response, { index }) => {
|
|
1249
|
+
const isSessionLevelFailure = topLevelFailureIndexes.has(index);
|
|
1250
|
+
const isWholeChainForbidden = isSingleNetworkBundle && _optionalChain([response, 'access', _27 => _27.payload, 'optionalAccess', _28 => _28.code]) === _hwkadaptercore.HardwareErrorCode.DevicePathForbidden;
|
|
1251
|
+
const isPassphrasePolicyFailure = _optionalChain([response, 'access', _29 => _29.payload, 'optionalAccess', _30 => _30.code]) === _hwkadaptercore.HardwareErrorCode.PassphraseAlwaysOnDevice;
|
|
1252
|
+
return isSessionLevelFailure || isWholeChainForbidden || isPassphrasePolicyFailure;
|
|
1253
|
+
}
|
|
1254
|
+
});
|
|
1540
1255
|
}
|
|
1541
|
-
getFeatures(connectId
|
|
1542
|
-
return this._callDeviceManagerMethod(
|
|
1543
|
-
"getFeatures",
|
|
1544
|
-
connectId,
|
|
1545
|
-
{},
|
|
1546
|
-
operationContext
|
|
1547
|
-
);
|
|
1256
|
+
getFeatures(connectId) {
|
|
1257
|
+
return this._callDeviceManagerMethod("getFeatures", connectId, {});
|
|
1548
1258
|
}
|
|
1549
1259
|
/**
|
|
1550
1260
|
* Device authenticity attestation. Sends a host-generated challenge, has the
|
|
@@ -1579,7 +1289,7 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1579
1289
|
if (!internalModel) {
|
|
1580
1290
|
return _hwkadaptercore.failure.call(void 0, _hwkadaptercore.HardwareErrorCode.UnknownError, "Device internal_model unavailable");
|
|
1581
1291
|
}
|
|
1582
|
-
const challengeHex = _nullishCoalesce(_optionalChain([params, 'access',
|
|
1292
|
+
const challengeHex = _nullishCoalesce(_optionalChain([params, 'access', _31 => _31.challenge, 'optionalAccess', _32 => _32.toLowerCase, 'call', _33 => _33()]), () => ( Buffer.from(_utils.randomBytes.call(void 0, 32)).toString("hex")));
|
|
1583
1293
|
const challenge = Buffer.from(challengeHex, "hex");
|
|
1584
1294
|
const proofRes = await this._callDeviceManagerMethod(
|
|
1585
1295
|
"authenticateDevice",
|
|
@@ -1604,65 +1314,28 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1604
1314
|
}
|
|
1605
1315
|
});
|
|
1606
1316
|
}
|
|
1607
|
-
deviceSettings(connectId, params
|
|
1317
|
+
deviceSettings(connectId, params) {
|
|
1608
1318
|
return this._callDeviceManagerMethod(
|
|
1609
1319
|
"deviceSettings",
|
|
1610
1320
|
connectId,
|
|
1611
|
-
params
|
|
1612
|
-
operationContext
|
|
1321
|
+
params
|
|
1613
1322
|
);
|
|
1614
1323
|
}
|
|
1615
|
-
setBrightness(connectId, params = {}
|
|
1324
|
+
setBrightness(connectId, params = {}) {
|
|
1616
1325
|
return this._callDeviceManagerMethod(
|
|
1617
1326
|
"setBrightness",
|
|
1618
1327
|
connectId,
|
|
1619
|
-
params
|
|
1620
|
-
operationContext
|
|
1328
|
+
params
|
|
1621
1329
|
);
|
|
1622
1330
|
}
|
|
1623
|
-
changePin(connectId, params = {}
|
|
1624
|
-
return this._callDeviceManagerMethod(
|
|
1625
|
-
"changePin",
|
|
1626
|
-
connectId,
|
|
1627
|
-
params,
|
|
1628
|
-
operationContext
|
|
1629
|
-
);
|
|
1331
|
+
changePin(connectId, params = {}) {
|
|
1332
|
+
return this._callDeviceManagerMethod("changePin", connectId, params);
|
|
1630
1333
|
}
|
|
1631
|
-
wipeDevice(connectId
|
|
1632
|
-
return this._callDeviceManagerMethod(
|
|
1633
|
-
"wipeDevice",
|
|
1634
|
-
connectId,
|
|
1635
|
-
{},
|
|
1636
|
-
operationContext
|
|
1637
|
-
);
|
|
1334
|
+
wipeDevice(connectId) {
|
|
1335
|
+
return this._callDeviceManagerMethod("wipeDevice", connectId, {});
|
|
1638
1336
|
}
|
|
1639
|
-
async _getTrezorDeviceId(connectId
|
|
1640
|
-
const
|
|
1641
|
-
const features = bundleContext || hasConnectionContext ? await this._callMethod(
|
|
1642
|
-
"getFeatures",
|
|
1643
|
-
connectId,
|
|
1644
|
-
hasConnectionContext || !connectId ? expectedDeviceId : void 0,
|
|
1645
|
-
hasConnectionContext ? {
|
|
1646
|
-
operationId: commonParams.operationId,
|
|
1647
|
-
knownConnections: commonParams.knownConnections,
|
|
1648
|
-
extra: commonParams.extra,
|
|
1649
|
-
allowDeviceSelection: commonParams.allowDeviceSelection,
|
|
1650
|
-
supportedTransports: commonParams.supportedTransports,
|
|
1651
|
-
passphraseState: commonParams.passphraseState,
|
|
1652
|
-
useEmptyPassphrase: commonParams.useEmptyPassphrase
|
|
1653
|
-
} : {},
|
|
1654
|
-
false,
|
|
1655
|
-
bundleContext
|
|
1656
|
-
) : await this.getFeatures(
|
|
1657
|
-
connectId,
|
|
1658
|
-
!connectId && expectedDeviceId ? {
|
|
1659
|
-
expectedDeviceIdentity: {
|
|
1660
|
-
vendor: "trezor",
|
|
1661
|
-
type: "deviceId",
|
|
1662
|
-
value: expectedDeviceId
|
|
1663
|
-
}
|
|
1664
|
-
} : void 0
|
|
1665
|
-
);
|
|
1337
|
+
async _getTrezorDeviceId(connectId) {
|
|
1338
|
+
const features = await this.getFeatures(connectId);
|
|
1666
1339
|
if (!features.success) return features;
|
|
1667
1340
|
const liveDeviceId = features.payload.device_id;
|
|
1668
1341
|
if (typeof liveDeviceId !== "string" || liveDeviceId.length === 0) {
|
|
@@ -1671,64 +1344,23 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1671
1344
|
return _hwkadaptercore.success.call(void 0, liveDeviceId);
|
|
1672
1345
|
}
|
|
1673
1346
|
cancel(connectId) {
|
|
1674
|
-
if (_hwkadaptercore.isHardwareOperationId.call(void 0, connectId)) {
|
|
1675
|
-
try {
|
|
1676
|
-
this._operations.resolve(connectId);
|
|
1677
|
-
} catch (e5) {
|
|
1678
|
-
return;
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
1347
|
const userAbortReason = Object.assign(new Error("User aborted operation"), {
|
|
1682
1348
|
code: _hwkadaptercore.HardwareErrorCode.UserAborted
|
|
1683
1349
|
});
|
|
1684
|
-
const activeJobId = _optionalChain([this, 'access', _62 => _62._jobQueue, 'access', _63 => _63.getActiveJob, 'call', _64 => _64(), 'optionalAccess', _65 => _65.deviceId]);
|
|
1685
|
-
const targetId = _nullishCoalesce(connectId, () => ( activeJobId));
|
|
1686
|
-
if (targetId) {
|
|
1687
|
-
let resolvedConnectId = targetId;
|
|
1688
|
-
let operationId;
|
|
1689
|
-
if (_hwkadaptercore.isHardwareOperationId.call(void 0, targetId)) {
|
|
1690
|
-
try {
|
|
1691
|
-
operationId = targetId;
|
|
1692
|
-
resolvedConnectId = this._operations.resolve(targetId).connectId;
|
|
1693
|
-
} catch (e6) {
|
|
1694
|
-
resolvedConnectId = "";
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
const interactionForPhysicalId = !operationId && connectId ? this._operations.findActiveByConnectionKey(connectId) : void 0;
|
|
1698
|
-
const pendingOperationId = _nullishCoalesce(operationId, () => ( _optionalChain([interactionForPhysicalId, 'optionalAccess', _66 => _66.operationId])));
|
|
1699
|
-
if (!connectId) {
|
|
1700
|
-
this._uiRegistry.cancel();
|
|
1701
|
-
} else if (pendingOperationId) {
|
|
1702
|
-
this._uiRegistry.cancel(void 0, void 0, pendingOperationId);
|
|
1703
|
-
}
|
|
1704
|
-
const queueKeys = /* @__PURE__ */ new Set([trezorQueueKey({ connectId: targetId })]);
|
|
1705
|
-
if (pendingOperationId) queueKeys.add(trezorQueueKey({ operationId: pendingOperationId }));
|
|
1706
|
-
const ownsConnectorInteraction = activeJobId !== void 0 ? queueKeys.has(activeJobId) || pendingOperationId !== void 0 && this._activeOperationId() === pendingOperationId : this._connectingPromises.size === 1 && this._connectingPromises.has(resolvedConnectId);
|
|
1707
|
-
if (connectId === void 0 || ownsConnectorInteraction) {
|
|
1708
|
-
this._connector.uiResponse({ type: _hwkadaptercore.UI_RESPONSE.CANCEL });
|
|
1709
|
-
}
|
|
1710
|
-
for (const key of queueKeys) {
|
|
1711
|
-
this._jobQueue.cancelActiveAndPending(key, userAbortReason);
|
|
1712
|
-
}
|
|
1713
|
-
if (resolvedConnectId) {
|
|
1714
|
-
void this._connector.cancel(_nullishCoalesce(this._sessions.get(resolvedConnectId), () => ( resolvedConnectId)));
|
|
1715
|
-
}
|
|
1716
|
-
return;
|
|
1717
|
-
}
|
|
1718
1350
|
this._uiRegistry.cancel();
|
|
1719
1351
|
this._connector.uiResponse({ type: _hwkadaptercore.UI_RESPONSE.CANCEL });
|
|
1720
|
-
|
|
1352
|
+
if (connectId) {
|
|
1353
|
+
this._jobQueue.forceCancelActive(connectId, userAbortReason);
|
|
1354
|
+
void this._connector.cancel(_nullishCoalesce(this._sessions.get(connectId), () => ( connectId)));
|
|
1355
|
+
return;
|
|
1356
|
+
}
|
|
1357
|
+
for (const cid of this._sessions.keys()) {
|
|
1358
|
+
this._jobQueue.forceCancelActive(cid, userAbortReason);
|
|
1359
|
+
}
|
|
1721
1360
|
for (const sessionId of this._sessions.values()) {
|
|
1722
1361
|
void this._connector.cancel(sessionId);
|
|
1723
1362
|
}
|
|
1724
1363
|
}
|
|
1725
|
-
/**
|
|
1726
|
-
* Operation owning the running job: its queue key when pinned, else the live
|
|
1727
|
-
* operation of its connectId, so a mid-call UI request can name it.
|
|
1728
|
-
*/
|
|
1729
|
-
_activeOperationId() {
|
|
1730
|
-
return this._operations.findOperationIdByJobKey(_optionalChain([this, 'access', _67 => _67._jobQueue, 'access', _68 => _68.getActiveJob, 'call', _69 => _69(), 'optionalAccess', _70 => _70.deviceId]));
|
|
1731
|
-
}
|
|
1732
1364
|
/**
|
|
1733
1365
|
* Routes to BOTH the adapter's local UI registry (preemption decisions,
|
|
1734
1366
|
* future SELECT_DEVICE / DEVICE_PERMISSION) AND the connector's registry
|
|
@@ -1737,7 +1369,6 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1737
1369
|
*/
|
|
1738
1370
|
uiResponse(response) {
|
|
1739
1371
|
this._uiRegistry.resolve(response.type, response.payload);
|
|
1740
|
-
if (response.type === _hwkadaptercore.UI_RESPONSE.RECEIVE_SELECT_DEVICE) return;
|
|
1741
1372
|
this._connector.uiResponse(response);
|
|
1742
1373
|
}
|
|
1743
1374
|
/**
|
|
@@ -1749,8 +1380,8 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1749
1380
|
* Unlike Ledger (which hashes a per-chain address), it is chain-global, so
|
|
1750
1381
|
* `chain` is accepted for API parity but ignored.
|
|
1751
1382
|
*/
|
|
1752
|
-
async getChainFingerprint(connectId,
|
|
1753
|
-
return this._getTrezorDeviceId(connectId
|
|
1383
|
+
async getChainFingerprint(connectId, _deviceId, _chain) {
|
|
1384
|
+
return this._getTrezorDeviceId(connectId);
|
|
1754
1385
|
}
|
|
1755
1386
|
/**
|
|
1756
1387
|
* Resolve the active passphrase wallet identity (`passphraseState`).
|
|
@@ -1760,87 +1391,17 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1760
1391
|
* can't interleave with a chain call on the same device (which would desync
|
|
1761
1392
|
* the THP session selection).
|
|
1762
1393
|
*/
|
|
1763
|
-
getPassphraseState(connectId, passphraseState
|
|
1764
|
-
const expectedIdentity = _optionalChain([operationContext, 'optionalAccess', _71 => _71.expectedDeviceIdentity]);
|
|
1765
|
-
if (expectedIdentity && (expectedIdentity.vendor !== "trezor" || expectedIdentity.type !== "deviceId")) {
|
|
1766
|
-
return Promise.resolve(
|
|
1767
|
-
_hwkadaptercore.failure.call(void 0, _hwkadaptercore.HardwareErrorCode.InvalidParams, "Trezor device identity is required")
|
|
1768
|
-
);
|
|
1769
|
-
}
|
|
1770
|
-
const target = _hwkadaptercore.resolveHardwareOperationTarget.call(void 0,
|
|
1771
|
-
connectId,
|
|
1772
|
-
_optionalChain([operationContext, 'optionalAccess', _72 => _72.operationId]),
|
|
1773
|
-
"trezor"
|
|
1774
|
-
);
|
|
1775
|
-
if (!target.success) return Promise.resolve(target);
|
|
1776
|
-
const { operationId } = target.payload;
|
|
1777
|
-
let resolvedConnectId = _nullishCoalesce(target.payload.targetId, () => ( ""));
|
|
1778
|
-
let releaseOperationRetention;
|
|
1779
|
-
if (operationId) {
|
|
1780
|
-
try {
|
|
1781
|
-
resolvedConnectId = this._operations.resolve(operationId).connectId;
|
|
1782
|
-
releaseOperationRetention = this._operations.retain(operationId);
|
|
1783
|
-
} catch (error) {
|
|
1784
|
-
return Promise.resolve(this._errorToFailure(error));
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1394
|
+
getPassphraseState(connectId, passphraseState) {
|
|
1787
1395
|
return this._jobQueue.enqueue(
|
|
1788
|
-
|
|
1396
|
+
connectId,
|
|
1789
1397
|
async (signal) => {
|
|
1790
|
-
|
|
1791
|
-
|
|
1398
|
+
const restorePassphraseRequestContext = this._setPassphraseRequestContext(connectId, {
|
|
1399
|
+
passphraseState
|
|
1400
|
+
});
|
|
1792
1401
|
try {
|
|
1793
|
-
|
|
1794
|
-
const resolved = await this._resolveExpectedDeviceConnectId(
|
|
1795
|
-
expectedIdentity.value,
|
|
1796
|
-
signal,
|
|
1797
|
-
operationContext
|
|
1798
|
-
);
|
|
1799
|
-
resolvedConnectId = resolved.connectId;
|
|
1800
|
-
selectionRequestId = resolved.selectionRequestId;
|
|
1801
|
-
}
|
|
1802
|
-
if (_optionalChain([expectedIdentity, 'optionalAccess', _75 => _75.value])) {
|
|
1803
|
-
if (!operationId) await this._ensureSession(resolvedConnectId, signal);
|
|
1804
|
-
if (_optionalChain([this, 'access', _76 => _76._devices, 'access', _77 => _77.get, 'call', _78 => _78(resolvedConnectId), 'optionalAccess', _79 => _79.deviceId]) !== expectedIdentity.value) {
|
|
1805
|
-
return _hwkadaptercore.failure.call(void 0,
|
|
1806
|
-
_hwkadaptercore.HardwareErrorCode.DeviceMismatch,
|
|
1807
|
-
"Trezor device identity does not match"
|
|
1808
|
-
);
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
const restorePassphraseRequestContext = this._setPassphraseRequestContext(
|
|
1812
|
-
resolvedConnectId,
|
|
1813
|
-
{
|
|
1814
|
-
passphraseState
|
|
1815
|
-
}
|
|
1816
|
-
);
|
|
1817
|
-
try {
|
|
1818
|
-
const result = await this._resolvePassphraseState(
|
|
1819
|
-
resolvedConnectId,
|
|
1820
|
-
passphraseState,
|
|
1821
|
-
signal,
|
|
1822
|
-
operationId
|
|
1823
|
-
);
|
|
1824
|
-
if (result.success && _optionalChain([expectedIdentity, 'optionalAccess', _80 => _80.value])) {
|
|
1825
|
-
await this._emitVerifiedBinding(
|
|
1826
|
-
expectedIdentity.value,
|
|
1827
|
-
resolvedConnectId,
|
|
1828
|
-
selectionRequestId,
|
|
1829
|
-
operationContext,
|
|
1830
|
-
signal
|
|
1831
|
-
);
|
|
1832
|
-
verified = true;
|
|
1833
|
-
this._rememberVerifiedConnection(expectedIdentity.value, resolvedConnectId);
|
|
1834
|
-
}
|
|
1835
|
-
return result;
|
|
1836
|
-
} finally {
|
|
1837
|
-
restorePassphraseRequestContext();
|
|
1838
|
-
}
|
|
1402
|
+
return await this._resolvePassphraseState(connectId, passphraseState, signal);
|
|
1839
1403
|
} finally {
|
|
1840
|
-
|
|
1841
|
-
this._emitBindingStatus(selectionRequestId, signal.aborted ? "cancelled" : "failed");
|
|
1842
|
-
await this._releaseProvisionalConnection(resolvedConnectId, signal);
|
|
1843
|
-
}
|
|
1404
|
+
restorePassphraseRequestContext();
|
|
1844
1405
|
}
|
|
1845
1406
|
},
|
|
1846
1407
|
{
|
|
@@ -1848,7 +1409,7 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1848
1409
|
rejectIfBusy: true,
|
|
1849
1410
|
busyError: _TrezorAdapter._createDeviceBusyError("getPassphraseState")
|
|
1850
1411
|
}
|
|
1851
|
-
).catch((error) => this._errorToFailure(error))
|
|
1412
|
+
).catch((error) => this._errorToFailure(error));
|
|
1852
1413
|
}
|
|
1853
1414
|
evmGetAddress(connectId, deviceId, params) {
|
|
1854
1415
|
return this._callWalletMethod("evmGetAddress", connectId, deviceId, params);
|
|
@@ -1911,100 +1472,11 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
1911
1472
|
}
|
|
1912
1473
|
return result;
|
|
1913
1474
|
}
|
|
1914
|
-
async _callConnector(sessionId, method, params, signal) {
|
|
1915
|
-
|
|
1916
|
-
throw _nullishCoalesce(signal.reason, () => ( new Error("Aborted")));
|
|
1917
|
-
}
|
|
1918
|
-
this._assertConnectorIdle(method);
|
|
1919
|
-
const releaseOperation = this._retainConnectorOperation(`call:${sessionId}`);
|
|
1920
|
-
let promise;
|
|
1921
|
-
try {
|
|
1922
|
-
promise = this._connector.call(sessionId, method, params).finally(() => {
|
|
1923
|
-
releaseOperation();
|
|
1924
|
-
});
|
|
1925
|
-
} catch (error) {
|
|
1926
|
-
releaseOperation();
|
|
1927
|
-
throw error;
|
|
1928
|
-
}
|
|
1475
|
+
static async _callConnector(connector, sessionId, method, params, signal) {
|
|
1476
|
+
const promise = connector.call(sessionId, method, params);
|
|
1929
1477
|
const result = signal ? await _TrezorAdapter._abortable(signal, promise) : await promise;
|
|
1930
1478
|
return _TrezorAdapter._unwrapConnectorResult(result);
|
|
1931
1479
|
}
|
|
1932
|
-
_assertConnectorIdle(method) {
|
|
1933
|
-
if (this._resetPromise || this._pendingConnectorTeardowns > 0 || this._unsettledConnectorOperations.size > 0) {
|
|
1934
|
-
throw _TrezorAdapter._createDeviceBusyError(method);
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
|
-
_runConnectorTeardown(task) {
|
|
1938
|
-
const previous = this._connectorTeardownTail;
|
|
1939
|
-
let releaseTail = () => void 0;
|
|
1940
|
-
this._connectorTeardownTail = new Promise((resolve) => {
|
|
1941
|
-
releaseTail = resolve;
|
|
1942
|
-
});
|
|
1943
|
-
this._pendingConnectorTeardowns += 1;
|
|
1944
|
-
return (async () => {
|
|
1945
|
-
try {
|
|
1946
|
-
await previous;
|
|
1947
|
-
await this._waitForConnectorOperationsToDrain();
|
|
1948
|
-
await task();
|
|
1949
|
-
} finally {
|
|
1950
|
-
this._pendingConnectorTeardowns -= 1;
|
|
1951
|
-
releaseTail();
|
|
1952
|
-
}
|
|
1953
|
-
})();
|
|
1954
|
-
}
|
|
1955
|
-
async _disconnectSession(connectId, sessionId = this._sessions.get(connectId)) {
|
|
1956
|
-
this._sessions.delete(connectId);
|
|
1957
|
-
this._verifiedPassphraseSessionsByConnectId.delete(connectId);
|
|
1958
|
-
if (sessionId) await this._runConnectorTeardown(() => this._connector.disconnect(sessionId));
|
|
1959
|
-
}
|
|
1960
|
-
_availableTransports() {
|
|
1961
|
-
return _nullishCoalesce(this._connector.availableTransports, () => ( [this._connector.connectionType]));
|
|
1962
|
-
}
|
|
1963
|
-
/** Transports the connector offers and the host's model table allows; discovery opens no other. */
|
|
1964
|
-
_allowedTransports(context) {
|
|
1965
|
-
const supported = _optionalChain([context, 'optionalAccess', _83 => _83.supportedTransports]);
|
|
1966
|
-
const available = this._availableTransports();
|
|
1967
|
-
return supported ? available.filter((transport) => supported.includes(transport)) : available;
|
|
1968
|
-
}
|
|
1969
|
-
async _releaseProvisionalConnection(connectId, signal) {
|
|
1970
|
-
const sessionId = this._sessions.get(connectId);
|
|
1971
|
-
this._sessions.delete(connectId);
|
|
1972
|
-
this._verifiedPassphraseSessionsByConnectId.delete(connectId);
|
|
1973
|
-
if (!sessionId) return;
|
|
1974
|
-
const teardown = this._runConnectorTeardown(() => this._connector.disconnect(sessionId)).catch(
|
|
1975
|
-
() => void 0
|
|
1976
|
-
);
|
|
1977
|
-
if (!signal.aborted) await teardown;
|
|
1978
|
-
}
|
|
1979
|
-
_waitForConnectorOperationsToDrain() {
|
|
1980
|
-
if (this._unsettledConnectorOperations.size === 0) {
|
|
1981
|
-
return Promise.resolve();
|
|
1982
|
-
}
|
|
1983
|
-
return new Promise((resolve) => {
|
|
1984
|
-
this._connectorIdleWaiters.add(resolve);
|
|
1985
|
-
});
|
|
1986
|
-
}
|
|
1987
|
-
_retainConnectorOperation(key) {
|
|
1988
|
-
this._unsettledConnectorOperations.set(
|
|
1989
|
-
key,
|
|
1990
|
-
(_nullishCoalesce(this._unsettledConnectorOperations.get(key), () => ( 0))) + 1
|
|
1991
|
-
);
|
|
1992
|
-
let released = false;
|
|
1993
|
-
return () => {
|
|
1994
|
-
if (released) return;
|
|
1995
|
-
released = true;
|
|
1996
|
-
const remaining = (_nullishCoalesce(this._unsettledConnectorOperations.get(key), () => ( 1))) - 1;
|
|
1997
|
-
if (remaining > 0) {
|
|
1998
|
-
this._unsettledConnectorOperations.set(key, remaining);
|
|
1999
|
-
} else {
|
|
2000
|
-
this._unsettledConnectorOperations.delete(key);
|
|
2001
|
-
}
|
|
2002
|
-
if (this._unsettledConnectorOperations.size === 0) {
|
|
2003
|
-
for (const resolve of this._connectorIdleWaiters) resolve();
|
|
2004
|
-
this._connectorIdleWaiters.clear();
|
|
2005
|
-
}
|
|
2006
|
-
};
|
|
2007
|
-
}
|
|
2008
1480
|
static _normalizeAllNetworkItem(method, item) {
|
|
2009
1481
|
if (method !== "btcGetAddress" && method !== "btcGetPublicKey") {
|
|
2010
1482
|
return item;
|
|
@@ -2023,14 +1495,18 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2023
1495
|
const { deviceId } = item;
|
|
2024
1496
|
return typeof deviceId === "string" && deviceId.length > 0 ? deviceId : void 0;
|
|
2025
1497
|
}
|
|
2026
|
-
_callAllNetworkMethod(connectId, method, item
|
|
1498
|
+
_callAllNetworkMethod(connectId, method, item) {
|
|
2027
1499
|
switch (method) {
|
|
2028
1500
|
case "evmGetAddress":
|
|
1501
|
+
return this.evmGetAddress(connectId, "", item);
|
|
2029
1502
|
case "btcGetAddress":
|
|
1503
|
+
return this.btcGetAddress(connectId, "", item);
|
|
2030
1504
|
case "btcGetPublicKey":
|
|
1505
|
+
return this.btcGetPublicKey(connectId, "", item);
|
|
2031
1506
|
case "solGetAddress":
|
|
1507
|
+
return this.solGetAddress(connectId, "", item);
|
|
2032
1508
|
case "tronGetAddress":
|
|
2033
|
-
return this.
|
|
1509
|
+
return this.tronGetAddress(connectId, "", item);
|
|
2034
1510
|
default:
|
|
2035
1511
|
return Promise.resolve(
|
|
2036
1512
|
_hwkadaptercore.failure.call(void 0,
|
|
@@ -2049,51 +1525,11 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2049
1525
|
_callWalletMethod(methodName, connectId, deviceId, params) {
|
|
2050
1526
|
return this._callMethod(methodName, connectId, deviceId, params, true);
|
|
2051
1527
|
}
|
|
2052
|
-
_callDeviceManagerMethod(methodName, connectId, params
|
|
2053
|
-
|
|
2054
|
-
if (expectedIdentity && (expectedIdentity.vendor !== "trezor" || expectedIdentity.type !== "deviceId")) {
|
|
2055
|
-
return Promise.resolve(
|
|
2056
|
-
_hwkadaptercore.failure.call(void 0,
|
|
2057
|
-
_hwkadaptercore.HardwareErrorCode.InvalidParams,
|
|
2058
|
-
"Trezor device-manager operations require a Trezor deviceId identity"
|
|
2059
|
-
)
|
|
2060
|
-
);
|
|
2061
|
-
}
|
|
2062
|
-
return this._callMethod(
|
|
2063
|
-
methodName,
|
|
2064
|
-
connectId,
|
|
2065
|
-
_optionalChain([expectedIdentity, 'optionalAccess', _85 => _85.value]),
|
|
2066
|
-
{
|
|
2067
|
-
...params && typeof params === "object" ? params : {},
|
|
2068
|
-
knownConnections: _optionalChain([operationContext, 'optionalAccess', _86 => _86.knownConnections]),
|
|
2069
|
-
extra: _optionalChain([operationContext, 'optionalAccess', _87 => _87.extra]),
|
|
2070
|
-
allowDeviceSelection: _optionalChain([operationContext, 'optionalAccess', _88 => _88.allowDeviceSelection]),
|
|
2071
|
-
supportedTransports: _optionalChain([operationContext, 'optionalAccess', _89 => _89.supportedTransports]),
|
|
2072
|
-
..._optionalChain([operationContext, 'optionalAccess', _90 => _90.operationId]) ? { operationId: operationContext.operationId } : {}
|
|
2073
|
-
},
|
|
2074
|
-
false
|
|
2075
|
-
);
|
|
1528
|
+
_callDeviceManagerMethod(methodName, connectId, params) {
|
|
1529
|
+
return this._callMethod(methodName, connectId, void 0, params, false);
|
|
2076
1530
|
}
|
|
2077
|
-
async _callMethod(methodName, connectId, deviceId, params, requiresWalletIntent
|
|
1531
|
+
async _callMethod(methodName, connectId, deviceId, params, requiresWalletIntent) {
|
|
2078
1532
|
const call = _TrezorAdapter._normalizeCallArgs(connectId, deviceId, params);
|
|
2079
|
-
const commonParams = _TrezorAdapter._splitCommonParams(call.params);
|
|
2080
|
-
const positionalOperationId = _hwkadaptercore.isHardwareOperationId.call(void 0, call.connectId) ? call.connectId : void 0;
|
|
2081
|
-
if (positionalOperationId && commonParams.operationId && positionalOperationId !== commonParams.operationId) {
|
|
2082
|
-
return _hwkadaptercore.failure.call(void 0, _hwkadaptercore.HardwareErrorCode.InvalidParams, "Conflicting Trezor operation ids", {
|
|
2083
|
-
positionalOperationId,
|
|
2084
|
-
commonOperationId: commonParams.operationId
|
|
2085
|
-
});
|
|
2086
|
-
}
|
|
2087
|
-
const operationId = _nullishCoalesce(commonParams.operationId, () => ( positionalOperationId));
|
|
2088
|
-
let releaseOperationRetention;
|
|
2089
|
-
try {
|
|
2090
|
-
if (operationId) {
|
|
2091
|
-
call.connectId = this._operations.resolve(operationId).connectId;
|
|
2092
|
-
releaseOperationRetention = this._operations.retain(operationId);
|
|
2093
|
-
}
|
|
2094
|
-
} catch (error) {
|
|
2095
|
-
return this._errorToFailure(error);
|
|
2096
|
-
}
|
|
2097
1533
|
debugLog("[TrezorAdapter][REQ]", {
|
|
2098
1534
|
method: methodName,
|
|
2099
1535
|
connectId: call.connectId || "(empty)",
|
|
@@ -2102,40 +1538,15 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2102
1538
|
});
|
|
2103
1539
|
try {
|
|
2104
1540
|
const response = await this._jobQueue.enqueue(
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
commonParams.connectionContext
|
|
2115
|
-
);
|
|
2116
|
-
effectiveConnectId = resolved.connectId;
|
|
2117
|
-
selectionRequestId = resolved.selectionRequestId;
|
|
2118
|
-
}
|
|
2119
|
-
} catch (error) {
|
|
2120
|
-
return this._errorToFailure(error);
|
|
2121
|
-
}
|
|
2122
|
-
const response2 = await this._callWithRetry(
|
|
2123
|
-
_nullishCoalesce(_optionalChain([bundleContext, 'optionalAccess', _94 => _94.connection, 'optionalAccess', _95 => _95.connectId]), () => ( effectiveConnectId)),
|
|
2124
|
-
methodName,
|
|
2125
|
-
call.params,
|
|
2126
|
-
deviceId || "",
|
|
2127
|
-
requiresWalletIntent,
|
|
2128
|
-
true,
|
|
2129
|
-
signal,
|
|
2130
|
-
operationId,
|
|
2131
|
-
selectionRequestId,
|
|
2132
|
-
bundleContext
|
|
2133
|
-
);
|
|
2134
|
-
if (!response2.success && selectionRequestId) {
|
|
2135
|
-
await this._releaseProvisionalConnection(effectiveConnectId, signal);
|
|
2136
|
-
}
|
|
2137
|
-
return response2;
|
|
2138
|
-
},
|
|
1541
|
+
call.connectId,
|
|
1542
|
+
(signal) => this._callWithRetry(
|
|
1543
|
+
call.connectId,
|
|
1544
|
+
methodName,
|
|
1545
|
+
call.params,
|
|
1546
|
+
requiresWalletIntent,
|
|
1547
|
+
true,
|
|
1548
|
+
signal
|
|
1549
|
+
),
|
|
2139
1550
|
{
|
|
2140
1551
|
label: methodName,
|
|
2141
1552
|
rejectIfBusy: true,
|
|
@@ -2156,53 +1567,16 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2156
1567
|
payload: _TrezorAdapter._sanitizeForLog(response.payload, methodName)
|
|
2157
1568
|
});
|
|
2158
1569
|
return response;
|
|
2159
|
-
} finally {
|
|
2160
|
-
_optionalChain([releaseOperationRetention, 'optionalCall', _96 => _96()]);
|
|
2161
1570
|
}
|
|
2162
1571
|
}
|
|
2163
|
-
async _callWithRetry(connectId, methodName, params,
|
|
2164
|
-
const { passphraseState, useEmptyPassphrase, rest
|
|
2165
|
-
let pendingBindingRequestId = selectionRequestId;
|
|
2166
|
-
let businessCallStarted = false;
|
|
1572
|
+
async _callWithRetry(connectId, methodName, params, requiresWalletIntent, allowRetry, signal) {
|
|
1573
|
+
const { passphraseState, useEmptyPassphrase, rest } = _TrezorAdapter._splitCommonParams(params);
|
|
2167
1574
|
const restorePassphraseRequestContext = this._setPassphraseRequestContext(connectId, {
|
|
2168
1575
|
passphraseState,
|
|
2169
1576
|
useEmptyPassphrase
|
|
2170
1577
|
});
|
|
2171
1578
|
try {
|
|
2172
|
-
|
|
2173
|
-
const pinned = bundleContext.connection;
|
|
2174
|
-
if (this._sessions.get(pinned.connectId) !== pinned.sessionId) {
|
|
2175
|
-
return _hwkadaptercore.failure.call(void 0,
|
|
2176
|
-
_hwkadaptercore.HardwareErrorCode.DeviceDisconnected,
|
|
2177
|
-
"Trezor all-network connection ended"
|
|
2178
|
-
);
|
|
2179
|
-
}
|
|
2180
|
-
}
|
|
2181
|
-
const sessionId = operationId ? this._sessions.get(this._operations.resolve(operationId).connectId) : await this._ensureSession(connectId, signal);
|
|
2182
|
-
if (!sessionId) {
|
|
2183
|
-
if (operationId) {
|
|
2184
|
-
this._operations.end(operationId, "disconnect");
|
|
2185
|
-
return _hwkadaptercore.failure.call(void 0,
|
|
2186
|
-
_hwkadaptercore.HardwareErrorCode.OperationEnded,
|
|
2187
|
-
"Trezor operation connection is no longer active",
|
|
2188
|
-
{ operationId, reason: "disconnect" }
|
|
2189
|
-
);
|
|
2190
|
-
}
|
|
2191
|
-
return _hwkadaptercore.failure.call(void 0, _hwkadaptercore.HardwareErrorCode.DeviceNotFound, "Trezor session was not found");
|
|
2192
|
-
}
|
|
2193
|
-
if (bundleContext && !bundleContext.connection) {
|
|
2194
|
-
bundleContext.connection = { connectId, sessionId };
|
|
2195
|
-
}
|
|
2196
|
-
if (expectedDeviceId) {
|
|
2197
|
-
const actualDeviceId = _optionalChain([this, 'access', _98 => _98._devices, 'access', _99 => _99.get, 'call', _100 => _100(connectId), 'optionalAccess', _101 => _101.deviceId]);
|
|
2198
|
-
if (!actualDeviceId || actualDeviceId !== expectedDeviceId) {
|
|
2199
|
-
return _hwkadaptercore.failure.call(void 0,
|
|
2200
|
-
_hwkadaptercore.HardwareErrorCode.DeviceMismatch,
|
|
2201
|
-
`Wrong device: expected ${expectedDeviceId}, got ${actualDeviceId || "unknown"}`,
|
|
2202
|
-
{ expected: expectedDeviceId, actual: actualDeviceId || "" }
|
|
2203
|
-
);
|
|
2204
|
-
}
|
|
2205
|
-
}
|
|
1579
|
+
const sessionId = await this._ensureSession(connectId, signal);
|
|
2206
1580
|
if (requiresWalletIntent && !passphraseState && useEmptyPassphrase !== true) {
|
|
2207
1581
|
return _hwkadaptercore.failure.call(void 0,
|
|
2208
1582
|
_hwkadaptercore.HardwareErrorCode.InvalidParams,
|
|
@@ -2217,85 +1591,39 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2217
1591
|
} else if (useEmptyPassphrase === true) {
|
|
2218
1592
|
await _TrezorAdapter._abortable(signal, this._createFreshAppSession(sessionId, signal));
|
|
2219
1593
|
}
|
|
2220
|
-
if (expectedDeviceId) {
|
|
2221
|
-
await this._emitVerifiedBinding(
|
|
2222
|
-
expectedDeviceId,
|
|
2223
|
-
connectId,
|
|
2224
|
-
pendingBindingRequestId,
|
|
2225
|
-
connectionContext,
|
|
2226
|
-
signal
|
|
2227
|
-
);
|
|
2228
|
-
pendingBindingRequestId = void 0;
|
|
2229
|
-
this._rememberVerifiedConnection(expectedDeviceId, connectId);
|
|
2230
|
-
}
|
|
2231
|
-
businessCallStarted = true;
|
|
2232
1594
|
const result = await _TrezorAdapter._abortable(
|
|
2233
1595
|
signal,
|
|
2234
|
-
|
|
1596
|
+
_TrezorAdapter._callConnector(this._connector, sessionId, methodName, rest)
|
|
2235
1597
|
);
|
|
2236
1598
|
return _hwkadaptercore.success.call(void 0, result);
|
|
2237
1599
|
} catch (error) {
|
|
2238
1600
|
if (signal.aborted) {
|
|
2239
|
-
if (pendingBindingRequestId) {
|
|
2240
|
-
this._emitBindingStatus(pendingBindingRequestId, "cancelled");
|
|
2241
|
-
pendingBindingRequestId = void 0;
|
|
2242
|
-
}
|
|
2243
1601
|
return this._errorToFailure(error);
|
|
2244
1602
|
}
|
|
2245
1603
|
const code = _TrezorAdapter._errorCode(error);
|
|
2246
|
-
|
|
2247
|
-
if (pendingBindingRequestId && !willRetryStaleSession) {
|
|
2248
|
-
this._emitBindingStatus(pendingBindingRequestId, "failed");
|
|
2249
|
-
pendingBindingRequestId = void 0;
|
|
2250
|
-
}
|
|
2251
|
-
const ambiguousTransportFailure = code === _hwkadaptercore.HardwareErrorCode.DeviceDisconnected || code === _hwkadaptercore.HardwareErrorCode.OperationTimeout || code === _hwkadaptercore.HardwareErrorCode.TransportError;
|
|
2252
|
-
if (ambiguousTransportFailure) {
|
|
1604
|
+
if (allowRetry && code === _hwkadaptercore.HardwareErrorCode.DeviceDisconnected) {
|
|
2253
1605
|
this._sessions.delete(connectId);
|
|
2254
1606
|
this._verifiedPassphraseSessionsByConnectId.delete(connectId);
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
_hwkadaptercore.operationMayHaveCompletedParams.call(void 0, methodName, endedParams),
|
|
2264
|
-
void 0,
|
|
2265
|
-
{ scope: "unknown" }
|
|
2266
|
-
) : _hwkadaptercore.failure.call(void 0,
|
|
2267
|
-
_hwkadaptercore.HardwareErrorCode.OperationEnded,
|
|
2268
|
-
"Trezor operation connection was lost",
|
|
2269
|
-
endedParams
|
|
2270
|
-
);
|
|
2271
|
-
}
|
|
2272
|
-
if (mayHaveCompleted) {
|
|
2273
|
-
return _hwkadaptercore.failure.call(void 0,
|
|
2274
|
-
code,
|
|
2275
|
-
mayHaveCompletedMessage,
|
|
2276
|
-
_hwkadaptercore.operationMayHaveCompletedParams.call(void 0, methodName),
|
|
2277
|
-
void 0,
|
|
2278
|
-
{ scope: "unknown" }
|
|
2279
|
-
);
|
|
2280
|
-
}
|
|
1607
|
+
return await this._callWithRetry(
|
|
1608
|
+
connectId,
|
|
1609
|
+
methodName,
|
|
1610
|
+
params,
|
|
1611
|
+
requiresWalletIntent,
|
|
1612
|
+
false,
|
|
1613
|
+
signal
|
|
1614
|
+
);
|
|
2281
1615
|
}
|
|
2282
|
-
if (
|
|
1616
|
+
if (allowRetry && (passphraseState || useEmptyPassphrase === true) && _TrezorAdapter._isStaleSessionError(code)) {
|
|
2283
1617
|
if (passphraseState) {
|
|
2284
1618
|
this._forgetVerifiedPassphraseSession(connectId, passphraseState);
|
|
2285
1619
|
}
|
|
2286
|
-
const retryBindingRequestId = pendingBindingRequestId;
|
|
2287
|
-
pendingBindingRequestId = void 0;
|
|
2288
1620
|
return await this._callWithRetry(
|
|
2289
1621
|
connectId,
|
|
2290
1622
|
methodName,
|
|
2291
1623
|
params,
|
|
2292
|
-
expectedDeviceId,
|
|
2293
1624
|
requiresWalletIntent,
|
|
2294
1625
|
false,
|
|
2295
|
-
signal
|
|
2296
|
-
operationId,
|
|
2297
|
-
retryBindingRequestId,
|
|
2298
|
-
bundleContext
|
|
1626
|
+
signal
|
|
2299
1627
|
);
|
|
2300
1628
|
}
|
|
2301
1629
|
debugLog("[TrezorAdapter][ERROR]", {
|
|
@@ -2306,249 +1634,36 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2306
1634
|
return this._errorToFailure(error);
|
|
2307
1635
|
} finally {
|
|
2308
1636
|
restorePassphraseRequestContext();
|
|
2309
|
-
if (pendingBindingRequestId) {
|
|
2310
|
-
this._emitBindingStatus(pendingBindingRequestId, signal.aborted ? "cancelled" : "failed");
|
|
2311
|
-
pendingBindingRequestId = void 0;
|
|
2312
|
-
}
|
|
2313
1637
|
}
|
|
2314
1638
|
}
|
|
2315
|
-
async _ensureSession(connectId, signal
|
|
1639
|
+
async _ensureSession(connectId, signal) {
|
|
2316
1640
|
const existing = this._sessions.get(connectId);
|
|
2317
1641
|
if (existing) return existing;
|
|
2318
1642
|
const pending = this._connectingPromises.get(connectId);
|
|
2319
1643
|
if (pending) return pending;
|
|
2320
|
-
const stateGeneration = this._stateGeneration;
|
|
2321
1644
|
const promise = (async () => {
|
|
2322
|
-
if (_optionalChain([signal, 'optionalAccess', _102 => _102.aborted])) {
|
|
2323
|
-
throw Object.assign(new Error("Trezor connection aborted"), {
|
|
2324
|
-
code: _hwkadaptercore.HardwareErrorCode.UserAborted
|
|
2325
|
-
});
|
|
2326
|
-
}
|
|
2327
1645
|
try {
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
this._verifiedPassphraseSessionsByConnectId.delete(connectId);
|
|
1646
|
+
if (_optionalChain([signal, 'optionalAccess', _34 => _34.aborted])) {
|
|
1647
|
+
throw Object.assign(new Error("Trezor connection aborted"), {
|
|
1648
|
+
code: _hwkadaptercore.HardwareErrorCode.UserAborted
|
|
1649
|
+
});
|
|
2333
1650
|
}
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
} finally {
|
|
2341
|
-
if (this._connectingPromises.get(connectId) === promise) {
|
|
2342
|
-
this._connectingPromises.delete(connectId);
|
|
2343
|
-
}
|
|
2344
|
-
this._disconnectRequested.delete(connectId);
|
|
2345
|
-
}
|
|
2346
|
-
}
|
|
2347
|
-
/** An identity probe tears down only a session it opened; another caller's stays up. */
|
|
2348
|
-
_hasSessionOrConnect(connectId) {
|
|
2349
|
-
return this._sessions.has(connectId) || this._connectingPromises.has(connectId);
|
|
2350
|
-
}
|
|
2351
|
-
async _resolveExpectedDeviceConnectId(expectedDeviceId, signal, context) {
|
|
2352
|
-
const connectedMatch = Array.from(this._devices.values()).find(
|
|
2353
|
-
(device) => device.deviceId === expectedDeviceId && this._sessions.has(device.connectId)
|
|
2354
|
-
);
|
|
2355
|
-
if (connectedMatch) return { connectId: connectedMatch.connectId };
|
|
2356
|
-
const allowedTransports = this._allowedTransports(context);
|
|
2357
|
-
if (allowedTransports.includes("usb")) {
|
|
2358
|
-
await _TrezorAdapter._abortable(
|
|
2359
|
-
signal,
|
|
2360
|
-
this._ensureDevicePermission(void 0, expectedDeviceId, "usb")
|
|
2361
|
-
);
|
|
2362
|
-
}
|
|
2363
|
-
const candidates = allowedTransports.includes("usb") ? await _TrezorAdapter._abortable(
|
|
2364
|
-
signal,
|
|
2365
|
-
this._searchDevices({ transportType: "usb" }, signal)
|
|
2366
|
-
) : [];
|
|
2367
|
-
const mismatchedDeviceIds = [];
|
|
2368
|
-
const knownConnection = this._knownDeviceConnections.get(expectedDeviceId);
|
|
2369
|
-
const knownUsbIds = _optionalChain([context, 'optionalAccess', _103 => _103.knownConnections]) !== void 0 ? context.knownConnections.flatMap(
|
|
2370
|
-
(connection) => connection.transport === "usb" ? [connection.connectId] : []
|
|
2371
|
-
) : [_optionalChain([knownConnection, 'optionalAccess', _104 => _104.usbConnectId])].filter((id) => Boolean(id));
|
|
2372
|
-
const suppliedBleIds = _optionalChain([context, 'optionalAccess', _105 => _105.knownConnections, 'optionalAccess', _106 => _106.flatMap, 'call', _107 => _107(
|
|
2373
|
-
(connection) => connection.transport === "ble" ? [connection.connectId] : []
|
|
2374
|
-
)]);
|
|
2375
|
-
const knownBleIds = _optionalChain([suppliedBleIds, 'optionalAccess', _108 => _108.length]) ? suppliedBleIds : [_optionalChain([knownConnection, 'optionalAccess', _109 => _109.bleConnectId])].filter((id) => Boolean(id));
|
|
2376
|
-
const usbCandidates = candidates.filter(
|
|
2377
|
-
(device) => device.connectionType === "usb" && (!knownUsbIds.length || knownUsbIds.includes(device.connectId))
|
|
2378
|
-
);
|
|
2379
|
-
for (const candidate of usbCandidates) {
|
|
2380
|
-
let sessionId;
|
|
2381
|
-
const probeOpensSession = !this._hasSessionOrConnect(candidate.connectId);
|
|
2382
|
-
try {
|
|
2383
|
-
sessionId = await this._ensureSession(candidate.connectId, signal, "usb");
|
|
2384
|
-
const actualDeviceId = _nullishCoalesce(_optionalChain([this, 'access', _110 => _110._devices, 'access', _111 => _111.get, 'call', _112 => _112(candidate.connectId), 'optionalAccess', _113 => _113.deviceId]), () => ( ""));
|
|
2385
|
-
if (actualDeviceId === expectedDeviceId) return { connectId: candidate.connectId };
|
|
2386
|
-
mismatchedDeviceIds.push(actualDeviceId || "unknown");
|
|
2387
|
-
} catch (error) {
|
|
2388
|
-
if (signal.aborted) throw error;
|
|
2389
|
-
if (!_TrezorAdapter._isConnectionUnavailableError(error)) throw error;
|
|
2390
|
-
}
|
|
2391
|
-
if (sessionId && probeOpensSession) {
|
|
2392
|
-
await this._disconnectSession(candidate.connectId, sessionId);
|
|
2393
|
-
}
|
|
2394
|
-
}
|
|
2395
|
-
if (mismatchedDeviceIds.length) {
|
|
2396
|
-
throw _hwkadaptercore.createHwkError.call(void 0, {
|
|
2397
|
-
code: _hwkadaptercore.HardwareErrorCode.DeviceSearchMismatch,
|
|
2398
|
-
message: "The connected Trezor is not the wallet this operation needs. Unplug it and connect the right device.",
|
|
2399
|
-
params: { connectedDeviceIds: mismatchedDeviceIds }
|
|
2400
|
-
});
|
|
2401
|
-
}
|
|
2402
|
-
if (usbCandidates.length > 0) {
|
|
2403
|
-
throw _hwkadaptercore.createHwkError.call(void 0, {
|
|
2404
|
-
code: _hwkadaptercore.HardwareErrorCode.DeviceNotFound,
|
|
2405
|
-
message: "Trezor devices are present but none could be opened to check its identity."
|
|
2406
|
-
});
|
|
2407
|
-
}
|
|
2408
|
-
const [knownBleConnectId] = knownBleIds;
|
|
2409
|
-
if (knownBleConnectId && allowedTransports.includes("ble")) {
|
|
2410
|
-
await _TrezorAdapter._abortable(
|
|
2411
|
-
signal,
|
|
2412
|
-
this._ensureDevicePermission(knownBleConnectId, expectedDeviceId, "ble")
|
|
2413
|
-
);
|
|
2414
|
-
const probeOpensSession = !this._hasSessionOrConnect(knownBleConnectId);
|
|
2415
|
-
await this._ensureSession(knownBleConnectId, signal, "ble");
|
|
2416
|
-
const actualDeviceId = _optionalChain([this, 'access', _114 => _114._devices, 'access', _115 => _115.get, 'call', _116 => _116(knownBleConnectId), 'optionalAccess', _117 => _117.deviceId]);
|
|
2417
|
-
if (actualDeviceId === expectedDeviceId) return { connectId: knownBleConnectId };
|
|
2418
|
-
if (probeOpensSession) await this._disconnectSession(knownBleConnectId);
|
|
2419
|
-
throw _hwkadaptercore.createHwkError.call(void 0, {
|
|
2420
|
-
code: _hwkadaptercore.HardwareErrorCode.DeviceMismatch,
|
|
2421
|
-
message: "The bound Trezor Bluetooth device has a different identity"
|
|
2422
|
-
});
|
|
2423
|
-
}
|
|
2424
|
-
if (_optionalChain([context, 'optionalAccess', _118 => _118.supportedTransports]) && !context.supportedTransports.includes("ble")) {
|
|
2425
|
-
throw _hwkadaptercore.createHwkError.call(void 0, {
|
|
2426
|
-
code: _hwkadaptercore.HardwareErrorCode.DeviceNotFound,
|
|
2427
|
-
message: "This Trezor model has no Bluetooth transport; connect it over USB"
|
|
2428
|
-
});
|
|
2429
|
-
}
|
|
2430
|
-
if (_optionalChain([context, 'optionalAccess', _119 => _119.allowDeviceSelection]) === false) {
|
|
2431
|
-
throw _hwkadaptercore.createHwkError.call(void 0, {
|
|
2432
|
-
code: _hwkadaptercore.HardwareErrorCode.DeviceNotFound,
|
|
2433
|
-
message: "No known Trezor connection is available"
|
|
2434
|
-
});
|
|
2435
|
-
}
|
|
2436
|
-
return this._selectBleDeviceForBinding(expectedDeviceId, signal, context, "missing-binding");
|
|
2437
|
-
}
|
|
2438
|
-
async _selectBleDeviceForBinding(expectedDeviceId, signal, context, reason) {
|
|
2439
|
-
const availableTransports = this._allowedTransports(context);
|
|
2440
|
-
const allowUsbFallback = reason !== "manual-rebind" && availableTransports.includes("usb");
|
|
2441
|
-
const knownUsbIds = _optionalChain([context, 'optionalAccess', _120 => _120.knownConnections]) ? context.knownConnections.flatMap(
|
|
2442
|
-
(connection) => connection.transport === "usb" ? [connection.connectId] : []
|
|
2443
|
-
) : [_optionalChain([this, 'access', _121 => _121._knownDeviceConnections, 'access', _122 => _122.get, 'call', _123 => _123(expectedDeviceId), 'optionalAccess', _124 => _124.usbConnectId])];
|
|
2444
|
-
if (availableTransports.includes("ble")) {
|
|
2445
|
-
await _TrezorAdapter._abortable(
|
|
2446
|
-
signal,
|
|
2447
|
-
this._ensureDevicePermission(void 0, expectedDeviceId, "ble")
|
|
2448
|
-
);
|
|
2449
|
-
}
|
|
2450
|
-
const bleCandidates = (await _TrezorAdapter._abortable(
|
|
2451
|
-
signal,
|
|
2452
|
-
this._searchDevices({ transportType: "ble", waitForAllTransports: true }, signal)
|
|
2453
|
-
)).filter((device) => device.connectionType === "ble");
|
|
2454
|
-
if (signal.aborted) throw signal.reason;
|
|
2455
|
-
const rejectedConnectIds = /* @__PURE__ */ new Set();
|
|
2456
|
-
const bindingSessionId = this._uiRegistry.createRequestId();
|
|
2457
|
-
let rejectedConnectId;
|
|
2458
|
-
while (availableTransports.includes("ble") && this._emitter.listenerCount(_hwkadaptercore.UI_REQUEST.REQUEST_SELECT_DEVICE)) {
|
|
2459
|
-
const { device: selected, requestId } = await _hwkadaptercore.requestBleDeviceSelection.call(void 0, {
|
|
2460
|
-
emitter: this._emitter,
|
|
2461
|
-
registry: this._uiRegistry,
|
|
2462
|
-
signal,
|
|
2463
|
-
allowUsbFallback,
|
|
2464
|
-
scan: async () => {
|
|
2465
|
-
if (allowUsbFallback) {
|
|
2466
|
-
const usbCandidates = (await this._searchDevices({ transportType: "usb" }, signal)).filter(
|
|
2467
|
-
(device) => device.connectionType === "usb" && !rejectedConnectIds.has(device.connectId)
|
|
2468
|
-
);
|
|
2469
|
-
const candidate = _nullishCoalesce(usbCandidates.find((device) => knownUsbIds.includes(device.connectId)), () => ( usbCandidates[0]));
|
|
2470
|
-
if (candidate) return [candidate];
|
|
1651
|
+
try {
|
|
1652
|
+
return await this._connectSession(connectId, signal);
|
|
1653
|
+
} catch (error) {
|
|
1654
|
+
if (_TrezorAdapter._isConnectionUnavailableError(error)) {
|
|
1655
|
+
this._sessions.delete(connectId);
|
|
1656
|
+
this._verifiedPassphraseSessionsByConnectId.delete(connectId);
|
|
2471
1657
|
}
|
|
2472
|
-
|
|
2473
|
-
(device) => device.connectionType === "ble" && !rejectedConnectIds.has(device.connectId)
|
|
2474
|
-
);
|
|
2475
|
-
},
|
|
2476
|
-
request: {
|
|
2477
|
-
devices: bleCandidates.filter((device) => !rejectedConnectIds.has(device.connectId)),
|
|
2478
|
-
bindingSessionId,
|
|
2479
|
-
rejectedConnectId,
|
|
2480
|
-
context: {
|
|
2481
|
-
kind: "bind-connection",
|
|
2482
|
-
transport: "ble",
|
|
2483
|
-
reason
|
|
2484
|
-
},
|
|
2485
|
-
extra: _optionalChain([context, 'optionalAccess', _125 => _125.extra]),
|
|
2486
|
-
operationId: this._activeOperationId()
|
|
2487
|
-
}
|
|
2488
|
-
});
|
|
2489
|
-
let probeOpensSession = false;
|
|
2490
|
-
try {
|
|
2491
|
-
if (reason === "manual-rebind") {
|
|
2492
|
-
this._operations.endByConnectionKey(selected.connectId, "explicit");
|
|
2493
|
-
await this._releaseProvisionalConnection(selected.connectId, signal);
|
|
1658
|
+
throw error;
|
|
2494
1659
|
}
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
this._emitBindingStatus(requestId, signal.aborted ? "cancelled" : "failed");
|
|
2499
|
-
throw error;
|
|
2500
|
-
}
|
|
2501
|
-
if (_optionalChain([this, 'access', _126 => _126._devices, 'access', _127 => _127.get, 'call', _128 => _128(selected.connectId), 'optionalAccess', _129 => _129.deviceId]) !== expectedDeviceId) {
|
|
2502
|
-
if (probeOpensSession) await this._disconnectSession(selected.connectId);
|
|
2503
|
-
rejectedConnectId = selected.connectId;
|
|
2504
|
-
rejectedConnectIds.add(selected.connectId);
|
|
2505
|
-
continue;
|
|
2506
|
-
}
|
|
2507
|
-
if (selected.connectionType === "usb") {
|
|
2508
|
-
this._emitBindingStatus(requestId, "cancelled");
|
|
2509
|
-
return { connectId: selected.connectId };
|
|
1660
|
+
} finally {
|
|
1661
|
+
this._connectingPromises.delete(connectId);
|
|
1662
|
+
this._disconnectRequested.delete(connectId);
|
|
2510
1663
|
}
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
code: _hwkadaptercore.HardwareErrorCode.DeviceNotFound,
|
|
2515
|
-
message: "No readable Trezor device is available"
|
|
2516
|
-
});
|
|
2517
|
-
}
|
|
2518
|
-
_emitBindingStatus(selectionRequestId, status) {
|
|
2519
|
-
_hwkadaptercore.emitDeviceBindingStatus.call(void 0, this._emitter, selectionRequestId, status);
|
|
2520
|
-
}
|
|
2521
|
-
_rememberVerifiedConnection(deviceId, connectId) {
|
|
2522
|
-
const device = this._devices.get(connectId);
|
|
2523
|
-
if (!device || device.deviceId !== deviceId) return;
|
|
2524
|
-
const known = _nullishCoalesce(this._knownDeviceConnections.get(deviceId), () => ( { deviceId }));
|
|
2525
|
-
if (device.connectionType === "ble") {
|
|
2526
|
-
known.bleConnectId = connectId;
|
|
2527
|
-
} else if (device.connectionType === "usb" && _optionalChain([device, 'access', _130 => _130.capabilities, 'optionalAccess', _131 => _131.persistentDeviceIdentity])) {
|
|
2528
|
-
known.usbConnectId = connectId;
|
|
2529
|
-
}
|
|
2530
|
-
this._knownDeviceConnections.set(deviceId, known);
|
|
2531
|
-
}
|
|
2532
|
-
async _emitVerifiedBinding(deviceId, connectId, selectionRequestId, context, signal) {
|
|
2533
|
-
if (!selectionRequestId) return false;
|
|
2534
|
-
const device = this._devices.get(connectId);
|
|
2535
|
-
if (!device || device.deviceId !== deviceId || device.connectionType !== "ble") {
|
|
2536
|
-
this._emitBindingStatus(selectionRequestId, "cancelled");
|
|
2537
|
-
return false;
|
|
2538
|
-
}
|
|
2539
|
-
const outcome = await _hwkadaptercore.requestSaveDeviceBinding.call(void 0,
|
|
2540
|
-
this._emitter,
|
|
2541
|
-
this._uiRegistry,
|
|
2542
|
-
{
|
|
2543
|
-
selectionRequestId,
|
|
2544
|
-
connection: { transport: "ble", connectId },
|
|
2545
|
-
identity: { vendor: "trezor", type: "deviceId", value: deviceId },
|
|
2546
|
-
extra: _optionalChain([context, 'optionalAccess', _132 => _132.extra]),
|
|
2547
|
-
operationId: this._activeOperationId()
|
|
2548
|
-
},
|
|
2549
|
-
signal
|
|
2550
|
-
);
|
|
2551
|
-
return outcome.saved;
|
|
1664
|
+
})();
|
|
1665
|
+
this._connectingPromises.set(connectId, promise);
|
|
1666
|
+
return promise;
|
|
2552
1667
|
}
|
|
2553
1668
|
/**
|
|
2554
1669
|
* Pin the device's active wallet session to `passphraseState` (the target
|
|
@@ -2570,21 +1685,12 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2570
1685
|
if (reused) return;
|
|
2571
1686
|
const created = await _TrezorAdapter._abortable(
|
|
2572
1687
|
signal,
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
{
|
|
2577
|
-
passphraseMode: "prompt"
|
|
2578
|
-
},
|
|
2579
|
-
signal
|
|
2580
|
-
)
|
|
1688
|
+
_TrezorAdapter._callConnector(this._connector, sessionId, "__thpCreateSession", {
|
|
1689
|
+
passphraseMode: "prompt"
|
|
1690
|
+
})
|
|
2581
1691
|
);
|
|
2582
|
-
if (_optionalChain([created, 'optionalAccess',
|
|
2583
|
-
|
|
2584
|
-
code: _hwkadaptercore.HardwareErrorCode.TransportError,
|
|
2585
|
-
message: "Cannot verify the requested Trezor wallet session"
|
|
2586
|
-
});
|
|
2587
|
-
}
|
|
1692
|
+
if (_optionalChain([created, 'optionalAccess', _35 => _35.protocol]) === "thp" && !created.thpSessionId) return;
|
|
1693
|
+
if (_optionalChain([created, 'optionalAccess', _36 => _36.protocol]) !== "thp" && _optionalChain([created, 'optionalAccess', _37 => _37.protocol]) !== "v1") return;
|
|
2588
1694
|
const state = await this._deriveState(sessionId, signal);
|
|
2589
1695
|
if (state !== passphraseState) {
|
|
2590
1696
|
throw Object.assign(
|
|
@@ -2598,13 +1704,13 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2598
1704
|
}
|
|
2599
1705
|
_rememberVerifiedPassphraseSession(connectId, passphraseState, sessionId, created) {
|
|
2600
1706
|
let session;
|
|
2601
|
-
if (_optionalChain([created, 'optionalAccess',
|
|
1707
|
+
if (_optionalChain([created, 'optionalAccess', _38 => _38.protocol]) === "thp" && typeof created.thpSessionId === "string") {
|
|
2602
1708
|
session = {
|
|
2603
1709
|
sessionId,
|
|
2604
1710
|
protocol: "thp",
|
|
2605
1711
|
thpSessionId: created.thpSessionId
|
|
2606
1712
|
};
|
|
2607
|
-
} else if (_optionalChain([created, 'optionalAccess',
|
|
1713
|
+
} else if (_optionalChain([created, 'optionalAccess', _39 => _39.protocol]) === "v1") {
|
|
2608
1714
|
session = {
|
|
2609
1715
|
sessionId,
|
|
2610
1716
|
protocol: "v1"
|
|
@@ -2624,7 +1730,7 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2624
1730
|
}
|
|
2625
1731
|
}
|
|
2626
1732
|
async _reuseVerifiedPassphraseSession(connectId, sessionId, passphraseState, signal) {
|
|
2627
|
-
const cached = _optionalChain([this, 'access',
|
|
1733
|
+
const cached = _optionalChain([this, 'access', _40 => _40._verifiedPassphraseSessionsByConnectId, 'access', _41 => _41.get, 'call', _42 => _42(connectId), 'optionalAccess', _43 => _43.get, 'call', _44 => _44(passphraseState)]);
|
|
2628
1734
|
if (!cached || cached.sessionId !== sessionId) {
|
|
2629
1735
|
this._forgetVerifiedPassphraseSession(connectId, passphraseState);
|
|
2630
1736
|
return false;
|
|
@@ -2634,14 +1740,9 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2634
1740
|
if (!cached.thpSessionId) return false;
|
|
2635
1741
|
await _TrezorAdapter._abortable(
|
|
2636
1742
|
signal,
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
{
|
|
2641
|
-
thpSessionId: cached.thpSessionId
|
|
2642
|
-
},
|
|
2643
|
-
signal
|
|
2644
|
-
)
|
|
1743
|
+
_TrezorAdapter._callConnector(this._connector, sessionId, "__thpSelectSession", {
|
|
1744
|
+
thpSessionId: cached.thpSessionId
|
|
1745
|
+
})
|
|
2645
1746
|
);
|
|
2646
1747
|
}
|
|
2647
1748
|
const state = await this._deriveState(sessionId, signal);
|
|
@@ -2659,14 +1760,9 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2659
1760
|
async _createFreshAppSession(sessionId, signal) {
|
|
2660
1761
|
await _TrezorAdapter._abortable(
|
|
2661
1762
|
signal,
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
{
|
|
2666
|
-
passphraseMode: "empty"
|
|
2667
|
-
},
|
|
2668
|
-
signal
|
|
2669
|
-
)
|
|
1763
|
+
_TrezorAdapter._callConnector(this._connector, sessionId, "__thpCreateSession", {
|
|
1764
|
+
passphraseMode: "empty"
|
|
1765
|
+
})
|
|
2670
1766
|
);
|
|
2671
1767
|
}
|
|
2672
1768
|
/**
|
|
@@ -2681,17 +1777,12 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2681
1777
|
async _deriveState(sessionId, signal) {
|
|
2682
1778
|
const derived = await _TrezorAdapter._abortable(
|
|
2683
1779
|
signal,
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
path: "m/44'/0'/0'",
|
|
2689
|
-
showOnDevice: false
|
|
2690
|
-
},
|
|
2691
|
-
signal
|
|
2692
|
-
)
|
|
1780
|
+
_TrezorAdapter._callConnector(this._connector, sessionId, "btcGetPublicKey", {
|
|
1781
|
+
path: "m/44'/0'/0'",
|
|
1782
|
+
showOnDevice: false
|
|
1783
|
+
})
|
|
2693
1784
|
);
|
|
2694
|
-
const state = _optionalChain([derived, 'optionalAccess',
|
|
1785
|
+
const state = _optionalChain([derived, 'optionalAccess', _45 => _45.publicKey]);
|
|
2695
1786
|
if (!state) {
|
|
2696
1787
|
throw Object.assign(new Error("Failed to derive passphrase state (wallet public key)"), {
|
|
2697
1788
|
code: _hwkadaptercore.HardwareErrorCode.UnknownError
|
|
@@ -2699,36 +1790,25 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2699
1790
|
}
|
|
2700
1791
|
return state;
|
|
2701
1792
|
}
|
|
2702
|
-
async _resolvePassphraseState(connectId, passphraseState, signal
|
|
1793
|
+
async _resolvePassphraseState(connectId, passphraseState, signal) {
|
|
2703
1794
|
try {
|
|
2704
|
-
const sessionId =
|
|
2705
|
-
if (!sessionId) {
|
|
2706
|
-
return _hwkadaptercore.failure.call(void 0,
|
|
2707
|
-
_hwkadaptercore.HardwareErrorCode.OperationEnded,
|
|
2708
|
-
"Trezor operation connection is no longer active"
|
|
2709
|
-
);
|
|
2710
|
-
}
|
|
1795
|
+
const sessionId = await this._ensureSession(connectId, signal);
|
|
2711
1796
|
if (passphraseState) {
|
|
2712
1797
|
await this._alignAppSession(connectId, sessionId, passphraseState, signal);
|
|
2713
1798
|
return _hwkadaptercore.success.call(void 0, passphraseState);
|
|
2714
1799
|
}
|
|
2715
1800
|
const created = await _TrezorAdapter._abortable(
|
|
2716
1801
|
signal,
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
{
|
|
2721
|
-
passphraseMode: "prompt"
|
|
2722
|
-
},
|
|
2723
|
-
signal
|
|
2724
|
-
)
|
|
1802
|
+
_TrezorAdapter._callConnector(this._connector, sessionId, "__thpCreateSession", {
|
|
1803
|
+
passphraseMode: "prompt"
|
|
1804
|
+
})
|
|
2725
1805
|
);
|
|
2726
1806
|
const state = await this._deriveState(sessionId, signal);
|
|
2727
1807
|
const features = await _TrezorAdapter._abortable(
|
|
2728
1808
|
signal,
|
|
2729
|
-
|
|
1809
|
+
_TrezorAdapter._callConnector(this._connector, sessionId, "getFeatures", { refresh: true })
|
|
2730
1810
|
);
|
|
2731
|
-
if (_optionalChain([features, 'optionalAccess',
|
|
1811
|
+
if (_optionalChain([features, 'optionalAccess', _46 => _46.passphrase_protection]) !== true) {
|
|
2732
1812
|
return _hwkadaptercore.success.call(void 0, null);
|
|
2733
1813
|
}
|
|
2734
1814
|
this._rememberVerifiedPassphraseSession(connectId, state, sessionId, created);
|
|
@@ -2776,16 +1856,7 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2776
1856
|
}
|
|
2777
1857
|
const trustedNumericCode = typeof typed.code === "number" && KNOWN_HARDWARE_ERROR_CODES.has(typed.code) ? typed.code : void 0;
|
|
2778
1858
|
const code = _nullishCoalesce(_nullishCoalesce(trustedNumericCode, () => ( _TrezorAdapter._mapTrezorFailureCode(error))), () => ( _hwkadaptercore.HardwareErrorCode.UnknownError));
|
|
2779
|
-
|
|
2780
|
-
const origin = stampedOrigin === "device" || stampedOrigin === "transport" || stampedOrigin === "host" ? stampedOrigin : _hwkadaptercore.defaultOriginForCode.call(void 0, code);
|
|
2781
|
-
const params = typed.params && typeof typed.params === "object" ? typed.params : void 0;
|
|
2782
|
-
return _hwkadaptercore.failure.call(void 0,
|
|
2783
|
-
code,
|
|
2784
|
-
_nullishCoalesce(typed.message, () => ( String(error))),
|
|
2785
|
-
params,
|
|
2786
|
-
origin,
|
|
2787
|
-
_hwkadaptercore.isHwkRecoveryHint.call(void 0, typed.recovery) ? typed.recovery : void 0
|
|
2788
|
-
);
|
|
1859
|
+
return _hwkadaptercore.failure.call(void 0, code, _nullishCoalesce(typed.message, () => ( String(error))));
|
|
2789
1860
|
}
|
|
2790
1861
|
/**
|
|
2791
1862
|
* Emit `REQUEST_DEVICE_PERMISSION` and await the host's
|
|
@@ -2800,33 +1871,29 @@ var _TrezorAdapter = class _TrezorAdapter {
|
|
|
2800
1871
|
* - no `connectId` → environment-level check (scan / picker)
|
|
2801
1872
|
* - with `connectId` → device-level check (per-call gating)
|
|
2802
1873
|
*/
|
|
2803
|
-
async _ensureDevicePermission(connectId, deviceId
|
|
1874
|
+
async _ensureDevicePermission(connectId, deviceId) {
|
|
2804
1875
|
if (!this._emitter.listenerCount(_hwkadaptercore.UI_REQUEST.REQUEST_DEVICE_PERMISSION)) {
|
|
2805
1876
|
return;
|
|
2806
1877
|
}
|
|
2807
|
-
const transportType = _nullishCoalesce(
|
|
2808
|
-
const operationId = this._activeOperationId();
|
|
1878
|
+
const transportType = _nullishCoalesce(this.activeTransport, () => ( "usb"));
|
|
2809
1879
|
const waitPromise = this._uiRegistry.wait(
|
|
2810
1880
|
_hwkadaptercore.UI_REQUEST.REQUEST_DEVICE_PERMISSION,
|
|
2811
|
-
{ timeoutMs: 6e4
|
|
1881
|
+
{ timeoutMs: 6e4 }
|
|
2812
1882
|
);
|
|
2813
1883
|
this._emitter.emit(_hwkadaptercore.UI_REQUEST.REQUEST_DEVICE_PERMISSION, {
|
|
2814
1884
|
type: _hwkadaptercore.UI_REQUEST.REQUEST_DEVICE_PERMISSION,
|
|
2815
|
-
payload: { transportType, connectId, deviceId
|
|
1885
|
+
payload: { transportType, connectId, deviceId }
|
|
2816
1886
|
});
|
|
2817
|
-
const { granted
|
|
1887
|
+
const { granted } = await waitPromise;
|
|
2818
1888
|
if (!granted) {
|
|
2819
1889
|
throw Object.assign(new Error("Device permission denied"), {
|
|
2820
|
-
code: _hwkadaptercore.HardwareErrorCode.DevicePermissionDenied
|
|
2821
|
-
...reason ? { params: { permissionDeniedReason: reason } } : {}
|
|
1890
|
+
code: _hwkadaptercore.HardwareErrorCode.DevicePermissionDenied
|
|
2822
1891
|
});
|
|
2823
1892
|
}
|
|
2824
1893
|
}
|
|
2825
1894
|
};
|
|
2826
1895
|
// Keys are matched after normalizeLogKey, so snake_case/camelCase both hit.
|
|
2827
1896
|
_TrezorAdapter._sensitiveLogKeys = /* @__PURE__ */ new Set([
|
|
2828
|
-
"extra",
|
|
2829
|
-
"knownconnections",
|
|
2830
1897
|
"credential",
|
|
2831
1898
|
"credentials",
|
|
2832
1899
|
"entropy",
|
|
@@ -2945,7 +2012,7 @@ async function fetchDefinitionHex(url, fetchImpl) {
|
|
|
2945
2012
|
}
|
|
2946
2013
|
return arrayBufferToHex(await response.arrayBuffer());
|
|
2947
2014
|
});
|
|
2948
|
-
} catch (
|
|
2015
|
+
} catch (e5) {
|
|
2949
2016
|
return void 0;
|
|
2950
2017
|
}
|
|
2951
2018
|
}
|
|
@@ -2974,7 +2041,7 @@ async function fetchSolanaTokenDefinition({
|
|
|
2974
2041
|
}
|
|
2975
2042
|
return Buffer.from(await response.arrayBuffer()).toString("hex");
|
|
2976
2043
|
});
|
|
2977
|
-
} catch (
|
|
2044
|
+
} catch (e6) {
|
|
2978
2045
|
return void 0;
|
|
2979
2046
|
}
|
|
2980
2047
|
}
|