UNPKG

@metamask/eth-ledger-bridge-keyring

Version:
35 lines 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isDeviceExchangeError = exports.translateDmkError = void 0; const device_management_kit_1 = require("@ledgerhq/device-management-kit"); const hw_transport_1 = require("@ledgerhq/hw-transport"); const GENERIC_ERROR_STATUS_CODE = 0x6f00; /** * Translates a DMK error (DeviceExchangeError with hex error codes) into a * TransportStatusError that the Ledger keyring error handler can process. * * @param error - The error from a DMK device action or command. * @returns A TransportStatusError with the corresponding APDU status code. */ function translateDmkError(error) { if (isDeviceExchangeError(error)) { const statusCode = parseHexErrorCode(error.errorCode); return new hw_transport_1.TransportStatusError(statusCode); } return new hw_transport_1.TransportStatusError(GENERIC_ERROR_STATUS_CODE); } exports.translateDmkError = translateDmkError; function isDeviceExchangeError(error) { return (typeof error === 'object' && error !== null && '_tag' in error && 'errorCode' in error); } exports.isDeviceExchangeError = isDeviceExchangeError; function parseHexErrorCode(errorCode) { if (typeof errorCode === 'string' && /^[0-9a-fA-F]{4}$/u.test(errorCode)) { return parseInt(errorCode, 16); } return GENERIC_ERROR_STATUS_CODE; } //# sourceMappingURL=dmk-error-translator.cjs.map