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

adds cli command to restore ledger multisig backup #5401

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
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