-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
- Loading branch information
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void> { | ||
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') | ||
} | ||
} |