@metamask/eth-ledger-bridge-keyring
Version:
A MetaMask compatible keyring, for ledger hardware wallets
26 lines • 1.43 kB
text/typescript
import { DeviceExchangeError } from "@ledgerhq/device-management-kit";
import { TransportStatusError } from "@ledgerhq/hw-transport";
import { HardwareWalletError } from "@metamask/hw-wallet-sdk";
/**
* Translates a DMK error into an error the Ledger keyring error handler can
* process.
*
* Resolution order:
* 1. **DMK `_tag`** — connection/session-level DMK errors (e.g.
* `DeviceSessionNotFound`, `DeviceLockedError`) carry a `_tag` but no hex
* APDU status code. These are resolved to a {@link HardwareWalletError}
* via the shared SDK mappings.
* 2. **`DeviceExchangeError` hex code** — APDU-level errors that carry a
* 4-character hex `errorCode` (e.g. `'6985'`). These are converted to a
* {@link TransportStatusError} so the existing `LEDGER_ERROR_MAPPINGS`
* lookup in the keyring error handler applies.
* 3. **Generic fallback** — anything else is wrapped in a
* {@link TransportStatusError} with status `0x6f00`.
*
* @param error - The error from a DMK device action or command.
* @returns A `HardwareWalletError` (for resolved DMK tags) or a
* `TransportStatusError` (for hex codes and the generic fallback).
*/
export declare function translateDmkError(error: unknown): TransportStatusError | HardwareWalletError;
export declare function isDeviceExchangeError(error: unknown): error is DeviceExchangeError<string>;
//# sourceMappingURL=dmk-error-translator.d.cts.map