CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-ledgerhq--errors

Comprehensive error handling system for Ledger hardware wallet applications and libraries

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

application-manager-errors.mddocs/

Application and Manager Errors

Error classes for Ledger application management including app installation, dependencies, firmware updates, and manager operations.

Capabilities

Application Installation Errors

Errors related to installing and managing applications on Ledger devices.

const ManagerAppAlreadyInstalledError: CustomErrorFunc;
const ManagerAppRelyOnBTCError: CustomErrorFunc;
const ManagerAppDepInstallRequired: CustomErrorFunc;
const ManagerAppDepUninstallRequired: CustomErrorFunc;
const ManagerUninstallBTCDep: CustomErrorFunc;

Usage Examples:

import { 
  ManagerAppAlreadyInstalledError,
  ManagerAppRelyOnBTCError,
  ManagerAppDepInstallRequired,
  ManagerAppDepUninstallRequired,
  ManagerUninstallBTCDep
} from "@ledgerhq/errors";

// Handle app already installed
try {
  await installApp("Bitcoin");
} catch (error) {
  if (error instanceof ManagerAppAlreadyInstalledError) {
    console.log("Bitcoin app is already installed");
  }
}

// Handle Bitcoin dependency requirement
try {
  await installApp("BitcoinCash");
} catch (error) {
  if (error instanceof ManagerAppRelyOnBTCError) {
    console.log("Bitcoin Cash app requires Bitcoin app to be installed first");
  }
}

// Handle dependency install requirement
if (requiredDeps.length > 0) {
  throw new ManagerAppDepInstallRequired(
    `Please install dependencies first: ${requiredDeps.join(", ")}`
  );
}

// Handle dependency uninstall requirement
if (dependentApps.length > 0) {
  throw new ManagerAppDepUninstallRequired(
    `Please uninstall dependent apps first: ${dependentApps.join(", ")}`
  );
}

// Handle Bitcoin dependency uninstall
try {
  await uninstallApp("Bitcoin");
} catch (error) {
  if (error instanceof ManagerUninstallBTCDep) {
    console.log("Cannot uninstall Bitcoin - other apps depend on it");
  }
}

Device Manager Errors

Errors related to device manager operations and device locking.

const ManagerDeviceLockedError: CustomErrorFunc;
const ManagerNotEnoughSpaceError: CustomErrorFunc;

Usage Examples:

import { 
  ManagerDeviceLockedError,
  ManagerNotEnoughSpaceError
} from "@ledgerhq/errors";

// Handle locked device during manager operations
try {
  await performManagerOperation();
} catch (error) {
  if (error instanceof ManagerDeviceLockedError) {
    console.log("Device is locked - please enter PIN and try again");
  }
}

// Handle insufficient storage space
function checkDeviceSpace(requiredSpace: number, availableSpace: number) {
  if (availableSpace < requiredSpace) {
    throw new ManagerNotEnoughSpaceError(
      `Insufficient space: ${requiredSpace}KB required, ${availableSpace}KB available`
    );
  }
}

// Example space management
async function installAppWithSpaceCheck(appName: string, appSize: number) {
  const deviceInfo = await getDeviceInfo();
  
  try {
    checkDeviceSpace(appSize, deviceInfo.availableSpace);
    await installApp(appName);
  } catch (error) {
    if (error instanceof ManagerNotEnoughSpaceError) {
      console.log("Please free up space by uninstalling unused apps");
      const suggestions = await getAppsToRemove(appSize);
      console.log("Consider removing:", suggestions.join(", "));
    }
  }
}

Firmware Management Errors

Errors related to firmware updates and MCU operations.

const FirmwareNotRecognized: CustomErrorFunc;
const FirmwareOrAppUpdateRequired: CustomErrorFunc;
const ManagerFirmwareNotEnoughSpaceError: CustomErrorFunc;
const LatestMCUInstalledError: CustomErrorFunc;
const UnknownMCU: CustomErrorFunc;
const UpdateFetchFileFail: CustomErrorFunc;
const UpdateIncorrectHash: CustomErrorFunc;
const UpdateIncorrectSig: CustomErrorFunc;

Usage Examples:

