Initial version
This commit is contained in:
commit
e5b6226a85
68 changed files with 7338 additions and 0 deletions
21
DataTransfer.Client/Services/BotCheckSolver.cs
Normal file
21
DataTransfer.Client/Services/BotCheckSolver.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using DataTransfer.Client.Shared;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace DataTransfer.Client.Services;
|
||||
|
||||
/// <summary>Solves the server's proof-of-work bot check in web workers (<c>wwwroot/js/bot-check.js</c> of the server).</summary>
|
||||
public sealed class BotCheckSolver(IJSRuntime js, NavigationManager navigation)
|
||||
{
|
||||
/// <returns>The solution, or <c>-1</c> if none was found.</returns>
|
||||
public async Task<int> SolveAsync(BotCheckChallenge challenge)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(challenge);
|
||||
|
||||
// An absolute URL, so the module resolves relative to the app's base URI under any path base.
|
||||
await using var module = await js.InvokeAsync<IJSObjectReference>(
|
||||
"import",
|
||||
navigation.ToAbsoluteUri("js/bot-check.js").ToString());
|
||||
return await module.InvokeAsync<int>("solve", challenge.Salt, challenge.Hash, challenge.MaxNumber);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue