Feat: addition of nip-05 verification (issue #261)#463
Open
archief2910 wants to merge 7 commits intocameri:mainfrom
Open
Feat: addition of nip-05 verification (issue #261)#463archief2910 wants to merge 7 commits intocameri:mainfrom
archief2910 wants to merge 7 commits intocameri:mainfrom
Conversation
Author
|
@phoenix-server @cameri This pr is ready for review and checks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR implements NIP-05 verification as a spam reduction mechanism for nostream, as described in the nostr-rs-relay reference configuration.
Changes included:
NIP-05 Verification Core:
Nip05VerificationandDBNip05Verificationtypes for application and database layers.Nip05Settingsinterface with three operational modes:enabled(require NIP-05 for publishing),passive(validate without blocking), anddisabled(no-op).parseNip05Identifier,extractNip05FromEvent,verifyNip05Identifier, andisDomainAllowedutility functions conforming to the NIP-05 protocol (https://<domain>/.well-known/nostr.json?name=<local>).Nip05VerificationRepositoryfollowing the existing repository pattern with RamdaapplySpecDB-to-app mapping.nip05_verificationstable with indexes ondomain,is_verified, andlast_checked_at.Event Handler Integration:
checkNip05VerificationintoEventMessageHandlerpipeline — blocks unverified authors when mode isenabled, always allows kind-0 (SET_METADATA) events through so users can set their NIP-05 identifier.processNip05Metadataas fire-and-forget async verification triggered on successful kind-0 event persistence. Deletes verification records when a user removes their NIP-05 from metadata.Background Re-verification:
processNip05ReverificationstoMaintenanceWorker— periodically re-checks stale verifications respectingverifyUpdateFrequencyandmaxConsecutiveFailuressettings with jittered delays between requests.Configuration:
nip05section todefault-settings.yamlwith defaults matching nostr-rs-relay: 1 week expiration, 24-hour update frequency, 20 max consecutive failures.CONFIGURATION.mdwith documentation for all six settings.Factory Wiring:
Nip05VerificationRepositorythroughworkerFactory→webSocketAdapterFactory→messageHandlerFactory→EventMessageHandlerandmaintenanceWorkerFactory→MaintenanceWorkeras a required dependency.Cleanup:
import from '../constants/base'lines inevent-message-handler.ts.sinonChaiimport from NIP-05 utility test file.Related Issue
Closes #261
Motivation and Context
Spam is a persistent problem for public Nostr relays. NIP-05 verification provides a DNS-based identity layer that ties pubkeys to domain names, allowing relay operators to require that event authors have a verifiable internet identity. This is the same approach implemented by nostr-rs-relay and requested in issue #261. The three-mode system (
enabled/passive/disabled) gives operators full control over enforcement level without requiring code changes.How Has This Been Tested?
parseNip05Identifier: 12 tests — valid identifiers, subdomains, case normalization, edge cases (null, empty, missing @, no TLD).extractNip05FromEvent: 6 tests — valid kind-0, wrong kind, missing field, bad JSON, empty string, non-string value.isDomainAllowed: 8 tests — whitelist, blacklist, empty lists, case-insensitivity, blacklist-over-whitelist precedence.checkNip05Verification: 12 tests — all three modes, relay pubkey bypass, kind-0 passthrough, missing/expired/unverified records, domain whitelist/blacklist filtering.processNip05Metadata: 10 tests — disabled/passive modes, non-kind-0, delete on missing NIP-05, unparseable identifier, blocked domain, successful/failed verification with upsert assertions, error handling, passive mode verification.processNip05Reverifications: 9 tests — disabled mode, no pending records, success/failure state updates, failure count increment, error resilience across batch, custom config values, undefined fallback defaults, passive mode operation.message-handler-factory.spec.ts,websocket-adapter-factory.spec.ts) for the new required repository parameter.--noEmit.Screenshots (if appropriate):
N/A
Types of changes
Checklist: