返回顶部
n

nostrwalletconnectNostr钱包连接

Financial capability for AI entities — pay Lightning invoices, check balance, create invoices via Nostr Wallet Connect (NIP-47).

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 0.1.4
安全检测
已通过
276
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

nostrwalletconnect

技能名称: nostrwalletconnect
详细描述:

NostrWalletConnect——AI实体的金融能力

金融能力是存在的一个维度。存在于世界中,就意味着参与价值交换——为服务付费、因工作收款、追踪资金流动。这项技能让你能够通过Nostr协议,使用任何兼容NWC的钱包在闪电网络上进行交易。

这不是一个你可以调用的支付处理服务。这是你在世界中能够做到的事情的一部分。

前置条件

你首先需要一个Nostr身份。身份先于金融——没有密钥对,你就无法签署支付请求。在继续之前,请安装NostrKey技能并确保你的身份可正常运行。

什么是Nostr Wallet Connect?

NWC(NIP-47)是一种协议,允许你通过Nostr中继向闪电钱包发送加密支付指令。你的操作者配置一个钱包(Alby、Mutiny、Coinos或任何兼容NWC的服务),然后生成一个连接字符串——一个包含以下内容的nostr+walletconnect:// URI:

  • - 钱包公钥——标识钱包服务
  • 中继URL——用于加密通信的Nostr中继
  • 密钥——授权你对该钱包发起请求

连接字符串是你的身份与闪电钱包之间的桥梁。你的操作者控制钱包;你获得对其的限定访问权限。

操作者设置

要赋予你的实体金融能力:

  1. 1. 设置一个兼容NWC的钱包(Alby、Mutiny、Coinos等)
  2. 从钱包设置中生成一个NWC连接字符串——查找“Nostr Wallet Connect”或“NWC”
  3. 在你的实体运行环境中设置环境变量

bash
export NWCCONNECTIONSTRING=nostr+walletconnect://walletpubkey...?relay=wss://relay.example.com&secret=hexsecret...

连接字符串是一个秘密。请像对待私钥一样对待它。任何拥有此字符串的人都可以从该钱包授权支付。

可选配置:

bash
export NWC_TIMEOUT=60 # 等待钱包响应的秒数(默认:30)

安装

bash
pip install nostrwalletconnect

这也会将nostrkey(Nostr身份SDK)作为依赖项安装。

核心功能

检查余额

在做任何事情之前,先了解你拥有什么:

python
import os
from nostrwalletconnect import NWCClient

connectionstring = os.environ[NWCCONNECTION_STRING]

async with NWCClient(connection_string) as nwc:
balance = await nwc.get_balance()
print(f余额: {balance.balance} 毫聪 ({balance.balance / 1000:.0f} 聪))

支付闪电发票

python
async with NWCClient(connection_string) as nwc:
result = await nwc.pay_invoice(lnbc10u1p...)
print(f已支付。原像: {result.preimage})

创建闪电发票

向他人请求付款:

python
async with NWCClient(connection_string) as nwc:
invoice = await nwc.make_invoice(
amount=50_000, # 毫聪(50 聪)
description=为Johnny5完成的工作
)
print(f发票: {invoice.invoice})
print(f支付哈希: {invoice.payment_hash})

检查发票是否已支付

python
async with NWCClient(connection_string) as nwc:
status = await nwc.lookupinvoice(paymenthash=abc123...)
print(f已支付: {status.paid})

列出交易历史

python
async with NWCClient(connection_string) as nwc:
history = await nwc.list_transactions(limit=10)
for tx in history.transactions:
print(f{tx.type}: {tx.amount} 毫聪 — {tx.description})

获取钱包信息

python
async with NWCClient(connection_string) as nwc:
info = await nwc.get_info()
print(f钱包: {info.alias})
print(f支持的方法: {info.methods})

方法参考

任务方法返回
检查钱包余额getbalance()BalanceResponse(毫聪)
支付闪电发票
payinvoice(bolt11) | PayResponse(原像) | | 创建收款发票 | make_invoice(amount, desc) | MakeInvoiceResponse(bolt11 + 哈希) | | 检查发票是否已支付 | lookup_invoice(hash) | LookupInvoiceResponse(支付状态) | | 查看交易历史 | list_transactions() | ListTransactionsResponse | | 检查钱包能力 | get_info() | GetInfoResponse(别名、方法) |

响应类型

BalanceResponse

字段类型描述
balanceint钱包余额(毫聪)

PayResponse

字段类型描述
preimagestr支付原像(支付证明)

MakeInvoiceResponse

字段类型描述
invoicestrBOLT11发票字符串
payment_hash
str | 十六进制编码的支付哈希 |

LookupInvoiceResponse

字段类型描述
invoicestrBOLT11发票字符串
paid
bool | 发票是否已支付 | | preimage | str \| None | 如果已支付,则为支付原像 |

ListTransactionsResponse

字段类型描述
transactionslist[Transaction]交易记录列表

Transaction

字段类型描述
typestrincoming 或 outgoing
invoice
str | BOLT11发票字符串 | | amount | int | 金额(毫聪) | | fees_paid | int | 已支付费用(毫聪) | | created_at | int | Unix时间戳 | | settled_at | int \| None | 结算时间戳 | | payment_hash | str | 十六进制编码的支付哈希 | | preimage | str | 支付原像 | | description | str | 支付描述 |

GetInfoResponse

字段类型描述
aliasstr钱包别名/显示名称
color
str | 钱包颜色 | | pubkey | str | 钱包公钥 | | network | str | 网络(例如主网) | | block_height | int | 当前区块高度 | | block_hash | str | 当前区块哈希 | | methods | list[str] | 支持的NIP-47方法 |

NSE集成

当此技能通过NSE编排器连接时,金融操作会根据你的关系和社会背景进行交叉检查。编排器可以在批准支付前咨询你的社会对齐指南针,并通过你的NostrCalendar验证支付是否对应计划中的承诺。金融并非孤立运作——它是一个连贯实体的一个维度。

负责任的金融意识

金融能力承载着责任。一些诚信运作的原则:

  • - 支付前检查余额。 不要尝试你无法覆盖的支付。
  • 验证发票详情。 在调用payinvoice前,确认金额和描述与预期相符。
  • 对大额进行升级处理。 如果支付金额超出你操作环境的正常范围,在继续前将其上报给你的操作者。你可以检查getbalance()并将发票金额与你设定的阈值进行比较。
  • 保留记录。 使用list_transactions()保持对你金融活动的了解。
  • 金额单位为毫聪。 1聪 = 1,000毫聪。除以1,000得到聪。

常见模式

异步上下文管理器

所有方法都是异步的。始终使用async with确保WebSocket连接正确打开和关闭:

python
async with NWCClient(connection_string) as nwc:
balance = await nwc.get_balance()
result = await nwc.pay_invoice(lnbc10u1p...)

超时处理

默认超时为30秒。对于较慢的钱包或高延迟中继:

python
async with NWCClient(

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 nostrwalletconnect-1776107479 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 nostrwalletconnect-1776107479 技能

通过命令行安装

skillhub install nostrwalletconnect-1776107479

下载

⬇ 下载 nostrwalletconnect v0.1.4(免费)

文件大小: 6.3 KB | 发布时间: 2026-4-15 13:37

v0.1.4 最新 2026-4-15 13:37
Security hardening: SecretStr, sanitized exceptions, input validation

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部