Add relay directory crawler#86
Conversation
📝 WalkthroughWalkthroughA new Node.js script ChangesNostr Relay Directory Crawler
Sequence Diagram(s)sequenceDiagram
participant CLI
participant runCrawler
participant queryRelayPool
participant fetchTweet
participant checkZapSupport
participant computeWotScores
participant FileSystem
CLI->>runCrawler: parsed args
runCrawler->>queryRelayPool: REQ kinds 10011 + 0
queryRelayPool-->>runCrawler: de-duplicated events
runCrawler->>runCrawler: extractDirectoryInputs → candidates, claimed
loop each candidate
runCrawler->>fetchTweet: proofTweetId (X API / syndication / oEmbed)
fetchTweet-->>runCrawler: tweet text + author handle
runCrawler->>runCrawler: verifyCandidate → verified / rejected
end
runCrawler->>queryRelayPool: backfill kind:0 for verified authors
loop each verified record
runCrawler->>checkZapSupport: lud16 → LNURLp → allowsNostr
checkZapSupport-->>runCrawler: zapSupport result
end
runCrawler->>computeWotScores: directory records + all events
computeWotScores-->>runCrawler: records with wot scores
runCrawler->>FileSystem: write JSON output
runCrawler-->>CLI: stdout summary
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
scripts/relay-directory-crawler.test.mjs (1)
102-117: 💤 Low valueTest event has invalid signature and will be skipped by
computeWotScores.The mock event uses
sig: 'invalid-for-test'butcomputeWotScorescallsisValidSignedEvent(event)on line 493 and skips events that fail signature verification. This means the follow event is never counted, sowot.followerGraphMentionswill be 0.The test still passes because it only asserts that identity fields are preserved and
wot.noteexists, but it doesn't actually test that follower counting works.Consider either:
- Removing the signature validation in
computeWotScores(WoT is advisory, not security-critical)- Or adding a test with properly signed events (more complex)
- Or accepting that this test only verifies field preservation, not scoring logic
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@scripts/relay-directory-crawler.test.mjs` around lines 102 - 117, The mock follow event in the test uses an invalid signature ('invalid-for-test') which causes computeWotScores to skip event validation when it calls isValidSignedEvent() on line 493, meaning the follow event is never counted in the WoT scoring. To fix this, either remove the signature validation check in computeWotScores since WoT scoring is advisory and not security-critical, or provide a properly signed event in the test. Choose the first option if WoT verification should not be security-critical for advisory purposes, or the second if signature validation must remain but the test needs to demonstrate actual scoring logic by using a valid signature.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/relay-directory-crawler.mjs`:
- Around line 53-54: The argument parsing for `--kind10011-limit` and
`--kind0-limit` converts the input values using `Number()` but does not validate
them, allowing `NaN` values to propagate into the relay query logic. Add
validation checks after parsing these arguments (similar to how `timeoutMs` and
`maxProofs` are validated) to ensure the converted numbers are valid and non-NaN
before assigning them to `args.kind10011Limit` and `args.kind0Limit`. If
validation fails, either log an error message or set a sensible default value to
prevent invalid `limit` values from being used in relay queries.
---
Nitpick comments:
In `@scripts/relay-directory-crawler.test.mjs`:
- Around line 102-117: The mock follow event in the test uses an invalid
signature ('invalid-for-test') which causes computeWotScores to skip event
validation when it calls isValidSignedEvent() on line 493, meaning the follow
event is never counted in the WoT scoring. To fix this, either remove the
signature validation check in computeWotScores since WoT scoring is advisory and
not security-critical, or provide a properly signed event in the test. Choose
the first option if WoT verification should not be security-critical for
advisory purposes, or the second if signature validation must remain but the
test needs to demonstrate actual scoring logic by using a valid signature.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ac3557d2-3269-4cae-9df8-6143f6b05aeb
📒 Files selected for processing (3)
package.jsonscripts/relay-directory-crawler.mjsscripts/relay-directory-crawler.test.mjs
| else if (arg === '--kind10011-limit') args.kind10011Limit = Number(next()); | ||
| else if (arg === '--kind0-limit') args.kind0Limit = Number(next()); |
There was a problem hiding this comment.
Missing validation for --kind10011-limit and --kind0-limit.
These numeric arguments are parsed with Number() but not validated like timeoutMs and maxProofs. If invalid values are passed, they become NaN and propagate to the relay query's limit field.
Proposed fix
if (!args.relays.length) throw new Error('At least one relay is required.');
if (!Number.isFinite(args.timeoutMs) || args.timeoutMs <= 0) throw new Error('--timeout-ms must be positive.');
if (!Number.isFinite(args.maxProofs) || args.maxProofs < 0) throw new Error('--max-proofs must be >= 0.');
+ if (!Number.isFinite(args.kind10011Limit) || args.kind10011Limit <= 0) throw new Error('--kind10011-limit must be positive.');
+ if (!Number.isFinite(args.kind0Limit) || args.kind0Limit <= 0) throw new Error('--kind0-limit must be positive.');
return args;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@scripts/relay-directory-crawler.mjs` around lines 53 - 54, The argument
parsing for `--kind10011-limit` and `--kind0-limit` converts the input values
using `Number()` but does not validate them, allowing `NaN` values to propagate
into the relay query logic. Add validation checks after parsing these arguments
(similar to how `timeoutMs` and `maxProofs` are validated) to ensure the
converted numbers are valid and non-NaN before assigning them to
`args.kind10011Limit` and `args.kind0Limit`. If validation fails, either log an
error message or set a sensible default value to prevent invalid `limit` values
from being used in relay queries.
Summary'
the relay crawler:
kind:10011andkind:0Trust model
Tests
Summary by CodeRabbit
New Features
crawl:directory) for building a verified mapping of X/Twitter handles to Nostr identities with proof verification, Lightning zap support detection, and Web-of-Trust scoring.Tests