Skip to content
This repository has been archived by the owner on Jun 4, 2018. It is now read-only.

Commit

Permalink
Use WalletSeed.DecodeAndValidateUserInput for backup confirmation.
Browse files Browse the repository at this point in the history
This allows proceeding to create the wallet when either the
hexadecimal or PGP word list encoding of the seed is entered in the
backup confirmation dialog.
  • Loading branch information
jrick committed Feb 19, 2016
1 parent a60497d commit 8e82946
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions Paymetheus/StartupWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private void Continue()

if (CreateChecked)
{
Wizard.CurrentDialog = new ConfirmSeedBackupDialog(Wizard, _randomSeed, this);
Wizard.CurrentDialog = new ConfirmSeedBackupDialog(Wizard, this, _randomSeed, _pgpWordList);
}
else
{
Expand All @@ -202,35 +202,49 @@ private void Continue()

sealed class ConfirmSeedBackupDialog : ConnectionWizardDialog
{
public ConfirmSeedBackupDialog(StartupWizard wizard, byte[] seed, CreateOrImportSeedDialog previousDialog)
public ConfirmSeedBackupDialog(StartupWizard wizard, CreateOrImportSeedDialog previousDialog,
byte[] seed, PgpWordList pgpWordlist)
: base(wizard)
{
_seed = seed;
_previousDialog = previousDialog;
_seed = seed;
_pgpWordList = pgpWordlist;

ConfirmSeedCommand = new DelegateCommand(ConfirmSeed);
BackCommand = new DelegateCommand(Back);
}

private byte[] _seed;
private CreateOrImportSeedDialog _previousDialog;
private byte[] _seed;
private PgpWordList _pgpWordList;

public string Input { get; set; } = "";

public DelegateCommand ConfirmSeedCommand { get; }
private void ConfirmSeed()
{
byte[] decodedSeed;
if (Hexadecimal.TryDecode(Input, out decodedSeed))
try
{
ConfirmSeedCommand.Executable = false;

var decodedSeed = WalletSeed.DecodeAndValidateUserInput(Input, _pgpWordList);
if (ValueArray.ShallowEquals(_seed, decodedSeed))
{
_wizard.CurrentDialog = new PromptPassphrasesDialog(Wizard, _seed);
return;
}
else
{
MessageBox.Show("Seed does not match");
}
}

MessageBox.Show("Seed does not match");
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Invalid seed");
}
finally
{
ConfirmSeedCommand.Executable = true;
}
}

public DelegateCommand BackCommand { get; }
Expand Down

0 comments on commit 8e82946

Please sign in to comment.