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

lightningnetwork / lnd / 13408822928

19 Feb 2025 08:59AM UTC coverage: 41.123% (-17.7%) from 58.794%
13408822928

Pull #9521

github

web-flow
Merge d2f397b3c into 0e8786348
Pull Request #9521: unit: remove GOACC, use Go 1.20 native coverage functionality

92496 of 224923 relevant lines covered (41.12%)

18825.83 hits per line

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

0.0
/watchtower/blob/derivation.go
1
package blob
2

3
import (
4
        "crypto/sha256"
5
        "encoding/hex"
6

7
        "github.com/btcsuite/btcd/chaincfg/chainhash"
8
)
9

10
// BreachHintSize is the length of the identifier used to detect remote
11
// commitment broadcasts.
12
const BreachHintSize = 16
13

14
// BreachHint is the first 16-bytes of SHA256(txid), which is used to identify
15
// the breach transaction.
16
type BreachHint [BreachHintSize]byte
17

18
// NewBreachHintFromHash creates a breach hint from a transaction ID.
19
func NewBreachHintFromHash(hash *chainhash.Hash) BreachHint {
×
20
        h := sha256.New()
×
21
        h.Write(hash[:])
×
22

×
23
        var hint BreachHint
×
24
        copy(hint[:], h.Sum(nil))
×
25
        return hint
×
26
}
×
27

28
// String returns a hex encoding of the breach hint.
29
func (h BreachHint) String() string {
×
30
        return hex.EncodeToString(h[:])
×
31
}
×
32

33
// BreachKey is computed as SHA256(txid || txid), which produces the key for
34
// decrypting a client's encrypted blobs.
35
type BreachKey [KeySize]byte
36

37
// NewBreachKeyFromHash creates a breach key from a transaction ID.
38
func NewBreachKeyFromHash(hash *chainhash.Hash) BreachKey {
×
39
        h := sha256.New()
×
40
        h.Write(hash[:])
×
41
        h.Write(hash[:])
×
42

×
43
        var key BreachKey
×
44
        copy(key[:], h.Sum(nil))
×
45
        return key
×
46
}
×
47

48
// String returns a hex encoding of the breach key.
49
func (k BreachKey) String() string {
×
50
        return hex.EncodeToString(k[:])
×
51
}
×
52

53
// NewBreachHintAndKeyFromHash derives a BreachHint and BreachKey from a given
54
// txid in a single pass. The hint and key are computed as:
55
//
56
//        hint = SHA256(txid)
57
//        key = SHA256(txid || txid)
58
func NewBreachHintAndKeyFromHash(hash *chainhash.Hash) (BreachHint, BreachKey) {
×
59
        var (
×
60
                hint BreachHint
×
61
                key  BreachKey
×
62
        )
×
63

×
64
        h := sha256.New()
×
65
        h.Write(hash[:])
×
66
        copy(hint[:], h.Sum(nil))
×
67
        h.Write(hash[:])
×
68
        copy(key[:], h.Sum(nil))
×
69

×
70
        return hint, key
×
71
}
×
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