Skip to content

Commit 7099c26

Browse files
authored
Merge pull request #23 from Zondax/dev
New Release
2 parents 4b09307 + 50f5f1b commit 7099c26

File tree

3 files changed

+85
-20
lines changed

3 files changed

+85
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"url": "https://github.com/zondax/ledger-ironfish-js/issues"
2929
},
3030
"dependencies": {
31-
"@zondax/ledger-js": "^1.0.1"
31+
"@zondax/ledger-js": "^1.2.0"
3232
},
3333
"devDependencies": {
3434
"@trivago/prettier-plugin-sort-imports": "^4.3.0",

src/consts.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,67 @@ export const REDJUBJUB_SIGNATURE_LEN = 64
1616
export const ED25519_SIGNATURE_LEN = 64
1717
export const IDENTITY_LEN = VERSION + KEY_LENGTH + KEY_LENGTH + ED25519_SIGNATURE_LEN
1818
export const TX_HASH_LEN = 32
19+
20+
export enum LedgerAppError {
21+
AddrDisplayFail = 0xb002,
22+
TxWrongLength = 0xb004,
23+
TxParsingFail = 0xb005,
24+
TxSignFail = 0xb008,
25+
KeyDeriveFail = 0xb009,
26+
VersionParsingFail = 0xb00a,
27+
DkgRound2Fail = 0xb00b,
28+
DkgRound3Fail = 0xb00c,
29+
InvalidKeyType = 0xb00d,
30+
InvalidIdentity = 0xb00e,
31+
InvalidPayload = 0xb00f,
32+
BufferOutOfBounds = 0xb010,
33+
InvalidSigningPackage = 0xb011,
34+
InvalidRandomizer = 0xb012,
35+
InvalidSigningNonces = 0xb013,
36+
InvalidIdentityIndex = 0xb014,
37+
InvalidKeyPackage = 0xb015,
38+
InvalidPublicPackage = 0xb016,
39+
InvalidGroupSecretKey = 0xb017,
40+
InvalidScalar = 0xb018,
41+
DecryptionFail = 0xb019,
42+
EncryptionFail = 0xb020,
43+
InvalidNVMWrite = 0xb021,
44+
InvalidDkgStatus = 0xb022,
45+
InvalidDkgKeysVersion = 0xb023,
46+
TooManyParticipants = 0xb024,
47+
InvalidTxHash = 0xb025,
48+
InvalidToken = 0xb026,
49+
ErrExpertModeMustBeEnabled = 0xb027,
50+
}
51+
52+
export const ERROR_DESCRIPTION_OVERRIDE: Readonly<Record<LedgerAppError, string>> = {
53+
[LedgerAppError.AddrDisplayFail]: 'Invalid address',
54+
[LedgerAppError.TxWrongLength]: 'Tx too long',
55+
[LedgerAppError.TxParsingFail]: 'Tx parsing failed',
56+
[LedgerAppError.TxSignFail]: 'Tx signing failed',
57+
[LedgerAppError.KeyDeriveFail]: 'Invalid signing key',
58+
[LedgerAppError.VersionParsingFail]: 'Invalid tx version',
59+
[LedgerAppError.DkgRound2Fail]: 'Round 2 has failed',
60+
[LedgerAppError.DkgRound3Fail]: 'Round 3 has failed',
61+
[LedgerAppError.InvalidKeyType]: 'Invalid key type',
62+
[LedgerAppError.InvalidIdentity]: 'Invalid identity',
63+
[LedgerAppError.InvalidPayload]: 'Invalid payload',
64+
[LedgerAppError.BufferOutOfBounds]: 'Buffer out of bounds',
65+
[LedgerAppError.InvalidSigningPackage]: 'Invalid signing package',
66+
[LedgerAppError.InvalidRandomizer]: 'Invalid tx randomizer',
67+
[LedgerAppError.InvalidSigningNonces]: 'Invalid signing nonces',
68+
[LedgerAppError.InvalidIdentityIndex]: 'Invalid identity index',
69+
[LedgerAppError.InvalidKeyPackage]: 'Invalid key package',
70+
[LedgerAppError.InvalidPublicPackage]: 'Invalid public package',
71+
[LedgerAppError.InvalidGroupSecretKey]: 'Invalid group secret key',
72+
[LedgerAppError.InvalidScalar]: 'Invalid scalar',
73+
[LedgerAppError.DecryptionFail]: 'Keys decryption failed',
74+
[LedgerAppError.EncryptionFail]: 'Keys encryption failed',
75+
[LedgerAppError.InvalidNVMWrite]: 'Invalid flash write',
76+
[LedgerAppError.InvalidDkgStatus]: 'Invalid dkg process status',
77+
[LedgerAppError.InvalidDkgKeysVersion]: 'Invalid keys version',
78+
[LedgerAppError.TooManyParticipants]: 'Too many participants for DKG',
79+
[LedgerAppError.InvalidTxHash]: 'Invalid tx hash',
80+
[LedgerAppError.InvalidToken]: 'Invalid asset',
81+
[LedgerAppError.ErrExpertModeMustBeEnabled]: 'Expert mode is required',
82+
}

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)