Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

lightning-onion

БесплатноБез исполняемых скриптовНе проверен

Sphinx onion routing for Lightning (BOLT 4): packet structure, per-hop encryption, payload TLV, blinded paths, attribution data, onion messages. USE WHEN…

claude-dev-suiteот claude-dev-suite★ 51 звезда на GitHub

Об этом скилле

Lightning Onion Routing (Sphinx)

Lightning uses Sphinx — an anonymity-set-of-N onion routing protocol. Each hop knows only the previous and next hops, not source/destination.

Packet structure (BOLT 4)

[1 byte]    version (0x00)
[33 bytes]  ephemeral compressed pubkey
[1300 bytes] hops_data (encrypted)
[32 bytes]  HMAC over the packet

Total: 1366 bytes.

Up to 20 hops at 65 bytes/hop in legacy mode, or 27 hops in TLV mode.

Per-hop derivation

For each hop i:

shared_secret_i = ECDH(node_i_privkey, ephemeral_pubkey)
rho_key_i, mu_key_i, um_key_i = derive_keys(shared_secret_i)

Used for:

  • rho (ChaCha20) — encrypt forward stream.
  • mu (HMAC-SHA256) — verify HMAC.
  • um (HMAC-SHA256) — authenticate failure messages on the backward path; the backward XOR stream uses ammag (and ammagext for attribution data).

Per-hop payload (TLV mode)

TLV records, each: type, length, value:
  type 2: amt_to_forward (u64)
  type 4: outgoing_cltv_value (u32)
  type 6: short_channel_id (u64)
  type 8: payment_data { payment_secret, total_msat }   (final hop)
  type 10: encrypted_recipient_data (for blinded paths)
  type 16: payment_metadata
  custom records (>= 65536, per BOLT 4)

For non-final hops: short_channel_id says which channel to forward on. For final hop: omit short_channel_id, include payment_data.

Onion construction (sender)

def build_onion(route, payloads, payment_hash):
    eph_priv = random_scalar()
    eph_pub  = eph_priv * G

    shared_secrets = []
    cur_priv = eph_priv
    for hop in route:
        ss = ecdh(cur_priv, hop.pubkey)
        shared_secrets.push(ss)
        # blinding factor for next hop
        b = sha256(eph_pub_bytes(cur_priv) || ss)
        cur_priv = (cur_priv * b) mod n

    # Build hops_data layered backward
    hops_data = zeros(1300)
    for i in reverse(range(len(route))):
        # Generate fillers for previous hops
        # Encrypt payload[i] using rho_key[i]
        # Insert payload bytes
        ...

    return SphinxPacket(version=0, eph_pub=eph_pub_initial, hops_data, hmac)

Reference impl: rust-bitcoin/lightning-onion, BOLT 4 test vectors.

Onion processing (forwarder)

def process_onion(my_priv, packet):
    # 1. Verify HMAC
    ss = ecdh(my_priv, packet.eph_pub)
    if hmac(mu_key(ss), payload) != packet.hmac: REJECT

    # 2. Decrypt one layer
    payload, rest = chacha20_decrypt(rho_key(ss), packet.hops_data)

    # 3. Read this hop's data
    my_payload = parse_tlv(payload)

    # 4. Build packet for next hop
    next_eph_pub = ss-derived blinded next eph_pub
    return next_packet, my_payload

Failure messages

When a hop fails the HTLC, it returns a failure message encrypted backward along the route:

return_packet = hmac(32B) || failure_len(2B) || failuremsg
                || pad_len(2B) || pad
hmac          = HMAC-SHA256(um_key_i, rest of return_packet)
obfuscated    = return_packet XOR chacha20_stream(ammag_key_i)

Each upstream hop wraps with its own ammag stream — no hop decrypts or re-MACs. The source peels the layers in route order and attributes the failure to the first hop whose um HMAC verifies, so eventually only the source can read the original failure.

This prevents intermediate nodes from learning the source's identity even on failure.

Attribution data (feature 36/37)

option_attribution_data (BOLT 9 bits 36/37, merged into BOLT 4 2025-11-17 by bolts PR #1044) adds a second return field next to reason, carried as TLV type 1 on both update_fail_htlc and update_fulfill_htlc:

htlc_hold_times  20 * u32        per-hop hold time, units of 100 ms
truncated_hmacs  210 * 4 bytes   HMAC-SHA256 truncated to 4 bytes

Each hop shifts both arrays back one slot (pruning the now-unreachable HMACs), writes its own hold time at the front, adds its 20 truncated HMACs — one per position it could occupy, since only the sender knows where it sits — and XORs the whole block with a stream from a new key type ammagext. hmac_x_y covers, in order: the return packet before obfuscation, the first y+1 hold times, and the y downstream HMACs. So a hop cannot tamper with anything downstream without invalidating its own HMAC. 210 = 20+19+...+1, the HMACs still reachable after pruning.

The origin verifies each hop's HMAC with that hop's um key. The first HMAC that fails is the blame boundary: it makes a failure attributable to a node pair rather than to the whole route, and the recorded hold times give the sender a per-hop latency measurement for scoring. Reporting zero is allowed for nodes without accurate timing; the sender should then spread the latency penalty across hops.

Hops reached with path_key set (inside a blinded path) do not contribute attribution data — they fail via update_fail_malformed_htlc with invalid_onion_blinding, and their timings would aid de-anonymization. Attribution therefore stops at the introduction n

Полный SKILL.md на GitHub

Установить lightning-onion в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Read
Grep
Glob

FAQ

Что делает скилл lightning-onion?

Sphinx onion routing for Lightning (BOLT 4): packet structure, per-hop encryption, payload TLV, blinded paths, attribution data, onion messages. USE WHEN: implementing onion construction/decryption, debugging routing payloads, designing onion-based off-chain protocols.

Как установить скилл lightning-onion?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл lightning-onion запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить lightning-onion с