Nostr
通过 NIP-04 加密私信接入 Nostr
状态: 可选插件(默认禁用)。
Nostr 是一个去中心化的社交/消息协议。本通道让 OpenClaw 通过 NIP-04 接收并回复加密私信(DM)。
安装(按需)
#
Onboarding(推荐)
- onboarding 向导(<code>openclaw onboard</code>)与 <code>openclaw channels add</code> 会列出可选通道插件。
- 选择 Nostr 后会提示你按需安装插件。
安装默认策略:
- <strong>开发通道 + 存在 git checkout:</strong> 使用本地插件路径
- <strong>Stable/Beta:</strong> 从 npm 下载
你可以在提示中覆盖默认选择。
#
手动安装
openclaw plugins install @openclaw/nostr
本地安装(开发工作流):
openclaw plugins install --link '<path-to-openclaw>'/extensions/nostr
安装或启用插件后,请重启 Gateway。
快速配置
1. 生成 Nostr 密钥对(如需要):
nak key generate
2. 写入配置:
{
"channels": {
"nostr": {
"privateKey": "\${NOSTR_PRIVATE_KEY}"
}
}
}3. 设置环境变量:
export NOSTR_PRIVATE_KEY="nsec1..."
4. 重启 Gateway。
配置参考
| Key | Type | Default | 说明 |
| | -- | - | |
| privateKey | string | required | 私钥(nsec 或 16 进制格式) |
| relays | string[] | ['wss://relay.damus.io', 'wss://nos.lol'] | relay URLs(WebSocket) |
| dmPolicy | string | pairing | 私信访问策略 |
| allowFrom | string[] | [] | 允许的发送者 pubkeys(allowlist) |
| enabled | boolean | true | 启用/禁用通道 |
| name | string | - | 显示名 |
| profile | object | - | NIP-01 profile metadata |
Profile metadata
Profile 数据会以 NIP-01 的 <code>kind:0</code> event 发布。你可以在 Control UI(Channels → Nostr → Profile)中管理,或直接写到配置中。
示例:
{
"channels": {
"nostr": {
"privateKey": "\${NOSTR_PRIVATE_KEY}",
"profile": {
"name": "openclaw",
"displayName": "OpenClaw",
"about": "Personal assistant DM bot",
"picture": "https://example.com/avatar.png",
"banner": "https://example.com/banner.png",
"website": "https://example.com",
"nip05": "[email protected]",
"lud16": "[email protected]"
}
}
}
}说明:
- Profile URLs 必须使用 <code>https://</code>。
- 从 relays 导入时会合并字段,并保留本地覆盖值。
访问控制
#
DM 策略
- <strong>pairing</strong>(默认):未知发送者会收到配对码。
- <strong>allowlist</strong>:仅 <code>allowFrom</code> 中的 pubkeys 可以私信。
- <strong>open</strong>:公开入站私信(需要 <code>allowFrom: ["*"]</code>)。
- <strong>disabled</strong>:忽略入站私信。
#
Allowlist 示例
{
"channels": {
"nostr": {
"privateKey": "\${NOSTR_PRIVATE_KEY}",
"dmPolicy": "allowlist",
"allowFrom": ["npub1abc...", "npub1xyz..."]
}
}
}Key 格式
支持的格式:
- <strong>私钥:</strong> <code>nsec...</code> 或 64 字符 16 进制
- <strong>公钥(<code>allowFrom</code>):</strong> <code>npub...</code> 或 16 进制
Relays
默认:<code>relay.damus.io</code> 与 <code>nos.lol</code>。
{
"channels": {
"nostr": {
"privateKey": "\${NOSTR_PRIVATE_KEY}",
"relays": ["wss://relay.damus.io", "wss://relay.primal.net", "wss://nostr.wine"]
}
}
}建议:
- 使用 2–3 个 relay 做冗余。
- 避免太多 relay(延迟、重复消息)。
- 付费 relay 通常更稳定。
- 本地 relay 适合测试(<code>ws://localhost:7777</code>)。
协议支持
| NIP | 状态 | 说明 |
| | - |
| NIP-01 | Supported | 基础 event 格式 + profile metadata |
| NIP-04 | Supported | 加密私信(kind:4) |
| NIP-17 | Planned | Gift-wrapped DMs |
| NIP-44 | Planned | 版本化加密 |
测试
#
本地 relay
docker run -p 7777:7777 ghcr.io/hoytech/strfry
{
"channels": {
"nostr": {
"privateKey": "\${NOSTR_PRIVATE_KEY}",
"relays": ["ws://localhost:7777"]
}
}
}#
手动测试
1. 从 logs 里记录 bot 的 pubkey(npub)。
2. 打开一个 Nostr 客户端(Damus、Amethyst 等)。
3. 私信 bot 的 pubkey。
4. 验证 bot 是否回复。
排障
#
收不到消息
- 确认私钥有效。
- 确认 relay URLs 可达,并使用 <code>wss://</code>(或本地 <code>ws://</code>)。
- 确认 <code>enabled</code> 不为 <code>false</code>。
- 查看 gateway logs 中的 relay 连接错误。
#
发不出回复
- 确认 relay 允许写入(writes)。
- 确认出站网络连通。
- 留意 relay 的 rate limits。
#
重复回复
- 在使用多个 relays 时属于预期行为。