Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sandwichfarm/nostr-watch/llms.txt
Use this file to discover all available pages before exploring further.
@nostrwatch/nocap is the primary relay-probing engine in the nostr-watch monorepo. It checks Nostr relay health across five dimensions — WebSocket open/read/write connectivity, DNS resolution, TLS certificate validity, NIP-11 info document retrieval, and geolocation — using a pluggable adapter architecture that keeps check orchestration separate from check implementation. This means you can swap how DNS is resolved, how SSL is checked, or how WebSocket connections work without changing any application code.
Installation
Node.js >=18 and pnpm >=9 are required.
@nostrwatch/websocket must also be available as a peer dependency in your consuming package.Quick start
Nocap class
The Nocap class handles check orchestration, result collection, and timeout management. Adapters supply the actual check implementations.
Constructor
A valid
wss:// or ws:// WebSocket URL for the relay to check.Optional configuration. May include timeout settings and logging configuration.
Methods
useAdapter(Adapter)
Registers a single adapter class. The adapter’s static type property determines which check dimension it handles. Throws if an adapter of that type has already been registered.
useAdapters(Adapters)
Registers multiple adapter classes in one call. Accepts either an array of adapter classes or a plain object mapping type names to adapter classes. Throws if any adapter type is already registered.
check(keys)
Runs one or more checks against the relay. keys can be a single check key string, an array of check key strings, or 'all' to run every supported check. Returns an IResult object. Rejects if a required adapter is missing for the requested check.
Valid check key strings: 'open', 'read', 'write', 'dns', 'ssl', 'info', 'geo'
checkAll()
Convenience wrapper for check('all').
static checksSupported()
Returns the full list of supported check keys: ['open', 'read', 'write', 'ssl', 'dns', 'geo', 'info'].
static translateCheckKeys(checks)
Translates check key aliases to their canonical form. For example, 'websocket' and 'ws' expand to ['open', 'read', 'write']; 'nip11' expands to ['info']; 'tls' expands to ['ssl'].
IResult interface
The object returned by check() has this shape:
IResult fields
The relay URL that was checked.
Network classification:
'clearnet', 'tor', or 'i2p'.Slugs of the adapters used during this check run.
Unix timestamp in milliseconds when the check was performed.
Optional identifier for the monitoring node that ran the check.
WebSocket read check result. Same shape as
open.WebSocket write check result. Same shape as
open.DNS resolution result.
data contains { ipv4: string[] }.TLS certificate validation result. Node.js only.
Geolocation result. Depends on the
dns check having run first.NIP-11 relay information document result.
AbstractAdapter base class
All custom adapters must extend AbstractAdapter:
static type property is the dispatch key — nocap reads it to determine which checks the adapter handles. The base getter exposes the parent Nocap instance, including base.finish() which resolves a check result.
Adapter types
Each adapter type maps to a specific set of check methods. Implement the interface that matches your adapter’sstatic type:
| Type | Interface | Required methods |
|---|---|---|
websocket | IWebsocketAdapter | check_open(), check_read(), check_write() |
dns | IDnsAdapter | check_dns() |
info | IInfoAdapter | check_info() |
ssl | ISslAdapter | check_ssl() |
geo | IGeoAdapter | check_geo() |
(): Promise<void>. They do not return values directly — instead, they call this.base.finish(key, result) to resolve the check.
Custom adapter example
The following is a complete, minimal DNS adapter:Default adapters
Five adapter implementations ship with nocap inlibraries/nocap/adapters/default/. Use them as-is or as reference implementations for custom adapters:
WebsocketAdapterDefault
WebSocket open/read/write checks. Establishes a connection, sends a REQ and EVENT, and verifies protocol-level responses.
DnsAdapterDefault
DNS lookup via Cloudflare DNS-over-HTTPS (1.1.1.1). Handles both clearnet and IP-addressed relays.
GeoAdapterDefault
Geographic IP lookup. Depends on the DNS check result for the relay’s resolved IP address.
InfoAdapterDefault
Fetches the NIP-11 relay information document from the relay’s HTTP endpoint.
SslAdapterDefault
TLS certificate validation. Retrieves and validates the relay’s SSL certificate chain. Node.js only.
Known limitations
Geo check depends on DNS. The
geo check requires a resolved IP address from the dns check. If check('geo') is requested without 'dns' in the check list, nocap automatically prepends 'dns' as a dependency. The DNS result is excluded from the returned result if it was added automatically (controlled by the autoDepsIgnoredInResult config option).Related packages
@nostrwatch/auditor
NIP conformance testing; uses nocap WebSocket adapters for relay connectivity.
@nostrwatch/route66
Relay monitoring orchestration; uses nocap as its check engine.
@nostrwatch/nostrings
Relay URL sanitization and normalization used before connecting.