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

lightningnetwork / lnd / 13211764208

08 Feb 2025 03:08AM UTC coverage: 49.288% (-9.5%) from 58.815%
13211764208

Pull #9489

github

calvinrzachman
itest: verify switchrpc server enforces send then track

We prevent the rpc server from allowing onion dispatches for
attempt IDs which have already been tracked by rpc clients.

This helps protect the client from leaking a duplicate onion
attempt. NOTE: This is not the only method for solving this
issue! The issue could be addressed via careful client side
programming which accounts for the uncertainty and async
nature of dispatching onions to a remote process via RPC.
This would require some lnd ChannelRouter changes for how
we intend to use these RPCs though.
Pull Request #9489: multi: add BuildOnion, SendOnion, and TrackOnion RPCs

474 of 990 new or added lines in 11 files covered. (47.88%)

27321 existing lines in 435 files now uncovered.

101192 of 205306 relevant lines covered (49.29%)

1.54 hits per line

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

0.0
/lntest/mock/secretkeyring.go
1
package mock
2

3
import (
4
        "github.com/btcsuite/btcd/btcec/v2"
5
        "github.com/btcsuite/btcd/btcec/v2/ecdsa"
6
        "github.com/btcsuite/btcd/btcec/v2/schnorr"
7
        "github.com/btcsuite/btcd/chaincfg/chainhash"
8
        "github.com/btcsuite/btcd/txscript"
9
        "github.com/lightningnetwork/lnd/keychain"
10
)
11

12
// SecretKeyRing is a mock implementation of the SecretKeyRing interface.
13
type SecretKeyRing struct {
14
        RootKey *btcec.PrivateKey
15
}
16

17
// DeriveNextKey currently returns dummy values.
18
func (s *SecretKeyRing) DeriveNextKey(
UNCOV
19
        _ keychain.KeyFamily) (keychain.KeyDescriptor, error) {
×
UNCOV
20

×
UNCOV
21
        return keychain.KeyDescriptor{
×
UNCOV
22
                PubKey: s.RootKey.PubKey(),
×
UNCOV
23
        }, nil
×
UNCOV
24
}
×
25

26
// DeriveKey currently returns dummy values.
27
func (s *SecretKeyRing) DeriveKey(
UNCOV
28
        _ keychain.KeyLocator) (keychain.KeyDescriptor, error) {
×
UNCOV
29

×
UNCOV
30
        return keychain.KeyDescriptor{
×
UNCOV
31
                PubKey: s.RootKey.PubKey(),
×
UNCOV
32
        }, nil
×
UNCOV
33
}
×
34

35
// DerivePrivKey currently returns dummy values.
36
func (s *SecretKeyRing) DerivePrivKey(
37
        _ keychain.KeyDescriptor) (*btcec.PrivateKey, error) {
×
38

×
39
        return s.RootKey, nil
×
40
}
×
41

42
// ECDH currently returns dummy values.
43
func (s *SecretKeyRing) ECDH(_ keychain.KeyDescriptor,
UNCOV
44
        _ *btcec.PublicKey) ([32]byte, error) {
×
UNCOV
45

×
UNCOV
46
        return [32]byte{}, nil
×
UNCOV
47
}
×
48

49
// SignMessage signs the passed message and ignores the KeyDescriptor.
50
func (s *SecretKeyRing) SignMessage(_ keychain.KeyLocator,
51
        msg []byte, doubleHash bool) (*ecdsa.Signature, error) {
×
52

×
53
        var digest []byte
×
54
        if doubleHash {
×
55
                digest = chainhash.DoubleHashB(msg)
×
56
        } else {
×
57
                digest = chainhash.HashB(msg)
×
58
        }
×
59
        return ecdsa.Sign(s.RootKey, digest), nil
×
60
}
61

62
// SignMessageCompact signs the passed message.
63
func (s *SecretKeyRing) SignMessageCompact(_ keychain.KeyLocator,
64
        msg []byte, doubleHash bool) ([]byte, error) {
×
65

×
66
        var digest []byte
×
67
        if doubleHash {
×
68
                digest = chainhash.DoubleHashB(msg)
×
69
        } else {
×
70
                digest = chainhash.HashB(msg)
×
71
        }
×
72

73
        return ecdsa.SignCompact(s.RootKey, digest, true), nil
×
74
}
75

76
// SignMessageSchnorr signs the passed message and ignores the KeyDescriptor.
77
func (s *SecretKeyRing) SignMessageSchnorr(_ keychain.KeyLocator,
78
        msg []byte, doubleHash bool, taprootTweak []byte,
79
        tag []byte) (*schnorr.Signature, error) {
×
80

×
81
        var digest []byte
×
82
        switch {
×
83
        case len(tag) > 0:
×
84
                taggedHash := chainhash.TaggedHash(tag, msg)
×
85
                digest = taggedHash[:]
×
86
        case doubleHash:
×
87
                digest = chainhash.DoubleHashB(msg)
×
88
        default:
×
89
                digest = chainhash.HashB(msg)
×
90
        }
91

92
        privKey := s.RootKey
×
93
        if len(taprootTweak) > 0 {
×
94
                privKey = txscript.TweakTaprootPrivKey(*privKey, taprootTweak)
×
95
        }
×
96

97
        return schnorr.Sign(privKey, digest)
×
98
}
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