高級
Onion Messages 洋蔥訊息
了解洋蔥訊息如何在閃電網路中實現無需支付、無需通道的端到端加密通訊,是 BOLT 12 的基礎設施。
12 分鐘
什麼是 Onion Messages?
Onion Messages(洋蔥訊息)是閃電網路的一種新型通訊機制,允許節點之間 發送端到端加密的訊息,而不需要建立通道或進行支付。它使用與支付相同的 洋蔥路由技術來保護隱私,是 BOLT 12 Offers 的核心基礎設施。
核心價值: Onion Messages 讓閃電網路從純支付網路擴展為通用的隱私通訊層, 支持發票請求、報價查詢、未來甚至可能支持聊天應用。
與 HTLC 的區別
HTLC vs Onion Messages: HTLC (Payments): • Transfers value (sats) • Requires channels and liquidity • Funds locked until settlement • Has time limits (CLTV) • Failures roll back • Cannot send pure messages Onion Messages: • Only transfers data (no value transfer) • No channel needed (just need node pubkey) • No funds locked • No time limits • Fire and forget • Cannot transfer sats Both use onion routing for privacy!
訊息結構
Onion Message Structure:
Message type: 513 (onion_message)
onion_message:
blinding_point: 33 bytes (for route blinding)
onion_routing_packet:
version: 0
public_key: 33 bytes
hop_payloads: 1300 bytes (encrypted routing info)
hmac: 32 bytes
Per-hop Payload (TLV):
encrypted_recipient_data (type 4): encrypted routing data
next_node_id (type 6): next hop node ID
path_id (type 8): for reply path identification
message (type 64): final message content
invoice_request (type 66): BOLT 12 invoice request
invoice (type 68): BOLT 12 invoice 路由與轉發
Onion Message Routing:
Routing without channels:
Alice --> Bob --> Carol --> Dave
| | |
| Can forward without channels!
|
+-- Only need to know network topology
Send flow:
1. Alice knows Dave's public key
2. Alice finds a path from gossip network
3. Alice builds onion packet
4. Each node decrypts its layer, forwards to next hop
5. Dave receives final message
Connectionless forwarding:
Bob receives onion_message:
1. Uses blinding_point to decrypt his payload
2. Finds next_node_id
3. Calculates new blinding_point
4. Forwards to next hop
Bob doesn't need channels with Alice or Dave! Reply Path(回覆路徑)
Reply Path Mechanism:
Problem: How to reply to an anonymous sender?
Solution: Sender includes blinded reply path
Alice's request message:
destination: Dave (or blinded path to Dave)
reply_path:
introduction_node: Bob
blinding_point: ...
blinded_hops: [..., ..., Alice]
message: "Please send me an invoice"
Dave replies:
1. Dave decrypts message
2. Dave uses reply_path to send reply
3. Reply reaches Alice through blinded path
4. Dave doesn't know who Alice is!
Bidirectional privacy:
• Alice doesn't know Dave's real location (if using blinded path)
• Dave doesn't know Alice's real location (through reply path) BOLT 12 整合
Onion Messages 是 BOLT 12 Offers 的傳輸層:
BOLT 12 Flow Using Onion Messages:
1. Bob publishes Offer
lno1... (contains blinded path to Bob)
2. Alice sends invoice_request (Onion Message)
onion_message:
destination: Bob's blinded path
payload:
invoice_request:
offer_id: ...
amount: 100000
payer_key: Alice's key
reply_path: [... -> Alice]
3. Bob replies with invoice (Onion Message)
onion_message:
destination: Alice's reply_path
payload:
invoice:
amount: 100000
payment_hash: ...
paths: [blinded paths to Bob]
4. Alice pays using blinded paths from invoice DoS 保護
潛在風險
- • 免費轉發可能被濫用
- • 可能用於垃圾訊息攻擊
- • 節點資源可能被耗盡
- • 無法追蹤發送者
保護措施
- • 速率限制(每秒/每對等)
- • 訊息大小限制
- • 可選擇不轉發
- • 未來可能加入付費轉發
未來應用
隱私聊天
基於 Onion Messages 構建端到端加密的去中心化聊天應用。
支付證明傳遞
支付完成後,通過 Onion Message 發送收據或額外數據。
訂閱通知
商家可以向訂閱者發送更新通知,用戶保持匿名。
實現狀態
Core Lightning 完整支持
CLN 是 Onion Messages 的主要推動者,完整支持發送、接收和轉發。
LDK 完整支持
Lightning Dev Kit 支持 Onion Messages 和 BOLT 12。
LND 開發中
LND 正在開發 BOLT 12 和 Onion Messages 支持。
Eclair 已支持
Eclair 支持 Onion Messages,用於 Phoenix 的 BOLT 12 功能。
相關資源
下一步: 了解 Anchor Outputs 如何解決閃電網路的手續費問題。
已複製連結