Skip to content

Commit

Permalink
adds ledger flag to 'wallet:multisig:participant' (#5712)
Browse files Browse the repository at this point in the history
* adds ledger flag to 'wallet:multisig:participant'

supports reading identity from ledger and displaying on CLI

* avoids checking for wallet encryption when using ledger flag
  • Loading branch information
hughy authored Jan 24, 2025
1 parent f7a99d8 commit 0f0d71f
Showing 1 changed file with 49 additions and 28 deletions.
77 changes: 49 additions & 28 deletions ironfish-cli/src/commands/wallet/multisig/participant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,78 @@ import { Flags } from '@oclif/core'
import inquirer from 'inquirer'
import { IronfishCommand } from '../../../../command'
import { RemoteFlags } from '../../../../flags'
import { LedgerMultiSigner } from '../../../../ledger'
import * as ui from '../../../../ui'

export class MultisigIdentity extends IronfishCommand {
static description = `Retrieve a multisig participant identity from a name`
static description = `Retrieve a multisig participant identity`

static flags = {
...RemoteFlags,
name: Flags.string({
char: 'n',
description: 'Name of the participant identity',
}),
ledger: Flags.boolean({
default: false,
description: 'Retrieve participant identity from a ledger device',
exclusive: ['name'],
}),
}

async start(): Promise<void> {
const { flags } = await this.parse(MultisigIdentity)

const client = await this.connectRpc()
await ui.checkWalletUnlocked(client)
if (flags.ledger) {
const ledger = new LedgerMultiSigner()

if (flags.name) {
const response = await client.wallet.multisig.getIdentity({ name: flags.name })
const identity = (
await ui.ledger({
ledger,
message: 'Getting Ledger Identity',
action: () => ledger.dkgGetIdentity(0),
})
).toString('hex')

this.log('Identity:')
this.log(response.content.identity)
this.log(identity)
} else {
const response = await client.wallet.multisig.getIdentities()
const client = await this.connectRpc()
await ui.checkWalletUnlocked(client)

const choices = []
for (const { name, identity } of response.content.identities) {
choices.push({
name,
value: identity,
})
}
if (flags.name) {
const response = await client.wallet.multisig.getIdentity({ name: flags.name })

// sort identities by name
choices.sort((a, b) => a.name.localeCompare(b.name))
this.log('Identity:')
this.log(response.content.identity)
} else {
const response = await client.wallet.multisig.getIdentities()

const selection = await inquirer.prompt<{
identity: string
}>([
{
name: 'identity',
message: 'Select participant name to view identity',
type: 'list',
choices,
},
])
const choices = []
for (const { name, identity } of response.content.identities) {
choices.push({
name,
value: identity,
})
}

this.log('Identity:')
this.log(selection.identity)
// sort identities by name
choices.sort((a, b) => a.name.localeCompare(b.name))

const selection = await inquirer.prompt<{
identity: string
}>([
{
name: 'identity',
message: 'Select participant name to view identity',
type: 'list',
choices,
},
])

this.log('Identity:')
this.log(selection.identity)
}
}
}
}

0 comments on commit 0f0d71f

Please sign in to comment.