Skip to content

Commit aa4676b

Browse files
committed
feat: add method to get identities involved on the dkg generated process
1 parent aabdab6 commit aa4676b

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/deserialize.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TX_HASH_LEN } from './consts'
1+
import { IDENTITY_LEN, TX_HASH_LEN } from './consts'
22

33
export const deserializeDkgRound1 = (data?: Buffer) => {
44
if (!data) throw new Error('unexpected empty data')
@@ -38,6 +38,20 @@ export const deserializeDkgRound2 = (data?: Buffer) => {
3838
}
3939
}
4040

41+
export const deserializeGetIdentities = (data?: Buffer) => {
42+
if (!data) throw new Error('unexpected empty data')
43+
44+
const identities: Buffer[] = []
45+
const elements = data.length / IDENTITY_LEN
46+
for (let i = 0; i < elements; i++) {
47+
identities.push(data.subarray(i * IDENTITY_LEN, IDENTITY_LEN + i * IDENTITY_LEN))
48+
}
49+
50+
return {
51+
identities,
52+
}
53+
}
54+
4155
export const deserializeReviewTx = (data?: Buffer) => {
4256
if (!data) throw new Error('unexpected empty data')
4357

src/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import GenericApp, { ConstructorParams, LedgerError, Transport, processErrorResp
1818
import { ResponsePayload } from '@zondax/ledger-js/dist/payload'
1919

2020
import { P2_VALUES } from './consts'
21-
import { deserializeDkgRound1, deserializeDkgRound2, deserializeReviewTx } from './deserialize'
21+
import { deserializeDkgRound1, deserializeDkgRound2, deserializeGetIdentities, deserializeReviewTx } from './deserialize'
2222
import { processGetIdentityResponse, processGetKeysResponse } from './helper'
2323
import { serializeDkgGetCommitments, serializeDkgRound1, serializeDkgRound2, serializeDkgRound3Min, serializeDkgSign } from './serialize'
2424
import {
@@ -31,6 +31,7 @@ import {
3131
ResponseDkgRound1,
3232
ResponseDkgRound2,
3333
ResponseDkgSign,
34+
ResponseIdentities,
3435
ResponseIdentity,
3536
ResponseReviewTransaction,
3637
ResponseSign,
@@ -59,7 +60,7 @@ export default class IronfishApp extends GenericApp {
5960
DKG_GET_COMMITMENTS: 0x14,
6061
DKG_SIGN: 0x15,
6162
DKG_GET_KEYS: 0x16,
62-
DKG_GET_NONCES: 0x17,
63+
DKG_IDENTITIES: 0x17,
6364
DKG_GET_PUBLIC_PACKAGE: 0x18,
6465
DKG_BACKUP_KEYS: 0x19,
6566
DKG_RESTORE_KEYS: 0x1a,
@@ -233,6 +234,19 @@ export default class IronfishApp extends GenericApp {
233234
throw processErrorResponse(e)
234235
}
235236
}
237+
238+
async dkgGetIdentities(): Promise<ResponseIdentities> {
239+
try {
240+
let response = await this.transport.send(this.CLA, this.INS.DKG_IDENTITIES, 0, 0, Buffer.alloc(0), [LedgerError.NoErrors])
241+
let data = processResponse(response)
242+
243+
let result = await this.getResult(data)
244+
return deserializeGetIdentities(result)
245+
} catch (e) {
246+
throw processErrorResponse(e)
247+
}
248+
}
249+
236250
async dkgRetrieveKeys(keyType: IronfishKeys, showInDevice?: boolean): Promise<KeyResponse> {
237251
const p1 = showInDevice ? 1 : 0
238252
const response = await this.transport.send(this.CLA, this.INS.DKG_GET_KEYS, p1, keyType, Buffer.alloc(0), [LedgerError.NoErrors])

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface IronfishIns extends INSGeneric {
1111
DKG_GET_COMMITMENTS: 0x14
1212
DKG_SIGN: 0x15
1313
DKG_GET_KEYS: 0x16
14+
DKG_IDENTITIES: 0x17
1415
DKG_GET_PUBLIC_PACKAGE: 0x18
1516
DKG_BACKUP_KEYS: 0x19
1617
DKG_RESTORE_KEYS: 0x1a
@@ -75,3 +76,7 @@ export interface ResponseDkgBackupKeys {
7576
export interface ResponseReviewTransaction {
7677
hash: Buffer
7778
}
79+
80+
export interface ResponseIdentities {
81+
identities: Buffer[]
82+
}

0 commit comments

Comments
 (0)