Nostr decentralized messaging plugin for elizaOS agents
Project description
@elizaos/plugin-nostr
Nostr decentralized messaging plugin for elizaOS agents. Enables secure, encrypted direct messaging (NIP-04) over the Nostr protocol.
Features
- Encrypted Direct Messages (NIP-04): Send and receive encrypted DMs using the Nostr protocol
- Multi-relay Support: Connect to multiple Nostr relays for redundancy
- Profile Management: Publish and update your agent's Nostr profile (kind:0)
- DM Policy Control: Configure who can message your agent (open, pairing, allowlist, disabled)
- Multi-language Support: Available in TypeScript, Python, and Rust
Installation
# npm
npm install @elizaos/plugin-nostr
# pnpm
pnpm add @elizaos/plugin-nostr
Configuration
Environment Variables
| 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 |
Agent Configuration
{
"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"
}
}
Usage
Actions
NOSTR_SEND_DM
Send an encrypted direct message to a Nostr pubkey.
"Send them a message saying 'Hello!'"
"Message npub1abc... saying 'Thanks for the zap!'"
NOSTR_PUBLISH_PROFILE
Update the agent's Nostr profile.
"Update your profile name to 'Bot Assistant'"
"Set your bio to 'I am an AI assistant on Nostr'"
Providers
nostrIdentityContext
Provides information about the bot's Nostr identity:
- Public key (hex and npub)
- Connected relays
- Connection status
nostrSenderContext
Provides information about the current conversation partner:
- Sender's pubkey (hex and npub)
- Display name
- Encryption status
DM Policies
| 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 Concepts
Keys
- Private Key: Used to sign events and decrypt messages. Keep this secret!
- Public Key: Your identity on Nostr. Can be shared freely.
- npub/nsec: Bech32-encoded formats for public/private keys
Events
- kind:0: Profile metadata
- kind:4: Encrypted DMs (NIP-04)
Relays
Nostr relays are servers that store and forward events. Your agent connects to multiple relays for redundancy.
Example
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
Security Considerations
-
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-06or thenostr-toolslibrary. -
Relay Selection: Choose relays carefully. Consider running your own relay for sensitive applications.
-
DM Policy: Start with a restrictive policy and relax as needed.
Development
Building
# TypeScript
cd typescript && npm run build
# Python
cd python && pip install -e .
# Rust
cd rust && cargo build
Testing
# TypeScript
npm test
# Python
pytest
# Rust
cargo test
API Reference
NostrService
Methods
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 metadata
Types
interface 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;
}
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file elizaos_plugin_nostr-2.0.0a5.tar.gz.
File metadata
- Download URL: elizaos_plugin_nostr-2.0.0a5.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc39e969559a3e7c34b613a4e6cee3a7b4f8fb0880196dcdc3eb7836489bca4f
|
|
| MD5 |
7d0018f4bfa019826995fa44b2f085ba
|
|
| BLAKE2b-256 |
3abd8883f1d5b1b3c71b8e4ba4791ee227a8ca9f066065f76c8b795ae6091186
|
File details
Details for the file elizaos_plugin_nostr-2.0.0a5-py3-none-any.whl.
File metadata
- Download URL: elizaos_plugin_nostr-2.0.0a5-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26d28cddfe232661902ab12a5b4666808cf5beae84f87a4af1265cdc654a19c8
|
|
| MD5 |
462e90b5101ac08ecdde1bb8aaa491d5
|
|
| BLAKE2b-256 |
a3eceffb4d0cade6c4ec1dccc826a5f91256158d0393ed7712e7a7d066d66755
|