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,CAAC,eAAe,CAAC,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAe;IACrD,MAAM,YAAY,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAElD,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,OAAO,GAAG,WAAW,YAAY,CAAC,OAAO,EAAE,CAAC;QAElD,OAAO,IAAI,mBAAmB,CAAC,OAAO,EAAE;YACtC,IAAI,EAAE,YAAY,CAAC,IAAI;YACvB,QAAQ,EAAE,YAAY,CAAC,QAAQ;YAC/B,QAAQ,EAAE,YAAY,CAAC,QAAQ;YAC/B,WAAW,EAAE,YAAY,CAAC,WAAW,IAAI,OAAO;SACjD,CAAC,CAAC;IACL,CAAC;IAED,MAAM,eAAe,GAAG,iCAAiC,IAAI,EAAE,CAAC;IAEhE,OAAO,IAAI,mBAAmB,CAAC,eAAe,EAAE;QAC9C,IAAI,EAAE,SAAS,CAAC,OAAO;QACvB,QAAQ,EAAE,QAAQ,CAAC,GAAG;QACtB,QAAQ,EAAE,QAAQ,CAAC,OAAO;QAC1B,WAAW,EAAE,eAAe;KAC7B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n  ErrorMapping,\n  ErrorCode,\n  Severity,\n  Category,\n  HardwareWalletError,\n  LEDGER_ERROR_MAPPINGS,\n  KEYRING_ERROR_MAPPINGS,\n} from '@metamask/hw-wallet-sdk';\n\n/**\n * Factory function to create a HardwareWalletError from a Ledger error code.\n *\n * @param ledgerErrorCode - The Ledger error code (e.g., '0x6985', '0x5515')\n * @param context - Optional additional context to append to the error message\n * @returns A HardwareWalletError instance with mapped error details\n */\nexport function createLedgerError(\n  ledgerErrorCode: string,\n  context?: string,\n): HardwareWalletError {\n  const errorMapping = getLedgerErrorMapping(ledgerErrorCode);\n\n  if (errorMapping) {\n    const message = context\n      ? `${errorMapping.message} (${context})`\n      : errorMapping.message;\n\n    return new HardwareWalletError(message, {\n      code: errorMapping.code,\n      severity: errorMapping.severity,\n      category: errorMapping.category,\n      userMessage: errorMapping.userMessage ?? message,\n    });\n  }\n\n  // Fallback for unknown error codes\n  const fallbackMessage = context\n    ? `Unknown Ledger error: ${ledgerErrorCode} (${context})`\n    : `Unknown Ledger error: ${ledgerErrorCode}`;\n\n  return new HardwareWalletError(fallbackMessage, {\n    code: ErrorCode.Unknown,\n    severity: Severity.Err,\n    category: Category.Unknown,\n    userMessage: fallbackMessage,\n  });\n}\n\n/**\n * Checks if a Ledger error code exists in the error mappings.\n *\n * @param ledgerErrorCode - The Ledger error code to check\n * @returns True if the error code is mapped, false otherwise\n */\nexport function isKnownLedgerError(ledgerErrorCode: string): boolean {\n  return ledgerErrorCode in LEDGER_ERROR_MAPPINGS;\n}\n\n/**\n * Gets the error mapping details for a Ledger error code without creating an error instance.\n *\n * @param ledgerErrorCode - The Ledger error code to look up\n * @returns The error mapping details or undefined if not found\n */\nexport function getLedgerErrorMapping(\n  ledgerErrorCode: string,\n): ErrorMapping | undefined {\n  return LEDGER_ERROR_MAPPINGS[ledgerErrorCode];\n}\n\n/**\n * Factory function to create a HardwareWalletError from a keyring-level error code.\n *\n * @param code - The keyring error code (e.g., ErrorCode.DeviceStateOnlyV4Supported)\n * @returns A HardwareWalletError instance with mapped error details\n */\nexport function createKeyringStateError(code: ErrorCode): HardwareWalletError {\n  const errorMapping = KEYRING_ERROR_MAPPINGS[code];\n\n  if (errorMapping) {\n    const message = `Ledger: ${errorMapping.message}`;\n\n    return new HardwareWalletError(message, {\n      code: errorMapping.code,\n      severity: errorMapping.severity,\n      category: errorMapping.category,\n      userMessage: errorMapping.userMessage ?? message,\n    });\n  }\n\n  const fallbackMessage = `Unknown Ledger keyring error: ${code}`;\n\n  return new HardwareWalletError(fallbackMessage, {\n    code: ErrorCode.Unknown,\n    severity: Severity.Err,\n    category: Category.Unknown,\n    userMessage: fallbackMessage,\n  });\n}\n"]}