Skip to content

Commit 6bd113c

Browse files
authored
Merge pull request #7 from Zondax/dev
New Release
2 parents b7c63eb + 280e2fc commit 6bd113c

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

src/consts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export const KEY_LENGTH = 32
1515
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
18+
export const TX_HASH_LEN = 32

src/deserialize.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { TX_HASH_LEN } from './consts'
2+
13
export const deserializeDkgRound1 = (data?: Buffer) => {
24
if (!data) throw new Error('unexpected empty data')
35

@@ -35,3 +37,14 @@ export const deserializeDkgRound2 = (data?: Buffer) => {
3537
publicPackage,
3638
}
3739
}
40+
41+
export const deserializeReviewTx = (data?: Buffer) => {
42+
if (!data) throw new Error('unexpected empty data')
43+
44+
// We expect a hash of 32 bytes
45+
const hash = data.subarray(0, TX_HASH_LEN)
46+
47+
return {
48+
hash,
49+
}
50+
}

src/index.ts

Lines changed: 20 additions & 1 deletion
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 } from './deserialize'
21+
import { deserializeDkgRound1, deserializeDkgRound2, deserializeReviewTx } from './deserialize'
2222
import { processGetIdentityResponse, processGetKeysResponse } from './helper'
2323
import { serializeDkgGetCommitments, serializeDkgRound1, serializeDkgRound2, serializeDkgRound3Min, serializeDkgSign } from './serialize'
2424
import {
@@ -32,6 +32,7 @@ import {
3232
ResponseDkgRound2,
3333
ResponseDkgSign,
3434
ResponseIdentity,
35+
ResponseReviewTransaction,
3536
ResponseSign,
3637
} from './types'
3738

@@ -63,6 +64,7 @@ export default class IronfishApp extends GenericApp {
6364
DKG_BACKUP_KEYS: 0x19,
6465
DKG_RESTORE_KEYS: 0x1a,
6566
GET_RESULT: 0x1b,
67+
REVIEW_TX: 0x1c,
6668
},
6769
p1Values: {
6870
ONLY_RETRIEVE: 0x00,
@@ -248,6 +250,23 @@ export default class IronfishApp extends GenericApp {
248250
}
249251
}
250252

253+
async reviewTransaction(tx: string): Promise<ResponseReviewTransaction> {
254+
try {
255+
const blob = Buffer.from(tx, 'hex')
256+
const chunks = this.prepareChunks(DUMMY_PATH, blob)
257+
258+
let rawResponse: any
259+
for (let i = 0; i < chunks.length; i += 1) {
260+
rawResponse = await this.sendGenericChunk(this.INS.REVIEW_TX, P2_VALUES.DEFAULT, 1 + i, chunks.length, chunks[i])
261+
}
262+
263+
let result = await this.getResult(rawResponse)
264+
return deserializeReviewTx(result)
265+
} catch (e) {
266+
throw processErrorResponse(e)
267+
}
268+
}
269+
251270
async getResult(rawResponse: ResponsePayload): Promise<Buffer> {
252271
let data = Buffer.alloc(0)
253272

src/serialize.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export const serializeDkgRound3Min = (
7373
2 +
7474
gskBytes.length * gskLen
7575
)
76+
console.log(`dkgRound3 msg size: ${blob.byteLength}`)
77+
7678
let pos = 0
7779

7880
// identity index

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface IronfishIns extends INSGeneric {
1515
DKG_BACKUP_KEYS: 0x19
1616
DKG_RESTORE_KEYS: 0x1a
1717
GET_RESULT: 0x1b
18+
REVIEW_TX: 0x1c
1819
}
1920

2021
export type KeyResponse = ResponseAddress | ResponseViewKey | ResponseProofGenKey
@@ -70,3 +71,6 @@ export interface ResponseDkgGetPublicPackage {
7071
export interface ResponseDkgBackupKeys {
7172
encryptedKeys: Buffer
7273
}
74+
export interface ResponseReviewTransaction {
75+
hash: Buffer
76+
}

0 commit comments

Comments
 (0)