Skip to content
On this page

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

Shell
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

conf
# 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):

ini
[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 varDefaultPurpose
OC_MIN_SATS0Minimum bonded sats
OC_MIN_DAYS0Minimum days unspent
OC_ALLOW_KINDS0,3,10002Kinds that bypass (profile, contacts, relay list)
OC_ALLOW_PUBKEYSnoneComma-separated hex pubkeys that bypass (e.g. operator)
OC_RELAYSSDK defaultsDiscovery relays for lookups
OC_FAIL_OPENfalsetrue accepts a verified signature whose bond the chain API cannot read; never a signature not yet checked
OC_REFRESH_MS600000How often each bond is re-read from the chain. A spent bond keeps passing for at most this long
OC_LOGtrueEmit 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:

conf
# strfry.conf
writePolicy = {
  plugin = "npx -y @orangecheck/relay-filter"
}
YAML
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:

TypeScript
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, filterEvent caches each pubkey for cacheTtlMs (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_RELAYS overrides 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

Code
['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