< Summary

Information
Class: NostrSure.Domain.Services.EventIdValidator
Assembly: NostrSure.Domain
File(s): /home/runner/work/NostrSure/NostrSure/NostrSure.Domain/Services/EventIdValidator.cs
Line coverage
100%
Covered lines: 24
Uncovered lines: 0
Coverable lines: 24
Total lines: 47
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ValidateEventIdAsync(...)100%11100%
ValidateEventId(...)100%22100%

File(s)

/home/runner/work/NostrSure/NostrSure/NostrSure.Domain/Services/EventIdValidator.cs

#LineLine coverage
 1using NostrSure.Domain.Entities;
 2using NostrSure.Domain.Validation;
 3
 4namespace NostrSure.Domain.Services;
 5
 6/// <summary>
 7/// Validates event IDs against calculated hashes according to NIP-01
 8/// </summary>
 9public sealed class EventIdValidator : IEventIdValidator
 10{
 11    private readonly IEventIdCalculator _eventIdCalculator;
 12
 1813    public EventIdValidator(IEventIdCalculator eventIdCalculator)
 1814    {
 1815        _eventIdCalculator = eventIdCalculator;
 1816    }
 17
 18    public Task<ValidationResult> ValidateEventIdAsync(NostrEvent evt, CancellationToken cancellationToken = default)
 10319    {
 10320        var result = ValidateEventId(evt);
 10321        return Task.FromResult(result);
 10322    }
 23
 24    public ValidationResult ValidateEventId(NostrEvent evt)
 10825    {
 26        try
 10827        {
 10828            var calculatedId = _eventIdCalculator.CalculateEventId(evt);
 29
 10730            if (evt.Id != calculatedId)
 131            {
 132                return ValidationResult.Failure(
 133                    $"Event ID mismatch. Expected: {calculatedId}, Got: {evt.Id}",
 134                    "EVENT_ID_MISMATCH");
 35            }
 36
 10637            return ValidationResult.Success();
 38        }
 139        catch (System.Exception ex)
 140        {
 141            return ValidationResult.Failure(
 142                $"Exception during event ID validation: {ex.Message}",
 143                ex,
 144                ValidationSeverity.Critical);
 45        }
 10846    }
 47}