@@ -15,6 +15,8 @@ import { ResponseError, Transport } from '@zondax/ledger-js'
15
15
export const IronfishLedgerStatusCodes = {
16
16
...StatusCodes ,
17
17
COMMAND_NOT_ALLOWED : 0x6986 ,
18
+ APP_NOT_OPEN : 0x6e01 ,
19
+ UNKNOWN_TRANSPORT_ERROR : 0xffff ,
18
20
}
19
21
20
22
export class Ledger {
@@ -35,61 +37,25 @@ export class Ledger {
35
37
36
38
Assert . isNotUndefined ( this . app , 'Unable to establish connection with Ledger device' )
37
39
38
- const app = this . app
39
-
40
- // App info is a request to the dashboard CLA. The purpose of this it to
41
- // produce a Locked Device error and works if an app is open or closed.
42
- try {
43
- await app . appInfo ( )
44
- } catch ( error ) {
45
- if (
46
- error instanceof ResponseError &&
47
- error . message . includes ( 'Attempt to read beyond buffer length' ) &&
48
- error . returnCode === IronfishLedgerStatusCodes . TECHNICAL_PROBLEM
49
- ) {
50
- // Catch this error and swollow it until the SDK fix merges to fix
51
- // this
52
- }
53
- }
54
-
55
- // This is an app specific request. This is useful because this throws
56
- // INS_NOT_SUPPORTED in the case that the app is locked which is useful to
57
- // know versus the device is locked.
58
- try {
59
- await app . getVersion ( )
60
- } catch ( error ) {
61
- if (
62
- error instanceof ResponseError &&
63
- error . returnCode === IronfishLedgerStatusCodes . INS_NOT_SUPPORTED
64
- ) {
65
- throw new LedgerAppLocked ( )
66
- }
40
+ return await instruction ( this . app )
41
+ } catch ( e : unknown ) {
42
+ let error = e
67
43
68
- throw error
69
- }
70
-
71
- return await instruction ( app )
72
- } catch ( error : unknown ) {
73
- if ( LedgerPortIsBusyError . IsError ( error ) ) {
44
+ if ( LedgerPortIsBusyError . IsError ( e ) ) {
74
45
throw new LedgerPortIsBusyError ( )
75
- } else if ( LedgerConnectError . IsError ( error ) ) {
46
+ } else if ( LedgerConnectError . IsError ( e ) ) {
76
47
throw new LedgerConnectError ( )
77
48
}
78
49
79
50
if ( error instanceof TransportStatusError ) {
80
- if (
81
- error . statusCode === IronfishLedgerStatusCodes . COMMAND_NOT_ALLOWED ||
82
- error . statusCode === IronfishLedgerStatusCodes . CONDITIONS_OF_USE_NOT_SATISFIED
83
- ) {
84
- throw new LedgerActionRejected ( )
85
- } else {
86
- throw new LedgerConnectError ( )
87
- }
51
+ error = new ResponseError ( error . statusCode , error . statusText )
88
52
}
89
53
90
54
if ( error instanceof ResponseError ) {
91
55
if ( error . returnCode === IronfishLedgerStatusCodes . LOCKED_DEVICE ) {
92
56
throw new LedgerDeviceLockedError ( )
57
+ } else if ( error . returnCode === IronfishLedgerStatusCodes . INS_NOT_SUPPORTED ) {
58
+ throw new LedgerAppLocked ( )
93
59
} else if ( error . returnCode === IronfishLedgerStatusCodes . CLA_NOT_SUPPORTED ) {
94
60
throw new LedgerClaNotSupportedError ( )
95
61
} else if ( error . returnCode === IronfishLedgerStatusCodes . GP_AUTH_FAILED ) {
@@ -103,15 +69,16 @@ export class Ledger {
103
69
throw new LedgerActionRejected ( )
104
70
} else if (
105
71
[
106
- IronfishLedgerStatusCodes . INS_NOT_SUPPORTED ,
107
72
IronfishLedgerStatusCodes . TECHNICAL_PROBLEM ,
108
- 0xffff , // Unknown transport error
109
- 0x6e01 , // App not open
73
+ IronfishLedgerStatusCodes . UNKNOWN_TRANSPORT_ERROR ,
74
+ IronfishLedgerStatusCodes . APP_NOT_OPEN ,
110
75
] . includes ( error . returnCode )
111
76
) {
112
77
throw new LedgerAppNotOpen (
113
78
`Unable to connect to Ironfish app on Ledger. Please check that the device is unlocked and the app is open.` ,
114
79
)
80
+ } else if ( e instanceof TransportStatusError ) {
81
+ throw new LedgerConnectError ( )
115
82
}
116
83
117
84
throw new LedgerError ( error . message )
0 commit comments