@onekeyfe/hwk-adapter-core 1.2.3-alpha.8 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/{chunk-WUIWRX56.js → chunk-BAGEFFFY.js} +13 -49
  2. package/dist/chunk-BAGEFFFY.js.map +1 -0
  3. package/dist/{chunk-CQM2P5IG.js → chunk-SZZF623R.js} +55 -155
  4. package/dist/chunk-SZZF623R.js.map +1 -0
  5. package/dist/{chunk-EQYPRCWU.mjs → chunk-U63HTLGJ.mjs} +12 -48
  6. package/dist/chunk-U63HTLGJ.mjs.map +1 -0
  7. package/dist/{chunk-IOFMG7YO.mjs → chunk-YA4BWFTZ.mjs} +55 -155
  8. package/dist/chunk-YA4BWFTZ.mjs.map +1 -0
  9. package/dist/errors.d.mts +207 -1
  10. package/dist/errors.d.ts +207 -1
  11. package/dist/errors.js +2 -8
  12. package/dist/errors.js.map +1 -1
  13. package/dist/errors.mjs +3 -9
  14. package/dist/index.d.mts +98 -635
  15. package/dist/index.d.ts +98 -635
  16. package/dist/index.js +82 -680
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +73 -671
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/{ui-events-BGUpXxvP.d.ts → ui-events-Cb7haAeE.d.mts} +3 -44
  21. package/dist/{ui-events-BGUpXxvP.d.mts → ui-events-Cb7haAeE.d.ts} +3 -44
  22. package/dist/ui-events.d.mts +1 -1
  23. package/dist/ui-events.d.ts +1 -1
  24. package/dist/ui-events.js +2 -3
  25. package/dist/ui-events.js.map +1 -1
  26. package/dist/ui-events.mjs +1 -2
  27. package/package.json +2 -2
  28. package/dist/chunk-CQM2P5IG.js.map +0 -1
  29. package/dist/chunk-DB4JOPZO.mjs +0 -74
  30. package/dist/chunk-DB4JOPZO.mjs.map +0 -1
  31. package/dist/chunk-EQYPRCWU.mjs.map +0 -1
  32. package/dist/chunk-IOFMG7YO.mjs.map +0 -1
  33. package/dist/chunk-WUIWRX56.js.map +0 -1
  34. package/dist/chunk-YLCHSNXO.js +0 -74
  35. package/dist/chunk-YLCHSNXO.js.map +0 -1
  36. package/dist/errors-Cm8XpjmX.d.mts +0 -321
  37. package/dist/errors-Cm8XpjmX.d.ts +0 -321
