@onekeyfe/hwk-adapter-core 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.
Files changed (37) hide show
  1. package/dist/{chunk-YIQFVAFZ.js → chunk-BAGEFFFY.js} +13 -45
  2. package/dist/chunk-BAGEFFFY.js.map +1 -0
  3. package/dist/{chunk-T5HIQPNG.js → chunk-SZZF623R.js} +55 -155
  4. package/dist/chunk-SZZF623R.js.map +1 -0
  5. package/dist/{chunk-3D45OEC2.mjs → chunk-U63HTLGJ.mjs} +12 -44
  6. package/dist/chunk-U63HTLGJ.mjs.map +1 -0
  7. package/dist/{chunk-KTRQZ5AJ.mjs → chunk-YA4BWFTZ.mjs} +55 -155
  8. package/dist/chunk-YA4BWFTZ.mjs.map +1 -0
  9. package/dist/errors.d.mts +207 -1
  10. package/dist/errors.d.ts +207 -1
  11. package/dist/errors.js +2 -8
  12. package/dist/errors.js.map +1 -1
  13. package/dist/errors.mjs +3 -9
  14. package/dist/index.d.mts +104 -610
  15. package/dist/index.d.ts +104 -610
  16. package/dist/index.js +86 -754
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +78 -746
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/{ui-events-29Va0fPc.d.ts → ui-events-Cb7haAeE.d.mts} +3 -57
  21. package/dist/{ui-events-29Va0fPc.d.mts → ui-events-Cb7haAeE.d.ts} +3 -57
  22. package/dist/ui-events.d.mts +1 -1
  23. package/dist/ui-events.d.ts +1 -1
  24. package/dist/ui-events.js +2 -3
  25. package/dist/ui-events.js.map +1 -1
  26. package/dist/ui-events.mjs +1 -2
  27. package/package.json +2 -2
  28. package/dist/chunk-3D45OEC2.mjs.map +0 -1
  29. package/dist/chunk-DB4JOPZO.mjs +0 -74
  30. package/dist/chunk-DB4JOPZO.mjs.map +0 -1
  31. package/dist/chunk-KTRQZ5AJ.mjs.map +0 -1
  32. package/dist/chunk-T5HIQPNG.js.map +0 -1
  33. package/dist/chunk-YIQFVAFZ.js.map +0 -1
  34. package/dist/chunk-YLCHSNXO.js +0 -74
  35. package/dist/chunk-YLCHSNXO.js.map +0 -1
  36. package/dist/errors-BgJ4kzRx.d.mts +0 -276
  37. package/dist/errors-BgJ4kzRx.d.ts +0 -276
package/dist/index.js CHANGED
@@ -1,58 +1,28 @@
1
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
2
 
3
- var _chunkYLCHSNXOjs = require('./chunk-YLCHSNXO.js');
4
3
 
5
4
 
6
5
 
6
+ var _chunkSZZF623Rjs = require('./chunk-SZZF623R.js');
7
7
 
8
8
 
9
9
 
10
10
 
11
11
 
12
12
 
13
- var _chunkYIQFVAFZjs = require('./chunk-YIQFVAFZ.js');
14
13
 
15
14
 
16
15
 
17
-
18
-
19
-
20
-
21
-
22
- var _chunkT5HIQPNGjs = require('./chunk-T5HIQPNG.js');
16
+ var _chunkBAGEFFFYjs = require('./chunk-BAGEFFFY.js');
23
17
 
24
18
  // src/types/response.ts
25
19
  function success(payload) {
26
20
  return { success: true, payload };
27
21
  }
