@onekeyfe/hwk-adapter-core 1.2.0-alpha.12 → 1.2.0-alpha.13
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/chunk-BAGEFFFY.js +151 -0
- package/dist/chunk-BAGEFFFY.js.map +1 -0
- package/dist/chunk-FT3SZP2W.js +149 -0
- package/dist/chunk-FT3SZP2W.js.map +1 -0
- package/dist/chunk-U63HTLGJ.mjs +151 -0
- package/dist/chunk-U63HTLGJ.mjs.map +1 -0
- package/dist/chunk-XGIIA4A4.mjs +149 -0
- package/dist/chunk-XGIIA4A4.mjs.map +1 -0
- package/dist/errors.d.mts +197 -0
- package/dist/errors.d.ts +197 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/errors.mjs +13 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.d.mts +657 -274
- package/dist/index.d.ts +657 -274
- package/dist/index.js +452 -355
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +401 -247
- package/dist/index.mjs.map +1 -1
- package/dist/ui-events-Cb7haAeE.d.mts +128 -0
- package/dist/ui-events-Cb7haAeE.d.ts +128 -0
- package/dist/ui-events.d.mts +1 -0
- package/dist/ui-events.d.ts +1 -0
- package/dist/ui-events.js +21 -0
- package/dist/ui-events.js.map +1 -0
- package/dist/ui-events.mjs +21 -0
- package/dist/ui-events.mjs.map +1 -0
- package/package.json +22 -2
package/dist/index.js
CHANGED
|
@@ -1,115 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
deriveDeviceFingerprint: () => deriveDeviceFingerprint,
|
|
45
|
-
enrichErrorMessage: () => enrichErrorMessage,
|
|
46
|
-
ensure0x: () => ensure0x,
|
|
47
|
-
failure: () => failure,
|
|
48
|
-
hexToBytes: () => hexToBytes,
|
|
49
|
-
padHex64: () => padHex64,
|
|
50
|
-
rehydrateConnectorError: () => rehydrateConnectorError,
|
|
51
|
-
serializeConnectorError: () => serializeConnectorError,
|
|
52
|
-
stripHex: () => stripHex,
|
|
53
|
-
success: () => success
|
|
54
|
-
});
|
|
55
|
-
module.exports = __toCommonJS(index_exports);
|
|
56
|
-
|
|
57
|
-
// src/types/errors.ts
|
|
58
|
-
var HardwareErrorCode = /* @__PURE__ */ ((HardwareErrorCode2) => {
|
|
59
|
-
HardwareErrorCode2[HardwareErrorCode2["UnknownError"] = 1e4] = "UnknownError";
|
|
60
|
-
HardwareErrorCode2[HardwareErrorCode2["UserRejected"] = 10001] = "UserRejected";
|
|
61
|
-
HardwareErrorCode2[HardwareErrorCode2["InvalidParams"] = 10002] = "InvalidParams";
|
|
62
|
-
HardwareErrorCode2[HardwareErrorCode2["OperationTimeout"] = 10003] = "OperationTimeout";
|
|
63
|
-
HardwareErrorCode2[HardwareErrorCode2["MethodNotSupported"] = 10004] = "MethodNotSupported";
|
|
64
|
-
HardwareErrorCode2[HardwareErrorCode2["UserAborted"] = 10005] = "UserAborted";
|
|
65
|
-
HardwareErrorCode2[HardwareErrorCode2["DeviceNotFound"] = 10100] = "DeviceNotFound";
|
|
66
|
-
HardwareErrorCode2[HardwareErrorCode2["DeviceDisconnected"] = 10101] = "DeviceDisconnected";
|
|
67
|
-
HardwareErrorCode2[HardwareErrorCode2["DeviceBusy"] = 10102] = "DeviceBusy";
|
|
68
|
-
HardwareErrorCode2[HardwareErrorCode2["DeviceLocked"] = 10103] = "DeviceLocked";
|
|
69
|
-
HardwareErrorCode2[HardwareErrorCode2["DeviceNotInitialized"] = 10104] = "DeviceNotInitialized";
|
|
70
|
-
HardwareErrorCode2[HardwareErrorCode2["DeviceInBootloader"] = 10105] = "DeviceInBootloader";
|
|
71
|
-
HardwareErrorCode2[HardwareErrorCode2["DeviceMismatch"] = 10106] = "DeviceMismatch";
|
|
72
|
-
HardwareErrorCode2[HardwareErrorCode2["DeviceAppStuck"] = 10107] = "DeviceAppStuck";
|
|
73
|
-
HardwareErrorCode2[HardwareErrorCode2["ChainNotSupported"] = 10108] = "ChainNotSupported";
|
|
74
|
-
HardwareErrorCode2[HardwareErrorCode2["DeviceOneDeviceOnly"] = 10109] = "DeviceOneDeviceOnly";
|
|
75
|
-
HardwareErrorCode2[HardwareErrorCode2["FirmwareTooOld"] = 10200] = "FirmwareTooOld";
|
|
76
|
-
HardwareErrorCode2[HardwareErrorCode2["FirmwareUpdateRequired"] = 10201] = "FirmwareUpdateRequired";
|
|
77
|
-
HardwareErrorCode2[HardwareErrorCode2["TransportError"] = 10300] = "TransportError";
|
|
78
|
-
HardwareErrorCode2[HardwareErrorCode2["BridgeNotFound"] = 10301] = "BridgeNotFound";
|
|
79
|
-
HardwareErrorCode2[HardwareErrorCode2["TransportNotAvailable"] = 10302] = "TransportNotAvailable";
|
|
80
|
-
HardwareErrorCode2[HardwareErrorCode2["DevicePermissionDenied"] = 10303] = "DevicePermissionDenied";
|
|
81
|
-
HardwareErrorCode2[HardwareErrorCode2["BlePairingTimeout"] = 10304] = "BlePairingTimeout";
|
|
82
|
-
HardwareErrorCode2[HardwareErrorCode2["PinInvalid"] = 10400] = "PinInvalid";
|
|
83
|
-
HardwareErrorCode2[HardwareErrorCode2["PinCancelled"] = 10401] = "PinCancelled";
|
|
84
|
-
HardwareErrorCode2[HardwareErrorCode2["PassphraseRejected"] = 10402] = "PassphraseRejected";
|
|
85
|
-
HardwareErrorCode2[HardwareErrorCode2["AppNotInstalled"] = 10500] = "AppNotInstalled";
|
|
86
|
-
HardwareErrorCode2[HardwareErrorCode2["WrongApp"] = 10501] = "WrongApp";
|
|
87
|
-
HardwareErrorCode2[HardwareErrorCode2["AppTooOld"] = 10502] = "AppTooOld";
|
|
88
|
-
HardwareErrorCode2[HardwareErrorCode2["DeviceOutOfMemory"] = 10503] = "DeviceOutOfMemory";
|
|
89
|
-
HardwareErrorCode2[HardwareErrorCode2["EvmBlindSigningRequired"] = 11e3] = "EvmBlindSigningRequired";
|
|
90
|
-
HardwareErrorCode2[HardwareErrorCode2["EvmClearSignPluginMissing"] = 11001] = "EvmClearSignPluginMissing";
|
|
91
|
-
HardwareErrorCode2[HardwareErrorCode2["EvmDataTooLarge"] = 11002] = "EvmDataTooLarge";
|
|
92
|
-
HardwareErrorCode2[HardwareErrorCode2["EvmTxTypeNotSupported"] = 11003] = "EvmTxTypeNotSupported";
|
|
93
|
-
HardwareErrorCode2[HardwareErrorCode2["SolanaBlindSigningRequired"] = 11100] = "SolanaBlindSigningRequired";
|
|
94
|
-
HardwareErrorCode2[HardwareErrorCode2["TronCustomContractRequired"] = 11200] = "TronCustomContractRequired";
|
|
95
|
-
HardwareErrorCode2[HardwareErrorCode2["TronDataSigningRequired"] = 11201] = "TronDataSigningRequired";
|
|
96
|
-
HardwareErrorCode2[HardwareErrorCode2["TronSignByHashRequired"] = 11202] = "TronSignByHashRequired";
|
|
97
|
-
HardwareErrorCode2[HardwareErrorCode2["BtcWalletPolicyHmacMismatch"] = 11300] = "BtcWalletPolicyHmacMismatch";
|
|
98
|
-
HardwareErrorCode2[HardwareErrorCode2["BtcUnexpectedState"] = 11301] = "BtcUnexpectedState";
|
|
99
|
-
return HardwareErrorCode2;
|
|
100
|
-
})(HardwareErrorCode || {});
|
|
101
|
-
var ORPHAN_ELIGIBLE_ERROR_CODES = [
|
|
102
|
-
10005 /* UserAborted */,
|
|
103
|
-
10001 /* UserRejected */,
|
|
104
|
-
10100 /* DeviceNotFound */,
|
|
105
|
-
10101 /* DeviceDisconnected */,
|
|
106
|
-
10106 /* DeviceMismatch */,
|
|
107
|
-
10107 /* DeviceAppStuck */,
|
|
108
|
-
10109 /* DeviceOneDeviceOnly */,
|
|
109
|
-
10300 /* TransportError */,
|
|
110
|
-
10303 /* DevicePermissionDenied */,
|
|
111
|
-
10304 /* BlePairingTimeout */
|
|
112
|
-
];
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkFT3SZP2Wjs = require('./chunk-FT3SZP2W.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunkBAGEFFFYjs = require('./chunk-BAGEFFFY.js');
|
|
113
17
|
|
|
114
18
|
// src/types/response.ts
|
|
115
19
|
function success(payload) {
|
|
@@ -123,8 +27,8 @@ function failure(code, error, params) {
|
|
|
123
27
|
}
|
|
124
28
|
|
|
125
29
|
// src/types/fingerprint.ts
|
|
126
|
-
var
|
|
127
|
-
var
|
|
30
|
+
var _sha256 = require('@noble/hashes/sha256');
|
|
31
|
+
var _utils = require('@noble/hashes/utils');
|
|
128
32
|
var CHAIN_FINGERPRINT_PATHS = {
|
|
129
33
|
evm: "m/44'/60'/0'/0/0",
|
|
130
34
|
// BTC: account-level path (3 levels), mainnet cointype 0.
|
|
@@ -134,7 +38,7 @@ var CHAIN_FINGERPRINT_PATHS = {
|
|
|
134
38
|
tron: "m/44'/195'/0'/0/0"
|
|
135
39
|
};
|
|
136
40
|
function deriveDeviceFingerprint(value) {
|
|
137
|
-
return
|
|
41
|
+
return _utils.bytesToHex.call(void 0, _sha256.sha256.call(void 0, _utils.utf8ToBytes.call(void 0, value))).slice(0, 16);
|
|
138
42
|
}
|
|
139
43
|
|
|
140
44
|
// src/events/device.ts
|
|
@@ -142,43 +46,19 @@ var DEVICE_EVENT = "DEVICE_EVENT";
|
|
|
142
46
|
var DEVICE = {
|
|
143
47
|
CONNECT: "device-connect",
|
|
144
48
|
DISCONNECT: "device-disconnect",
|
|
145
|
-
CHANGED: "device-changed"
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
REQUEST_SELECT_DEVICE: "ui-request-select-device",
|
|
159
|
-
REQUEST_DEVICE_CONNECT: "ui-request-device-connect",
|
|
160
|
-
// Ledger BTC App: account index >= 100 requires display=true. Adapter asks
|
|
161
|
-
// the user once per session before promoting the call.
|
|
162
|
-
REQUEST_BTC_HIGH_INDEX_CONFIRM: "ui-request-btc-high-index-confirm",
|
|
163
|
-
// Required app is not installed; with autoInstallApp on, ask the user
|
|
164
|
-
// whether to install it before retrying the operation.
|
|
165
|
-
REQUEST_INSTALL_APP: "ui-request-install-app",
|
|
166
|
-
CLOSE_UI_WINDOW: "ui-close",
|
|
167
|
-
DEVICE_PROGRESS: "ui-device_progress",
|
|
168
|
-
FIRMWARE_PROGRESS: "ui-firmware-progress",
|
|
169
|
-
FIRMWARE_TIP: "ui-firmware-tip"
|
|
170
|
-
};
|
|
171
|
-
var UI_RESPONSE = {
|
|
172
|
-
RECEIVE_PIN: "receive-pin",
|
|
173
|
-
RECEIVE_PASSPHRASE: "receive-passphrase",
|
|
174
|
-
RECEIVE_PASSPHRASE_ON_DEVICE: "receive-passphrase-on-device",
|
|
175
|
-
RECEIVE_QR_RESPONSE: "receive-qr-response",
|
|
176
|
-
RECEIVE_SELECT_DEVICE: "receive-select-device",
|
|
177
|
-
RECEIVE_DEVICE_CONNECT: "receive-device-connect",
|
|
178
|
-
RECEIVE_DEVICE_PERMISSION: "receive-device-permission",
|
|
179
|
-
RECEIVE_BTC_HIGH_INDEX_CONFIRM: "receive-btc-high-index-confirm",
|
|
180
|
-
RECEIVE_INSTALL_APP: "receive-install-app",
|
|
181
|
-
CANCEL: "cancel"
|
|
49
|
+
CHANGED: "device-changed",
|
|
50
|
+
FEATURES: "features",
|
|
51
|
+
/**
|
|
52
|
+
* Trezor-only. Emitted after a successful THP handshake that minted or
|
|
53
|
+
* refreshed pairing credentials. The host should persist `credentials`
|
|
54
|
+
* keyed by `deviceId` and feed them back into the connector on the next
|
|
55
|
+
* connect to skip the CodeEntry/QrCode/NFC pairing UX.
|
|
56
|
+
*
|
|
57
|
+
* The `TREZOR_` prefix mirrors `UI_REQUEST.REQUEST_TREZOR_THP_PAIRING` —
|
|
58
|
+
* vendor-specific events live in the shared event taxonomy but are named
|
|
59
|
+
* so hosts can ignore them when they don't drive Trezor hardware.
|
|
60
|
+
*/
|
|
61
|
+
TREZOR_THP_CREDENTIALS_CHANGED: "device-trezor-thp-credentials-changed"
|
|
182
62
|
};
|
|
183
63
|
|
|
184
64
|
// src/events/sdk.ts
|
|
@@ -205,7 +85,7 @@ var DeviceJobQueue = class {
|
|
|
205
85
|
*/
|
|
206
86
|
async enqueue(deviceId, job, options = {}) {
|
|
207
87
|
if (options.rejectIfBusy && this._jobs.size > 0) {
|
|
208
|
-
throw options.busyError
|
|
88
|
+
throw _nullishCoalesce(options.busyError, () => ( new Error("Device is busy")));
|
|
209
89
|
}
|
|
210
90
|
const ac = new AbortController();
|
|
211
91
|
const gen = this._generation;
|
|
@@ -221,7 +101,7 @@ var DeviceJobQueue = class {
|
|
|
221
101
|
const next = prev.catch(() => {
|
|
222
102
|
}).then(async () => {
|
|
223
103
|
if (this._generation !== gen) {
|
|
224
|
-
throw this._generationCancelReasons.get(gen)
|
|
104
|
+
throw _nullishCoalesce(this._generationCancelReasons.get(gen), () => ( new Error("Job cancelled: queue was cleared")));
|
|
225
105
|
}
|
|
226
106
|
this._active = activeJob;
|
|
227
107
|
try {
|
|
@@ -249,20 +129,20 @@ var DeviceJobQueue = class {
|
|
|
249
129
|
forceCancelActive(deviceId, reason) {
|
|
250
130
|
if (!this._active) return false;
|
|
251
131
|
if (deviceId && this._active.deviceId !== deviceId) return false;
|
|
252
|
-
this._active.abortController.abort(reason
|
|
132
|
+
this._active.abortController.abort(_nullishCoalesce(reason, () => ( new Error("Force cancelled for recovery"))));
|
|
253
133
|
return true;
|
|
254
134
|
}
|
|
255
135
|
/** Cancel the active job (alias for callers that previously needed multi-device cancel). */
|
|
256
136
|
cancelAllActive(reason) {
|
|
257
137
|
if (!this._active) return;
|
|
258
|
-
this._active.abortController.abort(reason
|
|
138
|
+
this._active.abortController.abort(_nullishCoalesce(reason, () => ( new Error("Cancelled by cancelAllActive"))));
|
|
259
139
|
}
|
|
260
140
|
/** Cancel the active job and invalidate queued jobs that have not started. */
|
|
261
141
|
cancelActiveAndPending(deviceId, reason) {
|
|
262
142
|
if (deviceId && this._active && this._active.deviceId !== deviceId) {
|
|
263
143
|
return false;
|
|
264
144
|
}
|
|
265
|
-
this.clear(reason
|
|
145
|
+
this.clear(_nullishCoalesce(reason, () => ( new Error("Cancelled by cancelActiveAndPending"))));
|
|
266
146
|
return true;
|
|
267
147
|
}
|
|
268
148
|
/** Get info about the currently active job, or null if idle. */
|
|
@@ -282,7 +162,7 @@ var DeviceJobQueue = class {
|
|
|
282
162
|
clear(reason) {
|
|
283
163
|
const cancelledGeneration = this._generation;
|
|
284
164
|
this._generation++;
|
|
285
|
-
const cancelReason = reason
|
|
165
|
+
const cancelReason = _nullishCoalesce(reason, () => ( new Error("Job cancelled: queue was cleared")));
|
|
286
166
|
this._generationCancelReasons.set(cancelledGeneration, cancelReason);
|
|
287
167
|
for (const generation of this._generationCancelReasons.keys()) {
|
|
288
168
|
if (generation < this._generation - 10) {
|
|
@@ -309,7 +189,7 @@ function createBridgedConnector(vendor, connectionType, bridge) {
|
|
|
309
189
|
const handlerMap = /* @__PURE__ */ new Map();
|
|
310
190
|
return {
|
|
311
191
|
connectionType,
|
|
312
|
-
searchDevices: () => bridge.searchDevices({ vendor }),
|
|
192
|
+
searchDevices: (options) => bridge.searchDevices({ vendor, options }),
|
|
313
193
|
connect: (deviceId) => bridge.connect({ vendor, deviceId }),
|
|
314
194
|
disconnect: (sessionId) => bridge.disconnect({ vendor, sessionId }),
|
|
315
195
|
call: (sessionId, method, callParams) => bridge.call({ vendor, sessionId, method, callParams }),
|
|
@@ -331,13 +211,14 @@ function createBridgedConnector(vendor, connectionType, bridge) {
|
|
|
331
211
|
},
|
|
332
212
|
off: (event, handler) => {
|
|
333
213
|
const inner = handlerMap.get(event);
|
|
334
|
-
const bridgeHandler = inner
|
|
214
|
+
const bridgeHandler = _optionalChain([inner, 'optionalAccess', _ => _.get, 'call', _2 => _2(handler)]);
|
|
335
215
|
if (!bridgeHandler || !inner) return;
|
|
336
216
|
bridge.offEvent({ vendor }, bridgeHandler);
|
|
337
217
|
inner.delete(handler);
|
|
338
218
|
if (inner.size === 0) handlerMap.delete(event);
|
|
339
219
|
},
|
|
340
|
-
reset: () => bridge.reset({ vendor })
|
|
220
|
+
reset: () => bridge.reset({ vendor }),
|
|
221
|
+
setKnownCredentials: bridge.setKnownCredentials ? (credentials) => bridge.setKnownCredentials({ vendor, credentials }) : void 0
|
|
341
222
|
};
|
|
342
223
|
}
|
|
343
224
|
var SERIALIZED_ERROR_TOP_LEVEL_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -378,7 +259,7 @@ function serializeConnectorError(err) {
|
|
|
378
259
|
for (const key of Object.keys(params)) {
|
|
379
260
|
try {
|
|
380
261
|
JSON.stringify(params[key]);
|
|
381
|
-
} catch {
|
|
262
|
+
} catch (e2) {
|
|
382
263
|
delete params[key];
|
|
383
264
|
}
|
|
384
265
|
}
|
|
@@ -394,9 +275,225 @@ function rehydrateConnectorError(error) {
|
|
|
394
275
|
return Object.assign(new Error(message), {
|
|
395
276
|
...code !== void 0 ? { code } : {},
|
|
396
277
|
...errorCode !== void 0 ? { errorCode } : {},
|
|
397
|
-
...params
|
|
278
|
+
..._nullishCoalesce(params, () => ( {}))
|
|
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 _chunkFT3SZP2Wjs.createHwkError.call(void 0, {
|
|
290
|
+
code: 10100 /* DeviceNotFound */,
|
|
291
|
+
message
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
function combinedSessionNotFoundError(message) {
|
|
295
|
+
return _chunkFT3SZP2Wjs.createHwkError.call(void 0, {
|
|
296
|
+
code: 10101 /* DeviceDisconnected */,
|
|
297
|
+
message
|
|
398
298
|
});
|
|
399
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 _chunkFT3SZP2Wjs.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
|
+
}
|
|
400
497
|
|
|
401
498
|
// src/utils/TypedEventEmitter.ts
|
|
402
499
|
var TypedEventEmitter = class {
|
|
@@ -428,103 +525,9 @@ var TypedEventEmitter = class {
|
|
|
428
525
|
removeAllListeners() {
|
|
429
526
|
this._listeners.clear();
|
|
430
527
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
var UI_REQUEST_DEFAULT_TIMEOUT_MS = 6e5;
|
|
435
|
-
var RESPONSE_TO_REQUEST = {
|
|
436
|
-
[UI_RESPONSE.RECEIVE_PIN]: UI_REQUEST.REQUEST_PIN,
|
|
437
|
-
[UI_RESPONSE.RECEIVE_PASSPHRASE]: UI_REQUEST.REQUEST_PASSPHRASE,
|
|
438
|
-
[UI_RESPONSE.RECEIVE_PASSPHRASE_ON_DEVICE]: UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE,
|
|
439
|
-
[UI_RESPONSE.RECEIVE_SELECT_DEVICE]: UI_REQUEST.REQUEST_SELECT_DEVICE,
|
|
440
|
-
[UI_RESPONSE.RECEIVE_DEVICE_CONNECT]: UI_REQUEST.REQUEST_DEVICE_CONNECT,
|
|
441
|
-
[UI_RESPONSE.RECEIVE_DEVICE_PERMISSION]: UI_REQUEST.REQUEST_DEVICE_PERMISSION,
|
|
442
|
-
[UI_RESPONSE.RECEIVE_BTC_HIGH_INDEX_CONFIRM]: UI_REQUEST.REQUEST_BTC_HIGH_INDEX_CONFIRM,
|
|
443
|
-
[UI_RESPONSE.RECEIVE_INSTALL_APP]: UI_REQUEST.REQUEST_INSTALL_APP
|
|
444
|
-
// RECEIVE_QR_RESPONSE maps to QR_DISPLAY or QR_SCAN — resolved dynamically below.
|
|
445
|
-
};
|
|
446
|
-
var UI_REQUEST_PREEMPTED_TAG = "UiRequestPreempted";
|
|
447
|
-
var UI_REQUEST_CANCELLED_TAG = "UiRequestCancelled";
|
|
448
|
-
var UI_REQUEST_TIMEOUT_TAG = "UiRequestTimeout";
|
|
449
|
-
var UiRequestRegistry = class {
|
|
450
|
-
constructor() {
|
|
451
|
-
this.pending = /* @__PURE__ */ new Map();
|
|
452
|
-
}
|
|
453
|
-
wait(requestType, options) {
|
|
454
|
-
const existing = this.pending.get(requestType);
|
|
455
|
-
if (existing) {
|
|
456
|
-
clearTimeout(existing.timer);
|
|
457
|
-
this.pending.delete(requestType);
|
|
458
|
-
existing.reject(
|
|
459
|
-
Object.assign(new Error(`UI request '${requestType}' was superseded by a new request`), {
|
|
460
|
-
_tag: UI_REQUEST_PREEMPTED_TAG
|
|
461
|
-
})
|
|
462
|
-
);
|
|
463
|
-
}
|
|
464
|
-
const timeoutMs = options?.timeoutMs ?? UI_REQUEST_DEFAULT_TIMEOUT_MS;
|
|
465
|
-
return new Promise((resolve, reject) => {
|
|
466
|
-
const timer = setTimeout(() => {
|
|
467
|
-
if (this.pending.get(requestType)?.timer === timer) {
|
|
468
|
-
this.pending.delete(requestType);
|
|
469
|
-
reject(
|
|
470
|
-
Object.assign(new Error(`UI request '${requestType}' timed out after ${timeoutMs}ms`), {
|
|
471
|
-
_tag: UI_REQUEST_TIMEOUT_TAG
|
|
472
|
-
})
|
|
473
|
-
);
|
|
474
|
-
}
|
|
475
|
-
}, timeoutMs);
|
|
476
|
-
this.pending.set(requestType, {
|
|
477
|
-
resolve,
|
|
478
|
-
reject,
|
|
479
|
-
timer
|
|
480
|
-
});
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
resolve(responseType, payload) {
|
|
484
|
-
let requestType = RESPONSE_TO_REQUEST[responseType];
|
|
485
|
-
if (responseType === UI_RESPONSE.RECEIVE_QR_RESPONSE) {
|
|
486
|
-
if (this.pending.has(UI_REQUEST.REQUEST_QR_DISPLAY)) {
|
|
487
|
-
requestType = UI_REQUEST.REQUEST_QR_DISPLAY;
|
|
488
|
-
} else if (this.pending.has(UI_REQUEST.REQUEST_QR_SCAN)) {
|
|
489
|
-
requestType = UI_REQUEST.REQUEST_QR_SCAN;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
if (!requestType) return;
|
|
493
|
-
const entry = this.pending.get(requestType);
|
|
494
|
-
if (!entry) return;
|
|
495
|
-
clearTimeout(entry.timer);
|
|
496
|
-
this.pending.delete(requestType);
|
|
497
|
-
entry.resolve(payload);
|
|
498
|
-
}
|
|
499
|
-
cancel(requestType) {
|
|
500
|
-
if (requestType) {
|
|
501
|
-
const entry = this.pending.get(requestType);
|
|
502
|
-
if (!entry) return;
|
|
503
|
-
clearTimeout(entry.timer);
|
|
504
|
-
this.pending.delete(requestType);
|
|
505
|
-
entry.reject(
|
|
506
|
-
Object.assign(new Error(`UI request '${requestType}' was cancelled`), {
|
|
507
|
-
_tag: UI_REQUEST_CANCELLED_TAG
|
|
508
|
-
})
|
|
509
|
-
);
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
|
-
for (const [type, entry] of this.pending) {
|
|
513
|
-
clearTimeout(entry.timer);
|
|
514
|
-
entry.reject(
|
|
515
|
-
Object.assign(new Error(`UI request '${type}' was cancelled`), {
|
|
516
|
-
_tag: UI_REQUEST_CANCELLED_TAG
|
|
517
|
-
})
|
|
518
|
-
);
|
|
519
|
-
}
|
|
520
|
-
this.pending.clear();
|
|
521
|
-
}
|
|
522
|
-
reset() {
|
|
523
|
-
this.cancel();
|
|
524
|
-
}
|
|
525
|
-
hasPending(requestType) {
|
|
526
|
-
if (requestType) return this.pending.has(requestType);
|
|
527
|
-
return this.pending.size > 0;
|
|
528
|
+
/** Number of listeners registered for `event`. 0 if none. */
|
|
529
|
+
listenerCount(event) {
|
|
530
|
+
return _nullishCoalesce(_optionalChain([this, 'access', _8 => _8._listeners, 'access', _9 => _9.get, 'call', _10 => _10(event), 'optionalAccess', _11 => _11.size]), () => ( 0));
|
|
528
531
|
}
|
|
529
532
|
};
|
|
530
533
|
|
|
@@ -533,8 +536,8 @@ function compareSemver(a, b) {
|
|
|
533
536
|
const pa = a.split(".").map(Number);
|
|
534
537
|
const pb = b.split(".").map(Number);
|
|
535
538
|
for (let i = 0; i < 3; i++) {
|
|
536
|
-
const va = pa[i]
|
|
537
|
-
const vb = pb[i]
|
|
539
|
+
const va = _nullishCoalesce(pa[i], () => ( 0));
|
|
540
|
+
const vb = _nullishCoalesce(pb[i], () => ( 0));
|
|
538
541
|
if (va < vb) return -1;
|
|
539
542
|
if (va > vb) return 1;
|
|
540
543
|
}
|
|
@@ -542,7 +545,7 @@ function compareSemver(a, b) {
|
|
|
542
545
|
}
|
|
543
546
|
|
|
544
547
|
// src/utils/hex.ts
|
|
545
|
-
|
|
548
|
+
|
|
546
549
|
function ensure0x(hex) {
|
|
547
550
|
return hex.startsWith("0x") ? hex : `0x${hex}`;
|
|
548
551
|
}
|
|
@@ -553,68 +556,43 @@ function padHex64(hex) {
|
|
|
553
556
|
return `0x${stripHex(hex).padStart(64, "0")}`;
|
|
554
557
|
}
|
|
555
558
|
function hexToBytes(hex) {
|
|
556
|
-
return (0,
|
|
559
|
+
return _utils.hexToBytes.call(void 0, stripHex(hex));
|
|
557
560
|
}
|
|
558
561
|
function bytesToHex2(bytes) {
|
|
559
|
-
return (0,
|
|
562
|
+
return _utils.bytesToHex.call(void 0, bytes);
|
|
560
563
|
}
|
|
561
564
|
|
|
562
|
-
// src/utils/
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
case 10200 /* FirmwareTooOld */:
|
|
588
|
-
return `${originalMessage}. Please update your device firmware.`;
|
|
589
|
-
case 10104 /* DeviceNotInitialized */:
|
|
590
|
-
return `${originalMessage}. The device may need to be set up first.`;
|
|
591
|
-
case 10003 /* OperationTimeout */:
|
|
592
|
-
return `${originalMessage}. The operation timed out. Please try again.`;
|
|
593
|
-
case 11e3 /* EvmBlindSigningRequired */:
|
|
594
|
-
return "Ledger: Blind signing not enabled in Ethereum app.";
|
|
595
|
-
case 11001 /* EvmClearSignPluginMissing */:
|
|
596
|
-
return "Ledger: Required plugin not installed (install via Ledger Live).";
|
|
597
|
-
case 11002 /* EvmDataTooLarge */:
|
|
598
|
-
return "Ledger: Transaction data too large for device memory.";
|
|
599
|
-
case 11003 /* EvmTxTypeNotSupported */:
|
|
600
|
-
return "Ledger: Transaction type not supported by current Ethereum app.";
|
|
601
|
-
case 10502 /* AppTooOld */:
|
|
602
|
-
return "Ledger: App out of date (update via Ledger Live).";
|
|
603
|
-
case 11100 /* SolanaBlindSigningRequired */:
|
|
604
|
-
return "Blind signing disabled in the Solana app.";
|
|
605
|
-
case 11200 /* TronCustomContractRequired */:
|
|
606
|
-
return "Custom Contracts setting disabled in the Tron app.";
|
|
607
|
-
case 11201 /* TronDataSigningRequired */:
|
|
608
|
-
return "Transactions Data setting disabled in the Tron app.";
|
|
609
|
-
case 11202 /* TronSignByHashRequired */:
|
|
610
|
-
return "Sign by Hash setting disabled in the Tron app.";
|
|
611
|
-
case 11300 /* BtcWalletPolicyHmacMismatch */:
|
|
612
|
-
return "Wallet policy not registered or HMAC mismatch.";
|
|
613
|
-
case 11301 /* BtcUnexpectedState */:
|
|
614
|
-
return "Signing aborted due to unexpected device state.";
|
|
615
|
-
default:
|
|
616
|
-
return originalMessage;
|
|
565
|
+
// src/utils/deviceIdentity.ts
|
|
566
|
+
var ONEKEY_BLE_SERVICE_UUID = "00000001-0000-1000-8000-00805f9b34fb";
|
|
567
|
+
var TREZOR_BLE_SERVICE_UUID = "8c000001-a59b-4d58-a9ad-073df69fa1b1";
|
|
568
|
+
var LEDGER_USB_VENDOR_ID = 11415;
|
|
569
|
+
var lower = (value) => _nullishCoalesce(_optionalChain([value, 'optionalAccess', _12 => _12.trim, 'call', _13 => _13(), 'access', _14 => _14.toLowerCase, 'call', _15 => _15()]), () => ( ""));
|
|
570
|
+
var hasServiceUuid = (input, uuid) => {
|
|
571
|
+
const expected = uuid.toLowerCase();
|
|
572
|
+
const values = [
|
|
573
|
+
..._nullishCoalesce(input.serviceUUIDs, () => ( [])),
|
|
574
|
+
..._nullishCoalesce(input.advertisedServiceUuids, () => ( [])),
|
|
575
|
+
..._nullishCoalesce(input.serviceUuids, () => ( []))
|
|
576
|
+
];
|
|
577
|
+
return values.some((value) => value.toLowerCase() === expected);
|
|
578
|
+
};
|
|
579
|
+
function detectHardwareVendorFromDescriptor(input) {
|
|
580
|
+
const manufacturerName = lower(input.manufacturerName);
|
|
581
|
+
const fwVendor = lower(input.fw_vendor);
|
|
582
|
+
if (hasServiceUuid(input, ONEKEY_BLE_SERVICE_UUID) || manufacturerName.includes("onekey") || fwVendor === "onekey" || input.onekey_version || input.onekey_device_type || input.onekey_serial) {
|
|
583
|
+
return "onekey";
|
|
584
|
+
}
|
|
585
|
+
if (hasServiceUuid(input, TREZOR_BLE_SERVICE_UUID) || manufacturerName.includes("trezor") || fwVendor === "trezor") {
|
|
586
|
+
return "trezor";
|
|
587
|
+
}
|
|
588
|
+
if (typeof input.vendor === "number" && input.vendor === LEDGER_USB_VENDOR_ID || input.vendorId === LEDGER_USB_VENDOR_ID || manufacturerName.includes("ledger")) {
|
|
589
|
+
return "ledger";
|
|
617
590
|
}
|
|
591
|
+
return void 0;
|
|
592
|
+
}
|
|
593
|
+
function isKnownNonTargetHardwareVendor(input, targetVendor) {
|
|
594
|
+
const detectedVendor = detectHardwareVendorFromDescriptor(input);
|
|
595
|
+
return detectedVendor !== void 0 && detectedVendor !== targetVendor;
|
|
618
596
|
}
|
|
619
597
|
|
|
620
598
|
// src/utils/batchCall.ts
|
|
@@ -626,42 +604,161 @@ async function batchCall(params, callFn, onProgress) {
|
|
|
626
604
|
return result;
|
|
627
605
|
}
|
|
628
606
|
results.push(result.payload);
|
|
629
|
-
onProgress
|
|
607
|
+
_optionalChain([onProgress, 'optionalCall', _16 => _16({ index: i, total: params.length })]);
|
|
630
608
|
}
|
|
631
609
|
return { success: true, payload: results };
|
|
632
610
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
611
|
+
|
|
612
|
+
// src/utils/methodCatalog.ts
|
|
613
|
+
var HARDWARE_METHOD_CATALOG = {
|
|
614
|
+
evmGetAddress: { chain: "evm", allNetwork: true },
|
|
615
|
+
evmSignTransaction: { chain: "evm", allNetwork: false },
|
|
616
|
+
evmSignMessage: { chain: "evm", allNetwork: false },
|
|
617
|
+
evmSignTypedData: { chain: "evm", allNetwork: false },
|
|
618
|
+
btcGetAddress: { chain: "btc", allNetwork: true },
|
|
619
|
+
btcGetPublicKey: { chain: "btc", allNetwork: true },
|
|
620
|
+
btcSignTransaction: { chain: "btc", allNetwork: false },
|
|
621
|
+
btcSignPsbt: { chain: "btc", allNetwork: false },
|
|
622
|
+
btcSignMessage: { chain: "btc", allNetwork: false },
|
|
623
|
+
btcGetMasterFingerprint: { chain: "btc", allNetwork: false },
|
|
624
|
+
solGetAddress: { chain: "sol", allNetwork: true },
|
|
625
|
+
solSignTransaction: { chain: "sol", allNetwork: false },
|
|
626
|
+
solSignMessage: { chain: "sol", allNetwork: false },
|
|
627
|
+
tronGetAddress: { chain: "tron", allNetwork: true },
|
|
628
|
+
tronSignTransaction: { chain: "tron", allNetwork: false },
|
|
629
|
+
tronSignMessage: { chain: "tron", allNetwork: false }
|
|
630
|
+
};
|
|
631
|
+
var ALL_NETWORK_METHOD_NAMES = Object.entries(HARDWARE_METHOD_CATALOG).filter(([, metadata]) => metadata.allNetwork).map(([method]) => method);
|
|
632
|
+
var ALL_NETWORK_METHOD_SET = new Set(ALL_NETWORK_METHOD_NAMES);
|
|
633
|
+
function getHardwareMethodMetadata(method) {
|
|
634
|
+
return HARDWARE_METHOD_CATALOG[method];
|
|
635
|
+
}
|
|
636
|
+
function isAllNetworkMethodName(method) {
|
|
637
|
+
return ALL_NETWORK_METHOD_SET.has(method);
|
|
638
|
+
}
|
|
639
|
+
function getAllNetworkMethodChain(method) {
|
|
640
|
+
return HARDWARE_METHOD_CATALOG[method].chain;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// src/utils/allNetwork.ts
|
|
644
|
+
async function runAllNetworkGetAddress({
|
|
645
|
+
connectId,
|
|
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 = _chunkFT3SZP2Wjs.HardwareErrorCode; exports.ORPHAN_ELIGIBLE_ERROR_CODES = _chunkFT3SZP2Wjs.ORPHAN_ELIGIBLE_ERROR_CODES; exports.SDK = SDK; exports.TypedEventEmitter = TypedEventEmitter; exports.UI_EVENT = _chunkBAGEFFFYjs.UI_EVENT; exports.UI_REQUEST = _chunkBAGEFFFYjs.UI_REQUEST; exports.UI_REQUEST_CANCELLED_TAG = _chunkBAGEFFFYjs.UI_REQUEST_CANCELLED_TAG; exports.UI_REQUEST_DEFAULT_TIMEOUT_MS = _chunkBAGEFFFYjs.UI_REQUEST_DEFAULT_TIMEOUT_MS; exports.UI_REQUEST_PREEMPTED_TAG = _chunkBAGEFFFYjs.UI_REQUEST_PREEMPTED_TAG; exports.UI_REQUEST_TIMEOUT_TAG = _chunkBAGEFFFYjs.UI_REQUEST_TIMEOUT_TAG; exports.UI_RESPONSE = _chunkBAGEFFFYjs.UI_RESPONSE; exports.UiRequestRegistry = _chunkBAGEFFFYjs.UiRequestRegistry; exports.batchCall = batchCall; exports.buildUnsupportedMethodResponse = buildUnsupportedMethodResponse; exports.bytesToHex = bytesToHex2; exports.compareSemver = compareSemver; exports.createBridgedConnector = createBridgedConnector; exports.createCombinedConnector = createCombinedConnector; exports.createHwkError = _chunkFT3SZP2Wjs.createHwkError; exports.deriveDeviceFingerprint = deriveDeviceFingerprint; exports.detectHardwareVendorFromDescriptor = detectHardwareVendorFromDescriptor; exports.enrichErrorMessage = _chunkFT3SZP2Wjs.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;
|
|
667
764
|
//# sourceMappingURL=index.js.map
|