Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Release #7

Merged
merged 2 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export const KEY_LENGTH = 32
export const REDJUBJUB_SIGNATURE_LEN = 64
export const ED25519_SIGNATURE_LEN = 64
export const IDENTITY_LEN = VERSION + KEY_LENGTH + KEY_LENGTH + ED25519_SIGNATURE_LEN
export const TX_HASH_LEN = 32
13 changes: 13 additions & 0 deletions src/deserialize.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TX_HASH_LEN } from './consts'

export const deserializeDkgRound1 = (data?: Buffer) => {
if (!data) throw new Error('unexpected empty data')

Expand Down Expand Up @@ -35,3 +37,14 @@ export const deserializeDkgRound2 = (data?: Buffer) => {
publicPackage,
}
}

export const deserializeReviewTx = (data?: Buffer) => {
if (!data) throw new Error('unexpected empty data')

// We expect a hash of 32 bytes
const hash = data.subarray(0, TX_HASH_LEN)

return {
hash,
}
}
21 changes: 20 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import GenericApp, { ConstructorParams, LedgerError, Transport, processErrorResp
import { ResponsePayload } from '@zondax/ledger-js/dist/payload'

import { P2_VALUES } from './consts'
import { deserializeDkgRound1, deserializeDkgRound2 } from './deserialize'
import { deserializeDkgRound1, deserializeDkgRound2, deserializeReviewTx } from './deserialize'
import { processGetIdentityResponse, processGetKeysResponse } from './helper'
import { serializeDkgGetCommitments, serializeDkgRound1, serializeDkgRound2, serializeDkgRound3Min, serializeDkgSign } from './serialize'
import {
Expand All @@ -32,6 +32,7 @@ import {
ResponseDkgRound2,
ResponseDkgSign,
ResponseIdentity,
ResponseReviewTransaction,
ResponseSign,
} from './types'

Expand Down Expand Up @@ -63,6 +64,7 @@ export default class IronfishApp extends GenericApp {
DKG_BACKUP_KEYS: 0x19,
DKG_RESTORE_KEYS: 0x1a,
GET_RESULT: 0x1b,
REVIEW_TX: 0x1c,
},
p1Values: {
ONLY_RETRIEVE: 0x00,
Expand Down Expand Up @@ -248,6 +250,23 @@ export default class IronfishApp extends GenericApp {
}
}

async reviewTransaction(tx: string): Promise<ResponseReviewTransaction> {
try {
const blob = Buffer.from(tx, 'hex')
const chunks = this.prepareChunks(DUMMY_PATH, blob)

let rawResponse: any
for (let i = 0; i < chunks.length; i += 1) {
rawResponse = await this.sendGenericChunk(this.INS.REVIEW_TX, P2_VALUES.DEFAULT, 1 + i, chunks.length, chunks[i])
}

let result = await this.getResult(rawResponse)
return deserializeReviewTx(result)
} catch (e) {
throw processErrorResponse(e)
}
}

async getResult(rawResponse: ResponsePayload): Promise<Buffer> {
let data = Buffer.alloc(0)

Expand Down
2 changes: 2 additions & 0 deletions src/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export const serializeDkgRound3Min = (
2 +
gskBytes.length * gskLen
)
console.log(`dkgRound3 msg size: ${blob.byteLength}`)

let pos = 0

// identity index
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface IronfishIns extends INSGeneric {
DKG_BACKUP_KEYS: 0x19
DKG_RESTORE_KEYS: 0x1a
GET_RESULT: 0x1b
REVIEW_TX: 0x1c
}

export type KeyResponse = ResponseAddress | ResponseViewKey | ResponseProofGenKey
Expand Down Expand Up @@ -70,3 +71,6 @@ export interface ResponseDkgGetPublicPackage {
export interface ResponseDkgBackupKeys {
encryptedKeys: Buffer
}
export interface ResponseReviewTransaction {
hash: Buffer
}