Skip to content

Commit

Permalink
Add ledger flag to dkg rounds (#5380)
Browse files Browse the repository at this point in the history
In preparation for adding ledger support to the DKG rounds, this commit adds a `--ledger` flag to the `dkg round1`, `dkg round2`, and `dkg round3` commands.
This flag will be used to specify that the user wants to use a Ledger device to perform DKG operations
  • Loading branch information
patnir authored Sep 17, 2024
1 parent 062657b commit 9263726
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ironfish-cli/src/commands/wallet/multisig/dkg/round1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../../command'
import { RemoteFlags } from '../../../../flags'
import * as ui from '../../../../ui'
import { Ledger } from '../../../../utils/ledger'

export class DkgRound1Command extends IronfishCommand {
static description = 'Perform round1 of the DKG protocol for multisig account creation'
Expand All @@ -26,6 +27,11 @@ export class DkgRound1Command extends IronfishCommand {
char: 'm',
description: 'Minimum number of signers to meet signing threshold',
}),
ledger: Flags.boolean({
default: false,
description: 'Perform operation with a ledger device',
hidden: true,
}),
}

async start(): Promise<void> {
Expand Down Expand Up @@ -64,6 +70,11 @@ export class DkgRound1Command extends IronfishCommand {
}
}

if (flags.ledger) {
await this.performRound1WithLedger()
return
}

const response = await client.wallet.multisig.dkg.round1({
participantName,
participants: identities.map((identity) => ({ identity })),
Expand All @@ -81,4 +92,17 @@ export class DkgRound1Command extends IronfishCommand {
this.log('Next step:')
this.log('Send the round 1 public package to each participant')
}

async performRound1WithLedger(): Promise<void> {
const ledger = new Ledger(this.logger)
try {
await ledger.connect()
} catch (e) {
if (e instanceof Error) {
this.error(e.message)
} else {
throw e
}
}
}
}
24 changes: 24 additions & 0 deletions ironfish-cli/src/commands/wallet/multisig/dkg/round2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../../command'
import { RemoteFlags } from '../../../../flags'
import * as ui from '../../../../ui'
import { Ledger } from '../../../../utils/ledger'

export class DkgRound2Command extends IronfishCommand {
static description = 'Perform round2 of the DKG protocol for multisig account creation'
Expand All @@ -26,6 +27,11 @@ export class DkgRound2Command extends IronfishCommand {
'The public packages that each participant generated during DKG round 1 (may be specified multiple times for multiple participants). Must include your own round 1 public package',
multiple: true,
}),
ledger: Flags.boolean({
default: false,
description: 'Perform operation with a ledger device',
hidden: true,
}),
}

async start(): Promise<void> {
Expand Down Expand Up @@ -63,6 +69,11 @@ export class DkgRound2Command extends IronfishCommand {
}
round1PublicPackages = round1PublicPackages.map((i) => i.trim())

if (flags.ledger) {
await this.performRound2WithLedger()
return
}

const response = await client.wallet.multisig.dkg.round2({
participantName,
round1SecretPackage,
Expand All @@ -81,4 +92,17 @@ export class DkgRound2Command extends IronfishCommand {
this.log('Next step:')
this.log('Send the round 2 public package to each participant')
}

async performRound2WithLedger(): Promise<void> {
const ledger = new Ledger(this.logger)
try {
await ledger.connect()
} catch (e) {
if (e instanceof Error) {
this.error(e.message)
} else {
throw e
}
}
}
}
24 changes: 24 additions & 0 deletions ironfish-cli/src/commands/wallet/multisig/dkg/round3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../../command'
import { RemoteFlags } from '../../../../flags'
import * as ui from '../../../../ui'
import { Ledger } from '../../../../utils/ledger'

export class DkgRound3Command extends IronfishCommand {
static description = 'Perform round3 of the DKG protocol for multisig account creation'
Expand Down Expand Up @@ -36,6 +37,11 @@ export class DkgRound3Command extends IronfishCommand {
'The public package that a participant generated during DKG round 2 (may be specified multiple times for multiple participants). Your own round 2 public package is optional; if included, it will be ignored',
multiple: true,
}),
ledger: Flags.boolean({
default: false,
description: 'Perform operation with a ledger device',
hidden: true,
}),
}

async start(): Promise<void> {
Expand Down Expand Up @@ -100,6 +106,11 @@ export class DkgRound3Command extends IronfishCommand {
}
round2PublicPackages = round2PublicPackages.map((i) => i.trim())

if (flags.ledger) {
await this.performRound3WithLedger()
return
}

const response = await client.wallet.multisig.dkg.round3({
participantName,
accountName: flags.accountName,
Expand All @@ -113,4 +124,17 @@ export class DkgRound3Command extends IronfishCommand {
`Account ${response.content.name} imported with public address: ${response.content.publicAddress}`,
)
}

async performRound3WithLedger(): Promise<void> {
const ledger = new Ledger(this.logger)
try {
await ledger.connect()
} catch (e) {
if (e instanceof Error) {
this.error(e.message)
} else {
throw e
}
}
}
}

0 comments on commit 9263726

Please sign in to comment.