Sybil-filtered Nostr relay
Reject Nostr events from pubkeys that don't have an orangecheck proof meeting your thresholds. Ships as a Strfry write-policy plugin.
InstallLink to this section
yarn global add @orangecheck/relay-filter
# `oc-strfry` is now on PATH
Strfry setupLink to this section
Strfry (opens in a new tab) is the most widely-deployed relay
implementation. Its write-policy plugin protocol is exactly what oc-strfry
speaks.
ConfigureLink to this section
# strfry.conf
writePolicy = {
plugin = "/usr/local/bin/oc-strfry"
}
Pass options via environmentLink to this section
In your Strfry unit file (systemd, docker-compose, or whatever):
[Service]
Environment="OC_MIN_SATS=100000"
Environment="OC_MIN_DAYS=30"
Environment="OC_ALLOW_KINDS=0,3,10002"
Environment="OC_ALLOW_PUBKEYS=abc123...,def456..."
ExecStart=/usr/bin/strfry relay
Full env var referenceLink to this section
| Env var | Default | Purpose |
|---|---|---|
OC_ | 0 | Minimum bonded sats |
OC_ | 0 | Minimum days unspent |
OC_ | 0, | Kinds that bypass (profile, contacts, relay list) |
OC_ | none | Comma-separated hex pubkeys that bypass (e.g. operator) |
OC_ | SDK defaults | Discovery relays for lookups |
OC_ | false | true accepts a verified signature whose bond the chain API cannot read; never a signature not yet checked |
OC_ | 600000 | How often each bond is re-read from the chain. A spent bond keeps passing for at most this long |
OC_ | true | Emit one decision per line on stderr |
Docker composeLink to this section
The container runs Strfry as usual; Strfry starts the plugin itself from
strfry.conf, and the plugin reads the OC_* variables from Strfry's
environment. Without a global install, point the plugin at npx:
# strfry.conf
writePolicy = {
plugin = "npx -y @orangecheck/relay-filter"
}
services:
strfry:
image: strfry/strfry:latest # the image needs Node.js 18+ for the plugin
volumes:
- ./strfry.conf:/etc/strfry.conf:ro
- strfry-db:/var/lib/strfry
environment:
- OC_MIN_SATS=100000
- OC_MIN_DAYS=30
- OC_ALLOW_KINDS=0,3,10002
ports:
- '7777:7777'
Why bypass kinds 0, 3, 10002Link to this section
- Kind 0 — profile metadata. Users need this to publish their npub before they can create an orangecheck proof.
- Kind 3 — contact lists.
- Kind 10002 — relay list metadata.
These are bootstrap events. Gating them creates a chicken-and-egg problem. Everything else (notes, reactions, DMs, zaps, orangecheck attestations themselves) goes through the gate.
Custom relay — nostr-toolsLink to this section
If you run your own relay in JS:
import type { Event } from 'nostr-tools';
import { filterEvent } from '@orangecheck/relay-filter';
import { verifyEvent } from 'nostr-tools';
// Yours: the operator's pubkey and the relay's event store.
declare const OPERATOR_PUBKEY: string;
declare const store: { put(event: Event): Promise<void> };
async function handleEvent(socket: WebSocket, event: Event) {
if (!verifyEvent(event)) {
socket.send(
JSON.stringify(['OK', event.id, false, 'invalid signature'])
);
return;
}
const decision = await filterEvent(event, {
minSats: 100_000,
minDays: 30,
allowKinds: [0, 3, 10002],
allowPubkeys: [OPERATOR_PUBKEY],
});
if (decision.action === 'reject') {
socket.send(JSON.stringify(['OK', event.id, false, decision.message]));
return;
}
await store.put(event);
socket.send(JSON.stringify(['OK', event.id, true, '']));
}
TuningLink to this section
- Bond refresh — the Strfry plugin re-reads every bond each
OC_REFRESH_MS(10 minutes by default). A shorter interval drops a spent bond sooner, for more chain reads. In your own relay,filterEventcaches each pubkey forcacheTtlMs(60 s by default, at most 10 minutes). - Concurrency — the filter runs serialised per inbound event. If events are backing up, consider horizontal-scaling the relay rather than parallelising the filter.
- Discovery relays —
OC_RELAYSoverrides the Nostr relays the filter queries to find a pubkey's attestation. Set this to include your own relay so you see proofs published locally.
What clients see when rejectedLink to this section
['OK', '<event_id>', false, 'orangecheck: proof below relay thresholds (min_sats=100000, min_days=30)']
Clients SHOULD display this message to the user. Good client UX tells the user "this relay requires X sats bonded — create an attestation at attest.ochk.io/create".
FurtherLink to this section
@orangecheck/relay-filterreference- Nostr NIP spec (opens in a new tab)
- Security implications — threat model for publishers and verifiers.