-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds cli command to restore ledger multisig backup (#5401)
* adds cli command to restore ledger multisig backup 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 * Update ironfish-cli/src/commands/wallet/multisig/ledger/restore.ts Co-authored-by: mat-if <[email protected]> --------- Co-authored-by: mat-if <[email protected]>
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
ironfish-cli/src/commands/wallet/multisig/ledger/restore.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters