進階
發票格式
深入理解閃電網路 BOLT 11 發票格式,以及新一代 BOLT 12 Offers 協議。
15 分鐘
BOLT 11 發票
BOLT 11 定義了閃電網路支付請求的標準格式。發票包含支付所需的所有資訊, 使用 Bech32 編碼,易於複製分享和 QR 碼掃描。
BOLT 11 Invoice Example: lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl 2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5 tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n 7erqz25le42c4u4ecky03ylcqca784w Structure: lnbc - prefix (mainnet) 1 - amount (optional) p... - tagged data 8rkx... - signature
發票結構
BOLT 11 Invoice Structure: Prefix: ln + network: • lnbc - Bitcoin mainnet • lntb - testnet • lnbcrt - regtest • lnsb - signet Amount (optional): number + multiplier: • m = milli (0.001) • u = micro (0.000001) • n = nano (0.000000001) • p = pico (0.000000000001) Example: 2500u = 2500 micro = 250000 sats Timestamp: Invoice creation time (UNIX seconds) Tagged Fields: Various payment info... Signature: Receiver node signature
標籤化欄位
Tagged Field Format:
type (5 bits) + data_length (10 bits) + data
Common Tags:
p (1): payment_hash (52 chars, 256 bits)
SHA256 payment hash, required
s (16): payment_secret (52 chars, 256 bits)
prevents probing attacks
d (13): description (variable)
UTF-8 description text
h (23): description_hash (52 chars)
hash of long description
x (6): expiry (variable)
expiry seconds, default 3600 (1 hour)
c (24): min_final_cltv_expiry (variable)
minimum CLTV delta, default 18
n (19): payee node_id (53 chars)
receiver pubkey (recoverable from sig)
r (3): routing hint
private channel routing info
f (9): fallback address
on-chain fallback address
9 (5): feature bits
supported features 路由提示
當接收方只有私有通道時,需要提供路由提示:
Routing Hint Structure (r tag):
Each hint contains one channel:
├── pubkey (33 bytes): entry node pubkey
├── short_channel_id (8 bytes)
├── fee_base_msat (4 bytes)
├── fee_proportional_millionths (4 bytes)
└── cltv_expiry_delta (2 bytes)
Example scenario:
Carol only has private channel to Bob
Invoice includes hint:
r = [
{
pubkey: Bob's pubkey,
short_channel_id: Bob-Carol channel,
fee: ...,
cltv: ...
}
]
Sender routing:
Alice -> ... -> Bob -> Carol (private channel) 解析發票
Decode Example (using lncli):
$ lncli decodepayreq lnbc...
{
"destination": "03...公鑰",
"payment_hash": "0001020304...",
"num_satoshis": "100000",
"timestamp": "1609459200",
"expiry": "3600",
"description": "Coffee payment",
"cltv_expiry": "18",
"features": {
"9": { "name": "tlv-onion" },
"14": { "name": "payment-addr" },
"17": { "name": "multi-path-payments" }
},
"payment_addr": "abcd..."
} BOLT 11 限制
一次性使用
每次支付需要生成新發票,不適合訂閱或捐款場景。
需要交互
發送方必須先從接收方獲取發票,無法離線支付。
會過期
發票有過期時間,過期後無法支付。
無退款機制
沒有標準的退款或部分退款協議。
BOLT 12 Offers
BOLT 12 (Offers) 是新一代支付協議,解決了 BOLT 11 的諸多限制:
BOLT 12 Core Concepts: Offer: • Reusable payment request template • Like a "donation link" • No payment_hash (generated per request) lno1qcp4256ypq... Flow: 1. Merchant publishes Offer 2. Payer sends invoice_request (via onion message) 3. Merchant responds with invoice (with payment_hash) 4. Payer pays Advantages: • Reusable (subscriptions, donations) • Supports refunds (refund message) • Enhanced privacy (receiver can use blinded paths) • No centralized server needed
Offer 結構
Offer TLV Fields: offer_chains (2): supported blockchains offer_metadata (4): merchant custom data offer_currency (6): currency code (e.g. USD) offer_amount (8): amount (for fiat pricing) offer_description (10): description offer_features (12): feature bits offer_absolute_expiry (14): absolute expiry time offer_paths (16): blinded paths offer_issuer (18): issuer name offer_quantity_max (20): max quantity offer_node_id (22): node ID invoice_request Additional Fields: invreq_metadata (0): requester data invreq_chain (80): selected chain invreq_amount (82): payment amount invreq_features (84): features invreq_quantity (86): quantity invreq_payer_id (88): payer ephemeral pubkey invreq_payer_note (89): payer note
BOLT 12 退款
Refund Flow: 1. Original Payment Payer -> Merchant (pay invoice) 2. Refund Request Merchant creates refund (like reverse offer) Sends to original payer 3. Refund Invoice Payer sends invoice_request Merchant responds with invoice 4. Refund Payment Merchant pays invoice Refund TLV: refund_for: original payment_hash refund_amount: refund amount
隱私增強
BOLT 12 Privacy Features: 1. Blinded Paths • Offer can include blinded paths • Payer cannot identify receiver's real node • Suitable for anonymous donations 2. Onion Messages • invoice_request sent via onion network • No direct connection to receiver needed 3. Payer Ephemeral Identity • Each request uses new payer_id • Does not reveal payer's real node ID 4. No payment_hash Correlation • Each payment uses new hash • Cannot correlate multiple payments to same offer
比較
| 特性 | BOLT 11 | BOLT 12 |
|---|---|---|
| 重複使用 | X 一次性 | O 可重複 |
| 退款 | X 無標準 | O 原生支持 |
| 接收方隱私 | - 有限 | O 盲化路徑 |
| 離線接收 | X 需在線 | - 需處理請求 |
| 採用狀態 | O 廣泛 | - 逐步採用中 |
下一步: 了解 路由與尋路 如何找到支付路徑。
已複製連結