Skip to content

Commit b7c63eb

Browse files
authored
Merge pull request #10 from Zondax/feat/dkg
New Release
2 parents ca8fbc2 + a9857ea commit b7c63eb

File tree

9 files changed

+508
-136
lines changed

9 files changed

+508
-136
lines changed

README-npm.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Use `yarn install` to avoid issues.
1111

1212
# Available commands
1313

14-
| Operation | Response | Command |
15-
|--------------|------------------------------------------|-------------------------------|
16-
| getVersion | app version | --------------- |
17-
| appInfo | name, version, flags, etc | --------------- |
18-
| deviceInfo | fw and mcu version, id, etc | Only available in dashboard |
19-
| sign | signed message | path + message |
20-
| retrieveKeys | address or view key or proof gen key | path + key type + verify flag |
14+
| Operation | Response | Command |
15+
| ------------ | ------------------------------------ | ----------------------------- |
16+
| getVersion | app version | --------------- |
17+
| appInfo | name, version, flags, etc | --------------- |
18+
| deviceInfo | fw and mcu version, id, etc | Only available in dashboard |
19+
| sign | signed message | path + message |
20+
| retrieveKeys | address or view key or proof gen key | path + key type + verify flag |
2121

2222
# Who we are?
2323

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Use `yarn install` to avoid issues.
1111

1212
# Available commands
1313

14-
| Operation | Response | Command |
15-
|--------------|------------------------------------------|-------------------------------|
16-
| getVersion | app version | --------------- |
17-
| appInfo | name, version, flags, etc | --------------- |
18-
| deviceInfo | fw and mcu version, id, etc | Only available in dashboard |
19-
| sign | signed message | path + message |
20-
| retrieveKeys | address or view key or proof gen key | path + key type + verify flag |
14+
| Operation | Response | Command |
15+
| ------------ | ------------------------------------ | ----------------------------- |
16+
| getVersion | app version | --------------- |
17+
| appInfo | name, version, flags, etc | --------------- |
18+
| deviceInfo | fw and mcu version, id, etc | Only available in dashboard |
19+
| sign | signed message | path + message |
20+
| retrieveKeys | address or view key or proof gen key | path + key type + verify flag |
2121

2222
# Who we are?
2323

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/consts.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ export const KEY_TYPES = {
1010
PROOF_GEN_KEY: 0x02,
1111
}
1212

13+
export const VERSION = 1
1314
export const KEY_LENGTH = 32
1415
export const REDJUBJUB_SIGNATURE_LEN = 64
16+
export const ED25519_SIGNATURE_LEN = 64
17+
export const IDENTITY_LEN = VERSION + KEY_LENGTH + KEY_LENGTH + ED25519_SIGNATURE_LEN

src/deserialize.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export const deserializeDkgRound1 = (data?: Buffer) => {
2+
if (!data) throw new Error('unexpected empty data')
3+
4+
let pos = 0
5+
const secretPackageLen = data.readUint16BE(pos)
6+
pos += 2
7+
const secretPackage = data.subarray(pos, pos + secretPackageLen)
8+
pos += secretPackageLen
9+
const publicPackageLen = data.readUint16BE(pos)
10+
pos += 2
11+
const publicPackage = data.subarray(pos, pos + publicPackageLen)
12+
pos += publicPackageLen
13+
14+
return {
15+
secretPackage,
16+
publicPackage,
17+
}
18+
}
19+
20+
export const deserializeDkgRound2 = (data?: Buffer) => {
21+
if (!data) throw new Error('unexpected empty data')
22+
23+
let pos = 0
24+
const secretPackageLen = data.readUint16BE(pos)
25+
pos += 2
26+
const secretPackage = data.subarray(pos, pos + secretPackageLen)
27+
pos += secretPackageLen
28+
const publicPackageLen = data.readUint16BE(pos)
29+
pos += 2
30+
const publicPackage = data.subarray(pos, pos + publicPackageLen)
31+
pos += publicPackageLen
32+
33+
return {
34+
secretPackage,
35+
publicPackage,
36+
}
37+
}

src/helper.ts

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

3-
import { KEY_LENGTH } from './consts'
4-
import { IronfishKeys, KeyResponse } from './types'
5-
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-
}
3+
import { ED25519_SIGNATURE_LEN, IDENTITY_LEN, KEY_LENGTH, REDJUBJUB_SIGNATURE_LEN, VERSION } from './consts'
4+
import { IronfishKeys, KeyResponse, ResponseIdentity } from './types'
145

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)
28-
29-
const ivk = Buffer.from(response.subarray(0, KEY_LENGTH))
30-
response = response.subarray(KEY_LENGTH)
16+
const viewKey = response.readBytes(2 * KEY_LENGTH)
17+
const ivk = response.readBytes(KEY_LENGTH)
18+
const ovk = response.readBytes(KEY_LENGTH)
3119

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
}
37+
}
38+
39+
export function processGetIdentityResponse(response: ResponsePayload): ResponseIdentity {
40+
const identity = response.readBytes(IDENTITY_LEN)
5941

60-
return requestedKey
42+
return { identity }
6143
}

0 commit comments

Comments
 (0)