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

lightningnetwork / lnd / 13536249039

26 Feb 2025 03:42AM UTC coverage: 57.462% (-1.4%) from 58.835%
13536249039

Pull #8453

github

Roasbeef
peer: update chooseDeliveryScript to gen script if needed

In this commit, we update `chooseDeliveryScript` to generate a new
script if needed. This allows us to fold in a few other lines that
always followed this function into this expanded function.

The tests have been updated accordingly.
Pull Request #8453: [4/4] - multi: integrate new rbf coop close FSM into the existing peer flow

275 of 1318 new or added lines in 22 files covered. (20.86%)

19521 existing lines in 257 files now uncovered.

103858 of 180741 relevant lines covered (57.46%)

24750.23 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 {
514✔
31
        return p.keyDesc.PubKey
514✔
32
}
514✔
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.
UNCOV
44
func (p *PubKeyECDH) ECDH(pubKey *btcec.PublicKey) ([32]byte, error) {
×
UNCOV
45
        return p.ecdh.ECDH(p.keyDesc, pubKey)
×
UNCOV
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