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

Commit

Permalink
Convert Paymetheus.Bitcoin to a Portable Class Library.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Feb 22, 2016
1 parent 0b9b3d7 commit 5177a2e
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 49 deletions.
1 change: 0 additions & 1 deletion Paymetheus.Bitcoin/BlockChainConsistencyException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace Paymetheus.Bitcoin
{
[Serializable]
public class BlockChainConsistencyException : Exception
{
internal BlockChainConsistencyException(string message) : base(message) { }
Expand Down
1 change: 0 additions & 1 deletion Paymetheus.Bitcoin/BlockChainIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public static BlockChainIdentity FromNetworkBits(uint network)
}
}

[Serializable]
public class UnknownBlockChainException : Exception
{
public UnknownBlockChainException(string message) : base(message) { }
Expand Down
16 changes: 0 additions & 16 deletions Paymetheus.Bitcoin/EncodingException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

using Paymetheus.Bitcoin.Util;
using System;
using System.Runtime.Serialization;

namespace Paymetheus.Bitcoin
{
[Serializable]
public class EncodingException : Exception
{
private const string messageFormat = "Operation uses or creates an invalid encoding for type {0}";
Expand All @@ -27,21 +25,7 @@ public EncodingException(Type resultType, ByteCursor cursor, Exception innerExce
Cursor = cursor;
}

protected EncodingException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
ResultType = (Type)info.GetValue(nameof(ResultType), typeof(Type));
Cursor = (ByteCursor)info.GetValue(nameof(Cursor), typeof(ByteCursor));
}

public Type ResultType { get; }
public ByteCursor Cursor { get; }

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue(nameof(ResultType), ResultType);
info.AddValue(nameof(Cursor), Cursor);
}
}
}
21 changes: 15 additions & 6 deletions Paymetheus.Bitcoin/Paymetheus.Bitcoin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Paymetheus.Bitcoin</RootNamespace>
<AssemblyName>Paymetheus.Bitcoin</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<DefaultLanguage>en-US</DefaultLanguage>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkProfile>Profile7</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -35,15 +36,20 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="PCLCrypto">
<HintPath>..\packages\PCLCrypto.1.0.86\lib\net40-Client\PCLCrypto.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Validation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7, processorArchitecture=MSIL">
<HintPath>..\packages\Validation.2.0.6.15003\lib\portable-net40+sl50+win+wpa81+wp80+Xamarin.iOS10+MonoAndroid10+MonoTouch10\Validation.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Amount.cs" />
Expand Down Expand Up @@ -86,7 +92,10 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
1 change: 0 additions & 1 deletion Paymetheus.Bitcoin/TransactionRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ private static void CheckNonCoinbaseInputs(Transaction tx)
}
}

[Serializable]
public class TransactionRuleException : Exception
{
public TransactionRuleException(string message) : base(message) { }
Expand Down
13 changes: 9 additions & 4 deletions Paymetheus.Bitcoin/Util/Base58.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;

Expand Down Expand Up @@ -127,8 +126,15 @@ public static bool TryDecode(string encodedData, out byte[] decodedResult)
/// </summary>
/// <param name="value">The string to check.</param>
/// <returns>True iff the value is valid base58.</returns>
public static bool IsBase58Encoded(string value) =>
value.All(ch => ch < AsciiToDigitMap.Length && AsciiToDigitMap[ch] < Radix);
public static bool IsBase58Encoded(string value)
{
foreach (var ch in value)
{
if (!(ch < AsciiToDigitMap.Length && AsciiToDigitMap[ch] < Radix))
return false;
}
return true;
}

public static string Encode(byte[] value)
{
Expand Down Expand Up @@ -165,7 +171,6 @@ public static string Encode(byte[] value)
}
}

[Serializable]
public class Base58Exception : Exception
{
public Base58Exception(string message) : base(message) { }
Expand Down
1 change: 0 additions & 1 deletion Paymetheus.Bitcoin/Util/CompactInt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ private static ulong CanonicalCheck(ulong value, ulong minValue, byte discrimina
}
}

[Serializable]
public class CanonicalCompactIntException : Exception
{
public CanonicalCompactIntException(string message) : base(message) { }
Expand Down
1 change: 0 additions & 1 deletion Paymetheus.Bitcoin/Wallet/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public static bool TryFromOutputScript(OutputScript pkScript, BlockChainIdentity
}
}

[Serializable]
public class AddressException : Exception
{
public AddressException(string message) : base(message) { }
Expand Down
16 changes: 11 additions & 5 deletions Paymetheus.Bitcoin/Wallet/Checksum.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (c) 2016 The btcsuite developers
// Licensed under the ISC license. See LICENSE file in the project root for full license information.

using PCLCrypto;
using System;
using System.Security.Cryptography;
using System.IO;
using static PCLCrypto.WinRTCrypto;

namespace Paymetheus.Bitcoin.Wallet
{
Expand Down Expand Up @@ -63,10 +65,15 @@ public static void WriteSum(byte[] buffer)
private static byte[] Hash(byte[] value)
{
byte[] hash;
using (var hasher = SHA256.Create())
using (var hasher = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256).CreateHash())
{
var intermediateHash = hasher.ComputeHash(value, 0, value.Length - SumLength);
hash = hasher.ComputeHash(intermediateHash);
using (var stream = new CryptoStream(Stream.Null, hasher, CryptoStreamMode.Write))
{
stream.Write(value, 0, value.Length - SumLength);
}
var intermediateHash = hasher.GetValueAndReset();
hasher.Append(intermediateHash);
hash = hasher.GetValueAndReset();
}

if (hash.Length != Sha256Hash.Length || hash.Length < SumLength)
Expand All @@ -76,7 +83,6 @@ private static byte[] Hash(byte[] value)
}
}

[Serializable]
public class ChecksumException : Exception
{
public ChecksumException(string message) : base(message) { }
Expand Down
12 changes: 2 additions & 10 deletions Paymetheus.Bitcoin/Wallet/WalletSeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using Paymetheus.Bitcoin.Util;
using System;
using System.Security.Cryptography;
using static PCLCrypto.WinRTCrypto;

namespace Paymetheus.Bitcoin.Wallet
{
Expand All @@ -14,15 +14,7 @@ public static class WalletSeed
/// </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;
}
public static byte[] GenerateRandomSeed() => CryptographicBuffer.GenerateRandom(SeedLength);

/// <summary>
/// Decodes user input as either the hexadecimal or PGP word list encoding
Expand Down
2 changes: 2 additions & 0 deletions Paymetheus.Bitcoin/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Grpc.Tools" version="0.12.0" targetFramework="net45" />
<package id="PCLCrypto" version="1.0.86" targetFramework="portable45-net45+win8" />
<package id="Validation" version="2.0.6.15003" targetFramework="portable45-net45+win8" />
</packages>
6 changes: 4 additions & 2 deletions Paymetheus.Tests.Bitcoin/Paymetheus.Tests.Bitcoin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
<AssemblyName>Paymetheus.Tests.Bitcoin</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -33,6 +31,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="PCLCrypto, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d4421c8a4786956c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\PCLCrypto.1.0.86\lib\net40-Client\PCLCrypto.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down
2 changes: 1 addition & 1 deletion Paymetheus.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
VisualStudioVersion = 14.0.25008.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Paymetheus", "Paymetheus\Paymetheus.csproj", "{23FDCF32-22C6-4AC1-89CF-64B79A237CA3}"
EndProject
Expand Down
5 changes: 5 additions & 0 deletions Paymetheus/Paymetheus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="Validation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7, processorArchitecture=MSIL">
<HintPath>..\packages\Validation.2.0.6.15003\lib\portable-net40+sl50+win+wpa81+wp80+Xamarin.iOS10+MonoAndroid10+MonoTouch10\Validation.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
Expand Down Expand Up @@ -316,6 +320,7 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\app.manifest" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down
6 changes: 6 additions & 0 deletions Paymetheus/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Mono.Security" version="3.2.3.0" targetFramework="net45" />
<package id="PCLCrypto" version="1.0.86" targetFramework="net45" />
<package id="Validation" version="2.0.6.15003" targetFramework="net45" />
</packages>

0 comments on commit 5177a2e

Please sign in to comment.