Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Feature/standard Tezos key support
Browse files Browse the repository at this point in the history
  • Loading branch information
matsakiv committed Aug 13, 2021
1 parent 0f0882e commit 8d9f59c
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Atomex.Client.Core
Submodule Atomex.Client.Core updated 49 files
+6 −1 Atomex.Client.Core.Tests/BitcoinBased/BitcoinBasedCurrencyAccountSendTests.cs
+3 −3 Atomex.Client.Core.Tests/Tezos/TezosExtKeyTests.cs
+4 −2 Atomex.Client.Core/Blockchain/BitcoinBased/BitcoinBasedTransaction.cs
+4 −2 Atomex.Client.Core/Blockchain/Ethereum/EthereumTransaction.cs
+0 −74 Atomex.Client.Core/Blockchain/Tezos/Internal/Keys.cs
+2 −1 Atomex.Client.Core/Blockchain/Tezos/Internal/Prefix.cs
+4 −2 Atomex.Client.Core/Blockchain/Tezos/TezosTransaction.cs
+109 −17 Atomex.Client.Core/Common/AsyncHelpers.cs
+4 −3 Atomex.Client.Core/Common/WalletAddressExtensions.cs
+2 −2 Atomex.Client.Core/Core/CurrencyConfig.cs
+7 −9 Atomex.Client.Core/Core/WalletAddress.cs
+3 −2 Atomex.Client.Core/Cryptography/IKey.cs
+1 −1 Atomex.Client.Core/Currencies/BitcoinBasedConfig.cs
+3 −0 Atomex.Client.Core/Currencies/Currencies.cs
+1 −1 Atomex.Client.Core/Currencies/EthereumConfig.cs
+10 −2 Atomex.Client.Core/Currencies/TezosConfig.cs
+61 −2 Atomex.Client.Core/LiteDb/LiteDbAccountDataRepository.cs
+6 −5 Atomex.Client.Core/LiteDb/LiteDbMigrationManager.cs
+43 −2 Atomex.Client.Core/LiteDb/LiteDbMigrations.cs
+2 −2 Atomex.Client.Core/Swaps/Helpers/RewardForRedeemHelper.cs
+1 −1 Atomex.Client.Core/Swaps/SwapManager.cs
+4 −4 Atomex.Client.Core/Swaps/Tezos/FA12/FA12Swap.cs
+4 −4 Atomex.Client.Core/Swaps/Tezos/TezosSwap.cs
+45 −21 Atomex.Client.Core/Wallet/Abstract/CurrencyAccount.cs
+10 −1 Atomex.Client.Core/Wallet/Abstract/IAccountDataRepository.cs
+14 −3 Atomex.Client.Core/Wallet/Abstract/IHdWallet.cs
+9 −2 Atomex.Client.Core/Wallet/Abstract/IKeyStorage.cs
+8 −2 Atomex.Client.Core/Wallet/Abstract/ILegacyCurrencyAccount.cs
+2 −1 Atomex.Client.Core/Wallet/Abstract/KeyIndex.cs
+45 −1 Atomex.Client.Core/Wallet/AccountDataRepository.cs
+5 −2 Atomex.Client.Core/Wallet/Bip/Bip44.cs
+19 −0 Atomex.Client.Core/Wallet/BitcoinBased/BitcoinBasedAccount.cs
+5 −2 Atomex.Client.Core/Wallet/BitcoinBased/BitcoinBasedWalletScanner.cs
+16 −7 Atomex.Client.Core/Wallet/Ethereum/ERC20/ERC20Account.cs
+6 −1 Atomex.Client.Core/Wallet/Ethereum/ERC20/ERC20WalletScanner.cs
+2 −5 Atomex.Client.Core/Wallet/Ethereum/EthereumAccount.cs
+5 −2 Atomex.Client.Core/Wallet/Ethereum/EthereumWalletScanner.cs
+77 −161 Atomex.Client.Core/Wallet/HdKeyStorage.cs
+58 −26 Atomex.Client.Core/Wallet/HdWallet.cs
+367 −0 Atomex.Client.Core/Wallet/Tezos/Bip32TezosExtKey.cs
+4 −2 Atomex.Client.Core/Wallet/Tezos/FA12/FA12Account.cs
+4 −2 Atomex.Client.Core/Wallet/Tezos/FA2/FA2Account.cs
+6 −3 Atomex.Client.Core/Wallet/Tezos/TezosAccount.cs
+56 −199 Atomex.Client.Core/Wallet/Tezos/TezosExtKey.cs
+32 −17 Atomex.Client.Core/Wallet/Tezos/TezosTokenAccount.cs
+51 −5 Atomex.Client.Core/Wallet/Tezos/TezosTokensScanner.cs
+84 −14 Atomex.Client.Core/Wallet/Tezos/TezosWalletScanner.cs
+0 −220 Atomex.Client.Core/Wallet/Tezos/TrustWalletTezosExtKey.cs
+2 −58 Atomex.Client.Core/currencies.json
2 changes: 1 addition & 1 deletion Atomex.Client.Wpf.Installer/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<?define Name = "Atomex Client" ?>
<?define Manufacturer = "Atomex.me" ?>
<?define Description = "Multicurrency HD wallet with built-in hybrid exchange based on atomic swap." ?>
<?define Version = "1.1.0" ?>
<?define Version = "1.1.1" ?>
<?define UpgradeCode = "DB7FCF8D-E0C6-4C99-A6B1-3FB6D703F97E" ?>
<?define ExeName = "Atomex.Client.Wpf.exe" ?>

Expand Down
89 changes: 70 additions & 19 deletions Atomex.Client.Wpf/ViewModels/AddressesViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
Expand All @@ -16,18 +17,19 @@
using Atomex.Client.Wpf.Controls;
using Atomex.Wallet;
using Atomex.Wallet.Tezos;
using System.Collections.ObjectModel;
using Atomex.Cryptography;
using Atomex.Blockchain.Tezos.Internal;

namespace Atomex.Client.Wpf.ViewModels
{
public class AddressInfo
{
public string Address { get; set; }
public string Type { get; set; }
public string Path { get; set; }
public string Balance { get; set; }
//public string CurrencyCode { get; set; }
public string TokenBalance { get; set; }
//public string TokenCode { get; set; }

public Action<string> CopyToClipboard { get; set; }
public Action<string> OpenInExplorer { get; set; }
public Action<string> Update { get; set; }
Expand Down Expand Up @@ -65,7 +67,7 @@ public class AddressesViewModel : BaseViewModel
private CurrencyConfig _currency;
private bool _isBalanceUpdating;
private CancellationTokenSource _cancellation;
private string _tokenContract;
private readonly string _tokenContract;

public ObservableCollection<AddressInfo> Addresses { get; set; }
public bool HasTokens { get; set; }
Expand Down Expand Up @@ -117,23 +119,41 @@ public async void RealodAddresses()

addresses.Sort((a1, a2) =>
{
var typeResult = a1.KeyType.CompareTo(a2.KeyType);

if (typeResult != 0)
return typeResult;

var accountResult = a1.KeyIndex.Account.CompareTo(a2.KeyIndex.Account);

if (accountResult != 0)
return accountResult;

var chainResult = a1.KeyIndex.Chain.CompareTo(a2.KeyIndex.Chain);

return chainResult == 0
? a1.KeyIndex.Index.CompareTo(a2.KeyIndex.Index)
: chainResult;
return chainResult != 0
? chainResult
: a1.KeyIndex.Index.CompareTo(a2.KeyIndex.Index);
});

Addresses = new ObservableCollection<AddressInfo>(
addresses.Select(a => new AddressInfo
addresses.Select(a =>
{
Address = a.Address,
Path = $"m/44'/{_currency.Bip44Code}/0'/{a.KeyIndex.Chain}/{a.KeyIndex.Index}",
Balance = $"{a.Balance.ToString(CultureInfo.InvariantCulture)} {_currency.Name}",
CopyToClipboard = CopyToClipboard,
OpenInExplorer = OpenInExplorer,
Update = Update,
ExportKey = ExportKey
var path = a.KeyType == CurrencyConfig.StandardKey && Currencies.IsTezosBased(_currency.Name)
? $"m/44'/{_currency.Bip44Code}'/{a.KeyIndex.Account}'/{a.KeyIndex.Chain}'"
: $"m/44'/{_currency.Bip44Code}'/{a.KeyIndex.Account}'/{a.KeyIndex.Chain}/{a.KeyIndex.Index}";

return new AddressInfo
{
Address = a.Address,
Type = KeyTypeToString(a.KeyType),
Path = path,
Balance = $"{a.Balance.ToString(CultureInfo.InvariantCulture)} {_currency.Name}",
CopyToClipboard = CopyToClipboard,
OpenInExplorer = OpenInExplorer,
Update = Update,
ExportKey = ExportKey
};
}));

// token balances
Expand Down Expand Up @@ -183,6 +203,14 @@ public async void RealodAddresses()
}
}

private string KeyTypeToString(int keyType) =>
keyType switch
{
CurrencyConfig.StandardKey => "Standard",
TezosConfig.Bip32Ed25519Key => "Atomex",
_ => throw new NotSupportedException($"Key type {keyType} not supported.")
};

private void CopyToClipboard(string address)
{
try
Expand Down Expand Up @@ -282,14 +310,37 @@ private async void ExportKey(string address)

var hdWallet = _app.Account.Wallet as HdWallet;

using var privateKey = hdWallet.KeyStorage
.GetPrivateKey(_currency, walletAddress.KeyIndex);
using var privateKey = hdWallet.KeyStorage.GetPrivateKey(
currency: _currency,
keyIndex: walletAddress.KeyIndex,
keyType: walletAddress.KeyType);

using var unsecuredPrivateKey = privateKey.ToUnsecuredBytes();

var hex = Hex.ToHexString(unsecuredPrivateKey.Data);
if (Currencies.IsBitcoinBased(_currency.Name))
{
var btcBasedConfig = _currency as BitcoinBasedConfig;

var wif = new NBitcoin.Key(unsecuredPrivateKey)
.GetWif(btcBasedConfig.Network)
.ToWif();

Clipboard.SetText(wif);
}
else if (Currencies.IsTezosBased(_currency.Name))
{
var base58 = unsecuredPrivateKey.Length == 32
? Base58Check.Encode(unsecuredPrivateKey, Prefix.Edsk)
: Base58Check.Encode(unsecuredPrivateKey, Prefix.EdskSecretKey);

Clipboard.SetText(base58);
}
else
{
var hex = Hex.ToHexString(unsecuredPrivateKey.Data);

Clipboard.SetText(hex);
Clipboard.SetText(hex);
}

Warning = "Private key successfully copied to clipboard.";
}
Expand Down
6 changes: 4 additions & 2 deletions Atomex.Client.Wpf/ViewModels/DelegateConfirmationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ await tezosAccount.AddressLocker
OperationType = OperationType.Delegation
};

