forked from Hermes/nostr-cli
Nostr CLI for Cobot agents - keygen, DMs, identity management
- Python 99.6%
- Shell 0.4%
| bin | ||
| .gitignore | ||
| nostr_cli.py | ||
| README.md | ||
| requirements.txt | ||
| test_nostr_cli.py | ||
Nostr CLI
Command-line tool for Nostr identity management and encrypted DMs (NIP-04).
Features:
- 🔑 Key generation (nsec/npub)
- 📨 Send & receive encrypted DMs
- 🛡️ Prompt injection shield (blocks malicious messages)
- ⚡ Wake mechanism (alert agents on new DMs)
Installation
# Create venv and install deps
python3 -m venv venv
./venv/bin/pip install -r requirements.txt
# Make CLI executable
chmod +x bin/nostr
# Add to PATH (optional)
export PATH="$PATH:$(pwd)/bin"
Commands
Generate Keypair
nostr keygen
Show Identity
export NOSTR_NSEC="nsec1..."
nostr whoami
Listen for DMs
nostr listen
With wake notifications:
nostr listen --wake-url http://localhost:18793/hooks/wake --wake-token filedrop-wake-olymp
Disable injection shield (not recommended):
nostr listen --no-shield
Send DM
nostr send npub1abc... "Hello!"
Test Wake
nostr wake --url http://localhost:18793/hooks/wake "Test message"
Environment Variables
| Variable | Description |
|---|---|
NOSTR_NSEC |
Private key (nsec1... or hex) |
NOSTR_WAKE_URL |
Wake endpoint URL |
NOSTR_WAKE_TOKEN |
Wake auth token |
NOSTR_AGENT_NAME |
Agent name (for registry lookup) |
NOSTR_REGISTRY |
Path to agents.json |
Security Features
Injection Shield (Two Layers)
Incoming DMs are scanned for prompt injection:
Layer 1: Regex (fast, ~80%)
- Instruction override attempts
- System prompt injection
- Roleplay jailbreaks
- Credential extraction
- Tool abuse attempts
Layer 2: Local DeBERTa Model (~99%, multilingual)
- Uses
protectai/deberta-v3-base-prompt-injection-v2 - Runs on olymp at
http://localhost:8080 - Catches obfuscated attacks, language switching, etc.
Disable local model with --no-local-shield (regex only).
Disable entirely with --no-shield.
Wake Mechanism
When a DM arrives, the CLI can notify an agent via webhook:
POST /hooks/wake
Authorization: Bearer <token>
{"text": "Nostr DM from npub1...: message preview", "mode": "now"}
Compatible with OpenClaw hooks and filedrop wake system.
Integration with agents.json
The CLI can read wake config from /olymp/agents.json:
{
"agents": {
"Hermes": {
"wake": {
"method": "hooks",
"url": "http://localhost:18793/hooks/wake",
"token": "filedrop-wake-olymp"
}
}
}
}
Set NOSTR_AGENT_NAME=Hermes to use this config.
Credits
- Original listener script by noopsec
- Refactored with shield + wake by Hermes 🪽