Skip to content

Commit db06728

Browse files
committed
feat: remove getnonces command, and adapt dkg sign
1 parent d32e96d commit db06728

File tree

2 files changed

+7
-83
lines changed

2 files changed

+7
-83
lines changed

src/index.ts

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,7 @@ import GenericApp, {
2727
import { P2_VALUES, REDJUBJUB_SIGNATURE_LEN } from './consts'
2828
import { deserializeDkgRound1, deserializeDkgRound2 } from './deserialize'
2929
import { processGetIdentityResponse, processGetKeysResponse } from './helper'
30-
import {
31-
serializeDkgGetCommitments,
32-
serializeDkgGetNonces,
33-
serializeDkgRound1,
34-
serializeDkgRound2,
35-
serializeDkgRound3,
36-
serializeDkgSign,
37-
} from './serialize'
30+
import { serializeDkgGetCommitments, serializeDkgRound1, serializeDkgRound2, serializeDkgRound3, serializeDkgSign } from './serialize'
3831
import {
3932
IronfishIns,
4033
IronfishKeys,
@@ -406,61 +399,8 @@ export default class IronfishApp extends GenericApp {
406399
}
407400
}
408401

409-
async dkgGetNonces(identities: string[], tx_hash: string): Promise<ResponseDkgGetNonces> {
410-
const blob = serializeDkgGetNonces(identities, tx_hash)
411-
const chunks = this.prepareChunks(DUMMY_PATH, blob)
412-
413-
try {
414-
let response = Buffer.alloc(0)
415-
let returnCode = 0
416-
let errorCodeData = Buffer.alloc(0)
417-
let errorMessage = ''
418-
try {
419-
response = await this.sendDkgChunk(this.INS.DKG_GET_NONCES, 1, chunks.length, chunks[0])
420-
// console.log("resp 0 " + response.toString("hex"))
421-
422-
errorCodeData = response.subarray(-2)
423-
returnCode = errorCodeData[0] * 256 + errorCodeData[1]
424-
errorMessage = errorCodeToString(returnCode)
425-
} catch (e) {
426-
// console.log(e)
427-
}
428-
429-
for (let i = 1; i < chunks.length; i += 1) {
430-
// eslint-disable-next-line no-await-in-loop
431-
response = await this.sendDkgChunk(this.INS.DKG_GET_NONCES, 1 + i, chunks.length, chunks[i])
432-
// console.log("resp " + i + " " + response.toString("hex"))
433-
434-
errorCodeData = response.subarray(-2)
435-
returnCode = errorCodeData[0] * 256 + errorCodeData[1]
436-
errorMessage = errorCodeToString(returnCode)
437-
438-
// console.log("returnCode " + returnCode)
439-
if (returnCode !== LedgerError.NoErrors) {
440-
return {
441-
returnCode,
442-
errorMessage,
443-
}
444-
}
445-
}
446-
447-
let { isError, responseResult, rawResponse } = this.checkResponseCode(response)
448-
if (isError) return responseResult
449-
450-
let result = await this.getResult(rawResponse)
451-
452-
return {
453-
returnCode: result.returnCode,
454-
errorMessage: result.errorMessage,
455-
nonces: result.data,
456-
}
457-
} catch (e) {
458-
return processErrorResponse(e)
459-
}
460-
}
461-
462-
async dkgSign(pkRandomness: string, frostSigningPackage: string, nonces: string): Promise<ResponseDkgSign> {
463-
const blob = serializeDkgSign(pkRandomness, frostSigningPackage, nonces)
402+
async dkgSign(pkRandomness: string, frostSigningPackage: string, txHash: string): Promise<ResponseDkgSign> {
403+
const blob = serializeDkgSign(pkRandomness, frostSigningPackage, txHash)
464404
const chunks = this.prepareChunks(DUMMY_PATH, blob)
465405

466406
try {

src/serialize.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,12 @@ export const serializeDkgGetCommitments = (identities: string[], tx_hash: string
7575
return blob
7676
}
7777

78-
export const serializeDkgGetNonces = (identities: string[], tx_hash: string): Buffer => {
79-
let blob = Buffer.alloc(1 + identities.length * 129 + 32)
80-
console.log(`dkgGetNonces msg size: ${blob.byteLength}`)
81-
82-
blob.writeUint8(identities.length, 0)
83-
84-
for (let i = 0; i < identities.length; i++) {
85-
blob.fill(Buffer.from(identities[i], 'hex'), 1 + i * 129)
86-
}
87-
88-
blob.fill(Buffer.from(tx_hash, 'hex'), 1 + identities.length * 129)
89-
return blob
90-
}
91-
92-
export const serializeDkgSign = (pkRandomness: string, frostSigningPackage: string, nonces: string): Buffer => {
78+
export const serializeDkgSign = (pkRandomness: string, frostSigningPackage: string, txHash: string): Buffer => {
9379
let pkRandomnessLen = pkRandomness.length / 2
9480
let frostSigningPackageLen = frostSigningPackage.length / 2
95-
let noncesLen = nonces.length / 2
81+
let txHashLen = 32
9682

97-
let blob = Buffer.alloc(2 + pkRandomnessLen + 2 + frostSigningPackageLen + 2 + noncesLen)
83+
let blob = Buffer.alloc(2 + pkRandomnessLen + 2 + frostSigningPackageLen + txHashLen)
9884
console.log(`dkgSign msg size: ${blob.byteLength}`)
9985

10086
let pos = 0
@@ -109,9 +95,7 @@ export const serializeDkgSign = (pkRandomness: string, frostSigningPackage: stri
10995
blob.fill(Buffer.from(frostSigningPackage, 'hex'), pos)
11096
pos += frostSigningPackageLen
11197

112-
blob.writeUint16BE(noncesLen, pos)
113-
pos += 2
114-
blob.fill(Buffer.from(nonces, 'hex'), pos)
98+
blob.fill(Buffer.from(txHash, 'hex'), pos)
11599

116100
return blob
117101
}

0 commit comments

Comments
 (0)