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

lightningnetwork / lnd / 15561477203

10 Jun 2025 01:54PM UTC coverage: 58.351% (-10.1%) from 68.487%
15561477203

Pull #9356

github

web-flow
Merge 6440b25db into c6d6d4c0b
Pull Request #9356: lnrpc: add incoming/outgoing channel ids filter to forwarding history request

33 of 36 new or added lines in 2 files covered. (91.67%)

28366 existing lines in 455 files now uncovered.

97715 of 167461 relevant lines covered (58.35%)

1.81 hits per line

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

88.89
/keychain/ecdh.go
1
package keychain
2

3
import (
4
        "crypto/sha256"
5

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

9
// NewPubKeyECDH wraps the given key of the key ring so it adheres to the
10
// SingleKeyECDH interface.
11
func NewPubKeyECDH(keyDesc KeyDescriptor, ecdh ECDHRing) *PubKeyECDH {
3✔
12
        return &PubKeyECDH{
3✔
13
                keyDesc: keyDesc,
3✔
14
                ecdh:    ecdh,
3✔
15
        }
3✔
16
}
3✔
17

18
// PubKeyECDH is an implementation of the SingleKeyECDH interface. It wraps an
19
// ECDH key ring so it can perform ECDH shared key generation against a single
20
// abstracted away private key.
21
type PubKeyECDH struct {
22
        keyDesc KeyDescriptor
23
        ecdh    ECDHRing
24
}
25

26
// PubKey returns the public key of the private key that is abstracted away by
27
// the interface.
28
//
29
// NOTE: This is part of the SingleKeyECDH interface.
30
func (p *PubKeyECDH) PubKey() *btcec.PublicKey {
3✔
31
        return p.keyDesc.PubKey
3✔
32
}
3✔
33

34
// ECDH performs a scalar multiplication (ECDH-like operation) between the
35
// abstracted private key and a remote public key. The output returned will be
36
// the sha256 of the resulting shared point serialized in compressed format. If
37
// k is our private key, and P is the public key, we perform the following
38
// operation:
39
//
40
//        sx := k*P
41
//        s := sha256(sx.SerializeCompressed())
42
//
43
// NOTE: This is part of the SingleKeyECDH interface.
44
func (p *PubKeyECDH) ECDH(pubKey *btcec.PublicKey) ([32]byte, error) {
3✔
45
        return p.ecdh.ECDH(p.keyDesc, pubKey)
3✔
46
}
3✔
47

48
// PrivKeyECDH is an implementation of the SingleKeyECDH in which we do have the
49
// full private key. This can be used to wrap a temporary key to conform to the
50
// SingleKeyECDH interface.
51
type PrivKeyECDH struct {
52
        // PrivKey is the private key that is used for the ECDH operation.
53
        PrivKey *btcec.PrivateKey
54
}
55

56
// PubKey returns the public key of the private key that is abstracted away by
57
// the interface.
58
//
59
// NOTE: This is part of the SingleKeyECDH interface.
UNCOV
60
func (p *PrivKeyECDH) PubKey() *btcec.PublicKey {
×
UNCOV
61
        return p.PrivKey.PubKey()
×
UNCOV
62
}
×
63

64
// ECDH performs a scalar multiplication (ECDH-like operation) between the
65
// abstracted private key and a remote public key. The output returned will be
66
// the sha256 of the resulting shared point serialized in compressed format. If
67
// k is our private key, and P is the public key, we perform the following
68
// operation:
69
//
70
//        sx := k*P
71
//        s := sha256(sx.SerializeCompressed())
72
//
73
// NOTE: This is part of the SingleKeyECDH interface.
74
func (p *PrivKeyECDH) ECDH(pub *btcec.PublicKey) ([32]byte, error) {
3✔
75
        var (
3✔
76
                pubJacobian btcec.JacobianPoint
3✔
77
                s           btcec.JacobianPoint
3✔
78
        )
3✔
79
        pub.AsJacobian(&pubJacobian)
3✔
80

3✔
81
        btcec.ScalarMultNonConst(&p.PrivKey.Key, &pubJacobian, &s)
3✔
82
        s.ToAffine()
3✔
83
        sPubKey := btcec.NewPublicKey(&s.X, &s.Y)
3✔
84
        return sha256.Sum256(sPubKey.SerializeCompressed()), nil
3✔
85
}
3✔
86

87
var _ SingleKeyECDH = (*PubKeyECDH)(nil)
88
var _ SingleKeyECDH = (*PrivKeyECDH)(nil)
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