Skip to content

Commit a9857ea

Browse files
committed
feat: bump ledger-js package and implement it
1 parent 1dd2062 commit a9857ea

File tree

5 files changed

+126
-487
lines changed

5 files changed

+126
-487
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": "^0.2.1"
31+
"@zondax/ledger-js": "^1.0.1"
3232
},
3333
"devDependencies": {
3434
"@trivago/prettier-plugin-sort-imports": "^4.3.0",

src/deserialize.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const deserializeDkgRound1 = (data?: Buffer) => {
2-
if (!data) return {}
2+
if (!data) throw new Error('unexpected empty data')
33

44
let pos = 0
55
const secretPackageLen = data.readUint16BE(pos)
@@ -18,7 +18,7 @@ export const deserializeDkgRound1 = (data?: Buffer) => {
1818
}
1919

2020
export const deserializeDkgRound2 = (data?: Buffer) => {
21-
if (!data) return {}
21+
if (!data) throw new Error('unexpected empty data')
2222

2323
let pos = 0
2424
const secretPackageLen = data.readUint16BE(pos)

src/helper.ts

Lines changed: 14 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,43 @@
1-
import { errorCodeToString } from '@zondax/ledger-js'
1+
import { ResponsePayload } from '@zondax/ledger-js/dist/payload'
22

33
import { ED25519_SIGNATURE_LEN, IDENTITY_LEN, KEY_LENGTH, REDJUBJUB_SIGNATURE_LEN, VERSION } from './consts'
44
import { IronfishKeys, KeyResponse, ResponseIdentity } from './types'
55

6-
export function processGetKeysResponse(response: Buffer, keyType: IronfishKeys): KeyResponse {
7-
const errorCodeData = response.subarray(-2)
8-
const returnCode = errorCodeData[0] * 256 + errorCodeData[1]
9-
10-
let requestedKey: KeyResponse = {
11-
returnCode: returnCode,
12-
errorMessage: errorCodeToString(returnCode),
13-
}
14-
6+
export function processGetKeysResponse(response: ResponsePayload, keyType: IronfishKeys): KeyResponse {
157
switch (keyType) {
168
case IronfishKeys.PublicAddress: {
17-
const publicAddress = Buffer.from(response.subarray(0, KEY_LENGTH))
18-
requestedKey = {
19-
...requestedKey,
9+
const publicAddress = response.readBytes(KEY_LENGTH)
10+
return {
2011
publicAddress,
2112
}
22-
break
2313
}
2414

2515
case IronfishKeys.ViewKey: {
26-
const viewKey = Buffer.from(response.subarray(0, 2 * KEY_LENGTH))
27-
response = response.subarray(2 * KEY_LENGTH)
16+
const viewKey = response.readBytes(2 * KEY_LENGTH)
17+
const ivk = response.readBytes(KEY_LENGTH)
18+
const ovk = response.readBytes(KEY_LENGTH)
2819

29-
const ivk = Buffer.from(response.subarray(0, KEY_LENGTH))
30-
response = response.subarray(KEY_LENGTH)
31-
32-
const ovk = Buffer.from(response.subarray(0, KEY_LENGTH))
33-
response = response.subarray(KEY_LENGTH)
34-
35-
requestedKey = {
36-
...requestedKey,
20+
return {
3721
viewKey,
3822
ivk,
3923
ovk,
4024
}
41-
break
4225
}
4326

4427
case IronfishKeys.ProofGenerationKey: {
45-
const ak = Buffer.from(response.subarray(0, KEY_LENGTH))
46-
response = response.subarray(KEY_LENGTH)
47-
48-
const nsk = Buffer.from(response.subarray(0, KEY_LENGTH))
49-
response = response.subarray(KEY_LENGTH)
28+
const ak = response.readBytes(KEY_LENGTH)
29+
const nsk = response.readBytes(KEY_LENGTH)
5030

51-
requestedKey = {
52-
...requestedKey,
31+
return {
5332
ak,
5433
nsk,
5534
}
56-
break
5735
}
5836
}
59-
60-
return requestedKey
6137
}
6238

63-
export function processGetIdentityResponse(response: Buffer): ResponseIdentity {
64-
const errorCodeData = response.subarray(-2)
65-
const returnCode = errorCodeData[0] * 256 + errorCodeData[1]
66-
67-
let getIdentityResponse: ResponseIdentity = {
68-
returnCode: returnCode,
69-
errorMessage: errorCodeToString(returnCode),
70-
}
71-
72-
const identity = Buffer.from(response.subarray(0, IDENTITY_LEN))
73-
74-
getIdentityResponse = {
75-
...getIdentityResponse,
76-
identity,
77-
}
39+
export function processGetIdentityResponse(response: ResponsePayload): ResponseIdentity {
40+
const identity = response.readBytes(IDENTITY_LEN)
7841

79-
return getIdentityResponse
42+
return { identity }
8043
}

0 commit comments

Comments
 (0)