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

lightningnetwork / lnd / 12293715361

12 Dec 2024 09:38AM UTC coverage: 57.483% (+7.9%) from 49.538%
12293715361

Pull #9348

github

ziggie1984
github: update goveralls tool

The goverall tool had a bug regarding the module versioning of
golang packages see also
https://github.com/mattn/goveralls/pull/222 for more background.
Goveralls is wrapped by another library to make it available for
github actions. So the relevant PR which is referenced here in
LND is:
https://github.com/shogo82148/actions-goveralls/pull/521.
Pull Request #9348: github: update goveralls tool

101897 of 177264 relevant lines covered (57.48%)

24982.4 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 {
136✔
12
        return &PubKeyECDH{
136✔
13
                keyDesc: keyDesc,
136✔
14
                ecdh:    ecdh,
136✔
15
        }
136✔
16
}
136✔
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 {
516✔
31
        return p.keyDesc.PubKey
516✔
32
}
516✔
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) {
×
45
        return p.ecdh.ECDH(p.keyDesc, pubKey)
×
46
}
×
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.
60
func (p *PrivKeyECDH) PubKey() *btcec.PublicKey {
768✔
61
        return p.PrivKey.PubKey()
768✔
62
}
768✔
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) {
2,027✔
75
        var (
2,027✔
76
                pubJacobian btcec.JacobianPoint
2,027✔
77
                s           btcec.JacobianPoint
2,027✔
78
        )
2,027✔
79
        pub.AsJacobian(&pubJacobian)
2,027✔
80

2,027✔
81
        btcec.ScalarMultNonConst(&p.PrivKey.Key, &pubJacobian, &s)
2,027✔
82
        s.ToAffine()
2,027✔
83
        sPubKey := btcec.NewPublicKey(&s.X, &s.Y)
2,027✔
84
        return sha256.Sum256(sPubKey.SerializeCompressed()), nil
2,027✔
85
}
2,027✔
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