Skip to content

Commit edd83ad

Browse files
authored
Unify ledger errors and zondax errors (#5499)
This makes one unified type with all the known error codes.
1 parent 2424713 commit edd83ad

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

ironfish-cli/src/ledger/ledger.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
44
import { Assert, createRootLogger, Logger } from '@ironfish/sdk'
5-
import { StatusCodes as LedgerStatusCodes, TransportStatusError } from '@ledgerhq/errors'
5+
import { StatusCodes, TransportStatusError } from '@ledgerhq/errors'
66
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
77
import IronfishApp, {
88
KeyResponse,
@@ -12,6 +12,11 @@ import IronfishApp, {
1212
} from '@zondax/ledger-ironfish'
1313
import { ResponseError, Transport } from '@zondax/ledger-js'
1414

15+
export const IronfishLedgerStatusCodes = {
16+
...StatusCodes,
17+
COMMAND_NOT_ALLOWED: 0x6986,
18+
}
19+
1520
export class Ledger {
1621
app: IronfishApp | undefined
1722
logger: Logger
@@ -41,7 +46,7 @@ export class Ledger {
4146
if (
4247
error instanceof ResponseError &&
4348
error.message.includes('Attempt to read beyond buffer length') &&
44-
error.returnCode === LedgerStatusCodes.TECHNICAL_PROBLEM
49+
error.returnCode === IronfishLedgerStatusCodes.TECHNICAL_PROBLEM
4550
) {
4651
// Catch this error and swollow it until the SDK fix merges to fix
4752
// this
@@ -56,7 +61,7 @@ export class Ledger {
5661
} catch (error) {
5762
if (
5863
error instanceof ResponseError &&
59-
error.returnCode === LedgerStatusCodes.INS_NOT_SUPPORTED
64+
error.returnCode === IronfishLedgerStatusCodes.INS_NOT_SUPPORTED
6065
) {
6166
throw new LedgerAppLocked()
6267
}
@@ -77,16 +82,16 @@ export class Ledger {
7782
}
7883

7984
if (error instanceof ResponseError) {
80-
if (error.returnCode === LedgerStatusCodes.LOCKED_DEVICE) {
85+
if (error.returnCode === IronfishLedgerStatusCodes.LOCKED_DEVICE) {
8186
throw new LedgerDeviceLockedError()
82-
} else if (error.returnCode === LedgerStatusCodes.CLA_NOT_SUPPORTED) {
87+
} else if (error.returnCode === IronfishLedgerStatusCodes.CLA_NOT_SUPPORTED) {
8388
throw new LedgerClaNotSupportedError()
84-
} else if (error.returnCode === LedgerStatusCodes.GP_AUTH_FAILED) {
89+
} else if (error.returnCode === IronfishLedgerStatusCodes.GP_AUTH_FAILED) {
8590
throw new LedgerGPAuthFailed()
8691
} else if (
8792
[
88-
LedgerStatusCodes.INS_NOT_SUPPORTED,
89-
LedgerStatusCodes.TECHNICAL_PROBLEM,
93+
IronfishLedgerStatusCodes.INS_NOT_SUPPORTED,
94+
IronfishLedgerStatusCodes.TECHNICAL_PROBLEM,
9095
0xffff, // Unknown transport error
9196
0x6e01, // App not open
9297
].includes(error.returnCode)

0 commit comments

Comments
 (0)