Skip to content

Commit e2efe00

Browse files
committed
feat: use custom error descriptions
1 parent 3ed3227 commit e2efe00

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/index.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import GenericApp, { ConstructorParams, LedgerError, Transport, processErrorResponse, processResponse } from '@zondax/ledger-js'
1818
import { ResponsePayload } from '@zondax/ledger-js/dist/payload'
1919

20-
import { P2_VALUES } from './consts'
20+
import { ERROR_DESCRIPTION_OVERRIDE, P2_VALUES } from './consts'
2121
import { deserializeDkgRound1, deserializeDkgRound2, deserializeGetIdentities, deserializeReviewTx } from './deserialize'
2222
import { processGetIdentityResponse, processGetKeysResponse } from './helper'
2323
import { serializeDkgGetCommitments, serializeDkgRound1, serializeDkgRound2, serializeDkgRound3Min, serializeDkgSign } from './serialize'
@@ -78,6 +78,7 @@ export default class IronfishApp extends GenericApp {
7878
},
7979
acceptedPathLengths: [3],
8080
chunkSize: 250,
81+
customAppErrorDescription: ERROR_DESCRIPTION_OVERRIDE,
8182
}
8283
super(transport, params)
8384
}
@@ -87,7 +88,7 @@ export default class IronfishApp extends GenericApp {
8788
const p1 = showInDevice ? this.P1_VALUES.SHOW_ADDRESS_IN_DEVICE : this.P1_VALUES.ONLY_RETRIEVE
8889

8990
const response = await this.transport.send(this.CLA, this.INS.GET_KEYS, p1, keyType, serializedPath, [LedgerError.NoErrors])
90-
const payload = processResponse(response)
91+
const payload = processResponse(response, this.CUSTOM_APP_ERROR_DESCRIPTION)
9192
return processGetKeysResponse(payload, keyType)
9293
}
9394

@@ -103,7 +104,7 @@ export default class IronfishApp extends GenericApp {
103104
signature: result.readBytes(result.length()),
104105
}
105106
} catch (e) {
106-
throw processErrorResponse(e)
107+
throw processErrorResponse(e, this.CUSTOM_APP_ERROR_DESCRIPTION)
107108
}
108109
}
109110

@@ -113,7 +114,7 @@ export default class IronfishApp extends GenericApp {
113114

114115
const p1 = showInDevice ? 1 : 0
115116
const response = await this.transport.send(this.CLA, this.INS.DKG_IDENTITY, p1, 0, req, [LedgerError.NoErrors])
116-
const data = processResponse(response)
117+
const data = processResponse(response, this.CUSTOM_APP_ERROR_DESCRIPTION)
117118
return processGetIdentityResponse(data)
118119
}
119120

@@ -130,7 +131,7 @@ export default class IronfishApp extends GenericApp {
130131
let result = await this.getResult(rawResponse)
131132
return deserializeDkgRound1(result)
132133
} catch (e) {
133-
throw processErrorResponse(e)
134+
throw processErrorResponse(e, this.CUSTOM_APP_ERROR_DESCRIPTION)
134135
}
135136
}
136137

@@ -147,7 +148,7 @@ export default class IronfishApp extends GenericApp {
147148
let result = await this.getResult(rawResponse)
148149
return deserializeDkgRound2(result)
149150
} catch (e) {
150-
throw processErrorResponse(e)
151+
throw processErrorResponse(e, this.CUSTOM_APP_ERROR_DESCRIPTION)
151152
}
152153
}
153154

@@ -167,7 +168,7 @@ export default class IronfishApp extends GenericApp {
167168
await this.sendGenericChunk(this.INS.DKG_ROUND_3_MIN, P2_VALUES.DEFAULT, 1 + i, chunks.length, chunks[i])
168169
}
169170
} catch (e) {
170-
throw processErrorResponse(e)
171+
throw processErrorResponse(e, this.CUSTOM_APP_ERROR_DESCRIPTION)
171172
}
172173
}
173174

@@ -186,7 +187,7 @@ export default class IronfishApp extends GenericApp {
186187
commitments: result,
187188
}
188189
} catch (e) {
189-
throw processErrorResponse(e)
190+
throw processErrorResponse(e, this.CUSTOM_APP_ERROR_DESCRIPTION)
190191
}
191192
}
192193

