nostr-event-builder
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNostr Event Builder
Nostr事件构建器
Overview
概述
Construct correct Nostr event structures from natural language descriptions.
This skill handles the non-obvious parts: choosing the right kind, building
proper tag arrays with correct markers, enforcing NIP-10 vs NIP-22 threading
rules, and producing valid event JSON ready for signing.
从自然语言描述构建正确的Nostr事件结构。
该技能负责处理容易出错的部分:选择正确的kind、构建带有正确标记的标签数组、执行NIP-10和NIP-22线程规则,以及生成可供签名的有效事件JSON。
When to Use
适用场景
- Developer describes what they want to publish on Nostr
- Building reply threads (NIP-10 kind:1 replies)
- Commenting on non-note content (NIP-22 kind:1111 comments)
- Creating or updating user profiles (kind:0 metadata)
- Constructing any Nostr event and unsure about tag structure
- Debugging malformed events (wrong markers, missing tags)
Do NOT use when:
- Implementing relay WebSocket logic (that's relay protocol, not event building)
- Working with NIP-19 encoding/decoding (bech32 concerns, not event structure)
- Building subscription filters (REQ messages, not EVENT messages)
- 开发者描述他们想要在Nostr上发布的内容
- 构建回复线程(NIP-10 kind:1回复)
- 对非笔记内容发表评论(NIP-22 kind:1111评论)
- 创建或更新用户资料(kind:0元数据)
- 构建任意Nostr事件但不确定标签结构
- 调试格式错误的事件(标记错误、标签缺失)
不适用场景:
- 实现中继WebSocket逻辑(属于中继协议范畴,不属于事件构建)
- 处理NIP-19编码/解码(属于bech32相关内容,不属于事件结构)
- 构建订阅过滤器(属于REQ消息范畴,不属于EVENT消息)
Workflow
工作流程
1. Identify the Event Kind
1. 确定事件Kind
Ask: "What is the developer trying to publish?"
| Intent | Kind | Category | Key NIP |
|---|---|---|---|
| Post a short text note | 1 | Regular | NIP-10 |
| Reply to a kind:1 note | 1 | Regular | NIP-10 |
| Comment on non-kind:1 content | 1111 | Regular | NIP-22 |
| Set/update user profile | 0 | Replaceable | NIP-01 |
| Update follow list | 3 | Replaceable | NIP-02 |
| Delete events | 5 | Regular | NIP-09 |
| Repost a note | 6 | Regular | NIP-18 |
| React to an event | 7 | Regular | NIP-25 |
| Publish a long-form article | 30023 | Addressable | NIP-23 |
See references/event-kinds.md for full
kind-to-structure mapping.
Critical routing rule:
Is the target a kind:1 note?
YES → Use kind:1 reply with NIP-10 e-tag markers
NO → Use kind:1111 comment with NIP-22 uppercase/lowercase tags询问:「开发者想要发布什么内容?」
| 意图 | Kind | 分类 | 核心NIP |
|---|---|---|---|
| 发布短文本笔记 | 1 | 常规 | NIP-10 |
| 回复kind:1笔记 | 1 | 常规 | NIP-10 |
| 评论非kind:1内容 | 1111 | 常规 | NIP-22 |
| 设置/更新用户资料 | 0 | 可替换 | NIP-01 |
| 更新关注列表 | 3 | 可替换 | NIP-02 |
| 删除事件 | 5 | 常规 | NIP-09 |
| 转发笔记 | 6 | 常规 | NIP-18 |
| 对事件作出反应 | 7 | 常规 | NIP-25 |
| 发布长文 | 30023 | 可寻址 | NIP-23 |
查看references/event-kinds.md获取完整的kind到结构的映射关系。
关键路由规则:
Is the target a kind:1 note?
YES → Use kind:1 reply with NIP-10 e-tag markers
NO → Use kind:1111 comment with NIP-22 uppercase/lowercase tags2. Build the Tag Array
2. 构建标签数组
Tags are the hardest part. Follow the tag guide for your kind:
For kind:1 replies (NIP-10):
Direct reply to root (no intermediate replies):
json
{
"kind": 1,
"tags": [
["e", "<root-event-id>", "<relay-url>", "root", "<root-author-pubkey>"],
["p", "<root-author-pubkey>"]
],
"content": "Your reply text"
}Reply to a reply in a thread:
json
{
"kind": 1,
"tags": [
["e", "<root-event-id>", "<relay-url>", "root", "<root-author-pubkey>"],
[
"e",
"<parent-event-id>",
"<relay-url>",
"reply",
"<parent-author-pubkey>"
],
["p", "<root-author-pubkey>"],
["p", "<parent-author-pubkey>"]
],
"content": "Your reply text"
}For kind:1111 comments (NIP-22):
Top-level comment on a regular event:
json
{
"kind": 1111,
"tags": [
["E", "<root-event-id>", "<relay-url>", "<root-author-pubkey>"],
["K", "<root-event-kind>"],
["P", "<root-author-pubkey>", "<relay-url>"],
["e", "<root-event-id>", "<relay-url>", "<root-author-pubkey>"],
["k", "<root-event-kind>"],
["p", "<root-author-pubkey>", "<relay-url>"]
],
"content": "Your comment text"
}Top-level comment on an addressable event (kind 30000-39999):
json
{
"kind": 1111,
"tags": [
["A", "<kind>:<pubkey>:<d-tag>", "<relay-url>"],
["K", "<root-event-kind>"],
["P", "<root-author-pubkey>", "<relay-url>"],
["a", "<kind>:<pubkey>:<d-tag>", "<relay-url>"],
["e", "<event-id>", "<relay-url>"],
["k", "<root-event-kind>"],
["p", "<root-author-pubkey>", "<relay-url>"]
],
"content": "Your comment text"
}Comment on a URL or external identifier:
json
{
"kind": 1111,
"tags": [
["I", "<url-or-identifier>"],
["K", "<identifier-type>"],
["i", "<url-or-identifier>"],
["k", "<identifier-type>"]
],
"content": "Your comment text"
}Reply to an existing comment:
json
{
"kind": 1111,
"tags": [
["E", "<original-root-event-id>", "<relay-url>", "<root-author-pubkey>"],
["K", "<original-root-kind>"],
["P", "<root-author-pubkey>"],
[
"e",
"<parent-comment-id>",
"<relay-url>",
"<parent-comment-author-pubkey>"
],
["k", "1111"],
["p", "<parent-comment-author-pubkey>"]
],
"content": "Your reply to the comment"
}See references/tag-guide.md for complete tag
semantics.
标签是最复杂的部分,请遵循对应kind的标签指南:
针对kind:1回复(NIP-10):
直接回复根内容(无中间回复):
json
{
"kind": 1,
"tags": [
["e", "<root-event-id>", "<relay-url>", "root", "<root-author-pubkey>"],
["p", "<root-author-pubkey>"]
],
"content": "Your reply text"
}回复线程中的某条回复:
json
{
"kind": 1,
"tags": [
["e", "<root-event-id>", "<relay-url>", "root", "<root-author-pubkey>"],
[
"e",
"<parent-event-id>",
"<relay-url>",
"reply",
"<parent-author-pubkey>"
],
["p", "<root-author-pubkey>"],
["p", "<parent-author-pubkey>"]
],
"content": "Your reply text"
}针对kind:1111评论(NIP-22):
对常规事件的顶层评论:
json
{
"kind": 1111,
"tags": [
["E", "<root-event-id>", "<relay-url>", "<root-author-pubkey>"],
["K", "<root-event-kind>"],
["P", "<root-author-pubkey>", "<relay-url>"],
["e", "<root-event-id>", "<relay-url>", "<root-author-pubkey>"],
["k", "<root-event-kind>"],
["p", "<root-author-pubkey>", "<relay-url>"]
],
"content": "Your comment text"
}对可寻址事件(kind 30000-39999)的顶层评论:
json
{
"kind": 1111,
"tags": [
["A", "<kind>:<pubkey>:<d-tag>", "<relay-url>"],
["K", "<root-event-kind>"],
["P", "<root-author-pubkey>", "<relay-url>"],
["a", "<kind>:<pubkey>:<d-tag>", "<relay-url>"],
["e", "<event-id>", "<relay-url>"],
["k", "<root-event-kind>"],
["p", "<root-author-pubkey>", "<relay-url>"]
],
"content": "Your comment text"
}对URL或外部标识符的评论:
json
{
"kind": 1111,
"tags": [
["I", "<url-or-identifier>"],
["K", "<identifier-type>"],
["i", "<url-or-identifier>"],
["k", "<identifier-type>"]
],
"content": "Your comment text"
}回复已有评论:
json
{
"kind": 1111,
"tags": [
["E", "<original-root-event-id>", "<relay-url>", "<root-author-pubkey>"],
["K", "<original-root-kind>"],
["P", "<root-author-pubkey>"],
[
"e",
"<parent-comment-id>",
"<relay-url>",
"<parent-comment-author-pubkey>"
],
["k", "1111"],
["p", "<parent-comment-author-pubkey>"]
],
"content": "Your reply to the comment"
}查看references/tag-guide.md获取完整的标签语义说明。
3. Set the Content Field
3. 设置Content字段
Content format depends on the kind:
| Kind | Content Format |
|---|---|
| 0 | Stringified JSON: |
| 1 | Plaintext (no markdown, no HTML) |
| 5 | Optional deletion reason text |
| 6 | Stringified JSON of the reposted event |
| 7 | |
| 1111 | Plaintext comment |
| 30023 | Markdown-formatted article body |
内容格式取决于kind:
| Kind | 内容格式 |
|---|---|
| 0 | 序列化JSON: |
| 1 | 纯文本(无markdown,无HTML) |
| 5 | 可选的删除原因文本 |
| 6 | 被转发事件的序列化JSON |
| 7 | |
| 1111 | 纯文本评论 |
| 30023 | Markdown格式的文章正文 |
4. Construct the Complete Event
4. 构建完整事件
Assemble the unsigned event object:
json
{
"pubkey": "<32-bytes-lowercase-hex-public-key>",
"created_at": "<unix-timestamp-seconds>",
"kind": "<integer>",
"tags": [["..."]],
"content": "<string>"
}The is computed as SHA-256 of the serialized form:
idjson
[0, "<pubkey>", <created_at>, <kind>, <tags>, "<content>"]Serialization rules:
- UTF-8 encoding, no whitespace/formatting
- Escape in content: ,
\n,\",\\,\r,\t,\b\f - All other characters verbatim
The is a Schnorr signature (secp256k1) of the .
sigid组装未签名的事件对象:
json
{
"pubkey": "<32-bytes-lowercase-hex-public-key>",
"created_at": "<unix-timestamp-seconds>",
"kind": "<integer>",
"tags": [["..."]],
"content": "<string>"
}idjson
[0, "<pubkey>", <created_at>, <kind>, <tags>, "<content>"]序列化规则:
- UTF-8编码,无空格/格式
- 内容中的转义字符:,
\n,\",\\,\r,\t,\b\f - 所有其他字符保持原样
sigid5. Validate Before Signing
5. 签名前验证
Checklist before the event is ready:
- is correct for the intent
kind - All required tags present for this kind
- tags have correct markers (
e/rootfor kind:1)reply - tags include ALL participants in the thread
p - NIP-10 kind:1 replies only target other kind:1 events
- NIP-22 kind:1111 comments do NOT target kind:1 events
- and
Ktags present for kind:1111 commentsk - Uppercase tags (E/A/I/K/P) point to root scope in kind:1111
- Lowercase tags (e/a/i/k/p) point to parent item in kind:1111
- format matches the kind's requirements
content - is a Unix timestamp in seconds (not milliseconds)
created_at - All hex values are 32-byte lowercase
事件准备就绪前的检查清单:
- 符合发布意图
kind - 该kind所需的所有标签都已存在
- 标签带有正确的标记(kind:1对应
e/root)reply - 标签包含线程中的所有参与者
p - NIP-10 kind:1回复仅针对其他kind:1事件
- NIP-22 kind:1111评论不针对kind:1事件
- kind:1111评论包含和
K标签k - kind:1111中的大写标签(E/A/I/K/P)指向根范围
- kind:1111中的小写标签(e/a/i/k/p)指向父项
- 格式符合对应kind的要求
content - 是秒级Unix时间戳(不是毫秒级)
created_at - 所有十六进制值都是32字节小写
Common Mistakes
常见错误
| Mistake | Why It Breaks | Fix |
|---|---|---|
| Using kind:1 to reply to a kind:30023 article | NIP-10 kind:1 replies MUST only reply to other kind:1 events | Use kind:1111 (NIP-22 comment) for non-kind:1 targets |
| Using kind:1111 to reply to a kind:1 note | NIP-22 comments MUST NOT reply to kind:1 | Use kind:1 with NIP-10 e-tag markers |
Missing | Clients can't reconstruct the thread tree | Always use marked e tags: |
Only one e tag with | Direct replies to root need | Single e tag = use |
| Missing p tags for thread participants | Users don't get notified of replies | Include p tags for ALL pubkeys in the thread |
| Lowercase e/k/p tags for root scope in kind:1111 | Root scope MUST use uppercase E/K/P tags | Uppercase = root scope, lowercase = parent item |
| Missing K or k tags in kind:1111 | Both are REQUIRED by NIP-22 | Always include |
| Nostr uses seconds, not milliseconds | Use |
| Content as object instead of string for kind:0 | Content must be stringified JSON | Use |
Missing | Relay can't address the event properly | Always include |
| Positional e tags without markers | Deprecated; creates ambiguity in thread reconstruction | Always use marked e tags with |
| 错误 | 出错原因 | 修复方案 |
|---|---|---|
| 使用kind:1回复kind:30023文章 | NIP-10 kind:1回复必须仅回复其他kind:1事件 | 对非kind:1目标使用kind:1111(NIP-22评论) |
| 使用kind:1111回复kind:1笔记 | NIP-22评论禁止回复kind:1内容 | 使用带有NIP-10 e标签标记的kind:1 |
kind:1的e标签缺失 | 客户端无法重建线程树 | 始终使用带标记的e标签: |
仅存在一个带有 | 直接回复根内容需要 | 单个e标签 = 仅使用 |
| 缺失线程参与者对应的p标签 | 用户无法收到回复通知 | 包含线程中所有公钥对应的p标签 |
| kind:1111中根范围使用小写e/k/p标签 | 根范围必须使用大写E/K/P标签 | 大写 = 根范围,小写 = 父项 |
| kind:1111中缺失K或k标签 | NIP-22要求两者都必须存在 | 始终包含 |
| Nostr使用秒级时间戳,而非毫秒级 | 使用 |
| kind:0的content是对象而非字符串 | content必须是序列化JSON | 使用 |
可寻址事件(30000-39999)缺失 | 中继无法正确寻址事件 | 始终包含 |
| 使用不带标记的位置型e标签 | 已废弃;会在线程重建时产生歧义 | 始终使用带有 |
Kind Category Quick Reference
Kind分类快速参考
| Range | Category | Behavior |
|---|---|---|
| 1000-9999, 4-44, 1, 2 | Regular | Stored by relays, all kept |
| 10000-19999, 0, 3 | Replaceable | Latest per pubkey+kind kept |
| 20000-29999 | Ephemeral | Not stored by relays |
| 30000-39999 | Addressable | Latest per pubkey+kind+d-tag kept |
| 范围 | 分类 | 行为 |
|---|---|---|
| 1000-9999, 4-44, 1, 2 | 常规 | 由中继存储,全部保留 |
| 10000-19999, 0, 3 | 可替换 | 仅保留每个pubkey+kind对应的最新版本 |
| 20000-29999 | 临时 | 不会被中继存储 |
| 30000-39999 | 可寻址 | 仅保留每个pubkey+kind+d-tag对应的最新版本 |
Example: Complete Event Construction
示例:完整事件构建
User says: "I want to reply to my friend's note in an existing thread"
Step 1 — Identify kind: Replying to a kind:1 note → use kind:1 (NIP-10)
Step 2 — Determine thread position: This is a reply to a reply (not the
root), so we need both and e tags.
rootreplyStep 3 — Build the event:
json
{
"pubkey": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2",
"created_at": 1709827200,
"kind": 1,
"tags": [
["e", "aaa111...", "wss://relay.example.com", "root", "f7234bd4..."],
["e", "bbb222...", "wss://relay.example.com", "reply", "93ef2eba..."],
["p", "f7234bd4...", "wss://relay.example.com"],
["p", "93ef2eba...", "wss://relay.example.com"]
],
"content": "Great point! I totally agree with this take."
}Step 4 — Validate: Root e tag has marker ✓, reply e tag has
marker ✓, p tags include both the root author and the parent author ✓, content
is plaintext ✓.
rootreply用户说:「我想在已有线程中回复我朋友的笔记」
步骤1 — 确定kind: 回复kind:1笔记 → 使用kind:1(NIP-10)
步骤2 — 确定线程位置: 这是对回复的回复(不是根内容),所以我们需要同时带有和标记的e标签。
rootreply步骤3 — 构建事件:
json
{
"pubkey": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2",
"created_at": 1709827200,
"kind": 1,
"tags": [
["e", "aaa111...", "wss://relay.example.com", "root", "f7234bd4..."],
["e", "bbb222...", "wss://relay.example.com", "reply", "93ef2eba..."],
["p", "f7234bd4...", "wss://relay.example.com"],
["p", "93ef2eba...", "wss://relay.example.com"]
],
"content": "Great point! I totally agree with this take."
}步骤4 — 验证: 根e标签带有标记 ✓,回复e标签带有标记 ✓,p标签包含根作者和父回复作者 ✓,内容为纯文本 ✓。
rootreply