@onekeyfe/hwk-adapter-core 1.2.3-alpha.1 → 1.2.3-alpha.2

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.
@@ -18,8 +18,9 @@ var HardwareErrorCode = /* @__PURE__ */ ((HardwareErrorCode2) => {
18
18
  HardwareErrorCode2[HardwareErrorCode2["DeviceOneDeviceOnly"] = 10109] = "DeviceOneDeviceOnly";
19
19
  HardwareErrorCode2[HardwareErrorCode2["DevicePathForbidden"] = 10110] = "DevicePathForbidden";
20
20
  HardwareErrorCode2[HardwareErrorCode2["DeviceBusyInternal"] = 10111] = "DeviceBusyInternal";
21
- HardwareErrorCode2[HardwareErrorCode2["InteractionNotFound"] = 10112] = "InteractionNotFound";
22
- HardwareErrorCode2[HardwareErrorCode2["InteractionEnded"] = 10113] = "InteractionEnded";
21
+ HardwareErrorCode2[HardwareErrorCode2["OperationNotFound"] = 10112] = "OperationNotFound";
22
+ HardwareErrorCode2[HardwareErrorCode2["OperationEnded"] = 10113] = "OperationEnded";
23
+ HardwareErrorCode2[HardwareErrorCode2["DeviceSearchMismatch"] = 10114] = "DeviceSearchMismatch";
23
24
  HardwareErrorCode2[HardwareErrorCode2["FirmwareTooOld"] = 10200] = "FirmwareTooOld";
24
25
  HardwareErrorCode2[HardwareErrorCode2["FirmwareUpdateRequired"] = 10201] = "FirmwareUpdateRequired";
25
26
  HardwareErrorCode2[HardwareErrorCode2["TransportError"] = 10300] = "TransportError";
@@ -61,9 +62,10 @@ var ORPHAN_ELIGIBLE_ERROR_CODES = [
61
62
  10001 /* UserRejected */,
62
63
  10100 /* DeviceNotFound */,
63
64
  10101 /* DeviceDisconnected */,
64
- 10112 /* InteractionNotFound */,
65
- 10113 /* InteractionEnded */,
65
+ 10112 /* OperationNotFound */,
66
+ 10113 /* OperationEnded */,
66
67
  10106 /* DeviceMismatch */,
68
+ 10114 /* DeviceSearchMismatch */,
67
69
  10107 /* DeviceAppStuck */,
68
70
  10109 /* DeviceOneDeviceOnly */,
69
71
  10300 /* TransportError */,
@@ -77,8 +79,8 @@ var ORPHAN_ELIGIBLE_ERROR_CODES = [
77
79
  10405 /* PassphraseAlwaysOnDevice */
78
80
  ];
79
81
  var RECOVERY_SCOPES = /* @__PURE__ */ new Set([
82
+ "call",
80
83
  "operation",
81
- "interaction",
82
84
  "search-target",
83
85
  "transport",
84
86
  "not-recoverable",
@@ -89,8 +91,8 @@ function isHwkRecoveryHint(value) {
89
91
  const { scope } = value;
90
92
  return typeof scope === "string" && RECOVERY_SCOPES.has(scope);
91
93
  }
94
+ var RECOVERY_CALL = Object.freeze({ scope: "call" });
92
95
  var RECOVERY_OPERATION = Object.freeze({ scope: "operation" });
93
- var RECOVERY_INTERACTION = Object.freeze({ scope: "interaction" });
94
96
  var RECOVERY_SEARCH_TARGET = Object.freeze({ scope: "search-target" });
95
97
  var RECOVERY_TRANSPORT = Object.freeze({ scope: "transport" });
96
98
  var RECOVERY_NOT_RECOVERABLE = Object.freeze({
@@ -129,19 +131,20 @@ function defaultRecoveryForCode(code) {
129
131
  case 11202 /* TronSignByHashRequired */:
130
132
  case 11300 /* BtcWalletPolicyHmacMismatch */:
131
133
  case 11301 /* BtcUnexpectedState */:
132
- return RECOVERY_OPERATION;
134
+ return RECOVERY_CALL;
133
135
  case 10100 /* DeviceNotFound */:
134
136
  case 10101 /* DeviceDisconnected */:
135
- case 10112 /* InteractionNotFound */:
136
- case 10113 /* InteractionEnded */:
137
+ case 10112 /* OperationNotFound */:
138
+ case 10113 /* OperationEnded */:
137
139
  case 10300 /* TransportError */:
138
140
  case 10304 /* BlePairingTimeout */:
139
141
  case 10306 /* ThpPairingFailed */:
140
142
  case 10308 /* ThpPairingRequired */:
141
143
  case 10309 /* BleConnectFailed */:
142
144
  case 10310 /* BlePairingCancelled */:
143
- return RECOVERY_INTERACTION;
145
+ return RECOVERY_OPERATION;
144
146
  case 10106 /* DeviceMismatch */:
147
+ case 10114 /* DeviceSearchMismatch */:
145
148
  case 10109 /* DeviceOneDeviceOnly */:
146
149
  case 10307 /* BleBondInvalid */:
147
150
  return RECOVERY_SEARCH_TARGET;
@@ -169,6 +172,7 @@ function defaultOriginForCode(code) {
169
172
  case 10104 /* DeviceNotInitialized */:
170
173
  case 10105 /* DeviceInBootloader */:
171
174
  case 10106 /* DeviceMismatch */:
175
+ case 10114 /* DeviceSearchMismatch */:
172
176
  case 10107 /* DeviceAppStuck */:
173
177
  case 10110 /* DevicePathForbidden */:
174
178
  case 10111 /* DeviceBusyInternal */:
@@ -237,4 +241,4 @@ export {
237
241
  operationMayHaveCompletedParams,
238
242
  createHwkError
239
243
  };
240
- //# sourceMappingURL=chunk-72KOSYTH.mjs.map
244
+ //# sourceMappingURL=chunk-E3UPXUN5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/errors.ts"],"sourcesContent":["/**\n * HWK HardwareErrorCode — independent namespace from the legacy\n * `@onekeyfe/shared` HardwareErrorCode (which occupies 0-902).\n *\n * All HWK codes are 5-digit (>= 10000) so the two tables never collide\n * even if either side grows. Each sub-category gets a 100-slot block.\n *\n * 10000-10099 Generic / cross-cutting primitives\n * 10100-10199 Device state\n * 10200-10299 Firmware\n * 10300-10399 Transport + OS-level permission\n * 10400-10499 PIN / Passphrase\n * 10500-10599 App lifecycle (wrong app, not open, too old)\n * 10600-10699 Payload / framing limits (adapter-level)\n * 10700-10999 RESERVED — future adapter-level categories\n *\n * 11000-11099 EVM APDU (reactive mapping)\n * 11100-11199 Solana APDU\n * 11200-11299 Tron APDU\n * 11300-11399 BTC APDU\n * 11400-11999 RESERVED — future chain APDU blocks (100 per chain)\n *\n * 12000-99999 RESERVED — future major categories\n */\nexport enum HardwareErrorCode {\n // --- 10000s Generic ---\n UnknownError = 10000,\n UserRejected = 10001,\n InvalidParams = 10002,\n OperationTimeout = 10003,\n MethodNotSupported = 10004,\n /** User dismissed in-app cancel UI. Distinct from UserRejected (on-device). */\n UserAborted = 10005,\n\n // --- 10100s Device state ---\n DeviceNotFound = 10100,\n DeviceDisconnected = 10101,\n DeviceBusy = 10102,\n DeviceLocked = 10103,\n DeviceNotInitialized = 10104,\n DeviceInBootloader = 10105,\n DeviceMismatch = 10106,\n /** Chain app wedged (e.g. Ledger BTC 0x6901). User must exit app on device. */\n DeviceAppStuck = 10107,\n /** Vendor (Ledger / Trezor) doesn't support the chain at all. */\n ChainNotSupported = 10108,\n /** Current operation supports only one connected device. */\n DeviceOneDeviceOnly = 10109,\n /**\n * The device rejected the requested derivation path (Trezor Failure_DataError\n * \"Forbidden key path\") — the path is non-standard or its index is outside the\n * range the device's safety checks allow. Distinct from ChainNotSupported\n * (whole chain) and MethodNotSupported (the operation/method itself).\n */\n DevicePathForbidden = 10110,\n /** Busy with our own in-flight request (queue guard / firmware Failure_Busy), not another app — wait and retry, don't close other apps. */\n DeviceBusyInternal = 10111,\n /** The supplied runtime-only operation id is unknown to this adapter instance. */\n OperationNotFound = 10112,\n /** The supplied operation ended and can never be resumed. */\n OperationEnded = 10113,\n /**\n * Discovery found devices but none of them is the wallet being looked for.\n * Milder than DeviceMismatch: nothing about the known wallet has changed, the\n * user simply has the wrong unit connected. DeviceMismatch stays reserved for\n * reaching the expected device and finding a different identity on it, which\n * can mean it was wiped, reseeded, or swapped.\n */\n DeviceSearchMismatch = 10114,\n\n // --- 10200s Firmware ---\n FirmwareTooOld = 10200,\n FirmwareUpdateRequired = 10201,\n\n // --- 10300s Transport + permission ---\n TransportError = 10300,\n BridgeNotFound = 10301,\n TransportNotAvailable = 10302,\n /**\n * OS-level permission (Bluetooth / USB / etc.) — denied, blocked,\n * unavailable, or dismissed. Consumers surface a single \"please grant\n * permission\" toast and let the user retry manually.\n */\n DevicePermissionDenied = 10303,\n /**\n * BLE SMP pairing did not complete within the GATT bonding window.\n * GATT connected but the device didn't acknowledge SMP — typically\n * because the user didn't confirm the passkey on the device, or the\n * device went out of range mid-pairing. Distinct from OperationTimeout\n * (generic) and from DeviceLocked (Secure Element actually locked).\n */\n BlePairingTimeout = 10304,\n /** Remote network failure reaching a vendor's servers (HTTP/WS). Distinct from TransportError (local USB/BLE link). */\n NetworkError = 10305,\n /**\n * Host-managed pairing handshake failed (Trezor THP). The device rejected the\n * pairing exchange — e.g. CodeEntry: the user mistyped the code shown on the\n * device, so the CPace tag didn't match (\"Unexpected Code Entry Tag\").\n * Recoverable: the user re-pairs and re-enters the code. Distinct from\n * BlePairingTimeout (BLE SMP bonding window) and UserRejected (on-device\n * reject button).\n */\n ThpPairingFailed = 10306,\n /**\n * The OS-level BLE bond is stale/invalid, so the device rejected link\n * encryption: Android GATT_INSUF_AUTHENTICATION (status 5) or iOS \"Peer\n * removed pairing information\". Happens after the device is wiped/re-flashed\n * or unpaired elsewhere while the host still holds an old bond. The SDK cannot\n * remove an OS bond — the user must forget the device in system Bluetooth\n * settings and re-pair. Distinct from BlePairingTimeout (SMP window) and\n * ThpPairingFailed (THP code mismatch).\n */\n BleBondInvalid = 10307,\n /**\n * A stored THP pairing credential was rejected by the device during the\n * handshake (device returned completion `state=0`), so the autoconnect session\n * could not be established. The SDK discards the stale credential; recovery is\n * a fresh pairing. Distinct from ThpPairingFailed (user mistyped the code\n * during an *active* pairing) and BleBondInvalid (OS-level BLE bond).\n */\n ThpPairingRequired = 10308,\n /**\n * Generic BLE connect failure where the OS dropped the specific reason. On\n * macOS the noble native binding hardcodes \"connection failed\" (and a connect\n * timeout) and discards the CoreBluetooth NSError, so the SDK cannot tell a\n * stale bond from an out-of-range / unresponsive device. Surfaced as a\n * generic \"couldn't connect — check the device, re-pair if paired before\".\n * Distinct from BleBondInvalid (a *known* stale-bond signal, iOS/Android only)\n * and BlePairingTimeout (the SMP bonding window).\n */\n BleConnectFailed = 10309,\n /**\n * The user cancelled BLE pairing from the app while the connect was still\n * waiting on the OS pairing window. Not a failure to report — the flow ends\n * because they asked it to. Distinct from UserAborted (generic in-app cancel)\n * so the pairing UI can close quietly instead of surfacing a connect error,\n * and from BlePairingTimeout (the SMP window elapsed on its own).\n */\n BlePairingCancelled = 10310,\n\n // --- 10400s PIN / Passphrase ---\n PinInvalid = 10400,\n PinCancelled = 10401,\n PassphraseRejected = 10402,\n /**\n * The passphrase entered produced a different wallet (`passphraseState`) than\n * the one the caller asked to operate on. Trezor-only: the host pins a wallet\n * by its derived state and the SDK refuses to sign with a mismatched\n * passphrase session. Surfaced by TrezorAdapter.getPassphraseState.\n */\n PassphraseStateMismatch = 10403,\n /**\n * The two new-PIN entries did not match during set/change PIN. Only host-input\n * models (Trezor Model One matrix) surface this; on-device-input models show\n * the mismatch on the device and never return it.\n */\n PinMismatch = 10404,\n /** Standard wallet is unavailable while Trezor enforces on-device passphrase entry. */\n PassphraseAlwaysOnDevice = 10405,\n\n // --- 10500s App lifecycle ---\n /** Chain app NOT INSTALLED on device. User must install via Ledger Live. */\n AppNotInstalled = 10500,\n WrongApp = 10501,\n /** 0x911c Command code not supported — app predates current SDK. */\n AppTooOld = 10502,\n /** Not enough free storage for install/update; user must uninstall apps first. */\n DeviceOutOfMemory = 10503,\n\n // --- 10600s Payload / framing limits ---\n /**\n * The call payload exceeds a transport's fixed framing capacity (e.g.\n * Keystone USB's ~12.5KB per-request cap — 200 frames of 64 bytes). Distinct\n * from a generic TransportError: the request never reached the device, and\n * retrying with the same payload over the same transport will fail the same\n * way. Callers should route the call over a different channel (e.g. Keystone\n * QR) or reduce the payload (e.g. a smaller PSBT) instead of retrying as-is.\n */\n PayloadTooLarge = 10600,\n\n // --- 11000s EVM (Ledger Ethereum App) APDU-specific ---\n /** 0x6a80 Invalid data — observed on blindSignTransactionFallback when the\n * user has not enabled Blind signing on the device. */\n EvmBlindSigningRequired = 11000,\n /** 0x6984 Plugin not installed */\n EvmClearSignPluginMissing = 11001,\n /** 0x6a84 Insufficient memory (typical on Nano S with large calldata) */\n EvmDataTooLarge = 11002,\n /** 0x6501 TransactionType not supported (app too old for EIP-1559 / blob / 7702) */\n EvmTxTypeNotSupported = 11003,\n\n // --- 11100s Solana ---\n /** 0x6808 Blind signing disabled for this instruction. */\n SolanaBlindSigningRequired = 11100,\n\n // --- 11200s Tron ---\n /** 0x6a8d Custom Contracts setting disabled (blocks TRC-20 etc.). */\n TronCustomContractRequired = 11200,\n /** 0x6a8b Transactions Data setting disabled. */\n TronDataSigningRequired = 11201,\n /** 0x6a8c Sign by Hash setting disabled (hash-signing fallback). */\n TronSignByHashRequired = 11202,\n\n // --- 11300s BTC ---\n /** 0xb008 Wallet policy HMAC mismatch or not registered. */\n BtcWalletPolicyHmacMismatch = 11300,\n /** 0xb007 Aborted due to unexpected state (malformed PSBT / missing UTXO). */\n BtcUnexpectedState = 11301,\n}\n\n/**\n * Device-level failures the SDK cannot self-recover from — affect the entire\n * batch (vs per-chain failures like AppNotInstalled / WrongApp which soft-\n * skip in onboarding). Combined with `accounts.length === 0`, signals\n * genuine orphan. Also reused as the batch-abort whitelist for HWK.\n * Single source of truth.\n *\n * UserRejected (device-side reject) is included: pressing reject is an\n * explicit \"I don't consent\" — continuing the batch to ask again on the\n * next chain is harassment, not helpful.\n */\nexport const ORPHAN_ELIGIBLE_ERROR_CODES: number[] = [\n HardwareErrorCode.UserAborted,\n HardwareErrorCode.UserRejected,\n HardwareErrorCode.DeviceNotFound,\n HardwareErrorCode.DeviceDisconnected,\n HardwareErrorCode.OperationNotFound,\n HardwareErrorCode.OperationEnded,\n HardwareErrorCode.DeviceMismatch,\n HardwareErrorCode.DeviceSearchMismatch,\n HardwareErrorCode.DeviceAppStuck,\n HardwareErrorCode.DeviceOneDeviceOnly,\n HardwareErrorCode.TransportError,\n HardwareErrorCode.DevicePermissionDenied,\n HardwareErrorCode.BlePairingTimeout,\n HardwareErrorCode.ThpPairingFailed,\n HardwareErrorCode.ThpPairingRequired,\n HardwareErrorCode.BleBondInvalid,\n HardwareErrorCode.BleConnectFailed,\n HardwareErrorCode.BlePairingCancelled,\n HardwareErrorCode.PassphraseAlwaysOnDevice,\n];\n\n// ---------------------------------------------------------------------------\n// Standard throwable for HWK adapters\n// ---------------------------------------------------------------------------\n\n/**\n * Where a failure came from. The distinction the numeric code ranges cannot\n * make reliably (UserRejected=10001 sits in the general range but is the\n * device speaking; DevicePermissionDenied=10303 sits in the transport range\n * but is the browser speaking), and the one recovery logic actually needs:\n *\n * - `device` the firmware ANSWERED: rejection, locked screen, wrong\n * wallet, bad PIN. It is a result, not a malfunction — surface\n * it to the user verbatim; never auto-reconnect, never switch\n * channels, never drop a healthy session over it.\n * - `transport` the pipe failed: cable pulled, bus reset, bridge gone.\n * Reconnecting or falling back to another channel is fair game.\n * - `host` the host environment refused: browser permission, picker\n * dismissed, bad parameters. Fix the environment, not the link.\n *\n * Optional on purpose: a mapper that cannot tell MUST leave it unset rather\n * than guess — consumers fall back to their existing code-based tables, so an\n * unset origin degrades to today's behavior instead of mislabeling.\n */\nexport type HwkErrorOrigin = 'device' | 'transport' | 'host';\n\n/**\n * Smallest runtime resource a consumer must replace before retrying a failed\n * operation. This is connection-lifecycle metadata, not UI navigation and not\n * permission to replay a signing command automatically.\n *\n * - `call`: nothing needs replacing; re-issuing the same call is eligible,\n * usually after the user fixes device state.\n * - `operation`: the operation binding is no longer usable; the selected target\n * may be used to establish a new one when its identity is persistent.\n * - `search-target`: the selected discovery result is stale or untrusted;\n * rediscover on the same transport and let the user select again.\n * - `transport`: the selected transport is unavailable or unsuitable; repair\n * it or choose another transport.\n * - `not-recoverable`: retrying the same operation/context cannot succeed.\n * - `unknown`: the SDK cannot make a safe recovery claim.\n */\nexport type HwkRecoveryScope =\n | 'call'\n | 'operation'\n | 'search-target'\n | 'transport'\n | 'not-recoverable'\n | 'unknown';\n\nexport interface HwkRecoveryHint {\n scope: HwkRecoveryScope;\n}\n\nconst RECOVERY_SCOPES = new Set<HwkRecoveryScope>([\n 'call',\n 'operation',\n 'search-target',\n 'transport',\n 'not-recoverable',\n 'unknown',\n]);\n\nexport function isHwkRecoveryHint(value: unknown): value is HwkRecoveryHint {\n if (!value || typeof value !== 'object') return false;\n const { scope } = value as { scope?: unknown };\n return typeof scope === 'string' && RECOVERY_SCOPES.has(scope as HwkRecoveryScope);\n}\n\nconst RECOVERY_CALL: HwkRecoveryHint = Object.freeze({ scope: 'call' });\nconst RECOVERY_OPERATION: HwkRecoveryHint = Object.freeze({ scope: 'operation' });\nconst RECOVERY_SEARCH_TARGET: HwkRecoveryHint = Object.freeze({ scope: 'search-target' });\nconst RECOVERY_TRANSPORT: HwkRecoveryHint = Object.freeze({ scope: 'transport' });\nconst RECOVERY_NOT_RECOVERABLE: HwkRecoveryHint = Object.freeze({\n scope: 'not-recoverable',\n});\nconst RECOVERY_UNKNOWN: HwkRecoveryHint = Object.freeze({ scope: 'unknown' });\n\n/**\n * Vendor-neutral fallback used when an adapter has no more precise runtime\n * knowledge. Adapters may stamp a narrower hint when transport/session state\n * makes the correct scope unambiguous.\n */\nexport function defaultRecoveryForCode(code: HardwareErrorCode): HwkRecoveryHint {\n switch (code) {\n case HardwareErrorCode.UserRejected:\n case HardwareErrorCode.UserAborted:\n case HardwareErrorCode.DeviceBusy:\n case HardwareErrorCode.DeviceLocked:\n case HardwareErrorCode.DeviceNotInitialized:\n case HardwareErrorCode.DeviceInBootloader:\n case HardwareErrorCode.DeviceAppStuck:\n case HardwareErrorCode.DeviceBusyInternal:\n case HardwareErrorCode.NetworkError:\n case HardwareErrorCode.PinInvalid:\n case HardwareErrorCode.PinCancelled:\n case HardwareErrorCode.PassphraseRejected:\n case HardwareErrorCode.PassphraseStateMismatch:\n case HardwareErrorCode.PinMismatch:\n case HardwareErrorCode.FirmwareTooOld:\n case HardwareErrorCode.FirmwareUpdateRequired:\n case HardwareErrorCode.AppNotInstalled:\n case HardwareErrorCode.WrongApp:\n case HardwareErrorCode.AppTooOld:\n case HardwareErrorCode.DeviceOutOfMemory:\n case HardwareErrorCode.EvmBlindSigningRequired:\n case HardwareErrorCode.EvmClearSignPluginMissing:\n case HardwareErrorCode.EvmDataTooLarge:\n case HardwareErrorCode.EvmTxTypeNotSupported:\n case HardwareErrorCode.SolanaBlindSigningRequired:\n case HardwareErrorCode.TronCustomContractRequired:\n case HardwareErrorCode.TronDataSigningRequired:\n case HardwareErrorCode.TronSignByHashRequired:\n case HardwareErrorCode.BtcWalletPolicyHmacMismatch:\n case HardwareErrorCode.BtcUnexpectedState:\n return RECOVERY_CALL;\n case HardwareErrorCode.DeviceNotFound:\n case HardwareErrorCode.DeviceDisconnected:\n case HardwareErrorCode.OperationNotFound:\n case HardwareErrorCode.OperationEnded:\n case HardwareErrorCode.TransportError:\n case HardwareErrorCode.BlePairingTimeout:\n case HardwareErrorCode.ThpPairingFailed:\n case HardwareErrorCode.ThpPairingRequired:\n case HardwareErrorCode.BleConnectFailed:\n case HardwareErrorCode.BlePairingCancelled:\n return RECOVERY_OPERATION;\n case HardwareErrorCode.DeviceMismatch:\n case HardwareErrorCode.DeviceSearchMismatch:\n case HardwareErrorCode.DeviceOneDeviceOnly:\n case HardwareErrorCode.BleBondInvalid:\n return RECOVERY_SEARCH_TARGET;\n case HardwareErrorCode.BridgeNotFound:\n case HardwareErrorCode.TransportNotAvailable:\n case HardwareErrorCode.DevicePermissionDenied:\n case HardwareErrorCode.PayloadTooLarge:\n return RECOVERY_TRANSPORT;\n case HardwareErrorCode.InvalidParams:\n case HardwareErrorCode.MethodNotSupported:\n case HardwareErrorCode.ChainNotSupported:\n case HardwareErrorCode.DevicePathForbidden:\n return RECOVERY_NOT_RECOVERABLE;\n case HardwareErrorCode.UnknownError:\n case HardwareErrorCode.OperationTimeout:\n default:\n return RECOVERY_UNKNOWN;\n }\n}\n\n/**\n * The authoritative code→origin table. Most codes imply their origin by\n * definition (UserRejected IS the device speaking; BridgeNotFound IS the\n * pipe). Vendors use this as the default and override only where their\n * mapping context knows better. Codes whose origin genuinely depends on\n * context (UnknownError, OperationTimeout — the device may be waiting for a\n * human, or the pipe may be dead — and DeviceBusy) return undefined: an\n * honest \"can't tell\" beats a plausible mislabel, because consumers fall\n * back to their existing behavior instead of taking the wrong recovery.\n */\nexport function defaultOriginForCode(code: HardwareErrorCode): HwkErrorOrigin | undefined {\n // Chain APDU blocks (11000+) are, without exception, the chain app on the\n // device answering a request it understood and refused/qualified.\n if (code >= 11_000) return 'device';\n switch (code) {\n case HardwareErrorCode.UserRejected:\n case HardwareErrorCode.DeviceLocked:\n case HardwareErrorCode.DeviceNotInitialized:\n case HardwareErrorCode.DeviceInBootloader:\n case HardwareErrorCode.DeviceMismatch:\n case HardwareErrorCode.DeviceSearchMismatch:\n case HardwareErrorCode.DeviceAppStuck:\n case HardwareErrorCode.DevicePathForbidden:\n case HardwareErrorCode.DeviceBusyInternal:\n case HardwareErrorCode.ChainNotSupported:\n case HardwareErrorCode.FirmwareTooOld:\n case HardwareErrorCode.FirmwareUpdateRequired:\n case HardwareErrorCode.PinInvalid:\n case HardwareErrorCode.PinMismatch:\n case HardwareErrorCode.PassphraseRejected:\n case HardwareErrorCode.PassphraseStateMismatch:\n case HardwareErrorCode.ThpPairingFailed:\n case HardwareErrorCode.ThpPairingRequired:\n case HardwareErrorCode.WrongApp:\n case HardwareErrorCode.AppNotInstalled:\n case HardwareErrorCode.AppTooOld:\n case HardwareErrorCode.DeviceOutOfMemory:\n return 'device';\n case HardwareErrorCode.DeviceNotFound:\n case HardwareErrorCode.DeviceDisconnected:\n case HardwareErrorCode.TransportError:\n case HardwareErrorCode.BridgeNotFound:\n case HardwareErrorCode.TransportNotAvailable:\n case HardwareErrorCode.BlePairingTimeout:\n case HardwareErrorCode.NetworkError:\n case HardwareErrorCode.BleBondInvalid:\n case HardwareErrorCode.BleConnectFailed:\n return 'transport';\n case HardwareErrorCode.DevicePermissionDenied:\n case HardwareErrorCode.UserAborted:\n case HardwareErrorCode.InvalidParams:\n case HardwareErrorCode.MethodNotSupported:\n case HardwareErrorCode.PinCancelled:\n case HardwareErrorCode.BlePairingCancelled:\n case HardwareErrorCode.PayloadTooLarge:\n case HardwareErrorCode.DeviceOneDeviceOnly:\n return 'host';\n default:\n return undefined;\n }\n}\n\nexport interface IHwkErrorPayload {\n code: HardwareErrorCode;\n message: string;\n origin?: HwkErrorOrigin;\n recovery?: HwkRecoveryHint;\n appName?: string;\n _tag?: string;\n params?: Record<string, unknown>;\n}\n\nexport interface IOperationMayHaveCompletedParams extends Record<string, unknown> {\n operationMayHaveCompleted: true;\n method: string;\n}\n\n/**\n * Marks an unsafe hardware request whose response was lost after dispatch.\n * Callers must not interpret the resulting transport error as proof that the\n * device rejected or did not execute the operation.\n */\nexport function operationMayHaveCompletedParams(\n method: string,\n params?: Record<string, unknown>\n): IOperationMayHaveCompletedParams {\n return {\n ...params,\n operationMayHaveCompleted: true,\n method,\n };\n}\n\nexport type HwkError = Error & {\n code: HardwareErrorCode;\n /** See {@link HwkErrorOrigin}. Survives serializeConnectorError/rehydrate\n * automatically (own fields outside the top-level whitelist travel via\n * `params` and are lifted back). */\n origin?: HwkErrorOrigin;\n recovery?: HwkRecoveryHint;\n appName?: string;\n _tag?: string;\n params?: Record<string, unknown>;\n};\n\n/**\n * Canonical throwable for HWK adapters. Plain Error + canonical extra fields,\n * shape-compatible with `rehydrateConnectorError` so locally-thrown and\n * cross-boundary errors are indistinguishable to downstream classifiers\n * (`err.code` / `err._tag` / `err.appName`). Do NOT mutate caught errors\n * with `Object.assign` — construct a fresh one via this factory.\n */\nexport function createHwkError(payload: IHwkErrorPayload): HwkError {\n const recovery = payload.recovery ?? defaultRecoveryForCode(payload.code);\n return Object.assign(new Error(payload.message), {\n code: payload.code,\n ...(payload.origin !== undefined && { origin: payload.origin }),\n recovery,\n ...(payload._tag !== undefined && { _tag: payload._tag }),\n ...(payload.appName !== undefined && { appName: payload.appName }),\n ...(payload.params !== undefined && { params: payload.params }),\n });\n}\n"],"mappings":";AAwBO,IAAK,oBAAL,kBAAKA,uBAAL;AAEL,EAAAA,sCAAA,kBAAe,OAAf;AACA,EAAAA,sCAAA,kBAAe,SAAf;AACA,EAAAA,sCAAA,mBAAgB,SAAhB;AACA,EAAAA,sCAAA,sBAAmB,SAAnB;AACA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KAAK;AAAA,IACvD,GAAI,QAAQ,YAAY,UAAa,EAAE,SAAS,QAAQ,QAAQ;AAAA,IAChE,GAAI,QAAQ,WAAW,UAAa,EAAE,QAAQ,QAAQ,OAAO;AAAA,EAC/D,CAAC;AACH;","names":["HardwareErrorCode"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createHwkError
3
- } from "./chunk-72KOSYTH.mjs";
3
+ } from "./chunk-E3UPXUN5.mjs";
4
4
 
5
5
  // src/events/ui-request.ts
6
6
  var UI_EVENT = "UI_EVENT";
@@ -177,4 +177,4 @@ export {
177
177
  UI_REQUEST_TIMEOUT_TAG,
178
178
  UiRequestRegistry
179
179
  };
180
- //# sourceMappingURL=chunk-KCIK56B5.mjs.map
180
+ //# sourceMappingURL=chunk-ELC6PLKH.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/events/ui-request.ts","../src/utils/UiRequestRegistry.ts"],"sourcesContent":["import type { QrResponseData } from '../types/qr';\n\nexport const UI_EVENT = 'UI_EVENT';\n\nexport const UI_REQUEST = {\n REQUEST_PIN: 'ui-request-pin',\n REQUEST_PASSPHRASE: 'ui-request-passphrase',\n // One-way UI notification: device is waiting for passphrase entry on-device.\n // The prompt response path remains RECEIVE_PASSPHRASE with passphraseOnDevice=true.\n REQUEST_PASSPHRASE_ON_DEVICE: 'ui-request-passphrase-on-device',\n REQUEST_BUTTON: 'ui-request-button',\n REQUEST_QR_DISPLAY: 'ui-request-qr-display',\n REQUEST_QR_SCAN: 'ui-request-qr-scan',\n REQUEST_DEVICE_PERMISSION: 'ui-request-device-permission',\n REQUEST_SELECT_DEVICE: 'ui-request-select-device',\n REQUEST_SAVE_DEVICE_BINDING: 'ui-request-save-device-binding',\n DEVICE_BINDING_STATUS: 'ui-device-binding-status',\n REQUEST_DEVICE_CONNECT: 'ui-request-device-connect',\n // Ledger BTC App: account index >= 100 requires display=true. Adapter asks\n // the user once per session before promoting the call.\n REQUEST_BTC_HIGH_INDEX_CONFIRM: 'ui-request-btc-high-index-confirm',\n // Required app is not installed; with autoInstallApp on, ask the user\n // whether to install it before retrying the operation.\n REQUEST_INSTALL_APP: 'ui-request-install-app',\n REQUEST_PREEMPTION: 'ui-request-preemption',\n REQUEST_TREZOR_THP_PAIRING: 'ui-request-trezor-thp-pairing',\n CLOSE_UI_WINDOW: 'ui-close',\n DEVICE_PROGRESS: 'ui-device_progress',\n FIRMWARE_PROGRESS: 'ui-firmware-progress',\n FIRMWARE_TIP: 'ui-firmware-tip',\n} as const;\n\nexport const UI_RESPONSE = {\n RECEIVE_PIN: 'receive-pin',\n RECEIVE_PASSPHRASE: 'receive-passphrase',\n RECEIVE_QR_RESPONSE: 'receive-qr-response',\n RECEIVE_SELECT_DEVICE: 'receive-select-device',\n RECEIVE_SAVE_DEVICE_BINDING: 'receive-save-device-binding',\n RECEIVE_DEVICE_CONNECT: 'receive-device-connect',\n RECEIVE_DEVICE_PERMISSION: 'receive-device-permission',\n RECEIVE_BTC_HIGH_INDEX_CONFIRM: 'receive-btc-high-index-confirm',\n RECEIVE_INSTALL_APP: 'receive-install-app',\n RECEIVE_PREEMPTION: 'receive-preemption',\n RECEIVE_TREZOR_THP_PAIRING: 'receive-trezor-thp-pairing',\n CANCEL: 'cancel',\n} as const;\n\nexport type DevicePermissionDeniedReason =\n | 'bluetoothTurnedOff'\n | 'permissionDenied'\n | (string & Record<never, never>);\n\nexport type DevicePermissionResponse = {\n granted: boolean;\n reason?: DevicePermissionDeniedReason;\n message?: string;\n};\n\n/**\n * Why a host refused to persist a binding.\n * - `mismatch`: the selected device is not the one this operation belongs to —\n * a user-facing outcome, surfaced as `DeviceMismatch`.\n * - `skipped`: the host had nothing to bind (no record for this call). A host\n * contract problem, not something the user did.\n */\nexport type SaveDeviceBindingDeclineReason = 'mismatch' | 'skipped';\n\nexport type UiResponseEvent =\n | {\n type: typeof UI_RESPONSE.RECEIVE_SAVE_DEVICE_BINDING;\n payload: {\n requestId: string;\n saved: boolean;\n reason?: SaveDeviceBindingDeclineReason;\n };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_PIN;\n payload: string;\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_PASSPHRASE;\n payload: {\n value: string;\n passphraseOnDevice?: boolean;\n save?: boolean;\n };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_QR_RESPONSE;\n payload: QrResponseData;\n }\n | {\n // sdkConnectId echoes one of the DeviceInfo.connectId values emitted in\n // the REQUEST_SELECT_DEVICE event's `devices` list. Scope is the current\n // search session; may be ephemeral (e.g. Ledger USB DMK UUID).\n type: typeof UI_RESPONSE.RECEIVE_SELECT_DEVICE;\n payload: { requestId?: string } & (\n | { sdkConnectId: string; cancelled?: false }\n | { cancelled: true }\n );\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_DEVICE_CONNECT;\n payload: { confirmed: boolean };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_DEVICE_PERMISSION;\n payload: DevicePermissionResponse;\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_BTC_HIGH_INDEX_CONFIRM;\n payload: { confirmed: boolean };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_INSTALL_APP;\n payload: { confirmed: boolean };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_PREEMPTION;\n payload: { confirmed: boolean };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_TREZOR_THP_PAIRING;\n payload: {\n selectedMethod?: number | string;\n tag?: string;\n };\n }\n | {\n type: typeof UI_RESPONSE.CANCEL;\n payload?: undefined;\n };\n","import { UI_REQUEST, UI_RESPONSE } from '../events/ui-request';\nimport { createHwkError, HardwareErrorCode } from '../types/errors';\n\n/** 10 min — every UI request is human-in-the-loop; bias toward \"wait long\". */\nexport const UI_REQUEST_DEFAULT_TIMEOUT_MS = 600_000;\n\nconst RESPONSE_TO_REQUEST: Record<string, string> = {\n [UI_RESPONSE.RECEIVE_PIN]: UI_REQUEST.REQUEST_PIN,\n [UI_RESPONSE.RECEIVE_PASSPHRASE]: UI_REQUEST.REQUEST_PASSPHRASE,\n [UI_RESPONSE.RECEIVE_SELECT_DEVICE]: UI_REQUEST.REQUEST_SELECT_DEVICE,\n [UI_RESPONSE.RECEIVE_SAVE_DEVICE_BINDING]: UI_REQUEST.REQUEST_SAVE_DEVICE_BINDING,\n [UI_RESPONSE.RECEIVE_DEVICE_CONNECT]: UI_REQUEST.REQUEST_DEVICE_CONNECT,\n [UI_RESPONSE.RECEIVE_DEVICE_PERMISSION]: UI_REQUEST.REQUEST_DEVICE_PERMISSION,\n [UI_RESPONSE.RECEIVE_BTC_HIGH_INDEX_CONFIRM]: UI_REQUEST.REQUEST_BTC_HIGH_INDEX_CONFIRM,\n [UI_RESPONSE.RECEIVE_INSTALL_APP]: UI_REQUEST.REQUEST_INSTALL_APP,\n [UI_RESPONSE.RECEIVE_PREEMPTION]: UI_REQUEST.REQUEST_PREEMPTION,\n [UI_RESPONSE.RECEIVE_TREZOR_THP_PAIRING]: UI_REQUEST.REQUEST_TREZOR_THP_PAIRING,\n // RECEIVE_QR_RESPONSE maps to QR_DISPLAY or QR_SCAN — resolved dynamically below.\n};\n\nexport const UI_REQUEST_PREEMPTED_TAG = 'UiRequestPreempted';\nexport const UI_REQUEST_CANCELLED_TAG = 'UiRequestCancelled';\nexport const UI_REQUEST_TIMEOUT_TAG = 'UiRequestTimeout';\n\nlet requestSequence = 0;\n\ntype PendingEntry = {\n requestId?: string;\n resolve: (payload: unknown) => void;\n reject: (error: Error) => void;\n timer: ReturnType<typeof setTimeout>;\n};\n\n/**\n * Per-type single-slot registry for adapter-level UI requests. A new `wait`\n * of the same type supersedes (rejects) the prior pending entry. With the\n * job queue running globally serially, cross-type collisions don't occur in\n * normal flow — same-type preemption is a defensive measure for callers\n * that fire the same request twice without waiting on the first.\n *\n * Unknown response types are dropped silently so the public `uiResponse`\n * entry never throws.\n */\nexport class UiRequestRegistry {\n private pending = new Map<string, PendingEntry>();\n\n createRequestId(): string {\n requestSequence += 1;\n return `hwk-ui-${Date.now()}-${requestSequence}`;\n }\n\n wait<T = unknown>(\n requestType: string,\n options?: { timeoutMs?: number; requestId?: string }\n ): Promise<T> {\n const existing = this.pending.get(requestType);\n if (existing) {\n clearTimeout(existing.timer);\n this.pending.delete(requestType);\n existing.reject(\n Object.assign(new Error(`UI request '${requestType}' was superseded by a new request`), {\n _tag: UI_REQUEST_PREEMPTED_TAG,\n })\n );\n }\n\n const timeoutMs = options?.timeoutMs ?? UI_REQUEST_DEFAULT_TIMEOUT_MS;\n\n return new Promise<T>((resolve, reject) => {\n const timer = setTimeout(() => {\n if (this.pending.get(requestType)?.timer === timer) {\n this.pending.delete(requestType);\n reject(\n Object.assign(new Error(`UI request '${requestType}' timed out after ${timeoutMs}ms`), {\n _tag: UI_REQUEST_TIMEOUT_TAG,\n })\n );\n }\n }, timeoutMs);\n\n this.pending.set(requestType, {\n requestId: options?.requestId,\n resolve: resolve as (payload: unknown) => void,\n reject,\n timer,\n });\n });\n }\n\n resolve(responseType: string, payload: unknown): void {\n let requestType = RESPONSE_TO_REQUEST[responseType];\n if (responseType === UI_RESPONSE.RECEIVE_QR_RESPONSE) {\n if (this.pending.has(UI_REQUEST.REQUEST_QR_DISPLAY)) {\n requestType = UI_REQUEST.REQUEST_QR_DISPLAY;\n } else if (this.pending.has(UI_REQUEST.REQUEST_QR_SCAN)) {\n requestType = UI_REQUEST.REQUEST_QR_SCAN;\n }\n }\n if (!requestType) return;\n\n const entry = this.pending.get(requestType);\n if (!entry) return;\n\n const response =\n payload && typeof payload === 'object'\n ? (payload as { requestId?: unknown; cancelled?: unknown })\n : undefined;\n // A late response must not resolve (or cancel) a newer request of the same type.\n if (entry.requestId !== undefined && response?.requestId !== entry.requestId) return;\n if (requestType === UI_REQUEST.REQUEST_SELECT_DEVICE && response?.cancelled === true) {\n clearTimeout(entry.timer);\n this.pending.delete(requestType);\n entry.reject(\n createHwkError({\n code: HardwareErrorCode.UserAborted,\n message: 'Device selection was cancelled',\n _tag: UI_REQUEST_CANCELLED_TAG,\n })\n );\n return;\n }\n\n clearTimeout(entry.timer);\n this.pending.delete(requestType);\n entry.resolve(payload);\n }\n\n cancel(requestType?: string, requestId?: string): void {\n if (requestType) {\n const entry = this.pending.get(requestType);\n if (!entry) return;\n if (requestId !== undefined && entry.requestId !== requestId) return;\n clearTimeout(entry.timer);\n this.pending.delete(requestType);\n entry.reject(\n Object.assign(new Error(`UI request '${requestType}' was cancelled`), {\n _tag: UI_REQUEST_CANCELLED_TAG,\n })\n );\n return;\n }\n\n for (const [type, entry] of this.pending) {\n clearTimeout(entry.timer);\n entry.reject(\n Object.assign(new Error(`UI request '${type}' was cancelled`), {\n _tag: UI_REQUEST_CANCELLED_TAG,\n })\n );\n }\n this.pending.clear();\n }\n\n reset(): void {\n this.cancel();\n }\n\n hasPending(requestType?: string): boolean {\n if (requestType) return this.pending.has(requestType);\n return this.pending.size > 0;\n }\n}\n"],"mappings":";;;;;AAEO,IAAM,WAAW;AAEjB,IAAM,aAAa;AAAA,EACxB,aAAa;AAAA,EACb,oBAAoB;AAAA;AAAA;AAAA,EAGpB,8BAA8B;AAAA,EAC9B,gBAAgB;AAAA,EAChB,oBAAoB;AAAA,EACpB,iBAAiB;AAAA,EACjB,2BAA2B;AAAA,EAC3B,uBAAuB;AAAA,EACvB,6BAA6B;AAAA,EAC7B,uBAAuB;AAAA,EACvB,wBAAwB;AAAA;AAAA;AAAA,EAGxB,gCAAgC;AAAA;AAAA;AAAA,EAGhC,qBAAqB;AAAA,EACrB,oBAAoB;AAAA,EACpB,4BAA4B;AAAA,EAC5B,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,cAAc;AAChB;AAEO,IAAM,cAAc;AAAA,EACzB,aAAa;AAAA,EACb,oBAAoB;AAAA,EACpB,qBAAqB;AAAA,EACrB,uBAAuB;AAAA,EACvB,6BAA6B;AAAA,EAC7B,wBAAwB;AAAA,EACxB,2BAA2B;AAAA,EAC3B,gCAAg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,YAAM,QAAQ,KAAK,QAAQ,IAAI,WAAW;AAC1C,UAAI,CAAC,MAAO;AACZ,UAAI,cAAc,UAAa,MAAM,cAAc,UAAW;AAC9D,mBAAa,MAAM,KAAK;AACxB,WAAK,QAAQ,OAAO,WAAW;AAC/B,YAAM;AAAA,QACJ,OAAO,OAAO,IAAI,MAAM,eAAe,WAAW,iBAAiB,GAAG;AAAA,UACpE,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AACA;AAAA,IACF;AAEA,eAAW,CAAC,MAAM,KAAK,KAAK,KAAK,SAAS;AACxC,mBAAa,MAAM,KAAK;AACxB,YAAM;AAAA,QACJ,OAAO,OAAO,IAAI,MAAM,eAAe,IAAI,iBAAiB,GAAG;AAAA,UAC7D,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,IACF;AACA,SAAK,QAAQ,MAAM;AAAA,EACrB;AAAA,EAEA,QAAc;AACZ,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,WAAW,aAA+B;AACxC,QAAI,YAAa,QAAO,KAAK,QAAQ,IAAI,WAAW;AACpD,WAAO,KAAK,QAAQ,OAAO;AAAA,EAC7B;AACF;","names":[]}
@@ -1,6 +1,6 @@
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 _chunkIZEVYMJKjs = require('./chunk-IZEVYMJK.js');
3
+ var _chunkZ3IH25KVjs = require('./chunk-Z3IH25KV.js');
4
4
 
5
5
  // src/events/ui-request.ts
6
6
  var UI_EVENT = "UI_EVENT";
@@ -122,7 +122,7 @@ var UiRequestRegistry = class {
122
122
  clearTimeout(entry.timer);
123
123
  this.pending.delete(requestType);
124
124
  entry.reject(
125
- _chunkIZEVYMJKjs.createHwkError.call(void 0, {
125
+ _chunkZ3IH25KVjs.createHwkError.call(void 0, {
126
126
  code: 10005 /* UserAborted */,
127
127
  message: "Device selection was cancelled",
128
128
  _tag: UI_REQUEST_CANCELLED_TAG
@@ -177,4 +177,4 @@ var UiRequestRegistry = class {
177
177
 
178
178
 
179
179
  exports.UI_EVENT = UI_EVENT; exports.UI_REQUEST = UI_REQUEST; exports.UI_RESPONSE = UI_RESPONSE; exports.UI_REQUEST_DEFAULT_TIMEOUT_MS = UI_REQUEST_DEFAULT_TIMEOUT_MS; exports.UI_REQUEST_PREEMPTED_TAG = UI_REQUEST_PREEMPTED_TAG; exports.UI_REQUEST_CANCELLED_TAG = UI_REQUEST_CANCELLED_TAG; exports.UI_REQUEST_TIMEOUT_TAG = UI_REQUEST_TIMEOUT_TAG; exports.UiRequestRegistry = UiRequestRegistry;
180
- //# sourceMappingURL=chunk-RRCFH7X6.js.map
180
+ //# sourceMappingURL=chunk-S7X2HM7P.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/hardware-js-sdk/hardware-js-sdk/packages/hwk-adapter-core/dist/chunk-S7X2HM7P.js","../src/events/ui-request.ts","../src/utils/UiRequestRegistry.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACFO,IAAM,SAAA,EAAW,UAAA;AAEjB,IAAM,WAAA,EAAa;AAAA,EACxB,WAAA,EAAa,gBAAA;AAAA,EACb,kBAAA,EAAoB,uBAAA;AAAA;AAAA;AAAA,EAGpB,4BAAA,EAA8B,iCAAA;AAAA,EAC9B,cAAA,EAAgB,mBAAA;AAAA,EAChB,kBAAA,EAAoB,uBAAA;AAAA,EACpB,eAAA,EAAiB,oBAAA;AAAA,EACjB,y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A;AACH,EAAA;AAEsD,EAAA;AACd,IAAA;AACL,IAAA;AACC,MAAA;AACL,QAAA;AACY,MAAA;AACZ,QAAA;AAC3B,MAAA;AACF,IAAA;AACkB,IAAA;AAEwB,IAAA;AAC9B,IAAA;AAGoB,IAAA;AAIe,IAAA;AAChB,IAAA;AACL,MAAA;AACO,MAAA;AACzB,MAAA;AACW,QAAA;AACb,UAAA;AACS,UAAA;AACH,UAAA;AACP,QAAA;AACH,MAAA;AACA,MAAA;AACF,IAAA;AAEwB,IAAA;AACO,IAAA;AACV,IAAA;AACvB,EAAA;AAEuD,EAAA;AACpC,IAAA;AAC2B,MAAA;AAC9B,MAAA;AACyB,MAAA;AACb,MAAA;AACO,MAAA;AACzB,MAAA;AACmC,QAAA;AAC/B,UAAA;AACP,QAAA;AACH,MAAA;AACA,MAAA;AACF,IAAA;AAE0C,IAAA;AAChB,MAAA;AAClB,MAAA;AACuC,QAAA;AACnC,UAAA;AACP,QAAA;AACH,MAAA;AACF,IAAA;AACmB,IAAA;AACrB,EAAA;AAEc,EAAA;AACA,IAAA;AACd,EAAA;AAE0C,EAAA;AACC,IAAA;AACd,IAAA;AAC7B,EAAA;AACF;AFOmD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/hardware-js-sdk/hardware-js-sdk/packages/hwk-adapter-core/dist/chunk-S7X2HM7P.js","sourcesContent":[null,"import type { QrResponseData } from '../types/qr';\n\nexport const UI_EVENT = 'UI_EVENT';\n\nexport const UI_REQUEST = {\n REQUEST_PIN: 'ui-request-pin',\n REQUEST_PASSPHRASE: 'ui-request-passphrase',\n // One-way UI notification: device is waiting for passphrase entry on-device.\n // The prompt response path remains RECEIVE_PASSPHRASE with passphraseOnDevice=true.\n REQUEST_PASSPHRASE_ON_DEVICE: 'ui-request-passphrase-on-device',\n REQUEST_BUTTON: 'ui-request-button',\n REQUEST_QR_DISPLAY: 'ui-request-qr-display',\n REQUEST_QR_SCAN: 'ui-request-qr-scan',\n REQUEST_DEVICE_PERMISSION: 'ui-request-device-permission',\n REQUEST_SELECT_DEVICE: 'ui-request-select-device',\n REQUEST_SAVE_DEVICE_BINDING: 'ui-request-save-device-binding',\n DEVICE_BINDING_STATUS: 'ui-device-binding-status',\n REQUEST_DEVICE_CONNECT: 'ui-request-device-connect',\n // Ledger BTC App: account index >= 100 requires display=true. Adapter asks\n // the user once per session before promoting the call.\n REQUEST_BTC_HIGH_INDEX_CONFIRM: 'ui-request-btc-high-index-confirm',\n // Required app is not installed; with autoInstallApp on, ask the user\n // whether to install it before retrying the operation.\n REQUEST_INSTALL_APP: 'ui-request-install-app',\n REQUEST_PREEMPTION: 'ui-request-preemption',\n REQUEST_TREZOR_THP_PAIRING: 'ui-request-trezor-thp-pairing',\n CLOSE_UI_WINDOW: 'ui-close',\n DEVICE_PROGRESS: 'ui-device_progress',\n FIRMWARE_PROGRESS: 'ui-firmware-progress',\n FIRMWARE_TIP: 'ui-firmware-tip',\n} as const;\n\nexport const UI_RESPONSE = {\n RECEIVE_PIN: 'receive-pin',\n RECEIVE_PASSPHRASE: 'receive-passphrase',\n RECEIVE_QR_RESPONSE: 'receive-qr-response',\n RECEIVE_SELECT_DEVICE: 'receive-select-device',\n RECEIVE_SAVE_DEVICE_BINDING: 'receive-save-device-binding',\n RECEIVE_DEVICE_CONNECT: 'receive-device-connect',\n RECEIVE_DEVICE_PERMISSION: 'receive-device-permission',\n RECEIVE_BTC_HIGH_INDEX_CONFIRM: 'receive-btc-high-index-confirm',\n RECEIVE_INSTALL_APP: 'receive-install-app',\n RECEIVE_PREEMPTION: 'receive-preemption',\n RECEIVE_TREZOR_THP_PAIRING: 'receive-trezor-thp-pairing',\n CANCEL: 'cancel',\n} as const;\n\nexport type DevicePermissionDeniedReason =\n | 'bluetoothTurnedOff'\n | 'permissionDenied'\n | (string & Record<never, never>);\n\nexport type DevicePermissionResponse = {\n granted: boolean;\n reason?: DevicePermissionDeniedReason;\n message?: string;\n};\n\n/**\n * Why a host refused to persist a binding.\n * - `mismatch`: the selected device is not the one this operation belongs to —\n * a user-facing outcome, surfaced as `DeviceMismatch`.\n * - `skipped`: the host had nothing to bind (no record for this call). A host\n * contract problem, not something the user did.\n */\nexport type SaveDeviceBindingDeclineReason = 'mismatch' | 'skipped';\n\nexport type UiResponseEvent =\n | {\n type: typeof UI_RESPONSE.RECEIVE_SAVE_DEVICE_BINDING;\n payload: {\n requestId: string;\n saved: boolean;\n reason?: SaveDeviceBindingDeclineReason;\n };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_PIN;\n payload: string;\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_PASSPHRASE;\n payload: {\n value: string;\n passphraseOnDevice?: boolean;\n save?: boolean;\n };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_QR_RESPONSE;\n payload: QrResponseData;\n }\n | {\n // sdkConnectId echoes one of the DeviceInfo.connectId values emitted in\n // the REQUEST_SELECT_DEVICE event's `devices` list. Scope is the current\n // search session; may be ephemeral (e.g. Ledger USB DMK UUID).\n type: typeof UI_RESPONSE.RECEIVE_SELECT_DEVICE;\n payload: { requestId?: string } & (\n | { sdkConnectId: string; cancelled?: false }\n | { cancelled: true }\n );\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_DEVICE_CONNECT;\n payload: { confirmed: boolean };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_DEVICE_PERMISSION;\n payload: DevicePermissionResponse;\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_BTC_HIGH_INDEX_CONFIRM;\n payload: { confirmed: boolean };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_INSTALL_APP;\n payload: { confirmed: boolean };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_PREEMPTION;\n payload: { confirmed: boolean };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_TREZOR_THP_PAIRING;\n payload: {\n selectedMethod?: number | string;\n tag?: string;\n };\n }\n | {\n type: typeof UI_RESPONSE.CANCEL;\n payload?: undefined;\n };\n","import { UI_REQUEST, UI_RESPONSE } from '../events/ui-request';\nimport { createHwkError, HardwareErrorCode } from '../types/errors';\n\n/** 10 min — every UI request is human-in-the-loop; bias toward \"wait long\". */\nexport const UI_REQUEST_DEFAULT_TIMEOUT_MS = 600_000;\n\nconst RESPONSE_TO_REQUEST: Record<string, string> = {\n [UI_RESPONSE.RECEIVE_PIN]: UI_REQUEST.REQUEST_PIN,\n [UI_RESPONSE.RECEIVE_PASSPHRASE]: UI_REQUEST.REQUEST_PASSPHRASE,\n [UI_RESPONSE.RECEIVE_SELECT_DEVICE]: UI_REQUEST.REQUEST_SELECT_DEVICE,\n [UI_RESPONSE.RECEIVE_SAVE_DEVICE_BINDING]: UI_REQUEST.REQUEST_SAVE_DEVICE_BINDING,\n [UI_RESPONSE.RECEIVE_DEVICE_CONNECT]: UI_REQUEST.REQUEST_DEVICE_CONNECT,\n [UI_RESPONSE.RECEIVE_DEVICE_PERMISSION]: UI_REQUEST.REQUEST_DEVICE_PERMISSION,\n [UI_RESPONSE.RECEIVE_BTC_HIGH_INDEX_CONFIRM]: UI_REQUEST.REQUEST_BTC_HIGH_INDEX_CONFIRM,\n [UI_RESPONSE.RECEIVE_INSTALL_APP]: UI_REQUEST.REQUEST_INSTALL_APP,\n [UI_RESPONSE.RECEIVE_PREEMPTION]: UI_REQUEST.REQUEST_PREEMPTION,\n [UI_RESPONSE.RECEIVE_TREZOR_THP_PAIRING]: UI_REQUEST.REQUEST_TREZOR_THP_PAIRING,\n // RECEIVE_QR_RESPONSE maps to QR_DISPLAY or QR_SCAN — resolved dynamically below.\n};\n\nexport const UI_REQUEST_PREEMPTED_TAG = 'UiRequestPreempted';\nexport const UI_REQUEST_CANCELLED_TAG = 'UiRequestCancelled';\nexport const UI_REQUEST_TIMEOUT_TAG = 'UiRequestTimeout';\n\nlet requestSequence = 0;\n\ntype PendingEntry = {\n requestId?: string;\n resolve: (payload: unknown) => void;\n reject: (error: Error) => void;\n timer: ReturnType<typeof setTimeout>;\n};\n\n/**\n * Per-type single-slot registry for adapter-level UI requests. A new `wait`\n * of the same type supersedes (rejects) the prior pending entry. With the\n * job queue running globally serially, cross-type collisions don't occur in\n * normal flow — same-type preemption is a defensive measure for callers\n * that fire the same request twice without waiting on the first.\n *\n * Unknown response types are dropped silently so the public `uiResponse`\n * entry never throws.\n */\nexport class UiRequestRegistry {\n private pending = new Map<string, PendingEntry>();\n\n createRequestId(): string {\n requestSequence += 1;\n return `hwk-ui-${Date.now()}-${requestSequence}`;\n }\n\n wait<T = unknown>(\n requestType: string,\n options?: { timeoutMs?: number; requestId?: string }\n ): Promise<T> {\n const existing = this.pending.get(requestType);\n if (existing) {\n clearTimeout(existing.timer);\n this.pending.delete(requestType);\n existing.reject(\n Object.assign(new Error(`UI request '${requestType}' was superseded by a new request`), {\n _tag: UI_REQUEST_PREEMPTED_TAG,\n })\n );\n }\n\n const timeoutMs = options?.timeoutMs ?? UI_REQUEST_DEFAULT_TIMEOUT_MS;\n\n return new Promise<T>((resolve, reject) => {\n const timer = setTimeout(() => {\n if (this.pending.get(requestType)?.timer === timer) {\n this.pending.delete(requestType);\n reject(\n Object.assign(new Error(`UI request '${requestType}' timed out after ${timeoutMs}ms`), {\n _tag: UI_REQUEST_TIMEOUT_TAG,\n })\n );\n }\n }, timeoutMs);\n\n this.pending.set(requestType, {\n requestId: options?.requestId,\n resolve: resolve as (payload: unknown) => void,\n reject,\n timer,\n });\n });\n }\n\n resolve(responseType: string, payload: unknown): void {\n let requestType = RESPONSE_TO_REQUEST[responseType];\n if (responseType === UI_RESPONSE.RECEIVE_QR_RESPONSE) {\n if (this.pending.has(UI_REQUEST.REQUEST_QR_DISPLAY)) {\n requestType = UI_REQUEST.REQUEST_QR_DISPLAY;\n } else if (this.pending.has(UI_REQUEST.REQUEST_QR_SCAN)) {\n requestType = UI_REQUEST.REQUEST_QR_SCAN;\n }\n }\n if (!requestType) return;\n\n const entry = this.pending.get(requestType);\n if (!entry) return;\n\n const response =\n payload && typeof payload === 'object'\n ? (payload as { requestId?: unknown; cancelled?: unknown })\n : undefined;\n // A late response must not resolve (or cancel) a newer request of the same type.\n if (entry.requestId !== undefined && response?.requestId !== entry.requestId) return;\n if (requestType === UI_REQUEST.REQUEST_SELECT_DEVICE && response?.cancelled === true) {\n clearTimeout(entry.timer);\n this.pending.delete(requestType);\n entry.reject(\n createHwkError({\n code: HardwareErrorCode.UserAborted,\n message: 'Device selection was cancelled',\n _tag: UI_REQUEST_CANCELLED_TAG,\n })\n );\n return;\n }\n\n clearTimeout(entry.timer);\n this.pending.delete(requestType);\n entry.resolve(payload);\n }\n\n cancel(requestType?: string, requestId?: string): void {\n if (requestType) {\n const entry = this.pending.get(requestType);\n if (!entry) return;\n if (requestId !== undefined && entry.requestId !== requestId) return;\n clearTimeout(entry.timer);\n this.pending.delete(requestType);\n entry.reject(\n Object.assign(new Error(`UI request '${requestType}' was cancelled`), {\n _tag: UI_REQUEST_CANCELLED_TAG,\n })\n );\n return;\n }\n\n for (const [type, entry] of this.pending) {\n clearTimeout(entry.timer);\n entry.reject(\n Object.assign(new Error(`UI request '${type}' was cancelled`), {\n _tag: UI_REQUEST_CANCELLED_TAG,\n })\n );\n }\n this.pending.clear();\n }\n\n reset(): void {\n this.cancel();\n }\n\n hasPending(requestType?: string): boolean {\n if (requestType) return this.pending.has(requestType);\n return this.pending.size > 0;\n }\n}\n"]}
@@ -18,8 +18,9 @@ var HardwareErrorCode = /* @__PURE__ */ ((HardwareErrorCode2) => {
18
18
  HardwareErrorCode2[HardwareErrorCode2["DeviceOneDeviceOnly"] = 10109] = "DeviceOneDeviceOnly";
19
19
  HardwareErrorCode2[HardwareErrorCode2["DevicePathForbidden"] = 10110] = "DevicePathForbidden";
20
20
  HardwareErrorCode2[HardwareErrorCode2["DeviceBusyInternal"] = 10111] = "DeviceBusyInternal";
21
- HardwareErrorCode2[HardwareErrorCode2["InteractionNotFound"] = 10112] = "InteractionNotFound";
22
- HardwareErrorCode2[HardwareErrorCode2["InteractionEnded"] = 10113] = "InteractionEnded";
21
+ HardwareErrorCode2[HardwareErrorCode2["OperationNotFound"] = 10112] = "OperationNotFound";
22
+ HardwareErrorCode2[HardwareErrorCode2["OperationEnded"] = 10113] = "OperationEnded";
23
+ HardwareErrorCode2[HardwareErrorCode2["DeviceSearchMismatch"] = 10114] = "DeviceSearchMismatch";
23
24
  HardwareErrorCode2[HardwareErrorCode2["FirmwareTooOld"] = 10200] = "FirmwareTooOld";
24
25
  HardwareErrorCode2[HardwareErrorCode2["FirmwareUpdateRequired"] = 10201] = "FirmwareUpdateRequired";
25
26
  HardwareErrorCode2[HardwareErrorCode2["TransportError"] = 10300] = "TransportError";
@@ -61,9 +62,10 @@ var ORPHAN_ELIGIBLE_ERROR_CODES = [
61
62
  10001 /* UserRejected */,
62
63
  10100 /* DeviceNotFound */,
63
64
  10101 /* DeviceDisconnected */,
64
- 10112 /* InteractionNotFound */,
65
- 10113 /* InteractionEnded */,
65
+ 10112 /* OperationNotFound */,
66
+ 10113 /* OperationEnded */,
66
67
  10106 /* DeviceMismatch */,
68
+ 10114 /* DeviceSearchMismatch */,
67
69
  10107 /* DeviceAppStuck */,
68
70
  10109 /* DeviceOneDeviceOnly */,
69
71
  10300 /* TransportError */,
@@ -77,8 +79,8 @@ var ORPHAN_ELIGIBLE_ERROR_CODES = [
77
79
  10405 /* PassphraseAlwaysOnDevice */
78
80
  ];
79
81
  var RECOVERY_SCOPES = /* @__PURE__ */ new Set([
82
+ "call",
80
83
  "operation",
81
- "interaction",
82
84
  "search-target",
83
85
  "transport",
84
86
  "not-recoverable",
@@ -89,8 +91,8 @@ function isHwkRecoveryHint(value) {
89
91
  const { scope } = value;
90
92
  return typeof scope === "string" && RECOVERY_SCOPES.has(scope);
91
93
  }
94
+ var RECOVERY_CALL = Object.freeze({ scope: "call" });
92
95
  var RECOVERY_OPERATION = Object.freeze({ scope: "operation" });
93
- var RECOVERY_INTERACTION = Object.freeze({ scope: "interaction" });
94
96
  var RECOVERY_SEARCH_TARGET = Object.freeze({ scope: "search-target" });
95
97
  var RECOVERY_TRANSPORT = Object.freeze({ scope: "transport" });
96
98
  var RECOVERY_NOT_RECOVERABLE = Object.freeze({
@@ -129,19 +131,20 @@ function defaultRecoveryForCode(code) {
129
131
  case 11202 /* TronSignByHashRequired */:
130
132
  case 11300 /* BtcWalletPolicyHmacMismatch */:
131
133
  case 11301 /* BtcUnexpectedState */:
132
- return RECOVERY_OPERATION;
134
+ return RECOVERY_CALL;
133
135
  case 10100 /* DeviceNotFound */:
134
136
  case 10101 /* DeviceDisconnected */:
135
- case 10112 /* InteractionNotFound */:
136
- case 10113 /* InteractionEnded */:
137
+ case 10112 /* OperationNotFound */:
138
+ case 10113 /* OperationEnded */:
137
139
  case 10300 /* TransportError */:
138
140
  case 10304 /* BlePairingTimeout */:
139
141
  case 10306 /* ThpPairingFailed */:
140
142
  case 10308 /* ThpPairingRequired */:
141
143
  case 10309 /* BleConnectFailed */:
142
144
  case 10310 /* BlePairingCancelled */:
143
- return RECOVERY_INTERACTION;
145
+ return RECOVERY_OPERATION;
144
146
  case 10106 /* DeviceMismatch */:
147
+ case 10114 /* DeviceSearchMismatch */:
145
148
  case 10109 /* DeviceOneDeviceOnly */:
146
149
  case 10307 /* BleBondInvalid */:
147
150
  return RECOVERY_SEARCH_TARGET;
@@ -169,6 +172,7 @@ function defaultOriginForCode(code) {
169
172
  case 10104 /* DeviceNotInitialized */:
170
173
  case 10105 /* DeviceInBootloader */:
171
174
  case 10106 /* DeviceMismatch */:
175
+ case 10114 /* DeviceSearchMismatch */:
172
176
  case 10107 /* DeviceAppStuck */:
173
177
  case 10110 /* DevicePathForbidden */:
174
178
  case 10111 /* DeviceBusyInternal */:
@@ -237,4 +241,4 @@ function createHwkError(payload) {
237
241
 
238
242
 
239
243
  exports.HardwareErrorCode = HardwareErrorCode; exports.ORPHAN_ELIGIBLE_ERROR_CODES = ORPHAN_ELIGIBLE_ERROR_CODES; exports.isHwkRecoveryHint = isHwkRecoveryHint; exports.defaultRecoveryForCode = defaultRecoveryForCode; exports.defaultOriginForCode = defaultOriginForCode; exports.operationMayHaveCompletedParams = operationMayHaveCompletedParams; exports.createHwkError = createHwkError;
240
- //# sourceMappingURL=chunk-IZEVYMJK.js.map
244
+ //# sourceMappingURL=chunk-Z3IH25KV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/hardware-js-sdk/hardware-js-sdk/packages/hwk-adapter-core/dist/chunk-Z3IH25KV.js","../src/types/errors.ts"],"names":["HardwareErrorCode"],"mappings":"AAAA;ACwBO,IAAK,kBAAA,kBAAL,CAAA,CAAKA,kBAAAA,EAAAA,GAAL;AAEL,EAAAA,kBAAAA,CAAAA,kBAAAA,CAAA,cAAA,EAAA,EAAe,GAAA,EAAA,EAAf,cAAA;AACA,EAAAA,kBAAAA,CAAAA,kBAAAA,CAAA,cAAA,EAAA,EAAe,KAAA,EAAA,EAAf,cAAA;AACA,EAAAA,kBAAAA,CAAAA,kBAAAA,CAAA,eAAA,EAAA,EAAgB,KAAA,EAAA,EAAhB,eAAA;AACA,EAAAA,kBAAAA,CAAAA,kBAAAA,CAAA,kBAAA,EAAA,EAAmB,KAAA,EAAA,EAAnB,kBAAA;AACA,EAAAA,kBAAAA,CAAAA,kBAAAA,CAAA,oBAAA,EAAA,EAAqB,KAAA,EAAA,EAArB,oBAAA;AAEA,EAAAA,kBAAAA,CAAAA,kBAAAA,CAAA,aAAA,EAAA,EAAc,KAAA,EAAA,EAAd,aAAA;AAGA,EAAAA,kBAAAA,CAAAA,kBAAAA,CAAA,gBAAA,EAAA,EAAiB,KAAA,EAAA,EAAjB,gBAAA;AACA,EAAAA,kBAAAA,CAAAA,kBAAAA,CAAA,oBAAA,EAAA,EAAqB,KAAA,EAAA,EAArB,oBAAA;AACA,EAAAA,kBAAAA,CAAAA,kBAAAA,CAAA,YAAA,EAAA,EAAa,KAAA,EAAA,EAAb,YAAA;AACA,EAAAA,kBAAAA,CAAAA,kBAAAA,C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IAC/C,IAAA,EAAM,OAAA,CAAQ,IAAA;AAAA,IACd,GAAI,OAAA,CAAQ,OAAA,IAAW,KAAA,EAAA,GAAa,EAAE,MAAA,EAAQ,OAAA,CAAQ,OAAO,CAAA;AAAA,IAC7D,QAAA;AAAA,IACA,GAAI,OAAA,CAAQ,KAAA,IAAS,KAAA,EAAA,GAAa,EAAE,IAAA,EAAM,OAAA,CAAQ,KAAK,CAAA;AAAA,IACvD,GAAI,OAAA,CAAQ,QAAA,IAAY,KAAA,EAAA,GAAa,EAAE,OAAA,EAAS,OAAA,CAAQ,QAAQ,CAAA;AAAA,IAChE,GAAI,OAAA,CAAQ,OAAA,IAAW,KAAA,EAAA,GAAa,EAAE,MAAA,EAAQ,OAAA,CAAQ,OAAO;AAAA,EAC/D,CAAC,CAAA;AACH;ADxRA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,kYAAC","file":"/home/runner/work/hardware-js-sdk/hardware-js-sdk/packages/hwk-adapter-core/dist/chunk-Z3IH25KV.js","sourcesContent":[null,"/**\n * HWK HardwareErrorCode — independent namespace from the legacy\n * `@onekeyfe/shared` HardwareErrorCode (which occupies 0-902).\n *\n * All HWK codes are 5-digit (>= 10000) so the two tables never collide\n * even if either side grows. Each sub-category gets a 100-slot block.\n *\n * 10000-10099 Generic / cross-cutting primitives\n * 10100-10199 Device state\n * 10200-10299 Firmware\n * 10300-10399 Transport + OS-level permission\n * 10400-10499 PIN / Passphrase\n * 10500-10599 App lifecycle (wrong app, not open, too old)\n * 10600-10699 Payload / framing limits (adapter-level)\n * 10700-10999 RESERVED — future adapter-level categories\n *\n * 11000-11099 EVM APDU (reactive mapping)\n * 11100-11199 Solana APDU\n * 11200-11299 Tron APDU\n * 11300-11399 BTC APDU\n * 11400-11999 RESERVED — future chain APDU blocks (100 per chain)\n *\n * 12000-99999 RESERVED — future major categories\n */\nexport enum HardwareErrorCode {\n // --- 10000s Generic ---\n UnknownError = 10000,\n UserRejected = 10001,\n InvalidParams = 10002,\n OperationTimeout = 10003,\n MethodNotSupported = 10004,\n /** User dismissed in-app cancel UI. Distinct from UserRejected (on-device). */\n UserAborted = 10005,\n\n // --- 10100s Device state ---\n DeviceNotFound = 10100,\n DeviceDisconnected = 10101,\n DeviceBusy = 10102,\n DeviceLocked = 10103,\n DeviceNotInitialized = 10104,\n DeviceInBootloader = 10105,\n DeviceMismatch = 10106,\n /** Chain app wedged (e.g. Ledger BTC 0x6901). User must exit app on device. */\n DeviceAppStuck = 10107,\n /** Vendor (Ledger / Trezor) doesn't support the chain at all. */\n ChainNotSupported = 10108,\n /** Current operation supports only one connected device. */\n DeviceOneDeviceOnly = 10109,\n /**\n * The device rejected the requested derivation path (Trezor Failure_DataError\n * \"Forbidden key path\") — the path is non-standard or its index is outside the\n * range the device's safety checks allow. Distinct from ChainNotSupported\n * (whole chain) and MethodNotSupported (the operation/method itself).\n */\n DevicePathForbidden = 10110,\n /** Busy with our own in-flight request (queue guard / firmware Failure_Busy), not another app — wait and retry, don't close other apps. */\n DeviceBusyInternal = 10111,\n /** The supplied runtime-only operation id is unknown to this adapter instance. */\n OperationNotFound = 10112,\n /** The supplied operation ended and can never be resumed. */\n OperationEnded = 10113,\n /**\n * Discovery found devices but none of them is the wallet being looked for.\n * Milder than DeviceMismatch: nothing about the known wallet has changed, the\n * user simply has the wrong unit connected. DeviceMismatch stays reserved for\n * reaching the expected device and finding a different identity on it, which\n * can mean it was wiped, reseeded, or swapped.\n */\n DeviceSearchMismatch = 10114,\n\n // --- 10200s Firmware ---\n FirmwareTooOld = 10200,\n FirmwareUpdateRequired = 10201,\n\n // --- 10300s Transport + permission ---\n TransportError = 10300,\n BridgeNotFound = 10301,\n TransportNotAvailable = 10302,\n /**\n * OS-level permission (Bluetooth / USB / etc.) — denied, blocked,\n * unavailable, or dismissed. Consumers surface a single \"please grant\n * permission\" toast and let the user retry manually.\n */\n DevicePermissionDenied = 10303,\n /**\n * BLE SMP pairing did not complete within the GATT bonding window.\n * GATT connected but the device didn't acknowledge SMP — typically\n * because the user didn't confirm the passkey on the device, or the\n * device went out of range mid-pairing. Distinct from OperationTimeout\n * (generic) and from DeviceLocked (Secure Element actually locked).\n */\n BlePairingTimeout = 10304,\n /** Remote network failure reaching a vendor's servers (HTTP/WS). Distinct from TransportError (local USB/BLE link). */\n NetworkError = 10305,\n /**\n * Host-managed pairing handshake failed (Trezor THP). The device rejected the\n * pairing exchange — e.g. CodeEntry: the user mistyped the code shown on the\n * device, so the CPace tag didn't match (\"Unexpected Code Entry Tag\").\n * Recoverable: the user re-pairs and re-enters the code. Distinct from\n * BlePairingTimeout (BLE SMP bonding window) and UserRejected (on-device\n * reject button).\n */\n ThpPairingFailed = 10306,\n /**\n * The OS-level BLE bond is stale/invalid, so the device rejected link\n * encryption: Android GATT_INSUF_AUTHENTICATION (status 5) or iOS \"Peer\n * removed pairing information\". Happens after the device is wiped/re-flashed\n * or unpaired elsewhere while the host still holds an old bond. The SDK cannot\n * remove an OS bond — the user must forget the device in system Bluetooth\n * settings and re-pair. Distinct from BlePairingTimeout (SMP window) and\n * ThpPairingFailed (THP code mismatch).\n */\n BleBondInvalid = 10307,\n /**\n * A stored THP pairing credential was rejected by the device during the\n * handshake (device returned completion `state=0`), so the autoconnect session\n * could not be established. The SDK discards the stale credential; recovery is\n * a fresh pairing. Distinct from ThpPairingFailed (user mistyped the code\n * during an *active* pairing) and BleBondInvalid (OS-level BLE bond).\n */\n ThpPairingRequired = 10308,\n /**\n * Generic BLE connect failure where the OS dropped the specific reason. On\n * macOS the noble native binding hardcodes \"connection failed\" (and a connect\n * timeout) and discards the CoreBluetooth NSError, so the SDK cannot tell a\n * stale bond from an out-of-range / unresponsive device. Surfaced as a\n * generic \"couldn't connect — check the device, re-pair if paired before\".\n * Distinct from BleBondInvalid (a *known* stale-bond signal, iOS/Android only)\n * and BlePairingTimeout (the SMP bonding window).\n */\n BleConnectFailed = 10309,\n /**\n * The user cancelled BLE pairing from the app while the connect was still\n * waiting on the OS pairing window. Not a failure to report — the flow ends\n * because they asked it to. Distinct from UserAborted (generic in-app cancel)\n * so the pairing UI can close quietly instead of surfacing a connect error,\n * and from BlePairingTimeout (the SMP window elapsed on its own).\n */\n BlePairingCancelled = 10310,\n\n // --- 10400s PIN / Passphrase ---\n PinInvalid = 10400,\n PinCancelled = 10401,\n PassphraseRejected = 10402,\n /**\n * The passphrase entered produced a different wallet (`passphraseState`) than\n * the one the caller asked to operate on. Trezor-only: the host pins a wallet\n * by its derived state and the SDK refuses to sign with a mismatched\n * passphrase session. Surfaced by TrezorAdapter.getPassphraseState.\n */\n PassphraseStateMismatch = 10403,\n /**\n * The two new-PIN entries did not match during set/change PIN. Only host-input\n * models (Trezor Model One matrix) surface this; on-device-input models show\n * the mismatch on the device and never return it.\n */\n PinMismatch = 10404,\n /** Standard wallet is unavailable while Trezor enforces on-device passphrase entry. */\n PassphraseAlwaysOnDevice = 10405,\n\n // --- 10500s App lifecycle ---\n /** Chain app NOT INSTALLED on device. User must install via Ledger Live. */\n AppNotInstalled = 10500,\n WrongApp = 10501,\n /** 0x911c Command code not supported — app predates current SDK. */\n AppTooOld = 10502,\n /** Not enough free storage for install/update; user must uninstall apps first. */\n DeviceOutOfMemory = 10503,\n\n // --- 10600s Payload / framing limits ---\n /**\n * The call payload exceeds a transport's fixed framing capacity (e.g.\n * Keystone USB's ~12.5KB per-request cap — 200 frames of 64 bytes). Distinct\n * from a generic TransportError: the request never reached the device, and\n * retrying with the same payload over the same transport will fail the same\n * way. Callers should route the call over a different channel (e.g. Keystone\n * QR) or reduce the payload (e.g. a smaller PSBT) instead of retrying as-is.\n */\n PayloadTooLarge = 10600,\n\n // --- 11000s EVM (Ledger Ethereum App) APDU-specific ---\n /** 0x6a80 Invalid data — observed on blindSignTransactionFallback when the\n * user has not enabled Blind signing on the device. */\n EvmBlindSigningRequired = 11000,\n /** 0x6984 Plugin not installed */\n EvmClearSignPluginMissing = 11001,\n /** 0x6a84 Insufficient memory (typical on Nano S with large calldata) */\n EvmDataTooLarge = 11002,\n /** 0x6501 TransactionType not supported (app too old for EIP-1559 / blob / 7702) */\n EvmTxTypeNotSupported = 11003,\n\n // --- 11100s Solana ---\n /** 0x6808 Blind signing disabled for this instruction. */\n SolanaBlindSigningRequired = 11100,\n\n // --- 11200s Tron ---\n /** 0x6a8d Custom Contracts setting disabled (blocks TRC-20 etc.). */\n TronCustomContractRequired = 11200,\n /** 0x6a8b Transactions Data setting disabled. */\n TronDataSigningRequired = 11201,\n /** 0x6a8c Sign by Hash setting disabled (hash-signing fallback). */\n TronSignByHashRequired = 11202,\n\n // --- 11300s BTC ---\n /** 0xb008 Wallet policy HMAC mismatch or not registered. */\n BtcWalletPolicyHmacMismatch = 11300,\n /** 0xb007 Aborted due to unexpected state (malformed PSBT / missing UTXO). */\n BtcUnexpectedState = 11301,\n}\n\n/**\n * Device-level failures the SDK cannot self-recover from — affect the entire\n * batch (vs per-chain failures like AppNotInstalled / WrongApp which soft-\n * skip in onboarding). Combined with `accounts.length === 0`, signals\n * genuine orphan. Also reused as the batch-abort whitelist for HWK.\n * Single source of truth.\n *\n * UserRejected (device-side reject) is included: pressing reject is an\n * explicit \"I don't consent\" — continuing the batch to ask again on the\n * next chain is harassment, not helpful.\n */\nexport const ORPHAN_ELIGIBLE_ERROR_CODES: number[] = [\n HardwareErrorCode.UserAborted,\n HardwareErrorCode.UserRejected,\n HardwareErrorCode.DeviceNotFound,\n HardwareErrorCode.DeviceDisconnected,\n HardwareErrorCode.OperationNotFound,\n HardwareErrorCode.OperationEnded,\n HardwareErrorCode.DeviceMismatch,\n HardwareErrorCode.DeviceSearchMismatch,\n HardwareErrorCode.DeviceAppStuck,\n HardwareErrorCode.DeviceOneDeviceOnly,\n HardwareErrorCode.TransportError,\n HardwareErrorCode.DevicePermissionDenied,\n HardwareErrorCode.BlePairingTimeout,\n HardwareErrorCode.ThpPairingFailed,\n HardwareErrorCode.ThpPairingRequired,\n HardwareErrorCode.BleBondInvalid,\n HardwareErrorCode.BleConnectFailed,\n HardwareErrorCode.BlePairingCancelled,\n HardwareErrorCode.PassphraseAlwaysOnDevice,\n];\n\n// ---------------------------------------------------------------------------\n// Standard throwable for HWK adapters\n// ---------------------------------------------------------------------------\n\n/**\n * Where a failure came from. The distinction the numeric code ranges cannot\n * make reliably (UserRejected=10001 sits in the general range but is the\n * device speaking; DevicePermissionDenied=10303 sits in the transport range\n * but is the browser speaking), and the one recovery logic actually needs:\n *\n * - `device` the firmware ANSWERED: rejection, locked screen, wrong\n * wallet, bad PIN. It is a result, not a malfunction — surface\n * it to the user verbatim; never auto-reconnect, never switch\n * channels, never drop a healthy session over it.\n * - `transport` the pipe failed: cable pulled, bus reset, bridge gone.\n * Reconnecting or falling back to another channel is fair game.\n * - `host` the host environment refused: browser permission, picker\n * dismissed, bad parameters. Fix the environment, not the link.\n *\n * Optional on purpose: a mapper that cannot tell MUST leave it unset rather\n * than guess — consumers fall back to their existing code-based tables, so an\n * unset origin degrades to today's behavior instead of mislabeling.\n */\nexport type HwkErrorOrigin = 'device' | 'transport' | 'host';\n\n/**\n * Smallest runtime resource a consumer must replace before retrying a failed\n * operation. This is connection-lifecycle metadata, not UI navigation and not\n * permission to replay a signing command automatically.\n *\n * - `call`: nothing needs replacing; re-issuing the same call is eligible,\n * usually after the user fixes device state.\n * - `operation`: the operation binding is no longer usable; the selected target\n * may be used to establish a new one when its identity is persistent.\n * - `search-target`: the selected discovery result is stale or untrusted;\n * rediscover on the same transport and let the user select again.\n * - `transport`: the selected transport is unavailable or unsuitable; repair\n * it or choose another transport.\n * - `not-recoverable`: retrying the same operation/context cannot succeed.\n * - `unknown`: the SDK cannot make a safe recovery claim.\n */\nexport type HwkRecoveryScope =\n | 'call'\n | 'operation'\n | 'search-target'\n | 'transport'\n | 'not-recoverable'\n | 'unknown';\n\nexport interface HwkRecoveryHint {\n scope: HwkRecoveryScope;\n}\n\nconst RECOVERY_SCOPES = new Set<HwkRecoveryScope>([\n 'call',\n 'operation',\n 'search-target',\n 'transport',\n 'not-recoverable',\n 'unknown',\n]);\n\nexport function isHwkRecoveryHint(value: unknown): value is HwkRecoveryHint {\n if (!value || typeof value !== 'object') return false;\n const { scope } = value as { scope?: unknown };\n return typeof scope === 'string' && RECOVERY_SCOPES.has(scope as HwkRecoveryScope);\n}\n\nconst RECOVERY_CALL: HwkRecoveryHint = Object.freeze({ scope: 'call' });\nconst RECOVERY_OPERATION: HwkRecoveryHint = Object.freeze({ scope: 'operation' });\nconst RECOVERY_SEARCH_TARGET: HwkRecoveryHint = Object.freeze({ scope: 'search-target' });\nconst RECOVERY_TRANSPORT: HwkRecoveryHint = Object.freeze({ scope: 'transport' });\nconst RECOVERY_NOT_RECOVERABLE: HwkRecoveryHint = Object.freeze({\n scope: 'not-recoverable',\n});\nconst RECOVERY_UNKNOWN: HwkRecoveryHint = Object.freeze({ scope: 'unknown' });\n\n/**\n * Vendor-neutral fallback used when an adapter has no more precise runtime\n * knowledge. Adapters may stamp a narrower hint when transport/session state\n * makes the correct scope unambiguous.\n */\nexport function defaultRecoveryForCode(code: HardwareErrorCode): HwkRecoveryHint {\n switch (code) {\n case HardwareErrorCode.UserRejected:\n case HardwareErrorCode.UserAborted:\n case HardwareErrorCode.DeviceBusy:\n case HardwareErrorCode.DeviceLocked:\n case HardwareErrorCode.DeviceNotInitialized:\n case HardwareErrorCode.DeviceInBootloader:\n case HardwareErrorCode.DeviceAppStuck:\n case HardwareErrorCode.DeviceBusyInternal:\n case HardwareErrorCode.NetworkError:\n case HardwareErrorCode.PinInvalid:\n case HardwareErrorCode.PinCancelled:\n case HardwareErrorCode.PassphraseRejected:\n case HardwareErrorCode.PassphraseStateMismatch:\n case HardwareErrorCode.PinMismatch:\n case HardwareErrorCode.FirmwareTooOld:\n case HardwareErrorCode.FirmwareUpdateRequired:\n case HardwareErrorCode.AppNotInstalled:\n case HardwareErrorCode.WrongApp:\n case HardwareErrorCode.AppTooOld:\n case HardwareErrorCode.DeviceOutOfMemory:\n case HardwareErrorCode.EvmBlindSigningRequired:\n case HardwareErrorCode.EvmClearSignPluginMissing:\n case HardwareErrorCode.EvmDataTooLarge:\n case HardwareErrorCode.EvmTxTypeNotSupported:\n case HardwareErrorCode.SolanaBlindSigningRequired:\n case HardwareErrorCode.TronCustomContractRequired:\n case HardwareErrorCode.TronDataSigningRequired:\n case HardwareErrorCode.TronSignByHashRequired:\n case HardwareErrorCode.BtcWalletPolicyHmacMismatch:\n case HardwareErrorCode.BtcUnexpectedState:\n return RECOVERY_CALL;\n case HardwareErrorCode.DeviceNotFound:\n case HardwareErrorCode.DeviceDisconnected:\n case HardwareErrorCode.OperationNotFound:\n case HardwareErrorCode.OperationEnded:\n case HardwareErrorCode.TransportError:\n case HardwareErrorCode.BlePairingTimeout:\n case HardwareErrorCode.ThpPairingFailed:\n case HardwareErrorCode.ThpPairingRequired:\n case HardwareErrorCode.BleConnectFailed:\n case HardwareErrorCode.BlePairingCancelled:\n return RECOVERY_OPERATION;\n case HardwareErrorCode.DeviceMismatch:\n case HardwareErrorCode.DeviceSearchMismatch:\n case HardwareErrorCode.DeviceOneDeviceOnly:\n case HardwareErrorCode.BleBondInvalid:\n return RECOVERY_SEARCH_TARGET;\n case HardwareErrorCode.BridgeNotFound:\n case HardwareErrorCode.TransportNotAvailable:\n case HardwareErrorCode.DevicePermissionDenied:\n case HardwareErrorCode.PayloadTooLarge:\n return RECOVERY_TRANSPORT;\n case HardwareErrorCode.InvalidParams:\n case HardwareErrorCode.MethodNotSupported:\n case HardwareErrorCode.ChainNotSupported:\n case HardwareErrorCode.DevicePathForbidden:\n return RECOVERY_NOT_RECOVERABLE;\n case HardwareErrorCode.UnknownError:\n case HardwareErrorCode.OperationTimeout:\n default:\n return RECOVERY_UNKNOWN;\n }\n}\n\n/**\n * The authoritative code→origin table. Most codes imply their origin by\n * definition (UserRejected IS the device speaking; BridgeNotFound IS the\n * pipe). Vendors use this as the default and override only where their\n * mapping context knows better. Codes whose origin genuinely depends on\n * context (UnknownError, OperationTimeout — the device may be waiting for a\n * human, or the pipe may be dead — and DeviceBusy) return undefined: an\n * honest \"can't tell\" beats a plausible mislabel, because consumers fall\n * back to their existing behavior instead of taking the wrong recovery.\n */\nexport function defaultOriginForCode(code: HardwareErrorCode): HwkErrorOrigin | undefined {\n // Chain APDU blocks (11000+) are, without exception, the chain app on the\n // device answering a request it understood and refused/qualified.\n if (code >= 11_000) return 'device';\n switch (code) {\n case HardwareErrorCode.UserRejected:\n case HardwareErrorCode.DeviceLocked:\n case HardwareErrorCode.DeviceNotInitialized:\n case HardwareErrorCode.DeviceInBootloader:\n case HardwareErrorCode.DeviceMismatch:\n case HardwareErrorCode.DeviceSearchMismatch:\n case HardwareErrorCode.DeviceAppStuck:\n case HardwareErrorCode.DevicePathForbidden:\n case HardwareErrorCode.DeviceBusyInternal:\n case HardwareErrorCode.ChainNotSupported:\n case HardwareErrorCode.FirmwareTooOld:\n case HardwareErrorCode.FirmwareUpdateRequired:\n case HardwareErrorCode.PinInvalid:\n case HardwareErrorCode.PinMismatch:\n case HardwareErrorCode.PassphraseRejected:\n case HardwareErrorCode.PassphraseStateMismatch:\n case HardwareErrorCode.ThpPairingFailed:\n case HardwareErrorCode.ThpPairingRequired:\n case HardwareErrorCode.WrongApp:\n case HardwareErrorCode.AppNotInstalled:\n case HardwareErrorCode.AppTooOld:\n case HardwareErrorCode.DeviceOutOfMemory:\n return 'device';\n case HardwareErrorCode.DeviceNotFound:\n case HardwareErrorCode.DeviceDisconnected:\n case HardwareErrorCode.TransportError:\n case HardwareErrorCode.BridgeNotFound:\n case HardwareErrorCode.TransportNotAvailable:\n case HardwareErrorCode.BlePairingTimeout:\n case HardwareErrorCode.NetworkError:\n case HardwareErrorCode.BleBondInvalid:\n case HardwareErrorCode.BleConnectFailed:\n return 'transport';\n case HardwareErrorCode.DevicePermissionDenied:\n case HardwareErrorCode.UserAborted:\n case HardwareErrorCode.InvalidParams:\n case HardwareErrorCode.MethodNotSupported:\n case HardwareErrorCode.PinCancelled:\n case HardwareErrorCode.BlePairingCancelled:\n case HardwareErrorCode.PayloadTooLarge:\n case HardwareErrorCode.DeviceOneDeviceOnly:\n return 'host';\n default:\n return undefined;\n }\n}\n\nexport interface IHwkErrorPayload {\n code: HardwareErrorCode;\n message: string;\n origin?: HwkErrorOrigin;\n recovery?: HwkRecoveryHint;\n appName?: string;\n _tag?: string;\n params?: Record<string, unknown>;\n}\n\nexport interface IOperationMayHaveCompletedParams extends Record<string, unknown> {\n operationMayHaveCompleted: true;\n method: string;\n}\n\n/**\n * Marks an unsafe hardware request whose response was lost after dispatch.\n * Callers must not interpret the resulting transport error as proof that the\n * device rejected or did not execute the operation.\n */\nexport function operationMayHaveCompletedParams(\n method: string,\n params?: Record<string, unknown>\n): IOperationMayHaveCompletedParams {\n return {\n ...params,\n operationMayHaveCompleted: true,\n method,\n };\n}\n\nexport type HwkError = Error & {\n code: HardwareErrorCode;\n /** See {@link HwkErrorOrigin}. Survives serializeConnectorError/rehydrate\n * automatically (own fields outside the top-level whitelist travel via\n * `params` and are lifted back). */\n origin?: HwkErrorOrigin;\n recovery?: HwkRecoveryHint;\n appName?: string;\n _tag?: string;\n params?: Record<string, unknown>;\n};\n\n/**\n * Canonical throwable for HWK adapters. Plain Error + canonical extra fields,\n * shape-compatible with `rehydrateConnectorError` so locally-thrown and\n * cross-boundary errors are indistinguishable to downstream classifiers\n * (`err.code` / `err._tag` / `err.appName`). Do NOT mutate caught errors\n * with `Object.assign` — construct a fresh one via this factory.\n */\nexport function createHwkError(payload: IHwkErrorPayload): HwkError {\n const recovery = payload.recovery ?? defaultRecoveryForCode(payload.code);\n return Object.assign(new Error(payload.message), {\n code: payload.code,\n ...(payload.origin !== undefined && { origin: payload.origin }),\n recovery,\n ...(payload._tag !== undefined && { _tag: payload._tag }),\n ...(payload.appName !== undefined && { appName: payload.appName }),\n ...(payload.params !== undefined && { params: payload.params }),\n });\n}\n"]}
@@ -52,10 +52,18 @@ declare enum HardwareErrorCode {
52
52
  DevicePathForbidden = 10110,
53
53
  /** Busy with our own in-flight request (queue guard / firmware Failure_Busy), not another app — wait and retry, don't close other apps. */
54
54
  DeviceBusyInternal = 10111,
55
- /** The supplied runtime-only interaction id is unknown to this adapter instance. */
56
- InteractionNotFound = 10112,
57
- /** The supplied interaction ended and can never be resumed. */
58
- InteractionEnded = 10113,
55
+ /** The supplied runtime-only operation id is unknown to this adapter instance. */
56
+ OperationNotFound = 10112,
57
+ /** The supplied operation ended and can never be resumed. */
58
+ OperationEnded = 10113,
59
+ /**
60
+ * Discovery found devices but none of them is the wallet being looked for.
61
+ * Milder than DeviceMismatch: nothing about the known wallet has changed, the
62
+ * user simply has the wrong unit connected. DeviceMismatch stays reserved for
63
+ * reaching the expected device and finding a different identity on it, which
64
+ * can mean it was wiped, reseeded, or swapped.
65
+ */
66
+ DeviceSearchMismatch = 10114,
59
67
  FirmwareTooOld = 10200,
60
68
  FirmwareUpdateRequired = 10201,
61
69
  TransportError = 10300,
@@ -215,10 +223,10 @@ type HwkErrorOrigin = 'device' | 'transport' | 'host';
215
223
  * operation. This is connection-lifecycle metadata, not UI navigation and not
216
224
  * permission to replay a signing command automatically.
217
225
  *
218
- * - `operation`: the interaction and selected target are still eligible for an
219
- * explicit retry, usually after the user fixes device state.
220
- * - `interaction`: the interaction is no longer usable; the selected target may
221
- * be used to establish a new one when its identity is persistent.
226
+ * - `call`: nothing needs replacing; re-issuing the same call is eligible,
227
+ * usually after the user fixes device state.
228
+ * - `operation`: the operation binding is no longer usable; the selected target
229
+ * may be used to establish a new one when its identity is persistent.
222
230
  * - `search-target`: the selected discovery result is stale or untrusted;
223
231
  * rediscover on the same transport and let the user select again.
224
232
  * - `transport`: the selected transport is unavailable or unsuitable; repair
@@ -226,7 +234,7 @@ type HwkErrorOrigin = 'device' | 'transport' | 'host';
226
234
  * - `not-recoverable`: retrying the same operation/context cannot succeed.
227
235
  * - `unknown`: the SDK cannot make a safe recovery claim.
228
236
  */
229
- type HwkRecoveryScope = 'operation' | 'interaction' | 'search-target' | 'transport' | 'not-recoverable' | 'unknown';
237
+ type HwkRecoveryScope = 'call' | 'operation' | 'search-target' | 'transport' | 'not-recoverable' | 'unknown';
230
238
  interface HwkRecoveryHint {
231
239
  scope: HwkRecoveryScope;
232
240
  }
@@ -52,10 +52,18 @@ declare enum HardwareErrorCode {
52
52
  DevicePathForbidden = 10110,
53
53
  /** Busy with our own in-flight request (queue guard / firmware Failure_Busy), not another app — wait and retry, don't close other apps. */
54
54
  DeviceBusyInternal = 10111,
55
- /** The supplied runtime-only interaction id is unknown to this adapter instance. */
56
- InteractionNotFound = 10112,
57
- /** The supplied interaction ended and can never be resumed. */
58
- InteractionEnded = 10113,
55
+ /** The supplied runtime-only operation id is unknown to this adapter instance. */
56
+ OperationNotFound = 10112,
57
+ /** The supplied operation ended and can never be resumed. */
58
+ OperationEnded = 10113,
59
+ /**
60
+ * Discovery found devices but none of them is the wallet being looked for.
61
+ * Milder than DeviceMismatch: nothing about the known wallet has changed, the
62
+ * user simply has the wrong unit connected. DeviceMismatch stays reserved for
63
+ * reaching the expected device and finding a different identity on it, which
64
+ * can mean it was wiped, reseeded, or swapped.
65
+ */
66
+ DeviceSearchMismatch = 10114,
59
67
  FirmwareTooOld = 10200,
60
68
  FirmwareUpdateRequired = 10201,
61
69
  TransportError = 10300,
@@ -215,10 +223,10 @@ type HwkErrorOrigin = 'device' | 'transport' | 'host';
215
223
  * operation. This is connection-lifecycle metadata, not UI navigation and not
216
224
  * permission to replay a signing command automatically.
217
225
  *
218
- * - `operation`: the interaction and selected target are still eligible for an
219
- * explicit retry, usually after the user fixes device state.
220
- * - `interaction`: the interaction is no longer usable; the selected target may
221
- * be used to establish a new one when its identity is persistent.
226
+ * - `call`: nothing needs replacing; re-issuing the same call is eligible,
227
+ * usually after the user fixes device state.
228
+ * - `operation`: the operation binding is no longer usable; the selected target
229
+ * may be used to establish a new one when its identity is persistent.
222
230
  * - `search-target`: the selected discovery result is stale or untrusted;
223
231
  * rediscover on the same transport and let the user select again.
224
232
  * - `transport`: the selected transport is unavailable or unsuitable; repair
@@ -226,7 +234,7 @@ type HwkErrorOrigin = 'device' | 'transport' | 'host';
226
234
  * - `not-recoverable`: retrying the same operation/context cannot succeed.
227
235
  * - `unknown`: the SDK cannot make a safe recovery claim.
228
236
  */
229
- type HwkRecoveryScope = 'operation' | 'interaction' | 'search-target' | 'transport' | 'not-recoverable' | 'unknown';
237
+ type HwkRecoveryScope = 'call' | 'operation' | 'search-target' | 'transport' | 'not-recoverable' | 'unknown';
230
238
  interface HwkRecoveryHint {
231
239
  scope: HwkRecoveryScope;
232
240
  }
package/dist/errors.d.mts CHANGED
@@ -1 +1 @@
1
- export { H as HardwareErrorCode, c as HwkError, b as HwkRecoveryHint, d as HwkRecoveryScope, I as IHwkErrorPayload, O as ORPHAN_ELIGIBLE_ERROR_CODES, f as createHwkError, h as defaultRecoveryForCode, i as enrichErrorMessage, j as isHwkRecoveryHint } from './errors-ChA_YEZY.mjs';
1
+ export { H as HardwareErrorCode, c as HwkError, b as HwkRecoveryHint, d as HwkRecoveryScope, I as IHwkErrorPayload, O as ORPHAN_ELIGIBLE_ERROR_CODES, f as createHwkError, h as defaultRecoveryForCode, i as enrichErrorMessage, j as isHwkRecoveryHint } from './errors-C5GWtyVN.mjs';
package/dist/errors.d.ts CHANGED
@@ -1 +1 @@
1
- export { H as HardwareErrorCode, c as HwkError, b as HwkRecoveryHint, d as HwkRecoveryScope, I as IHwkErrorPayload, O as ORPHAN_ELIGIBLE_ERROR_CODES, f as createHwkError, h as defaultRecoveryForCode, i as enrichErrorMessage, j as isHwkRecoveryHint } from './errors-ChA_YEZY.js';
1
+ export { H as HardwareErrorCode, c as HwkError, b as HwkRecoveryHint, d as HwkRecoveryScope, I as IHwkErrorPayload, O as ORPHAN_ELIGIBLE_ERROR_CODES, f as createHwkError, h as defaultRecoveryForCode, i as enrichErrorMessage, j as isHwkRecoveryHint } from './errors-C5GWtyVN.js';
package/dist/errors.js CHANGED
@@ -7,7 +7,7 @@ var _chunk7SFFS2NLjs = require('./chunk-7SFFS2NL.js');
7
7
 
8
8
 
9
9
 
10
- var _chunkIZEVYMJKjs = require('./chunk-IZEVYMJK.js');
10
+ var _chunkZ3IH25KVjs = require('./chunk-Z3IH25KV.js');
11
11
 
12
12
 
13
13
 
@@ -15,5 +15,5 @@ var _chunkIZEVYMJKjs = require('./chunk-IZEVYMJK.js');
15
15
 
16
16
 
17
17
 
18
- exports.HardwareErrorCode = _chunkIZEVYMJKjs.HardwareErrorCode; exports.ORPHAN_ELIGIBLE_ERROR_CODES = _chunkIZEVYMJKjs.ORPHAN_ELIGIBLE_ERROR_CODES; exports.createHwkError = _chunkIZEVYMJKjs.createHwkError; exports.defaultRecoveryForCode = _chunkIZEVYMJKjs.defaultRecoveryForCode; exports.enrichErrorMessage = _chunk7SFFS2NLjs.enrichErrorMessage; exports.isHwkRecoveryHint = _chunkIZEVYMJKjs.isHwkRecoveryHint;
18
+ exports.HardwareErrorCode = _chunkZ3IH25KVjs.HardwareErrorCode; exports.ORPHAN_ELIGIBLE_ERROR_CODES = _chunkZ3IH25KVjs.ORPHAN_ELIGIBLE_ERROR_CODES; exports.createHwkError = _chunkZ3IH25KVjs.createHwkError; exports.defaultRecoveryForCode = _chunkZ3IH25KVjs.defaultRecoveryForCode; exports.enrichErrorMessage = _chunk7SFFS2NLjs.enrichErrorMessage; exports.isHwkRecoveryHint = _chunkZ3IH25KVjs.isHwkRecoveryHint;
19
19
  //# sourceMappingURL=errors.js.map
package/dist/errors.mjs CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  createHwkError,
8
8
  defaultRecoveryForCode,
9
9
  isHwkRecoveryHint
10
- } from "./chunk-72KOSYTH.mjs";
10
+ } from "./chunk-E3UPXUN5.mjs";
11
11
  export {
12
12
  HardwareErrorCode,
13
13
  ORPHAN_ELIGIBLE_ERROR_CODES,