@onekeyfe/hwk-adapter-core 1.2.5 → 1.2.6-alpha.0

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-U63HTLGJ.mjs → chunk-AYA6FQES.mjs} +44 -12
  2. package/dist/chunk-AYA6FQES.mjs.map +1 -0
  3. package/dist/chunk-DB4JOPZO.mjs +74 -0
  4. package/dist/chunk-DB4JOPZO.mjs.map +1 -0
  5. package/dist/{chunk-BAGEFFFY.js → chunk-H7BZ2C6J.js} +45 -13
  6. package/dist/chunk-H7BZ2C6J.js.map +1 -0
  7. package/dist/{chunk-YA4BWFTZ.mjs → chunk-KTRQZ5AJ.mjs} +155 -55
  8. package/dist/chunk-KTRQZ5AJ.mjs.map +1 -0
  9. package/dist/{chunk-SZZF623R.js → chunk-T5HIQPNG.js} +155 -55
  10. package/dist/chunk-T5HIQPNG.js.map +1 -0
  11. package/dist/chunk-YLCHSNXO.js +74 -0
  12. package/dist/chunk-YLCHSNXO.js.map +1 -0
  13. package/dist/errors-BgJ4kzRx.d.mts +276 -0
  14. package/dist/errors-BgJ4kzRx.d.ts +276 -0
  15. package/dist/errors.d.mts +1 -207
  16. package/dist/errors.d.ts +1 -207
  17. package/dist/errors.js +8 -2
  18. package/dist/errors.js.map +1 -1
  19. package/dist/errors.mjs +9 -3
  20. package/dist/index.d.mts +583 -104
  21. package/dist/index.d.ts +583 -104
  22. package/dist/index.js +642 -85
  23. package/dist/index.js.map +1 -1
  24. package/dist/index.mjs +633 -76
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/{ui-events-Cb7haAeE.d.mts → ui-events-DdttFKj9.d.mts} +37 -3
  27. package/dist/{ui-events-Cb7haAeE.d.ts → ui-events-DdttFKj9.d.ts} +37 -3
  28. package/dist/ui-events.d.mts +1 -1
  29. package/dist/ui-events.d.ts +1 -1
  30. package/dist/ui-events.js +3 -2
  31. package/dist/ui-events.js.map +1 -1
  32. package/dist/ui-events.mjs +2 -1
  33. package/package.json +2 -2
  34. package/dist/chunk-BAGEFFFY.js.map +0 -1
  35. package/dist/chunk-SZZF623R.js.map +0 -1
  36. package/dist/chunk-U63HTLGJ.mjs.map +0 -1
  37. package/dist/chunk-YA4BWFTZ.mjs.map +0 -1
package/dist/index.js CHANGED
@@ -1,31 +1,48 @@
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');
3
4
 
4
5
 
5
6
 
6
- var _chunkSZZF623Rjs = require('./chunk-SZZF623R.js');
7
7
 
8
8
 
9
9
 
10
10
 
11
11
 
12
12
 
13
+ var _chunkH7BZ2C6Jjs = require('./chunk-H7BZ2C6J.js');
13
14
 
14
15
 
15
16
 
16
- var _chunkBAGEFFFYjs = require('./chunk-BAGEFFFY.js');
17
+
18
+
19
+
20
+
21
+
22
+ var _chunkT5HIQPNGjs = require('./chunk-T5HIQPNG.js');
17
23
 
18
24
  // src/types/response.ts
19
25
  function success(payload) {
20
26
  return { success: true, payload };
21
27
  }
22
- function failure(code, error, params) {
28
+ function failure(code, error, params, origin, recovery) {
23
29
  return {
24
30
  success: false,
25
- payload: { error, code, ...params ? { params } : {} }
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
+ }
26
38
  };
27
39
  }
28
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
+
29
46
  // src/types/fingerprint.ts
30
47
  var _sha256 = require('@noble/hashes/sha256');
31
48
  var _utils = require('@noble/hashes/utils');
@@ -35,11 +52,26 @@ var CHAIN_FINGERPRINT_PATHS = {
35
52
  // Cointype 1 (testnet) is rejected by some Ledger BTC App configurations.
36
53
  btc: "m/44'/0'/0'",
37
54
  sol: "m/44'/501'/0'",
38
- tron: "m/44'/195'/0'/0/0"
55
+ tron: "m/44'/195'/0'/0/0",
56
+ // Shielded UA (single Orchard receiver) derived from the transparent path.
57
+ zcash: "m/44'/133'/0'/0/0"
39
58
  };
59
+ function parseBip32MasterFingerprint(value) {
60
+ if (typeof value !== "string") return void 0;
61
+ const normalized = value.trim().toLowerCase();
62
+ return /^[0-9a-f]{8}$/.test(normalized) ? normalized : void 0;
63
+ }
64
+ var MISSING_BIP32_MASTER_FINGERPRINT = "00000000";
65
+ function parseWalletMasterFingerprint(value) {
66
+ const fingerprint = parseBip32MasterFingerprint(value);
67
+ return fingerprint === MISSING_BIP32_MASTER_FINGERPRINT ? void 0 : fingerprint;
68
+ }
40
69
  function deriveDeviceFingerprint(value) {
41
70
  return _utils.bytesToHex.call(void 0, _sha256.sha256.call(void 0, _utils.utf8ToBytes.call(void 0, value))).slice(0, 16);
42
71
  }
72
+ function deriveWalletId(canonicalPublicMaterial) {
73
+ return _utils.bytesToHex.call(void 0, _sha256.sha256.call(void 0, _utils.utf8ToBytes.call(void 0, `onekey-hwk-wallet-id:v1:${canonicalPublicMaterial}`)));
74
+ }
43
75
 
44
76
  // src/events/device.ts
45
77
  var DEVICE_EVENT = "DEVICE_EVENT";
@@ -66,7 +98,8 @@ var SDK = {
66
98
  DEVICE_STUCK: "device-stuck",
67
99
  DEVICE_UNRESPONSIVE: "device-unresponsive",
68
100
  DEVICE_RECOVERED: "device-recovered",
69
- DEVICE_INTERACTION: "device-interaction"
101
+ DEVICE_INTERACTION: "device-interaction",
102
+ OPERATION_ENDED: "operation-ended"
70
103
  };
71
104
 
72
105
  // src/utils/DeviceJobQueue.ts