import { 
  FirmwareNotRecognized,
  FirmwareOrAppUpdateRequired,
  ManagerFirmwareNotEnoughSpaceError,
  LatestMCUInstalledError,
  UnknownMCU
} from "@ledgerhq/errors";

// Handle unrecognized firmware
try {
  await validateFirmware();
} catch (error) {
  if (error instanceof FirmwareNotRecognized) {
    console.log("Device firmware is not recognized");
    console.log("Please contact support or update your device");
  }
}

// Handle required updates
function checkCompatibility(firmwareVersion: string, appVersion: string) {
  if (!isCompatible(firmwareVersion, appVersion)) {
    throw new FirmwareOrAppUpdateRequired(
      "Firmware or app update required for compatibility"
    );
  }
}

// Handle firmware space issues
try {
  await installFirmwareUpdate();
} catch (error) {
  if (error instanceof ManagerFirmwareNotEnoughSpaceError) {
    console.log("Insufficient space for firmware update");
    console.log("Please remove some apps and try again");
  }
}

// Handle MCU update attempts
try {
  await updateMCU();
} catch (error) {
  if (error instanceof LatestMCUInstalledError) {
    console.log("Latest MCU version is already installed");
  } else if (error instanceof UnknownMCU) {
    console.log("MCU type is not recognized");
  }
}

// Handle update file operations
try {
  const updateFile = await fetchUpdateFile(updateUrl);
} catch (error) {
  if (error instanceof UpdateFetchFileFail) {
    console.log("Failed to download update file - check network connection");
  }
}

// Handle update integrity validation
try {
  await validateUpdateFile(updateFile);
} catch (error) {
  if (error instanceof UpdateIncorrectHash) {
    console.log("Update file hash validation failed - file may be corrupted");
  } else if (error instanceof UpdateIncorrectSig) {
    console.log("Update file signature verification failed - file may be tampered");
  }
}

Application Compatibility Errors

Errors related to application compatibility and requirements.

const UpdateYourApp: CustomErrorFunc;
const DeviceAppVerifyNotSupported: CustomErrorFunc;
const BtcUnmatchedApp: CustomErrorFunc;
const WrongAppForCurrency: CustomErrorFunc;

Usage Examples:

import { 
  UpdateYourApp,
  DeviceAppVerifyNotSupported,
  BtcUnmatchedApp,
  WrongAppForCurrency
} from "@ledgerhq/errors";

// Handle app update requirement
function checkAppVersion(currentVersion: string, requiredVersion: string) {
  if (isVersionOlder(currentVersion, requiredVersion)) {
    throw new UpdateYourApp(
      `Please update your app from ${currentVersion} to ${requiredVersion}`
    );
  }
}

// Handle unsupported verification
try {
  await verifyApp();
} catch (error) {
  if (error instanceof DeviceAppVerifyNotSupported) {
    console.log("App verification is not supported for this app version");
  }
}

// Handle Bitcoin app mismatch
function validateBitcoinOperation(openApp: string) {
  if (openApp !== "Bitcoin" && openApp !== "Bitcoin Test") {
    throw new BtcUnmatchedApp("Please open the Bitcoin app on your device");
  }
}

// Handle wrong app for currency
function validateCurrencyApp(currency: string, openApp: string) {
  const expectedApp = getCurrencyApp(currency);
  if (openApp !== expectedApp) {
    throw new WrongAppForCurrency(
      `Please open the ${expectedApp} app to handle ${currency} transactions`
    );
  }
}

// Example usage in transaction flow
async function prepareTransaction(currency: string, amount: number) {
  const deviceStatus = await getDeviceStatus();
  
  try {
    validateCurrencyApp(currency, deviceStatus.currentApp);
    await createTransaction(currency, amount);
  } catch (error) {
    if (error instanceof WrongAppForCurrency) {
      console.log("Please switch to the correct app on your device");
      await waitForAppSwitch();
      return prepareTransaction(currency, amount);
    }
  }
}

docs

account-balance-errors.md

application-manager-errors.md

currency-transaction-errors.md

database-errors.md

device-management-errors.md

error-utilities.md

index.md

network-api-errors.md

transport-errors.md

user-interaction-errors.md

tile.json