Nostrbook 扩展
本教程介绍如何把 Nostrbook MCP 服务器 添加为 goose 扩展,以便访问一套完整的 Nostr 文档登记库。它帮助用户理解这个去中心化社交协议、实现方式和技术规范。
快速安装
- goose Desktop
- goose CLI
命令
npx -y @nostrbook/mcp@latest
配置
信息
运行此命令需要系统已安装 Node.js,因为会用到 npx。
- goose Desktop
- goose CLI
- Launch the installer
- Click
Yesto confirm the installation - Click the button in the top-left to open the sidebar
- Navigate to the chat
- Run the
configurecommand:
goose configure
- Choose to add a
Command-line Extension.
┌ goose-configure
│
◇ What would you like to configure?
│ Add Extension
│
◆ What type of extension would you like to add?
│ ○ Built-in Extension
│ ● Command-line Extension (Run a local command or script)
│ ○ Remote Extension (Streamable HTTP)
└
- Give your extension a name.
┌ goose-configure
│
◇ What would you like to configure?
│ Add Extension
│
◇ What type of extension would you like to add?
│ Command-line Extension
│
◆ What would you like to call this extension?
│ Nostrbook
└
- Enter the command to run when this extension is used.
┌ goose-configure
│
◇ What would you like to configure?
│ Add Extension
│
◇ What type of extension would you like to add?
│ Command-line Extension
│
◇ What would you like to call this extension?
│ Nostrbook
│
◆ What command should be run?
│ npx -y @nostrbook/mcp@latest
└
- Enter the number of seconds goose should wait for actions to complete before timing out. Default is
300seconds.
┌ goose-configure
│
◇ What would you like to configure?
│ Add Extension
│
◇ What type of extension would you like to add?
│ Command-line Extension
│
◇ What would you like to call this extension?
│ Nostrbook
│
◇ What command should be run?
│ npx -y @nostrbook/mcp@latest
│
◆ Please set the timeout for this tool (in secs):
│ 300
└
- Enter a description for this extension.
┌ goose-configure
│
◇ What would you like to configure?
│ Add Extension
│
◇ What type of extension would you like to add?
│ Command-line Extension
│
◇ What would you like to call this extension?
│ Nostrbook
│
◇ What command should be run?
│ npx -y @nostrbook/mcp@latest
│
◇ Please set the timeout for this tool (in secs):
│ 300
│
◆ Enter a description for this extension:
│ A comprehensive registry of Nostr documentation with structured knowledge
└
- Choose
Nowhen asked to add environment variables.
┌ goose-configure
│
◇ What would you like to configure?
│ Add Extension
│
◇ What type of extension would you like to add?
│ Command-line Extension
│
◇ What would you like to call this extension?
│ Nostrbook
│
◇ What command should be run?
│ npx -y @nostrbook/mcp@latest
│
◇ Please set the timeout for this tool (in secs):
│ 300
│
◇ Enter a description for this extension:
│ A comprehensive registry of Nostr documentation with structured knowledge
│
◆ Would you like to add environment variables?
│ No
│
└ Added Nostrbook extension
使用示例
goose 提示词
goose,什么是 NIP-61,我该如何实现它?
goose 输出
注意:示例中的 ID 已替换为通用占位符。
命令行
工具调用
─── read_nip | nostrbook ──────────────────────────
nip: 61
NIP-61:实现 Nutzaps
NIP-61 定义了「Nutzaps」,即 P2PK Cashu 代币,支付本身就是收据。该协议允许通过 Nostr 生态,用 Cashu 代币进行比特币小额支付。
核心概念
Nutzaps 让用户通过 Nostr 事件互相发送小额比特币支付,代币锁定到接收方指定的公钥。
实现指南
前置条件
第 1 步:设置接收方信息(用于接收 Nutzaps)
创建并发布一个 kind:10019 事件,告诉别人如何给你打款:
{
"kind": 10019,
"tags": [
["relay", "wss://your-relay1.com"],
["relay", "wss://your-relay2.com"],
["mint", "https://your-trusted-mint.com", "sat"],
["pubkey", "<your-p2pk-pubkey>"]
]
}
pubkey应是专用公钥(不要用你的 Nostr 身份密钥)- 把对应的私钥安全地存放在 NIP-60 钱包事件中
- 只列出你信任并会监控的 mint
第 2 步:构建发送方功能
要实现 nutzap:
-
查询接收方信息:
// Fetch recipient's kind:10019 event
const recipientInfo = await relay.get({
kinds: [10019],
authors: [recipientPubkey]
}); -
提取 mint 和 P2PK 信息:
const recipientMints = recipientInfo.tags
.filter(tag => tag[0] === 'mint')
.map(tag => tag[1]);
const recipientLockKey = recipientInfo.tags
.find(tag => tag[0] === 'pubkey')?.[1]; -
铸造或兑换代币:在接收方信任的某个 mint 上操作,并用 P2PK 锁定到对方指定的密钥
-
发布 nutzap 事件:
{
"kind": 9321,
"content": "Thanks for your post!",
"tags": [
["proof", "{\"amount\":1,\"C\":\"02...3f\",\"id\":\"000...\",\"secret\":\"[\\\"P2PK\\\",...]\"}"],
["u", "https://recipient-specified-mint.com"],
["e", "<event-being-zapped>", "<relay-hint>"],
["p", "<recipient-pubkey>"]
]
}
第 3 步:构建接收方功能
要实现接收 nutzap:
-
查询收到的 nutzap:
// Subscribe to nutzap events
relay.subscribe([
{
kinds: [9321],
"#p": [myPubkey],
"#u": myTrustedMints,
since: lastCheckTimestamp
}
]); -
校验收到的 nutzap:
- 确认代币来自你指定的 mint
- 确认代币锁定到你的 P2PK 密钥
- 校验 DLEQ 证明
-
赎回代币:
- 把 P2PK 代币兑换进你的钱包
- 创建
kind:7376事件记录赎回:
{
"kind": 7376,
"content": "<encrypted-content>",
"tags": [
["e", "<nutzap-event-id>", "", "redeemed"],
["p", "<sender-pubkey>"]
]
}
重要实现细节
- P2PK 密钥前缀:始终给 P2PK 锁定公钥加上 "02" 前缀,以保证兼容
- 代币校验:在本地实现 DLEQ 证明校验
- Mint URL 规范化:规范化 mint URL,避免细微 URL 差异带来的问题
- 用户引导:引导用户只使用兼容 NUT-11 和 NUT-12 的 mint
- 发布位置:把 nutzap 事件发布到接收方指定的 relay
测试
测试实现时:
- 用小额创建测试 nutzap
- 确认代币赎回正确
- 检查赎回记录是否正确创建
- 用多个 mint 测试兼容性
安全注意事项
- 不要用用户的主 Nostr 密钥做 P2PK 操作
- 确保敏感钱包数据得到正确加密
- 尝试赎回代币之前校验所有证明
- 只与明确信任的 mint 交互
按这些步骤,你可以实现完整的 nutzap 方案,让用户通过 Nostr 协议用 Cashu 代币收发比特币小额支付。