mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-18 08:04:26 +01:00
ws: remove aff server
This commit is contained in:
@@ -37,7 +37,7 @@
|
||||
<PackageReference Include="AsyncKeyedLock" Version="6.2.6" />
|
||||
<PackageReference Include="FlexLabs.EntityFrameworkCore.Upsert" Version="8.0.0" />
|
||||
<PackageReference Include="Laraue.EfCoreTriggers.PostgreSql" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.8.0" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.9.2" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,146 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Mime;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Abstractions.Constants;
|
||||
using BTCPayServer.Client;
|
||||
using BTCPayServer.Configuration;
|
||||
using BTCPayServer.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NBitcoin.DataEncoders;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serilog.Core;
|
||||
using WalletWasabi.Affiliation;
|
||||
using WalletWasabi.Affiliation.Models;
|
||||
using WalletWasabi.Affiliation.Models.CoinJoinNotification;
|
||||
using WalletWasabi.Affiliation.Serialization;
|
||||
using Constants = WalletWasabi.Helpers.Constants;
|
||||
|
||||
namespace BTCPayServer.Plugins.Wabisabi.AffiliateServer;
|
||||
|
||||
public class WabisabiAffiliateSettings
|
||||
{
|
||||
public bool Enabled { get; set; }
|
||||
public string SigningKey { get; set; }
|
||||
|
||||
|
||||
}
|
||||
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||
[Authorize(Policy = Policies.CanModifyServerSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||
[Route("plugins/wabisabi-affiliate")]
|
||||
public class AffiliateServerController:Controller
|
||||
{
|
||||
private readonly SettingsRepository _settingsRepository;
|
||||
private readonly IOptions<DataDirectories> _dataDirectories;
|
||||
private readonly ILogger<AffiliateServerController> _logger;
|
||||
|
||||
public AffiliateServerController(SettingsRepository settingsRepository, IOptions<DataDirectories> dataDirectories, ILogger<AffiliateServerController> logger)
|
||||
{
|
||||
_settingsRepository = settingsRepository;
|
||||
_dataDirectories = dataDirectories;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet("edit")]
|
||||
public async Task<IActionResult> Edit()
|
||||
{
|
||||
var settings =
|
||||
await _settingsRepository.GetSettingAsync<WabisabiAffiliateSettings>();
|
||||
return View(settings);
|
||||
}
|
||||
[HttpPost("edit")]
|
||||
public async Task<IActionResult> Edit(WabisabiAffiliateSettings settings)
|
||||
{
|
||||
await _settingsRepository.UpdateSetting(settings);
|
||||
return RedirectToAction("Edit");
|
||||
}
|
||||
[HttpGet("history")]
|
||||
public async Task<IActionResult> ViewRequests()
|
||||
{
|
||||
|
||||
var path = Path.Combine(_dataDirectories.Value.DataDir, "Plugins", "CoinjoinAffiliate", $"History{DateTime.Today:dd_MM_yyyy}.txt");
|
||||
if (!System.IO.File.Exists(path))
|
||||
return NotFound();
|
||||
|
||||
return PhysicalFile(path, MediaTypeNames.Text.Plain);
|
||||
}
|
||||
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("get_status")]
|
||||
[HttpGet("get_status")]
|
||||
public async Task<IActionResult> GetStatus()
|
||||
{
|
||||
_logger.LogTrace("GetStatus Called");
|
||||
var settings =
|
||||
await _settingsRepository.GetSettingAsync<WabisabiAffiliateSettings>();
|
||||
if(settings?.Enabled is true&& !string.IsNullOrEmpty(settings.SigningKey))
|
||||
return Ok(new { });
|
||||
return NotFound();
|
||||
|
||||
}
|
||||
|
||||
private static ECDsa ecdsa = ECDsa.Create();
|
||||
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("notify_coinjoin")]
|
||||
[HttpGet("notify_coinjoin")]
|
||||
public async Task<IActionResult> GetCoinjoinRequest()
|
||||
{
|
||||
|
||||
_logger.LogTrace("notify_coinjoin Called");
|
||||
var settings = await _settingsRepository.GetSettingAsync<WabisabiAffiliateSettings>();
|
||||
if (settings?.Enabled is not true)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
var keyB = Encoders.Hex.DecodeData(settings.SigningKey);
|
||||
ecdsa.ImportSubjectPublicKeyInfo(keyB.AsSpan(), out _);
|
||||
|
||||
using var reader = new StreamReader(Request.Body);
|
||||
var request =
|
||||
AffiliateServerHttpApiClient.Deserialize<CoinJoinNotificationRequest>(await reader.ReadToEndAsync());
|
||||
if (request.Body.Inputs.All(input => !input.IsAffiliated))
|
||||
{
|
||||
var response = new CoinJoinNotificationResponse(Array.Empty<byte>());
|
||||
return Json(response, AffiliationJsonSerializationOptions.Settings);
|
||||
}
|
||||
|
||||
Payload payload = new(Header.Create(AffiliationConstants.NonDefaultAffiliationId), request.Body);
|
||||
try
|
||||
{
|
||||
|
||||
var valid = ecdsa.VerifyData(payload.GetCanonicalSerialization(), request.Signature, HashAlgorithmName.SHA256);
|
||||
if (!valid)
|
||||
{
|
||||
|
||||
_logger.LogError($"Invalid coinjoin request sent\n{payload.GetCanonicalSerialization()}\n{request.Signature}" );
|
||||
return NotFound();
|
||||
}
|
||||
var path = Path.Combine(_dataDirectories.Value.DataDir, "Plugins", "CoinjoinAffiliate", $"History{DateTime.Today:dd_MM_yyyy}.txt");
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
await System.IO.File.AppendAllLinesAsync(path, new[] {JObject.FromObject(request, JsonSerializer.Create(AffiliationJsonSerializationOptions.Settings) ).ToString(Formatting.None).Replace(Environment.NewLine, "")}, Encoding.UTF8);
|
||||
var response = new CoinJoinNotificationResponse(Array.Empty<byte>());
|
||||
return Json(response, AffiliationJsonSerializationOptions.Settings);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Failed on GetCoinjoinRequest" );
|
||||
return NotFound();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
@using Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@model BTCPayServer.Plugins.Wabisabi.AffiliateServer.WabisabiAffiliateSettings
|
||||
@{
|
||||
Layout = "../Shared/_NavLayout.cshtml";
|
||||
ViewData["NavPartialName"] = "../UIServer/_Nav";
|
||||
}
|
||||
|
||||
<h2 class="mb-4">Coinjoin affiliate configuration</h2>
|
||||
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-xxl-constrain col-xl-8">
|
||||
<div class="form-group form-check">
|
||||
<label asp-for="Enabled" class="form-check-label">Enable </label>
|
||||
<input asp-for="Enabled" type="checkbox" class="form-check-input"/>
|
||||
</div>
|
||||
|
||||
<div class="form-group pt-3">
|
||||
<label class="form-label" for="config">Coordinator Key</label>
|
||||
|
||||
<input type="text" class="form-control " asp-for="SigningKey">
|
||||
</input>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button name="command" type="submit" value="save" class="btn btn-primary mt-2">Save</button>
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
@section PageFootContent {
|
||||
<partial name="_ValidationScriptsPartial"/>
|
||||
}
|
||||
Reference in New Issue
Block a user