@@ -1,321 +0,0 @@
1
- /**
2
- * HWK HardwareErrorCode — independent namespace from the legacy
3
- * `@onekeyfe/shared` HardwareErrorCode (which occupies 0-902).
4
- *
5
- * All HWK codes are 5-digit (>= 10000) so the two tables never collide
6
- * even if either side grows. Each sub-category gets a 100-slot block.
7
- *
8
- * 10000-10099 Generic / cross-cutting primitives
9
- * 10100-10199 Device state
10
- * 10200-10299 Firmware
11
- * 10300-10399 Transport + OS-level permission
12
- * 10400-10499 PIN / Passphrase
13
- * 10500-10599 App lifecycle (wrong app, not open, too old)
14
- * 10600-10699 Payload / framing limits (adapter-level)
15
- * 10700-10999 RESERVED — future adapter-level categories
16
- *
17
- * 11000-11099 EVM APDU (reactive mapping)
18
- * 11100-11199 Solana APDU
19
- * 11200-11299 Tron APDU
20
- * 11300-11399 BTC APDU
21
- * 11400-11999 RESERVED — future chain APDU blocks (100 per chain)
22
- *
23
- * 12000-99999 RESERVED — future major categories
24
- */
25
- declare enum HardwareErrorCode {
26
- UnknownError = 10000,
27
- UserRejected = 10001,
28
- InvalidParams = 10002,
29
- OperationTimeout = 10003,
30
- MethodNotSupported = 10004,
31
- /** User dismissed in-app cancel UI. Distinct from UserRejected (on-device). */
32
- UserAborted = 10005,
33
- DeviceNotFound = 10100,
34
- DeviceDisconnected = 10101,
35
- DeviceBusy = 10102,
36
- DeviceLocked = 10103,
37
- DeviceNotInitialized = 10104,
38
- DeviceInBootloader = 10105,
39
- DeviceMismatch = 10106,
40
- /** Chain app wedged (e.g. Ledger BTC 0x6901). User must exit app on device. */
41
- DeviceAppStuck = 10107,
42
- /** Vendor (Ledger / Trezor) doesn't support the chain at all. */
43
- ChainNotSupported = 10108,
44
- /** Current operation supports only one connected device. */
45
- DeviceOneDeviceOnly = 10109,
46
- /**
47
- * The device rejected the requested derivation path (Trezor Failure_DataError
48
- * "Forbidden key path") — the path is non-standard or its index is outside the
49
- * range the device's safety checks allow. Distinct from ChainNotSupported
50
- * (whole chain) and MethodNotSupported (the operation/method itself).
51
- */
52
- DevicePathForbidden = 10110,
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
- DeviceBusyInternal = 10111,
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,
67
- FirmwareTooOld = 10200,
68
- FirmwareUpdateRequired = 10201,
69
- TransportError = 10300,
70
- BridgeNotFound = 10301,
71
- TransportNotAvailable = 10302,
72
- /**
73
- * OS-level permission (Bluetooth / USB / etc.) — denied, blocked,
74
- * unavailable, or dismissed. Consumers surface a single "please grant
75
- * permission" toast and let the user retry manually.
76
- */
77
- DevicePermissionDenied = 10303,
78
- /**
79
- * BLE SMP pairing did not complete within the GATT bonding window.
80
- * GATT connected but the device didn't acknowledge SMP — typically
81
- * because the user didn't confirm the passkey on the device, or the
82
- * device went out of range mid-pairing. Distinct from OperationTimeout
83
- * (generic) and from DeviceLocked (Secure Element actually locked).
84
- */
85
- BlePairingTimeout = 10304,
86
- /** Remote network failure reaching a vendor's servers (HTTP/WS). Distinct from TransportError (local USB/BLE link). */
87
- NetworkError = 10305,
88
- /**
89
- * Host-managed pairing handshake failed (Trezor THP). The device rejected the
90
- * pairing exchange — e.g. CodeEntry: the user mistyped the code shown on the
91
- * device, so the CPace tag didn't match ("Unexpected Code Entry Tag").
92
- * Recoverable: the user re-pairs and re-enters the code. Distinct from
93
- * BlePairingTimeout (BLE SMP bonding window) and UserRejected (on-device
94
- * reject button).
95
- */
96
- ThpPairingFailed = 10306,
97
- /**
98
- * The OS-level BLE bond is stale/invalid, so the device rejected link
99
- * encryption: Android GATT_INSUF_AUTHENTICATION (status 5) or iOS "Peer
100
- * removed pairing information". Happens after the device is wiped/re-flashed
101
- * or unpaired elsewhere while the host still holds an old bond. The SDK cannot
102
- * remove an OS bond — the user must forget the device in system Bluetooth
103
- * settings and re-pair. Distinct from BlePairingTimeout (SMP window) and
104
- * ThpPairingFailed (THP code mismatch).
105
- */
106
- BleBondInvalid = 10307,
107
- /**
108
- * A stored THP pairing credential was rejected by the device during the
109
- * handshake (device returned completion `state=0`), so the autoconnect session
110
- * could not be established. The SDK discards the stale credential; recovery is
111
- * a fresh pairing. Distinct from ThpPairingFailed (user mistyped the code
112
- * during an *active* pairing) and BleBondInvalid (OS-level BLE bond).
113
- */
114
- ThpPairingRequired = 10308,
115
- /**
116
- * Generic BLE connect failure where the OS dropped the specific reason. On
117
- * macOS the noble native binding hardcodes "connection failed" (and a connect
118
- * timeout) and discards the CoreBluetooth NSError, so the SDK cannot tell a
119
- * stale bond from an out-of-range / unresponsive device. Surfaced as a
120
- * generic "couldn't connect — check the device, re-pair if paired before".
121
- * Distinct from BleBondInvalid (a *known* stale-bond signal, iOS/Android only)
122
- * and BlePairingTimeout (the SMP bonding window).
123
- */
124
- BleConnectFailed = 10309,
125
- /**
126
- * The user cancelled BLE pairing from the app while the connect was still
127
- * waiting on the OS pairing window. Not a failure to report — the flow ends
128
- * because they asked it to. Distinct from UserAborted (generic in-app cancel)
129
- * so the pairing UI can close quietly instead of surfacing a connect error,
130
- * and from BlePairingTimeout (the SMP window elapsed on its own).
131
- */
132
- BlePairingCancelled = 10310,
133
- /**
134
- * The vendor's remote secure channel broke while it was relaying APDUs to the
135
- * device (Ledger: the manager-api script-runner WebSocket behind app install,
136
- * uninstall and genuine check). The device link itself is still usable, so
137
- * this is not a disconnect: retry the same call. Distinct from NetworkError,
138
- * which is a plain HTTP/WS request that never carried device traffic.
139
- */
140
- LedgerSecureChannelError = 10311,
141
- /**
142
- * The vendor's metadata service answered with a payload the SDK cannot use
143
- * (Ledger: firmware metadata or the application catalog). Not a connectivity
144
- * failure — the request succeeded and the response was unusable — so callers
145
- * must not treat it as a dropped link.
146
- */
147
- LedgerFirmwareMetadataError = 10312,
148
- PinInvalid = 10400,
149
- PinCancelled = 10401,
150
- PassphraseRejected = 10402,
151
- /**
152
- * The passphrase entered produced a different wallet (`passphraseState`) than
153
- * the one the caller asked to operate on. Trezor-only: the host pins a wallet
154
- * by its derived state and the SDK refuses to sign with a mismatched
155
- * passphrase session. Surfaced by TrezorAdapter.getPassphraseState.
156
- */
157
- PassphraseStateMismatch = 10403,
158
- /**
159
- * The two new-PIN entries did not match during set/change PIN. Only host-input
160
- * models (Trezor Model One matrix) surface this; on-device-input models show
161
- * the mismatch on the device and never return it.
162
- */
163
- PinMismatch = 10404,
164
- /** Standard wallet is unavailable while Trezor enforces on-device passphrase entry. */
165
- PassphraseAlwaysOnDevice = 10405,
166
- /** Chain app NOT INSTALLED on device. User must install via Ledger Live. */
167
- AppNotInstalled = 10500,
168
- WrongApp = 10501,
169
- /** 0x911c Command code not supported — app predates current SDK. */
170
- AppTooOld = 10502,
171
- /** Not enough free storage for install/update; user must uninstall apps first. */
172
- DeviceOutOfMemory = 10503,
173
- /** Install refused because the app is already on the device. Benign for callers that only need it present. */
174
- AppAlreadyInstalled = 10504,
175
- /**
176
- * The call payload exceeds a transport's fixed framing capacity (e.g.
177
- * Keystone USB's ~12.5KB per-request cap — 200 frames of 64 bytes). Distinct
178
- * from a generic TransportError: the request never reached the device, and
179
- * retrying with the same payload over the same transport will fail the same
180
- * way. Callers should route the call over a different channel (e.g. Keystone
181
- * QR) or reduce the payload (e.g. a smaller PSBT) instead of retrying as-is.
182
- */
183
- PayloadTooLarge = 10600,
184
- /** 0x6a80 Invalid data — observed on blindSignTransactionFallback when the
185
- * user has not enabled Blind signing on the device. */
186
- EvmBlindSigningRequired = 11000,
187
- /** 0x6984 Plugin not installed */
188
- EvmClearSignPluginMissing = 11001,
189
- /** 0x6a84 Insufficient memory (typical on Nano S with large calldata) */
190
- EvmDataTooLarge = 11002,
191
- /** 0x6501 TransactionType not supported (app too old for EIP-1559 / blob / 7702) */
192
- EvmTxTypeNotSupported = 11003,
193
- /** 0x6808 Blind signing disabled for this instruction. */
194
- SolanaBlindSigningRequired = 11100,
195
- /** 0x6a8d Custom Contracts setting disabled (blocks TRC-20 etc.). */
196
- TronCustomContractRequired = 11200,
197
- /** 0x6a8b Transactions Data setting disabled. */
198
- TronDataSigningRequired = 11201,
199
- /** 0x6a8c Sign by Hash setting disabled (hash-signing fallback). */
200
- TronSignByHashRequired = 11202,
201
- /** 0xb008 Wallet policy HMAC mismatch or not registered. */
202
- BtcWalletPolicyHmacMismatch = 11300,
203
- /** 0xb007 Aborted due to unexpected state (malformed PSBT / missing UTXO). */
204
- BtcUnexpectedState = 11301
205
- }
206
- /**
207
- * Device-level failures the SDK cannot self-recover from — affect the entire
208
- * batch (vs per-chain failures like AppNotInstalled / WrongApp which soft-
209
- * skip in onboarding). Combined with `accounts.length === 0`, signals
210
- * genuine orphan. Also reused as the batch-abort whitelist for HWK.
211
- * Single source of truth.
212
- *
213
- * UserRejected (device-side reject) is included: pressing reject is an
214
- * explicit "I don't consent" — continuing the batch to ask again on the
215
- * next chain is harassment, not helpful.
216
- */
217
- declare const ORPHAN_ELIGIBLE_ERROR_CODES: number[];
218
- /**
219
- * Where a failure came from. The distinction the numeric code ranges cannot
220
- * make reliably (UserRejected=10001 sits in the general range but is the
221
- * device speaking; DevicePermissionDenied=10303 sits in the transport range
222
- * but is the browser speaking), and the one recovery logic actually needs:
223
- *
224
- * - `device` the firmware ANSWERED: rejection, locked screen, wrong
225
- * wallet, bad PIN. It is a result, not a malfunction — surface
226
- * it to the user verbatim; never auto-reconnect, never switch
227
- * channels, never drop a healthy session over it.
228
- * - `transport` the pipe failed: cable pulled, bus reset, bridge gone.
229
- * Reconnecting or falling back to another channel is fair game.
230
- * - `host` the host environment refused: browser permission, picker
231
- * dismissed, bad parameters. Fix the environment, not the link.
232
- *
233
- * Optional on purpose: a mapper that cannot tell MUST leave it unset rather
234
- * than guess — consumers fall back to their existing code-based tables, so an
235
- * unset origin degrades to today's behavior instead of mislabeling.
236
- */
237
- type HwkErrorOrigin = 'device' | 'transport' | 'host';
238
- /**
239
- * Smallest runtime resource a consumer must replace before retrying a failed
240
- * operation. This is connection-lifecycle metadata, not UI navigation and not
241
- * permission to replay a signing command automatically.
242
- *
243
- * - `call`: nothing needs replacing; re-issuing the same call is eligible,
244
- * usually after the user fixes device state.
245
- * - `operation`: the operation binding is no longer usable; the selected target
246
- * may be used to establish a new one when its identity is persistent.
247
- * - `search-target`: the selected discovery result is stale or untrusted;
248
- * rediscover on the same transport and let the user select again.
249
- * - `transport`: the selected transport is unavailable or unsuitable; repair
250
- * it or choose another transport.
251
- * - `not-recoverable`: retrying the same operation/context cannot succeed.
252
- * - `unknown`: the SDK cannot make a safe recovery claim.
253
- */
254
- type HwkRecoveryScope = 'call' | 'operation' | 'search-target' | 'transport' | 'not-recoverable' | 'unknown';
255
- interface HwkRecoveryHint {
256
- scope: HwkRecoveryScope;
257
- }
258
- declare function isHwkRecoveryHint(value: unknown): value is HwkRecoveryHint;
259
- /**
260
- * Vendor-neutral fallback used when an adapter has no more precise runtime
261
- * knowledge. Adapters may stamp a narrower hint when transport/session state
262
- * makes the correct scope unambiguous.
263
- */
264
- declare function defaultRecoveryForCode(code: HardwareErrorCode): HwkRecoveryHint;
265
- /**
266
- * The authoritative code→origin table. Most codes imply their origin by
267
- * definition (UserRejected IS the device speaking; BridgeNotFound IS the
268
- * pipe). Vendors use this as the default and override only where their
269
- * mapping context knows better. Codes whose origin genuinely depends on
270
- * context (UnknownError, OperationTimeout — the device may be waiting for a
271
- * human, or the pipe may be dead — and DeviceBusy) return undefined: an
272
- * honest "can't tell" beats a plausible mislabel, because consumers fall
273
- * back to their existing behavior instead of taking the wrong recovery.
274
- */
275
- declare function defaultOriginForCode(code: HardwareErrorCode): HwkErrorOrigin | undefined;
276
- interface IHwkErrorPayload {
277
- code: HardwareErrorCode;
278
- message: string;
279
- origin?: HwkErrorOrigin;
280
- recovery?: HwkRecoveryHint;
281
- appName?: string;
282
- _tag?: string;
283
- params?: Record<string, unknown>;
284
- }
285
- interface IOperationMayHaveCompletedParams extends Record<string, unknown> {
286
- operationMayHaveCompleted: true;
287
- method: string;
288
- }
289
- /**
290
- * Marks an unsafe hardware request whose response was lost after dispatch.
291
- * Callers must not interpret the resulting transport error as proof that the
292
- * device rejected or did not execute the operation.
293
- */
294
- declare function operationMayHaveCompletedParams(method: string, params?: Record<string, unknown>): IOperationMayHaveCompletedParams;
295
- type HwkError = Error & {
296
- code: HardwareErrorCode;
297
- /** See {@link HwkErrorOrigin}. Survives serializeConnectorError/rehydrate
298
- * automatically (own fields outside the top-level whitelist travel via
299
- * `params` and are lifted back). */
300
- origin?: HwkErrorOrigin;
301
- recovery?: HwkRecoveryHint;
302
- appName?: string;
303
- _tag?: string;
304
- params?: Record<string, unknown>;
305
- };
306
- /**
307
- * Canonical throwable for HWK adapters. Plain Error + canonical extra fields,
308
- * shape-compatible with `rehydrateConnectorError` so locally-thrown and
309
- * cross-boundary errors are indistinguishable to downstream classifiers
310
- * (`err.code` / `err._tag` / `err.appName`). Do NOT mutate caught errors
311
- * with `Object.assign` — construct a fresh one via this factory.
312
- */
313
- declare function createHwkError(payload: IHwkErrorPayload): HwkError;
314
-
315
- /**
316
- * Enrich a hardware error message with actionable recovery hints.
317
- * Shared across adapters (Ledger, Trezor, etc.).
318
- */
319
- declare function enrichErrorMessage(code: HardwareErrorCode, originalMessage: string): string;
320
-
321
- export { HardwareErrorCode as H, type IHwkErrorPayload as I, ORPHAN_ELIGIBLE_ERROR_CODES as O, type HwkErrorOrigin as a, type HwkRecoveryHint as b, type HwkError as c, type HwkRecoveryScope as d, type IOperationMayHaveCompletedParams as e, createHwkError as f, defaultOriginForCode as g, defaultRecoveryForCode as h, enrichErrorMessage as i, isHwkRecoveryHint as j, operationMayHaveCompletedParams as o };
@@ -1,321 +0,0 @@
1
- /**
2
- * HWK HardwareErrorCode — independent namespace from the legacy
3
- * `@onekeyfe/shared` HardwareErrorCode (which occupies 0-902).
4
- *
5
- * All HWK codes are 5-digit (>= 10000) so the two tables never collide
6
- * even if either side grows. Each sub-category gets a 100-slot block.
7
- *
8
- * 10000-10099 Generic / cross-cutting primitives
9
- * 10100-10199 Device state
10
- * 10200-10299 Firmware
11
- * 10300-10399 Transport + OS-level permission
12
- * 10400-10499 PIN / Passphrase
13
- * 10500-10599 App lifecycle (wrong app, not open, too old)
14
- * 10600-10699 Payload / framing limits (adapter-level)
15
- * 10700-10999 RESERVED — future adapter-level categories
16
- *
17
- * 11000-11099 EVM APDU (reactive mapping)
18
- * 11100-11199 Solana APDU
19
- * 11200-11299 Tron APDU
20
- * 11300-11399 BTC APDU
21
- * 11400-11999 RESERVED — future chain APDU blocks (100 per chain)
22
- *
23
- * 12000-99999 RESERVED — future major categories
24
- */
25
- declare enum HardwareErrorCode {
26
- UnknownError = 10000,
27
- UserRejected = 10001,
28
- InvalidParams = 10002,
29
- OperationTimeout = 10003,
30
- MethodNotSupported = 10004,
31
- /** User dismissed in-app cancel UI. Distinct from UserRejected (on-device). */
32
- UserAborted = 10005,
33
- DeviceNotFound = 10100,
34
- DeviceDisconnected = 10101,
35
- DeviceBusy = 10102,
36
- DeviceLocked = 10103,
37
- DeviceNotInitialized = 10104,
38
- DeviceInBootloader = 10105,
39
- DeviceMismatch = 10106,
40
- /** Chain app wedged (e.g. Ledger BTC 0x6901). User must exit app on device. */
41
- DeviceAppStuck = 10107,
42
- /** Vendor (Ledger / Trezor) doesn't support the chain at all. */
43
- ChainNotSupported = 10108,
44
- /** Current operation supports only one connected device. */
45
- DeviceOneDeviceOnly = 10109,
46
- /**
47
- * The device rejected the requested derivation path (Trezor Failure_DataError
48
- * "Forbidden key path") — the path is non-standard or its index is outside the
49
- * range the device's safety checks allow. Distinct from ChainNotSupported
50
- * (whole chain) and MethodNotSupported (the operation/method itself).
51
- */
52
- DevicePathForbidden = 10110,
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
- DeviceBusyInternal = 10111,
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,
67
- FirmwareTooOld = 10200,
68
- FirmwareUpdateRequired = 10201,
69
- TransportError = 10300,
70
- BridgeNotFound = 10301,
71
- TransportNotAvailable = 10302,
72
- /**
73
- * OS-level permission (Bluetooth / USB / etc.) — denied, blocked,
74
- * unavailable, or dismissed. Consumers surface a single "please grant
75
- * permission" toast and let the user retry manually.
76
- */
77
- DevicePermissionDenied = 10303,
78
- /**
79
- * BLE SMP pairing did not complete within the GATT bonding window.
80
- * GATT connected but the device didn't acknowledge SMP — typically
81
- * because the user didn't confirm the passkey on the device, or the
82
- * device went out of range mid-pairing. Distinct from OperationTimeout
83
- * (generic) and from DeviceLocked (Secure Element actually locked).
84
- */
85
- BlePairingTimeout = 10304,
86
- /** Remote network failure reaching a vendor's servers (HTTP/WS). Distinct from TransportError (local USB/BLE link). */
87
- NetworkError = 10305,
88
- /**
89
- * Host-managed pairing handshake failed (Trezor THP). The device rejected the
90
- * pairing exchange — e.g. CodeEntry: the user mistyped the code shown on the
91
- * device, so the CPace tag didn't match ("Unexpected Code Entry Tag").
92
- * Recoverable: the user re-pairs and re-enters the code. Distinct from
93
- * BlePairingTimeout (BLE SMP bonding window) and UserRejected (on-device
94
- * reject button).
95
- */
96
- ThpPairingFailed = 10306,
97
- /**
98
- * The OS-level BLE bond is stale/invalid, so the device rejected link
99
- * encryption: Android GATT_INSUF_AUTHENTICATION (status 5) or iOS "Peer
100
- * removed pairing information". Happens after the device is wiped/re-flashed
101
- * or unpaired elsewhere while the host still holds an old bond. The SDK cannot
102
- * remove an OS bond — the user must forget the device in system Bluetooth
103
- * settings and re-pair. Distinct from BlePairingTimeout (SMP window) and
104
- * ThpPairingFailed (THP code mismatch).
105
- */
106
- BleBondInvalid = 10307,
107
- /**
108
- * A stored THP pairing credential was rejected by the device during the
109
- * handshake (device returned completion `state=0`), so the autoconnect session
110
- * could not be established. The SDK discards the stale credential; recovery is
111
- * a fresh pairing. Distinct from ThpPairingFailed (user mistyped the code
112
- * during an *active* pairing) and BleBondInvalid (OS-level BLE bond).
113
- */
114
- ThpPairingRequired = 10308,
115
- /**
116
- * Generic BLE connect failure where the OS dropped the specific reason. On
117
- * macOS the noble native binding hardcodes "connection failed" (and a connect
118
- * timeout) and discards the CoreBluetooth NSError, so the SDK cannot tell a
119
- * stale bond from an out-of-range / unresponsive device. Surfaced as a
120
- * generic "couldn't connect — check the device, re-pair if paired before".
121
- * Distinct from BleBondInvalid (a *known* stale-bond signal, iOS/Android only)
122
- * and BlePairingTimeout (the SMP bonding window).
123
- */
124
- BleConnectFailed = 10309,
125
- /**
126
- * The user cancelled BLE pairing from the app while the connect was still
127
- * waiting on the OS pairing window. Not a failure to report — the flow ends
128
- * because they asked it to. Distinct from UserAborted (generic in-app cancel)
129
- * so the pairing UI can close quietly instead of surfacing a connect error,
130
- * and from BlePairingTimeout (the SMP window elapsed on its own).
131
- */
132
- BlePairingCancelled = 10310,
133
- /**
134
- * The vendor's remote secure channel broke while it was relaying APDUs to the
135
- * device (Ledger: the manager-api script-runner WebSocket behind app install,
136
- * uninstall and genuine check). The device link itself is still usable, so
137
- * this is not a disconnect: retry the same call. Distinct from NetworkError,
138
- * which is a plain HTTP/WS request that never carried device traffic.
139
- */
140
- LedgerSecureChannelError = 10311,
141
- /**
142
- * The vendor's metadata service answered with a payload the SDK cannot use
143
- * (Ledger: firmware metadata or the application catalog). Not a connectivity
144
- * failure — the request succeeded and the response was unusable — so callers
145
- * must not treat it as a dropped link.
146
- */
147
- LedgerFirmwareMetadataError = 10312,
148
- PinInvalid = 10400,
149
- PinCancelled = 10401,
150
- PassphraseRejected = 10402,
151
- /**
152
- * The passphrase entered produced a different wallet (`passphraseState`) than
153
- * the one the caller asked to operate on. Trezor-only: the host pins a wallet
154
- * by its derived state and the SDK refuses to sign with a mismatched
155
- * passphrase session. Surfaced by TrezorAdapter.getPassphraseState.
156
- */
157
- PassphraseStateMismatch = 10403,
158
- /**
159
- * The two new-PIN entries did not match during set/change PIN. Only host-input
160
- * models (Trezor Model One matrix) surface this; on-device-input models show
161
- * the mismatch on the device and never return it.
162
- */
163
- PinMismatch = 10404,
164
- /** Standard wallet is unavailable while Trezor enforces on-device passphrase entry. */
165
- PassphraseAlwaysOnDevice = 10405,
166
- /** Chain app NOT INSTALLED on device. User must install via Ledger Live. */
167
- AppNotInstalled = 10500,
168
- WrongApp = 10501,
169
- /** 0x911c Command code not supported — app predates current SDK. */
170
- AppTooOld = 10502,
171
- /** Not enough free storage for install/update; user must uninstall apps first. */
172
- DeviceOutOfMemory = 10503,
173
- /** Install refused because the app is already on the device. Benign for callers that only need it present. */
174
- AppAlreadyInstalled = 10504,
175
- /**
176
- * The call payload exceeds a transport's fixed framing capacity (e.g.
177
- * Keystone USB's ~12.5KB per-request cap — 200 frames of 64 bytes). Distinct
178
- * from a generic TransportError: the request never reached the device, and
179
- * retrying with the same payload over the same transport will fail the same
180
- * way. Callers should route the call over a different channel (e.g. Keystone
181
- * QR) or reduce the payload (e.g. a smaller PSBT) instead of retrying as-is.
182
- */
183
- PayloadTooLarge = 10600,
184
- /** 0x6a80 Invalid data — observed on blindSignTransactionFallback when the
185
- * user has not enabled Blind signing on the device. */
186
- EvmBlindSigningRequired = 11000,
187
- /** 0x6984 Plugin not installed */
188
- EvmClearSignPluginMissing = 11001,
189
- /** 0x6a84 Insufficient memory (typical on Nano S with large calldata) */
190
- EvmDataTooLarge = 11002,
191
- /** 0x6501 TransactionType not supported (app too old for EIP-1559 / blob / 7702) */
192
- EvmTxTypeNotSupported = 11003,
193
- /** 0x6808 Blind signing disabled for this instruction. */
194
- SolanaBlindSigningRequired = 11100,
195
- /** 0x6a8d Custom Contracts setting disabled (blocks TRC-20 etc.). */
196
- TronCustomContractRequired = 11200,
197
- /** 0x6a8b Transactions Data setting disabled. */
198
- TronDataSigningRequired = 11201,
199
- /** 0x6a8c Sign by Hash setting disabled (hash-signing fallback). */
200
- TronSignByHashRequired = 11202,
201
- /** 0xb008 Wallet policy HMAC mismatch or not registered. */
202
- BtcWalletPolicyHmacMismatch = 11300,
203
- /** 0xb007 Aborted due to unexpected state (malformed PSBT / missing UTXO). */
204
- BtcUnexpectedState = 11301
205
- }
206
- /**
207
- * Device-level failures the SDK cannot self-recover from — affect the entire
208
- * batch (vs per-chain failures like AppNotInstalled / WrongApp which soft-
209
- * skip in onboarding). Combined with `accounts.length === 0`, signals
210
- * genuine orphan. Also reused as the batch-abort whitelist for HWK.
211
- * Single source of truth.
212
- *
213
- * UserRejected (device-side reject) is included: pressing reject is an
214
- * explicit "I don't consent" — continuing the batch to ask again on the
215
- * next chain is harassment, not helpful.
216
- */
217
- declare const ORPHAN_ELIGIBLE_ERROR_CODES: number[];
218
- /**
219
- * Where a failure came from. The distinction the numeric code ranges cannot
220
- * make reliably (UserRejected=10001 sits in the general range but is the
221
- * device speaking; DevicePermissionDenied=10303 sits in the transport range
222
- * but is the browser speaking), and the one recovery logic actually needs:
223
- *
224
- * - `device` the firmware ANSWERED: rejection, locked screen, wrong
225
- * wallet, bad PIN. It is a result, not a malfunction — surface
226
- * it to the user verbatim; never auto-reconnect, never switch
227
- * channels, never drop a healthy session over it.
228
- * - `transport` the pipe failed: cable pulled, bus reset, bridge gone.
229
- * Reconnecting or falling back to another channel is fair game.
230
- * - `host` the host environment refused: browser permission, picker
231
- * dismissed, bad parameters. Fix the environment, not the link.
232
- *
233
- * Optional on purpose: a mapper that cannot tell MUST leave it unset rather
234
- * than guess — consumers fall back to their existing code-based tables, so an
235
- * unset origin degrades to today's behavior instead of mislabeling.
236
- */
237
- type HwkErrorOrigin = 'device' | 'transport' | 'host';
238
- /**
239
- * Smallest runtime resource a consumer must replace before retrying a failed
240
- * operation. This is connection-lifecycle metadata, not UI navigation and not
241
- * permission to replay a signing command automatically.
242
- *
243
- * - `call`: nothing needs replacing; re-issuing the same call is eligible,
244
- * usually after the user fixes device state.
245
- * - `operation`: the operation binding is no longer usable; the selected target
246
- * may be used to establish a new one when its identity is persistent.
247
- * - `search-target`: the selected discovery result is stale or untrusted;
248
- * rediscover on the same transport and let the user select again.
249
- * - `transport`: the selected transport is unavailable or unsuitable; repair
250
- * it or choose another transport.
251
- * - `not-recoverable`: retrying the same operation/context cannot succeed.
252
- * - `unknown`: the SDK cannot make a safe recovery claim.
253
- */
254
- type HwkRecoveryScope = 'call' | 'operation' | 'search-target' | 'transport' | 'not-recoverable' | 'unknown';
255
- interface HwkRecoveryHint {
256
- scope: HwkRecoveryScope;
257
- }
258
- declare function isHwkRecoveryHint(value: unknown): value is HwkRecoveryHint;
259
- /**
260
- * Vendor-neutral fallback used when an adapter has no more precise runtime
261
- * knowledge. Adapters may stamp a narrower hint when transport/session state
262
- * makes the correct scope unambiguous.
263
- */
264
- declare function defaultRecoveryForCode(code: HardwareErrorCode): HwkRecoveryHint;
265
- /**
266
- * The authoritative code→origin table. Most codes imply their origin by
267
- * definition (UserRejected IS the device speaking; BridgeNotFound IS the
268
- * pipe). Vendors use this as the default and override only where their
269
- * mapping context knows better. Codes whose origin genuinely depends on
270
- * context (UnknownError, OperationTimeout — the device may be waiting for a
271
- * human, or the pipe may be dead — and DeviceBusy) return undefined: an
272
- * honest "can't tell" beats a plausible mislabel, because consumers fall
273
- * back to their existing behavior instead of taking the wrong recovery.
274
- */
275
- declare function defaultOriginForCode(code: HardwareErrorCode): HwkErrorOrigin | undefined;
276
- interface IHwkErrorPayload {
277
- code: HardwareErrorCode;
278
- message: string;
279
- origin?: HwkErrorOrigin;
280
- recovery?: HwkRecoveryHint;
281
- appName?: string;
282
- _tag?: string;
283
- params?: Record<string, unknown>;
284
- }
285
- interface IOperationMayHaveCompletedParams extends Record<string, unknown> {
286
- operationMayHaveCompleted: true;
287
- method: string;
288
- }
289
- /**
290
- * Marks an unsafe hardware request whose response was lost after dispatch.
291
- * Callers must not interpret the resulting transport error as proof that the
292
- * device rejected or did not execute the operation.
293
- */
294
- declare function operationMayHaveCompletedParams(method: string, params?: Record<string, unknown>): IOperationMayHaveCompletedParams;
295
- type HwkError = Error & {
296
- code: HardwareErrorCode;
297
- /** See {@link HwkErrorOrigin}. Survives serializeConnectorError/rehydrate
298
- * automatically (own fields outside the top-level whitelist travel via
299
- * `params` and are lifted back). */
300
- origin?: HwkErrorOrigin;
301
- recovery?: HwkRecoveryHint;
302
- appName?: string;
303
- _tag?: string;
304
- params?: Record<string, unknown>;
305
- };
306
- /**
307
- * Canonical throwable for HWK adapters. Plain Error + canonical extra fields,
308
- * shape-compatible with `rehydrateConnectorError` so locally-thrown and
309
- * cross-boundary errors are indistinguishable to downstream classifiers
310
- * (`err.code` / `err._tag` / `err.appName`). Do NOT mutate caught errors
311
- * with `Object.assign` — construct a fresh one via this factory.
312
- */
313
- declare function createHwkError(payload: IHwkErrorPayload): HwkError;
314
-
315
- /**
316
- * Enrich a hardware error message with actionable recovery hints.
317
- * Shared across adapters (Ledger, Trezor, etc.).
318
- */
319
- declare function enrichErrorMessage(code: HardwareErrorCode, originalMessage: string): string;
320
-
321
- export { HardwareErrorCode as H, type IHwkErrorPayload as I, ORPHAN_ELIGIBLE_ERROR_CODES as O, type HwkErrorOrigin as a, type HwkRecoveryHint as b, type HwkError as c, type HwkRecoveryScope as d, type IOperationMayHaveCompletedParams as e, createHwkError as f, defaultOriginForCode as g, defaultRecoveryForCode as h, enrichErrorMessage as i, isHwkRecoveryHint as j, operationMayHaveCompletedParams as o };