using Svrnty.CQRS.Abstractions; using Svrnty.CQRS.Altcha.Abstractions; namespace Svrnty.Sample; // Exercises the ICommandAuthorizationCheck seam at runtime. // The command is decorated with [Altcha] and carries the solution // through IHasAltchaSolution. With Svrnty.CQRS.Altcha + a registered // IAltchaVerifier, the framework's check pipeline reads the field, // calls the verifier, and short-circuits on failure. [Altcha] public sealed class ProtectedActionCommand : IHasAltchaSolution { public string Action { get; set; } = string.Empty; public string? AltchaSolution { get; set; } } public sealed class ProtectedActionCommandHandler : ICommandHandler { public Task HandleAsync(ProtectedActionCommand command, CancellationToken cancellationToken = default) { return Task.FromResult($"executed:{command.Action}"); } } // Stub verifier that doesn't talk to an external altcha service — // enough to exercise the check pipeline in isolation. Treats the // literal string "valid-solution" as a passing PoW solution. public sealed class StubAltchaVerifier : IAltchaVerifier { public Task VerifyAsync(string payload, CancellationToken cancellationToken = default) { if (payload == "valid-solution") return Task.FromResult(AltchaVerifyResult.Success); return Task.FromResult(AltchaVerifyResult.Fail("stub-rejected")); } }