This repository has been archived by the owner on Jun 4, 2018. It is now read-only.
forked from btcsuite/Paymetheus
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
265 additions
and
79 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
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,63 @@ | ||
// Copyright (c) 2016 The btcsuite developers | ||
// Copyright (c) 2016 The Decred developers | ||
// Licensed under the ISC license. See LICENSE file in the project root for full license information. | ||
|
||
using Paymetheus.Decred.Util; | ||
using System; | ||
using System.Security.Cryptography; | ||
|
||
namespace Paymetheus.Decred.Wallet | ||
{ | ||
public static class WalletSeed | ||
{ | ||
/// <summary> | ||
/// The length in bytes of the wallet's BIP0032 seed. | ||
/// </summary> | ||
public const int SeedLength = 32; | ||
|
||
public static byte[] GenerateRandomSeed() | ||
{ | ||
var seed = new byte[SeedLength]; | ||
using (var prng = new RNGCryptoServiceProvider()) | ||
{ | ||
prng.GetBytes(seed); | ||
} | ||
return seed; | ||
} | ||
|
||
/// <summary> | ||
/// Decodes user input as either the hexadecimal or PGP word list encoding | ||
/// of a seed and validates the seed length. | ||
/// </summary> | ||
public static byte[] DecodeAndValidateUserInput(string userInput, PgpWordList pgpWordList) | ||
{ | ||
if (userInput == null) | ||
throw new ArgumentNullException(nameof(userInput)); | ||
if (pgpWordList == null) | ||
throw new ArgumentNullException(nameof(pgpWordList)); | ||
|
||
var decodedInput = DecodeUserInput(userInput, pgpWordList); | ||
if (decodedInput.Length != SeedLength) | ||
{ | ||
throw new Exception($"Decoded seed must have byte length {SeedLength}"); | ||
} | ||
return decodedInput; | ||
} | ||
|
||
private static byte[] DecodeUserInput(string userInput, PgpWordList pgpWordList) | ||
{ | ||
byte[] seed; | ||
if (Hexadecimal.TryDecode(userInput, out seed)) | ||
return seed; | ||
|
||
var splitInput = userInput.Split(new char[0], StringSplitOptions.RemoveEmptyEntries); | ||
if (splitInput.Length == 1) | ||
{ | ||
// Hex decoding failed, but it's not a multi-word mneumonic either. | ||
// Assume the user intended hex. | ||
throw new HexadecimalEncodingException(); | ||
} | ||
return pgpWordList.Decode(splitInput); | ||
} | ||
} | ||
} |
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,54 @@ | ||
// Copyright (c) 2016 The btcsuite developers | ||
// Licensed under the ISC license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Windows; | ||
using System.Windows.Data; | ||
using System.Windows.Input; | ||
|
||
namespace Paymetheus | ||
{ | ||
static class BindingProperties | ||
{ | ||
public static readonly DependencyProperty UpdateSourceOnEnterProperty = | ||
DependencyProperty.RegisterAttached(nameof(UpdateSourceOnEnter), typeof(DependencyProperty), | ||
typeof(BindingProperties), new PropertyMetadata(null, UpdateSourceOnEnter)); | ||
|
||
public static DependencyProperty GetUpdateSourceOnEnterProperty(DependencyObject instance) | ||
{ | ||
return (DependencyProperty)instance.GetValue(UpdateSourceOnEnterProperty); | ||
} | ||
|
||
public static void SetUpdateSourceOnEnterProperty(DependencyObject instance, DependencyProperty value) | ||
{ | ||
instance.SetValue(UpdateSourceOnEnterProperty, value); | ||
} | ||
|
||
private static void UpdateSourceOnEnter(DependencyObject dp, DependencyPropertyChangedEventArgs e) | ||
{ | ||
var element = dp as UIElement; | ||
if (element == null) | ||
return; | ||
|
||
if (e.OldValue != null) | ||
element.PreviewKeyDown -= UpdateSourceOnEnter_PreviewKeyDown; | ||
if (e.NewValue != null) | ||
element.PreviewKeyDown += UpdateSourceOnEnter_PreviewKeyDown; | ||
} | ||
|
||
private static void UpdateSourceOnEnter_PreviewKeyDown(object sender, KeyEventArgs e) | ||
{ | ||
if (e.Key == Key.Enter) | ||
{ | ||
var element = sender as UIElement; | ||
if (element == null) | ||
return; | ||
|
||
var property = GetUpdateSourceOnEnterProperty(element); | ||
if (property == null) | ||
return; | ||
|
||
BindingOperations.GetBindingExpression(element, property)?.UpdateSource(); | ||
} | ||
} | ||
} | ||
} |
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,50 @@ | ||
<UserControl x:Class="Paymetheus.CreateOrImportSeedView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:Paymetheus" | ||
mc:Ignorable="d" | ||
d:DesignHeight="300" d:DesignWidth="600"> | ||
<DockPanel Focusable="False"> | ||
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right"> | ||
<Button Content="Continue" IsDefault="True" Command="{Binding ContinueCommand}" Width="100" Margin="6,12,3,6" Padding="10 2"/> | ||
</StackPanel> | ||
<Label DockPanel.Dock="Top" FontSize="18" Content="Create or recover wallet"/> | ||
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top" HorizontalAlignment="Center"> | ||
<StackPanel.Resources> | ||
<Style TargetType="{x:Type RadioButton}"> | ||
<Setter Property="Width" Value="160"/> | ||
</Style> | ||
</StackPanel.Resources> | ||
<RadioButton Content="Create new wallet" IsChecked="{Binding CreateChecked}"/> | ||
<RadioButton Content="Recover wallet from seed" IsChecked="{Binding ImportChecked}"/> | ||
</StackPanel> | ||
<Grid> | ||
<StackPanel Visibility="{Binding CreateChecked, Converter={StaticResource hiddenConverter}}"> | ||
<Label> | ||
<TextBlock TextWrapping="Wrap"> | ||
The wallet seed must be backed up before the wallet may be used. | ||
This seed is necessary to recover wallet keys in case of data loss. | ||
Write down this seed and save it in a secure location. | ||
The next prompt will require entering this seed to confirm it has been saved. | ||
</TextBlock> | ||
</Label> | ||
<Label Content="{Binding Bip0032SeedHex}" FontSize="16" HorizontalContentAlignment="Center"/> | ||
</StackPanel> | ||
<StackPanel Visibility="{Binding ImportChecked, Converter={StaticResource hiddenConverter}}"> | ||
<Label> | ||
<TextBlock TextWrapping="Wrap"> | ||
The seed from a previously-created wallet may be used to recreate the wallet | ||
with all of its addresses and keys. The seed should be formatted as a | ||
hexadecimal number (64 characters between 0-9 and A-F) or a list of | ||
mneumonic words. | ||
</TextBlock> | ||
</Label> | ||
<Label Content="Seed:"/> | ||
<TextBox Text="{Binding ImportedSeed, Mode=OneWayToSource}" | ||
local:BindingProperties.UpdateSourceOnEnterProperty="TextBox.Text"/> | ||
</StackPanel> | ||
</Grid> | ||
</DockPanel> | ||
</UserControl> |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.