-
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.
passes wallet passphrase from CLI to migrator (#5631)
* passes wallet passphrase from CLI to migrator adds an error type, EncryptedWalletMigrationError, and catches errors of that type in the three commands that run migrations: 'migrations:start', 'migrations:revert', and 'start' prompts user to enter wallet passphrase and passes passphrase through to migrator to support passing the passphrase down to the migrator in the 'start' command we pass the passphrase through 'NodeUtils.waitForOpen' and the the node's 'openDB' method supports implementing database migrations that handle encrypted wallet logic. for example, throwing the EncryptedWalletMigrationError on an encrypted account and using the wallet passphrase passed to 'migrate' to decrypt and re-encrypt the wallet * removes passphrase prompt from start command displays error message to user instead removes logic plumbing passphrase through openDB to migrator
- Loading branch information
Showing
9 changed files
with
118 additions
and
9 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,17 +1,50 @@ | ||
/* 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 { AccountDecryptionFailedError, EncryptedWalletMigrationError } from '@ironfish/sdk' | ||
import { Flags } from '@oclif/core' | ||
import { IronfishCommand } from '../../command' | ||
import { inputPrompt } from '../../ui' | ||
|
||
export class RevertCommand extends IronfishCommand { | ||
static description = `revert the last run migration` | ||
|
||
static flags = { | ||
passphrase: Flags.string({ | ||
description: 'Passphrase to unlock the wallet database with', | ||
}), | ||
} | ||
|
||
static hidden = true | ||
|
||
async start(): Promise<void> { | ||
await this.parse(RevertCommand) | ||
const { flags } = await this.parse(RevertCommand) | ||
|
||
const node = await this.sdk.node() | ||
await node.migrator.revert() | ||
|
||
let walletPassphrase = flags.passphrase | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
try { | ||
await node.migrator.revert({ walletPassphrase }) | ||
break | ||
} catch (e) { | ||
if ( | ||
e instanceof EncryptedWalletMigrationError || | ||
e instanceof AccountDecryptionFailedError | ||
) { | ||
this.logger.info(e.message) | ||
walletPassphrase = await inputPrompt( | ||
'Enter your passphrase to unlock the wallet', | ||
true, | ||
{ | ||
password: true, | ||
}, | ||
) | ||
} else { | ||
throw e | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
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,7 @@ | ||
/* 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/. */ | ||
|
||
export class EncryptedWalletMigrationError extends Error { | ||
name = this.constructor.name | ||
} |
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
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
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
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
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