该提交新增了完整的 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 部署,内置安全防护与流量控制机制。
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
import aiohttp
|
|
|
|
from yuxi.utils.logging_config import logger
|
|
|
|
|
|
async def verify_nip05(name: str, pubkey_hex: str, timeout: float = 10.0) -> bool:
|
|
if "@" not in name:
|
|
return False
|
|
|
|
local_part, domain = name.rsplit("@", 1)
|
|
url = f"https://{domain}/.well-known/nostr.json?name={local_part}"
|
|
|
|
try:
|
|
async with aiohttp.ClientSession() as session:
|
|
async with session.get(url, timeout=aiohttp.ClientTimeout(total=timeout)) as resp:
|
|
if resp.status != 200:
|
|
logger.debug("[NIP-05] HTTP %s from %s", resp.status, url)
|
|
return False
|
|
data = await resp.json()
|
|
except Exception:
|
|
logger.debug("[NIP-05] 请求失败: %s", url, exc_info=True)
|
|
return False
|
|
|
|
names = data.get("names", {})
|
|
registered_pubkey = names.get(local_part)
|
|
if not registered_pubkey:
|
|
logger.debug("[NIP-05] %s 未在 names 中找到 %s", domain, local_part)
|
|
return False
|
|
|
|
if registered_pubkey.lower() == pubkey_hex.lower():
|
|
return True
|
|
|
|
logger.debug("[NIP-05] pubkey 不匹配: expected=%s, got=%s", pubkey_hex[:12], registered_pubkey[:12])
|
|
return False
|