Make mixer network agnostic
MODIFY
HiddenWallet.Daemon/Controllers/TumblerController.cs
HiddenWallet.Daemon/Controllers/TumblerController.cs
@@ -101,8 +101,8 @@ namespace HiddenWallet.Daemon.Controllers
for (int i = 0; i < request.RoundCount; i++)
{
IEnumerable<Script> unusedOutputs = await Global.WalletWrapper.WalletJob.GetUnusedScriptPubKeysAsync(AddressType.Pay2WitnessPublicKeyHash, toAccount, HdPathType.NonHardened);
- BitcoinAddress activeOutput = unusedOutputs.RandomElement().GetDestinationAddress(Global.WalletWrapper.Network); // TODO: this is sub-optimal, it'd be better to not which had been already registered and not reregister it
- BitcoinWitPubKeyAddress bech32 = new BitcoinWitPubKeyAddress(activeOutput.ToString(), Global.WalletWrapper.Network);
+ BitcoinAddress activeOutput = unusedOutputs.RandomElement().GetDestinationAddress(Global.WalletWrapper.WalletJob.CurrentNetwork); // TODO: this is sub-optimal, it'd be better to not which had been already registered and not reregister it
+ BitcoinWitPubKeyAddress bech32 = new BitcoinWitPubKeyAddress(activeOutput.ToString(), Global.WalletWrapper.WalletJob.CurrentNetwork);
uint256 txid = null;
try

MODIFY
HiddenWallet.Daemon/Controllers/WalletController.cs
HiddenWallet.Daemon/Controllers/WalletController.cs
@@ -243,7 +243,7 @@ namespace HiddenWallet.Daemon.Controllers
BitcoinAddress address;
try
{
- address = BitcoinAddress.Create(request.Address, Global.WalletWrapper.Network);
+ address = BitcoinAddress.Create(request.Address, Global.WalletWrapper.WalletJob.CurrentNetwork);
}
catch (Exception)
{
@@ -317,7 +317,7 @@ namespace HiddenWallet.Daemon.Controllers
BitcoinAddress address;
try
{
- address = BitcoinAddress.Create(request.Address, Global.WalletWrapper.Network);
+ address = BitcoinAddress.Create(request.Address, Global.WalletWrapper.WalletJob.CurrentNetwork);
}
catch (Exception)
{

MODIFY
HiddenWallet.Daemon/Global.cs
HiddenWallet.Daemon/Global.cs
@@ -12,6 +12,5 @@ namespace HiddenWallet.Daemon
{
public static WalletWrapper WalletWrapper;
public static Config Config;
- public static BlindingRsaPubKey RsaPubKey;
}
}

MODIFY
HiddenWallet.Daemon/Program.cs
HiddenWallet.Daemon/Program.cs
@@ -26,30 +26,6 @@ namespace HiddenWallet.Daemon
Global.Config = new Config();
await Global.Config.LoadOrCreateDefaultFileAsync(configFilePath, CancellationToken.None);
- string rsaPath;
- if (Global.Config.Network == Network.Main)
- {
- rsaPath = Path.Combine(FullSpvWallet.Global.DataDir, "RsaPubKeyMain.json");
- }
- else
- {
- rsaPath = Path.Combine(FullSpvWallet.Global.DataDir, "RsaPubKeyTestNet.json");
- }
- if (File.Exists(rsaPath))
- {
- string rsaPubKeyJson = await File.ReadAllTextAsync(rsaPath, Encoding.UTF8);
- Global.RsaPubKey = BlindingRsaPubKey.CreateFromJson(rsaPubKeyJson);
- }
- else
- {
- // TODO: change these default values to the default testnet and mainnet server's keys
- var modulus = new BigInteger("23765292524202909590312633661559508105372542245888884022732405845352867619510400148700590630819909854245443768683013002454300998561366066863075543900854183218255556958603829744574143217473373221883959779439395079947766381668459828953701726054394843911847063235903761918014727346563249795000296937701840334243492972569641205615480654015909880231725449975599905030093854844840930446509242634799081158992191062980583060919718404098183279802755923836822248873360647411342760279712271227024615021525054883324946175934075264032794034681653369283673040524060792800105336875314739176592340110027306283977215862005685674572993");
- var exponent = new BigInteger("65537");
- Global.RsaPubKey = new BlindingRsaPubKey(modulus, exponent);
- await File.WriteAllTextAsync(rsaPath, Global.RsaPubKey.ToJson(), Encoding.UTF8);
- Console.WriteLine($"Created RSA key at: {rsaPath}");
- }
-
var endPoint = "http://localhost:37120/";
var alreadyRunning = false;
using (var client = new HttpClient())

MODIFY
HiddenWallet.Daemon/Wrappers/WalletWrapper.cs
HiddenWallet.Daemon/Wrappers/WalletWrapper.cs
@@ -17,6 +17,9 @@ using static HiddenWallet.FullSpv.WalletJob;
using DotNetTor.SocksPort;
using HiddenWallet.FullSpv.Fees;
using HiddenWallet.SharedApi.Models;
+using HiddenWallet.Crypto;
+using System.Text;
+using Org.BouncyCastle.Math;
namespace HiddenWallet.Daemon.Wrappers
{
@@ -37,8 +40,6 @@ namespace HiddenWallet.Daemon.Wrappers
public bool WalletExists => File.Exists(Global.Config.WalletFilePath);
public bool IsDecrypted => !_walletJobTask.IsCompleted && _password != null;
- public Network Network => WalletJob.Safe.Network;
-
private Money _availableAlice = Money.Zero;
private Money _availableBob = Money.Zero;
private Money _incomingAlice = Money.Zero;
@@ -106,19 +107,48 @@ namespace HiddenWallet.Daemon.Wrappers
_walletJobTask = WalletJob.StartAsync(_cts.Token);
await UpdateHistoryRelatedMembersAsync();
+ await InitializeCoinJoinServiceAsync(network);
+ }
+ }
+
+ private async Task InitializeCoinJoinServiceAsync(Network network)
+ {
+ string rsaPath;
+ if (network == Network.Main)
+ {
+ rsaPath = Path.Combine(FullSpvWallet.Global.DataDir, "RsaPubKeyMain.json");
+ }
+ else
+ {
+ rsaPath = Path.Combine(FullSpvWallet.Global.DataDir, "RsaPubKeyTestNet.json");
+ }
+ BlindingRsaPubKey rsaPubKey;
+ if (File.Exists(rsaPath))
+ {
+ string rsaPubKeyJson = await File.ReadAllTextAsync(rsaPath, Encoding.UTF8);
+ rsaPubKey = BlindingRsaPubKey.CreateFromJson(rsaPubKeyJson);
+ }
+ else
+ {
+ // TODO: change these default values to the default testnet and mainnet server's keys
+ var modulus = new BigInteger("23765292524202909590312633661559508105372542245888884022732405845352867619510400148700590630819909854245443768683013002454300998561366066863075543900854183218255556958603829744574143217473373221883959779439395079947766381668459828953701726054394843911847063235903761918014727346563249795000296937701840334243492972569641205615480654015909880231725449975599905030093854844840930446509242634799081158992191062980583060919718404098183279802755923836822248873360647411342760279712271227024615021525054883324946175934075264032794034681653369283673040524060792800105336875314739176592340110027306283977215862005685674572993");
+ var exponent = new BigInteger("65537");
+ rsaPubKey = new BlindingRsaPubKey(modulus, exponent);
+ await File.WriteAllTextAsync(rsaPath, rsaPubKey.ToJson(), Encoding.UTF8);
+ Console.WriteLine($"Created RSA key at: {rsaPath}");
+ }
- if (Network == Network.Main)
+ if (network == Network.Main)
{
- WalletJob.CoinJoinService.SetConnection(Global.Config.ChaumianTumblerMainAddress, Global.Config.ChaumianTumblerMainNotificationAddress, Global.RsaPubKey, Tor.SocksPortHandler, disposeHandler: false);
+ WalletJob.CoinJoinService.SetConnection(Global.Config.ChaumianTumblerMainAddress, Global.Config.ChaumianTumblerMainNotificationAddress, rsaPubKey, Tor.SocksPortHandler, disposeHandler: false);
}
else
{
- WalletJob.CoinJoinService.SetConnection(Global.Config.ChaumianTumblerTestNetAddress, Global.Config.ChaumianTumblerTestNetNotificationAddress, Global.RsaPubKey, Tor.SocksPortHandler, disposeHandler: false);
+ WalletJob.CoinJoinService.SetConnection(Global.Config.ChaumianTumblerTestNetAddress, Global.Config.ChaumianTumblerTestNetNotificationAddress, rsaPubKey, Tor.SocksPortHandler, disposeHandler: false);
}
await WalletJob.CoinJoinService.SubscribeNotificationsAsync();
}
- }
private async void WalletWrapper_BestHeightChangedAsync(object sender, Height height)
{
@@ -435,7 +465,7 @@ namespace HiddenWallet.Daemon.Wrappers
inputs.Add(new TransactionInputModel
{
Amount = coin.Amount.ToString(false, true),
- Address = coin.ScriptPubKey.GetDestinationAddress(Network).ToString(),
+ Address = coin.ScriptPubKey.GetDestinationAddress(WalletJob.CurrentNetwork).ToString(),
Hash = coin.Outpoint.Hash.ToString(),
Index = (int)coin.Outpoint.N
});
@@ -447,9 +477,9 @@ namespace HiddenWallet.Daemon.Wrappers
Fee = result.Fee.ToString(false, true),
FeePercentOfSent = result.FeePercentOfSent.ToString("0.##"),
Hex = result.Transaction.ToHex(),
- ActiveOutputAddress = result.ActiveOutput.ScriptPubKey.GetDestinationAddress(Network).ToString(),
+ ActiveOutputAddress = result.ActiveOutput.ScriptPubKey.GetDestinationAddress(WalletJob.CurrentNetwork).ToString(),
ActiveOutputAmount = result.ActiveOutput.Value.ToString(false, true),
- ChangeOutputAddress = result.ChangeOutput?.ScriptPubKey?.GetDestinationAddress(Network)?.ToString() ?? "",
+ ChangeOutputAddress = result.ChangeOutput?.ScriptPubKey?.GetDestinationAddress(WalletJob.CurrentNetwork)?.ToString() ?? "",
ChangeOutputAmount = result.ChangeOutput?.Value?.ToString(false, true) ?? "0",
NumberOfInputs = result.SpentCoins.Count(),
Inputs = inputs.ToArray(),

Make mixer network agnostic