@onekeyfe/hwk-keystone-adapter 1.2.8-alpha.126 → 1.2.8-alpha.127

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -35,15 +35,6 @@ interface KeystoneParsedMultiAccounts {
35
35
  deviceId?: string;
36
36
  deviceVersion?: string;
37
37
  accounts: KeystoneParsedAccount[];
38
- /**
39
- * Export only: paths the export carried but could not vouch for. They are left out of `accounts`
40
- * and only fail a caller that asks for one of them.
41
- */
42
- rejectedPaths?: KeystoneRejectedExportPath[];
43
- }
44
- interface KeystoneRejectedExportPath {
45
- path: string;
46
- reason: 'different-wallet' | 'conflicting-keys' | 'unusable-key';
47
38
  }
48
39
  interface KeystoneEthSignRequestInput {
49
40
  requestId: string;
@@ -142,11 +133,7 @@ declare class KeystoneUrEngine {
142
133
  * hdkey source fingerprint is the mfp only because every request here derives from the seed.
143
134
  */
144
135
  parseAccountResponse(ur: KeystoneUr): KeystoneParsedMultiAccounts;
145
- /**
146
- * Device exports are opt-in: request responses retain their existing format/path checks. An
147
- * export carries whatever the device syncs to other wallets, so each key is checked on its own: a
148
- * key that fails lands in `rejectedPaths` instead of discarding the whole export.
149
- */
136
+ /** Device exports are opt-in: request responses retain their existing format/path checks. */
150
137
  parseAccountExport(ur: KeystoneUr): KeystoneParsedMultiAccounts;
151
138
  buildEthSignRequest(input: KeystoneEthSignRequestInput): KeystoneUr;
152
139
  parseEthSignature(ur: KeystoneUr): KeystoneEthSignatureResult;
@@ -270,8 +257,6 @@ declare class KeystoneAdapter implements IHardwareWallet {
270
257
  private readonly _origin;
271
258
  /** Host answer timeout for QR display/scan requests; undefined uses the registry default. */
272
259
  private readonly _qrTimeoutMs;
273
- /** At most this many account paths per QR key request; see the constructor option. */
274
- private readonly _qrKeyRequestLimit;
275
260
  /** Host-supplied USB connector; undefined means QR-only. */
276
261
  private readonly _usbConnector;
277
262
  /** Serializes USB open/identity handshakes that run outside the job queue. */
@@ -285,15 +270,10 @@ declare class KeystoneAdapter implements IHardwareWallet {
285
270
  private _forcedTransport;
286
271
  private readonly _handleUsbDisconnect;
287
272
  private readonly _handleUsbUiEvent;
288
- /**
289
- * `qrKeyRequestLimit` caps the account paths one QR key request may ask for, below the firmware's
290
- * own limit: a host with no USB to fall back on can refuse a large request before the device does.
291
- */
292
273
  constructor(options?: {
293
274
  origin?: string;
294
275
  qrTimeoutMs?: number;
295
276
  usbConnector?: IConnector;
296
- qrKeyRequestLimit?: number;
297
277
  });
298
278
  get activeTransport(): TransportType | null;
299
279
  getAvailableTransports(): TransportType[];
@@ -402,7 +382,7 @@ declare class KeystoneAdapter implements IHardwareWallet {
402
382
  private _connectUsbExclusive;
403
383
  /**
404
384
  * Probes already-authorized USB devices without a permission picker, then attaches and verifies
405
- * the requested wallet if present. Undefined means use QR: no device, or the user chose QR.
385
+ * the requested wallet if present.
406
386
  */
407
387
  private _tryUsbAttach;
408
388
  /**
@@ -439,8 +419,6 @@ declare class KeystoneAdapter implements IHardwareWallet {
439
419
  * prompt reads as no; a cancelled call keeps its own error.
440
420
  */
441
421
  private _confirmQrFallback;
442
- /** A timeout or an unanswered prompt reads as cancel; a cancelled call keeps its own error. */
443
- private _askQrFallback;
444
422
  /** Shows `data` for the device to scan, or with no `data` asks the host to scan the device. */
445
423
  private _requestQrAndAwaitResponse;
446
424
  private _callUsbResolveUr;
package/dist/index.d.ts CHANGED
@@ -35,15 +35,6 @@ interface KeystoneParsedMultiAccounts {
35
35
  deviceId?: string;
36
36
  deviceVersion?: string;
37
37
  accounts: KeystoneParsedAccount[];
38
- /**
39
- * Export only: paths the export carried but could not vouch for. They are left out of `accounts`
40
- * and only fail a caller that asks for one of them.
41
- */
42
- rejectedPaths?: KeystoneRejectedExportPath[];
43
- }
44
- interface KeystoneRejectedExportPath {
45
- path: string;
46
- reason: 'different-wallet' | 'conflicting-keys' | 'unusable-key';
47
38
  }
48
39
  interface KeystoneEthSignRequestInput {
49
40
  requestId: string;
@@ -142,11 +133,7 @@ declare class KeystoneUrEngine {
142
133
  * hdkey source fingerprint is the mfp only because every request here derives from the seed.
143
134
  */
144
135
  parseAccountResponse(ur: KeystoneUr): KeystoneParsedMultiAccounts;
145
- /**
146
- * Device exports are opt-in: request responses retain their existing format/path checks. An
147
- * export carries whatever the device syncs to other wallets, so each key is checked on its own: a
148
- * key that fails lands in `rejectedPaths` instead of discarding the whole export.
149
- */
136
+ /** Device exports are opt-in: request responses retain their existing format/path checks. */
150
137
  parseAccountExport(ur: KeystoneUr): KeystoneParsedMultiAccounts;
151
138
  buildEthSignRequest(input: KeystoneEthSignRequestInput): KeystoneUr;
152
139
  parseEthSignature(ur: KeystoneUr): KeystoneEthSignatureResult;
@@ -270,8 +257,6 @@ declare class KeystoneAdapter implements IHardwareWallet {
270
257
  private readonly _origin;
271
258
  /** Host answer timeout for QR display/scan requests; undefined uses the registry default. */
272
259
  private readonly _qrTimeoutMs;
273
- /** At most this many account paths per QR key request; see the constructor option. */
274
- private readonly _qrKeyRequestLimit;
275
260
  /** Host-supplied USB connector; undefined means QR-only. */
276
261
  private readonly _usbConnector;
277
262
  /** Serializes USB open/identity handshakes that run outside the job queue. */
@@ -285,15 +270,10 @@ declare class KeystoneAdapter implements IHardwareWallet {
285
270
  private _forcedTransport;
286
271
  private readonly _handleUsbDisconnect;
287
272
  private readonly _handleUsbUiEvent;
288
- /**
289
- * `qrKeyRequestLimit` caps the account paths one QR key request may ask for, below the firmware's
290
- * own limit: a host with no USB to fall back on can refuse a large request before the device does.
291
- */
292
273
  constructor(options?: {
293
274
  origin?: string;
294
275
  qrTimeoutMs?: number;
295
276
  usbConnector?: IConnector;
296
- qrKeyRequestLimit?: number;
297
277
  });
298
278
  get activeTransport(): TransportType | null;
299
279
  getAvailableTransports(): TransportType[];
@@ -402,7 +382,7 @@ declare class KeystoneAdapter implements IHardwareWallet {
402
382
  private _connectUsbExclusive;
403
383
  /**
404
384
  * Probes already-authorized USB devices without a permission picker, then attaches and verifies
405
- * the requested wallet if present. Undefined means use QR: no device, or the user chose QR.
385
+ * the requested wallet if present.
406
386
  */
407
387
  private _tryUsbAttach;
408
388
  /**
@@ -439,8 +419,6 @@ declare class KeystoneAdapter implements IHardwareWallet {
439
419
  * prompt reads as no; a cancelled call keeps its own error.
440
420
  */
441
421
  private _confirmQrFallback;
442
- /** A timeout or an unanswered prompt reads as cancel; a cancelled call keeps its own error. */
443
- private _askQrFallback;
444
422
  /** Shows `data` for the device to scan, or with no `data` asks the host to scan the device. */
445
423
  private _requestQrAndAwaitResponse;
446
424
  private _callUsbResolveUr;
package/dist/index.js CHANGED
@@ -209,35 +209,6 @@ function toParsedAccount(key) {
209
209
  };
210
210
  }
211
211
  var BIP32_HARDENED_OFFSET = 2147483648;
212
- function isExportedAccountPath(path) {
213
- return /^m(?:\/\d+')+(?:\/\d+)*$/.test(path) && path.slice(2).split("/").every(
214
- (segment) => Number(segment.endsWith("'") ? segment.slice(0, -1) : segment) < BIP32_HARDENED_OFFSET
215
- );
216
- }
217
- function checkExportedKey(key, account, masterFingerprint, unsupportedDescriptor) {
218
- if (unsupportedDescriptor || key.isMaster() || key.isPrivateKey()) {
219
- return { rejected: "unusable-key" };
220
- }
221
- const source = key.getOrigin()?.getSourceFingerprint();
222
- if (source && source.toString("hex") !== masterFingerprint) {
223
- return { rejected: "different-wallet" };
224
- }
225
- if (!account.extendedPublicKey) {
226
- return /^[0-9a-f]{64}$/i.test(account.publicKey) ? { identity: account.publicKey } : { rejected: "unusable-key" };
227
- }
228
- try {
229
- const node = import_hdkey.default.fromExtendedKey(account.extendedPublicKey);
230
- if (node.privateKey || !node.publicKey || !node.chainCode || node.publicKey.toString("hex") !== account.publicKey.toLowerCase()) {
231
- return { rejected: "unusable-key" };
232
- }
233
- return { identity: `${account.publicKey}:${node.chainCode.toString("hex")}` };
234
- } catch {
235
- return { rejected: "unusable-key" };
236
- }
237
- }
238
- function unexpectedQrCodeError(message, code = import_hwk_adapter_core.HardwareErrorCode.InvalidParams) {
239
- return (0, import_hwk_adapter_core.createHwkError)({ code, message, params: { reason: "unexpected-qr-code" } });
240
- }
241
212
  function relativeHdPath(relativeDerivePath) {
242
213
  const segments = relativeDerivePath.replace(/^m\//i, "").split("/");
243
214
  const valid = segments.every(
@@ -307,32 +278,26 @@ var KeystoneUrEngine = class {
307
278
  }
308
279
  return this.parseMultiAccounts(ur);
309
280
  }
310
- /**
311
- * Device exports are opt-in: request responses retain their existing format/path checks. An
312
- * export carries whatever the device syncs to other wallets, so each key is checked on its own: a
313
- * key that fails lands in `rejectedPaths` instead of discarding the whole export.
314
- */
281
+ /** Device exports are opt-in: request responses retain their existing format/path checks. */
315
282
  parseAccountExport(ur) {
316
- let parsed;
317
- let keys;
318
- const unsupportedDescriptors = /* @__PURE__ */ new Set();
319
283
  try {
320
284
  const { cbor } = toSdkUr(ur);
285
+ let parsed;
286
+ let keys;
321
287
  if (ur.urType === "crypto-account") {
322
288
  if (!Object.values(import_bc_ur_registry3.ScriptExpressions).some((script) => script.getTag() === 409)) {
323
289
  Object.assign(import_bc_ur_registry3.ScriptExpressions, { TAPROOT: new import_ScriptExpression.ScriptExpression(409, "tr") });
324
290
  }
325
291
  import_bc_ur_registry3.extend.cbor.patchTags([409]);
326
292
  const account = import_bc_ur_registry3.CryptoAccount.fromCBOR(cbor);
327
- keys = account.getOutputDescriptors().map((output, index) => {
293
+ keys = account.getOutputDescriptors().map((output) => {
328
294
  const key = output.getHDKey();
329
295
  const path = key?.getOrigin()?.getPath();
330
296
  const script = output.getScriptExpressions().map((item) => item.getExpression()).join("/");
331
297
  const validScript = path?.startsWith("44'/0'/") && script === "pkh" || path?.startsWith("49'/0'/") && script === "sh/wpkh" || path?.startsWith("84'/0'/") && script === "wpkh" || path?.startsWith("86'/0'/") && script === "tr";
332
298
  const children = key?.getChildren();
333
- if (!key) throw new Error("Unsupported account descriptor");
334
- if (!validScript || children && children.getPath() !== "0/*") {
335
- unsupportedDescriptors.add(index);
299
+ if (!key || !validScript || children && children.getPath() !== "0/*") {
300
+ throw new Error("Unsupported account descriptor");
336
301
  }
337
302
  return key;
338
303
  });
@@ -353,43 +318,54 @@ var KeystoneUrEngine = class {
353
318
  if (!keys.length || keys.length !== parsed.accounts.length) {
354
319
  throw new Error("Empty account export");
355
320
  }
356
- } catch {
357
- throw unexpectedQrCodeError(
358
- "Unable to read account export; scan a supported Keystone account export code"
359
- );
360
- }
361
- const byPath = /* @__PURE__ */ new Map();
362
- parsed.accounts.forEach((account, index) => {
363
- if (!isExportedAccountPath(account.path)) return;
364
- const entry = byPath.get(account.path) ?? {};
365
- byPath.set(account.path, entry);
366
- const check = checkExportedKey(
367
- keys[index],
368
- account,
369
- parsed.masterFingerprint,
370
- unsupportedDescriptors.has(index)
371
- );
372
- if (check.rejected === "different-wallet") {
373
- entry.rejected = check.rejected;
374
- } else if (check.identity === void 0) {
375
- entry.rejected ?? (entry.rejected = check.rejected);
376
- } else if (entry.identity === void 0) {
377
- entry.account = account;
378
- entry.identity = check.identity;
379
- } else if (entry.identity !== check.identity && entry.rejected !== "different-wallet") {
380
- entry.rejected = "conflicting-keys";
321
+ for (const key of keys) {
322
+ if (key.isMaster() || key.isPrivateKey()) throw new Error("Account public keys required");
323
+ const source = key.getOrigin()?.getSourceFingerprint();
324
+ if (source && source.toString("hex") !== parsed.masterFingerprint) {
325
+ throw (0, import_hwk_adapter_core.createHwkError)({
326
+ code: import_hwk_adapter_core.HardwareErrorCode.DeviceMismatch,
327
+ message: "Account export contains a different wallet fingerprint"
328
+ });
329
+ }
381
330
  }
382
- });
383
- const accounts = [];
384
- const rejectedPaths = [];
385
- byPath.forEach((entry, path) => {
386
- if (entry.account && entry.rejected !== "different-wallet" && entry.rejected !== "conflicting-keys") {
387
- accounts.push(entry.account);
388
- } else if (entry.rejected) {
389
- rejectedPaths.push({ path, reason: entry.rejected });
331
+ const byPath = /* @__PURE__ */ new Map();
332
+ for (const account of parsed.accounts) {
333
+ if (!/^m(?:\/\d+')+(?:\/\d+)*$/.test(account.path) || account.path.slice(2).split("/").some(
334
+ (segment) => Number(segment.endsWith("'") ? segment.slice(0, -1) : segment) >= BIP32_HARDENED_OFFSET
335
+ )) {
336
+ throw new Error("Account export has an unsupported derivation path");
337
+ }
338
+ let identity = account.publicKey;
339
+ if (account.extendedPublicKey) {
340
+ const node = import_hdkey.default.fromExtendedKey(account.extendedPublicKey);
341
+ if (node.privateKey || !node.publicKey || !node.chainCode) {
342
+ throw new Error("Account public keys required");
343
+ }
344
+ if (node.publicKey.toString("hex") !== account.publicKey.toLowerCase()) {
345
+ throw new Error("Account public key does not match its extended key");
346
+ }
347
+ identity = `${identity}:${node.chainCode.toString("hex")}`;
348
+ } else if (!/^[0-9a-f]{64}$/i.test(account.publicKey)) {
349
+ throw new Error("Account export is missing a usable public key");
350
+ }
351
+ const previous = byPath.get(account.path);
352
+ if (previous !== void 0 && previous !== identity) {
353
+ throw (0, import_hwk_adapter_core.createHwkError)({
354
+ code: import_hwk_adapter_core.HardwareErrorCode.DeviceMismatch,
355
+ message: "Account export contains conflicting keys for the same path"
356
+ });
357
+ }
358
+ byPath.set(account.path, identity);
390
359
  }
391
- });
392
- return { ...parsed, accounts, rejectedPaths };
360
+ return parsed;
361
+ } catch (error) {
362
+ if (error && typeof error === "object" && "code" in error && error.code === import_hwk_adapter_core.HardwareErrorCode.DeviceMismatch)
363
+ throw error;
364
+ throw (0, import_hwk_adapter_core.createHwkError)({
365
+ code: import_hwk_adapter_core.HardwareErrorCode.InvalidParams,
366
+ message: "Unable to read account export; scan a supported Keystone account export code"
367
+ });
368
+ }
393
369
  }
394
370
  // --- EVM ---
395
371
  buildEthSignRequest(input) {
@@ -475,10 +451,10 @@ var KeystoneUrEngine = class {
475
451
  sameTransaction = false;
476
452
  }
477
453
  if (!sameTransaction) {
478
- throw unexpectedQrCodeError(
479
- "Keystone returned a PSBT for another transaction than the one requested",
480
- import_hwk_adapter_core.HardwareErrorCode.DeviceMismatch
481
- );
454
+ throw (0, import_hwk_adapter_core.createHwkError)({
455
+ code: import_hwk_adapter_core.HardwareErrorCode.DeviceMismatch,
456
+ message: "Keystone returned a PSBT for another transaction than the one requested"
457
+ });
482
458
  }
483
459
  return signedPsbtHex;
484
460
  }
@@ -752,11 +728,6 @@ function keystoneBtcParamsFailure(params) {
752
728
  }
753
729
  return void 0;
754
730
  }
755
- var USB_ATTACH_FAILURE_REASONS = {
756
- [import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch]: "wallet-mismatch",
757
- [import_hwk_adapter_core3.HardwareErrorCode.DeviceNotInitialized]: "wallet-mismatch",
758
- [import_hwk_adapter_core3.HardwareErrorCode.DeviceLocked]: "device-locked"
759
- };
760
731
  var KEYSTONE_MAX_KEY_DERIVATION_SCHEMAS = 24;
761
732
  var KEYSTONE_USB_REATTACH_PROBE_ATTEMPTS = 4;
762
733
  var KEYSTONE_USB_REATTACH_PROBE_INTERVAL_MS = 500;
@@ -805,37 +776,8 @@ function exactHex(value) {
805
776
  function invalidHexFailure(field) {
806
777
  return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, `${field} must be an even-length hex string`);
807
778
  }
808
- function exportedAccountAt(parsed, path) {
809
- const rejected = parsed.rejectedPaths?.find((entry) => normalizePath(entry.path) === path);
810
- switch (rejected?.reason) {
811
- case "different-wallet":
812
- throw (0, import_hwk_adapter_core3.createHwkError)({
813
- code: import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch,
814
- message: "Account export contains a different wallet fingerprint"
815
- });
816
- case "conflicting-keys":
817
- throw (0, import_hwk_adapter_core3.createHwkError)({
818
- code: import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch,
819
- message: "Account export contains conflicting keys for the same path"
820
- });
821
- case "unusable-key":
822
- throw unexpectedQrCodeError(`Account export key at ${path} is not usable`);
823
- default:
824
- return parsed.accounts.find((returned) => normalizePath(returned.path) === path);
825
- }
826
- }
827
- function parseScannedAnswer(parse) {
828
- try {
829
- return parse();
830
- } catch (error) {
831
- if (typeof error?.code === "number") throw error;
832
- throw unexpectedQrCodeError(
833
- `Scanned code is not this request's answer: ${error instanceof Error ? error.message : ""}`
834
- );
835
- }
836
- }
837
779
  function requireExportedPath(parsed, path, accountExport = false) {
838
- const account = exportedAccountAt(parsed, path);
780
+ const account = parsed.accounts.find((returned) => normalizePath(returned.path) === path);
839
781
  if (!account) {
840
782
  throw (0, import_hwk_adapter_core3.createHwkError)({
841
783
  code: accountExport ? import_hwk_adapter_core3.HardwareErrorCode.DevicePathForbidden : import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch,
@@ -868,10 +810,6 @@ function evmMessageSignature(sig) {
868
810
  return { signature: (0, import_hwk_adapter_core3.ensure0x)(sig.r + sig.s + sig.v) };
869
811
  }
870
812
  var KeystoneAdapter = class _KeystoneAdapter {
871
- /**
872
- * `qrKeyRequestLimit` caps the account paths one QR key request may ask for, below the firmware's
873
- * own limit: a host with no USB to fall back on can refuse a large request before the device does.
874
- */
875
813
  constructor(options) {
876
814
  this.vendor = "keystone";
877
815
  // No protocol-level cancel exists over Keystone USB, and QR has no transport
@@ -1030,8 +968,6 @@ var KeystoneAdapter = class _KeystoneAdapter {
1030
968
  };
1031
969
  this._origin = options?.origin ?? "OneKey";
1032
970
  this._qrTimeoutMs = options?.qrTimeoutMs;
1033
- const limit = options?.qrKeyRequestLimit;
1034
- this._qrKeyRequestLimit = limit !== void 0 && Number.isInteger(limit) && limit > 0 ? Math.min(limit, KEYSTONE_MAX_KEY_DERIVATION_SCHEMAS) : KEYSTONE_MAX_KEY_DERIVATION_SCHEMAS;
1035
971
  this.urEngine = new KeystoneUrEngine(this._origin);
1036
972
  this._jobQueue = new import_hwk_adapter_core3.DeviceJobQueue();
1037
973
  this._usbConnector = options?.usbConnector;
@@ -1558,9 +1494,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
1558
1494
  "btcSignPsbt"
1559
1495
  );
1560
1496
  _KeystoneAdapter._throwIfAborted(signal);
1561
- const signedPsbt = parseScannedAnswer(
1562
- () => this.urEngine.parseBtcPsbt(responseUr, requestPsbtHex)
1563
- );
1497
+ const signedPsbt = this.urEngine.parseBtcPsbt(responseUr, requestPsbtHex);
1564
1498
  return (0, import_hwk_adapter_core3.success)({ signedPsbt });
1565
1499
  });
1566
1500
  }
@@ -1907,7 +1841,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
1907
1841
  args.operationName
1908
1842
  );
1909
1843
  _KeystoneAdapter._throwIfAborted(signal);
1910
- const signature = parseScannedAnswer(() => args.parseResponse(responseUr));
1844
+ const signature = args.parseResponse(responseUr);
1911
1845
  _KeystoneAdapter._assertRequestIdMatches(requestId, signature.requestId);
1912
1846
  return (0, import_hwk_adapter_core3.success)(args.toPayload(signature));
1913
1847
  });
@@ -1968,11 +1902,11 @@ var KeystoneAdapter = class _KeystoneAdapter {
1968
1902
  });
1969
1903
  }
1970
1904
  const schemas = Array.from(requestedByKey.values());
1971
- if (schemas.length > this._qrKeyRequestLimit) {
1905
+ if (schemas.length > KEYSTONE_MAX_KEY_DERIVATION_SCHEMAS) {
1972
1906
  throw (0, import_hwk_adapter_core3.createHwkError)({
1973
1907
  code: import_hwk_adapter_core3.HardwareErrorCode.QrRequestTooLarge,
1974
- message: `Keystone QR requests take at most ${this._qrKeyRequestLimit} account paths here; this one needs ${schemas.length}`,
1975
- params: { limit: this._qrKeyRequestLimit, requested: schemas.length }
1908
+ message: `Keystone accepts at most ${KEYSTONE_MAX_KEY_DERIVATION_SCHEMAS} account paths per QR request; this one needs ${schemas.length}`,
1909
+ params: { limit: KEYSTONE_MAX_KEY_DERIVATION_SCHEMAS, requested: schemas.length }
1976
1910
  });
1977
1911
  }
1978
1912
  const request = {
@@ -1992,6 +1926,12 @@ var KeystoneAdapter = class _KeystoneAdapter {
1992
1926
  const parsed = responseUr.accountExport ? this.urEngine.parseAccountExport(responseUr) : this.urEngine.parseAccountResponse(responseUr);
1993
1927
  this._assertParsedIdentity(parsed, target);
1994
1928
  const firmware = getKeystoneFirmwareProfile(parsed.deviceVersion);
1929
+ if (responseUr.accountExport && parsed.accounts.some((account) => !isBip32Path(account.path))) {
1930
+ throw (0, import_hwk_adapter_core3.createHwkError)({
1931
+ code: import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
1932
+ message: "Account export contains an invalid derivation path"
1933
+ });
1934
+ }
1995
1935
  const usableSchemas = schemas.filter(
1996
1936
  (schema) => !firmware || firmware.supportedChains.includes(schema.hwkChain)
1997
1937
  );
@@ -2004,7 +1944,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
2004
1944
  });
2005
1945
  }
2006
1946
  for (const schema of usableSchemas) {
2007
- const exported = responseUr.accountExport ? exportedAccountAt(parsed, schema.path) : requireExportedPath(parsed, schema.path);
1947
+ const exported = responseUr.accountExport ? parsed.accounts.find((account) => normalizePath(account.path) === schema.path) : requireExportedPath(parsed, schema.path);
2008
1948
  if (exported) {
2009
1949
  scanned.set(accountKey(schema.hwkChain, schema.path), {
2010
1950
  ...exported,
@@ -2221,7 +2161,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
2221
2161
  }
2222
2162
  /**
2223
2163
  * Probes already-authorized USB devices without a permission picker, then attaches and verifies
2224
- * the requested wallet if present. Undefined means use QR: no device, or the user chose QR.
2164
+ * the requested wallet if present.
2225
2165
  */
2226
2166
  async _tryUsbAttach(signal, expectedMasterFingerprint, options) {
2227
2167
  _KeystoneAdapter._throwIfAborted(signal);
@@ -2265,27 +2205,13 @@ var KeystoneAdapter = class _KeystoneAdapter {
2265
2205
  signal
2266
2206
  );
2267
2207
  _KeystoneAdapter._throwIfAborted(signal);
2268
- if (attached.success) return this._devices.get(expectedMasterFingerprint);
2269
- const { code } = attached.payload;
2270
- if (code === import_hwk_adapter_core3.HardwareErrorCode.DeviceBusyInternal || code === import_hwk_adapter_core3.HardwareErrorCode.DeviceOneDeviceOnly) {
2208
+ if (!attached.success && (attached.payload.code === import_hwk_adapter_core3.HardwareErrorCode.DeviceBusyInternal || attached.payload.code === import_hwk_adapter_core3.HardwareErrorCode.DeviceOneDeviceOnly)) {
2271
2209
  throw (0, import_hwk_adapter_core3.createHwkError)({
2272
2210
  ...attached.payload,
2273
2211
  message: attached.payload.error
2274
2212
  });
2275
2213
  }
2276
- if (code === import_hwk_adapter_core3.HardwareErrorCode.DeviceNotFound || this._forcedTransport) return void 0;
2277
- const answer = await this._askQrFallback(
2278
- signal,
2279
- USB_ATTACH_FAILURE_REASONS[code] ?? "usb-unavailable"
2280
- );
2281
- if (answer === "retry") return this._tryUsbAttach(signal, expectedMasterFingerprint);
2282
- if (answer === "cancel") {
2283
- throw (0, import_hwk_adapter_core3.createHwkError)({
2284
- code: import_hwk_adapter_core3.HardwareErrorCode.UserAborted,
2285
- message: "User declined to continue by QR while the connected Keystone was unusable"
2286
- });
2287
- }
2288
- return void 0;
2214
+ return attached.success ? this._devices.get(expectedMasterFingerprint) : void 0;
2289
2215
  }
2290
2216
  /**
2291
2217
  * Decides QR vs USB for one UR round trip. A pinned 'usb' with no live session reattaches once
@@ -2584,33 +2510,29 @@ var KeystoneAdapter = class _KeystoneAdapter {
2584
2510
  */
2585
2511
  async _confirmQrFallback(signal, choice) {
2586
2512
  if (choice?.confirmed !== void 0) return choice.confirmed;
2587
- const confirmed = await this._askQrFallback(signal, "payload-too-large") === "qr";
2588
- if (choice) choice.confirmed = confirmed;
2589
- return confirmed;
2590
- }
2591
- /** A timeout or an unanswered prompt reads as cancel; a cancelled call keeps its own error. */
2592
- async _askQrFallback(signal, reason) {
2593
2513
  const requestType = import_hwk_adapter_core3.UI_REQUEST.REQUEST_QR_FALLBACK_CONFIRM;
2594
2514
  const requestId = this._uiRegistry.createRequestId();
2595
2515
  const operationId = this._activeOperationId();
2596
2516
  const release = operationId ? this._operations.retain(operationId) : void 0;
2597
2517
  try {
2598
- const waitPromise = this._uiRegistry.wait(
2599
- requestType,
2600
- { requestId, operationId }
2601
- );
2518
+ const waitPromise = this._uiRegistry.wait(requestType, {
2519
+ requestId,
2520
+ operationId
2521
+ });
2602
2522
  this.emitter.emit(requestType, {
2603
2523
  type: requestType,
2604
- payload: { vendor: "keystone", requestId, operationId, reason }
2524
+ payload: { vendor: "keystone", requestId, operationId }
2605
2525
  });
2606
- let answer;
2526
+ let confirmed = false;
2607
2527
  try {
2608
- answer = await this._awaitQrResponse(requestType, waitPromise, signal);
2528
+ confirmed = Boolean(
2529
+ (await this._awaitQrResponse(requestType, waitPromise, signal))?.confirmed
2530
+ );
2609
2531
  } catch (error) {
2610
2532
  if (signal.aborted) throw error;
2611
2533
  }
2612
- if (answer?.retry && reason !== "payload-too-large") return "retry";
2613
- return answer?.confirmed ? "qr" : "cancel";
2534
+ if (choice) choice.confirmed = confirmed;
2535
+ return confirmed;
2614
2536
  } finally {
2615
2537
  release?.();
2616
2538
  }
@@ -2638,7 +2560,10 @@ var KeystoneAdapter = class _KeystoneAdapter {
2638
2560
  }
2639
2561
  const response = await this._awaitQrResponse(requestType, waitPromise, signal);
2640
2562
  if (response.accountExport && data && !data.allowAccountExport) {
2641
- throw unexpectedQrCodeError("This request cannot be answered with an account export");
2563
+ throw (0, import_hwk_adapter_core3.createHwkError)({
2564
+ code: import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
2565
+ message: "This request cannot be answered with an account export"
2566
+ });
2642
2567
  }
2643
2568
  return {
2644
2569
  urType: response.urType,
@@ -2750,10 +2675,10 @@ var KeystoneAdapter = class _KeystoneAdapter {
2750
2675
  /** A response without the request's id is as unrelated as one with another id. */
2751
2676
  static _assertRequestIdMatches(expected, actual) {
2752
2677
  if (!actual || actual.toLowerCase() !== expected.toLowerCase()) {
2753
- throw unexpectedQrCodeError(
2754
- actual ? "Keystone response requestId does not match the pending request \u2014 discarding a stale or unrelated scan" : "Keystone response carries no requestId \u2014 discarding a stale or unrelated scan",
2755
- import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch
2756
- );
2678
+ throw (0, import_hwk_adapter_core3.createHwkError)({
2679
+ code: import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch,
2680
+ message: actual ? "Keystone response requestId does not match the pending request \u2014 discarding a stale or unrelated scan" : "Keystone response carries no requestId \u2014 discarding a stale or unrelated scan"
2681
+ });
2757
2682
  }
2758
2683
  }
2759
2684
  _unsupported(method, reason) {