From 99ecf8c2bc60e0b0909c7ebf1fad25aa1e2053c3 Mon Sep 17 00:00:00 2001 From: Hugh Cunningham Date: Thu, 19 Sep 2024 16:59:15 -0700 Subject: [PATCH] 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 --- .../commands/wallet/multisig/ledger/backup.ts | 28 +++++++++++++++++++ ironfish-cli/src/utils/ledger.ts | 12 ++++++++ 2 files changed, 40 insertions(+) create mode 100644 ironfish-cli/src/commands/wallet/multisig/ledger/backup.ts diff --git a/ironfish-cli/src/commands/wallet/multisig/ledger/backup.ts b/ironfish-cli/src/commands/wallet/multisig/ledger/backup.ts new file mode 100644 index 0000000000..4c581a9497 --- /dev/null +++ b/ironfish-cli/src/commands/wallet/multisig/ledger/backup.ts @@ -0,0 +1,28 @@ +/* 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 = `Backup encrypted multisig keys from a Ledger device` + + async start(): Promise { + 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')) + } +} diff --git a/ironfish-cli/src/utils/ledger.ts b/ironfish-cli/src/utils/ledger.ts index 082bfcf4c5..0ed2d40135 100644 --- a/ironfish-cli/src/utils/ledger.ts +++ b/ironfish-cli/src/utils/ledger.ts @@ -305,6 +305,18 @@ export class Ledger { return signature } + + dkgBackupKeys = async (): Promise => { + if (!this.app) { + throw new Error('Connect to Ledger first') + } + + this.logger.log('Please approve the request on your ledger device.') + + const { encryptedKeys } = await this.tryInstruction(this.app.dkgBackupKeys()) + + return encryptedKeys + } } function isResponseAddress(response: KeyResponse): response is ResponseAddress {