diff --git a/ironfish-cli/src/commands/wallet/multisig/dkg/round1.ts b/ironfish-cli/src/commands/wallet/multisig/dkg/round1.ts index b26085cf0c..b76c12317e 100644 --- a/ironfish-cli/src/commands/wallet/multisig/dkg/round1.ts +++ b/ironfish-cli/src/commands/wallet/multisig/dkg/round1.ts @@ -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' @@ -71,7 +72,7 @@ export class DkgRound1Command extends IronfishCommand { } if (flags.ledger) { - await this.performRound1WithLedger() + await this.performRound1WithLedger(client, participantName, identities, minSigners) return } @@ -93,10 +94,15 @@ export class DkgRound1Command extends IronfishCommand { this.log('Send the round 1 public package to each participant') } - async performRound1WithLedger(): Promise { + async performRound1WithLedger( + client: RpcClient, + participantName: string, + identities: string[], + minSigners: number, + ): Promise { const ledger = new Ledger(this.logger) try { - await ledger.connect() + await ledger.connect(true) } catch (e) { if (e instanceof Error) { this.error(e.message) @@ -104,5 +110,26 @@ export class DkgRound1Command extends IronfishCommand { 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') } } diff --git a/ironfish-cli/src/utils/ledger.ts b/ironfish-cli/src/utils/ledger.ts index e782f9915d..7a0a173316 100644 --- a/ironfish-cli/src/utils/ledger.ts +++ b/ironfish-cli/src/utils/ledger.ts @@ -8,6 +8,7 @@ import IronfishApp, { IronfishKeys, KeyResponse, ResponseAddress, + ResponseDkgRound1, ResponseIdentity, ResponseProofGenKey, ResponseSign, @@ -168,6 +169,20 @@ export class Ledger { return response.identity } + + dkgRound1 = async ( + index: number, + identities: string[], + minSigners: number, + ): Promise => { + 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 {