• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 18340726508

08 Oct 2025 09:49AM UTC coverage: 66.653%. First build
18340726508

Pull #9868

github

web-flow
Merge a988f91c8 into 30decfc3c
Pull Request #9868: Basic structures for onion messages into LND

162 of 243 new or added lines in 11 files covered. (66.67%)

137441 of 206205 relevant lines covered (66.65%)

21298.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.71
/lnwire/onion_message.go
1
package lnwire
2

3
import (
4
        "bytes"
5
        "io"
6

7
        "github.com/btcsuite/btcd/btcec/v2"
8
)
9

10
// OnionMessage is a message that carries an onion-encrypted payload.
11
// This is used for BOLT12 messages.
12
type OnionMessage struct {
13
        // PathKey is the route blinding ephemeral pubkey to be used for
14
        // the onion message.
15
        PathKey *btcec.PublicKey
16

17
        // OnionBlob contains the onion_message_packet, the raw serialized
18
        // Sphinx onion packet (BOLT 4) containing the layered, per-hop
19
        // encrypted payloads and routing instructions used to forward this
20
        // message along its designated path. This blob should be handled in the
21
        // same manner as onion_routing_packet used to route HTLCs, with the
22
        // exception that it uses blinded routes by default.
23
        OnionBlob []byte
24
}
25

26
// NewOnionMessage creates a new OnionMessage.
27
func NewOnionMessage(pathKey *btcec.PublicKey,
28
        onion []byte) *OnionMessage {
103✔
29

103✔
30
        return &OnionMessage{
103✔
31
                PathKey:   pathKey,
103✔
32
                OnionBlob: onion,
103✔
33
        }
103✔
34
}
103✔
35

36
// A compile-time check to ensure OnionMessage implements the Message interface.
37
var _ Message = (*OnionMessage)(nil)
38

39
// Decode reads the bytes stream and converts it to the object.
40
func (o *OnionMessage) Decode(r io.Reader, _ uint32) error {
103✔
41
        if err := ReadElement(r, &o.PathKey); err != nil {
103✔
NEW
42
                return err
×
NEW
43
        }
×
44

45
        var onionLen uint16
103✔
46
        if err := ReadElement(r, &onionLen); err != nil {
103✔
NEW
47
                return err
×
NEW
48
        }
×
49

50
        o.OnionBlob = make([]byte, onionLen)
103✔
51
        if err := ReadElement(r, o.OnionBlob); err != nil {
103✔
NEW
52
                return err
×
NEW
53
        }
×
54

55
        return nil
103✔
56
}
57

58
// Encode converts object to the bytes stream and write it into the
59
// write buffer.
60
func (o *OnionMessage) Encode(w *bytes.Buffer, _ uint32) error {
103✔
61
        if err := WritePublicKey(w, o.PathKey); err != nil {
103✔
NEW
62
                return err
×
NEW
63
        }
×
64

65
        onionLen := len(o.OnionBlob)
103✔
66
        if err := WriteUint16(w, uint16(onionLen)); err != nil {
103✔
NEW
67
                return err
×
NEW
68
        }
×
69

70
        if err := WriteBytes(w, o.OnionBlob); err != nil {
103✔
NEW
71
                return err
×
NEW
72
        }
×
73

74
        return nil
103✔
75
}
76

77
// MsgType returns the integer uniquely identifying this message type on the
78
// wire.
79
func (o *OnionMessage) MsgType() MessageType {
103✔
80
        return MsgOnionMessage
103✔
81
}
103✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc