using DataTransfer.Client.Shared; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; namespace DataTransfer.Client.Services; /// Solves the server's proof-of-work bot check in web workers (wwwroot/js/bot-check.js of the server). public sealed class BotCheckSolver(IJSRuntime js, NavigationManager navigation) { /// The solution, or -1 if none was found. public async Task 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( "import", navigation.ToAbsoluteUri("js/bot-check.js").ToString()); return await module.InvokeAsync("solve", challenge.Salt, challenge.Hash, challenge.MaxNumber); } }