Skip to content

Commit

Permalink
implements ledger multisig backup command
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hughy committed Sep 19, 2024
1 parent a487c5d commit 99ecf8c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ironfish-cli/src/commands/wallet/multisig/ledger/backup.ts
Original file line number Diff line number Diff line change
@@ -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<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'))
}
}
12 changes: 12 additions & 0 deletions ironfish-cli/src/utils/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,18 @@ export class Ledger {

return signature
}

dkgBackupKeys = async (): Promise<Buffer> => {
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 {
Expand Down

0 comments on commit 99ecf8c

Please sign in to comment.