Skip to content

Commit

Permalink
adds cli command to restore ledger multisig backup
Browse files Browse the repository at this point in the history
if the ironfish dkg ledger app is uninstalled, or if it is used to create a
second set of keys, then the multisig keys on the device may be lost

the 'wallet:multisig:ledger:backup' command creates an encrypted key backup that
can be restored to the device

the 'wallet:multisig:ledger:restore' command restores the backed up keys to the
ledger
  • Loading branch information
hughy committed Sep 20, 2024
1 parent 99ecf8c commit d040d9c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
45 changes: 45 additions & 0 deletions ironfish-cli/src/commands/wallet/multisig/ledger/restore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* 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 { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../../command'
import * as ui from '../../../../ui'
import { Ledger } from '../../../../utils/ledger'

export class MultisigLedgerRestore extends IronfishCommand {
static description = `Restore encrypted multisig keys to a Ledger device`

static flags = {
backup: Flags.string({
description: 'Encrypted multisig key backup from your Ledger device',
char: 'b',
}),
}

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

let encryptedKeys = flags.backup
if (!encryptedKeys) {
encryptedKeys = await ui.longPrompt(
'Enter the encrypted multisig key backup to restore to your Ledger device',
)
}

const ledger = new Ledger(this.logger)
try {
await ledger.connect(true)
} catch (e) {
if (e instanceof Error) {
this.error(e.message)
} else {
throw e
}
}

await ledger.dkgRestoreKeys(encryptedKeys)

this.log()
this.log('Encrypted multisig key backup restored to Ledger.')
}
}
10 changes: 10 additions & 0 deletions ironfish-cli/src/utils/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,16 @@ export class Ledger {

return encryptedKeys
}

dkgRestoreKeys = async (encryptedKeys: string): Promise<void> => {
if (!this.app) {
throw new Error('Connect to Ledger first')
}

this.logger.log('Please approve the request on your ledger device.')

await this.tryInstruction(this.app.dkgRestoreKeys(encryptedKeys))
}
}

function isResponseAddress(response: KeyResponse): response is ResponseAddress {
Expand Down

0 comments on commit d040d9c

Please sign in to comment.