该提交新增了完整的 Nostr 去中心化社交网络适配器实现,包含以下核心功能: 1. 基础加密与密钥处理:支持 nsec/npub/hex 格式密钥转换,实现 NIP-04/NIP-17 加解密 2. Relay 管理与健康监控:支持多 Relay 连接、自动重连、健康评分与自动选优 3. 事件与消息处理:实现事件校验、去重、速率限制、消息缓存与状态持久化 4. 个人资料管理:支持发布/导入/合并 Nostr Kind 0 元数据事件 5. 配对机制:实现安全的双向配对通信流程 6. Zap 功能:支持 NIP-57 打赏请求与收据解析 7. NIP-05 验证:实现域名身份验证 8. 配置系统:完整的配置校验与多账户支持 9. 监控与指标:提供连接监控、事件统计与健康快照 10. HTTP API:提供个人资料管理的 RESTful 接口 11. 安装向导:命令行配置向导与初始化流程 所有模块均遵循 Nostr 协议规范,支持多账户、多 Relay 部署,内置安全防护与流量控制机制。
35 lines
870 B
Python
35 lines
870 B
Python
from __future__ import annotations
|
|
|
|
from yuxi.channels.adapters.nostr.crypto import normalize_pubkey
|
|
|
|
|
|
def normalize_target(raw: str) -> str:
|
|
if not raw:
|
|
return ""
|
|
cleaned = raw.strip().lower()
|
|
if cleaned.startswith("nostr:"):
|
|
cleaned = cleaned[6:]
|
|
normalized = normalize_pubkey(cleaned)
|
|
if normalized:
|
|
return normalized
|
|
return ""
|
|
|
|
|
|
def looks_like_id(raw: str) -> bool:
|
|
if not raw:
|
|
return False
|
|
cleaned = raw.strip().lower()
|
|
if cleaned.startswith("nostr:"):
|
|
cleaned = cleaned[6:]
|
|
if cleaned.startswith("npub1") and len(cleaned) == 63:
|
|
return True
|
|
if cleaned.startswith("nprofile1"):
|
|
return True
|
|
if len(cleaned) == 64 and all(c in "0123456789abcdef" for c in cleaned):
|
|
return True
|
|
return False
|
|
|
|
|
|
def hint() -> str:
|
|
return "<npub|hex pubkey|nprofile>"
|