From f8ec29499e2f2b3034b2736829e5496be56a1ff6 Mon Sep 17 00:00:00 2001 From: Hugh Cunningham <57735705+hughy@users.noreply.github.com> Date: Tue, 16 Apr 2024 09:16:54 -0700 Subject: [PATCH] add dkg round1 cli command (#4890) * add dkg round1 cli command adds a cli command to run round1 of the dkg protocol takes flags for secret name, identities of particicpants, and minimum signers logs encrypted secret package and public package to command-line * prompts user for secretName if flag not set --- .../commands/wallet/multisig/dkg/round1.ts | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 ironfish-cli/src/commands/wallet/multisig/dkg/round1.ts diff --git a/ironfish-cli/src/commands/wallet/multisig/dkg/round1.ts b/ironfish-cli/src/commands/wallet/multisig/dkg/round1.ts new file mode 100644 index 0000000000..b14a23a87b --- /dev/null +++ b/ironfish-cli/src/commands/wallet/multisig/dkg/round1.ts @@ -0,0 +1,84 @@ +/* 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 { CliUx, Flags } from '@oclif/core' +import { IronfishCommand } from '../../../../command' +import { RemoteFlags } from '../../../../flags' +import { longPrompt } from '../../../../utils/longPrompt' + +export class DkgRound1Command extends IronfishCommand { + static description = 'Perform round1 of the DKG protocol for multisig account creation' + static hidden = true + + static flags = { + ...RemoteFlags, + secretName: Flags.string({ + char: 's', + description: 'The name of the secret to use for encryption during DKG', + }), + identity: Flags.string({ + char: 'i', + description: + 'The identity of the participants will generate the group keys (may be specified multiple times to add multiple participants). Must include the identity for secretName', + multiple: true, + }), + minSigners: Flags.integer({ + char: 'm', + description: 'Minimum number of signers to meet signing threshold', + }), + } + + async start(): Promise { + const { flags } = await this.parse(DkgRound1Command) + + let secretName = flags.secretName + if (!secretName) { + secretName = await CliUx.ux.prompt('Enter the name of the secret to use', { + required: true, + }) + } + + let identities = flags.identity + if (!identities || identities.length < 2) { + const input = await longPrompt('Enter the identities separated by commas', { + required: true, + }) + identities = input.split(',') + + if (identities.length < 2) { + this.error('Minimum number of identities must be at least 2') + } + } + identities = identities.map((i) => i.trim()) + + let minSigners = flags.minSigners + if (!minSigners) { + const input = await CliUx.ux.prompt('Enter the number of minimum signers', { + required: true, + }) + minSigners = parseInt(input) + if (isNaN(minSigners) || minSigners < 2) { + this.error('Minimum number of signers must be at least 2') + } + } + + const client = await this.sdk.connectRpc() + + const response = await client.wallet.multisig.dkg.round1({ + secretName: secretName, + participants: identities.map((identity) => ({ identity })), + minSigners: minSigners, + }) + + this.log('\nEncrypted Secret Package:\n') + this.log(response.content.encryptedSecretPackage) + this.log() + + this.log('\nPublic Package:\n') + this.log(response.content.publicPackage) + this.log() + + this.log('Next step:') + this.log('Send the public package to each participant') + } +}