@onekeyfe/hwk-adapter-core 1.1.29-alpha.3 → 1.1.29
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 +292 -610
- package/dist/index.d.ts +292 -610
- package/dist/index.js +368 -452
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +258 -400
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -22
- package/dist/chunk-6JWUE3GT.mjs +0 -151
- package/dist/chunk-6JWUE3GT.mjs.map +0 -1
- package/dist/chunk-D5OZT7RZ.mjs +0 -138
- package/dist/chunk-D5OZT7RZ.mjs.map +0 -1
- package/dist/chunk-LYVS67EX.js +0 -151
- package/dist/chunk-LYVS67EX.js.map +0 -1
- package/dist/chunk-QD4EQWQA.js +0 -138
- package/dist/chunk-QD4EQWQA.js.map +0 -1
- package/dist/errors.d.mts +0 -164
- package/dist/errors.d.ts +0 -164
- package/dist/errors.js +0 -13
- package/dist/errors.js.map +0 -1
- package/dist/errors.mjs +0 -13
- package/dist/errors.mjs.map +0 -1
- package/dist/ui-events-BzkI1wZk.d.mts +0 -132
- package/dist/ui-events-BzkI1wZk.d.ts +0 -132
- package/dist/ui-events.d.mts +0 -1
- package/dist/ui-events.d.ts +0 -1
- package/dist/ui-events.js +0 -21
- package/dist/ui-events.js.map +0 -1
- package/dist/ui-events.mjs +0 -21
- package/dist/ui-events.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,19 +1,125 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
CHAIN_FINGERPRINT_PATHS: () => CHAIN_FINGERPRINT_PATHS,
|
|
24
|
+
DEVICE: () => DEVICE,
|
|
25
|
+
DEVICE_EVENT: () => DEVICE_EVENT,
|
|
26
|
+
DeviceJobQueue: () => DeviceJobQueue,
|
|
27
|
+
EConnectorInteraction: () => EConnectorInteraction,
|
|
28
|
+
HardwareErrorCode: () => HardwareErrorCode,
|
|
29
|
+
ORPHAN_ELIGIBLE_ERROR_CODES: () => ORPHAN_ELIGIBLE_ERROR_CODES,
|
|
30
|
+
SDK: () => SDK,
|
|
31
|
+
TypedEventEmitter: () => TypedEventEmitter,
|
|
32
|
+
UI_EVENT: () => UI_EVENT,
|
|
33
|
+
UI_REQUEST: () => UI_REQUEST,
|
|
34
|
+
UI_REQUEST_CANCELLED_TAG: () => UI_REQUEST_CANCELLED_TAG,
|
|
35
|
+
UI_REQUEST_DEFAULT_TIMEOUT_MS: () => UI_REQUEST_DEFAULT_TIMEOUT_MS,
|
|
36
|
+
UI_REQUEST_PREEMPTED_TAG: () => UI_REQUEST_PREEMPTED_TAG,
|
|
37
|
+
UI_REQUEST_TIMEOUT_TAG: () => UI_REQUEST_TIMEOUT_TAG,
|
|
38
|
+
UI_RESPONSE: () => UI_RESPONSE,
|
|
39
|
+
UiRequestRegistry: () => UiRequestRegistry,
|
|
40
|
+
batchCall: () => batchCall,
|
|
41
|
+
bytesToHex: () => bytesToHex2,
|
|
42
|
+
compareSemver: () => compareSemver,
|
|
43
|
+
createBridgedConnector: () => createBridgedConnector,
|
|
44
|
+
createHwkError: () => createHwkError,
|
|
45
|
+
deriveDeviceFingerprint: () => deriveDeviceFingerprint,
|
|
46
|
+
enrichErrorMessage: () => enrichErrorMessage,
|
|
47
|
+
ensure0x: () => ensure0x,
|
|
48
|
+
failure: () => failure,
|
|
49
|
+
hexToBytes: () => hexToBytes,
|
|
50
|
+
padHex64: () => padHex64,
|
|
51
|
+
rehydrateConnectorError: () => rehydrateConnectorError,
|
|
52
|
+
serializeConnectorError: () => serializeConnectorError,
|
|
53
|
+
stripHex: () => stripHex,
|
|
54
|
+
success: () => success
|
|
55
|
+
});
|
|
56
|
+
module.exports = __toCommonJS(index_exports);
|
|
57
|
+
|
|
58
|
+
// src/types/errors.ts
|
|
59
|
+
var HardwareErrorCode = /* @__PURE__ */ ((HardwareErrorCode2) => {
|
|
60
|
+
HardwareErrorCode2[HardwareErrorCode2["UnknownError"] = 1e4] = "UnknownError";
|
|
61
|
+
HardwareErrorCode2[HardwareErrorCode2["UserRejected"] = 10001] = "UserRejected";
|
|
62
|
+
HardwareErrorCode2[HardwareErrorCode2["InvalidParams"] = 10002] = "InvalidParams";
|
|
63
|
+
HardwareErrorCode2[HardwareErrorCode2["OperationTimeout"] = 10003] = "OperationTimeout";
|
|
64
|
+
HardwareErrorCode2[HardwareErrorCode2["MethodNotSupported"] = 10004] = "MethodNotSupported";
|
|
65
|
+
HardwareErrorCode2[HardwareErrorCode2["UserAborted"] = 10005] = "UserAborted";
|
|
66
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceNotFound"] = 10100] = "DeviceNotFound";
|
|
67
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceDisconnected"] = 10101] = "DeviceDisconnected";
|
|
68
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceBusy"] = 10102] = "DeviceBusy";
|
|
69
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceLocked"] = 10103] = "DeviceLocked";
|
|
70
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceNotInitialized"] = 10104] = "DeviceNotInitialized";
|
|
71
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceInBootloader"] = 10105] = "DeviceInBootloader";
|
|
72
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceMismatch"] = 10106] = "DeviceMismatch";
|
|
73
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceAppStuck"] = 10107] = "DeviceAppStuck";
|
|
74
|
+
HardwareErrorCode2[HardwareErrorCode2["ChainNotSupported"] = 10108] = "ChainNotSupported";
|
|
75
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceOneDeviceOnly"] = 10109] = "DeviceOneDeviceOnly";
|
|
76
|
+
HardwareErrorCode2[HardwareErrorCode2["FirmwareTooOld"] = 10200] = "FirmwareTooOld";
|
|
77
|
+
HardwareErrorCode2[HardwareErrorCode2["FirmwareUpdateRequired"] = 10201] = "FirmwareUpdateRequired";
|
|
78
|
+
HardwareErrorCode2[HardwareErrorCode2["TransportError"] = 10300] = "TransportError";
|
|
79
|
+
HardwareErrorCode2[HardwareErrorCode2["BridgeNotFound"] = 10301] = "BridgeNotFound";
|
|
80
|
+
HardwareErrorCode2[HardwareErrorCode2["TransportNotAvailable"] = 10302] = "TransportNotAvailable";
|
|
81
|
+
HardwareErrorCode2[HardwareErrorCode2["DevicePermissionDenied"] = 10303] = "DevicePermissionDenied";
|
|
82
|
+
HardwareErrorCode2[HardwareErrorCode2["BlePairingTimeout"] = 10304] = "BlePairingTimeout";
|
|
83
|
+
HardwareErrorCode2[HardwareErrorCode2["NetworkError"] = 10305] = "NetworkError";
|
|
84
|
+
HardwareErrorCode2[HardwareErrorCode2["PinInvalid"] = 10400] = "PinInvalid";
|
|
85
|
+
HardwareErrorCode2[HardwareErrorCode2["PinCancelled"] = 10401] = "PinCancelled";
|
|
86
|
+
HardwareErrorCode2[HardwareErrorCode2["PassphraseRejected"] = 10402] = "PassphraseRejected";
|
|
87
|
+
HardwareErrorCode2[HardwareErrorCode2["AppNotInstalled"] = 10500] = "AppNotInstalled";
|
|
88
|
+
HardwareErrorCode2[HardwareErrorCode2["WrongApp"] = 10501] = "WrongApp";
|
|
89
|
+
HardwareErrorCode2[HardwareErrorCode2["AppTooOld"] = 10502] = "AppTooOld";
|
|
90
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceOutOfMemory"] = 10503] = "DeviceOutOfMemory";
|
|
91
|
+
HardwareErrorCode2[HardwareErrorCode2["EvmBlindSigningRequired"] = 11e3] = "EvmBlindSigningRequired";
|
|
92
|
+
HardwareErrorCode2[HardwareErrorCode2["EvmClearSignPluginMissing"] = 11001] = "EvmClearSignPluginMissing";
|
|
93
|
+
HardwareErrorCode2[HardwareErrorCode2["EvmDataTooLarge"] = 11002] = "EvmDataTooLarge";
|
|
94
|
+
HardwareErrorCode2[HardwareErrorCode2["EvmTxTypeNotSupported"] = 11003] = "EvmTxTypeNotSupported";
|
|
95
|
+
HardwareErrorCode2[HardwareErrorCode2["SolanaBlindSigningRequired"] = 11100] = "SolanaBlindSigningRequired";
|
|
96
|
+
HardwareErrorCode2[HardwareErrorCode2["TronCustomContractRequired"] = 11200] = "TronCustomContractRequired";
|
|
97
|
+
HardwareErrorCode2[HardwareErrorCode2["TronDataSigningRequired"] = 11201] = "TronDataSigningRequired";
|
|
98
|
+
HardwareErrorCode2[HardwareErrorCode2["TronSignByHashRequired"] = 11202] = "TronSignByHashRequired";
|
|
99
|
+
HardwareErrorCode2[HardwareErrorCode2["BtcWalletPolicyHmacMismatch"] = 11300] = "BtcWalletPolicyHmacMismatch";
|
|
100
|
+
HardwareErrorCode2[HardwareErrorCode2["BtcUnexpectedState"] = 11301] = "BtcUnexpectedState";
|
|
101
|
+
return HardwareErrorCode2;
|
|
102
|
+
})(HardwareErrorCode || {});
|
|
103
|
+
var ORPHAN_ELIGIBLE_ERROR_CODES = [
|
|
104
|
+
10005 /* UserAborted */,
|
|
105
|
+
10001 /* UserRejected */,
|
|
106
|
+
10100 /* DeviceNotFound */,
|
|
107
|
+
10101 /* DeviceDisconnected */,
|
|
108
|
+
10106 /* DeviceMismatch */,
|
|
109
|
+
10107 /* DeviceAppStuck */,
|
|
110
|
+
10109 /* DeviceOneDeviceOnly */,
|
|
111
|
+
10300 /* TransportError */,
|
|
112
|
+
10303 /* DevicePermissionDenied */,
|
|
113
|
+
10304 /* BlePairingTimeout */
|
|
114
|
+
];
|
|
115
|
+
function createHwkError(payload) {
|
|
116
|
+
return Object.assign(new Error(payload.message), {
|
|
117
|
+
code: payload.code,
|
|
118
|
+
...payload._tag !== void 0 && { _tag: payload._tag },
|
|
119
|
+
...payload.appName !== void 0 && { appName: payload.appName },
|
|
120
|
+
...payload.params !== void 0 && { params: payload.params }
|
|
121
|
+
});
|
|
122
|
+
}
|
|
17
123
|
|
|
18
124
|
// src/types/response.ts
|
|
19
125
|
function success(payload) {
|
|
@@ -27,8 +133,8 @@ function failure(code, error, params) {
|
|
|
27
133
|
}
|
|
28
134
|
|
|
29
135
|
// src/types/fingerprint.ts
|
|
30
|
-
var
|
|
31
|
-
var
|
|
136
|
+
var import_sha256 = require("@noble/hashes/sha256");
|
|
137
|
+
var import_utils = require("@noble/hashes/utils");
|
|
32
138
|
var CHAIN_FINGERPRINT_PATHS = {
|
|
33
139
|
evm: "m/44'/60'/0'/0/0",
|
|
34
140
|
// BTC: account-level path (3 levels), mainnet cointype 0.
|
|
@@ -38,7 +144,7 @@ var CHAIN_FINGERPRINT_PATHS = {
|
|
|
38
144
|
tron: "m/44'/195'/0'/0/0"
|
|
39
145
|
};
|
|
40
146
|
function deriveDeviceFingerprint(value) {
|
|
41
|
-
return
|
|
147
|
+
return (0, import_utils.bytesToHex)((0, import_sha256.sha256)((0, import_utils.utf8ToBytes)(value))).slice(0, 16);
|
|
42
148
|
}
|
|
43
149
|
|
|
44
150
|
// src/events/device.ts
|
|
@@ -46,19 +152,43 @@ var DEVICE_EVENT = "DEVICE_EVENT";
|
|
|
46
152
|
var DEVICE = {
|
|
47
153
|
CONNECT: "device-connect",
|
|
48
154
|
DISCONNECT: "device-disconnect",
|
|
49
|
-
CHANGED: "device-changed"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
155
|
+
CHANGED: "device-changed"
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// src/events/ui-request.ts
|
|
159
|
+
var UI_EVENT = "UI_EVENT";
|
|
160
|
+
var UI_REQUEST = {
|
|
161
|
+
REQUEST_PIN: "ui-request-pin",
|
|
162
|
+
REQUEST_PASSPHRASE: "ui-request-passphrase",
|
|
163
|
+
REQUEST_PASSPHRASE_ON_DEVICE: "ui-request-passphrase-on-device",
|
|
164
|
+
REQUEST_BUTTON: "ui-request-button",
|
|
165
|
+
REQUEST_QR_DISPLAY: "ui-request-qr-display",
|
|
166
|
+
REQUEST_QR_SCAN: "ui-request-qr-scan",
|
|
167
|
+
REQUEST_DEVICE_PERMISSION: "ui-request-device-permission",
|
|
168
|
+
REQUEST_SELECT_DEVICE: "ui-request-select-device",
|
|
169
|
+
REQUEST_DEVICE_CONNECT: "ui-request-device-connect",
|
|
170
|
+
// Ledger BTC App: account index >= 100 requires display=true. Adapter asks
|
|
171
|
+
// the user once per session before promoting the call.
|
|
172
|
+
REQUEST_BTC_HIGH_INDEX_CONFIRM: "ui-request-btc-high-index-confirm",
|
|
173
|
+
// Required app is not installed; with autoInstallApp on, ask the user
|
|
174
|
+
// whether to install it before retrying the operation.
|
|
175
|
+
REQUEST_INSTALL_APP: "ui-request-install-app",
|
|
176
|
+
CLOSE_UI_WINDOW: "ui-close",
|
|
177
|
+
DEVICE_PROGRESS: "ui-device_progress",
|
|
178
|
+
FIRMWARE_PROGRESS: "ui-firmware-progress",
|
|
179
|
+
FIRMWARE_TIP: "ui-firmware-tip"
|
|
180
|
+
};
|
|
181
|
+
var UI_RESPONSE = {
|
|
182
|
+
RECEIVE_PIN: "receive-pin",
|
|
183
|
+
RECEIVE_PASSPHRASE: "receive-passphrase",
|
|
184
|
+
RECEIVE_PASSPHRASE_ON_DEVICE: "receive-passphrase-on-device",
|
|
185
|
+
RECEIVE_QR_RESPONSE: "receive-qr-response",
|
|
186
|
+
RECEIVE_SELECT_DEVICE: "receive-select-device",
|
|
187
|
+
RECEIVE_DEVICE_CONNECT: "receive-device-connect",
|
|
188
|
+
RECEIVE_DEVICE_PERMISSION: "receive-device-permission",
|
|
189
|
+
RECEIVE_BTC_HIGH_INDEX_CONFIRM: "receive-btc-high-index-confirm",
|
|
190
|
+
RECEIVE_INSTALL_APP: "receive-install-app",
|
|
191
|
+
CANCEL: "cancel"
|
|
62
192
|
};
|
|
63
193
|
|
|
64
194
|
// src/events/sdk.ts
|
|
@@ -85,7 +215,7 @@ var DeviceJobQueue = class {
|
|
|
85
215
|
*/
|
|
86
216
|
async enqueue(deviceId, job, options = {}) {
|
|
87
217
|
if (options.rejectIfBusy && this._jobs.size > 0) {
|
|
88
|
-
throw
|
|
218
|
+
throw options.busyError ?? new Error("Device is busy");
|
|
89
219
|
}
|
|
90
220
|
const ac = new AbortController();
|
|
91
221
|
const gen = this._generation;
|
|
@@ -101,7 +231,7 @@ var DeviceJobQueue = class {
|
|
|
101
231
|
const next = prev.catch(() => {
|
|
102
232
|
}).then(async () => {
|
|
103
233
|
if (this._generation !== gen) {
|
|
104
|
-
throw
|
|
234
|
+
throw this._generationCancelReasons.get(gen) ?? new Error("Job cancelled: queue was cleared");
|
|
105
235
|
}
|
|
106
236
|
this._active = activeJob;
|
|
107
237
|
try {
|
|
@@ -129,20 +259,20 @@ var DeviceJobQueue = class {
|
|
|
129
259
|
forceCancelActive(deviceId, reason) {
|
|
130
260
|
if (!this._active) return false;
|
|
131
261
|
if (deviceId && this._active.deviceId !== deviceId) return false;
|
|
132
|
-
this._active.abortController.abort(
|
|
262
|
+
this._active.abortController.abort(reason ?? new Error("Force cancelled for recovery"));
|
|
133
263
|
return true;
|
|
134
264
|
}
|
|
135
265
|
/** Cancel the active job (alias for callers that previously needed multi-device cancel). */
|
|
136
266
|
cancelAllActive(reason) {
|
|
137
267
|
if (!this._active) return;
|
|
138
|
-
this._active.abortController.abort(
|
|
268
|
+
this._active.abortController.abort(reason ?? new Error("Cancelled by cancelAllActive"));
|
|
139
269
|
}
|
|
140
270
|
/** Cancel the active job and invalidate queued jobs that have not started. */
|
|
141
271
|
cancelActiveAndPending(deviceId, reason) {
|
|
142
272
|
if (deviceId && this._active && this._active.deviceId !== deviceId) {
|
|
143
273
|
return false;
|
|
144
274
|
}
|
|
145
|
-
this.clear(
|
|
275
|
+
this.clear(reason ?? new Error("Cancelled by cancelActiveAndPending"));
|
|
146
276
|
return true;
|
|
147
277
|
}
|
|
148
278
|
/** Get info about the currently active job, or null if idle. */
|
|
@@ -162,7 +292,7 @@ var DeviceJobQueue = class {
|
|
|
162
292
|
clear(reason) {
|
|
163
293
|
const cancelledGeneration = this._generation;
|
|
164
294
|
this._generation++;
|
|
165
|
-
const cancelReason =
|
|
295
|
+
const cancelReason = reason ?? new Error("Job cancelled: queue was cleared");
|
|
166
296
|
this._generationCancelReasons.set(cancelledGeneration, cancelReason);
|
|
167
297
|
for (const generation of this._generationCancelReasons.keys()) {
|
|
168
298
|
if (generation < this._generation - 10) {
|
|
@@ -189,7 +319,7 @@ function createBridgedConnector(vendor, connectionType, bridge) {
|
|
|
189
319
|
const handlerMap = /* @__PURE__ */ new Map();
|
|
190
320
|
return {
|
|
191
321
|
connectionType,
|
|
192
|
-
searchDevices: (
|
|
322
|
+
searchDevices: () => bridge.searchDevices({ vendor }),
|
|
193
323
|
connect: (deviceId) => bridge.connect({ vendor, deviceId }),
|
|
194
324
|
disconnect: (sessionId) => bridge.disconnect({ vendor, sessionId }),
|
|
195
325
|
call: (sessionId, method, callParams) => bridge.call({ vendor, sessionId, method, callParams }),
|
|
@@ -211,14 +341,13 @@ function createBridgedConnector(vendor, connectionType, bridge) {
|
|
|
211
341
|
},
|
|
212
342
|
off: (event, handler) => {
|
|
213
343
|
const inner = handlerMap.get(event);
|
|
214
|
-
const bridgeHandler =
|
|
344
|
+
const bridgeHandler = inner?.get(handler);
|
|
215
345
|
if (!bridgeHandler || !inner) return;
|
|
216
346
|
bridge.offEvent({ vendor }, bridgeHandler);
|
|
217
347
|
inner.delete(handler);
|
|
218
348
|
if (inner.size === 0) handlerMap.delete(event);
|
|
219
349
|
},
|
|
220
|
-
reset: () => bridge.reset({ vendor })
|
|
221
|
-
setKnownCredentials: bridge.setKnownCredentials ? (credentials) => bridge.setKnownCredentials({ vendor, credentials }) : void 0
|
|
350
|
+
reset: () => bridge.reset({ vendor })
|
|
222
351
|
};
|
|
223
352
|
}
|
|
224
353
|
var SERIALIZED_ERROR_TOP_LEVEL_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -259,7 +388,7 @@ function serializeConnectorError(err) {
|
|
|
259
388
|
for (const key of Object.keys(params)) {
|
|
260
389
|
try {
|
|
261
390
|
JSON.stringify(params[key]);
|
|
262
|
-
} catch
|
|
391
|
+
} catch {
|
|
263
392
|
delete params[key];
|
|
264
393
|
}
|
|
265
394
|
}
|
|
@@ -275,225 +404,9 @@ function rehydrateConnectorError(error) {
|
|
|
275
404
|
return Object.assign(new Error(message), {
|
|
276
405
|
...code !== void 0 ? { code } : {},
|
|
277
406
|
...errorCode !== void 0 ? { errorCode } : {},
|
|
278
|
-
...
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
function isDeviceUnavailableError(error) {
|
|
282
|
-
const typed = error;
|
|
283
|
-
if (typed.code === 10100 /* DeviceNotFound */ || typed.code === 10101 /* DeviceDisconnected */) {
|
|
284
|
-
return true;
|
|
285
|
-
}
|
|
286
|
-
return false;
|
|
287
|
-
}
|
|
288
|
-
function combinedDeviceNotFoundError(message) {
|
|
289
|
-
return _chunkQD4EQWQAjs.createHwkError.call(void 0, {
|
|
290
|
-
code: 10100 /* DeviceNotFound */,
|
|
291
|
-
message
|
|
407
|
+
...params ?? {}
|
|
292
408
|
});
|
|
293
409
|
}
|
|
294
|
-
function combinedSessionNotFoundError(message) {
|
|
295
|
-
return _chunkQD4EQWQAjs.createHwkError.call(void 0, {
|
|
296
|
-
code: 10101 /* DeviceDisconnected */,
|
|
297
|
-
message
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
function createCombinedConnector(connectors) {
|
|
301
|
-
if (connectors.length === 0) {
|
|
302
|
-
throw new Error("createCombinedConnector: at least one connector is required");
|
|
303
|
-
}
|
|
304
|
-
const SEARCH_SETTLE_AFTER_FIRST_DEVICE_MS = 250;
|
|
305
|
-
const deviceOwner = /* @__PURE__ */ new Map();
|
|
306
|
-
const sessionOwner = /* @__PURE__ */ new Map();
|
|
307
|
-
const forwarders = /* @__PURE__ */ new Map();
|
|
308
|
-
const rank = (device) => device.connectionType === "ble" ? 1 : 0;
|
|
309
|
-
const sharedCredentials = [];
|
|
310
|
-
const credentialKey = (c) => _nullishCoalesce(c.credential, () => ( JSON.stringify(c)));
|
|
311
|
-
const mergeShared = (incoming) => {
|
|
312
|
-
let changed = false;
|
|
313
|
-
for (const cred of incoming) {
|
|
314
|
-
const key = credentialKey(cred);
|
|
315
|
-
if (!sharedCredentials.some((e) => credentialKey(e) === key)) {
|
|
316
|
-
sharedCredentials.push(cred);
|
|
317
|
-
changed = true;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return changed;
|
|
321
|
-
};
|
|
322
|
-
const broadcastCredentials = async () => {
|
|
323
|
-
await Promise.all(
|
|
324
|
-
connectors.map((child) => Promise.resolve(_optionalChain([child, 'access', _3 => _3.setKnownCredentials, 'optionalCall', _4 => _4(sharedCredentials)])))
|
|
325
|
-
);
|
|
326
|
-
};
|
|
327
|
-
for (const child of connectors) {
|
|
328
|
-
child.on("device-trezor-thp-credentials-changed", (data) => {
|
|
329
|
-
if (mergeShared(data.credentials)) void broadcastCredentials();
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
const searchDevices = async (options = {}) => {
|
|
333
|
-
const perConnector = [];
|
|
334
|
-
await new Promise((resolve) => {
|
|
335
|
-
let finished = false;
|
|
336
|
-
let remaining = connectors.length;
|
|
337
|
-
let settleTimer;
|
|
338
|
-
const finish = () => {
|
|
339
|
-
if (finished) return;
|
|
340
|
-
finished = true;
|
|
341
|
-
if (settleTimer) clearTimeout(settleTimer);
|
|
342
|
-
resolve();
|
|
343
|
-
};
|
|
344
|
-
connectors.forEach((child, index) => {
|
|
345
|
-
void child.searchDevices().then(
|
|
346
|
-
(devices) => devices.map((device) => ({
|
|
347
|
-
...device,
|
|
348
|
-
connectionType: _nullishCoalesce(device.connectionType, () => ( child.connectionType))
|
|
349
|
-
}))
|
|
350
|
-
).catch(
|
|
351
|
-
() => (
|
|
352
|
-
// A transport that can't scan (powered off, unauthorized, absent)
|
|
353
|
-
// must not fail the whole fused search.
|
|
354
|
-
[]
|
|
355
|
-
)
|
|
356
|
-
).then((devices) => {
|
|
357
|
-
remaining -= 1;
|
|
358
|
-
if (!finished) {
|
|
359
|
-
perConnector.push({ index, devices });
|
|
360
|
-
}
|
|
361
|
-
if (remaining === 0) {
|
|
362
|
-
finish();
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
const hasUsbDevice = devices.some((device) => device.connectionType === "usb");
|
|
366
|
-
if (hasUsbDevice && !settleTimer && !options.waitForAll) {
|
|
367
|
-
settleTimer = setTimeout(finish, SEARCH_SETTLE_AFTER_FIRST_DEVICE_MS);
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
perConnector.sort((a, b) => a.index - b.index);
|
|
373
|
-
deviceOwner.clear();
|
|
374
|
-
const merged = [];
|
|
375
|
-
perConnector.forEach(({ index, devices }) => {
|
|
376
|
-
for (const device of devices) {
|
|
377
|
-
deviceOwner.set(device.connectId, connectors[index]);
|
|
378
|
-
merged.push(device);
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
return merged.sort((a, b) => rank(a) - rank(b));
|
|
382
|
-
};
|
|
383
|
-
const resolveOwner = async (deviceId) => {
|
|
384
|
-
if (deviceId && deviceOwner.has(deviceId)) {
|
|
385
|
-
return { owner: deviceOwner.get(deviceId), deviceId };
|
|
386
|
-
}
|
|
387
|
-
const devices = await searchDevices({ waitForAll: Boolean(deviceId) });
|
|
388
|
-
if (deviceId) {
|
|
389
|
-
const owner = deviceOwner.get(deviceId);
|
|
390
|
-
if (!owner)
|
|
391
|
-
throw combinedDeviceNotFoundError(`Combined connector: device not found: ${deviceId}`);
|
|
392
|
-
return { owner, deviceId };
|
|
393
|
-
}
|
|
394
|
-
const first = devices[0];
|
|
395
|
-
if (!first) throw combinedDeviceNotFoundError("Combined connector: no devices found");
|
|
396
|
-
return { owner: deviceOwner.get(first.connectId), deviceId: first.connectId };
|
|
397
|
-
};
|
|
398
|
-
const connectByExplicitId = async (deviceId) => {
|
|
399
|
-
const cachedOwner = deviceOwner.get(deviceId);
|
|
400
|
-
if (cachedOwner) {
|
|
401
|
-
return { session: await cachedOwner.connect(deviceId), owner: cachedOwner };
|
|
402
|
-
}
|
|
403
|
-
let lastError;
|
|
404
|
-
for (const child of connectors) {
|
|
405
|
-
try {
|
|
406
|
-
const session = await child.connect(deviceId);
|
|
407
|
-
deviceOwner.set(deviceId, child);
|
|
408
|
-
return { session, owner: child };
|
|
409
|
-
} catch (error) {
|
|
410
|
-
if (!isDeviceUnavailableError(error)) {
|
|
411
|
-
throw error;
|
|
412
|
-
}
|
|
413
|
-
lastError = error;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
const message = lastError instanceof Error ? lastError.message : `Combined connector: device not found: ${deviceId}`;
|
|
417
|
-
throw _chunkQD4EQWQAjs.createHwkError.call(void 0, {
|
|
418
|
-
code: 10100 /* DeviceNotFound */,
|
|
419
|
-
message
|
|
420
|
-
});
|
|
421
|
-
};
|
|
422
|
-
return {
|
|
423
|
-
// Nominal value only — the per-device `connectionType` is authoritative
|
|
424
|
-
// for a fused connector.
|
|
425
|
-
connectionType: connectors[0].connectionType,
|
|
426
|
-
searchDevices: (options) => searchDevices({ waitForAll: _optionalChain([options, 'optionalAccess', _5 => _5.waitForAll]) }),
|
|
427
|
-
connect: async (deviceId) => {
|
|
428
|
-
let owner;
|
|
429
|
-
let session;
|
|
430
|
-
if (deviceId) {
|
|
431
|
-
({ session, owner } = await connectByExplicitId(deviceId));
|
|
432
|
-
} else {
|
|
433
|
-
const resolved = await resolveOwner();
|
|
434
|
-
owner = resolved.owner;
|
|
435
|
-
session = await owner.connect(resolved.deviceId);
|
|
436
|
-
}
|
|
437
|
-
sessionOwner.set(session.sessionId, owner);
|
|
438
|
-
return session;
|
|
439
|
-
},
|
|
440
|
-
disconnect: async (sessionId) => {
|
|
441
|
-
const owner = sessionOwner.get(sessionId);
|
|
442
|
-
if (!owner) return;
|
|
443
|
-
await owner.disconnect(sessionId);
|
|
444
|
-
sessionOwner.delete(sessionId);
|
|
445
|
-
},
|
|
446
|
-
call: async (sessionId, method, params) => {
|
|
447
|
-
const owner = sessionOwner.get(sessionId);
|
|
448
|
-
if (!owner) {
|
|
449
|
-
throw combinedSessionNotFoundError(`Combined connector: session not found: ${sessionId}`);
|
|
450
|
-
}
|
|
451
|
-
return owner.call(sessionId, method, params);
|
|
452
|
-
},
|
|
453
|
-
cancel: async (sessionId) => {
|
|
454
|
-
const owner = sessionOwner.get(sessionId);
|
|
455
|
-
if (!owner) return;
|
|
456
|
-
await owner.cancel(sessionId);
|
|
457
|
-
},
|
|
458
|
-
uiResponse: (response) => {
|
|
459
|
-
for (const child of connectors) child.uiResponse(response);
|
|
460
|
-
},
|
|
461
|
-
on: (event, handler) => {
|
|
462
|
-
const attached = connectors.map((child) => {
|
|
463
|
-
const forward = (data) => handler(data);
|
|
464
|
-
child.on(event, forward);
|
|
465
|
-
return { child, handler: forward };
|
|
466
|
-
});
|
|
467
|
-
let inner = forwarders.get(event);
|
|
468
|
-
if (!inner) {
|
|
469
|
-
inner = /* @__PURE__ */ new Map();
|
|
470
|
-
forwarders.set(event, inner);
|
|
471
|
-
}
|
|
472
|
-
inner.set(handler, attached);
|
|
473
|
-
},
|
|
474
|
-
off: (event, handler) => {
|
|
475
|
-
const inner = forwarders.get(event);
|
|
476
|
-
const attached = _optionalChain([inner, 'optionalAccess', _6 => _6.get, 'call', _7 => _7(handler)]);
|
|
477
|
-
if (!attached || !inner) return;
|
|
478
|
-
for (const { child, handler: forward } of attached) {
|
|
479
|
-
child.off(event, forward);
|
|
480
|
-
}
|
|
481
|
-
inner.delete(handler);
|
|
482
|
-
if (inner.size === 0) forwarders.delete(event);
|
|
483
|
-
},
|
|
484
|
-
reset: () => {
|
|
485
|
-
for (const child of connectors) child.reset();
|
|
486
|
-
deviceOwner.clear();
|
|
487
|
-
sessionOwner.clear();
|
|
488
|
-
forwarders.clear();
|
|
489
|
-
},
|
|
490
|
-
setKnownCredentials: connectors.some((c) => c.setKnownCredentials) ? async (credentials) => {
|
|
491
|
-
sharedCredentials.length = 0;
|
|
492
|
-
mergeShared(_nullishCoalesce(credentials, () => ( [])));
|
|
493
|
-
await broadcastCredentials();
|
|
494
|
-
} : void 0
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
410
|
|
|
498
411
|
// src/utils/TypedEventEmitter.ts
|
|
499
412
|
var TypedEventEmitter = class {
|
|
@@ -525,9 +438,103 @@ var TypedEventEmitter = class {
|
|
|
525
438
|
removeAllListeners() {
|
|
526
439
|
this._listeners.clear();
|
|
527
440
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
// src/utils/UiRequestRegistry.ts
|
|
444
|
+
var UI_REQUEST_DEFAULT_TIMEOUT_MS = 6e5;
|
|
445
|
+
var RESPONSE_TO_REQUEST = {
|
|
446
|
+
[UI_RESPONSE.RECEIVE_PIN]: UI_REQUEST.REQUEST_PIN,
|
|
447
|
+
[UI_RESPONSE.RECEIVE_PASSPHRASE]: UI_REQUEST.REQUEST_PASSPHRASE,
|
|
448
|
+
[UI_RESPONSE.RECEIVE_PASSPHRASE_ON_DEVICE]: UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE,
|
|
449
|
+
[UI_RESPONSE.RECEIVE_SELECT_DEVICE]: UI_REQUEST.REQUEST_SELECT_DEVICE,
|
|
450
|
+
[UI_RESPONSE.RECEIVE_DEVICE_CONNECT]: UI_REQUEST.REQUEST_DEVICE_CONNECT,
|
|
451
|
+
[UI_RESPONSE.RECEIVE_DEVICE_PERMISSION]: UI_REQUEST.REQUEST_DEVICE_PERMISSION,
|
|
452
|
+
[UI_RESPONSE.RECEIVE_BTC_HIGH_INDEX_CONFIRM]: UI_REQUEST.REQUEST_BTC_HIGH_INDEX_CONFIRM,
|
|
453
|
+
[UI_RESPONSE.RECEIVE_INSTALL_APP]: UI_REQUEST.REQUEST_INSTALL_APP
|
|
454
|
+
// RECEIVE_QR_RESPONSE maps to QR_DISPLAY or QR_SCAN — resolved dynamically below.
|
|
455
|
+
};
|
|
456
|
+
var UI_REQUEST_PREEMPTED_TAG = "UiRequestPreempted";
|
|
457
|
+
var UI_REQUEST_CANCELLED_TAG = "UiRequestCancelled";
|
|
458
|
+
var UI_REQUEST_TIMEOUT_TAG = "UiRequestTimeout";
|
|
459
|
+
var UiRequestRegistry = class {
|
|
460
|
+
constructor() {
|
|
461
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
462
|
+
}
|
|
463
|
+
wait(requestType, options) {
|
|
464
|
+
const existing = this.pending.get(requestType);
|
|
465
|
+
if (existing) {
|
|
466
|
+
clearTimeout(existing.timer);
|
|
467
|
+
this.pending.delete(requestType);
|
|
468
|
+
existing.reject(
|
|
469
|
+
Object.assign(new Error(`UI request '${requestType}' was superseded by a new request`), {
|
|
470
|
+
_tag: UI_REQUEST_PREEMPTED_TAG
|
|
471
|
+
})
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
const timeoutMs = options?.timeoutMs ?? UI_REQUEST_DEFAULT_TIMEOUT_MS;
|
|
475
|
+
return new Promise((resolve, reject) => {
|
|
476
|
+
const timer = setTimeout(() => {
|
|
477
|
+
if (this.pending.get(requestType)?.timer === timer) {
|
|
478
|
+
this.pending.delete(requestType);
|
|
479
|
+
reject(
|
|
480
|
+
Object.assign(new Error(`UI request '${requestType}' timed out after ${timeoutMs}ms`), {
|
|
481
|
+
_tag: UI_REQUEST_TIMEOUT_TAG
|
|
482
|
+
})
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
}, timeoutMs);
|
|
486
|
+
this.pending.set(requestType, {
|
|
487
|
+
resolve,
|
|
488
|
+
reject,
|
|
489
|
+
timer
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
resolve(responseType, payload) {
|
|
494
|
+
let requestType = RESPONSE_TO_REQUEST[responseType];
|
|
495
|
+
if (responseType === UI_RESPONSE.RECEIVE_QR_RESPONSE) {
|
|
496
|
+
if (this.pending.has(UI_REQUEST.REQUEST_QR_DISPLAY)) {
|
|
497
|
+
requestType = UI_REQUEST.REQUEST_QR_DISPLAY;
|
|
498
|
+
} else if (this.pending.has(UI_REQUEST.REQUEST_QR_SCAN)) {
|
|
499
|
+
requestType = UI_REQUEST.REQUEST_QR_SCAN;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (!requestType) return;
|
|
503
|
+
const entry = this.pending.get(requestType);
|
|
504
|
+
if (!entry) return;
|
|
505
|
+
clearTimeout(entry.timer);
|
|
506
|
+
this.pending.delete(requestType);
|
|
507
|
+
entry.resolve(payload);
|
|
508
|
+
}
|
|
509
|
+
cancel(requestType) {
|
|
510
|
+
if (requestType) {
|
|
511
|
+
const entry = this.pending.get(requestType);
|
|
512
|
+
if (!entry) return;
|
|
513
|
+
clearTimeout(entry.timer);
|
|
514
|
+
this.pending.delete(requestType);
|
|
515
|
+
entry.reject(
|
|
516
|
+
Object.assign(new Error(`UI request '${requestType}' was cancelled`), {
|
|
517
|
+
_tag: UI_REQUEST_CANCELLED_TAG
|
|
518
|
+
})
|
|
519
|
+
);
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
for (const [type, entry] of this.pending) {
|
|
523
|
+
clearTimeout(entry.timer);
|
|
524
|
+
entry.reject(
|
|
525
|
+
Object.assign(new Error(`UI request '${type}' was cancelled`), {
|
|
526
|
+
_tag: UI_REQUEST_CANCELLED_TAG
|
|
527
|
+
})
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
this.pending.clear();
|
|
531
|
+
}
|
|
532
|
+
reset() {
|
|
533
|
+
this.cancel();
|
|
534
|
+
}
|
|
535
|
+
hasPending(requestType) {
|
|
536
|
+
if (requestType) return this.pending.has(requestType);
|
|
537
|
+
return this.pending.size > 0;
|
|
531
538
|
}
|
|
532
539
|
};
|
|
533
540
|
|
|
@@ -536,8 +543,8 @@ function compareSemver(a, b) {
|
|
|
536
543
|
const pa = a.split(".").map(Number);
|
|
537
544
|
const pb = b.split(".").map(Number);
|
|
538
545
|
for (let i = 0; i < 3; i++) {
|
|
539
|
-
const va =
|
|
540
|
-
const vb =
|
|
546
|
+
const va = pa[i] ?? 0;
|
|
547
|
+
const vb = pb[i] ?? 0;
|
|
541
548
|
if (va < vb) return -1;
|
|
542
549
|
if (va > vb) return 1;
|
|
543
550
|
}
|
|
@@ -545,7 +552,7 @@ function compareSemver(a, b) {
|
|
|
545
552
|
}
|
|
546
553
|
|
|
547
554
|
// src/utils/hex.ts
|
|
548
|
-
|
|
555
|
+
var import_utils2 = require("@noble/hashes/utils");
|
|
549
556
|
function ensure0x(hex) {
|
|
550
557
|
return hex.startsWith("0x") ? hex : `0x${hex}`;
|
|
551
558
|
}
|
|
@@ -556,43 +563,70 @@ function padHex64(hex) {
|
|
|
556
563
|
return `0x${stripHex(hex).padStart(64, "0")}`;
|
|
557
564
|
}
|
|
558
565
|
function hexToBytes(hex) {
|
|
559
|
-
return
|
|
566
|
+
return (0, import_utils2.hexToBytes)(stripHex(hex));
|
|
560
567
|
}
|
|
561
568
|
function bytesToHex2(bytes) {
|
|
562
|
-
return
|
|
569
|
+
return (0, import_utils2.bytesToHex)(bytes);
|
|
563
570
|
}
|
|
564
571
|
|
|
565
|
-
// src/utils/
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
572
|
+
// src/utils/errorMessages.ts
|
|
573
|
+
function enrichErrorMessage(code, originalMessage) {
|
|
574
|
+
switch (code) {
|
|
575
|
+
case 10400 /* PinInvalid */:
|
|
576
|
+
return `${originalMessage}. Please re-enter your PIN.`;
|
|
577
|
+
case 10401 /* PinCancelled */:
|
|
578
|
+
return `${originalMessage}. PIN entry was cancelled.`;
|
|
579
|
+
case 10102 /* DeviceBusy */:
|
|
580
|
+
return `${originalMessage}. The device is in use by another application. Close other wallet apps and try again.`;
|
|
581
|
+
case 10101 /* DeviceDisconnected */:
|
|
582
|
+
return `${originalMessage}. Please reconnect the device and try again.`;
|
|
583
|
+
case 10103 /* DeviceLocked */:
|
|
584
|
+
return `${originalMessage}. Please unlock your device and try again.`;
|
|
585
|
+
case 10109 /* DeviceOneDeviceOnly */:
|
|
586
|
+
return `${originalMessage}. Disconnect the extra device and try again.`;
|
|
587
|
+
case 10001 /* UserRejected */:
|
|
588
|
+
return `${originalMessage}. The request was rejected on the device.`;
|
|
589
|
+
case 10501 /* WrongApp */:
|
|
590
|
+
return `${originalMessage}. Please open the correct app on your device.`;
|
|
591
|
+
case 10500 /* AppNotInstalled */:
|
|
592
|
+
return `${originalMessage}. The required app is not installed on the device.`;
|
|
593
|
+
case 10503 /* DeviceOutOfMemory */:
|
|
594
|
+
return `${originalMessage}. Not enough free space on the device. Please uninstall some apps and try again.`;
|
|
595
|
+
case 10302 /* TransportNotAvailable */:
|
|
596
|
+
return `${originalMessage}. Ensure the device bridge/transport is available and running.`;
|
|
597
|
+
case 10305 /* NetworkError */:
|
|
598
|
+
return `${originalMessage}. Network error \u2014 check your internet connection and try again.`;
|
|
599
|
+
case 10200 /* FirmwareTooOld */:
|
|
600
|
+
return `${originalMessage}. Please update your device firmware.`;
|
|
601
|
+
case 10104 /* DeviceNotInitialized */:
|
|
602
|
+
return `${originalMessage}. The device may need to be set up first.`;
|
|
603
|
+
case 10003 /* OperationTimeout */:
|
|
604
|
+
return `${originalMessage}. The operation timed out. Please try again.`;
|
|
605
|
+
case 11e3 /* EvmBlindSigningRequired */:
|
|
606
|
+
return "Ledger: Blind signing not enabled in Ethereum app.";
|
|
607
|
+
case 11001 /* EvmClearSignPluginMissing */:
|
|
608
|
+
return "Ledger: Required plugin not installed (install via Ledger Live).";
|
|
609
|
+
case 11002 /* EvmDataTooLarge */:
|
|
610
|
+
return "Ledger: Transaction data too large for device memory.";
|
|
611
|
+
case 11003 /* EvmTxTypeNotSupported */:
|
|
612
|
+
return "Ledger: Transaction type not supported by current Ethereum app.";
|
|
613
|
+
case 10502 /* AppTooOld */:
|
|
614
|
+
return "Ledger: App out of date (update via Ledger Live).";
|
|
615
|
+
case 11100 /* SolanaBlindSigningRequired */:
|
|
616
|
+
return "Blind signing disabled in the Solana app.";
|
|
617
|
+
case 11200 /* TronCustomContractRequired */:
|
|
618
|
+
return "Custom Contracts setting disabled in the Tron app.";
|
|
619
|
+
case 11201 /* TronDataSigningRequired */:
|
|
620
|
+
return "Transactions Data setting disabled in the Tron app.";
|
|
621
|
+
case 11202 /* TronSignByHashRequired */:
|
|
622
|
+
return "Sign by Hash setting disabled in the Tron app.";
|
|
623
|
+
case 11300 /* BtcWalletPolicyHmacMismatch */:
|
|
624
|
+
return "Wallet policy not registered or HMAC mismatch.";
|
|
625
|
+
case 11301 /* BtcUnexpectedState */:
|
|
626
|
+
return "Signing aborted due to unexpected device state.";
|
|
627
|
+
default:
|
|
628
|
+
return originalMessage;
|
|
590
629
|
}
|
|
591
|
-
return void 0;
|
|
592
|
-
}
|
|
593
|
-
function isKnownNonTargetHardwareVendor(input, targetVendor) {
|
|
594
|
-
const detectedVendor = detectHardwareVendorFromDescriptor(input);
|
|
595
|
-
return detectedVendor !== void 0 && detectedVendor !== targetVendor;
|
|
596
630
|
}
|
|
597
631
|
|
|
598
632
|
// src/utils/batchCall.ts
|
|
@@ -604,161 +638,43 @@ async function batchCall(params, callFn, onProgress) {
|
|
|
604
638
|
return result;
|
|
605
639
|
}
|
|
606
640
|
results.push(result.payload);
|
|
607
|
-
|
|
641
|
+
onProgress?.({ index: i, total: params.length });
|
|
608
642
|
}
|
|
609
643
|
return { success: true, payload: results };
|
|
610
644
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
deviceId,
|
|
647
|
-
params,
|
|
648
|
-
getMethodChain = (method) => getAllNetworkMethodChain(method),
|
|
649
|
-
normalizeItem = (_method, item) => item,
|
|
650
|
-
buildUnsupportedNetworkResponse,
|
|
651
|
-
callItem,
|
|
652
|
-
attachIdentity,
|
|
653
|
-
shouldAbortBundle = () => false,
|
|
654
|
-
buildTopLevelFailure = defaultBuildTopLevelFailure
|
|
655
|
-
}) {
|
|
656
|
-
const responses = [];
|
|
657
|
-
for (const [index, item] of params.bundle.entries()) {
|
|
658
|
-
if (!isAllNetworkMethodName(String(item.methodName))) {
|
|
659
|
-
responses.push(buildUnsupportedMethodResponse(item));
|
|
660
|
-
continue;
|
|
661
|
-
}
|
|
662
|
-
const method = item.methodName;
|
|
663
|
-
const unsupportedNetwork = _optionalChain([buildUnsupportedNetworkResponse, 'optionalCall', _17 => _17(item, method)]);
|
|
664
|
-
if (unsupportedNetwork) {
|
|
665
|
-
responses.push(unsupportedNetwork);
|
|
666
|
-
continue;
|
|
667
|
-
}
|
|
668
|
-
const chain = getMethodChain(method, item);
|
|
669
|
-
const normalizedItem = normalizeItem(method, item);
|
|
670
|
-
const context = {
|
|
671
|
-
connectId,
|
|
672
|
-
deviceId,
|
|
673
|
-
method,
|
|
674
|
-
chain,
|
|
675
|
-
item: normalizedItem,
|
|
676
|
-
index
|
|
677
|
-
};
|
|
678
|
-
const response = await callItem(context);
|
|
679
|
-
const itemResponse = response.success ? await attachIdentity({
|
|
680
|
-
...context,
|
|
681
|
-
payload: response.payload
|
|
682
|
-
}) : {
|
|
683
|
-
...normalizedItem,
|
|
684
|
-
success: false,
|
|
685
|
-
payload: response.payload
|
|
686
|
-
};
|
|
687
|
-
const responseContext = { ...context, response: itemResponse };
|
|
688
|
-
if (!itemResponse.success && shouldAbortBundle(itemResponse, responseContext)) {
|
|
689
|
-
return buildTopLevelFailure(itemResponse, responseContext);
|
|
690
|
-
}
|
|
691
|
-
responses.push(itemResponse);
|
|
692
|
-
}
|
|
693
|
-
return success(responses);
|
|
694
|
-
}
|
|
695
|
-
function buildUnsupportedMethodResponse(item) {
|
|
696
|
-
return {
|
|
697
|
-
...item,
|
|
698
|
-
success: false,
|
|
699
|
-
payload: {
|
|
700
|
-
code: 10002 /* InvalidParams */,
|
|
701
|
-
error: `Unsupported allNetwork method: ${String(item.methodName)}`
|
|
702
|
-
}
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
function defaultBuildTopLevelFailure(response) {
|
|
706
|
-
const payload = _nullishCoalesce(response.payload, () => ( {}));
|
|
707
|
-
return failure(
|
|
708
|
-
_nullishCoalesce(payload.code, () => ( 10106)) /* DeviceMismatch */,
|
|
709
|
-
_nullishCoalesce(payload.error, () => ( "All-network get-address aborted")),
|
|
710
|
-
normalizeFailureParams(payload.params)
|
|
711
|
-
);
|
|
712
|
-
}
|
|
713
|
-
function normalizeFailureParams(params) {
|
|
714
|
-
return params && typeof params === "object" ? params : void 0;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
// src/constants.ts
|
|
718
|
-
var DEVICE_CONNECT_RETRY_DELAY_MS = 1e3;
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
exports.ALL_NETWORK_METHOD_NAMES = ALL_NETWORK_METHOD_NAMES; exports.CHAIN_FINGERPRINT_PATHS = CHAIN_FINGERPRINT_PATHS; exports.DEVICE = DEVICE; exports.DEVICE_CONNECT_RETRY_DELAY_MS = DEVICE_CONNECT_RETRY_DELAY_MS; exports.DEVICE_EVENT = DEVICE_EVENT; exports.DeviceJobQueue = DeviceJobQueue; exports.EConnectorInteraction = EConnectorInteraction; exports.HARDWARE_METHOD_CATALOG = HARDWARE_METHOD_CATALOG; exports.HardwareErrorCode = _chunkQD4EQWQAjs.HardwareErrorCode; exports.ORPHAN_ELIGIBLE_ERROR_CODES = _chunkQD4EQWQAjs.ORPHAN_ELIGIBLE_ERROR_CODES; exports.SDK = SDK; exports.TypedEventEmitter = TypedEventEmitter; exports.UI_EVENT = _chunkLYVS67EXjs.UI_EVENT; exports.UI_REQUEST = _chunkLYVS67EXjs.UI_REQUEST; exports.UI_REQUEST_CANCELLED_TAG = _chunkLYVS67EXjs.UI_REQUEST_CANCELLED_TAG; exports.UI_REQUEST_DEFAULT_TIMEOUT_MS = _chunkLYVS67EXjs.UI_REQUEST_DEFAULT_TIMEOUT_MS; exports.UI_REQUEST_PREEMPTED_TAG = _chunkLYVS67EXjs.UI_REQUEST_PREEMPTED_TAG; exports.UI_REQUEST_TIMEOUT_TAG = _chunkLYVS67EXjs.UI_REQUEST_TIMEOUT_TAG; exports.UI_RESPONSE = _chunkLYVS67EXjs.UI_RESPONSE; exports.UiRequestRegistry = _chunkLYVS67EXjs.UiRequestRegistry; exports.batchCall = batchCall; exports.buildUnsupportedMethodResponse = buildUnsupportedMethodResponse; exports.bytesToHex = bytesToHex2; exports.compareSemver = compareSemver; exports.createBridgedConnector = createBridgedConnector; exports.createCombinedConnector = createCombinedConnector; exports.createHwkError = _chunkQD4EQWQAjs.createHwkError; exports.deriveDeviceFingerprint = deriveDeviceFingerprint; exports.detectHardwareVendorFromDescriptor = detectHardwareVendorFromDescriptor; exports.enrichErrorMessage = _chunkQD4EQWQAjs.enrichErrorMessage; exports.ensure0x = ensure0x; exports.failure = failure; exports.getAllNetworkMethodChain = getAllNetworkMethodChain; exports.getHardwareMethodMetadata = getHardwareMethodMetadata; exports.hexToBytes = hexToBytes; exports.isAllNetworkMethodName = isAllNetworkMethodName; exports.isKnownNonTargetHardwareVendor = isKnownNonTargetHardwareVendor; exports.padHex64 = padHex64; exports.rehydrateConnectorError = rehydrateConnectorError; exports.runAllNetworkGetAddress = runAllNetworkGetAddress; exports.serializeConnectorError = serializeConnectorError; exports.stripHex = stripHex; exports.success = success;
|
|
645
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
646
|
+
0 && (module.exports = {
|
|
647
|
+
CHAIN_FINGERPRINT_PATHS,
|
|
648
|
+
DEVICE,
|
|
649
|
+
DEVICE_EVENT,
|
|
650
|
+
DeviceJobQueue,
|
|
651
|
+
EConnectorInteraction,
|
|
652
|
+
HardwareErrorCode,
|
|
653
|
+
ORPHAN_ELIGIBLE_ERROR_CODES,
|
|
654
|
+
SDK,
|
|
655
|
+
TypedEventEmitter,
|
|
656
|
+
UI_EVENT,
|
|
657
|
+
UI_REQUEST,
|
|
658
|
+
UI_REQUEST_CANCELLED_TAG,
|
|
659
|
+
UI_REQUEST_DEFAULT_TIMEOUT_MS,
|
|
660
|
+
UI_REQUEST_PREEMPTED_TAG,
|
|
661
|
+
UI_REQUEST_TIMEOUT_TAG,
|
|
662
|
+
UI_RESPONSE,
|
|
663
|
+
UiRequestRegistry,
|
|
664
|
+
batchCall,
|
|
665
|
+
bytesToHex,
|
|
666
|
+
compareSemver,
|
|
667
|
+
createBridgedConnector,
|
|
668
|
+
createHwkError,
|
|
669
|
+
deriveDeviceFingerprint,
|
|
670
|
+
enrichErrorMessage,
|
|
671
|
+
ensure0x,
|
|
672
|
+
failure,
|
|
673
|
+
hexToBytes,
|
|
674
|
+
padHex64,
|
|
675
|
+
rehydrateConnectorError,
|
|
676
|
+
serializeConnectorError,
|
|
677
|
+
stripHex,
|
|
678
|
+
success
|
|
679
|
+
});
|
|
764
680
|
//# sourceMappingURL=index.js.map
|