plugins/plugin-nostr/README.md
Nostr decentralized messaging plugin for ElizaOS agents. Enables secure, encrypted direct messaging (NIP-04) over the Nostr protocol.
# npm
npm install @elizaos/plugin-nostr
# bun
bun add @elizaos/plugin-nostr
| Variable | Description | Required |
|---|---|---|
NOSTR_PRIVATE_KEY | Private key (hex or nsec format) | Yes |
NOSTR_RELAYS | Comma-separated relay URLs | No |
NOSTR_DM_POLICY | DM policy: open, pairing, allowlist, disabled | No |
NOSTR_ALLOW_FROM | Comma-separated pubkeys for allowlist | No |
NOSTR_ENABLED | Enable/disable the plugin | No |
{
"plugins": ["@elizaos/plugin-nostr"],
"pluginParameters": {
"NOSTR_PRIVATE_KEY": "your-private-key-hex-or-nsec",
"NOSTR_RELAYS": "wss://relay.damus.io,wss://nos.lol,wss://relay.nostr.band",
"NOSTR_DM_POLICY": "pairing"
}
}
Nostr DMs and public notes are exposed through canonical connector actions. Use
source: "nostr" when a request needs to target Nostr explicitly.
| Primary action | Operation | Description |
|---|---|---|
MESSAGE | send | Send an encrypted direct message to a Nostr pubkey |
MESSAGE | read | Read recent direct messages where the connector can fetch them |
POST | send | Publish a public Nostr note |
POST | read | Read recent relay feed posts |
POST | search | Search relay posts where supported |
Profile updates remain a Nostr-specific profile capability outside the MESSAGE/POST connector action set.
Provides information about the bot's Nostr identity:
Provides information about the current conversation partner:
| Policy | Description |
|---|---|
open | Accept DMs from anyone |
pairing | Accept DMs and remember senders for future conversations |
allowlist | Only accept DMs from pubkeys in NOSTR_ALLOW_FROM |
disabled | Don't accept any DMs |
Nostr relays are servers that store and forward events. Your agent connects to multiple relays for redundancy.
import { createAgent } from "@elizaos/core";
import nostrPlugin from "@elizaos/plugin-nostr";
const agent = await createAgent({
plugins: [nostrPlugin],
settings: {
NOSTR_PRIVATE_KEY: process.env.NOSTR_PRIVATE_KEY,
NOSTR_RELAYS: "wss://relay.damus.io,wss://nos.lol",
NOSTR_DM_POLICY: "pairing",
},
});
// The agent can now receive DMs and respond
Private Key Storage: Never commit your private key to version control. Use environment variables or secure secret management.
Key Generation: Generate keys using a reputable tool like nip-06 or the nostr-tools library.
Relay Selection: Choose relays carefully. Consider running your own relay for sensitive applications.
DM Policy: Start with a restrictive policy and relax as needed.
cd typescript && npm run build
npm test
isConnected(): Check if connected to relaysgetPublicKey(): Get the bot's public key (hex)getNpub(): Get the bot's npubgetRelays(): Get connected relay URLssendDm(options): Send an encrypted DMpublishProfile(profile): Publish profile metadatainterface NostrSettings {
privateKey: string;
publicKey: string;
relays: string[];
dmPolicy: "open" | "pairing" | "allowlist" | "disabled";
allowFrom: string[];
enabled: boolean;
}
interface NostrProfile {
name?: string;
displayName?: string;
about?: string;
picture?: string;
banner?: string;
nip05?: string;
lud16?: string;
website?: string;
}
interface NostrDmSendOptions {
toPubkey: string;
text: string;
}
interface NostrSendResult {
success: boolean;
eventId?: string;
relays: string[];
error?: string;
}
MIT