Skip to content

Commit fdba802

Browse files
authored
Merge pull request #62 from Zondax/dev
New Release
2 parents 2d2eb39 + 68dd807 commit fdba802

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

bun.lockb

3.58 KB
Binary file not shown.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@
3535
"upgrade": "bunx npm-check-updates -i"
3636
},
3737
"dependencies": {
38-
"@ledgerhq/hw-transport": "6.31.2"
38+
"@ledgerhq/hw-transport": "6.31.4"
3939
},
4040
"devDependencies": {
4141
"@ledgerhq/hw-transport-mocker": "^6.28.6",
4242
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
43-
"@types/jest": "29.5.12",
43+
"@types/jest": "29.5.14",
4444
"@types/node": "^22.4.1",
4545
"@typescript-eslint/eslint-plugin": "^8.1.0",
46-
"@typescript-eslint/parser": "^7.13.0",
46+
"@typescript-eslint/parser": "^8.14.0",
4747
"eslint": "^9.4.0",
4848
"eslint-config-prettier": "^9.1.0",
4949
"eslint-config-standard-with-typescript": "^43.0.1",
@@ -53,6 +53,7 @@
5353
"eslint-plugin-tsdoc": "^0.3.0",
5454
"eslint-plugin-unused-imports": "^4.0.0",
5555
"prettier": "^3.3.2",
56+
"sort-package-json": "^2.10.1",
5657
"ts-jest": "^29.1.4",
5758
"ts-node": "^10.9.2",
5859
"typescript": "^5.4.5"

src/common.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*****************************************************************************/
1616
import { processErrorResponse } from './common'
17-
import { LedgerError } from './consts'
17+
import { LedgerCustomError, LedgerError } from './consts'
1818
import { errorCodeToString } from './errors'
1919
import { ResponseError } from './responseError'
2020

@@ -25,6 +25,18 @@ describe('errorCodeToString', () => {
2525
expect(errorCodeToString(knownErrorCode)).toEqual(expectedMessage)
2626
})
2727

28+
it('should return the correct error message for a custom error code', () => {
29+
const knownErrorCode: LedgerCustomError = 0xabcd
30+
const expectedMessage = 'test custom error'
31+
expect(errorCodeToString(knownErrorCode, { 0xabcd: expectedMessage })).toEqual(expectedMessage)
32+
})
33+
34+
it('should return the correct error message for a known error code, when a custom error list is passed', () => {
35+
const knownErrorCode: LedgerError = 0x9000
36+
const expectedMessage = 'No errors'
37+
expect(errorCodeToString(knownErrorCode, { [knownErrorCode]: 'Custom no errors' })).toEqual(expectedMessage)
38+
})
39+
2840
it('should return "Unknown Return Code" for an unknown error code', () => {
2941
const unknownErrorCode: LedgerError = 0x9999 as LedgerError
3042
const expectedMessage = 'Unknown Return Code: 0x9999'

src/consts.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export const PAYLOAD_TYPE: Readonly<Record<string, number>> = {
2525
LAST: 0x02,
2626
}
2727

28+
export type LedgerCustomError = number
29+
2830
// Ledger error codes and descriptions sorted by value
2931
export enum LedgerError {
3032
U2FUnknown = 1,

src/errors.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,25 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*****************************************************************************/
16-
import { ERROR_DESCRIPTION_OVERRIDE, LedgerError } from './consts'
16+
import { ERROR_DESCRIPTION_OVERRIDE, LedgerCustomError, LedgerError } from './consts'
1717

1818
/**
1919
* Converts a Ledger error code to a human-readable string.
2020
*
2121
* @param returnCode - The Ledger error code to convert.
22+
* @param customErrorList - Custom error description list to convert error code with.
2223
* @returns A string describing the error code.
2324
*/
24-
export function errorCodeToString(returnCode: LedgerError): string {
25+
export function errorCodeToString(returnCode: LedgerError, customErrorList?: Record<LedgerCustomError, string>): string {
2526
const returnCodeStr = returnCode.toString(16).toUpperCase()
2627
let errDescription = `Unknown Return Code: 0x${returnCodeStr}`
2728

2829
if (returnCode in ERROR_DESCRIPTION_OVERRIDE) {
29-
errDescription = ERROR_DESCRIPTION_OVERRIDE[returnCode]
30+
return ERROR_DESCRIPTION_OVERRIDE[returnCode]
31+
}
32+
33+
if (customErrorList && returnCode in customErrorList) {
34+
return customErrorList[returnCode]
3035
}
3136

3237
return errDescription

0 commit comments

Comments
 (0)