Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
patnir committed Sep 20, 2024
1 parent b1eae7f commit ca173d8
Showing 1 changed file with 53 additions and 28 deletions.
81 changes: 53 additions & 28 deletions ironfish-cli/src/commands/wallet/multisig/dkg/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export class DkgCreateCommand extends IronfishCommand {
...RemoteFlags,
}


async start(): Promise<void> {
await this.parse(DkgCreateCommand)
const client = await this.connectRpc()
Expand All @@ -28,27 +27,32 @@ export class DkgCreateCommand extends IronfishCommand {
return this.createParticipant(client, name)
})

const { round1Result, totalParticipants } = await this.retryStep(
async () => {
return this.performRound1(client, name, identity)
},
)
const { round1Result, totalParticipants } = await this.retryStep(async () => {
return this.performRound1(client, name, identity)
})

const { round2Result, round1PublicPackages } = await this.retryStep(
async () => {
return this.performRound2(client, name, round1Result, totalParticipants)
},
)
const { round2Result, round1PublicPackages } = await this.retryStep(async () => {
return this.performRound2(client, name, round1Result, totalParticipants)
})

await this.retryStep(async () => {
await this.performRound3(client, name, round2Result, round1PublicPackages, totalParticipants)
await this.performRound3(
client,
name,
round2Result,
round1PublicPackages,
totalParticipants,
)
})

this.log('Multisig account created successfully using DKG!')
}

private async getNameForMultisigAccount(client: RpcClient): Promise<string> {
const name = await ui.inputPrompt('Enter a name for your account and participant identity', true)
const name = await ui.inputPrompt(
'Enter a name for your account and participant identity',
true,
)

const identities = (await client.wallet.multisig.getIdentities()).content.identities

Expand All @@ -62,7 +66,6 @@ export class DkgCreateCommand extends IronfishCommand {

const foundIdentity = identities.find((identity) => identity.name === name)


if (foundIdentity) {
throw new Error(`Identity with name ${name} already exists`)
}
Expand Down Expand Up @@ -90,19 +93,22 @@ export class DkgCreateCommand extends IronfishCommand {
name = await ui.inputPrompt('Enter a name for your participant identity', true)
}

let identity = (await client.wallet.multisig.createParticipant({ name })).content.identity
const identity = (await client.wallet.multisig.createParticipant({ name })).content.identity

this.log(`\nParticipant identity for ${name}: \n${identity} \n`)

return { name, identity }
}

async collectStrings(item: string, count: number, additionalStrings: string[]): Promise<string[]> {
async collectStrings(
item: string,
count: number,
additionalStrings: string[],
): Promise<string[]> {
const array = []

for (let i = 0; i < count; i++) {
const input = await ui.longPrompt(
`${item} ${i + 1}`, { required: true })
const input = await ui.longPrompt(`${item} ${i + 1}`, { required: true })
array.push(input)
}

Expand All @@ -111,9 +117,7 @@ export class DkgCreateCommand extends IronfishCommand {
const withoutDuplicates = [...new Set(result)]

if (withoutDuplicates.length !== result.length) {
throw new Error(
`Duplicate ${item} found in the list`,
)
throw new Error(`Duplicate ${item} found in the list`)
}

return result
Expand All @@ -123,7 +127,10 @@ export class DkgCreateCommand extends IronfishCommand {
client: RpcClient,
participantName: string,
currentIdentity: string,
): Promise<{ round1Result: { secretPackage: string; publicPackage: string }, totalParticipants: number }> {
): Promise<{
round1Result: { secretPackage: string; publicPackage: string }
totalParticipants: number
}> {
this.log('\nCollecting Participant Info and Performing Round 1...')

let input = await ui.inputPrompt('Enter the total number of participants', true)
Expand All @@ -132,8 +139,14 @@ export class DkgCreateCommand extends IronfishCommand {
throw new Error('Total number of participants must be at least 2')
}

this.logger.log(`\nEnter ${totalParticipants - 1} times identities of all other participants (excluding yours) `)
const identities = await this.collectStrings('Identity', totalParticipants - 1, [currentIdentity])
this.logger.log(
`\nEnter ${
totalParticipants - 1
} times identities of all other participants (excluding yours) `,
)
const identities = await this.collectStrings('Identity', totalParticipants - 1, [
currentIdentity,
])

input = await ui.inputPrompt('Enter the number of minimum signers', true)
const minSigners = parseInt(input)
Expand Down Expand Up @@ -173,8 +186,14 @@ export class DkgCreateCommand extends IronfishCommand {
round2Result: { secretPackage: string; publicPackage: string }
round1PublicPackages: string[]
}> {
this.logger.log(`\nEnter ${totalParticipants - 1} times Round 1 Public Packages (excluding yours) `)
const round1PublicPackages = await this.collectStrings('Round 1 Public Package', totalParticipants - 1, [round1Result.publicPackage])
this.logger.log(
`\nEnter ${totalParticipants - 1} times Round 1 Public Packages (excluding yours) `,
)
const round1PublicPackages = await this.collectStrings(
'Round 1 Public Package',
totalParticipants - 1,
[round1Result.publicPackage],
)

this.log('\nPerforming DKG Round 2...')

Expand Down Expand Up @@ -208,9 +227,15 @@ export class DkgCreateCommand extends IronfishCommand {
round1PublicPackages: string[],
totalParticipants: number,
): Promise<void> {
this.logger.log(`\nEnter ${totalParticipants - 1} times Round 2 Public Packages (excluding yours) `)
this.logger.log(
`\nEnter ${totalParticipants - 1} times Round 2 Public Packages (excluding yours) `,
)

const round2PublicPackages = await this.collectStrings('Round 2 Public Package', totalParticipants - 1, [round2Result.publicPackage])
const round2PublicPackages = await this.collectStrings(
'Round 2 Public Package',
totalParticipants - 1,
[round2Result.publicPackage],
)

const response = await client.wallet.multisig.dkg.round3({
participantName: name,
Expand Down

0 comments on commit ca173d8

Please sign in to comment.