@metamask/eth-trezor-keyring
Version:
A MetaMask compatible keyring, for trezor hardware wallets
1 lines • 3.46 kB
Source Map (JSON)
{"version":3,"file":"trezor-errors.mjs","sourceRoot":"","sources":["../src/trezor-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACpB,gCAAgC;AAGjC;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,qBAA6B,EAC7B,OAAgB;;IAEhB,MAAM,YAAY,GAAG,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;IAElE,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,OAAO,GAAG,OAAO;YACrB,CAAC,CAAC,GAAG,YAAY,CAAC,OAAO,KAAK,OAAO,GAAG;YACxC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC;QAEzB,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,MAAA,YAAY,CAAC,WAAW,mCAAI,OAAO;SACjD,CAAC,CAAC;IACL,CAAC;IAED,mCAAmC;IACnC,MAAM,eAAe,GAAG,OAAO;QAC7B,CAAC,CAAC,yBAAyB,qBAAqB,KAAK,OAAO,GAAG;QAC/D,CAAC,CAAC,yBAAyB,qBAAqB,EAAE,CAAC;IAErD,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;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,qBAA6B;IAC9D,OAAO,qBAAqB,IAAI,qBAAqB,CAAC;AACxD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACnC,qBAA6B;IAE7B,OAAO,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import {\n TREZOR_ERROR_MAPPINGS,\n ErrorCode,\n Severity,\n Category,\n HardwareWalletError,\n} from '@metamask/hw-wallet-sdk';\nimport type { ErrorMapping } from '@metamask/hw-wallet-sdk';\n\n/**\n * Factory function to create a HardwareWalletError from a Trezor error identifier.\n *\n * @param trezorErrorIdentifier - The Trezor error identifier (e.g., 'Device_Disconnected', 'Method_Cancel')\n * @param context - Optional additional context to append to the error message\n * @returns A HardwareWalletError instance with mapped error details\n */\nexport function createTrezorError(\n trezorErrorIdentifier: string,\n context?: string,\n): HardwareWalletError {\n const errorMapping = getTrezorErrorMapping(trezorErrorIdentifier);\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 Trezor error: ${trezorErrorIdentifier} (${context})`\n : `Unknown Trezor error: ${trezorErrorIdentifier}`;\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 Trezor error identifier exists in the error mappings.\n *\n * @param trezorErrorIdentifier - The Trezor error identifier to check\n * @returns True if the error identifier is mapped, false otherwise\n */\nexport function isKnownTrezorError(trezorErrorIdentifier: string): boolean {\n return trezorErrorIdentifier in TREZOR_ERROR_MAPPINGS;\n}\n\n/**\n * Gets the error mapping details for a Trezor error identifier without creating an error instance.\n *\n * @param trezorErrorIdentifier - The Trezor error identifier to look up\n * @returns The error mapping details or undefined if not found\n */\nexport function getTrezorErrorMapping(\n trezorErrorIdentifier: string,\n): ErrorMapping | undefined {\n return TREZOR_ERROR_MAPPINGS[trezorErrorIdentifier];\n}\n"]}