-
Notifications
You must be signed in to change notification settings - Fork 574
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implements ledger multisig backup command (#5400)
* implements ledger multisig backup command adds a CLI command, 'wallet:multisig:ledger:backup', to create an encrypted backup of multisig keys from the ironfish dkg ledger app users can restore the keys to their ledger app if they reinstall the app on their device or overwrite the multisig keys in the app * 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]> * updates command description adds additional log output asking the user to save the backup and explaining how to restore the keys * fixes lint --------- Co-authored-by: mat-if <[email protected]>
- Loading branch information
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
ironfish-cli/src/commands/wallet/multisig/ledger/backup.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,33 @@ | ||
/* 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 { IronfishCommand } from '../../../../command' | ||
import { Ledger } from '../../../../utils/ledger' | ||
|
||
export class MultisigLedgerBackup extends IronfishCommand { | ||
static description = `show encrypted multisig keys from a Ledger device` | ||
|
||
async start(): Promise<void> { | ||
const ledger = new Ledger(this.logger) | ||
try { | ||
await ledger.connect(true) | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
this.error(e.message) | ||
} else { | ||
throw e | ||
} | ||
} | ||
|
||
const encryptedKeys = await ledger.dkgBackupKeys() | ||
|
||
this.log() | ||
this.log('Encrypted Ledger Multisig Backup:') | ||
this.log(encryptedKeys.toString('hex')) | ||
this.log() | ||
this.log('Please save the encrypted keys show above.') | ||
this.log( | ||
'Use `ironfish wallet:multisig:ledger:restore` if you need to restore the keys to your Ledger.', | ||
) | ||
} | ||
} |
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