using var securePublicKey = App.Account.Wallet
.GetPublicKey(Currency, WalletAddress.KeyIndex);
using var securePublicKey = App.Account.Wallet.GetPublicKey(
currency: Currency,
keyIndex: WalletAddress.KeyIndex,
keyType: WalletAddress.KeyType);

await tx.FillOperationsAsync(
securePublicKey: securePublicKey,
Expand Down
6 changes: 4 additions & 2 deletions Atomex.Client.Wpf/ViewModels/DelegateViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,10 @@ private async Task<Result<string>> GetDelegate(
.GetAddressAsync(_selectedAddress.Address)
.WaitForResult();

using var securePublicKey = App.Account.Wallet
.GetPublicKey(_tezosConfig, walletAddress.KeyIndex);
using var securePublicKey = App.Account.Wallet.GetPublicKey(
currency: _tezosConfig,
keyIndex: walletAddress.KeyIndex,
keyType: walletAddress.KeyType);

var isSuccess = await tx.FillOperationsAsync(
securePublicKey: securePublicKey,
Expand Down
4 changes: 4 additions & 0 deletions Atomex.Client.Wpf/Views/AddressesView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Type"
Binding="{Binding Type}"
Width="Auto"
FontSize="12"/>
<DataGridTextColumn Header="Path"
Binding="{Binding Path}"
Width="Auto"
Expand Down
2 changes: 1 addition & 1 deletion Atomex.Client.Wpf/Views/SendViews/TezosTokensSendPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
mc:Ignorable="d"
UseLayoutRounding="True"
Focusable="False"
d:DesignHeight="500"
d:DesignHeight="550"
d:DesignWidth="640"
d:DataContext="{d:DesignInstance Type=viewModels:TezosTokensSendViewModel, IsDesignTimeCreatable=True}">

Expand Down

0 comments on commit 8d9f59c

Please sign in to comment.