@@ -75,6 +108,7 @@ var DeviceJobQueue = class {
75
108
  this._tail = Promise.resolve();
76
109
  this._active = null;
77
110
  this._jobs = /* @__PURE__ */ new Map();
111
+ this._cancelScopes = /* @__PURE__ */ new Map();
78
112
  /** Incremented on clear() so queued-but-not-yet-running jobs detect invalidation. */
79
113
  this._generation = 0;
80
114
  this._generationCancelReasons = /* @__PURE__ */ new Map();
@@ -97,12 +131,13 @@ var DeviceJobQueue = class {
97
131
  abortController: ac,
98
132
  startedAt: Date.now()
99
133
  };
100
- this._jobs.set(jobToken, { deviceId });
134
+ this._jobs.set(jobToken, activeJob);
101
135
  const next = prev.catch(() => {
102
136
  }).then(async () => {
103
137
  if (this._generation !== gen) {
104
138
  throw _nullishCoalesce(this._generationCancelReasons.get(gen), () => ( new Error("Job cancelled: queue was cleared")));
105
139
  }
140
+ if (ac.signal.aborted) throw ac.signal.reason;
106
141
  this._active = activeJob;
107
142
  try {
108
143
  return await job(ac.signal);
@@ -118,32 +153,52 @@ var DeviceJobQueue = class {
118
153
  });
119
154
  return next;
120
155
  }
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;
156
+ /**
157
+ * Holds a cancel across the gaps between a bundle's per-item jobs, when the queue is empty.
158
+ * Callers must `release()` when the bundle ends.
159
+ */
160
+ createCancelScope(deviceId) {
161
+ const scopeToken = {};
162
+ const abortController = new AbortController();
163
+ this._cancelScopes.set(scopeToken, { deviceId, abortController });
164
+ return {
165
+ signal: abortController.signal,
166
+ release: () => {
167
+ this._cancelScopes.delete(scopeToken);
168
+ }
169
+ };
127
170
  }
128
- /** Force cancel the active job. `reason` becomes signal.reason. */
129
- forceCancelActive(deviceId, reason) {
171
+ /**
172
+ * Cancels the running job only; `reason` becomes signal.reason. Adapters use
173
+ * `cancelActiveAndPending`; this stays for a connector layer that stops only what is on the wire.
174
+ */
175
+ cancelActive(deviceId, reason) {
130
176
  if (!this._active) return false;
131
177
  if (deviceId && this._active.deviceId !== deviceId) return false;
132
- this._active.abortController.abort(_nullishCoalesce(reason, () => ( new Error("Force cancelled for recovery"))));
178
+ this._active.abortController.abort(_nullishCoalesce(reason, () => ( new Error("Cancelled"))));
133
179
  return true;
134
180
  }
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. */
181
+ /**
182
+ * Cancels the active job and unstarted queued jobs; returns whether anything was reached. Only
183
+ * `undefined` means everything: an empty key matches nothing instead of tearing the queue down.
184
+ */
141
185
  cancelActiveAndPending(deviceId, reason) {
142
- if (deviceId && this._active && this._active.deviceId !== deviceId) {
143
- return false;
186
+ const cancelReason = _nullishCoalesce(reason, () => ( new Error("Cancelled by cancelActiveAndPending")));
187
+ if (deviceId !== void 0) {
188
+ let cancelled = false;
189
+ const targets = [this._jobs, this._cancelScopes];
190
+ for (const map of targets) {
191
+ for (const target of map.values()) {
192
+ if (target.deviceId !== deviceId) continue;
193
+ target.abortController.abort(cancelReason);
194
+ cancelled = true;
195
+ }
196
+ }
197
+ return cancelled;
144
198
  }
145
- this.clear(_nullishCoalesce(reason, () => ( new Error("Cancelled by cancelActiveAndPending"))));
146
- return true;
199
+ const reached = this._active !== null || this._jobs.size > 0 || this._cancelScopes.size > 0;
200
+ this.clear(cancelReason);
201
+ return reached;
147
202
  }
148
203
  /** Get info about the currently active job, or null if idle. */
149
204
  getActiveJob(deviceId) {
@@ -155,10 +210,6 @@ var DeviceJobQueue = class {
155
210
  startedAt: this._active.startedAt
156
211
  };
157
212
  }
158
- /** True if any job is currently running. */
159
- isBusy() {
160
- return this._jobs.size > 0;
161
- }
162
213
  clear(reason) {
163
214
  const cancelledGeneration = this._generation;
164
215
  this._generation++;
@@ -172,9 +223,219 @@ var DeviceJobQueue = class {
172
223
  if (this._active) {
173
224
  this._active.abortController.abort(cancelReason);
174
225
  }
226
+ for (const scope of this._cancelScopes.values()) {
227
+ scope.abortController.abort(cancelReason);
228
+ }
175
229
  }
176
230
  };
177
231
 
232
+ // src/utils/hardwareRuntimeId.ts
233
+
234
+ var HARDWARE_RUNTIME_ID_PREFIX = "hwk:runtime";
235
+ var RANDOM_ID_BYTES = 16;
236
+ var RANDOM_ID_PATTERN = /^[0-9a-f]{32}$/;
237
+ var KINDS = /* @__PURE__ */ new Set([
238
+ "operation",
239
+ "search-target",
240
+ "link"
241
+ ]);
242
+ var VENDORS = /* @__PURE__ */ new Set(["trezor", "ledger", "keystone"]);
243
+ function create(kind, vendor) {
244
+ return `${HARDWARE_RUNTIME_ID_PREFIX}:${kind}:${vendor}:${_utils.bytesToHex.call(void 0,
245
+ _utils.randomBytes.call(void 0, RANDOM_ID_BYTES)
246
+ )}`;
247
+ }
248
+ function createHardwareOperationId(vendor) {
249
+ return create("operation", vendor);
250
+ }
251
+ function createHardwareSearchTargetId(vendor) {
252
+ return create("search-target", vendor);
253
+ }
254
+ function createHardwareLinkId(vendor) {
255
+ return create("link", vendor);
256
+ }
257
+ function hasHardwareRuntimeIdPrefix(value) {
258
+ return typeof value === "string" && value.startsWith(`${HARDWARE_RUNTIME_ID_PREFIX}:`);
259
+ }
260
+ function parseHardwareRuntimeId(value) {
261
+ if (!hasHardwareRuntimeIdPrefix(value)) return void 0;
262
+ const parts = value.split(":");
263
+ if (parts.length !== 5) return void 0;
264
+ const [, , kind, vendor, nonce] = parts;
265
+ if (!KINDS.has(kind) || !VENDORS.has(vendor) || !RANDOM_ID_PATTERN.test(nonce)) {
266
+ return void 0;
267
+ }
268
+ return { kind, vendor };
269
+ }
270
+ function isHardwareOperationId(value) {
271
+ return _optionalChain([parseHardwareRuntimeId, 'call', _3 => _3(value), 'optionalAccess', _4 => _4.kind]) === "operation";
272
+ }
273
+
274
+ // src/utils/OperationRegistry.ts
275
+ var OPERATION_DEFAULT_TTL_MS = 6e5;
276
+ var uniqueKeys = (keys) => Array.from(new Set(keys.filter(Boolean)));
277
+ var OperationRegistry = class {
278
+ constructor(options) {
279
+ this._active = /* @__PURE__ */ new Map();
280
+ this._ended = /* @__PURE__ */ new Map();
281
+ this._vendor = options.vendor;
282
+ this._ttlMs = _nullishCoalesce(options.ttlMs, () => ( OPERATION_DEFAULT_TTL_MS));
283
+ this._onEnded = options.onEnded;
284
+ }
285
+ create(params) {
286
+ const now = Date.now();
287
+ const operationId = createHardwareOperationId(this._vendor);
288
+ const operation = {
289
+ operationId,
290
+ connectId: params.connectId,
291
+ device: params.device,
292
+ connectionType: params.connectionType,
293
+ connectionKeys: uniqueKeys([
294
+ params.searchTargetId,
295
+ params.connectId,
296
+ ..._nullishCoalesce(params.connectionKeys, () => ( []))
297
+ ]),
298
+ createdAt: now,
299
+ lastActiveAt: now
300
+ };
301
+ const timer = this._createTimer(operationId);
302
+ this._active.set(operationId, { ...operation, timer, retainCount: 0 });
303
+ return operation;
304
+ }
305
+ resolve(operationId) {
306
+ const active = this._active.get(operationId);
307
+ if (!active) {
308
+ const ended = this._ended.get(operationId);
309
+ if (ended) {
310
+ throw _chunkT5HIQPNGjs.createHwkError.call(void 0, {
311
+ code: 10113 /* OperationEnded */,
312
+ message: `Hardware operation has ended (${ended.reason})`,
313
+ params: { operationId, reason: ended.reason }
314
+ });
315
+ }
316
+ throw _chunkT5HIQPNGjs.createHwkError.call(void 0, {
317
+ code: 10112 /* OperationNotFound */,
318
+ message: "Hardware operation was not found",
319
+ params: { operationId }
320
+ });
321
+ }
322
+ this._touch(active);
323
+ return active;
324
+ }
325
+ /** Keep an operation alive while one device job is actively using it. */
326
+ retain(operationId) {
327
+ const active = this.resolve(operationId);
328
+ active.retainCount += 1;
329
+ this._touch(active);
330
+ let released = false;
331
+ return () => {
332
+ if (released) return;
333
+ released = true;
334
+ const current = this._active.get(operationId);
335
+ if (!current) return;
336
+ current.retainCount = Math.max(0, current.retainCount - 1);
337
+ this._touch(current);
338
+ };
339
+ }
340
+ /** Return active or tombstoned binding data without refreshing its TTL. */
341
+ find(operationId) {
342
+ return _nullishCoalesce(this._active.get(operationId), () => ( _optionalChain([this, 'access', _5 => _5._ended, 'access', _6 => _6.get, 'call', _7 => _7(operationId), 'optionalAccess', _8 => _8.operation])));
343
+ }
344
+ findActiveByConnectionKey(connectionKey) {
345
+ if (!connectionKey) return void 0;
346
+ return [...this._active.values()].find(
347
+ (operation) => operation.connectionKeys.includes(connectionKey)
348
+ );
349
+ }
350
+ /** Replace the live transport binding after the same target was reconnected. */
351
+ rebind(operationId, params) {
352
+ const active = this.resolve(operationId);
353
+ active.connectId = params.connectId;
354
+ active.device = params.device;
355
+ active.connectionType = params.connectionType;
356
+ active.connectionKeys = uniqueKeys([params.connectId, ..._nullishCoalesce(params.connectionKeys, () => ( []))]);
357
+ this._touch(active);
358
+ return active;
359
+ }
360
+ end(operationId, reason) {
361
+ const active = this._active.get(operationId);
362
+ if (!active) return void 0;
363
+ if (active.timer) clearTimeout(active.timer);
364
+ this._active.delete(operationId);
365
+ this._rememberEnded(active, reason);
366
+ _optionalChain([this, 'access', _9 => _9._onEnded, 'optionalCall', _10 => _10(active, reason)]);
367
+ return active;
368
+ }
369
+ endByConnectionKey(connectionKey, reason, exceptOperationId) {
370
+ if (!connectionKey) return;
371
+ for (const operation of [...this._active.values()]) {
372
+ if (operation.operationId === exceptOperationId) continue;
373
+ if (operation.connectionKeys.includes(connectionKey)) {
374
+ this.end(operation.operationId, reason);
375
+ }
376
+ }
377
+ }
378
+ endAll(reason, exceptOperationId) {
379
+ for (const operationId of [...this._active.keys()]) {
380
+ if (operationId === exceptOperationId) continue;
381
+ this.end(operationId, reason);
382
+ }
383
+ }
384
+ _touch(active) {
385
+ if (active.timer) clearTimeout(active.timer);
386
+ active.lastActiveAt = Date.now();
387
+ active.timer = active.retainCount === 0 ? this._createTimer(active.operationId) : void 0;
388
+ }
389
+ _createTimer(operationId) {
390
+ const timer = setTimeout(() => {
391
+ this.end(operationId, "timeout");
392
+ }, this._ttlMs);
393
+ _optionalChain([timer, 'access', _11 => _11.unref, 'optionalCall', _12 => _12()]);
394
+ return timer;
395
+ }
396
+ _rememberEnded(operation, reason) {
397
+ this._ended.set(operation.operationId, { reason, operation });
398
+ if (this._ended.size <= 100) return;
399
+ const oldest = this._ended.keys().next().value;
400
+ if (oldest) this._ended.delete(oldest);
401
+ }
402
+ };
403
+
404
+ // src/utils/hardwareOperationTarget.ts
405
+ function resolveHardwareOperationTarget(positionalTargetId, commonOperationId, expectedVendor) {
406
+ const targetId = _nullishCoalesce(positionalTargetId, () => ( void 0));
407
+ const commonId = commonOperationId || void 0;
408
+ const parsedTarget = parseHardwareRuntimeId(targetId);
409
+ const parsedCommon = parseHardwareRuntimeId(commonId);
410
+ const positionalOperationId = _optionalChain([parsedTarget, 'optionalAccess', _13 => _13.kind]) === "operation" ? targetId : void 0;
411
+ if (hasHardwareRuntimeIdPrefix(targetId) && !parsedTarget) {
412
+ return failure(10002 /* InvalidParams */, "Invalid hardware operation target id");
413
+ }
414
+ if (_optionalChain([parsedTarget, 'optionalAccess', _14 => _14.kind]) === "link") {
415
+ return failure(
416
+ 10002 /* InvalidParams */,
417
+ "Hardware transport link id cannot be used as an operation target"
418
+ );
419
+ }
420
+ if (commonId && _optionalChain([parsedCommon, 'optionalAccess', _15 => _15.kind]) !== "operation") {
421
+ return failure(10002 /* InvalidParams */, "Invalid hardware operation id");
422
+ }
423
+ if (expectedVendor && [parsedTarget, parsedCommon].some((parsed) => parsed && parsed.vendor !== expectedVendor)) {
424
+ return failure(
425
+ 10002 /* InvalidParams */,
426
+ `Hardware operation does not belong to ${expectedVendor}`
427
+ );
428
+ }
429
+ if (positionalOperationId && commonId && positionalOperationId !== commonId) {
430
+ return failure(10002 /* InvalidParams */, "Conflicting hardware operation ids", {
431
+ positionalOperationId,
432
+ commonOperationId: commonId
433
+ });
434
+ }
435
+ const operationId = _nullishCoalesce(commonId, () => ( positionalOperationId));
436
+ return success({ operationId, targetId: _nullishCoalesce(operationId, () => ( targetId)) });
437
+ }
438
+
178
439
  // src/types/connector.ts
179
440
  var EConnectorInteraction = /* @__PURE__ */ ((EConnectorInteraction2) => {
180
441
  EConnectorInteraction2["Searching"] = "searching";
@@ -190,7 +451,7 @@ function createBridgedConnector(vendor, connectionType, bridge) {
190
451
  return {
191
452
  connectionType,
192
453
  searchDevices: (options) => bridge.searchDevices({ vendor, options }),
193
- connect: (deviceId) => bridge.connect({ vendor, deviceId }),
454
+ connect: (deviceId, options) => bridge.connect({ vendor, deviceId, ...options ? { options } : {} }),
194
455
  disconnect: (sessionId) => bridge.disconnect({ vendor, sessionId }),
195
456
  call: (sessionId, method, callParams) => bridge.call({ vendor, sessionId, method, callParams }),
196
457
  cancel: (sessionId) => bridge.cancel({ vendor, sessionId }),
@@ -211,14 +472,14 @@ function createBridgedConnector(vendor, connectionType, bridge) {
211
472
  },
212
473
  off: (event, handler) => {
213
474
  const inner = handlerMap.get(event);
214
- const bridgeHandler = _optionalChain([inner, 'optionalAccess', _ => _.get, 'call', _2 => _2(handler)]);
475
+ const bridgeHandler = _optionalChain([inner, 'optionalAccess', _16 => _16.get, 'call', _17 => _17(handler)]);
215
476
  if (!bridgeHandler || !inner) return;
216
477
  bridge.offEvent({ vendor }, bridgeHandler);
217
478
  inner.delete(handler);
218
479
  if (inner.size === 0) handlerMap.delete(event);
219
480
  },
220
481
  reset: () => bridge.reset({ vendor }),
221
- configure: bridge.configure ? (config) => _optionalChain([bridge, 'access', _3 => _3.configure, 'optionalCall', _4 => _4({ vendor, config })]) : void 0,
482
+ configure: bridge.configure ? (config) => _optionalChain([bridge, 'access', _18 => _18.configure, 'optionalCall', _19 => _19({ vendor, config })]) : void 0,
222
483
  setKnownCredentials: bridge.setKnownCredentials ? (credentials) => bridge.setKnownCredentials({ vendor, credentials }) : void 0
223
484
  };
224
485
  }
@@ -287,13 +548,13 @@ function isDeviceUnavailableError(error) {
287
548
  return false;
288
549
  }
289
550
  function combinedDeviceNotFoundError(message) {
290
- return _chunkSZZF623Rjs.createHwkError.call(void 0, {
551
+ return _chunkT5HIQPNGjs.createHwkError.call(void 0, {
291
552
  code: 10100 /* DeviceNotFound */,
292
553
  message
293
554
  });
294
555
  }
295
556
  function combinedSessionNotFoundError(message) {
296
- return _chunkSZZF623Rjs.createHwkError.call(void 0, {
557
+ return _chunkT5HIQPNGjs.createHwkError.call(void 0, {
297
558
  code: 10101 /* DeviceDisconnected */,
298
559
  message
299
560
  });
@@ -322,7 +583,7 @@ function createCombinedConnector(connectors) {
322
583
  };
323
584
  const broadcastCredentials = async () => {
324
585
  await Promise.all(
325
- connectors.map((child) => Promise.resolve(_optionalChain([child, 'access', _5 => _5.setKnownCredentials, 'optionalCall', _6 => _6(sharedCredentials)])))
586
+ connectors.map((child) => Promise.resolve(_optionalChain([child, 'access', _20 => _20.setKnownCredentials, 'optionalCall', _21 => _21(sharedCredentials)])))
326
587
  );
327
588
  };
328
589
  for (const child of connectors) {
@@ -330,11 +591,14 @@ function createCombinedConnector(connectors) {
330
591
  if (mergeShared(data.credentials)) void broadcastCredentials();
331
592
  });
332
593
  }
594
+ const onTransport = (child, transportType) => !transportType || child.connectionType === transportType;
333
595
  const searchDevices = async (options = {}) => {
596
+ const selectedConnectors = connectors.map((child, index) => ({ child, index })).filter(({ child }) => onTransport(child, options.transportType));
597
+ if (!selectedConnectors.length) return [];
334
598
  const perConnector = [];
335
- await new Promise((resolve) => {
599
+ await new Promise((resolve, reject) => {
336
600
  let finished = false;
337
- let remaining = connectors.length;
601
+ let remaining = selectedConnectors.length;
338
602
  let settleTimer;
339
603
  const finish = () => {
340
604
  if (finished) return;
@@ -342,19 +606,20 @@ function createCombinedConnector(connectors) {
342
606
  if (settleTimer) clearTimeout(settleTimer);
343
607
  resolve();
344
608
  };
345
- connectors.forEach((child, index) => {
346
- void child.searchDevices().then(
609
+ selectedConnectors.forEach(({ child, index }) => {
610
+ void child.searchDevices(options.purpose ? { purpose: options.purpose } : void 0).then(
347
611
  (devices) => devices.map((device) => ({
348
612
  ...device,
349
613
  connectionType: _nullishCoalesce(device.connectionType, () => ( child.connectionType))
350
614
  }))
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) => {
615
+ ).catch((error) => {
616
+ if (options.transportType) {
617
+ finished = true;
618
+ if (settleTimer) clearTimeout(settleTimer);
619
+ reject(error);
620
+ }
621
+ return [];
622
+ }).then((devices) => {
358
623
  remaining -= 1;
359
624
  if (!finished) {
360
625
  perConnector.push({ index, devices });
@@ -371,7 +636,9 @@ function createCombinedConnector(connectors) {
371
636
  });
372
637
  });
373
638
  perConnector.sort((a, b) => a.index - b.index);
374
- deviceOwner.clear();
639
+ for (const [id, owner] of deviceOwner) {
640
+ if (onTransport(owner, options.transportType)) deviceOwner.delete(id);
641
+ }
375
642
  const merged = [];
376
643
  perConnector.forEach(({ index, devices }) => {
377
644
  for (const device of devices) {
@@ -381,11 +648,12 @@ function createCombinedConnector(connectors) {
381
648
  });
382
649
  return merged.sort((a, b) => rank(a) - rank(b));
383
650
  };
384
- const resolveOwner = async (deviceId) => {
385
- if (deviceId && deviceOwner.has(deviceId)) {
386
- return { owner: deviceOwner.get(deviceId), deviceId };
651
+ const resolveOwner = async (deviceId, transportType) => {
652
+ const cachedOwner = deviceId ? deviceOwner.get(deviceId) : void 0;
653
+ if (cachedOwner && onTransport(cachedOwner, transportType)) {
654
+ return { owner: cachedOwner, deviceId };
387
655
  }
388
- const devices = await searchDevices({ waitForAll: Boolean(deviceId) });
656
+ const devices = await searchDevices({ waitForAll: Boolean(deviceId), transportType });
389
657
  if (deviceId) {
390
658
  const owner = deviceOwner.get(deviceId);
391
659
  if (!owner)
@@ -396,13 +664,14 @@ function createCombinedConnector(connectors) {
396
664
  if (!first) throw combinedDeviceNotFoundError("Combined connector: no devices found");
397
665
  return { owner: deviceOwner.get(first.connectId), deviceId: first.connectId };
398
666
  };
399
- const connectByExplicitId = async (deviceId) => {
667
+ const connectByExplicitId = async (deviceId, transportType) => {
400
668
  const cachedOwner = deviceOwner.get(deviceId);
401
- if (cachedOwner) {
669
+ if (cachedOwner && onTransport(cachedOwner, transportType)) {
402
670
  return { session: await cachedOwner.connect(deviceId), owner: cachedOwner };
403
671
  }
404
672
  let lastError;
405
673
  for (const child of connectors) {
674
+ if (!onTransport(child, transportType)) continue;
406
675
  try {
407
676
  const session = await child.connect(deviceId);
408
677
  deviceOwner.set(deviceId, child);
@@ -415,7 +684,7 @@ function createCombinedConnector(connectors) {
415
684
  }
416
685
  }
417
686
  const message = lastError instanceof Error ? lastError.message : `Combined connector: device not found: ${deviceId}`;
418
- throw _chunkSZZF623Rjs.createHwkError.call(void 0, {
687
+ throw _chunkT5HIQPNGjs.createHwkError.call(void 0, {
419
688
  code: 10100 /* DeviceNotFound */,
420
689
  message
421
690
  });
@@ -424,14 +693,15 @@ function createCombinedConnector(connectors) {
424
693
  // Nominal value only — the per-device `connectionType` is authoritative
425
694
  // for a fused connector.
426
695
  connectionType: connectors[0].connectionType,
427
- searchDevices: (options) => searchDevices({ waitForAll: _optionalChain([options, 'optionalAccess', _7 => _7.waitForAll]) }),
428
- connect: async (deviceId) => {
696
+ availableTransports: [...new Set(connectors.map((child) => child.connectionType))],
697
+ searchDevices: (options) => searchDevices(options),
698
+ connect: async (deviceId, options) => {
429
699
  let owner;
430
700
  let session;
431
701
  if (deviceId) {
432
- ({ session, owner } = await connectByExplicitId(deviceId));
702
+ ({ session, owner } = await connectByExplicitId(deviceId, _optionalChain([options, 'optionalAccess', _22 => _22.transportType])));
433
703
  } else {
434
- const resolved = await resolveOwner();
704
+ const resolved = await resolveOwner(void 0, _optionalChain([options, 'optionalAccess', _23 => _23.transportType]));
435
705
  owner = resolved.owner;
436
706
  session = await owner.connect(resolved.deviceId);
437
707
  }
@@ -453,8 +723,11 @@ function createCombinedConnector(connectors) {
453
723
  },
454
724
  cancel: async (sessionId) => {
455
725
  const owner = sessionOwner.get(sessionId);
456
- if (!owner) return;
457
- await owner.cancel(sessionId);
726
+ if (owner) {
727
+ await owner.cancel(sessionId);
728
+ return;
729
+ }
730
+ await Promise.all(connectors.map((child) => child.cancel(sessionId)));
458
731
  },
459
732
  uiResponse: (response) => {
460
733
  for (const child of connectors) child.uiResponse(response);
@@ -474,7 +747,7 @@ function createCombinedConnector(connectors) {
474
747
  },
475
748
  off: (event, handler) => {
476
749
  const inner = forwarders.get(event);
477
- const attached = _optionalChain([inner, 'optionalAccess', _8 => _8.get, 'call', _9 => _9(handler)]);
750
+ const attached = _optionalChain([inner, 'optionalAccess', _24 => _24.get, 'call', _25 => _25(handler)]);
478
751
  if (!attached || !inner) return;
479
752
  for (const { child, handler: forward } of attached) {
480
753
  child.off(event, forward);
@@ -489,7 +762,7 @@ function createCombinedConnector(connectors) {
489
762
  forwarders.clear();
490
763
  },
491
764
  configure: connectors.some((c) => c.configure) ? async (config) => {
492
- await Promise.all(connectors.map((child) => Promise.resolve(_optionalChain([child, 'access', _10 => _10.configure, 'optionalCall', _11 => _11(config)]))));
765
+ await Promise.all(connectors.map((child) => Promise.resolve(_optionalChain([child, 'access', _26 => _26.configure, 'optionalCall', _27 => _27(config)]))));
493
766
  deviceOwner.clear();
494
767
  sessionOwner.clear();
495
768
  } : void 0,
@@ -533,10 +806,145 @@ var TypedEventEmitter = class {
533
806
  }
534
807
  /** Number of listeners registered for `event`. 0 if none. */
535
808
  listenerCount(event) {
536
- return _nullishCoalesce(_optionalChain([this, 'access', _12 => _12._listeners, 'access', _13 => _13.get, 'call', _14 => _14(event), 'optionalAccess', _15 => _15.size]), () => ( 0));
809
+ return _nullishCoalesce(_optionalChain([this, 'access', _28 => _28._listeners, 'access', _29 => _29.get, 'call', _30 => _30(event), 'optionalAccess', _31 => _31.size]), () => ( 0));
537
810
  }
538
811
  };
539
812
 
813
+ // src/utils/requestSaveDeviceBinding.ts
814
+ async function requestSaveDeviceBinding(emitter, registry, binding, signal) {
815
+ const type = _chunkH7BZ2C6Jjs.UI_REQUEST.REQUEST_SAVE_DEVICE_BINDING;
816
+ const emitStatus = (status) => emitter.emit(_chunkH7BZ2C6Jjs.UI_REQUEST.DEVICE_BINDING_STATUS, {
817
+ type: _chunkH7BZ2C6Jjs.UI_REQUEST.DEVICE_BINDING_STATUS,
818
+ payload: { selectionRequestId: binding.selectionRequestId, status }
819
+ });
820
+ const declined = (reason) => {
821
+ emitStatus("failed");
822
+ return { saved: false, reason };
823
+ };
824
+ if (!emitter.listenerCount(type)) {
825
+ return declined("skipped");
826
+ }
827
+ if (_optionalChain([signal, 'optionalAccess', _32 => _32.aborted])) throw signal.reason;
828
+ const requestId = registry.createRequestId();
829
+ const pending = registry.wait(type, { requestId, operationId: binding.operationId });
830
+ void pending.catch(() => void 0);
831
+ const cancel = () => registry.cancel(type, requestId);
832
+ _optionalChain([signal, 'optionalAccess', _33 => _33.addEventListener, 'call', _34 => _34("abort", cancel, { once: true })]);
833
+ try {
834
+ emitter.emit(type, { type, payload: { ...binding, requestId } });
835
+ const response = await pending;
836
+ if (_optionalChain([signal, 'optionalAccess', _35 => _35.aborted])) throw signal.reason;
837
+ if (_optionalChain([response, 'optionalAccess', _36 => _36.saved]) !== true) {
838
+ return declined(_nullishCoalesce(_optionalChain([response, 'optionalAccess', _37 => _37.reason]), () => ( "skipped")));
839
+ }
840
+ emitStatus("saved");
841
+ return { saved: true };
842
+ } catch (error) {
843
+ if (_optionalChain([signal, 'optionalAccess', _38 => _38.aborted])) {
844
+ emitStatus("cancelled");
845
+ throw error;
846
+ }
847
+ return declined("skipped");
848
+ } finally {
849
+ _optionalChain([signal, 'optionalAccess', _39 => _39.removeEventListener, 'call', _40 => _40("abort", cancel)]);
850
+ registry.cancel(type, requestId);
851
+ }
852
+ }
853
+
854
+ // src/utils/requestBleDeviceSelection.ts
855
+ async function requestBleDeviceSelection({
856
+ emitter,
857
+ registry,
858
+ request,
859
+ scan,
860
+ signal,
861
+ allowUsbFallback = false,
862
+ pollIntervalMs = 1500
863
+ }) {
864
+ const type = _chunkH7BZ2C6Jjs.UI_REQUEST.REQUEST_SELECT_DEVICE;
865
+ if (signal.aborted) throw signal.reason;
866
+ if (!emitter.listenerCount(type)) {
867
+ throw _chunkT5HIQPNGjs.createHwkError.call(void 0, {
868
+ code: 10100 /* DeviceNotFound */,
869
+ message: "Select a Bluetooth device before continuing"
870
+ });
871
+ }
872
+ const requestId = registry.createRequestId();
873
+ const { operationId } = request;
874
+ let devices = allowUsbFallback ? request.devices.filter((device) => device.connectionType === "ble") : request.devices;
875
+ const publishedDevices = /* @__PURE__ */ new Map();
876
+ let stopped = false;
877
+ let timer;
878
+ let wake;
879
+ const stop = () => {
880
+ stopped = true;
881
+ if (timer !== void 0) clearTimeout(timer);
882
+ _optionalChain([wake, 'optionalCall', _41 => _41()]);
883
+ };
884
+ const waitForNextScan = () => new Promise((resolve) => {
885
+ wake = resolve;
886
+ timer = setTimeout(resolve, pollIntervalMs);
887
+ if (stopped) resolve();
888
+ });
889
+ const cancel = () => registry.cancel(type, requestId);
890
+ const reply = registry.wait(type, { requestId, operationId }).finally(stop);
891
+ void reply.catch(() => void 0);
892
+ const publish = () => {
893
+ for (const device of devices) publishedDevices.set(device.connectId, device);
894
+ emitter.emit(type, {
895
+ type,
896
+ payload: { ...request, devices, requestId, scanning: true }
897
+ });
898
+ };
899
+ signal.addEventListener("abort", cancel, { once: true });
900
+ let polling;
901
+ try {
902
+ publish();
903
+ polling = (async () => {
904
+ await Promise.resolve();
905
+ while (!stopped) {
906
+ const snapshot = await scan();
907
+ if (stopped || signal.aborted) return;
908
+ const usbFallback = allowUsbFallback ? snapshot.find((device2) => device2.connectionType === "usb") : void 0;
909
+ if (usbFallback) return usbFallback;
910
+ devices = snapshot;
911
+ publish();
912
+ await waitForNextScan();
913
+ }
914
+ })();
915
+ const userSelection = reply.then((selected) => publishedDevices.get(selected.sdkConnectId));
916
+ const device = await Promise.race([
917
+ userSelection,
918
+ polling.then((usbFallback) => _nullishCoalesce(usbFallback, () => ( userSelection)))
919
+ ]);
920
+ stop();
921
+ await polling;
922
+ if (signal.aborted) throw signal.reason;
923
+ if (!device) {
924
+ throw _chunkT5HIQPNGjs.createHwkError.call(void 0, {
925
+ code: 10100 /* DeviceNotFound */,
926
+ message: "Selected Bluetooth device is no longer available"
927
+ });
928
+ }
929
+ emitter.emit(_chunkH7BZ2C6Jjs.UI_REQUEST.DEVICE_BINDING_STATUS, {
930
+ type: _chunkH7BZ2C6Jjs.UI_REQUEST.DEVICE_BINDING_STATUS,
931
+ payload: { selectionRequestId: requestId, status: "verifying" }
932
+ });
933
+ return { device, requestId };
934
+ } catch (error) {
935
+ emitter.emit(_chunkH7BZ2C6Jjs.UI_REQUEST.DEVICE_BINDING_STATUS, {
936
+ type: _chunkH7BZ2C6Jjs.UI_REQUEST.DEVICE_BINDING_STATUS,
937
+ payload: { selectionRequestId: requestId, status: signal.aborted ? "cancelled" : "failed" }
938
+ });
939
+ throw error;
940
+ } finally {
941
+ stop();
942
+ signal.removeEventListener("abort", cancel);
943
+ registry.cancel(type, requestId);
944
+ await _optionalChain([polling, 'optionalAccess', _42 => _42.catch, 'call', _43 => _43(() => void 0)]);
945
+ }
946
+ }
947
+
540
948
  // src/utils/semver.ts
541
949
  function compareSemver(a, b) {
542
950
  const pa = a.split(".").map(Number);
@@ -564,15 +972,87 @@ function padHex64(hex) {
564
972
  function hexToBytes(hex) {
565
973
  return _utils.hexToBytes.call(void 0, stripHex(hex));
566
974
  }
567
- function bytesToHex2(bytes) {
975
+ function bytesToHex3(bytes) {
568
976
  return _utils.bytesToHex.call(void 0, bytes);
569
977
  }
570
978
 
979
+ // src/utils/solanaOffchainMessage.ts
980
+ var SOLANA_OFFCHAIN_SIGNING_DOMAIN = Uint8Array.of(
981
+ 255,
982
+ ...Array.from("solana offchain", (character) => character.charCodeAt(0))
983
+ );
984
+ var SOLANA_PUBLIC_KEY_LENGTH = 32;
985
+ var MAX_SOLANA_OFFCHAIN_SIGNERS = 255;
986
+ function compareBytes(a, b) {
987
+ for (let index = 0; index < a.length; index += 1) {
988
+ const difference = (_nullishCoalesce(a[index], () => ( 0))) - (_nullishCoalesce(b[index], () => ( 0)));
989
+ if (difference !== 0) return difference;
990
+ }
991
+ return a.length - b.length;
992
+ }
993
+ function bytesEqual(a, b) {
994
+ return a.length === b.length && a.every((value, index) => value === b[index]);
995
+ }
996
+ function decodeUtf8Strict(bytes) {
997
+ return decodeURIComponent(
998
+ Array.from(bytes, (value) => `%${value.toString(16).padStart(2, "0")}`).join("")
999
+ );
1000
+ }
1001
+ function prepareSolanaOffchainMessageV1({
1002
+ message,
1003
+ requiredSigners
1004
+ }) {
1005
+ if (message.length === 0) {
1006
+ throw new Error("Solana off-chain message cannot be empty");
1007
+ }
1008
+ if (requiredSigners.length === 0 || requiredSigners.length > MAX_SOLANA_OFFCHAIN_SIGNERS) {
1009
+ throw new Error("Solana off-chain message requires between 1 and 255 signers");
1010
+ }
1011
+ let messageText;
1012
+ try {
1013
+ messageText = decodeUtf8Strict(message);
1014
+ } catch (e3) {
1015
+ throw new Error("Solana off-chain message must contain valid UTF-8");
1016
+ }
1017
+ const signerBytes = requiredSigners.map((signer, index) => {
1018
+ let bytes;
1019
+ try {
1020
+ bytes = hexToBytes(signer);
1021
+ } catch (e4) {
1022
+ throw new Error(`Solana off-chain signer ${index} must be a hex public key`);
1023
+ }
1024
+ if (bytes.length !== SOLANA_PUBLIC_KEY_LENGTH) {
1025
+ throw new Error(`Solana off-chain signer ${index} must be 32 bytes`);
1026
+ }
1027
+ return bytes;
1028
+ });
1029
+ signerBytes.sort(compareBytes);
1030
+ if (signerBytes.some((bytes, index) => index > 0 && bytesEqual(signerBytes[index - 1], bytes))) {
1031
+ throw new Error("Solana off-chain signers must be unique");
1032
+ }
1033
+ const signersOffset = SOLANA_OFFCHAIN_SIGNING_DOMAIN.length + 2;
1034
+ const messageOffset = signersOffset + signerBytes.length * SOLANA_PUBLIC_KEY_LENGTH;
1035
+ const serializedMessage = new Uint8Array(messageOffset + message.length);
1036
+ serializedMessage.set(SOLANA_OFFCHAIN_SIGNING_DOMAIN);
1037
+ serializedMessage.set([1, signerBytes.length], SOLANA_OFFCHAIN_SIGNING_DOMAIN.length);
1038
+ signerBytes.forEach(
1039
+ (signer, index) => serializedMessage.set(signer, signersOffset + index * SOLANA_PUBLIC_KEY_LENGTH)
1040
+ );
1041
+ serializedMessage.set(message, messageOffset);
1042
+ return {
1043
+ messageText,
1044
+ requiredSigners: signerBytes.map(bytesToHex3),
1045
+ serializedMessage
1046
+ };
1047
+ }
1048
+
571
1049
  // src/utils/deviceIdentity.ts
572
1050
  var ONEKEY_BLE_SERVICE_UUID = "00000001-0000-1000-8000-00805f9b34fb";
573
1051
  var TREZOR_BLE_SERVICE_UUID = "8c000001-a59b-4d58-a9ad-073df69fa1b1";
574
1052
  var LEDGER_USB_VENDOR_ID = 11415;
575
- var lower = (value) => _nullishCoalesce(_optionalChain([value, 'optionalAccess', _16 => _16.trim, 'call', _17 => _17(), 'access', _18 => _18.toLowerCase, 'call', _19 => _19()]), () => ( ""));
1053
+ var KEYSTONE_USB_VENDOR_ID = 4617;
1054
+ var KEYSTONE_USB_PRODUCT_ID = 12289;
1055
+ var lower = (value) => _nullishCoalesce(_optionalChain([value, 'optionalAccess', _44 => _44.trim, 'call', _45 => _45(), 'access', _46 => _46.toLowerCase, 'call', _47 => _47()]), () => ( ""));
576
1056
  var hasServiceUuid = (input, uuid) => {
577
1057
  const expected = uuid.toLowerCase();
578
1058
  const values = [
@@ -594,6 +1074,11 @@ function detectHardwareVendorFromDescriptor(input) {
594
1074
  if (typeof input.vendor === "number" && input.vendor === LEDGER_USB_VENDOR_ID || input.vendorId === LEDGER_USB_VENDOR_ID || manufacturerName.includes("ledger")) {
595
1075
  return "ledger";
596
1076
  }
1077
+ const usbVendorId = typeof input.vendor === "number" ? input.vendor : input.vendorId;
1078
+ const usbProductId = typeof input.product === "number" ? input.product : input.productId;
1079
+ if (usbVendorId === KEYSTONE_USB_VENDOR_ID && usbProductId === KEYSTONE_USB_PRODUCT_ID || manufacturerName.includes("keystone")) {
1080
+ return "keystone";
1081
+ }
597
1082
  return void 0;
598
1083
  }
599
1084
  function isKnownNonTargetHardwareVendor(input, targetVendor) {
@@ -610,35 +1095,69 @@ async function batchCall(params, callFn, onProgress) {
610
1095
  return result;
611
1096
  }
612
1097
  results.push(result.payload);
613
- _optionalChain([onProgress, 'optionalCall', _20 => _20({ index: i, total: params.length })]);
1098
+ _optionalChain([onProgress, 'optionalCall', _48 => _48({ index: i, total: params.length })]);
614
1099
  }
615
1100
  return { success: true, payload: results };
616
1101
  }
617
1102
 
618
1103
  // src/utils/methodCatalog.ts
619
1104
  var HARDWARE_METHOD_CATALOG = {
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 }
1105
+ evmGetAddress: { chain: "evm", allNetwork: true, replayAfterTransportFailure: "safe" },
1106
+ evmSignTransaction: {
1107
+ chain: "evm",
1108
+ allNetwork: false,
1109
+ replayAfterTransportFailure: "unsafe"
1110
+ },
1111
+ evmSignMessage: { chain: "evm", allNetwork: false, replayAfterTransportFailure: "unsafe" },
1112
+ evmSignTypedData: { chain: "evm", allNetwork: false, replayAfterTransportFailure: "unsafe" },
1113
+ btcGetAddress: { chain: "btc", allNetwork: true, replayAfterTransportFailure: "safe" },
1114
+ btcGetPublicKey: { chain: "btc", allNetwork: true, replayAfterTransportFailure: "safe" },
1115
+ btcSignTransaction: {
1116
+ chain: "btc",
1117
+ allNetwork: false,
1118
+ replayAfterTransportFailure: "unsafe"
1119
+ },
1120
+ btcSignPsbt: { chain: "btc", allNetwork: false, replayAfterTransportFailure: "unsafe" },
1121
+ btcSignMessage: { chain: "btc", allNetwork: false, replayAfterTransportFailure: "unsafe" },
1122
+ btcGetMasterFingerprint: {
1123
+ chain: "btc",
1124
+ allNetwork: false,
1125
+ replayAfterTransportFailure: "safe"
1126
+ },
1127
+ solGetAddress: { chain: "sol", allNetwork: true, replayAfterTransportFailure: "safe" },
1128
+ solSignTransaction: {
1129
+ chain: "sol",
1130
+ allNetwork: false,
1131
+ replayAfterTransportFailure: "unsafe"
1132
+ },
1133
+ solSignMessage: { chain: "sol", allNetwork: false, replayAfterTransportFailure: "unsafe" },
1134
+ tronGetAddress: { chain: "tron", allNetwork: true, replayAfterTransportFailure: "safe" },
1135
+ tronSignTransaction: {
1136
+ chain: "tron",
1137
+ allNetwork: false,
1138
+ replayAfterTransportFailure: "unsafe"
1139
+ },
1140
+ tronSignMessage: { chain: "tron", allNetwork: false, replayAfterTransportFailure: "unsafe" },
1141
+ zcashGetFullViewingKey: {
1142
+ chain: "zcash",
1143
+ allNetwork: false,
1144
+ replayAfterTransportFailure: "safe"
1145
+ },
1146
+ zcashGetShieldedAddress: {
1147
+ chain: "zcash",
1148
+ allNetwork: false,
1149
+ replayAfterTransportFailure: "safe"
1150
+ }
636
1151
  };
637
1152
  var ALL_NETWORK_METHOD_NAMES = Object.entries(HARDWARE_METHOD_CATALOG).filter(([, metadata]) => metadata.allNetwork).map(([method]) => method);
638
1153
  var ALL_NETWORK_METHOD_SET = new Set(ALL_NETWORK_METHOD_NAMES);
639
1154
  function getHardwareMethodMetadata(method) {
640
1155
  return HARDWARE_METHOD_CATALOG[method];
641
1156
  }
1157
+ var SAFE_NON_CHAIN_METHODS = /* @__PURE__ */ new Set(["getFeatures", "authenticateDevice"]);
1158
+ function canReplayHardwareMethodAfterTransportFailure(method) {
1159
+ return _optionalChain([getHardwareMethodMetadata, 'call', _49 => _49(method), 'optionalAccess', _50 => _50.replayAfterTransportFailure]) === "safe" || SAFE_NON_CHAIN_METHODS.has(method);
1160
+ }
642
1161
  function isAllNetworkMethodName(method) {
643
1162
  return ALL_NETWORK_METHOD_SET.has(method);
644
1163
  }
@@ -666,7 +1185,7 @@ async function runAllNetworkGetAddress({
666
1185
  continue;
667
1186
  }
668
1187
  const method = item.methodName;
669
- const unsupportedNetwork = _optionalChain([buildUnsupportedNetworkResponse, 'optionalCall', _21 => _21(item, method)]);
1188
+ const unsupportedNetwork = _optionalChain([buildUnsupportedNetworkResponse, 'optionalCall', _51 => _51(item, method)]);
670
1189
  if (unsupportedNetwork) {
671
1190
  responses.push(unsupportedNetwork);
672
1191
  continue;
@@ -698,6 +1217,19 @@ async function runAllNetworkGetAddress({
698
1217
  }
699
1218
  return success(responses);
700
1219
  }
1220
+ function isUserRefusal(code) {
1221
+ return code === 10005 /* UserAborted */ || code === 10001 /* UserRejected */ || code === 10401 /* PinCancelled */;
1222
+ }
1223
+ function isConnectionLost(code) {
1224
+ const codes = [
1225
+ 10101 /* DeviceDisconnected */,
1226
+ 10003 /* OperationTimeout */,
1227
+ 10300 /* TransportError */,
1228
+ 10113 /* OperationEnded */,
1229
+ 10112 /* OperationNotFound */
1230
+ ];
1231
+ return code !== void 0 && codes.includes(code);
1232
+ }
701
1233
  function buildUnsupportedMethodResponse(item) {
702
1234
  return {
703
1235
  ...item,
@@ -766,5 +1298,30 @@ var DEVICE_CONNECT_RETRY_DELAY_MS = 1e3;
766
1298
 
767
1299
 
768
1300
 
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;
1301
+
1302
+
1303
+
1304
+
1305
+
1306
+
1307
+
1308
+
1309
+
1310
+
1311
+
1312
+
1313
+
1314
+
1315
+
1316
+
1317
+
1318
+
1319
+
1320
+
1321
+
1322
+
1323
+
1324
+
1325
+
1326
+ 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 = _chunkH7BZ2C6Jjs.UI_EVENT; exports.UI_REQUEST = _chunkH7BZ2C6Jjs.UI_REQUEST; exports.UI_REQUEST_CANCELLED_TAG = _chunkH7BZ2C6Jjs.UI_REQUEST_CANCELLED_TAG; exports.UI_REQUEST_DEFAULT_TIMEOUT_MS = _chunkH7BZ2C6Jjs.UI_REQUEST_DEFAULT_TIMEOUT_MS; exports.UI_REQUEST_PREEMPTED_TAG = _chunkH7BZ2C6Jjs.UI_REQUEST_PREEMPTED_TAG; exports.UI_REQUEST_TIMEOUT_TAG = _chunkH7BZ2C6Jjs.UI_REQUEST_TIMEOUT_TAG; exports.UI_RESPONSE = _chunkH7BZ2C6Jjs.UI_RESPONSE; exports.UiRequestRegistry = _chunkH7BZ2C6Jjs.UiRequestRegistry; exports.batchCall = batchCall; 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.deriveWalletId = deriveWalletId; exports.detectHardwareVendorFromDescriptor = detectHardwareVendorFromDescriptor; 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.operationMayHaveCompletedParams = _chunkT5HIQPNGjs.operationMayHaveCompletedParams; exports.padHex64 = padHex64; exports.parseBip32MasterFingerprint = parseBip32MasterFingerprint; exports.parseHardwareRuntimeId = parseHardwareRuntimeId; exports.parseWalletMasterFingerprint = parseWalletMasterFingerprint; 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;
770
1327
  //# sourceMappingURL=index.js.map