Skip to content

Commit

Permalink
handles Ledger 'invalid dkg status' errors (#5667)
Browse files Browse the repository at this point in the history
if a user attempts to sign a transaction, but their ledger app doesn't have any
multisig keys persisted, then the signing operation will fail with an
'invalid dkg status' error. this can happen if the user reinstalls the app or if
the user starts creating a new account on the device using bkg, but doesn't
finish

the only ways to recover from this error are to restore an encrypted backup to
the device, or to create a new multisig account using the device. since the
error shows up during signing, we can infer that the user expects to have an
account on the device and should be instructed to restore the backup
  • Loading branch information
hughy authored Nov 26, 2024
1 parent 6bdd3ec commit 0691c63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ironfish-cli/src/ledger/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const IronfishLedgerStatusCodes = {
PANIC: 0xe000,
EXPERT_MODE_REQUIRED: 0x6984,
DKG_EXPERT_MODE_REQUIRED: 0xb027,
INVALID_DKG_STATUS: 0xb022,
}

export class Ledger {
Expand Down Expand Up @@ -73,6 +74,8 @@ export class Ledger {
throw new LedgerPanicError()
} else if (error.returnCode === IronfishLedgerStatusCodes.GP_AUTH_FAILED) {
throw new LedgerGPAuthFailed()
} else if (error.returnCode === IronfishLedgerStatusCodes.INVALID_DKG_STATUS) {
throw new LedgerInvalidDkgStatusError()
} else if (
error.returnCode === IronfishLedgerStatusCodes.EXPERT_MODE_REQUIRED ||
error.returnCode === IronfishLedgerStatusCodes.DKG_EXPERT_MODE_REQUIRED
Expand Down Expand Up @@ -191,3 +194,4 @@ export class LedgerActionRejected extends LedgerError {}
export class LedgerInvalidTxHash extends LedgerError {}
export class LedgerPanicError extends LedgerError {}
export class LedgerExpertModeError extends LedgerError {}
export class LedgerInvalidDkgStatusError extends LedgerError {}
7 changes: 7 additions & 0 deletions ironfish-cli/src/ui/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
LedgerDeviceLockedError,
LedgerExpertModeError,
LedgerGPAuthFailed,
LedgerInvalidDkgStatusError,
LedgerPanicError,
LedgerPortIsBusyError,
LedgerSingleSigner,
Expand Down Expand Up @@ -103,6 +104,12 @@ export async function ledger<TResult>({
if (!wasRunning) {
ux.action.start(message)
}
} else if (e instanceof LedgerInvalidDkgStatusError) {
ux.action.stop('Ironfish DKG Ledger App does not have any multisig keys!')
ux.stdout(
'Use `wallet:multisig:ledger:restore` to restore an encrypted backup to your Ledger',
)
ux.exit(1)
} else if (e instanceof LedgerActionRejected) {
ux.action.status = 'User Rejected Ledger Request!'
ux.stdout('User Rejected Ledger Request!')
Expand Down

0 comments on commit 0691c63

Please sign in to comment.