闪电原生 HTTP 客户端,智能 L402 支付
简介
Lightning Labs 官方出品的 lnget,是支持 L402 协议的原生 HTTP 客户端,可自动完成比特币闪电网络微支付,无缝下载付费墙保护的内容。
原始描述
Install and use lnget, a Lightning-native HTTP client with automatic L402 payment support. Use when downloading files behind Lightning paywalls, managing L402 tokens, checking Lightning backend status, or making HTTP requests that may require micropayments.
通过你的 Agent 添加
安装目录:lnget/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
中文使用说明 来自收录源
核心用法
lnget 是 Lightning Labs 开发的类 wget/curl 命令行工具,原生支持 L402(Lightning HTTP 402)支付认证协议。当服务器返回 HTTP 402 状态码时,工具自动解析 L402 挑战、支付闪电网络发票并携带认证令牌重试请求,实现无感知的付费 API 访问。
主要功能模块
- 基础下载:支持 GET/POST、文件保存、断点续传、自定义 Header
- 支付控制:
--max-cost限制自动支付金额、--max-fee控制路由费、--no-pay预览模式 - 令牌管理:自动缓存 per-domain 的 L402 令牌于
~/.lnget/tokens/,支持手动清理 - 多后端支持:可连接本地 lnd、LNC(Lightning Node Connect)远程配对或嵌入式 Neutrino 轻钱包
- 配置灵活:YAML 配置文件 +
LNGET_前缀环境变量覆盖
显著优点
- 协议原生支持:市面上少数完整实现 L402 客户端协议的 CLI 工具,无需手动处理发票支付和令牌构造
- 来源高度可信:由 Lightning Labs(比特币闪电网络核心基础设施开发商)维护,代码开源 MIT 协议
- 安全设计:支付前金额校验、令牌本地加密存储、支持预览模式避免意外扣款
- 多后端兼容:从本地全节点到轻钱包到远程 LNC,覆盖多种运行场景
- 自动化友好:JSON 输出模式、明确退出码(2=超额、3=支付失败)、支持管道处理
潜在局限
- 生态依赖:仅适用于支持 L402 协议的服务端,当前采用该协议的公开 API 数量有限
- 配置复杂度:需预先配置 Lightning 后端(lnd/LNC/Neutrino),对非技术用户门槛较高
- YAML 生成缺陷:
lnget config init可能生成格式错误的键名(如tlscertpath),需手动修正 - 资金风险:自动支付特性需严格设置
--max-cost上限,否则可能因服务端恶意定价导致损失 - Go 环境依赖:安装需本地 Go toolchain,Windows 用户体验稍弱
适合人群
- 闪电网络开发者测试 L402 付费 API
- 需要自动化访问付费数据服务的脚本/代理系统
- 运行 lnd 节点并频繁使用微支付 API 的高级用户
- 希望体验闪电网络"流支付"场景的技术早期采用者
常规风险
- 支付金额失控:未设置
--max-cost时,服务端可能返回高额发票导致意外支出 - 令牌泄露:本地存储的令牌文件若权限设置不当,可能被其他用户读取复用
- 网络钓鱼:需警惕伪造的 L402 服务端,确保域名与预期服务一致
- LNC 会话管理:LNC 配对码一旦泄露,攻击者可建立持久会话控制节点支付能力
技能正文
name: lnget description: Install and use lnget, a Lightning-native HTTP client with automatic L402 payment support. Use when downloading files behind Lightning paywalls, managing L402 tokens, checking Lightning backend status, or making HTTP requests that may require micropayments.
lnget - Lightning-Native HTTP Client
lnget is a wget/curl-like CLI that natively handles L402 (Lightning HTTP 402) authentication. When a server responds with HTTP 402 and an L402 challenge, lnget automatically pays the Lightning invoice and retries with the paid token.
Source: github.com/lightninglabs/lnget
Quick Start
# 1. Install lnget
skills/lnget/scripts/install.sh
# 2. Initialize config (auto-detects local lnd)
lnget config init
# 3. Fetch an L402-protected resource
lnget --max-cost 1000 https://api.example.com/paid-data
Installation
skills/lnget/scripts/install.sh
This will:
- Verify Go is installed
- Run
go install github.com/lightninglabs/lnget/cmd/lnget@latest - Verify
lngetis on$PATH
To install manually:
go install github.com/lightninglabs/lnget/cmd/lnget@latest
Or build from source:
git clone https://github.com/lightninglabs/lnget.git
cd lnget
make install
Basic Usage
Downloads
# Fetch URL (output to stdout)
lnget https://api.example.com/data.json
# Save to file
lnget -o data.json https://api.example.com/data.json
# Quiet mode for piping
lnget -q https://api.example.com/data.json | jq .
# Resume partial download
lnget -c -o largefile.zip https://api.example.com/largefile.zip
# Custom HTTP method with data
lnget -X POST -d '{"query":"test"}' https://api.example.com/search
# Custom headers
lnget -H "Accept: text/plain" https://api.example.com/data
Payment Control
# Set maximum auto-pay amount (satoshis)
lnget --max-cost 5000 https://api.example.com/expensive.json
# Set maximum routing fee
lnget --max-fee 50 https://api.example.com/data.json
# Preview without paying (shows 402 challenge details)
lnget --no-pay https://api.example.com/data.json
# Custom payment timeout
lnget --payment-timeout 120s https://api.example.com/data.json
Output Modes
# JSON output (default, best for programmatic use)
lnget --json https://api.example.com/data.json
# Human-readable output
lnget --human https://api.example.com/data.json
# Verbose mode (shows L402 flow details)
lnget -v https://api.example.com/data.json
# Disable progress bar
lnget --no-progress -o file.zip https://api.example.com/file.zip
Subcommands
Token Management (lnget tokens)
Tokens are cached per-domain at ~/.lnget/tokens/<domain>/token.json and
reused automatically on subsequent requests.
# List all cached tokens
lnget tokens list
# Show token for a specific domain
lnget tokens show api.example.com
# Remove token for a domain (forces re-authentication)
lnget tokens remove api.example.com
# Clear all tokens
lnget tokens clear --force
Configuration (lnget config)
# Initialize config file at ~/.lnget/config.yaml
lnget config init
# Show current configuration
lnget config show
# Show config file path
lnget config path
Lightning Backend (lnget ln)
# Check backend connection status
lnget ln status
# Show detailed node info
lnget ln info
LNC (Lightning Node Connect)
# Pair with a node via LNC pairing phrase
lnget ln lnc pair "your-pairing-phrase"
# Ephemeral pairing (no session persistence)
lnget ln lnc pair "phrase" --ephemeral
# List saved LNC sessions
lnget ln lnc sessions
# Revoke a session
lnget ln lnc revoke <session-id>
Neutrino (Embedded Wallet)
# Initialize embedded neutrino wallet
lnget ln neutrino init
# Get address to fund wallet
lnget ln neutrino fund
# Check wallet balance
lnget ln neutrino balance
# Show sync status
lnget ln neutrino status
Configuration File
Config lives at ~/.lnget/config.yaml. Run lnget config init to create it.
Note: lnget config init may generate incorrect YAML key names (e.g.,
tlscertpath and macaroonpath instead of tls_cert and macaroon) due to
missing yaml struct tags in the lnget source. Use the example below as the
reference config format. If your config was generated by lnget config init,
verify the ln.lnd keys match the format shown here.
l402:
max_cost_sats: 1000 # Max invoice to auto-pay
max_fee_sats: 10 # Max routing fee
payment_timeout: 60s # Payment timeout
auto_pay: true # Enable auto-payment
http:
timeout: 30s
max_redirects: 10
user_agent: "lnget/0.1.0"
allow_insecure: false
ln:
mode: lnd # Options: lnd, lnc, neutrino
lnd:
host: localhost:10009
tls_cert: ~/.lnd/tls.cert
macaroon: ~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon
network: mainnet
output:
format: json
progress: true
verbose: false
tokens:
dir: ~/.lnget/tokens
Environment variables override config with LNGET_ prefix:
export LNGET_L402_MAX_COST_SATS=5000
export LNGET_LN_MODE=lnc
export LNGET_LN_LND_HOST=localhost:10009
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error |
| 2 | Payment exceeds max cost |
| 3 | Payment failed |
| 4 | Network/connection error |
L402 Flow
When lnget encounters a 402 response:
- Parses
WWW-Authenticate: L402 macaroon="...", invoice="..."header - Decodes the macaroon and BOLT11 invoice
- Checks invoice amount against
--max-cost - Stores a pending token (crash recovery)
- Pays the invoice via the configured Lightning backend
- Stores the paid token with preimage at
~/.lnget/tokens/<domain>/ - Retries the request with
Authorization: L402 <macaroon>:<preimage>
Subsequent requests to the same domain reuse the cached token without payment.
Agent Integration Patterns
Budget-Aware Fetching
# Check cost before committing
result=$(lnget --no-pay --json https://api.example.com/data.json)
cost=$(echo "$result" | jq -r '.invoice_amount_sat // 0')
if [ "$cost" -le "$BUDGET" ]; then
lnget --max-cost "$BUDGET" -q https://api.example.com/data.json
fi
Parsing JSON Output
# Extract just the response body
lnget --json -q https://api.example.com/data.json | jq '.body'
# Check if payment was required
lnget --json https://api.example.com/data.json | jq '.l402_paid'
Testing with Insecure Connections
# For local development with aperture (no TLS)
lnget -k https://localhost:8081/api/data
File Locations
| Path | Purpose |
|---|---|
~/.lnget/config.yaml |
Configuration file |
~/.lnget/tokens/<domain>/ |
Per-domain token storage |
~/.lnget/lnc/sessions/ |
LNC session persistence |
~/.lnget/neutrino/ |
Embedded wallet data |
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。