Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converts dkg commands to use ui.ledger #5669

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions ironfish-cli/src/commands/wallet/multisig/dkg/round1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,6 @@ export class DkgRound1Command extends IronfishCommand {
minSigners: number,
): Promise<void> {
const ledger = new LedgerMultiSigner()
try {
await ledger.connect()
} catch (e) {
if (e instanceof Error) {
this.error(e.message)
} else {
throw e
}
}

const identityResponse = await client.wallet.multisig.getIdentity({ name: participantName })
const identity = identityResponse.content.identity
Expand All @@ -118,8 +109,12 @@ export class DkgRound1Command extends IronfishCommand {
identities.push(identity)
}

// TODO(hughy): determine how to handle multiple identities using index
const { publicPackage, secretPackage } = await ledger.dkgRound1(0, identities, minSigners)
const { publicPackage, secretPackage } = await ui.ledger({
ledger,
message: 'Round1 on Ledger',
approval: true,
action: () => ledger.dkgRound1(0, identities, minSigners),
})

this.log('\nRound 1 Encrypted Secret Package:\n')
this.log(secretPackage.toString('hex'))
Expand Down
21 changes: 6 additions & 15 deletions ironfish-cli/src/commands/wallet/multisig/dkg/round2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,13 @@ export class DkgRound2Command extends IronfishCommand {
round1SecretPackage: string,
): Promise<void> {
const ledger = new LedgerMultiSigner()
try {
await ledger.connect()
} catch (e) {
if (e instanceof Error) {
this.error(e.message)
} else {
throw e
}
}

// TODO(hughy): determine how to handle multiple identities using index
const { publicPackage, secretPackage } = await ledger.dkgRound2(
0,
round1PublicPackages,
round1SecretPackage,
)
const { publicPackage, secretPackage } = await ui.ledger({
ledger,
message: 'Round2 on Ledger',
approval: true,
action: () => ledger.dkgRound2(0, round1PublicPackages, round1SecretPackage),
})

this.log('\nRound 2 Encrypted Secret Package:\n')
this.log(secretPackage.toString('hex'))
Expand Down
56 changes: 33 additions & 23 deletions ironfish-cli/src/commands/wallet/multisig/dkg/round3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,6 @@ export class DkgRound3Command extends IronfishCommand {
accountCreatedAt?: number,
): Promise<void> {
const ledger = new LedgerMultiSigner()
try {
await ledger.connect()
} catch (e) {
if (e instanceof Error) {
this.error(e.message)
} else {
throw e
}
}

const identityResponse = await client.wallet.multisig.getIdentity({ name: participantName })
const identity = identityResponse.content.identity
Expand All @@ -192,9 +183,9 @@ export class DkgRound3Command extends IronfishCommand {
.sort((a, b) => a.senderIdentity.localeCompare(b.senderIdentity))

// Extract raw parts from round1 and round2 public packages
const participants = []
const round1FrostPackages = []
const gskBytes = []
const participants: string[] = []
const round1FrostPackages: string[] = []
const gskBytes: string[] = []
for (const pkg of round1PublicPackages) {
// Exclude participant's own identity and round1 public package
if (pkg.identity !== identity) {
Expand All @@ -208,19 +199,33 @@ export class DkgRound3Command extends IronfishCommand {
const round2FrostPackages = round2PublicPackages.map((pkg) => pkg.frostPackage)

// Perform round3 with Ledger
await ledger.dkgRound3(
0,
participants,
round1FrostPackages,
round2FrostPackages,
round2SecretPackage,
gskBytes,
)
await ui.ledger({
ledger,
message: 'Round3 on Ledger',
approval: true,
action: () =>
ledger.dkgRound3(
0,
participants,
round1FrostPackages,
round2FrostPackages,
round2SecretPackage,
gskBytes,
),
})

// Retrieve all multisig account keys and publicKeyPackage
const dkgKeys = await ledger.dkgRetrieveKeys()
const dkgKeys = await ui.ledger({
ledger,
message: 'Getting Ledger DKG keys',
action: () => ledger.dkgRetrieveKeys(),
})

const publicKeyPackage = await ledger.dkgGetPublicPackage()
const publicKeyPackage = await ui.ledger({
ledger,
message: 'Getting Ledger Public Package',
action: () => ledger.dkgGetPublicPackage(),
})

const accountImport = {
...dkgKeys,
Expand Down Expand Up @@ -250,7 +255,12 @@ export class DkgRound3Command extends IronfishCommand {
this.log('Creating an encrypted backup of multisig keys from your Ledger device...')
this.log()

const encryptedKeys = await ledger.dkgBackupKeys()
const encryptedKeys = await ui.ledger({
ledger,
message: 'Backup DKG Keys',
approval: true,
action: () => ledger.dkgBackupKeys(),
})

this.log()
this.log('Encrypted Ledger Multisig Backup:')
Expand Down
16 changes: 5 additions & 11 deletions ironfish-cli/src/commands/wallet/multisig/participant/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,11 @@ export class MultisigIdentityCreate extends IronfishCommand {

async getIdentityFromLedger(): Promise<Buffer> {
const ledger = new LedgerMultiSigner()
try {
await ledger.connect()
} catch (e) {
if (e instanceof Error) {
this.error(e.message)
} else {
throw e
}
}

// TODO(hughy): support multiple identities using index
return ledger.dkgGetIdentity(0)
return ui.ledger({
ledger,
message: 'Getting Ledger Identity',
action: () => ledger.dkgGetIdentity(0),
})
}
}