Skip to content

Commit

Permalink
implements ledger dkg round1
Browse files Browse the repository at this point in the history
adds dkgRound1 method to Ledger util

fills in logic of performRound1WithLedger

reads identity from node and adds it to list of signer identities if it's
missing
  • Loading branch information
hughy committed Sep 19, 2024
1 parent 33c2b8e commit 3c60c8b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
33 changes: 30 additions & 3 deletions ironfish-cli/src/commands/wallet/multisig/dkg/round1.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { RpcClient } from '@ironfish/sdk'
import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../../command'
import { RemoteFlags } from '../../../../flags'
Expand Down Expand Up @@ -71,7 +72,7 @@ export class DkgRound1Command extends IronfishCommand {
}

if (flags.ledger) {
await this.performRound1WithLedger()
await this.performRound1WithLedger(client, participantName, identities, minSigners)
return
}

Expand All @@ -93,16 +94,42 @@ export class DkgRound1Command extends IronfishCommand {
this.log('Send the round 1 public package to each participant')
}

async performRound1WithLedger(): Promise<void> {
async performRound1WithLedger(
client: RpcClient,
participantName: string,
identities: string[],
minSigners: number,
): Promise<void> {
const ledger = new Ledger(this.logger)
try {
await ledger.connect()
await ledger.connect(true)
} catch (e) {
if (e instanceof Error) {
this.error(e.message)
} else {
throw e
}
}

const identityResponse = await client.wallet.multisig.getIdentity({ name: participantName })
const identity = identityResponse.content.identity

if (!identities.includes(identity)) {
identities.push(identity)
}

// TODO(hughy): determine how to handle multiple identities using index
const { publicPackage, secretPackage } = await ledger.dkgRound1(0, identities, minSigners)

this.log('\nRound 1 Encrypted Secret Package:\n')
this.log(secretPackage.toString('hex'))
this.log()

this.log('\nRound 1 Public Package:\n')
this.log(publicPackage.toString('hex'))
this.log()

this.log('Next step:')
this.log('Send the round 1 public package to each participant')
}
}
15 changes: 15 additions & 0 deletions ironfish-cli/src/utils/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import IronfishApp, {
IronfishKeys,
KeyResponse,
ResponseAddress,
ResponseDkgRound1,
ResponseIdentity,
ResponseProofGenKey,
ResponseSign,
Expand Down Expand Up @@ -168,6 +169,20 @@ export class Ledger {

return response.identity
}

dkgRound1 = async (
index: number,
identities: string[],
minSigners: number,
): Promise<ResponseDkgRound1> => {
if (!this.app) {
throw new Error('Connect to Ledger first')
}

this.logger.log('Please approve the request on your ledger device.')

return this.tryInstruction(this.app.dkgRound1(index, identities, minSigners))
}
}

function isResponseAddress(response: KeyResponse): response is ResponseAddress {
Expand Down

0 comments on commit 3c60c8b

Please sign in to comment.