28
- function failure(code, error, params, origin, recovery) {
22
+ function failure(code, error, params) {
29
23
  return {
30
24
  success: false,
31
- payload: {
32
- error,
33
- code,
34
- ...origin !== void 0 ? { origin } : {},
35
- recovery: _nullishCoalesce(recovery, () => ( _chunkT5HIQPNGjs.defaultRecoveryForCode.call(void 0, code))),
36
- ...params ? { params } : {}
37
- }
38
- };
39
- }
40
-
41
- // src/types/device.ts
42
- function resolveSearchTargetReusePolicy(device) {
43
- return _optionalChain([device, 'access', _ => _.capabilities, 'optionalAccess', _2 => _2.persistentDeviceIdentity]) ? "reconnectable" : "current-discovery";
44
- }
45
- function toPhysicalDeviceSearchTarget(vendor, device) {
46
- return {
47
- searchTargetId: device.connectId,
48
- searchTargetReusePolicy: resolveSearchTargetReusePolicy(device),
49
- vendor,
50
- connectionType: device.connectionType,
51
- kind: "physical",
52
- label: device.label,
53
- model: device.model,
54
- modelName: device.modelName,
55
- serialNumber: device.serialNumber
25
+ payload: { error, code, ...params ? { params } : {} }
56
26
  };
57
27
  }
58
28
 
@@ -65,20 +35,8 @@ var CHAIN_FINGERPRINT_PATHS = {
65
35
  // Cointype 1 (testnet) is rejected by some Ledger BTC App configurations.
66
36
  btc: "m/44'/0'/0'",
67
37
  sol: "m/44'/501'/0'",
68
- tron: "m/44'/195'/0'/0/0",
69
- // Shielded UA (single Orchard receiver) derived from the transparent path.
70
- zcash: "m/44'/133'/0'/0/0"
38
+ tron: "m/44'/195'/0'/0/0"
71
39
  };
72
- function parseBip32MasterFingerprint(value) {
73
- if (typeof value !== "string") return void 0;
74
- const normalized = value.trim().toLowerCase();
75
- return /^[0-9a-f]{8}$/.test(normalized) ? normalized : void 0;
76
- }
77
- var MISSING_BIP32_MASTER_FINGERPRINT = "00000000";
78
- function parseWalletMasterFingerprint(value) {
79
- const fingerprint = parseBip32MasterFingerprint(value);
80
- return fingerprint === MISSING_BIP32_MASTER_FINGERPRINT ? void 0 : fingerprint;
81
- }
82
40
  function deriveDeviceFingerprint(value) {
83
41
  return _utils.bytesToHex.call(void 0, _sha256.sha256.call(void 0, _utils.utf8ToBytes.call(void 0, value))).slice(0, 16);
84
42
  }
@@ -108,8 +66,7 @@ var SDK = {
108
66
  DEVICE_STUCK: "device-stuck",
109
67
  DEVICE_UNRESPONSIVE: "device-unresponsive",
110
68
  DEVICE_RECOVERED: "device-recovered",
111
- DEVICE_INTERACTION: "device-interaction",
112
- OPERATION_ENDED: "operation-ended"
69
+ DEVICE_INTERACTION: "device-interaction"
113
70
  };
114
71
 
115
72
  // src/utils/DeviceJobQueue.ts
@@ -118,7 +75,6 @@ var DeviceJobQueue = class {
118
75
  this._tail = Promise.resolve();
119
76
  this._active = null;
120
77
  this._jobs = /* @__PURE__ */ new Map();
121
- this._cancelScopes = /* @__PURE__ */ new Map();
122
78
  /** Incremented on clear() so queued-but-not-yet-running jobs detect invalidation. */
123
79
  this._generation = 0;
124
80
  this._generationCancelReasons = /* @__PURE__ */ new Map();
@@ -141,13 +97,12 @@ var DeviceJobQueue = class {
141
97
  abortController: ac,
142
98
  startedAt: Date.now()
143
99
  };
144
- this._jobs.set(jobToken, activeJob);
100
+ this._jobs.set(jobToken, { deviceId });
145
101
  const next = prev.catch(() => {
146
102
  }).then(async () => {
147
103
  if (this._generation !== gen) {
148
104
  throw _nullishCoalesce(this._generationCancelReasons.get(gen), () => ( new Error("Job cancelled: queue was cleared")));
149
105
  }
150
- if (ac.signal.aborted) throw ac.signal.reason;
151
106
  this._active = activeJob;
152
107
  try {
153
108
  return await job(ac.signal);
@@ -163,52 +118,32 @@ var DeviceJobQueue = class {
163
118
  });
164
119
  return next;
165
120
  }
166
- /**
167
- * Holds a cancel across the gaps between a bundle's per-item jobs, when the queue is empty.
168
- * Callers must `release()` when the bundle ends.
169
- */
170
- createCancelScope(deviceId) {
171
- const scopeToken = {};
172
- const abortController = new AbortController();
173
- this._cancelScopes.set(scopeToken, { deviceId, abortController });
174
- return {
175
- signal: abortController.signal,
176
- release: () => {
177
- this._cancelScopes.delete(scopeToken);
178
- }
179
- };
121
+ /** Cancel the active job. If `deviceId` is given, only cancels when it matches. */
122
+ cancelActive(deviceId) {
123
+ if (!this._active) return false;
124
+ if (deviceId && this._active.deviceId !== deviceId) return false;
125
+ this._active.abortController.abort(new Error("Manually cancelled"));
126
+ return true;
180
127
  }
181
- /**
182
- * Cancels the running job only; `reason` becomes signal.reason. Adapters use
183
- * `cancelActiveAndPending`; this stays for a connector layer that stops only what is on the wire.
184
- */
185
- cancelActive(deviceId, reason) {
128
+ /** Force cancel the active job. `reason` becomes signal.reason. */
129
+ forceCancelActive(deviceId, reason) {
186
130
  if (!this._active) return false;
187
131
  if (deviceId && this._active.deviceId !== deviceId) return false;
188
- this._active.abortController.abort(_nullishCoalesce(reason, () => ( new Error("Cancelled"))));
132
+ this._active.abortController.abort(_nullishCoalesce(reason, () => ( new Error("Force cancelled for recovery"))));
189
133
  return true;
190
134
  }
191
- /**
192
- * Cancels the active job and unstarted queued jobs; returns whether anything was reached. Only
193
- * `undefined` means everything: an empty key matches nothing instead of tearing the queue down.
194
- */
135
+ /** Cancel the active job (alias for callers that previously needed multi-device cancel). */
136
+ cancelAllActive(reason) {
137
+ if (!this._active) return;
138
+ this._active.abortController.abort(_nullishCoalesce(reason, () => ( new Error("Cancelled by cancelAllActive"))));
139
+ }
140
+ /** Cancel the active job and invalidate queued jobs that have not started. */
195
141
  cancelActiveAndPending(deviceId, reason) {
196
- const cancelReason = _nullishCoalesce(reason, () => ( new Error("Cancelled by cancelActiveAndPending")));
197
- if (deviceId !== void 0) {
198
- let cancelled = false;
199
- const targets = [this._jobs, this._cancelScopes];
200
- for (const map of targets) {
201
- for (const target of map.values()) {
202
- if (target.deviceId !== deviceId) continue;
203
- target.abortController.abort(cancelReason);
204
- cancelled = true;
205
- }
206
- }
207
- return cancelled;
142
+ if (deviceId && this._active && this._active.deviceId !== deviceId) {
143
+ return false;
208
144
  }
209
- const reached = this._active !== null || this._jobs.size > 0 || this._cancelScopes.size > 0;
210
- this.clear(cancelReason);
211
- return reached;
145
+ this.clear(_nullishCoalesce(reason, () => ( new Error("Cancelled by cancelActiveAndPending"))));
146
+ return true;
212
147
  }
213
148
  /** Get info about the currently active job, or null if idle. */
214
149
  getActiveJob(deviceId) {
@@ -220,6 +155,10 @@ var DeviceJobQueue = class {
220
155
  startedAt: this._active.startedAt
221
156
  };
222
157
  }
158
+ /** True if any job is currently running. */
159
+ isBusy() {
160
+ return this._jobs.size > 0;
161
+ }
223
162
  clear(reason) {
224
163
  const cancelledGeneration = this._generation;
225
164
  this._generation++;
@@ -233,234 +172,9 @@ var DeviceJobQueue = class {
233
172
  if (this._active) {
234
173
  this._active.abortController.abort(cancelReason);
235
174
  }
236
- for (const scope of this._cancelScopes.values()) {
237
- scope.abortController.abort(cancelReason);
238
- }
239
175
  }
240
176
  };
241
177
 
242
- // src/utils/hardwareRuntimeId.ts
243
-
244
- var HARDWARE_RUNTIME_ID_PREFIX = "hwk:runtime";
245
- var RANDOM_ID_BYTES = 16;
246
- var RANDOM_ID_PATTERN = /^[0-9a-f]{32}$/;
247
- var KINDS = /* @__PURE__ */ new Set([
248
- "operation",
249
- "search-target",
250
- "link"
251
- ]);
252
- var VENDORS = /* @__PURE__ */ new Set(["trezor", "ledger", "keystone"]);
253
- function create(kind, vendor) {
254
- return `${HARDWARE_RUNTIME_ID_PREFIX}:${kind}:${vendor}:${_utils.bytesToHex.call(void 0,
255
- _utils.randomBytes.call(void 0, RANDOM_ID_BYTES)
256
- )}`;
257
- }
258
- function createHardwareOperationId(vendor) {
259
- return create("operation", vendor);
260
- }
261
- function createHardwareSearchTargetId(vendor) {
262
- return create("search-target", vendor);
263
- }
264
- function createHardwareLinkId(vendor) {
265
- return create("link", vendor);
266
- }
267
- function hasHardwareRuntimeIdPrefix(value) {
268
- return typeof value === "string" && value.startsWith(`${HARDWARE_RUNTIME_ID_PREFIX}:`);
269
- }
270
- function parseHardwareRuntimeId(value) {
271
- if (!hasHardwareRuntimeIdPrefix(value)) return void 0;
272
- const parts = value.split(":");
273
- if (parts.length !== 5) return void 0;
274
- const [, , kind, vendor, nonce] = parts;
275
- if (!KINDS.has(kind) || !VENDORS.has(vendor) || !RANDOM_ID_PATTERN.test(nonce)) {
276
- return void 0;
277
- }
278
- return { kind, vendor };
279
- }
280
- function isHardwareOperationId(value) {
281
- return _optionalChain([parseHardwareRuntimeId, 'call', _3 => _3(value), 'optionalAccess', _4 => _4.kind]) === "operation";
282
- }
283
-
284
- // src/utils/OperationRegistry.ts
285
- var OPERATION_DEFAULT_TTL_MS = 6e5;
286
- var uniqueKeys = (keys) => Array.from(new Set(keys.filter(Boolean)));
287
- var OperationRegistry = class {
288
- constructor(options) {
289
- this._active = /* @__PURE__ */ new Map();
290
- this._ended = /* @__PURE__ */ new Map();
291
- this._vendor = options.vendor;
292
- this._ttlMs = _nullishCoalesce(options.ttlMs, () => ( OPERATION_DEFAULT_TTL_MS));
293
- this._onEnded = options.onEnded;
294
- }
295
- create(params) {
296
- const operationId = createHardwareOperationId(this._vendor);
297
- const operation = {
298
- operationId,
299
- connectId: params.connectId,
300
- device: params.device,
301
- connectionType: params.connectionType,
302
- connectionKeys: uniqueKeys([
303
- params.searchTargetId,
304
- params.connectId,
305
- ..._nullishCoalesce(params.connectionKeys, () => ( []))
306
- ])
307
- };
308
- const timer = this._createTimer(operationId);
309
- this._active.set(operationId, { ...operation, timer, retainCount: 0 });
310
- return operation;
311
- }
312
- resolve(operationId) {
313
- const active = this._active.get(operationId);
314
- if (!active) {
315
- const ended = this._ended.get(operationId);
316
- if (ended) {
317
- throw _chunkT5HIQPNGjs.createHwkError.call(void 0, {
318
- code: 10113 /* OperationEnded */,
319
- message: `Hardware operation has ended (${ended.reason})`,
320
- params: { operationId, reason: ended.reason }
321
- });
322
- }
323
- throw _chunkT5HIQPNGjs.createHwkError.call(void 0, {
324
- code: 10112 /* OperationNotFound */,
325
- message: "Hardware operation was not found",
326
- params: { operationId }
327
- });
328
- }
329
- this._touch(active);
330
- return active;
331
- }
332
- /** Keep an operation alive while one device job is actively using it. */
333
- retain(operationId) {
334
- const active = this.resolve(operationId);
335
- active.retainCount += 1;
336
- this._touch(active);
337
- let released = false;
338
- return () => {
339
- if (released) return;
340
- released = true;
341
- const current = this._active.get(operationId);
342
- if (!current) return;
343
- current.retainCount = Math.max(0, current.retainCount - 1);
344
- this._touch(current);
345
- };
346
- }
347
- /** Return a live operation without refreshing its TTL; ended and unknown ids give undefined. */
348
- findActive(operationId) {
349
- return this._active.get(operationId);
350
- }
351
- /** Return active or tombstoned binding data without refreshing its TTL. */
352
- find(operationId) {
353
- return _nullishCoalesce(this._active.get(operationId), () => ( _optionalChain([this, 'access', _5 => _5._ended, 'access', _6 => _6.get, 'call', _7 => _7(operationId), 'optionalAccess', _8 => _8.operation])));
354
- }
355
- findActiveByConnectionKey(connectionKey) {
356
- if (!connectionKey) return void 0;
357
- return [...this._active.values()].find(
358
- (operation) => operation.connectionKeys.includes(connectionKey)
359
- );
360
- }
361
- /** Map a job queue key (an operation id or a connection key) to its live operation id. */
362
- findOperationIdByJobKey(jobKey) {
363
- if (!jobKey) return void 0;
364
- if (isHardwareOperationId(jobKey)) return jobKey;
365
- return _optionalChain([this, 'access', _9 => _9.findActiveByConnectionKey, 'call', _10 => _10(jobKey), 'optionalAccess', _11 => _11.operationId]);
366
- }
367
- /**
368
- * End an operation on the caller's explicit release. Throws for an unknown id; returns undefined
369
- * when it had already ended.
370
- */
371
- release(operationId) {
372
- if (!this.find(operationId)) {
373
- this.resolve(operationId);
374
- return void 0;
375
- }
376
- return this.end(operationId, "explicit");
377
- }
378
- end(operationId, reason) {
379
- const active = this._active.get(operationId);
380
- if (!active) return void 0;
381
- if (active.timer) clearTimeout(active.timer);
382
- this._active.delete(operationId);
383
- this._rememberEnded(active, reason);
384
- _optionalChain([this, 'access', _12 => _12._onEnded, 'optionalCall', _13 => _13(active, reason)]);
385
- return active;
386
- }
387
- endByConnectionKey(connectionKey, reason, exceptOperationId) {
388
- if (!connectionKey) return;
389
- for (const operation of [...this._active.values()]) {
390
- if (operation.operationId === exceptOperationId) continue;
391
- if (operation.connectionKeys.includes(connectionKey)) {
392
- this.end(operation.operationId, reason);
393
- }
394
- }
395
- }
396
- endAll(reason, exceptOperationId) {
397
- for (const operationId of [...this._active.keys()]) {
398
- if (operationId === exceptOperationId) continue;
399
- this.end(operationId, reason);
400
- }
401
- }
402
- _touch(active) {
403
- if (active.timer) clearTimeout(active.timer);
404
- active.timer = active.retainCount === 0 ? this._createTimer(active.operationId) : void 0;
405
- }
406
- _createTimer(operationId) {
407
- const timer = setTimeout(() => {
408
- this.end(operationId, "timeout");
409
- }, this._ttlMs);
410
- _optionalChain([timer, 'access', _14 => _14.unref, 'optionalCall', _15 => _15()]);
411
- return timer;
412
- }
413
- _rememberEnded(operation, reason) {
414
- this._ended.set(operation.operationId, { reason, operation });
415
- if (this._ended.size <= 100) return;
416
- const oldest = this._ended.keys().next().value;
417
- if (oldest) this._ended.delete(oldest);
418
- }
419
- };
420
-
421
- // src/utils/hardwareOperationTarget.ts
422
- function resolveHardwareOperationTarget(positionalTargetId, commonOperationId, expectedVendor) {
423
- const targetId = _nullishCoalesce(positionalTargetId, () => ( void 0));
424
- const commonId = commonOperationId || void 0;
425
- const parsedTarget = parseHardwareRuntimeId(targetId);
426
- const parsedCommon = parseHardwareRuntimeId(commonId);
427
- const positionalOperationId = _optionalChain([parsedTarget, 'optionalAccess', _16 => _16.kind]) === "operation" ? targetId : void 0;
428
- if (hasHardwareRuntimeIdPrefix(targetId) && !parsedTarget) {
429
- return failure(10002 /* InvalidParams */, "Invalid hardware operation target id");
430
- }
431
- if (_optionalChain([parsedTarget, 'optionalAccess', _17 => _17.kind]) === "link") {
432
- return failure(
433
- 10002 /* InvalidParams */,
434
- "Hardware transport link id cannot be used as an operation target"
435
- );
436
- }
437
- if (commonId && _optionalChain([parsedCommon, 'optionalAccess', _18 => _18.kind]) !== "operation") {
438
- return failure(10002 /* InvalidParams */, "Invalid hardware operation id");
439
- }
440
- if (expectedVendor && [parsedTarget, parsedCommon].some((parsed) => parsed && parsed.vendor !== expectedVendor)) {
441
- return failure(
442
- 10002 /* InvalidParams */,
443
- `Hardware operation does not belong to ${expectedVendor}`
444
- );
445
- }
446
- if (positionalOperationId && commonId && positionalOperationId !== commonId) {
447
- return failure(10002 /* InvalidParams */, "Conflicting hardware operation ids", {
448
- positionalOperationId,
449
- commonOperationId: commonId
450
- });
451
- }
452
- const operationId = _nullishCoalesce(commonId, () => ( positionalOperationId));
453
- return success({ operationId, targetId: _nullishCoalesce(operationId, () => ( targetId)) });
454
- }
455
- function pickConnectionContext(params) {
456
- return {
457
- knownConnections: params.knownConnections,
458
- extra: params.extra,
459
- allowDeviceSelection: typeof params.allowDeviceSelection === "boolean" ? params.allowDeviceSelection : void 0,
460
- supportedTransports: params.supportedTransports
461
- };
462
- }
463
-
464
178
  // src/types/connector.ts
465
179
  var EConnectorInteraction = /* @__PURE__ */ ((EConnectorInteraction2) => {
466
180
  EConnectorInteraction2["Searching"] = "searching";
@@ -476,7 +190,7 @@ function createBridgedConnector(vendor, connectionType, bridge) {
476
190
  return {
477
191
  connectionType,
478
192
  searchDevices: (options) => bridge.searchDevices({ vendor, options }),
479
- connect: (deviceId, options) => bridge.connect({ vendor, deviceId, ...options ? { options } : {} }),
193
+ connect: (deviceId) => bridge.connect({ vendor, deviceId }),
480
194
  disconnect: (sessionId) => bridge.disconnect({ vendor, sessionId }),
481
195
  call: (sessionId, method, callParams) => bridge.call({ vendor, sessionId, method, callParams }),
482
196
  cancel: (sessionId) => bridge.cancel({ vendor, sessionId }),
@@ -497,14 +211,14 @@ function createBridgedConnector(vendor, connectionType, bridge) {
497
211
  },
498
212
  off: (event, handler) => {
499
213
  const inner = handlerMap.get(event);
500
- const bridgeHandler = _optionalChain([inner, 'optionalAccess', _19 => _19.get, 'call', _20 => _20(handler)]);
214
+ const bridgeHandler = _optionalChain([inner, 'optionalAccess', _ => _.get, 'call', _2 => _2(handler)]);
501
215
  if (!bridgeHandler || !inner) return;
502
216
  bridge.offEvent({ vendor }, bridgeHandler);
503
217
  inner.delete(handler);
504
218
  if (inner.size === 0) handlerMap.delete(event);
505
219
  },
506
220
  reset: () => bridge.reset({ vendor }),
507
- configure: bridge.configure ? (config) => _optionalChain([bridge, 'access', _21 => _21.configure, 'optionalCall', _22 => _22({ vendor, config })]) : void 0,
221
+ configure: bridge.configure ? (config) => _optionalChain([bridge, 'access', _3 => _3.configure, 'optionalCall', _4 => _4({ vendor, config })]) : void 0,
508
222
  setKnownCredentials: bridge.setKnownCredentials ? (credentials) => bridge.setKnownCredentials({ vendor, credentials }) : void 0
509
223
  };
510
224
  }
@@ -573,13 +287,13 @@ function isDeviceUnavailableError(error) {
573
287
  return false;
574
288
  }
575
289
  function combinedDeviceNotFoundError(message) {
576
- return _chunkT5HIQPNGjs.createHwkError.call(void 0, {
290
+ return _chunkSZZF623Rjs.createHwkError.call(void 0, {
577
291
  code: 10100 /* DeviceNotFound */,
578
292
  message
579
293
  });
580
294
  }
581
295
  function combinedSessionNotFoundError(message) {
582
- return _chunkT5HIQPNGjs.createHwkError.call(void 0, {
296
+ return _chunkSZZF623Rjs.createHwkError.call(void 0, {
583
297
  code: 10101 /* DeviceDisconnected */,
584
298
  message
585
299
  });
@@ -608,26 +322,19 @@ function createCombinedConnector(connectors) {
608
322
  };
609
323
  const broadcastCredentials = async () => {
610
324
  await Promise.all(
611
- connectors.map((child) => Promise.resolve(_optionalChain([child, 'access', _23 => _23.setKnownCredentials, 'optionalCall', _24 => _24(sharedCredentials)])))
325
+ connectors.map((child) => Promise.resolve(_optionalChain([child, 'access', _5 => _5.setKnownCredentials, 'optionalCall', _6 => _6(sharedCredentials)])))
612
326
  );
613
327
  };
614
328
  for (const child of connectors) {
615
329
  child.on("device-trezor-thp-credentials-changed", (data) => {
616
- const removed = new Set((_nullishCoalesce(data.removed, () => ( []))).map(credentialKey));
617
- const kept = sharedCredentials.filter((cred) => !removed.has(credentialKey(cred)));
618
- const dropped = kept.length !== sharedCredentials.length;
619
- sharedCredentials.splice(0, sharedCredentials.length, ...kept);
620
- if (mergeShared(data.credentials) || dropped) void broadcastCredentials();
330
+ if (mergeShared(data.credentials)) void broadcastCredentials();
621
331
  });
622
332
  }
623
- const onTransport = (child, transportType) => !transportType || child.connectionType === transportType;
624
333
  const searchDevices = async (options = {}) => {
625
- const selectedConnectors = connectors.map((child, index) => ({ child, index })).filter(({ child }) => onTransport(child, options.transportType));
626
- if (!selectedConnectors.length) return [];
627
334
  const perConnector = [];
628
- await new Promise((resolve, reject) => {
335
+ await new Promise((resolve) => {
629
336
  let finished = false;
630
- let remaining = selectedConnectors.length;
337
+ let remaining = connectors.length;
631
338
  let settleTimer;
632
339
  const finish = () => {
633
340
  if (finished) return;
@@ -635,20 +342,19 @@ function createCombinedConnector(connectors) {
635
342
  if (settleTimer) clearTimeout(settleTimer);
636
343
  resolve();
637
344
  };
638
- selectedConnectors.forEach(({ child, index }) => {
639
- void child.searchDevices(options.purpose ? { purpose: options.purpose } : void 0).then(
345
+ connectors.forEach((child, index) => {
346
+ void child.searchDevices().then(
640
347
  (devices) => devices.map((device) => ({
641
348
  ...device,
642
349
  connectionType: _nullishCoalesce(device.connectionType, () => ( child.connectionType))
643
350
  }))
644
- ).catch((error) => {
645
- if (options.transportType) {
646
- finished = true;
647
- if (settleTimer) clearTimeout(settleTimer);
648
- reject(error);
649
- }
650
- return [];
651
- }).then((devices) => {
351
+ ).catch(
352
+ () => (
353
+ // A transport that can't scan (powered off, unauthorized, absent)
354
+ // must not fail the whole fused search.
355
+ []
356
+ )
357
+ ).then((devices) => {
652
358
  remaining -= 1;
653
359
  if (!finished) {
654
360
  perConnector.push({ index, devices });
@@ -665,9 +371,7 @@ function createCombinedConnector(connectors) {
665
371
  });
666
372
  });
667
373
  perConnector.sort((a, b) => a.index - b.index);
668
- for (const [id, owner] of deviceOwner) {
669
- if (onTransport(owner, options.transportType)) deviceOwner.delete(id);
670
- }
374
+ deviceOwner.clear();
671
375
  const merged = [];
672
376
  perConnector.forEach(({ index, devices }) => {
673
377
  for (const device of devices) {
@@ -677,12 +381,11 @@ function createCombinedConnector(connectors) {
677
381
  });
678
382
  return merged.sort((a, b) => rank(a) - rank(b));
679
383
  };
680
- const resolveOwner = async (deviceId, transportType) => {
681
- const cachedOwner = deviceId ? deviceOwner.get(deviceId) : void 0;
682
- if (cachedOwner && onTransport(cachedOwner, transportType)) {
683
- return { owner: cachedOwner, deviceId };
384
+ const resolveOwner = async (deviceId) => {
385
+ if (deviceId && deviceOwner.has(deviceId)) {
386
+ return { owner: deviceOwner.get(deviceId), deviceId };
684
387
  }
685
- const devices = await searchDevices({ waitForAll: Boolean(deviceId), transportType });
388
+ const devices = await searchDevices({ waitForAll: Boolean(deviceId) });
686
389
  if (deviceId) {
687
390
  const owner = deviceOwner.get(deviceId);
688
391
  if (!owner)
@@ -693,14 +396,13 @@ function createCombinedConnector(connectors) {
693
396
  if (!first) throw combinedDeviceNotFoundError("Combined connector: no devices found");
694
397
  return { owner: deviceOwner.get(first.connectId), deviceId: first.connectId };
695
398
  };
696
- const connectByExplicitId = async (deviceId, transportType) => {
399
+ const connectByExplicitId = async (deviceId) => {
697
400
  const cachedOwner = deviceOwner.get(deviceId);
698
- if (cachedOwner && onTransport(cachedOwner, transportType)) {
401
+ if (cachedOwner) {
699
402
  return { session: await cachedOwner.connect(deviceId), owner: cachedOwner };
700
403
  }
701
404
  let lastError;
702
405
  for (const child of connectors) {
703
- if (!onTransport(child, transportType)) continue;
704
406
  try {
705
407
  const session = await child.connect(deviceId);
706
408
  deviceOwner.set(deviceId, child);
@@ -713,7 +415,7 @@ function createCombinedConnector(connectors) {
713
415
  }
714
416
  }
715
417
  const message = lastError instanceof Error ? lastError.message : `Combined connector: device not found: ${deviceId}`;
716
- throw _chunkT5HIQPNGjs.createHwkError.call(void 0, {
418
+ throw _chunkSZZF623Rjs.createHwkError.call(void 0, {
717
419
  code: 10100 /* DeviceNotFound */,
718
420
  message
719
421
  });
@@ -722,15 +424,14 @@ function createCombinedConnector(connectors) {
722
424
  // Nominal value only — the per-device `connectionType` is authoritative
723
425
  // for a fused connector.
724
426
  connectionType: connectors[0].connectionType,
725
- availableTransports: [...new Set(connectors.map((child) => child.connectionType))],
726
- searchDevices: (options) => searchDevices(options),
727
- connect: async (deviceId, options) => {
427
+ searchDevices: (options) => searchDevices({ waitForAll: _optionalChain([options, 'optionalAccess', _7 => _7.waitForAll]) }),
428
+ connect: async (deviceId) => {
728
429
  let owner;
729
430
  let session;
730
431
  if (deviceId) {
731
- ({ session, owner } = await connectByExplicitId(deviceId, _optionalChain([options, 'optionalAccess', _25 => _25.transportType])));
432
+ ({ session, owner } = await connectByExplicitId(deviceId));
732
433
  } else {
733
- const resolved = await resolveOwner(void 0, _optionalChain([options, 'optionalAccess', _26 => _26.transportType]));
434
+ const resolved = await resolveOwner();
734
435
  owner = resolved.owner;
735
436
  session = await owner.connect(resolved.deviceId);
736
437
  }
@@ -752,11 +453,8 @@ function createCombinedConnector(connectors) {
752
453
  },
753
454
  cancel: async (sessionId) => {
754
455
  const owner = sessionOwner.get(sessionId);
755
- if (owner) {
756
- await owner.cancel(sessionId);
757
- return;
758
- }
759
- await Promise.all(connectors.map((child) => child.cancel(sessionId)));
456
+ if (!owner) return;
457
+ await owner.cancel(sessionId);
760
458
  },
761
459
  uiResponse: (response) => {
762
460
  for (const child of connectors) child.uiResponse(response);
@@ -776,7 +474,7 @@ function createCombinedConnector(connectors) {
776
474
  },
777
475
  off: (event, handler) => {
778
476
  const inner = forwarders.get(event);
779
- const attached = _optionalChain([inner, 'optionalAccess', _27 => _27.get, 'call', _28 => _28(handler)]);
477
+ const attached = _optionalChain([inner, 'optionalAccess', _8 => _8.get, 'call', _9 => _9(handler)]);
780
478
  if (!attached || !inner) return;
781
479
  for (const { child, handler: forward } of attached) {
782
480
  child.off(event, forward);
@@ -791,7 +489,7 @@ function createCombinedConnector(connectors) {
791
489
  forwarders.clear();
792
490
  },
793
491
  configure: connectors.some((c) => c.configure) ? async (config) => {
794
- await Promise.all(connectors.map((child) => Promise.resolve(_optionalChain([child, 'access', _29 => _29.configure, 'optionalCall', _30 => _30(config)]))));
492
+ await Promise.all(connectors.map((child) => Promise.resolve(_optionalChain([child, 'access', _10 => _10.configure, 'optionalCall', _11 => _11(config)]))));
795
493
  deviceOwner.clear();
796
494
  sessionOwner.clear();
797
495
  } : void 0,
@@ -835,148 +533,10 @@ var TypedEventEmitter = class {
835
533
  }
836
534
  /** Number of listeners registered for `event`. 0 if none. */
837
535
  listenerCount(event) {
838
- return _nullishCoalesce(_optionalChain([this, 'access', _31 => _31._listeners, 'access', _32 => _32.get, 'call', _33 => _33(event), 'optionalAccess', _34 => _34.size]), () => ( 0));
536
+ return _nullishCoalesce(_optionalChain([this, 'access', _12 => _12._listeners, 'access', _13 => _13.get, 'call', _14 => _14(event), 'optionalAccess', _15 => _15.size]), () => ( 0));
839
537
  }
840
538
  };
841
539
 
842
- // src/utils/requestSaveDeviceBinding.ts
843
- function emitDeviceBindingStatus(emitter, selectionRequestId, status) {
844
- emitter.emit(_chunkYIQFVAFZjs.UI_REQUEST.DEVICE_BINDING_STATUS, {
845
- type: _chunkYIQFVAFZjs.UI_REQUEST.DEVICE_BINDING_STATUS,
846
- payload: { selectionRequestId, status }
847
- });
848
- }
849
- async function requestSaveDeviceBinding(emitter, registry, binding, signal) {
850
- const type = _chunkYIQFVAFZjs.UI_REQUEST.REQUEST_SAVE_DEVICE_BINDING;
851
- const emitStatus = (status) => emitDeviceBindingStatus(emitter, binding.selectionRequestId, status);
852
- const declined = (reason) => {
853
- emitStatus("failed");
854
- return { saved: false, reason };
855
- };
856
- if (!emitter.listenerCount(type)) {
857
- return declined("skipped");
858
- }
859
- if (_optionalChain([signal, 'optionalAccess', _35 => _35.aborted])) throw signal.reason;
860
- const requestId = registry.createRequestId();
861
- const pending = registry.wait(type, { requestId, operationId: binding.operationId });
862
- void pending.catch(() => void 0);
863
- const cancel = () => registry.cancel(type, requestId);
864
- _optionalChain([signal, 'optionalAccess', _36 => _36.addEventListener, 'call', _37 => _37("abort", cancel, { once: true })]);
865
- try {
866
- emitter.emit(type, { type, payload: { ...binding, requestId } });
867
- const response = await pending;
868
- if (_optionalChain([signal, 'optionalAccess', _38 => _38.aborted])) throw signal.reason;
869
- if (_optionalChain([response, 'optionalAccess', _39 => _39.saved]) !== true) {
870
- return declined(_nullishCoalesce(_optionalChain([response, 'optionalAccess', _40 => _40.reason]), () => ( "skipped")));
871
- }
872
- emitStatus("saved");
873
- return { saved: true };
874
- } catch (error) {
875
- if (_optionalChain([signal, 'optionalAccess', _41 => _41.aborted])) {
876
- emitStatus("cancelled");
877
- throw error;
878
- }
879
- return declined("skipped");
880
- } finally {
881
- _optionalChain([signal, 'optionalAccess', _42 => _42.removeEventListener, 'call', _43 => _43("abort", cancel)]);
882
- registry.cancel(type, requestId);
883
- }
884
- }
885
-
886
- // src/utils/requestBleDeviceSelection.ts
887
- async function requestBleDeviceSelection({
888
- emitter,
889
- registry,
890
- request,
891
- scan,
892
- signal,
893
- allowUsbFallback = false,
894
- pollIntervalMs = 1500
895
- }) {
896
- const type = _chunkYIQFVAFZjs.UI_REQUEST.REQUEST_SELECT_DEVICE;
897
- if (signal.aborted) throw signal.reason;
898
- if (!emitter.listenerCount(type)) {
899
- throw _chunkT5HIQPNGjs.createHwkError.call(void 0, {
900
- code: 10100 /* DeviceNotFound */,
901
- message: "Select a Bluetooth device before continuing"
902
- });
903
- }
904
- const requestId = registry.createRequestId();
905
- const { operationId } = request;
906
- let devices = allowUsbFallback ? request.devices.filter((device) => device.connectionType === "ble") : request.devices;
907
- const publishedDevices = /* @__PURE__ */ new Map();
908
- let stopped = false;
909
- let timer;
910
- let wake;
911
- const stop = () => {
912
- stopped = true;
913
- if (timer !== void 0) clearTimeout(timer);
914
- _optionalChain([wake, 'optionalCall', _44 => _44()]);
915
- };
916
- const waitForNextScan = () => new Promise((resolve) => {
917
- wake = resolve;
918
- timer = setTimeout(resolve, pollIntervalMs);
919
- if (stopped) resolve();
920
- });
921
- const cancel = () => registry.cancel(type, requestId);
922
- const reply = registry.wait(type, { requestId, operationId }).finally(stop);
923
- void reply.catch(() => void 0);
924
- const publish = () => {
925
- for (const device of devices) publishedDevices.set(device.connectId, device);
926
- emitter.emit(type, {
927
- type,
928
- payload: { ...request, devices, requestId, scanning: true }
929
- });
930
- };
931
- signal.addEventListener("abort", cancel, { once: true });
932
- const rescan = () => scan().catch((error) => {
933
- if (stopped || signal.aborted || devices.length) return void 0;
934
- throw error;
935
- });
936
- let polling;
937
- try {
938
- publish();
939
- polling = (async () => {
940
- await Promise.resolve();
941
- while (!stopped) {
942
- const snapshot = await rescan();
943
- if (stopped || signal.aborted) return;
944
- const usbFallback = allowUsbFallback ? _optionalChain([snapshot, 'optionalAccess', _45 => _45.find, 'call', _46 => _46((device2) => device2.connectionType === "usb")]) : void 0;
945
- if (usbFallback) return usbFallback;
946
- if (snapshot) {
947
- devices = snapshot;
948
- publish();
949
- }
950
- await waitForNextScan();
951
- }
952
- })();
953
- const userSelection = reply.then((selected) => publishedDevices.get(selected.sdkConnectId));
954
- const device = await Promise.race([
955
- userSelection,
956
- polling.then((usbFallback) => _nullishCoalesce(usbFallback, () => ( userSelection)))
957
- ]);
958
- stop();
959
- await polling;
960
- if (signal.aborted) throw signal.reason;
961
- if (!device) {
962
- throw _chunkT5HIQPNGjs.createHwkError.call(void 0, {
963
- code: 10100 /* DeviceNotFound */,
964
- message: "Selected Bluetooth device is no longer available"
965
- });
966
- }
967
- emitDeviceBindingStatus(emitter, requestId, "verifying");
968
- return { device, requestId };
969
- } catch (error) {
970
- emitDeviceBindingStatus(emitter, requestId, signal.aborted ? "cancelled" : "failed");
971
- throw error;
972
- } finally {
973
- stop();
974
- signal.removeEventListener("abort", cancel);
975
- registry.cancel(type, requestId);
976
- await _optionalChain([polling, 'optionalAccess', _47 => _47.catch, 'call', _48 => _48(() => void 0)]);
977
- }
978
- }
979
-
980
540
  // src/utils/semver.ts
981
541
  function compareSemver(a, b) {
982
542
  const pa = a.split(".").map(Number);
@@ -1004,141 +564,15 @@ function padHex64(hex) {
1004
564
  function hexToBytes(hex) {
1005
565
  return _utils.hexToBytes.call(void 0, stripHex(hex));
1006
566
  }
1007
- function bytesToHex3(bytes) {
567
+ function bytesToHex2(bytes) {
1008
568
  return _utils.bytesToHex.call(void 0, bytes);
1009
569
  }
1010
570
 
1011
- // src/utils/boundedCbor.ts
1012
- var MAX_CBOR_DEPTH = 64;
1013
- var DEFAULT_MAX_CBOR_BYTES = 8 * 1024 * 1024;
1014
- var ARGUMENT_BYTES = [1, 2, 4, 8];
1015
- function malformed(reason) {
1016
- return _chunkT5HIQPNGjs.createHwkError.call(void 0, {
1017
- code: 10002 /* InvalidParams */,
1018
- message: `Malformed CBOR payload: ${reason}`
1019
- });
1020
- }
1021
- function assertBoundedCbor(input, maxBytes = DEFAULT_MAX_CBOR_BYTES) {
1022
- if (input.length === 0) throw malformed("empty");
1023
- if (input.length > maxBytes) throw malformed(`larger than ${maxBytes} bytes`);
1024
- let offset = 0;
1025
- const readArgument = (info) => {
1026
- if (info < 24) return info;
1027
- const size = ARGUMENT_BYTES[info - 24];
1028
- if (offset + size > input.length) throw malformed("truncated length");
1029
- let value = 0;
1030
- for (let i = 0; i < size; i += 1) value = value * 256 + input[offset + i];
1031
- offset += size;
1032
- return value;
1033
- };
1034
- const walkItem = (depth) => {
1035
- if (depth > MAX_CBOR_DEPTH) throw malformed("nested too deeply");
1036
- if (offset >= input.length) throw malformed("truncated item");
1037
- const initial = input[offset];
1038
- offset += 1;
1039
- const major = Math.floor(initial / 32);
1040
- const info = initial % 32;
1041
- if (info >= 28) throw malformed("indefinite or reserved length");
1042
- const argument = readArgument(info);
1043
- const remaining = input.length - offset;
1044
- if (major === 2 || major === 3) {
1045
- if (argument > remaining) throw malformed("string longer than the payload");
1046
- offset += argument;
1047
- } else if (major === 4 || major === 5) {
1048
- const items = major === 5 ? argument * 2 : argument;
1049
- if (items > remaining) throw malformed("container longer than the payload");
1050
- for (let i = 0; i < items; i += 1) walkItem(depth + 1);
1051
- } else if (major === 6) {
1052
- walkItem(depth + 1);
1053
- }
1054
- };
1055
- walkItem(0);
1056
- if (offset !== input.length) throw malformed("trailing bytes");
1057
- }
1058
- function boundedCborFromHex(hex, maxBytes) {
1059
- if (!/^(?:[0-9a-f]{2})+$/i.test(hex)) throw malformed("not an even-length hex string");
1060
- const bytes = Buffer.from(hex, "hex");
1061
- assertBoundedCbor(bytes, maxBytes);
1062
- return bytes;
1063
- }
1064
-
1065
- // src/utils/solanaOffchainMessage.ts
1066
- var SOLANA_OFFCHAIN_SIGNING_DOMAIN = Uint8Array.of(
1067
- 255,
1068
- ...Array.from("solana offchain", (character) => character.charCodeAt(0))
1069
- );
1070
- var SOLANA_PUBLIC_KEY_LENGTH = 32;
1071
- var MAX_SOLANA_OFFCHAIN_SIGNERS = 255;
1072
- function compareBytes(a, b) {
1073
- for (let index = 0; index < a.length; index += 1) {
1074
- const difference = (_nullishCoalesce(a[index], () => ( 0))) - (_nullishCoalesce(b[index], () => ( 0)));
1075
- if (difference !== 0) return difference;
1076
- }
1077
- return a.length - b.length;
1078
- }
1079
- function bytesEqual(a, b) {
1080
- return a.length === b.length && a.every((value, index) => value === b[index]);
1081
- }
1082
- function decodeUtf8Strict(bytes) {
1083
- return decodeURIComponent(
1084
- Array.from(bytes, (value) => `%${value.toString(16).padStart(2, "0")}`).join("")
1085
- );
1086
- }
1087
- function prepareSolanaOffchainMessageV1({
1088
- message,
1089
- requiredSigners
1090
- }) {
1091
- if (message.length === 0) {
1092
- throw new Error("Solana off-chain message cannot be empty");
1093
- }
1094
- if (requiredSigners.length === 0 || requiredSigners.length > MAX_SOLANA_OFFCHAIN_SIGNERS) {
1095
- throw new Error("Solana off-chain message requires between 1 and 255 signers");
1096
- }
1097
- let messageText;
1098
- try {
1099
- messageText = decodeUtf8Strict(message);
1100
- } catch (e3) {
1101
- throw new Error("Solana off-chain message must contain valid UTF-8");
1102
- }
1103
- const signerBytes = requiredSigners.map((signer, index) => {
1104
- let bytes;
1105
- try {
1106
- bytes = hexToBytes(signer);
1107
- } catch (e4) {
1108
- throw new Error(`Solana off-chain signer ${index} must be a hex public key`);
1109
- }
1110
- if (bytes.length !== SOLANA_PUBLIC_KEY_LENGTH) {
1111
- throw new Error(`Solana off-chain signer ${index} must be 32 bytes`);
1112
- }
1113
- return bytes;
1114
- });
1115
- signerBytes.sort(compareBytes);
1116
- if (signerBytes.some((bytes, index) => index > 0 && bytesEqual(signerBytes[index - 1], bytes))) {
1117
- throw new Error("Solana off-chain signers must be unique");
1118
- }
1119
- const signersOffset = SOLANA_OFFCHAIN_SIGNING_DOMAIN.length + 2;
1120
- const messageOffset = signersOffset + signerBytes.length * SOLANA_PUBLIC_KEY_LENGTH;
1121
- const serializedMessage = new Uint8Array(messageOffset + message.length);
1122
- serializedMessage.set(SOLANA_OFFCHAIN_SIGNING_DOMAIN);
1123
- serializedMessage.set([1, signerBytes.length], SOLANA_OFFCHAIN_SIGNING_DOMAIN.length);
1124
- signerBytes.forEach(
1125
- (signer, index) => serializedMessage.set(signer, signersOffset + index * SOLANA_PUBLIC_KEY_LENGTH)
1126
- );
1127
- serializedMessage.set(message, messageOffset);
1128
- return {
1129
- messageText,
1130
- requiredSigners: signerBytes.map(bytesToHex3),
1131
- serializedMessage
1132
- };
1133
- }
1134
-
1135
571
  // src/utils/deviceIdentity.ts
1136
572
  var ONEKEY_BLE_SERVICE_UUID = "00000001-0000-1000-8000-00805f9b34fb";
1137
573
  var TREZOR_BLE_SERVICE_UUID = "8c000001-a59b-4d58-a9ad-073df69fa1b1";
1138
574
  var LEDGER_USB_VENDOR_ID = 11415;
1139
- var KEYSTONE_USB_VENDOR_ID = 4617;
1140
- var KEYSTONE_USB_PRODUCT_ID = 12289;
1141
- var lower = (value) => _nullishCoalesce(_optionalChain([value, 'optionalAccess', _49 => _49.trim, 'call', _50 => _50(), 'access', _51 => _51.toLowerCase, 'call', _52 => _52()]), () => ( ""));
575
+ var lower = (value) => _nullishCoalesce(_optionalChain([value, 'optionalAccess', _16 => _16.trim, 'call', _17 => _17(), 'access', _18 => _18.toLowerCase, 'call', _19 => _19()]), () => ( ""));
1142
576
  var hasServiceUuid = (input, uuid) => {
1143
577
  const expected = uuid.toLowerCase();
1144
578
  const values = [
@@ -1160,11 +594,6 @@ function detectHardwareVendorFromDescriptor(input) {
1160
594
  if (typeof input.vendor === "number" && input.vendor === LEDGER_USB_VENDOR_ID || input.vendorId === LEDGER_USB_VENDOR_ID || manufacturerName.includes("ledger")) {
1161
595
  return "ledger";
1162
596
  }
1163
- const usbVendorId = typeof input.vendor === "number" ? input.vendor : input.vendorId;
1164
- const usbProductId = typeof input.product === "number" ? input.product : input.productId;
1165
- if (usbVendorId === KEYSTONE_USB_VENDOR_ID && usbProductId === KEYSTONE_USB_PRODUCT_ID || manufacturerName.includes("keystone")) {
1166
- return "keystone";
1167
- }
1168
597
  return void 0;
1169
598
  }
1170
599
  function isKnownNonTargetHardwareVendor(input, targetVendor) {
@@ -1181,69 +610,35 @@ async function batchCall(params, callFn, onProgress) {
1181
610
  return result;
1182
611
  }
1183
612
  results.push(result.payload);
1184
- _optionalChain([onProgress, 'optionalCall', _53 => _53({ index: i, total: params.length })]);
613
+ _optionalChain([onProgress, 'optionalCall', _20 => _20({ index: i, total: params.length })]);
1185
614
  }
1186
615
  return { success: true, payload: results };
1187
616
  }
1188
617
 
1189
618
  // src/utils/methodCatalog.ts
1190
619
  var HARDWARE_METHOD_CATALOG = {
1191
- evmGetAddress: { chain: "evm", allNetwork: true, replayAfterTransportFailure: "safe" },
1192
- evmSignTransaction: {
1193
- chain: "evm",
1194
- allNetwork: false,
1195
- replayAfterTransportFailure: "unsafe"
1196
- },
1197
- evmSignMessage: { chain: "evm", allNetwork: false, replayAfterTransportFailure: "unsafe" },
1198
- evmSignTypedData: { chain: "evm", allNetwork: false, replayAfterTransportFailure: "unsafe" },
1199
- btcGetAddress: { chain: "btc", allNetwork: true, replayAfterTransportFailure: "safe" },
1200
- btcGetPublicKey: { chain: "btc", allNetwork: true, replayAfterTransportFailure: "safe" },
1201
- btcSignTransaction: {
1202
- chain: "btc",
1203
- allNetwork: false,
1204
- replayAfterTransportFailure: "unsafe"
1205
- },
1206
- btcSignPsbt: { chain: "btc", allNetwork: false, replayAfterTransportFailure: "unsafe" },
1207
- btcSignMessage: { chain: "btc", allNetwork: false, replayAfterTransportFailure: "unsafe" },
1208
- btcGetMasterFingerprint: {
1209
- chain: "btc",
1210
- allNetwork: false,
1211
- replayAfterTransportFailure: "safe"
1212
- },
1213
- solGetAddress: { chain: "sol", allNetwork: true, replayAfterTransportFailure: "safe" },
1214
- solSignTransaction: {
1215
- chain: "sol",
1216
- allNetwork: false,
1217
- replayAfterTransportFailure: "unsafe"
1218
- },
1219
- solSignMessage: { chain: "sol", allNetwork: false, replayAfterTransportFailure: "unsafe" },
1220
- tronGetAddress: { chain: "tron", allNetwork: true, replayAfterTransportFailure: "safe" },
1221
- tronSignTransaction: {
1222
- chain: "tron",
1223
- allNetwork: false,
1224
- replayAfterTransportFailure: "unsafe"
1225
- },
1226
- tronSignMessage: { chain: "tron", allNetwork: false, replayAfterTransportFailure: "unsafe" },
1227
- zcashGetFullViewingKey: {
1228
- chain: "zcash",
1229
- allNetwork: false,
1230
- replayAfterTransportFailure: "safe"
1231
- },
1232
- zcashGetShieldedAddress: {
1233
- chain: "zcash",
1234
- allNetwork: false,
1235
- replayAfterTransportFailure: "safe"
1236
- }
620
+ evmGetAddress: { chain: "evm", allNetwork: true },
621
+ evmSignTransaction: { chain: "evm", allNetwork: false },
622
+ evmSignMessage: { chain: "evm", allNetwork: false },
623
+ evmSignTypedData: { chain: "evm", allNetwork: false },
624
+ btcGetAddress: { chain: "btc", allNetwork: true },
625
+ btcGetPublicKey: { chain: "btc", allNetwork: true },
626
+ btcSignTransaction: { chain: "btc", allNetwork: false },
627
+ btcSignPsbt: { chain: "btc", allNetwork: false },
628
+ btcSignMessage: { chain: "btc", allNetwork: false },
629
+ btcGetMasterFingerprint: { chain: "btc", allNetwork: false },
630
+ solGetAddress: { chain: "sol", allNetwork: true },
631
+ solSignTransaction: { chain: "sol", allNetwork: false },
632
+ solSignMessage: { chain: "sol", allNetwork: false },
633
+ tronGetAddress: { chain: "tron", allNetwork: true },
634
+ tronSignTransaction: { chain: "tron", allNetwork: false },
635
+ tronSignMessage: { chain: "tron", allNetwork: false }
1237
636
  };
1238
637
  var ALL_NETWORK_METHOD_NAMES = Object.entries(HARDWARE_METHOD_CATALOG).filter(([, metadata]) => metadata.allNetwork).map(([method]) => method);
1239
638
  var ALL_NETWORK_METHOD_SET = new Set(ALL_NETWORK_METHOD_NAMES);
1240
639
  function getHardwareMethodMetadata(method) {
1241
640
  return HARDWARE_METHOD_CATALOG[method];
1242
641
  }
1243
- var SAFE_NON_CHAIN_METHODS = /* @__PURE__ */ new Set(["getFeatures", "authenticateDevice"]);
1244
- function canReplayHardwareMethodAfterTransportFailure(method) {
1245
- return _optionalChain([getHardwareMethodMetadata, 'call', _54 => _54(method), 'optionalAccess', _55 => _55.replayAfterTransportFailure]) === "safe" || SAFE_NON_CHAIN_METHODS.has(method);
1246
- }
1247
642
  function isAllNetworkMethodName(method) {
1248
643
  return ALL_NETWORK_METHOD_SET.has(method);
1249
644
  }
@@ -1271,7 +666,7 @@ async function runAllNetworkGetAddress({
1271
666
  continue;
1272
667
  }
1273
668
  const method = item.methodName;
1274
- const unsupportedNetwork = _optionalChain([buildUnsupportedNetworkResponse, 'optionalCall', _56 => _56(item, method)]);
669
+ const unsupportedNetwork = _optionalChain([buildUnsupportedNetworkResponse, 'optionalCall', _21 => _21(item, method)]);
1275
670
  if (unsupportedNetwork) {
1276
671
  responses.push(unsupportedNetwork);
1277
672
  continue;
@@ -1303,38 +698,6 @@ async function runAllNetworkGetAddress({
1303
698
  }
1304
699
  return success(responses);
1305
700
  }
1306
- function isUserRefusal(code) {
1307
- return code === 10005 /* UserAborted */ || code === 10001 /* UserRejected */ || code === 10401 /* PinCancelled */;
1308
- }
1309
- function isWalletSafetyFailure(code) {
1310
- const codes = [
1311
- 10106 /* DeviceMismatch */,
1312
- 10114 /* DeviceSearchMismatch */,
1313
- 10103 /* DeviceLocked */,
1314
- 10400 /* PinInvalid */,
1315
- 10404 /* PinMismatch */,
1316
- 10402 /* PassphraseRejected */,
1317
- 10403 /* PassphraseStateMismatch */,
1318
- 10405 /* PassphraseAlwaysOnDevice */
1319
- ];
1320
- return code !== void 0 && codes.includes(code);
1321
- }
1322
- function isConnectionLost(code) {
1323
- const codes = [
1324
- 10101 /* DeviceDisconnected */,
1325
- 10003 /* OperationTimeout */,
1326
- 10300 /* TransportError */,
1327
- 10113 /* OperationEnded */,
1328
- 10112 /* OperationNotFound */
1329
- ];
1330
- return code !== void 0 && codes.includes(code);
1331
- }
1332
- function buildAllNetworkCancelledFailure(signal) {
1333
- const reason = signal.reason;
1334
- const code = typeof _optionalChain([reason, 'optionalAccess', _57 => _57.code]) === "number" ? reason.code : 10005 /* UserAborted */;
1335
- const message = typeof _optionalChain([reason, 'optionalAccess', _58 => _58.message]) === "string" ? reason.message : "";
1336
- return failure(code, message || "All-network get-address cancelled");
1337
- }
1338
701
  function buildUnsupportedMethodResponse(item) {
1339
702
  return {
1340
703
  ...item,
@@ -1403,36 +766,5 @@ var DEVICE_CONNECT_RETRY_DELAY_MS = 1e3;
1403
766
 
1404
767
 
1405
768
 
1406
-
1407
-
1408
-
1409
-
1410
-
1411
-
1412
-
1413
-
1414
-
1415
-
1416
-
1417
-
1418
-
1419
-
1420
-
1421
-
1422
-
1423
-
1424
-
1425
-
1426
-
1427
-
1428
-
1429
-
1430
-
1431
-
1432
-
1433
-
1434
-
1435
-
1436
-
1437
- 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.HARDWARE_RUNTIME_ID_PREFIX = HARDWARE_RUNTIME_ID_PREFIX; exports.HardwareErrorCode = _chunkT5HIQPNGjs.HardwareErrorCode; exports.MISSING_BIP32_MASTER_FINGERPRINT = MISSING_BIP32_MASTER_FINGERPRINT; exports.OPERATION_DEFAULT_TTL_MS = OPERATION_DEFAULT_TTL_MS; exports.ORPHAN_ELIGIBLE_ERROR_CODES = _chunkT5HIQPNGjs.ORPHAN_ELIGIBLE_ERROR_CODES; exports.OperationRegistry = OperationRegistry; exports.SDK = SDK; exports.TypedEventEmitter = TypedEventEmitter; exports.UI_EVENT = _chunkYIQFVAFZjs.UI_EVENT; exports.UI_REQUEST = _chunkYIQFVAFZjs.UI_REQUEST; exports.UI_REQUEST_CANCELLED_TAG = _chunkYIQFVAFZjs.UI_REQUEST_CANCELLED_TAG; exports.UI_REQUEST_DEFAULT_TIMEOUT_MS = _chunkYIQFVAFZjs.UI_REQUEST_DEFAULT_TIMEOUT_MS; exports.UI_REQUEST_PREEMPTED_TAG = _chunkYIQFVAFZjs.UI_REQUEST_PREEMPTED_TAG; exports.UI_REQUEST_TIMEOUT_TAG = _chunkYIQFVAFZjs.UI_REQUEST_TIMEOUT_TAG; exports.UI_RESPONSE = _chunkYIQFVAFZjs.UI_RESPONSE; exports.UiRequestRegistry = _chunkYIQFVAFZjs.UiRequestRegistry; exports.assertBoundedCbor = assertBoundedCbor; exports.batchCall = batchCall; exports.boundedCborFromHex = boundedCborFromHex; exports.buildAllNetworkCancelledFailure = buildAllNetworkCancelledFailure; exports.buildUnsupportedMethodResponse = buildUnsupportedMethodResponse; exports.bytesToHex = bytesToHex3; exports.canReplayHardwareMethodAfterTransportFailure = canReplayHardwareMethodAfterTransportFailure; exports.compareSemver = compareSemver; exports.createBridgedConnector = createBridgedConnector; exports.createCombinedConnector = createCombinedConnector; exports.createHardwareLinkId = createHardwareLinkId; exports.createHardwareOperationId = createHardwareOperationId; exports.createHardwareSearchTargetId = createHardwareSearchTargetId; exports.createHwkError = _chunkT5HIQPNGjs.createHwkError; exports.defaultOriginForCode = _chunkT5HIQPNGjs.defaultOriginForCode; exports.defaultRecoveryForCode = _chunkT5HIQPNGjs.defaultRecoveryForCode; exports.deriveDeviceFingerprint = deriveDeviceFingerprint; exports.detectHardwareVendorFromDescriptor = detectHardwareVendorFromDescriptor; exports.emitDeviceBindingStatus = emitDeviceBindingStatus; exports.enrichErrorMessage = _chunkYLCHSNXOjs.enrichErrorMessage; exports.ensure0x = ensure0x; exports.failure = failure; exports.getAllNetworkMethodChain = getAllNetworkMethodChain; exports.getHardwareMethodMetadata = getHardwareMethodMetadata; exports.hasHardwareRuntimeIdPrefix = hasHardwareRuntimeIdPrefix; exports.hexToBytes = hexToBytes; exports.isAllNetworkMethodName = isAllNetworkMethodName; exports.isConnectionLost = isConnectionLost; exports.isHardwareOperationId = isHardwareOperationId; exports.isHwkRecoveryHint = _chunkT5HIQPNGjs.isHwkRecoveryHint; exports.isKnownNonTargetHardwareVendor = isKnownNonTargetHardwareVendor; exports.isUserRefusal = isUserRefusal; exports.isWalletSafetyFailure = isWalletSafetyFailure; exports.operationMayHaveCompletedParams = _chunkT5HIQPNGjs.operationMayHaveCompletedParams; exports.padHex64 = padHex64; exports.parseBip32MasterFingerprint = parseBip32MasterFingerprint; exports.parseHardwareRuntimeId = parseHardwareRuntimeId; exports.parseWalletMasterFingerprint = parseWalletMasterFingerprint; exports.pickConnectionContext = pickConnectionContext; exports.prepareSolanaOffchainMessageV1 = prepareSolanaOffchainMessageV1; exports.rehydrateConnectorError = rehydrateConnectorError; exports.requestBleDeviceSelection = requestBleDeviceSelection; exports.requestSaveDeviceBinding = requestSaveDeviceBinding; exports.resolveHardwareOperationTarget = resolveHardwareOperationTarget; exports.resolveSearchTargetReusePolicy = resolveSearchTargetReusePolicy; exports.runAllNetworkGetAddress = runAllNetworkGetAddress; exports.serializeConnectorError = serializeConnectorError; exports.stripHex = stripHex; exports.success = success; exports.toPhysicalDeviceSearchTarget = toPhysicalDeviceSearchTarget;
769
+ 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 = _chunkSZZF623Rjs.HardwareErrorCode; exports.ORPHAN_ELIGIBLE_ERROR_CODES = _chunkSZZF623Rjs.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 = _chunkSZZF623Rjs.createHwkError; exports.deriveDeviceFingerprint = deriveDeviceFingerprint; exports.detectHardwareVendorFromDescriptor = detectHardwareVendorFromDescriptor; exports.enrichErrorMessage = _chunkSZZF623Rjs.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;
1438
770
  //# sourceMappingURL=index.js.map