跳至主要內容
高級

Key Derivation 密鑰派生

了解閃電網路節點的密鑰派生機制,從種子到各種用途的密鑰。

12 分鐘

密鑰層次結構

閃電網路節點從單一種子派生出多種用途的密鑰,確保所有密鑰都可以從種子恢復。

確定性派生: 使用 BIP 32/39 標準,從 24 個助記詞可以恢復所有密鑰。

LND 密鑰路徑

LND Key Family 結構:

種子 → Master Key → 各種密鑰家族
m/1017'/coin_type'/key_family/0/index

1017' = Lightning 專用 BIP
coin_type' = 0' (mainnet) / 1' (testnet)

Key Families:
├── 0: MultiSig(多簽,用於資金輸出)
├── 1: RevocationBase(撤銷基礎密鑰)
├── 2: HtlcBase(HTLC 基礎密鑰)
├── 3: PaymentBase(支付基礎密鑰)
├── 4: DelayBase(延遲基礎密鑰)
├── 5: RevocationRoot(撤銷根密鑰)
├── 6: NodeKey(節點身份密鑰)
└── 7+: 自定義用途

通道密鑰

每個通道使用的密鑰:

Funding 多簽:
funding_pubkey = derive(MultiSig, channel_index)
2-of-2 多簽:local_funding + remote_funding

Commitment 交易密鑰:
per_commitment_point = 每次更新變化

派生的密鑰:
├── local_delayedpubkey(延遲輸出)
├── remote_pubkey(對方輸出)
├── local_htlcpubkey(本地 HTLC)
├── remote_htlcpubkey(對方 HTLC)
└── revocationpubkey(撤銷密鑰)

公式:
pubkey = basepoint + SHA256(per_commitment || basepoint) × G

撤銷密鑰派生:
revocation_pubkey = revocation_basepoint × SHA256(...) +
                    per_commitment_point × SHA256(...)

只有知道 per_commitment_secret 才能花費撤銷輸出

Per-Commitment Secrets

Shachain 高效存儲:

問題:每個承諾交易需要一個 secret
1000 萬次更新 = 需要存儲 1000 萬個 secrets?

解決方案:Shachain
使用二叉樹結構派生 secrets

             root
            /    \
          s0      s1
         /  \    /  \
       s00  s01 s10  s11

特性:
• 可以從父節點派生所有子節點
• 只需存儲 O(log n) 個值
• 48 個元素可覆蓋 2^48 次更新

派生:secret_i = SHA256(secret_{parent} || direction)

備份重要性

種子詞語是恢復節點的唯一方式,必須安全備份。

通道狀態

種子無法恢復通道狀態,需要額外的 SCB 備份。

Aezeed vs BIP39: LND 使用 Aezeed 格式(包含版本和生日),與標準 BIP39 不完全兼容。

相關資源

已複製連結
已複製到剪貼簿