@@ -205,56 +206,56 @@ export default class IronfishApp extends GenericApp {
205206
signature: result,
206207
}
207208
} catch (e) {
208-
throw processErrorResponse(e)
209+
throw processErrorResponse(e, this.CUSTOM_APP_ERROR_DESCRIPTION)
209210
}
210211
}
211212

212213
async dkgGetPublicPackage(): Promise<ResponseDkgGetPublicPackage> {
213214
try {
214215
let response = await this.transport.send(this.CLA, this.INS.DKG_GET_PUBLIC_PACKAGE, 0, 0, Buffer.alloc(0), [LedgerError.NoErrors])
215-
let data = processResponse(response)
216+
let data = processResponse(response, this.CUSTOM_APP_ERROR_DESCRIPTION)
216217

217218
let result = await this.getResult(data)
218219

219220
return {
220221
publicPackage: result,
221222
}
222223
} catch (e) {
223-
throw processErrorResponse(e)
224+
throw processErrorResponse(e, this.CUSTOM_APP_ERROR_DESCRIPTION)
224225
}
225226
}
226227

227228
async dkgBackupKeys(): Promise<ResponseDkgBackupKeys> {
228229
try {
229230
let response = await this.transport.send(this.CLA, this.INS.DKG_BACKUP_KEYS, 0, 0, Buffer.alloc(0), [LedgerError.NoErrors])
230-
let data = processResponse(response)
231+
let data = processResponse(response, this.CUSTOM_APP_ERROR_DESCRIPTION)
231232

232233
let result = await this.getResult(data)
233234

234235
return {
235236
encryptedKeys: result,
236237
}
237238
} catch (e) {
238-
throw processErrorResponse(e)
239+
throw processErrorResponse(e, this.CUSTOM_APP_ERROR_DESCRIPTION)
239240
}
240241
}
241242

242243
async dkgGetIdentities(): Promise<ResponseIdentities> {
243244
try {
244245
let response = await this.transport.send(this.CLA, this.INS.DKG_IDENTITIES, 0, 0, Buffer.alloc(0), [LedgerError.NoErrors])
245-
let data = processResponse(response)
246+
let data = processResponse(response, this.CUSTOM_APP_ERROR_DESCRIPTION)
246247

247248
let result = await this.getResult(data)
248249
return deserializeGetIdentities(result)
249250
} catch (e) {
250-
throw processErrorResponse(e)
251+
throw processErrorResponse(e, this.CUSTOM_APP_ERROR_DESCRIPTION)
251252
}
252253
}
253254

254255
async dkgRetrieveKeys(keyType: IronfishKeys, showInDevice?: boolean): Promise<KeyResponse> {
255256
const p1 = showInDevice ? 1 : 0
256257
const response = await this.transport.send(this.CLA, this.INS.DKG_GET_KEYS, p1, keyType, Buffer.alloc(0), [LedgerError.NoErrors])
257-
const data = processResponse(response)
258+
const data = processResponse(response, this.CUSTOM_APP_ERROR_DESCRIPTION)
258259
return processGetKeysResponse(data, keyType)
259260
}
260261

@@ -266,7 +267,7 @@ export default class IronfishApp extends GenericApp {
266267
await this.sendGenericChunk(this.INS.DKG_RESTORE_KEYS, P2_VALUES.DEFAULT, 1 + i, chunks.length, chunks[i])
267268
}
268269
} catch (e) {
269-
throw processErrorResponse(e)
270+
throw processErrorResponse(e, this.CUSTOM_APP_ERROR_DESCRIPTION)
270271
}
271272
}
272273

@@ -283,7 +284,7 @@ export default class IronfishApp extends GenericApp {
283284
let result = await this.getResult(rawResponse)
284285
return deserializeReviewTx(result)
285286
} catch (e) {
286-
throw processErrorResponse(e)
287+
throw processErrorResponse(e, this.CUSTOM_APP_ERROR_DESCRIPTION)
287288
}
288289
}
289290

@@ -293,7 +294,7 @@ export default class IronfishApp extends GenericApp {
293294
let chunks = rawResponse.readBytes(1).readUint8()
294295
for (let i = 0; i < chunks; i++) {
295296
let result = await this.transport.send(this.CLA, this.INS.GET_RESULT, i, 0, Buffer.alloc(0))
296-
let response = processResponse(result)
297+
let response = processResponse(result, this.CUSTOM_APP_ERROR_DESCRIPTION)
297298
data = Buffer.concat([data, response.getCompleteBuffer()])
298299
}
299300

0 commit comments

Comments
 (0)